[PATCH] Fix NULL pointer access in getopt_internal()
Sebastian Huber
sebastian.huber@embedded-brains.de
Tue Nov 12 09:52:00 GMT 2013
The getopt() family functions assume a NULL terminated argument vector
(argv). In case the ordering is PERMUTE, then the option processing
stops if argv[data->optind] == NULL. Do this also for the alternative
orderings to avoid later NULL pointer read access.
newlib/ChangeLog
2013-11-12 Sebastian Huber <sebastian.huber@embedded-brains.de>
* libc/libc/stdlib/getopt.c (getopt_internal): Fix NULL pointer
access.
---
newlib/libc/stdlib/getopt.c | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/newlib/libc/stdlib/getopt.c b/newlib/libc/stdlib/getopt.c
index 2bea694..bb3a070 100644
--- a/newlib/libc/stdlib/getopt.c
+++ b/newlib/libc/stdlib/getopt.c
@@ -262,9 +262,13 @@ getopt_internal (int argc, char *const argv[], const char *shortopts,
data->optarg = argv[data->optind++];
return (data->optopt = 1);
}
+ else if (argv[data->optind] == 0)
+ {
+ return EOF;
+ }
break;
case REQUIRE_ORDER:
- if (!is_option (argv[data->optind], only))
+ if (argv[data->optind] == 0 || !is_option (argv[data->optind], only))
return EOF;
break;
}
--
1.7.7
More information about the Newlib
mailing list