* [PATCH] sim-utils.c: prevent buffer overflow.
@ 2019-11-30 22:54 Pavel I. Kryukov
2019-12-01 14:46 ` Simon Marchi
2019-12-02 10:09 ` Andrew Burgess
0 siblings, 2 replies; 10+ messages in thread
From: Pavel I. Kryukov @ 2019-11-30 22:54 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 1 bytes --]
[-- Attachment #2: 0001-sim-utils.c-prevent-buffer-overflow.patch --]
[-- Type: application/octet-stream, Size: 1519 bytes --]
From 5958a57053a755030e930c63168f09ca8fab1c84 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.
---
sim/common/ChangeLog | 4 ++++
sim/common/sim-utils.c | 4 ++--
2 files changed, 6 insertions(+), 2 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..a60dd92 100644
--- a/sim/common/sim-utils.c
+++ b/sim/common/sim-utils.c
@@ -355,7 +355,7 @@ map_to_str (unsigned map)
case io_map: return "io";
default:
{
- static char str[10];
+ static char str[16];
sprintf (str, "(%ld)", (long) map);
return str;
}
@@ -385,7 +385,7 @@ access_to_str (unsigned access)
case access_read_write_exec_io: return "read_write_exec_io";
default:
{
- static char str[10];
+ static char str[16];
sprintf (str, "(%ld)", (long) access);
return str;
}
--
2.7.4
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] sim-utils.c: prevent buffer overflow.
2019-11-30 22:54 [PATCH] sim-utils.c: prevent buffer overflow Pavel I. Kryukov
@ 2019-12-01 14:46 ` Simon Marchi
2019-12-01 15:33 ` Павел Крюков
2019-12-02 10:09 ` Andrew Burgess
1 sibling, 1 reply; 10+ messages in thread
From: Simon Marchi @ 2019-12-01 14:46 UTC (permalink / raw)
To: Pavel I. Kryukov, gdb-patches; +Cc: Andrew Burgess
On 2019-11-30 5:53 p.m., Pavel I. Kryukov wrote:
Is the sim built in C++ like GDB? If so, maybe this function could return
an std::string, so there's no more concerns of allocating a static buffer
with sufficient space?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] sim-utils.c: prevent buffer overflow.
2019-12-01 14:46 ` Simon Marchi
@ 2019-12-01 15:33 ` Павел Крюков
2021-01-15 5:18 ` Mike Frysinger
0 siblings, 1 reply; 10+ messages in thread
From: Павел Крюков @ 2019-12-01 15:33 UTC (permalink / raw)
To: Simon Marchi; +Cc: gdb-patches, Andrew Burgess
No, simulators are built in C. Probably they may be switched to C++, but that would require more effort; plus, there may be external C simulators.
Thanks,
--
Pavel
> 1 дек. 2019 г., в 17:46, Simon Marchi <simark@simark.ca> написал(а):
>
> On 2019-11-30 5:53 p.m., Pavel I. Kryukov wrote:
>
> Is the sim built in C++ like GDB? If so, maybe this function could return
> an std::string, so there's no more concerns of allocating a static buffer
> with sufficient space?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] sim-utils.c: prevent buffer overflow.
2019-11-30 22:54 [PATCH] sim-utils.c: prevent buffer overflow Pavel I. Kryukov
2019-12-01 14:46 ` Simon Marchi
@ 2019-12-02 10:09 ` Andrew Burgess
2019-12-02 12:00 ` Pavel I. Kryukov
1 sibling, 1 reply; 10+ messages in thread
From: Andrew Burgess @ 2019-12-02 10:09 UTC (permalink / raw)
To: Pavel I. Kryukov; +Cc: gdb-patches
* Pavel I. Kryukov <kryukov@frtk.ru> [2019-12-01 01:53:59 +0300]:
>
> From 5958a57053a755030e930c63168f09ca8fab1c84 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 with the nit below fixed.
Thanks,
Andrew
> ---
> sim/common/ChangeLog | 4 ++++
> sim/common/sim-utils.c | 4 ++--
> 2 files changed, 6 insertions(+), 2 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..a60dd92 100644
> --- a/sim/common/sim-utils.c
> +++ b/sim/common/sim-utils.c
> @@ -355,7 +355,7 @@ map_to_str (unsigned map)
> case io_map: return "io";
> default:
> {
> - static char str[10];
> + static char str[16];
> sprintf (str, "(%ld)", (long) map);
I think you could/should change this call to sprintf to use
xsnprintf instead.
> return str;
> }
> @@ -385,7 +385,7 @@ access_to_str (unsigned access)
> case access_read_write_exec_io: return "read_write_exec_io";
> default:
> {
> - static char str[10];
> + static char str[16];
> sprintf (str, "(%ld)", (long) access);
Same.
> return str;
> }
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] sim-utils.c: prevent buffer overflow.
2019-12-02 10:09 ` Andrew Burgess
@ 2019-12-02 12:00 ` Pavel I. Kryukov
2019-12-02 19:06 ` Pavel I. Kryukov
0 siblings, 1 reply; 10+ messages in thread
From: Pavel I. Kryukov @ 2019-12-02 12:00 UTC (permalink / raw)
To: Andrew Burgess; +Cc: gdb-patches
> > diff --git a/sim/common/sim-utils.c b/sim/common/sim-utils.c
> > index e83a2e4..a60dd92 100644
> > --- a/sim/common/sim-utils.c
> > +++ b/sim/common/sim-utils.c
> > @@ -355,7 +355,7 @@ map_to_str (unsigned map)
> > case io_map: return "io";
> > default:
> > {
> > - static char str[10];
> > + static char str[16];
> > sprintf (str, "(%ld)", (long) map);
>
> I think you could/should change this call to sprintf to use
> xsnprintf instead.
If I understand correctly, xsnprintf is defined in GDB header
(gdb/gdbsupport/common-utils.h) which is C++.
Can we use "pure" snprintf instead?
Thanks,
--
Pavel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] sim-utils.c: prevent buffer overflow.
2019-12-02 12:00 ` Pavel I. Kryukov
@ 2019-12-02 19:06 ` Pavel I. Kryukov
2019-12-02 21:20 ` Andrew Burgess
0 siblings, 1 reply; 10+ messages in thread
From: Pavel I. Kryukov @ 2019-12-02 19:06 UTC (permalink / raw)
To: Andrew Burgess, Simon Marchi; +Cc: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 39 bytes --]
Attached new version
Thanks,
--
Pavel
[-- Attachment #2: 0001-sim-utils.c-prevent-buffer-overflow.patch --]
[-- Type: application/octet-stream, Size: 1644 bytes --]
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.
---
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] sim-utils.c: prevent buffer overflow.
2019-12-02 19:06 ` Pavel I. Kryukov
@ 2019-12-02 21:20 ` Andrew Burgess
2019-12-03 9:47 ` Pavel I. Kryukov
0 siblings, 1 reply; 10+ messages in thread
From: Andrew Burgess @ 2019-12-02 21:20 UTC (permalink / raw)
To: Pavel I. Kryukov; +Cc: Simon Marchi, gdb-patches
* 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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] sim-utils.c: prevent buffer overflow.
2019-12-02 21:20 ` Andrew Burgess
@ 2019-12-03 9:47 ` Pavel I. Kryukov
2019-12-04 17:39 ` Tom Tromey
0 siblings, 1 reply; 10+ messages in thread
From: Pavel I. Kryukov @ 2019-12-03 9:47 UTC (permalink / raw)
To: Andrew Burgess; +Cc: Simon Marchi, gdb-patches
Thanks. Could you please tell if there is any action required from me?
--
Pavel
вт, 3 дек. 2019 г. в 00:20, Andrew Burgess <andrew.burgess@embecosm.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
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] sim-utils.c: prevent buffer overflow.
2019-12-03 9:47 ` Pavel I. Kryukov
@ 2019-12-04 17:39 ` Tom Tromey
0 siblings, 0 replies; 10+ messages in thread
From: Tom Tromey @ 2019-12-04 17:39 UTC (permalink / raw)
To: Pavel I. Kryukov; +Cc: Andrew Burgess, Simon Marchi, gdb-patches
>>>>> "Pavel" == Pavel I Kryukov <kryukov@frtk.ru> writes:
Pavel> Thanks. Could you please tell if there is any action required from me?
I've pushed it.
I didn't check to see if you have a copyright assignment.
This patch doesn't need one, but if you plan to do more work on gdb, you
should get that set up. You can contact me off-list for details.
thanks,
Tom
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] sim-utils.c: prevent buffer overflow.
2019-12-01 15:33 ` Павел Крюков
@ 2021-01-15 5:18 ` Mike Frysinger
0 siblings, 0 replies; 10+ messages in thread
From: Mike Frysinger @ 2021-01-15 5:18 UTC (permalink / raw)
To: Павел
Крюков
Cc: Simon Marchi, gdb-patches, Andrew Burgess
[-- Attachment #1: Type: text/plain, Size: 807 bytes --]
On 01 Dec 2019 18:33, Павел Крюков wrote:
> 1 дек. 2019 г., в 17:46, Simon Marchi <simark@simark.ca> написал(а):
> > Is the sim built in C++ like GDB? If so, maybe this function could return
> > an std::string, so there's no more concerns of allocating a static buffer
> > with sufficient space?
>
> No, simulators are built in C. Probably they may be switched to C++, but that would require more effort; plus, there may be external C simulators.
i've been thinking about the sim & C-vs-C++. the only reason i
hesitate to go all in is that we provide libsim.a for people to
link the runtime into other programs, and providing a static lib
that requires C++ feels wrong.
gdb has the advantage that it doesn't provide a library interface.
maybe it should ...
-mike
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2021-01-15 5:18 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-30 22:54 [PATCH] sim-utils.c: prevent buffer overflow 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
2019-12-03 9:47 ` Pavel I. Kryukov
2019-12-04 17:39 ` Tom Tromey
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).