Commit c1aa7f57 authored by Robert Lubos's avatar Robert Lubos Committed by Fabio Baltieri
Browse files

net: lwm2m: registry: Validate value pointer before use



Check if value pointer is not NULL before passing it to memcmp() inside
lwm2m_engine_set(). As the function actually expects that the value
pointer can be NULL in case resource value is cleared (there is a test
case for such behavior), validate that len value is actually 0 if NULL
value is provided, to avoid unexpected behavior in other parts of the
function.

Signed-off-by: default avatarRobert Lubos <robert.lubos@nordicsemi.no>
parent 7697eff4
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -545,6 +545,10 @@ static int lwm2m_engine_set(const struct lwm2m_obj_path *path, const void *value
	int ret = 0;
	bool changed = false;

	if (value == NULL && len > 0) {
		return -EINVAL;
	}

	if (path->level < LWM2M_PATH_LEVEL_RESOURCE) {
		LOG_ERR("path must have at least 3 parts");
		return -EINVAL;
@@ -600,7 +604,7 @@ static int lwm2m_engine_set(const struct lwm2m_obj_path *path, const void *value
		return ret;
	}

	if (memcmp(data_ptr, value, len) != 0 || res_inst->data_len != len) {
	if ((value != NULL && memcmp(data_ptr, value, len) != 0) || res_inst->data_len != len) {
		changed = true;
	}