Skip to contentSkip to conversation

master - dmsetup: validate strtol reading

PATCH Zdenek Kabelac 1 participant 1 message Aug 25, 2017

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=962874bfe2a3c3511e42fe29f0f013c780f65e63
Commit:        962874bfe2a3c3511e42fe29f0f013c780f65e63
Parent:        47b7d4a7336fa60eb25ad15b2fc3fcb5b96ce1c2
Author:        Zdenek Kabelac <[email protected]>
AuthorDate:    Fri Aug 25 11:48:17 2017 +0200
Committer:     Zdenek Kabelac <[email protected]>
CommitterDate: Fri Aug 25 14:20:59 2017 +0200

dmsetup: validate strtol reading

Better validation for --mode option.

---
 tools/dmsetup.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
tools/dmsetup.c +7 -1
index 341522c..d9532fb 100644
@@ -7054,7 +7054,13 @@ static int _process_switches(int *argcp, char ***argvp, const char *dev_dir)
 		if (c == 'M' || ind == MODE_ARG) {
 			_switches[MODE_ARG]++;
 			/* FIXME Accept modes as per chmod */
-			_int_args[MODE_ARG] = (int) strtol(optarg, NULL, 8);
+			errno = 0;
+			_int_args[MODE_ARG] = (int) strtol(optarg, &s, 8);
+			if (errno || !s || *s || !_int_args[MODE_ARG]) {
+				log_error("Invalid argument for --mode: %s. %s",
+					  optarg, errno ? strerror(errno) : "");
+				return 0;
+			}
 		}
 		if (ind == DEFERRED_ARG)
 			_switches[DEFERRED_ARG]++;