usb-mtp: fix segmentation fault
When x-root property not be configured, will cause segfault because of null pointer accessing. Add a check for s->root property avoid segfault. Signed-off-by: Gonglei <arei.gonglei@huawei.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
parent
7c03a899e6
commit
e60baebd40
@ -1071,6 +1071,10 @@ static void usb_mtp_realize(USBDevice *dev, Error **errp)
|
|||||||
usb_desc_init(dev);
|
usb_desc_init(dev);
|
||||||
QTAILQ_INIT(&s->objects);
|
QTAILQ_INIT(&s->objects);
|
||||||
if (s->desc == NULL) {
|
if (s->desc == NULL) {
|
||||||
|
if (s->root == NULL) {
|
||||||
|
error_setg(errp, "usb-mtp: x-root property must be configured");
|
||||||
|
return;
|
||||||
|
}
|
||||||
s->desc = strrchr(s->root, '/');
|
s->desc = strrchr(s->root, '/');
|
||||||
if (s->desc && s->desc[0]) {
|
if (s->desc && s->desc[0]) {
|
||||||
s->desc = g_strdup(s->desc + 1);
|
s->desc = g_strdup(s->desc + 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user