Skip to content

Fix potential buffer overflow #1365

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

Merged
merged 1 commit into from
Nov 12, 2019
Merged

Conversation

hannesweisbach
Copy link
Contributor

Use snprintf instead of sprintf to avoid a potential buffer overflow, as noted by the compiler:

hal/architecture/Linux/drivers/core/GPIO.cpp: In constructor ‘GPIOClass::GPIOClass()’:
hal/architecture/Linux/drivers/core/GPIO.cpp:53:18: warning: ‘%s’ directive writing up to 255 bytes into a region of size 48 [-Wformat-overflow=]
sprintf(file, "/sys/class/gpio/%s/base", de->d_name);
^~~~~~~~~~~~~~~~~~~~~~~~~
hal/architecture/Linux/drivers/core/GPIO.cpp:53:11: note: ‘sprintf’ output between 22 and 277 bytes into a destination of size 64
sprintf(file, "/sys/class/gpio/%s/base", de->d_name);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hal/architecture/Linux/drivers/core/GPIO.cpp:62:18: warning: ‘%s’ directive writing up to 255 bytes into a region of size 48 [-Wformat-overflow=]
sprintf(file, "/sys/class/gpio/%s/ngpio", de->d_name);
^~~~~~~~~~~~~~~~~~~~~~~~~~
hal/architecture/Linux/drivers/core/GPIO.cpp:62:11: note: ‘sprintf’ output between 23 and 278 bytes into a destination of size 64
sprintf(file, "/sys/class/gpio/%s/ngpio", de->d_name);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Use snprintf instead of sprintf to avoid a potential buffer overflow.
@tekka007
Copy link
Contributor

@hannesweisbach Thank you for submitting this PR. Would you mind signing the CLA?

@tekka007 tekka007 added the RPi label Nov 11, 2019
@tekka007 tekka007 merged commit 409902d into mysensors:development Nov 12, 2019
@mfalkvidd mfalkvidd added the release-notes Issues that have information that should be included in the release notes label Nov 13, 2019
@hannesweisbach hannesweisbach deleted the patch-1 branch November 13, 2019 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes Issues that have information that should be included in the release notes RPi
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants