From patchwork Fri Apr 1 05:46:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Chestnyh X-Patchwork-Id: 52551 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4DC423945C29 for ; Fri, 1 Apr 2022 05:46:47 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mxout04.lancloud.ru (mxout04.lancloud.ru [45.84.86.114]) by sourceware.org (Postfix) with ESMTPS id 81B633858C53 for ; Fri, 1 Apr 2022 05:46:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 81B633858C53 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=omp.ru Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=omp.ru Received: from LanCloud DKIM-Filter: OpenDKIM Filter v2.11.0 mxout04.lancloud.ru 21CFD20BD15D Received: from LanCloud Received: from LanCloud Received: from LanCloud From: Dmitry Chestnyh To: Subject: [PATCH] [locale] Corrected return value check. Date: Fri, 1 Apr 2022 08:46:26 +0300 Message-ID: <20220401054626.505298-1-d.chestnyh@omp.ru> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [192.168.11.198] X-ClientProxiedBy: LFEXT02.lancloud.ru (fd00:f066::142) To LFEX1912.lancloud.ru (fd00:f066::166) X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY 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: , Cc: Dmitry Chestnyh Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" strtol returns LONG_MAX or LONG_MIN on ERANGE error. strtoul can return ULONG_MAX on ERANGE error. This issue was found by SVACE static analyzer. --- locale/programs/ld-collate.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/locale/programs/ld-collate.c b/locale/programs/ld-collate.c index 992814491d..4c401c9268 100644 --- a/locale/programs/ld-collate.c +++ b/locale/programs/ld-collate.c @@ -1344,12 +1344,12 @@ order for `%.*s' already defined at %s:%Zu"), errno = 0; from = strtol (startp->name + preflen, &cp, base); - if ((from == UINT_MAX && errno == ERANGE) || *cp != '\0') + if (((from == LONG_MAX || from == LONG_MIN ) && errno == ERANGE) || *cp != '\0') goto invalid_range; errno = 0; to = strtol (endp->name + preflen, &cp, base); - if ((to == UINT_MAX && errno == ERANGE) || *cp != '\0') + if (((to == LONG_MAX || to == LONG_MIN ) && errno == ERANGE) || *cp != '\0') goto invalid_range; /* Copy the prefix. */ @@ -2934,13 +2934,13 @@ collate_read (struct linereader *ldfile, struct localedef_t *result, symbol[symbol_len] = '\0'; from = strtoul (&symbol[prefixlen], &endp, ellipsis == tok_ellipsis2 ? 16 : 10); - if (*endp != '\0') + if ((from == ULONG_MAX && errno == ERANGE) || *endp != '\0') goto col_sym_inv_range; endsymbol[symbol_len] = '\0'; to = strtoul (&endsymbol[prefixlen], &endp, ellipsis == tok_ellipsis2 ? 16 : 10); - if (*endp != '\0') + if ((to == ULONG_MAX && errno == ERANGE) || *endp != '\0') goto col_sym_inv_range; if (from > to)