You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Justin Erenkrantz <ju...@erenkrantz.com> on 2003/10/24 23:57:49 UTC

[PATCH] Fix integer overflow in svn_auth.h

My compiler (Sun Forte) gave me:

"../../subversion/subversion/libsvn_ra_dav/session.c", line 138: warning: 
integer overflow detected: op "<<" (E_INTEGER_OVERFLOW_DETECTED)

session.c line 138 is:

svn_failures |= SVN_AUTH_SSL_OTHER;

SVN_AUTH_SSL_OTHER is defined as (1<<31), which is -2147483648.  I think 
the  or will lose/obscure all of the other status values - which based on 
my reading, isn't quite right (and is an overflow condition).  So, I think 
it should be (1<<30).

But, svn_auth.h has this above the #define's:

 * Note that these values are stored in the on disk auth cache by the
 * SSL server certificate auth provider, so the meaning of these bits
 * must not be changed without careful consideration.

So, what to do?  Yet, I propose to change it as follows.  -- justin

Index: subversion/include/svn_auth.h
===================================================================
--- subversion/include/svn_auth.h	(revision 7517)
+++ subversion/include/svn_auth.h	(working copy)
@@ -277,7 +277,7 @@
 #define SVN_AUTH_SSL_EXPIRED     (1<<1)
 #define SVN_AUTH_SSL_CNMISMATCH  (1<<2)
 #define SVN_AUTH_SSL_UNKNOWNCA   (1<<3)
-#define SVN_AUTH_SSL_OTHER       (1<<31)
+#define SVN_AUTH_SSL_OTHER       (1<<30)

 typedef svn_error_t *(*svn_auth_ssl_server_trust_prompt_func_t) (
   svn_auth_cred_ssl_server_trust_t **cred,


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] Fix integer overflow in svn_auth.h

Posted by Branko Čibej <br...@xbc.nu>.
Tobias Ringström wrote:

> Justin Erenkrantz wrote:
>
>> So, what to do?  Yet, I propose to change it as follows.  -- justin
>
>
> Whoups, my mistake.  I added that code yesterday.  I really intended
> (1<<30) to avoid the sign bit, but I obviously cannot count.  I doubt
> that anyone has had time to depend on that bit position yet, so I've
> fixed it in revision 7518.  Thanks for spotting this!  I think I have
> seen gcc warn about this, but it did not this time... :-(
>
> Actually it would have been enough to say (1U << 31), but I think it's
> still wise to stay away from the sign bit.

No, Greg Hudson is right. Use apr_uint32_t for the bitmask. And please
define the constants as constants, not expressions; e.g.,

    #define SVN_AUTH_SSL_OTHER   0x80000000

Then the compiler won't complain.

-- 
Brane Čibej   <br...@xbc.nu>   http://www.xbc.nu/brane/


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] Fix integer overflow in svn_auth.h

Posted by Tobias Ringström <to...@ringstrom.mine.nu>.
Justin Erenkrantz wrote:

> So, what to do?  Yet, I propose to change it as follows.  -- justin

Whoups, my mistake.  I added that code yesterday.  I really intended 
(1<<30) to avoid the sign bit, but I obviously cannot count.  I doubt 
that anyone has had time to depend on that bit position yet, so I've 
fixed it in revision 7518.  Thanks for spotting this!  I think I have 
seen gcc warn about this, but it did not this time... :-(

Actually it would have been enough to say (1U << 31), but I think it's 
still wise to stay away from the sign bit.

/Tobias


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] Fix integer overflow in svn_auth.h

Posted by Greg Hudson <gh...@MIT.EDU>.
On Fri, 2003-10-24 at 19:57, Justin Erenkrantz wrote:
> "../../subversion/subversion/libsvn_ra_dav/session.c", line 138: warning: 
> integer overflow detected: op "<<" (E_INTEGER_OVERFLOW_DETECTED)

By my reading, if we want to use 1 << 31, we need to cast the 1 to
unsigned apr_uint32_t, and hold the status in an apr_uint32_t instead of
an int.  That also has implications for ssl_server_trust_providers.c and
possibly other code.  It's a lot more work to fix this up, but we really
shouldn't be using a signed type for bit containers even if we aren't
using 1<<31; it's cleaner to use an unsigned type.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org