summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDouglas Christman <DouglasChristman@gmail.com>2018-02-27 20:35:58 -0500
committerDouglas Christman <DouglasChristman@gmail.com>2018-03-01 21:50:38 +0800
commit6c1a6df3752f9df0780dee29b829dd91c0802f34 (patch)
tree3a8c03f671834a7760f868e65b1a79515ae272f9 /src
parent3a6a6889e1b2cc1495a5969e98d1b4d629730f13 (diff)
downloadsystemd-6c1a6df3752f9df0780dee29b829dd91c0802f34.tar.gz
systemd-6c1a6df3752f9df0780dee29b829dd91c0802f34.tar.bz2
systemd-6c1a6df3752f9df0780dee29b829dd91c0802f34.zip
udevadm: prevent segfault in blkid builtin when offset not specified
"--offset" takes an optional argument; if none is specified, stroull() will attempt to parse a NULL pointer. For example: $ udevadm test-builtin 'blkid --offset' /sys/dev/block/8:1 Update "--offset" to require an argument; also verify that the offset is not negative.
Diffstat (limited to 'src')
-rw-r--r--src/udev/udev-builtin-blkid.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/udev/udev-builtin-blkid.c b/src/udev/udev-builtin-blkid.c
index 6ff244e96c..eeed803f57 100644
--- a/src/udev/udev-builtin-blkid.c
+++ b/src/udev/udev-builtin-blkid.c
@@ -35,6 +35,7 @@
#include "efivars.h"
#include "fd-util.h"
#include "gpt.h"
+#include "parse-util.h"
#include "string-util.h"
#include "udev.h"
@@ -236,7 +237,7 @@ static int builtin_blkid(struct udev_device *dev, int argc, char *argv[], bool t
bool is_gpt = false;
static const struct option options[] = {
- { "offset", optional_argument, NULL, 'o' },
+ { "offset", required_argument, NULL, 'o' },
{ "noraid", no_argument, NULL, 'R' },
{}
};
@@ -244,13 +245,19 @@ static int builtin_blkid(struct udev_device *dev, int argc, char *argv[], bool t
for (;;) {
int option;
- option = getopt_long(argc, argv, "oR", options, NULL);
+ option = getopt_long(argc, argv, "o:R", options, NULL);
if (option == -1)
break;
switch (option) {
case 'o':
- offset = strtoull(optarg, NULL, 0);
+ err = safe_atoi64(optarg, &offset);
+ if (err < 0)
+ goto out;
+ if (offset < 0) {
+ err = -ERANGE;
+ goto out;
+ }
break;
case 'R':
noraid = true;