Skip to content

Commit 4ded23a

Browse files
Copilotlpcox
andcommitted
fix: add missing secure_getenv initialization code
Add missing declarations and initialization functions for real_secure_getenv: - Add real_secure_getenv function pointer declaration - Add secure_getenv_init_once pthread_once control - Add init_real_secure_getenv_once() initialization function - Add init_real_secure_getenv() wrapper function This fixes the compilation error in the Docker build where secure_getenv was being called before its function pointer was initialized. Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
1 parent 56f6c7c commit 4ded23a

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

containers/agent/one-shot-token/one-shot-token.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ static pthread_mutex_t token_mutex = PTHREAD_MUTEX_INITIALIZER;
4545
/* Pointer to the real getenv function */
4646
static char *(*real_getenv)(const char *name) = NULL;
4747

48+
/* Pointer to the real secure_getenv function */
49+
static char *(*real_secure_getenv)(const char *name) = NULL;
50+
4851
/* pthread_once control for thread-safe initialization */
4952
static pthread_once_t getenv_init_once = PTHREAD_ONCE_INIT;
53+
static pthread_once_t secure_getenv_init_once = PTHREAD_ONCE_INIT;
5054

5155
/* Initialize the real getenv pointer (called exactly once via pthread_once) */
5256
static void init_real_getenv_once(void) {
@@ -63,6 +67,20 @@ static void init_real_getenv(void) {
6367
pthread_once(&getenv_init_once, init_real_getenv_once);
6468
}
6569

70+
/* Initialize the real secure_getenv pointer (called exactly once via pthread_once) */
71+
static void init_real_secure_getenv_once(void) {
72+
real_secure_getenv = dlsym(RTLD_NEXT, "secure_getenv");
73+
/* secure_getenv may not exist on all systems - this is OK, we'll fall back to getenv */
74+
if (real_secure_getenv == NULL) {
75+
fprintf(stderr, "[one-shot-token] INFO: secure_getenv not available, will fall back to getenv\n");
76+
}
77+
}
78+
79+
/* Ensure real_secure_getenv is initialized (thread-safe) */
80+
static void init_real_secure_getenv(void) {
81+
pthread_once(&secure_getenv_init_once, init_real_secure_getenv_once);
82+
}
83+
6684
/* Check if a variable name is a sensitive token */
6785
static int get_token_index(const char *name) {
6886
if (name == NULL) return -1;

0 commit comments

Comments
 (0)