Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions kubernetes/ConfigureChecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ include(CheckSymbolExists)
check_symbol_exists(strndup "string.h" HAVE_STRNDUP)
check_symbol_exists(secure_getenv "stdlib.h" HAVE_SECURE_GETENV)
check_symbol_exists(getenv "stdlib.h" HAVE_GETENV)
check_symbol_exists(strtok_r "string.h" HAVE_STRTOK_R)
3 changes: 2 additions & 1 deletion kubernetes/config.h.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#cmakedefine HAVE_STRNDUP
#cmakedefine HAVE_SECURE_GETENV
#cmakedefine HAVE_GETENV
#cmakedefine HAVE_GETENV
#cmakedefine HAVE_STRTOK_R
13 changes: 12 additions & 1 deletion kubernetes/config/authn_plugin/plugins/oidc/libkubernetes_oidc.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include "authn_plugin.h"
#include "authn_plugin_util.h"
#include "kube_config_util.h"
Expand Down Expand Up @@ -41,12 +42,22 @@ 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 */
#ifdef HAVE_STRTOK_R
char *last = NULL;

p = strtok_r(dup_token_string, OIDC_ID_TOKEN_DELIM, &last); /* jwt header */
#else
p = strtok(dup_token_string, OIDC_ID_TOKEN_DELIM);
#endif
if (!p) {
fprintf(stderr, "%s: The token <%s> is not a valid JWT token.\n", fname, token_string);
goto end;
}
#ifdef HAVE_STRTOK_R
p = strtok_r(NULL, OIDC_ID_TOKEN_DELIM, &last); /* jwt part2 */
#else
p = strtok(NULL, OIDC_ID_TOKEN_DELIM); /* jwt part2 */
#endif
if (!p) {
fprintf(stderr, "%s: The token <%s> is not a valid JWT token.\n", fname, token_string);
goto end;
Expand Down
1 change: 1 addition & 0 deletions kubernetes/src/utils.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdlib.h>
#include "../include/utils.h"
#include <string.h>
#include "config.h"

// based on https://github.com/libssh/libssh-mirror/commit/247983e9820fd264cb5a59c14cc12846c028bd08#diff-744295d01685fa411dbfd78679ea20b51dfa4ac7d2d722df53f3d86d728493f8
#if !defined(HAVE_STRNDUP)
Expand Down
12 changes: 12 additions & 0 deletions kubernetes/watch/watch_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include "config.h"
#include "../include/list.h"
#include "watch_util.h"

Expand All @@ -18,7 +19,14 @@ 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;
#ifdef HAVE_STRTOK_R
char *last = NULL;

token = strtok_r(json_string_dup, JSON_ARRAY_DELIM, &last);
#else
token = strtok(json_string_dup, JSON_ARRAY_DELIM);
#endif

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

end:
Expand Down