From patchwork Tue May 7 00:44:20 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 241862 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id D05642C00B0 for ; Tue, 7 May 2013 10:44:30 +1000 (EST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1UZW17-0003Oe-Dv; Tue, 07 May 2013 00:44:29 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1UZW0y-0003ON-U4 for fwts-devel@lists.ubuntu.com; Tue, 07 May 2013 00:44:20 +0000 Received: from cpc3-craw6-2-0-cust180.croy.cable.virginmedia.com ([77.100.248.181] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1UZW0y-0008Tu-Pj for fwts-devel@lists.ubuntu.com; Tue, 07 May 2013 00:44:20 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH] hotkey: check lstat() return value rather Date: Tue, 7 May 2013 01:44:20 +0100 Message-Id: <1367887460-25000-1-git-send-email-colin.king@canonical.com> X-Mailer: git-send-email 1.8.1.2 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: fwts-devel-bounces@lists.ubuntu.com From: Colin Ian King Coverity CID #997313, Unchecked return value from library Check return from lstat rather than blindly accepting that it always works. Signed-off-by: Colin Ian King Acked-by: Alex Hung Acked-by: Keng-Yu Lin --- src/hotkey/hotkey/hotkey.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/hotkey/hotkey/hotkey.c b/src/hotkey/hotkey/hotkey.c index ff3c669..381f029 100644 --- a/src/hotkey/hotkey/hotkey.c +++ b/src/hotkey/hotkey/hotkey.c @@ -154,19 +154,20 @@ static char *hotkey_find_keyboard(char *path) if (strlen(entry->d_name) > 3) { snprintf(filename, sizeof(filename), "%s/%s", path, entry->d_name); - lstat(filename, &statbuf); - if (S_ISDIR(statbuf.st_mode)) { - if (!S_ISLNK(statbuf.st_mode)) - if ((dev = hotkey_find_keyboard(filename)) != NULL) - break; - } else { - if ((data = fwts_get(filename)) != NULL) { - if (strncmp(data, AT_KEYBOARD, sizeof(AT_KEYBOARD)-1) == 0) { - dev = hotkey_device(path); + if (lstat(filename, &statbuf) == 0) { + if (S_ISDIR(statbuf.st_mode)) { + if (!S_ISLNK(statbuf.st_mode)) + if ((dev = hotkey_find_keyboard(filename)) != NULL) + break; + } else { + if ((data = fwts_get(filename)) != NULL) { + if (strncmp(data, AT_KEYBOARD, sizeof(AT_KEYBOARD)-1) == 0) { + dev = hotkey_device(path); + free(data); + break; + } free(data); - break; } - free(data); } } }