lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAAYit8TfBD40aRchLiOWsvqwpAR0x6nW9zObza4vLVzg93N+eA@mail.gmail.com>
Date: Mon, 23 Sep 2024 17:40:48 +0800
From: Ming-Hung Tsai <mingnus@...il.com>
To: Dipendra Khadka <kdipendra88@...il.com>
Cc: agk@...hat.com, snitzer@...nel.org, mpatocka@...hat.com, 
	dm-devel@...ts.linux.dev, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] Return error code for failure input for sscanf in parse_cblock_range()

On Mon, Sep 23, 2024 at 12:47 AM Dipendra Khadka <kdipendra88@...il.com> wrote:
>
> 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.
>
> Signed-off-by: Dipendra Khadka <kdipendra88@...il.com>
> ---
>  drivers/md/dm-cache-target.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c
> index 17f0fab1e254..c35d65e310d6 100644
> --- a/drivers/md/dm-cache-target.c
> +++ b/drivers/md/dm-cache-target.c
> @@ -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);


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

> --
> 2.43.0
>
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ