diff options
author | Richard Hughes <richard@hughsie.com> | 2009-11-17 13:30:25 +0000 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2009-11-17 13:30:25 +0000 |
commit | 99ab6b00c06dc778d9f4b04e8a7048e0c938cb4f (patch) | |
tree | 20ca3844a22235a2c4ca43a986a6d219de63c35e | |
parent | 9f4fae9cccd7aed7b81d87520a586489b1e3feb3 (diff) |
Some vendors fill the NVRAM full of junk. Don't crash the daemon if the battery is broken. Fixes rh#533654
-rw-r--r-- | src/linux/dkp-device-supply.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/linux/dkp-device-supply.c b/src/linux/dkp-device-supply.c index 5a1acd9..ac5e1e1 100644 --- a/src/linux/dkp-device-supply.c +++ b/src/linux/dkp-device-supply.c @@ -341,6 +341,35 @@ out: } /** + * dkp_device_supply_make_safe_string: + **/ +static void +dkp_device_supply_make_safe_string (gchar *text) +{ + guint i; + guint idx = 0; + + /* no point checking */ + if (text == NULL) + return; + + /* shunt up only safe chars */ + for (i=0; text[i] != '\0'; i++) { + if (g_ascii_isprint (text[i])) { + /* only copy if the address is going to change */ + if (idx != i) + text[idx] = text[i]; + idx++; + } else { + egg_debug ("invalid char '%c'", text[i]); + } + } + + /* ensure null terminated */ + text[idx] = '\0'; +} + +/** * dkp_device_supply_refresh_battery: * * Return %TRUE on success, %FALSE if we failed to refresh or no data @@ -412,6 +441,11 @@ dkp_device_supply_refresh_battery (DkpDeviceSupply *supply) model_name = dkp_device_supply_get_string (native_path, "model_name"); serial_number = dkp_device_supply_get_string (native_path, "serial_number"); + /* some vendors fill this with binary garbage */ + dkp_device_supply_make_safe_string (manufacturer); + dkp_device_supply_make_safe_string (model_name); + dkp_device_supply_make_safe_string (serial_number); + /* are we possibly recalled by the vendor? */ recall_notice = g_udev_device_has_property (native, "DKP_RECALL_NOTICE"); if (recall_notice) { |