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:
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.6 extern.h $NHDT-Date: 1541145514 2018/11/02 07:58:34 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.645 $ */
|
||||
/* NetHack 3.6 extern.h $NHDT-Date: 1541719965 2018/11/08 23:32:45 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.647 $ */
|
||||
/* Copyright (c) Steve Creps, 1988. */
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
|
||||
@@ -785,7 +785,7 @@ E void FDECL(unlock_file, (const char *));
|
||||
E boolean FDECL(can_read_file, (const char *));
|
||||
#endif
|
||||
E void FDECL(config_error_init, (BOOLEAN_P, const char *, BOOLEAN_P));
|
||||
E void FDECL(config_error_add, (const char *, ...)) PRINTF_F(1, 2);
|
||||
E void FDECL(config_erradd, (const char *));
|
||||
E int NDECL(config_error_done);
|
||||
E boolean FDECL(read_config_file, (const char *, int));
|
||||
E void FDECL(check_recordfile, (const char *));
|
||||
@@ -1877,6 +1877,7 @@ E void VDECL(There, (const char *, ...)) PRINTF_F(1, 2);
|
||||
E void VDECL(verbalize, (const char *, ...)) PRINTF_F(1, 2);
|
||||
E void VDECL(raw_printf, (const char *, ...)) PRINTF_F(1, 2);
|
||||
E void VDECL(impossible, (const char *, ...)) PRINTF_F(1, 2);
|
||||
E void VDECL(config_error_add, (const char *, ...)) PRINTF_F(1, 2);
|
||||
|
||||
/* ### polyself.c ### */
|
||||
|
||||
|
||||
44
src/files.c
44
src/files.c
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.6 files.c $NHDT-Date: 1526382938 2018/05/15 11:15:38 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.240 $ */
|
||||
/* NetHack 3.6 files.c $NHDT-Date: 1541719971 2018/11/08 23:32:51 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.242 $ */
|
||||
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||
/*-Copyright (c) Derek S. Ray, 2015. */
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
@@ -2736,7 +2736,7 @@ struct _config_error_frame {
|
||||
struct _config_error_frame *next;
|
||||
};
|
||||
|
||||
struct _config_error_frame *config_error_data = (struct _config_error_frame *)0;
|
||||
static struct _config_error_frame *config_error_data = 0;
|
||||
|
||||
void
|
||||
config_error_init(from_file, sourcename, secure)
|
||||
@@ -2786,41 +2786,35 @@ const char *line;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*VARARGS1*/
|
||||
void config_error_add
|
||||
VA_DECL(const char *, str)
|
||||
/* varargs 'config_error_add()' moved to pline.c */
|
||||
void
|
||||
config_erradd(buf)
|
||||
const char *buf;
|
||||
{
|
||||
char buf[BUFSZ];
|
||||
char lineno[QBUFSZ];
|
||||
|
||||
VA_START(str);
|
||||
VA_INIT(str, char *);
|
||||
|
||||
Vsprintf(buf, str, VA_ARGS);
|
||||
if (!buf || !*buf)
|
||||
buf = "Unknown error";
|
||||
|
||||
if (!config_error_data) {
|
||||
pline("%s.", *buf ? buf : "Unknown error");
|
||||
/* assumes pline() is using raw_printf() as this stage */
|
||||
pline("config_error_add: %s.", buf);
|
||||
wait_synch();
|
||||
return;
|
||||
}
|
||||
|
||||
config_error_data->num_errors++;
|
||||
if (!config_error_data->origline_shown
|
||||
&& !config_error_data->secure) {
|
||||
if (!config_error_data->origline_shown && !config_error_data->secure) {
|
||||
pline("\n%s", config_error_data->origline);
|
||||
config_error_data->origline_shown = TRUE;
|
||||
}
|
||||
if (config_error_data->line_num > 0
|
||||
&& !config_error_data->secure) {
|
||||
Sprintf(lineno, "Line %i: ", config_error_data->line_num);
|
||||
if (config_error_data->line_num > 0 && !config_error_data->secure) {
|
||||
Sprintf(lineno, "Line %d: ", config_error_data->line_num);
|
||||
} else
|
||||
lineno[0] = '\0';
|
||||
pline("%s %s%s.",
|
||||
config_error_data->secure ? "Error:" : " *",
|
||||
lineno,
|
||||
*buf ? buf : "Unknown error");
|
||||
|
||||
VA_END();
|
||||
pline("%s %s%s.", config_error_data->secure ? "Error:" : " *",
|
||||
lineno, buf);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -2833,17 +2827,14 @@ config_error_done()
|
||||
return 0;
|
||||
n = config_error_data->num_errors;
|
||||
if (n) {
|
||||
pline("\n%i error%s in %s.\n", n,
|
||||
pline("\n%d error%s in %s.\n", n,
|
||||
(n > 1) ? "s" : "",
|
||||
*config_error_data->source
|
||||
? config_error_data->source : configfile);
|
||||
wait_synch();
|
||||
}
|
||||
|
||||
config_error_data = tmp->next;
|
||||
|
||||
free(tmp);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
@@ -3108,7 +3099,8 @@ boolean FDECL((*proc), (char *));
|
||||
char *section;
|
||||
char *bufp = find_optparam(buf);
|
||||
if (!bufp) {
|
||||
config_error_add("Format is CHOOSE=section1,section2,...");
|
||||
config_error_add(
|
||||
"Format is CHOOSE=section1,section2,...");
|
||||
rv = FALSE;
|
||||
free(buf);
|
||||
buf = (char *) 0;
|
||||
|
||||
80
src/pline.c
80
src/pline.c
@@ -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*/
|
||||
|
||||
Reference in New Issue
Block a user