Skip to content

parse: don't remove datalist items during iteration#450

Merged
daniloegea merged 1 commit intocanonical:mainfrom
daniloegea:datalist_foreach_crash
Apr 3, 2024
Merged

parse: don't remove datalist items during iteration#450
daniloegea merged 1 commit intocanonical:mainfrom
daniloegea:datalist_foreach_crash

Conversation

@daniloegea
Copy link
Contributor

@daniloegea daniloegea commented Apr 3, 2024

The glib documentation says that it should be safe to remove items from inside the function called by g_datalist_foreach but I've found some crashes related to it where the last element was returning NULL.

This is one of the instances that causes the crash:

passthrough:
  Utf14: sit cupidatat aliquip proident ut
  reprehenderit6e2: 16408719.105799645
  connection.type: ullamco officia

Message from glib:

GLib-CRITICAL **: 10:16:09.406: g_strsplit: assertion 'string != NULL' failed

With this change the bad keys will be stored in an GArray and removed from the datalist outside the foreach.

Description

I was testing my https://github.com/daniloegea/netplan-fuzz and stumbled upon this issue.

Error from glib:

(generate:272642): GLib-CRITICAL **: 10:16:09.406: g_strsplit: assertion 'string != NULL' failed

Note this case, the last warning mentions a key called GParamGType but it is not part of the keys. That means the pointer it's working with at this moment is not what we expect due to inconsistencies in the data structure.

** (generate:281561): WARNING **: 11:16:21.688: NetworkManager: passthrough key 'Utf14' format is invalid, should be 'group.key'.
processing key reprehenderit6e2

** (generate:281561): WARNING **: 11:16:21.688: NetworkManager: passthrough key 'reprehenderit6e2' format is invalid, should be 'group.key'.
processing key GParamGType

** (generate:281561): WARNING **: 11:16:21.688: NetworkManager: passthrough key 'GParamGType' format is invalid, should be 'group.key'.
/tmp/fakeroot/etc/netplan/asd.yaml: Error in network definition: 9a9A0-ZA0Z: virtual-ethernet missing 'peer' property

Full YAML that found the problem.

network:
  renderer: NetworkManager
  version: 2
  virtual-ethernets:
    9a9A0-ZA0Z:
      dhcp6: false
      dhcp-identifier: mac
      ipv6-privacy: false
      networkmanager:
        uuid: et magna occaecat laborum deserunt
        name: officia et id
        passthrough:
          Utf14: sit cupidatat aliquip proident ut
          reprehenderit6e2: 16408719.105799645
          connection.type: ullamco officia
      renderer: NetworkManager
    renderer: networkd

Checklist

  • Runs make check successfully.
  • Retains 100% code coverage (make check-coverage).
  • New/changed keys in YAML format are documented.
  • (Optional) Adds example YAML for new feature.
  • (Optional) Closes an open bug in Launchpad.

The glib documentation says that it should be safe to remove items from
inside the function called by g_datalist_foreach but I've found some
crashes related to it where the last element was returning NULL.

This is one of the instances that causes the crash:

passthrough:
  Utf14: sit cupidatat aliquip proident ut
  reprehenderit6e2: 16408719.105799645
  connection.type: ullamco officia

Message from glib:
GLib-CRITICAL **: 10:16:09.406: g_strsplit: assertion 'string != NULL' failed

With this change the bad keys will be stored in an GArray and removed
from the datalist outside the foreach.
@daniloegea daniloegea marked this pull request as ready for review April 3, 2024 12:30
@daniloegea daniloegea requested a review from slyon April 3, 2024 12:30
Copy link
Contributor

@slyon slyon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@daniloegea daniloegea merged commit 7afe56f into canonical:main Apr 3, 2024
@slyon slyon mentioned this pull request Apr 10, 2024
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants