summaryrefslogtreecommitdiff
path: root/camlibs
diff options
context:
space:
mode:
authorMarcus Meissner <marcus@jet.franken.de>2021-09-19 15:49:14 +0200
committerMarcus Meissner <marcus@jet.franken.de>2021-09-19 15:49:14 +0200
commitca1568067d2e71ee11b494b6c325990d0c9546c8 (patch)
treed2b3add1d22d495e8eb6e09d10d7f1e2475a994a /camlibs
parent196ded1f0059f3e90334e46ce966a9009e7defad (diff)
downloadlibgphoto2-ca1568067d2e71ee11b494b6c325990d0c9546c8.tar.gz
pass lenght of datablobs into the directory compare function to avoid overreads
Diffstat (limited to 'camlibs')
-rw-r--r--camlibs/canon/canon.c12
-rw-r--r--camlibs/canon/canon.h3
-rw-r--r--camlibs/canon/usb.c14
3 files changed, 17 insertions, 12 deletions
diff --git a/camlibs/canon/canon.c b/camlibs/canon/canon.c
index b8ca56393..9393f0b0e 100644
--- a/camlibs/canon/canon.c
+++ b/camlibs/canon/canon.c
@@ -1284,7 +1284,9 @@ canon_int_capture_preview (Camera *camera, unsigned char **data, unsigned int *l
* canon_int_find_new_image:
* @camera: Camera * to this camera
* @initial_state: Camera directory dump before image capture
+ * @initial_state_len: Lengt of before dump
* @final_state: Directory dump after image capture
+ * @final_state_len: Length of after dump
* @path: Will be filled in with the path and filename of the captured
* image, in canonical gphoto2 format.
*
@@ -1293,8 +1295,11 @@ canon_int_capture_preview (Camera *camera, unsigned char **data, unsigned int *l
* and its pathname is decoded into the given CameraFilePath.
*
*/
-void canon_int_find_new_image ( Camera *camera, unsigned char *initial_state, unsigned char *final_state,
- CameraFilePath *path )
+void canon_int_find_new_image (
+ Camera *camera,
+ unsigned char *initial_state, unsigned int initial_state_length,
+ unsigned char *final_state, unsigned int final_state_length,
+ CameraFilePath *path )
{
char *old_entry = (char *)initial_state, *new_entry = (char *)final_state;
@@ -1633,12 +1638,13 @@ canon_int_capture_image (Camera *camera, CameraFilePath *path,
}
/* Find new file name in camera directory */
- canon_int_find_new_image ( camera, initial_state, final_state, path );
+ canon_int_find_new_image ( camera, initial_state, initial_state_len, final_state, final_state_len, path );
/* Save this state to the camera directory state */
if (camera->pl->directory_state)
free (camera->pl->directory_state);
camera->pl->directory_state = final_state;
+ camera->pl->directory_state_length = final_state_len;
free ( initial_state );
break;
diff --git a/camlibs/canon/canon.h b/camlibs/canon/canon.h
index 34750ac2d..06cec2b3f 100644
--- a/camlibs/canon/canon.h
+++ b/camlibs/canon/canon.h
@@ -497,6 +497,7 @@ struct _CameraPrivateLibrary
int cached_ready; /* whether the camera is ready to rock */
unsigned char *directory_state; /* directory content state for wait_for_event */
+ unsigned int directory_state_length; /* length of directory content state for wait_for_event */
long image_key, thumb_length, image_length; /* For immediate download of captured image */
long image_b_key, image_b_length; /* For immediate download of secondary captured image */
@@ -722,7 +723,7 @@ int canon_int_get_zoom(Camera *camera, unsigned char *zoom_level, unsigned char
*/
int canon_int_get_release_params (Camera *camera, GPContext *context);
-void canon_int_find_new_image ( Camera *camera, unsigned char *initial_state, unsigned char *final_state, CameraFilePath *path );
+void canon_int_find_new_image ( Camera *camera, unsigned char *initial_state, unsigned int initial_state_length, unsigned char *final_state, unsigned int final_state_length, CameraFilePath *path );
/* path conversion - needs drive letter, and therefore cannot be moved
diff --git a/camlibs/canon/usb.c b/camlibs/canon/usb.c
index d43d32bb6..c655b3c1d 100644
--- a/camlibs/canon/usb.c
+++ b/camlibs/canon/usb.c
@@ -940,11 +940,11 @@ canon_usb_wait_for_event (Camera *camera, int timeout,
unsigned char *final_state = NULL; /* For comparing
* before/after
* directories */
- unsigned int directory_state_len, final_state_len;
+ unsigned int final_state_len;
int status = GP_OK;
if (!camera->pl->directory_state)
- status = canon_usb_list_all_dirs ( camera, &camera->pl->directory_state, &directory_state_len, context );
+ status = canon_usb_list_all_dirs ( camera, &camera->pl->directory_state, &camera->pl->directory_state_length, context );
if (status < GP_OK) {
GP_DEBUG ("canon_usb_wait_for_event: status %d", status);
return status;
@@ -967,7 +967,7 @@ canon_usb_wait_for_event (Camera *camera, int timeout,
if (status < GP_OK)
return status;
/* Find new file name in camera directory */
- canon_int_find_new_image ( camera, camera->pl->directory_state, final_state, path );
+ canon_int_find_new_image ( camera, camera->pl->directory_state, camera->pl->directory_state_length, final_state, final_state_len, path );
if (path->folder[0] != '/') {
free (path);
*eventtype = GP_EVENT_UNKNOWN;
@@ -976,6 +976,7 @@ canon_usb_wait_for_event (Camera *camera, int timeout,
}
free ( camera->pl->directory_state );
camera->pl->directory_state = final_state;
+ camera->pl->directory_state_length = final_state_len;
return GP_OK;
}
default:
@@ -1022,11 +1023,8 @@ canon_usb_capture_dialogue (Camera *camera, unsigned int *return_length, int *ph
*return_length = 0;
/* for later wait_event */
- if (!camera->pl->directory_state) {
- unsigned int directory_state_len;
-
- status = canon_usb_list_all_dirs ( camera, &camera->pl->directory_state, &directory_state_len, context );
- }
+ if (!camera->pl->directory_state)
+ status = canon_usb_list_all_dirs ( camera, &camera->pl->directory_state, &camera->pl->directory_state_length, context );
GP_DEBUG ("canon_usb_capture_dialogue()");