You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by wr...@apache.org on 2006/11/06 22:05:58 UTC

svn commit: r471878 - in /apr/apr/branches/1.2.x: CHANGES misc/win32/env.c test/testenv.c

Author: wrowe
Date: Mon Nov  6 13:05:57 2006
New Revision: 471878

URL: http://svn.apache.org/viewvc?view=rev&rev=471878
Log:
Correctly retrieve 'empty' environment values with apr_env_get
on Win32 (e.g. "VAR="), and added validation to testall suite.  

PR: 40764
Backports: 471877
Submitted by: Issac Goldstand <margol beamartyr.net>
Reviewed by: wrowe


Modified:
    apr/apr/branches/1.2.x/CHANGES
    apr/apr/branches/1.2.x/misc/win32/env.c
    apr/apr/branches/1.2.x/test/testenv.c

Modified: apr/apr/branches/1.2.x/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.2.x/CHANGES?view=diff&rev=471878&r1=471877&r2=471878
==============================================================================
--- apr/apr/branches/1.2.x/CHANGES (original)
+++ apr/apr/branches/1.2.x/CHANGES Mon Nov  6 13:05:57 2006
@@ -1,5 +1,9 @@
 Changes for APR 1.2.8
 
+  *) Correctly retrieve 'empty' environment values with apr_env_get
+     on Win32 (e.g. "VAR="), and added validation to testall suite.  
+     PR 40764.  [Issac Goldstand <margol beamartyr.net>]
+
   *) APR_FIND_APR macro no longer checks /usr/local/apache2/.
      PR 40842.  [Colm MacCarthaigh]
 

Modified: apr/apr/branches/1.2.x/misc/win32/env.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.2.x/misc/win32/env.c?view=diff&rev=471878&r1=471877&r2=471878
==============================================================================
--- apr/apr/branches/1.2.x/misc/win32/env.c (original)
+++ apr/apr/branches/1.2.x/misc/win32/env.c Mon Nov  6 13:05:57 2006
@@ -22,6 +22,7 @@
 #include "apr_env.h"
 #include "apr_errno.h"
 #include "apr_pools.h"
+#include "apr_strings.h"
 
 
 #if APR_HAS_UNICODE_FS
@@ -61,11 +62,18 @@
         if (status)
             return status;
 
+        SetLastError(0);
         size = GetEnvironmentVariableW(wenvvar, &dummy, 0);
-        if (size == 0)
+        if (GetLastError() == ERROR_ENVVAR_NOT_FOUND)
             /* The environment variable doesn't exist. */
             return APR_ENOENT;
 
+        if (size == 0) {
+            /* The environment value exists, but is zero-length. */
+            *value = apr_pstrdup(pool, "");
+            return APR_SUCCESS;
+        }
+
         wvalue = apr_palloc(pool, size * sizeof(*wvalue));
         size = GetEnvironmentVariableW(wenvvar, wvalue, size);
         if (size == 0)
@@ -85,10 +93,17 @@
     {
         char dummy;
 
+        SetLastError(0);
         size = GetEnvironmentVariableA(envvar, &dummy, 0);
-        if (size == 0)
+        if (GetLastError() == ERROR_ENVVAR_NOT_FOUND)
             /* The environment variable doesn't exist. */
             return APR_ENOENT;
+
+        if (size == 0) {
+            /* The environment value exists, but is zero-length. */
+            *value = apr_pstrdup(pool, "");
+            return APR_SUCCESS;
+        }
 
         val = apr_palloc(pool, size);
         size = GetEnvironmentVariableA(envvar, val, size);

Modified: apr/apr/branches/1.2.x/test/testenv.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.2.x/test/testenv.c?view=diff&rev=471878&r1=471877&r2=471878
==============================================================================
--- apr/apr/branches/1.2.x/test/testenv.c (original)
+++ apr/apr/branches/1.2.x/test/testenv.c Mon Nov  6 13:05:57 2006
@@ -19,10 +19,12 @@
 #include "testutil.h"
 
 #define TEST_ENVVAR_NAME "apr_test_envvar"
+#define TEST_ENVVAR2_NAME "apr_test_envvar2"
 #define TEST_ENVVAR_VALUE "Just a value that we'll check"
 
 static int have_env_set;
 static int have_env_get;
+static int have_env_del;
 
 static void test_setenv(abts_case *tc, void *data)
 {
@@ -68,7 +70,8 @@
     }
 
     rv = apr_env_delete(TEST_ENVVAR_NAME, p);
-    if (rv == APR_ENOTIMPL) {
+    have_env_del = (rv != APR_ENOTIMPL);
+    if (!have_env_del) {
         ABTS_NOT_IMPL(tc, "apr_env_delete");
         return;
     }
@@ -82,6 +85,51 @@
     ABTS_INT_EQUAL(tc, APR_ENOENT, rv);
 }
 
+/** http://issues.apache.org/bugzilla/show_bug.cgi?id=40764 */
+static void test_emptyenv(abts_case *tc, void *data)
+{
+    char *value;
+    apr_status_t rv;
+
+    if (!(have_env_set && have_env_get)) {
+        ABTS_NOT_IMPL(tc, "apr_env_set (skip test_emptyenv)");
+        return;
+    }
+    /** Set empty string and test that rv != ENOENT) */
+    rv = apr_env_set(TEST_ENVVAR_NAME, "", p);
+    APR_ASSERT_SUCCESS(tc, "set environment variable", rv);
+    rv = apr_env_get(&value, TEST_ENVVAR_NAME, p);
+    APR_ASSERT_SUCCESS(tc, "get environment variable", rv);
+    ABTS_STR_EQUAL(tc, "", value);
+
+    if (!have_env_del) {
+        ABTS_NOT_IMPL(tc, "apr_env_del (skip recycle test_emptyenv)");
+        return;
+    }
+    /** Delete and retest */
+    rv = apr_env_delete(TEST_ENVVAR_NAME, p);
+    APR_ASSERT_SUCCESS(tc, "delete environment variable", rv);
+    rv = apr_env_get(&value, TEST_ENVVAR_NAME, p);
+    ABTS_INT_EQUAL(tc, APR_ENOENT, rv);
+
+    /** Set second variable + test*/
+    rv = apr_env_set(TEST_ENVVAR2_NAME, TEST_ENVVAR_VALUE, p);
+    APR_ASSERT_SUCCESS(tc, "set second environment variable", rv);
+    rv = apr_env_get(&value, TEST_ENVVAR2_NAME, p);
+    APR_ASSERT_SUCCESS(tc, "get second environment variable", rv);
+    ABTS_STR_EQUAL(tc, TEST_ENVVAR_VALUE, value);
+
+    /** Finally, test ENOENT (first variable) followed by second != ENOENT) */
+    rv = apr_env_get(&value, TEST_ENVVAR_NAME, p);
+    ABTS_INT_EQUAL(tc, APR_ENOENT, rv);
+    rv = apr_env_get(&value, TEST_ENVVAR2_NAME, p);
+    APR_ASSERT_SUCCESS(tc, "verify second environment variable", rv);
+    ABTS_STR_EQUAL(tc, TEST_ENVVAR_VALUE, value);
+
+    /** Cleanup */
+    apr_env_delete(TEST_ENVVAR2_NAME, p);
+}
+
 abts_suite *testenv(abts_suite *suite)
 {
     suite = ADD_SUITE(suite)
@@ -89,6 +137,7 @@
     abts_run_test(suite, test_setenv, NULL);
     abts_run_test(suite, test_getenv, NULL);
     abts_run_test(suite, test_delenv, NULL);
+    abts_run_test(suite, test_emptyenv, NULL);
 
     return suite;
 }