]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Use arc4random, when available.
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Fri, 18 Dec 2009 23:50:23 +0000 (23:50 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Fri, 18 Dec 2009 23:50:23 +0000 (23:50 +0000)
Also fix a few problems that the latest clang found.

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@8937 7a7537e8-13f0-0310-91df-b6672ffda945

16 files changed:
Makefile
backend/ipp.c
backend/lpd.c
cgi-bin/admin.c
config-scripts/cups-common.m4
config.h.in
cups/dest.c
cups/emit.c
cups/page.c
cups/testfile.c
driver/dither.c
filter/image-bmp.c
filter/rasterbench.c
scheduler/cert.c
scheduler/ipp.c
scheduler/process.c

index fb97bf02d457cd1d7973f89e382995dccd692448..a888c7d06ffd2796a9a9b4a81c1f6a7882a71461 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -139,13 +139,13 @@ depend:
 
 #
 # 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
 
 
 #
index 40292921c2878e252e61b3caa3e74922c20abd33..1682742a6319e64869cda217bd0a0da31108d93c 100644 (file)
@@ -1794,8 +1794,11 @@ run_pictwps_filter(char       **argv,    /* I - Command-line arguments */
       * 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],
index 559ca0e4f943be17828067a7cd52abe8993d4c6f..d2bf78aabc6a0a1f70f541f32039c8d5656ea032 100644 (file)
@@ -796,7 +796,6 @@ lpd_queue(const char *hostname,             /* I - Host to connect to */
 
       error = errno;
       close(fd);
-      fd = -1;
 
       if (addr->next)
         continue;
index e9144fa59807d72d2bad1122486e696b2a07d47e..8578a47be584d4b933c334ded8a64c01473cedab 100644 (file)
@@ -948,7 +948,8 @@ do_am_printer(http_t *http,         /* I - HTTP connection */
          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;
index b1bcb512dc17ab799c48af8ab75ceeed948f2e9f..ee392ef740154da1fd15411b97362c510b927fe3 100644 (file)
@@ -142,7 +142,7 @@ else
 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)
index b081edefa33dea9f93d65b9c1471165eaf925dc5..d497acb0dbc4e1a1ff76259f99a491ccd68466c0 100644 (file)
  * 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?
index 6a349bee06ef310a317f6e5b9e893e9a1c20d4e7..939b00d7bc5d9c89960706c2f2152a13f4890ac7 100644 (file)
@@ -138,8 +138,7 @@ cupsAddDest(const char  *name,              /* I  - Destination name */
 
   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);
index 10cc42f0a1c3c3b265ffb5794eeaf48934427a13..6a873964d91012ae8a6b254950dcd1feefc6c948 100644 (file)
@@ -772,6 +772,7 @@ ppdEmitString(ppd_file_t    *ppd,   /* I - PPD file record */
     if (section == PPD_ORDER_JCL)
     {
       if (!strcasecmp(choices[i]->choice, "Custom") &&
+         choices[i]->code &&
           (coption = ppdFindCustomOption(ppd, choices[i]->option->keyword))
              != NULL)
       {
index ce434ccb91d662e32f55a8b698ae2bd649059b4b..8ef9df15bf4a27d7f624a27a2eafbe30c750a2d4 100644 (file)
@@ -277,8 +277,8 @@ ppdPageSizeLimits(ppd_file_t *ppd,  /* I - PPD file record */
       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];
index 3c54329ff45a01fa53ac319422f8a6b49bd6f949..2869f28b0eb2a9526c1bb5becf72727e09d0a8dc 100644 (file)
@@ -375,9 +375,9 @@ random_tests(void)
     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)
     {
      /*
@@ -471,14 +471,10 @@ read_write_tests(int compression) /* I - Use compression? */
   * 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)
index 2391734422091e063930e06667f38b743b8a8e0b..dfefed7c1d872fa8c0c69324657f42e8eeace1a8 100644 (file)
  */
 
 #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>
 
 
 /*
@@ -169,8 +155,8 @@ cupsDitherLine(cups_dither_t    *d, /* I - Dither data */
 
       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;
@@ -263,8 +249,8 @@ cupsDitherLine(cups_dither_t    *d, /* I - Dither data */
 
       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;
index 576580a06819c9badc1e357ccb8d0cbc52c6a16e..0c124b6ec533304adb897eb68d5c55ae8b2a6a5a 100644 (file)
@@ -3,7 +3,7 @@
  *
  *   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
@@ -170,6 +170,8 @@ _cupsImageReadBMP(
 
   if (colors_used > 0)
     fread(colormap, colors_used, 4, fp);
+  else
+    memset(colormap, 0, sizeof(colormap));
 
  /*
   * Setup image and buffers...
index 40ce08d6bf669c3b26033775b325c8e1b8f31166..5d30c8455946d2d38fd2bf6c832216c0c7571dda 100644 (file)
@@ -26,6 +26,7 @@
  * Include necessary headers...
  */
 
+#include <config.h>
 #include <cups/raster.h>
 #include <stdlib.h>
 #include <sys/time.h>
@@ -275,26 +276,26 @@ write_test(int         fd,                /* I - File descriptor to write to */
   * 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();
     }
   }
 
index 2f09620e89823e98227f167934c4dd06a0104631..2e089b859c80f9a6f3e00fcfb883999b01d81690 100644 (file)
@@ -71,7 +71,7 @@ cupsdAddCert(int        pid,          /* I - Process ID */
   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
@@ -425,7 +425,7 @@ cupsdInitCerts(void)
     cupsFileClose(fp);
   }
 
-  srandom(seed);
+  CUPS_SRAND(seed);
 
  /*
   * Create a root certificate and return...
index 515cdecc35e49711a5953d2ac22337a9f5b81116..cff4a1a9fdbb73f2853b1a04d7bafa769d7d6a10 100644 (file)
@@ -1547,12 +1547,9 @@ add_job(cupsd_client_t  *con,            /* I - Client connection */
                   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)
   {
@@ -9631,7 +9628,7 @@ save_auth_info(
   * 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');
 
  /*
index bf3060273407ca050fd279bfefa0bea2edc3620a..9e8d5b8ef7f498e8726ae49a11b41110edbcf8c7 100644 (file)
@@ -491,8 +491,11 @@ cupsdStartProcess(
       * 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);
     }
 
    /*