Merge pull request #4008 from zmeizy/claude/getenv-invalid-name-errno
fix(libc): set EINVAL when getenv gets an invalid name
This commit is contained in:
commit
e929880df4
|
|
@ -50,7 +50,7 @@ int EnvironmentError(int error) { errno = error; return -1; }
|
|||
|
||||
extern "C" {
|
||||
char* APS5_VABI getenv_nid_postfix(const char* name) {
|
||||
if (!ValidEnvironmentName(name)) return nullptr;
|
||||
if (!ValidEnvironmentName(name)) { errno = 22; return nullptr; }
|
||||
try {
|
||||
std::lock_guard lock(environmentMutex);
|
||||
for (auto& entry : Environment())
|
||||
|
|
|
|||
|
|
@ -37,6 +37,13 @@ int main() {
|
|||
Require(std::strcmp(getenv_nid_postfix(key), "two") == 0);
|
||||
Require(setenv_nid_postfix("bad=name", "x", 1) == -1);
|
||||
Require(*__error_nid_postfix() == 22);
|
||||
const char* const invalidNames[] = {nullptr, "", "bad=name"};
|
||||
for (const char* name : invalidNames) {
|
||||
*__error_nid_postfix() = 0;
|
||||
Require(getenv_nid_postfix(name) == nullptr && *__error_nid_postfix() == 22);
|
||||
}
|
||||
*__error_nid_postfix() = 34;
|
||||
Require(getenv_nid_postfix("ANYPS5_GUEST_ENV_ABSENT_4C27") == nullptr && *__error_nid_postfix() == 34);
|
||||
Require(unsetenv_nid_postfix("") == -1);
|
||||
char invalid[] = "no-separator";
|
||||
Require(putenv_nid_postfix(invalid) == -1);
|
||||
|
|
|
|||
Loading…
Reference in New Issue