backends: A 0-length read when doing our inital header load is

and EOF, so treat it as such and don't error out.
This commit is contained in:
Solomon Peachy 2014-01-20 19:41:52 -05:00
parent 3cb593f36d
commit 2eb20f90f4
8 changed files with 30 additions and 11 deletions

View File

@ -367,11 +367,13 @@ static int canonselphy_early_parse(void *vctx, int data_fd)
int printer_type, i; int printer_type, i;
if (!ctx) if (!ctx)
return 1; return -1;
/* Figure out printer this file is intended for */ /* Figure out printer this file is intended for */
i = read(data_fd, ctx->buffer, MAX_HEADER); i = read(data_fd, ctx->buffer, MAX_HEADER);
if (i < 0 || i != MAX_HEADER) { if (i < 0 || i != MAX_HEADER) {
if (i == 0)
return -1;
ERROR("Read failed (%d/%d/%d)\n", ERROR("Read failed (%d/%d/%d)\n",
i, 0, MAX_HEADER); i, 0, MAX_HEADER);
perror("ERROR: Read failed"); perror("ERROR: Read failed");
@ -654,7 +656,7 @@ top:
struct dyesub_backend canonselphy_backend = { struct dyesub_backend canonselphy_backend = {
.name = "Canon SELPHY CP/ES", .name = "Canon SELPHY CP/ES",
.version = "0.64", .version = "0.65",
.multipage_capable = 1, .multipage_capable = 1,
.uri_prefix = "canonselphy", .uri_prefix = "canonselphy",
.init = canonselphy_init, .init = canonselphy_init,

View File

@ -389,6 +389,8 @@ static int dnpds40_read_parse(void *vctx, int data_fd) {
/* Add in the size of this chunk */ /* Add in the size of this chunk */
ctx->datalen += sizeof(struct dnpds40_cmd) + j; ctx->datalen += sizeof(struct dnpds40_cmd) + j;
} }
if (!ctx->datalen)
return 1;
return 0; return 0;
} }
@ -898,7 +900,7 @@ static int dnpds40_cmdline_arg(void *vctx, int run, char *arg1, char *arg2)
/* Exported */ /* Exported */
struct dyesub_backend dnpds40_backend = { struct dyesub_backend dnpds40_backend = {
.name = "DNP DS40/DS80", .name = "DNP DS40/DS80",
.version = "0.22", .version = "0.23",
.uri_prefix = "dnpds40", .uri_prefix = "dnpds40",
.multipage_capable = 1, .multipage_capable = 1,
.cmdline_usage = dnpds40_cmdline, .cmdline_usage = dnpds40_cmdline,

View File

@ -307,6 +307,8 @@ static int kodak1400_read_parse(void *vctx, int data_fd) {
/* Read in then validate header */ /* Read in then validate header */
ret = read(data_fd, &ctx->hdr, sizeof(ctx->hdr)); ret = read(data_fd, &ctx->hdr, sizeof(ctx->hdr));
if (ret < 0 || ret != sizeof(ctx->hdr)) { if (ret < 0 || ret != sizeof(ctx->hdr)) {
if (ret == 0)
return 1;
ERROR("Read failed (%d/%d/%d)\n", ERROR("Read failed (%d/%d/%d)\n",
ret, 0, (int)sizeof(ctx->hdr)); ret, 0, (int)sizeof(ctx->hdr));
perror("ERROR: Read failed"); perror("ERROR: Read failed");
@ -566,7 +568,7 @@ top:
struct dyesub_backend kodak1400_backend = { struct dyesub_backend kodak1400_backend = {
.name = "Kodak 1400/805", .name = "Kodak 1400/805",
.version = "0.27", .version = "0.28",
.uri_prefix = "kodak1400", .uri_prefix = "kodak1400",
.multipage_capable = 1, .multipage_capable = 1,
.cmdline_usage = kodak1400_cmdline, .cmdline_usage = kodak1400_cmdline,

View File

@ -130,6 +130,8 @@ static int kodak605_read_parse(void *vctx, int data_fd) {
/* Read in then validate header */ /* Read in then validate header */
ret = read(data_fd, &ctx->hdr, sizeof(ctx->hdr)); ret = read(data_fd, &ctx->hdr, sizeof(ctx->hdr));
if (ret < 0 || ret != sizeof(ctx->hdr)) { if (ret < 0 || ret != sizeof(ctx->hdr)) {
if (ret == 0)
return 1;
ERROR("Read failed (%d/%d/%d)\n", ERROR("Read failed (%d/%d/%d)\n",
ret, 0, (int)sizeof(ctx->hdr)); ret, 0, (int)sizeof(ctx->hdr));
perror("ERROR: Read failed"); perror("ERROR: Read failed");
@ -491,7 +493,7 @@ static int kodak605_cmdline_arg(void *vctx, int run, char *arg1, char *arg2)
/* Exported */ /* Exported */
struct dyesub_backend kodak605_backend = { struct dyesub_backend kodak605_backend = {
.name = "Kodak 605", .name = "Kodak 605",
.version = "0.14", .version = "0.15",
.uri_prefix = "kodak605", .uri_prefix = "kodak605",
.multipage_capable = 1, .multipage_capable = 1,
.cmdline_usage = kodak605_cmdline, .cmdline_usage = kodak605_cmdline,

View File

@ -356,6 +356,8 @@ static int kodak6800_read_parse(void *vctx, int data_fd) {
/* Read in then validate header */ /* Read in then validate header */
ret = read(data_fd, &ctx->hdr, sizeof(ctx->hdr)); ret = read(data_fd, &ctx->hdr, sizeof(ctx->hdr));
if (ret < 0 || ret != sizeof(ctx->hdr)) { if (ret < 0 || ret != sizeof(ctx->hdr)) {
if (ret == 0)
return 1;
ERROR("Read failed (%d/%d/%d)\n", ERROR("Read failed (%d/%d/%d)\n",
ret, 0, (int)sizeof(ctx->hdr)); ret, 0, (int)sizeof(ctx->hdr));
perror("ERROR: Read failed"); perror("ERROR: Read failed");
@ -604,7 +606,7 @@ skip_query:
/* Exported */ /* Exported */
struct dyesub_backend kodak6800_backend = { struct dyesub_backend kodak6800_backend = {
.name = "Kodak 6800/6850", .name = "Kodak 6800/6850",
.version = "0.28", .version = "0.29",
.uri_prefix = "kodak6800", .uri_prefix = "kodak6800",
.multipage_capable = 1, .multipage_capable = 1,
.cmdline_usage = kodak6800_cmdline, .cmdline_usage = kodak6800_cmdline,

View File

@ -136,6 +136,8 @@ static int mitsu70x_read_parse(void *vctx, int data_fd) {
remain = sizeof(hdr); remain = sizeof(hdr);
while (remain > 0) { while (remain > 0) {
i = read(data_fd, hdr + sizeof(hdr) - remain, remain); i = read(data_fd, hdr + sizeof(hdr) - remain, remain);
if (i == 0)
return 1;
if (i < 0) if (i < 0)
return i; return i;
remain -= i; remain -= i;

View File

@ -1370,6 +1370,9 @@ static void *shinkos2145_init(void)
return NULL; return NULL;
memset(ctx, 0, sizeof(struct shinkos2145_ctx)); memset(ctx, 0, sizeof(struct shinkos2145_ctx));
if (getenv("FAST_RETURN"))
ctx->fast_return = 1;
return ctx; return ctx;
} }
@ -1411,12 +1414,11 @@ static int shinkos2145_read_parse(void *vctx, int data_fd) {
if (ctx->databuf) if (ctx->databuf)
free(ctx->databuf); free(ctx->databuf);
if (getenv("FAST_RETURN"))
ctx->fast_return = 1;
/* Read in then validate header */ /* Read in then validate header */
ret = read(data_fd, &ctx->hdr, sizeof(ctx->hdr)); ret = read(data_fd, &ctx->hdr, sizeof(ctx->hdr));
if (ret < 0 || ret != sizeof(ctx->hdr)) { if (ret < 0 || ret != sizeof(ctx->hdr)) {
if (ret == 0)
return 1;
ERROR("Read failed (%d/%d/%d)\n", ERROR("Read failed (%d/%d/%d)\n",
ret, 0, (int)sizeof(ctx->hdr)); ret, 0, (int)sizeof(ctx->hdr));
perror("ERROR: Read failed"); perror("ERROR: Read failed");
@ -1661,7 +1663,7 @@ static int shinkos2145_query_serno(struct libusb_device_handle *dev, uint8_t end
struct dyesub_backend shinkos2145_backend = { struct dyesub_backend shinkos2145_backend = {
.name = "Shinko/Sinfonia CHC-S2145 (S2)", .name = "Shinko/Sinfonia CHC-S2145 (S2)",
.version = "0.27", .version = "0.28",
.multipage_capable = 1, .multipage_capable = 1,
.uri_prefix = "shinkos2145", .uri_prefix = "shinkos2145",
.cmdline_usage = shinkos2145_cmdline, .cmdline_usage = shinkos2145_cmdline,

View File

@ -103,6 +103,8 @@ static int updr150_read_parse(void *vctx, int data_fd) {
i = read(data_fd, ctx->databuf + ctx->datalen, 4); i = read(data_fd, ctx->databuf + ctx->datalen, 4);
if (i < 0) if (i < 0)
return i; return i;
if (i == 0)
break;
ptr = (uint32_t *) ctx->databuf + ctx->datalen; ptr = (uint32_t *) ctx->databuf + ctx->datalen;
len = le32_to_cpu(*ptr); len = le32_to_cpu(*ptr);
@ -159,6 +161,9 @@ static int updr150_read_parse(void *vctx, int data_fd) {
len -= i; len -= i;
} }
} }
if (!ctx->datalen)
return 1;
return 0; return 0;
} }
@ -203,7 +208,7 @@ top:
struct dyesub_backend updr150_backend = { struct dyesub_backend updr150_backend = {
.name = "Sony UP-DR150", .name = "Sony UP-DR150",
.version = "0.09", .version = "0.10",
.uri_prefix = "sonyupdr150", .uri_prefix = "sonyupdr150",
.multipage_capable = 1, .multipage_capable = 1,
.init = updr150_init, .init = updr150_init,