From: Tedd Ho-Jeong An <[email protected]>
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) {
--
2.25.1
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=613281
---Test result---
Test Summary:
CheckPatch FAIL 5.88 seconds
GitLint PASS 3.93 seconds
Prep - Setup ELL PASS 42.74 seconds
Build - Prep PASS 0.72 seconds
Build - Configure PASS 8.53 seconds
Build - Make PASS 1372.70 seconds
Make Check PASS 11.35 seconds
Make Check w/Valgrind PASS 438.47 seconds
Make Distcheck PASS 225.85 seconds
Build w/ext ELL - Configure PASS 8.50 seconds
Build w/ext ELL - Make PASS 1361.92 seconds
Incremental Build with patchesPASS 5555.64 seconds
Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script with rule in .checkpatch.conf
Output:
[BlueZ,1/4] adapter: Fix the reusing gerror without re-initialization
WARNING:UNKNOWN_COMMIT_ID: Unknown commit id '2287c517ca1bd', maybe rebased or not pulled?
#88:
Fixes: 2287c517ca1bd ("adapter: Fix unchecked return value")
/github/workspace/src/12742616.patch total: 0 errors, 1 warnings, 136 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/github/workspace/src/12742616.patch has style problems, please review.
NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
[BlueZ,2/4] device: Fix the reusing gerror without re-initialization
WARNING:UNKNOWN_COMMIT_ID: Unknown commit id '6a154cd08000b', maybe rebased or not pulled?
#90:
Fixes: 6a154cd08000b ("device: Fix unchecked return value")
/github/workspace/src/12742617.patch total: 0 errors, 1 warnings, 48 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/github/workspace/src/12742617.patch has style problems, please review.
NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
[BlueZ,3/4] profiles: Fix the reusing gerror without re-initialization
WARNING:UNKNOWN_COMMIT_ID: Unknown commit id '4ad622d592ba5', maybe rebased or not pulled?
#90:
Fixes: 4ad622d592ba5 ("profiles/a2dp: Fix unchecked return value")
/github/workspace/src/12742618.patch total: 0 errors, 1 warnings, 48 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/github/workspace/src/12742618.patch has style problems, please review.
NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
[BlueZ,4/4] device: Fix crash when removing device
WARNING:TYPO_SPELLING: 'immediatelly' may be misspelled - perhaps 'immediately'?
#81:
cause a crash, so instead of removing it immediatelly this set a the
^^^^^^^^^^^^
/github/workspace/src/12742619.patch total: 0 errors, 1 warnings, 64 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/github/workspace/src/12742619.patch has style problems, please review.
NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
---
Regards,
Linux Bluetooth
Dear Tedd,
Am 11.02.22 um 01:18 schrieb Tedd Ho-Jeong An:
> From: Tedd Ho-Jeong An <[email protected]>
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) {
Hi Paul,
On Fri, Feb 11, 2022 at 8:41 AM Paul Menzel <[email protected]> wrote:
>
> Dear Tedd,
>
>
> Am 11.02.22 um 01:18 schrieb Tedd Ho-Jeong An:
> > From: Tedd Ho-Jeong An <[email protected]>
>
> 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?
That is part of issue if you open the link:
https://github.com/bluez/bluez/issues/276#issue-1111278644
> > 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.
But this is on kernel space, and afaik github uses *Fixes* instead to
auto close the issues, so I don't really follow what you are trying to
suggest here, or do you want github to start following Linux kernel
tags?
>
> 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) {
--
Luiz Augusto von Dentz
Dear Luiz,
Am 11.02.22 um 21:30 schrieb Luiz Augusto von Dentz:
> On Fri, Feb 11, 2022 at 8:41 AM Paul Menzel <[email protected]> wrote:
>> Am 11.02.22 um 01:18 schrieb Tedd Ho-Jeong An:
>>> From: Tedd Ho-Jeong An <[email protected]>
>>
>> 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?
>
> That is part of issue if you open the link:
>
> https://github.com/bluez/bluez/issues/276#issue-1111278644
Yes, I know. I prefer commit messages to be self-contained, as it’s
never known if you are online or the Web service has problems or is shut
down. But of course, if BlueZ does it differently, that is fine.
>>> 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.
>
> But this is on kernel space, and afaik github uses *Fixes* instead to
> auto close the issues, so I don't really follow what you are trying to
> suggest here, or do you want github to start following Linux kernel
> tags?
GitHub already does. ;-) Resolves, Closes, Fixes all automatically close
the referenced issue.
[…]
Kind regards,
Paul