#
# Run the clang.llvm.org static code analysis tool on the C sources.
+# (at least checker-231 is required for scan-build to work this way)
#
.PHONY: clang
clang:
$(RM) -r clang
- scan-build -V -k -o `pwd`/clang $(MAKE) $(MFLAGS) \
- CC=ccc-analyzer CXX=ccc-analyzer clean all
+ scan-build -V -k -o `pwd`/clang $(MAKE) $(MFLAGS) clean all
#
* Change to an unpriviledged user...
*/
- setgid(fileinfo.st_gid);
- setuid(fileinfo.st_uid);
+ if (setgid(fileinfo.st_gid))
+ return (errno);
+
+ if (setuid(fileinfo.st_uid))
+ return (errno);
}
execlp("pictwpstops", printer, argv[1], argv[2], argv[3], argv[4], argv[5],
error = errno;
close(fd);
- fd = -1;
if (addr->next)
continue;
if (isalnum(*uriptr & 255) || *uriptr == '_' || *uriptr == '-' ||
*uriptr == '.')
*tptr++ = *uriptr;
- else if ((*uriptr == ' ' || *uriptr == '/') && tptr[-1] != '_')
+ else if ((*uriptr == ' ' || *uriptr == '/') && tptr > template &&
+ tptr[-1] != '_')
*tptr++ = '_';
else if (*uriptr == '?' || *uriptr == '(')
break;
fi
dnl Check for random number functions...
-AC_CHECK_FUNCS(random mrand48 lrand48)
+AC_CHECK_FUNCS(random lrand48 arc4random)
dnl Check for geteuid function.
AC_CHECK_FUNCS(geteuid)
* Which random number generator function to use...
*/
+#undef HAVE_ARC4RANDOM
#undef HAVE_RANDOM
-#undef HAVE_MRAND48
#undef HAVE_LRAND48
+#ifdef HAVE_ARC4RANDOM
+# define CUPS_RAND() arc4random()
+# define CUPS_SRAND(v) arc4random_stir()
+#elif defined(HAVE_RANDOM)
+# define CUPS_RAND() random()
+# define CUPS_SRAND(v) srandom(v)
+#elif defined(HAVE_LRAND48)
+# define CUPS_RAND() lrand48()
+# define CUPS_SRAND(v) srand48(v)
+#else
+# define CUPS_RAND() rand()
+# define CUPS_SRAND(v) srand(v)
+#endif /* HAVE_ARC4RANDOM */
+
/*
* Do we have vproc_transaction_begin/end?
if (!cupsGetDest(name, instance, num_dests, *dests))
{
- if (instance &&
- (parent = cupsGetDest(name, NULL, num_dests, *dests)) == NULL)
+ if (instance && !cupsGetDest(name, NULL, num_dests, *dests))
return (num_dests);
dest = cups_add_dest(name, instance, &num_dests, dests);
if (section == PPD_ORDER_JCL)
{
if (!strcasecmp(choices[i]->choice, "Custom") &&
+ choices[i]->code &&
(coption = ppdFindCustomOption(ppd, choices[i]->option->keyword))
!= NULL)
{
attr = ppdFindAttr(ppd, "cupsMinSize", spec);
}
- if (!attr ||
- (attr->value && sscanf(attr->value, "%f%f", &width, &length) != 2))
+ if ((attr && attr->value &&
+ sscanf(attr->value, "%f%f", &width, &length) != 2) || !attr)
{
width = ppd->custom_min[0];
length = ppd->custom_min[1];
fputs("cupsFileSeek(), cupsFileRead(): ", stdout);
for (num_records = (pass + 1) * 256, count = (pass + 1) * 256,
- record = rand() % num_records;
+ record = CUPS_RAND() % num_records;
count > 0;
- count --, record = (record + (rand() & 31) - 16 + num_records) %
+ count --, record = (record + (CUPS_RAND() & 31) - 16 + num_records) %
num_records)
{
/*
* Initialize the write buffer with random data...
*/
-#ifdef WIN32
- srand((unsigned)time(NULL));
-#else
- srand(time(NULL));
-#endif /* WIN32 */
+ CUPS_SRAND(time(NULL));
for (i = 0; i < (int)sizeof(writebuf); i ++)
- writebuf[i] = rand();
+ writebuf[i] = CUPS_RAND();
/*
* cupsFileOpen(write)
*/
#include "driver.h"
-
-
-/*
- * Random number function to use, in order of preference...
- */
-
-#ifdef HAVE_RANDOM
-# define RANDOM_FUNCTION random
-#elif defined(HAVE_MRAND48)
-# define RANDOM_FUNCTION mrand48
-#elif defined(HAVE_LRAND48)
-# define RANDOM_FUNCTION lrand48
-#else
-# define RANDOM_FUNCTION rand
-#endif /* HAVE_RANDOM */
+#include <config.h>
/*
if (errrange > 1)
{
- errbase0 = errbase + (RANDOM_FUNCTION() % errrange);
- errbase1 = errbase + (RANDOM_FUNCTION() % errrange);
+ errbase0 = errbase + (CUPS_RAND() % errrange);
+ errbase1 = errbase + (CUPS_RAND() % errrange);
}
else
errbase0 = errbase1 = errbase;
if (errrange > 1)
{
- errbase0 = errbase + (RANDOM_FUNCTION() % errrange);
- errbase1 = errbase + (RANDOM_FUNCTION() % errrange);
+ errbase0 = errbase + (CUPS_RAND() % errrange);
+ errbase1 = errbase + (CUPS_RAND() % errrange);
}
else
errbase0 = errbase1 = errbase;
*
* BMP image routines for the Common UNIX Printing System (CUPS).
*
- * Copyright 2007-2008 by Apple Inc.
+ * Copyright 2007-2009 by Apple Inc.
* Copyright 1993-2007 by Easy Software Products.
*
* These coded instructions, statements, and computer programs are the
if (colors_used > 0)
fread(colormap, colors_used, 4, fp);
+ else
+ memset(colormap, 0, sizeof(colormap));
/*
* Setup image and buffers...
* Include necessary headers...
*/
+#include <config.h>
#include <cups/raster.h>
#include <stdlib.h>
#include <sys/time.h>
* text with some whitespace.
*/
- srand(time(NULL));
+ CUPS_SRAND(time(NULL));
memset(data, 0, sizeof(data));
for (y = 0; y < 28; y ++)
{
- for (x = rand() & 127, count = (rand() & 15) + 1;
+ for (x = CUPS_RAND() & 127, count = (CUPS_RAND() & 15) + 1;
x < sizeof(data[0]);
x ++, count --)
{
if (count <= 0)
{
- x += (rand() & 15) + 1;
- count = (rand() & 15) + 1;
+ x += (CUPS_RAND() & 15) + 1;
+ count = (CUPS_RAND() & 15) + 1;
if (x >= sizeof(data[0]))
break;
}
- data[y][x] = rand();
+ data[y][x] = CUPS_RAND();
}
}
strlcpy(cert->username, username, sizeof(cert->username));
for (i = 0; i < 32; i ++)
- cert->certificate[i] = hex[random() & 15];
+ cert->certificate[i] = hex[CUPS_RAND() & 15];
/*
* Save the certificate to a file readable only by the User and Group
cupsFileClose(fp);
}
- srandom(seed);
+ CUPS_SRAND(seed);
/*
* Create a root certificate and return...
priority);
}
- if ((attr = ippFindAttribute(con->request, "job-name",
- IPP_TAG_NAME)) != NULL)
- title = attr->values[0].string.text;
- else
+ if (!ippFindAttribute(con->request, "job-name", IPP_TAG_NAME))
ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_NAME, "job-name", NULL,
- title = "Untitled");
+ "Untitled");
if ((job = cupsdAddJob(priority, printer->name)) == NULL)
{
* Write a random number of newlines to the end of the file...
*/
- for (i = (rand() % 1024); i >= 0; i --)
+ for (i = (CUPS_RAND() % 1024); i >= 0; i --)
cupsFilePutChar(fp, '\n');
/*
* Reset group membership to just the main one we belong to.
*/
- setgid(Group);
- setgroups(1, &Group);
+ if (setgid(Group))
+ exit(errno);
+
+ if (setgroups(1, &Group))
+ exit(errno);
}
/*