php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #24802 [THTTPD SAPI] Patch for implementing missing getenv
Submitted: 2003-07-25 04:14 UTC Modified: 2017-01-08 06:23 UTC
From: mattias at sudac dot org Assigned: krakjoe (profile)
Status: Closed Package: Other web server
PHP Version: 4CVS-2003-07-25 (stable) OS:
Private report: No CVE-ID: None
 [2003-07-25 04:14 UTC] mattias at sudac dot org
Description:
------------
Hello

I think this is a better-then-nothing implementation of getenv for the thttpd SAPI.

The patch should proabably work with both rev 1.77.2.13.2.2 and 1.91 of thttpd.c

--- thttpd.c.orig   2003-07-25 10:56:54.000000000 +0200
+++ thttpd.c    2003-07-25 11:02:00.000000000 +0200
@@ -368,6 +368,20 @@
    return SUCCESS;
 }

+/* This implementation will return values of environment variables matched in the
+ * $_SERVER array, if not return NULL and it will fallback to normal libc getenv.
+ * By doing this getenv("REMOTE_ADDR") and others will work fine.
+ */
+static char *sapi_thttpd_getenv(char *name, size_t name_len TSRMLS_DC)
+{
+    zval **val = NULL;
+
+    if(zend_hash_find(HASH_OF(PG(http_globals)[TRACK_VARS_SERVER]),name,name_len+1,(void**)&v
+        return Z_STRVAL_PP(val);
+    else
+        return NULL;
+}
+
 static sapi_module_struct thttpd_sapi_module = {
    "thttpd",
    "thttpd",
@@ -381,7 +395,7 @@
    sapi_thttpd_ub_write,
    NULL,
    NULL,                                   /* get uid */
-   NULL,                                   /* getenv */
+   sapi_thttpd_getenv,                     /* getenv */

    php_error,



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-25 05:48 UTC] mattias at sudac dot org
The web form seams to have mangle the patch a bit, &v insted of &val for example.
 [2003-07-25 06:16 UTC] magnus@php.net
Send it to internals@lists.php.net and CC Sascha (sas@php.net)
 [2011-01-01 21:06 UTC] jani@php.net
-Package: Feature/Change Request +Package: Other web server
 [2017-01-08 06:23 UTC] krakjoe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: krakjoe
 [2017-01-08 06:23 UTC] krakjoe@php.net
This SAPI has been removed from PHP.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 06:01:29 2024 UTC