From e2c4ed6be3b35cfb0235efd58cf3a20172d8c42e Mon Sep 17 00:00:00 2001 From: d00f <8052722+DrDoof@users.noreply.github.com> Date: Thu, 17 Sep 2026 21:10:22 +0200 Subject: [PATCH] sfp: clean the module strings where they are read The vendor, model and serial strings are filtered while the EEPROM read fills the buffers, so the page copies them out as they are. NUL still ends a string, so a field shorter than its slot reads the same as before. The three loops in send_status() become one call each. strcpy() cannot return the length: rtl837x_common.h hides that prototype under RTLP_HOST_TEST so host builds take the C library version, and a call that adds its result to slen does not compile there. A small static helper does the copy instead, and bank 1 drops by 96 bytes. --- httpd/page_impl.c | 16 ++++++++++------ sfp.c | 7 ++++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/httpd/page_impl.c b/httpd/page_impl.c index 1ed36c51..58624145 100644 --- a/httpd/page_impl.c +++ b/httpd/page_impl.c @@ -70,6 +70,13 @@ void char_to_html(char c) } +static void str_x_to_html(__xdata const char *s) +{ + while (*s) + outbuf[slen++] = *s++; +} + + void json_char_to_html(uint8_t c) { if (c < 0x20 || c > 0x7e || c == '"' || c == '\\') @@ -872,14 +879,11 @@ void send_status(void) sfp_send_data(sfp, 238, 1); } slen += strtox(outbuf + slen,"\",\"sfp_vendor\":\""); - for (uint8_t s = 0; s < 16 && sfp_module_vendor[sfp][s]; s++) - json_char_to_html(sfp_module_vendor[sfp][s]); + str_x_to_html(sfp_module_vendor[sfp]); slen += strtox(outbuf + slen,"\",\"sfp_model\":\""); - for (uint8_t s = 0; s < 16 && sfp_module_model[sfp][s]; s++) - json_char_to_html(sfp_module_model[sfp][s]); + str_x_to_html(sfp_module_model[sfp]); slen += strtox(outbuf + slen,"\",\"sfp_serial\":\""); - for (uint8_t s = 0; s < 16 && sfp_module_serial[sfp][s]; s++) - json_char_to_html(sfp_module_serial[sfp][s]); + str_x_to_html(sfp_module_serial[sfp]); slen += strtox(outbuf + slen,"\",\"sfp_los\":"); if (machine.sfp_port[sfp].pin_los == GPIO_NA) { slen += strtox(outbuf + slen,"null"); diff --git a/sfp.c b/sfp.c index 7bc4f301..1f1f6652 100644 --- a/sfp.c +++ b/sfp.c @@ -88,7 +88,12 @@ bool sfp_read_field(__xdata char *dst, uint8_t sfp, uint8_t start, uint8_t lengt return false; dst[length] = NUL; - memcpy(dst, sfp_buf, length); + for (uint8_t i = 0; i < length; i++) { + uint8_t c = sfp_buf[i]; + if (c && (c < 0x20 || c > 0x7e || c == '"' || c == '\\')) + c = '.'; + dst[i] = c; + } while (length > 0 && dst[--length] == ' ') dst[length] = NUL;