Files
LCUI/lib/ui-xml/tests/test_resource_node.c
Liu d57350e286 fix(ui-xml): resource node should reject missing type attribute
ui_builder_parse_resource_node() only rejected the case where both
type and src were absent, then passed a NULL type to strstr(). Require
type before dispatching on it, release attributes through the existing
exit path, and check src before loading a font.

Fixes GHSA-xr82-f9q8-h384.
2026-11-24 21:49:20 +08:00

55 lines
1.6 KiB
C

#include <string.h>
#include <ui.h>
#include <ui_xml.h>
#include <ctest.h>
static void check_resource_missing_type(void)
{
const char *xml =
"<lcui-app><ui><resource src=\"theme.css\"/></ui></lcui-app>";
ui_widget_t *pack;
pack = ui_load_xml_string(xml, (int)strlen(xml));
ctest_equal_bool("should parse without crashing", pack != NULL, true);
if (pack) {
ui_widget_destroy(pack);
}
}
static void check_resource_missing_type_and_src(void)
{
const char *xml = "<lcui-app><ui><resource/></ui></lcui-app>";
ui_widget_t *pack;
pack = ui_load_xml_string(xml, (int)strlen(xml));
ctest_equal_bool("should return pack for empty resource", pack != NULL,
true);
if (pack) {
ui_widget_destroy(pack);
}
}
static void check_inline_css_resource(void)
{
const char *xml = "<lcui-app><ui><resource type=\"text/css\">"
"a{display:block;}</resource></ui></lcui-app>";
ui_widget_t *pack;
pack = ui_load_xml_string(xml, (int)strlen(xml));
ctest_equal_bool("should parse inline css resource", pack != NULL,
true);
if (pack) {
ui_widget_destroy(pack);
}
}
void test_ui_xml_resource_node(void)
{
ui_init();
ctest_describe("resource missing type", check_resource_missing_type);
ctest_describe("resource missing type and src",
check_resource_missing_type_and_src);
ctest_describe("inline css resource", check_inline_css_resource);
ui_destroy();
}