Browse Source

AP_HAL_Linux: Prevent buffer overflow

master
mirkix 9 years ago committed by Lucas De Marchi
parent
commit
86e335b6b6
  1. 4
      libraries/AP_HAL_Linux/AnalogIn_IIO.cpp

4
libraries/AP_HAL_Linux/AnalogIn_IIO.cpp

@ -38,7 +38,7 @@ void AnalogSource_IIO::init_pins(void) @@ -38,7 +38,7 @@ void AnalogSource_IIO::init_pins(void)
for (int i=0; i < IIO_ANALOG_IN_COUNT; i++) {
// Construct the path by appending strings
strncpy(buf, IIO_ANALOG_IN_DIR, sizeof(buf));
strncat(buf, AnalogSource_IIO::analog_sources[i], sizeof(buf));
strncat(buf, AnalogSource_IIO::analog_sources[i], sizeof(buf) - strlen(buf) -1);
fd_analog_sources[i] = open(buf, O_RDONLY | O_NONBLOCK);
if (fd_analog_sources[i] == -1) {
@ -79,7 +79,7 @@ void AnalogSource_IIO::reopen_pin(void) @@ -79,7 +79,7 @@ void AnalogSource_IIO::reopen_pin(void)
// Construct the path by appending strings
strncpy(buf, IIO_ANALOG_IN_DIR, sizeof(buf));
strncat(buf, AnalogSource_IIO::analog_sources[_pin], sizeof(buf));
strncat(buf, AnalogSource_IIO::analog_sources[_pin], sizeof(buf) - strlen(buf) - 1);
fd_analog_sources[_pin] = open(buf, O_RDONLY | O_NONBLOCK);
if (fd_analog_sources[_pin] == -1) {

Loading…
Cancel
Save