diff --git a/libc/Makefile b/libc/Makefile index 8240d080..0f03296c 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -191,6 +191,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 7be64848..cc521d9c 100644 --- a/libc/include/stdlib.h +++ b/libc/include/stdlib.h @@ -144,6 +144,7 @@ int mkostemp(char*, int); int ptsname_r(int, char*, size_t); void qsort_r(void*, size_t, size_t, int (*)(const void*, const void*, void*), void*); void* reallocarray(void*, size_t, size_t); +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); +}