Module Name: src Committed By: kamil Date: Sat Feb 22 10:05:12 UTC 2020
Modified Files: src/lib/libc/stdlib: _env.c Log Message: 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 *' To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/lib/libc/stdlib/_env.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libc/stdlib/_env.c diff -u src/lib/libc/stdlib/_env.c:1.9 src/lib/libc/stdlib/_env.c:1.10 --- src/lib/libc/stdlib/_env.c:1.9 Tue Jan 20 18:31:25 2015 +++ src/lib/libc/stdlib/_env.c Sat Feb 22 10:05:12 2020 @@ -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_ /* 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. */