void-packages/srcpkgs/bctoolbox/patches/use-after-realloc.patch

30 lines
964 B
Diff

Index: bctoolbox-5.1.17/src/utils/port.c
===================================================================
--- bctoolbox-5.1.17.orig/src/utils/port.c
+++ bctoolbox-5.1.17/src/utils/port.c
@@ -398,6 +398,7 @@ char * WSAAPI gai_strerror(int errnum){
#include <netdb.h>
#include <sys/un.h>
#include <sys/stat.h>
+#include <stddef.h>
static char *make_pipe_name(const char *name){
return bctbx_strdup_printf("/tmp/%s",name);
@@ -1508,6 +1509,7 @@ char * bctbx_concat(const char *str, ...
/* Resize the allocated memory if necessary. */
if (wp + len + 1 > result + allocated)
{
+ ptrdiff_t offset = wp - result;
allocated = (allocated + len) * 2;
newp = (char *) realloc (result, allocated);
if (newp == NULL)
@@ -1515,7 +1517,7 @@ char * bctbx_concat(const char *str, ...
free (result);
return NULL;
}
- wp = newp + (wp - result);
+ wp = newp + offset;
result = newp;
}
memcpy (wp, s, len);