aboutsummaryrefslogtreecommitdiff
path: root/tests/server
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2016-04-03 22:35:43 +0200
committerDaniel Stenberg <daniel@haxx.se>2016-04-03 22:38:36 +0200
commita332c4f769dc25bdc57ebb88bccef03d7ca6b258 (patch)
treebb555dd587a6cac23d369843983fdb7fd6848a73 /tests/server
parenta71012c03ef6a7cbfba69bcafb559fa417c49af0 (diff)
tests/server: comply with our code style
Diffstat (limited to 'tests/server')
-rw-r--r--tests/server/fake_ntlm.c17
-rw-r--r--tests/server/getpart.c4
-rw-r--r--tests/server/resolve.c6
-rw-r--r--tests/server/rtspd.c107
-rw-r--r--tests/server/sockfilt.c59
-rw-r--r--tests/server/sws.c104
-rw-r--r--tests/server/testpart.c4
-rw-r--r--tests/server/tftpd.c126
-rw-r--r--tests/server/util.c23
9 files changed, 240 insertions, 210 deletions
diff --git a/tests/server/fake_ntlm.c b/tests/server/fake_ntlm.c
index 5b4d4fe98..87118b315 100644
--- a/tests/server/fake_ntlm.c
+++ b/tests/server/fake_ntlm.c
@@ -76,7 +76,7 @@ static char *printable(char *inbuf, size_t inlength)
return NULL;
if(!inlength) {
- sprintf(&outbuf[0], "%s", NOTHING_STR);
+ snprintf(&outbuf[0], outsize, "%s", NOTHING_STR);
return outbuf;
}
@@ -98,7 +98,7 @@ static char *printable(char *inbuf, size_t inlength)
o++;
}
else {
- sprintf(&outbuf[o], HEX_FMT_STR, inbuf[i]);
+ snprintf(&outbuf[o], outsize - o, HEX_FMT_STR, inbuf[i]);
o += HEX_STR_LEN;
}
@@ -163,7 +163,7 @@ int main(int argc, char *argv[])
(use_cached_creds) ? "yes" : "no");
env = getenv("CURL_NTLM_AUTH_TESTNUM");
- if (env) {
+ if(env) {
char *endptr;
long lnum = strtol(env, &endptr, 10);
if((endptr != env + strlen(env)) || (lnum < 1L)) {
@@ -171,13 +171,14 @@ int main(int argc, char *argv[])
exit(1);
}
testnum = lnum;
- } else {
+ }
+ else {
logmsg("Test number not specified in CURL_NTLM_AUTH_TESTNUM");
exit(1);
}
env = getenv("CURL_NTLM_AUTH_SRCDIR");
- if (env) {
+ if(env) {
path = env;
}
@@ -230,7 +231,8 @@ int main(int argc, char *argv[])
}
else {
size = 0;
- error = getpart(&type1_output, &size, "ntlm_auth_type1", "output", stream);
+ error = getpart(&type1_output, &size, "ntlm_auth_type1", "output",
+ stream);
fclose(stream);
if(error || size == 0) {
logmsg("getpart() type 1 output failed with error: %d", error);
@@ -251,7 +253,8 @@ int main(int argc, char *argv[])
}
else {
size = 0;
- error = getpart(&type3_output, &size, "ntlm_auth_type3", "output", stream);
+ error = getpart(&type3_output, &size, "ntlm_auth_type3", "output",
+ stream);
fclose(stream);
if(error || size == 0) {
logmsg("getpart() type 3 output failed with error: %d", error);
diff --git a/tests/server/getpart.c b/tests/server/getpart.c
index 0642564eb..960fbaa50 100644
--- a/tests/server/getpart.c
+++ b/tests/server/getpart.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -101,7 +101,7 @@ static int readline(char **buffer, size_t *bufsize, FILE *stream)
int bytestoread = curlx_uztosi(*bufsize - offset);
if(!fgets(*buffer + offset, bytestoread, stream))
- return (offset != 0) ? GPE_OK : GPE_END_OF_FILE ;
+ return (offset != 0) ? GPE_OK : GPE_END_OF_FILE;
length = offset + strlen(*buffer + offset);
if(*(*buffer + length - 1) == '\n')
diff --git a/tests/server/resolve.c b/tests/server/resolve.c
index 8cd0c260d..206245aba 100644
--- a/tests/server/resolve.c
+++ b/tests/server/resolve.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -126,7 +126,7 @@ int main(int argc, char *argv[])
sclose(s);
}
- if (rc == 0) {
+ if(rc == 0) {
/* getaddrinfo() resolve */
struct addrinfo *ai;
struct addrinfo hints;
@@ -138,7 +138,7 @@ int main(int argc, char *argv[])
/* Use parenthesis around functions to stop them from being replaced by
the macro in memdebug.h */
rc = (getaddrinfo)(host, "80", &hints, &ai);
- if (rc == 0)
+ if(rc == 0)
(freeaddrinfo)(ai);
}
diff --git a/tests/server/rtspd.c b/tests/server/rtspd.c
index 0838ce2b7..91ef6c62b 100644
--- a/tests/server/rtspd.c
+++ b/tests/server/rtspd.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -353,15 +353,15 @@ static int ProcessRequest(struct httprequest *req)
char *ptr;
if(!strcmp(prot_str, "HTTP")) {
- req->protocol = RPROT_HTTP;
+ req->protocol = RPROT_HTTP;
}
else if(!strcmp(prot_str, "RTSP")) {
- req->protocol = RPROT_RTSP;
+ req->protocol = RPROT_RTSP;
}
else {
- req->protocol = RPROT_NONE;
- logmsg("got unknown protocol %s", prot_str);
- return 1;
+ req->protocol = RPROT_NONE;
+ logmsg("got unknown protocol %s", prot_str);
+ return 1;
}
req->prot_version = prot_major*10 + prot_minor;
@@ -375,10 +375,10 @@ static int ProcessRequest(struct httprequest *req)
char *filename;
if((strlen(doc) + strlen(request)) < 200)
- sprintf(logbuf, "Got request: %s %s %s/%d.%d",
- request, doc, prot_str, prot_major, prot_minor);
+ snprintf(logbuf, sizeof(logbuf), "Got request: %s %s %s/%d.%d",
+ request, doc, prot_str, prot_major, prot_minor);
else
- sprintf(logbuf, "Got a *HUGE* request %s/%d.%d",
+ snprintf(logbuf, sizeof(logbuf), "Got a *HUGE* request %s/%d.%d",
prot_str, prot_major, prot_minor);
logmsg("%s", logbuf);
@@ -409,8 +409,8 @@ static int ProcessRequest(struct httprequest *req)
else
req->partno = 0;
- sprintf(logbuf, "Requested test number %ld part %ld",
- req->testno, req->partno);
+ snprintf(logbuf, sizeof(logbuf), "Requested test number %ld part %ld",
+ req->testno, req->partno);
logmsg("%s", logbuf);
filename = test2file(req->testno);
@@ -488,7 +488,7 @@ static int ProcessRequest(struct httprequest *req)
rtp_scratch[0] = '$';
/* The channel follows and is one byte */
- SET_RTP_PKT_CHN(rtp_scratch ,rtp_channel);
+ SET_RTP_PKT_CHN(rtp_scratch, rtp_channel);
/* Length follows and is a two byte short in network order */
SET_RTP_PKT_LEN(rtp_scratch, rtp_size);
@@ -501,14 +501,18 @@ static int ProcessRequest(struct httprequest *req)
if(req->rtp_buffer == NULL) {
req->rtp_buffer = rtp_scratch;
req->rtp_buffersize = rtp_size + 4;
- } else {
- req->rtp_buffer = realloc(req->rtp_buffer, req->rtp_buffersize + rtp_size + 4);
- memcpy(req->rtp_buffer + req->rtp_buffersize, rtp_scratch, rtp_size + 4);
+ }
+ else {
+ req->rtp_buffer = realloc(req->rtp_buffer,
+ req->rtp_buffersize +
+ rtp_size + 4);
+ memcpy(req->rtp_buffer + req->rtp_buffersize, rtp_scratch,
+ rtp_size + 4);
req->rtp_buffersize += rtp_size + 4;
free(rtp_scratch);
}
- logmsg("rtp_buffersize is %zu, rtp_size is %d.", req->rtp_buffersize, rtp_size);
-
+ logmsg("rtp_buffersize is %zu, rtp_size is %d.",
+ req->rtp_buffersize, rtp_size);
}
}
else {
@@ -529,8 +533,9 @@ static int ProcessRequest(struct httprequest *req)
else {
if(sscanf(req->reqbuf, "CONNECT %" MAXDOCNAMELEN_TXT "s HTTP/%d.%d",
doc, &prot_major, &prot_minor) == 3) {
- sprintf(logbuf, "Received a CONNECT %s HTTP/%d.%d request",
- doc, prot_major, prot_minor);
+ snprintf(logbuf, sizeof(logbuf),
+ "Received a CONNECT %s HTTP/%d.%d request",
+ doc, prot_major, prot_minor);
logmsg("%s", logbuf);
if(req->prot_version == 10)
@@ -662,10 +667,11 @@ static int ProcessRequest(struct httprequest *req)
req->ntlm = TRUE; /* NTLM found */
logmsg("Received NTLM type-1, sending back data %ld", req->partno);
}
- else if((req->partno >= 1000) && strstr(req->reqbuf, "Authorization: Basic")) {
- /* If the client is passing this Basic-header and the part number is already
- >=1000, we add 1 to the part number. This allows simple Basic authentication
- negotiation to work in the test suite. */
+ else if((req->partno >= 1000) &&
+ strstr(req->reqbuf, "Authorization: Basic")) {
+ /* If the client is passing this Basic-header and the part number is
+ already >=1000, we add 1 to the part number. This allows simple Basic
+ authentication negotiation to work in the test suite. */
req->partno += 1;
logmsg("Received Basic request, sending back data %ld", req->partno);
}
@@ -723,15 +729,15 @@ static void storerequest(char *reqbuf, size_t totalsize)
size_t writeleft;
FILE *dump;
- if (reqbuf == NULL)
+ if(reqbuf == NULL)
return;
- if (totalsize == 0)
+ if(totalsize == 0)
return;
do {
dump = fopen(REQUEST_DUMP, "ab");
- } while ((dump == NULL) && ((error = errno) == EINTR));
- if (dump == NULL) {
+ } while((dump == NULL) && ((error = errno) == EINTR));
+ if(dump == NULL) {
logmsg("Error opening file %s error: %d %s",
REQUEST_DUMP, error, strerror(error));
logmsg("Failed to write request input to " REQUEST_DUMP);
@@ -746,7 +752,7 @@ static void storerequest(char *reqbuf, size_t totalsize)
goto storerequest_cleanup;
if(written > 0)
writeleft -= written;
- } while ((writeleft > 0) && ((error = errno) == EINTR));
+ } while((writeleft > 0) && ((error = errno) == EINTR));
if(writeleft == 0)
logmsg("Wrote request (%zu bytes) input to " REQUEST_DUMP, totalsize);
@@ -815,9 +821,9 @@ static int get_request(curl_socket_t sock, struct httprequest *req)
}
else {
if(req->skip)
- /* we are instructed to not read the entire thing, so we make sure to only
- read what we're supposed to and NOT read the enire thing the client
- wants to send! */
+ /* we are instructed to not read the entire thing, so we make sure to
+ only read what we're supposed to and NOT read the enire thing the
+ client wants to send! */
got = sread(sock, reqbuf + req->offset, req->cl);
else
got = sread(sock, reqbuf + req->offset, REQBUFSIZ-1 - req->offset);
@@ -908,7 +914,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
case RCMD_STREAM:
#define STREAMTHIS "a string to stream 01234567890\n"
count = strlen(STREAMTHIS);
- for (;;) {
+ for(;;) {
written = swrite(sock, STREAMTHIS, count);
if(got_exit_signal)
return -1;
@@ -937,10 +943,12 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
case DOCNUMBER_WERULEZ:
/* we got a "friends?" question, reply back that we sure are */
logmsg("Identifying ourselves as friends");
- sprintf(msgbuf, "RTSP_SERVER WE ROOLZ: %ld\r\n", (long)getpid());
+ snprintf(msgbuf, sizeof(msgbuf), "RTSP_SERVER WE ROOLZ: %ld\r\n",
+ (long)getpid());
msglen = strlen(msgbuf);
- sprintf(weare, "HTTP/1.1 200 OK\r\nContent-Length: %zu\r\n\r\n%s",
- msglen, msgbuf);
+ snprintf(weare, sizeof(weare),
+ "HTTP/1.1 200 OK\r\nContent-Length: %zu\r\n\r\n%s",
+ msglen, msgbuf);
buffer = weare;
break;
case DOCNUMBER_INTERNAL:
@@ -958,9 +966,10 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
default:
logmsg("Replying to with a 404");
if(req->protocol == RPROT_HTTP) {
- buffer = doc404_HTTP;
- } else {
- buffer = doc404_RTSP;
+ buffer = doc404_HTTP;
+ }
+ else {
+ buffer = doc404_RTSP;
}
break;
}
@@ -971,7 +980,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
char *filename = test2file(req->testno);
if(0 != req->partno)
- sprintf(partbuf, "data%ld", req->partno);
+ snprintf(partbuf, sizeof(partbuf), "data%ld", req->partno);
stream=fopen(filename, "rb");
if(!stream) {
@@ -1058,7 +1067,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
if(num > 200)
num = 200;
written = swrite(sock, buffer, num);
- if (written < 0) {
+ if(written < 0) {
sendfailure = TRUE;
break;
}
@@ -1082,7 +1091,8 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
size_t num = count;
if(num > 200)
num = 200;
- written = swrite(sock, req->rtp_buffer + (req->rtp_buffersize - count), num);
+ written = swrite(sock, req->rtp_buffer + (req->rtp_buffersize - count),
+ num);
if(written < 0) {
sendfailure = TRUE;
break;
@@ -1108,7 +1118,8 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
}
if(sendfailure) {
- logmsg("Sending response failed. Only (%zu bytes) of (%zu bytes) were sent",
+ logmsg("Sending response failed. Only (%zu bytes) of "
+ "(%zu bytes) were sent",
responsesize-count, responsesize);
free(ptr);
free(cmd);
@@ -1119,7 +1130,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
responsesize);
free(ptr);
- if(cmdsize > 0 ) {
+ if(cmdsize > 0) {
char command[32];
int quarters;
int num;
@@ -1278,7 +1289,7 @@ int main(int argc, char *argv[])
}
flag = 1;
- if (0 != setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
+ if(0 != setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
(void *)&flag, sizeof(flag))) {
error = SOCKERRNO;
logmsg("setsockopt(SO_REUSEADDR) failed with error: (%d) %s",
@@ -1331,12 +1342,12 @@ int main(int argc, char *argv[])
if(!wrotepidfile)
goto server_cleanup;
- for (;;) {
+ for(;;) {
msgsock = accept(sock, NULL, NULL);
if(got_exit_signal)
break;
- if (CURL_SOCKET_BAD == msgsock) {
+ if(CURL_SOCKET_BAD == msgsock) {
error = SOCKERRNO;
logmsg("MAJOR ERROR: accept() failed with error: (%d) %s",
error, strerror(error));
@@ -1360,7 +1371,7 @@ int main(int argc, char *argv[])
* response in many small segments to torture the clients more.
*/
flag = 1;
- if (setsockopt(msgsock, IPPROTO_TCP, TCP_NODELAY,
+ if(setsockopt(msgsock, IPPROTO_TCP, TCP_NODELAY,
(void *)&flag, sizeof(flag)) == -1) {
logmsg("====> TCP_NODELAY failed");
}
@@ -1424,7 +1435,7 @@ int main(int argc, char *argv[])
clear_advisor_read_lock(SERVERLOGS_LOCK);
}
- if (req.testno == DOCNUMBER_QUIT)
+ if(req.testno == DOCNUMBER_QUIT)
break;
}
diff --git a/tests/server/sockfilt.c b/tests/server/sockfilt.c
index 2e30f62fd..38aa51e67 100644
--- a/tests/server/sockfilt.c
+++ b/tests/server/sockfilt.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -53,31 +53,34 @@
*
* This program is a single-threaded process.
*
- * This program is intended to be highly portable and as such it must be kept as
- * simple as possible, due to this the only signal handling mechanisms used will
- * be those of ANSI C, and used only in the most basic form which is good enough
- * for the purpose of this program.
+ * This program is intended to be highly portable and as such it must be kept
+ * as simple as possible, due to this the only signal handling mechanisms used
+ * will be those of ANSI C, and used only in the most basic form which is good
+ * enough for the purpose of this program.
*
* For the above reason and the specific needs of this program signals SIGHUP,
- * SIGPIPE and SIGALRM will be simply ignored on systems where this can be done.
- * If possible, signals SIGINT and SIGTERM will be handled by this program as an
- * indication to cleanup and finish execution as soon as possible. This will be
- * achieved with a single signal handler 'exit_signal_handler' for both signals.
+ * SIGPIPE and SIGALRM will be simply ignored on systems where this can be
+ * done. If possible, signals SIGINT and SIGTERM will be handled by this
+ * program as an indication to cleanup and finish execution as soon as
+ * possible. This will be achieved with a single signal handler
+ * 'exit_signal_handler' for both signals.
*
* The 'exit_signal_handler' upon the first SIGINT or SIGTERM received signal
* will just set to one the global var 'got_exit_signal' storing in global var
* 'exit_signal' the signal that triggered this change.
*
* Nothing fancy that could introduce problems is used, the program at certain
- * points in its normal flow checks if var 'got_exit_signal' is set and in case
- * this is true it just makes its way out of loops and functions in structured
- * and well behaved manner to achieve proper program cleanup and termination.
+ * points in its normal flow checks if var 'got_exit_signal' is set and in
+ * case this is true it just makes its way out of loops and functions in
+ * structured and well behaved manner to achieve proper program cleanup and
+ * termination.
*
- * Even with the above mechanism implemented it is worthwile to note that other
- * signals might still be received, or that there might be systems on which it
- * is not possible to trap and ignore some of the above signals. This implies
- * that for increased portability and reliability the program must be coded as
- * if no signal was being ignored or handled at all. Enjoy it!
+ * Even with the above mechanism implemented it is worthwile to note that
+ * other signals might still be received, or that there might be systems on
+ * which it is not possible to trap and ignore some of the above signals.
+ * This implies that for increased portability and reliability the program
+ * must be coded as if no signal was being ignored or handled at all. Enjoy
+ * it!
*/
#ifdef HAVE_SIGNAL_H
@@ -469,23 +472,28 @@ static void lograw(unsigned char *buffer, ssize_t len)
unsigned char *ptr = buffer;
char *optr = data;
ssize_t width=0;
+ int left = sizeof(data);
for(i=0; i<len; i++) {
switch(ptr[i]) {
case '\n':
- sprintf(optr, "\\n");
+ snprintf(optr, left, "\\n");
width += 2;
optr += 2;
+ left-=2;
break;
case '\r':
- sprintf(optr, "\\r");
+ snprintf(optr, left, "\\r");
width += 2;
optr += 2;
+ left-=2;
break;
default:
- sprintf(optr, "%c", (ISGRAPH(ptr[i]) || ptr[i]==0x20) ?ptr[i]:'.');
+ snprintf(optr, left, "%c", (ISGRAPH(ptr[i]) ||
+ ptr[i]==0x20) ?ptr[i]:'.');
width++;
optr++;
+ left--;
break;
}
@@ -493,6 +501,7 @@ static void lograw(unsigned char *buffer, ssize_t len)
logmsg("'%s'", data);
width = 0;
optr = data;
+ left = sizeof(data);
}
}
if(width)
@@ -1038,7 +1047,7 @@ static bool juggle(curl_socket_t *sockfdp,
return FALSE;
logmsg("Received %c%c%c%c (on stdin)",
- buffer[0], buffer[1], buffer[2], buffer[3] );
+ buffer[0], buffer[1], buffer[2], buffer[3]);
if(!memcmp("PING", buffer, 4)) {
/* send reply on stdout, just proving we are alive */
@@ -1049,7 +1058,7 @@ static bool juggle(curl_socket_t *sockfdp,
else if(!memcmp("PORT", buffer, 4)) {
/* Question asking us what PORT number we are listening to.
Replies to PORT with "IPv[num]/[port]" */
- sprintf((char *)buffer, "%s/%hu\n", ipv_inuse, port);
+ snprintf((char *)buffer, sizeof(buffer), "%s/%hu\n", ipv_inuse, port);
buffer_len = (ssize_t)strlen((char *)buffer);
snprintf(data, sizeof(data), "PORT\n%04zx\n", buffer_len);
if(!write_stdout(data, 10))
@@ -1071,7 +1080,7 @@ static bool juggle(curl_socket_t *sockfdp,
buffer[5] = '\0';
buffer_len = (ssize_t)strtol((char *)buffer, NULL, 16);
- if (buffer_len > (ssize_t)sizeof(buffer)) {
+ if(buffer_len > (ssize_t)sizeof(buffer)) {
logmsg("ERROR: Buffer size (%zu bytes) too small for data size "
"(%zd bytes)", sizeof(buffer), buffer_len);
return FALSE;
@@ -1469,7 +1478,7 @@ int main(int argc, char *argv[])
me.sa4.sin_family = AF_INET;
me.sa4.sin_port = htons(connectport);
me.sa4.sin_addr.s_addr = INADDR_ANY;
- if (!addr)
+ if(!addr)
addr = "127.0.0.1";
Curl_inet_pton(AF_INET, addr, &me.sa4.sin_addr);
@@ -1480,7 +1489,7 @@ int main(int argc, char *argv[])
memset(&me.sa6, 0, sizeof(me.sa6));
me.sa6.sin6_family = AF_INET6;
me.sa6.sin6_port = htons(connectport);
- if (!addr)
+ if(!addr)
addr = "::1";
Curl_inet_pton(AF_INET6, addr, &me.sa6.sin6_addr);
diff --git a/tests/server/sws.c b/tests/server/sws.c
index ffed3838d..27c86e013 100644
--- a/tests/server/sws.c
+++ b/tests/server/sws.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -491,11 +491,11 @@ static int ProcessRequest(struct httprequest *req)
/* get the number after it */
if(ptr) {
if((strlen(doc) + strlen(request)) < 400)
- sprintf(logbuf, "Got request: %s %s HTTP/%d.%d",
- request, doc, prot_major, prot_minor);
+ snprintf(logbuf, sizeof(logbuf), "Got request: %s %s HTTP/%d.%d",
+ request, doc, prot_major, prot_minor);
else
- sprintf(logbuf, "Got a *HUGE* request HTTP/%d.%d",
- prot_major, prot_minor);
+ snprintf(logbuf, sizeof(logbuf), "Got a *HUGE* request HTTP/%d.%d",
+ prot_major, prot_minor);
logmsg("%s", logbuf);
if(!strncmp("/verifiedserver", ptr, 15)) {
@@ -527,8 +527,8 @@ static int ProcessRequest(struct httprequest *req)
if(req->testno) {
- sprintf(logbuf, "Requested test number %ld part %ld",
- req->testno, req->partno);
+ snprintf(logbuf, sizeof(logbuf), "Requested test number %ld part %ld",
+ req->testno, req->partno);
logmsg("%s", logbuf);
/* find and parse <servercmd> for this test */
@@ -548,8 +548,9 @@ static int ProcessRequest(struct httprequest *req)
char *portp = NULL;
unsigned long part=0;
- sprintf(logbuf, "Received a CONNECT %s HTTP/%d.%d request",
- doc, prot_major, prot_minor);
+ snprintf(logbuf, sizeof(logbuf),
+ "Received a CONNECT %s HTTP/%d.%d request",
+ doc, prot_major, prot_minor);
logmsg("%s", logbuf);
req->connect_request = TRUE;
@@ -571,7 +572,7 @@ static int ProcessRequest(struct httprequest *req)
}
if(*p != ']')
logmsg("Invalid CONNECT IPv6 address format");
- else if (*(p+1) != ':')
+ else if(*(p+1) != ':')
logmsg("Invalid CONNECT IPv6 port format");
else
portp = p+1;
@@ -618,8 +619,9 @@ static int ProcessRequest(struct httprequest *req)
else
req->partno = 0;
- sprintf(logbuf, "Requested test number %ld part %ld (from host name)",
- req->testno, req->partno);
+ snprintf(logbuf, sizeof(logbuf),
+ "Requested test number %ld part %ld (from host name)",
+ req->testno, req->partno);
logmsg("%s", logbuf);
}
@@ -668,8 +670,9 @@ static int ProcessRequest(struct httprequest *req)
else
req->partno = 0;
- sprintf(logbuf, "Requested GOPHER test number %ld part %ld",
- req->testno, req->partno);
+ snprintf(logbuf, sizeof(logbuf),
+ "Requested GOPHER test number %ld part %ld",
+ req->testno, req->partno);
logmsg("%s", logbuf);
}
}
@@ -843,15 +846,15 @@ static void storerequest(char *reqbuf, size_t totalsize)
FILE *dump;
const char *dumpfile=is_proxy?REQUEST_PROXY_DUMP:REQUEST_DUMP;
- if (reqbuf == NULL)
+ if(reqbuf == NULL)
return;
- if (totalsize == 0)
+ if(totalsize == 0)
return;
do {
dump = fopen(dumpfile, "ab");
- } while ((dump == NULL) && ((error = errno) == EINTR));
- if (dump == NULL) {
+ } while((dump == NULL) && ((error = errno) == EINTR));
+ if(dump == NULL) {
logmsg("[2] Error opening file %s error: %d %s",
dumpfile, error, strerror(error));
logmsg("Failed to write request input ");
@@ -866,7 +869,7 @@ static void storerequest(char *reqbuf, size_t totalsize)
goto storerequest_cleanup;
if(written > 0)
writeleft -= written;
- } while ((writeleft > 0) && ((error = errno) == EINTR));
+ } while((writeleft > 0) && ((error = errno) == EINTR));
if(writeleft == 0)
logmsg("Wrote request (%zu bytes) input to %s", totalsize, dumpfile);
@@ -968,7 +971,7 @@ static int get_request(curl_socket_t sock, struct httprequest *req)
}
else if(got < 0) {
error = SOCKERRNO;
- if (EAGAIN == error || EWOULDBLOCK == error) {
+ if(EAGAIN == error || EWOULDBLOCK == error) {
/* nothing to read at the moment */
return 0;
}
@@ -1013,7 +1016,7 @@ static int get_request(curl_socket_t sock, struct httprequest *req)
reqbuf[req->offset] = '\0';
/* at the end of a request dump it to an external file */
- if (fail || req->done_processing)
+ if(fail || req->done_processing)
storerequest(reqbuf, req->pipelining ? req->checkindex : req->offset);
if(got_exit_signal)
return -1;
@@ -1047,7 +1050,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
case RCMD_STREAM:
#define STREAMTHIS "a string to stream 01234567890\n"
count = strlen(STREAMTHIS);
- for (;;) {
+ for(;;) {
written = swrite(sock, STREAMTHIS, count);
if(got_exit_signal)
return -1;
@@ -1076,13 +1079,14 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
case DOCNUMBER_WERULEZ:
/* we got a "friends?" question, reply back that we sure are */
logmsg("Identifying ourselves as friends");
- sprintf(msgbuf, "WE ROOLZ: %ld\r\n", (long)getpid());
+ snprintf(msgbuf, sizeof(msgbuf), "WE ROOLZ: %ld\r\n", (long)getpid());
msglen = strlen(msgbuf);
if(use_gopher)
- sprintf(weare, "%s", msgbuf);
+ snprintf(weare, sizeof(weare), "%s", msgbuf);
else
- sprintf(weare, "HTTP/1.1 200 OK\r\nContent-Length: %zu\r\n\r\n%s",
- msglen, msgbuf);
+ snprintf(weare, sizeof(weare),
+ "HTTP/1.1 200 OK\r\nContent-Length: %zu\r\n\r\n%s",
+ msglen, msgbuf);
buffer = weare;
break;
case DOCNUMBER_404:
@@ -1103,9 +1107,9 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
const char *section= req->connect_request?"connect":"data";
if(req->partno)
- sprintf(partbuf, "%s%ld", section, req->partno);
+ snprintf(partbuf, sizeof(partbuf), "%s%ld", section, req->partno);
else
- sprintf(partbuf, "%s", section);
+ snprintf(partbuf, sizeof(partbuf), "%s", section);
logmsg("Send response test%ld section <%s>", req->testno, partbuf);
@@ -1191,7 +1195,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
if(num > 200)
num = 200;
written = swrite(sock, buffer, num);
- if (written < 0) {
+ if(written < 0) {
sendfailure = TRUE;
break;
}
@@ -1228,7 +1232,8 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
}
if(sendfailure) {
- logmsg("Sending response failed. Only (%zu bytes) of (%zu bytes) were sent",
+ logmsg("Sending response failed. Only (%zu bytes) of (%zu bytes) "
+ "were sent",
responsesize-count, responsesize);
free(ptr);
free(cmd);
@@ -1239,7 +1244,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
responsesize, responsedump);
free(ptr);
- if(cmdsize > 0 ) {
+ if(cmdsize > 0) {
char command[32];
int quarters;
int num;
@@ -1552,7 +1557,8 @@ static void http_connect(curl_socket_t *infdp,
/* connect to the server */
serverfd[DATA] = connect_to(ipaddr, req2.connect_port);
if(serverfd[DATA] != CURL_SOCKET_BAD) {
- /* secondary tunnel established, now we have two connections */
+ /* secondary tunnel established, now we have two
+ connections */
poll_client_rd[DATA] = TRUE;
poll_client_wr[DATA] = TRUE;
poll_server_rd[DATA] = TRUE;
@@ -1874,7 +1880,7 @@ static int service_connection(curl_socket_t msgsock, struct httprequest *req,
while(!req->done_processing) {
int rc = get_request(msgsock, req);
- if (rc <= 0) {
+ if(rc <= 0) {
/* Nothing further to read now (possibly because the socket was closed */
return rc;
}
@@ -2153,7 +2159,7 @@ int main(int argc, char *argv[])
/* socket server is not alive, now check if it was actually a socket.
* Systems which have Unix sockets will also have lstat */
rc = lstat(unix_socket, &statbuf);
- if (0 != rc) {
+ if(0 != rc) {
logmsg("Error binding socket, failed to stat %s: (%d) %s",
unix_socket, errno, strerror(errno));
goto sws_cleanup;
@@ -2223,8 +2229,8 @@ int main(int argc, char *argv[])
curl_socket_t maxfd = (curl_socket_t)-1;
/* Clear out closed sockets */
- for (socket_idx = num_sockets - 1; socket_idx >= 1; --socket_idx) {
- if (CURL_SOCKET_BAD == all_sockets[socket_idx]) {
+ for(socket_idx = num_sockets - 1; socket_idx >= 1; --socket_idx) {
+ if(CURL_SOCKET_BAD == all_sockets[socket_idx]) {
char* dst = (char *) (all_sockets + socket_idx);
char* src = (char *) (all_sockets + socket_idx + 1);
char* end = (char *) (all_sockets + num_sockets);
@@ -2240,7 +2246,7 @@ int main(int argc, char *argv[])
FD_ZERO(&input);
FD_ZERO(&output);
- for (socket_idx = 0; socket_idx < num_sockets; ++socket_idx) {
+ for(socket_idx = 0; socket_idx < num_sockets; ++socket_idx) {
/* Listen on all sockets */
FD_SET(all_sockets[socket_idx], &input);
if(all_sockets[socket_idx] > maxfd)
@@ -2251,7 +2257,7 @@ int main(int argc, char *argv[])
goto sws_cleanup;
rc = select((int)maxfd + 1, &input, &output, NULL, &timeout);
- if (rc < 0) {
+ if(rc < 0) {
error = SOCKERRNO;
logmsg("select() failed with error: (%d) %s",
error, strerror(error));
@@ -2261,26 +2267,26 @@ int main(int argc, char *argv[])
if(got_exit_signal)
goto sws_cleanup;
- if (rc == 0) {
+ if(rc == 0) {
/* Timed out - try again*/
continue;
}
/* Check if the listening socket is ready to accept */
- if (FD_ISSET(all_sockets[0], &input)) {
+ if(FD_ISSET(all_sockets[0], &input)) {
/* Service all queued connections */
curl_socket_t msgsock;
do {
msgsock = accept_connection(sock);
logmsg("accept_connection %d returned %d", sock, msgsock);
- if (CURL_SOCKET_BAD == msgsock)
+ if(CURL_SOCKET_BAD == msgsock)
goto sws_cleanup;
- } while (msgsock > 0);
+ } while(msgsock > 0);
}
/* Service all connections that are ready */
- for (socket_idx = 1; socket_idx < num_sockets; ++socket_idx) {
- if (FD_ISSET(all_sockets[socket_idx], &input)) {
+ for(socket_idx = 1; socket_idx < num_sockets; ++socket_idx) {
+ if(FD_ISSET(all_sockets[socket_idx], &input)) {
if(got_exit_signal)
goto sws_cleanup;
@@ -2291,7 +2297,7 @@ int main(int argc, char *argv[])
if(got_exit_signal)
goto sws_cleanup;
- if (rc < 0) {
+ if(rc < 0) {
logmsg("====> Client disconnect %d", req.connmon);
if(req.connmon) {
@@ -2315,14 +2321,14 @@ int main(int argc, char *argv[])
if(!serverlogslocked)
clear_advisor_read_lock(SERVERLOGS_LOCK);
- if (req.testno == DOCNUMBER_QUIT)
+ if(req.testno == DOCNUMBER_QUIT)
goto sws_cleanup;
}
/* Reset the request, unless we're still in the middle of reading */
- if (rc != 0)
+ if(rc != 0)
init_httprequest(&req);
- } while (rc > 0);
+ } while(rc > 0);
}
}
@@ -2332,7 +2338,7 @@ int main(int argc, char *argv[])
sws_cleanup:
- for (socket_idx = 1; socket_idx < num_sockets; ++socket_idx)
+ for(socket_idx = 1; socket_idx < num_sockets; ++socket_idx)
if((all_sockets[socket_idx] != sock) &&
(all_sockets[socket_idx] != CURL_SOCKET_BAD))
sclose(all_sockets[socket_idx]);
diff --git a/tests/server/testpart.c b/tests/server/testpart.c
index 86854f645..f3a70c7cf 100644
--- a/tests/server/testpart.c
+++ b/tests/server/testpart.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -41,7 +41,7 @@ int main(int argc, char **argv)
else {
rc = getpart(&part, &partlen, argv[1], argv[2], stdin);
if(rc)
- return(rc);
+ return rc;
for(i = 0; i < partlen; i++)
printf("%c", part[i]);
free(part);
diff --git a/tests/server/tftpd.c b/tests/server/tftpd.c
index ffc2496d6..afc0884e0 100644
--- a/tests/server/tftpd.c
+++ b/tests/server/tftpd.c
@@ -459,7 +459,7 @@ static int readit(struct testcase *test, struct tftphdr **dpp,
current = !current; /* "incr" current */
b = &bfs[current]; /* look at new buffer */
- if (b->counter == BF_FREE) /* if it's empty */
+ if(b->counter == BF_FREE) /* if it's empty */
read_ahead(test, convert); /* fill it */
*dpp = &b->buf.hdr; /* set caller's ptr */
@@ -468,7 +468,7 @@ static int readit(struct testcase *test, struct tftphdr **dpp,
/*
* fill the input buffer, doing ascii conversions if requested
- * conversions are lf -> cr,lf and cr -> cr, nul
+ * conversions are lf -> cr, lf and cr -> cr, nul
*/
static void read_ahead(struct testcase *test,
int convert /* if true, convert to ascii */)
@@ -480,13 +480,13 @@ static void read_ahead(struct testcase *test,
struct tftphdr *dp;
b = &bfs[nextone]; /* look at "next" buffer */
- if (b->counter != BF_FREE) /* nop if not free */
+ if(b->counter != BF_FREE) /* nop if not free */
return;
nextone = !nextone; /* "incr" next buffer ptr */
dp = &b->buf.hdr;
- if (convert == 0) {
+ if(convert == 0) {
/* The former file reading code did this:
b->counter = read(fileno(file), dp->th_data, SEGSIZE); */
size_t copy_n = MIN(SEGSIZE, test->rcount);
@@ -500,9 +500,9 @@ static void read_ahead(struct testcase *test,
}
p = dp->th_data;
- for (i = 0 ; i < SEGSIZE; i++) {
- if (newline) {
- if (prevchar == '\n')
+ for(i = 0 ; i < SEGSIZE; i++) {
+ if(newline) {
+ if(prevchar == '\n')
c = '\n'; /* lf to cr,lf */
else
c = '\0'; /* cr to cr,nul */
@@ -516,7 +516,7 @@ static void read_ahead(struct testcase *test,
}
else
break;
- if (c == '\n' || c == '\r') {
+ if(c == '\n' || c == '\r') {
prevchar = c;
c = '\r';
newline = 1;
@@ -535,7 +535,7 @@ static int writeit(struct testcase *test, struct tftphdr * volatile *dpp,
{
bfs[current].counter = ct; /* set size of data to write */
current = !current; /* switch to other buffer */
- if (bfs[current].counter != BF_FREE) /* if not free */
+ if(bfs[current].counter != BF_FREE) /* if not free */
write_behind(test, convert); /* flush it */
bfs[current].counter = BF_ALLOC; /* mark as alloc'd */
*dpp = &bfs[current].buf.hdr;
@@ -544,7 +544,7 @@ static int writeit(struct testcase *test, struct tftphdr * volatile *dpp,
/*
* Output a buffer to a file, converting from netascii if requested.
- * CR,NUL -> CR and CR,LF => LF.
+ * CR, NUL -> CR and CR, LF => LF.
* Note spec is undefined if we get CR as last byte of file or a
* CR followed by anything else. In this case we leave it alone.
*/
@@ -559,7 +559,7 @@ static ssize_t write_behind(struct testcase *test, int convert)
struct tftphdr *dp;
b = &bfs[nextone];
- if (b->counter < -1) /* anything to flush? */
+ if(b->counter < -1) /* anything to flush? */
return 0; /* just nop if nothing to do */
if(!test->ofile) {
@@ -582,21 +582,21 @@ static ssize_t write_behind(struct testcase *test, int convert)
nextone = !nextone; /* incr for next time */
writebuf = dp->th_data;
- if (count <= 0)
+ if(count <= 0)
return -1; /* nak logic? */
- if (convert == 0)
+ if(convert == 0)
return write(test->ofile, writebuf, count);
p = writebuf;
ct = count;
- while (ct--) { /* loop over the buffer */
+ while(ct--) { /* loop over the buffer */
c = *p++; /* pick up a character */
- if (prevchar == '\r') { /* if prev char was cr */
- if (c == '\n') /* if have cr,lf then just */
+ if(prevchar == '\r') { /* if prev char was cr */
+ if(c == '\n') /* if have cr,lf then just */
lseek(test->ofile, -1, SEEK_CUR); /* smash lf on top of the cr */
else
- if (c == '\0') /* if have cr,nul then */
+ if(c == '\0') /* if have cr,nul then */
goto skipit; /* just skip over the putc */
/* else just fall through and allow it */
}
@@ -634,13 +634,13 @@ static int synchnet(curl_socket_t f /* socket to flush */)
srvr_sockaddr_union_t fromaddr;
curl_socklen_t fromaddrlen;
- for (;;) {
+ for(;;) {
#if defined(HAVE_IOCTLSOCKET)
(void) ioctlsocket(f, FIONREAD, &i);
#else
(void) ioctl(f, FIONREAD, &i);
#endif
- if (i) {
+ if(i) {
j++;
#ifdef ENABLE_IPV6
if(!use_ipv6)
@@ -773,7 +773,7 @@ int main(int argc, char **argv)
}
flag = 1;
- if (0 != setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
+ if(0 != setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
(void *)&flag, sizeof(flag))) {
error = SOCKERRNO;
logmsg("setsockopt(SO_REUSEADDR) failed with error: (%d) %s",
@@ -816,7 +816,7 @@ int main(int argc, char **argv)
logmsg("Running %s version on port UDP/%d", ipv_inuse, (int)port);
- for (;;) {
+ for(;;) {
fromlen = sizeof(from);
#ifdef ENABLE_IPV6
if(!use_ipv6)
@@ -830,7 +830,7 @@ int main(int argc, char **argv)
&from.sa, &fromlen);
if(got_exit_signal)
break;
- if (n < 0) {
+ if(n < 0) {
logmsg("recvfrom");
result = 3;
break;
@@ -876,9 +876,9 @@ int main(int argc, char **argv)
tp = &buf.hdr;
tp->th_opcode = ntohs(tp->th_opcode);
- if (tp->th_opcode == opcode_RRQ || tp->th_opcode == opcode_WRQ) {
+ if(tp->th_opcode == opcode_RRQ || tp->th_opcode == opcode_WRQ) {
memset(&test, 0, sizeof(test));
- if (do_tftp(&test, tp, n) < 0)
+ if(do_tftp(&test, tp, n) < 0)
break;
free(test.buffer);
}
@@ -974,8 +974,8 @@ static int do_tftp(struct testcase *test, struct tftphdr *tp, ssize_t size)
filename = cp;
do {
bool endofit = true;
- while (cp < &buf.storage[size]) {
- if (*cp == '\0') {
+ while(cp < &buf.storage[size]) {
+ if(*cp == '\0') {
endofit = false;
break;
}
@@ -1008,7 +1008,7 @@ static int do_tftp(struct testcase *test, struct tftphdr *tp, ssize_t size)
break;
} while(1);
- if (*cp) {
+ if(*cp) {
nak(EBADOP);
fclose(server);
return 3;
@@ -1017,22 +1017,22 @@ static int do_tftp(struct testcase *test, struct tftphdr *tp, ssize_t size)
/* store input protocol */
fprintf(server, "filename: %s\n", filename);
- for (cp = mode; cp && *cp; cp++)
+ for(cp = mode; cp && *cp; cp++)
if(ISUPPER(*cp))
*cp = (char)tolower((int)*cp);
/* store input protocol */
fclose(server);
- for (pf = formata; pf->f_mode; pf++)
- if (strcmp(pf->f_mode, mode) == 0)
+ for(pf = formata; pf->f_mode; pf++)
+ if(strcmp(pf->f_mode, mode) == 0)
break;
- if (!pf->f_mode) {
+ if(!pf->f_mode) {
nak(EBADOP);
return 2;
}
ecode = validate_access(test, filename, tp->th_opcode);
- if (ecode) {
+ if(ecode) {
nak(ecode);
return 1;
}
@@ -1046,7 +1046,7 @@ static int do_tftp(struct testcase *test, struct tftphdr *tp, ssize_t size)
(const char*)&recvtimeout, sizeof(recvtimeout));
#endif
- if (tp->th_opcode == opcode_WRQ)
+ if(tp->th_opcode == opcode_WRQ)
recvtftp(test, pf);
else
sendtftp(test, pf);
@@ -1141,7 +1141,8 @@ static int validate_access(struct testcase *test,
if(!strncmp("verifiedserver", filename, 14)) {
char weare[128];
- size_t count = sprintf(weare, "WE ROOLZ: %ld\r\n", (long)getpid());
+ size_t count = snprintf(weare, sizeof(weare),
+ "WE ROOLZ: %ld\r\n", (long)getpid());
logmsg("Are-we-friendly question received");
test->buffer = strdup(weare);
@@ -1183,7 +1184,7 @@ static int validate_access(struct testcase *test,
file = test2file(testno);
if(0 != partno)
- sprintf(partbuf, "data%ld", partno);
+ snprintf(partbuf, sizeof(partbuf), "data%ld", partno);
if(file) {
FILE *stream=fopen(file, "rb");
@@ -1244,7 +1245,7 @@ static void sendtftp(struct testcase *test, struct formats *pf)
sap = &ackbuf.hdr;
do {
size = readit(test, &sdp, pf->f_convert);
- if (size < 0) {
+ if(size < 0) {
nak(errno + 100);
return;
}
@@ -1261,12 +1262,12 @@ static void sendtftp(struct testcase *test, struct formats *pf)
}
send_data:
- if (swrite(peer, sdp, size + 4) != size + 4) {
+ if(swrite(peer, sdp, size + 4) != size + 4) {
logmsg("write");
return;
}
read_ahead(test, pf->f_convert);
- for ( ; ; ) {
+ for(;;) {
#ifdef HAVE_ALARM
alarm(rexmtval); /* read the ack */
#endif
@@ -1276,32 +1277,32 @@ static void sendtftp(struct testcase *test, struct formats *pf)
#endif
if(got_exit_signal)
return;
- if (n < 0) {
+ if(n < 0) {
logmsg("read: fail");
return;
}
sap->th_opcode = ntohs((unsigned short)sap->th_opcode);
sap->th_block = ntohs(sap->th_block);
- if (sap->th_opcode == opcode_ERROR) {
+ if(sap->th_opcode == opcode_ERROR) {
logmsg("got ERROR");
return;
}
- if (sap->th_opcode == opcode_ACK) {
- if (sap->th_block == sendblock) {
+ if(sap->th_opcode == opcode_ACK) {
+ if(sap->th_block == sendblock) {
break;
}
/* Re-synchronize with the other side */
(void) synchnet(peer);
- if (sap->th_block == (sendblock-1)) {
+ if(sap->th_block == (sendblock-1)) {
goto send_data;
}
}
}
sendblock++;
- } while (size == SEGSIZE);
+ } while(size == SEGSIZE);
}
/*
@@ -1330,12 +1331,12 @@ static void recvtftp(struct testcase *test, struct formats *pf)
(void) sigsetjmp(timeoutbuf, 1);
#endif
send_ack:
- if (swrite(peer, &ackbuf.storage[0], 4) != 4) {
+ if(swrite(peer, &ackbuf.storage[0], 4) != 4) {
logmsg("write: fail\n");
goto abort;
}
write_behind(test, pf->f_convert);
- for ( ; ; ) {
+ for(;;) {
#ifdef HAVE_ALARM
alarm(rexmtval);
#endif
@@ -1345,37 +1346,38 @@ send_ack:
#endif
if(got_exit_signal)
goto abort;
- if (n < 0) { /* really? */
+ if(n < 0) { /* really? */
logmsg("read: fail\n");
goto abort;
}
rdp->th_opcode = ntohs((unsigned short)rdp->th_opcode);
rdp->th_block = ntohs(rdp->th_block);
- if (rdp->th_opcode == opcode_ERROR)
+ if(rdp->th_opcode == opcode_ERROR)
goto abort;
- if (rdp->th_opcode == opcode_DATA) {
- if (rdp->th_block == recvblock) {
+ if(rdp->th_opcode == opcode_DATA) {
+ if(rdp->th_block == recvblock) {
break; /* normal */
}
/* Re-synchronize with the other side */
(void) synchnet(peer);
- if (rdp->th_block == (recvblock-1))
+ if(rdp->th_block == (recvblock-1))
goto send_ack; /* rexmit */
}
}
size = writeit(test, &rdp, (int)(n - 4), pf->f_convert);
- if (size != (n-4)) { /* ahem */
- if (size < 0)
+ if(size != (n-4)) { /* ahem */
+ if(size < 0)
nak(errno + 100);
else
nak(ENOSPACE);
goto abort;
}
- } while (size == SEGSIZE);
+ } while(size == SEGSIZE);
write_behind(test, pf->f_convert);
- rap->th_opcode = htons((unsigned short)opcode_ACK); /* send the "final" ack */
+ rap->th_opcode = htons((unsigned short)opcode_ACK); /* send the "final"
+ ack */
rap->th_block = htons(recvblock);
(void) swrite(peer, &ackbuf.storage[0], 4);
#if defined(HAVE_ALARM) && defined(SIGALRM)
@@ -1389,9 +1391,9 @@ send_ack:
#endif
if(got_exit_signal)
goto abort;
- if (n >= 4 && /* if read some data */
- rdp->th_opcode == opcode_DATA && /* and got a data block */
- recvblock == rdp->th_block) { /* then my last ack was lost */
+ if(n >= 4 && /* if read some data */
+ rdp->th_opcode == opcode_DATA && /* and got a data block */
+ recvblock == rdp->th_block) { /* then my last ack was lost */
(void) swrite(peer, &ackbuf.storage[0], 4); /* resend final ack */
}
abort:
@@ -1411,10 +1413,10 @@ static void nak(int error)
tp = &buf.hdr;
tp->th_opcode = htons((unsigned short)opcode_ERROR);
tp->th_code = htons((unsigned short)error);
- for (pe = errmsgs; pe->e_code >= 0; pe++)
- if (pe->e_code == error)
+ for(pe = errmsgs; pe->e_code >= 0; pe++)
+ if(pe->e_code == error)
break;
- if (pe->e_code < 0) {
+ if(pe->e_code < 0) {
pe->e_msg = strerror(error - 100);
tp->th_code = EUNDEF; /* set 'undef' errorcode */
}
@@ -1424,6 +1426,6 @@ static void nak(int error)
* report from glibc with FORTIFY_SOURCE */
memcpy(tp->th_msg, pe->e_msg, length + 1);
length += 5;
- if (swrite(peer, &buf.storage[0], length) != length)
+ if(swrite(peer, &buf.storage[0], length) != length)
logmsg("nak: fail\n");
}
diff --git a/tests/server/util.c b/tests/server/util.c
index 535554c9b..d99336397 100644
--- a/tests/server/util.c
+++ b/tests/server/util.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -77,11 +77,11 @@ char *data_to_hex(char *data, size_t len)
if((data[i] >= 0x20) && (data[i] < 0x7f))
*optr++ = *iptr++;
else {
- sprintf(optr, "%%%02x", *iptr++);
+ snprintf(optr, 4, "%%%02x", *iptr++);
optr+=3;
}
}
- *optr=0; /* in case no sprintf() was used */
+ *optr=0; /* in case no sprintf was used */
return buf;
}
@@ -99,7 +99,7 @@ void logmsg(const char *msg, ...)
static time_t epoch_offset;
static int known_offset;
- if (!serverlogfile) {
+ if(!serverlogfile) {
fprintf(stderr, "Error: serverlogfile not set\n");
return;
}
@@ -140,11 +140,11 @@ void win32_perror (const char *msg)
char buf[512];
DWORD err = SOCKERRNO;
- if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
- LANG_NEUTRAL, buf, sizeof(buf), NULL))
+ if(!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
+ LANG_NEUTRAL, buf, sizeof(buf), NULL))
snprintf(buf, sizeof(buf), "Unknown error %lu (%#lx)", err, err);
- if (msg)
- fprintf(stderr, "%s: ", msg);
+ if(msg)
+ fprintf(stderr, "%s: ", msg);
fprintf(stderr, "%s\n", buf);
}
#endif /* WIN32 */
@@ -159,15 +159,14 @@ void win32_init(void)
err = WSAStartup(wVersionRequested, &wsaData);
- if (err != 0) {
+ if(err != 0) {
perror("Winsock init failed");
logmsg("Error initialising winsock -- aborting");
exit(1);
}
- if ( LOBYTE( wsaData.wVersion ) != USE_WINSOCK ||
- HIBYTE( wsaData.wVersion ) != USE_WINSOCK ) {
-
+ if(LOBYTE(wsaData.wVersion) != USE_WINSOCK ||
+ HIBYTE(wsaData.wVersion) != USE_WINSOCK) {
WSACleanup();
perror("Winsock init failed");
logmsg("No suitable winsock.dll found -- aborting");