git: da8884202940 - main - config: error out on malformed env/hint lines
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 16 Feb 2023 20:37:36 UTC
The branch main has been updated by kevans:
URL: https://cgit.FreeBSD.org/src/commit/?id=da8884202940498096a8c37d91d2fbbf471c6e7b
commit da8884202940498096a8c37d91d2fbbf471c6e7b
Author: Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2023-02-16 20:36:17 +0000
Commit: Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2023-02-16 20:37:05 +0000
config: error out on malformed env/hint lines
We need these to be assignments, error out if they're not.
While we're here, tag errout as __printflike so that the compiler will
sanity check the format string + args.
CID: 1505293
Reviewed by: emaste, imp
Differential Revision: https://reviews.freebsd.org/D38642
---
usr.sbin/config/mkmakefile.cc | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)
diff --git a/usr.sbin/config/mkmakefile.cc b/usr.sbin/config/mkmakefile.cc
index 969d32cf1389..2aaed82ce3ee 100644
--- a/usr.sbin/config/mkmakefile.cc
+++ b/usr.sbin/config/mkmakefile.cc
@@ -69,10 +69,11 @@ static void read_files(void);
static void sanitize_envline(char *result, const char *src);
static bool preprocess(char *line, char *result);
static void process_into_file(char *line, FILE *ofp);
-static void process_into_map(char *line, env_map &emap);
+static int process_into_map(char *line, env_map &emap);
static void dump_map(env_map &emap, FILE *ofp);
-static void errout(const char *fmt, ...)
+static void __printflike(1, 2)
+errout(const char *fmt, ...)
{
va_list ap;
@@ -269,16 +270,20 @@ process_into_file(char *line, FILE *ofp)
fprintf(ofp, "\"%s\\0\"\n", result);
}
-static void
+static int
process_into_map(char *line, env_map &emap)
{
char result[BUFSIZ], *s;
if (preprocess(line, result)) {
s = strchr(result, '=');
+ if (s == NULL)
+ return (EINVAL);
*s = '\0';
emap[result] = s + 1;
}
+
+ return (0);
}
static void
@@ -320,8 +325,11 @@ makehints(void)
ifp = fopen(hint->hint_name, "r");
if (ifp == NULL)
err(1, "%s", hint->hint_name);
- while (fgets(line, BUFSIZ, ifp) != NULL)
- process_into_map(line, emap);
+ while (fgets(line, BUFSIZ, ifp) != NULL) {
+ if (process_into_map(line, emap) != 0)
+ errout("%s: malformed line: %s\n",
+ hint->hint_name, line);
+ }
dump_map(emap, ofp);
fclose(ifp);
}
@@ -360,8 +368,11 @@ makeenv(void)
ifp = fopen(envvar->env_str, "r");
if (ifp == NULL)
err(1, "%s", envvar->env_str);
- while (fgets(line, BUFSIZ, ifp) != NULL)
- process_into_map(line, emap);
+ while (fgets(line, BUFSIZ, ifp) != NULL) {
+ if (process_into_map(line, emap) != 0)
+ errout("%s: malformed line: %s\n",
+ envvar->env_str, line);
+ }
dump_map(emap, ofp);
fclose(ifp);
} else