From: Pasi Kallinen Date: Sun, 20 Dec 2020 10:23:09 +0000 (+0200) Subject: More futureproofing hypotheticals X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=957990c14d4e33c965bc1ff7d6bc6947197dedcf;p=nethack More futureproofing hypotheticals 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. --- diff --git a/include/global.h b/include/global.h index 1cdc6a168..c1b9ae14d 100644 --- a/include/global.h +++ b/include/global.h @@ -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 */ diff --git a/src/cmd.c b/src/cmd.c index 94f5a0068..2192f499c 100644 --- 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); diff --git a/src/detect.c b/src/detect.c index 4bf7e0a0b..ddf52e59f 100644 --- a/src/detect.c +++ b/src/detect.c @@ -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; /* diff --git a/src/options.c b/src/options.c index c1ce9eefb..6560681a0 100644 --- a/src/options.c +++ b/src/options.c @@ -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);