hrev50256 adds 1 changeset to branch 'master'
old head: 63a0065c835eaf155ca3f96719475147772ccadd
new head: 82185a52e22179ec842d2c5fb983b307b9ebc7d2
overview:
http://cgit.haiku-os.org/haiku/log/?qt=range&q=82185a52e221+%5E63a0065c835e
----------------------------------------------------------------------------
82185a52e221: Future proofing core file format
* The Haiku specific notes contain a structure size field, now.
* Change the type of the count and size fields in the Haiku specific
notes to uint32 also for 64 bit ELF. The size field for a note is a
uint32 anyway.
[ Ingo Weinhold <ingo_weinhold@xxxxxx> ]
----------------------------------------------------------------------------
Revision: hrev50256
Commit: 82185a52e22179ec842d2c5fb983b307b9ebc7d2
URL: http://cgit.haiku-os.org/haiku/commit/?id=82185a52e221
Author: Ingo Weinhold <ingo_weinhold@xxxxxx>
Date: Tue Apr 26 22:55:05 2016 UTC
----------------------------------------------------------------------------
4 files changed, 140 insertions(+), 74 deletions(-)
headers/os/kernel/elf.h | 36 +++++--
src/apps/debugger/elf/CoreFile.cpp | 152 ++++++++++++++++++------------
src/apps/debugger/elf/CoreFile.h | 8 ++
src/system/kernel/debug/core_dump.cpp | 18 ++--
----------------------------------------------------------------------------
diff --git a/headers/os/kernel/elf.h b/headers/os/kernel/elf.h
index f25fc8b..b1ff0ca 100644
--- a/headers/os/kernel/elf.h
+++ b/headers/os/kernel/elf.h
@@ -611,7 +611,7 @@ typedef struct {
#define NT_IMAGES 0x696d6167 /* images */
#define NT_THREADS 0x74687264 /* threads */
-/* NT_TEAM: Elf32_Note_Team; char[] args */
+/* NT_TEAM: uint32 entrySize; Elf32_Note_Team; char[] args */
typedef struct {
int32 nt_id; /* team ID */
int32 nt_uid; /* team owner ID */
@@ -620,7 +620,12 @@ typedef struct {
typedef Elf32_Note_Team Elf64_Note_Team;
-/* NT_AREAS: uint32 count; Elf32_Note_Area_Entry[count]; char[] names */
+/* NT_AREAS:
+ * uint32 count;
+ * uint32 entrySize;
+ * Elf32_Note_Area_Entry[count];
+ * char[] names
+ */
typedef struct {
int32 na_id; /* area ID */
uint32 na_lock; /* lock type
(B_NO_LOCK, ...) */
@@ -630,7 +635,12 @@ typedef struct {
uint32 na_ram_size; /* physical memory used */
} Elf32_Note_Area_Entry;
-/* NT_AREAS: uint64 count; Elf64_Note_Area_Entry[count]; char[] names */
+/* NT_AREAS:
+ * uint32 count;
+ * uint32 entrySize;
+ * Elf64_Note_Area_Entry[count];
+ * char[] names
+ */
typedef struct {
int32 na_id; /* area ID */
uint32 na_lock; /* lock type
(B_NO_LOCK, ...) */
@@ -641,7 +651,12 @@ typedef struct {
uint64 na_ram_size; /* physical memory used */
} Elf64_Note_Area_Entry;
-/* NT_IMAGES: uint32 count; Elf32_Note_Image_Entry[count]; char[] names */
+/* NT_IMAGES:
+ * uint32 count;
+ * uint32 entrySize;
+ * Elf32_Note_Image_Entry[count];
+ * char[] names
+ */
typedef struct {
int32 ni_id; /* image ID */
int32 ni_type; /* image type
(B_APP_IMAGE, ...) */
@@ -655,7 +670,12 @@ typedef struct {
uint32 ni_data_size; /* size of data segment */
} Elf32_Note_Image_Entry;
-/* NT_IMAGES: uint64 count; Elf64_Note_Image_Entry[count]; char[] names */
+/* NT_IMAGES:
+ * uint32 count;
+ * uint32 entrySize;
+ * Elf64_Note_Image_Entry[count];
+ * char[] names
+ */
typedef struct {
int32 ni_id; /* image ID */
int32 ni_type; /* image type
(B_APP_IMAGE, ...) */
@@ -672,6 +692,7 @@ typedef struct {
/* NT_THREADS:
* uint32 count;
+ * uint32 entrySize;
* uint32 cpuStateSize;
* {Elf32_Note_Thread_Entry, uint8[cpuStateSize] cpuState}[count];
* char[] names
@@ -685,8 +706,9 @@ typedef struct {
} Elf32_Note_Thread_Entry;
/* NT_THREADS:
- * uint64 count;
- * uint64 cpuStateSize;
+ * uint32 count;
+ * uint32 entrySize;
+ * uint32 cpuStateSize;
* {Elf64_Note_Thread_Entry, uint8[cpuStateSize] cpuState}[count];
* char[] names
*/
diff --git a/src/apps/debugger/elf/CoreFile.cpp
b/src/apps/debugger/elf/CoreFile.cpp
index dd8cf33..4f77ea3 100644
--- a/src/apps/debugger/elf/CoreFile.cpp
+++ b/src/apps/debugger/elf/CoreFile.cpp
@@ -8,6 +8,8 @@
#include <errno.h>
+#include <algorithm>
+
#include <OS.h>
#include <AutoDeleter.h>
@@ -319,23 +321,34 @@ CoreFile::_ReadTeamNote(const void* data, uint32 dataSize)
{
typedef typename ElfClass::NoteTeam NoteTeam;
- if (dataSize < sizeof(NoteTeam) + 1) {
+ if (dataSize < sizeof(uint32)) {
WARNING("Team note too short\n");
return B_BAD_DATA;
}
- const NoteTeam* note = (const NoteTeam*)data;
+ uint32 entrySize = Get(*(const uint32*)data);
+ data = (const uint32*)data + 1;
+ dataSize -= sizeof(uint32);
+
+ if (entrySize == 0 || dataSize == 0 || dataSize - 1 < entrySize) {
+ WARNING("Team note: too short or invalid entry size (%"
B_PRIu32 ")\n",
+ entrySize);
+ return B_BAD_DATA;
+ }
+
+ NoteTeam note = {};
+ _ReadEntry(data, dataSize, note, entrySize);
// check, if args are null-terminated
- const char* args = (const char*)(note + 1);
- size_t argsSize = dataSize - sizeof(NoteTeam);
- if (argsSize == 0 || args[argsSize - 1] != '\0') {
+ const char* args = (const char*)data;
+ size_t argsSize = dataSize;
+ if (args[argsSize - 1] != '\0') {
WARNING("Team note args not terminated\n");
return B_BAD_DATA;
}
- int32 id = Get(note->nt_id);
- int32 uid = Get(note->nt_uid);
- int32 gid = Get(note->nt_gid);
+ int32 id = Get(note.nt_id);
+ int32 uid = Get(note.nt_uid);
+ int32 gid = Get(note.nt_gid);
BString copiedArgs(args);
if (args[0] != '\0' && copiedArgs.Length() == 0)
@@ -350,29 +363,29 @@ template<typename ElfClass>
status_t
CoreFile::_ReadAreasNote(const void* data, uint32 dataSize)
{
- const size_t addressSize = sizeof(typename ElfClass::Size);
- if (dataSize < addressSize) {
+ if (dataSize < 2 * sizeof(uint32)) {
WARNING("Areas note too short\n");
return B_BAD_DATA;
}
- uint64 areaCount = Get(*(const typename ElfClass::Size*)data);
+ uint32 areaCount = _ReadValue<uint32>(data, dataSize);
+ uint32 entrySize = _ReadValue<uint32>(data, dataSize);
typedef typename ElfClass::NoteAreaEntry Entry;
- const Entry* table = (Entry*)((const uint8*)data + addressSize);
- dataSize -= addressSize;
if (areaCount == 0)
return B_OK;
- // check area count
- if (areaCount > dataSize || areaCount * sizeof(Entry) >= dataSize) {
- WARNING("Areas note too short for area count\n");
+ // check entry size and area count
+ if (entrySize == 0 || dataSize == 0 || areaCount > dataSize
+ || dataSize - 1 < entrySize || areaCount * entrySize >=
dataSize) {
+ WARNING("Areas note: too short or invalid entry size (%"
B_PRIu32 ")\n",
+ entrySize);
return B_BAD_DATA;
}
// check, if strings are null-terminated
- const char* strings = (const char*)(table + areaCount);
- size_t stringsSize = dataSize - areaCount * sizeof(Entry);
+ const char* strings = (const char*)data + areaCount * entrySize;
+ size_t stringsSize = dataSize - areaCount * entrySize;
if (stringsSize == 0 || strings[stringsSize - 1] != '\0') {
WARNING("Areas note strings not terminated\n");
return B_BAD_DATA;
@@ -380,8 +393,8 @@ CoreFile::_ReadAreasNote(const void* data, uint32 dataSize)
for (uint64 i = 0; i < areaCount; i++) {
// get entry values
- Entry entry;
- memcpy(&entry, table, sizeof(entry));
+ Entry entry = {};
+ _ReadEntry(data, dataSize, entry, entrySize);
int32 id = Get(entry.na_id);
uint64 baseAddress = Get(entry.na_base);
@@ -413,8 +426,6 @@ CoreFile::_ReadAreasNote(const void* data, uint32 dataSize)
delete area;
return B_NO_MEMORY;
}
-
- table++;
}
return B_OK;
@@ -425,29 +436,29 @@ template<typename ElfClass>
status_t
CoreFile::_ReadImagesNote(const void* data, uint32 dataSize)
{
- const size_t addressSize = sizeof(typename ElfClass::Size);
- if (dataSize < addressSize) {
+ if (dataSize < 2 * sizeof(uint32)) {
WARNING("Images note too short\n");
return B_BAD_DATA;
}
- uint64 imageCount = Get(*(const typename ElfClass::Size*)data);
+ uint32 imageCount = _ReadValue<uint32>(data, dataSize);
+ uint32 entrySize = _ReadValue<uint32>(data, dataSize);
typedef typename ElfClass::NoteImageEntry Entry;
- const Entry* table = (Entry*)((const uint8*)data + addressSize);
- dataSize -= addressSize;
if (imageCount == 0)
return B_OK;
- // check image count
- if (imageCount > dataSize || imageCount * sizeof(Entry) >= dataSize) {
- WARNING("Images note too short for image count\n");
+ // check entry size and image count
+ if (entrySize == 0 || dataSize == 0 || imageCount > dataSize
+ || dataSize - 1 < entrySize || imageCount * entrySize
= dataSize) {+ WARNING("Images note: too short or invalid entry size (%"