Skip to contentSkip to conversation

master - cmdline: fix missing NULL at end of array of args

PATCH Zdenek Kabelac 1 participant 1 message Jun 26, 2017

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=52f4042f1a3b21054041298d7e50ded7ae366f44
Commit:        52f4042f1a3b21054041298d7e50ded7ae366f44
Parent:        4e4067dd94f52f90f0aaae30c522102ccbaa2826
Author:        Zdenek Kabelac <[email protected]>
AuthorDate:    Mon Jun 26 20:03:05 2017 +0200
Committer:     Zdenek Kabelac <[email protected]>
CommitterDate: Mon Jun 26 20:07:21 2017 +0200

cmdline: fix missing NULL at end of array of args

lvm_run needs to place NULL as the last element into argv[]. Otherwise we get:

Conditional jump or move depends on uninitialised value(s)
_command_required_pos_matches (lvmcmdline.c:1443) _find_command (lvmcmdline.c:1610) lvm_run_command (lvmcmdline.c:2770)
lvm2_run (lvmcmdlib.c:91)

---
 WHATS_NEW          |    1 +
 test/api/test.c    |    3 +++
 tools/lvmcmdline.c |    3 +++
 3 files changed, 7 insertions(+), 0 deletions(-)
WHATS_NEW +1 -0
index 6a60f0b..2872dbb 100644
@@ -1,5 +1,6 @@
 Version 2.02.172 - 
 ===============================
+  Add missing NULL to argv array when spliting cmdline arguments.
   Add display_percent helper function for printing percent values.
   Lvconvert --repair handles failing raid legs (present but marked 'D'ead).
   Do not lvdisplay --maps unset settings of cache pool.
test/api/test.c +3 -0
index 1413030..a79afc1 100644
@@ -51,6 +51,9 @@ static int lvm_split(char *str, int *argc, char **argv, int max)
 			break;
 	}
 
+	if (*argc < max)
+		argv[*argc] = NULL;
+
 	return *argc;
 }
 
tools/lvmcmdline.c +3 -0
index 9e77d48..0aca37a 100644
@@ -3045,6 +3045,9 @@ int lvm_split(char *str, int *argc, char **argv, int max)
 			break;
 	}
 
+	if (*argc < max)
+		argv[*argc] = NULL;
+
 	return *argc;
 }