device_manager: missing NULL checks.

We should investigate why there are anonymous or unset attributes. But
at least let's not KDL because of it.

Fixes #16038.

Change-Id: Ifd49475e25ce8dcc3e98bc22df81f0e4f493f915
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2710
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
Adrien Destugues 2020-05-16 17:50:52 +02:00 committed by waddlesplash
parent 872240af5f
commit 59588089e7

View File

@ -529,7 +529,10 @@ control_device_manager(const char* subsystem, uint32 function, void* buffer,
device_attr* attr = iterator.Next();
attrInfo.cookie = (device_node_cookie)attr;
strlcpy(attrInfo.name, attr->name, 254);
if (attr->name != NULL)
strlcpy(attrInfo.name, attr->name, 254);
else
attrInfo.name[0] = '\0';
attrInfo.type = attr->type;
switch (attrInfo.type) {
case B_UINT8_TYPE:
@ -545,7 +548,10 @@ control_device_manager(const char* subsystem, uint32 function, void* buffer,
attrInfo.value.ui64 = attr->value.ui64;
break;
case B_STRING_TYPE:
strlcpy(attrInfo.value.string, attr->value.string, 254);
if (attr->value.string != NULL)
strlcpy(attrInfo.value.string, attr->value.string, 254);
else
attrInfo.value.string[0] = '\0';
break;
/*case B_RAW_TYPE:
if (attr.value.raw.length > attr_info->attr.value.raw.length)