Skip to content

pgmspace library string functions causing core panic #706

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

Closed
stickbreaker opened this issue Oct 8, 2017 · 2 comments
Closed

pgmspace library string functions causing core panic #706

stickbreaker opened this issue Oct 8, 2017 · 2 comments

Comments

@stickbreaker
Copy link
Contributor

Hardware:

Board: WeMos WiFi&Bluetooth Battery
Core Installation/update date: 05/OCT/2017
IDE name: Arduino IDE 1.8.5
Flash Frequency: 80Mhz
Upload Speed: 921600

Description:

pgmspace.h is wrong.

strncpy(dest,source,0x7fffffff) is not equivalent to strcpy(dest,source).

strncpy(dest,source,0x7fffffff) correctly copies source to destination, but it then NULL fills then next 2 billion bytes. (kinda hard on app, to have it's data NULL'd!).

Sketch:

#include <pgmspace.h>

#define eol "<br>\r\n"
const char ENVPRINT[] PROGMEM={
	"Environment Variables:"eol
	"********************"eol
	"<!--#printenv -->"
	"********************"eol};
	
void setup(){
Serial.begin(115200);
Serial.println("hello");

char buffer[500];
Serial.print(" should work, Arduino AVR coded -> ");
Serial.println(FPSTR(ENVPRINT)); // how Arduino AVR expects
Serial.print("\n should work because ESP32 is not Harvard ->");
Serial.println(ENVPRINT); // how ESP32 can work

strcpy(buffer,ENVPRINT);
Serial.print(" Program Mem copied into buffer, buffer=");
Serial.println(buffer);

Serial.println(" the pgmspace.h defines strcpy_P(dest,src) as strncpy(dest,src,0x7FFFFFFF).\n Which copies the src string to the destination, then continues to overwrite the next 2 billion bytes of memory with NULL");
Serial.println(" This of course causes 'bad things' to happen");

strcpy_P(buffer,ENVPRINT);

Serial.println(buffer);
Serial.print(" Never Arrives!!!");
}

void loop(){}

Debug Messages:

************ captured Output
hello
 should work, Arduino AVR coded -> Environment Variables:<br>
********************<br>
<!--#printenv -->********************<br>


 should work because ESP32 is not Harvard ->Environment Variables:<br>
********************<br>
<!--#printenv -->********************<br>

 Program Mem copied into buffer, buffer=Environment Variables:<br>
********************<br>
<!--#printenv -->********************<br>

 the pgmspace.h defines strcpy_P(dest,src) as strncpy(dest,src,0x7FFFFFFF).
 Which copies the src string to the destination, then continues to overwrite the next 2 billion bytes of memory with NULL
 This of course causes 'bad things' to happen
ets Jun  8 2016 00:22:57

rst:0x7 (TG0WDT_SYS_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,
************ captured Output
@stickbreaker
Copy link
Contributor Author

stickbreaker commented Oct 9, 2017

I created a Fork and modified pgmspace.h, and create a Pull request 'I think?'
#707

Chuck.

@me-no-dev
Copy link
Member

Merged :)

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