Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/thingset.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ int thingset_export_subsets(struct thingset_context *ts, uint8_t *buf, size_t bu
thingset_bin_setup(ts, 0);
break;
default:
k_sem_give(&ts->lock);
return -THINGSET_ERR_NOT_IMPLEMENTED;
}

Expand Down Expand Up @@ -623,7 +624,7 @@ struct thingset_data_object *thingset_get_object_by_path(struct thingset_context

/* maximum depth of 10 assumed */
for (int i = 0; i < 10; i++) {
end = strchr(start, '/');
end = memchr(start, '/', path + path_len - start);
if (end == NULL || end >= path + path_len) {
/* reached at the end of the path */
if (object != NULL && object->type == THINGSET_TYPE_RECORDS && *start >= '0'
Expand Down Expand Up @@ -791,13 +792,14 @@ static int get_function_arg_types(struct thingset_context *ts, uint16_t parent_i
len += snprintf(buf, size, ",");
}
char *elementType = type_to_type_name(ts->data_objects[i].type);
len += snprintf(buf + len, size - len, "%s", elementType);
int elem_len = snprintf(buf + len, size - len, "%s", elementType);
len += elem_len;
if (len >= size) {
return -THINGSET_ERR_RESPONSE_TOO_LARGE;
}
buf += len;
size -= len;
total_len += len;
if (total_len > size) {
return -THINGSET_ERR_RESPONSE_TOO_LARGE;
}
}
}
return total_len;
Expand All @@ -809,7 +811,7 @@ int thingset_get_type_name(struct thingset_context *ts, const struct thingset_da
switch (obj->type) {
case THINGSET_TYPE_ARRAY: {
char *elementType = type_to_type_name(obj->data.array->element_type);
if (sizeof(elementType) > size) {
if (strlen(elementType) + 3 > size) {
return -THINGSET_ERR_RESPONSE_TOO_LARGE;
}
return snprintf(buf, size, "%s[]", elementType);
Expand Down
18 changes: 10 additions & 8 deletions src/thingset_bin.c
Original file line number Diff line number Diff line change
Expand Up @@ -602,18 +602,20 @@ static int bin_deserialize_simple_value(struct thingset_context *ts,
int32_t *mantissa = data.decfrac;
if (zcbor_tag_expect(ts->decoder, ZCBOR_TAG_DECFRAC_ARR)) {
success = zcbor_list_start_decode(ts->decoder);
int32_t mantissa_tmp;
int32_t exponent_received;
int32_t mantissa_tmp = 0;
int32_t exponent_received = 0;
success = success && zcbor_int32_decode(ts->decoder, &exponent_received);
success = success && zcbor_int32_decode(ts->decoder, &mantissa_tmp);

for (int i = exponent_received; i < exponent; i++) {
mantissa_tmp /= 10;
}
for (int i = exponent_received; i > exponent; i--) {
mantissa_tmp *= 10;
if (success) {
for (int i = exponent_received; i < exponent; i++) {
mantissa_tmp /= 10;
}
for (int i = exponent_received; i > exponent; i--) {
mantissa_tmp *= 10;
}
*mantissa = mantissa_tmp;
}
*mantissa = mantissa_tmp;
}
else {
/* try integer and float types */
Expand Down
1 change: 1 addition & 0 deletions src/thingset_txt.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ static int txt_deserialize_simple_value(struct thingset_context *ts,
data.str[data_pos++] = buf[pos];
}
}
data.str[data_pos] = '\0';
#else
strncpy(data.str, buf, len);
data.str[len] = '\0';
Expand Down