From: "H.J. Lu" <hjl.tools@gmail.com>
To: Yann Droneaud <ydroneaud@opteya.com>
Cc: GNU C Library <libc-alpha@sourceware.org>
Subject: Re: [PATCH] src/ext4_resize.c: set errno to 0 before the strtoull call
Date: Tue, 18 Jan 2022 06:54:43 -0800 [thread overview]
Message-ID: <CAMe9rOpC3LmWDXy0uH_GKydyq255Ug07q0YXfXEv0eX_r8LAKg@mail.gmail.com> (raw)
In-Reply-To: <1f209861-9ab7-340a-f4a9-f28423a39a4c@opteya.com>
On Tue, Jan 18, 2022 at 6:43 AM Yann Droneaud <ydroneaud@opteya.com> wrote:
>
> Hi,
>
> Le 18/01/2022 à 15:29, H.J. Lu via Libc-alpha a écrit :
> > On Tue, Jan 18, 2022 at 6:22 AM Andreas Schwab <schwab@linux-m68k.org> wrote:
> >> On Jan 18 2022, xuyang2018.jy@fujitsu.com wrote:
> >>
> >>> Now, I use glibc-2.34 and run the following program[1] but the errno is
> >>> not 0 in the beginning. So is this a known bug on glibc-2.34(Theodore
> >>> doesn't meet this problem on glicb-2.31)?
> >>>
> >>> [1]https://git.kernel.org/pub/scm/fs/xfs/xfstests-dev.git/tree/src/ext4_resize.c
> >> Note that there is a call to open preceding the strtoull call, so no
> >> guarantees can be made about the value of errno before the latter.
> >>
> > strtoull man page:
> >
> > RETURN VALUE
> > The strtoul() function returns either the result of the conversion or,
> > if there was a leading minus sign, the negation of the result of the
> > conversion represented as an unsigned value, unless the original (non‐
> > negated) value would overflow; in the latter case, strtoul() returns
> > ULONG_MAX and sets errno to ERANGE. Precisely the same holds for str‐
> > toull() (with ULLONG_MAX instead of ULONG_MAX).
> >
> > new_size = strtoull(argv[2], &tmp, 10);
> > if ((errno) || (*tmp != '\0')) {
> > ^^^^^^^^^^^^ Shouldn't errno be checked only after the prior function
> > return value is checked first?
> >
> > fprintf(stderr, "%s: invalid new size\n", argv[0]);
> > return 1;
> > }
>
> Something like:
>
> errno = 0; /* must be cleared to distinguish error */
^^^^^^^^^^^^^^^^^ Remove it.
> tmp = NULL;
> new_size = strtoull(argv[2], &p, 0);
> if ((new_size == 0 || new_size == ULONGLONG_MAX) && errno) {
Change it to
if (new_size == 0 || (new_size == ULONGLONG_MAX) && errno)) {
> fprintf(stderr, "%s: invalid new size\n", argv[0]);
> return 1;
> }
>
> if (tmp) {
> /* error, unused trailing characters */
> if (*tmp) {
> fprintf(stderr, "%s: invalid new size\n", argv[0]);
> return 1;
> }
>
> /* error, empty string */
> if (tmp == argv[2]) {
> fprintf(stderr, "%s: invalid new size\n", argv[0]);
> return 1;
>
> }
> }
>
> --
> Yann Droneaud
> OPTEYA
>
--
H.J.
next prev parent reply other threads:[~2022-01-18 14:55 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1642405014-3287-1-git-send-email-xuyang2018.jy@fujitsu.com>
[not found] ` <YeYmzJG5M0y9BcMc@mit.edu>
[not found] ` <61E6298D.80006@fujitsu.com>
[not found] ` <YeY6Uh8I7RlsCicw@mit.edu>
2022-01-18 5:27 ` xuyang2018.jy
2022-01-18 11:23 ` Adhemerval Zanella
2022-01-18 11:26 ` Florian Weimer
2022-01-18 11:49 ` Adhemerval Zanella
2022-01-18 12:00 ` Florian Weimer
2022-01-18 12:04 ` Andreas Schwab
2022-01-18 12:26 ` Adhemerval Zanella
2022-01-18 14:02 ` Florian Weimer
2022-01-19 6:14 ` xuyang2018.jy
2022-01-19 7:19 ` xuyang2018.jy
2022-01-19 13:57 ` Cristian Rodríguez
2022-01-19 14:07 ` Cristian Rodríguez
2022-01-19 14:50 ` Andrew G. Morgan
2022-01-19 20:13 ` Theodore Ts'o
2022-01-18 14:22 ` Andreas Schwab
2022-01-18 14:29 ` H.J. Lu
2022-01-18 14:43 ` Yann Droneaud
2022-01-18 14:54 ` H.J. Lu [this message]
2022-01-18 15:30 ` Andreas Schwab
2022-01-19 2:07 ` xuyang2018.jy
2022-01-19 8:23 ` Andreas Schwab
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAMe9rOpC3LmWDXy0uH_GKydyq255Ug07q0YXfXEv0eX_r8LAKg@mail.gmail.com \
--to=hjl.tools@gmail.com \
--cc=libc-alpha@sourceware.org \
--cc=ydroneaud@opteya.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).