aboutsummaryrefslogtreecommitdiff
path: root/archival/rpm2cpio.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-08-28 21:09:51 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-08-28 21:09:51 +0200
commit0a130d510dc5272dc2fc7bc5a116f0694c8bd2a9 (patch)
tree029e91a6302547df06524ae6d73ecb5b85e35360 /archival/rpm2cpio.c
parent7f2149489fe62373a13792d3de6c33c39725c76c (diff)
downloadbusybox-w32-0a130d510dc5272dc2fc7bc5a116f0694c8bd2a9.tar.gz
busybox-w32-0a130d510dc5272dc2fc7bc5a116f0694c8bd2a9.tar.bz2
busybox-w32-0a130d510dc5272dc2fc7bc5a116f0694c8bd2a9.zip
rpm2cpio: handle unseekable input correctly
function old new delta data_skip 14 20 +6 seek_by_jump 67 72 +5 data_align 81 84 +3 seek_by_read 20 19 -1 skip_header 99 94 -5 rpm2cpio_main 183 177 -6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/3 up/down: 14/-12) Total: 2 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'archival/rpm2cpio.c')
-rw-r--r--archival/rpm2cpio.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/archival/rpm2cpio.c b/archival/rpm2cpio.c
index 566a9f213..30ec80e22 100644
--- a/archival/rpm2cpio.c
+++ b/archival/rpm2cpio.c
@@ -33,9 +33,10 @@ struct rpm_header {
33 uint32_t size; /* Size of store (4 bytes) */ 33 uint32_t size; /* Size of store (4 bytes) */
34}; 34};
35 35
36static off_t skip_header(int rpm_fd) 36static unsigned skip_header(int rpm_fd)
37{ 37{
38 struct rpm_header header; 38 struct rpm_header header;
39 unsigned len;
39 40
40 xread(rpm_fd, &header, sizeof(header)); 41 xread(rpm_fd, &header, sizeof(header));
41// if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC_STR, 3) != 0) { 42// if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC_STR, 3) != 0) {
@@ -48,10 +49,12 @@ static off_t skip_header(int rpm_fd)
48 bb_error_msg_and_die("invalid RPM header magic or unsupported version"); 49 bb_error_msg_and_die("invalid RPM header magic or unsupported version");
49 // ": %x != %x", header.magic_and_ver, htonl(RPM_HEADER_VERnMAGIC)); 50 // ": %x != %x", header.magic_and_ver, htonl(RPM_HEADER_VERnMAGIC));
50 } 51 }
51 /* Seek past index entries */ 52
52 lseek(rpm_fd, 16 * ntohl(header.entries), SEEK_CUR); 53 /* Seek past index entries, and past store */
53 /* Seek past store */ 54 len = 16 * ntohl(header.entries) + ntohl(header.size);
54 return lseek(rpm_fd, ntohl(header.size), SEEK_CUR); 55 seek_by_jump(rpm_fd, len);
56
57 return sizeof(header) + len;
55} 58}
56 59
57/* No getopt required */ 60/* No getopt required */
@@ -60,7 +63,7 @@ int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
60{ 63{
61 struct rpm_lead lead; 64 struct rpm_lead lead;
62 int rpm_fd; 65 int rpm_fd;
63 off_t pos; 66 unsigned pos;
64 unsigned char magic[2]; 67 unsigned char magic[2];
65 IF_DESKTOP(long long) int FAST_FUNC (*unpack)(int src_fd, int dst_fd); 68 IF_DESKTOP(long long) int FAST_FUNC (*unpack)(int src_fd, int dst_fd);
66 69
@@ -78,7 +81,7 @@ int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
78 81
79 /* Skip the signature header, align to 8 bytes */ 82 /* Skip the signature header, align to 8 bytes */
80 pos = skip_header(rpm_fd); 83 pos = skip_header(rpm_fd);
81 lseek(rpm_fd, (8 - (unsigned)pos) & 7, SEEK_CUR); 84 seek_by_jump(rpm_fd, (8 - pos) & 7);
82 85
83 /* Skip the main header */ 86 /* Skip the main header */
84 skip_header(rpm_fd); 87 skip_header(rpm_fd);