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 a6ee2e7..8129f09 Binary files a/dumpifs and b/dumpifs differ diff --git a/dumpifs.c b/dumpifs.c index 5f35862..5ddae4c 100644 --- a/dumpifs.c +++ b/dumpifs.c @@ -994,7 +994,6 @@ int mkdir_p(const char *path) } void extract_file(FILE *fp, int ipos, struct image_file *ent) { - char *name; FILE *dst; struct utimbuf buff; struct extract_file *ef; @@ -1003,7 +1002,14 @@ void extract_file(FILE *fp, int ipos, struct image_file *ent) { return; } - name = (flags & FLAG_BASENAME) ? basename(ent->path) : 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)); }