]> granicus.if.org Git - nethack/commitdiff
X11 buffer overflow avoidance
authorcohrs <cohrs>
Wed, 23 Jan 2002 06:21:58 +0000 (06:21 +0000)
committercohrs <cohrs>
Wed, 23 Jan 2002 06:21:58 +0000 (06:21 +0000)
Don't overflow the buffer passed to getlin().

win/X11/winX.c

index 2d767f2a6ebaee7e49def575919e0aeffbe78e35..cb68d05cff7158d4384d9a0aec417885e240f44c 100644 (file)
@@ -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;
 }