From 8f16ff112436c115996dfc19f3d8754d0cb76bc4 Mon Sep 17 00:00:00 2001 From: daxia16 <110370108+daxia16@users.noreply.github.com> Date: Tue, 15 Nov 2022 03:41:13 +0800 Subject: [PATCH] Initialize pointer variable platform before use in get_num_of_asic (#12351) - Why I did it Pointer variable platform not initialized before use in get_num_of_asic of src/systemd-sonic-generator/systemd-sonic-generator.c. Then wild pointer will introduce undetermined exception when use in snprintf at line 545 . Other pointers in this function like token will be assigned the value before use, and will not have such issue. - How I did it Initialized pointer platform to NULL when defined and before use. --- src/systemd-sonic-generator/systemd-sonic-generator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/systemd-sonic-generator/systemd-sonic-generator.c b/src/systemd-sonic-generator/systemd-sonic-generator.c index 0c419893c3..9267a48aa4 100644 --- a/src/systemd-sonic-generator/systemd-sonic-generator.c +++ b/src/systemd-sonic-generator/systemd-sonic-generator.c @@ -516,7 +516,7 @@ int get_num_of_asic() { FILE *fp; char *line = NULL; char* token; - char* platform; + char* platform = NULL; char* saveptr; size_t len = 0; ssize_t nread;