summaryrefslogtreecommitdiff
path: root/libgphoto2_port
diff options
context:
space:
mode:
authorMarcus Meissner <meissner@suse.de>2019-04-23 11:44:53 +0200
committerMarcus Meissner <meissner@suse.de>2019-04-23 11:44:53 +0200
commit501978309097bb0cfc456be4ccc515bb4811b193 (patch)
tree33add3264441eae2f75f9715eb4e8c624d524ff5 /libgphoto2_port
parente33b5766a0e3672470ec8f4ef4e651e66d2f78c1 (diff)
downloadlibgphoto2-501978309097bb0cfc456be4ccc515bb4811b193.tar.gz
generic usb fuzzing
the format puts in vendor and product id in front of the fuzz file
Diffstat (limited to 'libgphoto2_port')
-rw-r--r--libgphoto2_port/vusb/vcamera.c5
-rw-r--r--libgphoto2_port/vusb/vcamera.h2
-rw-r--r--libgphoto2_port/vusb/vusb.c35
3 files changed, 38 insertions, 4 deletions
diff --git a/libgphoto2_port/vusb/vcamera.c b/libgphoto2_port/vusb/vcamera.c
index 4939f3b6e..536e09b72 100644
--- a/libgphoto2_port/vusb/vcamera.c
+++ b/libgphoto2_port/vusb/vcamera.c
@@ -1815,6 +1815,11 @@ static int vcam_open(vcamera* cam, const char *port) {
cam->fuzzmode = FUZZMODE_PROTOCOL;
} else {
cam->fuzzf = fopen(s+1,"rb");
+#ifndef FUZZ_PTP
+ /* first 4 byte are vendor and product USB id */
+ if (cam->fuzzf)
+ fseek (cam->fuzzf, 4, SEEK_SET);
+#endif
cam->fuzzpending = 0;
cam->fuzzmode = FUZZMODE_NORMAL;
}
diff --git a/libgphoto2_port/vusb/vcamera.h b/libgphoto2_port/vusb/vcamera.h
index b3c57258c..b6fe4ae3b 100644
--- a/libgphoto2_port/vusb/vcamera.h
+++ b/libgphoto2_port/vusb/vcamera.h
@@ -22,7 +22,7 @@
#ifndef __VCAMERA_H__
#define __VCAMERA_H__
-#define FUZZ_PTP
+#undef FUZZ_PTP
#include <stdio.h>
diff --git a/libgphoto2_port/vusb/vusb.c b/libgphoto2_port/vusb/vusb.c
index d097f565b..b810910bf 100644
--- a/libgphoto2_port/vusb/vusb.c
+++ b/libgphoto2_port/vusb/vusb.c
@@ -272,7 +272,36 @@ gp_port_vusb_find_device_lib(GPPort *port, int idvendor, int idproduct)
#ifdef FUZZ_PTP
if ((idvendor == 0x04b0) && (idproduct == 0x0437)) { /* Nikon D750 */
#else
- if ((idvendor == 0x0851) && (idproduct == 0x1542)) { /* sipix blink */
+ GPPortInfo info;
+ char *path, *s;
+ static unsigned short vendor, product;
+ int fd;
+
+ static char *lastpath = NULL;
+
+ gp_port_get_info (port, &info);
+ gp_port_info_get_path (info, &path);
+
+ if (!lastpath || strcmp(path, lastpath)) {
+ gp_log(GP_LOG_DEBUG,__FUNCTION__,"(path=%s)", path);
+ if (lastpath) {
+ free(lastpath);
+ }
+ lastpath = strdup(path);
+
+ s = strchr(path, ':')+1;
+ fd = open(s, O_RDONLY);
+ vendor = product = 0;
+ if (fd != -1) {
+ if (-1 == read( fd, &vendor, 2))
+ gp_log(GP_LOG_DEBUG,__FUNCTION__,"could not read vendor");
+ if (-1 == read( fd, &product, 2))
+ gp_log(GP_LOG_DEBUG,__FUNCTION__,"could not read product");
+ close(fd);
+ }
+ }
+
+ if ((idvendor == vendor) && (idproduct == product)) {
#endif
port->settings.usb.config = 1;
port->settings.usb.interface = 1;
@@ -284,7 +313,7 @@ gp_port_vusb_find_device_lib(GPPort *port, int idvendor, int idproduct)
port->settings.usb.maxpacketsize = 512;
return GP_OK;
}
- /* gp_log(GP_LOG_DEBUG,__FUNCTION__,"(0x%04x,0x%04x)", idvendor, idproduct); */
+ gp_log(GP_LOG_DEBUG,__FUNCTION__,"(0x%04x,0x%04x)", idvendor, idproduct);
return GP_ERROR_IO_USB_FIND;
}
@@ -305,8 +334,8 @@ gp_port_vusb_find_device_by_class_lib(GPPort *port, int class, int subclass, int
port->settings.usb.maxpacketsize = 512;
return GP_OK;
}
- return GP_ERROR_IO_USB_FIND;
#endif
+ return GP_ERROR_IO_USB_FIND;
}