net: lwm2m: return 4.04 when URI is not composed by digits
Modify zoap_options_to_path() to return error when URI contains character other than digits and return 4.04 NOT FOUND to caller. PATH such as "/1a/2/3" was treated as "/1/2/3" after parsring which is incorrect. Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
This commit is contained in:
parent
d5ab14697f
commit
cfa9990c41
1 changed files with 12 additions and 6 deletions
|
@ -687,37 +687,39 @@ static u16_t atou16(u8_t *buf, u16_t buflen, u16_t *len)
|
|||
return val;
|
||||
}
|
||||
|
||||
static void zoap_options_to_path(struct zoap_option *opt, int options_count,
|
||||
static int zoap_options_to_path(struct zoap_option *opt, int options_count,
|
||||
struct lwm2m_obj_path *path)
|
||||
{
|
||||
u16_t len;
|
||||
|
||||
path->level = options_count;
|
||||
path->obj_id = atou16(opt[0].value, opt[0].len, &len);
|
||||
if (len == 0) {
|
||||
if (len == 0 || opt[0].len != len) {
|
||||
path->level = 0;
|
||||
}
|
||||
|
||||
if (path->level > 1) {
|
||||
path->obj_inst_id = atou16(opt[1].value, opt[1].len, &len);
|
||||
if (len == 0) {
|
||||
if (len == 0 || opt[1].len != len) {
|
||||
path->level = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (path->level > 2) {
|
||||
path->res_id = atou16(opt[2].value, opt[2].len, &len);
|
||||
if (len == 0) {
|
||||
if (len == 0 || opt[2].len != len) {
|
||||
path->level = 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (path->level > 3) {
|
||||
path->res_inst_id = atou16(opt[3].value, opt[3].len, &len);
|
||||
if (len == 0) {
|
||||
if (len == 0 || opt[3].len != len) {
|
||||
path->level = 3;
|
||||
}
|
||||
}
|
||||
|
||||
return options_count == path->level ? 0 : -EINVAL;
|
||||
}
|
||||
|
||||
static struct lwm2m_message *find_msg(struct zoap_pending *pending,
|
||||
|
@ -2306,7 +2308,11 @@ static int handle_request(struct zoap_packet *request,
|
|||
strncmp(options[1].value, "core", 4) == 0)) {
|
||||
discover = true;
|
||||
} else {
|
||||
zoap_options_to_path(options, r, &path);
|
||||
r = zoap_options_to_path(options, r, &path);
|
||||
if (r < 0) {
|
||||
r = -ENOENT;
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
/* read Content Format */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue