public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Replace unchecked malloc with xmalloc
@ 2024-04-04  5:26 Nandakumar Edamana
  2024-04-04  7:28 ` Alan Modra
  0 siblings, 1 reply; 5+ messages in thread
From: Nandakumar Edamana @ 2024-04-04  5:26 UTC (permalink / raw)
  To: binutils

diff --git a/binutils/dlltool.c b/binutils/dlltool.c
index 066c99a4d4f..7a3d20f0af9 100644
--- a/binutils/dlltool.c
+++ b/binutils/dlltool.c
@@ -876,7 +876,7 @@ dlltmp (char **buf, const char *fmt)
  {
    if (!*buf)
      {
-      *buf = malloc (strlen (tmp_prefix) + 64);
+      *buf = xmalloc (strlen (tmp_prefix) + 64);
        sprintf (*buf, fmt, tmp_prefix);
      }
    return *buf;


This is the first time I submit a patch to binutils. Please guide me if 
I'm doing it wrong.

An automated script lists more occurrences of unchecked mallocs, and a 
quick manual review points to potentially unsound code from a memory 
safety perspective. But I'll wait until this patch gets reviewed.

Thank you,

-- 
Nandakumar Edamana
https://nandakumar.org/


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Replace unchecked malloc with xmalloc
  2024-04-04  5:26 [PATCH] Replace unchecked malloc with xmalloc Nandakumar Edamana
@ 2024-04-04  7:28 ` Alan Modra
  2024-04-04  7:39   ` Nandakumar Edamana
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Modra @ 2024-04-04  7:28 UTC (permalink / raw)
  To: Nandakumar Edamana; +Cc: binutils

On Thu, Apr 04, 2024 at 10:56:14AM +0530, Nandakumar Edamana wrote:
> diff --git a/binutils/dlltool.c b/binutils/dlltool.c
> index 066c99a4d4f..7a3d20f0af9 100644
> --- a/binutils/dlltool.c
> +++ b/binutils/dlltool.c
> @@ -876,7 +876,7 @@ dlltmp (char **buf, const char *fmt)
>  {
>    if (!*buf)
>      {
> -      *buf = malloc (strlen (tmp_prefix) + 64);
> +      *buf = xmalloc (strlen (tmp_prefix) + 64);
>        sprintf (*buf, fmt, tmp_prefix);
>      }
>    return *buf;
> 
> 
> This is the first time I submit a patch to binutils. Please guide me if I'm
> doing it wrong.

There was a problem when applying the patch, possibly caused by your
email app.
git am /tmp/nandakumar
warning: Patch sent with format=flowed; space at the end of lines might be lost.
Applying: Replace unchecked malloc with xmalloc
error: corrupt patch at line 6
Patch failed at 0001 Replace unchecked malloc with xmalloc

Since the patch was simple, I've applied it by hand and will commit it
for you.  Thanks for the fix!

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Replace unchecked malloc with xmalloc
  2024-04-04  7:28 ` Alan Modra
@ 2024-04-04  7:39   ` Nandakumar Edamana
  2024-04-04 22:31     ` Alan Modra
  0 siblings, 1 reply; 5+ messages in thread
From: Nandakumar Edamana @ 2024-04-04  7:39 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 486 bytes --]

On 04/04/24 12:58, Alan Modra wrote:
> There was a problem when applying the patch, possibly caused by your
> email app.

Thanks for accepting the patch! Maybe next time I'll attach it as a file.

BTW, what is your opinion on fixing similar issues in seemingly 
test-related files? Would that be a total waste of time? Although they 
may not run as part of the final product, tests could yield false 
results due to memory errors, right?

-- 
Nandakumar Edamana
https://nandakumar.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Replace unchecked malloc with xmalloc
  2024-04-04  7:39   ` Nandakumar Edamana
@ 2024-04-04 22:31     ` Alan Modra
  2024-04-05  2:22       ` Nandakumar Edamana
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Modra @ 2024-04-04 22:31 UTC (permalink / raw)
  To: Nandakumar Edamana; +Cc: binutils

On Thu, Apr 04, 2024 at 01:09:11PM +0530, Nandakumar Edamana wrote:
> On 04/04/24 12:58, Alan Modra wrote:
> > There was a problem when applying the patch, possibly caused by your
> > email app.
> 
> Thanks for accepting the patch! Maybe next time I'll attach it as a file.
> 
> BTW, what is your opinion on fixing similar issues in seemingly test-related
> files? Would that be a total waste of time? Although they may not run as
> part of the final product, tests could yield false results due to memory
> errors, right?

Tests are very unlikely to run out of memory, so, no it isn't
necessary to fix tests.  In fact you might break the test by "fixing"
it.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Replace unchecked malloc with xmalloc
  2024-04-04 22:31     ` Alan Modra
@ 2024-04-05  2:22       ` Nandakumar Edamana
  0 siblings, 0 replies; 5+ messages in thread
From: Nandakumar Edamana @ 2024-04-05  2:22 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 247 bytes --]

On 05/04/24 04:01, Alan Modra wrote:
> Tests are very unlikely to run out of memory, so, no it isn't
> necessary to fix tests.  In fact you might break the test by "fixing"
> it.
Understood, thanks.

-- 
Nandakumar Edamana
https://nandakumar.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-04-05  2:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-04  5:26 [PATCH] Replace unchecked malloc with xmalloc Nandakumar Edamana
2024-04-04  7:28 ` Alan Modra
2024-04-04  7:39   ` Nandakumar Edamana
2024-04-04 22:31     ` Alan Modra
2024-04-05  2:22       ` Nandakumar Edamana

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).