cvs: php4 /sapi/tux php_tux.c

From: Date: Mon, 04 Mar 2002 08:22:33 +0000
Subject: cvs: php4 /sapi/tux php_tux.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-9617@lists.php.net to get a copy of this message
sas Mon Mar 4 03:22:33 2002 EDT Modified files: /php4/sapi/tux php_tux.c Log: Free status line, initialize number_vec, correctly account for the number of bytes in the document, avoid strcpy/strlen. Index: php4/sapi/tux/php_tux.c diff -u php4/sapi/tux/php_tux.c:1.13 php4/sapi/tux/php_tux.c:1.14 --- php4/sapi/tux/php_tux.c:1.13 Tue Dec 11 10:32:10 2001 +++ php4/sapi/tux/php_tux.c Mon Mar 4 03:22:33 2002 @@ -52,7 +52,8 @@ static int sapi_tux_ub_write(const char *str, uint str_length TSRMLS_DC) { int n; - uint sent = 0; + uint sent = 0; + int m; /* combine headers and body */ if (TG(number_vec)) { @@ -62,9 +63,13 @@ vec[n].iov_base = (void *) str; vec[n++].iov_len = str_length; - if (writev(TG(req)->sock, vec, n) == -1 && errno == EPIPE) + /* XXX: this might need more complete error handling */ + if ((m = writev(TG(req)->sock, vec, n)) == -1 && errno == EPIPE) php_handle_aborted_connection(); + if (m > 0) + TG(req)->bytes_sent += str_length; + TG(number_vec) = 0; return str_length; } @@ -92,7 +97,7 @@ { char buf[1024]; struct iovec *vec; - int n = 0; + int n; int max_headers; zend_llist_position pos; sapi_header_struct *h; @@ -102,15 +107,18 @@ TSRMLS_FETCH(); max_headers = 30; - snprintf(buf, 1023, "HTTP/1.1 %d NA\r\n", SG(sapi_headers).http_response_code); + n = 1; vec = malloc(sizeof(struct iovec) * max_headers); + status_line = malloc(30); + + /* safe sprintf use */ + len = sprintf(status_line, "HTTP/1.1 %d NA\r\n", SG(sapi_headers).http_response_code); - vec[n].iov_base = strdup(buf); - vec[n++].iov_len = strlen(buf); + vec[0].iov_base = status_line; + vec[0].iov_len = len; TG(req)->http_status = SG(sapi_headers).http_response_code; - TG(req)->bytes_sent += len; if (TG(tux_action) == TUX_ACTION_FINISH_CLOSE_REQ && TG(req)->http_version == HTTP_1_1) locate_cl = 1; @@ -296,7 +304,8 @@ size_t cwd_len; smart_str s = {0}; char *p; - + + TG(number_vec) = 0; TG(header_vec) = NULL; SG(request_info).query_string = strdup(TG(req)->query); @@ -325,8 +334,11 @@ static void tux_request_dtor(TSRMLS_D) { - if (TG(header_vec)) + if (TG(header_vec)) { + /* free status_line */ + free(TG(header_vec)[0].iov_base); free(TG(header_vec)); + } if (SG(request_info).query_string) free(SG(request_info).query_string); free(SG(request_info).request_uri);

« previous php.cvs (#9617) next »