mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-08-30 14:52:51 +08:00
Fix and refactor is_url_word_x().
With content_type = "application/x-www-form-urlencoded", "+" means space. This case was not handled. Also refactor the code to make a loop to process the hex digits.
This commit is contained in:
+37
-18
@@ -131,28 +131,46 @@ char is_word(__xdata uint8_t *c, __code uint8_t * __xdata d)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char is_url_word_x(__xdata uint8_t *c, __xdata uint8_t *d)
|
bool is_url_word_x(__xdata uint8_t *uri_str_p, __xdata uint8_t *src_str_p)
|
||||||
{
|
{
|
||||||
uint8_t i = 0, j = 0;
|
uint8_t u, s;
|
||||||
|
|
||||||
while (d[i]) {
|
while(1) {
|
||||||
if (c[j] == '%') {
|
u = *uri_str_p++;
|
||||||
uint8_t v;
|
s = *src_str_p++;
|
||||||
j++;
|
|
||||||
v = c[j] - '0' < 10 ? (c[j] - '0') << 4 : (c[j] - 'A' + 10) << 4;
|
if (s == '\0') {
|
||||||
j++;
|
if (u != '\0' && u != ' ' && u != '\t' && u != ':' && u != '?' && u != '=' && u != '\n' && u != '\r')
|
||||||
v += c[j] - '0' < 10 ? c[j] - '0' : c[j] - 'A' + 10;
|
return false;
|
||||||
if (d[i] != v)
|
return true;
|
||||||
return 0;
|
|
||||||
} else if (d[i] != c[j])
|
|
||||||
return 0;
|
|
||||||
i++;
|
|
||||||
j++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c[j] != ' ' && c[j] != '\t' && c[j] != ':' && c[j] != '?' && c[j] != '=' && c[j] != '\n' && c[j] != '\r' && c[j])
|
if (u == '%') {
|
||||||
return 0;
|
bool again = true;
|
||||||
return 1;
|
u = 0;
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
// Swap instruction is fine for rotation
|
||||||
|
u = (u << 4) | (u >> 4);
|
||||||
|
|
||||||
|
uint8_t p = *uri_str_p++;
|
||||||
|
u |= p - '0' < 10 ? (p - '0') : (p - 'A' + 10);
|
||||||
|
|
||||||
|
// force `jbc`-instruction.
|
||||||
|
if (again) {
|
||||||
|
again = false;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (u == '+') {
|
||||||
|
u = ' ';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s != u) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -461,6 +479,7 @@ void handle_post(void)
|
|||||||
outbuf[slen++] = session_id[i];
|
outbuf[slen++] = session_id[i];
|
||||||
slen += strtox(outbuf + slen, "; SameSite=Strict\r\n\r\n");
|
slen += strtox(outbuf + slen, "; SameSite=Strict\r\n\r\n");
|
||||||
} else {
|
} else {
|
||||||
|
dbg_string("Password invalid!\n");
|
||||||
slen = strtox(outbuf, "HTTP/1.1 302 Found\r\nLocation: login.html\r\n\r\n");
|
slen = strtox(outbuf, "HTTP/1.1 302 Found\r\nLocation: login.html\r\n\r\n");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user