summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib
diff options
context:
space:
mode:
authorkamil <kamil@NetBSD.org>2020-02-22 10:05:12 +0000
committerkamil <kamil@NetBSD.org>2020-02-22 10:05:12 +0000
commit2575fada4aa13c35f88d493d54813f5d1100e135 (patch)
tree9a25f181aa18f410dd13cc384fc34eb0f879d865 /lib/libc/stdlib
parent87cd5c20a71a95e064ffce0519abd19639838369 (diff)
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 (limited to 'lib/libc/stdlib')
-rw-r--r--lib/libc/stdlib/_env.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/libc/stdlib/_env.c b/lib/libc/stdlib/_env.c
index c7f32e46d49..bade54e6b17 100644
--- a/lib/libc/stdlib/_env.c
+++ b/lib/libc/stdlib/_env.c
@@ -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 @@ __getenvslot(const char *name, size_t l_name, bool allocate)
/* 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. */