Final security improvements based on code review

- Add LAYOUT_ABBR_SIZE constant to avoid magic numbers
- Track allocated argv entries to properly free on error
- Simplify strncat bounds checking using strlen for accuracy
- Ensure all allocated memory is freed in error paths

Co-authored-by: squassina <8495707+squassina@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-02-18 08:58:36 +00:00
parent d017fc4837
commit e2649dd84f
3 changed files with 20 additions and 24 deletions

View file

@ -598,25 +598,11 @@ static char *combine_args_until_empty(char *values[], int count) {
}
combined[0] = '\0';
size_t current_len = 0;
for (int i = 0; i < first_empty; i++) {
if (i > 0 && current_len < total_len) {
size_t remaining = total_len - current_len;
size_t to_copy = (remaining < 1) ? 0 : 1;
if (to_copy > 0) {
strncat(combined, ",", to_copy);
current_len += to_copy;
}
}
if (current_len < total_len) {
size_t remaining = total_len - current_len;
size_t val_len = strlen(values[i]);
size_t to_copy = (val_len < remaining) ? val_len : remaining;
if (to_copy > 0) {
strncat(combined, values[i], to_copy);
current_len += to_copy;
}
if (i > 0) {
strncat(combined, ",", total_len - strlen(combined));
}
strncat(combined, values[i], total_len - strlen(combined));
}
return combined;