1 From f5de3401b974ce103ffd93af8f9d43505a04aaf9 Mon Sep 17 00:00:00 2001
2 From: Damian Kurek <starfire24680@gmail.com>
3 Date: Thu, 7 Jul 2022 03:39:16 +0000
4 Subject: [PATCH] Fix NULL dereference when duplicating string argument
6 poptGetArg can return NULL if there are no additional arguments, which
7 makes strdup dereference NULL on strlen
10 1 file changed, 4 insertions(+), 2 deletions(-)
12 diff --git a/gptcl.cc b/gptcl.cc
13 index 0d578eb..ab95239 100644
16 @@ -155,10 +155,11 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
19 // Assume first non-option argument is the device filename....
20 - device = strdup((char*) poptGetArg(poptCon));
21 - poptResetContext(poptCon);
22 + device = (char*) poptGetArg(poptCon);
25 + device = strdup(device);
26 + poptResetContext(poptCon);
27 JustLooking(); // reset as necessary
28 BeQuiet(); // Tell called functions to be less verbose & interactive
29 if (LoadPartitions((string) device)) {
30 @@ -498,6 +499,7 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
31 cerr << "Error encountered; not saving changes.\n";
35 } // if (device != NULL)
36 poptFreeContext(poptCon);