summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorXavier Chantry <shiningxc@gmail.com>2009-12-05 23:45:34 +0100
committerDan McGee <dan@archlinux.org>2009-12-13 23:21:56 -0600
commitb8b8c78627b2f1791a2b46b0d6c87d7a9b90f376 (patch)
treebc1c7cbf1ce65fbf29a7e42af9d1711c9a12088f /src
parent51f9e5e40a7b4c9a2a4bb61562a07946adc2bb2d (diff)
add some more sanity check for optarg
getopt should already ensure that optarg is not NULL when an argument is required, but just be extra safe and double check it before using optarg. To be honest, I only did that to make clang shut up and eliminate the last warnings it reported. Signed-off-by: Xavier Chantry <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'src')
-rw-r--r--src/pacman/pacman.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 315aceb0..0e80fb22 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -334,6 +334,8 @@ static void setlibpaths(void)
}
}
+#define check_optarg() if(!optarg) { return(1); }
+
/** Parse command-line arguments for each operation.
* @param argc argc
* @param argv argv
@@ -408,12 +410,14 @@ static int parseargs(int argc, char *argv[])
case 0: break;
case OP_NOCONFIRM: config->noconfirm = 1; break;
case OP_CONFIG:
+ check_optarg();
if(config->configfile) {
free(config->configfile);
}
config->configfile = strndup(optarg, PATH_MAX);
break;
case OP_IGNORE:
+ check_optarg();
list = strsplit(optarg, ',');
for(item = list; item; item = alpm_list_next(item)) {
alpm_option_add_ignorepkg((char *)alpm_list_getdata(item));
@@ -445,8 +449,13 @@ static int parseargs(int argc, char *argv[])
break;
case OP_NOPROGRESSBAR: config->noprogressbar = 1; break;
case OP_NOSCRIPTLET: config->flags |= PM_TRANS_FLAG_NOSCRIPTLET; break;
- case OP_ASK: config->noask = 1; config->ask = atoi(optarg); break;
+ case OP_ASK:
+ check_optarg();
+ config->noask = 1;
+ config->ask = atoi(optarg);
+ break;
case OP_CACHEDIR:
+ check_optarg();
if(alpm_option_add_cachedir(optarg) != 0) {
pm_printf(PM_LOG_ERROR, _("problem adding cachedir '%s' (%s)\n"),
optarg, alpm_strerrorlast());
@@ -457,9 +466,11 @@ static int parseargs(int argc, char *argv[])
config->flags |= PM_TRANS_FLAG_ALLDEPS;
break;
case OP_LOGFILE:
+ check_optarg();
config->logfile = strndup(optarg, PATH_MAX);
break;
case OP_IGNOREGROUP:
+ check_optarg();
list = strsplit(optarg, ',');
for(item = list; item; item = alpm_list_next(item)) {
alpm_option_add_ignoregrp((char *)alpm_list_getdata(item));
@@ -471,6 +482,7 @@ static int parseargs(int argc, char *argv[])
config->flags |= PM_TRANS_FLAG_ALLEXPLICIT;
break;
case OP_ARCH:
+ check_optarg();
setarch(optarg);
break;
case 'Q': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_QUERY); break;
@@ -480,6 +492,7 @@ static int parseargs(int argc, char *argv[])
case 'U': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_UPGRADE); break;
case 'V': config->version = 1; break;
case 'b':
+ check_optarg();
config->dbpath = strdup(optarg);
break;
case 'c':
@@ -516,6 +529,7 @@ static int parseargs(int argc, char *argv[])
config->quiet = 1;
break;
case 'r':
+ check_optarg();
config->rootdir = strdup(optarg);
break;
case 's':