Skip to content

Fix core subsystem logic and safety bugs#1723

Open
sirus20x6 wants to merge 1 commit intorakshasa:masterfrom
sirus20x6:fix/core-logic
Open

Fix core subsystem logic and safety bugs#1723
sirus20x6 wants to merge 1 commit intorakshasa:masterfrom
sirus20x6:fix/core-logic

Conversation

@sirus20x6
Copy link
Copy Markdown
Contributor

Summary

  • Fix inverted condition in apply_ip_tables_size_data that threw when table was found and dereferenced end() when not
  • Fix always-true condition in remove_newlines (|| should be &&, add \r check)
  • Add NULL FILE* check in log_vmmap_dump before fprintf
  • Fix unreachable emit_changed() in ListFocus::erase by restructuring control flow
  • Fix string::npos + 7 wraparound in decode_data_uri by checking find() before adding offset
  • Fix off-by-one in signal handler bounds checks (>>= for array indexed by HIGHEST_SIGNAL)
  • Add input length validation in find_hex to prevent out-of-bounds reads on short hash strings
  • Initialize group variable and check parse return value in download_tracker_insert
  • Add mask_bits==0 special case in CIDR parsing to avoid undefined behavior from shift by 32
  • Catch all exceptions (not just bencode_error) for stack cleanup in command_function_call_object
  • Add NULL check before closedir in Directory::is_valid
  • Add empty file list check in retrieve_d_base_filename (matches existing guard in retrieve_d_base_path)

Test plan

  • Test ip_tables.size_data command with valid and invalid table names
  • Test base64 decoding with strings containing \r\n line endings
  • Test log.vmmap.dump with an invalid/unwritable path
  • Test CIDR /0 address range parsing
  • Test find_hex with short/empty hash strings
  • Build and verify no regressions in signal handling

🤖 Generated with Claude Code

- Fix inverted condition in apply_ip_tables_size_data (!=→==)
- Fix always-true condition in remove_newlines (||→&&, add \r check)
- Add NULL FILE* check in log_vmmap_dump before fprintf
- Fix unreachable emit_changed() in ListFocus::erase by restructuring
- Fix npos+7 wraparound in decode_data_uri by checking find() before offset
- Fix off-by-one in signal handler bounds checks (>→>=)
- Add input length validation in find_hex
- Initialize group and check parse return in download_tracker_insert
- Add mask_bits==0 special case to avoid UB shift by 32
- Catch all exceptions (not just bencode_error) for stack cleanup in parse_commands
- Add NULL check before closedir in Directory::is_valid
- Add empty file list check in retrieve_d_base_filename (matches retrieve_d_base_path)
DownloadList::iterator
DownloadList::find_hex(const char* hash) {
if (strlen(hash) < 40)
return end();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should throw torrent::input_error when not 40.

if (download->file_list()->is_multi_file())
base = &download->file_list()->frozen_root_dir();
else if (download->file_list()->empty())
return std::string();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this is right, as we don't want to return empty strings that get used in user's custom commands.

Empty should either throw an input or internal error (as empty filelist is supposed to be impossible to load iirc), or make a fake one using frozen_root_dir()+name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants