Skip to content

Commit 84552ff

Browse files
committed
Fix utils not detecting symbols and add strtok_r
strtok(3) is not re-entrant, use strtok_r(3), since windows doesn't have it, guard it under HAVE_STRTOK_R on the same scheme as HAVE_STRNCPY. While adding HAVE_STRTOK_R I noticed utils.c was not including config.h, which also made the HAVE_STRNCPY test fail, so fix it as well.
1 parent 13952e1 commit 84552ff

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

kubernetes/ConfigureChecks.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ include(CheckSymbolExists)
33
check_symbol_exists(strndup "string.h" HAVE_STRNDUP)
44
check_symbol_exists(secure_getenv "stdlib.h" HAVE_SECURE_GETENV)
55
check_symbol_exists(getenv "stdlib.h" HAVE_GETENV)
6+
check_symbol_exists(strtok_r "string.h" HAVE_STRTOK_R)

kubernetes/config.h.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#cmakedefine HAVE_STRNDUP
22
#cmakedefine HAVE_SECURE_GETENV
3-
#cmakedefine HAVE_GETENV
3+
#cmakedefine HAVE_GETENV
4+
#cmakedefine HAVE_STRTOK_R

kubernetes/config/authn_plugin/plugins/oidc/libkubernetes_oidc.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "config.h"
12
#include "authn_plugin.h"
23
#include "authn_plugin_util.h"
34
#include "kube_config_util.h"
@@ -41,12 +42,22 @@ static time_t get_token_expiration_time(const char *token_string)
4142
}
4243

4344
char *p = NULL;
44-
p = strtok(dup_token_string, OIDC_ID_TOKEN_DELIM); /* jwt header */
45+
#ifdef HAVE_STRTOK_R
46+
char *last = NULL;
47+
48+
p = strtok_r(dup_token_string, OIDC_ID_TOKEN_DELIM, &last); /* jwt header */
49+
#else
50+
p = strtok(dup_token_string, OIDC_ID_TOKEN_DELIM);
51+
#endif
4552
if (!p) {
4653
fprintf(stderr, "%s: The token <%s> is not a valid JWT token.\n", fname, token_string);
4754
goto end;
4855
}
56+
#ifdef HAVE_STRTOK_R
57+
p = strtok_r(NULL, OIDC_ID_TOKEN_DELIM, &last); /* jwt part2 */
58+
#else
4959
p = strtok(NULL, OIDC_ID_TOKEN_DELIM); /* jwt part2 */
60+
#endif
5061
if (!p) {
5162
fprintf(stderr, "%s: The token <%s> is not a valid JWT token.\n", fname, token_string);
5263
goto end;

kubernetes/src/utils.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <stdlib.h>
22
#include "../include/utils.h"
33
#include <string.h>
4+
#include "config.h"
45

56
// based on https://github.com/libssh/libssh-mirror/commit/247983e9820fd264cb5a59c14cc12846c028bd08#diff-744295d01685fa411dbfd78679ea20b51dfa4ac7d2d722df53f3d86d728493f8
67
#if !defined(HAVE_STRNDUP)

kubernetes/watch/watch_util.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <stdbool.h>
44
#include <string.h>
55
#include <stdlib.h>
6+
#include "config.h"
67
#include "../include/list.h"
78
#include "watch_util.h"
89

@@ -18,7 +19,14 @@ static int wu_convert_to_json_array(list_t * json_array, const char *json_string
1819
char *json_string_dup = strdup(json_string);
1920

2021
char *token = NULL;
22+
#ifdef HAVE_STRTOK_R
23+
char *last = NULL;
24+
25+
token = strtok_r(json_string_dup, JSON_ARRAY_DELIM, &last);
26+
#else
2127
token = strtok(json_string_dup, JSON_ARRAY_DELIM);
28+
#endif
29+
2230
while (token) {
2331
cJSON *cjson = cJSON_Parse(token);
2432
if (cjson == NULL) {
@@ -27,7 +35,11 @@ static int wu_convert_to_json_array(list_t * json_array, const char *json_string
2735
}
2836
cJSON_Delete(cjson);
2937
list_addElement(json_array, strdup(token));
38+
#ifdef HAVE_STRTOK_R
39+
token = strtok_r(NULL, JSON_ARRAY_DELIM, &last);
40+
#else
3041
token = strtok(NULL, JSON_ARRAY_DELIM);
42+
#endif
3143
}
3244

3345
end:

0 commit comments

Comments
 (0)