aboutsummaryrefslogtreecommitdiff
path: root/modules/pam_namespace/argv_parse.c
diff options
context:
space:
mode:
Diffstat (limited to 'modules/pam_namespace/argv_parse.c')
-rw-r--r--modules/pam_namespace/argv_parse.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/modules/pam_namespace/argv_parse.c b/modules/pam_namespace/argv_parse.c
index 40510542..cbae7831 100644
--- a/modules/pam_namespace/argv_parse.c
+++ b/modules/pam_namespace/argv_parse.c
@@ -28,6 +28,9 @@
* Version 1.1, modified 2/27/1999
*/
+#include "config.h"
+
+#include <limits.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
@@ -56,16 +59,21 @@ int argv_parse(const char *in_buf, int *ret_argc, char ***ret_argv)
outcp = buf;
for (cp = in_buf; (ch = *cp); cp++) {
if (state == STATE_WHITESPACE) {
- if (isspace((int) ch))
+ if (isspace((unsigned char)ch))
continue;
/* Not whitespace, so start a new token */
state = STATE_TOKEN;
if (argc >= max_argc) {
+ if (max_argc >= INT_MAX - 3) {
+ free(argv);
+ free(buf);
+ return -1;
+ }
max_argc += 3;
new_argv = realloc(argv,
(max_argc+1)*sizeof(char *));
if (!new_argv) {
- if (argv) free(argv);
+ free(argv);
free(buf);
return -1;
}
@@ -81,7 +89,7 @@ int argv_parse(const char *in_buf, int *ret_argc, char ***ret_argv)
continue;
}
/* Must be processing characters in a word */
- if (isspace((int) ch)) {
+ if (isspace((unsigned char)ch)) {
/*
* Terminate the current word and start
* looking for the beginning of the next word.
@@ -131,8 +139,7 @@ int argv_parse(const char *in_buf, int *ret_argc, char ***ret_argv)
void argv_free(char **argv)
{
if (argv) {
- if (*argv)
- free(*argv);
+ free(*argv);
free(argv);
}
}