Changeset ef06c74 in mod_gnutls


Ignore:
Timestamp:
Jun 18, 2016, 3:18:36 PM (7 years ago)
Author:
Thomas Klute <thomas2.klute@…>
Branches:
asyncio, debian/master, debian/stretch-backports, main, master, proxy-ticket, upstream
Children:
f1147b6
Parents:
ac3f500
Message:

Compatibility code for GCC version < 5

The builtin_add_overflow() which is used for safe integer type
conversion was introduced with GCC 5, and thus unfortunately is not
available in Debian stable.

The "!defined(clang)" part in the version check is because Clang
3.8 has the builtin, but pretends to be GCC 4 as far as the GNUC
macro is concerned.

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/gnutls_ocsp.c

    rac3f500 ref06c74  
    393393     * (unsigned int) and fplen (size_t) may have different
    394394     * lengths. */
     395#if defined(__GNUC__) && __GNUC__ < 5 && !defined(__clang__)
     396    if (__builtin_expect(fplen <= UINT_MAX, 1))
     397    {
     398        fingerprint.size = (unsigned int) fplen;
     399        fingerprint.data = fp;
     400    }
     401#else
    395402    if (__builtin_add_overflow(fplen, 0, &fingerprint.size))
    396403        fingerprint.size = 0;
    397404    else
    398405        fingerprint.data = fp;
     406#endif
    399407    return fingerprint;
    400408}
     
    541549    }
    542550
    543     /* With the length restriction this really should not happen. */
     551    /* With the length restriction this really should not overflow. */
     552#if defined(__GNUC__) && __GNUC__ < 5 && !defined(__clang__)
     553    if (__builtin_expect(len > UINT_MAX, 0))
     554#else
    544555    if (__builtin_add_overflow(len, 0, &response->size))
     556#endif
    545557    {
    546558        response->data = NULL;
     
    549561    else
    550562    {
     563#if defined(__GNUC__) && __GNUC__ < 5 && !defined(__clang__)
     564        response->size = (unsigned int) len;
     565#endif
    551566        response->data = apr_pmemdup(p, buf, len);
    552567    }
  • src/gnutls_util.c

    rac3f500 ref06c74  
    112112    apr_file_close(file);
    113113
    114     /* safe integer type conversion */
     114    /* safe integer type conversion: unsigned int and apr_size_t might
     115     * have different sizes */
     116#if defined(__GNUC__) && __GNUC__ < 5 && !defined(__clang__)
     117    if (__builtin_expect(br > UINT_MAX, 0))
     118        return APR_EINVAL;
     119    else
     120        datum->size = (unsigned int) br;
     121#else
    115122    if (__builtin_add_overflow(br, 0, &datum->size))
    116123        return APR_EINVAL;
     124#endif
    117125
    118126    return rv;
Note: See TracChangeset for help on using the changeset viewer.