bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

astrxfrm: Fix use-after-free bug


From: Bruno Haible
Subject: astrxfrm: Fix use-after-free bug
Date: Thu, 18 May 2023 23:14:37 +0200

One of the gcc warnings points to an actual bug:

../../gllib/astrxfrm.c:159:19: warning: pointer 'result' may be used after 
'realloc' [-Wuse-after-free]

This patch fixes it.


2023-05-18  Bruno Haible  <bruno@clisp.org>

        astrxfrm: Fix use-after-free bug.
        * lib/astrxfrm.c (astrxfrm): Don't use memcpy after realloc succeeded.

diff --git a/lib/astrxfrm.c b/lib/astrxfrm.c
index 214ebc38b8..845f0a0711 100644
--- a/lib/astrxfrm.c
+++ b/lib/astrxfrm.c
@@ -155,10 +155,7 @@ astrxfrm (const char *s, char *resultbuf, size_t *lengthp)
             {
               char *memory = (char *) realloc (result, length);
               if (memory != NULL)
-                {
-                  memcpy (memory, result, length);
-                  result = memory;
-                }
+                result = memory;
             }
         }
     }






reply via email to

[Prev in Thread] Current Thread [Next in Thread]