diff --git a/src/citizen_aqualand.c b/src/citizen_aqualand.c index 21894a5..99e60e6 100644 --- a/src/citizen_aqualand.c +++ b/src/citizen_aqualand.c @@ -185,7 +185,10 @@ citizen_aqualand_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) return status; } - dc_buffer_append(buffer, answer, sizeof (answer)); + if (!dc_buffer_append(buffer, answer, sizeof (answer))) { + ERROR (abstract->context, "Insufficient buffer space available."); + return status; + } // Send the command. status = dc_iostream_write (device->iostream, command, sizeof (command), NULL); diff --git a/src/divesystem_idive.c b/src/divesystem_idive.c index c3d21bd..f2976b1 100644 --- a/src/divesystem_idive.c +++ b/src/divesystem_idive.c @@ -493,7 +493,12 @@ divesystem_idive_device_foreach (dc_device_t *abstract, dc_dive_callback_t callb dc_buffer_clear(buffer); dc_buffer_reserve(buffer, commands->header.size + commands->sample.size * nsamples); - dc_buffer_append(buffer, packet, commands->header.size); + + if (!dc_buffer_append(buffer, packet, commands->header.size)) { + ERROR (abstract->context, "Insufficient buffer space available."); + dc_buffer_free(buffer); + return rc; + } for (unsigned int j = 0; j < nsamples; j += commands->nsamples) { unsigned int idx = j + 1; @@ -518,7 +523,11 @@ divesystem_idive_device_foreach (dc_device_t *abstract, dc_dive_callback_t callb progress.current = i * NSTEPS + STEP(j + n + 1, nsamples + 1); device_event_emit (abstract, DC_EVENT_PROGRESS, &progress); - dc_buffer_append(buffer, packet, commands->sample.size * n); + if (!dc_buffer_append(buffer, packet, commands->sample.size * n)) { + ERROR (abstract->context, "Insufficient buffer space available."); + dc_buffer_free(buffer); + return rc; + } } unsigned char *data = dc_buffer_get_data(buffer); diff --git a/src/hw_ostc.c b/src/hw_ostc.c index 941b3ef..c47af16 100644 --- a/src/hw_ostc.c +++ b/src/hw_ostc.c @@ -587,7 +587,10 @@ hw_ostc_device_screenshot (dc_device_t *abstract, dc_buffer_t *buffer, hw_ostc_f if (format == HW_OSTC_FORMAT_RAW) { // Append the raw data to the output buffer. - dc_buffer_append (buffer, raw, nbytes); + if (!dc_buffer_append (buffer, raw, nbytes)) { + ERROR (abstract->context, "Insufficient buffer space available."); + return DC_STATUS_NOMEMORY; + } } else { // Store the decompressed data in the output buffer. for (unsigned int i = 0; i < count; ++i) { diff --git a/src/hw_ostc3.c b/src/hw_ostc3.c index 0391c53..5dec754 100644 --- a/src/hw_ostc3.c +++ b/src/hw_ostc3.c @@ -1150,7 +1150,11 @@ hw_ostc3_firmware_readfile4 (dc_buffer_t *buffer, dc_context_t *context, const c size_t n = 0; unsigned char block[1024] = {0}; while ((n = fread (block, 1, sizeof (block), fp)) > 0) { - dc_buffer_append (buffer, block, n); + if (!dc_buffer_append (buffer, block, n)) { + ERROR (context, "Insufficient buffer space available."); + fclose (fp); + return DC_STATUS_NOMEMORY; + } } // Close the file. diff --git a/src/suunto_eonsteel.c b/src/suunto_eonsteel.c index db272d0..bac7e22 100644 --- a/src/suunto_eonsteel.c +++ b/src/suunto_eonsteel.c @@ -94,6 +94,15 @@ static const dc_device_vtable_t suunto_eonsteel_device_vtable = { static const char dive_directory[] = "0:/dives"; +static void file_list_free (struct directory_entry *de) +{ + while (de) { + struct directory_entry *next = de->next; + free (de); + de = next; + } +} + static struct directory_entry *alloc_dirent(int type, int len, const char *name) { struct directory_entry *res; @@ -414,7 +423,10 @@ static int read_file(suunto_eonsteel_device_t *eon, const char *filename, dc_buf if (got > size) got = size; - dc_buffer_append(buf, result+8, got); + if (!dc_buffer_append (buf, result + 8, got)) { + ERROR (eon->base.context, "Insufficient buffer space available."); + return -1; + } offset += got; size -= got; } @@ -674,7 +686,13 @@ suunto_eonsteel_device_foreach(dc_device_t *abstract, dc_dive_callback_t callbac de = de->next; } - file = dc_buffer_new(0); + file = dc_buffer_new (16384); + if (file == NULL) { + ERROR (abstract->context, "Insufficient buffer space available."); + file_list_free (latest); + return DC_STATUS_NOMEMORY; + } + progress.maximum = count; progress.current = 0; device_event_emit(abstract, DC_EVENT_PROGRESS, &progress);