diff options
author | Mikulas Patocka <mpatocka@redhat.com> | 2012-03-28 13:41:26 -0400 |
---|---|---|
committer | Alasdair G Kergon <agk@redhat.com> | 2012-03-28 13:41:26 -0400 |
commit | 31998ef19385c944600d9a981b96252f98204bee (patch) | |
tree | ab757b8d6e3d349cf42827354e594687dcf6c5c8 | |
parent | 0447568fc51e0268e201f7086d2450cf986e0411 (diff) |
dm: reject trailing characters in sccanf input
Device mapper uses sscanf to convert arguments to numbers. The problem is that
the way we use it ignores additional unmatched characters in the scanned string.
For example, this `if (sscanf(string, "%d", &number) == 1)' will match a number,
but also it will match number with some garbage appended, like "123abc".
As a result, device mapper accepts garbage after some numbers. For example
the command `dmsetup create vg1-new --table "0 16384 linear 254:1bla 34816bla"'
will pass without an error.
This patch fixes all sscanf uses in device mapper. It appends "%c" with
a pointer to a dummy character variable to every sscanf statement.
The construct `if (sscanf(string, "%d%c", &number, &dummy) == 1)' succeeds
only if string is a null-terminated number (optionally preceded by some
whitespace characters). If there is some character appended after the number,
sscanf matches "%c", writes the character to the dummy variable and returns 2.
We check the return value for 1 and consequently reject numbers with some
garbage appended.
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Acked-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
-rw-r--r-- | drivers/md/dm-crypt.c | 8 | ||||
-rw-r--r-- | drivers/md/dm-delay.c | 9 | ||||
-rw-r--r-- | drivers/md/dm-flakey.c | 3 | ||||
-rw-r--r-- | drivers/md/dm-ioctl.c | 5 | ||||
-rw-r--r-- | drivers/md/dm-linear.c | 3 | ||||
-rw-r--r-- | drivers/md/dm-log.c | 3 | ||||
-rw-r--r-- | drivers/md/dm-mpath.c | 6 | ||||
-rw-r--r-- | drivers/md/dm-queue-length.c | 3 | ||||
-rw-r--r-- | drivers/md/dm-raid1.c | 12 | ||||
-rw-r--r-- | drivers/md/dm-round-robin.c | 3 | ||||
-rw-r--r-- | drivers/md/dm-service-time.c | 5 | ||||
-rw-r--r-- | drivers/md/dm-stripe.c | 3 | ||||
-rw-r--r-- | drivers/md/dm-table.c | 6 |
13 files changed, 44 insertions, 25 deletions
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index 87de0d6b49f2..3f06df59fd82 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c | |||
@@ -1415,6 +1415,7 @@ static int crypt_ctr_cipher(struct dm_target *ti, | |||
1415 | char *tmp, *cipher, *chainmode, *ivmode, *ivopts, *keycount; | 1415 | char *tmp, *cipher, *chainmode, *ivmode, *ivopts, *keycount; |
1416 | char *cipher_api = NULL; | 1416 | char *cipher_api = NULL; |
1417 | int cpu, ret = -EINVAL; | 1417 | int cpu, ret = -EINVAL; |
1418 | char dummy; | ||
1418 | 1419 | ||
1419 | /* Convert to crypto api definition? */ | 1420 | /* Convert to crypto api definition? */ |
1420 | if (strchr(cipher_in, '(')) { | 1421 | if (strchr(cipher_in, '(')) { |
@@ -1436,7 +1437,7 @@ static int crypt_ctr_cipher(struct dm_target *ti, | |||
1436 | 1437 | ||
1437 | if (!keycount) | 1438 | if (!keycount) |
1438 | cc->tfms_count = 1; | 1439 | cc->tfms_count = 1; |
1439 | else if (sscanf(keycount, "%u", &cc->tfms_count) != 1 || | 1440 | else if (sscanf(keycount, "%u%c", &cc->tfms_count, &dummy) != 1 || |
1440 | !is_power_of_2(cc->tfms_count)) { | 1441 | !is_power_of_2(cc->tfms_count)) { |
1441 | ti->error = "Bad cipher key count specification"; | 1442 | ti->error = "Bad cipher key count specification"; |
1442 | return -EINVAL; | 1443 | return -EINVAL; |
@@ -1581,6 +1582,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) | |||
1581 | int ret; | 1582 | int ret; |
1582 | struct dm_arg_set as; | 1583 | struct dm_arg_set as; |
1583 | const char *opt_string; | 1584 | const char *opt_string; |
1585 | char dummy; | ||
1584 | 1586 | ||
1585 | static struct dm_arg _args[] = { | 1587 | static struct dm_arg _args[] = { |
1586 | {0, 1, "Invalid number of feature args"}, | 1588 | {0, 1, "Invalid number of feature args"}, |
@@ -1638,7 +1640,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) | |||
1638 | } | 1640 | } |
1639 | 1641 | ||
1640 | ret = -EINVAL; | 1642 | ret = -EINVAL; |
1641 | if (sscanf(argv[2], "%llu", &tmpll) != 1) { | 1643 | if (sscanf(argv[2], "%llu%c", &tmpll, &dummy) != 1) { |
1642 | ti->error = "Invalid iv_offset sector"; | 1644 | ti->error = "Invalid iv_offset sector"; |
1643 | goto bad; | 1645 | goto bad; |
1644 | } | 1646 | } |
@@ -1649,7 +1651,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) | |||
1649 | goto bad; | 1651 | goto bad; |
1650 | } | 1652 | } |
1651 | 1653 | ||
1652 | if (sscanf(argv[4], "%llu", &tmpll) != 1) { | 1654 | if (sscanf(argv[4], "%llu%c", &tmpll, &dummy) != 1) { |
1653 | ti->error = "Invalid device sector"; | 1655 | ti->error = "Invalid device sector"; |
1654 | goto bad; | 1656 | goto bad; |
1655 | } | 1657 | } |
diff --git a/drivers/md/dm-delay.c b/drivers/md/dm-delay.c index f18375dcedd9..2dc22dddb2ae 100644 --- a/drivers/md/dm-delay.c +++ b/drivers/md/dm-delay.c | |||
@@ -131,6 +131,7 @@ static int delay_ctr(struct dm_target *ti, unsigned int argc, char **argv) | |||
131 | { | 131 | { |
132 | struct delay_c *dc; | 132 | struct delay_c *dc; |
133 | unsigned long long tmpll; | 133 | unsigned long long tmpll; |
134 | char dummy; | ||
134 | 135 | ||
135 | if (argc != 3 && argc != 6) { | 136 | if (argc != 3 && argc != 6) { |
136 | ti->error = "requires exactly 3 or 6 arguments"; | 137 | ti->error = "requires exactly 3 or 6 arguments"; |
@@ -145,13 +146,13 @@ static int delay_ctr(struct dm_target *ti, unsigned int argc, char **argv) | |||
145 | 146 | ||
146 | dc->reads = dc->writes = 0; | 147 | dc->reads = dc->writes = 0; |
147 | 148 | ||
148 | if (sscanf(argv[1], "%llu", &tmpll) != 1) { | 149 | if (sscanf(argv[1], "%llu%c", &tmpll, &dummy) != 1) { |
149 | ti->error = "Invalid device sector"; | 150 | ti->error = "Invalid device sector"; |
150 | goto bad; | 151 | goto bad; |
151 | } | 152 | } |
152 | dc->start_read = tmpll; | 153 | dc->start_read = tmpll; |
153 | 154 | ||
154 | if (sscanf(argv[2], "%u", &dc->read_delay) != 1) { | 155 | if (sscanf(argv[2], "%u%c", &dc->read_delay, &dummy) != 1) { |
155 | ti->error = "Invalid delay"; | 156 | ti->error = "Invalid delay"; |
156 | goto bad; | 157 | goto bad; |
157 | } | 158 | } |
@@ -166,13 +167,13 @@ static int delay_ctr(struct dm_target *ti, unsigned int argc, char **argv) | |||
166 | if (argc == 3) | 167 | if (argc == 3) |
167 | goto out; | 168 | goto out; |
168 | 169 | ||
169 | if (sscanf(argv[4], "%llu", &tmpll) != 1) { | 170 | if (sscanf(argv[4], "%llu%c", &tmpll, &dummy) != 1) { |
170 | ti->error = "Invalid write device sector"; | 171 | ti->error = "Invalid write device sector"; |
171 | goto bad_dev_read; | 172 | goto bad_dev_read; |
172 | } | 173 | } |
173 | dc->start_write = tmpll; | 174 | dc->start_write = tmpll; |
174 | 175 | ||
175 | if (sscanf(argv[5], "%u", &dc->write_delay) != 1) { | 176 | if (sscanf(argv[5], "%u%c", &dc->write_delay, &dummy) != 1) { |
176 | ti->error = "Invalid write delay"; | 177 | ti->error = "Invalid write delay"; |
177 | goto bad_dev_read; | 178 | goto bad_dev_read; |
178 | } | 179 | } |
diff --git a/drivers/md/dm-flakey.c b/drivers/md/dm-flakey.c index b280c433e4a0..ac49c01f1a44 100644 --- a/drivers/md/dm-flakey.c +++ b/drivers/md/dm-flakey.c | |||
@@ -160,6 +160,7 @@ static int flakey_ctr(struct dm_target *ti, unsigned int argc, char **argv) | |||
160 | unsigned long long tmpll; | 160 | unsigned long long tmpll; |
161 | struct dm_arg_set as; | 161 | struct dm_arg_set as; |
162 | const char *devname; | 162 | const char *devname; |
163 | char dummy; | ||
163 | 164 | ||
164 | as.argc = argc; | 165 | as.argc = argc; |
165 | as.argv = argv; | 166 | as.argv = argv; |
@@ -178,7 +179,7 @@ static int flakey_ctr(struct dm_target *ti, unsigned int argc, char **argv) | |||
178 | 179 | ||
179 | devname = dm_shift_arg(&as); | 180 | devname = dm_shift_arg(&as); |
180 | 181 | ||
181 | if (sscanf(dm_shift_arg(&as), "%llu", &tmpll) != 1) { | 182 | if (sscanf(dm_shift_arg(&as), "%llu%c", &tmpll, &dummy) != 1) { |
182 | ti->error = "Invalid device sector"; | 183 | ti->error = "Invalid device sector"; |
183 | goto bad; | 184 | goto bad; |
184 | } | 185 | } |
diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c index 1ce84ed0b765..a1a3e6df17b8 100644 --- a/drivers/md/dm-ioctl.c +++ b/drivers/md/dm-ioctl.c | |||
@@ -880,6 +880,7 @@ static int dev_set_geometry(struct dm_ioctl *param, size_t param_size) | |||
880 | struct hd_geometry geometry; | 880 | struct hd_geometry geometry; |
881 | unsigned long indata[4]; | 881 | unsigned long indata[4]; |
882 | char *geostr = (char *) param + param->data_start; | 882 | char *geostr = (char *) param + param->data_start; |
883 | char dummy; | ||
883 | 884 | ||
884 | md = find_device(param); | 885 | md = find_device(param); |
885 | if (!md) | 886 | if (!md) |
@@ -891,8 +892,8 @@ static int dev_set_geometry(struct dm_ioctl *param, size_t param_size) | |||
891 | goto out; | 892 | goto out; |
892 | } | 893 | } |
893 | 894 | ||
894 | x = sscanf(geostr, "%lu %lu %lu %lu", indata, | 895 | x = sscanf(geostr, "%lu %lu %lu %lu%c", indata, |
895 | indata + 1, indata + 2, indata + 3); | 896 | indata + 1, indata + 2, indata + 3, &dummy); |
896 | 897 | ||
897 | if (x != 4) { | 898 | if (x != 4) { |
898 | DMWARN("Unable to interpret geometry settings."); | 899 | DMWARN("Unable to interpret geometry settings."); |
diff --git a/drivers/md/dm-linear.c b/drivers/md/dm-linear.c index 9728839f844a..3639eeab6042 100644 --- a/drivers/md/dm-linear.c +++ b/drivers/md/dm-linear.c | |||
@@ -29,6 +29,7 @@ static int linear_ctr(struct dm_target *ti, unsigned int argc, char **argv) | |||
29 | { | 29 | { |
30 | struct linear_c *lc; | 30 | struct linear_c *lc; |
31 | unsigned long long tmp; | 31 | unsigned long long tmp; |
32 | char dummy; | ||
32 | 33 | ||
33 | if (argc != 2) { | 34 | if (argc != 2) { |
34 | ti->error = "Invalid argument count"; | 35 | ti->error = "Invalid argument count"; |
@@ -41,7 +42,7 @@ static int linear_ctr(struct dm_target *ti, unsigned int argc, char **argv) | |||
41 | return -ENOMEM; | 42 | return -ENOMEM; |
42 | } | 43 | } |
43 | 44 | ||
44 | if (sscanf(argv[1], "%llu", &tmp) != 1) { | 45 | if (sscanf(argv[1], "%llu%c", &tmp, &dummy) != 1) { |
45 | ti->error = "dm-linear: Invalid device sector"; | 46 | ti->error = "dm-linear: Invalid device sector"; |
46 | goto bad; | 47 | goto bad; |
47 | } | 48 | } |
diff --git a/drivers/md/dm-log.c b/drivers/md/dm-log.c index 3b52bb72bd1f..65ebaebf502b 100644 --- a/drivers/md/dm-log.c +++ b/drivers/md/dm-log.c | |||
@@ -369,6 +369,7 @@ static int create_log_context(struct dm_dirty_log *log, struct dm_target *ti, | |||
369 | unsigned int region_count; | 369 | unsigned int region_count; |
370 | size_t bitset_size, buf_size; | 370 | size_t bitset_size, buf_size; |
371 | int r; | 371 | int r; |
372 | char dummy; | ||
372 | 373 | ||
373 | if (argc < 1 || argc > 2) { | 374 | if (argc < 1 || argc > 2) { |
374 | DMWARN("wrong number of arguments to dirty region log"); | 375 | DMWARN("wrong number of arguments to dirty region log"); |
@@ -387,7 +388,7 @@ static int create_log_context(struct dm_dirty_log *log, struct dm_target *ti, | |||
387 | } | 388 | } |
388 | } | 389 | } |
389 | 390 | ||
390 | if (sscanf(argv[0], "%u", ®ion_size) != 1 || | 391 | if (sscanf(argv[0], "%u%c", ®ion_size, &dummy) != 1 || |
391 | !_check_region_size(ti, region_size)) { | 392 | !_check_region_size(ti, region_size)) { |
392 | DMWARN("invalid region size %s", argv[0]); | 393 | DMWARN("invalid region size %s", argv[0]); |
393 | return -EINVAL; | 394 | return -EINVAL; |
diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c index e92a0005eeff..922a3385eead 100644 --- a/drivers/md/dm-mpath.c +++ b/drivers/md/dm-mpath.c | |||
@@ -1070,8 +1070,9 @@ static int switch_pg_num(struct multipath *m, const char *pgstr) | |||
1070 | struct priority_group *pg; | 1070 | struct priority_group *pg; |
1071 | unsigned pgnum; | 1071 | unsigned pgnum; |
1072 | unsigned long flags; | 1072 | unsigned long flags; |
1073 | char dummy; | ||
1073 | 1074 | ||
1074 | if (!pgstr || (sscanf(pgstr, "%u", &pgnum) != 1) || !pgnum || | 1075 | if (!pgstr || (sscanf(pgstr, "%u%c", &pgnum, &dummy) != 1) || !pgnum || |
1075 | (pgnum > m->nr_priority_groups)) { | 1076 | (pgnum > m->nr_priority_groups)) { |
1076 | DMWARN("invalid PG number supplied to switch_pg_num"); | 1077 | DMWARN("invalid PG number supplied to switch_pg_num"); |
1077 | return -EINVAL; | 1078 | return -EINVAL; |
@@ -1101,8 +1102,9 @@ static int bypass_pg_num(struct multipath *m, const char *pgstr, int bypassed) | |||
1101 | { | 1102 | { |
1102 | struct priority_group *pg; | 1103 | struct priority_group *pg; |
1103 | unsigned pgnum; | 1104 | unsigned pgnum; |
1105 | char dummy; | ||
1104 | 1106 | ||
1105 | if (!pgstr || (sscanf(pgstr, "%u", &pgnum) != 1) || !pgnum || | 1107 | if (!pgstr || (sscanf(pgstr, "%u%c", &pgnum, &dummy) != 1) || !pgnum || |
1106 | (pgnum > m->nr_priority_groups)) { | 1108 | (pgnum > m->nr_priority_groups)) { |
1107 | DMWARN("invalid PG number supplied to bypass_pg"); | 1109 | DMWARN("invalid PG number supplied to bypass_pg"); |
1108 | return -EINVAL; | 1110 | return -EINVAL; |
diff --git a/drivers/md/dm-queue-length.c b/drivers/md/dm-queue-length.c index 03a837aa5ce6..3941fae0de9f 100644 --- a/drivers/md/dm-queue-length.c +++ b/drivers/md/dm-queue-length.c | |||
@@ -112,6 +112,7 @@ static int ql_add_path(struct path_selector *ps, struct dm_path *path, | |||
112 | struct selector *s = ps->context; | 112 | struct selector *s = ps->context; |
113 | struct path_info *pi; | 113 | struct path_info *pi; |
114 | unsigned repeat_count = QL_MIN_IO; | 114 | unsigned repeat_count = QL_MIN_IO; |
115 | char dummy; | ||
115 | 116 | ||
116 | /* | 117 | /* |
117 | * Arguments: [<repeat_count>] | 118 | * Arguments: [<repeat_count>] |
@@ -123,7 +124,7 @@ static int ql_add_path(struct path_selector *ps, struct dm_path *path, | |||
123 | return -EINVAL; | 124 | return -EINVAL; |
124 | } | 125 | } |
125 | 126 | ||
126 | if ((argc == 1) && (sscanf(argv[0], "%u", &repeat_count) != 1)) { | 127 | if ((argc == 1) && (sscanf(argv[0], "%u%c", &repeat_count, &dummy) != 1)) { |
127 | *error = "queue-length ps: invalid repeat count"; | 128 | *error = "queue-length ps: invalid repeat count"; |
128 | return -EINVAL; | 129 | return -EINVAL; |
129 | } | 130 | } |
diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c index 9bfd057be686..d039de8322f0 100644 --- a/drivers/md/dm-raid1.c +++ b/drivers/md/dm-raid1.c | |||
@@ -924,8 +924,9 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti, | |||
924 | unsigned int mirror, char **argv) | 924 | unsigned int mirror, char **argv) |
925 | { | 925 | { |
926 | unsigned long long offset; | 926 | unsigned long long offset; |
927 | char dummy; | ||
927 | 928 | ||
928 | if (sscanf(argv[1], "%llu", &offset) != 1) { | 929 | if (sscanf(argv[1], "%llu%c", &offset, &dummy) != 1) { |
929 | ti->error = "Invalid offset"; | 930 | ti->error = "Invalid offset"; |
930 | return -EINVAL; | 931 | return -EINVAL; |
931 | } | 932 | } |
@@ -953,13 +954,14 @@ static struct dm_dirty_log *create_dirty_log(struct dm_target *ti, | |||
953 | { | 954 | { |
954 | unsigned param_count; | 955 | unsigned param_count; |
955 | struct dm_dirty_log *dl; | 956 | struct dm_dirty_log *dl; |
957 | char dummy; | ||
956 | 958 | ||
957 | if (argc < 2) { | 959 | if (argc < 2) { |
958 | ti->error = "Insufficient mirror log arguments"; | 960 | ti->error = "Insufficient mirror log arguments"; |
959 | return NULL; | 961 | return NULL; |
960 | } | 962 | } |
961 | 963 | ||
962 | if (sscanf(argv[1], "%u", ¶m_count) != 1) { | 964 | if (sscanf(argv[1], "%u%c", ¶m_count, &dummy) != 1) { |
963 | ti->error = "Invalid mirror log argument count"; | 965 | ti->error = "Invalid mirror log argument count"; |
964 | return NULL; | 966 | return NULL; |
965 | } | 967 | } |
@@ -986,13 +988,14 @@ static int parse_features(struct mirror_set *ms, unsigned argc, char **argv, | |||
986 | { | 988 | { |
987 | unsigned num_features; | 989 | unsigned num_features; |
988 | struct dm_target *ti = ms->ti; | 990 | struct dm_target *ti = ms->ti; |
991 | char dummy; | ||
989 | 992 | ||
990 | *args_used = 0; | 993 | *args_used = 0; |
991 | 994 | ||
992 | if (!argc) | 995 | if (!argc) |
993 | return 0; | 996 | return 0; |
994 | 997 | ||
995 | if (sscanf(argv[0], "%u", &num_features) != 1) { | 998 | if (sscanf(argv[0], "%u%c", &num_features, &dummy) != 1) { |
996 | ti->error = "Invalid number of features"; | 999 | ti->error = "Invalid number of features"; |
997 | return -EINVAL; | 1000 | return -EINVAL; |
998 | } | 1001 | } |
@@ -1036,6 +1039,7 @@ static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv) | |||
1036 | unsigned int nr_mirrors, m, args_used; | 1039 | unsigned int nr_mirrors, m, args_used; |
1037 | struct mirror_set *ms; | 1040 | struct mirror_set *ms; |
1038 | struct dm_dirty_log *dl; | 1041 | struct dm_dirty_log *dl; |
1042 | char dummy; | ||
1039 | 1043 | ||
1040 | dl = create_dirty_log(ti, argc, argv, &args_used); | 1044 | dl = create_dirty_log(ti, argc, argv, &args_used); |
1041 | if (!dl) | 1045 | if (!dl) |
@@ -1044,7 +1048,7 @@ static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv) | |||
1044 | argv += args_used; | 1048 | argv += args_used; |
1045 | argc -= args_used; | 1049 | argc -= args_used; |
1046 | 1050 | ||
1047 | if (!argc || sscanf(argv[0], "%u", &nr_mirrors) != 1 || | 1051 | if (!argc || sscanf(argv[0], "%u%c", &nr_mirrors, &dummy) != 1 || |
1048 | nr_mirrors < 2 || nr_mirrors > DM_KCOPYD_MAX_REGIONS + 1) { | 1052 | nr_mirrors < 2 || nr_mirrors > DM_KCOPYD_MAX_REGIONS + 1) { |
1049 | ti->error = "Invalid number of mirrors"; | 1053 | ti->error = "Invalid number of mirrors"; |
1050 | dm_dirty_log_destroy(dl); | 1054 | dm_dirty_log_destroy(dl); |
diff --git a/drivers/md/dm-round-robin.c b/drivers/md/dm-round-robin.c index 27f1d423b76c..6ab1192cdd5f 100644 --- a/drivers/md/dm-round-robin.c +++ b/drivers/md/dm-round-robin.c | |||
@@ -114,6 +114,7 @@ static int rr_add_path(struct path_selector *ps, struct dm_path *path, | |||
114 | struct selector *s = (struct selector *) ps->context; | 114 | struct selector *s = (struct selector *) ps->context; |
115 | struct path_info *pi; | 115 | struct path_info *pi; |
116 | unsigned repeat_count = RR_MIN_IO; | 116 | unsigned repeat_count = RR_MIN_IO; |
117 | char dummy; | ||
117 | 118 | ||
118 | if (argc > 1) { | 119 | if (argc > 1) { |
119 | *error = "round-robin ps: incorrect number of arguments"; | 120 | *error = "round-robin ps: incorrect number of arguments"; |
@@ -121,7 +122,7 @@ static int rr_add_path(struct path_selector *ps, struct dm_path *path, | |||
121 | } | 122 | } |
122 | 123 | ||
123 | /* First path argument is number of I/Os before switching path */ | 124 | /* First path argument is number of I/Os before switching path */ |
124 | if ((argc == 1) && (sscanf(argv[0], "%u", &repeat_count) != 1)) { | 125 | if ((argc == 1) && (sscanf(argv[0], "%u%c", &repeat_count, &dummy) != 1)) { |
125 | *error = "round-robin ps: invalid repeat count"; | 126 | *error = "round-robin ps: invalid repeat count"; |
126 | return -EINVAL; | 127 | return -EINVAL; |
127 | } | 128 | } |
diff --git a/drivers/md/dm-service-time.c b/drivers/md/dm-service-time.c index 59883bd78214..9df8f6bd6418 100644 --- a/drivers/md/dm-service-time.c +++ b/drivers/md/dm-service-time.c | |||
@@ -110,6 +110,7 @@ static int st_add_path(struct path_selector *ps, struct dm_path *path, | |||
110 | struct path_info *pi; | 110 | struct path_info *pi; |
111 | unsigned repeat_count = ST_MIN_IO; | 111 | unsigned repeat_count = ST_MIN_IO; |
112 | unsigned relative_throughput = 1; | 112 | unsigned relative_throughput = 1; |
113 | char dummy; | ||
113 | 114 | ||
114 | /* | 115 | /* |
115 | * Arguments: [<repeat_count> [<relative_throughput>]] | 116 | * Arguments: [<repeat_count> [<relative_throughput>]] |
@@ -128,13 +129,13 @@ static int st_add_path(struct path_selector *ps, struct dm_path *path, | |||
128 | return -EINVAL; | 129 | return -EINVAL; |
129 | } | 130 | } |
130 | 131 | ||
131 | if (argc && (sscanf(argv[0], "%u", &repeat_count) != 1)) { | 132 | if (argc && (sscanf(argv[0], "%u%c", &repeat_count, &dummy) != 1)) { |
132 | *error = "service-time ps: invalid repeat count"; | 133 | *error = "service-time ps: invalid repeat count"; |
133 | return -EINVAL; | 134 | return -EINVAL; |
134 | } | 135 | } |
135 | 136 | ||
136 | if ((argc == 2) && | 137 | if ((argc == 2) && |
137 | (sscanf(argv[1], "%u", &relative_throughput) != 1 || | 138 | (sscanf(argv[1], "%u%c", &relative_throughput, &dummy) != 1 || |
138 | relative_throughput > ST_MAX_RELATIVE_THROUGHPUT)) { | 139 | relative_throughput > ST_MAX_RELATIVE_THROUGHPUT)) { |
139 | *error = "service-time ps: invalid relative_throughput value"; | 140 | *error = "service-time ps: invalid relative_throughput value"; |
140 | return -EINVAL; | 141 | return -EINVAL; |
diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c index 3d80cf0c152d..35c94ff24ad5 100644 --- a/drivers/md/dm-stripe.c +++ b/drivers/md/dm-stripe.c | |||
@@ -75,8 +75,9 @@ static int get_stripe(struct dm_target *ti, struct stripe_c *sc, | |||
75 | unsigned int stripe, char **argv) | 75 | unsigned int stripe, char **argv) |
76 | { | 76 | { |
77 | unsigned long long start; | 77 | unsigned long long start; |
78 | char dummy; | ||
78 | 79 | ||
79 | if (sscanf(argv[1], "%llu", &start) != 1) | 80 | if (sscanf(argv[1], "%llu%c", &start, &dummy) != 1) |
80 | return -EINVAL; | 81 | return -EINVAL; |
81 | 82 | ||
82 | if (dm_get_device(ti, argv[0], dm_table_get_mode(ti->table), | 83 | if (dm_get_device(ti, argv[0], dm_table_get_mode(ti->table), |
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index a3d1e18317f4..2e227fbf1622 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c | |||
@@ -463,10 +463,11 @@ int dm_get_device(struct dm_target *ti, const char *path, fmode_t mode, | |||
463 | struct dm_dev_internal *dd; | 463 | struct dm_dev_internal *dd; |
464 | unsigned int major, minor; | 464 | unsigned int major, minor; |
465 | struct dm_table *t = ti->table; | 465 | struct dm_table *t = ti->table; |
466 | char dummy; | ||
466 | 467 | ||
467 | BUG_ON(!t); | 468 | BUG_ON(!t); |
468 | 469 | ||
469 | if (sscanf(path, "%u:%u", &major, &minor) == 2) { | 470 | if (sscanf(path, "%u:%u%c", &major, &minor, &dummy) == 2) { |
470 | /* Extract the major/minor numbers */ | 471 | /* Extract the major/minor numbers */ |
471 | dev = MKDEV(major, minor); | 472 | dev = MKDEV(major, minor); |
472 | if (MAJOR(dev) != major || MINOR(dev) != minor) | 473 | if (MAJOR(dev) != major || MINOR(dev) != minor) |
@@ -841,9 +842,10 @@ static int validate_next_arg(struct dm_arg *arg, struct dm_arg_set *arg_set, | |||
841 | unsigned *value, char **error, unsigned grouped) | 842 | unsigned *value, char **error, unsigned grouped) |
842 | { | 843 | { |
843 | const char *arg_str = dm_shift_arg(arg_set); | 844 | const char *arg_str = dm_shift_arg(arg_set); |
845 | char dummy; | ||
844 | 846 | ||
845 | if (!arg_str || | 847 | if (!arg_str || |
846 | (sscanf(arg_str, "%u", value) != 1) || | 848 | (sscanf(arg_str, "%u%c", value, &dummy) != 1) || |
847 | (*value < arg->min) || | 849 | (*value < arg->min) || |
848 | (*value > arg->max) || | 850 | (*value > arg->max) || |
849 | (grouped && arg_set->argc < *value)) { | 851 | (grouped && arg_set->argc < *value)) { |