Return error code for failure input for sscanf in parse_cblock_range()
PATCH 1/1 Return error code for failure input for sscanf in parse_cblock_range()
Smatch reported following:
'''drivers/md/dm-cache-target.c:3204 parse_cblock_range() warn: sscanf doesn't return error codes drivers/md/dm-cache-target.c:3217 parse_cblock_range() warn: sscanf doesn't return error codes '''
Since, the only negative value that is returned by sscanf is -1. Returning -ENVAL when sscanf returns -1.
--- drivers/md/dm-cache-target.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/md/dm-cache-target.c +4 -4
@@ -3200,8 +3200,8 @@ static int parse_cblock_range(struct cache *cache, const char *str,* Try and parse form (ii) first. */ r =sscanf (str,"%llu-%llu%c" , &b, &e, &dummy); -if (r <0 ) -return r; +if (r ==-1 ) +return -EINVAL ;if (r ==2 ) { result->begin =to_cblock (b);
@@ -3213,8 +3213,8 @@ static int parse_cblock_range(struct cache *cache, const char *str,* That didn't work, try form (i). */ r =sscanf (str,"%llu%c" , &b, &dummy); -if (r <0 ) -return r; +if (r ==-1 ) +return -EINVAL ;if (r ==1 ) { result->begin =to_cblock (b);
Signature · 1 line
2.43.0
Quoted 31 lines · Dipendra Khadka
Smatch reported following:
'''drivers/md/dm-cache-target.c:3204parse_cblock_range()warn: sscanf doesn't return error codesdrivers/md/dm-cache-target.c:3217parse_cblock_range()warn: sscanf doesn't return error codes '''Since, the only negative value that is returned by sscanf is -1. Returning
-ENVALwhen sscanf returns -1.Signed-off-by Dipendra Khadka <[email protected]>--- drivers/md/dm-cache-target.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/md/dm-cache-target.c +2
-2@@ -3200,8 +3200,8 @@ static int parse_cblock_range(struct cache *cache, const char *str,* Try and parse form (ii) first. */ r =sscanf (str,"%llu-%llu%c" , &b, &e, &dummy); -if (r <0 ) -return r; +if (r ==-1 ) +return -EINVAL ;if (r ==2 ) { result->begin =to_cblock (b);
drivers/md/dm-cache-target.c static int parse_cblock_range(struct cache *cache, const char *str, · line 3220
Quoted 10 lines
drivers/md/dm-cache-target.c +2
-2@@ -3213,8 +3213,8 @@ static int parse_cblock_range(struct cache *cache, const char *str,* That didn't work, try form (i). */ r =sscanf (str,"%llu%c" , &b, &dummy); -if (r <0 ) -return r; +if (r ==-1 ) +return -EINVAL ;if (r ==1 ) { result->begin =to_cblock (b);
Could you please clarify how to reproduce unexpected results? From what I observe, the kernel's sscanf doesn't return -1 on an empty input. Even if a negative value other than -EINVAL is returned, it is handled by the callers.
Hank
Quoted 4 lines
--
2.43.0
Mikulas Patocka
maintainerQuoted 49 lines · Ming-Hung Tsai
Quoted 31 lines · Dipendra Khadka
Smatch reported following:
'''drivers/md/dm-cache-target.c:3204parse_cblock_range()warn: sscanf doesn't return error codesdrivers/md/dm-cache-target.c:3217parse_cblock_range()warn: sscanf doesn't return error codes '''Since, the only negative value that is returned by sscanf is -1. Returning
-ENVALwhen sscanf returns -1.Signed-off-by Dipendra Khadka <[email protected]>--- drivers/md/dm-cache-target.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/md/dm-cache-target.c +2
-2@@ -3200,8 +3200,8 @@ static int parse_cblock_range(struct cache *cache, const char *str,* Try and parse form (ii) first. */ r =sscanf (str,"%llu-%llu%c" , &b, &e, &dummy); -if (r <0 ) -return r; +if (r ==-1 ) +return -EINVAL ;if (r ==2 ) { result->begin =to_cblock (b);drivers/md/dm-cache-target.c static int parse_cblock_range(struct cache *cache, const char *str, · line 3220
Quoted 10 lines
drivers/md/dm-cache-target.c +2
-2@@ -3213,8 +3213,8 @@ static int parse_cblock_range(struct cache *cache, const char *str,* That didn't work, try form (i). */ r =sscanf (str,"%llu%c" , &b, &dummy); -if (r <0 ) -return r; +if (r ==-1 ) +return -EINVAL ;if (r ==1 ) { result->begin =to_cblock (b);Could you please clarify how to reproduce unexpected results? From what I observe, the kernel's sscanf doesn't return -1 on an empty input. Even if a negative value other than
-EINVALis returned, it is handled by the callers.
Quoted 1 line
Hank
I applied the patch, but I deleted the conditions "if (r == -1) return -EINVAL;"
sscanf in the kernel doesn't return negative numbers.
Mikulas
Hi,
Quoted 54 lines · Mikulas Patocka
Quoted 49 lines · Ming-Hung Tsai
Quoted 31 lines · Dipendra Khadka
Smatch reported following:
'''drivers/md/dm-cache-target.c:3204parse_cblock_range()warn: sscanf doesn't return error codesdrivers/md/dm-cache-target.c:3217parse_cblock_range()warn: sscanf doesn't return error codes '''Since, the only negative value that is returned by sscanf is -1. Returning
-ENVALwhen sscanf returns -1.Signed-off-by Dipendra Khadka <[email protected]>--- drivers/md/dm-cache-target.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/md/dm-cache-target.c +2
-2@@ -3200,8 +3200,8 @@ static int parse_cblock_range(struct cache *cache, const char *str,* Try and parse form (ii) first. */ r =sscanf (str,"%llu-%llu%c" , &b, &e, &dummy); -if (r <0 ) -return r; +if (r ==-1 ) +return -EINVAL ;if (r ==2 ) { result->begin =to_cblock (b);drivers/md/dm-cache-target.c static int parse_cblock_range(struct cache *cache, const char *str, · line 3220
Quoted 10 lines
drivers/md/dm-cache-target.c +2
-2@@ -3213,8 +3213,8 @@ static int parse_cblock_range(struct cache *cache, const char *str,* That didn't work, try form (i). */ r =sscanf (str,"%llu%c" , &b, &dummy); -if (r <0 ) -return r; +if (r ==-1 ) +return -EINVAL ;if (r ==1 ) { result->begin =to_cblock (b);Could you please clarify how to reproduce unexpected results? From what I observe, the kernel's sscanf doesn't return -1 on an empty input. Even if a negative value other than
-EINVALis returned, it is handled by the callers.
Quoted 7 lines
Quoted 1 line
Hank
I applied the patch, but I deleted the conditions "if (r == -1) return
-EINVAL;"sscanf in the kernel doesn't return negative numbers.
Do I have to send v2 with
if (r != 2)
return -EINVAL;
or what should I do now?
Quoted 1 line
Mikulas
Best Regards,
Dipendra
Mikulas Patocka
maintainerQuoted 69 lines · Dipendra Khadka
Hi,
Quoted 54 lines · Mikulas Patocka
Quoted 49 lines · Ming-Hung Tsai
Quoted 31 lines · Dipendra Khadka
Smatch reported following:
'''drivers/md/dm-cache-target.c:3204parse_cblock_range()warn: sscanf doesn't return error codesdrivers/md/dm-cache-target.c:3217parse_cblock_range()warn: sscanf doesn't return error codes '''Since, the only negative value that is returned by sscanf is -1. Returning
-ENVALwhen sscanf returns -1.Signed-off-by Dipendra Khadka <[email protected]>--- drivers/md/dm-cache-target.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/md/dm-cache-target.c +2
-2@@ -3200,8 +3200,8 @@ static int parse_cblock_range(struct cache *cache, const char *str,* Try and parse form (ii) first. */ r =sscanf (str,"%llu-%llu%c" , &b, &e, &dummy); -if (r <0 ) -return r; +if (r ==-1 ) +return -EINVAL ;if (r ==2 ) { result->begin =to_cblock (b);drivers/md/dm-cache-target.c static int parse_cblock_range(struct cache *cache, const char *str, · line 3220
Quoted 10 lines
drivers/md/dm-cache-target.c +2
-2@@ -3213,8 +3213,8 @@ static int parse_cblock_range(struct cache *cache, const char *str,* That didn't work, try form (i). */ r =sscanf (str,"%llu%c" , &b, &dummy); -if (r <0 ) -return r; +if (r ==-1 ) +return -EINVAL ;if (r ==1 ) { result->begin =to_cblock (b);Could you please clarify how to reproduce unexpected results? From what I observe, the kernel's sscanf doesn't return -1 on an empty input. Even if a negative value other than
-EINVALis returned, it is handled by the callers.Quoted 7 lines
Quoted 1 line
Hank
I applied the patch, but I deleted the conditions "if (r == -1) return
-EINVAL;"sscanf in the kernel doesn't return negative numbers.
Do I have to send v2 with
if (r != 2)
return-EINVAL;
Quoted 5 lines
or what should I do now?
Quoted 1 line
Mikulas
Best Regards,
Dipendra
You can do nothing :)
I fixed the patch and I'll send it to Linus in this merge window.
Mikulas
Quoted 75 lines · Mikulas Patocka
Quoted 70 lines · Dipendra Khadka
Hi,
Quoted 54 lines · Mikulas Patocka
Quoted 49 lines · Ming-Hung Tsai
Quoted 31 lines · Dipendra Khadka
Smatch reported following:
'''drivers/md/dm-cache-target.c:3204parse_cblock_range()warn: sscanf doesn't return error codesdrivers/md/dm-cache-target.c:3217parse_cblock_range()warn: sscanf doesn't return error codes '''Since, the only negative value that is returned by sscanf is -1. Returning
-ENVALwhen sscanf returns -1.Signed-off-by Dipendra Khadka <[email protected]>--- drivers/md/dm-cache-target.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/md/dm-cache-target.c +2
-2@@ -3200,8 +3200,8 @@ static int parse_cblock_range(struct cache *cache, const char *str,* Try and parse form (ii) first. */ r =sscanf (str,"%llu-%llu%c" , &b, &e, &dummy); -if (r <0 ) -return r; +if (r ==-1 ) +return -EINVAL ;if (r ==2 ) { result->begin =to_cblock (b);drivers/md/dm-cache-target.c static int parse_cblock_range(struct cache *cache, const char *str, · line 3220
Quoted 10 lines
drivers/md/dm-cache-target.c +2
-2@@ -3213,8 +3213,8 @@ static int parse_cblock_range(struct cache *cache, const char *str,* That didn't work, try form (i). */ r =sscanf (str,"%llu%c" , &b, &dummy); -if (r <0 ) -return r; +if (r ==-1 ) +return -EINVAL ;if (r ==1 ) { result->begin =to_cblock (b);Could you please clarify how to reproduce unexpected results? From what I observe, the kernel's sscanf doesn't return -1 on an empty input. Even if a negative value other than
-EINVALis returned, it is handled by the callers.Quoted 7 lines
Quoted 1 line
Hank
I applied the patch, but I deleted the conditions "if (r == -1) return
-EINVAL;"sscanf in the kernel doesn't return negative numbers.
Do I have to send v2 with
if (r != 2)
return-EINVAL;or what should I do now?
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
Mikulas
Best Regards,
DipendraYou can do nothing :)
I fixed the patch and I'll send it to Linus in this merge window.
Oh, ok. Thank you for your time.
Quoted 1 line
Mikulas
Best Regards,
Dipendra.
Mikulas Patocka
maintainerHi
I skimmed through the sscanf source code and it seems that it can't return a negative value at all.
I think, this should be:
r = sscanf(str, "%llu-%llu%c", &b, &e, &dummy); if (r != 2) return -EINVAL;
Mikulas
Quoted 43 lines · Dipendra Khadka
Smatch reported following:
'''drivers/md/dm-cache-target.c:3204parse_cblock_range()warn: sscanf doesn't return error codesdrivers/md/dm-cache-target.c:3217parse_cblock_range()warn: sscanf doesn't return error codes '''Since, the only negative value that is returned by sscanf is -1. Returning
-ENVALwhen sscanf returns -1.Signed-off-by Dipendra Khadka <[email protected]>--- drivers/md/dm-cache-target.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/md/dm-cache-target.c +4
-4@@ -3200,8 +3200,8 @@ static int parse_cblock_range(struct cache *cache, const char *str,* Try and parse form (ii) first. */ r =sscanf (str,"%llu-%llu%c" , &b, &e, &dummy); -if (r <0 ) -return r; +if (r ==-1 ) +return -EINVAL ;if (r ==2 ) { result->begin =to_cblock (b);@@ -3213,8 +3213,8 @@ static int parse_cblock_range(struct cache *cache, const char *str,* That didn't work, try form (i). */ r =sscanf (str,"%llu%c" , &b, &dummy); -if (r <0 ) -return r; +if (r ==-1 ) +return -EINVAL ;if (r ==1 ) { result->begin =to_cblock (b);Signature · 1 line
2.43.0