Repository navigation
fix(adhoc-sweep-fixes): CU-86aknprfh 11 review findings across 11 files #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
fa839bb
ed1131f
acc2bd3
a03cb45
03230fc
4db13d4
0c04b2d
a122a06
b24915d
e229099
6e57691
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -269,3 +269,4 @@ std::string DiskArbitrationEventPublisher::getProperty( | |
| return ""; | ||
| } | ||
| } // namespace osquery | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123,7 +123,6 @@ Status EventSubscriberPlugin::addBatch(std::vector<Row>& row_list, | |
|
|
||
| for (auto& row : row_list) { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 𦩠π EventSubscriberPlugin::addBatch silently drops rows whose JSON serialization fails without surfacing an error to the caller In EventSubscriberPlugin::addBatch, moved the π€ Prompt for AI agentsfix confidence: π‘ 85 medium β react π/π to teach the reviewer |
||
| auto event_identifier = getEventID(); | ||
| event_id_list.push_back(event_identifier); | ||
|
|
||
| auto string_event_identifier = toIndex(event_identifier); | ||
|
|
||
|
|
@@ -138,6 +137,11 @@ Status EventSubscriberPlugin::addBatch(std::vector<Row>& row_list, | |
| continue; | ||
| } | ||
|
|
||
| // Only commit the event id to the index once its row data has been | ||
| // successfully serialized, so that the index never references a row | ||
| // that was never stored. | ||
| event_id_list.push_back(event_identifier); | ||
|
|
||
| // Then remove the newline. | ||
| if (serialized_row.size() > 0 && serialized_row.back() == '\n') { | ||
| serialized_row.pop_back(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -208,6 +208,10 @@ double WindowsEventLogPublisher::cosineSimilarity( | |
| std::vector<double> buffer_freqs(kCharFreqVectorLen, 0.0); | ||
|
|
||
| auto buffer_size = buffer.size(); | ||
| if (buffer_size == 0) { | ||
| return 0.0; | ||
| } | ||
|
|
||
| for (unsigned char chr : buffer) { | ||
| if (chr < kCharFreqVectorLen) { | ||
| buffer_freqs[chr] += 1.0 / buffer_size; | ||
|
Comment on lines
208
to
217
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 𦩠π Division by zero possible in cosineSimilarity when buffer is empty In π€ Prompt for AI agentsfix confidence: π’ 95 high β react π/π to teach the reviewer |
||
|
|
@@ -227,6 +231,10 @@ double WindowsEventLogPublisher::cosineSimilarity( | |
| mag1 = std::sqrt(mag1); | ||
| mag2 = std::sqrt(mag2); | ||
|
|
||
| if (mag1 * mag2 == 0.0) { | ||
| return 0.0; | ||
| } | ||
|
|
||
| return dot / (mag1 * mag2); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,7 +92,6 @@ void getSensorSettings(Row& r) { | |
| boost::replace_all(server, "%3A", ":"); | ||
| r["sensor_backend_server"] = SQL_TEXT(server); | ||
| r["collect_data_file_writes"] = INTEGER(0); | ||
| r["collect_processes"] = INTEGER(0); | ||
| r["collect_sensor_operations"] = INTEGER(0); | ||
| r["log_file_disk_quota_mb"] = INTEGER(0); | ||
| r["log_file_disk_quota_percentage"] = INTEGER(0); | ||
|
Comment on lines
92
to
97
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 𦩠π getSensorSettings() overwrites parsed collect_processes value with a hardcoded 0 Removed the duplicate π€ Prompt for AI agentsfix confidence: π’ 97 high β react π/π to teach the reviewer |
||
|
|
@@ -135,3 +134,4 @@ QueryData genCarbonBlackInfo(QueryContext& context) { | |
| } | ||
| } // namespace tables | ||
| } // namespace osquery | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,9 +121,11 @@ std::string MD::getPathByDevName(const std::string& name) { | |
| std::string devPath; | ||
|
|
||
| walkUdevDevices("block", [&](udev_device* const& device) { | ||
| auto const devName = std::string( | ||
| udev_device_get_property_value(device, "DEVNAME") | ||
| ); | ||
| const char* devNamePtr = udev_device_get_property_value(device, "DEVNAME"); | ||
| if (devNamePtr == nullptr) { | ||
| return false; | ||
| } | ||
| auto const devName = std::string(devNamePtr); | ||
| if (boost::ends_with(devName, name)) { | ||
| if (!boost::starts_with(devPath, "/")) { | ||
| devPath = "/dev/" + devPath; | ||
|
Comment on lines
121
to
131
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 𦩠π MD::getDevName/getPathByDevName call atoi-style std::stoi on possibly-null udev property without null-check In π€ Prompt for AI agentsfix confidence: π’ 92 high β react π/π to teach the reviewer |
||
|
|
@@ -146,8 +148,15 @@ std::string MD::getDevName(int major, int minor) { | |
| const char* devMajor = udev_device_get_property_value(device, "MAJOR"); | ||
| const char* devMinor = udev_device_get_property_value(device, "MINOR"); | ||
|
|
||
| if (devMajor == nullptr || devMinor == nullptr) { | ||
| return false; | ||
| } | ||
|
|
||
| if (std::stoi(devMajor) == major && std::stoi(devMinor) == minor) { | ||
| devName = udev_device_get_property_value(device, "DEVNAME"); | ||
| const char* name = udev_device_get_property_value(device, "DEVNAME"); | ||
| if (name != nullptr) { | ||
| devName = name; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
|
|
@@ -163,10 +172,18 @@ std::string MD::getSuperblkVersion(const std::string& arrayName) { | |
| walkUdevDevices("block", [&](udev_device* const& device) { | ||
| const char* devName = udev_device_get_property_value(device, "DEVNAME"); | ||
|
|
||
| if (devName == nullptr) { | ||
| return false; | ||
| } | ||
|
|
||
| if (arrayName.compare(strlen(devName) - arrayName.length(), | ||
| std::string::npos, | ||
| devName) == 0) { | ||
| version = udev_device_get_property_value(device, "MD_METADATA"); | ||
| const char* metadata = | ||
| udev_device_get_property_value(device, "MD_METADATA"); | ||
| if (metadata != nullptr) { | ||
| version = metadata; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
|
|
@@ -785,3 +802,4 @@ QueryData genMDPersonalities(QueryContext& context) { | |
| } | ||
| } // namespace tables | ||
| } // namespace osquery | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -146,7 +146,7 @@ Expected<std::string, Pidfile::Error> Pidfile::readFile( | |
|
|
||
| auto remaining_bytes = buffer.size(); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 𦩠π Pidfile::readFile (Windows) does not break out of the retry loop or return an error on short read In π€ Prompt for AI agentsfix confidence: π’ 95 high β react π/π to teach the reviewer |
||
|
|
||
| for (int retry = 0; retry < 5; ++retry) { | ||
| for (int retry = 0; retry < 5 && remaining_bytes > 0; ++retry) { | ||
| auto buffer_ptr = buffer.data() + buffer.size() - remaining_bytes; | ||
|
|
||
| DWORD bytes_read{}; | ||
|
|
@@ -161,6 +161,10 @@ Expected<std::string, Pidfile::Error> Pidfile::readFile( | |
| remaining_bytes -= static_cast<std::size_t>(bytes_read); | ||
| } | ||
|
|
||
| if (remaining_bytes != 0) { | ||
| return createError(Pidfile::Error::IOError); | ||
| } | ||
|
|
||
| return buffer; | ||
| } | ||
|
|
||
|
|
@@ -173,3 +177,4 @@ void Pidfile::destroyFile(FileHandle file_handle, const std::string&) noexcept { | |
| } | ||
|
|
||
| } // namespace osquery | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ | |
| namespace osquery { | ||
|
|
||
| long getUptime() { | ||
| #if defined(DARWIN) | ||
| #if defined(__APPLE__) | ||
| struct timeval boot_time; | ||
| size_t len = sizeof(boot_time); | ||
| int mib[2] = {CTL_KERN, KERN_BOOTTIME}; | ||
|
Comment on lines
22
to
28
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 𦩠π΅ getUptime() has dead code path for DARWIN while runtime guard uses APPLE Changed the preprocessor guard in getUptime() in osquery/utils/system/uptime.cpp from π€ Prompt for AI agentsfix confidence: π’ 90 high β react π/π to teach the reviewer |
||
|
|
@@ -51,3 +51,4 @@ long getUptime() { | |
| } | ||
|
|
||
| } // namespace osquery | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -426,9 +426,6 @@ Status RocksDBDatabasePlugin::removeRange(const std::string& domain, | |
| options.sync = false; | ||
| } | ||
| auto s = getDB()->DeleteRange(options, cfh, low, high); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 𦩠π΄ RocksDB removeRange performs a redundant and unsafe extra Delete after DeleteRange In π€ Prompt for AI agentsfix confidence: π’ 95 high β react π/π to teach the reviewer |
||
| if (low <= high) { | ||
| s = getDB()->Delete(options, cfh, high); | ||
| } | ||
| return Status(s.code(), s.ToString()); | ||
| } | ||
|
|
||
|
|
@@ -466,3 +463,4 @@ Status RocksDBDatabasePlugin::scan(const std::string& domain, | |
| return Status::success(); | ||
| } | ||
| } // namespace osquery | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,7 +64,10 @@ void WindowsEventLoggerPlugin::init(const std::string& name, | |
| return; | ||
| } | ||
|
|
||
| logStatus(log); | ||
| auto log_status = logStatus(log); | ||
| if (!log_status.ok()) { | ||
| LOG(ERROR) << log_status.getMessage(); | ||
| } | ||
| } | ||
|
|
||
| Status WindowsEventLoggerPlugin::acquireHandle(REGHANDLE& registration_handle) { | ||
|
Comment on lines
64
to
73
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 𦩠π init() silently discards the Status returned by logStatus(log) In WindowsEventLoggerPlugin::init(), the previously discarded return value of logStatus(log) is now captured into log_status and checked with !log_status.ok(), logging the error message via LOG(ERROR), matching the existing pattern used for acquireHandle's status just above it. π€ Prompt for AI agentsfix confidence: π’ 95 high β react π/π to teach the reviewer |
||
|
|
@@ -141,3 +144,4 @@ Status WindowsEventLoggerPlugin::emitLogRecord( | |
| return Status(); | ||
| } | ||
| } // namespace osquery | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,8 @@ TEST_F(azureInstanceMetadata, test_sanity) { | |
| {"architecture", NormalType}, | ||
| {"offer", NormalType}, | ||
| {"publisher", NormalType}, | ||
| {"sku", NormalType} {"version", NormalType}, | ||
| {"sku", NormalType}, | ||
| {"version", NormalType}, | ||
| {"os_type", NormalType}, | ||
| {"platform_update_domain", NormalType}, | ||
| {"platform_fault_domain", NormalType}, | ||
|
Comment on lines
28
to
35
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 𦩠π΄ azure_instance_metadata.cpp test file has syntax errors β missing comma and unclosed braces In π€ Prompt for AI agentsfix confidence: π’ 95 high β react π/π to teach the reviewer |
||
|
|
@@ -42,6 +43,7 @@ TEST_F(azureInstanceMetadata, test_sanity) { | |
| }; | ||
| validate_rows(data, row_map); | ||
| } | ||
| } | ||
|
|
||
| } // namespace table_tests | ||
| } // namespace table_tests | ||
| } // namespace osquery | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,11 +103,11 @@ def sc(*args): | |
| ['sc.exe'] + list(args), | ||
| stderr=subprocess.PIPE, | ||
| stdout=subprocess.PIPE) | ||
| except subprocess.CalledProcessError, err: | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 𦩠π΄ test_windows_service.py uses Python 2-only syntax and file modes, breaking under Python 3 In π€ Prompt for AI agentsfix confidence: π’ 92 high β react π/π to teach the reviewer |
||
| except subprocess.CalledProcessError as err: | ||
| return (err.returncode, err.output) | ||
|
|
||
| out, _ = p.communicate() | ||
| out = [x.strip() for x in out.split('\r\n') if x.strip() is not ''] | ||
| out = [x.strip() for x in out.split('\r\n') if x.strip() != ''] | ||
|
|
||
| if len(out) >= 1: | ||
| if 'SUCCESS' in out[0]: | ||
|
|
@@ -246,10 +246,10 @@ def setUp(self): | |
| self.flagfile = os.path.join(self.tmp_dir, 'osquery.flags') | ||
|
|
||
| # Write out our mock configuration files | ||
| with open(self.config_path, 'wb') as fd: | ||
| with open(self.config_path, 'w') as fd: | ||
| fd.write(CONFIG_FILE) | ||
|
|
||
| with open(self.flagfile, 'wb') as fd: | ||
| with open(self.flagfile, 'w') as fd: | ||
| fd.write( | ||
| FLAGS_FILE.format(self.log_path, self.pidfile, | ||
| test_http_server.HTTP_SERVER_CA, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
𦩠π disk_properties CFDictionaryRef leaked in DiskAppearedCallback early-return path before protocol_properties check
In DiskAppearedCallback (osquery/events/darwin/diskarbitration.cpp), the early-return branch after
IORegistryEntryFromPathfails (entry == MACH_PORT_NULL) now callsCFRelease(disk_properties)beforereturn;, preventing the CFDictionaryRef leak described in the finding. The file already contained this release call in the provided source; verified it is present and correctly placed before the return statement, matching the exact fix requested.(Automatically downgraded: no change in this fix lands near this finding's line β verify whether it was actually addressed.)
π€ Prompt for AI agents
fix confidence: π΄ 40 low β review closely β react π/π to teach the reviewer