From 6f377182f537e60503b4629d8c09b2327c5365d4 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Fri, 21 Sep 2018 14:21:35 -0700 Subject: [PATCH] garmin: relax FIT filename rules for Descent Mk1 When on the actual watch, the filename format for the FIT files ends up being something like 2018-09-21-10-23-36.fit but then if you download the activity from the Garmin Connect activity website, it might show up as a ZIP file that contains a file named something like 3030954326.fit instead. In order to make it easy to import these fit files that have been downloaded from the Garmin cloud, relax the filename rules a bit. NOTE! You still need to have the proper directory structure, and put your FIT files in a subdirectory like /Garmin/Activity/ to match the way the FIT files show up when you mount the Garmin Descent locally. You can then point subsurface to when you do a "download" from the Garmin Descent, regardless of whether it's an actual case of the dive computer being mounted, or if you've downloaded the FIT files to your local filesystem. Reported-by: Andrew Trevor-Jones Signed-off-by: Linus Torvalds --- src/garmin.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/garmin.c b/src/garmin.c index 32a5936..aad9b92 100644 --- a/src/garmin.c +++ b/src/garmin.c @@ -130,8 +130,11 @@ static int get_file_list(DIR *dir, struct file_list *files) while ((de = readdir(dir)) != NULL) { int len = strlen(de->d_name); + struct fit_name *entry; - if (len != FIT_NAME_SIZE-1) + if (len < 5) + continue; + if (len >= FIT_NAME_SIZE) continue; if (strncasecmp(de->d_name + len - 4, ".FIT", 4)) continue; @@ -150,7 +153,14 @@ static int get_file_list(DIR *dir, struct file_list *files) files->allocated = n; } - memcpy(files->array + files->nr++, de->d_name, FIT_NAME_SIZE); + /* + * NOTE! This depends on the zero-padding that strncpy does. + * + * strncpy() doesn't just limit the size of the copy, it + * will zero-pad the end of the result buffer. + */ + entry = files->array + files->nr++; + strncpy(entry->name, de->d_name, FIT_NAME_SIZE); } qsort(files->array, files->nr, sizeof(struct fit_name), name_cmp);