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:
+3
-2
@@ -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. */
|
/* Copyright (c) Steve Creps, 1988. */
|
||||||
/* NetHack may be freely redistributed. See license for details. */
|
/* 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 *));
|
E boolean FDECL(can_read_file, (const char *));
|
||||||
#endif
|
#endif
|
||||||
E void FDECL(config_error_init, (BOOLEAN_P, const char *, BOOLEAN_P));
|
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 int NDECL(config_error_done);
|
||||||
E boolean FDECL(read_config_file, (const char *, int));
|
E boolean FDECL(read_config_file, (const char *, int));
|
||||||
E void FDECL(check_recordfile, (const char *));
|
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(verbalize, (const char *, ...)) PRINTF_F(1, 2);
|
||||||
E void VDECL(raw_printf, (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(impossible, (const char *, ...)) PRINTF_F(1, 2);
|
||||||
|
E void VDECL(config_error_add, (const char *, ...)) PRINTF_F(1, 2);
|
||||||
|
|
||||||
/* ### polyself.c ### */
|
/* ### polyself.c ### */
|
||||||
|
|
||||||
|
|||||||
+26
-34
@@ -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) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||||
/*-Copyright (c) Derek S. Ray, 2015. */
|
/*-Copyright (c) Derek S. Ray, 2015. */
|
||||||
/* NetHack may be freely redistributed. See license for details. */
|
/* NetHack may be freely redistributed. See license for details. */
|
||||||
@@ -2494,7 +2494,7 @@ char *origbuf;
|
|||||||
n = atoi(bufp);
|
n = atoi(bufp);
|
||||||
if (n < 1) {
|
if (n < 1) {
|
||||||
config_error_add(
|
config_error_add(
|
||||||
"Illegal value in MAX_STATUENAME_RANK (minimum is 1).");
|
"Illegal value in MAX_STATUENAME_RANK (minimum is 1).");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
sysopt.tt_oname_maxrank = n;
|
sysopt.tt_oname_maxrank = n;
|
||||||
@@ -2736,7 +2736,7 @@ struct _config_error_frame {
|
|||||||
struct _config_error_frame *next;
|
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
|
void
|
||||||
config_error_init(from_file, sourcename, secure)
|
config_error_init(from_file, sourcename, secure)
|
||||||
@@ -2745,7 +2745,7 @@ const char *sourcename;
|
|||||||
boolean secure;
|
boolean secure;
|
||||||
{
|
{
|
||||||
struct _config_error_frame *tmp = (struct _config_error_frame *)
|
struct _config_error_frame *tmp = (struct _config_error_frame *)
|
||||||
alloc(sizeof(struct _config_error_frame));
|
alloc(sizeof (struct _config_error_frame));
|
||||||
|
|
||||||
tmp->line_num = 0;
|
tmp->line_num = 0;
|
||||||
tmp->num_errors = 0;
|
tmp->num_errors = 0;
|
||||||
@@ -2754,8 +2754,8 @@ boolean secure;
|
|||||||
tmp->secure = secure;
|
tmp->secure = secure;
|
||||||
tmp->origline[0] = '\0';
|
tmp->origline[0] = '\0';
|
||||||
if (sourcename && sourcename[0]) {
|
if (sourcename && sourcename[0]) {
|
||||||
(void) strncpy(tmp->source, sourcename, sizeof(tmp->source)-1);
|
(void) strncpy(tmp->source, sourcename, sizeof (tmp->source) - 1);
|
||||||
tmp->source[sizeof(tmp->source)-1] = '\0';
|
tmp->source[sizeof (tmp->source) - 1] = '\0';
|
||||||
} else
|
} else
|
||||||
tmp->source[0] = '\0';
|
tmp->source[0] = '\0';
|
||||||
|
|
||||||
@@ -2778,49 +2778,43 @@ const char *line;
|
|||||||
ced->line_num++;
|
ced->line_num++;
|
||||||
ced->origline_shown = FALSE;
|
ced->origline_shown = FALSE;
|
||||||
if (line && line[0]) {
|
if (line && line[0]) {
|
||||||
(void) strncpy(ced->origline, line, sizeof(ced->origline)-1);
|
(void) strncpy(ced->origline, line, sizeof (ced->origline) - 1);
|
||||||
ced->origline[sizeof(ced->origline)-1] = '\0';
|
ced->origline[sizeof (ced->origline) - 1] = '\0';
|
||||||
} else
|
} else
|
||||||
ced->origline[0] = '\0';
|
ced->origline[0] = '\0';
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*VARARGS1*/
|
/* varargs 'config_error_add()' moved to pline.c */
|
||||||
void config_error_add
|
void
|
||||||
VA_DECL(const char *, str)
|
config_erradd(buf)
|
||||||
|
const char *buf;
|
||||||
{
|
{
|
||||||
char buf[BUFSZ];
|
|
||||||
char lineno[QBUFSZ];
|
char lineno[QBUFSZ];
|
||||||
|
|
||||||
VA_START(str);
|
if (!buf || !*buf)
|
||||||
VA_INIT(str, char *);
|
buf = "Unknown error";
|
||||||
|
|
||||||
Vsprintf(buf, str, VA_ARGS);
|
|
||||||
|
|
||||||
if (!config_error_data) {
|
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();
|
wait_synch();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
config_error_data->num_errors++;
|
config_error_data->num_errors++;
|
||||||
if (!config_error_data->origline_shown
|
if (!config_error_data->origline_shown && !config_error_data->secure) {
|
||||||
&& !config_error_data->secure) {
|
|
||||||
pline("\n%s", config_error_data->origline);
|
pline("\n%s", config_error_data->origline);
|
||||||
config_error_data->origline_shown = TRUE;
|
config_error_data->origline_shown = TRUE;
|
||||||
}
|
}
|
||||||
if (config_error_data->line_num > 0
|
if (config_error_data->line_num > 0 && !config_error_data->secure) {
|
||||||
&& !config_error_data->secure) {
|
Sprintf(lineno, "Line %d: ", config_error_data->line_num);
|
||||||
Sprintf(lineno, "Line %i: ", config_error_data->line_num);
|
|
||||||
} else
|
} else
|
||||||
lineno[0] = '\0';
|
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
|
int
|
||||||
@@ -2833,17 +2827,14 @@ config_error_done()
|
|||||||
return 0;
|
return 0;
|
||||||
n = config_error_data->num_errors;
|
n = config_error_data->num_errors;
|
||||||
if (n) {
|
if (n) {
|
||||||
pline("\n%i error%s in %s.\n", n,
|
pline("\n%d error%s in %s.\n", n,
|
||||||
(n > 1) ? "s" : "",
|
(n > 1) ? "s" : "",
|
||||||
*config_error_data->source
|
*config_error_data->source
|
||||||
? config_error_data->source : configfile);
|
? config_error_data->source : configfile);
|
||||||
wait_synch();
|
wait_synch();
|
||||||
}
|
}
|
||||||
|
|
||||||
config_error_data = tmp->next;
|
config_error_data = tmp->next;
|
||||||
|
|
||||||
free(tmp);
|
free(tmp);
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3108,7 +3099,8 @@ boolean FDECL((*proc), (char *));
|
|||||||
char *section;
|
char *section;
|
||||||
char *bufp = find_optparam(buf);
|
char *bufp = find_optparam(buf);
|
||||||
if (!bufp) {
|
if (!bufp) {
|
||||||
config_error_add("Format is CHOOSE=section1,section2,...");
|
config_error_add(
|
||||||
|
"Format is CHOOSE=section1,section2,...");
|
||||||
rv = FALSE;
|
rv = FALSE;
|
||||||
free(buf);
|
free(buf);
|
||||||
buf = (char *) 0;
|
buf = (char *) 0;
|
||||||
@@ -3199,8 +3191,8 @@ int which_set;
|
|||||||
}
|
}
|
||||||
if (!chosen_symset_end)
|
if (!chosen_symset_end)
|
||||||
config_error_add("Missing finish for symset \"%s\"",
|
config_error_add("Missing finish for symset \"%s\"",
|
||||||
symset[which_set].name ? symset[which_set].name
|
symset[which_set].name ? symset[which_set].name
|
||||||
: "unknown");
|
: "unknown");
|
||||||
|
|
||||||
config_error_done();
|
config_error_done();
|
||||||
|
|
||||||
|
|||||||
+70
-10
@@ -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) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||||
/*-Copyright (c) Robert Patrick Rankin, 2018. */
|
/*-Copyright (c) Robert Patrick Rankin, 2018. */
|
||||||
/* NetHack may be freely redistributed. See license for details. */
|
/* 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"
|
#include "hack.h"
|
||||||
|
|
||||||
static unsigned pline_flags = 0;
|
static unsigned pline_flags = 0;
|
||||||
@@ -62,7 +61,6 @@ dumplogfreemessages()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*VARARGS1*/
|
|
||||||
/* Note that these declarations rely on knowledge of the internals
|
/* Note that these declarations rely on knowledge of the internals
|
||||||
* of the variable argument handling stuff in "tradstdc.h"
|
* of the variable argument handling stuff in "tradstdc.h"
|
||||||
*/
|
*/
|
||||||
@@ -70,7 +68,9 @@ dumplogfreemessages()
|
|||||||
#if defined(USE_STDARG) || defined(USE_VARARGS)
|
#if defined(USE_STDARG) || defined(USE_VARARGS)
|
||||||
static void FDECL(vpline, (const char *, va_list));
|
static void FDECL(vpline, (const char *, va_list));
|
||||||
|
|
||||||
void pline
|
/*VARARGS1*/
|
||||||
|
void
|
||||||
|
pline
|
||||||
VA_DECL(const char *, line)
|
VA_DECL(const char *, line)
|
||||||
{
|
{
|
||||||
VA_START(line);
|
VA_START(line);
|
||||||
@@ -93,7 +93,9 @@ va_list the_args;
|
|||||||
|
|
||||||
# define vpline pline
|
# define vpline pline
|
||||||
|
|
||||||
void pline
|
/*VARARGS1*/
|
||||||
|
void
|
||||||
|
pline
|
||||||
VA_DECL(const char *, line)
|
VA_DECL(const char *, line)
|
||||||
#endif /* USE_STDARG | USE_VARARG */
|
#endif /* USE_STDARG | USE_VARARG */
|
||||||
{ /* start of vpline() or of nested block in USE_OLDARG's pline() */
|
{ /* start of vpline() or of nested block in USE_OLDARG's pline() */
|
||||||
@@ -260,6 +262,7 @@ void You
|
|||||||
VA_DECL(const char *, line)
|
VA_DECL(const char *, line)
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
VA_START(line);
|
VA_START(line);
|
||||||
VA_INIT(line, const char *);
|
VA_INIT(line, const char *);
|
||||||
vpline(YouMessage(tmp, "You ", line), VA_ARGS);
|
vpline(YouMessage(tmp, "You ", line), VA_ARGS);
|
||||||
@@ -271,6 +274,7 @@ void Your
|
|||||||
VA_DECL(const char *, line)
|
VA_DECL(const char *, line)
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
VA_START(line);
|
VA_START(line);
|
||||||
VA_INIT(line, const char *);
|
VA_INIT(line, const char *);
|
||||||
vpline(YouMessage(tmp, "Your ", line), VA_ARGS);
|
vpline(YouMessage(tmp, "Your ", line), VA_ARGS);
|
||||||
@@ -282,6 +286,7 @@ void You_feel
|
|||||||
VA_DECL(const char *, line)
|
VA_DECL(const char *, line)
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
VA_START(line);
|
VA_START(line);
|
||||||
VA_INIT(line, const char *);
|
VA_INIT(line, const char *);
|
||||||
if (Unaware)
|
if (Unaware)
|
||||||
@@ -297,6 +302,7 @@ void You_cant
|
|||||||
VA_DECL(const char *, line)
|
VA_DECL(const char *, line)
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
VA_START(line);
|
VA_START(line);
|
||||||
VA_INIT(line, const char *);
|
VA_INIT(line, const char *);
|
||||||
vpline(YouMessage(tmp, "You can't ", line), VA_ARGS);
|
vpline(YouMessage(tmp, "You can't ", line), VA_ARGS);
|
||||||
@@ -308,6 +314,7 @@ void pline_The
|
|||||||
VA_DECL(const char *, line)
|
VA_DECL(const char *, line)
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
VA_START(line);
|
VA_START(line);
|
||||||
VA_INIT(line, const char *);
|
VA_INIT(line, const char *);
|
||||||
vpline(YouMessage(tmp, "The ", line), VA_ARGS);
|
vpline(YouMessage(tmp, "The ", line), VA_ARGS);
|
||||||
@@ -319,6 +326,7 @@ void There
|
|||||||
VA_DECL(const char *, line)
|
VA_DECL(const char *, line)
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
VA_START(line);
|
VA_START(line);
|
||||||
VA_INIT(line, const char *);
|
VA_INIT(line, const char *);
|
||||||
vpline(YouMessage(tmp, "There ", line), VA_ARGS);
|
vpline(YouMessage(tmp, "There ", line), VA_ARGS);
|
||||||
@@ -444,6 +452,7 @@ void impossible
|
|||||||
VA_DECL(const char *, s)
|
VA_DECL(const char *, s)
|
||||||
{
|
{
|
||||||
char pbuf[2 * BUFSZ];
|
char pbuf[2 * BUFSZ];
|
||||||
|
|
||||||
VA_START(s);
|
VA_START(s);
|
||||||
VA_INIT(s, const char *);
|
VA_INIT(s, const char *);
|
||||||
if (program_state.in_impossible)
|
if (program_state.in_impossible)
|
||||||
@@ -454,16 +463,21 @@ VA_DECL(const char *, s)
|
|||||||
pbuf[BUFSZ - 1] = '\0'; /* sanity */
|
pbuf[BUFSZ - 1] = '\0'; /* sanity */
|
||||||
paniclog("impossible", pbuf);
|
paniclog("impossible", pbuf);
|
||||||
if (iflags.debug_fuzzer)
|
if (iflags.debug_fuzzer)
|
||||||
panic(pbuf);
|
panic("%s", pbuf);
|
||||||
pline("%s", VA_PASS1(pbuf));
|
pline("%s", VA_PASS1(pbuf));
|
||||||
pline(VA_PASS1(
|
/* reuse pbuf[] */
|
||||||
"Program in disorder! (Saving and reloading may fix this problem.)"));
|
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;
|
program_state.in_impossible = 0;
|
||||||
VA_END();
|
VA_END();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MSGHANDLER) && (defined(POSIX_TYPES) || defined(__GNUC__))
|
#if defined(MSGHANDLER) && (defined(POSIX_TYPES) || defined(__GNUC__))
|
||||||
static boolean use_pline_handler = TRUE;
|
static boolean use_pline_handler = TRUE;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
execplinehandler(line)
|
execplinehandler(line)
|
||||||
const char *line;
|
const char *line;
|
||||||
@@ -501,6 +515,52 @@ const char *line;
|
|||||||
pline("%s", VA_PASS1("Fork to message handler failed."));
|
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*/
|
/*pline.c*/
|
||||||
|
|||||||
Reference in New Issue
Block a user