From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by sourceware.org (Postfix) with ESMTPS id 62311385803B for ; Tue, 18 Jan 2022 14:29:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 62311385803B Received: by mail-pj1-x1032.google.com with SMTP id b1-20020a17090a990100b001b14bd47532so3009552pjp.0 for ; Tue, 18 Jan 2022 06:29:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=A6/8lqxpaoNZBrhADMY//ieFuJ9CiGfe5sWorX/7Qac=; b=hOWhQ1dIAKkiScuuc0QDv0DhNBk9EuAof+kzRXG1UnaQJhRm1wwL5yJh3fseo72hDx IDUvXKzfHhS43/9pV87O9R8GN5jqiY/HhvRIFr2iZ5Y06ntC9NdchlecDxy019U+kuMz z9+No40kr/eN8wLcdNAdqlTu4Zv1qDb3qPeAIYFUi8hybF9OMPd+k6fhRhvVhErDN7Dy M6d96bVFvRbUvYr11xQsK3QSYMJBzjmIhmeUdBKUgsP8GpWrP0v1NihqqZsgttIZd8jh bVLiUQBTExsnTTpISUwjdYWMF+3HQbyiPg7b2Oja4DXXjfyexuu8o2hxrqE8GKH/E2V7 N3Eg== X-Gm-Message-State: AOAM533na5QlNQ75cqBfIKQwpRjOk7LDvNCVQdLHYH3HUAJOfvzXNQjP FkYPGDoQQyClsJjE2RX5vHPE8M5SWeHSM8yMvzs= X-Google-Smtp-Source: ABdhPJz9aCASzcudsaFOj+l3h2mIbbU6c/6cJlP3IuhbUbxS2wwJE5G1LemEWBDNHw/tcgEQV7t6qI97nRBYRJF+5Us= X-Received: by 2002:a17:903:1c4:b0:14a:555c:adc0 with SMTP id e4-20020a17090301c400b0014a555cadc0mr27497578plh.101.1642516176542; Tue, 18 Jan 2022 06:29:36 -0800 (PST) MIME-Version: 1.0 References: <1642405014-3287-1-git-send-email-xuyang2018.jy@fujitsu.com> <61E6298D.80006@fujitsu.com> <61E64FED.2010906@fujitsu.com> <87fspl6s44.fsf@igel.home> In-Reply-To: <87fspl6s44.fsf@igel.home> From: "H.J. Lu" Date: Tue, 18 Jan 2022 06:29:00 -0800 Message-ID: Subject: Re: [PATCH] src/ext4_resize.c: set errno to 0 before the strtoull call To: Andreas Schwab Cc: xuyang2018.jy@fujitsu.com, "fweimer@redhat.com" , "libc-alpha@sourceware.org" , "Theodore Ts'o" , "fstests@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3021.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Jan 2022 14:29:38 -0000 On Tue, Jan 18, 2022 at 6:22 AM Andreas Schwab wrot= e: > > 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 (n= on=E2=80=90 negated) value would overflow; in the latter case, strtoul() retu= rns ULONG_MAX and sets errno to ERANGE. Precisely the same holds for s= tr=E2=80=90 toull() (with ULLONG_MAX instead of ULONG_MAX). new_size =3D strtoull(argv[2], &tmp, 10); if ((errno) || (*tmp !=3D '\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; } --=20 H.J.