summaryrefslogtreecommitdiff
path: root/usr.bin/diff/diffreg.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2012-05-22 12:30:25 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2012-05-22 12:30:25 +0000
commit9cca22000779cf6006e2aba6cfdd1f32569e8c09 (patch)
treebfb5fff9bec1c90a3e8b6cb32c5cd5adf5bb6a23 /usr.bin/diff/diffreg.c
parent78cd304b7b07161637cb18551d43b87d7e1f7be4 (diff)
Strip trailing slashes from directory in splice() before
appending the file portion. OK krw@ matthew@
Diffstat (limited to 'usr.bin/diff/diffreg.c')
-rw-r--r--usr.bin/diff/diffreg.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c
index 328ce07dddd..80907aa5554 100644
--- a/usr.bin/diff/diffreg.c
+++ b/usr.bin/diff/diffreg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diffreg.c,v 1.80 2011/04/01 17:25:26 nicm Exp $ */
+/* $OpenBSD: diffreg.c,v 1.81 2012/05/22 12:30:24 millert Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
@@ -536,12 +536,16 @@ char *
splice(char *dir, char *file)
{
char *tail, *buf;
+ size_t dirlen;
+ dirlen = strlen(dir);
+ while (dirlen != 0 && dir[dirlen - 1] == '/')
+ dirlen--;
if ((tail = strrchr(file, '/')) == NULL)
tail = file;
else
tail++;
- xasprintf(&buf, "%s/%s", dir, tail);
+ xasprintf(&buf, "%.*s/%s", (int)dirlen, dir, tail);
return (buf);
}