diff options
Diffstat (limited to 'archival/libarchive/get_header_ar.c')
-rw-r--r-- | archival/libarchive/get_header_ar.c | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/archival/libarchive/get_header_ar.c b/archival/libarchive/get_header_ar.c index 23c412496..c66bb3ee7 100644 --- a/archival/libarchive/get_header_ar.c +++ b/archival/libarchive/get_header_ar.c | |||
@@ -8,11 +8,19 @@ | |||
8 | #include "bb_archive.h" | 8 | #include "bb_archive.h" |
9 | #include "ar.h" | 9 | #include "ar.h" |
10 | 10 | ||
11 | static unsigned read_num(const char *str, int base) | 11 | /* WARNING: Clobbers str[len], so fields must be read in reverse order! */ |
12 | static unsigned read_num(char *str, int base, int len) | ||
12 | { | 13 | { |
14 | int err; | ||
15 | |||
16 | /* ar fields are fixed length text strings (padded with spaces). | ||
17 | * Ensure bb_strtou doesn't read past the field in case the full | ||
18 | * width is used. */ | ||
19 | str[len] = 0; | ||
20 | |||
13 | /* This code works because | 21 | /* This code works because |
14 | * on misformatted numbers bb_strtou returns all-ones */ | 22 | * on misformatted numbers bb_strtou returns all-ones */ |
15 | int err = bb_strtou(str, NULL, base); | 23 | err = bb_strtou(str, NULL, base); |
16 | if (err == -1) | 24 | if (err == -1) |
17 | bb_error_msg_and_die("invalid ar header"); | 25 | bb_error_msg_and_die("invalid ar header"); |
18 | return err; | 26 | return err; |
@@ -51,11 +59,13 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle) | |||
51 | if (ar.formatted.magic[0] != '`' || ar.formatted.magic[1] != '\n') | 59 | if (ar.formatted.magic[0] != '`' || ar.formatted.magic[1] != '\n') |
52 | bb_error_msg_and_die("invalid ar header"); | 60 | bb_error_msg_and_die("invalid ar header"); |
53 | 61 | ||
54 | /* FIXME: more thorough routine would be in order here | 62 | /* |
55 | * (we have something like that in tar) | 63 | * Note that the fields MUST be read in reverse order as |
56 | * but for now we are lax. */ | 64 | * read_num() clobbers the next byte after the field! |
57 | ar.formatted.magic[0] = '\0'; /* else 4G-2 file will have size="4294967294`\n..." */ | 65 | * Order is: name, date, uid, gid, mode, size, magic. |
58 | typed->size = size = read_num(ar.formatted.size, 10); | 66 | */ |
67 | typed->size = size = read_num(ar.formatted.size, 10, | ||
68 | sizeof(ar.formatted.size)); | ||
59 | 69 | ||
60 | /* special filenames have '/' as the first character */ | 70 | /* special filenames have '/' as the first character */ |
61 | if (ar.formatted.name[0] == '/') { | 71 | if (ar.formatted.name[0] == '/') { |
@@ -87,10 +97,10 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle) | |||
87 | * long filename pseudo file. Thus we decode the rest | 97 | * long filename pseudo file. Thus we decode the rest |
88 | * after dealing with long filename pseudo file. | 98 | * after dealing with long filename pseudo file. |
89 | */ | 99 | */ |
90 | typed->mode = read_num(ar.formatted.mode, 8); | 100 | typed->mode = read_num(ar.formatted.mode, 8, sizeof(ar.formatted.mode)); |
91 | typed->mtime = read_num(ar.formatted.date, 10); | 101 | typed->gid = read_num(ar.formatted.gid, 10, sizeof(ar.formatted.gid)); |
92 | typed->uid = read_num(ar.formatted.uid, 10); | 102 | typed->uid = read_num(ar.formatted.uid, 10, sizeof(ar.formatted.uid)); |
93 | typed->gid = read_num(ar.formatted.gid, 10); | 103 | typed->mtime = read_num(ar.formatted.date, 10, sizeof(ar.formatted.date)); |
94 | 104 | ||
95 | #if ENABLE_FEATURE_AR_LONG_FILENAMES | 105 | #if ENABLE_FEATURE_AR_LONG_FILENAMES |
96 | if (ar.formatted.name[0] == '/') { | 106 | if (ar.formatted.name[0] == '/') { |
@@ -98,7 +108,8 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle) | |||
98 | 108 | ||
99 | /* The number after the '/' indicates the offset in the ar data section | 109 | /* The number after the '/' indicates the offset in the ar data section |
100 | * (saved in ar_long_names) that conatains the real filename */ | 110 | * (saved in ar_long_names) that conatains the real filename */ |
101 | long_offset = read_num(&ar.formatted.name[1], 10); | 111 | long_offset = read_num(&ar.formatted.name[1], 10, |
112 | sizeof(ar.formatted.name) - 1); | ||
102 | if (long_offset >= ar_long_name_size) { | 113 | if (long_offset >= ar_long_name_size) { |
103 | bb_error_msg_and_die("can't resolve long filename"); | 114 | bb_error_msg_and_die("can't resolve long filename"); |
104 | } | 115 | } |