Changeset 5682


Ignore:
Timestamp:
Nov 8, 2017 2:58:18 AM (6 years ago)
Author:
riza
Message:

Closed #2056: Add validity checking for numeric header values.

Location:
pjproject/trunk
Files:
2 added
12 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/build/pjlib.vcproj

    r4537 r5682  
    1497114971                        </File> 
    1497214972                        <File 
     14973                                RelativePath="..\include\pj\limits.h" 
     14974                                > 
     14975                        </File> 
     14976                        <File 
    1497314977                                RelativePath="..\include\pj\list.h" 
    1497414978                                > 
     
    1507415078                                </File> 
    1507515079                                <File 
     15080                                        RelativePath="..\include\pj\compat\limits.h" 
     15081                                        > 
     15082                                </File> 
     15083                                <File 
    1507615084                                        RelativePath="..\include\pj\compat\m_alpha.h" 
    1507715085                                        > 
  • pjproject/trunk/pjlib/build/pjlib.vcxproj

    r5539 r5682  
    495495      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> 
    496496    </ClCompile> 
    497     <ClCompile Include="..\src\pj\file_io_win32.c" />     
     497    <ClCompile Include="..\src\pj\file_io_win32.c" /> 
    498498    <ClCompile Include="..\src\pj\guid.c" /> 
    499499    <ClCompile Include="..\src\pj\guid_simple.c"> 
     
    891891    <ClInclude Include="..\include\pj\compat\errno.h" /> 
    892892    <ClInclude Include="..\include\pj\compat\high_precision.h" /> 
     893    <ClInclude Include="..\include\pj\compat\limits.h" /> 
    893894    <ClInclude Include="..\include\pj\compat\malloc.h" /> 
    894895    <ClInclude Include="..\include\pj\compat\m_alpha.h" /> 
     
    926927    <ClInclude Include="..\include\pj\ioqueue.h" /> 
    927928    <ClInclude Include="..\include\pj\ip_helper.h" /> 
     929    <ClInclude Include="..\include\pj\limits.h" /> 
    928930    <ClInclude Include="..\include\pj\list.h" /> 
    929931    <ClInclude Include="..\include\pj\list_i.h" /> 
  • pjproject/trunk/pjlib/build/pjlib.vcxproj.filters

    r5539 r5682  
    440440      <Filter>Header Files\compat</Filter> 
    441441    </ClInclude> 
     442    <ClInclude Include="..\include\pj\limits.h"> 
     443      <Filter>Header Files</Filter> 
     444    </ClInclude> 
     445    <ClInclude Include="..\include\pj\compat\limits.h"> 
     446      <Filter>Header Files\compat</Filter> 
     447    </ClInclude> 
    442448  </ItemGroup> 
    443449</Project> 
  • pjproject/trunk/pjlib/include/pj/compat/os_win32.h

    r3553 r5682  
    5858#define PJ_HAS_TIME_H               1 
    5959#define PJ_HAS_UNISTD_H             0 
     60#define PJ_HAS_LIMITS_H             1 
    6061 
    6162#define PJ_HAS_MSWSOCK_H            1 
  • pjproject/trunk/pjlib/include/pj/string.h

    r5520 r5682  
    2828#include <pj/types.h> 
    2929#include <pj/compat/string.h> 
    30  
    3130 
    3231PJ_BEGIN_DECL 
     
    637636 
    638637/** 
     638 * Convert string to signed long integer. The conversion will stop as 
     639 * soon as non-digit character is found or all the characters have 
     640 * been processed. 
     641 * 
     642 * @param str   the string. 
     643 * @param value Pointer to a long to receive the value. 
     644 * 
     645 * @return PJ_SUCCESS if successful.  Otherwise: 
     646 *         PJ_ETOOSMALL if the value was an impossibly long negative number. 
     647 *         In this case *value will be set to LONG_MIN. 
     648 *         \n 
     649 *         PJ_ETOOBIG if the value was an impossibly long positive number. 
     650 *         In this case, *value will be set to LONG_MAX. 
     651 *         \n 
     652 *         PJ_EINVAL if the input string was NULL, the value pointer was NULL  
     653 *         or the input string could not be parsed at all such as starting with 
     654 *         a character other than a '+', '-' or not in the '0' - '9' range. 
     655 *         In this case, *value will be left untouched. 
     656 */ 
     657PJ_DECL(pj_status_t) pj_strtol2(const pj_str_t *str, long *value); 
     658 
     659 
     660/** 
    639661 * Convert string to unsigned integer. The conversion will stop as 
    640662 * soon as non-digit character is found or all the characters have 
     
    663685PJ_DECL(unsigned long) pj_strtoul2(const pj_str_t *str, pj_str_t *endptr, 
    664686                                   unsigned base); 
     687 
     688/** 
     689 * Convert string to unsigned long integer. The conversion will stop as 
     690 * soon as non-digit character is found or all the characters have 
     691 * been processed. 
     692 * 
     693 * @param str       The input string. 
     694 * @param value     Pointer to an unsigned long to receive the value. 
     695 * @param base      Number base to use. 
     696 * 
     697 * @return PJ_SUCCESS if successful.  Otherwise: 
     698 *         PJ_ETOOBIG if the value was an impossibly long positive number. 
     699 *         In this case, *value will be set to ULONG_MAX. 
     700 *         \n 
     701 *         PJ_EINVAL if the input string was NULL, the value pointer was NULL  
     702 *         or the input string could not be parsed at all such as starting  
     703 *         with a character outside the base character range.  In this case, 
     704 *         *value will be left untouched. 
     705 */ 
     706PJ_DECL(pj_status_t) pj_strtoul3(const pj_str_t *str, unsigned long *value, 
     707                                 unsigned base); 
    665708 
    666709/** 
     
    787830} 
    788831 
    789  
    790832/** 
    791833 * @} 
  • pjproject/trunk/pjlib/include/pj/types.h

    r4704 r5682  
    280280/** Utility macro to compute the number of elements in static array. */ 
    281281#define PJ_ARRAY_SIZE(a)    (sizeof(a)/sizeof(a[0])) 
    282  
    283 /** Maximum value for signed 32-bit integer. */ 
    284 #define PJ_MAXINT32  0x7FFFFFFFL 
    285282 
    286283/** 
  • pjproject/trunk/pjlib/src/pj/string.c

    r5520 r5682  
    2424#include <pj/rand.h> 
    2525#include <pj/os.h> 
     26#include <pj/errno.h> 
     27#include <pj/limits.h> 
    2628 
    2729#if PJ_FUNCTIONS_ARE_INLINED==0 
    2830#  include <pj/string_i.h> 
    2931#endif 
     32 
    3033 
    3134PJ_DEF(pj_ssize_t) pj_strspn(const pj_str_t *str, const pj_str_t *set_char) 
     
    231234} 
    232235 
     236 
     237PJ_DEF(pj_status_t) pj_strtol2(const pj_str_t *str, long *value) 
     238{ 
     239    pj_str_t s; 
     240    unsigned long retval = 0; 
     241    pj_bool_t is_negative = PJ_FALSE; 
     242    int rc = 0; 
     243 
     244    PJ_CHECK_STACK(); 
     245 
     246    if (!str || !value) { 
     247        return PJ_EINVAL; 
     248    } 
     249 
     250    s = *str; 
     251    pj_strltrim(&s); 
     252 
     253    if (s.slen == 0) 
     254        return PJ_EINVAL; 
     255 
     256    if (s.ptr[0] == '+' || s.ptr[0] == '-') { 
     257        is_negative = (s.ptr[0] == '-'); 
     258        s.ptr += 1; 
     259        s.slen -= 1; 
     260    } 
     261 
     262    rc = pj_strtoul3(&s, &retval, 10); 
     263    if (rc == PJ_EINVAL) { 
     264        return rc; 
     265    } else if (rc != PJ_SUCCESS) { 
     266        *value = is_negative ? PJ_MINLONG : PJ_MAXLONG; 
     267        return is_negative ? PJ_ETOOSMALL : PJ_ETOOBIG; 
     268    } 
     269 
     270    if (retval > PJ_MAXLONG && !is_negative) { 
     271        *value = PJ_MAXLONG; 
     272        return PJ_ETOOBIG; 
     273    } 
     274 
     275    if (retval > (PJ_MAXLONG + 1UL) && is_negative) { 
     276        *value = PJ_MINLONG; 
     277        return PJ_ETOOSMALL; 
     278    } 
     279 
     280    *value = is_negative ? -(long)retval : retval; 
     281 
     282    return PJ_SUCCESS; 
     283} 
     284 
    233285PJ_DEF(unsigned long) pj_strtoul(const pj_str_t *str) 
    234286{ 
     
    281333 
    282334    return value; 
     335} 
     336 
     337PJ_DEF(pj_status_t) pj_strtoul3(const pj_str_t *str, unsigned long *value, 
     338                                unsigned base) 
     339{ 
     340    pj_str_t s; 
     341    unsigned i; 
     342 
     343    PJ_CHECK_STACK(); 
     344 
     345    if (!str || !value) { 
     346        return PJ_EINVAL; 
     347    } 
     348 
     349    s = *str; 
     350    pj_strltrim(&s); 
     351 
     352    if (s.slen == 0 || s.ptr[0] < '0' || 
     353        (base <= 10 && (unsigned)s.ptr[0] > ('0' - 1) + base) || 
     354        (base == 16 && !pj_isxdigit(s.ptr[0]))) 
     355    { 
     356        return PJ_EINVAL; 
     357    } 
     358 
     359    *value = 0; 
     360    if (base <= 10) { 
     361        for (i=0; i<(unsigned)s.slen; ++i) { 
     362            unsigned c = s.ptr[i] - '0'; 
     363            if (s.ptr[i] < '0' || (unsigned)s.ptr[i] > ('0' - 1) + base) { 
     364                break; 
     365            } 
     366            if (*value > PJ_MAXULONG / base) { 
     367                *value = PJ_MAXULONG; 
     368                return PJ_ETOOBIG; 
     369            } 
     370 
     371            *value *= base; 
     372            if ((PJ_MAXULONG - *value) < c) { 
     373                *value = PJ_MAXULONG; 
     374                return PJ_ETOOBIG; 
     375            } 
     376            *value += c; 
     377        } 
     378    } else if (base == 16) { 
     379        for (i=0; i<(unsigned)s.slen; ++i) { 
     380            unsigned c = pj_hex_digit_to_val(s.ptr[i]); 
     381            if (!pj_isxdigit(s.ptr[i])) 
     382                break; 
     383 
     384            if (*value > PJ_MAXULONG / base) { 
     385                *value = PJ_MAXULONG; 
     386                return PJ_ETOOBIG; 
     387            } 
     388            *value *= base; 
     389            if ((PJ_MAXULONG - *value) < c) { 
     390                *value = PJ_MAXULONG; 
     391                return PJ_ETOOBIG; 
     392            } 
     393            *value += c; 
     394        } 
     395    } else { 
     396        pj_assert(!"Unsupported base"); 
     397        return PJ_EINVAL; 
     398    } 
     399    return PJ_SUCCESS; 
    283400} 
    284401 
     
    357474    return len; 
    358475} 
    359  
    360  
  • pjproject/trunk/pjlib/src/pj/timer.c

    r4855 r5682  
    3737#include <pj/log.h> 
    3838#include <pj/rand.h> 
     39#include <pj/limits.h> 
    3940 
    4041#define THIS_FILE       "timer.c" 
  • pjproject/trunk/pjsip/include/pjsip/sip_parser.h

    r4445 r5682  
    3838 * @{ 
    3939 */ 
     40 
     41/** 
     42 * Contants for limit checks 
     43 */ 
     44#define PJSIP_MIN_CONTENT_LENGTH    0 
     45#define PJSIP_MAX_CONTENT_LENGTH    PJ_MAXINT32 
     46#define PJSIP_MIN_PORT              0 
     47#define PJSIP_MAX_PORT              PJ_MAXUINT16 
     48#define PJSIP_MIN_TTL               0 
     49#define PJSIP_MAX_TTL               PJ_MAXUINT8 
     50#define PJSIP_MIN_STATUS_CODE       100 
     51#define PJSIP_MAX_STATUS_CODE       999 
     52#define PJSIP_MIN_Q1000             0 
     53#define PJSIP_MAX_Q1000             PJ_MAXINT32 / 1000 
     54#define PJSIP_MIN_EXPIRES           0 
     55#define PJSIP_MAX_EXPIRES           PJ_MAXINT32 
     56#define PJSIP_MIN_CSEQ              0 
     57#define PJSIP_MAX_CSEQ              PJ_MAXINT32 
     58#define PJSIP_MIN_RETRY_AFTER       0 
     59#define PJSIP_MAX_RETRY_AFTER       PJ_MAXINT32 
    4060 
    4161/** 
     
    6383 */ 
    6484extern int PJSIP_SYN_ERR_EXCEPTION; 
     85 
     86/** 
     87 * Invalid value error exception value. 
     88 */ 
     89extern int PJSIP_EINVAL_ERR_EXCEPTION; 
    6590 
    6691/** 
  • pjproject/trunk/pjsip/src/pjsip/sip_parser.c

    r5280 r5682  
    3535#include <pj/ctype.h> 
    3636#include <pj/assert.h> 
     37#include <pj/limits.h> 
    3738 
    3839#define THIS_FILE           "sip_parser.c" 
     
    9495 */ 
    9596int PJSIP_SYN_ERR_EXCEPTION = -1; 
     97int PJSIP_EINVAL_ERR_EXCEPTION = -2; 
    9698 
    9799/* Parser constants */ 
     
    206208#define parser_stricmp(s1, s2)  (s1.slen!=s2.slen || pj_stricmp_alnum(&s1, &s2)) 
    207209 
    208  
    209210/* Get a token and unescape */ 
    210211PJ_INLINE(void) parser_get_and_unescape(pj_scanner *scanner, pj_pool_t *pool, 
     
    224225} 
    225226 
    226  
    227  
    228227/* Syntax error handler for parser. */ 
    229228static void on_syntax_error(pj_scanner *scanner) 
     
    231230    PJ_UNUSED_ARG(scanner); 
    232231    PJ_THROW(PJSIP_SYN_ERR_EXCEPTION); 
     232} 
     233 
     234/* Syntax error handler for parser. */ 
     235static void on_str_parse_error(const pj_str_t *str, int rc) 
     236{ 
     237    char *s; 
     238 
     239    switch(rc) { 
     240    case PJ_EINVAL: 
     241        s = "NULL input string, invalid input string, or NULL return "\ 
     242            "value pointer"; 
     243        break; 
     244    case PJ_ETOOSMALL: 
     245        s = "String value was less than the minimum allowed value."; 
     246        break; 
     247    case PJ_ETOOBIG: 
     248        s = "String value was greater than the maximum allowed value."; 
     249        break; 
     250    default: 
     251        s = "Unknown error"; 
     252    } 
     253 
     254    if (str) { 
     255        PJ_LOG(1, (THIS_FILE, "Error parsing '%.*s': %s", 
     256                   (int)str->slen, str->ptr, s)); 
     257    } else { 
     258        PJ_LOG(1, (THIS_FILE, "Can't parse input string: %s", s)); 
     259    } 
     260    PJ_THROW(PJSIP_EINVAL_ERR_EXCEPTION); 
     261} 
     262 
     263static void strtoi_validate(const pj_str_t *str, int min_val, 
     264                            int max_val, int *value) 
     265{  
     266    long retval; 
     267    pj_status_t status; 
     268 
     269    if (!str || !value) { 
     270        on_str_parse_error(str, PJ_EINVAL); 
     271    } 
     272    status = pj_strtol2(str, &retval); 
     273    if (status != PJ_EINVAL) { 
     274        if (min_val > retval) { 
     275            *value = min_val; 
     276            status = PJ_ETOOSMALL; 
     277        } else if (retval > max_val) { 
     278            *value = max_val; 
     279            status = PJ_ETOOBIG; 
     280        } else 
     281            *value = (int)retval; 
     282    } 
     283 
     284    if (status != PJ_SUCCESS) 
     285        on_str_parse_error(str, status); 
    233286} 
    234287 
     
    286339 
    287340    /* 
     341     * Invalid value exception. 
     342     */ 
     343    pj_assert (PJSIP_EINVAL_ERR_EXCEPTION == -2); 
     344    status = pj_exception_id_alloc("PJSIP invalid value error",  
     345                                   &PJSIP_EINVAL_ERR_EXCEPTION); 
     346    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     347 
     348    /* 
    288349     * Init character input spec (cis) 
    289350     */ 
     
    503564        pj_exception_id_free(PJSIP_SYN_ERR_EXCEPTION); 
    504565        PJSIP_SYN_ERR_EXCEPTION = -1; 
     566 
     567        pj_exception_id_free(PJSIP_EINVAL_ERR_EXCEPTION); 
     568        PJSIP_EINVAL_ERR_EXCEPTION = -2; 
    505569    } 
    506570    pj_leave_critical_section(); 
     
    767831 
    768832/* Determine if a message has been received. */ 
    769 PJ_DEF(pj_bool_t) pjsip_find_msg( const char *buf, pj_size_t size,  
     833PJ_DEF(pj_status_t) pjsip_find_msg( const char *buf, pj_size_t size,  
    770834                                  pj_bool_t is_datagram, pj_size_t *msg_size) 
    771835{ 
     
    777841    int content_length = -1; 
    778842    pj_str_t cur_msg; 
     843    pj_status_t status = PJ_SUCCESS; 
    779844    const pj_str_t end_hdr = { "\n\r\n", 3}; 
    780845 
     
    837902 
    838903                /* Found a valid Content-Length header. */ 
    839                 content_length = pj_strtoul(&str_clen); 
     904                strtoi_validate(&str_clen, PJSIP_MIN_CONTENT_LENGTH, 
     905                                PJSIP_MAX_CONTENT_LENGTH, &content_length); 
    840906            } 
    841907            PJ_CATCH_ANY { 
     908                int eid = PJ_GET_EXCEPTION(); 
     909                if (eid == PJSIP_SYN_ERR_EXCEPTION) { 
     910                    status = PJSIP_EMISSINGHDR; 
     911                } else if (eid == PJSIP_EINVAL_ERR_EXCEPTION) { 
     912                    status = PJSIP_EINVALIDHDR; 
     913                } 
    842914                content_length = -1; 
    843915            } 
     
    859931    /* Found Content-Length? */ 
    860932    if (content_length == -1) { 
    861         return PJSIP_EMISSINGHDR; 
     933        return status; 
    862934    } 
    863935 
     
    9391011                                 pjsip_parser_err_report *err_list) 
    9401012{ 
    941     pj_bool_t parsing_headers; 
    942     pjsip_msg *msg = NULL; 
     1013    /* These variables require "volatile" so their values get 
     1014     * preserved when re-entering the PJ_TRY block after an error. 
     1015     */ 
     1016    volatile pj_bool_t parsing_headers; 
     1017    pjsip_msg *volatile msg = NULL; 
     1018    pjsip_ctype_hdr *volatile ctype_hdr = NULL; 
     1019 
    9431020    pj_str_t hname; 
    944     pjsip_ctype_hdr *ctype_hdr = NULL; 
    9451021    pj_scanner *scanner = ctx->scanner; 
    9461022    pj_pool_t *pool = ctx->pool; 
     
    10241100            } 
    10251101             
    1026          
    10271102            /* Single parse of header line can produce multiple headers. 
    10281103             * For example, if one Contact: header contains Contact list 
     
    12681343        pj_scan_get_char(scanner); 
    12691344        pj_scan_get(scanner, &pconst.pjsip_DIGIT_SPEC, &port); 
    1270         *p_port = pj_strtoul(&port); 
     1345        strtoi_validate(&port, PJSIP_MIN_PORT, PJSIP_MAX_PORT, p_port); 
    12711346    } else { 
    12721347        *p_port = 0; 
     
    14591534 
    14601535        } else if (!parser_stricmp(pname, pconst.pjsip_TTL_STR) && pvalue.slen) { 
    1461             url->ttl_param = pj_strtoul(&pvalue); 
    1462  
     1536            strtoi_validate(&pvalue, PJSIP_MIN_TTL, PJSIP_MAX_TTL, 
     1537                            &url->ttl_param); 
    14631538        } else if (!parser_stricmp(pname, pconst.pjsip_MADDR_STR) && pvalue.slen) { 
    14641539            url->maddr_param = pvalue; 
     
    15961671    parse_sip_version(scanner); 
    15971672    pj_scan_get( scanner, &pconst.pjsip_DIGIT_SPEC, &token); 
    1598     status_line->code = pj_strtoul(&token); 
     1673    strtoi_validate(&token, PJSIP_MIN_STATUS_CODE, PJSIP_MAX_STATUS_CODE, 
     1674                    &status_line->code); 
    15991675    if (*scanner->curptr != '\r' && *scanner->curptr != '\n') 
    16001676        pj_scan_get( scanner, &pconst.pjsip_NOT_NEWLINE, &status_line->reason); 
     
    17811857            char *dot_pos = (char*) pj_memchr(pvalue.ptr, '.', pvalue.slen); 
    17821858            if (!dot_pos) { 
    1783                 hdr->q1000 = pj_strtoul(&pvalue) * 1000; 
     1859                strtoi_validate(&pvalue, PJSIP_MIN_Q1000, PJSIP_MAX_Q1000, 
     1860                                &hdr->q1000); 
     1861                hdr->q1000 *= 1000; 
    17841862            } else { 
    17851863                pj_str_t tmp = pvalue; 
     1864                unsigned long qval_frac; 
    17861865 
    17871866                tmp.slen = dot_pos - pvalue.ptr; 
    1788                 hdr->q1000 = pj_strtoul(&tmp) * 1000; 
     1867                strtoi_validate(&tmp, PJSIP_MIN_Q1000, PJSIP_MAX_Q1000, 
     1868                                &hdr->q1000); 
     1869                hdr->q1000 *= 1000; 
    17891870 
    17901871                pvalue.slen = (pvalue.ptr+pvalue.slen) - (dot_pos+1); 
    17911872                pvalue.ptr = dot_pos + 1; 
    1792                 hdr->q1000 += pj_strtoul_mindigit(&pvalue, 3); 
     1873                if (pvalue.slen > 3) { 
     1874                    pvalue.slen = 3; 
     1875                } 
     1876                qval_frac = pj_strtoul_mindigit(&pvalue, 3); 
     1877                if ((unsigned)hdr->q1000 > (PJ_MAXINT32 - qval_frac)) { 
     1878                    PJ_THROW(PJSIP_SYN_ERR_EXCEPTION); 
     1879                } 
     1880                hdr->q1000 += qval_frac; 
    17931881            }     
    1794         } else if (!parser_stricmp(pname, pconst.pjsip_EXPIRES_STR) && pvalue.slen) { 
    1795             hdr->expires = pj_strtoul(&pvalue); 
    1796  
     1882        } else if (!parser_stricmp(pname, pconst.pjsip_EXPIRES_STR) &&  
     1883                   pvalue.slen)  
     1884        { 
     1885            strtoi_validate(&pvalue, PJSIP_MIN_EXPIRES, PJSIP_MAX_EXPIRES, 
     1886                            &hdr->expires); 
    17971887        } else { 
    17981888            pjsip_param *p = PJ_POOL_ALLOC_T(pool, pjsip_param); 
     
    18911981{ 
    18921982    pj_str_t cseq, method; 
    1893     pjsip_cseq_hdr *hdr; 
     1983    pjsip_cseq_hdr *hdr = NULL; 
     1984    int cseq_val = 0; 
     1985 
     1986    pj_scan_get( ctx->scanner, &pconst.pjsip_DIGIT_SPEC, &cseq); 
     1987    strtoi_validate(&cseq, PJSIP_MIN_CSEQ, PJSIP_MAX_CSEQ, &cseq_val); 
    18941988 
    18951989    hdr = pjsip_cseq_hdr_create(ctx->pool); 
    1896     pj_scan_get( ctx->scanner, &pconst.pjsip_DIGIT_SPEC, &cseq); 
    1897     hdr->cseq = pj_strtoul(&cseq); 
     1990    hdr->cseq = cseq_val; 
    18981991 
    18991992    pj_scan_get( ctx->scanner, &pconst.pjsip_TOKEN_SPEC, &method); 
     1993    parse_hdr_end( ctx->scanner ); 
     1994 
    19001995    pjsip_method_init_np(&hdr->method, &method); 
    1901  
    1902     parse_hdr_end( ctx->scanner ); 
    1903  
    1904     if (ctx->rdata) 
     1996    if (ctx->rdata) { 
    19051997        ctx->rdata->msg_info.cseq = hdr; 
     1998    } 
    19061999 
    19072000    return (pjsip_hdr*)hdr; 
     
    19852078     
    19862079    pj_scan_get(scanner, &pconst.pjsip_DIGIT_SPEC, &tmp); 
    1987     hdr->ivalue = pj_strtoul(&tmp); 
     2080    strtoi_validate(&tmp, PJSIP_MIN_RETRY_AFTER, PJSIP_MAX_RETRY_AFTER, 
     2081                    &hdr->ivalue); 
    19882082 
    19892083    while (!pj_scan_is_eof(scanner) && *scanner->curptr!='\r' && 
     
    20742168 
    20752169        } else if (!parser_stricmp(pname, pconst.pjsip_TTL_STR) && pvalue.slen) { 
    2076             hdr->ttl_param = pj_strtoul(&pvalue); 
     2170            strtoi_validate(&pvalue, PJSIP_MIN_TTL, PJSIP_MAX_TTL, 
     2171                            &hdr->ttl_param); 
    20772172             
    20782173        } else if (!parser_stricmp(pname, pconst.pjsip_MADDR_STR) && pvalue.slen) { 
     
    20832178 
    20842179        } else if (!parser_stricmp(pname, pconst.pjsip_RPORT_STR)) { 
    2085             if (pvalue.slen) 
    2086                 hdr->rport_param = pj_strtoul(&pvalue); 
    2087             else 
     2180            if (pvalue.slen) { 
     2181                strtoi_validate(&pvalue, PJSIP_MIN_PORT, PJSIP_MAX_PORT, 
     2182                                &hdr->rport_param); 
     2183            } else 
    20882184                hdr->rport_param = 0; 
    20892185        } else { 
     
    22142310            pj_scan_get_char(scanner); 
    22152311            pj_scan_get(scanner, &pconst.pjsip_DIGIT_SPEC, &digit); 
    2216             hdr->sent_by.port = pj_strtoul(&digit); 
     2312            strtoi_validate(&digit, PJSIP_MIN_PORT, PJSIP_MAX_PORT, 
     2313                            &hdr->sent_by.port); 
    22172314        } 
    22182315         
     
    22992396{ 
    23002397    enum { STOP_ON_ERROR = 1 }; 
     2398    pj_str_t hname; 
    23012399    pj_scanner scanner; 
    23022400    pjsip_parse_ctx ctx; 
    2303     pj_str_t hname; 
     2401 
    23042402    PJ_USE_EXCEPTION; 
    23052403 
     
    23242422            hname.slen = 0; 
    23252423 
    2326             /* Get hname. */ 
     2424            /* Get hname. */             
    23272425            pj_scan_get( &scanner, &pconst.pjsip_TOKEN_SPEC, &hname); 
    23282426            if (pj_scan_get_char( &scanner ) != ':') { 
  • pjproject/trunk/pjsip/src/pjsip/sip_transaction.c

    r5613 r5682  
    290290    /* Calculate length required. */ 
    291291    len_required = method->name.slen +      /* Method */ 
    292                    9 +                      /* CSeq number */ 
     292                   11 +                     /* CSeq number */ 
    293293                   rdata->msg_info.from->tag.slen +   /* From tag. */ 
    294294                   rdata->msg_info.cid->id.slen +    /* Call-ID */ 
    295295                   host->slen +             /* Via host. */ 
    296                    9 +                      /* Via port. */ 
     296                   11 +                     /* Via port. */ 
    297297                   16;                      /* Separator+Allowance. */ 
    298298    key = p = (char*) pj_pool_alloc(pool, len_required); 
  • pjproject/trunk/pjsip/src/pjsip/sip_transport.c

    r5564 r5682  
    18491849        if (msg==NULL || !pj_list_empty(&rdata->msg_info.parse_err)) { 
    18501850            pjsip_parser_err_report *err; 
    1851             char buf[128]; 
     1851            char buf[256]; 
    18521852            pj_str_t tmp; 
    18531853 
     
    18631863                                       (int)err->hname.slen, err->hname.ptr, 
    18641864                                       err->line, err->col); 
    1865                 if (len > 0 && len < (int) (sizeof(buf)-tmp.slen)) { 
     1865                if (len >= (int)sizeof(buf)-tmp.slen) { 
     1866                    len = (int)sizeof(buf)-tmp.slen; 
     1867                } 
     1868                if (len > 0) { 
    18661869                    tmp.slen += len; 
    18671870                } 
Note: See TracChangeset for help on using the changeset viewer.