build and bug fixes for USE_OLDARGS

New:  call to panic() in impossible() used arbitrary string as a
format so was vulnerable to percent signs in that string.  (This
potentially serious problem is not limited to USE_OLDARGS.)

Old:  revised message string for impossible ("save/restore might fix
this" instead of "perhaps you'd better quit") passed wrong number of
arguments to pline() when using the clumsy VA_PASSx() mechanism (was
missing arg 0 for the fixed-arg format argument).

Old:  varargs config_error_add() in files.c wouldn't compile for
USE_OLDARGS.  Evidently no one has been impacted by that but this
fixes it anyway.  (Two problems:  prototype used FDECL() when it
should have been using VDECL(), and calls to config_error_add() in
the same file would need the VA_PASSx() stuff to force presence of
all optional args.  I moved it instead of adding the latter.)
This commit is contained in:
PatR
2018-11-08 15:33:03 -08:00
parent f9f1236f26
commit 91f973306b
3 changed files with 99 additions and 46 deletions

View File

@@ -1,10 +1,9 @@
/* NetHack 3.6 pline.c $NHDT-Date: 1520964541 2018/03/13 18:09:01 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.66 $ */
/* NetHack 3.6 pline.c $NHDT-Date: 1541719974 2018/11/08 23:32:54 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.69 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2018. */
/* NetHack may be freely redistributed. See license for details. */
#define NEED_VARARGS /* Uses ... */ /* comment line for pre-compiled headers \
*/
#define NEED_VARARGS /* Uses ... */ /* comment line for pre-compiled headers */
#include "hack.h"
static unsigned pline_flags = 0;
@@ -62,7 +61,6 @@ dumplogfreemessages()
}
#endif
/*VARARGS1*/
/* Note that these declarations rely on knowledge of the internals
* of the variable argument handling stuff in "tradstdc.h"
*/
@@ -70,7 +68,9 @@ dumplogfreemessages()
#if defined(USE_STDARG) || defined(USE_VARARGS)
static void FDECL(vpline, (const char *, va_list));
void pline
/*VARARGS1*/
void
pline
VA_DECL(const char *, line)
{
VA_START(line);
@@ -93,7 +93,9 @@ va_list the_args;
# define vpline pline
void pline
/*VARARGS1*/
void
pline
VA_DECL(const char *, line)
#endif /* USE_STDARG | USE_VARARG */
{ /* start of vpline() or of nested block in USE_OLDARG's pline() */
@@ -260,6 +262,7 @@ void You
VA_DECL(const char *, line)
{
char *tmp;
VA_START(line);
VA_INIT(line, const char *);
vpline(YouMessage(tmp, "You ", line), VA_ARGS);
@@ -271,6 +274,7 @@ void Your
VA_DECL(const char *, line)
{
char *tmp;
VA_START(line);
VA_INIT(line, const char *);
vpline(YouMessage(tmp, "Your ", line), VA_ARGS);
@@ -282,6 +286,7 @@ void You_feel
VA_DECL(const char *, line)
{
char *tmp;
VA_START(line);
VA_INIT(line, const char *);
if (Unaware)
@@ -297,6 +302,7 @@ void You_cant
VA_DECL(const char *, line)
{
char *tmp;
VA_START(line);
VA_INIT(line, const char *);
vpline(YouMessage(tmp, "You can't ", line), VA_ARGS);
@@ -308,6 +314,7 @@ void pline_The
VA_DECL(const char *, line)
{
char *tmp;
VA_START(line);
VA_INIT(line, const char *);
vpline(YouMessage(tmp, "The ", line), VA_ARGS);
@@ -319,6 +326,7 @@ void There
VA_DECL(const char *, line)
{
char *tmp;
VA_START(line);
VA_INIT(line, const char *);
vpline(YouMessage(tmp, "There ", line), VA_ARGS);
@@ -444,6 +452,7 @@ void impossible
VA_DECL(const char *, s)
{
char pbuf[2 * BUFSZ];
VA_START(s);
VA_INIT(s, const char *);
if (program_state.in_impossible)
@@ -454,16 +463,21 @@ VA_DECL(const char *, s)
pbuf[BUFSZ - 1] = '\0'; /* sanity */
paniclog("impossible", pbuf);
if (iflags.debug_fuzzer)
panic(pbuf);
panic("%s", pbuf);
pline("%s", VA_PASS1(pbuf));
pline(VA_PASS1(
"Program in disorder! (Saving and reloading may fix this problem.)"));
/* reuse pbuf[] */
Strcpy(pbuf, "Program in disorder!");
if (program_state.something_worth_saving)
Strcat(pbuf, " (Saving and reloading may fix this problem.)");
pline("%s", VA_PASS1(pbuf));
program_state.in_impossible = 0;
VA_END();
}
#if defined(MSGHANDLER) && (defined(POSIX_TYPES) || defined(__GNUC__))
static boolean use_pline_handler = TRUE;
static void
execplinehandler(line)
const char *line;
@@ -501,6 +515,52 @@ const char *line;
pline("%s", VA_PASS1("Fork to message handler failed."));
}
}
#endif /* defined(POSIX_TYPES) || defined(__GNUC__) */
#endif /* MSGHANDLER && (POSIX_TYPES || __GNUC__) */
/*
* varargs handling for files.c
*/
#if defined(USE_STDARG) || defined(USE_VARARGS)
static void FDECL(vconfig_error_add, (const char *, va_list));
/*VARARGS1*/
void
config_error_add
VA_DECL(const char *, str)
{
VA_START(str);
VA_INIT(str, char *);
vconfig_error_add(str, VA_ARGS);
VA_END();
}
# ifdef USE_STDARG
static void
vconfig_error_add(const char *str, va_list the_args)
# else
static void
vconfig_error_add(str, the_args)
const char *str;
va_list the_args;
# endif
#else /* !(USE_STDARG || USE_VARARG) => USE_OLDARGS */
/*VARARGS1*/
void
config_error_add
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];
Vsprintf(buf, str, VA_ARGS);
buf[BUFSZ - 1] = '\0';
config_erradd(buf);
#if !(defined(USE_STDARG) || defined(USE_VARARGS))
VA_END(); /* (see pline/vpline -- ends nested block for USE_OLDARGS) */
#endif
}
/*pline.c*/