提交 e23a22e6 编写于 作者: J Jens Osterkamp 提交者: Aurelien Jarno

qemu-sockets: avoid strlen of NULL pointer

If the user wants to create a chardev of type socket but forgets to give a
host= option, qemu_opt_get returns NULL. This NULL pointer is then fed into
strlen a few lines below without a check which results in a segfault.
This fixes it.
Signed-off-by: NJens Osterkamp <jens@linux.vnet.ibm.com>
Signed-off-by: NAurelien Jarno <aurelien@aurel32.net>
上级 81bbe906
......@@ -130,7 +130,8 @@ int inet_listen_opts(QemuOpts *opts, int port_offset)
ai.ai_family = PF_UNSPEC;
ai.ai_socktype = SOCK_STREAM;
if (qemu_opt_get(opts, "port") == NULL) {
if ((qemu_opt_get(opts, "host") == NULL) ||
(qemu_opt_get(opts, "port") == NULL)) {
fprintf(stderr, "%s: host and/or port not specified\n", __FUNCTION__);
return -1;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册