From 162ac4860481853044eafc94cc2dd76ce4e46e1d Mon Sep 17 00:00:00 2001 From: YONETANI Tomokazu Date: Thu, 28 Apr 2005 01:43:53 +0000 Subject: [PATCH] Backout part of the change in 1.4; copy directory part of the path, rather than the whole path. This is something not doable with strlcpy() alone, unless source buffer can be writable. --- lib/libc/gen/dirname.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/libc/gen/dirname.c b/lib/libc/gen/dirname.c index fe287ace66..cb3493e10f 100644 --- a/lib/libc/gen/dirname.c +++ b/lib/libc/gen/dirname.c @@ -1,6 +1,6 @@ /* $OpenBSD: dirname.c,v 1.4 1999/05/30 17:10:30 espie Exp $ */ /* $FreeBSD: src/lib/libc/gen/dirname.c,v 1.1.2.2 2001/07/23 10:13:04 dd Exp $ */ -/* $DragonFly: src/lib/libc/gen/dirname.c,v 1.4 2005/04/27 11:50:50 joerg Exp $ */ +/* $DragonFly: src/lib/libc/gen/dirname.c,v 1.5 2005/04/28 01:43:53 y0netan1 Exp $ */ /* * Copyright (c) 1997 Todd C. Miller @@ -67,9 +67,11 @@ dirname(const char *path) endp--; } while (endp > path && *endp == '/'); - if (strlcpy(bname, path, sizeof(bname)) >= sizeof(bname)) { + if (endp - path + 2 > sizeof(bname)) { errno = ENAMETOOLONG; return(NULL); } + strncpy(bname, path, endp - path + 1); + bname[endp - path + 1] = '\0'; return(bname); } -- 2.11.4.GIT