Replace strtok in systemd-sonic-generator (#11710)
Signed-off-by: maipbui <maibui@microsoft.com> <!-- Please make sure you've read and understood our contributing guidelines: https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md ** Make sure all your commits include a signature generated with `git commit -s` ** If this is a bug fix, make sure your description includes "fixes #xxxx", or "closes #xxxx" or "resolves #xxxx" Please provide the following information: --> #### Why I did it Replace unsafe functions to safe functions #### How I did it Replace `strtok()` by `strtok_r()` #### How to verify it #### Which release branch to backport (provide reason below if selected) <!-- - Note we only backport fixes to a release branch, *not* features! - Please also provide a reason for the backporting below. - e.g. - [x] 202006 --> - [ ] 201811 - [ ] 201911 - [ ] 202006 - [ ] 202012 - [ ] 202106 - [ ] 202111 - [ ] 202205 #### Description for the changelog <!-- Write a short (one line) summary that describes the changes in this pull request for inclusion in the changelog: --> #### Link to config_db schema for YANG module changes <!-- Provide a link to config_db schema for the table for which YANG model is defined Link should point to correct section on https://github.com/Azure/sonic-buildimage/blob/master/src/sonic-yang-models/doc/Configuration.md --> #### A picture of a cute animal (not mandatory but encouraged)
This commit is contained in:
parent
ddf3110f36
commit
dd42d828a4
@ -121,6 +121,7 @@ static int get_install_targets_from_line(char* target_string, char* install_type
|
|||||||
***/
|
***/
|
||||||
char* token;
|
char* token;
|
||||||
char* target;
|
char* target;
|
||||||
|
char* saveptr;
|
||||||
char final_target[PATH_MAX];
|
char final_target[PATH_MAX];
|
||||||
int num_targets = 0;
|
int num_targets = 0;
|
||||||
|
|
||||||
@ -135,8 +136,8 @@ static int get_install_targets_from_line(char* target_string, char* install_type
|
|||||||
strip_trailing_newline(target);
|
strip_trailing_newline(target);
|
||||||
|
|
||||||
if (strstr(target, "%") != NULL) {
|
if (strstr(target, "%") != NULL) {
|
||||||
char* prefix = strtok(target, ".");
|
char* prefix = strtok_r(target, ".", &saveptr);
|
||||||
char* suffix = strtok(NULL, ".");
|
char* suffix = strtok_r(NULL, ".", &saveptr);
|
||||||
int prefix_len = strlen(prefix);
|
int prefix_len = strlen(prefix);
|
||||||
|
|
||||||
strncpy(final_target, prefix, prefix_len - 2);
|
strncpy(final_target, prefix, prefix_len - 2);
|
||||||
@ -516,6 +517,7 @@ int get_num_of_asic() {
|
|||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
char* token;
|
char* token;
|
||||||
char* platform;
|
char* platform;
|
||||||
|
char* saveptr;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
ssize_t nread;
|
ssize_t nread;
|
||||||
bool ans;
|
bool ans;
|
||||||
@ -534,8 +536,8 @@ int get_num_of_asic() {
|
|||||||
while ((nread = getline(&line, &len, fp)) != -1) {
|
while ((nread = getline(&line, &len, fp)) != -1) {
|
||||||
if ((strstr(line, "onie_platform") != NULL) ||
|
if ((strstr(line, "onie_platform") != NULL) ||
|
||||||
(strstr(line, "aboot_platform") != NULL)) {
|
(strstr(line, "aboot_platform") != NULL)) {
|
||||||
token = strtok(line, "=");
|
token = strtok_r(line, "=", &saveptr);
|
||||||
platform = strtok(NULL, "=");
|
platform = strtok_r(NULL, "=", &saveptr);
|
||||||
strip_trailing_newline(platform);
|
strip_trailing_newline(platform);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -547,8 +549,8 @@ int get_num_of_asic() {
|
|||||||
if (fp != NULL) {
|
if (fp != NULL) {
|
||||||
while ((nread = getline(&line, &len, fp)) != -1) {
|
while ((nread = getline(&line, &len, fp)) != -1) {
|
||||||
if (strstr(line, "NUM_ASIC") != NULL) {
|
if (strstr(line, "NUM_ASIC") != NULL) {
|
||||||
token = strtok(line, "=");
|
token = strtok_r(line, "=", &saveptr);
|
||||||
str_num_asic = strtok(NULL, "=");
|
str_num_asic = strtok_r(NULL, "=", &saveptr);
|
||||||
strip_trailing_newline(str_num_asic);
|
strip_trailing_newline(str_num_asic);
|
||||||
if (str_num_asic != NULL){
|
if (str_num_asic != NULL){
|
||||||
sscanf(str_num_asic, "%d",&num_asic);
|
sscanf(str_num_asic, "%d",&num_asic);
|
||||||
@ -571,6 +573,7 @@ int ssg_main(int argc, char **argv) {
|
|||||||
char* unit_instance;
|
char* unit_instance;
|
||||||
char* prefix;
|
char* prefix;
|
||||||
char* suffix;
|
char* suffix;
|
||||||
|
char* saveptr;
|
||||||
int num_unit_files;
|
int num_unit_files;
|
||||||
int num_targets;
|
int num_targets;
|
||||||
int r;
|
int r;
|
||||||
@ -589,8 +592,8 @@ int ssg_main(int argc, char **argv) {
|
|||||||
for (int i = 0; i < num_unit_files; i++) {
|
for (int i = 0; i < num_unit_files; i++) {
|
||||||
unit_instance = strdup(unit_files[i]);
|
unit_instance = strdup(unit_files[i]);
|
||||||
if ((num_asics == 1) && strstr(unit_instance, "@") != NULL) {
|
if ((num_asics == 1) && strstr(unit_instance, "@") != NULL) {
|
||||||
prefix = strtok(unit_instance, "@");
|
prefix = strtok_r(unit_instance, "@", &saveptr);
|
||||||
suffix = strtok(NULL, "@");
|
suffix = strtok_r(NULL, "@", &saveptr);
|
||||||
|
|
||||||
strcpy(unit_instance, prefix);
|
strcpy(unit_instance, prefix);
|
||||||
strcat(unit_instance, suffix);
|
strcat(unit_instance, suffix);
|
||||||
|
Reference in New Issue
Block a user