You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/09/13 14:44:07 UTC
[incubator-nuttx] branch master updated: libc/unistd: getopt: add
some NULL pointer checks
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 17bfa18 libc/unistd: getopt: add some NULL pointer checks
17bfa18 is described below
commit 17bfa18679b9a9435903c9b0dd2700b3d8408b7e
Author: Juha Niskanen <ju...@haltian.com>
AuthorDate: Mon Sep 13 14:53:50 2021 +0300
libc/unistd: getopt: add some NULL pointer checks
Signed-off-by: Juha Niskanen <ju...@haltian.com>
---
libs/libc/unistd/lib_getopt_common.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/libs/libc/unistd/lib_getopt_common.c b/libs/libc/unistd/lib_getopt_common.c
index cd9e481..c84d9a6 100644
--- a/libs/libc/unistd/lib_getopt_common.c
+++ b/libs/libc/unistd/lib_getopt_common.c
@@ -24,6 +24,7 @@
#include <nuttx/config.h>
+#include <assert.h>
#include <stdbool.h>
#include <string.h>
@@ -514,7 +515,7 @@ int getopt_common(int argc, FAR char * const argv[],
* not think that the first interpretation is standard.
*/
- else if (*(go->go_optptr + 1) != '\0')
+ else if (go->go_optptr == NULL || go->go_optptr[1] != '\0')
{
/* Skip over the unrecognized long option. */
@@ -542,6 +543,8 @@ int getopt_common(int argc, FAR char * const argv[],
* (which could be another single character command).
*/
+ DEBUGASSERT(go->go_optptr != NULL);
+
go->go_optopt = *go->go_optptr;
go->go_optptr = NULL;
go->go_optind++;
@@ -570,6 +573,8 @@ int getopt_common(int argc, FAR char * const argv[],
/* Check if the option appears in 'optstring' */
+ DEBUGASSERT(go->go_optptr != NULL);
+
optchar = strchr(optstring, *go->go_optptr);
if (!optchar)
{