Skip to content

Commit

Permalink
fix(mdns): Fix name mangling not to use strcpy()
Browse files Browse the repository at this point in the history
Since it was flagged by clang-tidy as insecture API
  • Loading branch information
david-cermak committed Jan 13, 2025
1 parent 51e5e56 commit c84ce1e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions components/mdns/mdns.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,13 @@ static char *_mdns_mangle_name(char *in)
}
sprintf(ret, "%s-2", in);
} else {
ret = malloc(strlen(in) + 2); //one extra byte in case 9-10 or 99-100 etc
size_t in_len = strlen(in);
ret = malloc(in_len + 2); //one extra byte in case 9-10 or 99-100 etc
if (ret == NULL) {
HOOK_MALLOC_FAILED;
return NULL;
}
strcpy(ret, in);
memcpy(ret, in, in_len);
int baseLen = p - in; //length of 'bla' in 'bla-123'
//overwrite suffix with new suffix
sprintf(ret + baseLen, "-%d", suffix + 1);
Expand Down

0 comments on commit c84ce1e

Please sign in to comment.