Skip to content

Don't use strtok(3) #276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
static time_t get_token_expiration_time(const char *token_string)
{
static char fname[] = "get_token_expiration_time()";
char *last;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: please set to explicit NULL


time_t expiration_time = 0;

Expand All @@ -41,12 +42,12 @@ static time_t get_token_expiration_time(const char *token_string)
}

char *p = NULL;
p = strtok(dup_token_string, OIDC_ID_TOKEN_DELIM); /* jwt header */
p = strtok_r(dup_token_string, OIDC_ID_TOKEN_DELIM, &last); /* jwt header */
if (!p) {
fprintf(stderr, "%s: The token <%s> is not a valid JWT token.\n", fname, token_string);
goto end;
}
p = strtok(NULL, OIDC_ID_TOKEN_DELIM); /* jwt part2 */
p = strtok_r(NULL, OIDC_ID_TOKEN_DELIM, &last); /* jwt part2 */
if (!p) {
fprintf(stderr, "%s: The token <%s> is not a valid JWT token.\n", fname, token_string);
goto end;
Expand Down
6 changes: 4 additions & 2 deletions kubernetes/watch/watch_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

static int wu_convert_to_json_array(list_t * json_array, const char *json_string)
{
char *last;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too wrt NULL


if (!json_string || '\0' == json_string[0] || !json_array) {
return -1;
}
Expand All @@ -18,7 +20,7 @@ static int wu_convert_to_json_array(list_t * json_array, const char *json_string
char *json_string_dup = strdup(json_string);

char *token = NULL;
token = strtok(json_string_dup, JSON_ARRAY_DELIM);
token = strtok_r(json_string_dup, JSON_ARRAY_DELIM, &last);
while (token) {
cJSON *cjson = cJSON_Parse(token);
if (cjson == NULL) {
Expand All @@ -27,7 +29,7 @@ static int wu_convert_to_json_array(list_t * json_array, const char *json_string
}
cJSON_Delete(cjson);
list_addElement(json_array, strdup(token));
token = strtok(NULL, JSON_ARRAY_DELIM);
token = strtok_r(NULL, JSON_ARRAY_DELIM, &last);
}

end:
Expand Down