summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Meissner <marcus@jet.franken.de>2020-01-25 18:29:59 +0100
committerMarcus Meissner <marcus@jet.franken.de>2020-01-25 18:29:59 +0100
commit8a06cb3f5a53a212ef79a877c393088866f7ea15 (patch)
treed0c4a8c27e7d8a5e0c3a2cdc87f149d20d34c48f
parentec549ee2367befc478a700ff5bba3b64d896168a (diff)
downloadlibgphoto2-8a06cb3f5a53a212ef79a877c393088866f7ea15.tar.gz
avoid endless loops (AFL)
-rw-r--r--camlibs/sonix/sonix.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/camlibs/sonix/sonix.c b/camlibs/sonix/sonix.c
index e0164761d..22b2d73f5 100644
--- a/camlibs/sonix/sonix.c
+++ b/camlibs/sonix/sonix.c
@@ -44,24 +44,21 @@
static int
SONIX_READ (GPPort *port, char *data)
{
- gp_port_usb_msg_interface_read(port, 0, 1, 0, data, 1);
- return GP_OK;
+ return gp_port_usb_msg_interface_read(port, 0, 1, 0, data, 1);
}
/* This reads a 4-byte response to a command */
static int
SONIX_READ4 (GPPort *port, char *data)
{
- gp_port_usb_msg_interface_read(port, 0, 4, 0, data, 4);
- return GP_OK;
+ return gp_port_usb_msg_interface_read(port, 0, 4, 0, data, 4);
}
/* A command to the camera is a 6-byte string, and this sends it. */
static int
SONIX_COMMAND (GPPort *port, char *command)
{
- gp_port_usb_msg_interface_write(port, 8, 2, 0, command ,6);
- return GP_OK;
+ return gp_port_usb_msg_interface_write(port, 8, 2, 0, command ,6);
}
@@ -88,7 +85,8 @@ int sonix_init (GPPort *port, CameraPrivateLibrary *priv)
i = 0;
while ((unsigned)status > 0) {
- SONIX_READ(port, &status);
+ if (SONIX_READ(port, &status) < GP_OK)
+ break;
i++;
if (i==1000) break;
}
@@ -97,8 +95,10 @@ int sonix_init (GPPort *port, CameraPrivateLibrary *priv)
SONIX_COMMAND ( port, c);
- while (status !=2)
- SONIX_READ(port, &status);
+ while (status !=2) {
+ if (SONIX_READ(port, &status) < GP_OK)
+ break;
+ }
/* FIXME(Marcus): was indented at above level, unclear if it is needed this way ... */
SONIX_READ(port, &status);
@@ -117,7 +117,8 @@ int sonix_init (GPPort *port, CameraPrivateLibrary *priv)
while (!reading[1]&&!reading[2]&&!reading[3]) {
c[0]=0x16;
- SONIX_COMMAND ( port, c );
+ if (SONIX_COMMAND ( port, c ) < GP_OK)
+ break;
/*
* For the Vivicam 3350b this always gives
* 96 0a 76 07. This is apparently the firmware version.
@@ -129,7 +130,8 @@ int sonix_init (GPPort *port, CameraPrivateLibrary *priv)
* Spy Camera 70137 it is 96 01 31 09. Since the cameras
* have different abilities, we ought to distinguish.
*/
- SONIX_READ4 (port, (char *)reading);
+ if (SONIX_READ4 (port, (char *)reading) < GP_OK)
+ break;
}
GP_DEBUG("%02x %02x %02x %02x\n", reading[0], reading[1],
reading[2], reading[3]);