fixed NULL-pointer dereference in the ftdi_error_return(code, str) macro that occures...
authorPeter Schneider <pitpompej@arcor.de>
Wed, 25 Jul 2012 13:26:23 +0000 (15:26 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Sat, 28 Jul 2012 16:01:40 +0000 (18:01 +0200)
Hi,

as we just performed a Cppcheck run upon our project including the libftdi sources it found a possible null-pointer dereference when calling the ftdi_error_return(code, str) macro after the ftdi==NULL check.

Fix for this bug:

src/ftdi.c

index 07687e8..5a3d44e 100644 (file)
 #include "ftdi_version_i.h"
 
 #define ftdi_error_return(code, str) do {  \
-        ftdi->error_str = str;             \
+        if ( ftdi )                        \
+            ftdi->error_str = str;         \
+        else                               \
+            fprintf(stderr, str);          \
         return code;                       \
    } while(0);