- Fix snprintf return value usage, fixed libunbound_get_option.

git-svn-id: file:///svn/unbound/trunk@2888 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
Wouter Wijngaards 2013-04-19 11:34:36 +00:00
parent ec2d4ed2b9
commit 06a5fdb3f6
3 changed files with 34 additions and 16 deletions

View file

@ -1,3 +1,6 @@
19 April 2013: Wouter
- Fixup snprintf return value usage, fixed libunbound_get_option.
18 April 2013: Wouter
- fix bug #491: pick program name (0th argument) as syslog identity.
- own implementation of compat/snprintf.c.

View file

@ -354,7 +354,8 @@ provide_file_10(SSL* ssl, char* fname)
if(!in) {
char hdr[1024];
rcode = "404 File not found";
r = snprintf(hdr, sizeof(hdr), "HTTP/1.1 %s\r\n\r\n", rcode);
snprintf(hdr, sizeof(hdr), "HTTP/1.1 %s\r\n\r\n", rcode);
r = strlen(hdr);
if(SSL_write(ssl, hdr, r) <= 0) {
/* write failure */
}
@ -371,16 +372,20 @@ provide_file_10(SSL* ssl, char* fname)
}
avail = len+header_reserve;
at = buf;
r = snprintf(at, avail, "HTTP/1.1 %s\r\n", rcode);
snprintf(at, avail, "HTTP/1.1 %s\r\n", rcode);
r = strlen(at);
at += r;
avail -= r;
r = snprintf(at, avail, "Server: petal/%s\r\n", PACKAGE_VERSION);
snprintf(at, avail, "Server: petal/%s\r\n", PACKAGE_VERSION);
r = strlen(at);
at += r;
avail -= r;
r = snprintf(at, avail, "Content-Length: %u\r\n", (unsigned)len);
snprintf(at, avail, "Content-Length: %u\r\n", (unsigned)len);
r = strlen(at);
at += r;
avail -= r;
r = snprintf(at, avail, "\r\n");
snprintf(at, avail, "\r\n");
r = strlen(at);
at += r;
avail -= r;
if(avail < len) { /* robust */
@ -423,19 +428,24 @@ provide_file_chunked(SSL* ssl, char* fname)
}
/* print headers */
r = snprintf(at, avail, "HTTP/1.1 %s\r\n", rcode);
snprintf(at, avail, "HTTP/1.1 %s\r\n", rcode);
r = strlen(at);
at += r;
avail -= r;
r = snprintf(at, avail, "Server: petal/%s\r\n", PACKAGE_VERSION);
snprintf(at, avail, "Server: petal/%s\r\n", PACKAGE_VERSION);
r = strlen(at);
at += r;
avail -= r;
r = snprintf(at, avail, "Transfer-Encoding: chunked\r\n");
snprintf(at, avail, "Transfer-Encoding: chunked\r\n");
r = strlen(at);
at += r;
avail -= r;
r = snprintf(at, avail, "Connection: close\r\n");
snprintf(at, avail, "Connection: close\r\n");
r = strlen(at);
at += r;
avail -= r;
r = snprintf(at, avail, "\r\n");
snprintf(at, avail, "\r\n");
r = strlen(at);
at += r;
avail -= r;
if(avail < 16) { /* robust */
@ -448,7 +458,8 @@ provide_file_chunked(SSL* ssl, char* fname)
/* read chunk; space-16 for xxxxCRLF..CRLF0CRLFCRLF (3 spare)*/
size_t red = in?fread(tmpbuf, 1, avail-16, in):0;
/* prepare chunk */
r = snprintf(at, avail, "%x\r\n", (unsigned)red);
snprintf(at, avail, "%x\r\n", (unsigned)red);
r = strlen(at);
if(verb >= 3)
{printf("chunk len %x\n", (unsigned)red); fflush(stdout);}
at += r;
@ -458,17 +469,20 @@ provide_file_chunked(SSL* ssl, char* fname)
memmove(at, tmpbuf, red);
at += red;
avail -= red;
r = snprintf(at, avail, "\r\n");
snprintf(at, avail, "\r\n");
r = strlen(at);
at += r;
avail -= r;
}
if(in && feof(in) && red != 0) {
r = snprintf(at, avail, "0\r\n");
snprintf(at, avail, "0\r\n");
r = strlen(at);
at += r;
avail -= r;
}
if(!in || feof(in)) {
r = snprintf(at, avail, "\r\n");
snprintf(at, avail, "\r\n");
r = strlen(at);
at += r;
avail -= r;
}

View file

@ -516,8 +516,9 @@ config_collate_cat(struct config_strlist* list)
return NULL;
}
snprintf(w, left, "%s\n", s->str);
w += this+1;
left -= this+1;
this = strlen(w);
w += this;
left -= this;
}
return r;
}