From eb6c695e1a2a79967935b4cea07695141ba60336 Mon Sep 17 00:00:00 2001 From: Alex Beigel Date: Tue, 31 Aug 2021 14:39:43 -0400 Subject: [PATCH] Fixed mkdir_p. Modified .sh script to handle paths properly. Made the binary and the .sh script executable. --- dumpIfs.sh | 26 ++++++++++++++------------ dumpifs | Bin 41584 -> 41576 bytes dumpifs.c | 18 +++++++++++++----- 3 files changed, 27 insertions(+), 17 deletions(-) mode change 100644 => 100755 dumpIfs.sh mode change 100644 => 100755 dumpifs diff --git a/dumpIfs.sh b/dumpIfs.sh old mode 100644 new mode 100755 index 0dda692..80f6519 --- a/dumpIfs.sh +++ b/dumpIfs.sh @@ -4,35 +4,37 @@ PRGNAME=$0 DIRNAME=$(dirname $0) -DUMPIFS=$DIRNAME/dumpifs +DUMPIFS=$(realpath $DIRNAME/dumpifs) prnUsageAndQuit() { - echo "Usage: $PRGNAME " - exit + echo "Usage: $PRGNAME " + exit } if [ "x$1" = "x" ];then - prnUsageAndQuit + prnUsageAndQuit fi if [ "x$2" = "x" ];then - prnUsageAndQuit + prnUsageAndQuit fi -dirs=$($DUMPIFS $1 | grep -v ^[a-zA-Z]|grep -v '\-\-\-\-'|awk '{print($3)}'|sort -u |xargs -n 1 dirname |sort -u) +IFS_FILE=$(realpath $1) + +dirs=$($DUMPIFS ${IFS_FILE} | grep -v ^[a-zA-Z]|grep -v '\-\-\-\-'|awk '{print($3)}'|sort -u |xargs -n 1 dirname |sort -u) for d in $dirs;do -theDir=$2/$d -echo mkdir -p $theDir -mkdir -p $theDir + theDir=$2/$d + echo mkdir -p $theDir + mkdir -p $theDir done echo "Enter dir $2" cd $2 -for x in $($DUMPIFS ../$1 | grep -v ^[a-zA-Z]| awk '{print($3)}'|sort -u |xargs -n 1 basename) -do -$DUMPIFS -x ../$1 $x +for x in $($DUMPIFS "${IFS_FILE}" | grep -v ^[a-zA-Z]| awk '{print($3)}'|sort -u |xargs -n 1 basename) + do + $DUMPIFS -x "${IFS_FILE}" $x done cd .. diff --git a/dumpifs b/dumpifs old mode 100644 new mode 100755 index a6ee2e75a90ea46fdb5cc5347f0300e412b23ea3..8129f093d35b06578181e738970b0a31cf8503ef GIT binary patch delta 86 zcmexxgz3c*rU@F185=c^HH(|-8R#09CY9!ulp590Z5apath) : ent->path; + // Both dirname() and basename() may modify the contents of path, so we'll use copies + const size_t len = strlen(ent->path); + char ent_path_copy[len]; + strncpy(ent_path_copy, ent->path, len); + + char* name = (flags & FLAG_BASENAME) ? basename(ent_path_copy) : ent->path; + // Reset in case it was altered by basename() + strncpy(ent_path_copy, ent->path, len); if ( extract_files != NULL ) { for ( ef = extract_files; ef != NULL; ef = ef->next ) { @@ -1018,12 +1024,14 @@ void extract_file(FILE *fp, int ipos, struct image_file *ent) { processing_done = 1; } } -/* - if(mkdir_p(dirname(ent->path))) { + + if(mkdir_p(dirname(ent_path_copy))) { printf("unable to mkdir -p for %s\n", name); return; } -*/ + // Reset because it was probably altered by dirname() + strncpy(ent_path_copy, ent->path, len); + if(!(dst = fopen(name, "wb"))) { error(0, "Unable to open %s: %s\n", name, strerror(errno)); }