ensure existing callers of string_for_opt() check return value before using it
fix potential buffer overflow in add_menu_coloring()
fix potential buffer overflow in sym_val()
+fix potential buffer overflow in pline(), raw_printf(), and config_error_add()
Fixes to Post-3.6.4 Problems that Were Exposed Via git Repository
#define NEED_VARARGS /* Uses ... */ /* comment line for pre-compiled headers */
#include "hack.h"
+#define BIGBUFSZ (5 * BUFSZ) /* big enough to format a 4*BUFSZ string (from
+ * config file parsing) with modest decoration;
+ * result will then be truncated to BUFSZ-1 */
+
static unsigned pline_flags = 0;
static char prevmsg[BUFSZ];
#endif /* USE_STDARG | USE_VARARG */
{ /* start of vpline() or of nested block in USE_OLDARG's pline() */
static int in_pline = 0;
- char pbuf[3 * BUFSZ];
+ char pbuf[BIGBUFSZ]; /* will get chopped down to BUFSZ-1 if longer */
int ln;
int msgtyp;
boolean no_repeat;
VA_DECL(const char *, line)
#endif
{
- char pbuf[3 * BUFSZ];
- int ln;
+ char pbuf[BIGBUFSZ]; /* will be chopped down to BUFSZ-1 if longer */
/* Do NOT use VA_START and VA_END in here... see above */
if (index(line, '%')) {
Vsprintf(pbuf, line, VA_ARGS);
line = pbuf;
}
- if ((ln = (int) strlen(line)) > BUFSZ - 1) {
+ if ((int) strlen(line) > BUFSZ - 1) {
if (line != pbuf)
line = strncpy(pbuf, line, BUFSZ - 1);
/* unlike pline, we don't futz around to keep last few chars */
void impossible
VA_DECL(const char *, s)
{
- char pbuf[2 * BUFSZ];
+ char pbuf[BIGBUFSZ]; /* will be chopped down to BUFSZ-1 if longer */
VA_START(s);
VA_INIT(s, const char *);
VA_DECL(const char *, str)
#endif /* ?(USE_STDARG || USE_VARARG) */
{ /* start of vconf...() or of nested block in USE_OLDARG's conf...() */
- char buf[2 * BUFSZ];
+ char buf[BIGBUFSZ]; /* will be chopped down to BUFSZ-1 if longer */
Vsprintf(buf, str, VA_ARGS);
buf[BUFSZ - 1] = '\0';