From: Holger Schemel Date: Sat, 16 Dec 2006 13:08:06 +0000 (+0100) Subject: rnd-20061216-1-src X-Git-Tag: 3.2.3^2~4 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=07ebce49a5cbbaa7728e84e118961f750abe377a;p=rocksndiamonds.git rnd-20061216-1-src * fixed nasty string overflow bug when entering too long envelope text --- diff --git a/ChangeLog b/ChangeLog index 7fb353ec..c5cf663e 100644 --- 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) diff --git a/src/conftime.h b/src/conftime.h index 8c7013bb..b269d2ab 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2006-12-06 01:13]" +#define COMPILE_DATE_STRING "[2006-12-16 14:05]" diff --git a/src/editor.c b/src/editor.c index 4218efbb..69c63d20 100644 --- a/src/editor.c +++ b/src/editor.c @@ -9081,7 +9081,14 @@ static void HandleTextAreaGadgets(struct GadgetInfo *gi) { 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); +#endif level.changed = TRUE; } diff --git a/src/libgame/gadgets.c b/src/libgame/gadgets.c index afe4c810..23c51d36 100644 --- a/src/libgame/gadgets.c +++ b/src/libgame/gadgets.c @@ -742,7 +742,7 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) 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) @@ -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) - 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); @@ -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); - 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'; @@ -1992,10 +1992,10 @@ boolean HandleGadgets(int mx, int my, int button) 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; - 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); @@ -2056,7 +2056,7 @@ boolean HandleGadgetsKeyInput(Key key) } 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); @@ -2103,7 +2103,7 @@ boolean HandleGadgetsKeyInput(Key key) } 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; diff --git a/src/libgame/gadgets.h b/src/libgame/gadgets.h index 8c8d6c35..43125d66 100644 --- a/src/libgame/gadgets.h +++ b/src/libgame/gadgets.h @@ -150,14 +150,14 @@ struct GadgetDrawingArea 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 { - 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 */ @@ -167,8 +167,8 @@ struct GadgetTextInput 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 */ @@ -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 */ - 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, ...) */