summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--openbsd-compat/dirname.c36
2 files changed, 21 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog
index dc1bb31ec..2eaa822df 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -37,6 +37,7 @@
37 - (dtucker) [openbsd-compat/inet_ntop.c] Update from OpenBSD 1.5 -> 1.7. 37 - (dtucker) [openbsd-compat/inet_ntop.c] Update from OpenBSD 1.5 -> 1.7.
38 - (dtucker) [openbsd-compat/daemon.c] Update from OpenBSD 1.5 -> 1.6. 38 - (dtucker) [openbsd-compat/daemon.c] Update from OpenBSD 1.5 -> 1.6.
39 - (dtucker) [openbsd-compat/strsep.c] Update from OpenBSD 1.5 -> 1.6. 39 - (dtucker) [openbsd-compat/strsep.c] Update from OpenBSD 1.5 -> 1.6.
40 - (dtucker) [openbsd-compat/daemon.c] Update from OpenBSD 1.10 -> 1.13.
40 41
4120051105 4220051105
42 - (djm) OpenBSD CVS Sync 43 - (djm) OpenBSD CVS Sync
@@ -3279,4 +3280,4 @@
3279 - (djm) Trim deprecated options from INSTALL. Mention UsePAM 3280 - (djm) Trim deprecated options from INSTALL. Mention UsePAM
3280 - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu 3281 - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu
3281 3282
3282$Id: ChangeLog,v 1.3979 2005/11/10 06:28:35 dtucker Exp $ 3283$Id: ChangeLog,v 1.3980 2005/11/10 06:33:00 dtucker Exp $
diff --git a/openbsd-compat/dirname.c b/openbsd-compat/dirname.c
index e2cf81db3..30fcb4968 100644
--- a/openbsd-compat/dirname.c
+++ b/openbsd-compat/dirname.c
@@ -1,7 +1,7 @@
1/* $OpenBSD: dirname.c,v 1.10 2003/06/17 21:56:23 millert Exp $ */ 1/* $OpenBSD: dirname.c,v 1.13 2005/08/08 08:05:33 espie Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com> 4 * Copyright (c) 1997, 2004 Todd C. Miller <Todd.Miller@courtesan.com>
5 * 5 *
6 * Permission to use, copy, modify, and distribute this software for any 6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above 7 * purpose with or without fee is hereby granted, provided that the above
@@ -21,10 +21,6 @@
21#include "includes.h" 21#include "includes.h"
22#ifndef HAVE_DIRNAME 22#ifndef HAVE_DIRNAME
23 23
24#ifndef lint
25static char rcsid[] = "$OpenBSD: dirname.c,v 1.10 2003/06/17 21:56:23 millert Exp $";
26#endif /* not lint */
27
28#include <errno.h> 24#include <errno.h>
29#include <string.h> 25#include <string.h>
30#include <sys/param.h> 26#include <sys/param.h>
@@ -32,16 +28,18 @@ static char rcsid[] = "$OpenBSD: dirname.c,v 1.10 2003/06/17 21:56:23 millert Ex
32char * 28char *
33dirname(const char *path) 29dirname(const char *path)
34{ 30{
35 static char bname[MAXPATHLEN]; 31 static char dname[MAXPATHLEN];
36 register const char *endp; 32 size_t len;
33 const char *endp;
37 34
38 /* Empty or NULL string gets treated as "." */ 35 /* Empty or NULL string gets treated as "." */
39 if (path == NULL || *path == '\0') { 36 if (path == NULL || *path == '\0') {
40 (void)strlcpy(bname, ".", sizeof bname); 37 dname[0] = '.';
41 return(bname); 38 dname[1] = '\0';
39 return (dname);
42 } 40 }
43 41
44 /* Strip trailing slashes */ 42 /* Strip any trailing slashes */
45 endp = path + strlen(path) - 1; 43 endp = path + strlen(path) - 1;
46 while (endp > path && *endp == '/') 44 while (endp > path && *endp == '/')
47 endp--; 45 endp--;
@@ -52,19 +50,23 @@ dirname(const char *path)
52 50
53 /* Either the dir is "/" or there are no slashes */ 51 /* Either the dir is "/" or there are no slashes */
54 if (endp == path) { 52 if (endp == path) {
55 (void)strlcpy(bname, *endp == '/' ? "/" : ".", sizeof bname); 53 dname[0] = *endp == '/' ? '/' : '.';
56 return(bname); 54 dname[1] = '\0';
55 return (dname);
57 } else { 56 } else {
57 /* Move forward past the separating slashes */
58 do { 58 do {
59 endp--; 59 endp--;
60 } while (endp > path && *endp == '/'); 60 } while (endp > path && *endp == '/');
61 } 61 }
62 62
63 if (endp - path + 2 > sizeof(bname)) { 63 len = endp - path + 1;
64 if (len >= sizeof(dname)) {
64 errno = ENAMETOOLONG; 65 errno = ENAMETOOLONG;
65 return(NULL); 66 return (NULL);
66 } 67 }
67 strlcpy(bname, path, endp - path + 2); 68 memcpy(dname, path, len);
68 return(bname); 69 dname[len] = '\0';
70 return (dname);
69} 71}
70#endif 72#endif