In order to be used as drop in replacement for dirname() If path is a null pointer or points to an empty string, dirname() shall return a pointer to the string "." . --- lib/lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
From 884abd7b484c9ecf357004eb8e123e32b6b5cd01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jarno=20M=C3=A4kip=C3=A4=C3=A4?= <jmaki...@gmail.com> Date: Sat, 19 Oct 2019 09:47:10 +0300 Subject: [PATCH] lib: getdirname fix seqfault on null ptr
In order to be used as drop in replacement for dirname() If path is a null pointer or points to an empty string, dirname() shall return a pointer to the string "." . --- lib/lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lib.c b/lib/lib.c index f98f00a5..be490eb3 100644 --- a/lib/lib.c +++ b/lib/lib.c @@ -1012,7 +1012,7 @@ char *getdirname(char *name) char *s, *ss, *keep; for (s = name, ss = keep = 0; ; s++) { - if (!*s) return keep ? xstrndup(name, keep-name) : xstrdup("."); + if (!s || !*s) return keep ? xstrndup(name, keep-name) : xstrdup("."); if (*s != '/') keep = ss; else if (s == name) keep = ss = s+1; else if (s[-1] != '/') ss = s; -- 2.19.1
_______________________________________________ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net