git: a8178eb7264b - main - sysutils/gdisk: fix memory corruption while using sgdisk command

From: Baptiste Daroussin <bapt_at_FreeBSD.org>
Date: Tue, 22 Nov 2022 10:42:56 UTC
The branch main has been updated by bapt:

URL: https://cgit.FreeBSD.org/ports/commit/?id=a8178eb7264b6be494206d37141bd67827883488

commit a8178eb7264b6be494206d37141bd67827883488
Author:     Baptiste Daroussin <bapt@FreeBSD.org>
AuthorDate: 2022-11-22 10:08:49 +0000
Commit:     Baptiste Daroussin <bapt@FreeBSD.org>
CommitDate: 2022-11-22 10:10:42 +0000

    sysutils/gdisk: fix memory corruption while using sgdisk command
    
    while parsing arguments, the device (last argument) variable is reset
    before being used.
---
 sysutils/gdisk/Makefile             |  2 +-
 sysutils/gdisk/files/patch-gptcl.cc | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/sysutils/gdisk/Makefile b/sysutils/gdisk/Makefile
index e3e3a34d3a94..52443cd3ee63 100644
--- a/sysutils/gdisk/Makefile
+++ b/sysutils/gdisk/Makefile
@@ -1,6 +1,6 @@
 PORTNAME=	gdisk
 PORTVERSION=	1.0.9
-PORTREVISION=	1
+PORTREVISION=	2
 CATEGORIES=	sysutils
 MASTER_SITES=	SF/gptfdisk/gptfdisk/${PORTVERSION}
 DISTNAME=	gptfdisk-${PORTVERSION}
diff --git a/sysutils/gdisk/files/patch-gptcl.cc b/sysutils/gdisk/files/patch-gptcl.cc
new file mode 100644
index 000000000000..19e73564d9d0
--- /dev/null
+++ b/sysutils/gdisk/files/patch-gptcl.cc
@@ -0,0 +1,33 @@
+--- gptcl.cc.orig	2022-11-22 09:31:13 UTC
++++ gptcl.cc
+@@ -71,7 +71,7 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
+    uint64_t low, high, startSector, endSector, sSize, mainTableLBA;
+    uint64_t temp; // temporary variable; free to use in any case
+    char *device;
+-   string cmd, typeGUID, name;
++   string cmd, typeGUID, name, devstr;
+    PartType typeHelper;
+ 
+    struct poptOption theOptions[] =
+@@ -156,9 +156,11 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
+ 
+    // Assume first non-option argument is the device filename....
+    device = (char*) poptGetArg(poptCon);
++   if (device != NULL)
++        devstr = device;
+    poptResetContext(poptCon);
+ 
+-   if (device != NULL) {
++   if (devstr.empty()) {
+       JustLooking(); // reset as necessary
+       BeQuiet(); // Tell called functions to be less verbose & interactive
+       if (LoadPartitions(devstr)) {
+@@ -498,7 +500,7 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
+          cerr << "Error encountered; not saving changes.\n";
+          retval = 4;
+       } // if
+-   } // if (device != NULL)
++   } // if (devstr empty)
+    poptFreeContext(poptCon);
+    return retval;
+ } // GPTDataCL::DoOptions()