[systemd-sonic-generator] Fix overlapping strings being passed to strcpy/strcat (#13647) (#13891)

This commit is contained in:
mssonicbld 2023-02-21 02:11:46 +08:00 committed by GitHub
parent 785f9c3f0c
commit daacf6850e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -592,11 +592,14 @@ int ssg_main(int argc, char **argv) {
for (int i = 0; i < num_unit_files; i++) {
unit_instance = strdup(unit_files[i]);
if ((num_asics == 1) && strstr(unit_instance, "@") != NULL) {
prefix = strtok_r(unit_instance, "@", &saveptr);
suffix = strtok_r(NULL, "@", &saveptr);
prefix = strdup(strtok_r(unit_instance, "@", &saveptr));
suffix = strdup(strtok_r(NULL, "@", &saveptr));
strcpy(unit_instance, prefix);
strcat(unit_instance, suffix);
free(prefix);
free(suffix);
}
num_targets = get_install_targets(unit_instance, targets);