From patchwork Fri Feb 11 02:00:52 2022 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: 541888 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E50E8C433F5 for ; Fri, 11 Feb 2022 02:00:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347069AbiBKCA5 (ORCPT ); Thu, 10 Feb 2022 21:00:57 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:57402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244359AbiBKCA4 (ORCPT ); Thu, 10 Feb 2022 21:00:56 -0500 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D429A2A3 for ; Thu, 10 Feb 2022 18:00:56 -0800 (PST) Received: by mail-pf1-x42b.google.com with SMTP id a39so12743921pfx.7 for ; Thu, 10 Feb 2022 18:00:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=4c4lSDhQw9gBes/CzLEVSAVialIXB+yXKGpThtYQ4/Q=; b=g6GA2AFoXwsO8DwkBn2Uc0Nrv/UBDXyJ93OLTJ6KSxDahyvXuLL4QPuf6BzELhzav6 olZOTgkjZ2f2zDUEV5hOMWIebISauohzOmVeak4Lojukl5cDwoyurJKf+I26yv0jDjKP kdkJovVBh3ecI+kaToh/VJevZrqt/dfDnQCpjTJsiNuacbwmLeZ/EcTrKfsOOU9vZD7Q Z100VfC4RcF+EAc0JYekJlOczFpv+HmobUDddVKi/yZJsWeKKc8olbJsEtCozP9zH+0X f10bej7HKRY5E+IzuF6GN06UiuS5djcmooMbUJMDFitbjE6Q6rXZLtxqQSMC1iItlCmU 9BlQ== 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:mime-version :content-transfer-encoding; bh=4c4lSDhQw9gBes/CzLEVSAVialIXB+yXKGpThtYQ4/Q=; b=4QnR/X1TmEJhT8l3YkYKvMAJ0M3nFLpgYeR004gERKuFBareJWEk4LHXR7uP0s2Oxt o98UwNLyAVP7FpuHk/K2uvXUakEWelyIz8pMPh/7ki5+ujey9ocr2xxYUdGyJAukaILw Dynj3r3PgdWaoZcLmsyOiPgKTdBsEVuHQNASQ2JRvClox1jvsawX09tH4wuPco52I2pm rna2eKnp9hAaoXRcT+JP8bC5/8k9r5q8eVXTTlJIxOBWmVloNn+8yVMDmjUdupyk4bdd v9P3t4PJNWeEhMEmYNwICN0yPYrehFF25Qj0Q/q3+Lgm+vyTH5AtI0pDrsb5OPnco7eK Udzg== X-Gm-Message-State: AOAM531LL5vYw7IVzP831rNSuZUkJebdCKc/p7frUjEublw+pZiaGJ6P EBsvtXp477KsHYbeMm2xv/twJPyQ1lU= X-Google-Smtp-Source: ABdhPJzYtz7XE1At3Rpa9p8JGx0rDsiBB50NBaFVLcTVGorA4HEkxVitBqmTqM2rVOXyXwqNhU1xnA== X-Received: by 2002:a63:1a21:: with SMTP id a33mr8451702pga.35.1644544855896; Thu, 10 Feb 2022 18:00:55 -0800 (PST) Received: from han1-NUC8i7BEH.hsd1.or.comcast.net ([2601:1c0:6a01:d830::169b]) by smtp.gmail.com with ESMTPSA id b2sm17752759pgg.59.2022.02.10.18.00.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 18:00:55 -0800 (PST) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH 1/3] adapter: Fix the reusing gerror without re-initialization Date: Thu, 10 Feb 2022 18:00:52 -0800 Message-Id: <20220211020054.28534-1-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Tedd Ho-Jeong An When the GError variable is freeed with g_error_free(), it is not set to NULL and reusing the same variable again can cause the seg_fault because it is still pointing the old memory address which is freed. This patch relaces the g_error_free() to g_clear_error() which frees the variable and set it to NULL if the variable is used in the function again. Fixes: 2287c517ca1bd ("adapter: Fix unchecked return value") Fixes: https://github.com/bluez/bluez/issues/276 --- src/adapter.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/adapter.c b/src/adapter.c index 3ee98431d..eef50f67a 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -4676,7 +4676,7 @@ static void load_devices(struct btd_adapter *adapter) 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_clear_error(&gerr); } key_info = get_key_info(key_file, entry->d_name); @@ -5662,7 +5662,7 @@ static void convert_names_entry(char *key, char *value, void *user_data) 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_clear_error(&gerr); } g_key_file_set_string(key_file, "General", "Name", value); @@ -5895,7 +5895,7 @@ static void convert_entry(char *key, char *value, void *user_data) 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_clear_error(&gerr); } set_device_type(key_file, type); @@ -6001,7 +6001,7 @@ static void store_sdp_record(char *local, char *peer, int handle, char *value) 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_clear_error(&gerr); } sprintf(handle_str, "0x%8.8X", handle); @@ -6085,7 +6085,7 @@ static void convert_sdp_entry(char *key, char *value, void *user_data) 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_clear_error(&gerr); } store_attribute_uuid(key_file, start, end, prim_uuid, uuid); @@ -6145,7 +6145,7 @@ static void convert_primaries_entry(char *key, char *value, void *user_data) 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_clear_error(&gerr); } for (service = services; *service; service++) { @@ -6170,7 +6170,7 @@ static void convert_primaries_entry(char *key, char *value, void *user_data) if (!g_file_set_contents(filename, data, length, &gerr)) { error("Unable set contents for %s: (%s)", filename, gerr->message); - g_error_free(gerr); + g_clear_error(&gerr); } if (device_type < 0) @@ -6185,7 +6185,7 @@ static void convert_primaries_entry(char *key, char *value, void *user_data) 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_clear_error(&gerr); } set_device_type(key_file, device_type); @@ -6241,7 +6241,7 @@ static void convert_ccc_entry(char *key, char *value, void *user_data) 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_clear_error(&gerr); } sprintf(group, "%hu", handle); @@ -6297,7 +6297,7 @@ static void convert_gatt_entry(char *key, char *value, void *user_data) 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_clear_error(&gerr); } sprintf(group, "%hu", handle); @@ -6352,7 +6352,7 @@ static void convert_proximity_entry(char *key, char *value, void *user_data) 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_clear_error(&gerr); } g_key_file_set_string(key_file, alert, "Level", value); @@ -6556,7 +6556,7 @@ static void load_config(struct btd_adapter *adapter) 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_clear_error(&gerr); } /* Get alias */ @@ -8313,7 +8313,7 @@ static void store_ltk_group(struct btd_adapter *adapter, const bdaddr_t *peer, 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_clear_error(&gerr); } for (i = 0; i < 16; i++) @@ -8479,7 +8479,7 @@ static void store_csrk(struct btd_adapter *adapter, const bdaddr_t *peer, 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_clear_error(&gerr); } for (i = 0; i < 16; i++) @@ -8657,7 +8657,7 @@ static void store_conn_param(struct btd_adapter *adapter, const bdaddr_t *peer, 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_clear_error(&gerr); } g_key_file_set_integer(key_file, "ConnectionParameters", @@ -9316,7 +9316,7 @@ static void remove_keys(struct btd_adapter *adapter, 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_clear_error(&gerr); } if (type == BDADDR_BREDR) { @@ -9418,7 +9418,7 @@ static bool get_static_addr(struct btd_adapter *adapter) &gerr)) { error("Unable to load key file from %s: (%s)", STORAGEDIR "/addresses", gerr->message); - g_error_free(gerr); + g_clear_error(&gerr); } addrs = g_key_file_get_string_list(file, "Static", mfg, &len, NULL); if (addrs) { From patchwork Fri Feb 11 02:00:53 2022 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: 541887 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A972C433FE for ; Fri, 11 Feb 2022 02:00:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347084AbiBKCA6 (ORCPT ); Thu, 10 Feb 2022 21:00:58 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:57410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347045AbiBKCA5 (ORCPT ); Thu, 10 Feb 2022 21:00:57 -0500 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4546B5F48 for ; Thu, 10 Feb 2022 18:00:57 -0800 (PST) Received: by mail-pj1-x102b.google.com with SMTP id k60-20020a17090a4cc200b001b932781f3eso3135302pjh.0 for ; Thu, 10 Feb 2022 18:00:57 -0800 (PST) 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=WAQz1cmq7S+46Q19Se7FctEmdzmieMxLeZeEwTRluAA=; b=ocaDmjuxFlfiYVeIJ3rXTBcAOUnAZPXDPjT0qu2LoPdObMGqa20/0gU560JvHkUVat 97T4nSMX7ciHymHHYZ74eR5Ld+aIfXoVgEjweXdh4lW2RscK+q+2qPfwK+GXEb7uixT9 cjAHLNZm5PJktrvnlQ4CyBMZZkpB7WsaAjOuiU/1ms+hILlKF9yuYufoyrYasAVeWQGM lyzPimYRE76e9nlsZDn6O0HDKW46EWhut+/APvcTzFs75omcb2sKOlF2hDlDYzgnFeQS jECvxEpqsuR8o6hKjAjWE/nhUnpRSULfzF2HrdUJZ36WlmZ9lj2VljhBCx38TgTK8Yg+ pJpQ== 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=WAQz1cmq7S+46Q19Se7FctEmdzmieMxLeZeEwTRluAA=; b=O9v4rykfWYeN2a6D2OK3oWvZh07FgMZOkn5cEBcudujO3ljD8oSM2adDWMpBGSQEXm DGVOpjFw9a5Iv08VLNh0ne1qsfEbp19mfgWZ9/QxI/NEaNuWC79mQJb5KMTFtnK7sVDA 5Nmn+lBBZ1ZBmxMps6t2u4wUQwVwEeWRKcINDxibTWNhJ85KZMkSMqLNvMzoe36arcal aSdP2Nfv/0y/FmyemF4n94R09A9jvVuyrIFvMGowsAIm3O8CDOzZWFKAwBITcuCfwBRp an94jaNUx+3uxJYJT8Aj4avdArg5kPTI5gsK5ViSKqIF7RjQBTiGqTFuAYK7joZWyTmC 98FA== X-Gm-Message-State: AOAM5326vANTK8s7Q9/6ikfiPUpDHYIAJz7JTAFATM0CEYdSY0L9WvGr OuWx4Wlg9jseWlgIlIPEUGul3TYo9UA= X-Google-Smtp-Source: ABdhPJx5YUslb7lhB/NM590f4ZASXvUs1/PiFzCfdyL8Qj/UVLnnkYlZm+BkCgS96i8McjhkO/eIrw== X-Received: by 2002:a17:90b:350c:: with SMTP id ls12mr313898pjb.182.1644544856537; Thu, 10 Feb 2022 18:00:56 -0800 (PST) Received: from han1-NUC8i7BEH.hsd1.or.comcast.net ([2601:1c0:6a01:d830::169b]) by smtp.gmail.com with ESMTPSA id b2sm17752759pgg.59.2022.02.10.18.00.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 18:00:56 -0800 (PST) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH 2/3] device: Fix the reusing gerror without re-initialization Date: Thu, 10 Feb 2022 18:00:53 -0800 Message-Id: <20220211020054.28534-2-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220211020054.28534-1-hj.tedd.an@gmail.com> References: <20220211020054.28534-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 When the GError variable is freeed with g_error_free(), it is not set to NULL and reusing the same variable again can cause the seg_fault because it is still pointing the old memory address which is freed. This patch relaces the g_error_free() to g_clear_error() which frees the variable and set it to NULL if the variable is used in the function again. Fixes: 6a154cd08000b ("device: Fix unchecked return value") --- src/device.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/device.c b/src/device.c index 6d29eb896..6a7bdd207 100644 --- a/src/device.c +++ b/src/device.c @@ -543,7 +543,7 @@ void device_store_cached_name(struct btd_device *dev, const char *name) 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_clear_error(&gerr); } data_old = g_key_file_to_data(key_file, &length_old, NULL); @@ -556,7 +556,7 @@ void device_store_cached_name(struct btd_device *dev, const char *name) if (!g_file_set_contents(filename, data, length, &gerr)) { error("Unable set contents for %s: (%s)", filename, gerr->message); - g_error_free(gerr); + g_clear_error(&gerr); } } g_free(data); @@ -592,7 +592,7 @@ static void device_store_cached_name_resolve(struct btd_device *dev) 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_clear_error(&gerr); } failed_time = (uint64_t) dev->name_resolve_failed_time; @@ -2666,7 +2666,7 @@ static void store_gatt_db(struct btd_device *device) 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_clear_error(&gerr); } /* Remove current attributes since it might have changed */ @@ -3635,7 +3635,7 @@ static void load_att_info(struct btd_device *device, const char *local, 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_clear_error(&gerr); } groups = g_key_file_get_groups(key_file, NULL); @@ -6163,7 +6163,7 @@ void device_store_svc_chng_ccc(struct btd_device *device, uint8_t bdaddr_type, 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_clear_error(&gerr); } /* for bonded devices this is done on every connection so limit writes From patchwork Fri Feb 11 02:00:54 2022 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: 542615 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B0EEC433EF for ; Fri, 11 Feb 2022 02:01:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347085AbiBKCA6 (ORCPT ); Thu, 10 Feb 2022 21:00:58 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:57418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347083AbiBKCA6 (ORCPT ); Thu, 10 Feb 2022 21:00:58 -0500 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E58D25FA4 for ; Thu, 10 Feb 2022 18:00:57 -0800 (PST) Received: by mail-pl1-x62f.google.com with SMTP id c3so3463216pls.5 for ; Thu, 10 Feb 2022 18:00:57 -0800 (PST) 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=3z6Py4ZnUxwkEa/ciP6EGzTvF/M5d9y32+u5BX0inys=; b=K7NIb+vN1V8HR408rNhfdVfyNc81xSwDYeJGFxGH+E8LrNe2o2zZVGwkydZ0ScBxR+ uYSgKZybfOvCjblVarAUkIRPkmsLu6Gy198DoNutEMb5rKo6YuZKs82XSeiNt2IhLVKI XctyaBzZh92pH/fLMwaMojzwhphUKHPVZEOAB2UTXuqEmFxIEJ914gzdf9ieWvLY2yqX ICLHgtwwapkCK0FPVo1m76J/FeR7dynV7EPoQ9d66+MrxnzBQUxLi0iHdMATBYsFreap Hxm6TNK8vFU2vsy1UToKUgQujs3UHOzcUlU+eA19mhsPJ+NpxKxwHalBBPvDZPURvJj1 lgAg== 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=3z6Py4ZnUxwkEa/ciP6EGzTvF/M5d9y32+u5BX0inys=; b=cUOCKtY3uI/hZj+1f7Js6MD9hNMYiPUlFfCIFFWzr5mFVZRyoFzkZKFxd06m+Re+zB dCko3ivm8XZ9HHzS3+6GDgxG6s1RzE1vXR/pbqtWvPssn2xuwZUoGflEQQCnGhyXDI5/ rKtrf2jJe+JFF6kJYT34K4D8lm1nf8LYhC9NGyX50DKswLfeRp1duUXZJ5N0ZyNeefCf SNpJHr+w+0FpD2jZ1MWWG7oIVJu77gLBmw6sxVWSJRt/LL6/5/IdlhU9qtKLMHdGwFjY +MkjogNexVXSDxMB4zdGVZIGpbxEicjP8ZvA2u+gMQoe1CgYIF+Am6apvnCnHksom7ww 7acQ== X-Gm-Message-State: AOAM53312JuFzg797+pHs+F1OH3xIMw6Nq66YwqG35K2+maGAJirMj/t imqYEwGu97zO1g2REo47p/ZS1j0RD3w= X-Google-Smtp-Source: ABdhPJy1ymaKEfJ5nH3p4Lv1AcNp13yjV4fQTJVOK0dO26HI6KF0G01gvYh9uNy3hvuUNPqEhs4LoQ== X-Received: by 2002:a17:902:ce04:: with SMTP id k4mr9866069plg.131.1644544857228; Thu, 10 Feb 2022 18:00:57 -0800 (PST) Received: from han1-NUC8i7BEH.hsd1.or.comcast.net ([2601:1c0:6a01:d830::169b]) by smtp.gmail.com with ESMTPSA id b2sm17752759pgg.59.2022.02.10.18.00.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 18:00:56 -0800 (PST) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH 3/3] profiles: Fix the reusing gerror without re-initialization Date: Thu, 10 Feb 2022 18:00:54 -0800 Message-Id: <20220211020054.28534-3-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220211020054.28534-1-hj.tedd.an@gmail.com> References: <20220211020054.28534-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 When the GError variable is freeed with g_error_free(), it is not set to NULL and reusing the same variable again can cause the seg_fault because it is still pointing the old memory address which is freed. This patch relaces the g_error_free() to g_clear_error() which frees the variable and set it to NULL if the variable is used in the function again. Fixes: 4ad622d592ba5 ("profiles/a2dp: Fix unchecked return value") --- profiles/audio/a2dp.c | 4 ++-- profiles/health/hdp.c | 6 +++--- profiles/input/device.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c index d0808c77a..9fbcd35f7 100644 --- a/profiles/audio/a2dp.c +++ b/profiles/audio/a2dp.c @@ -832,7 +832,7 @@ static void store_remote_seps(struct a2dp_channel *chan) 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_clear_error(&gerr); } data = g_key_file_get_string(key_file, "Endpoints", "LastUsed", @@ -1006,7 +1006,7 @@ static void store_last_used(struct a2dp_channel *chan, uint8_t lseid, 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_clear_error(&gerr); } sprintf(value, "%02hhx:%02hhx", lseid, rseid); diff --git a/profiles/health/hdp.c b/profiles/health/hdp.c index 40b6cc18a..9d9d1e824 100644 --- a/profiles/health/hdp.c +++ b/profiles/health/hdp.c @@ -576,7 +576,7 @@ static void device_reconnect_mdl_cb(struct mcap_mdl *mdl, GError *err, "Cannot reconnect: %s", gerr->message); g_dbus_send_message(conn, reply); hdp_tmp_dc_data_unref(dc_data); - g_error_free(gerr); + g_clear_error(&gerr); /* Send abort request because remote side is now in PENDING state */ if (!mcap_mdl_abort(mdl, abort_mdl_cb, NULL, NULL, &gerr)) { @@ -1766,7 +1766,7 @@ static void device_create_mdl_cb(struct mcap_mdl *mdl, uint8_t conf, return; error("%s", gerr->message); - g_error_free(gerr); + g_clear_error(&gerr); reply = g_dbus_create_reply(hdp_conn->msg, DBUS_TYPE_OBJECT_PATH, &hdp_chan->path, @@ -1790,7 +1790,7 @@ fail: ERROR_INTERFACE ".HealthError", "%s", gerr->message); g_dbus_send_message(conn, reply); - g_error_free(gerr); + g_clear_error(&gerr); /* Send abort request because remote side is now in PENDING */ /* state. Then we have to delete it because we couldn't */ diff --git a/profiles/input/device.c b/profiles/input/device.c index 013899211..ff4aa771a 100644 --- a/profiles/input/device.c +++ b/profiles/input/device.c @@ -1053,7 +1053,7 @@ static int hidp_add_connection(struct input_device *idev) 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_clear_error(&gerr); } str = g_key_file_get_string(key_file, "ServiceRecords", handle, NULL); g_key_file_free(key_file);