mirror of
https://github.com/lc-soft/LCUI.git
synced 2026-11-30 16:48:21 +01:00
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.
55 lines
1.6 KiB
C
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();
|
|
}
|