From: Michael Roth <mdroth@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com
Subject: [Qemu-devel] [PATCH for-1.2] libcacard: Fix segfault when no backend specified
Date: Tue, 21 Aug 2012 11:36:36 -0500 [thread overview]
Message-ID: <1345566996-13782-1-git-send-email-mdroth@linux.vnet.ibm.com> (raw)
When a user does not specify a backend, a segfault can be triggered due
to a strcmp() being called on a NULL char*:
$ gdb --args qemu -usb -device usb-ccid \
-device ccid-card-emulated,id=smartcard0 \
...
(gdb) s
emulated_initfn (base=0x555556cb2e70) at
/home/mdroth/w/qemu.git/hw/ccid-card-emulated.c:503
503 card->backend = parse_enumeration(card->backend_str,
backend_enum_table, 0);
(gdb) s
parse_enumeration (not_found_value=0, table=0x555555b9b3c0, str=0x0) at
/home/mdroth/w/qemu.git/hw/ccid-card-emulated.c:476
476 while (table->name != NULL) {
(gdb) s
477 if (strcmp(table->name, str) == 0) {
(gdb) s
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff60df09a in ?? () from /lib/x86_64-linux-gnu/libc.so.6
After the fix:
$ qemu -usb -device usb-ccid \
-device ccid-card-emulated,id=smartcard0 \
...
unknown backend, must be one of:
nss-emulated
certificates
qemu-system-x86_64: -device
ccid-card-emulated,id=smartcard0,backend=nss-certificates: Device
'ccid-card-emulated' could not be initialized
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
hw/ccid-card-emulated.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/hw/ccid-card-emulated.c b/hw/ccid-card-emulated.c
index f4a6da4..740e8df 100644
--- a/hw/ccid-card-emulated.c
+++ b/hw/ccid-card-emulated.c
@@ -473,6 +473,9 @@ static uint32_t parse_enumeration(char *str,
{
uint32_t ret = not_found_value;
+ if (!str) {
+ return ret;
+ }
while (table->name != NULL) {
if (strcmp(table->name, str) == 0) {
ret = table->value;
--
1.7.9.5
reply other threads:[~2012-08-21 16:36 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1345566996-13782-1-git-send-email-mdroth@linux.vnet.ibm.com \
--to=mdroth@linux.vnet.ibm.com \
--cc=aliguori@us.ibm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).