summaryrefslogtreecommitdiff
path: root/source/l/hal/patches/check_udi_properly.diff
blob: cd474abc5fad7c91d86e5775921dea54ca1d103a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Author: Richard Hughes <richard@hughsie.com>
Date:   Thu Jan 29 08:33:00 2009 +0000

    check udi in hal-get-property
    
    We are not checking if a UDI is valid in hal-get-property
    which means getting a horrible DBUS error if the entry
    is not a valid DBUS path.

diff --git a/tools/hal_get_property.c b/tools/hal_get_property.c
index ecaa6ce..d31261a 100644
--- a/tools/hal_get_property.c
+++ b/tools/hal_get_property.c
@@ -84,6 +84,7 @@ main (int argc, char *argv[])
 	dbus_bool_t is_hex = FALSE;
 	dbus_bool_t is_verbose = FALSE;
 	dbus_bool_t is_version = FALSE;
+	dbus_bool_t udi_exists;
 	char *str;
 	DBusError error;
 
@@ -168,6 +169,19 @@ main (int argc, char *argv[])
 		return 1;
 	}
 
+	/* check UDI exists */
+	udi_exists = libhal_device_exists (hal_ctx, udi, &error);
+	if (!udi_exists) {
+		fprintf (stderr, "error: UDI %s does not exist\n", udi);
+		return 1;
+	}
+	if (dbus_error_is_set(&error)) {
+		fprintf (stderr, "error: libhal_device_exists: %s: %s\n", error.name, error.message);
+		LIBHAL_FREE_DBUS_ERROR (&error);
+		return 1;
+	}
+
+	/* get type */
 	type = libhal_device_get_property_type (hal_ctx, udi, key, &error);
 	if (type == LIBHAL_PROPERTY_TYPE_INVALID) {
 		fprintf (stderr, "error: libhal_device_get_property_type: %s: %s\n", error.name, error.message);