mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2026-07-02 00:06:12 -04:00
Polish security fixes with minor improvements
- Remove redundant null termination for short strings - Use descriptive variable names in cleanup loop - Cache strlen results to avoid O(n²) complexity in string concatenation - Add bounds checks before string operations Co-authored-by: squassina <8495707+squassina@users.noreply.github.com>
This commit is contained in:
parent
e2649dd84f
commit
12fe0abca1
3 changed files with 12 additions and 7 deletions
|
|
@ -598,11 +598,16 @@ 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) {
|
||||
strncat(combined, ",", total_len - strlen(combined));
|
||||
if (i > 0 && current_len < total_len) {
|
||||
strncat(combined, ",", total_len - current_len);
|
||||
current_len = strlen(combined);
|
||||
}
|
||||
if (current_len < total_len) {
|
||||
strncat(combined, values[i], total_len - current_len);
|
||||
current_len = strlen(combined);
|
||||
}
|
||||
strncat(combined, values[i], total_len - strlen(combined));
|
||||
}
|
||||
|
||||
return combined;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue