From eb5d285ed474f0cc20b968e4a5d590a3b35e52a7 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Sat, 1 Aug 2009 15:02:39 +0100 Subject: Avoid invalid memory accesses in lockdownd_client_new() Valgrind complains: ==2678== Conditional jump or move depends on uninitialised value(s) ==2678== at 0x3ACD40646C: lockdownd_client_new (lockdown.c:662) ==2678== by 0x405BA6: g_vfs_afc_volume_new (afc-volume.c:113) ==2678== by 0x406541: g_vfs_afc_monitor_device_added (afc-volume-monitor.c:46) ==2678== by 0x4066B1: g_vfs_afc_volume_monitor_constructor (afc-volume-monitor.c:173) ==2678== by 0x3A7FE11A38: g_object_newv (in /lib64/libgobject-2.0.so.0.2000.4) ==2678== by 0x3A7FE12584: g_object_new_valist (in /lib64/libgobject-2.0.so.0.2000.4) ==2678== by 0x3A7FE126DB: g_object_new (in /lib64/libgobject-2.0.so.0.2000.4) ==2678== by 0x408AD5: monitor_try_create (gvfsproxyvolumemonitordaemon.c:1651) ==2678== by 0x408C20: g_vfs_proxy_volume_monitor_daemon_main (gvfsproxyvolumemonitordaemon.c:1694) ==2678== by 0x37E881EA2C: (below main) (in /lib64/libc-2.10.1.so) ==2678== Uninitialised value was created by a stack allocation ==2678== at 0x405B00: g_vfs_afc_volume_new (afc-volume.c:138) --- src/lockdown.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lockdown.c b/src/lockdown.c index 88ab7b0..7a2aa7d 100644 --- a/src/lockdown.c +++ b/src/lockdown.c @@ -659,7 +659,7 @@ lockdownd_error_t lockdownd_get_device_name(lockdownd_client_t client, char **de */ lockdownd_error_t lockdownd_client_new(iphone_device_t device, lockdownd_client_t *client) { - if (!device || !client || (client && *client)) + if (!device || !client) return LOCKDOWN_E_INVALID_ARG; lockdownd_error_t ret = LOCKDOWN_E_SUCCESS; char *host_id = NULL; -- cgit v1.1-32-gdbae From d5da1a93f977688d621f3f3650ee0a7a51e2b373 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Sat, 1 Aug 2009 15:04:27 +0100 Subject: Add afc_get_device_info_field() helper function For use in front-end applications, also serves to document the available keys. --- include/libiphone/afc.h | 3 +++ src/AFC.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/libiphone/afc.h b/include/libiphone/afc.h index 651621e..77b6f0e 100644 --- a/include/libiphone/afc.h +++ b/include/libiphone/afc.h @@ -106,6 +106,9 @@ afc_error_t afc_make_directory(afc_client_t client, const char *dir); afc_error_t afc_truncate(afc_client_t client, const char *path, off_t newsize); afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const char *target, const char *linkname); +/* Helper functions */ +char * afc_get_device_info_field(afc_client_t client, const char *field); + #ifdef __cplusplus } #endif diff --git a/src/AFC.c b/src/AFC.c index 826c9e5..d2761cf 100644 --- a/src/AFC.c +++ b/src/AFC.c @@ -468,6 +468,35 @@ afc_error_t afc_get_device_info(afc_client_t client, char ***infos) return ret; } +/** Get a specific field of the device info for a client connection to phone. + * Known values are: Model, FSTotalBytes, FSFreeBytes and FSBlockSize. This is + * a helper function for afc_get_device_info(). + * + * @param client The client to get device info for. + * @param field The field to get the information for + * + * @return A char * or NULL if there was an error. + */ +char * afc_get_device_info_field(afc_client_t client, const char *field) +{ + char *ret = NULL; + char **kvps, **ptr; + + if (field == NULL || afc_get_device_info(client, &kvps) != AFC_E_SUCCESS) + return NULL; + + for (ptr = kvps; *ptr; ptr++) { + if (!strcmp(*ptr, field)) { + ret = strdup(*(ptr+1)); + break; + } + } + + g_strfreev(kvps); + + return ret; +} + /** Deletes a file or directory. * * @param client The client to use. -- cgit v1.1-32-gdbae From dbf7b02b4a09de4aa9220431d466d900e47b74ba Mon Sep 17 00:00:00 2001 From: Matt Colyer Date: Mon, 3 Aug 2009 09:01:51 -0700 Subject: Updated AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 8671482..8d76d8a 100644 --- a/AUTHORS +++ b/AUTHORS @@ -9,3 +9,4 @@ Patrick Walton Zoltan Balaton Nikias Bassen Todd Zullinger +Bastien Nocera -- cgit v1.1-32-gdbae