[haiku-commits] r38904 - haiku/trunk/src/system/libroot/posix/stdlib

  • From: philippe.houdoin@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 9 Oct 2010 11:09:02 +0200 (CEST)

Author: phoudoin
Date: 2010-10-09 11:09:01 +0200 (Sat, 09 Oct 2010)
New Revision: 38904
Changeset: http://dev.haiku-os.org/changeset/38904
Ticket: http://dev.haiku-os.org/ticket/6706

Modified:
   haiku/trunk/src/system/libroot/posix/stdlib/env.cpp
Log:
unsetenv() should remove *any* occurence of name=value.
As with putenv() both value and name can be modified afterwise in our 
back, multiple occurence of the same name is a possibility.
Fix #6706. 


Modified: haiku/trunk/src/system/libroot/posix/stdlib/env.cpp
===================================================================
--- haiku/trunk/src/system/libroot/posix/stdlib/env.cpp 2010-10-09 08:28:46 UTC 
(rev 38903)
+++ haiku/trunk/src/system/libroot/posix/stdlib/env.cpp 2010-10-09 09:09:01 UTC 
(rev 38904)
@@ -279,12 +279,16 @@
        copy_environ_to_heap_if_needed();
 
        env = find_variable(name, length, &index);
-       if (env != NULL) {
+       while (env != NULL) {
                // we don't free the memory for the slot, we just move the array
                // contents
                free(env);
                memmove(environ + index, environ + index + 1,
                        sizeof(char *) * (count_variables() - index));
+                       
+               // search possible another occurence, introduced via putenv() 
+               // and renamed since
+               env = find_variable(name, length, &index);
        }
 
        unlock_variables();


Other related posts:

  • » [haiku-commits] r38904 - haiku/trunk/src/system/libroot/posix/stdlib - philippe . houdoin