]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[settings] Use list_first_entry() when unregistering child settings
authorMichael Brown <mcb30@ipxe.org>
Tue, 3 Mar 2015 00:29:42 +0000 (00:29 +0000)
committerMichael Brown <mcb30@ipxe.org>
Tue, 3 Mar 2015 00:29:42 +0000 (00:29 +0000)
Unregistering a child settings block can have almost arbitrary
effects, due to the call to apply_settings().  Avoid potentially
dereferencing a stale pointer by using list_first_entry() rather than
list_for_each_entry_safe() to iterate over the list of child settings.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/core/settings.c

index 5e16b27d0ef4bbc06b378d9d57ab64662428648a..85d95e6ebfbf6ceb81973e69a2cdb68bc23f1adb 100644 (file)
@@ -499,10 +499,10 @@ int register_settings ( struct settings *settings, struct settings *parent,
  */
 void unregister_settings ( struct settings *settings ) {
        struct settings *child;
-       struct settings *tmp;
 
        /* Unregister child settings */
-       list_for_each_entry_safe ( child, tmp, &settings->children, siblings ) {
+       while ( ( child = list_first_entry ( &settings->children,
+                                            struct settings, siblings ) ) ) {
                unregister_settings ( child );
        }