VirtualBox

Changeset 74424 in vbox


Ignore:
Timestamp:
Sep 22, 2018 8:00:36 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
125259
Message:

IPRT/uri: Better handling of empty port specifiers. bugref:9249

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/uri.h

    r69105 r74424  
    9797    /** The length of the host part of the authority. */
    9898    size_t      cchAuthorityHost;
    99     /** The authority port number, UINT32_MAX if not present. */
     99    /** The authority port number, UINT32_MAX if not present or empty. */
    100100    uint32_t    uAuthorityPort;
    101101    /** @} */
     
    110110/** Set if the URI contains escaped characters. */
    111111#define RTURIPARSED_F_CONTAINS_ESCAPED_CHARS        UINT32_C(0x00000001)
    112 /** Set if the URI have an authority component.  Necessary since the authority
     112/** Set if the URI has an authority component.  Necessary since the authority
    113113 * component can have a zero length. */
    114 #define RTURIPARSED_F_HAVE_AUTHORITY                UINT32_C(0x00000002)
     114#define RTURIPARSED_F_HAS_AUTHORITY                 UINT32_C(0x00000002)
     115/** Set if there is a port component. */
     116#define RTURIPARSED_F_HAS_PORT                      UINT32_C(0x00000004)
    115117/** @} */
    116118
  • trunk/src/VBox/Runtime/common/misc/uri.cpp

    r69111 r74424  
    445445        off += 2;
    446446        pParsed->offAuthority = pParsed->offAuthorityUsername = pParsed->offAuthorityPassword = pParsed->offAuthorityHost = off;
    447         pParsed->fFlags |= RTURIPARSED_F_HAVE_AUTHORITY;
     447        pParsed->fFlags |= RTURIPARSED_F_HAS_AUTHORITY;
    448448
    449449        /*
     
    496496                size_t cchTmp = &pszUri[pParsed->offAuthorityHost + pParsed->cchAuthorityHost] - &pszColon[1];
    497497                pParsed->cchAuthorityHost -= cchTmp + 1;
    498 
    499                 pParsed->uAuthorityPort = 0;
    500                 while (cchTmp-- > 0)
     498                pParsed->fFlags |= RTURIPARSED_F_HAS_PORT;
     499                if (cchTmp > 0)
    501500                {
    502                     ch = *++pszColon;
    503                     if (   RT_C_IS_DIGIT(ch)
    504                         && pParsed->uAuthorityPort < UINT32_MAX / UINT32_C(10))
     501                    pParsed->uAuthorityPort = 0;
     502                    while (cchTmp-- > 0)
    505503                    {
    506                         pParsed->uAuthorityPort *= 10;
    507                         pParsed->uAuthorityPort += ch - '0';
     504                        ch = *++pszColon;
     505                        if (   RT_C_IS_DIGIT(ch)
     506                            && pParsed->uAuthorityPort < UINT32_MAX / UINT32_C(10))
     507                        {
     508                            pParsed->uAuthorityPort *= 10;
     509                            pParsed->uAuthorityPort += ch - '0';
     510                        }
     511                        else
     512                            return VERR_URI_INVALID_PORT_NUMBER;
    508513                    }
    509                     else
    510                         return VERR_URI_INVALID_PORT_NUMBER;
    511514                }
    512515            }
     
    678681    AssertPtrReturn(pParsed, NULL);
    679682    AssertReturn(pParsed->u32Magic == RTURIPARSED_MAGIC, NULL);
    680     if (pParsed->cchAuthority || (pParsed->fFlags & RTURIPARSED_F_HAVE_AUTHORITY))
     683    if (pParsed->cchAuthority || (pParsed->fFlags & RTURIPARSED_F_HAS_AUTHORITY))
    681684        return rtUriPercentDecodeN(&pszUri[pParsed->offAuthority], pParsed->cchAuthority);
    682685    return NULL;
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette