diff options
author | Marcus Meissner <marcus@jet.franken.de> | 2020-02-19 07:40:16 +0100 |
---|---|---|
committer | Marcus Meissner <marcus@jet.franken.de> | 2020-02-19 07:40:58 +0100 |
commit | 2afff46f5aef8d03d3be1395a1a4a01005bb6853 (patch) | |
tree | 05a32e2b1409fd8f5e9181b3b5e53007716b4809 | |
parent | d635d68403bb3fb4bde79ca07429376b8dfc0b71 (diff) | |
download | libgphoto2-2afff46f5aef8d03d3be1395a1a4a01005bb6853.tar.gz |
rewrite the port allocation code to not use freed resources,
although this kind of construct likely does not work
fixes crashes with AFL
-rw-r--r-- | camlibs/smal/ultrapocket.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/camlibs/smal/ultrapocket.c b/camlibs/smal/ultrapocket.c index 59a417c10..aa042c95d 100644 --- a/camlibs/smal/ultrapocket.c +++ b/camlibs/smal/ultrapocket.c @@ -385,11 +385,14 @@ static int ultrapocket_reset(Camera *camera) { GPPortInfo oldpi; + GPPortInfo newpi; GPPort *port = camera->port; CameraAbilities cab; unsigned char cmdbuf[0x10]; gp_camera_get_abilities(camera, &cab); GP_DEBUG ("First connect since camera was used - need to reset cam"); + char *val; + GPPortType porttype; /* * this resets the ultrapocket. Messy, but it's what the windows @@ -403,11 +406,20 @@ ultrapocket_reset(Camera *camera) /* -------------- */ sleep(4); /* This should do - _might_ need increasing */ CHECK_RESULT(gp_port_get_info(port, &oldpi)); + gp_port_info_new(&newpi); + gp_port_info_get_name (oldpi, &val); + gp_port_info_set_name (newpi, val); + gp_port_info_get_path (oldpi, &val); + gp_port_info_set_path (newpi, val); + gp_port_info_get_type (oldpi, &porttype); + gp_port_info_set_type (newpi, porttype); + gp_port_info_get_library_filename (oldpi, &val); + gp_port_info_set_library_filename (newpi, val); + CHECK_RESULT(gp_port_free(port)); CHECK_RESULT(gp_port_new(&port)); - CHECK_RESULT(gp_port_set_info(port, oldpi)); - CHECK_RESULT(gp_port_usb_find_device(port, - cab.usb_vendor, cab.usb_product)); + CHECK_RESULT(gp_port_set_info(port, newpi)); + CHECK_RESULT(gp_port_usb_find_device(port, cab.usb_vendor, cab.usb_product)); CHECK_RESULT(gp_port_open(port)); camera->port = port; return GP_OK; |