Skip to content

Conversation

@michaelbeale-IL
Copy link
Contributor

Potential fix for https://github.com/IntelLabs/async-toolkit/security/code-scanning/146

To fix the issue, calls to strcpy that copy untrusted data into a buffer, especially those that perform unbounded writes, should be replaced with their bounded counterparts, such as strncpy or memcpy with an explicit buffer size. Here, before strcpy(entry->member, member); the buffer is allocated with leak_realloc(entry->member, strlen(member) + 1), guaranteeing enough space for the string and its null terminator. To future-proof the code and ensure that the buffer is not overrun, use strncpy(entry->member, member, strlen(member) + 1);. This change should also be applied to the other similar lines (strcpy(entry->archive,archive); on line 123 and strcpy(entry->output,output); on line 129). However, since the data is allocated with the buffer size exactly matching the string length (plus null terminator), using the bounded version provides additional security by preventing accidental overruns.

Edits are confined to the region of the add_recent function in async-toolkit/atools/lib/archive.c, lines 122-129.


Suggested fixes powered by Copilot Autofix. Review carefully before merging.

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>

entry->archive=leak_realloc(entry->archive,strlen(archive)+1);
strcpy(entry->archive,archive);
strncpy(entry->archive,archive,strlen(archive)+1);

Check failure

Code scanning / CodeQL

Possibly wrong buffer size in string copy Critical

Potentially unsafe call to strncpy; third argument should be size of destination.

entry->member=leak_realloc(entry->member,strlen(member)+1);
strcpy(entry->member,member);
strncpy(entry->member,member,strlen(member)+1);

Check failure

Code scanning / CodeQL

Possibly wrong buffer size in string copy Critical

Potentially unsafe call to strncpy; third argument should be size of destination.

entry->output=leak_realloc(entry->output,strlen(output)+1);
strcpy(entry->output,output);
strncpy(entry->output,output,strlen(output)+1);

Check failure

Code scanning / CodeQL

Possibly wrong buffer size in string copy Critical

Potentially unsafe call to strncpy; third argument should be size of destination.
@michaelbeale-IL michaelbeale-IL marked this pull request as ready for review October 31, 2025 00:10
@michaelbeale-IL michaelbeale-IL merged commit 566a7ee into main Oct 31, 2025
2 of 4 checks passed
@michaelbeale-IL michaelbeale-IL deleted the alert-autofix-146 branch October 31, 2025 00:11
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.

1 participant