public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: Avoid possible signed overflow in decode_local_label_name
Date: Wed, 3 Jul 2024 15:42:47 +0930	[thread overview]
Message-ID: <ZoTr384PdyZixKbe@squeak.grove.modra.org> (raw)

This avoids signed overflow in the "10 * x + *p - '0'" expressions.
Matches what both fb_label_name and dollar_label_name use.

	* symbols.c (decode_local_label_name): Use unsigned variables.

diff --git a/gas/symbols.c b/gas/symbols.c
index b57dbfc64f4..fa3aaa37ed4 100644
--- a/gas/symbols.c
+++ b/gas/symbols.c
@@ -2185,11 +2185,11 @@ decode_local_label_name (char *s)
 {
   char *p;
   char *symbol_decode;
-  int label_number;
-  int instance_number;
+  unsigned int label_number;
+  unsigned int instance_number;
   const char *type;
   const char *message_format;
-  int lindex = 0;
+  unsigned int lindex = 0;
 
 #ifdef LOCAL_LABEL_PREFIX
   if (s[lindex] == LOCAL_LABEL_PREFIX)
@@ -2212,7 +2212,7 @@ decode_local_label_name (char *s)
   for (instance_number = 0, p++; ISDIGIT (*p); ++p)
     instance_number = (10 * instance_number) + *p - '0';
 
-  message_format = _("\"%d\" (instance number %d of a %s label)");
+  message_format = _("\"%u\" (instance number %u of a %s label)");
   symbol_decode = notes_alloc (strlen (message_format) + 30);
   sprintf (symbol_decode, message_format, label_number, instance_number, type);
 

-- 
Alan Modra

                 reply	other threads:[~2024-07-03  6:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=ZoTr384PdyZixKbe@squeak.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@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).