rpm: bail out if headers have abnormally large entry counts
function old new delta .rodata 104880 104906 +26 rpm_gettags 419 443 +24 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 50/0) Total: 50 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
1 parent
f3ca54f688
commit
5450a8ed71
2 files changed
+8
-1
No files matched your search
+7
-1
@@ -116,8 +116,13 @@ static int rpm_gettags(const char *filename)
|
||||
xread(fd, &header, sizeof(header));
|
||||
if (header.magic_and_ver != htonl(RPM_HEADER_MAGICnVER))
|
||||
bb_error_msg_and_die("invalid RPM header magic in '%s'", filename);
|
||||
#if BB_LITTLE_ENDIAN
|
||||
header.size = ntohl(header.size);
|
||||
#endif
|
||||
cnt = ntohl(header.entries);
|
||||
/* Prevent multiplication overflow leading to undersized allocations */
|
||||
if (sizeof(cnt) <= 4 && cnt >= 0x00400000) /* ~4 million */
|
||||
bb_error_msg_and_die("bad RPM header.entries:%u", cnt);
|
||||
storepos += sizeof(header) + cnt * 16;
|
||||
|
||||
G.tagcount += cnt;
|
||||
@@ -125,9 +130,11 @@ static int rpm_gettags(const char *filename)
|
||||
xread(fd, &tags[idx], sizeof(tags[0]) * cnt);
|
||||
while (cnt--) {
|
||||
rpm_index *tag = &tags[idx];
|
||||
#if BB_LITTLE_ENDIAN
|
||||
tag->tag = ntohl(tag->tag);
|
||||
tag->type = ntohl(tag->type);
|
||||
tag->count = ntohl(tag->count);
|
||||
#endif
|
||||
tag->offset = storepos + ntohl(tag->offset);
|
||||
if (pass == 0)
|
||||
tag->tag -= 743;
|
||||
@@ -146,7 +153,6 @@ static int rpm_gettags(const char *filename)
|
||||
storepos = (storepos + G_pagesize) & -(int)G_pagesize;
|
||||
/* remember size for munmap */
|
||||
G.mapsize = storepos;
|
||||
/* some NOMMU systems prefer MAP_PRIVATE over MAP_SHARED */
|
||||
G.map = mmap_read(fd, storepos);
|
||||
if (G.map == MAP_FAILED)
|
||||
bb_perror_msg_and_die("mmap '%s'", filename);
|
||||
|
||||
@@ -110,6 +110,7 @@ void* FAST_FUNC xmemdup(const void *s, size_t n)
|
||||
|
||||
void* FAST_FUNC mmap_read(int fd, size_t size)
|
||||
{
|
||||
/* some NOMMU systems prefer MAP_PRIVATE over MAP_SHARED */
|
||||
return mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user