if (*ptr < ' ' && *ptr > 0 && *ptr != '\t')
{
/*
- * Substitute "<XX>" for the control character; sprintf is safe because
- * we always leave 6 chars free at the end...
+ * Substitute "<XX>" for the control character...
*/
- sprintf(valptr, "<%02X>", *ptr);
+ snprintf(valptr, sizeof(value) - (size_t)(valptr - value), "<%02X>", *ptr);
valptr += 4;
}
else
i < packet.object_value.string.num_bytes &&
dataptr < (data + sizeof(data) - 3);
i ++, dataptr += 2)
- sprintf(dataptr, "%02X", packet.object_value.string.bytes[i]);
+ snprintf(dataptr, sizeof(data) - (size_t)(dataptr - data), "%02X", packet.object_value.string.bytes[i]);
datalen += (int)strlen(dataptr);
break;
* for USB printer devices. We get the honor of trying them all...
*/
- sprintf(device, "/dev/usblp%d", i);
+ snprintf(device, sizeof(device), "/dev/usblp%d", i);
if ((fd = open(device, O_RDWR | O_EXCL)) < 0)
{
if (errno != ENOENT)
continue;
- sprintf(device, "/dev/usb/lp%d", i);
+ snprintf(device, sizeof(device), "/dev/usb/lp%d", i);
if ((fd = open(device, O_RDWR | O_EXCL)) < 0)
{
if (errno != ENOENT)
continue;
- sprintf(device, "/dev/usb/usblp%d", i);
+ snprintf(device, sizeof(device), "/dev/usb/usblp%d", i);
if ((fd = open(device, O_RDWR | O_EXCL)) < 0)
continue;
for (i = 0; i < 8; i ++)
{
- sprintf(device, "/dev/usb/printer%d", i);
+ snprintf(device, sizeof(device), "/dev/usb/printer%d", i);
if ((fd = open(device, O_WRONLY | O_EXCL)) >= 0)
{
for (i = 0; i < 8; i ++)
{
- sprintf(device, "/dev/ulpt%d", i);
+ snprintf(device, sizeof(device), "/dev/ulpt%d", i);
if (!access(device, 0))
printf("direct usb:%s \"Unknown\" \"USB Printer #%d\"\n", device, i + 1);
- sprintf(device, "/dev/unlpt%d", i);
+ snprintf(device, sizeof(device), "/dev/unlpt%d", i);
if (!access(device, 0))
printf("direct usb:%s \"Unknown\" \"USB Printer #%d (no reset)\"\n", device, i + 1);
}
* for USB printer devices. We get the honor of trying them all...
*/
- sprintf(device, "/dev/usblp%d", i);
+ snprintf(device, sizeof(device), "/dev/usblp%d", i);
if ((fd = open(device, O_RDWR | O_EXCL)) < 0 && errno == ENOENT)
{
- sprintf(device, "/dev/usb/lp%d", i);
+ snprintf(device, sizeof(device), "/dev/usb/lp%d", i);
if ((fd = open(device, O_RDWR | O_EXCL)) < 0 && errno == ENOENT)
{
- sprintf(device, "/dev/usb/usblp%d", i);
+ snprintf(device, sizeof(device), "/dev/usb/usblp%d", i);
if ((fd = open(device, O_RDWR | O_EXCL)) < 0 && errno == ENOENT)
continue;
{
for (i = 0, busy = 0; i < 8; i ++)
{
- sprintf(device, "/dev/usb/printer%d", i);
+ snprintf(device, sizeof(device), "/dev/usb/printer%d", i);
if ((fd = open(device, O_WRONLY | O_EXCL)) >= 0)
backendGetDeviceID(fd, device_id, sizeof(device_id),
return (1);
}
- sprintf(buffer, "%d", num_copies);
- num_options = cupsAddOption("copies", buffer, num_options, &options);
+ num_options = cupsAddIntegerOption("copies", num_copies, num_options, &options);
break;
case 'C' : /* Class */
* bytes left in the array...
*/
- sprintf(ptr, "%%%02X", *url & 255);
+ snprintf(ptr, sizeof(encoded) - (size_t)(ptr - encoded), "%%%02X", *url & 255);
ptr += 3;
}
else
break;
else
{
- sprintf(baudrate, "%d", baudrates[i]);
+ snprintf(baudrate, sizeof(baudrate), "%d", baudrates[i]);
cgiSetArray("BAUDRATES", i, baudrate);
}
if (first < 0)
first = 0;
- sprintf(val, "%d", count);
+ snprintf(val, sizeof(val), "%d", count);
cgiSetVariable("TOTAL", val);
for (i = 0, pclass = (ipp_attribute_t *)cupsArrayIndex(classes, first);
if (first > 0)
{
- sprintf(val, "%d", first - CUPS_PAGE_MAX);
+ snprintf(val, sizeof(val), "%d", first - CUPS_PAGE_MAX);
cgiSetVariable("PREV", val);
}
if ((first + CUPS_PAGE_MAX) < count)
{
- sprintf(val, "%d", first + CUPS_PAGE_MAX);
+ snprintf(val, sizeof(val), "%d", first + CUPS_PAGE_MAX);
cgiSetVariable("NEXT", val);
}
char buf[255]; /* Number buffer */
- sprintf(buf, "%d", attr->values[i].integer);
+ snprintf(buf, sizeof(buf), "%d", attr->values[i].integer);
if (cgiDoSearch(search, buf))
add = 1;
char temp[255]; /* Temporary string */
- sprintf(temp, "%d", job_id);
+ snprintf(temp, sizeof(temp), "%d", job_id);
cgiSetVariable("JOB_ID", temp);
}
cgiSetVariable("SECTION", section);
- sprintf(val, "%d", count);
+ snprintf(val, sizeof(val), "%d", count);
cgiSetVariable("TOTAL", val);
if (which_jobs)
if (first > 0)
{
- sprintf(val, "%d", first - CUPS_PAGE_MAX);
+ snprintf(val, sizeof(val), "%d", first - CUPS_PAGE_MAX);
cgiSetVariable("PREV", val);
}
if ((first + CUPS_PAGE_MAX) < count)
{
- sprintf(val, "%d", first + CUPS_PAGE_MAX);
+ snprintf(val, sizeof(val), "%d", first + CUPS_PAGE_MAX);
cgiSetVariable("NEXT", val);
}
if (first < 0)
first = 0;
- sprintf(val, "%d", count);
+ snprintf(val, sizeof(val), "%d", count);
cgiSetVariable("TOTAL", val);
for (i = 0, printer = (ipp_attribute_t *)cupsArrayIndex(printers, first);
if (first > 0)
{
- sprintf(val, "%d", first - CUPS_PAGE_MAX);
+ snprintf(val, sizeof(val), "%d", first - CUPS_PAGE_MAX);
cgiSetVariable("PREV", val);
}
if ((first + CUPS_PAGE_MAX) < count)
{
- sprintf(val, "%d", first + CUPS_PAGE_MAX);
+ snprintf(val, sizeof(val), "%d", first + CUPS_PAGE_MAX);
cgiSetVariable("NEXT", val);
}
*/
if (name[1])
- sprintf(outval, "%d", cgiGetSize(name + 1));
+ snprintf(outval, sizeof(outval), "%d", cgiGetSize(name + 1));
else
- sprintf(outval, "%d", element + 1);
+ snprintf(outval, sizeof(outval), "%d", element + 1);
outptr = outval;
}
continue;
else if (ch == '#')
{
- sprintf(s, "%d", element + 1);
+ snprintf(s, sizeof(compare) - (size_t)(s - compare), "%d", element + 1);
s += strlen(s);
}
else if (ch == '{')
*innerptr = '\0';
if (innername[0] == '#')
- sprintf(s, "%d", cgiGetSize(innername + 1));
+ snprintf(s, sizeof(compare) - (size_t)(s - compare), "%d", cgiGetSize(innername + 1));
else if ((innerptr = strrchr(innername, '-')) != NULL &&
isdigit(innerptr[1] & 255))
{
* No, build an "0xxxxx" error string...
*/
- sprintf(cg->ipp_unknown, "0x%04x", error);
+ snprintf(cg->ipp_unknown, sizeof(cg->ipp_unknown), "0x%04x", error);
return (cg->ipp_unknown);
}
* No, build an "0xxxxx" operation string...
*/
- sprintf(cg->ipp_unknown, "0x%04x", op);
+ snprintf(cg->ipp_unknown, sizeof(cg->ipp_unknown), "0x%04x", op);
return (cg->ipp_unknown);
}
* Look it up in the PPD file...
*/
- sprintf(s, "%d", j);
+ snprintf(s, sizeof(s), "%d", j);
if ((attr = ppdFindAttr(ppd, "cupsIPPFinishings", s)) == NULL)
continue;
if ((width + 2) > sizeof(temp))
break;
- sprintf(temp, tformat, va_arg(ap, double));
+ snprintf(temp, sizeof(temp), tformat, va_arg(ap, double));
templen = strlen(temp);
bytes += (int)templen;
if ((width + 2) > sizeof(temp))
break;
- sprintf(temp, tformat, va_arg(ap, int));
+ snprintf(temp, sizeof(temp), tformat, va_arg(ap, int));
templen = strlen(temp);
bytes += (int)templen;
if ((width + 2) > sizeof(temp))
break;
- sprintf(temp, tformat, va_arg(ap, void *));
+ snprintf(temp, sizeof(temp), tformat, va_arg(ap, void *));
templen = strlen(temp);
bytes += (int)templen;
if (bufsize < 4)
break;
- sprintf(bufptr, "\\%03o", *s);
+ snprintf(bufptr, bufsize, "\\%03o", *s);
bufptr += 4;
bufsize -= 4;
}
}
else
{
- sprintf(content_length, "CONTENT_LENGTH=" CUPS_LLFMT,
- CUPS_LLCAST con->bytes);
+ snprintf(content_length, sizeof(content_length), "CONTENT_LENGTH=" CUPS_LLFMT, CUPS_LLCAST con->bytes);
snprintf(content_type, sizeof(content_type), "CONTENT_TYPE=%s",
httpGetField(con->http, HTTP_FIELD_CONTENT_TYPE));
* Use the default port...
*/
- sprintf(defpname, "%d", defport);
+ snprintf(defpname, sizeof(defpname), "%d", defport);
portname = defpname;
hostname = buffer;
}
request = ippNewRequest(IPP_OP_CANCEL_JOB);
- sprintf(uri, "ipp://localhost/jobs/%d", id);
+ snprintf(uri, sizeof(uri), "ipp://localhost/jobs/%d", id);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
case IPP_TAG_INTEGER :
case IPP_TAG_ENUM :
- sprintf(value, "%d", attr->values[0].integer);
- printer->num_options = cupsAddOption(name, value,
- printer->num_options,
- &(printer->options));
+ printer->num_options = cupsAddIntegerOption(name, attr->values[0].integer, printer->num_options, &(printer->options));
cupsdLogMessage(CUPSD_LOG_DEBUG,
"Setting %s to %s...", attr->name, value);
break;
case IPP_TAG_RANGE :
- sprintf(value, "%d-%d", attr->values[0].range.lower,
- attr->values[0].range.upper);
+ snprintf(value, sizeof(value), "%d-%d", attr->values[0].range.lower, attr->values[0].range.upper);
printer->num_options = cupsAddOption(name, value,
printer->num_options,
&(printer->options));
break;
case IPP_TAG_RESOLUTION :
- sprintf(value, "%dx%d%s", attr->values[0].resolution.xres,
- attr->values[0].resolution.yres,
- attr->values[0].resolution.units == IPP_RES_PER_INCH ?
- "dpi" : "dpcm");
+ snprintf(value, sizeof(value), "%dx%d%s", attr->values[0].resolution.xres, attr->values[0].resolution.yres, attr->values[0].resolution.units == IPP_RES_PER_INCH ? "dpi" : "dpcm");
printer->num_options = cupsAddOption(name, value,
printer->num_options,
&(printer->options));
goto abort_job;
}
- sprintf(jobid, "%d", job->id);
+ snprintf(jobid, sizeof(jobid), "%d", job->id);
argv[0] = job->printer->name;
argv[1] = jobid;
}
else
{
- sprintf(uri, "ipp://localhost/jobs/%d", job_id);
+ snprintf(uri, sizeof(uri), "ipp://localhost/jobs/%d", job_id);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL,
uri);
}
return (1);
}
- sprintf(buffer, "%d", num_copies);
- num_options = cupsAddOption("copies", buffer, num_options,
- &options);
+ num_options = cupsAddIntegerOption("copies", num_copies, num_options, &options);
break;
case 'o' : /* Option */
return (1);
}
- sprintf(buffer, "%d", priority);
- num_options = cupsAddOption("job-priority", buffer, num_options,
- &options);
+ num_options = cupsAddIntegerOption("job-priority", priority, num_options, &options);
break;
case 's' : /* Silent */
request = ippNewRequest(IPP_RESTART_JOB);
- sprintf(uri, "ipp://localhost/jobs/%d", job_id);
+ snprintf(uri, sizeof(uri), "ipp://localhost/jobs/%d", job_id);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
"job-uri", NULL, uri);
request = ippNewRequest(IPP_SET_JOB_ATTRIBUTES);
- sprintf(uri, "ipp://localhost/jobs/%d", job_id);
+ snprintf(uri, sizeof(uri), "ipp://localhost/jobs/%d", job_id);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
"job-uri", NULL, uri);
if ((size_t)(width + 2) > sizeof(temp))
break;
- sprintf(temp, tformat, va_arg(ap, double));
+ snprintf(temp, sizeof(temp), tformat, va_arg(ap, double));
httpWrite2(client->http, temp, strlen(temp));
break;
# ifdef HAVE_LONG_LONG
if (size == 'L')
- sprintf(temp, tformat, va_arg(ap, long long));
+ snprintf(temp, sizeof(temp), tformat, va_arg(ap, long long));
else
# endif /* HAVE_LONG_LONG */
if (size == 'l')
- sprintf(temp, tformat, va_arg(ap, long));
+ snprintf(temp, sizeof(temp), tformat, va_arg(ap, long));
else
- sprintf(temp, tformat, va_arg(ap, int));
+ snprintf(temp, sizeof(temp), tformat, va_arg(ap, int));
httpWrite2(client->http, temp, strlen(temp));
break;
if ((size_t)(width + 2) > sizeof(temp))
break;
- sprintf(temp, tformat, va_arg(ap, void *));
+ snprintf(temp, sizeof(temp), tformat, va_arg(ap, void *));
httpWrite2(client->http, temp, strlen(temp));
break;