fixed a crashing bug in ursd when a rewriter terminates prematurely.
changed urs code to truncate the trailing string after the first space in the response from ursd/rewriter
This commit is contained in:
		| @ -726,34 +726,38 @@ static void dispatch_mux_event (qse_mux_t* mux, const qse_mux_evt_t* evt) | |||||||
| 					/* read failure or end of input */ | 					/* read failure or end of input */ | ||||||
| 					rewriter->faulty = 1; | 					rewriter->faulty = 1; | ||||||
| 					release_rewriter (mux_xtn->ursd, rewriter, 1); | 					release_rewriter (mux_xtn->ursd, rewriter, 1); | ||||||
|  | 					/* TODO: error logging */ | ||||||
| 				} | 				} | ||||||
|  | 				else | ||||||
| 				rewriter->req.outlen += x; |  | ||||||
| 				if (rewriter->req.outlen > maxoutlen) |  | ||||||
| 				{ | 				{ | ||||||
| 					/* the rewriter returns too long a result */ | 					rewriter->req.outlen += x; | ||||||
| 					rewriter->faulty = 1; |  | ||||||
| 					release_rewriter (mux_xtn->ursd, rewriter, 1); |  | ||||||
| 				} |  | ||||||
|  |  | ||||||
| qse_printf (QSE_T("READ %d, %d bytes from pipes [%.*hs]\n"), (int)x, (int)rewriter->req.outlen, (int)rewriter->req.outlen, pkt->url); | qse_printf (QSE_T("READ %d, %d bytes from pipes [%.*hs]\n"), (int)x, (int)rewriter->req.outlen, (int)rewriter->req.outlen, pkt->url); | ||||||
|  |  | ||||||
| 				if (pkt->url[rewriter->req.outlen - 1] == QSE_MT('\n')) | 					if (rewriter->req.outlen > maxoutlen) | ||||||
| 				{ | 					{ | ||||||
| 					/* the last byte is a new line. i don't really care about | 						/* the rewriter returns too long a result */ | ||||||
| 					 * new lines in the middle of data. the rewriter must  | 						rewriter->faulty = 1; | ||||||
| 					 * keep to the protocol. */ | 						release_rewriter (mux_xtn->ursd, rewriter, 1); | ||||||
|  | 						/* TODO: error logging */ | ||||||
|  | 					} | ||||||
|  | 					else if (pkt->url[rewriter->req.outlen - 1] == QSE_MT('\n')) | ||||||
|  | 					{ | ||||||
|  | 						/* the last byte is a new line. i don't really care about | ||||||
|  | 						 * new lines in the middle of data. the rewriter must  | ||||||
|  | 						 * keep to the protocol. */ | ||||||
|  |  | ||||||
| 					/* add up the header size. -1 to exclude '\n' */ | 						/* add up the header size. -1 to exclude '\n' */ | ||||||
| 					rewriter->req.outlen += QSE_SIZEOF(urs_hdr_t) - 1; | 						rewriter->req.outlen += QSE_SIZEOF(urs_hdr_t) - 1; | ||||||
|  |  | ||||||
| 					pkt->hdr.pktlen = qse_hton16(rewriter->req.outlen); /* change the byte order */ | 						pkt->hdr.pktlen = qse_hton16(rewriter->req.outlen); /* change the byte order */ | ||||||
| 					sendto (mux_xtn->ursd->sck, pkt, rewriter->req.outlen, 0, (struct sockaddr*)&rewriter->req.from, rewriter->req.fromlen); | 						sendto (mux_xtn->ursd->sck, pkt, rewriter->req.outlen, 0, (struct sockaddr*)&rewriter->req.from, rewriter->req.fromlen); | ||||||
| 					/* TODO: error logging */ | 						/* TODO: error logging */ | ||||||
| 					/* sendto() to the socket can be blocking. if the socket side is too busy, there's no reason for rewriter to be as busy. | 						/* sendto() to the socket can be blocking. if the socket side is too busy, there's no reason for rewriter to be as busy. | ||||||
| 					 * it can wait a while. think about it. */ | 						 * it can wait a while. think about it. */ | ||||||
|  |  | ||||||
| 					release_rewriter (mux_xtn->ursd, rewriter, 0); | 						release_rewriter (mux_xtn->ursd, rewriter, 0); | ||||||
|  | 					} | ||||||
| 				} | 				} | ||||||
|  |  | ||||||
| /* TODO: is the complete output is not received within time, some actions must be taken. timer based... rewrite timeout */ | /* TODO: is the complete output is not received within time, some actions must be taken. timer based... rewrite timeout */ | ||||||
|  | |||||||
| @ -220,6 +220,7 @@ static int urs_recv (qse_httpd_t* httpd, qse_httpd_urs_t* urs, qse_ubi_t handle) | |||||||
| 	qse_ssize_t len, url_len; | 	qse_ssize_t len, url_len; | ||||||
| 	urs_pkt_t* pkt; | 	urs_pkt_t* pkt; | ||||||
| 	urs_req_t* req; | 	urs_req_t* req; | ||||||
|  | 	qse_mchar_t* spc; | ||||||
|  |  | ||||||
| printf ("URS_RECV............................................\n"); | printf ("URS_RECV............................................\n"); | ||||||
|  |  | ||||||
| @ -247,6 +248,10 @@ printf ("URS_RECV............................................\n"); | |||||||
| 					/* null-terminate the url for easier processing */ | 					/* null-terminate the url for easier processing */ | ||||||
| 					pkt->url[url_len] = QSE_MT('\0'); | 					pkt->url[url_len] = QSE_MT('\0'); | ||||||
|  |  | ||||||
|  | 					/* drop trailers starting from the first space onwards */ | ||||||
|  | 					spc = qse_mbschr (pkt->url, QSE_MT(' ')); | ||||||
|  | 					if (spc) *spc = QSE_MT('\0'); | ||||||
|  |  | ||||||
| 					urs_remove_tmr_tmout (httpd, req); | 					urs_remove_tmr_tmout (httpd, req); | ||||||
| 					req->rewrite (httpd, req->pkt->url, pkt->url, req->ctx); | 					req->rewrite (httpd, req->pkt->url, pkt->url, req->ctx); | ||||||
|  |  | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user