Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc/stdlib Avoid NULL pointer arithmetics on environ
details: https://anonhg.NetBSD.org/src/rev/9fddaf87524e
branches: trunk
changeset: 745063:9fddaf87524e
user: kamil <kamil%NetBSD.org@localhost>
date: Sat Feb 22 10:05:12 2020 +0000
description:
Avoid NULL pointer arithmetics on environ
_env.c:260:9, pointer expression with base 0 overflowed to 0
_env.c:260:9, load of null pointer of type 'char *'
diffstat:
lib/libc/stdlib/_env.c | 18 ++++++++++--------
1 files changed, 10 insertions(+), 8 deletions(-)
diffs (40 lines):
diff -r 720273834ddb -r 9fddaf87524e lib/libc/stdlib/_env.c
--- a/lib/libc/stdlib/_env.c Sat Feb 22 09:59:22 2020 +0000
+++ b/lib/libc/stdlib/_env.c Sat Feb 22 10:05:12 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: _env.c,v 1.9 2015/01/20 18:31:25 christos Exp $ */
+/* $NetBSD: _env.c,v 1.10 2020/02/22 10:05:12 kamil Exp $ */
/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: _env.c,v 1.9 2015/01/20 18:31:25 christos Exp $");
+__RCSID("$NetBSD: _env.c,v 1.10 2020/02/22 10:05:12 kamil Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
@@ -257,13 +257,15 @@
/* Search for an existing environment variable of the given name. */
num_entries = 0;
- while (environ[num_entries] != NULL) {
- if (strncmp(environ[num_entries], name, l_name) == 0 &&
- environ[num_entries][l_name] == '=') {
- /* We found a match. */
- return num_entries;
+ if (environ != NULL) {
+ while (environ[num_entries] != NULL) {
+ if (strncmp(environ[num_entries], name, l_name) == 0 &&
+ environ[num_entries][l_name] == '=') {
+ /* We found a match. */
+ return num_entries;
+ }
+ num_entries ++;
}
- num_entries ++;
}
/* No match found, return if we don't want to allocate a new slot. */
Home |
Main Index |
Thread Index |
Old Index