From patchwork Tue Aug 21 16:36:36 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 179101 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CBF752C008E for ; Wed, 22 Aug 2012 02:37:03 +1000 (EST) Received: from localhost ([::1]:48889 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T3rRt-00087P-Sy for incoming@patchwork.ozlabs.org; Tue, 21 Aug 2012 12:37:01 -0400 Received: from eggs.gnu.org ([208.118.235.92]:36348) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T3rRm-00086z-Ey for qemu-devel@nongnu.org; Tue, 21 Aug 2012 12:36:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T3rRg-0006lc-3w for qemu-devel@nongnu.org; Tue, 21 Aug 2012 12:36:54 -0400 Received: from mail-iy0-f173.google.com ([209.85.210.173]:38557) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T3rRf-0006lM-VT for qemu-devel@nongnu.org; Tue, 21 Aug 2012 12:36:48 -0400 Received: by iakx26 with SMTP id x26so3432806iak.4 for ; Tue, 21 Aug 2012 09:36:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer; bh=coNL7gstocQfHR6u9x9NxdDk9V7yIAJBrBEGT9/2NHA=; b=LTokIWc/lMNlQ3B8XvUkk3VctGDxOLBTwKAB8DpF4FCxmU6hTKMoedEOMcHwWHlies duFfL+g5KlgCIt40ELLNwCPzUHL9DNeBBpbXwIQ+4SnUC7pKGecIPD0aXsvYubBtdwQZ 904DwB0lt3JF9YKELhpfP8IdZFhu+xWy+SXkj26VQOrey08Aco0oHV13uftlzoK0mSn+ d5DjoEtzuvLobG3Ot6kbb6UIWf+NwfHBXg2+etmv05kI/KtasxdKxJXKwxwDQAploc2B bfmb1YZVvjCCXGKnBSGdBZktgRQHwNf8qL5LP62EaLnOU88x0mZzu5vEwDG3k1eM6gst EHcg== Received: by 10.42.123.130 with SMTP id s2mr14565048icr.50.1345567006127; Tue, 21 Aug 2012 09:36:46 -0700 (PDT) Received: from loki.morrigu.org (cpe-72-179-62-111.austin.res.rr.com. [72.179.62.111]) by mx.google.com with ESMTPS id dw5sm16228727igc.6.2012.08.21.09.36.44 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 21 Aug 2012 09:36:44 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 21 Aug 2012 11:36:36 -0500 Message-Id: <1345566996-13782-1-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.9.5 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.210.173 Cc: aliguori@us.ibm.com Subject: [Qemu-devel] [PATCH for-1.2] libcacard: Fix segfault when no backend specified X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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;