Skip to content

Commit 6024620

Browse files
authored
Fix Windows registry name crashes (netdata#20097)
* Fix Windows registry name crashes and optimize memory with Judy arrays This commit addresses two key issues with Windows performance counter registry handling: 1. Fixes crashes due to improper registry data parsing: - Added comprehensive validation of registry data structure - Added bounds checking to prevent buffer overruns - Added validation of ID string conversion - Improved error logging for malformed registry entries 2. Optimizes memory usage with Judy arrays: - Replaced fixed-size array with memory-efficient Judy array - Memory usage now scales with actual data rather than highest ID - Eliminated arbitrary limit on registry ID values - Added proper resource cleanup on shutdown Added unit tests to verify functionality and demonstrate memory efficiency with sparseness statistics. Run with: -W perflibnamestest * Enhance Windows registry validation and add comprehensive tests
1 parent 7ce3f10 commit 6024620

5 files changed

Lines changed: 656 additions & 43 deletions

File tree

src/collectors/windows.plugin/windows_plugin.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ static void windows_main_cleanup(void *pptr)
122122

123123
static_thread->enabled = NETDATA_MAIN_THREAD_EXITING;
124124

125+
// Cleanup registry resources
126+
PerflibNamesRegistryCleanup();
127+
125128
static_thread->enabled = NETDATA_MAIN_THREAD_EXITED;
126129

127130
worker_unregister();

src/daemon/main.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,9 @@ int netdata_main(int argc, char **argv) {
404404
if (dyncfg_unittest()) return 1;
405405
if (unittest_waiting_queue()) return 1;
406406
if (uuidmap_unittest()) return 1;
407+
#ifdef OS_WINDOWS
408+
if (perflibnamestest_main()) return 1;
409+
#endif
407410
sqlite_library_shutdown();
408411
fprintf(stderr, "\n\nALL TESTS PASSED\n\n");
409412
return 0;
@@ -455,6 +458,10 @@ int netdata_main(int argc, char **argv) {
455458
else if(strcmp(optarg, "perflibdump") == 0) {
456459
return windows_perflib_dump(optind + 1 > argc ? NULL : argv[optind]);
457460
}
461+
else if(strcmp(optarg, "perflibnamestest") == 0) {
462+
unittest_running = true;
463+
return perflibnamestest_main();
464+
}
458465
#endif
459466
#ifdef ENABLE_DBENGINE
460467
else if(strcmp(optarg, "mctest") == 0) {

src/daemon/unit_test.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@ void dbengine_stress_test(unsigned TEST_DURATION_SEC, unsigned DSET_CHARTS, unsi
2323

2424
bool command_argument_sanitization_tests();
2525

26+
#ifdef OS_WINDOWS
27+
int perflibnamestest_main(void);
28+
#endif
29+
2630
#endif /* NETDATA_UNIT_TEST_H */

0 commit comments

Comments
 (0)