Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit e7e7a50

Browse files
author
Greg Clayton
committed
LLDB could segfault if it got a .a file that had extra padding bytes at the end of the file.
<rdar://problem/16732178> git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@207877 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent e92256f commit e7e7a50

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp

+24-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,25 @@ ObjectContainerBSDArchive::Object::Extract (const DataExtractor& data, lldb::off
7474
size_t ar_name_len = 0;
7575
std::string str;
7676
char *err;
77+
78+
79+
// File header
80+
//
81+
// The common format is as follows.
82+
//
83+
// Offset Length Name Format
84+
// 0 16 File name ASCII right padded with spaces (no spaces allowed in file name)
85+
// 16 12 File mod Decimal as cstring right padded with spaces
86+
// 28 6 Owner ID Decimal as cstring right padded with spaces
87+
// 34 6 Group ID Decimal as cstring right padded with spaces
88+
// 40 8 File mode Octal as cstring right padded with spaces
89+
// 48 10 File byte size Decimal as cstring right padded with spaces
90+
// 58 2 File magic 0x60 0x0A
91+
92+
// Make sure there is enough data for the file header and bail if not
93+
if (!data.ValidOffsetForDataOfSize(offset, 60))
94+
return LLDB_INVALID_OFFSET;
95+
7796
str.assign ((const char *)data.GetData(&offset, 16), 16);
7897
if (str.find("#1/") == 0)
7998
{
@@ -110,7 +129,11 @@ ObjectContainerBSDArchive::Object::Extract (const DataExtractor& data, lldb::off
110129
{
111130
if (ar_name_len > 0)
112131
{
113-
str.assign ((const char *)data.GetData(&offset, ar_name_len), ar_name_len);
132+
const void *ar_name_ptr = data.GetData(&offset, ar_name_len);
133+
// Make sure there was enough data for the string value and bail if not
134+
if (ar_name_ptr == NULL)
135+
return LLDB_INVALID_OFFSET;
136+
str.assign ((const char *)ar_name_ptr, ar_name_len);
114137
ar_name.SetCString (str.c_str());
115138
}
116139
ar_file_offset = offset;

0 commit comments

Comments
 (0)