aboutsummaryrefslogtreecommitdiff
path: root/src/drivers/sf0x
diff options
context:
space:
mode:
authorLorenz Meier <lm@inf.ethz.ch>2014-08-31 17:59:21 +0200
committerLorenz Meier <lm@inf.ethz.ch>2014-08-31 17:59:21 +0200
commit7a253d50f8da7a6f8176f784c196b85bcae3c8f1 (patch)
tree3f75a46a69dd100bca318d1224028453ac7f314b /src/drivers/sf0x
parentc17c585c3e977688ad5ff64812fd499c0410f2da (diff)
downloadpx4-firmware-7a253d50f8da7a6f8176f784c196b85bcae3c8f1.tar.gz
px4-firmware-7a253d50f8da7a6f8176f784c196b85bcae3c8f1.tar.bz2
px4-firmware-7a253d50f8da7a6f8176f784c196b85bcae3c8f1.zip
Add more paranoid checks to sf0x altitude parsing
Diffstat (limited to 'src/drivers/sf0x')
-rw-r--r--src/drivers/sf0x/sf0x.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/drivers/sf0x/sf0x.cpp b/src/drivers/sf0x/sf0x.cpp
index 80ecab2ee..d7780e9e8 100644
--- a/src/drivers/sf0x/sf0x.cpp
+++ b/src/drivers/sf0x/sf0x.cpp
@@ -593,13 +593,19 @@ SF0X::collect()
/* wipe out partially read content from last cycle(s), check for dot */
for (unsigned i = 0; i < (lend - 2); i++) {
if (_linebuf[i] == '\n') {
+ /* allocate temporary buffer */
char buf[sizeof(_linebuf)];
+ /* copy remainder of buffer (2nd measurement) to temporary buffer */
memcpy(buf, &_linebuf[i+1], (lend + 1) - (i + 1));
+ /* copy temporary buffer to beginning of line buffer,
+ * effectively overwriting a previous temporary
+ * measurement
+ */
memcpy(_linebuf, buf, (lend + 1) - (i + 1));
}
/* we need a digit before the dot and a dot for a valid number */
- if (i > 0 && _linebuf[i] == '.') {
+ if (i > 0 && ((_linebuf[i - 1] >= '0') && (_linebuf[i - 1] <= '9')) && (_linebuf[i] == '.')) {
valid = true;
}
}