From: cohrs Date: Wed, 23 Jan 2002 06:21:58 +0000 (+0000) Subject: X11 buffer overflow avoidance X-Git-Tag: MOVE2GIT~3379 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a80a7ab93906aeed2ced5b0f52fc134006d37b30;p=nethack X11 buffer overflow avoidance Don't overflow the buffer passed to getlin(). --- diff --git a/win/X11/winX.c b/win/X11/winX.c index 2d767f2a6..cb68d05cf 100644 --- a/win/X11/winX.c +++ b/win/X11/winX.c @@ -1210,12 +1210,20 @@ done_button(w, client_data, call_data) XtPointer client_data; XtPointer call_data; { + int len; char *s; Widget dialog = (Widget) client_data; s = (char *) GetDialogResponse(dialog); - Strcpy(getline_input, s); + len = strlen(s); + + /* Truncate input if necessary */ + if (len >= BUFSZ) len = BUFSZ - 1; + + (void) strncpy(getline_input, s, len); + getline_input[len] = '\0'; XtFree(s); + nh_XtPopdown(XtParent(dialog)); exit_x_event = TRUE; }