misc: Fix up a small pile of bugs found via static analysis.

This commit is contained in:
Solomon Peachy 2019-05-06 21:10:43 -04:00
parent 16e11039c7
commit 701e6a45a2
12 changed files with 45 additions and 44 deletions

View File

@ -726,8 +726,10 @@ static int canonselphy_read_parse(void *vctx, const void **vjob, int data_fd, in
job contents. Ignore it if it comes through here.. */
i = read(data_fd, rdbuf, 4);
if (i != 4) {
if (i == 0)
if (i == 0) {
canonselphy_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
ERROR("Read failed (%d/%d)\n", i, 4);
perror("ERROR: Read failed");
canonselphy_cleanup_job(job);

View File

@ -49,7 +49,7 @@ int fast_return = 0;
int extra_vid = -1;
int extra_pid = -1;
int extra_type = -1;
int copies = 1;
int ncopies = 1;
int test_mode = 0;
int old_uri = 0;
int quiet = 0;
@ -1027,7 +1027,7 @@ int main (int argc, char **argv)
if (argv[base])
jobid = atoi(argv[base]);
if (argv[base + 3])
copies = atoi(argv[base + 3]);
ncopies = atoi(argv[base + 3]);
if (argc > 6)
fname = argv[base + 5];
else
@ -1265,7 +1265,7 @@ bypass:
signal(SIGTERM, sigterm_handler);
/* Time for the main processing loop */
INFO("Printing started (%d copies)\n", copies);
INFO("Printing started (%d copies)\n", ncopies);
/* See if it's a CUPS command stream, and if yes, handle it! */
if (type && !strcmp("application/vnd.cups-command", type))
@ -1277,7 +1277,7 @@ bypass:
newpage:
/* Read in data */
if ((ret = backend->read_parse(backend_ctx, &job, data_fd, copies))) {
if ((ret = backend->read_parse(backend_ctx, &job, data_fd, ncopies))) {
if (current_page)
goto done_multiple;
else
@ -1291,11 +1291,11 @@ newpage:
/* Create our own joblist if necessary */
if (!(backend->flags & BACKEND_FLAG_JOBLIST)) {
struct dyesub_joblist *list = dyesub_joblist_create(backend, backend_ctx);
struct dyesub_joblist *jlist = dyesub_joblist_create(backend, backend_ctx);
if (!list)
goto done_claimed;
dyesub_joblist_addjob(list, job);
job = list;
dyesub_joblist_addjob(jlist, job);
job = jlist;
}
/* Dump the full marker dump */
@ -1318,7 +1318,7 @@ newpage:
/* Log the completed page */
if (!uri)
PAGE("%d %d\n", current_page, copies);
PAGE("%d %d\n", current_page, ncopies);
/* Dump a marker status update */
ret = query_markers(backend, backend_ctx, !current_page);
@ -1335,7 +1335,7 @@ done_multiple:
/* Done printing, log the total number of pages */
if (!uri)
PAGE("total %d\n", current_page * copies);
PAGE("total %d\n", current_page * ncopies);
ret = CUPS_BACKEND_OK;
done_claimed:
@ -1525,7 +1525,7 @@ struct dyesub_joblist *dyesub_joblist_create(struct dyesub_backend *backend, voi
list->backend = backend;
list->ctx = ctx;
list->num_entries = 0;
list->copies = 1;
list->copies = ncopies;
return list;
}

View File

@ -244,7 +244,7 @@ extern int fast_return;
extern int extra_vid;
extern int extra_pid;
extern int extra_type;
extern int copies;
extern int ncopies;
extern int test_mode;
extern int quiet;
@ -273,7 +273,7 @@ extern struct dyesub_backend BACKEND;
#define GETOPT_LIST_GLOBAL "d:DfGhv"
#define GETOPT_PROCESS_GLOBAL \
case 'd': \
copies = atoi(optarg); \
ncopies = atoi(optarg); \
break; \
case 'D': \
dyesub_debug++; \

View File

@ -820,10 +820,6 @@ static int dnpds40_attach(void *vctx, struct libusb_device_handle *dev, int type
}
if (ctx->type == P_DNP_DS80D) {
struct dnpds40_cmd cmd;
uint8_t *resp;
int len = 0;
/* Query Duplex Media Info */
dnpds40_build_cmd(&cmd, "INFO", "CUT_PAPER", 0);
@ -1231,6 +1227,7 @@ static int dnpds40_read_parse(void *vctx, const void **vjob, int data_fd, int co
job->databuf = malloc(MAX_PRINTJOB_LEN);
if (!job->databuf) {
dnpds40_cleanup_job(job);
ERROR("Memory allocation failure!\n");
return CUPS_BACKEND_RETRY_CURRENT;
}
@ -2892,18 +2889,18 @@ static int dnpds40_cmdline_arg(void *vctx, int argc, char **argv)
j = dnpds40_get_sensors(ctx);
break;
case 'k': {
int time = atoi(optarg);
int sleeptime = atoi(optarg);
if (!ctx->supports_standby) {
ERROR("Printer does not support standby\n");
j = -1;
break;
}
if (time < 0 || time > 99) {
if (sleeptime < 0 || sleeptime > 99) {
ERROR("Value out of range (0-99)");
j = -1;
break;
}
j = dnpds620_standby_mode(ctx, time);
j = dnpds620_standby_mode(ctx, sleeptime);
break;
}
case 'K': {

View File

@ -854,6 +854,7 @@ static int magicard_read_parse(void *vctx, const void **vjob, int data_fd, int c
static int magicard_main_loop(void *vctx, const void *vjob) {
struct magicard_ctx *ctx = vctx;
int ret;
int copies;
const struct magicard_printjob *job = vjob;

View File

@ -656,7 +656,7 @@ hdr_done:
/* Byteswap data table to native endianness, if necessary */
#if (__BYTE_ORDER == __LITTLE_ENDIAN)
int i, j;
int j;
struct mitsu98xx_data *ptr = &ctx->m98xxdata->superfine;
for (j = 0 ; j < 3 ; j++) {
for (i = 3 ; i < 3 ; i++) {
@ -833,19 +833,19 @@ hdr_done:
}
if (!ctx->lut) {
uint8_t *buf = malloc(LUT_LEN);
if (!buf) {
uint8_t *lbuf = malloc(LUT_LEN);
if (!lbuf) {
ERROR("Memory allocation failure!\n");
mitsu9550_cleanup_job(job);
return CUPS_BACKEND_RETRY_CURRENT;
}
if (ctx->Get3DColorTable(buf, MITSU_M98xx_LUT_FILE)) {
if (ctx->Get3DColorTable(lbuf, MITSU_M98xx_LUT_FILE)) {
ERROR("Unable to open LUT file '%s'\n", MITSU_M98xx_LUT_FILE);
mitsu9550_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
ctx->lut = ctx->Load3DColorTable(buf);
free(buf);
ctx->lut = ctx->Load3DColorTable(lbuf);
free(lbuf);
if (!ctx->lut) {
ERROR("Unable to parse LUT\n");
mitsu9550_cleanup_job(job);
@ -1337,7 +1337,6 @@ top:
/* Send over plane data */
while(ptr < (job->databuf + job->datalen)) {
struct mitsu9550_plane *plane = (struct mitsu9550_plane *)ptr;
uint32_t planelen;
if (plane->cmd[0] != 0x1b ||
plane->cmd[1] != 0x5a ||
plane->cmd[2] != 0x54)
@ -1432,7 +1431,7 @@ top:
/* Don't forget the 9810's matte plane */
if (job->hdr1.matte) {
struct mitsu9550_plane *plane = (struct mitsu9550_plane *)ptr;
uint32_t planelen = be16_to_cpu(plane->rows) * be16_to_cpu(plane->cols);
planelen = be16_to_cpu(plane->rows) * be16_to_cpu(plane->cols);
if (plane->cmd[3] == 0x10)
planelen *= 2;

View File

@ -44,7 +44,7 @@ int sinfonia_read_parse(int data_fd, uint32_t model,
struct sinfonia_job_param *jp,
uint8_t **data, int *datalen)
{
uint32_t hdr[28];
uint32_t hdr[29];
int ret, i;
uint8_t tmpbuf[4];

View File

@ -1361,6 +1361,7 @@ static int shinkos1245_main_loop(void *vctx, const void *vjob) {
struct shinkos1245_ctx *ctx = vctx;
int i, num, last_state = -1, state = S_IDLE;
struct shinkos1245_resp_status status1, status2;
int copies;
const struct sinfonia_printjob *job = vjob;

View File

@ -1753,7 +1753,7 @@ int shinkos6145_cmdline_arg(void *vctx, int argc, char **argv)
j = get_fwinfo(ctx);
break;
case 'k': {
uint32_t i = atoi(optarg);
i = atoi(optarg);
if (i <= 5)
i = 0;
else if (i <= 15)
@ -2377,7 +2377,7 @@ static int shinkos6145_query_serno(struct libusb_device_handle *dev, uint8_t end
resp->hdr.payload_len = le16_to_cpu(resp->hdr.payload_len);
if (resp->hdr.payload_len > 23)
resp->hdr.payload_len = 23;
resp->data[resp->hdr.payload_len] = 0;
rdbuf[resp->hdr.payload_len] = 0;
strncpy(buf, (char*)resp->data, buf_len);
buf[buf_len-1] = 0; /* ensure it's null terminated */

View File

@ -1337,7 +1337,7 @@ int shinkos6245_cmdline_arg(void *vctx, int argc, char **argv)
j = get_fwinfo(ctx);
break;
case 'k': {
uint32_t i = atoi(optarg);
i = atoi(optarg);
if (i < 5)
i = 0;
else if (i < 15)
@ -1559,26 +1559,26 @@ static int shinkos6245_main_loop(void *vctx, const void *vjob) {
/* Send Set Time */
{
struct s6245_settime_cmd *stime = (struct s6245_settime_cmd *)cmdbuf;
struct s6245_settime_cmd *settime = (struct s6245_settime_cmd *)cmdbuf;
time_t now = time(NULL);
struct tm *cur = localtime(&now);
memset(cmdbuf, 0, CMDBUF_LEN);
cmd->cmd = cpu_to_le16(S6245_CMD_SETTIME);
cmd->len = cpu_to_le16(0);
stime->enable = 1;
stime->second = cur->tm_sec;
stime->minute = cur->tm_min;
stime->hour = cur->tm_hour;
stime->day = cur->tm_mday;
stime->month = cur->tm_mon;
stime->year = cur->tm_year + 1900 - 2000;
settime->enable = 1;
settime->second = cur->tm_sec;
settime->minute = cur->tm_min;
settime->hour = cur->tm_hour;
settime->day = cur->tm_mday;
settime->month = cur->tm_mon;
settime->year = cur->tm_year + 1900 - 2000;
if ((ret = s6245_do_cmd(ctx,
cmdbuf, sizeof(*stime),
cmdbuf, sizeof(*settime),
sizeof(struct s6245_status_hdr),
&num, (void*)&resp)) < 0) {
ERROR("Failed to execute %s command\n", cmd_names(stime->hdr.cmd));
ERROR("Failed to execute %s command\n", cmd_names(settime->hdr.cmd));
return CUPS_BACKEND_FAILED;
}
if (resp.result != RESULT_SUCCESS)
@ -1750,7 +1750,6 @@ static int shinkos6245_query_serno(struct libusb_device_handle *dev, uint8_t end
resp.hdr.payload_len = le16_to_cpu(resp.hdr.payload_len);
if (resp.hdr.payload_len > 23)
resp.hdr.payload_len = 23;
resp.data[resp.hdr.payload_len] = 0;
strncpy(buf, (char*)resp.data, buf_len);
buf[buf_len-1] = 0; /* ensure it's null terminated */

View File

@ -334,6 +334,7 @@ static int upd_read_parse(void *vctx, const void **vjob, int data_fd, int copies
if (job->datalen + len > MAX_PRINTJOB_LEN) {
ERROR("Buffer overflow when parsing printjob! (%d+%d)\n",
job->datalen, len);
upd_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}

View File

@ -174,14 +174,15 @@ static int updneo_read_parse(void *vctx, const void **vjob, int data_fd, int cop
*/
if (strncmp("JOBSIZE=", (char*) job->databuf + job->datalen, 8)) {
updneo_cleanup_job(job);
ERROR("Invalid spool format!\n");
return CUPS_BACKEND_CANCEL;
}
i = 0;
/* PDL */
char *tok = strtok((char*)job->databuf + job->datalen + 8, "\r\n,");
if (!tok) {
updneo_cleanup_job(job);
ERROR("Invalid spool format (PDL)!\n");
return CUPS_BACKEND_CANCEL;
}