From 2bf0aa5f5911d76099d160802d34f1a621efcde6 Mon Sep 17 00:00:00 2001 From: Ray Lai Date: Fri, 24 Mar 2006 04:17:27 +0000 Subject: Make sure `path' variable is always NUL-terminated. Totally different diff (but functionally equivalent) by Loic Tortay and okayed by tedu@. ``Looks sane to me'' moritz@ --- bin/mkdir/mkdir.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/bin/mkdir/mkdir.c b/bin/mkdir/mkdir.c index 9a446e10d48..051bf87fd01 100644 --- a/bin/mkdir/mkdir.c +++ b/bin/mkdir/mkdir.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mkdir.c,v 1.17 2004/07/01 18:25:47 otto Exp $ */ +/* $OpenBSD: mkdir.c,v 1.18 2006/03/24 04:17:26 ray Exp $ */ /* $NetBSD: mkdir.c,v 1.14 1995/06/25 21:59:21 mycroft Exp $ */ /* @@ -40,7 +40,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)mkdir.c 8.2 (Berkeley) 1/25/94"; #else -static char rcsid[] = "$OpenBSD: mkdir.c,v 1.17 2004/07/01 18:25:47 otto Exp $"; +static char rcsid[] = "$OpenBSD: mkdir.c,v 1.18 2006/03/24 04:17:26 ray Exp $"; #endif #endif /* not lint */ @@ -143,11 +143,11 @@ mkpath(char *path, mode_t mode, mode_t dir_mode) { struct stat sb; char *slash; - int done = 0; + int done; slash = path; - while (!done) { + for (;;) { slash += strspn(slash, "/"); slash += strcspn(slash, "/"); @@ -166,6 +166,9 @@ mkpath(char *path, mode_t mode, mode_t dir_mode) return (-1); } + if (done) + break; + *slash = '/'; } -- cgit v1.2.3