Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make Don't ignore return from snprintf or getcwd
details: https://anonhg.NetBSD.org/src/rev/1576b174dad4
branches: trunk
changeset: 371212:1576b174dad4
user: sjg <sjg%NetBSD.org@localhost>
date: Wed Sep 28 16:34:47 2022 +0000
description:
Don't ignore return from snprintf or getcwd
diffstat:
usr.bin/make/main.c | 10 ++++++----
usr.bin/make/meta.c | 34 ++++++++++++++++++++--------------
2 files changed, 26 insertions(+), 18 deletions(-)
diffs (102 lines):
diff -r 4be8584be449 -r 1576b174dad4 usr.bin/make/main.c
--- a/usr.bin/make/main.c Wed Sep 28 15:32:09 2022 +0000
+++ b/usr.bin/make/main.c Wed Sep 28 16:34:47 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.582 2022/05/07 17:49:47 rillig Exp $ */
+/* $NetBSD: main.c,v 1.583 2022/09/28 16:34:47 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -111,7 +111,7 @@
#include "trace.h"
/* "@(#)main.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: main.c,v 1.582 2022/05/07 17:49:47 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.583 2022/09/28 16:34:47 sjg Exp $");
#if defined(MAKE_NATIVE) && !defined(lint)
__COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
"The Regents of the University of California. "
@@ -704,8 +704,10 @@
va_end(ap);
if (path[0] != '/') {
- snprintf(buf2, MAXPATHLEN, "%s/%s", curdir, path);
- path = buf2;
+ if (snprintf(buf2, MAXPATHLEN, "%s/%s", curdir, path) <= MAXPATHLEN)
+ path = buf2;
+ else
+ return false;
}
/* look for the directory and try to chdir there */
diff -r 4be8584be449 -r 1576b174dad4 usr.bin/make/meta.c
--- a/usr.bin/make/meta.c Wed Sep 28 15:32:09 2022 +0000
+++ b/usr.bin/make/meta.c Wed Sep 28 16:34:47 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: meta.c,v 1.200 2022/04/15 12:28:16 rillig Exp $ */
+/* $NetBSD: meta.c,v 1.201 2022/09/28 16:34:47 sjg Exp $ */
/*
* Implement 'meta' mode.
@@ -274,15 +274,19 @@
/* on some systems dirname may modify its arg */
tp = bmake_strdup(tname);
dtp = dirname(tp);
- if (strcmp(dname, dtp) == 0)
- snprintf(mname, mnamelen, "%s.meta", tname);
- else {
+ if (strcmp(dname, dtp) == 0) {
+ if (snprintf(mname, mnamelen, "%s.meta", tname) >= (int)mnamelen)
+ mname[mnamelen - 1] = '\0';
+ } else {
+ int x;
+
ldname = strlen(dname);
if (strncmp(dname, dtp, ldname) == 0 && dtp[ldname] == '/')
- snprintf(mname, mnamelen, "%s/%s.meta", dname, &tname[ldname+1]);
+ x = snprintf(mname, mnamelen, "%s/%s.meta", dname, &tname[ldname+1]);
else
- snprintf(mname, mnamelen, "%s/%s.meta", dname, tname);
-
+ x = snprintf(mname, mnamelen, "%s/%s.meta", dname, tname);
+ if (x >= (int)mnamelen)
+ mname[mnamelen - 1] = '\0';
/*
* Replace path separators in the file name after the
* current object directory path.
@@ -762,7 +766,9 @@
}
if (gn != NULL)
Global_Set(".ERROR_TARGET", GNode_Path(gn));
- getcwd(cwd, sizeof cwd);
+ if (getcwd(cwd, sizeof cwd) == NULL)
+ Punt("Cannot get cwd: %s", strerror(errno));
+
Global_Set(".ERROR_CWD", cwd);
if (pbm->meta_fname[0] != '\0') {
Global_Set(".ERROR_META_FILE", pbm->meta_fname);
@@ -1436,18 +1442,18 @@
continue; /* no point */
/* Check vs latestdir */
- snprintf(fname1, sizeof fname1, "%s/%s", latestdir, p);
- sdirs[sdx++] = fname1;
+ if (snprintf(fname1, sizeof fname1, "%s/%s", latestdir, p) < (int)(sizeof fname1))
+ sdirs[sdx++] = fname1;
if (strcmp(latestdir, lcwd) != 0) {
/* Check vs lcwd */
- snprintf(fname2, sizeof fname2, "%s/%s", lcwd, p);
- sdirs[sdx++] = fname2;
+ if (snprintf(fname2, sizeof fname2, "%s/%s", lcwd, p) < (int)(sizeof fname2))
+ sdirs[sdx++] = fname2;
}
if (strcmp(lcwd, cwd) != 0) {
/* Check vs cwd */
- snprintf(fname3, sizeof fname3, "%s/%s", cwd, p);
- sdirs[sdx++] = fname3;
+ if (snprintf(fname3, sizeof fname3, "%s/%s", cwd, p) < (int)(sizeof fname3))
+ sdirs[sdx++] = fname3;
}
}
sdirs[sdx++] = NULL;
Home |
Main Index |
Thread Index |
Old Index