rnd-20061216-1-src
authorHolger Schemel <info@artsoft.org>
Sat, 16 Dec 2006 13:08:06 +0000 (14:08 +0100)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 08:53:53 +0000 (10:53 +0200)
* fixed nasty string overflow bug when entering too long envelope text

ChangeLog
src/conftime.h
src/editor.c
src/libgame/gadgets.c
src/libgame/gadgets.h

index 7fb353ec9789e5389aee227edd5af7654d8950b9..c5cf663ef7a2553687fc980b50c079aff39d4b09 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+2006-12-16
+       * fixed nasty string overflow bug when entering too long envelope text
+
 2006-12-05
        * added feedback sounds for menu navigation "menu.item.activating" and
          "menu.item.selecting" (for highlighting and executing menu entries)
 2006-12-05
        * added feedback sounds for menu navigation "menu.item.activating" and
          "menu.item.selecting" (for highlighting and executing menu entries)
index 8c7013bb719f22185b966874c5fafeb70dfdcabd..b269d2abc9bfb5aa8121118430d1121264d94464 100644 (file)
@@ -1 +1 @@
-#define COMPILE_DATE_STRING "[2006-12-06 01:13]"
+#define COMPILE_DATE_STRING "[2006-12-16 14:05]"
index 4218efbb530e4bf4e2b07229ebb4f93d1e29864a..69c63d208d74d0668fde7a200d8e3e86c6557b4a 100644 (file)
@@ -9081,7 +9081,14 @@ static void HandleTextAreaGadgets(struct GadgetInfo *gi)
 {
   int type_id = gi->custom_type_id;
 
 {
   int type_id = gi->custom_type_id;
 
+#if 1
+  strncpy(textarea_info[type_id].value, gi->textarea.value,
+         MAX_ENVELOPE_TEXT_LEN);
+  textarea_info[type_id].value[MAX_ENVELOPE_TEXT_LEN] = '\0';
+#else
+  /* !!! BUGGY !!! MAX_ENVELOPE_TEXT_LEN != MAX_GADGET_TEXTSIZE !!! */
   strcpy(textarea_info[type_id].value, gi->textarea.value);
   strcpy(textarea_info[type_id].value, gi->textarea.value);
+#endif
 
   level.changed = TRUE;
 }
 
   level.changed = TRUE;
 }
index afe4c81026630cef7c9a22a57e6bd69f60783958..23c51d36f4a9a15ff0608a3a6f27a1c00ff0cca4 100644 (file)
@@ -742,7 +742,7 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap)
 
       case GDI_INFO_TEXT:
        {
 
       case GDI_INFO_TEXT:
        {
-         int max_textsize = MAX_INFO_TEXTSIZE - 1;
+         int max_textsize = MAX_INFO_TEXTSIZE;
          char *text = va_arg(ap, char *);
 
          if (text != NULL)
          char *text = va_arg(ap, char *);
 
          if (text != NULL)
@@ -826,7 +826,7 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap)
          int max_textsize = MAX_GADGET_TEXTSIZE;
 
          if (gi->textinput.size)
          int max_textsize = MAX_GADGET_TEXTSIZE;
 
          if (gi->textinput.size)
-           max_textsize = MIN(gi->textinput.size, MAX_GADGET_TEXTSIZE - 1);
+           max_textsize = MIN(gi->textinput.size, MAX_GADGET_TEXTSIZE);
 
          strncpy(gi->textinput.value, va_arg(ap, char *), max_textsize);
          strcpy(gi->textinput.last_value, gi->textinput.value);
 
          strncpy(gi->textinput.value, va_arg(ap, char *), max_textsize);
          strcpy(gi->textinput.last_value, gi->textinput.value);
@@ -844,7 +844,7 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap)
       case GDI_TEXT_SIZE:
        {
          int tag_value = va_arg(ap, int);
       case GDI_TEXT_SIZE:
        {
          int tag_value = va_arg(ap, int);
-         int max_textsize = MIN(tag_value, MAX_GADGET_TEXTSIZE - 1);
+         int max_textsize = MIN(tag_value, MAX_GADGET_TEXTSIZE);
 
          gi->textinput.size = max_textsize;
          gi->textinput.value[max_textsize] = '\0';
 
          gi->textinput.size = max_textsize;
          gi->textinput.value[max_textsize] = '\0';
@@ -1992,10 +1992,10 @@ boolean HandleGadgets(int mx, int my, int button)
 
 static void insertCharIntoTextArea(struct GadgetInfo *gi, char c)
 {
 
 static void insertCharIntoTextArea(struct GadgetInfo *gi, char c)
 {
-  char text[MAX_GADGET_TEXTSIZE];
+  char text[MAX_GADGET_TEXTSIZE + 1];
   int cursor_position = gi->textarea.cursor_position;
 
   int cursor_position = gi->textarea.cursor_position;
 
-  if (strlen(gi->textarea.value) == MAX_GADGET_TEXTSIZE) /* no space left */
+  if (strlen(gi->textarea.value) >= MAX_GADGET_TEXTSIZE) /* no space left */
     return;
 
   strcpy(text, gi->textarea.value);
     return;
 
   strcpy(text, gi->textarea.value);
@@ -2056,7 +2056,7 @@ boolean HandleGadgetsKeyInput(Key key)
   }
   else if (gi->type & GD_TYPE_TEXT_INPUT)      /* only valid for text input */
   {
   }
   else if (gi->type & GD_TYPE_TEXT_INPUT)      /* only valid for text input */
   {
-    char text[MAX_GADGET_TEXTSIZE];
+    char text[MAX_GADGET_TEXTSIZE + 1];
     int text_length = strlen(gi->textinput.value);
     int cursor_pos = gi->textinput.cursor_position;
     char letter = getCharFromKey(key);
     int text_length = strlen(gi->textinput.value);
     int cursor_pos = gi->textinput.cursor_position;
     char letter = getCharFromKey(key);
@@ -2103,7 +2103,7 @@ boolean HandleGadgetsKeyInput(Key key)
   }
   else if (gi->type & GD_TYPE_TEXT_AREA)       /* only valid for text area */
   {
   }
   else if (gi->type & GD_TYPE_TEXT_AREA)       /* only valid for text area */
   {
-    char text[MAX_GADGET_TEXTSIZE];
+    char text[MAX_GADGET_TEXTSIZE + 1];
     int text_length = strlen(gi->textarea.value);
     int area_ysize = gi->textarea.ysize;
     int cursor_x_pref = gi->textarea.cursor_x_preferred;
     int text_length = strlen(gi->textarea.value);
     int area_ysize = gi->textarea.ysize;
     int cursor_x_pref = gi->textarea.cursor_x_preferred;
index 8c8d6c353bfd9b70a24a7792e9e8d11f9c394417..43125d66b3ab34b7d06c10a57d252678e5253bfa 100644 (file)
@@ -150,14 +150,14 @@ struct GadgetDrawingArea
 
 struct GadgetTextButton
 {
 
 struct GadgetTextButton
 {
-  char value[MAX_GADGET_TEXTSIZE];     /* text written on the button */
+  char value[MAX_GADGET_TEXTSIZE + 1]; /* text written on the button */
   int size;                            /* maximal size of button text */
 };
 
 struct GadgetTextInput
 {
   int size;                            /* maximal size of button text */
 };
 
 struct GadgetTextInput
 {
-  char value[MAX_GADGET_TEXTSIZE];     /* text string in input field */
-  char last_value[MAX_GADGET_TEXTSIZE];        /* last text string in input field */
+  char value[MAX_GADGET_TEXTSIZE + 1]; /* text string in input field */
+  char last_value[MAX_GADGET_TEXTSIZE + 1];/* last text string in input field */
   int cursor_position;                 /* actual text cursor position */
   int number_value;                    /* integer value, if numeric */
   int number_min;                      /* minimal allowed numeric value */
   int cursor_position;                 /* actual text cursor position */
   int number_value;                    /* integer value, if numeric */
   int number_min;                      /* minimal allowed numeric value */
@@ -167,8 +167,8 @@ struct GadgetTextInput
 
 struct GadgetTextArea
 {
 
 struct GadgetTextArea
 {
-  char value[MAX_GADGET_TEXTSIZE];     /* text string in input field */
-  char last_value[MAX_GADGET_TEXTSIZE];        /* last text string in input field */
+  char value[MAX_GADGET_TEXTSIZE + 1]; /* text string in input field */
+  char last_value[MAX_GADGET_TEXTSIZE + 1];/* last text string in input field */
   int cursor_position;                 /* actual text cursor position */
   int cursor_x;                                /* actual x cursor position */
   int cursor_y;                                /* actual y cursor position */
   int cursor_position;                 /* actual text cursor position */
   int cursor_x;                                /* actual x cursor position */
   int cursor_y;                                /* actual y cursor position */
@@ -221,7 +221,7 @@ struct GadgetInfo
   int id;                              /* internal gadget identifier */
   int custom_id;                       /* custom gadget identifier */
   int custom_type_id;                  /* custom gadget type identifier */
   int id;                              /* internal gadget identifier */
   int custom_id;                       /* custom gadget identifier */
   int custom_type_id;                  /* custom gadget type identifier */
-  char info_text[MAX_INFO_TEXTSIZE];   /* short popup info text */
+  char info_text[MAX_INFO_TEXTSIZE + 1];/* short popup info text */
   int x, y;                            /* gadget position */
   int width, height;                   /* gadget size */
   unsigned int type;                   /* type (button, text input, ...) */
   int x, y;                            /* gadget position */
   int width, height;                   /* gadget size */
   unsigned int type;                   /* type (button, text input, ...) */