hal/hald property.c,1.4,1.5
Joe Shaw
joe at freedesktop.org
Fri Jul 30 09:48:42 PDT 2004
Update of /cvs/hal/hal/hald
In directory pdx:/tmp/cvs-serv14845/hald
Modified Files:
property.c
Log Message:
2004-07-30 Joe Shaw <joeshaw at novell.com>
* hald/property.c (hal_property_new_string,
hal_property_set_string): Validate incoming strings as UTF-8 and
replace invalid sequences with '?'
Index: property.c
===================================================================
RCS file: /cvs/hal/hal/hald/property.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- property.c 20 Jun 2004 13:27:45 -0000 1.4
+++ property.c 30 Jul 2004 16:48:40 -0000 1.5
@@ -30,6 +30,7 @@
#include <glib.h>
+#include "logger.h"
#include "property.h"
struct _HalProperty {
@@ -62,6 +63,8 @@
hal_property_new_string (const char *key, const char *value)
{
HalProperty *prop;
+ char *endchar;
+ gboolean validated = TRUE;
prop = g_new0 (HalProperty, 1);
@@ -69,6 +72,17 @@
prop->key = g_strdup (key);
prop->str_value = g_strdup (value);
+ while (!g_utf8_validate (prop->str_value, -1,
+ (const char **) &endchar)) {
+ validated = FALSE;
+ *endchar = '?';
+ }
+
+ if (!validated) {
+ HAL_WARNING (("Key '%s' has invalid UTF-8 string '%s'",
+ key, value));
+ }
+
return prop;
}
@@ -189,12 +203,26 @@
void
hal_property_set_string (HalProperty *prop, const char *value)
{
+ char *endchar;
+ gboolean validated = TRUE;
+
g_return_if_fail (prop != NULL);
g_return_if_fail (prop->type == DBUS_TYPE_STRING ||
prop->type == DBUS_TYPE_NIL);
prop->type = DBUS_TYPE_STRING;
prop->str_value = g_strdup (value);
+
+ while (!g_utf8_validate (prop->str_value, -1,
+ (const char **) &endchar)) {
+ validated = FALSE;
+ *endchar = '?';
+ }
+
+ if (!validated) {
+ HAL_WARNING (("Key '%s' has invalid UTF-8 string '%s'",
+ prop->key, value));
+ }
}
void
More information about the hal-commit
mailing list