aboutsummaryrefslogtreecommitdiff
path: root/src/modules/systemlib/mixer
diff options
context:
space:
mode:
authorLorenz Meier <lm@inf.ethz.ch>2013-09-22 11:16:19 +0200
committerLorenz Meier <lm@inf.ethz.ch>2013-09-22 11:16:19 +0200
commitf62aeba4207beaeeff63af970ec5d6bb2fb1e8a7 (patch)
tree5ab79591d24d1d2e1565a0c989a5b99217e908ed /src/modules/systemlib/mixer
parent669d4c6dd26cec44196f755b223da588439816c6 (diff)
downloadpx4-firmware-f62aeba4207beaeeff63af970ec5d6bb2fb1e8a7.tar.gz
px4-firmware-f62aeba4207beaeeff63af970ec5d6bb2fb1e8a7.tar.bz2
px4-firmware-f62aeba4207beaeeff63af970ec5d6bb2fb1e8a7.zip
Cover last potential corner case with mixers, should be totally safe now
Diffstat (limited to 'src/modules/systemlib/mixer')
-rw-r--r--src/modules/systemlib/mixer/mixer.cpp6
-rw-r--r--src/modules/systemlib/mixer/mixer_multirotor.cpp7
-rw-r--r--src/modules/systemlib/mixer/mixer_simple.cpp23
3 files changed, 32 insertions, 4 deletions
diff --git a/src/modules/systemlib/mixer/mixer.cpp b/src/modules/systemlib/mixer/mixer.cpp
index df0dfe838..7d9ddba8f 100644
--- a/src/modules/systemlib/mixer/mixer.cpp
+++ b/src/modules/systemlib/mixer/mixer.cpp
@@ -142,6 +142,12 @@ NullMixer *
NullMixer::from_text(const char *buf, unsigned &buflen)
{
NullMixer *nm = nullptr;
+ const char *end = buf + buflen;
+
+ /* require a space or newline at the end of the buffer */
+ if (*end != ' ' && *end != '\n' && *end != '\r') {
+ return nm;
+ }
if ((buflen >= 2) && (buf[0] == 'Z') && (buf[1] == ':')) {
nm = new NullMixer;
diff --git a/src/modules/systemlib/mixer/mixer_multirotor.cpp b/src/modules/systemlib/mixer/mixer_multirotor.cpp
index 8ded0b05c..576af5e30 100644
--- a/src/modules/systemlib/mixer/mixer_multirotor.cpp
+++ b/src/modules/systemlib/mixer/mixer_multirotor.cpp
@@ -181,6 +181,13 @@ MultirotorMixer::from_text(Mixer::ControlCallback control_cb, uintptr_t cb_handl
char geomname[8];
int s[4];
int used;
+ const char *end = buf + buflen;
+
+ /* require a space or newline at the end of the buffer */
+ if (*end != ' ' && *end != '\n' && *end != '\r') {
+ debug("multirotor parser rejected: No newline / space at end of buf.");
+ return nullptr;
+ }
if (sscanf(buf, "R: %s %d %d %d %d%n", geomname, &s[0], &s[1], &s[2], &s[3], &used) != 5) {
debug("multirotor parse failed on '%s'", buf);
diff --git a/src/modules/systemlib/mixer/mixer_simple.cpp b/src/modules/systemlib/mixer/mixer_simple.cpp
index 07dc5f37f..44b6470f0 100644
--- a/src/modules/systemlib/mixer/mixer_simple.cpp
+++ b/src/modules/systemlib/mixer/mixer_simple.cpp
@@ -100,8 +100,10 @@ SimpleMixer::parse_output_scaler(const char *buf, unsigned &buflen, mixer_scaler
int s[5];
buf = findtag(buf, buflen, 'O');
- if ((buf == nullptr) || (buflen < 12))
+ if ((buf == nullptr) || (buflen < 12)) {
+ debug("output parser failed finding tag, ret: '%s'", buf);
return -1;
+ }
if ((ret = sscanf(buf, "O: %d %d %d %d %d",
&s[0], &s[1], &s[2], &s[3], &s[4])) != 5) {
@@ -126,8 +128,10 @@ SimpleMixer::parse_control_scaler(const char *buf, unsigned &buflen, mixer_scale
int s[5];
buf = findtag(buf, buflen, 'S');
- if ((buf == nullptr) || (buflen < 16))
+ if ((buf == nullptr) || (buflen < 16)) {
+ debug("contorl parser failed finding tag, ret: '%s'", buf);
return -1;
+ }
if (sscanf(buf, "S: %u %u %d %d %d %d %d",
&u[0], &u[1], &s[0], &s[1], &s[2], &s[3], &s[4]) != 7) {
@@ -156,6 +160,12 @@ SimpleMixer::from_text(Mixer::ControlCallback control_cb, uintptr_t cb_handle, c
int used;
const char *end = buf + buflen;
+ /* require a space or newline at the end of the buffer */
+ if (*end != ' ' && *end != '\n' && *end != '\r') {
+ debug("simple parser rejected: No newline / space at end of buf.");
+ goto out;
+ }
+
/* get the base info for the mixer */
if (sscanf(buf, "M: %u%n", &inputs, &used) != 1) {
debug("simple parse failed on '%s'", buf);
@@ -173,15 +183,20 @@ SimpleMixer::from_text(Mixer::ControlCallback control_cb, uintptr_t cb_handle, c
mixinfo->control_count = inputs;
- if (parse_output_scaler(end - buflen, buflen, mixinfo->output_scaler))
+ if (parse_output_scaler(end - buflen, buflen, mixinfo->output_scaler)) {
+ debug("simple mixer parser failed parsing out scaler tag, ret: '%s'", buf);
goto out;
+ }
for (unsigned i = 0; i < inputs; i++) {
if (parse_control_scaler(end - buflen, buflen,
mixinfo->controls[i].scaler,
mixinfo->controls[i].control_group,
- mixinfo->controls[i].control_index))
+ mixinfo->controls[i].control_index)) {
+ debug("simple mixer parser failed parsing ctrl scaler tag, ret: '%s'", buf);
goto out;
+ }
+
}
sm = new SimpleMixer(control_cb, cb_handle, mixinfo);