[PATCH 2/3] untar: Make path also for symbolic links

Sebastian Huber sebastian.huber at embedded-brains.de
Thu Nov 21 09:36:44 UTC 2019


Close #3823.
---
 cpukit/libmisc/untar/untar.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/cpukit/libmisc/untar/untar.c b/cpukit/libmisc/untar/untar.c
index 2bd1ab243c..1c69840a97 100644
--- a/cpukit/libmisc/untar/untar.c
+++ b/cpukit/libmisc/untar/untar.c
@@ -123,7 +123,7 @@ Stat_Node(const char* path)
  * Make the directory path for a file if it does not exist.
  */
 static int
-Make_Path(const rtems_printer *printer, const char* filename, bool end_is_dir)
+Make_Path(const rtems_printer *printer, const char* filename, int linktype)
 {
   char* copy = strdup(filename);
   char* path = copy;
@@ -216,7 +216,7 @@ Make_Path(const rtems_printer *printer, const char* filename, bool end_is_dir)
             path_end = true;
         }
       }
-      else if (path_end && r == DIRTYPE && !end_is_dir) {
+      else if (path_end && r == DIRTYPE && linktype != DIRTYPE) {
         /*
          * We only handle a directory if at the end of the path and the end is
          * a file. If we cannot remove the directory because it is not empty we
@@ -289,6 +289,11 @@ Untar_ProcessHeader(
    * We've decoded the header, now figure out what it contains and do something
    * with it.
    */
+
+  if (Make_Path(ctx->printer, ctx->fname, ctx->linkflag) < 0) {
+    retval  = UNTAR_FAIL;
+  }
+
   if (ctx->linkflag == SYMTYPE) {
     strlcpy(ctx->linkname, &bufr[157], sizeof(ctx->linkname));
     rtems_printf(ctx->printer, "untar: symlink: %s -> %s\n",
@@ -298,15 +303,9 @@ Untar_ProcessHeader(
     rtems_printf(ctx->printer, "untar: file: %s (s:%lu,m:%04lo)\n",
                  ctx->fname, ctx->file_size, ctx->mode);
     ctx->nblocks = (((ctx->file_size) + 511) & ~511) / 512;
-    if (Make_Path(ctx->printer, ctx->fname, false) < 0) {
-      retval  = UNTAR_FAIL;
-    }
   } else if (ctx->linkflag == DIRTYPE) {
     int r;
     rtems_printf(ctx->printer, "untar:  dir: %s\n", ctx->fname);
-    if (Make_Path(ctx->printer, ctx->fname, true) < 0) {
-      retval  = UNTAR_FAIL;
-    }
     r = mkdir(ctx->fname, S_IRWXU | S_IRWXG | S_IRWXO);
     if (r < 0) {
       if (errno == EEXIST) {
-- 
2.16.4



More information about the devel mailing list