GNU C compiler warning clean-up
cover GNU C compiler warning clean-up
The GNU C compiler gives a lot of different warnings when compiling with -Wall set. This patch-set tries to clean up all these issues, hopefully without breaking anything for other compilers - especially on the Windows platform.
David Sommerseth (6):
Use stricter snprintf() formatting in socks_username_password_auth() Fix compiler warnings about not used dummy() functions Fixed potential misinterpretation of boolean logic
Only add some functions when really needed
Removed functions not being used anywhere
Merged add_bypass_address() and add_host_route_if_nonlocal()
cryptoapi.c | 2 ++ ieproxy.c | 3 ++- options.c | 2 ++ perf.c | 2 ++ pkcs11.c | 2 ++ ps.c | 12 ------------ reliable.c | 2 ++ route.c | 34 ++++++++++++---------------------- sig.c | 9 --------- socks.c | 4 ++-- ssl.c | 2 +- 11 files changed, 27 insertions(+), 47 deletions(-)
Signature · 1 line
1.7.2.3
cover *** SUBJECT HERE ***
*** BLURB HERE ***
David Sommerseth (6):
Use stricter snprintf() formatting in socks_username_password_auth() Fix compiler warnings about not used dummy() functions Fixed potential misinterpretation of boolean logic
Only add some functions when really needed
Removed functions not being used anywhere
Merged add_bypass_address() and add_host_route_if_nonlocal()
cryptoapi.c | 2 ++ ieproxy.c | 3 ++- options.c | 2 ++ perf.c | 2 ++ pkcs11.c | 2 ++ ps.c | 12 ------------ reliable.c | 2 ++ route.c | 34 ++++++++++++---------------------- sig.c | 9 --------- socks.c | 4 ++-- ssl.c | 2 +- 11 files changed, 27 insertions(+), 47 deletions(-)
Signature · 1 line
1.7.2.3
PATCH 1/6 Use stricter snprintf() formatting in socks_username_password_auth()
In reply to David Sommersethcommit fc1fa9ffc7e3356458ec3 added a new function which needs to have a stricter string formatting. This was detected due to a compiler warning.
This patch makes sure that the %c parts in the string only gets 8 bits of data, which seems to be the intension. strlen() is used to determine the values passed to the %c places in, but it was not taken into consideration that size_t which strlen() returns might not be the same as int or char.
--- socks.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
socks.c +2 -2
@@ -114,8 +114,8 @@ socks_username_password_auth (struct socks_proxy_info *p, creds.defined =0 ;get_user_pass (&creds, p->authfile,UP_TYPE_SOCKS ,GET_USER_PASS_MANAGEMENT ); -snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" ,strlen (creds.username), - creds.username,strlen (creds.password), creds.password); +snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" , (int )strlen (creds.username) &0xff , + creds.username, (int )strlen (creds.password) &0xff , creds.password); size =send (sd, to_send,strlen (to_send),MSG_NOSIGNAL );if (size !=strlen (to_send))
Signature · 1 line
1.7.2.3
Re: [Openvpn-devel] [PATCH 1/6] Use stricter snprintf() formatting in socks_username_password_auth()
Hi,
socks.c socks_username_password_auth (struct socks_proxy_info *p, · line 118
Quoted 4 lines · David Sommerseth
socks.c +2
-2-snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" ,strlen (creds.username), - creds.username,strlen (creds.password), creds.password); +snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" , (int )strlen (creds.username) &0xff , + creds.username, (int )strlen (creds.password) &0xff , creds.password);
I tend to NAK this.
I'm fine with the "(int)" thingie, but not with the "0xff" part - if the creds.username/creds.password string is indeed longer than 255 bytes, the whole message will be unparsable by the receiver, and silent truncation of the length field is not helping to make the code more readable, nor does it improve code quality.
So if you want to make sure that the length is <= 255, add a check + error above the snprintf() block.
gert
Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
//www.muc.de/~gert/
Gert Doering - Munich, Germany [email protected]...
fax: +49-89-35655025 [email protected]...Re: [Openvpn-devel] [PATCH 1/6] Use stricter snprintf() formatting in socks_username_password_auth()
Quoted 6 lines · Gert Doering
socks.c socks_username_password_auth (struct socks_proxy_info *p, · line 118
Quoted 4 lines
socks.c +2
-2-snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" ,strlen (creds.username), - creds.username,strlen (creds.password), creds.password); +snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" , (int )strlen (creds.username) &0xff , + creds.username, (int )strlen (creds.password) &0xff , creds.password);I tend to NAK this.
I agree. My ack is only for the other patches. (Sorry, I should have written that in the other mail.) A better solution for this should be simple as Gert outlined.
//Peter
Re: [Openvpn-devel] [PATCH 1/6] Use stricter snprintf() formatting in socks_username_password_auth()
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 11 lines · Peter Stuge
Quoted 6 lines · Gert Doering
socks.c socks_username_password_auth (struct socks_proxy_info *p, · line 118
Quoted 4 lines
socks.c +2
-2-snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" ,strlen (creds.username), - creds.username,strlen (creds.password), creds.password); +snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" , (int )strlen (creds.username) &0xff , + creds.username, (int )strlen (creds.password) &0xff , creds.password);I tend to NAK this.
I agree. My ack is only for the other patches. (Sorry, I should have written that in the other mail.) A better solution for this should be simple as Gert outlined.
I didn't think about this when I wrote this patch, but I completely agree! I'll improve that part. It's also silly to truncate the %c part and not limit the %s as %.255s in this case.
Thanks for catching that, I'll send a new patch fixing this one!
kind regards,
David Sommerseth
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/
iEYEARECAAYFAkzhlJwACgkQDC186MBRfrpaPQCePSJrLAyNOysVGjG33NEGl46L qG4An3npEuIjRry2EO+dfRnCO1BfiEuN
=dv5a
-----END PGP SIGNATURE-----
PATCH 1/1 Use stricter snprintf() formatting in socks_username_password_auth() (v2)
commit fc1fa9ffc7e3356458ec3 added a new function which needs to have a stricter string formatting. This was detected due to a compiler warning.
This patch makes sure that the length of username and password is not longer than 255 bytes. It also adds extra checks to avoid NULL pointer issues with strlen() on these two parameters.
--- socks.c | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-)
socks.c +10 -3
@@ -112,10 +112,17 @@ socks_username_password_auth (struct socks_proxy_info *p,ssize_t size; creds.defined =0 ; -get_user_pass (&creds, p->authfile,UP_TYPE_SOCKS ,GET_USER_PASS_MANAGEMENT ); -snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" ,strlen (creds.username), - creds.username,strlen (creds.password), creds.password); + +if ( !creds.username || (strlen (creds.username) >255 ) + || !creds.password || (strlen (creds.password) >255 ) ) { +msg (M_NONFATAL , +"socks username and/or password exceeds 255 characters. " +"Authentiaction not possible." ); +return false; + } +snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" , (int )strlen (creds.username), + creds.username, (int )strlen (creds.password), creds.password); size =send (sd, to_send,strlen (to_send),MSG_NOSIGNAL );if (size !=strlen (to_send))
Signature · 1 line
1.7.2.3
Re: [Openvpn-devel] [PATCH] Use stricter snprintf() formatting in socks_username_password_auth() (v2)
Hi,
socks.c socks_username_password_auth (struct socks_proxy_info *p, · line 121
Quoted 4 lines · David Sommerseth
socks.c +4
-0+ || !creds.password || (strlen(creds.password) > 255) ) { +msg (M_NONFATAL , +"socks username and/or password exceeds 255 characters. " +"Authentiaction not possible." );
I'd ack this but for the spelling typo :-)
(Sorry, but, well, these things tend to stick...)
gert
Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
//www.muc.de/~gert/
Gert Doering - Munich, Germany [email protected]...
fax: +49-89-35655025 [email protected]...PATCH 2/6 Fix compiler warnings about not used dummy() functions
In reply to David SommersethIt has been reported that the Microsoft Visual C compiler complains if a .c file do not contain any compilable code, which can happen if the code has been #ifdef'ed out. To avoid this, these #ifdef sections have a #else section which adds a static dummy() function which does nothing.
On the other hand, the GNU C compiler complains about unused functions when it discovers this situation.
This patch tries to only add these dummy() functions if the Microsoft Visual C compiler is detected, via the _MSC_VER macro.
--- cryptoapi.c | 2 ++ ieproxy.c | 3 ++- perf.c | 2 ++ pkcs11.c | 2 ++ 4 files changed, 8 insertions(+), 1 deletions(-)
cryptoapi.c +2 -0
@@ -470,5 +470,7 @@ int SSL_CTX_use_CryptoAPI_certificate(SSL_CTX *ssl_ctx, const char *cert_prop) }#else +#ifdef _MSC_VER/* Dummy function needed to avoid empty file compiler warning in Microsoft VC */ static void dummy (void ) {} +#endif #endif /* WIN32 */
ieproxy.c +2 -1
@@ -139,7 +139,8 @@ LPCTSTR getIeHttpProxy() return(NULL); } } -#else +#ifdef _MSC_VER/* Dummy function needed to avoid empty file compiler warning in Microsoft VC */ static void dummy (void ) {} +#endif #endif /* WIN32 */
perf.c +2 -0
@@ -287,5 +287,7 @@ perf_print_state (int lev) }#else +#ifdef _MSC_VER/* Dummy function needed to avoid empty file compiler warning in Microsoft VC */ static void dummy (void ) {}#endif +#endif
pkcs11.c +2 -0
@@ -982,5 +982,7 @@ cleanup: }#else +#ifdef _MSC_VER/* Dummy function needed to avoid empty file compiler warning in Microsoft VC */ static void dummy (void ) {} +#endif #endif /* ENABLE_PKCS11 */
Signature · 1 line
1.7.2.3
PATCH 3/6 Fixed potential misinterpretation of boolean logic
In reply to David SommersethThe GNU C compiler warned about a potential issue with an if() expression missing an extra set of parentheses.
--- ssl.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
ssl.c +1 -1
@@ -940,7 +940,7 @@ verify_callback (int preverify_ok, X509_STORE_CTX * ctx)if (opt->verify_export_cert) { gc =gc_new (); -if (tmp_file=get_peer_cert (ctx, opt->verify_export_cert,&gc)) +if ((tmp_file=get_peer_cert (ctx, opt->verify_export_cert,&gc))) {setenv_str (opt->es,"peer_cert" , tmp_file); }
Signature · 1 line
1.7.2.3
PATCH 4/6 Only add some functions when really needed
In reply to David SommersethThe GNU C compiler gave warnings about some functions not being used. These functions where only used if certian #ifdef sections was enabled.
This patch encapsulates these function declarations with matching #ifdef's to make it more clear when these functions are needed.
--- options.c | 2 ++ reliable.c | 2 ++ 2 files changed, 4 insertions(+), 0 deletions(-)
options.c +2 -0
@@ -2785,6 +2785,7 @@ positive_atoi (const char *str)return i <0 ?0 : i; } +#ifdef WIN32 /* This function is only used when compiling on Windows */ static unsigned int atou (const char *str) {
@@ -2792,6 +2793,7 @@ atou (const char *str)sscanf (str,"%u" , &val); return val; } +#endif static inline bool space (unsigned char c)
reliable.c +2 -0
@@ -516,6 +516,7 @@ reliable_can_send (const struct reliable *rel)return n_current >0 && !rel->hold; } +#ifdef EXPONENTIAL_BACKOFF /* return a unique point-in-time to trigger retry */ static time_t reliable_unique_retry (struct reliable *rel,time_t retry)
@@ -535,6 +536,7 @@ reliable_unique_retry (struct reliable *rel, time_t retry) }return retry; } +#endif /* return next buffer to send to remote */ struct buffer *
Signature · 1 line
1.7.2.3
PATCH 5/6 Removed functions not being used anywhere
In reply to David SommersethThe GNU C compiler gave warnings about these functions in the patch not being used anywhere. Doing a git grep on the code turned out there were no callers to these functions. Taking these functions out, as there is not good reason why to carry dead code.
--- ps.c | 12 ------------ sig.c | 9 --------- 2 files changed, 0 insertions(+), 21 deletions(-)
ps.c +0 -12
@@ -234,18 +234,6 @@ port_share_sendmsg (const socket_descriptor_t sd, } } -static int -pc_list_len (struct proxy_connection *pc) -{ -int count =0 ; -while (pc) - { - ++count; - pc = pc->next; - } -return count; -} -static void proxy_entry_close_sd (struct proxy_connection *pc,struct event_set *es) {
sig.c +0 -9
@@ -185,15 +185,6 @@ signal_handler (const int signum) signal (signum, signal_handler); } -/* temporary signal handler, before we are fully initialized */ -static void -signal_handler_exit (const int signum) -{ -msg (M_FATAL , -"Signal %d (%s) received during initialization, exiting" , - signum,signal_description (signum,NULL )); -} -#endif /* set handlers for unix signals */
Signature · 1 line
1.7.2.3
PATCH 6/6 Merged add_bypass_address() and add_host_route_if_nonlocal()
In reply to David SommersethThe add_host_route_if_nonlocal() function is too simple to really benefit from calling add_bypass_address() when this function is the only caller to this function.
--- route.c | 34 ++++++++++++---------------------- 1 files changed, 12 insertions(+), 22 deletions(-)
route.c +12 -22
@@ -59,26 +59,6 @@ print_bypass_addresses (const struct route_bypass *rb)#endif -static bool -add_bypass_address (struct route_bypass *rb,const in_addr_t a) -{ -int i; -for (i =0 ; i < rb->n_bypass; ++i) - { -if (a == rb->bypass[i])/* avoid duplicates */ -return true; - } -if (rb->n_bypass <N_ROUTE_BYPASS ) - { - rb->bypass[rb->n_bypass++] = a; -return true; - } -else - { -return false; - } -} -struct route_option_list *new_route_option_list (const int max_routes,struct gc_arena *a) {
@@ -2124,8 +2104,18 @@ netmask_to_netbits (const in_addr_t network, const in_addr_t netmask, int *netbistatic void add_host_route_if_nonlocal (struct route_bypass *rb,const in_addr_t addr) { -if (test_local_addr (addr) ==TLA_NONLOCAL && addr !=0 && addr != ~0 ) -add_bypass_address (rb, addr); +if (test_local_addr (addr) ==TLA_NONLOCAL && addr !=0 && addr != ~0 ) { +int i; +for (i =0 ; i < rb->n_bypass; ++i) + { +if (addr == rb->bypass[i])/* avoid duplicates */ +return ; + } +if (rb->n_bypass <N_ROUTE_BYPASS ) + { + rb->bypass[rb->n_bypass++] = addr; + } + } } static void
Signature · 1 line
1.7.2.3
Quoted 7 lines · David Sommerseth
David Sommerseth (6):
Use strictersnprintf()formatting insocks_username_password_auth()Fix compiler warnings about not useddummy()functions Fixed potential misinterpretation of boolean logic
Only add some functions when really needed
Removed functions not being used anywhere
Mergedadd_bypass_address()andadd_host_route_if_nonlocal()