apr-bugs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 42250] New: - apr_snprintf %llu conversion for uint64_t can fail for large numbers
Date Wed, 25 Apr 2007 15:42:55 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=42250>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=42250

           Summary: apr_snprintf %llu conversion for uint64_t can fail for
                    large numbers
           Product: APR
           Version: HEAD
          Platform: All
        OS/Version: Linux
            Status: NEW
          Severity: major
          Priority: P1
         Component: APR
        AssignedTo: bugs@apr.apache.org
        ReportedBy: wynn@bungeelabs.com


If apr_snprintf is called with a format of %llu and a uint64_t is passed in, 
the code in conv_10_quad() in strings/apr_snprintf.c that tries to optimize 
the conversion by downcasting to a 32 bit number will sometimes incorrectly 
determine that the number can be treated as a 32 bit number.

If the original uint64_t number is large enough (like 10267677267010969076 - 
becomes -8179066806698582540 when cast to an int64_t) that it becomes negative 
when casted to the type that the widest_int type def is (int64_t in this 
case), the line (#399 in 1.2.8 - should be about the same place in 
subversion):
if ((num <= ULONG_MAX && is_unsigned)

will incorrectly succeed since the int64_t version (-8179066806698582540) is 
less than ULONG_MAX. Changing the line to:
if (((u_widest_int)num <= (u_widest_int)ULONG_MAX && is_unsigned)

fixes the problem as then num is not treated as a negative compiler. This may 
be compiler-dependant (i've seen this on kubuntu 7.04 with gcc 4.1.2) but it 
would be better to make the behavior explicit with the u_widest_int cast.

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@apr.apache.org
For additional commands, e-mail: bugs-help@apr.apache.org


Mime
View raw message