From patchwork Mon Oct 18 17:28:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tedd Ho-Jeong An X-Patchwork-Id: 12567487 X-Patchwork-Delegate: luiz.dentz@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6CBEC433EF for ; Mon, 18 Oct 2021 17:28:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB9366108E for ; Mon, 18 Oct 2021 17:28:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234100AbhJRRax (ORCPT ); Mon, 18 Oct 2021 13:30:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234006AbhJRRaw (ORCPT ); Mon, 18 Oct 2021 13:30:52 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A378C06161C for ; Mon, 18 Oct 2021 10:28:41 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id b14so1966706plg.2 for ; Mon, 18 Oct 2021 10:28:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=66qpyWVaDfHQMre7XUhyu7h/GLvkZFvo7tsk/hPA1w0=; b=L+AOgePiQPHBcs9kYjsEeCmjK8w4Udc2zX7OPrVJU+hVuBItIIZxTx6Fc/XzCg3w6n PQ88u88l1dn/Vnu/tY8e5oMD997yGYslh1AOekdH3tuqiObnNSRc0QHLZDfq4HsXrYQV DA8cOgynllFbBgxbxCI6hoTPfBhQ/yjFXzLZJidWrosvDAa5yH9dzGedzVXNMNsPLfdT wFX7+YsXqbu5pEgsdJq/PRUlR91qE5rIPFOXlFT7It0Hn7DymKZg1D+9MltfLnIPRYZF 3trSFfqiTXR0eYmeJsD+IWfKHcLRh8nfY6L6jYqwo09Kyu/p1YYmp82l+J87XiRC1mRz lidw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=66qpyWVaDfHQMre7XUhyu7h/GLvkZFvo7tsk/hPA1w0=; b=K4XyTxD/h55yCiot33BwGuImlWPcqZTTcqF+7hAxGHYL3YwwA8C92d/UfyUEqMuQMp WKh0oMmPjoN5iKqnPHOcDwqVzOs+cfWBMJ3TmRvwKF3eYrCRuqihK+aOdTk0MFKCDYIY yrmZxidP6O0DdPXji8sEpjT2YcSUS+VjoqeiIhHgw9S53J1Lm0o3mTD9Wupt+VXg+/jW np/wVdGIyfQaWRryhSgFy1CsaiadGX9L4mVEyPnBu6gaXCRkOYuNopRnpsJ+k+I3ZI+j Hqf1yLORN9Q0/ADCGRJaYgppyA/lLR1NJN7T4UlSeBqiWZ6buJ5UDwHxM6vcNxa5iJop Va/A== X-Gm-Message-State: AOAM531aKabZJJMTaEnAHdMdNG3fIidhYXW2gRnEzqyWOYAkBFGuNwcj 1SjYyK9Pwb8Yn6wt4V1Q4XdcUSlBPDnDYQ== X-Google-Smtp-Source: ABdhPJwGxkQULSbedEbS7OMaiTrXAKVSUFDpqCvcboHbBKSr8A3RgzmTeOBEn6tLaD2eP1XkpRCWpQ== X-Received: by 2002:a17:90a:73ce:: with SMTP id n14mr188096pjk.215.1634578120385; Mon, 18 Oct 2021 10:28:40 -0700 (PDT) Received: from han1-NUC8i7BEH.hsd1.or.comcast.net ([2601:1c0:6a01:d830:a510:aebd:a4ae:453c]) by smtp.gmail.com with ESMTPSA id fv9sm51156pjb.26.2021.10.18.10.28.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Oct 2021 10:28:39 -0700 (PDT) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH 1/9] device: Fix unchecked return value Date: Mon, 18 Oct 2021 10:28:25 -0700 Message-Id: <20211018172833.534191-2-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211018172833.534191-1-hj.tedd.an@gmail.com> References: <20211018172833.534191-1-hj.tedd.an@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Tedd Ho-Jeong An This patch fixes the unchecked return value(CWE-252) issues reported by the Coverity. --- src/device.c | 141 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 119 insertions(+), 22 deletions(-) diff --git a/src/device.c b/src/device.c index ac83cdc9c..d5aae9576 100644 --- a/src/device.c +++ b/src/device.c @@ -379,6 +379,7 @@ static gboolean store_device_info_cb(gpointer user_data) { struct btd_device *device = user_data; GKeyFile *key_file; + GError *gerr = NULL; char filename[PATH_MAX]; char device_addr[18]; char *str; @@ -394,7 +395,11 @@ static gboolean store_device_info_cb(gpointer user_data) device_addr); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } g_key_file_set_string(key_file, "General", "Name", device->name); @@ -467,7 +472,12 @@ static gboolean store_device_info_cb(gpointer user_data) create_file(filename, 0600); str = g_key_file_to_data(key_file, &length, NULL); - g_file_set_contents(filename, str, length, NULL); + if (!g_file_set_contents(filename, str, length, &gerr)) { + error("Unable set contents for %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } + g_free(str); g_key_file_free(key_file); @@ -509,6 +519,7 @@ void device_store_cached_name(struct btd_device *dev, const char *name) char filename[PATH_MAX]; char d_addr[18]; GKeyFile *key_file; + GError *gerr = NULL; char *data; char *data_old; gsize length = 0; @@ -526,16 +537,25 @@ void device_store_cached_name(struct btd_device *dev, const char *name) create_file(filename, 0600); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } + data_old = g_key_file_to_data(key_file, &length_old, NULL); g_key_file_set_string(key_file, "General", "Name", name); data = g_key_file_to_data(key_file, &length, NULL); - if ((length != length_old) || (memcmp(data, data_old, length))) - g_file_set_contents(filename, data, length, NULL); - + if ((length != length_old) || (memcmp(data, data_old, length))) { + if (!g_file_set_contents(filename, data, length, &gerr)) { + error("Unable set contents for %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } + } g_free(data); g_free(data_old); @@ -2306,6 +2326,7 @@ static void store_services(struct btd_device *device) uuid_t uuid; char *prim_uuid; GKeyFile *key_file; + GError *gerr = NULL; GSList *l; char *data; gsize length = 0; @@ -2363,7 +2384,11 @@ static void store_services(struct btd_device *device) data = g_key_file_to_data(key_file, &length, NULL); if (length > 0) { create_file(filename, 0600); - g_file_set_contents(filename, data, length, NULL); + if (!g_file_set_contents(filename, data, length, &gerr)) { + error("Unable set contents for %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } } free(prim_uuid); @@ -2532,6 +2557,7 @@ static void store_gatt_db(struct btd_device *device) char filename[PATH_MAX]; char dst_addr[18]; GKeyFile *key_file; + GError *gerr = NULL; char *data; gsize length = 0; struct gatt_saver saver; @@ -2553,7 +2579,11 @@ static void store_gatt_db(struct btd_device *device) create_file(filename, 0600); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } /* Remove current attributes since it might have changed */ g_key_file_remove_group(key_file, "Attributes", NULL); @@ -2564,7 +2594,11 @@ static void store_gatt_db(struct btd_device *device) gatt_db_foreach_service(device->db, NULL, store_service, &saver); data = g_key_file_to_data(key_file, &length, NULL); - g_file_set_contents(filename, data, length, NULL); + if (!g_file_set_contents(filename, data, length, &gerr)) { + error("Unable set contents for %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } g_free(data); g_key_file_free(key_file); @@ -3295,6 +3329,7 @@ static void convert_info(struct btd_device *device, GKeyFile *key_file) char **uuids; char *str; gsize length = 0; + GError *gerr = NULL; /* Load device profile list from legacy properties */ uuids = g_key_file_get_string_list(key_file, "General", "SDPServices", @@ -3320,7 +3355,11 @@ static void convert_info(struct btd_device *device, GKeyFile *key_file) device_addr); str = g_key_file_to_data(key_file, &length, NULL); - g_file_set_contents(filename, str, length, NULL); + if (!g_file_set_contents(filename, str, length, &gerr)) { + error("Unable set contents for %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } g_free(str); store_device_info(device); @@ -3466,6 +3505,7 @@ static void load_att_info(struct btd_device *device, const char *local, { char filename[PATH_MAX]; GKeyFile *key_file; + GError *gerr = NULL; char *prim_uuid, *str; char **groups, **handle, *service_uuid; struct gatt_primary *prim; @@ -3480,7 +3520,11 @@ static void load_att_info(struct btd_device *device, const char *local, peer); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } groups = g_key_file_get_groups(key_file, NULL); for (handle = groups; *handle; handle++) { @@ -3856,6 +3900,7 @@ static void load_gatt_db(struct btd_device *device, const char *local, { char **keys, filename[PATH_MAX]; GKeyFile *key_file; + GError *gerr = NULL; if (!gatt_cache_is_enabled(device)) return; @@ -3865,7 +3910,11 @@ static void load_gatt_db(struct btd_device *device, const char *local, snprintf(filename, PATH_MAX, STORAGEDIR "/%s/cache/%s", local, peer); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } keys = g_key_file_get_keys(key_file, "Attributes", NULL, NULL); if (!keys) { @@ -4516,6 +4565,7 @@ static void device_remove_stored(struct btd_device *device) char device_addr[18]; char filename[PATH_MAX]; GKeyFile *key_file; + GError *gerr = NULL; char *data; gsize length = 0; @@ -4543,14 +4593,22 @@ static void device_remove_stored(struct btd_device *device) device_addr); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } g_key_file_remove_group(key_file, "ServiceRecords", NULL); g_key_file_remove_group(key_file, "Attributes", NULL); data = g_key_file_to_data(key_file, &length, NULL); if (length > 0) { create_file(filename, 0600); - g_file_set_contents(filename, data, length, NULL); + if (!g_file_set_contents(filename, data, length, &gerr)) { + error("Unable set contents for %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } } g_free(data); @@ -4929,6 +4987,8 @@ static void update_bredr_services(struct browse_req *req, sdp_list_t *recs) char att_file[PATH_MAX]; GKeyFile *sdp_key_file; GKeyFile *att_key_file; + GError *gerr = NULL; + char *data; gsize length = 0; @@ -4939,13 +4999,21 @@ static void update_bredr_services(struct browse_req *req, sdp_list_t *recs) dstaddr); sdp_key_file = g_key_file_new(); - g_key_file_load_from_file(sdp_key_file, sdp_file, 0, NULL); + if (!g_key_file_load_from_file(sdp_key_file, sdp_file, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", sdp_file, + gerr->message); + g_error_free(gerr); + } snprintf(att_file, PATH_MAX, STORAGEDIR "/%s/%s/attributes", srcaddr, dstaddr); att_key_file = g_key_file_new(); - g_key_file_load_from_file(att_key_file, att_file, 0, NULL); + if (!g_key_file_load_from_file(att_key_file, att_file, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", att_file, + gerr->message); + g_error_free(gerr); + } for (seq = recs; seq; seq = seq->next) { sdp_record_t *rec = (sdp_record_t *) seq->data; @@ -5000,7 +5068,12 @@ next: data = g_key_file_to_data(sdp_key_file, &length, NULL); if (length > 0) { create_file(sdp_file, 0600); - g_file_set_contents(sdp_file, data, length, NULL); + if (!g_file_set_contents(sdp_file, data, length, + &gerr)) { + error("Unable set contents for %s: (%s)", + sdp_file, gerr->message); + g_error_free(gerr); + } } g_free(data); @@ -5011,7 +5084,12 @@ next: data = g_key_file_to_data(att_key_file, &length, NULL); if (length > 0) { create_file(att_file, 0600); - g_file_set_contents(att_file, data, length, NULL); + if (!g_file_set_contents(att_file, data, length, + &gerr)) { + error("Unable set contents for %s: (%s)", + att_file, gerr->message); + g_error_free(gerr); + } } g_free(data); @@ -5897,6 +5975,7 @@ void device_store_svc_chng_ccc(struct btd_device *device, uint8_t bdaddr_type, char filename[PATH_MAX]; char device_addr[18]; GKeyFile *key_file; + GError *gerr = NULL; uint16_t old_value; gsize length = 0; char *str; @@ -5907,7 +5986,11 @@ void device_store_svc_chng_ccc(struct btd_device *device, uint8_t bdaddr_type, device_addr); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } /* for bonded devices this is done on every connection so limit writes * to storage if no change needed @@ -5933,7 +6016,11 @@ void device_store_svc_chng_ccc(struct btd_device *device, uint8_t bdaddr_type, create_file(filename, 0600); str = g_key_file_to_data(key_file, &length, NULL); - g_file_set_contents(filename, str, length, NULL); + if (!g_file_set_contents(filename, str, length, &gerr)) { + error("Unable set contents for %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } g_free(str); done: @@ -5945,6 +6032,7 @@ void device_load_svc_chng_ccc(struct btd_device *device, uint16_t *ccc_le, char filename[PATH_MAX]; char device_addr[18]; GKeyFile *key_file; + GError *gerr = NULL; ba2str(&device->bdaddr, device_addr); snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info", @@ -5952,7 +6040,11 @@ void device_load_svc_chng_ccc(struct btd_device *device, uint16_t *ccc_le, device_addr); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } if (!g_key_file_has_group(key_file, "ServiceChanged")) { if (ccc_le) @@ -6794,6 +6886,7 @@ static sdp_list_t *read_device_records(struct btd_device *device) char local[18], peer[18]; char filename[PATH_MAX]; GKeyFile *key_file; + GError *gerr = NULL; char **keys, **handle; char *str; sdp_list_t *recs = NULL; @@ -6805,7 +6898,11 @@ static sdp_list_t *read_device_records(struct btd_device *device) snprintf(filename, PATH_MAX, STORAGEDIR "/%s/cache/%s", local, peer); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } keys = g_key_file_get_keys(key_file, "ServiceRecords", NULL, NULL); for (handle = keys; handle && *handle; handle++) { From patchwork Mon Oct 18 17:28:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tedd Ho-Jeong An X-Patchwork-Id: 12567489 X-Patchwork-Delegate: luiz.dentz@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05941C433F5 for ; Mon, 18 Oct 2021 17:28:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E2DCA610C7 for ; Mon, 18 Oct 2021 17:28:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234114AbhJRRay (ORCPT ); Mon, 18 Oct 2021 13:30:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234102AbhJRRax (ORCPT ); Mon, 18 Oct 2021 13:30:53 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A19DC06161C for ; Mon, 18 Oct 2021 10:28:42 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id v8so11128850pfu.11 for ; Mon, 18 Oct 2021 10:28:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=HNTn4H7mPsMVJx8sgRyETT/uP9qbRFkoaroKQHhYKh8=; b=bigAvK8/VFpzubCIx0/yoek6jtif8sgSRHKaLZO6FZNd7SMODwMw3wjjr6VIevc7x/ SWj5bPsCal1afF4nnS7Tayo5OTQfs+X/7jHzVWqGSXjeN7aH4kU0NuRSIlOj8UuQZxEt MH7gaRCjlbs6wpR9Uqei001t0AYm5ibriuz5yJavFvjldEH1f+ltUZu0ilsIW9rW8SBv 4/gDcaR3x1eUtGodhe6X+WlgNTijrCDpqoHGbGxQ/hybfoJW+kJ2f1isihB3+UwRkOMZ suBzKqHjw9Y5TW2k8mTfk6IJaXx6Z+uH/QejWck8p+PCw7CZqrCQBwayJFyWYKpr0qqO o/IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HNTn4H7mPsMVJx8sgRyETT/uP9qbRFkoaroKQHhYKh8=; b=RKIhUeSc5q8MxrYUEIbyEPLOuYD7Gw5iVygLVywFL6yidAn0eT7R/mx8TK5Ou2nuya 63/+RPevSvUoYEDs/3YXf+fXwFyNy03wpd3feQPrCysUUxVEbLy8tAxKDIdu2XUsQH1f drOyNdi/SlXzQmieWleYOyr9xsKOcu3DjKWyxm006RnAAsX12Zix3yQ0Q4dmDpesYVcg qcmxhtLucm9P3wFL6MDWDGeMVoE/Z7leQi0TnixRBycVnxVx0PimZeQJjBLPogwqR0Tp myRaJBnpbbPxA6UWjA+w0YPJzWoVD557bnDtySEUGamznDJTGbGuv/wmExq4FSmznmDr 6W0Q== X-Gm-Message-State: AOAM533XjAI8DJrcQQCBfqlmJOSlmh5gVYdfI2uIWe4APCaroviMBYB3 2VGEG2ZS1Id4E+LvtzlNk9LbMCRduix19w== X-Google-Smtp-Source: ABdhPJy/CWHTEheoKt93AggNjp9BJFR/vz7do9Co/44Vwe5rJzyBiX1w0dOKJbwM2Gbum+no6lqZ/A== X-Received: by 2002:a63:e041:: with SMTP id n1mr25178695pgj.211.1634578121181; Mon, 18 Oct 2021 10:28:41 -0700 (PDT) Received: from han1-NUC8i7BEH.hsd1.or.comcast.net ([2601:1c0:6a01:d830:a510:aebd:a4ae:453c]) by smtp.gmail.com with ESMTPSA id fv9sm51156pjb.26.2021.10.18.10.28.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Oct 2021 10:28:40 -0700 (PDT) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH 2/9] adapter: Fix unchecked return value Date: Mon, 18 Oct 2021 10:28:26 -0700 Message-Id: <20211018172833.534191-3-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211018172833.534191-1-hj.tedd.an@gmail.com> References: <20211018172833.534191-1-hj.tedd.an@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Tedd Ho-Jeong An This patch fixes the unchecked return value(CWE-252) issues reported by the Coverity. --- src/adapter.c | 249 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 211 insertions(+), 38 deletions(-) diff --git a/src/adapter.c b/src/adapter.c index 5846f0396..54b6322cc 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -515,6 +515,7 @@ uint8_t btd_adapter_get_address_type(struct btd_adapter *adapter) static void store_adapter_info(struct btd_adapter *adapter) { GKeyFile *key_file; + GError *gerr = NULL; char filename[PATH_MAX]; char *str; gsize length = 0; @@ -550,7 +551,11 @@ static void store_adapter_info(struct btd_adapter *adapter) create_file(filename, 0600); str = g_key_file_to_data(key_file, &length, NULL); - g_file_set_contents(filename, str, length, NULL); + if (!g_file_set_contents(filename, str, length, &gerr)) { + error("Unable set contents for %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } g_free(str); g_key_file_free(key_file); @@ -3933,6 +3938,7 @@ static int generate_and_write_irk(uint8_t *irk, GKeyFile *key_file, struct bt_crypto *crypto; char str_irk_out[33]; gsize length = 0; + GError *gerr = NULL; char *str; int i; @@ -3959,7 +3965,11 @@ static int generate_and_write_irk(uint8_t *irk, GKeyFile *key_file, g_key_file_set_string(key_file, "General", "IdentityResolvingKey", str_irk_out); str = g_key_file_to_data(key_file, &length, NULL); - g_file_set_contents(filename, str, length, NULL); + if (!g_file_set_contents(filename, str, length, &gerr)) { + error("Unable set contents for %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } g_free(str); DBG("Generated IRK written to file"); return 0; @@ -3969,6 +3979,7 @@ static int load_irk(struct btd_adapter *adapter, uint8_t *irk) { char filename[PATH_MAX]; GKeyFile *key_file; + GError *gerr = NULL; char *str_irk; int ret; @@ -3976,7 +3987,11 @@ static int load_irk(struct btd_adapter *adapter, uint8_t *irk) btd_adapter_get_storage_dir(adapter)); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } str_irk = g_key_file_get_string(key_file, "General", "IdentityResolvingKey", NULL); @@ -4664,6 +4679,7 @@ static void load_devices(struct btd_adapter *adapter) GSList *irks = NULL; GSList *params = NULL; GSList *added_devices = NULL; + GError *gerr = NULL; DIR *dir; struct dirent *entry; @@ -4701,7 +4717,11 @@ static void load_devices(struct btd_adapter *adapter) entry->d_name); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } key_info = get_key_info(key_file, entry->d_name); @@ -5686,6 +5706,7 @@ static void convert_names_entry(char *key, char *value, void *user_data) char *str = key; char filename[PATH_MAX]; GKeyFile *key_file; + GError *gerr = NULL; char *data; gsize length = 0; @@ -5699,11 +5720,19 @@ static void convert_names_entry(char *key, char *value, void *user_data) create_file(filename, 0600); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } g_key_file_set_string(key_file, "General", "Name", value); data = g_key_file_to_data(key_file, &length, NULL); - g_file_set_contents(filename, data, length, NULL); + if (!g_file_set_contents(filename, data, length, &gerr)) { + error("Unable set contents for %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } g_free(data); g_key_file_free(key_file); @@ -5897,6 +5926,7 @@ static void convert_entry(char *key, char *value, void *user_data) char type = BDADDR_BREDR; char filename[PATH_MAX]; GKeyFile *key_file; + GError *gerr = NULL; char *data; gsize length = 0; @@ -5924,7 +5954,11 @@ static void convert_entry(char *key, char *value, void *user_data) converter->address, key); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } set_device_type(key_file, type); @@ -5933,7 +5967,11 @@ static void convert_entry(char *key, char *value, void *user_data) data = g_key_file_to_data(key_file, &length, NULL); if (length > 0) { create_file(filename, 0600); - g_file_set_contents(filename, data, length, NULL); + if (!g_file_set_contents(filename, data, length, &gerr)) { + error("Unable set contents for %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } } g_free(data); @@ -6014,6 +6052,7 @@ static void store_sdp_record(char *local, char *peer, int handle, char *value) { char filename[PATH_MAX]; GKeyFile *key_file; + GError *gerr = NULL; char handle_str[11]; char *data; gsize length = 0; @@ -6021,7 +6060,11 @@ static void store_sdp_record(char *local, char *peer, int handle, char *value) snprintf(filename, PATH_MAX, STORAGEDIR "/%s/cache/%s", local, peer); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } sprintf(handle_str, "0x%8.8X", handle); g_key_file_set_string(key_file, "ServiceRecords", handle_str, value); @@ -6029,7 +6072,11 @@ static void store_sdp_record(char *local, char *peer, int handle, char *value) data = g_key_file_to_data(key_file, &length, NULL); if (length > 0) { create_file(filename, 0600); - g_file_set_contents(filename, data, length, NULL); + if (!g_file_set_contents(filename, data, length, &gerr)) { + error("Unable set contents for %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } } g_free(data); @@ -6045,6 +6092,7 @@ static void convert_sdp_entry(char *key, char *value, void *user_data) int handle, ret; char filename[PATH_MAX]; GKeyFile *key_file; + GError *gerr = NULL; struct stat st; sdp_record_t *rec; uuid_t uuid; @@ -6096,14 +6144,22 @@ static void convert_sdp_entry(char *key, char *value, void *user_data) dst_addr); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } store_attribute_uuid(key_file, start, end, prim_uuid, uuid); data = g_key_file_to_data(key_file, &length, NULL); if (length > 0) { create_file(filename, 0600); - g_file_set_contents(filename, data, length, NULL); + if (!g_file_set_contents(filename, data, length, &gerr)) { + error("Unable set contents for %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } } g_free(data); @@ -6123,6 +6179,7 @@ static void convert_primaries_entry(char *key, char *value, void *user_data) char **services, **service, *prim_uuid; char filename[PATH_MAX]; GKeyFile *key_file; + GError *gerr = NULL; int ret; uint16_t start, end; char uuid_str[MAX_LEN_UUID_STR + 1]; @@ -6147,7 +6204,11 @@ static void convert_primaries_entry(char *key, char *value, void *user_data) snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/attributes", address, key); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } for (service = services; *service; service++) { ret = sscanf(*service, "%04hX#%04hX#%s", &start, &end, @@ -6168,7 +6229,11 @@ static void convert_primaries_entry(char *key, char *value, void *user_data) goto end; create_file(filename, 0600); - g_file_set_contents(filename, data, length, NULL); + if (!g_file_set_contents(filename, data, length, &gerr)) { + error("Unable set contents for %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } if (device_type < 0) goto end; @@ -6179,13 +6244,21 @@ static void convert_primaries_entry(char *key, char *value, void *user_data) snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info", address, key); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } set_device_type(key_file, device_type); data = g_key_file_to_data(key_file, &length, NULL); if (length > 0) { create_file(filename, 0600); - g_file_set_contents(filename, data, length, NULL); + if (!g_file_set_contents(filename, data, length, &gerr)) { + error("Unable set contents for %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } } end: @@ -6203,6 +6276,7 @@ static void convert_ccc_entry(char *key, char *value, void *user_data) int ret, err; char filename[PATH_MAX]; GKeyFile *key_file; + GError *gerr = NULL; struct stat st; char group[6]; char *data; @@ -6226,7 +6300,11 @@ static void convert_ccc_entry(char *key, char *value, void *user_data) snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/ccc", src_addr, dst_addr); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } sprintf(group, "%hu", handle); g_key_file_set_string(key_file, group, "Value", value); @@ -6234,7 +6312,11 @@ static void convert_ccc_entry(char *key, char *value, void *user_data) data = g_key_file_to_data(key_file, &length, NULL); if (length > 0) { create_file(filename, 0600); - g_file_set_contents(filename, data, length, NULL); + if (!g_file_set_contents(filename, data, length, &gerr)) { + error("Unable set contents for %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } } g_free(data); @@ -6250,6 +6332,7 @@ static void convert_gatt_entry(char *key, char *value, void *user_data) int ret, err; char filename[PATH_MAX]; GKeyFile *key_file; + GError *gerr = NULL; struct stat st; char group[6]; char *data; @@ -6273,7 +6356,11 @@ static void convert_gatt_entry(char *key, char *value, void *user_data) snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/gatt", src_addr, dst_addr); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } sprintf(group, "%hu", handle); g_key_file_set_string(key_file, group, "Value", value); @@ -6281,7 +6368,11 @@ static void convert_gatt_entry(char *key, char *value, void *user_data) data = g_key_file_to_data(key_file, &length, NULL); if (length > 0) { create_file(filename, 0600); - g_file_set_contents(filename, data, length, NULL); + if (!g_file_set_contents(filename, data, length, &gerr)) { + error("Unable set contents for %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } } g_free(data); @@ -6294,6 +6385,7 @@ static void convert_proximity_entry(char *key, char *value, void *user_data) char *alert; char filename[PATH_MAX]; GKeyFile *key_file; + GError *gerr = NULL; struct stat st; int err; char *data; @@ -6319,14 +6411,22 @@ static void convert_proximity_entry(char *key, char *value, void *user_data) snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/proximity", src_addr, key); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } g_key_file_set_string(key_file, alert, "Level", value); data = g_key_file_to_data(key_file, &length, NULL); if (length > 0) { create_file(filename, 0600); - g_file_set_contents(filename, data, length, NULL); + if (!g_file_set_contents(filename, data, length, &gerr)) { + error("Unable set contents for %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } } g_free(data); @@ -6402,6 +6502,7 @@ static void convert_config(struct btd_adapter *adapter, const char *filename, uint8_t mode; char *data; gsize length = 0; + GError *gerr = NULL; ba2str(&adapter->bdaddr, address); snprintf(config_path, PATH_MAX, STORAGEDIR "/%s/config", address); @@ -6426,7 +6527,11 @@ static void convert_config(struct btd_adapter *adapter, const char *filename, create_file(filename, 0600); data = g_key_file_to_data(key_file, &length, NULL); - g_file_set_contents(filename, data, length, NULL); + if (!g_file_set_contents(filename, data, length, &gerr)) { + error("Unable set contents for %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } g_free(data); } @@ -6510,7 +6615,11 @@ static void load_config(struct btd_adapter *adapter) convert_device_storage(adapter); } - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } /* Get alias */ adapter->stored_alias = g_key_file_get_string(key_file, "General", @@ -8222,6 +8331,7 @@ static void store_link_key(struct btd_adapter *adapter, char device_addr[18]; char filename[PATH_MAX]; GKeyFile *key_file; + GError *gerr = NULL; gsize length = 0; char key_str[33]; char *str; @@ -8232,7 +8342,11 @@ static void store_link_key(struct btd_adapter *adapter, snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info", btd_adapter_get_storage_dir(adapter), device_addr); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } for (i = 0; i < 16; i++) sprintf(key_str + (i * 2), "%2.2X", key[i]); @@ -8245,7 +8359,11 @@ static void store_link_key(struct btd_adapter *adapter, create_file(filename, 0600); str = g_key_file_to_data(key_file, &length, NULL); - g_file_set_contents(filename, str, length, NULL); + if (!g_file_set_contents(filename, str, length, &gerr)) { + error("Unable set contents for %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } g_free(str); g_key_file_free(key_file); @@ -8307,6 +8425,7 @@ static void store_longtermkey(struct btd_adapter *adapter, const bdaddr_t *peer, char device_addr[18]; char filename[PATH_MAX]; GKeyFile *key_file; + GError *gerr = NULL; char key_str[33]; gsize length = 0; char *str; @@ -8322,7 +8441,11 @@ static void store_longtermkey(struct btd_adapter *adapter, const bdaddr_t *peer, snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info", btd_adapter_get_storage_dir(adapter), device_addr); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } /* Old files may contain this so remove it in case it exists */ g_key_file_remove_key(key_file, "LongTermKey", "Master", NULL); @@ -8342,7 +8465,11 @@ static void store_longtermkey(struct btd_adapter *adapter, const bdaddr_t *peer, create_file(filename, 0600); str = g_key_file_to_data(key_file, &length, NULL); - g_file_set_contents(filename, str, length, NULL); + if (!g_file_set_contents(filename, str, length, &gerr)) { + error("Unable set contents for %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } g_free(str); g_key_file_free(key_file); @@ -8420,6 +8547,7 @@ static void store_csrk(struct btd_adapter *adapter, const bdaddr_t *peer, char device_addr[18]; char filename[PATH_MAX]; GKeyFile *key_file; + GError *gerr = NULL; char key_str[33]; gsize length = 0; gboolean auth; @@ -8454,7 +8582,11 @@ static void store_csrk(struct btd_adapter *adapter, const bdaddr_t *peer, btd_adapter_get_storage_dir(adapter), device_addr); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } for (i = 0; i < 16; i++) sprintf(key_str + (i * 2), "%2.2X", key[i]); @@ -8466,7 +8598,11 @@ static void store_csrk(struct btd_adapter *adapter, const bdaddr_t *peer, create_file(filename, 0600); str = g_key_file_to_data(key_file, &length, NULL); - g_file_set_contents(filename, str, length, NULL); + if (!g_file_set_contents(filename, str, length, &gerr)) { + error("Unable set contents for %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } g_free(str); g_key_file_free(key_file); @@ -8514,6 +8650,7 @@ static void store_irk(struct btd_adapter *adapter, const bdaddr_t *peer, char device_addr[18]; char filename[PATH_MAX]; GKeyFile *key_file; + GError *gerr = NULL; char *store_data; char str[33]; size_t length = 0; @@ -8524,7 +8661,11 @@ static void store_irk(struct btd_adapter *adapter, const bdaddr_t *peer, snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info", btd_adapter_get_storage_dir(adapter), device_addr); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } for (i = 0; i < 16; i++) sprintf(str + (i * 2), "%2.2X", key[i]); @@ -8534,7 +8675,11 @@ static void store_irk(struct btd_adapter *adapter, const bdaddr_t *peer, create_file(filename, 0600); store_data = g_key_file_to_data(key_file, &length, NULL); - g_file_set_contents(filename, store_data, length, NULL); + if (!g_file_set_contents(filename, store_data, length, &gerr)) { + error("Unable set contents for %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } g_free(store_data); g_key_file_free(key_file); @@ -8602,6 +8747,7 @@ static void store_conn_param(struct btd_adapter *adapter, const bdaddr_t *peer, char device_addr[18]; char filename[PATH_MAX]; GKeyFile *key_file; + GError *gerr = NULL; char *store_data; size_t length = 0; @@ -8612,7 +8758,11 @@ static void store_conn_param(struct btd_adapter *adapter, const bdaddr_t *peer, snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info", btd_adapter_get_storage_dir(adapter), device_addr); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } g_key_file_set_integer(key_file, "ConnectionParameters", "MinInterval", min_interval); @@ -8626,7 +8776,11 @@ static void store_conn_param(struct btd_adapter *adapter, const bdaddr_t *peer, create_file(filename, 0600); store_data = g_key_file_to_data(key_file, &length, NULL); - g_file_set_contents(filename, store_data, length, NULL); + if (!g_file_set_contents(filename, store_data, length, &gerr)) { + error("Unable set contents for %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } g_free(store_data); g_key_file_free(key_file); @@ -9254,6 +9408,7 @@ static void remove_keys(struct btd_adapter *adapter, char device_addr[18]; char filename[PATH_MAX]; GKeyFile *key_file; + GError *gerr = NULL; gsize length = 0; char *str; @@ -9262,7 +9417,11 @@ static void remove_keys(struct btd_adapter *adapter, snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info", btd_adapter_get_storage_dir(adapter), device_addr); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } if (type == BDADDR_BREDR) { g_key_file_remove_group(key_file, "LinkKey", NULL); @@ -9274,7 +9433,11 @@ static void remove_keys(struct btd_adapter *adapter, } str = g_key_file_to_data(key_file, &length, NULL); - g_file_set_contents(filename, str, length, NULL); + if (!g_file_set_contents(filename, str, length, &gerr)) { + error("Unable set contents for %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } g_free(str); g_key_file_free(key_file); @@ -9345,6 +9508,7 @@ static bool get_static_addr(struct btd_adapter *adapter) { struct bt_crypto *crypto; GKeyFile *file; + GError *gerr = NULL; char **addrs; char mfg[7]; char *str; @@ -9354,7 +9518,12 @@ static bool get_static_addr(struct btd_adapter *adapter) snprintf(mfg, sizeof(mfg), "0x%04x", adapter->manufacturer); file = g_key_file_new(); - g_key_file_load_from_file(file, STORAGEDIR "/addresses", 0, NULL); + if (!g_key_file_load_from_file(file, STORAGEDIR "/addresses", 0, + &gerr)) { + error("Unable to load key file from %s: (%s)", + STORAGEDIR "/addresses", gerr->message); + g_error_free(gerr); + } addrs = g_key_file_get_string_list(file, "Static", mfg, &len, NULL); if (addrs) { for (i = 0; i < len; i++) { @@ -9408,7 +9577,11 @@ static bool get_static_addr(struct btd_adapter *adapter) (const char **)addrs, len); str = g_key_file_to_data(file, &len, NULL); - g_file_set_contents(STORAGEDIR "/addresses", str, len, NULL); + if (!g_file_set_contents(STORAGEDIR "/addresses", str, len, &gerr)) { + error("Unable set contents for %s: (%s)", + STORAGEDIR "/addresses", gerr->message); + g_error_free(gerr); + } g_free(str); ret = true; From patchwork Mon Oct 18 17:28:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tedd Ho-Jeong An X-Patchwork-Id: 12567491 X-Patchwork-Delegate: luiz.dentz@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0332BC433FE for ; Mon, 18 Oct 2021 17:28:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DE60C60EE9 for ; Mon, 18 Oct 2021 17:28:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234123AbhJRRaz (ORCPT ); Mon, 18 Oct 2021 13:30:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234006AbhJRRax (ORCPT ); Mon, 18 Oct 2021 13:30:53 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C0CCC061745 for ; Mon, 18 Oct 2021 10:28:42 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id 21so11725675plo.13 for ; Mon, 18 Oct 2021 10:28:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=+FfnDGZAWFELiL6UZ36GXT86gwbpLXHzNQYqIrlobIU=; b=MsYhv+eGCsDP1YuM/h8yrUzSxejDpWfLSWO4ZQFHat/0At7EObk2VpfKmY6Ucdr9Of 4GUMjKoxmoWw9iT8dYKTTereALOMUsLeB/RilVqhAn1TLvLnm92FH+oEIQtjahraAWGx 8wlnT2oohzf7YRvkbRBckCYZxj/yxskYSmAhi6Dyod02gfpZ1xs6b5sIZMQSpQtrTN3s 6gKZx0YnsOipDbaD/BlVrYjoqSV21/+LgP8WZwl3QVzXNgLTfwHonCcG9/LRyl7UgOF/ a0NXK6BIAfKf5NZzAZ0MdwYb9ZSCNA1EkC0Yj1kMzZuOViwKaPfg6lzS9DJiVhDiZ1Bp 4AoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+FfnDGZAWFELiL6UZ36GXT86gwbpLXHzNQYqIrlobIU=; b=l7EeZn/Cy0FqU2Gdi9LIsUxOX/SifH4mMIjTFO+cCtTFMcsBCJ+2ECFI45mYyv8kbc /2yVnfXvs7/C9T2oCSuCmZJ2+2vueDGnnaJCgpx4nshhSw+8puVACSJDJqbvrgExw8jB gTquIHnP19iI5T+cDv9HUvLoN/VIOmH5k5gpjsFKH65UqokkJ2nHLixWekdkZOdc/J1B W8vfPd7xuXyHJdpJ5Y+nuNefjjOxqosvKpPf7IbfD+hhtUS0M0Po74ViT5FDovhayxsJ KMTbol4Idfip5DYB8yQDFlJsuQ6s9bvUq0j3S0qgBbEyKN6hDlpseAsRaBJGzgA1DIDy btLw== X-Gm-Message-State: AOAM5336Af0YM5ceS5HZsrA3qtXlO62sQ7xBSKjJcg95izcqj50tw/nd xJUN/WZzGmarwGYZeP4RX+0i5gxHvD/XrQ== X-Google-Smtp-Source: ABdhPJztVEkZYKlOWfFSnjFCu/YrI0bxXzFHvjAs9yOBZceDOST8awKxvOneMObehGmBDytgGn5C5A== X-Received: by 2002:a17:90a:cc15:: with SMTP id b21mr216991pju.113.1634578121740; Mon, 18 Oct 2021 10:28:41 -0700 (PDT) Received: from han1-NUC8i7BEH.hsd1.or.comcast.net ([2601:1c0:6a01:d830:a510:aebd:a4ae:453c]) by smtp.gmail.com with ESMTPSA id fv9sm51156pjb.26.2021.10.18.10.28.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Oct 2021 10:28:41 -0700 (PDT) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH 3/9] attrib-server: Fix unchecked return value Date: Mon, 18 Oct 2021 10:28:27 -0700 Message-Id: <20211018172833.534191-4-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211018172833.534191-1-hj.tedd.an@gmail.com> References: <20211018172833.534191-1-hj.tedd.an@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Tedd Ho-Jeong An This patch fixes the unchecked return value(CWE-252) issues reported by the Coverity. --- src/attrib-server.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/attrib-server.c b/src/attrib-server.c index 5a178f95e..0063c9534 100644 --- a/src/attrib-server.c +++ b/src/attrib-server.c @@ -752,6 +752,7 @@ static int read_device_ccc(struct btd_device *device, uint16_t handle, { char *filename; GKeyFile *key_file; + GError *gerr = NULL; char group[6]; char *str; unsigned int config; @@ -764,7 +765,11 @@ static int read_device_ccc(struct btd_device *device, uint16_t handle, } key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } sprintf(group, "%hu", handle); @@ -867,6 +872,7 @@ static uint16_t write_value(struct gatt_channel *channel, uint16_t handle, struct attribute *a; uint8_t status; GList *l; + GError *gerr = NULL; guint h = handle; l = g_list_find_custom(channel->server->database, @@ -911,7 +917,11 @@ static uint16_t write_value(struct gatt_channel *channel, uint16_t handle, } key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } sprintf(group, "%hu", handle); sprintf(value, "%hX", cccval); @@ -920,7 +930,12 @@ static uint16_t write_value(struct gatt_channel *channel, uint16_t handle, data = g_key_file_to_data(key_file, &length, NULL); if (length > 0) { create_file(filename, 0600); - g_file_set_contents(filename, data, length, NULL); + if (!g_file_set_contents(filename, data, length, + &gerr)) { + error("Unable set contents for %s: (%s)", + filename, gerr->message); + g_error_free(gerr); + } } g_free(data); From patchwork Mon Oct 18 17:28:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tedd Ho-Jeong An X-Patchwork-Id: 12567493 X-Patchwork-Delegate: luiz.dentz@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59AEAC4332F for ; Mon, 18 Oct 2021 17:28:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4608B610C7 for ; Mon, 18 Oct 2021 17:28:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234126AbhJRRaz (ORCPT ); Mon, 18 Oct 2021 13:30:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234102AbhJRRay (ORCPT ); Mon, 18 Oct 2021 13:30:54 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 050CBC06161C for ; Mon, 18 Oct 2021 10:28:43 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id f21so11755965plb.3 for ; Mon, 18 Oct 2021 10:28:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=qBtLTgO0XNLNSg3e9uzJw7B6TjrjW0fhOnX+IBGEVRs=; b=pmg0N+0Pdagyd5IPP7T0uDf+OOPeuy8Y1+L5S8PGZ8cwfLgBCkEcP0uryLh2ew8JcV R78Swn13smX5Ort005jKGGDJBoAWXWkmYUn61sXKpX9EdriBBM4v4LmUvVTzftjb5xK9 YaIJ6Y45xyO3vmq7STqdoVlpVV12JkuuVOowlfKG6FD0ttsAnAQGrJZDJZhd7jAT+ckD lnnI2FaL8aDtwm4hz4mWx4WXJHs6qRoWwvJVMxLVA8AY2ibe/Ka/7QxOvOdmjZ+3Fmvg u5AYJ2rkZyjwg9PHf4M3OBZotwoCz5wBQxAm4qR4S6XnJlXxWMlMoDiJv+HEgTCHQqSr vJUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qBtLTgO0XNLNSg3e9uzJw7B6TjrjW0fhOnX+IBGEVRs=; b=zr7YPl3lxexRj0aVC/yAGZfHiddwQVXpRVVYylleZheIDfJlecKtf5dunqUu9npHOT r0SvdonGlhUmyhyTVxPfu2PF3DX6zAGayHE2LiZWQaHbtRV6w1ZP2p1Y3pO1C15F4EVi 10tNFRFcIPoYyELOk4Na6e75QsAJ5c91O3E4ir18BAjwAyLrcWJuF7xSXg3pwil62vUB 8bq0cLx8O4G4gRpn5p+tNAEmUcmPqxmD4BSyt3mtul5XnzI5e/gqyfEbtE4U0ABvl7CO pvJKIcAQ9ARCpmWZz9hRyFmK1mwv/GNAy2e3FgZfbQir6OBM35gFrWLr5XaqgDZqpbKh Tf+A== X-Gm-Message-State: AOAM530zbA6k7kZVZ8lmdhBuXOCY0hY0nc7+TevNVfm3ekhykaVBG6NW 4+IYfjSg5izo72jqcjsEqIbJh/aGvPRbOQ== X-Google-Smtp-Source: ABdhPJxvlklozO1rvxdCSb9cDdDgNG91LZa0DcjcN5wK8m8bmJgy8ecmPk0p/je2KzFlcwTm+WENyg== X-Received: by 2002:a17:90b:3a8b:: with SMTP id om11mr236457pjb.216.1634578122344; Mon, 18 Oct 2021 10:28:42 -0700 (PDT) Received: from han1-NUC8i7BEH.hsd1.or.comcast.net ([2601:1c0:6a01:d830:a510:aebd:a4ae:453c]) by smtp.gmail.com with ESMTPSA id fv9sm51156pjb.26.2021.10.18.10.28.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Oct 2021 10:28:42 -0700 (PDT) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH 4/9] plugins/admin: Fix unchecked return value Date: Mon, 18 Oct 2021 10:28:28 -0700 Message-Id: <20211018172833.534191-5-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211018172833.534191-1-hj.tedd.an@gmail.com> References: <20211018172833.534191-1-hj.tedd.an@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Tedd Ho-Jeong An This patch fixes the unchecked return value(CWE-252) issues reported by the Coverity. --- plugins/admin.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/plugins/admin.c b/plugins/admin.c index 7b7190a06..a8e7d2cd7 100644 --- a/plugins/admin.c +++ b/plugins/admin.c @@ -247,6 +247,7 @@ failed: static void store_policy_settings(struct btd_admin_policy *admin_policy) { GKeyFile *key_file = NULL; + GError *gerr = NULL; char *filename = ADMIN_POLICY_STORAGE; char *key_file_data = NULL; char **uuid_strs = NULL; @@ -274,7 +275,12 @@ static void store_policy_settings(struct btd_admin_policy *admin_policy) } key_file_data = g_key_file_to_data(key_file, &length, NULL); - g_file_set_contents(ADMIN_POLICY_STORAGE, key_file_data, length, NULL); + if (!g_file_set_contents(ADMIN_POLICY_STORAGE, key_file_data, length, + &gerr)) { + error("Unable set contents for %s: (%s)", ADMIN_POLICY_STORAGE, + gerr->message); + g_error_free(gerr); + } g_free(key_file_data); free_uuid_strings(uuid_strs, num_uuids); @@ -335,6 +341,7 @@ failed: static void load_policy_settings(struct btd_admin_policy *admin_policy) { GKeyFile *key_file; + GError *gerr = NULL; char *filename = ADMIN_POLICY_STORAGE; struct stat st; @@ -343,7 +350,11 @@ static void load_policy_settings(struct btd_admin_policy *admin_policy) key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } key_file_load_service_allowlist(key_file, admin_policy); From patchwork Mon Oct 18 17:28:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tedd Ho-Jeong An X-Patchwork-Id: 12567495 X-Patchwork-Delegate: luiz.dentz@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1551BC43217 for ; Mon, 18 Oct 2021 17:28:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F3BBB60EE9 for ; Mon, 18 Oct 2021 17:28:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234122AbhJRRa4 (ORCPT ); Mon, 18 Oct 2021 13:30:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234121AbhJRRaz (ORCPT ); Mon, 18 Oct 2021 13:30:55 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F1AAC06161C for ; Mon, 18 Oct 2021 10:28:43 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id l6so11730351plh.9 for ; Mon, 18 Oct 2021 10:28:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Br4XuJ9fwyEllCaKkS5Lu5qxgu2Hu1qKrQMaMgU5moo=; b=UCZ516YvOvbQHJkUlg08XWMI6pa7tcQKgr1xSuPQ8tacDF+47MnmrSy0zy7dc+CrcB ADemAdW+X072rF8XjC6GYEPDXelyJDXyHNIAEXHPZOtD2AtAPdpn85hGDMr1ZI7LhzM5 p4DFdWkqKgtpR17WDmB1f+atOvYXw5nQQiDjPwTZ87cBHoQRFICpNElfyAcchTV9kEdp twCcyVDUOF+KI6Z4F0HnTefHprSI9q1ISbAxLPz27M7ci4wWbfBzWEJ6aSKcUHBLJvp2 zCgr7uTRrSoLIbdAMxFNNZiSA9k5uok402GaZZPi2Mg9UB/XvmMUfr9fuUWIL0Js6jdP oq4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Br4XuJ9fwyEllCaKkS5Lu5qxgu2Hu1qKrQMaMgU5moo=; b=bORnQe0/vUvAqm/ISpyVpvuDCfhqIST02gVsRh7r3Ym341eRDO+4RYNFdpjLqXf3rU OSt1tlYMaouqxFZA9VfvM7wkDPUwaVwHP882ZymxoZrNb4juloEehRmw4hrlhZAbMEXa aqjpbgGtQ+EH9Sc1qhHMKEczTYujCN+u6CxjwPZOCxyRcUZKvxkxTFm1DOAsgT+dZIlO goaFmg7uSRAJRViozj02rM04MISK1Q0s2PAiMpiQhpY8tisGTDlbxk4YOmzSgY6MIf76 YvdLS4httfNd03SvFsudtZD4Te3C8d6ZDhurNvpUxALG+U8Cp9WnC7SmKA8xfM+cLi/M L0jQ== X-Gm-Message-State: AOAM530bS4ZFBCnqjlMrdMageN2VtASysW1jmNu5QmjgUiAX0nseyiN6 wgCUkVg2UZdZJ9KS9jZ16NqYlDYTWsD8KA== X-Google-Smtp-Source: ABdhPJx1/M8oq193D/LoGmg9+T1FCffMIgCGGrjHnaxWxmKBOp0S8FqXTe2SBnuOmVzVpyw2rCFnvw== X-Received: by 2002:a17:90b:1910:: with SMTP id mp16mr271356pjb.30.1634578123017; Mon, 18 Oct 2021 10:28:43 -0700 (PDT) Received: from han1-NUC8i7BEH.hsd1.or.comcast.net ([2601:1c0:6a01:d830:a510:aebd:a4ae:453c]) by smtp.gmail.com with ESMTPSA id fv9sm51156pjb.26.2021.10.18.10.28.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Oct 2021 10:28:42 -0700 (PDT) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH 5/9] profiles/a2dp: Fix unchecked return value Date: Mon, 18 Oct 2021 10:28:29 -0700 Message-Id: <20211018172833.534191-6-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211018172833.534191-1-hj.tedd.an@gmail.com> References: <20211018172833.534191-1-hj.tedd.an@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Tedd Ho-Jeong An This patch fixes the unchecked return value(CWE-252) issues reported by the Coverity. --- profiles/audio/a2dp.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c index 031ece628..eba2f9822 100644 --- a/profiles/audio/a2dp.c +++ b/profiles/audio/a2dp.c @@ -816,6 +816,7 @@ static void store_remote_seps(struct a2dp_channel *chan) char filename[PATH_MAX]; char dst_addr[18]; GKeyFile *key_file; + GError *gerr = NULL; char *data; gsize length = 0; @@ -828,7 +829,11 @@ static void store_remote_seps(struct a2dp_channel *chan) btd_adapter_get_storage_dir(device_get_adapter(device)), dst_addr); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } data = g_key_file_get_string(key_file, "Endpoints", "LastUsed", NULL); @@ -845,7 +850,11 @@ static void store_remote_seps(struct a2dp_channel *chan) } data = g_key_file_to_data(key_file, &length, NULL); - g_file_set_contents(filename, data, length, NULL); + if (!g_file_set_contents(filename, data, length, &gerr)) { + error("Unable set contents for %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } g_free(data); g_key_file_free(key_file); @@ -981,6 +990,7 @@ static void store_last_used(struct a2dp_channel *chan, uint8_t lseid, uint8_t rseid) { GKeyFile *key_file; + GError *gerr = NULL; char filename[PATH_MAX]; char dst_addr[18]; char value[6]; @@ -993,14 +1003,22 @@ static void store_last_used(struct a2dp_channel *chan, uint8_t lseid, btd_adapter_get_storage_dir(device_get_adapter(chan->device)), dst_addr); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } sprintf(value, "%02hhx:%02hhx", lseid, rseid); g_key_file_set_string(key_file, "Endpoints", "LastUsed", value); data = g_key_file_to_data(key_file, &len, NULL); - g_file_set_contents(filename, data, len, NULL); + if (!g_file_set_contents(filename, data, len, &gerr)) { + error("Unable set contents for %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } g_free(data); g_key_file_free(key_file); @@ -2218,6 +2236,7 @@ static void load_remote_seps(struct a2dp_channel *chan) char dst_addr[18]; char **keys; GKeyFile *key_file; + GError *gerr = NULL; ba2str(device_get_address(device), dst_addr); @@ -2225,7 +2244,11 @@ static void load_remote_seps(struct a2dp_channel *chan) btd_adapter_get_storage_dir(device_get_adapter(device)), dst_addr); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } keys = g_key_file_get_keys(key_file, "Endpoints", NULL, NULL); load_remote_sep(chan, key_file, keys); From patchwork Mon Oct 18 17:28:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tedd Ho-Jeong An X-Patchwork-Id: 12567497 X-Patchwork-Delegate: luiz.dentz@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4EAAEC433EF for ; Mon, 18 Oct 2021 17:28:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3E42C61077 for ; Mon, 18 Oct 2021 17:28:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234138AbhJRRa5 (ORCPT ); Mon, 18 Oct 2021 13:30:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234125AbhJRRaz (ORCPT ); Mon, 18 Oct 2021 13:30:55 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 540E7C06161C for ; Mon, 18 Oct 2021 10:28:44 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id n11so11751865plf.4 for ; Mon, 18 Oct 2021 10:28:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=81EVcq6gCmuUBjFDCUIL/Fcgync/V07YYoweuxYtC3M=; b=kwDZFy2q/qzCtyTiwWw3Wuxm6xhtmgma7qLtq8KVxysZV0PPBcEjsIgKk4yw7uwonZ H84FEOuSEomf2yy5KCmkPkSv4P46qqV+hWQ0o5F9C0er8XDSnDYzXX+MZDGimdzP3tx0 LoFCC6ffqE3gxQwrWlMeCprXR8AgbGazhQ7Rxru95aR8qedvzyYbQCdOZcnlt+AAqdo7 xeCvyvk/j+4WxvCpJvi6hX8zPm/XVJq2CMRXiRgDazCdlHJzv1ig202epYdJBIJ/C12H 3yfBkZQiqegVjTY9tOejH+/mFdWl0aHDvvIZdhUkJJ9k5Huub5jbfPpwFdu6Kxf4RfZj lfxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=81EVcq6gCmuUBjFDCUIL/Fcgync/V07YYoweuxYtC3M=; b=c4eOhtRIiVcdtAPkZ/g7tTnHEfNHbunDJ7Ol31a31DT7Bg0u0WqriQgm+kRviiidxq lwIEwldDFwWauHGBgaB+DNslgpyLRAA6g1yHzXi3qAk1W7VXb5CgjBXG21rQfdo5dX7e hrMO9xOuEJx/QYu2SZUR3ujAyiOSdtZXcpwcTJf906h6V5ojYuw11c7CHFs6BCtqtAJX UPhOXcKFgY0Zcd41HZci/xgSBmEXDeZufzvdnVLg3rbkAHsGLZJpxScawGQHjNlGwLef UNdEa8yNIOab8v+2WbuPutWFyORlnVmri75oCAA63/HcvlXuOnUAGCzD+vYLDd2frAX1 yq1Q== X-Gm-Message-State: AOAM53073ZE/79uMVkjqUwPX33zobthIFy9Mq/UQFrLqlANApub8FgFA ZUmFsvyVHw80qIlYOmVTQKpAjAYc8duG0Q== X-Google-Smtp-Source: ABdhPJzHPAR59cZWDMZqqopxugmvAZDV1y4hCuTT7AZ5tFXCz+w1K0rHsI0qdvuJAmzhe3MUFFzwhw== X-Received: by 2002:a17:90b:4a92:: with SMTP id lp18mr227728pjb.47.1634578123651; Mon, 18 Oct 2021 10:28:43 -0700 (PDT) Received: from han1-NUC8i7BEH.hsd1.or.comcast.net ([2601:1c0:6a01:d830:a510:aebd:a4ae:453c]) by smtp.gmail.com with ESMTPSA id fv9sm51156pjb.26.2021.10.18.10.28.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Oct 2021 10:28:43 -0700 (PDT) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH 6/9] profiles/input: Fix unchecked return value Date: Mon, 18 Oct 2021 10:28:30 -0700 Message-Id: <20211018172833.534191-7-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211018172833.534191-1-hj.tedd.an@gmail.com> References: <20211018172833.534191-1-hj.tedd.an@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Tedd Ho-Jeong An This patch fixes the unchecked return value(CWE-252) issues reported by the Coverity. --- profiles/input/device.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/profiles/input/device.c b/profiles/input/device.c index 50ae51855..013899211 100644 --- a/profiles/input/device.c +++ b/profiles/input/device.c @@ -1050,7 +1050,11 @@ static int hidp_add_connection(struct input_device *idev) sprintf(handle, "0x%8.8X", idev->handle); key_file = g_key_file_new(); - g_key_file_load_from_file(key_file, filename, 0, NULL); + if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { + error("Unable to load key file from %s: (%s)", filename, + gerr->message); + g_error_free(gerr); + } str = g_key_file_get_string(key_file, "ServiceRecords", handle, NULL); g_key_file_free(key_file); From patchwork Mon Oct 18 17:28:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tedd Ho-Jeong An X-Patchwork-Id: 12567499 X-Patchwork-Delegate: luiz.dentz@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6E79C433FE for ; Mon, 18 Oct 2021 17:28:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C44B861074 for ; Mon, 18 Oct 2021 17:28:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234127AbhJRRa6 (ORCPT ); Mon, 18 Oct 2021 13:30:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234124AbhJRRa4 (ORCPT ); Mon, 18 Oct 2021 13:30:56 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B011C06161C for ; Mon, 18 Oct 2021 10:28:45 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id d5so2431896pfu.1 for ; Mon, 18 Oct 2021 10:28:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=bMZac6HBMIWUpPhHFGa//A7khAdmsR+VAlHEvV+faD0=; b=hKDrResEzLHk4GiEKVfjm8cehvzZMuRfkZa6eSMcqcyy/N5ZJkolxWdv445PH7CKJV Bs5soyxgVC3egtsE1pj9jgFahFo2xFYVuQxJce5Hgq6AdoBWcrJKEOkos0XbzvpkFlxw CANZS4YXszG0x8sIq/0dPLRVYHkY7r2BtaT//8iRoCinyRicYcg8x1FiT1i8U0rmwwI9 CHv7KRXzmnHbDh/qCgN225gj4NFqt19SMT4VHyq83tszPwrga/V/CoDfUj89vAZsdrK9 H5irVWyfz74kEdD9zJHJrdtTge0b+NuNaoebFnzz++mIaTqalzccWjrTmQCKovoYzAOI koRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bMZac6HBMIWUpPhHFGa//A7khAdmsR+VAlHEvV+faD0=; b=7YoARbFDceiEJZSzvwhvjyqtV0btPgxGVZmY8RQLA0RCCFg4HcDyexpPqFn+67IDnR 3rIwWP74w+yt1/kcC+rcrB5Hywg4EyrokLy1mfL/KddQYYZzkJql4xaHTSrxj+qja+6Y kDadpJa2LAmp2StBm/HTvmR7Usb5NfG3KIw5+mib5gvmX9Q0H3EupwQXUov+pzlM1gBP RFhp2WpSohcOeSpTKh6BDX6qWi+fpGcnI1avJ5nO6TCBwkYfQPAVBrc9FdUyjZ7NL4eK lzT6z1/kZQRAmurvpy5PYlTSSXt8mY60wK+CLDiOPokD+FRiDHOEgtxw62MFXdyhrTrb BMgw== X-Gm-Message-State: AOAM532dRX/GbhmfhT4acWqwY8tbkVHwntH6NwKMKs4SaiWGQM5Vf0Pn X9hOGGd1gqYZy5BCZkvry6RelDBK+/qVvQ== X-Google-Smtp-Source: ABdhPJyShU11uPrF4mBnQqd6ajND3G62aAyIqIIE5KyTXQDoY/PtmZqSlSZb1z94XUFSxSxMlShTjg== X-Received: by 2002:a63:7055:: with SMTP id a21mr18901870pgn.338.1634578124356; Mon, 18 Oct 2021 10:28:44 -0700 (PDT) Received: from han1-NUC8i7BEH.hsd1.or.comcast.net ([2601:1c0:6a01:d830:a510:aebd:a4ae:453c]) by smtp.gmail.com with ESMTPSA id fv9sm51156pjb.26.2021.10.18.10.28.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Oct 2021 10:28:43 -0700 (PDT) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH 7/9] mesh: Fix unchecked return value Date: Mon, 18 Oct 2021 10:28:31 -0700 Message-Id: <20211018172833.534191-8-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211018172833.534191-1-hj.tedd.an@gmail.com> References: <20211018172833.534191-1-hj.tedd.an@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Tedd Ho-Jeong An This patch fixes the unchecked return value(CWE-252) issues reported by the Coverity. --- mesh/keyring.c | 6 ++++-- mesh/mesh-io-unit.c | 6 ++++-- mesh/rpl.c | 22 ++++++++++++++-------- mesh/util.c | 11 ++++++++--- 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/mesh/keyring.c b/mesh/keyring.c index 4b901643c..51621777d 100644 --- a/mesh/keyring.c +++ b/mesh/keyring.c @@ -50,7 +50,8 @@ static int open_key_file(struct mesh_node *node, const char *key_dir, if (flags & O_CREAT) { snprintf(fname, PATH_MAX, "%s%s", node_path, key_dir); - mkdir(fname, 0755); + if (mkdir(fname, 0755) != 0) + l_error("Failed to create dir(%d): %s", errno, fname); } snprintf(fname, PATH_MAX, "%s%s/%3.3x", node_path, key_dir, idx); @@ -206,7 +207,8 @@ bool keyring_put_remote_dev_key(struct mesh_node *node, uint16_t unicast, snprintf(key_file, PATH_MAX, "%s%s", node_path, dev_key_dir); - mkdir(key_file, 0755); + if (mkdir(key_file, 0755) != 0) + l_error("Failed to create dir(%d): %s", errno, key_file); for (i = 0; i < count; i++) { snprintf(key_file, PATH_MAX, "%s%s/%4.4x", node_path, diff --git a/mesh/mesh-io-unit.c b/mesh/mesh-io-unit.c index c5aae6741..f4b615ac8 100644 --- a/mesh/mesh-io-unit.c +++ b/mesh/mesh-io-unit.c @@ -133,7 +133,8 @@ static bool incoming(struct l_io *sio, void *user_data) buf[0] = 0; memcpy(buf + 1, pvt->unique_name, size + 1); - send(pvt->fd, buf, size + 2, MSG_DONTWAIT); + if (send(pvt->fd, buf, size + 2, MSG_DONTWAIT) < 0) + l_error("Failed to send(%d)", errno); } return true; @@ -304,7 +305,8 @@ static bool simple_match(const void *a, const void *b) static void send_pkt(struct mesh_io_private *pvt, struct tx_pkt *tx, uint16_t interval) { - send(pvt->fd, tx->pkt, tx->len, MSG_DONTWAIT); + if (send(pvt->fd, tx->pkt, tx->len, MSG_DONTWAIT) < 0) + l_error("Failed to send(%d)", errno); if (tx->delete) { l_queue_remove_if(pvt->tx_pkts, simple_match, tx); diff --git a/mesh/rpl.c b/mesh/rpl.c index c53c6fbfd..9a99afe7b 100644 --- a/mesh/rpl.c +++ b/mesh/rpl.c @@ -18,6 +18,7 @@ #include #include #include +#include #include @@ -54,9 +55,10 @@ bool rpl_put_entry(struct mesh_node *node, uint16_t src, uint32_t iv_index, iv_index); dir = opendir(src_file); - if (!dir) - mkdir(src_file, 0755); - else + if (!dir) { + if (mkdir(src_file, 0755) != 0) + l_error("Failed to create dir: %s", src_file); + } else closedir(dir); snprintf(src_file, PATH_MAX, "%s%s/%8.8x/%4.4x", node_path, rpl_dir, @@ -78,8 +80,8 @@ bool rpl_put_entry(struct mesh_node *node, uint16_t src, uint32_t iv_index, iv_index--; snprintf(src_file, PATH_MAX, "%s%s/%8.8x/%4.4x", node_path, rpl_dir, iv_index, src); - remove(src_file); - + if (remove(src_file) < 0) + l_error("Failed to remove(%d): %s", errno, src_file); return result; } @@ -110,7 +112,9 @@ void rpl_del_entry(struct mesh_node *node, uint16_t src) if (entry->d_type == DT_DIR && entry->d_name[0] != '.') { snprintf(rpl_path, PATH_MAX, "%s%s/%s/%4.4x", node_path, rpl_dir, entry->d_name, src); - remove(rpl_path); + if (remove(rpl_path) < 0) + l_error("Failed to remove(%d): %s", errno, + rpl_path); } } @@ -251,7 +255,8 @@ void rpl_update(struct mesh_node *node, uint32_t cur) /* Make sure path exists */ snprintf(path, PATH_MAX, "%s%s", node_path, rpl_dir); - mkdir(path, 0755); + if (mkdir(path, 0755) != 0) + l_error("Failed to create dir(%d): %s", errno, path); dir = opendir(path); if (!dir) @@ -288,6 +293,7 @@ bool rpl_init(const char *node_path) return false; snprintf(path, PATH_MAX, "%s%s", node_path, rpl_dir); - mkdir(path, 0755); + if (mkdir(path, 0755) != 0) + l_error("Failed to create dir(%d): %s", errno, path); return true; } diff --git a/mesh/util.c b/mesh/util.c index 308e7d998..d505e7a0c 100644 --- a/mesh/util.c +++ b/mesh/util.c @@ -14,6 +14,7 @@ #define _GNU_SOURCE #include +#include #include #include #include @@ -117,12 +118,14 @@ int create_dir(const char *dir_name) } strncat(dir, prev + 1, next - prev); - mkdir(dir, 0755); + if (mkdir(dir, 0755) != 0) + l_error("Failed to create dir(%d): %s", errno, dir); prev = next; } - mkdir(dir_name, 0755); + if (mkdir(dir_name, 0755) != 0) + l_error("Failed to create dir(%d): %s", errno, dir_name); return 0; } @@ -138,7 +141,9 @@ static int del_fobject(const char *fpath, const struct stat *sb, int typeflag, case FTW_SL: default: - remove(fpath); + if (remove(fpath) < 0) + l_error("Failed to remove(%d): %s", errno, fpath); + l_debug("RM %s", fpath); break; } From patchwork Mon Oct 18 17:28:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tedd Ho-Jeong An X-Patchwork-Id: 12567501 X-Patchwork-Delegate: luiz.dentz@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7B3CC433EF for ; Mon, 18 Oct 2021 17:28:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B0B9D6108E for ; Mon, 18 Oct 2021 17:28:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234140AbhJRRa7 (ORCPT ); Mon, 18 Oct 2021 13:30:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234121AbhJRRa5 (ORCPT ); Mon, 18 Oct 2021 13:30:57 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88C8FC061745 for ; Mon, 18 Oct 2021 10:28:45 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id s1so9926794plg.12 for ; Mon, 18 Oct 2021 10:28:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=il+5MXJHi06XKAsguhIoTzyIIoTFUOdDa4x0oU/Hk44=; b=GuNtyz9uIpcmnsKxitUG8iG+hyCLvmTDJ4DScS0j/rvx0t1Do851QH00uFQ9kNXaLm 5I1bryIi1GZVkmFnrUtVg4XwdqHQd+yHmTcVbZidwvYtX1f/wWUTrgIBD88sahO6xQQq OuRX1De+5omhGVfCeSvIe9StKsZaMZv9n+AuQw+AAK3UmeLJq/4Xsg6yxZAbpHqZ4hlD Lhq14/5CRtrZuTBSiAzB/ZoOtYLMHh4nRccV/3fQJynROlS39sVMfnU/FzwptXduoTaz 9Sp+JXLlViy3UiRbt4b34CXu0MezC4BB6IX0uRKHyXhDbDsyzh5t4zj8tiWzLXC94/op Axkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=il+5MXJHi06XKAsguhIoTzyIIoTFUOdDa4x0oU/Hk44=; b=31bBmo7Gmyd82OlmT7VS6jGIzV6qA4/tY3SrTCw1Bg41CK57c2/pNAAX1DMd9eJ/KK AIRXttjR8cxEEVj+Lohnt3ieFAnXy1EJMMqLUTOPCfrx4GtnciyxefpxwtnNW649iu0J p4a8PgBfYyJucw7rWxPuUOfBHzVCl6vbeUqA6FnQ+txADIXO/Cq8Wgxy9fVk8nWTOiGv zDk2gNp7DFNmJtBAzCK6Hn4RohVkIYPT7OArmCyufMu5KNN+b8Z4FPDEKY0eHAFhTqmE aP0kmbyk2bVSzSY7KBhb8Tw5C5bfo1m4lkLrc9W7q5+aNnGtPLu12Scs+WEiGG55donF Y9Zw== X-Gm-Message-State: AOAM532iIKK+kAvbjn3c7rTeelBTCRVtgpSjFOI/57HuSXsEnVJ2hIJ3 gq04iZdWqmv9cFM2o4zhFnoyhvq1JqwHAg== X-Google-Smtp-Source: ABdhPJygUQG4JwUO/x8JpB43I9ezUv9/KqbKS0b1rAZXBTuaFhPLlOQlL04P+7fGQgGmehsm7bJnPw== X-Received: by 2002:a17:90b:3850:: with SMTP id nl16mr209435pjb.127.1634578124905; Mon, 18 Oct 2021 10:28:44 -0700 (PDT) Received: from han1-NUC8i7BEH.hsd1.or.comcast.net ([2601:1c0:6a01:d830:a510:aebd:a4ae:453c]) by smtp.gmail.com with ESMTPSA id fv9sm51156pjb.26.2021.10.18.10.28.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Oct 2021 10:28:44 -0700 (PDT) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH 8/9] obexd: Fix unchecked return value Date: Mon, 18 Oct 2021 10:28:32 -0700 Message-Id: <20211018172833.534191-9-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211018172833.534191-1-hj.tedd.an@gmail.com> References: <20211018172833.534191-1-hj.tedd.an@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Tedd Ho-Jeong An This patch fixes the unchecked return value(CWE-252) issues reported by the Coverity. --- obexd/client/transfer.c | 12 +++++++++--- obexd/plugins/pcsuite.c | 4 +++- obexd/src/main.c | 4 +++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/obexd/client/transfer.c b/obexd/client/transfer.c index 744d8f106..dccce03b4 100644 --- a/obexd/client/transfer.c +++ b/obexd/client/transfer.c @@ -420,8 +420,11 @@ static void obc_transfer_free(struct obc_transfer *transfer) if (transfer->op == G_OBEX_OP_GET && transfer->status != TRANSFER_STATUS_COMPLETE && - transfer->filename) - remove(transfer->filename); + transfer->filename) { + if (remove(transfer->filename) < 0) + error("remove(%s): %s(%d)", transfer->filename, + strerror(errno), errno); + } if (transfer->fd > 0) close(transfer->fd); @@ -521,7 +524,10 @@ static gboolean transfer_open(struct obc_transfer *transfer, int flags, } if (transfer->filename == NULL) { - remove(filename); /* remove always only if NULL was given */ + /* remove always only if NULL was given */ + if (remove(filename) < 0) + error("remove(%s): %s(%d)", filename, strerror(errno), + errno); g_free(filename); } else { g_free(transfer->filename); diff --git a/obexd/plugins/pcsuite.c b/obexd/plugins/pcsuite.c index b2232ea09..f5a9d9ae8 100644 --- a/obexd/plugins/pcsuite.c +++ b/obexd/plugins/pcsuite.c @@ -219,7 +219,9 @@ static void pcsuite_disconnect(struct obex_session *os, void *user_data) close(pcsuite->fd); if (pcsuite->lock_file) { - remove(pcsuite->lock_file); + if (remove(pcsuite->lock_file) < 0) + error("remove(%s): %s(%d)", pcsuite->lock_file, + strerror(errno), errno); g_free(pcsuite->lock_file); } diff --git a/obexd/src/main.c b/obexd/src/main.c index 04284c9e1..d950883f0 100644 --- a/obexd/src/main.c +++ b/obexd/src/main.c @@ -270,7 +270,9 @@ int main(int argc, char *argv[]) if (option_root == NULL) { option_root = g_build_filename(g_get_user_cache_dir(), "obexd", NULL); - g_mkdir_with_parents(option_root, 0700); + if (g_mkdir_with_parents(option_root, 0700) < 0) + error("Failed to create dir(%d): %s", errno, + option_root); } if (option_root[0] != '/') { From patchwork Mon Oct 18 17:28:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tedd Ho-Jeong An X-Patchwork-Id: 12567503 X-Patchwork-Delegate: luiz.dentz@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2BC54C433FE for ; Mon, 18 Oct 2021 17:28:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0EB4660EE9 for ; Mon, 18 Oct 2021 17:28:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234143AbhJRRa7 (ORCPT ); Mon, 18 Oct 2021 13:30:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234139AbhJRRa5 (ORCPT ); Mon, 18 Oct 2021 13:30:57 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28238C06161C for ; Mon, 18 Oct 2021 10:28:46 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id v8so11129029pfu.11 for ; Mon, 18 Oct 2021 10:28:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=tNVd5nqsmkaPr48wbyHKgypDx1r3nVB4GCcN6zm3DF8=; b=BkIsPfFTqGZLgaKMf4iRVEzTqWL58NcRphEsC5dW6aQMD/tkn3zP7xGJXMokzMWJD5 f7/Ws/+ivrsyMhznMi/zWcTAlx2ahQcCh/FW+TvjrrA0DyokWdF4tWN4rymqtQT7aErp Gndy3+gBQyXUMYVLOCox3QJIyXJeOIm71+5UmGjRRvFV5vnjdsm5lQWwo6NEe9NuL19j LEGu2NdV4hUGe6gC+G6O0zVEYq0Kc1liN4DyzAGbaGP6uA5spGNquoSOT7doknl3q4Y/ kxiW6OteLcbEvRo7oPNmJ9HnYn/3bmaZ8xpvzCWOcivoTisMviyziu9MoUlFALuJsIox ygIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tNVd5nqsmkaPr48wbyHKgypDx1r3nVB4GCcN6zm3DF8=; b=IB7R3mQkijbwVSAjYPqTvDN2JPQuBYqUQXu3Fu7LkH7tAqKHIq4dtQZLjszMVhRkW7 rIIIuEuY3KB5Nh7FkDALrswq+F89vS2zIlKm5JfsfvtkqjZNviRqF9gmb3/TVUof2ljf 1CSkzWqSb5XjyqFFo56rKiqTKEHEt3hZn2Yz1NUq513cpSO771QrJctd4+sASENXByxR bOzxMaKhEO7z8qZNFB2YcSilYdU7DhtHl05ltMtzHYsPw+aCaIBcg2pI4/UMLkhG22OD 6IhGOjMROGR7dce/A8uMmBeQWGGvPJ6cxg/SQ3cH8wuKKgLzwjhHqXKMomI++6SY1hoH s3lw== X-Gm-Message-State: AOAM531no94AOeToBy8faS0pJNlQv+OJ4R77oJiFfyCE76rn1snHhFfh ECtpOIqpBXqEEeafnfS5dW7+s1oEpkybgg== X-Google-Smtp-Source: ABdhPJyEAO6fZpH3c9eO7hfu4FwUvQvIgQgZWBsP/AvRdQDVEzyTucBIL6NZq1SUV4Qwcc18nhOp0w== X-Received: by 2002:a63:ea58:: with SMTP id l24mr25055253pgk.334.1634578125519; Mon, 18 Oct 2021 10:28:45 -0700 (PDT) Received: from han1-NUC8i7BEH.hsd1.or.comcast.net ([2601:1c0:6a01:d830:a510:aebd:a4ae:453c]) by smtp.gmail.com with ESMTPSA id fv9sm51156pjb.26.2021.10.18.10.28.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Oct 2021 10:28:45 -0700 (PDT) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH 9/9] peripheral: Fix unchecked return value Date: Mon, 18 Oct 2021 10:28:33 -0700 Message-Id: <20211018172833.534191-10-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211018172833.534191-1-hj.tedd.an@gmail.com> References: <20211018172833.534191-1-hj.tedd.an@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Tedd Ho-Jeong An This patch fixes the unchecked return value(CWE-252) issues reported by the Coverity. --- peripheral/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/peripheral/main.c b/peripheral/main.c index 6ce729178..86b52236e 100644 --- a/peripheral/main.c +++ b/peripheral/main.c @@ -77,7 +77,8 @@ static void prepare_filesystem(void) if (lstat(mount_table[i].target, &st) < 0) { printf("Creating %s\n", mount_table[i].target); - mkdir(mount_table[i].target, 0755); + if (mkdir(mount_table[i].target, 0755) < 0) + perror("Failed to create dir"); } printf("Mounting %s to %s\n", mount_table[i].fstype,