diff options
author | Gonglei <arei.gonglei@huawei.com> | 2015-05-06 20:55:29 +0800 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2015-05-08 13:01:07 +0200 |
commit | e60baebd409d547292c778d599111ea1623dd4b5 (patch) | |
tree | e6d3d392e929dbf2593a7382596277718652c7a0 /hw/usb/dev-mtp.c | |
parent | 7c03a899e6e4030a88bd42c4d494e3a7521806ea (diff) |
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>
Diffstat (limited to 'hw/usb/dev-mtp.c')
-rw-r--r-- | hw/usb/dev-mtp.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c index c9c1f3210c..809b1cb118 100644 --- a/hw/usb/dev-mtp.c +++ b/hw/usb/dev-mtp.c @@ -1071,6 +1071,10 @@ static void usb_mtp_realize(USBDevice *dev, Error **errp) usb_desc_init(dev); QTAILQ_INIT(&s->objects); 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, '/'); if (s->desc && s->desc[0]) { s->desc = g_strdup(s->desc + 1); |