* @uri: pointer to an URI structure
* @str: the string to analyze
*
- * Parse a port part and fills in the appropriate fields
+ * Parse a port part and fills in the appropriate fields
* of the @uri structure
*
* port = *DIGIT
xmlParse3986Port(xmlURIPtr uri, const char **str)
{
const char *cur = *str;
+ unsigned port = 0; /* unsigned for defined overflow behavior */
if (ISA_DIGIT(cur)) {
- if (uri != NULL)
- uri->port = 0;
while (ISA_DIGIT(cur)) {
- if (uri != NULL)
- uri->port = uri->port * 10 + (*cur - '0');
+ port = port * 10 + (*cur - '0');
+
cur++;
}
+ if (uri != NULL)
+ uri->port = port & INT_MAX; /* port value modulo INT_MAX+1 */
*str = cur;
return(0);
}
res->scheme = xmlMemStrdup(bas->scheme);
if (bas->authority != NULL)
res->authority = xmlMemStrdup(bas->authority);
- else if (bas->server != NULL) {
- res->server = xmlMemStrdup(bas->server);
+ else if ((bas->server != NULL) || (bas->port == -1)) {
+ if (bas->server != NULL)
+ res->server = xmlMemStrdup(bas->server);
if (bas->user != NULL)
res->user = xmlMemStrdup(bas->user);
res->port = bas->port;
}
if (bas->authority != NULL)
res->authority = xmlMemStrdup(bas->authority);
- else if (bas->server != NULL) {
- res->server = xmlMemStrdup(bas->server);
+ else if ((bas->server != NULL) || (bas->port == -1)) {
+ if (bas->server != NULL)
+ res->server = xmlMemStrdup(bas->server);
if (bas->user != NULL)
res->user = xmlMemStrdup(bas->user);
res->port = bas->port;
xmlChar *val = NULL;
int ret;
int ix;
- int pos = 0;
int nbslash = 0;
int len;
xmlURIPtr ref = NULL;
uptr = NULL;
len = 1; /* this is for a string terminator only */
} else {
- /*
- * Next we compare the two strings and find where they first differ
- */
- if ((ref->path[pos] == '.') && (ref->path[pos+1] == '/'))
- pos += 2;
+ xmlChar *rptr = (xmlChar *) ref->path;
+ int pos = 0;
+
+ /*
+ * Next we compare the two strings and find where they first differ
+ */
+ if ((*rptr == '.') && (rptr[1] == '/'))
+ rptr += 2;
if ((*bptr == '.') && (bptr[1] == '/'))
bptr += 2;
- else if ((*bptr == '/') && (ref->path[pos] != '/'))
+ else if ((*bptr == '/') && (*rptr != '/'))
bptr++;
- while ((bptr[pos] == ref->path[pos]) && (bptr[pos] != 0))
+ while ((bptr[pos] == rptr[pos]) && (bptr[pos] != 0))
pos++;
- if (bptr[pos] == ref->path[pos]) {
+ if (bptr[pos] == rptr[pos]) {
val = xmlStrdup(BAD_CAST "");
goto done; /* (I can't imagine why anyone would do this) */
}
* beginning of the "unique" suffix of URI
*/
ix = pos;
- if ((ref->path[ix] == '/') && (ix > 0))
+ if ((rptr[ix] == '/') && (ix > 0))
ix--;
- else if ((ref->path[ix] == 0) && (ix > 1) && (ref->path[ix - 1] == '/'))
+ else if ((rptr[ix] == 0) && (ix > 1) && (rptr[ix - 1] == '/'))
ix -= 2;
for (; ix > 0; ix--) {
- if (ref->path[ix] == '/')
+ if (rptr[ix] == '/')
break;
}
if (ix == 0) {
- uptr = (xmlChar *)ref->path;
+ uptr = (xmlChar *)rptr;
} else {
ix++;
- uptr = (xmlChar *)&ref->path[ix];
+ uptr = (xmlChar *)&rptr[ix];
}
/*
* In base, count the number of '/' from the differing point
*/
- if (bptr[pos] != ref->path[pos]) {/* check for trivial URI == base */
+ if (bptr[pos] != rptr[pos]) {/* check for trivial URI == base */
for (; bptr[ix] != 0; ix++) {
if (bptr[ix] == '/')
nbslash++;
xmlFreeURI(uri);
return escURI;
}
+ xmlFree(escURI);
}
}