From deb02f9b368ca4970184e51830f8b97b27d6128b Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Sun, 10 Oct 1999 17:56:02 +0000 Subject: [PATCH] o Add T_PATH flag to allow simple sanity checks for default values that are supposed to be pathnames. o Fix a duplicate free when visudo finds an error. --- defaults.c | 16 ++++++++++++---- defaults.h | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/defaults.c b/defaults.c index 3287cc733..c10b48b60 100644 --- a/defaults.c +++ b/defaults.c @@ -195,10 +195,10 @@ struct sudo_defs_types sudo_defs_table[] = { "umask", T_MODE|T_BOOL, { 0 }, "Umask to use or 0777 to use user's: 0%o" }, { - "logfile", T_STR|T_BOOL, { 0 }, + "logfile", T_STR|T_BOOL|T_PATH, { 0 }, "Path to log file: %s" }, { - "mailerpath", T_STR|T_BOOL, { 0 }, + "mailerpath", T_STR|T_BOOL|T_PATH, { 0 }, "Path to mail program: %s" }, { "mailerflags", T_STR|T_BOOL, { 0 }, @@ -213,7 +213,7 @@ struct sudo_defs_types sudo_defs_table[] = { "badpass_message", T_STR, { 0 }, "Incorrect password message: %s" }, { - "timestampdir", T_STR, { 0 }, + "timestampdir", T_STR|T_PATH, { 0 }, "Path to authentication timestamp dir: %s" }, { "exempt_group", T_STR|T_BOOL, { 0 }, @@ -354,6 +354,12 @@ set_default(var, val, op) return(FALSE); } } + if ((cur->type & T_PATH) && *val != '/') { + (void) fprintf(stderr, + "%s: values for `%s' must start with a '/'\n", Argv[0], + var); + return(FALSE); + } if (!store_str(val, cur, op)) { (void) fprintf(stderr, "%s: value '%s' is invalid for option '%s'\n", Argv[0], @@ -426,8 +432,10 @@ init_defaults() case T_STR: case T_LOGFAC: case T_LOGPRI: - if (def->sd_un.str) + if (def->sd_un.str) { free(def->sd_un.str); + def->sd_un.str = NULL; + } break; } } diff --git a/defaults.h b/defaults.h index 76d12f441..e5d61ba39 100644 --- a/defaults.h +++ b/defaults.h @@ -65,6 +65,7 @@ struct sudo_defs_types { #define T_LOGPRI 0x006 #define T_MASK 0x0FF #define T_BOOL 0x100 +#define T_PATH 0x200 /* * Indexes into sudo_defs_table -- 2.40.0