Commit ac290b76 authored by rswindell's avatar rswindell
Browse files

Enabled GCC-assisted printf-style format/arg checking for lprintf() and

fix the resulting warnings.
parent 636767c6
......@@ -122,6 +122,9 @@ typedef struct {
static service_t *service=NULL;
static uint32_t services=0;
#if defined(__GNUC__) // Catch printf-format errors with lprintf
static int lprintf(int level, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
#endif
static int lprintf(int level, const char *fmt, ...)
{
va_list argptr;
......@@ -1100,7 +1103,7 @@ static void js_service_thread(void* arg)
if(startup->login_attempt.throttle
&& (login_attempts=loginAttempts(startup->login_attempt_list, &service_client.addr)) > 1) {
lprintf(LOG_DEBUG,"%04d %s Throttling suspicious connection from: %s (%u login attempts)"
lprintf(LOG_DEBUG,"%04d %s Throttling suspicious connection from: %s (%lu login attempts)"
,socket, service->protocol, client.addr, login_attempts);
mswait(login_attempts*startup->login_attempt.throttle);
}
......@@ -1168,7 +1171,7 @@ static void js_service_thread(void* arg)
#endif
thread_down();
lprintf(LOG_INFO,"%04d %s service thread terminated (%u clients remain, %d total, %lu served)"
lprintf(LOG_INFO,"%04d %s service thread terminated (%u clients remain, %lu total, %lu served)"
,socket, service->protocol, service->clients, active_clients(), service->served);
client_off(socket);
......@@ -1332,7 +1335,7 @@ static void native_static_service_thread(void* arg)
thread_down();
lprintf(LOG_INFO,"%04d %s service thread terminated (%lu clients served)"
,socket, service->protocol, service->served);
,inst.socket, service->protocol, service->served);
close_socket(inst.socket);
closesocket(socket_dup); /* close duplicate handle */
......@@ -1443,7 +1446,7 @@ static void native_service_thread(void* arg)
if(startup->login_attempt.throttle
&& (login_attempts=loginAttempts(startup->login_attempt_list, &service_client.addr)) > 1) {
lprintf(LOG_DEBUG,"%04d %s Throttling suspicious connection from: %s (%u login attempts)"
lprintf(LOG_DEBUG,"%04d %s Throttling suspicious connection from: %s (%lu login attempts)"
,socket, service->protocol, client.addr, login_attempts);
mswait(login_attempts*startup->login_attempt.throttle);
}
......@@ -1468,7 +1471,7 @@ static void native_service_thread(void* arg)
#endif
thread_down();
lprintf(LOG_INFO,"%04d %s service thread terminated (%u clients remain, %d total, %lu served)"
lprintf(LOG_INFO,"%04d %s service thread terminated (%u clients remain, %lu total, %lu served)"
,socket, service->protocol, service->clients, active_clients(), service->served);
client_off(socket);
......@@ -1781,7 +1784,7 @@ void DLLCALL services_thread(void* arg)
}
t=time(NULL);
lprintf(LOG_INFO,"Initializing on %.24s with options: %lx"
lprintf(LOG_INFO,"Initializing on %.24s with options: %x"
,ctime_r(&t,str),startup->options);
if(chdir(startup->ctrl_dir)!=0)
......@@ -1924,7 +1927,7 @@ void DLLCALL services_thread(void* arg)
}
}
lprintf(LOG_INFO,"0000 Services thread started (%u service sockets bound)", total_sockets);
lprintf(LOG_INFO,"0000 Services thread started (%lu service sockets bound)", total_sockets);
/* Main Server Loop */
while(!terminated) {
......@@ -2121,7 +2124,7 @@ void DLLCALL services_thread(void* arg)
if(banned || trashcan(&scfg,host_ip,"ip")) {
if(banned) {
char ban_duration[128];
lprintf(LOG_NOTICE, "%04d !TEMPORARY BAN of %s (%u login attempts, last: %s) - remaining: %s"
lprintf(LOG_NOTICE, "%04d !TEMPORARY BAN of %s (%lu login attempts, last: %s) - remaining: %s"
,client_socket, host_ip, attempted.count-attempted.dupes, attempted.user, seconds_to_str(banned, ban_duration));
} else
lprintf(LOG_NOTICE,"%04d !%s CLIENT BLOCKED in ip.can: %s"
......@@ -2139,7 +2142,7 @@ void DLLCALL services_thread(void* arg)
if((client=malloc(sizeof(service_client_t)))==NULL) {
FREE_AND_NULL(udp_buf);
lprintf(LOG_CRIT,"%04d !%s ERROR allocating %u bytes of memory for service_client"
lprintf(LOG_CRIT,"%04d !%s ERROR allocating %lu bytes of memory for service_client"
,client_socket, service[i].protocol, sizeof(service_client_t));
close_socket(client_socket);
continue;
......@@ -2185,7 +2188,7 @@ void DLLCALL services_thread(void* arg)
/* Wait for Dynamic Service Threads to terminate */
if(active_clients()) {
lprintf(LOG_INFO,"0000 Waiting for %d clients to disconnect",active_clients());
lprintf(LOG_INFO,"0000 Waiting for %lu clients to disconnect",active_clients());
while(active_clients()) {
mswait(500);
}
......@@ -2197,7 +2200,7 @@ void DLLCALL services_thread(void* arg)
for(i=0;i<(int)services;i++)
total_running+=service[i].running;
if(total_running) {
lprintf(LOG_INFO,"0000 Waiting for %d static services to terminate",total_running);
lprintf(LOG_INFO,"0000 Waiting for %lu static services to terminate",total_running);
while(1) {
total_running=0;
for(i=0;i<(int)services;i++)
......
......@@ -518,6 +518,9 @@ time_gm(struct tm *tm)
return (t < 0 ? (time_t) -1 : t);
}
#if defined(__GNUC__) // Catch printf-format errors with lprintf
static int lprintf(int level, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
#endif
static int lprintf(int level, const char *fmt, ...)
{
va_list argptr;
......@@ -1990,7 +1993,7 @@ static named_string_t** read_ini_list(char* path, char* section, char* desc
iniCloseFile(fp);
COUNT_LIST_ITEMS(list,i);
if(i)
lprintf(LOG_DEBUG,"Read %u %s from %s section of %s"
lprintf(LOG_DEBUG,"Read %lu %s from %s section of %s"
,i,desc,section==NULL ? "root":section,path);
} else
lprintf(LOG_WARNING, "Error %d opening %s", errno, path);
......@@ -4560,12 +4563,12 @@ static BOOL exec_fastcgi(http_session_t *session)
closesocket(sock);
if(!(ret & CGI_STUFF_VALID_HEADERS)) {
lprintf(LOG_ERR,"%04d FastCGI Process did not generate valid headers");
lprintf(LOG_ERR,"%04d FastCGI Process did not generate valid headers", session->socket);
return(FALSE);
}
if(!(ret & CGI_STUFF_DONE_PARSING)) {
lprintf(LOG_ERR,"%04d FastCGI Process did not send data header termination");
lprintf(LOG_ERR,"%04d FastCGI Process did not send data header termination", session->socket);
return(FALSE);
}
......@@ -5963,7 +5966,7 @@ int read_post_data(http_session_t * session)
/* FREE()d in close_request */
p=realloc(session->req.post_data, s);
if(p==NULL) {
lprintf(LOG_CRIT,"%04d !ERROR Allocating %d bytes of memory",session->socket,session->req.post_len);
lprintf(LOG_CRIT,"%04d !ERROR Allocating %lu bytes of memory",session->socket,session->req.post_len);
send_error(session,__LINE__,"413 Request entity too large");
if(fp) fclose(fp);
return(FALSE);
......@@ -6020,14 +6023,14 @@ int read_post_data(http_session_t * session)
if(s < (MAX_POST_LEN+1) && (session->req.post_data=malloc((size_t)(s+1))) != NULL)
session->req.post_len=recvbufsocket(session,session->req.post_data,s);
else {
lprintf(LOG_CRIT,"%04d !ERROR Allocating %d bytes of memory",session->socket,s);
lprintf(LOG_CRIT,"%04d !ERROR Allocating %lu bytes of memory",session->socket,s);
send_error(session,__LINE__,"413 Request entity too large");
return(FALSE);
}
}
}
if(session->req.post_len != s)
lprintf(LOG_DEBUG,"%04d !ERROR Browser said they sent %d bytes, but I got %d",session->socket,s,session->req.post_len);
lprintf(LOG_DEBUG,"%04d !ERROR Browser said they sent %lu bytes, but I got %lu",session->socket,s,session->req.post_len);
if(session->req.post_len > s)
session->req.post_len = s;
session->req.post_data[session->req.post_len]=0;
......@@ -6294,7 +6297,7 @@ void http_session_thread(void* arg)
if(banned || trashcan(&scfg,session.host_ip,"ip")) {
if(banned) {
char ban_duration[128];
lprintf(LOG_NOTICE, "%04d !TEMPORARY BAN of %s (%u login attempts, last: %s) - remaining: %s"
lprintf(LOG_NOTICE, "%04d !TEMPORARY BAN of %s (%lu login attempts, last: %s) - remaining: %s"
,session.socket, session.host_ip, attempted.count-attempted.dupes, attempted.user, seconds_to_str(banned, ban_duration));
} else
lprintf(LOG_NOTICE, "%04d !CLIENT BLOCKED in ip.can: %s", session.socket, session.host_ip);
......@@ -6321,7 +6324,7 @@ void http_session_thread(void* arg)
if(startup->login_attempt.throttle
&& (login_attempts=loginAttempts(startup->login_attempt_list, &session.addr)) > 1) {
lprintf(LOG_DEBUG,"%04d %s Throttling suspicious connection from: %s (%u login attempts)"
lprintf(LOG_DEBUG,"%04d %s Throttling suspicious connection from: %s (%lu login attempts)"
,socket, session.client.protocol, session.host_ip, login_attempts);
mswait(login_attempts*startup->login_attempt.throttle);
}
......@@ -6496,7 +6499,7 @@ static void cleanup(int code)
update_clients(); /* active_clients is destroyed below */
if(protected_uint32_value(active_clients))
lprintf(LOG_WARNING,"!!!! Terminating with %ld active clients", protected_uint32_value(active_clients));
lprintf(LOG_WARNING,"!!!! Terminating with %u active clients", protected_uint32_value(active_clients));
else
protected_uint32_destroy(active_clients);
......@@ -6762,7 +6765,7 @@ void DLLCALL web_server(void* arg)
}
t=time(NULL);
lprintf(LOG_INFO,"Initializing on %.24s with options: %lx"
lprintf(LOG_INFO,"Initializing on %.24s with options: %x"
,ctime_r(&t,logstr),startup->options);
if(chdir(startup->ctrl_dir)!=0)
......@@ -6921,7 +6924,7 @@ void DLLCALL web_server(void* arg)
if(session==NULL) {
/* FREE()d at the start of the session thread */
if((session=malloc(sizeof(http_session_t)))==NULL) {
lprintf(LOG_CRIT,"!ERROR allocating %u bytes of memory for http_session_t", sizeof(http_session_t));
lprintf(LOG_CRIT,"!ERROR allocating %lu bytes of memory for http_session_t", sizeof(http_session_t));
continue;
}
memset(session, 0, sizeof(http_session_t));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment