Skip to content

Add reallocating environ if it's set NULL / Fix NULL pointer dereference when PutEnvImpl is called after clearenv#542

Merged
jart merged 1 commit intojart:masterfrom
G4Vi:add_env_reset_v1
Aug 17, 2022
Merged

Add reallocating environ if it's set NULL / Fix NULL pointer dereference when PutEnvImpl is called after clearenv#542
jart merged 1 commit intojart:masterfrom
G4Vi:add_env_reset_v1

Conversation

@G4Vi
Copy link
Copy Markdown
Collaborator

@G4Vi G4Vi commented Aug 17, 2022

Potential fix for #541

Not sure if something different should be done instead of letting the __cxa_atexit(FreeEnviron callbacks stack up.

Copy link
Copy Markdown
Owner

@jart jart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for sending this!

I'd encourage you to write tests too when encountering issues like this. I'm a big fan of test driven development so the testing tools are pretty high quality to reflect that.

For example, with something like this you'd want to put the following code in test/libc/mem/putenv_test.c

#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/testlib/testlib.h"

TEST(putenv, test) {
  EXPECT_EQ(0, clearenv());
  EXPECT_EQ(0, putenv("hi=there"));
  EXPECT_STREQ("there", getenv("hi"));
}

Then you'd run make MODE=dbg -j16 o/dbg/test/libc/mem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants