Skip to contentSkip to conversation

Fix segfault with missing lockfile directory

PATCH Applied Phil Sutter 2 participants 2 messages Apr 9, 2019 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/1 Fix segfault with missing lockfile directory

Apparently, dirname() modifies the buffer passed to it. Given a read-only location, this leads to a segfault. Use a buffer initialized (and tailored) to the content of LOCKFILE macro at compile-time instead.

Fixes f45756c1ca3b5 ("Allow customizing lockfile location at configure time")
---
 libebtc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
libebtc.c +2 -1
index f2a2b500ea751..2a9ab87ac99c0 100644
@@ -140,12 +140,13 @@ int use_lockfd;
  * or -2 on any other error. */
 static int lock_file()
 {
+	char pathbuf[] = LOCKFILE;
 	int fd, try = 0;
 
 retry:
 	fd = open(LOCKFILE, O_CREAT, 00600);
 	if (fd < 0) {
-		if (try == 1 || mkdir(dirname(LOCKFILE), 00700))
+		if (try == 1 || mkdir(dirname(pathbuf), 00700))
 			return -2;
 		try = 1;
 		goto retry;
Signature · 1 line
2.21.0
maintainer Applied
#1 lore raw
Quoted 3 lines · Phil Sutter

Apparently, dirname() modifies the buffer passed to it. Given a read-only location, this leads to a segfault. Use a buffer initialized (and tailored) to the content of LOCKFILE macro at compile-time instead.

Applied, thanks.