]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Stop using strcpy.
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Fri, 7 Sep 2012 02:49:46 +0000 (02:49 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Fri, 7 Sep 2012 02:49:46 +0000 (02:49 +0000)
git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@10596 7a7537e8-13f0-0310-91df-b6672ffda945

44 files changed:
backend/dnssd.c
backend/usb-darwin.c
berkeley/lpq.c
cgi-bin/admin.c
cgi-bin/help-index.c
cgi-bin/ipp-var.c
cgi-bin/jobs.c
cgi-bin/search.c
cups/auth.c
cups/conflicts.c
cups/debug.c
cups/dest.c
cups/globals.c
cups/http.c
cups/langprintf.c
cups/language.c
cups/ppd.c
cups/snprintf.c
cups/string.c
cups/testarray.c
cups/testhttp.c
cups/testi18n.c
cups/testppd.c
cups/usersys.c
cups/util.c
filter/interpret.c
locale/checkpo.c
locale/po2strings.c
notifier/dbus.c
ppdc/ppdc-source.cxx
ppdc/ppdc-string.cxx
scheduler/auth.c
scheduler/client.c
scheduler/conf.c
scheduler/cups-driverd.cxx
scheduler/cups-lpd.c
scheduler/cupsfilter.c
scheduler/ipp.c
scheduler/job.c
scheduler/log.c
scheduler/mime.c
scheduler/type.c
systemv/cupstestppd.c
systemv/lpstat.c

index 7cff1cb4f96d15b570b4828276f69b4280b0a48f..46c0f134711bf311f5e6a568fcc27e544a91e6d0 100644 (file)
@@ -1080,7 +1080,7 @@ query_callback(
   device_id[0]      = '\0';
   make_and_model[0] = '\0';
 
-  strcpy(model, "Unknown");
+  strlcpy(model, "Unknown", sizeof(model));
 
   for (data = rdata, dataend = data + rdlen;
        data < dataend;
@@ -1134,9 +1134,9 @@ query_callback(
 
     if (!_cups_strcasecmp(key, "usb_MFG") || !_cups_strcasecmp(key, "usb_MANU") ||
        !_cups_strcasecmp(key, "usb_MANUFACTURER"))
-      strcpy(make_and_model, value);
+      strlcpy(make_and_model, value, sizeof(make_and_model));
     else if (!_cups_strcasecmp(key, "usb_MDL") || !_cups_strcasecmp(key, "usb_MODEL"))
-      strcpy(model, value);
+      strlcpy(model, value, sizeof(model));
     else if (!_cups_strcasecmp(key, "product") && !strstr(value, "Ghostscript"))
     {
       if (value[0] == '(')
@@ -1148,14 +1148,14 @@ query_callback(
        if ((ptr = value + strlen(value) - 1) > value && *ptr == ')')
          *ptr = '\0';
 
-       strcpy(model, value + 1);
+       strlcpy(model, value + 1, sizeof(model));
       }
       else
-       strcpy(model, value);
+       strlcpy(model, value, sizeof(model));
     }
     else if (!_cups_strcasecmp(key, "ty"))
     {
-      strcpy(model, value);
+      strlcpy(model, value, sizeof(model));
 
       if ((ptr = strchr(model, ',')) != NULL)
        *ptr = '\0';
index 6f7cfceabd7a77a05286c55189ee9bd011cc31e4..49d773d53296851658abfff901b4298dcc49dfaf 100644 (file)
@@ -1180,12 +1180,12 @@ static Boolean list_device_cb(void *refcon,
       if (!make ||
           !CFStringGetCString(make, makestr, sizeof(makestr),
                              kCFStringEncodingUTF8))
-        strcpy(makestr, "Unknown");
+        strlcpy(makestr, "Unknown", sizeof(makestr));
 
       if (!model ||
           !CFStringGetCString(model, &modelstr[1], sizeof(modelstr)-1,
                              kCFStringEncodingUTF8))
-        strcpy(modelstr + 1, "Printer");
+        strlcpy(modelstr + 1, "Printer", sizeof(modelstr) - 1);
 
       optionsstr[0] = '\0';
       if (serial != NULL)
@@ -2164,7 +2164,7 @@ static void parse_pserror(char *sockBuffer,
     }
 
     /* move everything over... */
-    strcpy(gErrorBuffer, pLineEnd);
+    strlcpy(gErrorBuffer, pLineEnd, sizeof(gErrorBuffer));
     gErrorBufferPtr = gErrorBuffer;
     pLineEnd = (char *)next_line((const char *)gErrorBuffer);
   }
index 60184eb9573c06bff3f114ba5df19f4d28e1ca85..dcce2c0ed952edd8c78be16ea9c58432b8e07983 100644 (file)
@@ -527,7 +527,7 @@ show_jobs(const char *command,              /* I - Command name */
       */
 
       if (jobstate == IPP_JOB_PROCESSING)
-       strcpy(rankstr, "active");
+       strlcpy(rankstr, "active", sizeof(rankstr));
       else
       {
        /*
index 73eca2b2442f28899fa94f66057ad2f75a0dd5a2..cecbba41831d5700b385d658291ccbba8b7bc120 100644 (file)
@@ -962,13 +962,13 @@ do_am_printer(http_t *http,               /* I - HTTP connection */
       else if (!_cups_strncasecmp(make, "laserjet", 8) ||
                !_cups_strncasecmp(make, "deskjet", 7) ||
                !_cups_strncasecmp(make, "designjet", 9))
-        strcpy(make, "HP");
+        strlcpy(make, "HP", sizeof(make));
       else if (!_cups_strncasecmp(make, "phaser", 6))
-        strcpy(make, "Xerox");
+        strlcpy(make, "Xerox", sizeof(make));
       else if (!_cups_strncasecmp(make, "stylus", 6))
-        strcpy(make, "Epson");
+        strlcpy(make, "Epson", sizeof(make));
       else
-        strcpy(make, "Generic");
+        strlcpy(make, "Generic", sizeof(make));
 
       if (!cgiGetVariable("CURRENT_MAKE"))
         cgiSetVariable("CURRENT_MAKE", make);
@@ -4187,7 +4187,7 @@ get_option_value(
     if (bufptr == buffer || (bufend - bufptr) < 2)
       return (NULL);
 
-    strcpy(bufptr, "}");
+    memcpy(bufptr, "}", 2);
   }
 
   return (buffer);
index 53d482021ce1238cbc10dbe191096c3f11bc19db..801f088fda8df867cb5b77bbc62a9272c42062b2 100644 (file)
@@ -3,7 +3,7 @@
  *
  *   Online help index routines for CUPS.
  *
- *   Copyright 2007-2011 by Apple Inc.
+ *   Copyright 2007-2012 by Apple Inc.
  *   Copyright 1997-2007 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
@@ -910,7 +910,7 @@ help_load_file(
   node   = NULL;
   offset = 0;
 
-  strcpy(section, "Other");
+  strlcpy(section, "Other", sizeof(section));
 
   while (cupsFileGets(fp, line, sizeof(line)))
   {
index 6f72c1c8024abf2a5db9e63cf2855c0bcc335ce1..a401bf49fe1154a3900cc0cd57ec3d4a894ab072 100644 (file)
@@ -129,7 +129,7 @@ cgiGetAttributes(ipp_t      *request,       /* I - IPP request */
       *nameptr = '\0';
 
       if (!strncmp(name, "printer_state_history", 21))
-        strcpy(name, "printer_state_history");
+        strlcpy(name, "printer_state_history", sizeof(name));
 
      /*
       * Possibly add it to the list of attributes...
index 283e2c314efa53a76ab0ed7a2d40e901df4aec0b..e57b0218d0b5a9008ca329baa4c84683b0e3c97e 100644 (file)
@@ -182,7 +182,7 @@ do_job_op(http_t      *http,                /* I - HTTP connection */
     char       url[1024];              /* Encoded URL */
 
 
-    strcpy(url, "5;URL=");
+    strlcpy(url, "5;URL=", sizeof(url));
     cgiFormEncode(url + 6, getenv("HTTP_REFERER"), sizeof(url) - 6);
     cgiSetVariable("refresh_page", url);
   }
index e2a1c5c5d069639e689ffa86fb6b76d4fbdeef2c..a6abd597809ecd7ab46909f7dbb92319e080679d 100644 (file)
@@ -3,7 +3,7 @@
  *
  *   Search routines for CUPS.
  *
- *   Copyright 2007-2011 by Apple Inc.
+ *   Copyright 2007-2012 by Apple Inc.
  *   Copyright 1997-2006 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
@@ -208,7 +208,7 @@ cgiCompileSearch(const char *query) /* I - Query string */
       * Add the prefix string...
       */
 
-      strcpy(sptr, prefix);
+      memcpy(sptr, prefix, strlen(prefix) + 1);
       sptr += strlen(sptr);
 
      /*
@@ -249,16 +249,16 @@ cgiCompileSearch(const char *query)       /* I - Query string */
          return (NULL);
        }
 
-        strcpy(sptr, ".*|.*");
+        memcpy(sptr, ".*|.*", 6);
        sptr += 5;
 
-       strcpy(sptr, lword2);
+       memcpy(sptr, lword2, strlen(lword2) + 1);
        sptr += strlen(sptr);
 
-        strcpy(sptr, ".*");
+        memcpy(sptr, ".*", 3);
        sptr += 2;
 
-       strcpy(sptr, lword);
+       memcpy(sptr, lword, strlen(lword) + 1);
        sptr += strlen(sptr);
 
         free(lword);
@@ -287,7 +287,7 @@ cgiCompileSearch(const char *query) /* I - Query string */
     free(lword);
 
   if (sptr > s)
-    strcpy(sptr, ".*");
+    memcpy(sptr, ".*", 3);
   else
   {
    /*
index 60edff87077ac3621d51782d3073f6f595f93a6e..0bfbb46b6929cae52d158f6bb0bc354fd03007a6 100644 (file)
@@ -465,7 +465,7 @@ _cupsSetNegotiateAuthString(
       authsize         = sizeof(http->_authstring);
     }
 
-    strcpy(http->authstring, "Negotiate ");
+    strlcpy(http->authstring, "Negotiate ", authsize);
     httpEncode64_2(http->authstring + 10, authsize - 10, output_token.value,
                   output_token.length);
 
index 456f690530613ad42209ec4d2f17d306f5d60d3c..ae048d135e8ed44b296793eb7a2c7045cf0b9fdf 100644 (file)
@@ -930,7 +930,7 @@ ppd_load_constraints(ppd_file_t *ppd)       /* I - PPD file */
       if (!_cups_strncasecmp(option, "Custom", 6) && !_cups_strcasecmp(choice, "True"))
       {
        _cups_strcpy(option, option + 6);
-       strcpy(choice, "Custom");
+       strlcpy(choice, "Custom", sizeof(choice));
       }
 
       constptr->option      = ppdFindOption(ppd, option);
index e8298ad0618ac88783c76378f6f09d4af8038e61..71b693c70a7b623f75b8d4a5314fbe263453b61d 100644 (file)
@@ -229,16 +229,8 @@ debug_vsnprintf(char       *buffer,        /* O - Output buffer */
 
             if (bufptr)
            {
-             if ((bufptr + strlen(temp)) > bufend)
-             {
-               strncpy(bufptr, temp, (size_t)(bufend - bufptr));
-               bufptr = bufend;
-             }
-             else
-             {
-               strcpy(bufptr, temp);
-               bufptr += strlen(temp);
-             }
+             strlcpy(bufptr, temp, (size_t)(bufend - bufptr));
+             bufptr += strlen(bufptr);
            }
            break;
 
@@ -267,16 +259,8 @@ debug_vsnprintf(char       *buffer,        /* O - Output buffer */
 
            if (bufptr)
            {
-             if ((bufptr + strlen(temp)) > bufend)
-             {
-               strncpy(bufptr, temp, (size_t)(bufend - bufptr));
-               bufptr = bufend;
-             }
-             else
-             {
-               strcpy(bufptr, temp);
-               bufptr += strlen(temp);
-             }
+             strlcpy(bufptr, temp, (size_t)(bufend - bufptr));
+             bufptr += strlen(bufptr);
            }
            break;
 
@@ -290,16 +274,8 @@ debug_vsnprintf(char       *buffer,        /* O - Output buffer */
 
            if (bufptr)
            {
-             if ((bufptr + strlen(temp)) > bufend)
-             {
-               strncpy(bufptr, temp, (size_t)(bufend - bufptr));
-               bufptr = bufend;
-             }
-             else
-             {
-               strcpy(bufptr, temp);
-               bufptr += strlen(temp);
-             }
+             strlcpy(bufptr, temp, (size_t)(bufend - bufptr));
+             bufptr += strlen(bufptr);
            }
            break;
 
index 8e3e974c099357b66740326b91508863ee45a1b2..5e4d9b87abca6fce912b23555f869e346dadf564 100644 (file)
@@ -3153,7 +3153,7 @@ cups_dnssd_query_cb(
     device->state     = _CUPS_DNSSD_PENDING;
     make_and_model[0] = '\0';
 
-    strcpy(model, "Unknown");
+    strlcpy(model, "Unknown", sizeof(model));
 
     for (txt = rdata, txtend = txt + rdlen;
         txt < txtend;
@@ -3195,10 +3195,10 @@ cups_dnssd_query_cb(
       if (!_cups_strcasecmp(key, "usb_MFG") ||
           !_cups_strcasecmp(key, "usb_MANU") ||
          !_cups_strcasecmp(key, "usb_MANUFACTURER"))
-       strcpy(make_and_model, value);
+       strlcpy(make_and_model, value, sizeof(make_and_model));
       else if (!_cups_strcasecmp(key, "usb_MDL") ||
                !_cups_strcasecmp(key, "usb_MODEL"))
-       strcpy(model, value);
+       strlcpy(model, value, sizeof(model));
       else if (!_cups_strcasecmp(key, "product") && !strstr(value, "Ghostscript"))
       {
        if (value[0] == '(')
@@ -3210,14 +3210,14 @@ cups_dnssd_query_cb(
          if ((ptr = value + strlen(value) - 1) > value && *ptr == ')')
            *ptr = '\0';
 
-         strcpy(model, value + 1);
+         strlcpy(model, value + 1, sizeof(model));
        }
        else
-         strcpy(model, value);
+         strlcpy(model, value, sizeof(model));
       }
       else if (!_cups_strcasecmp(key, "ty"))
       {
-       strcpy(model, value);
+       strlcpy(model, value, sizeof(model));
 
        if ((ptr = strchr(model, ',')) != NULL)
          *ptr = '\0';
index 692d0bcd8f63e962b0b6e3c250cc257bd396bae8..f382f393a6845683179947c4fe8e886340b4f033 100644 (file)
@@ -227,7 +227,7 @@ cups_globals_alloc(void)
     * Open the registry...
     */
 
-    strcpy(installdir, "C:/Program Files/cups.org");
+    strlcpy(installdir, "C:/Program Files/cups.org", sizeof(installdir));
 
     if (!RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\cups.org", 0, KEY_READ,
                       &key))
index 35cbe3acfb605e8d7a0564e6687ad7e5bfe2ad3e..b16b66836083e97f9b4b76e1d05054d8bc4876bb 100644 (file)
@@ -2646,7 +2646,8 @@ httpSetLength(http_t *http,               /* I - Connection to server */
 
   if (!length)
   {
-    strcpy(http->fields[HTTP_FIELD_TRANSFER_ENCODING], "chunked");
+    strlcpy(http->fields[HTTP_FIELD_TRANSFER_ENCODING], "chunked",
+            HTTP_MAX_VALUE);
     http->fields[HTTP_FIELD_CONTENT_LENGTH][0] = '\0';
   }
   else
@@ -3472,12 +3473,12 @@ http_debug_hex(const char *prefix,      /* I - Prefix for line */
 
     while (j < 16)
     {
-      strcpy(ptr, "  ");
+      memcpy(ptr, "  ", 3);
       ptr += 2;
       j ++;
     }
 
-    strcpy(ptr, "  ");
+    memcpy(ptr, "  ", 3);
     ptr += 2;
 
     for (j = 0; j < 16 && (i + j) < bytes; j ++)
index 9a308dbf2df9ee1f9fa31852665feeb931526f99..f63a473f70e2f32c7b8f64b954279b352b681e8c 100644 (file)
@@ -3,7 +3,7 @@
  *
  *   Localized printf/puts functions for CUPS.
  *
- *   Copyright 2007-2011 by Apple Inc.
+ *   Copyright 2007-2012 by Apple Inc.
  *   Copyright 2002-2007 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
@@ -304,7 +304,7 @@ _cupsSetLocale(char *argv[])                /* IO - Command-line arguments */
     strlcpy(charset, ".UTF-8", sizeof(new_lc_time) - (charset - new_lc_time));
   }
   else
-    strcpy(new_lc_time, "C");
+    strlcpy(new_lc_time, "C", sizeof(new_lc_time));
 
   setlocale(LC_TIME, new_lc_time);
 #endif /* LC_TIME */
index b38d75a7f2ad739cf51bc34aaa3dd55fbd110819..319e4ca7343452cea82f4742b7ed2a988e83a935 100644 (file)
@@ -446,7 +446,7 @@ cupsLangGet(const char *language)   /* I - Language or locale */
   * Set the character set to UTF-8...
   */
 
-  strcpy(charset, "UTF8");
+  strlcpy(charset, "UTF8", sizeof(charset));
 
  /*
   * Apple's setlocale doesn't give us the user's localization
@@ -582,7 +582,7 @@ cupsLangGet(const char *language)   /* I - Language or locale */
   */
 
   if (!charset[0])
-    strcpy(charset, "UTF8");
+    strlcpy(charset, "UTF8", sizeof(charset));
 
  /*
   * Parse the language string passed in to a locale string. "C" is the
@@ -597,7 +597,7 @@ cupsLangGet(const char *language)   /* I - Language or locale */
 
   if (language == NULL || !language[0] ||
       !strcmp(language, "POSIX"))
-    strcpy(langname, "C");
+    strlcpy(langname, "C", sizeof(langname));
   else
   {
    /*
@@ -646,7 +646,7 @@ cupsLangGet(const char *language)   /* I - Language or locale */
 
     if (strlen(langname) != 2)
     {
-      strcpy(langname, "C");
+      strlcpy(langname, "C", sizeof(langname));
       country[0] = '\0';
       charset[0] = '\0';
     }
@@ -701,7 +701,7 @@ cupsLangGet(const char *language)   /* I - Language or locale */
   if (country[0])
     snprintf(real, sizeof(real), "%s_%s", langname, country);
   else
-    strcpy(real, langname);
+    strlcpy(real, langname, sizeof(real));
 
   _cupsMutexLock(&lang_mutex);
 
@@ -847,6 +847,7 @@ _cupsMessageLoad(const char *filename,      /* I - Message catalog to load */
                        *ptr,           /* Pointer into buffer */
                        *temp;          /* New string */
   int                  length;         /* Length of combined strings */
+  size_t               ptrlen;         /* Length of string */
 
 
   DEBUG_printf(("4_cupsMessageLoad(filename=\"%s\")", filename));
@@ -978,9 +979,10 @@ _cupsMessageLoad(const char *filename,     /* I - Message catalog to load */
       */
 
       length = (int)strlen(m->str ? m->str : m->id);
+      ptrlen = strlen(ptr);
 
       if ((temp = realloc(m->str ? m->str : m->id,
-                          length + strlen(ptr) + 1)) == NULL)
+                          length + ptrlen + 1)) == NULL)
       {
         if (m->str)
          free(m->str);
@@ -995,25 +997,25 @@ _cupsMessageLoad(const char *filename,    /* I - Message catalog to load */
       {
        /*
         * Copy the new portion to the end of the msgstr string - safe
-       * to use strcpy because the buffer is allocated to the correct
+       * to use memcpy because the buffer is allocated to the correct
        * size...
        */
 
         m->str = temp;
 
-       strcpy(m->str + length, ptr);
+       memcpy(m->str + length, ptr, ptrlen + 1);
       }
       else
       {
        /*
         * Copy the new portion to the end of the msgid string - safe
-       * to use strcpy because the buffer is allocated to the correct
+       * to use memcpy because the buffer is allocated to the correct
        * size...
        */
 
         m->id = temp;
 
-       strcpy(m->id + length, ptr);
+       memcpy(m->id + length, ptr, ptrlen + 1);
       }
     }
     else if (!strncmp(s, "msgstr", 6) && m)
index 81bfd0b8f46d69906917686a6a0e540b545df1da..6813ea0e640628ff68a53b6492601bdc724c30fd 100644 (file)
@@ -1264,7 +1264,7 @@ _ppdOpen(
 
         ppd->patches = temp;
 
-        strcpy(ppd->patches + strlen(ppd->patches), string);
+        memcpy(ppd->patches + strlen(ppd->patches), string, strlen(string) + 1);
       }
     }
     else if (!strcmp(keyword, "OpenUI"))
@@ -1378,7 +1378,7 @@ _ppdOpen(
       */
 
       if (!_cups_strcasecmp(name, "PageRegion"))
-        strcpy(custom_name, "CustomPageSize");
+        strlcpy(custom_name, "CustomPageSize", sizeof(custom_name));
       else
         snprintf(custom_name, sizeof(custom_name), "Custom%s", name);
 
@@ -1944,9 +1944,9 @@ _ppdOpen(
         cupsCharsetToUTF8((cups_utf8_t *)choice->text, text,
                           sizeof(choice->text), encoding);
       else if (!strcmp(name, "True"))
-        strcpy(choice->text, _("Yes"));
+        strlcpy(choice->text, _("Yes"), sizeof(choice->text));
       else if (!strcmp(name, "False"))
-        strcpy(choice->text, _("No"));
+        strlcpy(choice->text, _("No"), sizeof(choice->text));
       else
         strlcpy(choice->text, name, sizeof(choice->text));
 
index 595be6594d13255257cd335de27153d835b4901e..2c45fa8df1132968dee24fb85d18e2875af9d8bf 100644 (file)
@@ -3,7 +3,7 @@
  *
  *   snprintf functions for CUPS.
  *
- *   Copyright 2007-2010 by Apple Inc.
+ *   Copyright 2007-2012 by Apple Inc.
  *   Copyright 1997-2007 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
@@ -48,6 +48,7 @@ _cups_vsnprintf(char       *buffer,   /* O - Output buffer */
   char         tformat[100],           /* Temporary format string for sprintf() */
                *tptr,                  /* Pointer into temporary format */
                temp[1024];             /* Buffer for formatted numbers */
+  size_t       templen;                /* Length of "temp" */
   char         *s;                     /* Pointer to string */
   int          slen;                   /* Length of string */
   int          bytes;                  /* Total number of bytes needed */
@@ -183,20 +184,21 @@ _cups_vsnprintf(char       *buffer,       /* O - Output buffer */
              break;
 
            sprintf(temp, tformat, va_arg(ap, double));
+           templen = strlen(temp):
 
-            bytes += (int)strlen(temp);
+            bytes += (int)templen;
 
             if (bufptr)
            {
-             if ((bufptr + strlen(temp)) > bufend)
+             if ((bufptr + templen) > bufend)
              {
-               strncpy(bufptr, temp, (size_t)(bufend - bufptr));
+               strlcpy(bufptr, temp, (size_t)(bufend - bufptr));
                bufptr = bufend;
              }
              else
              {
-               strcpy(bufptr, temp);
-               bufptr += strlen(temp);
+               memcpy(bufptr, temp, templen + 1);
+               bufptr += templen;
              }
            }
            break;
@@ -213,20 +215,21 @@ _cups_vsnprintf(char       *buffer,       /* O - Output buffer */
              break;
 
            sprintf(temp, tformat, va_arg(ap, int));
+           templen = strlen(temp):
 
-            bytes += (int)strlen(temp);
+            bytes += (int)templen;
 
            if (bufptr)
            {
-             if ((bufptr + strlen(temp)) > bufend)
+             if ((bufptr + templen) > bufend)
              {
-               strncpy(bufptr, temp, (size_t)(bufend - bufptr));
+               strlcpy(bufptr, temp, (size_t)(bufend - bufptr));
                bufptr = bufend;
              }
              else
              {
-               strcpy(bufptr, temp);
-               bufptr += strlen(temp);
+               memcpy(bufptr, temp, templen + 1);
+               bufptr += templen;
              }
            }
            break;
@@ -236,20 +239,21 @@ _cups_vsnprintf(char       *buffer,       /* O - Output buffer */
              break;
 
            sprintf(temp, tformat, va_arg(ap, void *));
+           templen = strlen(temp):
 
-            bytes += (int)strlen(temp);
+            bytes += (int)templen;
 
            if (bufptr)
            {
-             if ((bufptr + strlen(temp)) > bufend)
+             if ((bufptr + templen) > bufend)
              {
-               strncpy(bufptr, temp, (size_t)(bufend - bufptr));
+               strlcpy(bufptr, temp, (size_t)(bufend - bufptr));
                bufptr = bufend;
              }
              else
              {
-               strcpy(bufptr, temp);
-               bufptr += strlen(temp);
+               memcpy(bufptr, temp, templen + 1);
+               bufptr += templen;
              }
            }
            break;
index 60e346453fa40740c6f4924e884ed16587b1e276..7a862f6617882d7147aefc9d41eef61432e2bbdf 100644 (file)
@@ -3,7 +3,7 @@
  *
  *   String functions for CUPS.
  *
- *   Copyright 2007-2011 by Apple Inc.
+ *   Copyright 2007-2012 by Apple Inc.
  *   Copyright 1997-2007 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
@@ -69,6 +69,7 @@ static int    compare_sp_items(_cups_sp_item_t *a, _cups_sp_item_t *b);
 char *                                 /* O - String pointer */
 _cupsStrAlloc(const char *s)           /* I - String */
 {
+  size_t               slen;           /* Length of string */
   _cups_sp_item_t      *item,          /* String pool item */
                        *key;           /* Search key */
 
@@ -128,7 +129,8 @@ _cupsStrAlloc(const char *s)                /* I - String */
   * Not found, so allocate a new one...
   */
 
-  item = (_cups_sp_item_t *)calloc(1, sizeof(_cups_sp_item_t) + strlen(s));
+  slen = strlen(s);
+  item = (_cups_sp_item_t *)calloc(1, sizeof(_cups_sp_item_t) + slen);
   if (!item)
   {
     _cupsMutexUnlock(&sp_mutex);
@@ -137,7 +139,7 @@ _cupsStrAlloc(const char *s)                /* I - String */
   }
 
   item->ref_count = 1;
-  strcpy(item->str, s);
+  memcpy(item->str, s, slen + 1);
 
 #ifdef DEBUG_GUARDS
   item->guard = _CUPS_STR_GUARD;
@@ -588,16 +590,18 @@ _cups_strcpy(char       *dst,             /* I - Destination string */
 char   *                               /* O - New string pointer */
 _cups_strdup(const char *s)            /* I - String to duplicate */
 {
-  char *t;                             /* New string pointer */
+  char         *t;                     /* New string pointer */
+  size_t       slen;                   /* Length of string */
 
 
-  if (s == NULL)
+  if (!s)
     return (NULL);
 
-  if ((t = malloc(strlen(s) + 1)) == NULL)
+  slen = strlen(s);
+  if ((t = malloc(slen + 1)) == NULL)
     return (NULL);
 
-  return (strcpy(t, s));
+  return (memcpy(t, s, slen + 1));
 }
 #endif /* !HAVE_STRDUP */
 
index 8371840fa036ff92c6fe17c87919d69099e26933..cdae3c7a54b5468f7b5734fb09bb434ff645a8e5 100644 (file)
@@ -3,7 +3,7 @@
  *
  *   Array test program for CUPS.
  *
- *   Copyright 2007-2010 by Apple Inc.
+ *   Copyright 2007-2012 by Apple Inc.
  *   Copyright 1997-2006 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
@@ -139,7 +139,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
  /*
   * cupsArrayCount()
   */
+
   fputs("cupsArrayCount: ", stdout);
   if (cupsArrayCount(array) == 4)
     puts("PASS");
@@ -319,7 +319,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
       * the same buffer in the first place... :)
       */
 
-      strcpy(word, text);
+      strlcpy(word, text, sizeof(word));
 
      /*
       * Grab the next word and compare...
index bca5f9a772e4f5d82917219d0cfab4d9e23c6192..9ad0f81623c46e8b1845d4e7a7cb390b9bc04894 100644 (file)
@@ -3,7 +3,7 @@
  *
  *   HTTP test program for CUPS.
  *
- *   Copyright 2007-2011 by Apple Inc.
+ *   Copyright 2007-2012 by Apple Inc.
  *   Copyright 1997-2006 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
@@ -218,7 +218,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
     fputs("httpGetDateString()/httpGetDateTime(): ", stdout);
 
     start = time(NULL);
-    strcpy(buffer, httpGetDateString(start));
+    strlcpy(buffer, httpGetDateString(start), sizeof(buffer));
     current = httpGetDateTime(buffer);
 
     i = (int)(current - start);
index 2e626715f7a72005eecb6e78ef6ae780c645baaf..84645a8597421eb7c18d891a93a0b83281afae13 100644 (file)
@@ -3,7 +3,7 @@
  *
  *   Internationalization test for CUPS.
  *
- *   Copyright 2007-2011 by Apple Inc.
+ *   Copyright 2007-2012 by Apple Inc.
  *   Copyright 1997-2006 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
@@ -282,7 +282,7 @@ main(int  argc,                             /* I - Argument Count */
 
   fputs("cupsCharsetToUTF8(CUPS_ISO8859_1): ", stdout);
 
-  strcpy(legsrc, legdest);
+  strlcpy(legsrc, legdest, sizeof(legsrc));
 
   len = cupsCharsetToUTF8(utf8dest, legsrc, 1024, CUPS_ISO8859_1);
   if (len != strlen((char *)utf8latin))
@@ -333,7 +333,7 @@ main(int  argc,                             /* I - Argument Count */
 
   fputs("cupsCharsetToUTF8(CUPS_ISO8859_7): ", stdout);
 
-  strcpy(legsrc, legdest);
+  strlcpy(legsrc, legdest, sizeof(legsrc));
 
   len = cupsCharsetToUTF8(utf8dest, legsrc, 1024, CUPS_ISO8859_7);
   if (len != strlen((char *)utf8greek))
@@ -379,7 +379,7 @@ main(int  argc,                             /* I - Argument Count */
 
   fputs("cupsCharsetToUTF8(CUPS_WINDOWS_932): ", stdout);
 
-  strcpy(legsrc, legdest);
+  strlcpy(legsrc, legdest, sizeof(legsrc));
 
   len = cupsCharsetToUTF8(utf8dest, legsrc, 1024, CUPS_WINDOWS_932);
   if (len != strlen((char *)utf8japan))
@@ -426,7 +426,7 @@ main(int  argc,                             /* I - Argument Count */
 #ifndef __linux
   fputs("cupsCharsetToUTF8(CUPS_EUC_JP): ", stdout);
 
-  strcpy(legsrc, legdest);
+  strlcpy(legsrc, legdest, sizeof(legsrc));
 
   len = cupsCharsetToUTF8(utf8dest, legsrc, 1024, CUPS_EUC_JP);
   if (len != strlen((char *)utf8japan))
@@ -473,7 +473,7 @@ main(int  argc,                             /* I - Argument Count */
 
   fputs("cupsCharsetToUTF8(CUPS_WINDOWS_950): ", stdout);
 
-  strcpy(legsrc, legdest);
+  strlcpy(legsrc, legdest, sizeof(legsrc));
 
   len = cupsCharsetToUTF8(utf8dest, legsrc, 1024, CUPS_WINDOWS_950);
   if (len != strlen((char *)utf8taiwan))
@@ -519,7 +519,7 @@ main(int  argc,                             /* I - Argument Count */
 
   fputs("cupsCharsetToUTF8(CUPS_EUC_TW): ", stdout);
 
-  strcpy(legsrc, legdest);
+  strlcpy(legsrc, legdest, sizeof(legsrc));
 
   len = cupsCharsetToUTF8(utf8dest, legsrc, 1024, CUPS_EUC_TW);
   if (len != strlen((char *)utf8taiwan))
index 3de6475117fa123c11220528f952ab21d08412ad..31ffa050957c5ba3905438b03977621146feecf1 100644 (file)
@@ -3,7 +3,7 @@
  *
  *   PPD test program for CUPS.
  *
- *   Copyright 2007-2011 by Apple Inc.
+ *   Copyright 2007-2012 by Apple Inc.
  *   Copyright 1997-2006 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
@@ -897,7 +897,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
 
 
       if ((realsize = readlink(filename, realfile, sizeof(realfile) - 1)) < 0)
-        strcpy(realfile, "Unknown");
+        strlcpy(realfile, "Unknown", sizeof(realfile));
       else
         realfile[realsize] = '\0';
 
index d195e3d81648403e9f313d76c3d5632ad8ed72e0..c73c07f4d3df7ae14998a5b4a063516f1c0a4db2 100644 (file)
@@ -358,7 +358,7 @@ cupsSetServer(const char *server)   /* I - Server name */
     }
 
     if (cg->server[0] == '/')
-      strcpy(cg->servername, "localhost");
+      strlcpy(cg->servername, "localhost", sizeof(cg->servername));
     else
       strlcpy(cg->servername, cg->server, sizeof(cg->servername));
   }
@@ -949,7 +949,7 @@ cups_read_client_conf(
         value = NULL;
 
       if (cg->server[0] == '/')
-       strcpy(cg->servername, "localhost");
+       strlcpy(cg->servername, "localhost", sizeof(cg->servername));
       else
        strlcpy(cg->servername, cg->server, sizeof(cg->servername));
     }
@@ -1035,7 +1035,7 @@ cups_read_client_conf(
        * Use the default "unknown" user name...
        */
 
-       strcpy(cg->user, "unknown");
+       strlcpy(cg->user, "unknown", sizeof(cg->user));
       }
     }
   }
index 3d6181d1a2564aa6592728999ea0165f3593f86b..75ada5e4233d99d417e474ab8a86fa239410bfd1 100644 (file)
@@ -605,7 +605,7 @@ cupsGetJobs2(http_t     *http,              /* I - Connection to server or @code CUPS_HTTP_D
     }
   }
   else
-    strcpy(uri, "ipp://localhost/");
+    strlcpy(uri, "ipp://localhost/", sizeof(uri));
 
   if (!http)
     if ((http = _cupsConnect()) == NULL)
@@ -1059,7 +1059,7 @@ cupsGetPPD3(http_t     *http,             /* I  - HTTP connection or @code CUPS_HTTP_DEFAUL
   DEBUG_printf(("2cupsGetPPD3: Local hostname=\"%s\"", localhost));
 
   if (!_cups_strcasecmp(localhost, hostname))
-    strcpy(hostname, "localhost");
+    strlcpy(hostname, "localhost", sizeof(hostname));
 
  /*
   * Get the hostname and port number we are connected to...
index d6766b2cdb392c2675ae047763dd30eb32001785..77157fb97597c64bc3be8939136762c3fe999e72 100644 (file)
@@ -200,7 +200,7 @@ cupsRasterInterpretPPD(
   h->cupsImagingBBox[2]          = 612.0f;
   h->cupsImagingBBox[3]          = 792.0f;
 
-  strcpy(h->cupsPageSizeName, "Letter");
+  strlcpy(h->cupsPageSizeName, "Letter", sizeof(h->cupsPageSizeName));
 
 #ifdef __APPLE__
  /*
index fa2afbad3c80a78ee3925305bbd944e029798fc4..64563f679a95cb3c6eeb365901cf47798692c9e8 100644 (file)
@@ -4,7 +4,7 @@
  *   Verify that translations in the .po file have the same number and type of
  *   printf-style format strings.
  *
- *   Copyright 2007-2010 by Apple Inc.
+ *   Copyright 2007-2012 by Apple Inc.
  *   Copyright 1997-2007 by Easy Software Products, all rights reserved.
  *
  *   These coded instructions, statements, and computer programs are the
@@ -338,7 +338,7 @@ abbreviate(const char *s,           /* I - String to abbreviate */
   }
 
   if (*s)
-    strcpy(bufptr, "...");
+    memcpy(bufptr, "...", 4);
   else
     *bufptr = '\0';
 
index 8c79de4651c7f2a33b1c75bec1a1f398d24097c6..754a487b499d4a0eb91786a23197bc2dda9f1742 100644 (file)
@@ -213,10 +213,12 @@ main(int  argc,                           /* I - Number of command-line args */
        * Append to current string...
        */
 
+        size_t ptrlen = strlen(ptr);   /* Length of string */
+
        length = (int)strlen(msgstr ? msgstr : msgid);
 
        if ((temp = realloc(msgstr ? msgstr : msgid,
-                           length + strlen(ptr) + 1)) == NULL)
+                           length + ptrlen + 1)) == NULL)
        {
          free(msgid);
          if (msgstr)
@@ -235,7 +237,7 @@ main(int  argc,                             /* I - Number of command-line args */
 
          msgstr = temp;
 
-         strcpy(msgstr + length, ptr);
+         memcpy(msgstr + length, ptr, ptrlen + 1);
        }
        else
        {
@@ -247,7 +249,7 @@ main(int  argc,                             /* I - Number of command-line args */
 
          msgid = temp;
 
-         strcpy(msgid + length, ptr);
+         memcpy(msgid + length, ptr, ptrlen + 1);
        }
       }
       else if (!strncmp(s, "msgstr", 6) && msgid)
index 890b2ae09b4b3ec64084b69eda0443e56463b93d..1629c4e7fcdc49818a4e9f10cb4293556ced112b 100644 (file)
@@ -3,7 +3,7 @@
  *
  *   D-Bus notifier for CUPS.
  *
- *   Copyright 2008-2011 by Apple Inc.
+ *   Copyright 2008-2012 by Apple Inc.
  *   Copyright (C) 2011 Red Hat, Inc.
  *   Copyright (C) 2007 Tim Waugh <twaugh@redhat.com>
  *   Copyright 1997-2005 by Easy Software Products.
@@ -445,7 +445,8 @@ main(int  argc,                             /* I - Number of command-line args */
            if (i)
              *p++ = ',';
 
-           strcpy(p, ippGetString(attr, i, NULL));
+           strlcpy(p, ippGetString(attr, i, NULL),
+                   reasons_length - (p - printer_reasons));
            p += strlen(p);
          }
          if (!dbus_message_iter_append_string(&iter, &printer_reasons))
@@ -517,7 +518,8 @@ main(int  argc,                             /* I - Number of command-line args */
          if (i)
            *p++ = ',';
 
-         strcpy(p, ippGetString(attr, i, NULL));
+         strlcpy(p, ippGetString(attr, i, NULL),
+                 reasons_length - (p - job_reasons));
          p += strlen(p);
        }
        if (!dbus_message_iter_append_string(&iter, &job_reasons))
index 78e97adc8fbfdce7fd4ba49ef42609242c41ab70..9560daa49bb7c58df45be365059bae6e4451907d 100644 (file)
@@ -943,7 +943,7 @@ ppdcSource::get_filter(ppdcFile *fp)        // I - File to read
     while (isspace(*ptr))
       ptr ++;
 
-    strcpy(program, ptr);
+    strlcpy(program, ptr, sizeof(program));
   }
   else
   {
@@ -1706,7 +1706,7 @@ ppdcSource::get_po(ppdcFile *fp)  // I - File to read
   if ((baseptr = strrchr(basedir, '/')) != NULL)
     *baseptr = '\0';
   else
-    strcpy(basedir, ".");
+    strlcpy(basedir, ".", sizeof(basedir));
 
   // Find the po file...
   pofilename[0] = '\0';
@@ -2630,7 +2630,7 @@ ppdcSource::scan_file(ppdcFile   *fp,     // I - File to read
       if ((baseptr = strrchr(basedir, '/')) != NULL)
        *baseptr = '\0';
       else
-       strcpy(basedir, ".");
+       strlcpy(basedir, ".", sizeof(basedir));
 
       // Find the include file...
       if (find_include(inctemp, basedir, incname, sizeof(incname)))
index caf8f8015de67594e9271ff1cd116ae837bea804..706bd138c60609952c42e593f6ca6ed8e112ddce 100644 (file)
@@ -3,7 +3,7 @@
 //
 //   Shared string class for the CUPS PPD Compiler.
 //
-//   Copyright 2007-2009 by Apple Inc.
+//   Copyright 2007-2012 by Apple Inc.
 //   Copyright 2002-2005 by Easy Software Products.
 //
 //   These coded instructions, statements, and computer programs are the
@@ -36,8 +36,10 @@ ppdcString::ppdcString(const char *v)        // I - String
 
   if (v)
   {
-    value = new char[strlen(v) + 1];
-    strcpy(value, v);
+    size_t vlen = strlen(v);
+
+    value = new char[vlen + 1];
+    memcpy(value, v, vlen + 1);
   }
   else
     value = 0;
index b46223cab019279b431e450e7ba05183a19a68b7..f1665ced36746e20f539286777acdc9c8ec5406b 100644 (file)
@@ -1173,7 +1173,7 @@ cupsdAuthorize(cupsd_client_t *con)       /* I - Client connection */
 
 
     if (sscanf(authorization, "%255s", scheme) != 1)
-      strcpy(scheme, "UNKNOWN");
+      strlcpy(scheme, "UNKNOWN", sizeof(scheme));
 
     cupsdLogMessage(CUPSD_LOG_ERROR,
                     "[Client %d] Bad authentication data \"%s ...\"",
index c4f9f64d4706064f2ef408430023fd6249e9742c..e9e9b86d2218160829d38a4b9d48ca074f9666a8 100644 (file)
@@ -392,13 +392,13 @@ cupsdAcceptClient(cupsd_listener_t *lis)/* I - Listener socket */
     cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to get local address - %s",
                     strerror(errno));
 
-    strcpy(con->servername, "localhost");
+    strlcpy(con->servername, "localhost", sizeof(con->servername));
     con->serverport = LocalPort;
   }
 #ifdef AF_LOCAL
   else if (_httpAddrFamily(&temp) == AF_LOCAL)
   {
-    strcpy(con->servername, "localhost");
+    strlcpy(con->servername, "localhost", sizeof(con->servername));
     con->serverport = LocalPort;
   }
 #endif /* AF_LOCAL */
@@ -912,7 +912,7 @@ cupsdReadClient(cupsd_client_t *con)        /* I - Client to read from */
          * con->uri are HTTP_MAX_URI bytes in size...
          */
 
-          strcpy(con->uri, resource);
+          strlcpy(con->uri, resource, sizeof(con->uri));
        }
 
        /*
@@ -1489,7 +1489,7 @@ cupsdReadClient(cupsd_client_t *con)      /* I - Client to read from */
              else
               {
                if (type == NULL)
-                 strcpy(line, "text/plain");
+                 strlcpy(line, "text/plain", sizeof(line));
                else
                  snprintf(line, sizeof(line), "%s/%s", type->super, type->type);
 
@@ -1914,7 +1914,7 @@ cupsdReadClient(cupsd_client_t *con)      /* I - Client to read from */
 
              type = mimeFileType(MimeDatabase, filename, NULL, NULL);
              if (type == NULL)
-               strcpy(line, "text/plain");
+               strlcpy(line, "text/plain", sizeof(line));
              else
                snprintf(line, sizeof(line), "%s/%s", type->super, type->type);
 
@@ -3776,7 +3776,7 @@ pipe_command(cupsd_client_t *con, /* I - Client connection */
          * the POSIX locale...
          */
 
-         strcpy(lang, "LANG=C");
+         strlcpy(lang, "LANG=C", sizeof(lang));
          break;
 
       case 2 :
@@ -3804,9 +3804,9 @@ pipe_command(cupsd_client_t *con, /* I - Client connection */
   else if (con->language)
     snprintf(lang, sizeof(lang), "LANG=%s.UTF8", con->language->language);
   else
-    strcpy(lang, "LANG=C");
+    strlcpy(lang, "LANG=C", sizeof(lang));
 
-  strcpy(remote_addr, "REMOTE_ADDR=");
+  strlcpy(remote_addr, "REMOTE_ADDR=", sizeof(remote_addr));
   httpAddrString(con->http.hostaddr, remote_addr + 12,
                  sizeof(remote_addr) - 12);
 
index adf409af086770cc1e590706e0c8abe2a9daa185..bf98e831b2fd8595b32223c253af388aa9e1280d 100644 (file)
@@ -227,7 +227,7 @@ cupsdAddAlias(cups_array_t *aliases,        /* I - Array of aliases */
     return;
 
   a->namelen = namelen;
-  strcpy(a->name, name);               /* OK since a->name is allocated */
+  memcpy(a->name, name, namelen + 1);  /* OK since a->name is allocated */
 
   cupsArrayAdd(aliases, a);
 }
index 1a270b3729d59ea003f1feaccd6b47d96a773b1f..31a8a25a00649eabb5c24293f2629263af5bab01 100644 (file)
@@ -1877,7 +1877,7 @@ load_drivers(cups_array_t *include,       /* I - Drivers to include */
         device_id[0] = '\0';
        product[0]   = '\0';
        psversion[0] = '\0';
-       strcpy(type_str, "postscript");
+       strlcpy(type_str, "postscript", sizeof(type_str));
 
         if (sscanf(line, "\"%511[^\"]\"%127s%*[ \t]\"%127[^\"]\""
                         "%*[ \t]\"%127[^\"]\"%*[ \t]\"%255[^\"]\""
@@ -2043,7 +2043,7 @@ load_ppd(const char  *filename,           /* I - Real filename */
   manufacturer[0]  = '\0';
   device_id[0]     = '\0';
   lang_encoding[0] = '\0';
-  strcpy(lang_version, "en");
+  strlcpy(lang_version, "en", sizeof(lang_version));
   model_number     = 0;
   install_group    = 0;
   type             = PPD_TYPE_POSTSCRIPT;
@@ -2166,7 +2166,7 @@ load_ppd(const char  *filename,           /* I - Real filename */
     cupsCharsetToUTF8((cups_utf8_t *)make_model, nick_name,
                      sizeof(make_model), _ppdGetEncoding(lang_encoding));
   else
-    strcpy(make_model, model_name);
+    strlcpy(make_model, model_name, sizeof(make_model));
 
   while (isspace(make_model[0] & 255))
     _cups_strcpy(make_model, make_model + 1);
@@ -2236,13 +2236,13 @@ load_ppd(const char  *filename,         /* I - Real filename */
     if (*ptr && ptr > manufacturer)
       *ptr = '\0';
     else
-      strcpy(manufacturer, "Other");
+      strlcpy(manufacturer, "Other", sizeof(manufacturer));
   }
   else if (!_cups_strncasecmp(manufacturer, "LHAG", 4) ||
           !_cups_strncasecmp(manufacturer, "linotype", 8))
-    strcpy(manufacturer, "LHAG");
+    strlcpy(manufacturer, "LHAG", sizeof(manufacturer));
   else if (!_cups_strncasecmp(manufacturer, "Hewlett", 7))
-    strcpy(manufacturer, "HP");
+    strlcpy(manufacturer, "HP", sizeof(manufacturer));
 
  /*
   * Fix the lang_version as needed...
@@ -2290,7 +2290,7 @@ load_ppd(const char  *filename,           /* I - Real filename */
     * Unknown language; use "xx"...
     */
 
-    strcpy(lang_version, "xx");
+    strlcpy(lang_version, "xx", sizeof(lang_version));
   }
 
  /*
@@ -2519,8 +2519,8 @@ load_ppds(const char *d,          /* I - Actual directory */
     * See if this file has been scanned before...
     */
 
-    strcpy(key.record.filename, name);
-    strcpy(key.record.name, name);
+    strlcpy(key.record.filename, name, sizeof(key.record.filename));
+    strlcpy(key.record.name, name, sizeof(key.record.name));
 
     ppd = (ppd_info_t *)cupsArrayFind(PPDsByName, &key);
 
index 6dba2bd66e497b7092bb21b1031b4eaeef473fe7..f175f666915469fdecb57b22f015fe49b8ddaecd 100644 (file)
@@ -184,7 +184,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
   if (getpeername(0, (struct sockaddr *)&hostaddr, &hostlen))
   {
     syslog(LOG_WARNING, "Unable to get client address - %s", strerror(errno));
-    strcpy(hostname, "unknown");
+    strlcpy(hostname, "unknown", sizeof(hostname));
   }
   else
   {
@@ -914,7 +914,7 @@ recv_print_job(
              break;
            }
 
-           strcpy(filename, control);
+           strlcpy(filename, control, sizeof(filename));
          }
          break;
 
@@ -950,7 +950,7 @@ recv_print_job(
            break;
          }
 
-         strcpy(filename, temp[num_data]);
+         strlcpy(filename, temp[num_data], sizeof(filename));
 
           num_data ++;
          break;
@@ -1116,7 +1116,7 @@ recv_print_job(
       {
        syslog(LOG_WARNING, "No username specified by client! "
                            "Using \"anonymous\"...");
-       strcpy(user, "anonymous");
+       strlcpy(user, "anonymous", sizeof(user));
       }
 
      /*
@@ -1528,7 +1528,7 @@ send_state(const char *queue,             /* I - Destination */
     */
 
     if (jobstate == IPP_JOB_PROCESSING)
-      strcpy(rankstr, "active");
+      strlcpy(rankstr, "active", sizeof(rankstr));
     else
     {
       snprintf(rankstr, sizeof(rankstr), "%d%s", rank, ranks[rank % 10]);
index 68806ab6c9148385d77c2a694a2ccaa67a372a8c..97a388b84071d6307e1d59ad69ad0993cb42a701 100644 (file)
@@ -771,7 +771,7 @@ escape_options(
     if (sptr > s)
       *sptr++ = ' ';
 
-    strcpy(sptr, option->name);
+    strlcpy(sptr, option->name, bytes - (sptr - s));
     sptr += strlen(sptr);
     *sptr++ = '=';
 
index 7c76d5e46e2c97e3c874ec81e4d1ddc73a3d6924..f037c5880d4c86936df411963dd838b75ddd67ac 100644 (file)
@@ -8270,8 +8270,8 @@ print_job(cupsd_client_t  *con,           /* I - Client connection */
     * Auto-type it!
     */
 
-    strcpy(super, "application");
-    strcpy(type, "octet-stream");
+    strlcpy(super, "application", sizeof(super));
+    strlcpy(type, "octet-stream", sizeof(type));
   }
 
   if (!strcmp(super, "application") && !strcmp(type, "octet-stream"))
@@ -8639,7 +8639,8 @@ reject_jobs(cupsd_client_t  *con, /* I - Client connection */
 
   if ((attr = ippFindAttribute(con->request, "printer-state-message",
                                IPP_TAG_TEXT)) == NULL)
-    strcpy(printer->state_message, "Rejecting Jobs");
+    strlcpy(printer->state_message, "Rejecting Jobs",
+            sizeof(printer->state_message));
   else
     strlcpy(printer->state_message, attr->values[0].string.text,
             sizeof(printer->state_message));
@@ -9499,8 +9500,8 @@ send_document(cupsd_client_t  *con,       /* I - Client connection */
     * No document format attribute?  Auto-type it!
     */
 
-    strcpy(super, "application");
-    strcpy(type, "octet-stream");
+    strlcpy(super, "application", sizeof(super));
+    strlcpy(type, "octet-stream", sizeof(type));
   }
 
   if (!strcmp(super, "application") && !strcmp(type, "octet-stream"))
@@ -10745,7 +10746,7 @@ stop_printer(cupsd_client_t  *con,      /* I - Client connection */
 
   if ((attr = ippFindAttribute(con->request, "printer-state-message",
                                IPP_TAG_TEXT)) == NULL)
-    strcpy(printer->state_message, "Paused");
+    strlcpy(printer->state_message, "Paused", sizeof(printer->state_message));
   else
   {
     strlcpy(printer->state_message, attr->values[0].string.text,
index e6c0c9d8a5edd998a402cadf8f6d036c05232e5b..085cfc9d3ba49f65b1aa2ca7e19fa2d9daf8e220 100644 (file)
@@ -903,7 +903,7 @@ cupsdContinueJob(cupsd_job_t *job)  /* I - Job */
                           IPP_TAG_LANGUAGE);
 
 #ifdef __APPLE__
-  strcpy(apple_language, "APPLE_LANGUAGE=");
+  strlcpy(apple_language, "APPLE_LANGUAGE=", sizeof(apple_language));
   _cupsAppleLanguage(attr->values[0].string.text,
                     apple_language + 15, sizeof(apple_language) - 15);
 #endif /* __APPLE__ */
@@ -916,7 +916,7 @@ cupsdContinueJob(cupsd_job_t *job)  /* I - Job */
        * the POSIX locale...
        */
 
-       strcpy(lang, "LANG=C");
+       strlcpy(lang, "LANG=C", sizeof(lang));
        break;
 
     case 2 :
@@ -974,14 +974,15 @@ cupsdContinueJob(cupsd_job_t *job)        /* I - Job */
       * All of these strcpy's are safe because we allocated the psr string...
       */
 
-      strcpy(printer_state_reasons, "PRINTER_STATE_REASONS=");
+      strlcpy(printer_state_reasons, "PRINTER_STATE_REASONS=", psrlen);
       for (psrptr = printer_state_reasons + 22, i = 0;
            i < job->printer->num_reasons;
           i ++)
       {
         if (i)
          *psrptr++ = ',';
-       strcpy(psrptr, job->printer->reasons[i]);
+       strlcpy(psrptr, job->printer->reasons[i],
+               psrlen - (psrptr - printer_state_reasons));
        psrptr += strlen(psrptr);
       }
     }
@@ -3758,10 +3759,10 @@ get_options(cupsd_job_t *job,           /* I - Job */
   for (i = num_pwgppds, pwgppd = pwgppds; i > 0; i --, pwgppd ++)
   {
     *optptr++ = ' ';
-    strcpy(optptr, pwgppd->name);
+    strlcpy(optptr, pwgppd->name, optlength - (optptr - options));
     optptr += strlen(optptr);
     *optptr++ = '=';
-    strcpy(optptr, pwgppd->value);
+    strlcpy(optptr, pwgppd->value, optlength - (optptr - options));
     optptr += strlen(optptr);
   }
 
index b0c903c5455ae078524d156b2ef7ccb917f0a436..93265afd50568034054c344ddc0e8457404a5b21 100644 (file)
@@ -3,7 +3,7 @@
  *
  *   Log file routines for the CUPS scheduler.
  *
- *   Copyright 2007-2011 by Apple Inc.
+ *   Copyright 2007-2012 by Apple Inc.
  *   Copyright 1997-2007 by Easy Software Products, all rights reserved.
  *
  *   These coded instructions, statements, and computer programs are the
@@ -198,7 +198,7 @@ cupsdCheckLogFile(cups_file_t **lf, /* IO - Log file */
 
     cupsFileClose(*lf);
 
-    strcpy(backname, filename);
+    strlcpy(backname, filename, sizeof(backname));
     strlcat(backname, ".O", sizeof(backname));
 
     unlink(backname);
@@ -485,7 +485,7 @@ cupsdLogJob(cupsd_job_t *job,               /* I - Job */
       if ((temp = malloc(sizeof(cupsd_joblog_t) + strlen(log_line))) != NULL)
       {
         temp->time = time(NULL);
-       strcpy(temp->message, log_line);
+       strlcpy(temp->message, log_line, sizeof(temp->message));
       }
 
       if (!job->history)
@@ -603,7 +603,7 @@ cupsdLogPage(cupsd_job_t *job,              /* I - Job being printed */
   if (!PageLogFormat)
     return (1);
 
-  strcpy(number, "1");
+  strlcpy(number, "1", sizeof(number));
   copies = 1;
   sscanf(page, "%255s%d", number, &copies);
 
index abad962eb2b2707be58fc4404dfb73c6b441bf90..de3821c961154c7d0b2716aa0b5667d086fa97a1 100644 (file)
@@ -3,7 +3,7 @@
  *
  *   MIME database file routines for CUPS.
  *
- *   Copyright 2007-2011 by Apple Inc.
+ *   Copyright 2007-2012 by Apple Inc.
  *   Copyright 1997-2006 by Easy Software Products, all rights reserved.
  *
  *   These coded instructions, statements, and computer programs are the
@@ -134,7 +134,7 @@ mimeDeleteFilter(mime_t        *mime,       /* I - MIME database */
                filter ? filter->dst->super : "???",
                filter ? filter->cost : -1,
                filter ? CUPS_LLCAST filter->maxsize : CUPS_LLCAST -1));
-               
+
   if (!mime || !filter)
     return;
 
@@ -798,7 +798,7 @@ mime_load_convs(
       if (!mime_add_fcache(filtercache, filter, filterpath))
       {
         DEBUG_printf(("mime_load_convs: Filter %s not found in %s.", filter,
-                     filterpath)); 
+                     filterpath));
         _mimeError(mime, "Filter \"%s\" not found.", filter);
         continue;
       }
@@ -836,8 +836,8 @@ mime_load_convs(
       * Force * / * to be "application/octet-stream"...
       */
 
-      strcpy(super, "application");
-      strcpy(type, "octet-stream");
+      strlcpy(super, "application", sizeof(super));
+      strlcpy(type, "octet-stream", sizeof(type));
     }
 
    /*
index 2895116920f1cd0a8e499f18e9d36bc1f2469503..7b8743882f782f7029ccf83a66efb93e0170f0e4 100644 (file)
@@ -3,7 +3,7 @@
  *
  *   MIME typing routines for CUPS.
  *
- *   Copyright 2007-2011 by Apple Inc.
+ *   Copyright 2007-2012 by Apple Inc.
  *   Copyright 1997-2006 by Easy Software Products, all rights reserved.
  *
  *   These coded instructions, statements, and computer programs are the
@@ -515,7 +515,7 @@ mimeAddTypeRule(mime_type_t *mt,    /* I - Type to add to */
         case MIME_MAGIC_MATCH :
            if (length[0] > (sizeof(temp->value.matchv) - 1))
              return (-1);
-           strcpy(temp->value.matchv, value[0]);
+           strlcpy(temp->value.matchv, value[0], sizeof(temp->value.matchv));
            break;
        case MIME_MAGIC_ASCII :
        case MIME_MAGIC_PRINTABLE :
@@ -554,7 +554,7 @@ mimeAddTypeRule(mime_type_t *mt,    /* I - Type to add to */
            if (length[0] > (sizeof(temp->value.localev) - 1))
              return (-1);
 
-           strcpy(temp->value.localev, value[0]);
+           strlcpy(temp->value.localev, value[0], sizeof(temp->value.localev));
            break;
        case MIME_MAGIC_CONTAINS :
            temp->offset = strtol(value[0], NULL, 0);
index 04412ce16451f0cc735b27aad7a6bda30ea41b32..4ae53d49012e66a7a296c5f53a5bfe7d593b5c4a 100644 (file)
@@ -1880,7 +1880,7 @@ check_constraints(ppd_file_t *ppd,        /* I - PPD file */
         if (!_cups_strncasecmp(option, "Custom", 6) && !_cups_strcasecmp(choice, "True"))
        {
          _cups_strcpy(option, option + 6);
-         strcpy(choice, "Custom");
+         strlcpy(choice, "Custom", sizeof(choice));
        }
 
         if ((o = ppdFindOption(ppd, option)) == NULL)
@@ -1981,13 +1981,13 @@ check_constraints(ppd_file_t *ppd,      /* I - PPD file */
       if (!_cups_strncasecmp(c->option1, "Custom", 6) &&
           !_cups_strcasecmp(c->choice1, "True"))
       {
-       strcpy(option, c->option1 + 6);
-       strcpy(choice, "Custom");
+       strlcpy(option, c->option1 + 6, sizeof(option));
+       strlcpy(choice, "Custom", sizeof(choice));
       }
       else
       {
-       strcpy(option, c->option1);
-       strcpy(choice, c->choice1);
+       strlcpy(option, c->option1, sizeof(option));
+       strlcpy(choice, c->choice1, sizeof(choice));
       }
 
       if ((o = ppdFindOption(ppd, option)) == NULL)
@@ -2022,13 +2022,13 @@ check_constraints(ppd_file_t *ppd,      /* I - PPD file */
       if (!_cups_strncasecmp(c->option2, "Custom", 6) &&
           !_cups_strcasecmp(c->choice2, "True"))
       {
-       strcpy(option, c->option2 + 6);
-       strcpy(choice, "Custom");
+       strlcpy(option, c->option2 + 6, sizeof(option));
+       strlcpy(choice, "Custom", sizeof(choice));
       }
       else
       {
-       strcpy(option, c->option2);
-       strcpy(choice, c->choice2);
+       strlcpy(option, c->option2, sizeof(option));
+       strlcpy(choice, c->choice2, sizeof(choice));
       }
 
       if ((o = ppdFindOption(ppd, option)) == NULL)
index 124ce7c00e399e866b6b13e66bc2f17cdf57717f..ddd02221fdd18018f57e014bfde9eddc5b2b70c1 100644 (file)
@@ -1437,7 +1437,7 @@ show_jobs(const char *dests,              /* I - Destinations */
          */
 
          if (!strftime(date, sizeof(date), "%b %d %H:%M", jobdate))
-           strcpy(date, "Unknown");
+           strlcpy(date, "Unknown", sizeof(date));
 
          _cupsLangPrintf(stdout, "%s;%s;%d;%s;%s",
                          temp, username ? username : "unknown",
@@ -1446,7 +1446,7 @@ show_jobs(const char *dests,              /* I - Destinations */
        else
        {
          if (!strftime(date, sizeof(date), "%c", jobdate))
-           strcpy(date, "Unknown");
+           strlcpy(date, "Unknown", sizeof(date));
 
           if (ranking)
            _cupsLangPrintf(stdout, "%3d %-21s %-13s %8.0f %s",