URL-Parser: fix parsing of Usernames with @
authorWilfried Goesgens <dothebart@citadel.org>
Thu, 12 Jul 2012 20:23:27 +0000 (22:23 +0200)
committerWilfried Goesgens <dothebart@citadel.org>
Thu, 12 Jul 2012 20:23:27 +0000 (22:23 +0200)
  - we previously would use strch to find the first @ in the URL
  - when there is an @ inside of the username this one would be hit.
  - since we first search for the end of the host-path, we can search from the right for the last @ to separate the user:auth from the real hostname.

libcitadel/lib/urlhandling.c

index 131cafa6ec4efed449a330320a661b8ea4baf7d6..49878afda5ccd0d5180c1ec7060cd25d7a0d6545 100644 (file)
@@ -53,12 +53,12 @@ int ParseURL(ParsedURL **Url, StrBuf *UrlStr, unsigned short DefaultPort)
         */
        url->URL = NewStrBufDup(UrlStr);
        url->Host = pch = ChrPtr(url->URL);
-       url->LocalPart = strchr(pch, '/');
+       pEndHost = url->LocalPart = strchr(pch, '/');
        if (url->LocalPart != NULL) {
                if ((*(url->LocalPart + 1) == '/') && 
                    (*(url->LocalPart - 1) == ':')) { /* TODO: find default port for this protocol... */
                        url->Host = url->LocalPart + 2;
-                       url->LocalPart = strchr(url->Host, '/');
+                       pEndHost = url->LocalPart = strchr(url->Host, '/');
                        if (url->LocalPart != NULL)
                        {
                            StrBufPeek(url->URL, url->LocalPart, 0, '\0');
@@ -67,10 +67,10 @@ int ParseURL(ParsedURL **Url, StrBuf *UrlStr, unsigned short DefaultPort)
                }
        }
        if (url->LocalPart == NULL) {
-               url->LocalPart = pch + StrLength(url->URL);
+               pEndHost = url->LocalPart = ChrPtr(url->URL) + StrLength(url->URL);
        }
 
-       pCredEnd = strchr(pch, '@');
+       pCredEnd = strrchr(ChrPtr(url->URL), '@');
        if (pCredEnd >= url->LocalPart)
                pCredEnd = NULL;
        if (pCredEnd != NULL)