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

Compiler warning about buffer overflow in firmwareVersion() #303

Open
waldhol opened this issue Jan 2, 2021 · 1 comment
Open

Compiler warning about buffer overflow in firmwareVersion() #303

waldhol opened this issue Jan 2, 2021 · 1 comment
Labels
type: imperfection Perceived defect in any part of project

Comments

@waldhol
Copy link

waldhol commented Jan 2, 2021

I regularly compile my sketches with all compiler warnings enabled.
I got the following warning about a possible buffer overflow in WiFiClass::firmwareVersion():

/Users/***/Documents/Arduino/libraries/WiFi101/src/WiFi.cpp: In member function 'char* WiFiClass::firmwareVersion()':
/Users/***/Documents/Arduino/libraries/WiFi101/src/WiFi.cpp:356:10: note: 'sprintf' output between 6 and 12 bytes into a destination of size 9
  356 |   sprintf(_version, "%d.%d.%d", rev.u8FirmwareMajor, rev.u8FirmwareMinor, rev.u8FirmwarePatch);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The warning is legitimate.
This can be easily fixed by changing char _version[9]; to char _version[12]; in WiFi101.h

@per1234 per1234 added the type: imperfection Perceived defect in any part of project label Jan 2, 2021
@rickoman
Copy link

Consider using 'snprintf' to prevent any overflows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

3 participants