Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
Implement secure_getenv(3) if not provided by stdlib #147
Merged
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
661712a
Implement secure_getenv(3) if not provided by stdlib
zyga fd9ae69
Add extra sanity attributes to secure_getenv
zyga 3f90e72
Use extra { } on one-line if's
zyga a58ed97
Merge branch 'master' of github.com:snapcore/snap-confine into secure…
zyga
Jump to file or symbol
Failed to load files and symbols.
12
configure.ac
| @@ -0,0 +1,31 @@ | ||
| +/* | ||
| + * Copyright (C) 2016 Canonical Ltd | ||
| + * | ||
| + * This program is free software: you can redistribute it and/or modify | ||
| + * it under the terms of the GNU General Public License version 3 as | ||
| + * published by the Free Software Foundation. | ||
| + * | ||
| + * This program is distributed in the hope that it will be useful, | ||
| + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| + * GNU General Public License for more details. | ||
| + * | ||
| + * You should have received a copy of the GNU General Public License | ||
| + * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| + * | ||
| + */ | ||
| +#include "secure-getenv.h" | ||
| + | ||
| +#include <stdlib.h> | ||
| +#include <sys/auxv.h> | ||
| + | ||
| +#ifndef HAVE_SECURE_GETENV | ||
| +char *secure_getenv(const char *name) | ||
|
|
||
| +{ | ||
| + unsigned long secure = getauxval(AT_SECURE); | ||
| + if (secure != 0) { | ||
| + return NULL; | ||
| + } | ||
| + return getenv(name); | ||
| +} | ||
| +#endif // ! HAVE_SECURE_GETENV | ||
| @@ -0,0 +1,36 @@ | ||
| +/* | ||
| + * Copyright (C) 2016 Canonical Ltd | ||
| + * | ||
| + * This program is free software: you can redistribute it and/or modify | ||
| + * it under the terms of the GNU General Public License version 3 as | ||
| + * published by the Free Software Foundation. | ||
| + * | ||
| + * This program is distributed in the hope that it will be useful, | ||
| + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| + * GNU General Public License for more details. | ||
| + * | ||
| + * You should have received a copy of the GNU General Public License | ||
| + * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| + * | ||
| + */ | ||
| +#ifndef SNAP_CONFINE_SECURE_GETENV_H | ||
| +#define SNAP_CONFINE_SECURE_GETENV_H | ||
| + | ||
| +#ifdef HAVE_CONFIG_H | ||
| +#include "config.h" | ||
| +#endif | ||
| + | ||
| +#ifndef HAVE_SECURE_GETENV | ||
| +/** | ||
| + * Secure version of getenv() | ||
| + * | ||
| + * This version returns NULL if the process is running within a secure context. | ||
| + * This is exactly the same as the GNU extension to the standard library. It is | ||
| + * only used when glibc is not available. | ||
| + **/ | ||
| +char *secure_getenv(const char *name) | ||
| + __attribute__ ((nonnull(1), warn_unused_result)); | ||
| +#endif // ! HAVE_SECURE_GETENV | ||
| + | ||
| +#endif |
you could add
__attribute__((nonnull))so that gcc and clang warn you if you pass in null, i think?