summaryrefslogtreecommitdiffstats
path: root/common/userpref.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2018-10-01 02:32:51 +0200
committerGravatar Nikias Bassen2018-10-01 02:32:51 +0200
commitb34e3435c21d06b3e5a4e7b5246fb6ddb6641a9f (patch)
tree89b78560cd956b956a03c9b207816d8cb345c37e /common/userpref.c
parentf1ee0fd8b2b1dd65c64f5a67e208efc708295caa (diff)
downloadlibimobiledevice-b34e3435c21d06b3e5a4e7b5246fb6ddb6641a9f.tar.gz
libimobiledevice-b34e3435c21d06b3e5a4e7b5246fb6ddb6641a9f.tar.bz2
tools: Remove length check on device UDID arguments to support newer devices
The 40 characters length check on the device UDID made newer devices unusable with the libimobiledevice tools and was actually redundant since an invalid UDID will always fail to resolve. This commit removes the length check alltogether (but makes sure it is not an empty string "").
Diffstat (limited to 'common/userpref.c')
-rw-r--r--common/userpref.c53
1 files changed, 24 insertions, 29 deletions
diff --git a/common/userpref.c b/common/userpref.c
index 0fa5b96..b985285 100644
--- a/common/userpref.c
+++ b/common/userpref.c
@@ -208,14 +208,8 @@ int userpref_read_system_buid(char **system_buid)
*/
userpref_error_t userpref_get_paired_udids(char ***list, unsigned int *count)
{
- struct slist_t {
- char *name;
- void *next;
- };
DIR *config_dir;
const char *config_path = NULL;
- struct slist_t *udids = NULL;
- unsigned int i;
unsigned int found = 0;
if (!list || (list && *list)) {
@@ -226,41 +220,42 @@ userpref_error_t userpref_get_paired_udids(char ***list, unsigned int *count)
if (count) {
*count = 0;
}
+ *list = (char**)malloc(sizeof(char*));
config_path = userpref_get_config_dir();
config_dir = opendir(config_path);
if (config_dir) {
struct dirent *entry;
- struct slist_t *listp = udids;
while ((entry = readdir(config_dir))) {
- char *ext = strstr(entry->d_name, USERPREF_CONFIG_EXTENSION);
- if (ext && ((ext - entry->d_name) == 40) && (strlen(entry->d_name) == (40 + strlen(ext)))) {
- struct slist_t *ne = (struct slist_t*)malloc(sizeof(struct slist_t));
- ne->name = (char*)malloc(41);
- strncpy(ne->name, entry->d_name, 40);
- ne->name[40] = 0;
- ne->next = NULL;
- if (!listp) {
- listp = ne;
- udids = listp;
- } else {
- listp->next = ne;
- listp = listp->next;
+ if (strcmp(entry->d_name, USERPREF_CONFIG_FILE) == 0) {
+ /* ignore SystemConfiguration.plist */
+ continue;
+ }
+ char *ext = strrchr(entry->d_name, '.');
+ if (ext && (strcmp(ext, USERPREF_CONFIG_EXTENSION) == 0)) {
+ size_t len = strlen(entry->d_name) - strlen(USERPREF_CONFIG_EXTENSION);
+ char **newlist = (char**)realloc(*list, sizeof(char*) * (found+2));
+ if (!newlist) {
+ fprintf(stderr, "ERROR: Out of memory\n");
+ break;
+ }
+ *list = newlist;
+ char *tmp = (char*)malloc(len+1);
+ if (tmp) {
+ strncpy(tmp, entry->d_name, len);
+ tmp[len] = '\0';
+ }
+ (*list)[found] = tmp;
+ if (!tmp) {
+ fprintf(stderr, "ERROR: Out of memory\n");
+ break;
}
found++;
}
}
closedir(config_dir);
}
- *list = (char**)malloc(sizeof(char*) * (found+1));
- i = 0;
- while (udids) {
- (*list)[i++] = udids->name;
- struct slist_t *old = udids;
- udids = udids->next;
- free(old);
- }
- (*list)[i] = NULL;
+ (*list)[found] = NULL;
if (count) {
*count = found;