summaryrefslogtreecommitdiff
path: root/gio/gmenuexporter.c
diff options
context:
space:
mode:
Diffstat (limited to 'gio/gmenuexporter.c')
-rw-r--r--gio/gmenuexporter.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/gio/gmenuexporter.c b/gio/gmenuexporter.c
index a212b29f3..1860b34e8 100644
--- a/gio/gmenuexporter.c
+++ b/gio/gmenuexporter.c
@@ -1,6 +1,8 @@
/*
* Copyright © 2011 Canonical Ltd.
*
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
@@ -250,10 +252,21 @@ g_menu_exporter_menu_items_changed (GMenuModel *model,
GMenuExporterMenu *menu = user_data;
GSequenceIter *point;
gint i;
+#ifndef G_DISABLE_ASSERT
+ gint n_items;
+#endif
g_assert (menu->model == model);
g_assert (menu->item_links != NULL);
- g_assert (position + removed <= g_sequence_get_length (menu->item_links));
+
+#ifndef G_DISABLE_ASSERT
+ n_items = g_sequence_get_length (menu->item_links);
+#endif
+ g_assert (position >= 0 && position < G_MENU_EXPORTER_MAX_SECTION_SIZE);
+ g_assert (removed >= 0 && removed < G_MENU_EXPORTER_MAX_SECTION_SIZE);
+ g_assert (added < G_MENU_EXPORTER_MAX_SECTION_SIZE);
+ g_assert (position + removed <= n_items);
+ g_assert (n_items - removed + added < G_MENU_EXPORTER_MAX_SECTION_SIZE);
point = g_sequence_get_iter_at_pos (menu->item_links, position + removed);
g_sequence_remove_range (g_sequence_get_iter_at_pos (menu->item_links, position), point);
@@ -768,6 +781,10 @@ g_menu_exporter_method_call (GDBusConnection *connection,
* constraint is violated, the export will fail and 0 will be
* returned (with @error set accordingly).
*
+ * Exporting menus with sections containing more than
+ * %G_MENU_EXPORTER_MAX_SECTION_SIZE items is not supported and results in
+ * undefined behavior.
+ *
* You can unexport the menu model using
* g_dbus_connection_unexport_menu_model() with the return value of
* this function.