Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebServer serveStatic () can cause LoadProhibited exception in _svfprintf_r #5506

Closed
timr49 opened this issue Aug 7, 2021 · 1 comment
Closed

Comments

@timr49
Copy link
Contributor

timr49 commented Aug 7, 2021

Hardware:

Board: Sparkfun ESP32Thing
Core Installation version: 2.0.0-rc1
IDE name: Arduino IDE 1.8.5
Flash Frequency: 80Mhz
PSRAM enabled: ?PSRAM?
Upload Speed: 921600
Computer OS: Mac OSX 11.5.1

Description:

Using a Core Debug Level of Verbose and the WebServer serveStatic() function with the default value of nullptr for its cache_header argument, results in a LoadProhibited exception in _svfprintf_r().
This is because serveStatic() calls log_v() with cache_header corresponding to a "%s" in its format but without checking that cache_header is not nullptr, and then logv() (indirectly) calls _svfprintf_r().
On the other hand, with a Core Debug Level other than Verbose, this does not occur.

Sketch: (leave the backquotes for code formatting)

//Change the code below by your sketch
[code]
#include <WiFi.h>
#include <WebServer.h>
#include <SPIFFS.h>
#include "secret.h" // for definitions of MySSID and MyPASSWORD

WebServer server;

void setup() {
  // put your setup code here, to run once:
  // serial
  Serial.begin(115200);
  while (!Serial)
    delay(100);
  Serial.println("setting up");

  // wifi
  WiFi.begin(MySSID, MyPASSWORD); // as defined in "secret.h"
  while (!WiFi.isConnected())
  {
    Serial.print('.');
    delay(100);
  }
  Serial.println();
  Serial.print("connected to "); Serial.print(WiFi.SSID());
  Serial.print(" with address "); Serial.println(WiFi.localIP());

  // www server
  server.begin();
  SPIFFS.begin();
  server.serveStatic("/index.htm", SPIFFS, "/index.htm");

  Serial.println("listening");
}

void loop() {
  // put your main code here, to run repeatedly:
  server.handleClient();
}
[/code]```

### Debug Messages:

ets Jun 8 2016 00:22:57

rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1100
ho 0 tail 12 room 4
load:0x40078000,len:12752
load:0x40080400,len:3092
entry 0x400805e4
[����$$HLW+QW⸮Y.&⸮KZX⸮K,]⸮,'⸮LLW⸮⸮Y](]⸮⸮equencyMhz(): PLL: 480 / 2 = 240 Mhz, APB: 80000000 Hz
⸮⸮Y]⸮Z⸮�⸮�⸮H⸮[ 63][D][WiFiGeneric.cpp:808] _eventCallback(): Arduino Event: 0 - WIFI_READY
[ 160][V][WiFiGeneric.cpp:96] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
[ 159][V][WiFiGeneric.cpp:272] _arduino_event_cb(): STA Started
[ 166][D][WiFiGeneric.cpp:808] _eventCallback(): Arduino Event: 2 - STA_START
.....................[ 2266][V][WiFiGeneric.cpp:284] _arduino_event_cb(): STA Connected: SSID: MOBILE3, BSSID: 00:1e:42:19:71:d9, Channel: 11, Auth: WPA2_PSK
[ 2267][D][WiFiGeneric.cpp:808] _eventCallback(): Arduino Event: 4 - STA_CONNECTED
.[ 2338][V][WiFiGeneric.cpp:294] _arduino_event_cb(): STA Got New IP:192.168.10.157
[ 2338][D][WiFiGeneric.cpp:808] _eventCallback(): Arduino Event: 7 - STA_GOT_IP
[ 2342][D][WiFiGeneric.cpp:857] _eventCallback(): STA IP: 192.168.10.157, MASK: 255.255.255.0, GW: 192.168.10.3

connected to MOBILE3 with address 192.168.10.157
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.

Core 1 register dump:
PC : 0x40089275 PS : 0x00060630 A0 : 0x8014f16c A1 : 0x3ffb2340
A2 : 0x00000000 A3 : 0xfffffffc A4 : 0x000000ff A5 : 0x0000ff00
A6 : 0x00ff0000 A7 : 0xff000000 A8 : 0x00000000 A9 : 0x00000000
A10 : 0x00000000 A11 : 0x3ffb2543 A12 : 0x00000000 A13 : 0x3ffdd3f0
A14 : 0x3ffc2204 A15 : 0x00000011 SAR : 0x00000004 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000000 LBEG : 0x40089275 LEND : 0x40089285 LCOUNT : 0xffffffff

Backtrace:0x40089272:0x3ffb23400x4014f169:0x3ffb2350 0x4015634e:0x3ffb2660 0x4015638a:0x3ffb26f0 0x400dcdc9:0x3ffb2730 0x400dab16:0x3ffb2790 0x400d287e:0x3ffb27d0 0x400de5ab:0x3ffb2820

ELF file SHA256: 0000000000000000

Rebooting...
ets Jun 8 2016 00:22:57

EspExceptionDecoder ...

PC: 0x40089275
EXCVADDR: 0x00000000

Decoding stack results
0x4014f169: _svfprintf_r at /builds/idf/crosstool-NG/.build/HOST-x86_64-apple-darwin12/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/vfprintf.c line 1528
0x4015634e: _vsnprintf_r at /builds/idf/crosstool-NG/.build/HOST-x86_64-apple-darwin12/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/vsnprintf.c line 70
0x4015638a: vsnprintf at /builds/idf/crosstool-NG/.build/HOST-x86_64-apple-darwin12/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/vsnprintf.c line 40
0x400dcdc9: log_printf at /Users/tim/Library/Arduino15/packages/esp32/hardware/esp32/2.0.0-rc1/cores/esp32/esp32-hal-uart.c line 633
0x400dab16: WebServer::serveStatic(char const*, fs::FS&, char const*, char const*) at /Users/tim/Library/Arduino15/packages/esp32/hardware/esp32/2.0.0-rc1/libraries/WebServer/src/detail/RequestHandlersImpl.h line 72
0x400d287e: setup() at /Users/tim/Repositories/sam/src/Arduino/IssueLOGV/IssueLOGV.ino line 30
0x400de5ab: loopTask(void*) at /Users/tim/Library/Arduino15/packages/esp32/hardware/esp32/2.0.0-rc1/cores/esp32/main.cpp line 35

timr49 added a commit to timr49/arduino-esp32 that referenced this issue Aug 8, 2021
…ibited exception in _svfprintf_r"

"Using a Core Debug Level of Verbose and the WebServer serveStatic() function with the default value of nullptr for its cache_header argument, results in a LoadProhibited exception in _svfprintf_r().
This is because serveStatic() calls log_v() with cache_header corresponding to a "%s" in its format but without checking that cache_header is not nullptr, and then logv() (indirectly) calls _svfprintf_r().
On the other hand, with a Core Debug Level other than Verbose, this does not occur."

Changed serveStatic() to the check value of cache_header and if it is nullptr, instead pass an empty string to log_v().
me-no-dev pushed a commit that referenced this issue Aug 11, 2021
…ception in _svfprintf_r" (#5508)

"Using a Core Debug Level of Verbose and the WebServer serveStatic() function with the default value of nullptr for its cache_header argument, results in a LoadProhibited exception in _svfprintf_r().
This is because serveStatic() calls log_v() with cache_header corresponding to a "%s" in its format but without checking that cache_header is not nullptr, and then logv() (indirectly) calls _svfprintf_r().
On the other hand, with a Core Debug Level other than Verbose, this does not occur."

Changed serveStatic() to the check value of cache_header and if it is nullptr, instead pass an empty string to log_v().
@VojtechBartoska
Copy link
Contributor

For some reason issue wasn't closed with given PR. I'm closing manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants