Skip to content

require a terminator within maxlen in FIRCLSReadString - #16428

Open
isl-Ramzi wants to merge 1 commit into
firebase:mainfrom
isl-Ramzi:readstring-terminator-check
Open

require a terminator within maxlen in FIRCLSReadString#16428
isl-Ramzi wants to merge 1 commit into
firebase:mainfrom
isl-Ramzi:readstring-terminator-check

Conversation

@isl-Ramzi

Copy link
Copy Markdown
Contributor

FIRCLSReadString probes at most maxlen bytes to prove an address points at a readable, terminated string, but when no terminator turns up in that window it still falls through to *dest = src; return true. It never copies, so the caller gets a pointer it believes is terminated while only maxlen bytes were actually checked. All three call sites in FIRCLSProcess.c then walk it without a bound: the Swift crash_info message (maxlen 256) goes to FIRCLSRedactUUID, which strchrs past the window and writes '*' bytes into it, and then to FIRCLSFileWriteArrayEntryHexEncodedString, which strlens it, so a fatal-error annotation longer than 256 bytes gets neighbouring library memory hex-encoded into the report, or faults inside the handler and costs us the whole report. Moving the success return into the terminator branch keeps the contract the callers already rely on.

@gemini-code-assist

Copy link
Copy Markdown
Contributor
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

@paulb777

Copy link
Copy Markdown
Member

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request modifies the 'FIRCLSReadString' function to return false if a null terminator is not found within the specified 'maxlen' range, and adds corresponding unit tests. The review feedback points out a potential crash in the new unit tests where 'strlen' could be called on a NULL pointer if 'FIRCLSReadString' fails, and suggests guarding the assertion to prevent test suite crashes.

Comment on lines +87 to +89
XCTAssertTrue(FIRCLSReadString((vm_address_t)buffer, &string, 32));
XCTAssertEqual(string, (char *)buffer);
XCTAssertEqual(strlen(string), (size_t)31);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

low

Since continueAfterFailure is YES by default in XCTestCase, if FIRCLSReadString fails, the test will continue and call strlen(string). Passing NULL to strlen will cause a crash (segmentation fault), which abruptly terminates the test suite run. It is safer to guard the strlen check or assert that string is not NULL before calling strlen.

  XCTAssertTrue(FIRCLSReadString((vm_address_t)buffer, &string, 32));
  XCTAssertEqual(string, (char *)buffer);
  if (string != NULL) {
    XCTAssertEqual(strlen(string), (size_t)31);
  }

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants