]> granicus.if.org Git - nethack/commitdiff
More futureproofing hypotheticals
authorPasi Kallinen <paxed@alt.org>
Sun, 20 Dec 2020 10:23:09 +0000 (12:23 +0200)
committerPasi Kallinen <paxed@alt.org>
Sun, 20 Dec 2020 10:32:29 +0000 (12:32 +0200)
If you set COLNO larger than BUFSZ, few places cause a buffer overrun.
Add a new buffer size definition, COLBUFSZ, which is the larger of
COLNO and BUFSZ, used in places that care about a screen-wide string.

include/global.h
src/cmd.c
src/detect.c
src/options.c

index 1cdc6a1683a0296bd4aec654d098fb6cbf080dbd..c1b9ae14dbe9dff0bb33fdd05891962d7b23b2d6 100644 (file)
@@ -370,6 +370,13 @@ struct savefile_info {
 #define TBUFSZ 300 /* g.toplines[] buffer max msg: 3 81char names */
 /* plus longest prefix plus a few extra words */
 
+/* COLBUFSZ is the larger of BUFSZ and COLNO */
+#if BUFSZ > COLNO
+#define COLBUFSZ BUFSZ
+#else
+#define COLBUFSZ COLNO
+#endif
+
 #define PL_NSIZ 32 /* name of player, ghost, shopkeeper */
 #define PL_CSIZ 32 /* sizeof pl_character */
 #define PL_FSIZ 32 /* fruit name */
index 94f5a006876e0998600ffca8546fd255877b7348..2192f499c5b2ed83acf632cdeb0f6c5b78dc0c9f 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -1330,7 +1330,7 @@ wiz_map_levltyp(VOID_ARGS)
     }
 
     {
-        char dsc[BUFSZ];
+        char dsc[COLBUFSZ];
         s_level *slev = Is_special(&u.uz);
 
         Sprintf(dsc, "D:%d,L:%d", u.uz.dnum, u.uz.dlevel);
index 4bf7e0a0bb40a45da73e885f7500bb60ba11ad05..ddf52e59f05854b3b39a24f347d9afa04e6369a3 100644 (file)
@@ -1988,7 +1988,7 @@ dump_map()
     int x, y, glyph, skippedrows, lastnonblank;
     int subset = TER_MAP | TER_TRP | TER_OBJ | TER_MON;
     int default_glyph = cmap_to_glyph(g.level.flags.arboreal ? S_tree : S_stone);
-    char buf[BUFSZ];
+    char buf[COLBUFSZ];
     boolean blankrow, toprow;
 
     /*
index c1ce9eefb3a2cc925f9e836b028bc27f0de027f4..6560681a0f79e103f2fb5895a739f71cefe1dedd 100644 (file)
@@ -8307,7 +8307,7 @@ const char *str;
     char *s;
 
     if (!buf)
-        *(buf = (char *) alloc(BUFSZ)) = '\0';
+        *(buf = (char *) alloc(COLBUFSZ)) = '\0';
 
     if (!*str) {
         s = eos(buf);