From 014f00265263a4e24407605fe5fff0a6fb62e304 Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Jul 20 2015 18:29:14 +0000 Subject: Use poptGetOptArg() correctly Only call poptGetOptArg() once per option, since it appears to be returning NULL if we call it more than once per option. --- diff --git a/src/dogtag.c b/src/dogtag.c index af94669..c3b12ae 100644 --- a/src/dogtag.c +++ b/src/dogtag.c @@ -120,6 +120,7 @@ main(int argc, const char **argv) const char *csr = NULL, *serial = NULL, *template = NULL; const char *uid = NULL, *pwd = NULL, *pwdfile = NULL; const char *udn = NULL, *pin = NULL, *pinfile = NULL; + char *poptarg; struct { char *name; char *value; @@ -220,7 +221,8 @@ main(int argc, const char **argv) serial = util_dec_from_hex(poptGetOptArg(pctx)); break; case 'O': - if (strchr(poptGetOptArg(pctx), '=') == NULL) { + poptarg = poptGetOptArg(pctx); + if (strchr(poptarg, '=') == NULL) { printf(_("Profile params (-O) must be in the form of param=value.\n")); poptPrintUsage(pctx, stdout, 0); return CM_SUBMIT_STATUS_UNCONFIGURED; @@ -231,7 +233,7 @@ main(int argc, const char **argv) printf(_("Out of memory.\n")); return CM_SUBMIT_STATUS_UNCONFIGURED; } - p = strdup(poptGetOptArg(pctx)); + p = strdup(poptarg); if (p == NULL) { printf(_("Out of memory.\n")); return CM_SUBMIT_STATUS_UNCONFIGURED; @@ -242,7 +244,8 @@ main(int argc, const char **argv) aoptions[num_aoptions - 1].value = p + i + 1; break; case 'o': - if (strchr(poptGetOptArg(pctx), '=') == NULL) { + poptarg = poptGetOptArg(pctx); + if (strchr(poptarg, '=') == NULL) { printf(_("Submit params (-o) must be in the form of param=value.\n")); poptPrintUsage(pctx, stdout, 0); return CM_SUBMIT_STATUS_UNCONFIGURED; @@ -253,7 +256,7 @@ main(int argc, const char **argv) printf(_("Out of memory.\n")); return CM_SUBMIT_STATUS_UNCONFIGURED; } - p = strdup(poptGetOptArg(pctx)); + p = strdup(poptarg); if (p == NULL) { printf(_("Out of memory.\n")); return CM_SUBMIT_STATUS_UNCONFIGURED; diff --git a/src/scep.c b/src/scep.c index 658cb15..c5db5dc 100644 --- a/src/scep.c +++ b/src/scep.c @@ -323,8 +323,8 @@ main(int argc, const char **argv) racert = cm_submit_u_from_file(poptGetOptArg(pctx)); break; case 'R': - cacert = cm_submit_u_from_file(poptGetOptArg(pctx)); cainfo = poptGetOptArg(pctx); + cacert = cm_submit_u_from_file(cainfo); break; case 'I': certs = cm_submit_u_from_file(poptGetOptArg(pctx));