mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-03 06:51:36 +08:00
Mixer: add string wconditioning check.
This introduces a correctly designed pre-check for the input parsers. This fixes the mixer unit test and should fix all issues occuring on real hardware. ;
This commit is contained in:
committed by
Daniel Agar
parent
0810bcfe8e
commit
ff18140cf4
@@ -55,6 +55,9 @@
|
|||||||
|
|
||||||
#include "mixer.h"
|
#include "mixer.h"
|
||||||
|
|
||||||
|
#define debug(fmt, args...) do { } while(0)
|
||||||
|
//#define debug(fmt, args...) do { printf("[mixer] " fmt "\n", ##args); } while(0)
|
||||||
|
|
||||||
Mixer::Mixer(ControlCallback control_cb, uintptr_t cb_handle) :
|
Mixer::Mixer(ControlCallback control_cb, uintptr_t cb_handle) :
|
||||||
_next(nullptr),
|
_next(nullptr),
|
||||||
_control_cb(control_cb),
|
_control_cb(control_cb),
|
||||||
@@ -151,6 +154,28 @@ Mixer::skipline(const char *buf, unsigned &buflen)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
Mixer::string_well_formed(const char *buf, unsigned &buflen)
|
||||||
|
{
|
||||||
|
/* enforce that the mixer ends with a new line */
|
||||||
|
for (int i = buflen - 1; i >= 0; i--) {
|
||||||
|
if (buf[i] == '\0') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* require a space or newline at the end of the buffer, fail on printable chars */
|
||||||
|
if (buf[i] == '\n' || buf[i] == '\r') {
|
||||||
|
/* found a line ending, so no split symbols / numbers. good. */
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
debug("pre-parser rejected: No newline in buf");
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
|
|
||||||
NullMixer::NullMixer() :
|
NullMixer::NullMixer() :
|
||||||
@@ -186,21 +211,9 @@ NullMixer::from_text(const char *buf, unsigned &buflen)
|
|||||||
{
|
{
|
||||||
NullMixer *nm = nullptr;
|
NullMixer *nm = nullptr;
|
||||||
|
|
||||||
/* enforce that the mixer ends with space or a new line */
|
/* enforce that the mixer ends with a new line */
|
||||||
for (int i = buflen - 1; i >= 0; i--) {
|
if (!string_well_formed(buf, buflen)) {
|
||||||
if (buf[i] == '\0') {
|
return nullptr;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* require a space or newline at the end of the buffer, fail on printable chars */
|
|
||||||
if (buf[i] == ' ' || buf[i] == '\n' || buf[i] == '\r') {
|
|
||||||
/* found a line ending or space, so no split symbols / numbers. good. */
|
|
||||||
break;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return nm;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((buflen >= 2) && (buf[0] == 'Z') && (buf[1] == ':')) {
|
if ((buflen >= 2) && (buf[0] == 'Z') && (buf[1] == ':')) {
|
||||||
|
|||||||
@@ -262,6 +262,11 @@ protected:
|
|||||||
*/
|
*/
|
||||||
static const char *skipline(const char *buf, unsigned &buflen);
|
static const char *skipline(const char *buf, unsigned &buflen);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check wether the string is well formed and suitable for parsing
|
||||||
|
*/
|
||||||
|
static bool string_well_formed(const char *buf, unsigned &buflen);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/* do not allow to copy due to pointer data members */
|
/* do not allow to copy due to pointer data members */
|
||||||
|
|||||||
Reference in New Issue
Block a user