aboutsummaryrefslogtreecommitdiffstats
path: root/main/gptfdisk/0003-Fix-NULL-dereference-when-duplicating-string-argumen.patch
blob: 4354892f30967fc83619dfb42ef8257772dda823 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
From fb181ca613329886f017bbf0129108eafd01fe0f Mon Sep 17 00:00:00 2001
From: Damian Kurek <starfire24680@gmail.com>
Date: Wed, 6 Jul 2022 22:23:58 +0000
Subject: [PATCH 1/1] Fix NULL dereference when duplicating string argument

---
 gptcl.cc | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gptcl.cc b/gptcl.cc
index 0d578eb..ab95239 100644
--- a/gptcl.cc
+++ b/gptcl.cc
@@ -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;
-- 
2.35.1