The branch, master has been updated
via 7c21beca63e7d4b07d7ebff25428ca4cfdbc8ec5 (commit)
from a67c3be47d1af396f4ad1eb7e770fb3be4d58334 (commit)
- Log -----------------------------------------------------------------
commit 7c21beca63e7d4b07d7ebff25428ca4cfdbc8ec5
Author: Thomas Jarosch <thomas.jarosch@xxxxxxxxxxxxx>
Date: Sun Dec 23 17:53:25 2012 +0100
C++ wrapper: Fix use-after-free issue in List::find_all()
We can no longer call ftdi_deinit() inside find_all().
This will call libusb_exit() which invalidates all further
operations on device lists / usb devices pointers.
Instead we pass in the Ftdi::Context from the calling side.
-----------------------------------------------------------------------
Summary of changes:
examples/find_all_pp.cpp | 3 ++-
ftdipp/ftdi.cpp | 7 ++-----
ftdipp/ftdi.hpp | 2 +-
3 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/examples/find_all_pp.cpp b/examples/find_all_pp.cpp
index cf1675b..4061cd9 100644
--- a/examples/find_all_pp.cpp
+++ b/examples/find_all_pp.cpp
@@ -45,7 +45,8 @@ int main(int argc, char **argv)
<< std::endl << std::dec;
// Print whole list
- List* list = List::find_all(vid, pid);
+ Context context;
+ List* list = List::find_all(context, vid, pid);
for (List::iterator it = list->begin(); it != list->end(); it++)
{
std::cout << "FTDI (" << &*it << "): "
diff --git a/ftdipp/ftdi.cpp b/ftdipp/ftdi.cpp
index e2755d8..95f62a0 100644
--- a/ftdipp/ftdi.cpp
+++ b/ftdipp/ftdi.cpp
@@ -619,13 +619,10 @@ List::iterator List::erase(iterator beg, iterator end)
return d->list.erase(beg, end);
}
-List* List::find_all(int vendor, int product)
+List* List::find_all(Context &context, int vendor, int product)
{
struct ftdi_device_list* dlist = 0;
- struct ftdi_context ftdi;
- ftdi_init(&ftdi);
- ftdi_usb_find_all(&ftdi, &dlist, vendor, product);
- ftdi_deinit(&ftdi);
+ ftdi_usb_find_all(context.context(), &dlist, vendor, product);
return new List(dlist);
}
diff --git a/ftdipp/ftdi.hpp b/ftdipp/ftdi.hpp
index ec0e13d..d853717 100644
--- a/ftdipp/ftdi.hpp
+++ b/ftdipp/ftdi.hpp
@@ -174,7 +174,7 @@ public:
List(struct ftdi_device_list* devlist = 0);
~List();
- static List* find_all(int vendor, int product);
+ static List* find_all(Context &context, int vendor, int product);
/// List type storing "Context" objects
typedef std::list<Context> ListType;
hooks/post-receive
--
A library to talk to FTDI chips
--
libftdi-git - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi-git+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx
|