Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp3832237pxb; Fri, 11 Feb 2022 08:41:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJzxoepF2voUxQIE24wkqbK3Ngw4gz74dYSyuUNh5iOWKKs7uIxBNTgfVQuA6vExTEFy8AMv X-Received: by 2002:a17:906:3e87:: with SMTP id a7mr2104490ejj.227.1644597700986; Fri, 11 Feb 2022 08:41:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644597700; cv=none; d=google.com; s=arc-20160816; b=t73MC49+DYgaQmdSoENBKeZuXxXdQ6Z+psVtl4kFXlJ7zJ9XcKV/81toenirOjPDSO 6K6/+MXg9++TliT75y5nltiyl6PKxkZFID2KZa6WUV/YDZmDBfqEB4c0qWI3yCWNjEMY 0+M6BFNwkH9Fb1GT/9/hthi9GuknG3LKJAOK8xoT5wF2gnn4JNsgFC2YWbhlmqkOGVG2 rbyOVqyELs6paIUYrEP7/W7FPSwyBHX/ukj10A7wxVDJj59d9QUbfFmtAwitSLtbwy1J 5B/H1UNmG6DILqQWaZuvurLmCbGcsZ46GmaInYT4LhdLfoLyihZupohK4d+glyc5ngN+ ZHJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from:cc :references:to:content-language:subject:user-agent:mime-version:date :message-id; bh=q5w03ZNe+D00FGLevqHhj43zPxRnUyVJI5e6hg/QsHE=; b=NcKq9BLrDlFElBpP+xYy/3ggotQoHmu0r0JX5R5mz2TQEXvGw/AySkzl+nScHKTPhr FAJ0JO2m7laiBPbwXQiWWf4XOzbmY181bRUhD7rA5GyQgPONxswDVel0WT+oLQ/H7TSs M5HIoUX6dOorpz7MLgTo5/yR5TTv7VdHGIl115IIgbIJBad6cy4iQBORwNQ+7ZeftdAc W3+usveWpzEH0TYJ3nAnc0Nh6DFqZGPMpoKUdn8dncG/wI5Y5g501o0N0rayP6z6LfNM OSbHtK3MgicnbMfrDiD2iBaXXievLPlAttX8JOOTc2Pc+ZrzxTrA8trV4d/i63/NIBFn 0n0g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l10si20555234edb.628.2022.02.11.08.40.58; Fri, 11 Feb 2022 08:41:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347711AbiBKHiB (ORCPT + 99 others); Fri, 11 Feb 2022 02:38:01 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:46360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347721AbiBKHh6 (ORCPT ); Fri, 11 Feb 2022 02:37:58 -0500 Received: from mx1.molgen.mpg.de (mx3.molgen.mpg.de [141.14.17.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 419CE9B for ; Thu, 10 Feb 2022 23:37:41 -0800 (PST) Received: from [192.168.0.2] (ip5f5aebe1.dynamic.kabel-deutschland.de [95.90.235.225]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) (Authenticated sender: pmenzel) by mx.molgen.mpg.de (Postfix) with ESMTPSA id 6423E61EA1926; Fri, 11 Feb 2022 08:37:38 +0100 (CET) Message-ID: Date: Fri, 11 Feb 2022 08:37:38 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.1 Subject: Re: [BlueZ PATCH 1/4] adapter: Fix the reusing gerror without re-initialization Content-Language: en-US To: Tedd Ho-Jeong An References: <20220211001840.22566-1-hj.tedd.an@gmail.com> Cc: linux-bluetooth@vger.kernel.org From: Paul Menzel In-Reply-To: <20220211001840.22566-1-hj.tedd.an@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Dear Tedd, Am 11.02.22 um 01:18 schrieb Tedd Ho-Jeong An: > From: Tedd Ho-Jeong An I had a hard time to understand, what the git commit message summary meant. Maybe: > adapter: Use g_clear_error() to set gerr to NULL to fix segfault > 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. Could you please include an example stack-/backtrace? > 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 set*s* > again. > > Fixes: 2287c517ca1bd ("adapter: Fix unchecked return value") > Fixes: https://github.com/bluez/bluez/issues/276 To make the tags unambiguous, at least in the Linux kernel world, *Resolves* or *Closes* are used to refer to issues. Kind regards, Paul > --- > 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) {