summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2024-04-13 16:53:29 +0200
committerDirk Engling <erdgeist@erdgeist.org>2024-04-13 16:53:29 +0200
commit638ca0f56c33897601789442ba1414153766daef (patch)
treef7d040128950085be4c41f060d6a12d9bb5c95d3
parent3a2a711a29cf1bd1a9180214607a1959aa555841 (diff)
Use asprintf to allocate header instead of fixed array
-rw-r--r--ot_http.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/ot_http.c b/ot_http.c
index 5b96e6f..2d86ac1 100644
--- a/ot_http.c
+++ b/ot_http.c
@@ -146,26 +146,23 @@ fprintf(stderr, "http_sendiovecdata sending %d iovec entries found cookie->batch
146 146
147 if( iovec_entries ) { 147 if( iovec_entries ) {
148 148
149 /* Prepare space for http header */
150 header = malloc( SUCCESS_HTTP_HEADER_LENGTH + SUCCESS_HTTP_HEADER_LENGTH_CONTENT_ENCODING );
151 if( !header ) {
152 iovec_free( &iovec_entries, &iovector );
153 HTTPERROR_500;
154 }
155
156 if( cookie->flag & STRUCT_HTTP_FLAG_GZIP ) 149 if( cookie->flag & STRUCT_HTTP_FLAG_GZIP )
157 encoding = "Content-Encoding: gzip\r\n"; 150 encoding = "Content-Encoding: gzip\r\n";
158 else if( cookie->flag & STRUCT_HTTP_FLAG_BZIP2 ) 151 else if( cookie->flag & STRUCT_HTTP_FLAG_BZIP2 )
159 encoding = "Content-Encoding: bzip2\r\n"; 152 encoding = "Content-Encoding: bzip2\r\n";
160 153
161 if( !(cookie->flag & STRUCT_HTTP_FLAG_CHUNKED) ) 154 if( !(cookie->flag & STRUCT_HTTP_FLAG_CHUNKED) )
162 header_size = sprintf( header, "HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\n%sContent-Length: %zd\r\n\r\n", encoding, size ); 155 header_size = asprintf( &header, "HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\n%sContent-Length: %zd\r\n\r\n", encoding, size );
163 else { 156 else {
164 if ( !(cookie->flag & STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER )) { 157 if ( !(cookie->flag & STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER )) {
165 header_size = sprintf( header, "HTTP/1.0 200 OK\r\nContent-Type: application/octet-stream\r\n%sTransfer-Encoding: chunked\r\n\r\n%zx\r\n", encoding, size ); 158 header_size = asprintf( &header, "HTTP/1.0 200 OK\r\nContent-Type: application/octet-stream\r\n%sTransfer-Encoding: chunked\r\n\r\n%zx\r\n", encoding, size );
166 cookie->flag |= STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER; 159 cookie->flag |= STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER;
167 } else 160 } else
168 header_size = sprintf( header, "%zx\r\n", size ); 161 header_size = asprintf( &header, "%zx\r\n", size );
162 }
163 if( !header ) {
164 iovec_free( &iovec_entries, &iovector );
165 HTTPERROR_500;
169 } 166 }
170 167
171 if (!cookie->batch ) { 168 if (!cookie->batch ) {