From 9b6bc37bf4a92b66c03399b8a10a6708b8a65aec Mon Sep 17 00:00:00 2001 From: Stepan Blyschak Date: Thu, 2 Feb 2023 17:16:04 +0200 Subject: [PATCH] [systemd-sonic-generator] Fix overlapping strings being passed to strcpy/strcat Signed-off-by: Stepan Blyschak --- src/systemd-sonic-generator/systemd-sonic-generator.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/systemd-sonic-generator/systemd-sonic-generator.c b/src/systemd-sonic-generator/systemd-sonic-generator.c index 273fd5452b74..74f08fe39612 100644 --- a/src/systemd-sonic-generator/systemd-sonic-generator.c +++ b/src/systemd-sonic-generator/systemd-sonic-generator.c @@ -608,11 +608,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);