AP_HAL_Linux: Prevent buffer overflow

This commit is contained in:
mirkix 2016-01-18 21:01:47 +01:00 committed by Lucas De Marchi
parent 5d28fbfa1b
commit 86e335b6b6
1 changed files with 2 additions and 2 deletions

View File

@ -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)
// 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) {