Backport an overflow fix from upstream.

This fixes crashes in some consumers such as openttd (vm.malloc_conf=S).
This commit is contained in:
bentley 2020-01-13 08:20:51 +00:00
parent 3ef4b4bea6
commit a17cb750bf
2 changed files with 17 additions and 5 deletions

View File

@ -1,11 +1,11 @@
# $OpenBSD: Makefile,v 1.10 2019/07/12 20:51:15 sthen Exp $
# $OpenBSD: Makefile,v 1.11 2020/01/13 08:20:51 bentley Exp $
COMMENT = implementation of the XDG Base Directory specification
DISTNAME = libxdg-basedir-1.2.0
SHARED_LIBS += xdg-basedir 2.0 # .3.0
CATEGORIES = x11 devel
REVISION = 1
REVISION = 2
# MIT
PERMIT_PACKAGE = Yes

View File

@ -1,6 +1,9 @@
$OpenBSD: patch-src_basedir_c,v 1.2 2010/12/15 13:22:03 dcoppa Exp $
--- src/basedir.c.orig Tue Jul 13 07:48:54 2010
+++ src/basedir.c Wed Dec 15 14:13:49 2010
$OpenBSD: patch-src_basedir_c,v 1.3 2020/01/13 08:20:51 bentley Exp $
Overflow fix from upstream:
https://github.com/devnev/libxdg-basedir/commit/14e000f696ef8b83264b0ca4407669bdb365fb23
Index: src/basedir.c
--- src/basedir.c.orig
+++ src/basedir.c
@@ -91,13 +91,12 @@ static void xdgZeroMemory(void* p, int n)
static const char
DefaultRelativeDataHome[] = DIR_SEPARATOR_STR ".local" DIR_SEPARATOR_STR "share",
@ -18,3 +21,12 @@ $OpenBSD: patch-src_basedir_c,v 1.2 2010/12/15 13:22:03 dcoppa Exp $
*DefaultConfigDirectoriesList[] = { DefaultConfigDirectories, NULL };
typedef struct _xdgCachedData
@@ -574,7 +573,7 @@ static char * xdgGetRelativeHome(const char *envname,
unsigned int homelen;
if (!(home = xdgGetEnv("HOME")))
return NULL;
- if (!(relhome = (char*)malloc((homelen = strlen(home))+fallbacklength))) return NULL;
+ if (!(relhome = (char*)malloc((homelen = strlen(home))+fallbacklength+1))) return NULL;
memcpy(relhome, home, homelen);
memcpy(relhome+homelen, relativefallback, fallbacklength+1);
}