struct tm nowtm;
char datetime[128];
+ HTTP_CHECK_OPEN_BASEDIR(file, return);
+
time(&now);
strftime(datetime, sizeof(datetime), "%Y-%m-%d %H:%M:%S", php_localtime_r(&now, &nowtm));
SUCCESS != zend_hash_find(Z_ARRVAL_PP(data), "file", sizeof("file"), (void **) &file)) {
http_error(HE_NOTICE, HTTP_E_INVALID_PARAM, "Post file array entry misses either 'name', 'type' or 'file' entry");
} else {
- CURLcode err = curl_formadd(&http_post_data[0], &http_post_data[1],
+ CURLcode err;
+
+ HTTP_CHECK_OPEN_BASEDIR(Z_STRVAL_PP(file), curl_formfree(http_post_data[0]); return NULL);
+
+ err = curl_formadd(&http_post_data[0], &http_post_data[1],
CURLFORM_COPYNAME, Z_STRVAL_PP(name),
CURLFORM_FILE, Z_STRVAL_PP(file),
CURLFORM_CONTENTTYPE, Z_STRVAL_PP(type),
return http_request_body_init_rel(body, HTTP_REQUEST_BODY_CSTRING, encoded, encoded_len, 1);
}
}
-/* }}} */
+
/* {{{ void http_request_body_dtor(http_request_body *) */
PHP_HTTP_API void _http_request_body_dtor(http_request_body *body TSRMLS_DC)
char *ct = NULL;
#ifdef HTTP_HAVE_MAGIC
+ struct magic_set *magic;
+
+ HTTP_CHECK_OPEN_BASEDIR(magicfile, return NULL);
+
/* magic_load() fails if MAGIC_MIME is set because it
cowardly adds .mime to the file name */
- struct magic_set *magic = magic_open(magicmode &~ MAGIC_MIME);
+ magic = magic_open(magicmode &~ MAGIC_MIME);
if (!magic) {
http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Invalid magic mode: %ld", magicmode);
break;
default:
+ HTTP_CHECK_OPEN_BASEDIR(data_ptr, magic_close(magic); return NULL);
ctype = magic_file(magic, data_ptr);
break;
}
#ifndef PHP_EXT_HTTP_H
#define PHP_EXT_HTTP_H
-#define PHP_EXT_HTTP_VERSION "0.20.0"
+#define PHP_EXT_HTTP_VERSION "0.21.0dev"
#include "php.h"
#include "php_http_std_defs.h"
action; \
}
+#define HTTP_CHECK_OPEN_BASEDIR(file, act) \
+ if ((PG(open_basedir) && *PG(open_basedir)) || PG(safe_mode)) \
+ { \
+ const char *tmp = file; \
+ \
+ if (!strncasecmp(tmp, "file:", lenof("file:"))) { \
+ tmp += lenof("file:"); \
+ while (*tmp == '/' || *tmp == '\\') ++tmp; \
+ } \
+ \
+ if (!*tmp || php_check_open_basedir(tmp TSRMLS_CC) || \
+ (PG(safe_mode) && !php_checkuid(tmp, "rb+", CHECKUID_CHECK_MODE_PARAM))) { \
+ http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Permission denied: %s", file); \
+ act; \
+ } \
+ }
#define http_log(f, i, m) _http_log_ex((f), (i), (m) TSRMLS_CC)
extern void http_log_ex(char *file, const char *ident, const char *message TSRMLS_DC);