Re: [BlueZ PATCH 1/4] adapter: Fix the reusing gerror without re-initialization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Paul,

On Fri, Feb 11, 2022 at 8:41 AM Paul Menzel <pmenzel@xxxxxxxxxxxxx> wrote:
>
> Dear Tedd,
>
>
> Am 11.02.22 um 01:18 schrieb Tedd Ho-Jeong An:
> > From: Tedd Ho-Jeong An <tedd.an@xxxxxxxxx>
>
> 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



[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux