blob: c7fa965ec92cc554ea8b3a2679ab7d16ea333caa [file] [log] [blame]
Andrew Geisslerc5535c92023-01-27 16:10:19 -06001From f5de3401b974ce103ffd93af8f9d43505a04aaf9 Mon Sep 17 00:00:00 2001
2From: Damian Kurek <starfire24680@gmail.com>
3Date: Thu, 7 Jul 2022 03:39:16 +0000
4Subject: [PATCH] Fix NULL dereference when duplicating string argument
5
6poptGetArg can return NULL if there are no additional arguments, which
7makes strdup dereference NULL on strlen
8
9Upstream-Status: Submitted [https://sourceforge.net/p/gptfdisk/code/merge-requests/28/]
10
11---
12 gptcl.cc | 6 ++++--
13 1 file changed, 4 insertions(+), 2 deletions(-)
14
15diff --git a/gptcl.cc b/gptcl.cc
16index 0d578eb..ab95239 100644
17--- a/gptcl.cc
18+++ b/gptcl.cc
19@@ -155,10 +155,11 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
20 } // while
21
22 // Assume first non-option argument is the device filename....
23- device = strdup((char*) poptGetArg(poptCon));
24- poptResetContext(poptCon);
25+ device = (char*) poptGetArg(poptCon);
26
27 if (device != NULL) {
28+ device = strdup(device);
29+ poptResetContext(poptCon);
30 JustLooking(); // reset as necessary
31 BeQuiet(); // Tell called functions to be less verbose & interactive
32 if (LoadPartitions((string) device)) {
33@@ -498,6 +499,7 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
34 cerr << "Error encountered; not saving changes.\n";
35 retval = 4;
36 } // if
37+ free(device);
38 } // if (device != NULL)
39 poptFreeContext(poptCon);
40 return retval;
41