aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Kraai <kraai@debian.org>2001-08-24 19:51:54 +0000
committerMatt Kraai <kraai@debian.org>2001-08-24 19:51:54 +0000
commitac20ce1924a0eb563acfda6533a80701cd611bfa (patch)
tree5209668fde99a5caa4ed41d8d61c73770fcae646
parent2a953aed3831f8705444e720783ad4781904a625 (diff)
downloadbusybox-w32-ac20ce1924a0eb563acfda6533a80701cd611bfa.tar.gz
busybox-w32-ac20ce1924a0eb563acfda6533a80701cd611bfa.tar.bz2
busybox-w32-ac20ce1924a0eb563acfda6533a80701cd611bfa.zip
Canonicalize dirname(3) behavior.
-rw-r--r--archival/tar.c6
-rw-r--r--libbb/dirname.c10
-rw-r--r--libbb/make_directory.c10
-rw-r--r--libbb/unarchive.c6
-rw-r--r--tar.c6
5 files changed, 25 insertions, 13 deletions
diff --git a/archival/tar.c b/archival/tar.c
index cf65798ff..389d7f02e 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -342,9 +342,11 @@ tarExtractRegularFile(TarInfo *header, int extractFlag, int tostdoutFlag)
342 if (extractFlag==TRUE && tostdoutFlag==FALSE) { 342 if (extractFlag==TRUE && tostdoutFlag==FALSE) {
343 /* Create the path to the file, just in case it isn't there... 343 /* Create the path to the file, just in case it isn't there...
344 * This should not screw up path permissions or anything. */ 344 * This should not screw up path permissions or anything. */
345 char *dir = dirname (header->name); 345 char *buf, *dir;
346 buf = xstrdup (header->name);
347 dir = dirname (buf);
346 make_directory (dir, -1, FILEUTILS_RECUR); 348 make_directory (dir, -1, FILEUTILS_RECUR);
347 free (dir); 349 free (buf);
348 if ((outFd=open(header->name, O_CREAT|O_TRUNC|O_WRONLY, 350 if ((outFd=open(header->name, O_CREAT|O_TRUNC|O_WRONLY,
349 header->mode & ~S_IFMT)) < 0) { 351 header->mode & ~S_IFMT)) < 0) {
350 error_msg(io_error, header->name, strerror(errno)); 352 error_msg(io_error, header->name, strerror(errno));
diff --git a/libbb/dirname.c b/libbb/dirname.c
index 5f839945d..87db1f24f 100644
--- a/libbb/dirname.c
+++ b/libbb/dirname.c
@@ -22,7 +22,8 @@
22#include <string.h> 22#include <string.h>
23#include "libbb.h" 23#include "libbb.h"
24 24
25/* Return a string on the heap containing the directory component of PATH. */ 25/* Return a string containing the path name of the parent
26 * directory of PATH. */
26 27
27char *dirname(const char *path) 28char *dirname(const char *path)
28{ 29{
@@ -43,7 +44,8 @@ char *dirname(const char *path)
43 s--; 44 s--;
44 45
45 if (s < path) 46 if (s < path)
46 return xstrdup ("."); 47 return ".";
47 else 48
48 return xstrndup (path, s - path + 1); 49 s[1] = '\0';
50 return path;
49} 51}
diff --git a/libbb/make_directory.c b/libbb/make_directory.c
index 7b7fde911..a06a410d2 100644
--- a/libbb/make_directory.c
+++ b/libbb/make_directory.c
@@ -50,13 +50,17 @@ int make_directory (char *path, long mode, int flags)
50 50
51 if (stat (path, &st) < 0 && errno == ENOENT) { 51 if (stat (path, &st) < 0 && errno == ENOENT) {
52 int status; 52 int status;
53 char *parent = dirname (path); 53 char *buf, *parent;
54 mode_t mask = umask (0); 54 mode_t mask;
55
56 mask = umask (0);
55 umask (mask); 57 umask (mask);
56 58
59 buf = xstrdup (path);
60 parent = dirname (buf);
57 status = make_directory (parent, (0777 & ~mask) | 0300, 61 status = make_directory (parent, (0777 & ~mask) | 0300,
58 FILEUTILS_RECUR); 62 FILEUTILS_RECUR);
59 free (parent); 63 free (buf);
60 64
61 if (status < 0 || make_directory (path, mode, 0) < 0) 65 if (status < 0 || make_directory (path, mode, 0) < 0)
62 return -1; 66 return -1;
diff --git a/libbb/unarchive.c b/libbb/unarchive.c
index 0d414a3a8..2d171b4ce 100644
--- a/libbb/unarchive.c
+++ b/libbb/unarchive.c
@@ -127,13 +127,15 @@ char *extract_archive(FILE *src_stream, FILE *out_stream, const file_header_t *f
127 } 127 }
128 } 128 }
129 if (function & extract_create_leading_dirs) { /* Create leading directories with default umask */ 129 if (function & extract_create_leading_dirs) { /* Create leading directories with default umask */
130 char *parent = dirname(full_name); 130 char *buf, *parent;
131 buf = xstrdup(full_name);
132 parent = dirname(full_name);
131 if (make_directory (parent, -1, FILEUTILS_RECUR) != 0) { 133 if (make_directory (parent, -1, FILEUTILS_RECUR) != 0) {
132 if ((function & extract_quiet) != extract_quiet) { 134 if ((function & extract_quiet) != extract_quiet) {
133 error_msg("couldn't create leading directories"); 135 error_msg("couldn't create leading directories");
134 } 136 }
135 } 137 }
136 free (parent); 138 free (buf);
137 } 139 }
138 switch(file_entry->mode & S_IFMT) { 140 switch(file_entry->mode & S_IFMT) {
139 case S_IFREG: 141 case S_IFREG:
diff --git a/tar.c b/tar.c
index cf65798ff..389d7f02e 100644
--- a/tar.c
+++ b/tar.c
@@ -342,9 +342,11 @@ tarExtractRegularFile(TarInfo *header, int extractFlag, int tostdoutFlag)
342 if (extractFlag==TRUE && tostdoutFlag==FALSE) { 342 if (extractFlag==TRUE && tostdoutFlag==FALSE) {
343 /* Create the path to the file, just in case it isn't there... 343 /* Create the path to the file, just in case it isn't there...
344 * This should not screw up path permissions or anything. */ 344 * This should not screw up path permissions or anything. */
345 char *dir = dirname (header->name); 345 char *buf, *dir;
346 buf = xstrdup (header->name);
347 dir = dirname (buf);
346 make_directory (dir, -1, FILEUTILS_RECUR); 348 make_directory (dir, -1, FILEUTILS_RECUR);
347 free (dir); 349 free (buf);
348 if ((outFd=open(header->name, O_CREAT|O_TRUNC|O_WRONLY, 350 if ((outFd=open(header->name, O_CREAT|O_TRUNC|O_WRONLY,
349 header->mode & ~S_IFMT)) < 0) { 351 header->mode & ~S_IFMT)) < 0) {
350 error_msg(io_error, header->name, strerror(errno)); 352 error_msg(io_error, header->name, strerror(errno));