From: Andrew Burgess <andrew.burgess@embecosm.com>
To: "Pavel I. Kryukov" <kryukov@frtk.ru>
Cc: Simon Marchi <simark@simark.ca>, gdb-patches@sourceware.org
Subject: Re: [PATCH] sim-utils.c: prevent buffer overflow.
Date: Mon, 02 Dec 2019 21:20:00 -0000 [thread overview]
Message-ID: <20191202212031.GK3410@embecosm.com> (raw)
In-Reply-To: <CADip9gZV4DH7iiUxZXp85quX+OQ_Jj_Kxv_2zB-UWP1JLBNJ5w@mail.gmail.com>
* Pavel I. Kryukov <kryukov@frtk.ru> [2019-12-02 22:06:04 +0300]:
> From 2d6383b7baa715d65191f0f6818ecdd8f5e8fc7d Mon Sep 17 00:00:00 2001
> From: "Pavel I. Kryukov" <kryukov@frtk.ru>
> Date: Sun, 1 Dec 2019 01:40:21 +0300
> Subject: [PATCH] sim-utils.c: prevent buffer overflow.
>
> Representation of max 32-bit integer is 10 chars.
> The potential issue is observed by GCC 7 targeted to AArch64.
>
> sim/common/ChangeLog:
> 2019-12-01 Pavel I. Kryukov <kryukov@frtk.ru>
>
> * sim-utils.c: Prevent buffer overflow.
Approved.
Sorry about the xsnprintf confusion - I'd assumed that came from
libiberty, my mistake.
Thanks,
Andrew
> ---
> sim/common/ChangeLog | 4 ++++
> sim/common/sim-utils.c | 8 ++++----
> 2 files changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog
> index a7ec5c7..12d900e 100644
> --- a/sim/common/ChangeLog
> +++ b/sim/common/ChangeLog
> @@ -1,3 +1,7 @@
> +2019-12-01 Pavel I. Kryukov <kryukov@frtk.ru>
> +
> + * sim-utils.c: Prevent buffer overflow.
> +
> 2019-09-23 Dimitar Dimitrov <dimitar@dinux.eu>
>
> * gennltvals.sh: Add PRU libgloss target.
> diff --git a/sim/common/sim-utils.c b/sim/common/sim-utils.c
> index e83a2e4..0c46662 100644
> --- a/sim/common/sim-utils.c
> +++ b/sim/common/sim-utils.c
> @@ -355,8 +355,8 @@ map_to_str (unsigned map)
> case io_map: return "io";
> default:
> {
> - static char str[10];
> - sprintf (str, "(%ld)", (long) map);
> + static char str[16];
> + snprintf (str, sizeof(str), "(%ld)", (long) map);
> return str;
> }
> }
> @@ -385,8 +385,8 @@ access_to_str (unsigned access)
> case access_read_write_exec_io: return "read_write_exec_io";
> default:
> {
> - static char str[10];
> - sprintf (str, "(%ld)", (long) access);
> + static char str[16];
> + snprintf (str, sizeof(str), "(%ld)", (long) access);
> return str;
> }
> }
> --
> 2.7.4
next prev parent reply other threads:[~2019-12-02 21:20 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-30 22:54 Pavel I. Kryukov
2019-12-01 14:46 ` Simon Marchi
2019-12-01 15:33 ` Павел Крюков
2021-01-15 5:18 ` Mike Frysinger
2019-12-02 10:09 ` Andrew Burgess
2019-12-02 12:00 ` Pavel I. Kryukov
2019-12-02 19:06 ` Pavel I. Kryukov
2019-12-02 21:20 ` Andrew Burgess [this message]
2019-12-03 9:47 ` Pavel I. Kryukov
2019-12-04 17:39 ` Tom Tromey
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=20191202212031.GK3410@embecosm.com \
--to=andrew.burgess@embecosm.com \
--cc=gdb-patches@sourceware.org \
--cc=kryukov@frtk.ru \
--cc=simark@simark.ca \
/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).