Skip to content

Commit 2191a7d

Browse files
committed
Misc minor cleanups.
Fix various [-Wunused-parameter], [-Wsign-compare], [-Wshift-negative-value], etc. warnings that exist with recent compilers.
1 parent 7f1f22e commit 2191a7d

File tree

6 files changed

+43
-22
lines changed

6 files changed

+43
-22
lines changed

include/ssl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ extern const SSL_METHOD *meth;
3434
# endif
3535
extern SSL_CTX *ctx;
3636
extern SslParms sslprm;
37-
#endif
3837

3938
extern int use_ssl;
4039

@@ -45,3 +44,4 @@ void ssl_log_startup(int server);
4544
int ssl_load_certificates(void);
4645
int ssl_set_ciphers(void);
4746
int ssl_verify_callback_common(int preverify_ok, X509_STORE_CTX * ctx, int is_invalid);
47+
#endif

src/acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ int add_ipv4_to_acl(char *ipv4) {
241241

242242
/* Convert ip and mask to unsigned long */
243243
ip = htonl((data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]);
244-
mask = htonl(-1 << (32 - data[4]));
244+
mask = htonl(~0u << (32 - data[4]));
245245

246246
/* Wrong network address */
247247
if ( (ip & mask) != ip) {

src/check_nrpe.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,9 @@ int process_arguments(int argc, char **argv, int from_config_file)
331331
break;
332332

333333
case 'n':
334+
#ifdef HAVE_SSL
334335
use_ssl = FALSE;
336+
#endif
335337
break;
336338

337339
case 'u':
@@ -554,7 +556,7 @@ int read_config_file(char *fname)
554556
logit(LOG_ERR, "Error: read_config_file fail to allocate memory");
555557
return ERROR;
556558
}
557-
if ((sz = fread(buf, 1, st.st_size, f)) != st.st_size) {
559+
if ((sz = fread(buf, 1, st.st_size, f)) != (size_t)st.st_size) {
558560
fclose(f);
559561
free(buf);
560562
logit(LOG_ERR, "Error: Failed to completely read config file %s", fname);
@@ -993,7 +995,8 @@ int send_request(void)
993995
v2_packet *v2_send_packet = NULL;
994996
v3_packet *v3_send_packet = NULL;
995997
u_int32_t calculated_crc32;
996-
int rc, bytes_to_send, pkt_size;
998+
int rc, bytes_to_send;
999+
size_t pkt_size;
9971000
char *send_pkt;
9981001

9991002
if (packet_ver == NRPE_PACKET_VERSION_2) {
@@ -1229,10 +1232,13 @@ int read_packet(int sock, void *ssl_ptr, v2_packet ** v2_pkt, v3_packet ** v3_pk
12291232
int rc;
12301233
char *buff_ptr;
12311234

1235+
(void)ssl_ptr;
12321236
/* Read only the part that's common between versions 2 & 3 */
12331237
common_size = tot_bytes = bytes_to_recv = (char *)packet.buffer - (char *)&packet;
12341238

1239+
#ifdef HAVE_SSL
12351240
if (use_ssl == FALSE) {
1241+
#endif
12361242
rc = recvall(sock, (char *)&packet, &tot_bytes, socket_timeout);
12371243

12381244
if (rc <= 0 || rc != bytes_to_recv) {
@@ -1318,8 +1324,8 @@ int read_packet(int sock, void *ssl_ptr, v2_packet ** v2_pkt, v3_packet ** v3_pk
13181324
return -1;
13191325
} else
13201326
tot_bytes += rc;
1321-
}
13221327
#ifdef HAVE_SSL
1328+
}
13231329
else {
13241330
SSL *ssl = (SSL *) ssl_ptr;
13251331

@@ -1450,6 +1456,8 @@ void alarm_handler(int sig)
14501456
const char *text = state_text(timeout_return_code);
14511457
size_t lth1 = 0, lth2 = 0;
14521458

1459+
(void)sig;
1460+
14531461
for (lth1 = 0; lth1 < 10; ++lth1)
14541462
if (text[lth1] == 0)
14551463
break;

src/nrpe.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ void init_ssl(void)
230230
#ifdef HAVE_SSL
231231
char seedfile[FILENAME_MAX];
232232
char errstr[256] = { "" };
233-
int i, c, x, vrfy;
234-
unsigned long ssl_opts = SSL_OP_ALL | SSL_OP_SINGLE_DH_USE;
233+
int i, x, vrfy;
234+
unsigned long c, ssl_opts = SSL_OP_ALL | SSL_OP_SINGLE_DH_USE;
235235

236236
if (use_ssl == FALSE) {
237237
if (debug == TRUE)
@@ -954,7 +954,7 @@ int read_config_dir(char *dirname)
954954

955955
/* create the full path to the config file or subdirectory */
956956
rc = snprintf(config_file, sizeof(config_file) - 1, "%s/%s", dirname, dirfile->d_name);
957-
if (rc >= sizeof(config_file) - 1) {
957+
if (rc >= (long)sizeof(config_file) - 1) {
958958
logit(LOG_ERR, "Config file path too long '%s/%s'.\n", dirname, dirfile->d_name);
959959
return ERROR;
960960
}
@@ -1769,12 +1769,12 @@ void handle_connection(int sock)
17691769

17701770
/* send the response back to the client */
17711771
bytes_to_send = pkt_size;
1772-
if (use_ssl == FALSE)
1773-
sendall(sock, send_pkt, &bytes_to_send);
17741772
#ifdef HAVE_SSL
1775-
else
1773+
if (use_ssl)
17761774
SSL_write(ssl, send_pkt, bytes_to_send);
1775+
else
17771776
#endif
1777+
sendall(sock, send_pkt, &bytes_to_send);
17781778

17791779
#ifdef HAVE_SSL
17801780
if (ssl) {
@@ -1818,9 +1818,9 @@ void init_handle_conn(void)
18181818
alarm(connection_timeout);
18191819
}
18201820

1821+
#ifdef HAVE_SSL
18211822
int handle_conn_ssl(int sock, void *ssl_ptr)
18221823
{
1823-
#ifdef HAVE_SSL
18241824
# if (defined(__sun) && defined(SOLARIS_10)) || defined(_AIX) || defined(__hpux)
18251825
SSL_CIPHER *c;
18261826
#else
@@ -1923,21 +1923,24 @@ int handle_conn_ssl(int sock, void *ssl_ptr)
19231923
logit(LOG_NOTICE, "SSL Client %s did not present a certificate",
19241924
remote_host);
19251925
}
1926-
#endif
19271926

19281927
return OK;
19291928
}
1929+
#endif
19301930

19311931
int read_packet(int sock, void *ssl_ptr, v2_packet * v2_pkt, v3_packet ** v3_pkt)
19321932
{
19331933
int32_t common_size, tot_bytes, bytes_to_recv, buffer_size;
19341934
int rc;
19351935
char *buff_ptr;
19361936

1937+
(void)ssl_ptr;
19371938
/* Read only the part that's common between versions 2 & 3 */
19381939
common_size = tot_bytes = bytes_to_recv = (char *)&v2_pkt->buffer - (char *)v2_pkt;
19391940

1941+
#ifdef HAVE_SSL
19401942
if (use_ssl == FALSE) {
1943+
#endif
19411944
rc = recvall(sock, (char *)v2_pkt, &tot_bytes, socket_timeout);
19421945

19431946
if (rc <= 0 || rc != bytes_to_recv)
@@ -1997,8 +2000,8 @@ int read_packet(int sock, void *ssl_ptr, v2_packet * v2_pkt, v3_packet ** v3_pkt
19972000
return -1;
19982001
} else
19992002
tot_bytes += rc;
2000-
}
20012003
#ifdef HAVE_SSL
2004+
}
20022005
else {
20032006
SSL *ssl = (SSL *) ssl_ptr;
20042007
int sockfd, retval;
@@ -2338,7 +2341,7 @@ int my_system_child(const char *command, int timeout, int fd)
23382341

23392342
FD_ZERO(&rfds);
23402343
FD_ZERO(&wfds);
2341-
if (do_read && bytes_read < sizeof(buffer)) {
2344+
if (do_read && bytes_read < (long)sizeof(buffer)) {
23422345
FD_SET(fileno(fp), &rfds);
23432346
max_fd = fileno(fp);
23442347
}
@@ -2405,12 +2408,14 @@ int my_system_child(const char *command, int timeout, int fd)
24052408
/* handle timeouts when executing commands via my_system() */
24062409
void my_system_sighandler(int sig)
24072410
{
2411+
(void)sig;
24082412
exit(STATE_CRITICAL); /* force the child process to exit... */
24092413
}
24102414

24112415
/* handle errors where connection takes too long */
24122416
void my_connection_sighandler(int sig)
24132417
{
2418+
(void)sig;
24142419
logit(LOG_ERR, "Connection has taken too long to establish. Exiting...");
24152420
exit(STATE_CRITICAL);
24162421
}
@@ -2566,6 +2571,7 @@ int remove_pid_file(void)
25662571

25672572
void my_disconnect_sighandler(int sig)
25682573
{
2574+
(void)sig;
25692575
logit(LOG_ERR, "SSL_shutdown() has taken too long to complete. Exiting now..");
25702576
exit(STATE_CRITICAL);
25712577
}
@@ -2651,6 +2657,7 @@ void sighandler(int sig)
26512657
/* handle signals (child processes) */
26522658
void child_sighandler(int sig)
26532659
{
2660+
(void)sig;
26542661
exit(0); /* terminate */
26552662
}
26562663

@@ -2789,7 +2796,7 @@ int contains_nasty_metachars(char *str)
27892796
return FALSE;
27902797

27912798
result = strcspn(str, nasty_metachars);
2792-
if (result != strlen(str))
2799+
if (result != (long)strlen(str))
27932800
return TRUE;
27942801

27952802
return FALSE;
@@ -2813,15 +2820,15 @@ int process_macros(char *input_buffer, char *output_buffer, int buffer_length)
28132820
selected_macro = NULL;
28142821

28152822
if (in_macro == FALSE) {
2816-
if (strlen(output_buffer) + strlen(temp_buffer) < buffer_length - 1) {
2823+
if (strlen(output_buffer) + strlen(temp_buffer) < (size_t)buffer_length - 1) {
28172824
strncat(output_buffer, temp_buffer, buffer_length - strlen(output_buffer) - 1);
28182825
output_buffer[buffer_length - 1] = '\x0';
28192826
}
28202827
in_macro = TRUE;
28212828

28222829
} else {
28232830

2824-
if (strlen(output_buffer) + strlen(temp_buffer) < buffer_length - 1) {
2831+
if (strlen(output_buffer) + strlen(temp_buffer) < (size_t)buffer_length - 1) {
28252832

28262833
/* argument macro */
28272834
if (strstr(temp_buffer, "ARG") == temp_buffer) {
@@ -2940,7 +2947,9 @@ int process_arguments(int argc, char **argv)
29402947
break;
29412948

29422949
case 'n':
2950+
#ifdef HAVE_SSL
29432951
use_ssl = FALSE;
2952+
#endif
29442953
break;
29452954

29462955
case 's': /* Argument s to indicate SRC option */

src/ssl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void ssl_initialize(void)
3434
void ssl_set_protocol_version(SslVer ssl_proto_ver, unsigned long *ssl_opts)
3535
{
3636
#if OPENSSL_VERSION_NUMBER >= 0x10100000
37-
37+
(void)ssl_opts;
3838
SSL_CTX_set_max_proto_version(ctx, 0);
3939

4040
switch(ssl_proto_ver) {
@@ -223,7 +223,7 @@ int ssl_load_certificates(void)
223223

224224
int ssl_set_ciphers(void)
225225
{
226-
int x;
226+
size_t x;
227227
int changed = FALSE;
228228
char errstr[256] = { "" };
229229

src/utils.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@
2828
*
2929
****************************************************************************/
3030

31-
#include "../include/common.h"
32-
#include "../include/utils.h"
31+
#ifdef HAVE_CONFIG_H
32+
# include "config.h"
33+
#endif
34+
35+
#include "common.h"
36+
#include "utils.h"
3337
#include <stdarg.h>
3438
#ifdef HAVE_PATHS_H
3539
#include <paths.h>

0 commit comments

Comments
 (0)