From: Dmitry Chestnyh <d.chestnyh@omp.ru>
To: <libc-alpha@sourceware.org>
Cc: Dmitry Chestnyh <d.chestnyh@omp.ru>
Subject: [PATCH] [locale] Corrected return value check.
Date: Fri, 1 Apr 2022 08:46:26 +0300 [thread overview]
Message-ID: <20220401054626.505298-1-d.chestnyh@omp.ru> (raw)
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)
--
2.25.1
next reply other threads:[~2022-04-01 5:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-01 5:46 Dmitry Chestnyh [this message]
-- strict thread matches above, loose matches on Subject: below --
2022-03-31 19:47 Dmitry Chestnyh
2022-03-31 19:37 Dmitry Chestnyh
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=20220401054626.505298-1-d.chestnyh@omp.ru \
--to=d.chestnyh@omp.ru \
--cc=libc-alpha@sourceware.org \
/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).