Skip to content

Commit d88e14e

Browse files
committed
Bugfix: allow # on files paths
1 parent bc47c92 commit d88e14e

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

genext2fs.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
// 6 Jan 2003 Erik Andersen <[email protected]> added
5252
// mkfs.jffs2 compatible device table support,
5353
// along with -q, -P, -U
54+
// 10 Sep 2016 Bugfix: allow `#` on files paths <[email protected]>
5455

5556

5657
#include <config.h>
@@ -1534,8 +1535,6 @@ add2fs_from_file(filesystem *fs, uint32 this_nod, FILE * fh, uint32 fs_timestamp
15341535
mode = uid = gid = major = minor = 0;
15351536
start = 0; increment = 1; count = 0;
15361537
lineno++;
1537-
if((c = strchr(line, '#')))
1538-
*c = 0;
15391538
if (path) {
15401539
free(path);
15411540
path = NULL;
@@ -1544,15 +1543,28 @@ add2fs_from_file(filesystem *fs, uint32 this_nod, FILE * fh, uint32 fs_timestamp
15441543
free(path2);
15451544
path2 = NULL;
15461545
}
1547-
nbargs = sscanf (line, "%" SCANF_PREFIX "s %c %lo %lu %lu %lu %lu %lu %lu %lu",
1548-
SCANF_STRING(path), &type, &mode, &uid, &gid, &major, &minor,
1549-
&start, &increment, &count);
1550-
if(nbargs < 3)
1546+
1547+
// `sscanf()` is used twice to allow to have `#` character in the file path
1548+
if(line[0] == '\n' || line[0] == '#')
1549+
continue;
1550+
nbargs = sscanf(line, "%" SCANF_PREFIX "s", SCANF_STRING(path));
1551+
if(!nbargs)
1552+
{
1553+
error_msg("device table line %d skipped: file path not provided", lineno);
1554+
continue;
1555+
}
1556+
char* line2 = line+strlen(path);
1557+
if((c = strchr(line2, '#')))
1558+
*c = 0;
1559+
nbargs = sscanf(line2, " %c %lo %lu %lu %lu %lu %lu %lu %lu", &type, &mode,
1560+
&uid, &gid, &major, &minor, &start, &increment, &count);
1561+
if(nbargs < 2)
15511562
{
1552-
if(nbargs > 0)
1553-
error_msg("device table line %d skipped: bad format for entry '%s'", lineno, path);
1563+
error_msg("device table line %d skipped: bad format for entry '%s'",
1564+
lineno, path);
15541565
continue;
15551566
}
1567+
15561568
mode &= FM_IMASK;
15571569
path2 = strdup(path);
15581570
name = basename(path);

0 commit comments

Comments
 (0)