fixed quite some segmentation faults in http-thr.c.

similar fixes must be done on other task implementations such as http-file.c
This commit is contained in:
2023-01-11 23:59:41 +09:00
parent 529363913f
commit 97133f8c12
76 changed files with 2372 additions and 2167 deletions

View File

@ -848,7 +848,7 @@ static int print_qparam (hio_bcs_t* key, hio_bcs_t* val, void* ctx)
return 0;
}
static void on_htts_thr_request (hio_t* hio, hio_dev_thr_iopair_t* iop, hio_svc_htts_thr_func_info_t* tfi, void* ctx)
static void on_htts_thr_request (hio_svc_htts_t* hio, hio_dev_thr_iopair_t* iop, hio_svc_htts_thr_func_info_t* tfi, void* ctx)
{
FILE* fp;
int i;

View File

@ -27,7 +27,7 @@ static int print_qparam (hio_bcs_t* key, hio_bcs_t* val, void* ctx)
return 0;
}
static void on_htts_thr_request (hio_t* hio, hio_dev_thr_iopair_t* iop, hio_svc_htts_thr_func_info_t* tfi, void* ctx)
static void on_htts_thr_request (hio_svc_htts_t* htts, hio_dev_thr_iopair_t* iop, hio_svc_htts_thr_func_info_t* tfi, void* ctx)
{
FILE* fp;
int i;
@ -62,7 +62,7 @@ static void on_htts_thr_request (hio_t* hio, hio_dev_thr_iopair_t* iop, hio_svc_
fclose (fp);
}
static void on_htts_thr2_request (hio_t* hio, hio_dev_thr_iopair_t* iop, hio_svc_htts_thr_func_info_t* tfi, void* ctx)
static void on_htts_thr2_request (hio_svc_htts_t* htts, hio_dev_thr_iopair_t* iop, hio_svc_htts_thr_func_info_t* tfi, void* ctx)
{
FILE* fp, * sf;
@ -113,7 +113,7 @@ int process_http_request (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t*
{
hio_t* hio = hio_svc_htts_gethio(htts);
// hio_svc_htts_cli_t* cli = hio_dev_sck_getxtn(csck);
hio_http_method_t mth;
// hio_http_method_t mth;
/* percent-decode the query path to the original buffer
* since i'm not going to need it in the original form
@ -149,7 +149,7 @@ if (hio_htre_getcontentlen(req) > 0)
}
#endif
mth = hio_htre_getqmethodtype(req);
// mth = hio_htre_getqmethodtype(req);
/* determine what to do once the header fields are all received.
* i don't want to delay this until the contents are received.
* if you don't like this behavior, you must implement your own
@ -208,7 +208,7 @@ if (hio_htre_getcontentlen(req) > 0)
{
hio_skad_t fcgis_addr;
hio_bcstrtoskad(hio, "127.0.0.1:9000", &fcgis_addr);
x = hio_svc_htts_dofcgi(htts, csck, req, &fcgis_addr, 0);
x = hio_svc_htts_dofcgi(htts, csck, req, &fcgis_addr, "", qpath + 5, 0);
}
else
x = hio_svc_htts_dofile(htts, csck, req, "", qpath, "text/plain", 0, HIO_NULL);

View File

@ -51,15 +51,17 @@ static void untar_write_status_code (int fd, int code)
}
}
static void untar (hio_t* hio, hio_dev_thr_iopair_t* iop, hio_svc_htts_thr_func_info_t* tfi, void* ctx)
static void untar (hio_svc_htts_t* htts, hio_dev_thr_iopair_t* iop, hio_svc_htts_thr_func_info_t* tfi, void* ctx)
{
FILE* wfp = HIO_NULL;
hio_t* hio;
htts_ext_t* ext;
hio_tar_t* tar = HIO_NULL;
hio_uint8_t buf[4096];
ssize_t n;
ext = hio_svc_htts_getxtn(tfi->htts);
hio = hio_svc_htts_gethio(htts);
ext = hio_svc_htts_getxtn(htts);
/* TODO: error handling on write() failure */
wfp = fdopen(iop->wfd, "w");
@ -317,11 +319,19 @@ static int process_http_request (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_
/* don't care about the path for now. TODO: make this secure and reasonable */
if (hio_svc_htts_dothr(htts, csck, req, untar, HIO_NULL, 0) <= -1) goto oops;
}
else if (mth == HIO_HTTP_OPTIONS)
{
//if (hio_svc_htts_dofun(htts, csck, req, options, HIO_NULL, 0) <= -1) goto oops;
}
else if (hio_comp_bcstr(qpath_ext, ".php", 0) == 0)
{
hio_skad_t skad;
hio_bcstrtoskad(hio, "10.30.0.133:9000", &skad);
if (hio_svc_htts_dofcgi(htts, csck, req, &skad, 0) <= -1) goto oops;
/*if (hio_svc_htts_dofcgi(htts, csck, req, &skad, ext->ai->docroot, qpath, 0) <= -1) goto oops;*/
/* if the document root is relative, it is hard to gurantee that the same document is
* true to the fcgi server which is a different process. so map it a blank string for now.
* TODO: accept a separate document root for the fcgi server and use it below */
if (hio_svc_htts_dofcgi(htts, csck, req, &skad, "", qpath, 0) <= -1) goto oops;
/*if (hio_svc_htts_dotxt(htts, csck, req, HIO_HTTP_STATUS_INTERNAL_SERVER_ERROR, "text/plain", "what the...", 0) <= -1) goto oops;*/
}
else // if (mth == HIO_HTTP_GET || mth == HIO_HTTP_POST)