unsetenv() crashes after clearenv()

Bug #380487 reported by Timo Sirainen
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
glibc (Ubuntu)
Fix Released
Low
Unassigned

Bug Description

Here's a test program that crashes:

#include <stdlib.h>

int main(int argc, char **argv)
{
 clearenv();
 unsetenv("foobar");
 return 0;
}

ProblemType: Bug
Architecture: i386
Dependencies:
 libgcc1 1:4.3.3-5ubuntu4
 gcc-4.3-base 4.3.3-5ubuntu4
 findutils 4.4.0-2ubuntu4
 libc6 2.9-4ubuntu6
DistroRelease: Ubuntu 9.04
NonfreeKernelModules: nvidia
Package: libc6 2.9-4ubuntu6
ProcEnviron:
 LANG=en_US.UTF-8
 SHELL=/bin/zsh
SourcePackage: glibc
Uname: Linux 2.6.28-11-generic i686

Revision history for this message
Chris Coulson (chrisccoulson) wrote :

Do you think that is actually a bug, or something that you should just not do as a programmer?

"If the application modifies environ or the pointers to which it points, the behavior of unsetenv() is undefined. The unsetenv() function shall update the list of pointers to which environ points."

Running clearenv() clearly modifies environ (it sets it to NULL), and so you should expect the behaviour of unsetenv to be undefined after running this (and perhaps even crash in the way that you see)

Changed in glibc (Ubuntu):
importance: Undecided → Low
status: New → Incomplete
Revision history for this message
Timo Sirainen (tss-iki) wrote :

In my opinion it's a bug. My application doesn't modify environ directly, glibc does via clearenv() and I'd expect glibc not to crash when only using its own environment manipulation functions. Also there's no problems using clearenv() and unsetenv() together as long as there is at least one putenv() in the middle.

BTW. This is also causing deliver program in dovecot package to crash with a specific configuration file.

Revision history for this message
Lars Ljung (larslj) wrote :

I agree with Timo, this is a bug. But it should probably be reported upstream.

Changed in glibc (Ubuntu):
status: Incomplete → Confirmed
Revision history for this message
Timo Sirainen (tss-iki) wrote :

Looks like this is fixed in 10.4.

Revision history for this message
Lars Ljung (larslj) wrote :

This was also fixed upstream in version 2.10.1

Changed in glibc (Ubuntu):
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.