mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-10-29 17:54:14 +08:00
cmd: keep quotes and control bytes out of names when they are set
The console, POST /cmd and the saved config all go through the command parser, so one filter there covers every way a name can be set. The hostname already did this inline; port and VLAN names now do it too. The SFP strings still need escaping on the way out: they come from the module's EEPROM, not from a command.
This commit is contained in:
1 parent
8626b4c1d4
commit
56ee56af2e
1 file changed
+11
-5
+11
-5
@@ -440,6 +440,14 @@ static void cmd_error(__code const char *msg)
|
|||||||
// re-registers the static L2 management entry so the change applies without a
|
// re-registers the static L2 management entry so the change applies without a
|
||||||
// reboot. As a regular command a "mac ..." line in the startup config applies
|
// reboot. As a regular command a "mac ..." line in the startup config applies
|
||||||
// on every boot (execute_config runs before the final static L2 entry).
|
// on every boot (execute_config runs before the final static L2 entry).
|
||||||
|
static uint8_t name_char(uint8_t c)
|
||||||
|
{
|
||||||
|
if (c < 0x20 || c > 0x7e || c == '"' || c == '\\')
|
||||||
|
return '.';
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void parse_mac_cmd(void)
|
void parse_mac_cmd(void)
|
||||||
{
|
{
|
||||||
if (cmd_words_len == 1) {
|
if (cmd_words_len == 1) {
|
||||||
@@ -627,7 +635,7 @@ void parse_vlan(void)
|
|||||||
*vlan_str++ = hex[(vlan_settings.vlan >> 4) & 0xf] ;
|
*vlan_str++ = hex[(vlan_settings.vlan >> 4) & 0xf] ;
|
||||||
*vlan_str++ = hex[vlan_settings.vlan & 0xf];
|
*vlan_str++ = hex[vlan_settings.vlan & 0xf];
|
||||||
while(!cmd_is_space_or_nul(pos)) {
|
while(!cmd_is_space_or_nul(pos)) {
|
||||||
uint8_t c = cmd_buffer[pos++];
|
uint8_t c = name_char(cmd_buffer[pos++]);
|
||||||
write_char(c);
|
write_char(c);
|
||||||
*vlan_str++ = c;
|
*vlan_str++ = c;
|
||||||
}
|
}
|
||||||
@@ -889,7 +897,7 @@ void parse_port(void)
|
|||||||
} else if (cmd_compare(2, "name")) {
|
} else if (cmd_compare(2, "name")) {
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
while ( (i < PORT_NAME_SIZE-1) && (cmd_buffer[cmd_words_b[3] + i] != NUL) ) {
|
while ( (i < PORT_NAME_SIZE-1) && (cmd_buffer[cmd_words_b[3] + i] != NUL) ) {
|
||||||
port_names[phy_settings.port][i] = cmd_buffer[cmd_words_b[3] + i];
|
port_names[phy_settings.port][i] = name_char(cmd_buffer[cmd_words_b[3] + i]);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
port_names[phy_settings.port][i] = NUL;
|
port_names[phy_settings.port][i] = NUL;
|
||||||
@@ -1831,9 +1839,7 @@ void cmd_parser(void) __banked
|
|||||||
uint8_t c = *hp++;
|
uint8_t c = *hp++;
|
||||||
if (c == NUL || c == '\r' || c == '\n')
|
if (c == NUL || c == '\r' || c == '\n')
|
||||||
break;
|
break;
|
||||||
if (c < 0x20 || c > 0x7e || c == '"' || c == '\\')
|
*dst++ = name_char(c);
|
||||||
c = '.';
|
|
||||||
*dst++ = c;
|
|
||||||
}
|
}
|
||||||
*dst = NUL;
|
*dst = NUL;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in new issue
Block a user