diff --git a/libc/Makefile b/libc/Makefile index a649b5de..c8bee73f 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -164,6 +164,7 @@ stdlib/qsort.o \ stdlib/qsort_r.o \ stdlib/reallocarray.o \ stdlib/realloc.o \ +stdlib/secure_getenv.o \ stdlib/strtod.o \ stdlib/strtof.o \ stdlib/strtold.o \ diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h index 69ae1a1a..c9e972a5 100644 --- a/libc/include/stdlib.h +++ b/libc/include/stdlib.h @@ -164,6 +164,7 @@ void* reallocarray_trace(struct __allocation_site*, void*, size_t, size_t); #else void* reallocarray(void*, size_t, size_t); #endif +char* secure_getenv(const char*); #endif #if defined(__is_sortix_libc) diff --git a/libc/stdlib/secure_getenv.c b/libc/stdlib/secure_getenv.c new file mode 100644 index 00000000..92bfd810 --- /dev/null +++ b/libc/stdlib/secure_getenv.c @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 Jonas 'Sortie' Termansen. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * stdlib/secure_getenv.c + * Get an environment variable securely. + */ + +#include + +char* secure_getenv(const char* name) +{ + // Sortix does not have setuid / setgid executables. + return getenv(name); +}