Bug 14297

Summary: garmintools Error: command 5 not supported
Product: Mageia Reporter: Antonio Carvalho <decarvalhoaa>
Component: RPM PackagesAssignee: Oden Eriksson <oe>
Status: RESOLVED OLD QA Contact:
Severity: critical    
Priority: Normal Keywords: Triaged
Version: 4   
Target Milestone: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Source RPM: lib64garmintools4-0.10-2.mga4.x86_64.rpm CVE:
Status comment:

Description Antonio Carvalho 2014-10-15 22:09:32 CEST
When I try to use any of the garmin tools e.g. garmin_save_runs, I getting "Error: command 5 not supported"
"Segmentation fault"

From http://code.google.com/p/garmintools/issues/detail?id=35, I have found a solution for the problem, compiling it myself. For other less experience users, tt would be good to get a new package released.


protocol.c line 586 has a loop, checking values in the p.packet.data[].  p is a garmin_packet union with a struct called packet and a char array data.  the data member is 1024 bytes long, but packet.data is only defined to be one byte long.  Using gcc 4.8.0 and above, the call to get_uint16 in protocol.c line 587, some how makes its way to calling garmin_send_command before returning from get_uint16 (with 5 as the command since the variable "j" in protocol.c is 5 and is on the right place in the stack when things go awry, resulting in the error seen).  Using gcc 4.7.2 or gcc 4.8.0 without -O produces working code. So apparently there was an optimization added in 4.8.0 that doesn't like the fact that p.packet.data is only defined to be 1 byte long, despite the fact that the union as a whole is defined to be large enough.  Maybe it notices that the "data" member of the local variable p is never accessed and only allocates enough stack for the "packet" member.  In any case, defining the packet.data array to be of length 1012 so that the two members of the garmin_packet union are the same size fixes the problem.

(The reason it only showed up for us Arch users is there aren't many other distros using gcc 4.8.0+.  It worked on my other box because I compiled it before the upgrade of gcc).

Applying the following patch fixes the problem

Index: src/garmin.h
===================================================================
--- src/garmin.h (revision 27)
+++ src/garmin.h (working copy)
@@ -1509,7 +1509,7 @@
    uint8 reserved4;
    uint8 reserved5;
    uint8 size[4];    /* bytes 8-11 */
-   uint8 data[1];    /* bytes 12+ */
+   uint8 data[1012]; /* bytes 12+ */
   } packet;
   char data[1024];
} garmin_packet;


Reproducible: 

Steps to Reproduce:
Manuel Hiebel 2015-02-06 11:10:20 CET

Keywords: (none) => Triaged
Assignee: bugsquad => oe

Comment 1 Oden Eriksson 2015-03-31 14:49:25 CEST
Thank you. This fix has been submitted to mga4 updates_testing and to cauldron. Someone with the power has to submit the package to cauldron.
Comment 2 David Walser 2015-04-04 00:04:43 CEST
garmintools-0.10-6.mga5 uploaded for Cauldron.

Please assign this to QA with an advisory once it's ready to test.

garmintools-0.10-2.1.mga4
libgarmintools4-0.10-2.1.mga4
libgarmintools-devel-0.10-2.1.mga4

from garmintools-0.10-2.1.mga4.src.rpm
Comment 3 Samuel Verschelde 2015-09-21 10:24:31 CEST
Was not assigned to QA apparently. Too late for Mageia 4 now.

Status: NEW => RESOLVED
Resolution: (none) => OLD