From c13bcd2d9e76cb79cf1a727de4343fa4a9b0b90e Mon Sep 17 00:00:00 2001 From: Anders Blomdell <anders.blomdell@control.lth.se> Date: Wed, 4 Dec 2019 15:00:06 +0100 Subject: [PATCH] Add sanity check of values returned from serial2002_read --- plugins/serial2002/serial2002.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/plugins/serial2002/serial2002.c b/plugins/serial2002/serial2002.c index a890248..e94ca95 100644 --- a/plugins/serial2002/serial2002.c +++ b/plugins/serial2002/serial2002.c @@ -118,6 +118,10 @@ static struct moberg_status analog_in_read( } result = serial2002_read(device->port.fd, device->port.timeout, &data); if (OK(result)) { + if ((data.kind != is_channel) || (data.index != map.index)) { + result = MOBERG_ERRNO(ECHRNG); + goto return_result; + } *value = (data.value * map.delta + map.min); } return_result: @@ -173,6 +177,10 @@ static struct moberg_status digital_in_read( } result = serial2002_read(device->port.fd, device->port.timeout, &data); if (OK(result)) { + if ((data.kind != is_digital) || (data.index != map.index)) { + result = MOBERG_ERRNO(ECHRNG); + goto return_result; + } *value = data.value != 0; } return_result: @@ -216,6 +224,10 @@ static struct moberg_status encoder_in_read( } result = serial2002_read(device->port.fd, device->port.timeout, &data); if (OK(result)) { + if ((data.kind != is_channel) || (data.index != map.index)) { + result = MOBERG_ERRNO(ECHRNG); + goto return_result; + } *value = (data.value); } return_result: -- GitLab