Changeset 3332 for pjproject


Ignore:
Timestamp:
Oct 1, 2010 6:43:17 AM (14 years ago)
Author:
bennylp
Message:

Re #1136 (Basic and digest authentication in the HTTP client): fixed error in parsing URL if the path contains at ("@") character

Location:
pjproject/trunk/pjlib-util/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib-util/src/pjlib-util-test/http_client.c

    r3321 r3332  
    304304        {"http://:@pjsip.org", PJ_SUCCESS, "", "", "pjsip.org", 80, "/"}, 
    305305 
     306        /* '@' character in username and path */ 
     307        {"http://user@pjsip.org/@", PJ_SUCCESS, "user", "", "pjsip.org", 80, "/@"}, 
     308 
     309        /* '@' character in path */ 
     310        {"http://pjsip.org/@", PJ_SUCCESS, "", "", "pjsip.org", 80, "/@"}, 
     311 
     312        /* '@' character in path */ 
     313        {"http://pjsip.org/one@", PJ_SUCCESS, "", "", "pjsip.org", 80, "/one@"}, 
     314 
    306315        /* Invalid URL */ 
    307316        {"http://:", PJ_EINVAL, "", "", "", 0, ""}, 
     
    324333        /* Invalid URL */ 
    325334        {"http://@/", PJ_EINVAL, "", "", "", 0, ""}, 
     335 
     336        /* Invalid URL */ 
     337        {"http:///@", PJ_EINVAL, "", "", "", 0, ""}, 
    326338 
    327339        /* Invalid URL */ 
  • pjproject/trunk/pjlib-util/src/pjlib-util/http_client.c

    r3321 r3332  
    767767} 
    768768 
     769/* Get the location of '@' character to indicate the end of 
     770 * user:passwd part of an URI. If user:passwd part is not 
     771 * present, NULL will be returned. 
     772 */ 
     773static char *get_url_at_pos(const char *str, long len) 
     774{ 
     775    const char *end = str + len; 
     776    const char *p = str; 
     777 
     778    /* skip scheme: */ 
     779    while (p!=end && *p!='/') ++p; 
     780    if (p!=end && *p=='/') ++p; 
     781    if (p!=end && *p=='/') ++p; 
     782    if (p==end) return NULL; 
     783 
     784    for (; p!=end; ++p) { 
     785        switch (*p) { 
     786        case '/': 
     787            return NULL; 
     788        case '@': 
     789            return (char*)p; 
     790        } 
     791    } 
     792 
     793    return NULL; 
     794} 
     795 
     796 
    769797PJ_DEF(pj_status_t) pj_http_req_parse_url(const pj_str_t *url,  
    770798                                          pj_http_url *hurl) 
     
    802830        pj_scan_advance_n(&scanner, 3, PJ_FALSE); 
    803831 
    804         if (pj_memchr(url->ptr, '@', url->slen)) { 
     832        if (get_url_at_pos(url->ptr, url->slen)) { 
    805833            /* Parse username and password */ 
    806834            pj_scan_get_until_chr(&scanner, ":@", &hurl->username); 
     
    925953     * remove them from the URL. 
    926954     */ 
    927     if ((at_pos=pj_strchr(&hreq->url, '@')) != NULL) { 
     955    if ((at_pos=get_url_at_pos(hreq->url.ptr, hreq->url.slen)) != NULL) { 
    928956        pj_str_t tmp; 
    929957        char *user_pos = pj_strchr(&hreq->url, '/'); 
Note: See TracChangeset for help on using the changeset viewer.