}
/*
+ * Parse a single hexadecimal byte, which must be complete (two
+ * digits). This is used in URL parsing.
+ */
+static int hexbyte(const char *p)
+{
+ if (!is_hex(p[0]) || !is_hex(p[1]))
+ return -1;
+ else
+ return (hexval(p[0]) << 4) + hexval(p[1]);
+}
+
+/*
* Tests an IP address in _ip_ for validity; return with 0 for bad, 1 for good.
* We used to refuse class E, but class E addresses are likely to become
* assignable unicast addresses in the near future.
{
const char *p;
- if (strncasecmp(str, "tftp://", 7))
- return PXE_URL_TFTP;
-
p = str;
while (1) {
return PXE_HOMESERVER;
else
return PXE_TFTP;
- } else if (p > str && p[1] == '/' && p[2] == '/')
- return PXE_URL;
+ } else if (p > str && p[1] == '/' && p[2] == '/') {
+ if (strncasecmp(str, "tftp://", 7))
+ return PXE_URL_TFTP;
+ else
+ return PXE_URL;
+ }
/* else fall through */
case '/': case '!': case '@': case '#': case '%':
* 3617); it is to be followed by TFTP modes, which we just ignore.
*/
while (*np && *np != ';') {
- if (*np == '%') {
- if (is_hex(np[1]) && is_hex(np[2]))
- *buf++ = (hexval(np[1]) << 4) + hexval(np[2]);
+ int v;
+ if (*np == '%' && (v = hexbyte(np+1)) > 0) {
+ *buf++ = v;
np += 3;
} else {
*buf++ = *np++;