mirror of
https://github.com/php/php-src.git
synced 2025-08-18 15:08:55 +02:00
Replace memcpy and sprintf with smart_strs.
This commit is contained in:
parent
667a1f1fdb
commit
5708ddf171
1 changed files with 12 additions and 16 deletions
|
@ -24,6 +24,8 @@
|
||||||
#include "php_variables.h"
|
#include "php_variables.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
|
#include "ext/standard/php_smart_str.h"
|
||||||
|
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -257,30 +259,24 @@ static void thttpd_module_main(TLS_D SLS_DC)
|
||||||
|
|
||||||
static void thttpd_request_ctor(TLS_D SLS_DC)
|
static void thttpd_request_ctor(TLS_D SLS_DC)
|
||||||
{
|
{
|
||||||
char *cp;
|
|
||||||
size_t cp_len;
|
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
int offset;
|
int offset;
|
||||||
size_t filename_len;
|
size_t filename_len;
|
||||||
size_t cwd_len;
|
size_t cwd_len;
|
||||||
|
smart_str s = {0};
|
||||||
|
|
||||||
SG(request_info).query_string = TG(hc)->query?strdup(TG(hc)->query):NULL;
|
SG(request_info).query_string = TG(hc)->query?strdup(TG(hc)->query):NULL;
|
||||||
|
|
||||||
filename_len = strlen(TG(hc)->expnfilename);
|
smart_str_appends_ex(&s, TG(hc)->hs->cwd, 1);
|
||||||
cwd_len = strlen(TG(hc)->hs->cwd);
|
smart_str_appends_ex(&s, TG(hc)->expnfilename, 1);
|
||||||
|
smart_str_0(&s);
|
||||||
cp_len = cwd_len + filename_len;
|
SG(request_info).path_translated = s.c;
|
||||||
cp = (char *) malloc(cp_len + 1);
|
|
||||||
/* cwd always ends in "/", so this is safe */
|
|
||||||
memcpy(cp, TG(hc)->hs->cwd, cwd_len);
|
|
||||||
memcpy(cp + cwd_len, TG(hc)->expnfilename, filename_len);
|
|
||||||
cp[cp_len] = '\0';
|
|
||||||
|
|
||||||
SG(request_info).path_translated = cp;
|
s.c = NULL;
|
||||||
|
smart_str_appendc_ex(&s, '/', 1);
|
||||||
snprintf(buf, 1023, "/%s", TG(hc)->origfilename);
|
smart_str_appends_ex(&s, TG(hc)->origfilename, 1);
|
||||||
SG(request_info).request_uri = strdup(buf);
|
smart_str_0(&s);
|
||||||
|
SG(request_info).request_uri = s.c;
|
||||||
SG(request_info).request_method = httpd_method_str(TG(hc)->method);
|
SG(request_info).request_method = httpd_method_str(TG(hc)->method);
|
||||||
SG(sapi_headers).http_response_code = 200;
|
SG(sapi_headers).http_response_code = 200;
|
||||||
SG(request_info).content_type = TG(hc)->contenttype;
|
SG(request_info).content_type = TG(hc)->contenttype;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue