mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-08-30 14:52:51 +08:00
httpd: send_counter(): Validate phys_port_idx and better error handling
This commit is contained in:
+1
-8
@@ -758,16 +758,9 @@ void httpd_appcall(void)
|
|||||||
parse_short(q + 15);
|
parse_short(q + 15);
|
||||||
send_vlan(short_parsed);
|
send_vlan(short_parsed);
|
||||||
} else if (is_word(q, "/counters.json")) {
|
} else if (is_word(q, "/counters.json")) {
|
||||||
/* The port is one raw character of the request line and
|
|
||||||
* indexes a nine entry table, so bound it here instead
|
|
||||||
* of trusting the client to have sent a digit. Anything
|
|
||||||
* below '0' wraps well past eight, so the one test
|
|
||||||
* covers both ends. */
|
|
||||||
uint8_t cport = q[20] - '0';
|
uint8_t cport = q[20] - '0';
|
||||||
if (cport > 8)
|
if (send_counters(cport))
|
||||||
send_bad_request();
|
send_bad_request();
|
||||||
else
|
|
||||||
send_counters(cport);
|
|
||||||
} else if (is_word(q, "/eee.json")) {
|
} else if (is_word(q, "/eee.json")) {
|
||||||
send_eee();
|
send_eee();
|
||||||
} else if (is_word(q, "/bandwidth.json")) {
|
} else if (is_word(q, "/bandwidth.json")) {
|
||||||
|
|||||||
+22
-8
@@ -289,17 +289,25 @@ void send_vlan(uint16_t vlan)
|
|||||||
slen += strtox(outbuf + slen, "\"}");
|
slen += strtox(outbuf + slen, "\"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Send counters
|
||||||
void send_counters(char port)
|
* Only accepts physical port idx to 0-8.
|
||||||
|
* Returns an error if the port physical don't exists.
|
||||||
|
*/
|
||||||
|
bool send_counters(uint8_t phys_port_idx)
|
||||||
{
|
{
|
||||||
dbg_string("send_counters called: "); dbg_byte(port); dbg_char('\n');
|
if (phys_port_idx > 8)
|
||||||
|
goto err;
|
||||||
|
uint8_t log_port = machine.phys_to_log_port[phys_port_idx];
|
||||||
|
if (log_port == 0)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
dbg_string("send_counters called: "); dbg_byte(phys_port_idx); dbg_char('\n');
|
||||||
slen = strtox(outbuf, HTTP_RESPONCE_JSON);
|
slen = strtox(outbuf, HTTP_RESPONCE_JSON);
|
||||||
dbg_string("sending counters\n");
|
dbg_string("sending counters\n"); dbg_byte(phys_port_idx);
|
||||||
dbg_byte(port);
|
|
||||||
uint8_t i = machine.phys_to_log_port[port];
|
char_to_html('[');
|
||||||
slen += strtox(outbuf + slen, "[");
|
|
||||||
for (uint8_t counter = 0; counter < 0x37; counter++) {
|
for (uint8_t counter = 0; counter < 0x37; counter++) {
|
||||||
STAT_GET(counter, i);
|
STAT_GET(counter, log_port);
|
||||||
slen += strtox(outbuf + slen, "\"0x");
|
slen += strtox(outbuf + slen, "\"0x");
|
||||||
reg_to_html(RTL837X_STAT_V_HIGH);
|
reg_to_html(RTL837X_STAT_V_HIGH);
|
||||||
reg_to_html_long(RTL837X_STAT_V_LOW);
|
reg_to_html_long(RTL837X_STAT_V_LOW);
|
||||||
@@ -308,6 +316,12 @@ void send_counters(char port)
|
|||||||
char_to_html(',');
|
char_to_html(',');
|
||||||
}
|
}
|
||||||
char_to_html(']');
|
char_to_html(']');
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
err:
|
||||||
|
dbg_string("Error: counters: phy_port_idx don't exists\n");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -1,7 +1,9 @@
|
|||||||
#ifndef __PAGE_IMPL_H__
|
#ifndef __PAGE_IMPL_H__
|
||||||
#define __PAGE_IMPL_H__
|
#define __PAGE_IMPL_H__
|
||||||
|
|
||||||
void send_counters(char port);
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
bool send_counters(uint8_t phys_port_idx);
|
||||||
void send_status(void);
|
void send_status(void);
|
||||||
void send_vlan(uint16_t vlan);
|
void send_vlan(uint16_t vlan);
|
||||||
void send_basic_info(void);
|
void send_basic_info(void);
|
||||||
|
|||||||
Reference in New Issue
Block a user