]> granicus.if.org Git - nethack/commitdiff
Prevent possible buffer overflow
authorPasi Kallinen <paxed@alt.org>
Sun, 26 Apr 2015 12:56:28 +0000 (15:56 +0300)
committerPasi Kallinen <paxed@alt.org>
Sun, 26 Apr 2015 13:15:44 +0000 (16:15 +0300)
getlin() gets at most a BUFSZ string from user; make the buf big
enough to hold that _and_ the query itself.

src/dungeon.c

index 8c436e1c8cb0e437e16d97b11d4201ebd81eddd8..43f4afab156091601e7a682ea1c84b584d6777a8 100644 (file)
@@ -1868,9 +1868,10 @@ donamelevel()
     if (!(mptr = find_mapseen(&u.uz))) return 0;
 
     if (mptr->custom) {
-       char qbuf[BUFSZ];
-       Sprintf(qbuf, "Replace annotation \"%s\" with?", mptr->custom);
-       getlin(qbuf, nbuf);
+       const char querystr[] = "Replace annotation \"%s\" with?";
+       char tmpbuf[BUFSZ + sizeof(querystr)];
+       Sprintf(tmpbuf, querystr, mptr->custom);
+       getlin(tmpbuf, nbuf);
     } else
        getlin("What do you want to call this dungeon level?", nbuf);
     if (index(nbuf, '\033')) return 0;