diff options
author | Damian Kurek <starfire24680@gmail.com> | 2022-07-07 03:39:16 +0000 |
---|---|---|
committer | Damian Kurek <starfire24680@gmail.com> | 2022-07-07 04:04:57 +0000 |
commit | f5de3401b974ce103ffd93af8f9d43505a04aaf9 (patch) | |
tree | cc9457ee0167c1d0fbbf8086745f5f391208b0a5 | |
parent | 913f7b48647bdbd23fdc4abccf2168b061273aa4 (diff) | |
download | gptfdisk-f5de3401b974ce103ffd93af8f9d43505a04aaf9.tar.gz |
Fix NULL dereference when duplicating string argument
poptGetArg can return NULL if there are no additional arguments, which
makes strdup dereference NULL on strlen
-rw-r--r-- | gptcl.cc | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -155,10 +155,11 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) { } // while // Assume first non-option argument is the device filename.... - device = strdup((char*) poptGetArg(poptCon)); - poptResetContext(poptCon); + device = (char*) poptGetArg(poptCon); if (device != NULL) { + device = strdup(device); + poptResetContext(poptCon); JustLooking(); // reset as necessary BeQuiet(); // Tell called functions to be less verbose & interactive if (LoadPartitions((string) device)) { @@ -498,6 +499,7 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) { cerr << "Error encountered; not saving changes.\n"; retval = 4; } // if + free(device); } // if (device != NULL) poptFreeContext(poptCon); return retval; |