many: Fix more memory leaks and outright bugs.

This commit is contained in:
Solomon Peachy 2018-06-17 21:08:17 -04:00
parent 7cb03db04e
commit 43d4812856
7 changed files with 124 additions and 27 deletions

View file

@ -281,8 +281,10 @@ static int selphyneo_read_parse(void *vctx, const void **vjob, int data_fd, int
/* Read the header.. */
i = read(data_fd, &hdr, sizeof(hdr));
if (i != sizeof(hdr)) {
if (i == 0)
if (i == 0) {
selphyneo_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
ERROR("Read failed (%d/%d)\n",
i, (int)sizeof(hdr));
perror("ERROR: Read failed");
@ -300,6 +302,7 @@ static int selphyneo_read_parse(void *vctx, const void **vjob, int data_fd, int
default:
ERROR("Unknown print size! (%02x, %ux%u)\n",
hdr.data[10], le32_to_cpu(hdr.cols), le32_to_cpu(hdr.rows));
selphyneo_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}

View file

@ -1276,8 +1276,10 @@ static int dnpds40_read_parse(void *vctx, const void **vjob, int data_fd, int co
dnpds40_cleanup_job(job);
return i;
}
if (i == 0)
if (i == 0) {
dnpds40_cleanup_job(job);
return 1;
}
job->datalen += i;
remain -= i;
}
@ -1443,6 +1445,7 @@ parsed:
if (job->multicut > 100 &&
ctx->type != P_DNP_DS80D) {
ERROR("Only DS80D supports cut-paper sizes!\n");
dnpds40_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
@ -1513,6 +1516,7 @@ parsed:
if (job->dpi == 334 && ctx->type != P_CITIZEN_CW01)
{
ERROR("Illegal resolution (%u) for printer!\n", job->dpi);
dnpds40_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
@ -1525,6 +1529,7 @@ parsed:
case 200: //"5x3.5 (L)"
if (job->multicut != MULTICUT_5x3_5) {
ERROR("Incorrect media for job loaded (%u vs %u)\n", ctx->media, job->multicut);
dnpds40_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
break;
@ -1532,6 +1537,7 @@ parsed:
if (job->multicut != MULTICUT_5x3_5 && job->multicut != MULTICUT_5x7 &&
job->multicut != MULTICUT_5x3_5X2 && job->multicut != MULTICUT_5x5) {
ERROR("Incorrect media for job loaded (%u vs %u)\n", ctx->media, job->multicut);
dnpds40_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
/* Only 3.5x5 on 7x5 media can be rewound */
@ -1541,6 +1547,7 @@ parsed:
case 300: //"6x4 (PC)"
if (job->multicut != MULTICUT_6x4) {
ERROR("Incorrect media for job loaded (%u vs %u)\n", ctx->media, job->multicut);
dnpds40_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
break;
@ -1549,6 +1556,7 @@ parsed:
job->multicut != MULTICUT_6x4X2 &&
job->multicut != MULTICUT_6x6 && job->multicut != 30) {
ERROR("Incorrect media for job loaded (%u vs %u)\n", ctx->media, job->multicut);
dnpds40_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
/* Only 6x4 on 6x8 media can be rewound */
@ -1561,6 +1569,7 @@ parsed:
job->multicut != MULTICUT_6x6 &&
job->multicut != MULTICUT_6x4_5 && job->multicut != MULTICUT_6x4_5X2) {
ERROR("Incorrect media for job loaded (%u vs %u)\n", ctx->media, job->multicut);
dnpds40_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
/* Only 6x4 or 6x4.5 on 6x9 media can be rewound */
@ -1574,6 +1583,7 @@ parsed:
} else if (job->multicut < MULTICUT_8x10 || job->multicut == MULTICUT_8x12 ||
job->multicut == MULTICUT_8x6X2 || job->multicut >= MULTICUT_8x6_8x5 ) {
ERROR("Incorrect media for job loaded (%u vs %u)\n", ctx->media, job->multicut);
dnpds40_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
@ -1585,6 +1595,7 @@ parsed:
case 510: //"8x12"
if (job->multicut < MULTICUT_8x10 || (job->multicut > MULTICUT_8xA4LEN && !(job->multicut == MULTICUT_8x7 || job->multicut == MULTICUT_8x9))) {
ERROR("Incorrect media for job loaded (%u vs %u)\n", ctx->media, job->multicut);
dnpds40_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
@ -1597,6 +1608,7 @@ parsed:
case 600: //"A4"
if (job->multicut < MULTICUT_A5 || job->multicut > MULTICUT_A4x5X2) {
ERROR("Incorrect media for job loaded (%u vs %u)\n", ctx->media, job->multicut);
dnpds40_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
/* A4xn and A5 can be rewound */
@ -1608,6 +1620,7 @@ parsed:
break;
default:
ERROR("Unknown media (%u vs %u)!\n", ctx->media, job->multicut);
dnpds40_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
} else if (job->multicut < 400) {
@ -1624,6 +1637,7 @@ parsed:
mcut == MULTICUT_S_8x6X2 ||
mcut == MULTICUT_S_8x4X3) {
ERROR("Incorrect media for job loaded (%u vs %u)\n", ctx->duplex_media, job->multicut);
dnpds40_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
break;
@ -1632,37 +1646,44 @@ parsed:
break;
default:
ERROR("Unknown duplexer media (%u vs %u)!\n", ctx->duplex_media, job->multicut);
dnpds40_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
} else {
ERROR("Multicut value out of range! (%u)\n", job->multicut);
dnpds40_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
/* Additional santity checks, make sure printer support exists */
if (!ctx->supports_6x6 && job->multicut == MULTICUT_6x6) {
ERROR("Printer does not support 6x6 prints, aborting!\n");
dnpds40_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
if (!ctx->supports_5x5 && job->multicut == MULTICUT_5x5) {
ERROR("Printer does not support 5x5 prints, aborting!\n");
dnpds40_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
if ((job->multicut == MULTICUT_6x4_5 || job->multicut == MULTICUT_6x4_5X2) &&
!ctx->supports_6x4_5) {
ERROR("Printer does not support 6x4.5 prints, aborting!\n");
dnpds40_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
if (job->multicut == MULTICUT_6x9 && !ctx->supports_6x9) {
ERROR("Printer does not support 6x9 prints, aborting!\n");
dnpds40_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
if (job->multicut == MULTICUT_5x3_5X2 && !ctx->supports_3x5x2) {
ERROR("Printer does not support 3.5x5*2 prints, aborting!\n");
dnpds40_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
@ -1671,6 +1692,7 @@ skip_multicut:
if (job->fullcut && !ctx->supports_adv_fullcut &&
job->multicut != MULTICUT_6x8) {
ERROR("Printer does not support full control on sizes other than 6x8, aborting!\n");
dnpds40_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
@ -1678,10 +1700,12 @@ skip_multicut:
if (job->multicut == MULTICUT_6x4 || job->multicut == MULTICUT_6x8) {
if (!ctx->supports_2x6) {
ERROR("Printer does not support 2x6 prints, aborting!\n");
dnpds40_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
} else {
ERROR("Printer only supports legacy 2-inch cuts on 4x6 or 8x6 jobs!");
dnpds40_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
}

View file

@ -828,8 +828,8 @@ static int magicard_read_parse(void *vctx, const void **vjob, int data_fd, int c
while (remain > 0) {
i = read(data_fd, job->databuf + job->datalen, remain);
if (i < 0) {
magicard_cleanup_job(job);
ERROR("Data Read Error: %d (%u) @%d)\n", i, remain, job->datalen);
magicard_cleanup_job(job);
return i;
}
if (i == 0) {

View file

@ -873,10 +873,14 @@ repeat:
remain = sizeof(mhdr);
while (remain > 0) {
i = read(data_fd, ((uint8_t*)&mhdr) + sizeof(mhdr) - remain, remain);
if (i == 0)
if (i == 0) {
mitsu70x_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
if (i < 0)
}
if (i < 0) {
mitsu70x_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
remain -= i;
}
@ -893,6 +897,7 @@ repeat:
mhdr.hdr[1] != 0x5a ||
mhdr.hdr[2] != 0x54) {
ERROR("Unrecognized data format!\n");
mitsu70x_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
@ -1022,6 +1027,7 @@ repeat:
if (!job->databuf) {
ERROR("Memory allocation failure!\n");
mitsu70x_cleanup_job(job);
return CUPS_BACKEND_RETRY_CURRENT;
}
@ -1034,10 +1040,14 @@ repeat:
/* Read in the spool data */
while(remain) {
i = read(data_fd, job->databuf + job->datalen, remain);
if (i == 0)
if (i == 0) {
mitsu70x_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
if (i < 0)
}
if (i < 0) {
mitsu70x_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
job->datalen += i;
remain -= i;
}
@ -1052,6 +1062,7 @@ repeat:
spoolbuf = malloc(remain);
if (!spoolbuf) {
ERROR("Memory allocation failure!\n");
mitsu70x_cleanup_job(job);
return CUPS_BACKEND_RETRY_CURRENT;
}
@ -1059,10 +1070,12 @@ repeat:
while (remain) {
i = read(data_fd, spoolbuf + spoolbuflen, remain);
if (i == 0) {
mitsu70x_cleanup_job(job);
free(spoolbuf);
return CUPS_BACKEND_CANCEL;
}
if (i < 0) {
mitsu70x_cleanup_job(job);
free(spoolbuf);
return CUPS_BACKEND_CANCEL;
}
@ -1076,16 +1089,19 @@ repeat:
uint8_t *buf = malloc(LUT_LEN);
if (!buf) {
ERROR("Memory allocation failure!\n");
mitsu70x_cleanup_job(job);
return CUPS_BACKEND_RETRY_CURRENT;
}
if (ctx->Get3DColorTable(buf, job->lutfname)) {
ERROR("Unable to open LUT file '%s'\n", job->lutfname);
mitsu70x_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
ctx->lut = ctx->Load3DColorTable(buf);
free(buf);
if (!ctx->lut) {
ERROR("Unable to parse LUT file '%s'!\n", job->lutfname);
mitsu70x_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
ctx->DoColorConv(ctx->lut, spoolbuf, job->cols, job->rows, job->cols * 3, COLORCONV_BGR);
@ -1102,6 +1118,7 @@ repeat:
ctx->cpcdata = ctx->GetCPCData(job->cpcfname);
if (!ctx->cpcdata) {
ERROR("Unable to load CPC file '%s'\n", job->cpcfname);
mitsu70x_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
}
@ -1115,6 +1132,7 @@ repeat:
ctx->ecpcdata = ctx->GetCPCData(job->ecpcfname);
if (!ctx->ecpcdata) {
ERROR("Unable to load CPC file '%s'\n", job->cpcfname);
mitsu70x_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
} else {
@ -1139,11 +1157,13 @@ repeat:
if (ctx->DoImageEffect(ctx->cpcdata, ctx->ecpcdata,
&input, &ctx->output, job->sharpen, job->reverse, rew)) {
ERROR("Image Processing failed, aborting!\n");
mitsu70x_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
} else {
// XXXFALLBACK write fallback code?
ERROR("!!! Image Processing Library not found, aborting!\n");
mitsu70x_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
@ -1161,6 +1181,7 @@ repeat:
fd = open(job->laminatefname, O_RDONLY);
if (fd < 0) {
ERROR("Unable to open matte lamination data file '%s'\n", job->laminatefname);
mitsu70x_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
@ -1170,8 +1191,10 @@ repeat:
/* Read one row of lamination data at a time */
while (remain) {
i = read(fd, job->databuf + job->datalen, remain);
if (i < 0)
if (i < 0) {
mitsu70x_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
if (i == 0) {
/* We hit EOF, restart from beginning */
lseek(fd, 0, SEEK_SET);

View file

@ -619,10 +619,14 @@ top:
remain = sizeof(buf);
while (remain > 0) {
i = read(data_fd, buf + sizeof(buf) - remain, remain);
if (i == 0)
if (i == 0) {
mitsu9550_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
if (i < 0)
}
if (i < 0) {
mitsu9550_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
remain -= i;
}
@ -631,6 +635,7 @@ top:
if (!job->hdr1_present || !job->hdr2_present) {
ERROR("Unrecognized data format (%02x%02x%02x%02x)!\n",
buf[0], buf[1], buf[2], buf[3]);
mitsu9550_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
} else if (buf[0] == 0x1b &&
buf[1] == 0x5a &&
@ -646,6 +651,7 @@ top:
} else {
ERROR("Unrecognized data block (%02x%02x%02x%02x)!\n",
buf[0], buf[1], buf[2], buf[3]);
mitsu9550_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
}
@ -675,6 +681,7 @@ top:
break;
default:
ERROR("Unrecognized header format (%02x)!\n", buf[2]);
mitsu9550_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
@ -691,18 +698,22 @@ hdr_done:
fd = open(MITSU_M98xx_DATATABLE_FILE, O_RDONLY);
if (fd < 0) {
ERROR("Unable to open 98xx data table file '%s'\n", MITSU_M98xx_DATATABLE_FILE);
mitsu9550_cleanup_job(job);
return CUPS_BACKEND_FAILED;
}
ctx->m98xxdata = malloc(DATATABLE_SIZE);
if (!ctx->m98xxdata) {
ERROR("Memory allocation Failure!\n");
mitsu9550_cleanup_job(job);
return CUPS_BACKEND_RETRY_CURRENT;
}
remain = DATATABLE_SIZE;
while (remain) {
i = read(fd, ((uint8_t*)ctx->m98xxdata) + (DATATABLE_SIZE - remain), remain);
if (i < 0)
if (i < 0) {
mitsu9550_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
remain -= i;
}
close(fd);
@ -745,6 +756,7 @@ hdr_done:
job->databuf = malloc(remain);
if (!job->databuf) {
ERROR("Memory allocation failure!\n");
mitsu9550_cleanup_job(job);
return CUPS_BACKEND_RETRY_CURRENT;
}
@ -759,6 +771,7 @@ hdr_done:
plane->cmd[2] != 0x54) {
ERROR("Unrecognized data read (%02x%02x%02x%02x)!\n",
plane->cmd[0], plane->cmd[1], plane->cmd[2], plane->cmd[3]);
mitsu9550_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
@ -777,10 +790,14 @@ hdr_done:
/* Read in the spool data */
while(planelen > 0) {
i = read(data_fd, job->databuf + job->datalen, planelen);
if (i == 0)
if (i == 0) {
mitsu9550_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
if (i < 0)
}
if (i < 0) {
mitsu9550_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
job->datalen += i;
planelen -= i;
}
@ -790,10 +807,14 @@ hdr_done:
- Job footer (4B)
*/
i = read(data_fd, buf, 4);
if (i == 0)
if (i == 0) {
mitsu9550_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
if (i < 0)
}
if (i < 0) {
mitsu9550_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
/* Is this a "job end" marker? */
if (plane->cmd[0] == 0x1b &&
@ -815,10 +836,14 @@ hdr_done:
/* Read in the rest of the header */
while (remain > 0) {
i = read(data_fd, buf + sizeof(buf) - remain, remain);
if (i == 0)
if (i == 0) {
mitsu9550_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
if (i < 0)
}
if (i < 0) {
mitsu9550_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
remain -= i;
}
}
@ -836,16 +861,19 @@ hdr_done:
uint8_t *buf = malloc(LUT_LEN);
if (!buf) {
ERROR("Memory allocation failure!\n");
mitsu9550_cleanup_job(job);
return CUPS_BACKEND_RETRY_CURRENT;
}
if (CColorConv3D_Get3DColorTable(buf, MITSU_M98xx_LUT_FILE)) {
ERROR("Unable to open LUT file '%s'\n", MITSU_M98xx_LUT_FILE);
mitsu9550_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
lut = CColorConv3D_Load3DColorTable(buf);
free(buf);
if (!lut) {
ERROR("Unable to parse LUT\n");
mitsu9550_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
CColorConv3D_DoColorConv(lut, job->databuf + sizeof(struct mitsu9550_plane),
@ -859,6 +887,7 @@ hdr_done:
newbuf = malloc(remain);
if (!newbuf) {
ERROR("Memory allocation Failure!\n");
mitsu9550_cleanup_job(job);
return CUPS_BACKEND_RETRY_CURRENT;
}
switch (job->hdr2.mode) {
@ -920,8 +949,10 @@ hdr_done:
/* Now handle the matte plane generation */
if (job->hdr1.matte) {
if ((i = mitsu98xx_fillmatte(job)))
if ((i = mitsu98xx_fillmatte(job))) {
mitsu9550_cleanup_job(job);
return i;
}
}
}

View file

@ -205,12 +205,17 @@ static int mitsup95d_read_parse(void *vctx, const void **vjob, int data_fd, int
top:
i = read(data_fd, buf, sizeof(buf));
if (i == 0)
if (i == 0) {
mitsup95d_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
if (i < 0)
}
if (i < 0) {
mitsup95d_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
if (buf[0] != 0x1b) {
ERROR("malformed data stream\n");
mitsup95d_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
@ -244,6 +249,7 @@ top:
break;
default:
ERROR("Unrecognized command! (%02x %02x)\n", buf[0], buf[1]);
mitsup95d_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
@ -253,10 +259,14 @@ top:
while (remain) {
i = read(data_fd, ptr + ptr_offset, remain);
if (i == 0)
if (i == 0) {
mitsup95d_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
if (i < 0)
}
if (i < 0) {
mitsup95d_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
remain -= i;
ptr_offset += i;
@ -279,6 +289,7 @@ top:
if (tmphdr[3] != 46) {
ERROR("Unexpected header chunk: %02x %02x %02x %02x\n",
tmphdr[0], tmphdr[1], tmphdr[2], tmphdr[3]);
mitsup95d_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
switch (tmphdr[2]) {
@ -292,7 +303,7 @@ top:
ptr = job->hdr3;
break;
default:
ERROR("Unexpected header chunk: %02x %02x %02x %02x\n",
WARNING("Unexpected header chunk: %02x %02x %02x %02x\n",
tmphdr[0], tmphdr[1], tmphdr[2], tmphdr[3]);
}
memcpy(ptr, tmphdr, sizeof(tmphdr));
@ -307,20 +318,26 @@ top:
job->databuf = malloc(remain);
if (!job->databuf) {
ERROR("Memory allocation failure!\n");
mitsup95d_cleanup_job(job);
return CUPS_BACKEND_RETRY_CURRENT;
}
/* Read it in */
while (remain) {
i = read(data_fd, job->databuf + job->datalen, remain);
if (i == 0)
if (i == 0) {
mitsup95d_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
if (i < 0)
}
if (i < 0) {
mitsup95d_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
remain -= i;
job->datalen += i;
}
} else if (ptr == job->ftr) {
*vjob = job;
return CUPS_BACKEND_OK;
}
@ -334,8 +351,6 @@ top:
if (job->hdr2[13] != 0xff)
job->hdr2[13] = copies;
*vjob = job;
goto top;
}

View file

@ -195,6 +195,7 @@ static int updr150_read_parse(void *vctx, const void **vjob, int data_fd, int co
default:
if (len & 0xff000000) {
ERROR("Unknown block ID '%08x', aborting!\n", len);
updr150_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
} else {
/* Only keep these chunks */