From: mike Date: Thu, 16 May 2002 13:45:05 +0000 (+0000) Subject: Add strlcat() and strlcpy() checks and emulation functions. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=17438bf405c97c1c1a4b180e09e4472c005986dc;p=thirdparty%2Fcups.git Add strlcat() and strlcpy() checks and emulation functions. Rename all string emulation functions to cups_foo() to avoid namespace collisions, etc. Use strlcat() and strlcpy() instead of strncat() and strncpy() in most cases. git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@2414 7a7537e8-13f0-0310-91df-b6672ffda945 --- diff --git a/CHANGES.txt b/CHANGES.txt index 788b1284b..16db9b6bb 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,10 +1,12 @@ -CHANGES.txt - 05/15/2002 +CHANGES.txt - 05/16/2002 ------------------------ CHANGES IN CUPS V1.1.15 - Updated the CUPS license agreement for the new MacOS and OpenSSL license exceptions. + - Now use strlcat() and strlcpy() (or emulation + functions) for easier string/buffer protection. - The auto-generated printcap/printers.conf files now have a small comment header explaining where the file comes from... diff --git a/backend/ieee1394-linux.c b/backend/ieee1394-linux.c index b79f989b7..27b5bd2bd 100644 --- a/backend/ieee1394-linux.c +++ b/backend/ieee1394-linux.c @@ -1,5 +1,5 @@ /* - * "$Id: ieee1394-linux.c,v 1.1 2002/05/04 16:58:23 mike Exp $" + * "$Id: ieee1394-linux.c,v 1.2 2002/05/16 13:44:50 mike Exp $" * * Linux IEEE-1394 glue for the Common UNIX Printing System (CUPS). * @@ -645,8 +645,8 @@ ieee1394_list(int *num_devices) /* O - Number of printers */ * Use the description directly... */ - strncpy(nodes[num_nodes].make_model, idptr, - sizeof(nodes[num_nodes].make_model) - 1); + strlcpy(nodes[num_nodes].make_model, idptr, + sizeof(nodes[num_nodes].make_model)); } else { @@ -847,5 +847,5 @@ ieee1394_error(void) /* - * End of "$Id: ieee1394-linux.c,v 1.1 2002/05/04 16:58:23 mike Exp $". + * End of "$Id: ieee1394-linux.c,v 1.2 2002/05/16 13:44:50 mike Exp $". */ diff --git a/backend/ipp.c b/backend/ipp.c index 3999eeebb..351aab839 100644 --- a/backend/ipp.c +++ b/backend/ipp.c @@ -1,5 +1,5 @@ /* - * "$Id: ipp.c,v 1.61 2002/04/24 19:54:24 mike Exp $" + * "$Id: ipp.c,v 1.62 2002/05/16 13:44:50 mike Exp $" * * IPP backend for the Common UNIX Printing System (CUPS). * @@ -169,10 +169,7 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */ close(fd); } else - { - strncpy(filename, argv[6], sizeof(filename) - 1); - filename[sizeof(filename) - 1] = '\0'; - } + strlcpy(filename, argv[6], sizeof(filename)); /* * Extract the hostname and printer name from the URI... @@ -820,5 +817,5 @@ report_printer_state(ipp_t *ipp) /* I - IPP response */ /* - * End of "$Id: ipp.c,v 1.61 2002/04/24 19:54:24 mike Exp $". + * End of "$Id: ipp.c,v 1.62 2002/05/16 13:44:50 mike Exp $". */ diff --git a/backend/lpd.c b/backend/lpd.c index 07d83417f..4111293c2 100644 --- a/backend/lpd.c +++ b/backend/lpd.c @@ -1,5 +1,5 @@ /* - * "$Id: lpd.c,v 1.35 2002/03/25 17:13:55 mike Exp $" + * "$Id: lpd.c,v 1.36 2002/05/16 13:44:50 mike Exp $" * * Line Printer Daemon backend for the Common UNIX Printing System (CUPS). * @@ -168,10 +168,7 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */ close(fd); } else - { - strncpy(filename, argv[6], sizeof(filename) - 1); - filename[sizeof(filename) - 1] = '\0'; - } + strlcpy(filename, argv[6], sizeof(filename)); /* * Extract the hostname and printer name from the URI... @@ -274,8 +271,7 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */ * Sanitize the document title... */ - strncpy(title, argv[3], sizeof(title) - 1); - title[sizeof(title) - 1] = '\0'; + strlcpy(title, argv[3], sizeof(title)); for (ptr = title; *ptr; ptr ++) if (!isalnum(*ptr) && !isspace(*ptr)) @@ -764,5 +760,5 @@ rresvport(int *port) /* IO - Port number to bind to */ #endif /* !HAVE_RRESVPORT */ /* - * End of "$Id: lpd.c,v 1.35 2002/03/25 17:13:55 mike Exp $". + * End of "$Id: lpd.c,v 1.36 2002/05/16 13:44:50 mike Exp $". */ diff --git a/backend/parallel.c b/backend/parallel.c index 729a7d6ad..092ff6818 100644 --- a/backend/parallel.c +++ b/backend/parallel.c @@ -1,5 +1,5 @@ /* - * "$Id: parallel.c,v 1.42 2002/03/25 18:10:08 mike Exp $" + * "$Id: parallel.c,v 1.43 2002/05/16 13:44:50 mike Exp $" * * Parallel port backend for the Common UNIX Printing System (CUPS). * @@ -395,10 +395,10 @@ list_devices(void) if (strncmp(line, "MODEL:", 6) == 0 && strncmp(line, "MODEL:Unknown", 13) != 0) - strncpy(model, line + 6, sizeof(model) - 1); + strlcpy(model, line + 6, sizeof(model)); else if (strncmp(line, "MANUFACTURER:", 13) == 0 && strncmp(line, "MANUFACTURER:Unknown", 20) != 0) - strncpy(make, line + 13, sizeof(make) - 1); + strlcpy(make, line + 13, sizeof(make)); } fclose(probe); @@ -658,5 +658,5 @@ list_devices(void) /* - * End of "$Id: parallel.c,v 1.42 2002/03/25 18:10:08 mike Exp $". + * End of "$Id: parallel.c,v 1.43 2002/05/16 13:44:50 mike Exp $". */ diff --git a/backend/usb.c b/backend/usb.c index c5d947690..943942e67 100644 --- a/backend/usb.c +++ b/backend/usb.c @@ -1,5 +1,5 @@ /* - * "$Id: usb.c,v 1.29 2002/03/25 18:10:08 mike Exp $" + * "$Id: usb.c,v 1.30 2002/05/16 13:44:50 mike Exp $" * * USB port backend for the Common UNIX Printing System (CUPS). * @@ -342,12 +342,12 @@ list_devices(void) if (strncmp(line, "S: Manufacturer=", 17) == 0) { - strncpy(make, line + 17, sizeof(make) - 1); + strlcpy(make, line + 17, sizeof(make)); if (strcmp(make, "Hewlett-Packard") == 0) strcpy(make, "HP"); } else if (strncmp(line, "S: Product=", 12) == 0) - strncpy(model, line + 12, sizeof(model) - 1); + strlcpy(model, line + 12, sizeof(model)); } else if (strncmp(line, "I:", 2) == 0 && (strstr(line, "Driver=printer") != NULL || @@ -460,5 +460,5 @@ list_devices(void) /* - * End of "$Id: usb.c,v 1.29 2002/03/25 18:10:08 mike Exp $". + * End of "$Id: usb.c,v 1.30 2002/05/16 13:44:50 mike Exp $". */ diff --git a/berkeley/Dependencies b/berkeley/Dependencies index 046bab6b7..0915065b5 100644 --- a/berkeley/Dependencies +++ b/berkeley/Dependencies @@ -2,8 +2,9 @@ lpc.o: ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h lpc.o: ../cups/ppd.h ../cups/language.h ../cups/debug.h -lpq.o: ../config.h ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h -lpq.o: ../cups/ppd.h ../cups/language.h ../cups/debug.h +lpq.o: ../cups/string.h ../config.h ../cups/cups.h ../cups/ipp.h +lpq.o: ../cups/http.h ../cups/md5.h ../cups/ppd.h ../cups/language.h +lpq.o: ../cups/debug.h lpr.o: ../config.h ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h lpr.o: ../cups/ppd.h lprm.o: ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h diff --git a/berkeley/lpq.c b/berkeley/lpq.c index 1b97b6018..8aadce0ae 100644 --- a/berkeley/lpq.c +++ b/berkeley/lpq.c @@ -1,5 +1,5 @@ /* - * "$Id: lpq.c,v 1.20 2002/01/02 17:58:35 mike Exp $" + * "$Id: lpq.c,v 1.21 2002/05/16 13:44:51 mike Exp $" * * "lpq" command for the Common UNIX Printing System (CUPS). * @@ -38,8 +38,7 @@ #include #include -#include -#include +#include #include #include #include @@ -415,10 +414,7 @@ show_jobs(http_t *http, /* I - HTTP connection to server */ snprintf(namestr, sizeof(namestr), "%d copies of %s", jobcopies, jobname); else - { - strncpy(namestr, jobname, sizeof(namestr) - 1); - namestr[sizeof(namestr) - 1] = '\0'; - } + strlcpy(namestr, jobname, sizeof(namestr)); printf("%s: %-34.34s[job %d localhost]\n", jobuser, rankstr, jobid); printf(" %-40.40s%d bytes\n", namestr, jobsize); @@ -538,5 +534,5 @@ show_printer(http_t *http, /* I - HTTP connection to server */ /* - * End of "$Id: lpq.c,v 1.20 2002/01/02 17:58:35 mike Exp $". + * End of "$Id: lpq.c,v 1.21 2002/05/16 13:44:51 mike Exp $". */ diff --git a/cgi-bin/Dependencies b/cgi-bin/Dependencies index 778b3f713..d69abebfa 100644 --- a/cgi-bin/Dependencies +++ b/cgi-bin/Dependencies @@ -1,11 +1,11 @@ # DO NOT DELETE -html.o: cgi.h +html.o: cgi.h ../cups/string.h ../config.h ipp-var.o: ipp-var.h ../cups/cups.h ../cups/ipp.h ../cups/http.h ipp-var.o: ../cups/md5.h ../cups/ppd.h ../cups/debug.h ../cups/language.h ipp-var.o: ../cups/string.h ../config.h cgi.h -template.o: cgi.h -var.o: cgi.h +template.o: cgi.h ../cups/string.h ../config.h +var.o: cgi.h ../cups/string.h ../config.h admin.o: ipp-var.h ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h admin.o: ../cups/ppd.h ../cups/debug.h ../cups/language.h ../cups/string.h admin.o: ../config.h cgi.h diff --git a/cgi-bin/admin.c b/cgi-bin/admin.c index 689e5c179..84149079e 100644 --- a/cgi-bin/admin.c +++ b/cgi-bin/admin.c @@ -1,5 +1,5 @@ /* - * "$Id: admin.c,v 1.26 2002/03/25 17:51:17 mike Exp $" + * "$Id: admin.c,v 1.27 2002/05/16 13:44:51 mike Exp $" * * Administration CGI for the Common UNIX Printing System (CUPS). * @@ -635,8 +635,7 @@ do_am_printer(http_t *http, /* I - HTTP connection */ if (oldinfo && (attr = ippFindAttribute(oldinfo, "device-uri", IPP_TAG_URI)) != NULL) { - strncpy(uri, attr->values[0].string.text, sizeof(uri) - 1); - uri[sizeof(uri) - 1] = '\0'; + strlcpy(uri, attr->values[0].string.text, sizeof(uri)); if ((uriptr = strchr(uri, ':')) != NULL && strncmp(uriptr, "://", 3) == 0) *uriptr = '\0'; @@ -789,8 +788,7 @@ do_am_printer(http_t *http, /* I - HTTP connection */ * Let the user choose a model... */ - strncpy(make, var, sizeof(make) - 1); - make[sizeof(make) - 1] = '\0'; + strlcpy(make, var, sizeof(make)); ippSetCGIVars(response, "ppd-make", make); cgiCopyTemplateLang(stdout, TEMPLATES, "choose-model.tmpl", @@ -852,8 +850,7 @@ do_am_printer(http_t *http, /* I - HTTP connection */ ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_NAME, "ppd-name", NULL, cgiGetVariable("PPD_NAME")); - strncpy(uri, cgiGetVariable("DEVICE_URI"), sizeof(uri) - 1); - uri[sizeof(uri) - 1] = '\0'; + strlcpy(uri, cgiGetVariable("DEVICE_URI"), sizeof(uri)); if (strncmp(uri, "serial:", 7) == 0) { /* @@ -1146,8 +1143,7 @@ do_config_printer(http_t *http, /* I - HTTP connection */ * Get default option name... */ - strncpy(keyword, line + 8, sizeof(keyword) - 1); - keyword[sizeof(keyword) - 1] = '\0'; + strlcpy(keyword, line + 8, sizeof(keyword)); for (keyptr = keyword; *keyptr; keyptr ++) if (*keyptr == ':' || isspace(*keyptr)) @@ -1600,5 +1596,5 @@ get_line(char *buf, /* I - Line buffer */ /* - * End of "$Id: admin.c,v 1.26 2002/03/25 17:51:17 mike Exp $". + * End of "$Id: admin.c,v 1.27 2002/05/16 13:44:51 mike Exp $". */ diff --git a/cgi-bin/cgi.h b/cgi-bin/cgi.h index 01da2fe02..1b6f14832 100644 --- a/cgi-bin/cgi.h +++ b/cgi-bin/cgi.h @@ -1,5 +1,5 @@ /* - * "$Id: cgi.h,v 1.14 2002/01/27 21:16:09 mike Exp $" + * "$Id: cgi.h,v 1.15 2002/05/16 13:44:52 mike Exp $" * * CGI support library definitions. * @@ -25,10 +25,10 @@ # include # include -# include -# include # include +# include + # ifdef WIN32 # include # include @@ -38,16 +38,6 @@ # endif /* WIN32 */ -/* - * Stuff for WIN32 and OS/2... - */ - -# if defined(WIN32) || defined(__EMX__) -# define strcasecmp stricmp -# define strncasecmp strnicmp -# endif /* WIN32 || __EMX__ */ - - /* * Prototypes... */ @@ -92,5 +82,5 @@ extern void cgiSetCookie(const char *name, const char *value, #endif /* !_CGI_H_ */ /* - * End of "$Id: cgi.h,v 1.14 2002/01/27 21:16:09 mike Exp $". + * End of "$Id: cgi.h,v 1.15 2002/05/16 13:44:52 mike Exp $". */ diff --git a/cgi-bin/ipp-var.c b/cgi-bin/ipp-var.c index 52514582e..2cb28f5b5 100644 --- a/cgi-bin/ipp-var.c +++ b/cgi-bin/ipp-var.c @@ -1,5 +1,5 @@ /* - * "$Id: ipp-var.c,v 1.27 2002/04/08 16:28:31 mike Exp $" + * "$Id: ipp-var.c,v 1.28 2002/05/16 13:44:52 mike Exp $" * * IPP variable routines for the Common UNIX Printing System (CUPS). * @@ -177,14 +177,13 @@ ippSetCGIVars(ipp_t *response, /* I - Response data to be copied... */ * Copy values... */ - value[0] = '\0'; /* Initially an empty string */ - value[sizeof(value) - 1] = '\0'; /* In case string gets full */ - valptr = value; /* Start at the beginning */ + value[0] = '\0'; /* Initially an empty string */ + valptr = value; /* Start at the beginning */ for (i = 0; i < attr->num_values; i ++) { if (i) - strncat(valptr, ",", sizeof(value) - (valptr - value) - 1); + strlcat(valptr, ",", sizeof(value) - (valptr - value)); valptr += strlen(valptr); @@ -209,7 +208,7 @@ ippSetCGIVars(ipp_t *response, /* I - Response data to be copied... */ break; case IPP_TAG_NOVALUE : - strncat(valptr, "novalue", sizeof(value) - (valptr - value) - 1); + strlcat(valptr, "novalue", sizeof(value) - (valptr - value)); break; case IPP_TAG_RANGE : @@ -245,8 +244,7 @@ ippSetCGIVars(ipp_t *response, /* I - Response data to be copied... */ * Make URI relative to the current server... */ - strncpy(uri, resource, sizeof(uri) - 1); - uri[sizeof(uri) - 1] = '\0'; + strlcpy(uri, resource, sizeof(uri)); } else { @@ -264,7 +262,7 @@ ippSetCGIVars(ipp_t *response, /* I - Response data to be copied... */ hostname, port, resource); } - strncat(valptr, uri, sizeof(value) - (valptr - value) - 1); + strlcat(valptr, uri, sizeof(value) - (valptr - value)); break; } } @@ -275,8 +273,8 @@ ippSetCGIVars(ipp_t *response, /* I - Response data to be copied... */ case IPP_TAG_KEYWORD : case IPP_TAG_CHARSET : case IPP_TAG_LANGUAGE : - strncat(valptr, attr->values[i].string.text, - sizeof(value) - (valptr - value) - 1); + strlcat(valptr, attr->values[i].string.text, + sizeof(value) - (valptr - value)); break; default : @@ -298,5 +296,5 @@ ippSetCGIVars(ipp_t *response, /* I - Response data to be copied... */ /* - * End of "$Id: ipp-var.c,v 1.27 2002/04/08 16:28:31 mike Exp $". + * End of "$Id: ipp-var.c,v 1.28 2002/05/16 13:44:52 mike Exp $". */ diff --git a/cgi-bin/template.c b/cgi-bin/template.c index a4b621ae8..a79c56658 100644 --- a/cgi-bin/template.c +++ b/cgi-bin/template.c @@ -1,5 +1,5 @@ /* - * "$Id: template.c,v 1.25 2002/01/02 17:58:37 mike Exp $" + * "$Id: template.c,v 1.26 2002/05/16 13:44:52 mike Exp $" * * CGI template function. * @@ -373,28 +373,19 @@ cgi_copy(FILE *out, /* I - Output file */ if ((innerval = cgiGetArray(innername, atoi(innerptr) - 1)) == NULL) *s = '\0'; else - { - strncpy(s, innerval, sizeof(compare) - (s - compare) - 1); - compare[sizeof(compare) - 1] = '\0'; - } + strlcpy(s, innerval, sizeof(compare) - (s - compare)); } else if (innername[0] == '?') { if ((innerval = cgiGetArray(innername + 1, element)) == NULL) *s = '\0'; else - { - strncpy(s, innerval, sizeof(compare) - (s - compare) - 1); - compare[sizeof(compare) - 1] = '\0'; - } + strlcpy(s, innerval, sizeof(compare) - (s - compare)); } else if ((innerval = cgiGetArray(innername, element)) == NULL) snprintf(s, sizeof(s), "{%s}", innername); else - { - strncpy(s, innerval, sizeof(compare) - (s - compare) - 1); - compare[sizeof(compare) - 1] = '\0'; - } + strlcpy(s, innerval, sizeof(compare) - (s - compare)); s += strlen(s); } @@ -497,5 +488,5 @@ cgi_puts(const char *s, /* - * End of "$Id: template.c,v 1.25 2002/01/02 17:58:37 mike Exp $". + * End of "$Id: template.c,v 1.26 2002/05/16 13:44:52 mike Exp $". */ diff --git a/config-scripts/cups-common.m4 b/config-scripts/cups-common.m4 index cd166608a..06e28433e 100644 --- a/config-scripts/cups-common.m4 +++ b/config-scripts/cups-common.m4 @@ -1,5 +1,5 @@ dnl -dnl "$Id: cups-common.m4,v 1.16 2002/03/08 19:48:58 mike Exp $" +dnl "$Id: cups-common.m4,v 1.17 2002/05/16 13:44:53 mike Exp $" dnl dnl Common configuration stuff for the Common UNIX Printing System (CUPS). dnl @@ -91,7 +91,7 @@ AC_CHECK_HEADER(usersec.h,AC_DEFINE(HAVE_USERSEC_H)) AC_CHECK_HEADER(sys/ioctl.h,AC_DEFINE(HAVE_SYS_IOCTL_H)) dnl Checks for string functions. -AC_CHECK_FUNCS(strdup strcasecmp strncasecmp) +AC_CHECK_FUNCS(strdup strcasecmp strncasecmp strlcat strlcpy) if test "$uname" = "HP-UX" -a "$uversion" = "1020"; then echo Forcing snprintf emulation for HP-UX. else @@ -152,5 +152,5 @@ esac AC_SUBST(ARFLAGS) dnl -dnl End of "$Id: cups-common.m4,v 1.16 2002/03/08 19:48:58 mike Exp $". +dnl End of "$Id: cups-common.m4,v 1.17 2002/05/16 13:44:53 mike Exp $". dnl diff --git a/config.h.in b/config.h.in index 31cd94580..94bb7ceef 100644 --- a/config.h.in +++ b/config.h.in @@ -1,5 +1,5 @@ /* - * "$Id: config.h.in,v 1.56 2002/03/28 21:48:43 mike Exp $" + * "$Id: config.h.in,v 1.57 2002/05/16 13:44:49 mike Exp $" * * Configuration file for the Common UNIX Printing System (CUPS). * @@ -125,6 +125,8 @@ #undef HAVE_STRDUP #undef HAVE_STRCASECMP #undef HAVE_STRNCASECMP +#undef HAVE_STRLCAT +#undef HAVE_STRLCPY /* @@ -231,5 +233,5 @@ /* - * End of "$Id: config.h.in,v 1.56 2002/03/28 21:48:43 mike Exp $". + * End of "$Id: config.h.in,v 1.57 2002/05/16 13:44:49 mike Exp $". */ diff --git a/cups/dest.c b/cups/dest.c index c050e0aa3..25e9cf377 100644 --- a/cups/dest.c +++ b/cups/dest.c @@ -1,5 +1,5 @@ /* - * "$Id: dest.c,v 1.30 2002/03/22 14:21:42 mike Exp $" + * "$Id: dest.c,v 1.31 2002/05/16 13:44:53 mike Exp $" * * User-defined destination (and option) support for the Common UNIX * Printing System (CUPS). @@ -265,8 +265,7 @@ cupsGetDests(cups_dest_t **dests) /* O - Destinations */ * Grab printer and instance name... */ - strncpy(name, defprinter, sizeof(name) - 1); - name[sizeof(name) - 1] = '\0'; + strlcpy(name, defprinter, sizeof(name)); if ((instance = strchr(name, '/')) != NULL) *instance++ = '\0'; @@ -795,5 +794,5 @@ cups_get_sdests(ipp_op_t op, /* I - get-printers or get-classes */ /* - * End of "$Id: dest.c,v 1.30 2002/03/22 14:21:42 mike Exp $". + * End of "$Id: dest.c,v 1.31 2002/05/16 13:44:53 mike Exp $". */ diff --git a/cups/http.c b/cups/http.c index db97bc785..9006ba3d4 100644 --- a/cups/http.c +++ b/cups/http.c @@ -1,5 +1,5 @@ /* - * "$Id: http.c,v 1.96 2002/04/09 19:27:06 mike Exp $" + * "$Id: http.c,v 1.97 2002/05/16 13:44:53 mike Exp $" * * HTTP routines for the Common UNIX Printing System (CUPS) scheduler. * @@ -394,7 +394,7 @@ httpConnectEncrypt(const char *host, /* I - Host to connect to */ * Copy the hostname and port and then "reconnect"... */ - strncpy(http->hostname, host, sizeof(http->hostname) - 1); + strlcpy(http->hostname, host, sizeof(http->hostname)); http->hostaddr.sin_family = hostaddr->h_addrtype; #ifdef WIN32 http->hostaddr.sin_port = htons((u_short)port); @@ -415,7 +415,7 @@ httpConnectEncrypt(const char *host, /* I - Host to connect to */ * Loop through the addresses we have until one of them connects... */ - strncpy(http->hostname, host, sizeof(http->hostname) - 1); + strlcpy(http->hostname, host, sizeof(http->hostname)); for (i = 0; hostaddr->h_addr_list[i]; i ++) { @@ -719,8 +719,7 @@ httpSeparate(const char *uri, /* I - Universal Resource Identifier */ * longer than HTTP_MAX_URI characters long... */ - strncpy(safeuri, uri, sizeof(safeuri)); - safeuri[sizeof(safeuri) - 1] = '\0'; + strlcpy(safeuri, uri, sizeof(safeuri)); uri = safeuri; @@ -759,8 +758,7 @@ httpSeparate(const char *uri, /* I - Universal Resource Identifier */ { if ((ptr = strchr(host, '/')) != NULL) { - strncpy(resource, ptr, HTTP_MAX_URI); - resource[HTTP_MAX_URI - 1] = '\0'; + strlcpy(resource, ptr, HTTP_MAX_URI); *ptr = '\0'; } else @@ -775,10 +773,7 @@ httpSeparate(const char *uri, /* I - Universal Resource Identifier */ *port = strtol(uri, (char **)&uri, 10); if (*uri == '/') - { - strncpy(resource, uri, HTTP_MAX_URI); - resource[HTTP_MAX_URI - 1] = '\0'; - } + strlcpy(resource, uri, HTTP_MAX_URI); } else *port = 631; @@ -788,10 +783,7 @@ httpSeparate(const char *uri, /* I - Universal Resource Identifier */ return; } else - { - strncpy(method, host, 31); - method[31] = '\0'; - } + strlcpy(method, host, 32); } /* @@ -800,8 +792,7 @@ httpSeparate(const char *uri, /* I - Universal Resource Identifier */ if (strncmp(uri, "//", 2) != 0) { - strncpy(resource, uri, 1023); - resource[1023] = '\0'; + strlcpy(resource, uri, HTTP_MAX_URI); username[0] = '\0'; host[0] = '\0'; @@ -889,8 +880,7 @@ httpSeparate(const char *uri, /* I - Universal Resource Identifier */ * The remaining portion is the resource string... */ - strncpy(resource, uri, HTTP_MAX_URI); - resource[HTTP_MAX_URI - 1] = '\0'; + strlcpy(resource, uri, HTTP_MAX_URI); } @@ -1032,8 +1022,7 @@ httpSetField(http_t *http, /* I - HTTP data */ value == NULL) return; - strncpy(http->fields[field], value, HTTP_MAX_VALUE - 1); - http->fields[field][HTTP_MAX_VALUE - 1] = '\0'; + strlcpy(http->fields[field], value, HTTP_MAX_VALUE); } @@ -2280,5 +2269,5 @@ http_upgrade(http_t *http) /* I - HTTP data */ /* - * End of "$Id: http.c,v 1.96 2002/04/09 19:27:06 mike Exp $". + * End of "$Id: http.c,v 1.97 2002/05/16 13:44:53 mike Exp $". */ diff --git a/cups/language.c b/cups/language.c index 514f0fa86..ad3d627f8 100644 --- a/cups/language.c +++ b/cups/language.c @@ -1,5 +1,5 @@ /* - * "$Id: language.c,v 1.26 2002/03/01 19:53:29 mike Exp $" + * "$Id: language.c,v 1.27 2002/05/16 13:44:54 mike Exp $" * * I18N/language support for the Common UNIX Printing System (CUPS). * @@ -176,8 +176,7 @@ cupsLangGet(const char *language) /* I - Language or locale */ * Copy the locale string over safely... */ - strncpy(langname, language, sizeof(langname) - 1); - langname[sizeof(langname) - 1] = '\0'; + strlcpy(langname, language, sizeof(langname)); } if (strlen(langname) < 2) @@ -214,8 +213,7 @@ cupsLangGet(const char *language) /* I - Language or locale */ * Add charset... */ - strncpy(real + count, langname + count, sizeof(real) - count - 1); - langname[count] = '\0'; + strlcpy(real + count, langname + count, sizeof(real) - count); count += strlen(real + count); /* @@ -289,10 +287,7 @@ cupsLangGet(const char *language) /* I - Language or locale */ */ if (fp == NULL) - { - strncpy(line, lang_default[0], sizeof(line) - 1); - line[sizeof(line) - 1] = '\0'; - } + strlcpy(line, lang_default[0], sizeof(line)); else if (fgets(line, sizeof(line), fp) == NULL) { /* @@ -349,8 +344,7 @@ cupsLangGet(const char *language) /* I - Language or locale */ */ lang->used ++; - strncpy(lang->language, langname, sizeof(lang->language) - 1); - lang->language[sizeof(lang->language) - 1] = '\0'; + strlcpy(lang->language, langname, sizeof(lang->language)); for (i = 0; i < (sizeof(lang_encodings) / sizeof(lang_encodings[0])); i ++) if (strcmp(lang_encodings[i], line) == 0) @@ -377,8 +371,7 @@ cupsLangGet(const char *language) /* I - Language or locale */ if (lang_default[count] == NULL) break; - strncpy(line, lang_default[count], sizeof(line) - 1); - /* Already set last byte to 0 above... */ + strlcpy(line, lang_default[count], sizeof(line)); } else if (fgets(line, sizeof(line), fp) == NULL) break; @@ -429,5 +422,5 @@ cupsLangGet(const char *language) /* I - Language or locale */ /* - * End of "$Id: language.c,v 1.26 2002/03/01 19:53:29 mike Exp $". + * End of "$Id: language.c,v 1.27 2002/05/16 13:44:54 mike Exp $". */ diff --git a/cups/ppd.c b/cups/ppd.c index c6bdfa8ff..d11faacba 100644 --- a/cups/ppd.c +++ b/cups/ppd.c @@ -1,5 +1,5 @@ /* - * "$Id: ppd.c,v 1.67 2002/05/14 16:13:48 mike Exp $" + * "$Id: ppd.c,v 1.68 2002/05/16 13:44:54 mike Exp $" * * PPD file routines for the Common UNIX Printing System (CUPS). * @@ -310,7 +310,7 @@ ppd_get_group(ppd_file_t *ppd, /* I - PPD file */ ppd->num_groups ++; memset(group, 0, sizeof(ppd_group_t)); - strncpy(group->text, name, sizeof(group->text) - 1); + strlcpy(group->text, name, sizeof(group->text)); } return (group); @@ -349,7 +349,7 @@ ppd_get_option(ppd_group_t *group, /* I - Group */ group->num_options ++; memset(option, 0, sizeof(ppd_option_t)); - strncpy(option->keyword, name, sizeof(option->keyword) - 1); + strlcpy(option->keyword, name, sizeof(option->keyword)); } return (option); @@ -381,7 +381,7 @@ ppd_add_choice(ppd_option_t *option, /* I - Option */ option->num_choices ++; memset(choice, 0, sizeof(ppd_choice_t)); - strncpy(choice->choice, name, sizeof(choice->choice) - 1); + strlcpy(choice->choice, name, sizeof(choice->choice)); return (choice); } @@ -411,7 +411,7 @@ ppd_add_size(ppd_file_t *ppd, /* I - PPD file */ ppd->num_sizes ++; memset(size, 0, sizeof(ppd_size_t)); - strncpy(size->name, name, sizeof(size->name) - 1); + strlcpy(size->name, name, sizeof(size->name)); return (size); } @@ -646,8 +646,8 @@ ppdOpen(FILE *fp) /* I - File to read from */ ppd->num_profiles ++; memset(profile, 0, sizeof(ppd_profile_t)); - strncpy(profile->resolution, name, sizeof(profile->resolution) - 1); - strncpy(profile->media_type, text, sizeof(profile->media_type) - 1); + strlcpy(profile->resolution, name, sizeof(profile->resolution)); + strlcpy(profile->media_type, text, sizeof(profile->media_type)); sscanf(string, "%f%f%f%f%f%f%f%f%f%f%f", &(profile->density), &(profile->gamma), profile->matrix[0] + 0, profile->matrix[0] + 1, @@ -751,8 +751,8 @@ ppdOpen(FILE *fp) /* I - File to read from */ return (NULL); } - strncpy(choice->text, cupsLangString(language, CUPS_MSG_VARIABLE), - sizeof(choice->text) - 1); + strlcpy(choice->text, cupsLangString(language, CUPS_MSG_VARIABLE), + sizeof(choice->text)); option = NULL; } else if (strcmp(keyword, "MaxMediaWidth") == 0) @@ -821,8 +821,8 @@ ppdOpen(FILE *fp) /* I - File to read from */ return (NULL); } - strncpy(choice->text, cupsLangString(language, CUPS_MSG_VARIABLE), - sizeof(choice->text) - 1); + strlcpy(choice->text, cupsLangString(language, CUPS_MSG_VARIABLE), + sizeof(choice->text)); option = NULL; } @@ -994,28 +994,28 @@ ppdOpen(FILE *fp) /* I - File to read from */ if (text[0]) { - strncpy(option->text, text, sizeof(option->text) - 1); + strlcpy(option->text, text, sizeof(option->text)); ppd_fix(option->text); } else { if (strcmp(name, "PageSize") == 0) - strncpy(option->text, cupsLangString(language, CUPS_MSG_MEDIA_SIZE), - sizeof(option->text) - 1); + strlcpy(option->text, cupsLangString(language, CUPS_MSG_MEDIA_SIZE), + sizeof(option->text)); else if (strcmp(name, "MediaType") == 0) - strncpy(option->text, cupsLangString(language, CUPS_MSG_MEDIA_TYPE), - sizeof(option->text) - 1); + strlcpy(option->text, cupsLangString(language, CUPS_MSG_MEDIA_TYPE), + sizeof(option->text)); else if (strcmp(name, "InputSlot") == 0) - strncpy(option->text, cupsLangString(language, CUPS_MSG_MEDIA_SOURCE), - sizeof(option->text) - 1); + strlcpy(option->text, cupsLangString(language, CUPS_MSG_MEDIA_SOURCE), + sizeof(option->text)); else if (strcmp(name, "ColorModel") == 0) - strncpy(option->text, cupsLangString(language, CUPS_MSG_OUTPUT_MODE), - sizeof(option->text) - 1); + strlcpy(option->text, cupsLangString(language, CUPS_MSG_OUTPUT_MODE), + sizeof(option->text)); else if (strcmp(name, "Resolution") == 0) - strncpy(option->text, cupsLangString(language, CUPS_MSG_RESOLUTION), - sizeof(option->text) - 1); + strlcpy(option->text, cupsLangString(language, CUPS_MSG_RESOLUTION), + sizeof(option->text)); else - strncpy(option->text, name, sizeof(option->text) - 1); + strlcpy(option->text, name, sizeof(option->text)); } option->section = PPD_ORDER_ANY; @@ -1062,7 +1062,7 @@ ppdOpen(FILE *fp) /* I - File to read from */ else option->ui = PPD_UI_PICKONE; - strncpy(option->text, text, sizeof(option->text) - 1); + strlcpy(option->text, text, sizeof(option->text)); option->section = PPD_ORDER_JCL; group = NULL; @@ -1192,13 +1192,13 @@ ppdOpen(FILE *fp) /* I - File to read from */ for (i = 0; i < temp->num_options; i ++) if (strcmp(keyword, temp->options[i].keyword) == 0) { - strncpy(temp->options[i].defchoice, string, - sizeof(temp->options[i].defchoice) - 1); + strlcpy(temp->options[i].defchoice, string, + sizeof(temp->options[i].defchoice)); break; } } else - strncpy(option->defchoice, string, sizeof(option->defchoice) - 1); + strlcpy(option->defchoice, string, sizeof(option->defchoice)); } else if (strcmp(keyword, "UIConstraints") == 0 || strcmp(keyword, "NonUIConstraints") == 0) @@ -1342,7 +1342,7 @@ ppdOpen(FILE *fp) /* I - File to read from */ if (mask & PPD_TEXT) { - strncpy(choice->text, text, sizeof(choice->text) - 1); + strlcpy(choice->text, text, sizeof(choice->text)); ppd_fix(choice->text); } else if (strcmp(name, "True") == 0) @@ -1350,7 +1350,7 @@ ppdOpen(FILE *fp) /* I - File to read from */ else if (strcmp(name, "False") == 0) strcpy(choice->text, "No"); else - strncpy(choice->text, name, sizeof(choice->text) - 1); + strlcpy(choice->text, name, sizeof(choice->text)); if (option->section == PPD_ORDER_JCL) ppd_decode(string); /* Decode quoted string */ @@ -2028,5 +2028,5 @@ ppd_fix(char *string) /* IO - String to fix */ /* - * End of "$Id: ppd.c,v 1.67 2002/05/14 16:13:48 mike Exp $". + * End of "$Id: ppd.c,v 1.68 2002/05/16 13:44:54 mike Exp $". */ diff --git a/cups/snprintf.c b/cups/snprintf.c index e185fe38e..b7f4ab7de 100644 --- a/cups/snprintf.c +++ b/cups/snprintf.c @@ -1,5 +1,5 @@ /* - * "$Id: snprintf.c,v 1.6 2002/03/01 19:53:30 mike Exp $" + * "$Id: snprintf.c,v 1.7 2002/05/16 13:44:54 mike Exp $" * * snprintf functions for the Common UNIX Printing System (CUPS). * @@ -25,8 +25,8 @@ * * Contents: * - * vsnprintf() - Format a string into a fixed size buffer. - * snprintf() - Format a string into a fixed size buffer. + * cups_vsnprintf() - Format a string into a fixed size buffer. + * cups_snprintf() - Format a string into a fixed size buffer. */ /* @@ -40,28 +40,28 @@ #ifndef HAVE_VSNPRINTF /* - * 'vsnprintf()' - Format a string into a fixed size buffer. + * 'cups_vsnprintf()' - Format a string into a fixed size buffer. */ -int /* O - Number of bytes formatted */ -vsnprintf(char *buffer, /* O - Output buffer */ - size_t bufsize, /* O - Size of output buffer */ - const char *format, /* I - printf-style format string */ - va_list ap) /* I - Pointer to additional arguments */ +int /* O - Number of bytes formatted */ +cups_vsnprintf(char *buffer, /* O - Output buffer */ + size_t bufsize, /* O - Size of output buffer */ + const char *format, /* I - printf-style format string */ + va_list ap) /* I - Pointer to additional arguments */ { - char *bufptr, /* Pointer to position in buffer */ - *bufend, /* Pointer to end of buffer */ - sign, /* Sign of format width */ - size, /* Size character (h, l, L) */ - type; /* Format type character */ - const char *bufformat; /* Start of format */ - int width, /* Width of field */ - prec; /* Number of characters of precision */ - char tformat[100], /* Temporary format string for sprintf() */ - temp[1024]; /* Buffer for formatted numbers */ - int *chars; /* Pointer to integer for %p */ - char *s; /* Pointer to string */ - int slen; /* Length of string */ + char *bufptr, /* Pointer to position in buffer */ + *bufend, /* Pointer to end of buffer */ + sign, /* Sign of format width */ + size, /* Size character (h, l, L) */ + type; /* Format type character */ + const char *bufformat; /* Start of format */ + int width, /* Width of field */ + prec; /* Number of characters of precision */ + char tformat[100], /* Temporary format string for sprintf() */ + temp[1024]; /* Buffer for formatted numbers */ + int *chars; /* Pointer to integer for %p */ + char *s; /* Pointer to string */ + int slen; /* Length of string */ /* @@ -261,17 +261,17 @@ vsnprintf(char *buffer, /* O - Output buffer */ #ifndef HAVE_SNPRINTF /* - * 'snprintf()' - Format a string into a fixed size buffer. + * 'cups_snprintf()' - Format a string into a fixed size buffer. */ -int /* O - Number of bytes formatted */ -snprintf(char *buffer, /* O - Output buffer */ - size_t bufsize, /* O - Size of output buffer */ - const char *format, /* I - printf-style format string */ - ...) /* I - Additional arguments as needed */ +int /* O - Number of bytes formatted */ +cups_snprintf(char *buffer, /* O - Output buffer */ + size_t bufsize, /* O - Size of output buffer */ + const char *format, /* I - printf-style format string */ + ...) /* I - Additional arguments as needed */ { - int bytes; /* Number of bytes formatted */ - va_list ap; /* Pointer to additional arguments */ + int bytes; /* Number of bytes formatted */ + va_list ap; /* Pointer to additional arguments */ va_start(ap, format); @@ -284,6 +284,6 @@ snprintf(char *buffer, /* O - Output buffer */ /* - * End of "$Id: snprintf.c,v 1.6 2002/03/01 19:53:30 mike Exp $". + * End of "$Id: snprintf.c,v 1.7 2002/05/16 13:44:54 mike Exp $". */ diff --git a/cups/string.c b/cups/string.c index 26e595296..16d53ba31 100644 --- a/cups/string.c +++ b/cups/string.c @@ -1,5 +1,5 @@ /* - * "$Id: string.c,v 1.7 2002/03/01 19:53:30 mike Exp $" + * "$Id: string.c,v 1.8 2002/05/16 13:44:54 mike Exp $" * * String functions for the Common UNIX Printing System (CUPS). * @@ -25,9 +25,11 @@ * * Contents: * - * strdup() - Duplicate a string. - * strcasecmp() - Do a case-insensitive comparison. - * strncasecmp() - Do a case-insensitive comparison on up to N chars. + * cups_strdup() - Duplicate a string. + * cups_strcasecmp() - Do a case-insensitive comparison. + * cups_strncasecmp() - Do a case-insensitive comparison on up to N chars. + * cups_strlcat() - Safely concatenate two strings. + * cups_strlcpy() - Safely copy two strings. */ /* @@ -38,14 +40,14 @@ /* - * 'strdup()' - Duplicate a string. + * 'cups_strdup()' - Duplicate a string. */ -# ifndef HAVE_STRDUP -char * /* O - New string pointer */ -strdup(const char *s) /* I - String to duplicate */ +#ifndef HAVE_STRDUP +char * /* O - New string pointer */ +cups_strdup(const char *s) /* I - String to duplicate */ { - char *t; /* New string pointer */ + char *t; /* New string pointer */ if (s == NULL) @@ -56,17 +58,17 @@ strdup(const char *s) /* I - String to duplicate */ return (strcpy(t, s)); } -# endif /* !HAVE_STRDUP */ +#endif /* !HAVE_STRDUP */ /* - * 'strcasecmp()' - Do a case-insensitive comparison. + * 'cups_strcasecmp()' - Do a case-insensitive comparison. */ -# ifndef HAVE_STRCASECMP +#ifndef HAVE_STRCASECMP int /* O - Result of comparison (-1, 0, or 1) */ -strcasecmp(const char *s, /* I - First string */ - const char *t) /* I - Second string */ +cups_strcasecmp(const char *s, /* I - First string */ + const char *t) /* I - Second string */ { while (*s != '\0' && *t != '\0') { @@ -86,17 +88,17 @@ strcasecmp(const char *s, /* I - First string */ else return (-1); } -# endif /* !HAVE_STRCASECMP */ +#endif /* !HAVE_STRCASECMP */ /* - * 'strncasecmp()' - Do a case-insensitive comparison on up to N chars. + * 'cups_strncasecmp()' - Do a case-insensitive comparison on up to N chars. */ -# ifndef HAVE_STRNCASECMP +#ifndef HAVE_STRNCASECMP int /* O - Result of comparison (-1, 0, or 1) */ -strncasecmp(const char *s, /* I - First string */ - const char *t, /* I - Second string */ - size_t n) /* I - Maximum number of characters to compare */ +cups_strncasecmp(const char *s, /* I - First string */ + const char *t, /* I - Second string */ + size_t n) /* I - Maximum number of characters to compare */ { while (*s != '\0' && *t != '\0' && n > 0) { @@ -119,9 +121,90 @@ strncasecmp(const char *s, /* I - First string */ else return (-1); } -# endif /* !HAVE_STRNCASECMP */ +#endif /* !HAVE_STRNCASECMP */ +#ifndef HAVE_STRLCAT /* - * End of "$Id: string.c,v 1.7 2002/03/01 19:53:30 mike Exp $". + * 'cups_strlcat()' - Safely concatenate two strings. + */ + +size_t /* O - Length of string */ +cups_strlcat(char *dst, /* O - Destination string */ + const char *src, /* I - Source string */ + size_t size) /* I - Size of destination string buffer */ +{ + size_t srclen; /* Length of source string */ + size_t dstlen; /* Length of destination string */ + + + /* + * Figure out how much room is left... + */ + + dstlen = strlen(dst); + size -= dstlen + 1; + + if (!size) + return (dstlen); /* No room, return immediately... */ + + /* + * Figure out how much room is needed... + */ + + srclen = strlen(src); + + /* + * Copy the appropriate amount... + */ + + if (srclen > size) + srclen = size; + + memcpy(dst + dstlen, src, srclen); + dst[dstlen + srclen] = '\0'; + + return (dstlen + srclen); +} +#endif /* !HAVE_STRLCAT */ + + +#ifndef HAVE_STRLCPY +/* + * 'cups_strlcpy()' - Safely copy two strings. + */ + +size_t /* O - Length of string */ +cups_strlcpy(char *dst, /* O - Destination string */ + const char *src, /* I - Source string */ + size_t size) /* I - Size of destination string buffer */ +{ + size_t srclen; /* Length of source string */ + + + /* + * Figure out how much room is needed... + */ + + size --; + + srclen = strlen(src); + + /* + * Copy the appropriate amount... + */ + + if (srclen > size) + srclen = size; + + memcpy(dst, src, srclen); + dst[srclen] = '\0'; + + return (srclen); +} +#endif /* !HAVE_STRLCPY */ + + +/* + * End of "$Id: string.c,v 1.8 2002/05/16 13:44:54 mike Exp $". */ diff --git a/cups/string.h b/cups/string.h index 9a0c9e151..db6a8e453 100644 --- a/cups/string.h +++ b/cups/string.h @@ -1,5 +1,5 @@ /* - * "$Id: string.h,v 1.12 2002/05/15 01:52:16 mike Exp $" + * "$Id: string.h,v 1.13 2002/05/16 13:44:54 mike Exp $" * * String definitions for the Common UNIX Printing System (CUPS). * @@ -70,27 +70,42 @@ extern "C" { */ # ifndef HAVE_STRDUP -extern char *strdup(const char *); +extern char *cups_strdup(const char *); +# define strdup cups_strdup # endif /* !HAVE_STRDUP */ # ifndef HAVE_STRCASECMP -extern int strcasecmp(const char *, const char *); +extern int cups_strcasecmp(const char *, const char *); +# define strcasecmp cups_strcasecmp # endif /* !HAVE_STRCASECMP */ # ifndef HAVE_STRNCASECMP -extern int strncasecmp(const char *, const char *, size_t n); +extern int cups_strncasecmp(const char *, const char *, size_t n); +# define strncasecmp cups_strncasecmp # endif /* !HAVE_STRNCASECMP */ +# ifndef HAVE_STRLCAT +extern size_t cups_strlcat(char *, const char *, size_t); +# define strlcat cups_strlcat +# endif /* !HAVE_STRLCAT */ + +# ifndef HAVE_STRLCPY +extern size_t cups_strlcpy(char *, const char *, size_t); +# define strlcpy cups_strlcpy +# endif /* !HAVE_STRLCPY */ + # ifndef HAVE_SNPRINTF -extern int snprintf(char *, size_t, const char *, ...) +extern int cups_snprintf(char *, size_t, const char *, ...) # ifdef __GNUC__ __attribute__ ((__format__ (__printf__, 3, 4))) # endif /* __GNUC__ */ ; +# define snprintf cups_snprintf # endif /* !HAVE_SNPRINTF */ # ifndef HAVE_VSNPRINTF -extern int vsnprintf(char *, size_t, const char *, va_list); +extern int cups_vsnprintf(char *, size_t, const char *, va_list); +# define vsnprintf cups_vsnprintf # endif /* !HAVE_VSNPRINTF */ @@ -105,5 +120,5 @@ extern int vsnprintf(char *, size_t, const char *, va_list); #endif /* !_CUPS_STRING_H_ */ /* - * End of "$Id: string.h,v 1.12 2002/05/15 01:52:16 mike Exp $". + * End of "$Id: string.h,v 1.13 2002/05/16 13:44:54 mike Exp $". */ diff --git a/cups/usersys.c b/cups/usersys.c index b1e80b3e4..264c7ac0f 100644 --- a/cups/usersys.c +++ b/cups/usersys.c @@ -1,5 +1,5 @@ /* - * "$Id: usersys.c,v 1.16 2002/03/01 19:53:30 mike Exp $" + * "$Id: usersys.c,v 1.17 2002/05/16 13:44:54 mike Exp $" * * User, system, and password routines for the Common UNIX Printing * System (CUPS). @@ -260,8 +260,7 @@ cupsServer(void) * Copy the server name over... */ - strncpy(cups_server, server, sizeof(cups_server) - 1); - cups_server[sizeof(cups_server) - 1] = '\0'; + strlcpy(cups_server, server, sizeof(cups_server)); } return (cups_server); @@ -290,10 +289,7 @@ void cupsSetServer(const char *server) /* I - Server name */ { if (server) - { - strncpy(cups_server, server, sizeof(cups_server) - 1); - cups_server[sizeof(cups_server) - 1] = '\0'; - } + strlcpy(cups_server, server, sizeof(cups_server)); else cups_server[0] = '\0'; } @@ -307,10 +303,7 @@ void cupsSetUser(const char *user) /* I - User name */ { if (user) - { - strncpy(cups_user, user, sizeof(cups_user) - 1); - cups_user[sizeof(cups_user) - 1] = '\0'; - } + strlcpy(cups_user, user, sizeof(cups_user)); else cups_user[0] = '\0'; } @@ -383,8 +376,7 @@ cupsUser(void) setpwent(); - strncpy(cups_user, pwd->pw_name, sizeof(cups_user) - 1); - cups_user[sizeof(cups_user) - 1] = '\0'; + strlcpy(cups_user, pwd->pw_name, sizeof(cups_user)); } /* @@ -445,5 +437,5 @@ cups_get_line(char *buf, /* I - Line buffer */ /* - * End of "$Id: usersys.c,v 1.16 2002/03/01 19:53:30 mike Exp $". + * End of "$Id: usersys.c,v 1.17 2002/05/16 13:44:54 mike Exp $". */ diff --git a/cups/util.c b/cups/util.c index 15ea48d46..6c4eca3c7 100644 --- a/cups/util.c +++ b/cups/util.c @@ -1,5 +1,5 @@ /* - * "$Id: util.c,v 1.93 2002/03/01 19:53:30 mike Exp $" + * "$Id: util.c,v 1.94 2002/05/16 13:44:55 mike Exp $" * * Printing utilities for the Common UNIX Printing System (CUPS). * @@ -340,8 +340,7 @@ cupsDoFileRequest(http_t *http, /* I - HTTP connection to server */ if (!password[0]) break; - strncpy(pwdstring, password, sizeof(pwdstring) - 1); - pwdstring[sizeof(pwdstring) - 1] = '\0'; + strlcpy(pwdstring, password, sizeof(pwdstring)); digest_tries = 0; } @@ -683,8 +682,7 @@ cupsGetDefault(void) if ((attr = ippFindAttribute(response, "printer-name", IPP_TAG_NAME)) != NULL) { - strncpy(def_printer, attr->values[0].string.text, sizeof(def_printer) - 1); - def_printer[sizeof(def_printer) - 1] = '\0'; + strlcpy(def_printer, attr->values[0].string.text, sizeof(def_printer)); ippDelete(response); return (def_printer); } @@ -1070,8 +1068,7 @@ cupsGetPPD(const char *name) /* I - Printer name */ * Found a printer! */ - strncpy(printer, resource + 10, sizeof(printer) - 1); - printer[sizeof(printer) - 1] = '\0'; + strlcpy(printer, resource + 10, sizeof(printer)); break; } } @@ -1085,8 +1082,7 @@ cupsGetPPD(const char *name) /* I - Printer name */ httpSeparate(attr->values[0].string.text, method, username, hostname, &port, resource); - strncpy(printer, strrchr(resource, '/') + 1, sizeof(printer) - 1); - printer[sizeof(printer) - 1] = '\0'; + strlcpy(printer, strrchr(resource, '/') + 1, sizeof(printer)); } ippDelete(response); @@ -1204,8 +1200,7 @@ cupsGetPPD(const char *name) /* I - Printer name */ if (!password[0]) break; - strncpy(pwdstring, password, sizeof(pwdstring) - 1); - pwdstring[sizeof(pwdstring) - 1] = '\0'; + strlcpy(pwdstring, password, sizeof(pwdstring)); digest_tries = 0; } @@ -1635,24 +1630,15 @@ cups_connect(const char *name, /* I - Destination (printer[@host]) */ } if (sscanf(name, "%1023[^@]@%1023s", printerbuf, hostbuf) == 1) - { - strncpy(hostbuf, cupsServer(), sizeof(hostbuf) - 1); - hostbuf[sizeof(hostbuf) - 1] = '\0'; - } + strlcpy(hostbuf, cupsServer(), sizeof(hostbuf)); if (hostname != NULL) - { - strncpy(hostname, hostbuf, HTTP_MAX_URI - 1); - hostname[HTTP_MAX_URI - 1] = '\0'; - } + strlcpy(hostname, hostbuf, HTTP_MAX_URI); else hostname = hostbuf; if (printer != NULL) - { - strncpy(printer, printerbuf, HTTP_MAX_URI - 1); - printer[HTTP_MAX_URI - 1] = '\0'; - } + strlcpy(printer, printerbuf, HTTP_MAX_URI); else printer = printerbuf; @@ -1745,5 +1731,5 @@ cups_local_auth(http_t *http) /* I - Connection */ /* - * End of "$Id: util.c,v 1.93 2002/03/01 19:53:30 mike Exp $". + * End of "$Id: util.c,v 1.94 2002/05/16 13:44:55 mike Exp $". */ diff --git a/filter/Dependencies b/filter/Dependencies index f646f5ea7..fcc94363b 100644 --- a/filter/Dependencies +++ b/filter/Dependencies @@ -24,21 +24,21 @@ hpgl-polygon.o: ../cups/string.h ../config.h hpgl-vector.o: hpgltops.h common.h ../cups/cups.h ../cups/ipp.h hpgl-vector.o: ../cups/http.h ../cups/md5.h ../cups/ppd.h ../cups/language.h hpgl-vector.o: ../cups/string.h ../config.h -image-bmp.o: image.h ../config.h -image-colorspace.o: image.h ../config.h -image-gif.o: image.h ../config.h -image-jpeg.o: image.h ../config.h -image-photocd.o: image.h ../config.h -image-pix.o: image.h ../config.h -image-png.o: image.h ../config.h -image-pnm.o: image.h ../config.h -image-sgi.o: image.h ../config.h image-sgi.h +image-bmp.o: image.h ../config.h raster.h +image-colorspace.o: image.h ../config.h raster.h +image-gif.o: image.h ../config.h raster.h +image-jpeg.o: image.h ../config.h raster.h +image-photocd.o: image.h ../config.h raster.h +image-pix.o: image.h ../config.h raster.h +image-png.o: image.h ../config.h raster.h +image-pnm.o: image.h ../config.h raster.h +image-sgi.o: image.h ../config.h raster.h image-sgi.h image-sgilib.o: image-sgi.h -image-sun.o: image.h ../config.h -image-tiff.o: image.h ../config.h -image-zoom.o: image.h ../config.h -image.o: image.h ../config.h ../cups/cups.h ../cups/ipp.h ../cups/http.h -image.o: ../cups/md5.h ../cups/ppd.h +image-sun.o: image.h ../config.h raster.h +image-tiff.o: image.h ../config.h raster.h +image-zoom.o: image.h ../config.h raster.h +image.o: image.h ../config.h raster.h ../cups/cups.h ../cups/ipp.h +image.o: ../cups/http.h ../cups/md5.h ../cups/ppd.h raster.o: raster.h form-main.o: form.h common.h ../cups/cups.h ../cups/ipp.h ../cups/http.h form-main.o: ../cups/md5.h ../cups/ppd.h ../cups/language.h ../cups/string.h @@ -51,7 +51,7 @@ form-tree.o: ../cups/md5.h ../cups/ppd.h ../cups/language.h ../cups/string.h form-tree.o: ../config.h imagetops.o: common.h ../cups/cups.h ../cups/ipp.h ../cups/http.h imagetops.o: ../cups/md5.h ../cups/ppd.h ../cups/language.h ../cups/string.h -imagetops.o: ../config.h image.h +imagetops.o: ../config.h image.h raster.h imagetoraster.o: common.h ../cups/cups.h ../cups/ipp.h ../cups/http.h imagetoraster.o: ../cups/md5.h ../cups/ppd.h ../cups/language.h imagetoraster.o: ../cups/string.h ../config.h image.h raster.h diff --git a/filter/imagetops.c b/filter/imagetops.c index f82f86abe..e02a89201 100644 --- a/filter/imagetops.c +++ b/filter/imagetops.c @@ -1,5 +1,5 @@ /* - * "$Id: imagetops.c,v 1.45 2002/04/19 16:17:28 mike Exp $" + * "$Id: imagetops.c,v 1.46 2002/05/16 13:44:55 mike Exp $" * * Image file to PostScript filter for the Common UNIX Printing System (CUPS). * @@ -152,10 +152,7 @@ main(int argc, /* I - Number of command-line arguments */ close(fd); } else - { - strncpy(filename, argv[6], sizeof(filename) - 1); - filename[sizeof(filename) - 1] = '\0'; - } + strlcpy(filename, argv[6], sizeof(filename)); /* * Process command-line options and write the prolog... @@ -885,5 +882,5 @@ ps_ascii85(ib_t *data, /* I - Data to print */ /* - * End of "$Id: imagetops.c,v 1.45 2002/04/19 16:17:28 mike Exp $". + * End of "$Id: imagetops.c,v 1.46 2002/05/16 13:44:55 mike Exp $". */ diff --git a/filter/imagetoraster.c b/filter/imagetoraster.c index 7e63e7a0a..9984f027c 100644 --- a/filter/imagetoraster.c +++ b/filter/imagetoraster.c @@ -1,5 +1,5 @@ /* - * "$Id: imagetoraster.c,v 1.64 2002/04/29 15:56:59 mike Exp $" + * "$Id: imagetoraster.c,v 1.65 2002/05/16 13:44:56 mike Exp $" * * Image file to raster filter for the Common UNIX Printing System (CUPS). * @@ -369,10 +369,7 @@ main(int argc, /* I - Number of command-line arguments */ close(fd); } else - { - strncpy(filename, argv[6], sizeof(filename) - 1); - filename[sizeof(filename) - 1] = '\0'; - } + strlcpy(filename, argv[6], sizeof(filename)); /* * Process command-line options and write the prolog... @@ -1528,13 +1525,13 @@ exec_code(cups_page_header_t *header, /* I - Page header */ strcmp(name, "MediaPosition") == 0) header->MediaPosition = atoi(value); else if (strcmp(name, "MediaClass") == 0) - strncpy(header->MediaClass, value, sizeof(header->MediaClass) - 1); + strlcpy(header->MediaClass, value, sizeof(header->MediaClass)); else if (strcmp(name, "MediaColor") == 0) - strncpy(header->MediaColor, value, sizeof(header->MediaColor) - 1); + strlcpy(header->MediaColor, value, sizeof(header->MediaColor)); else if (strcmp(name, "MediaType") == 0) - strncpy(header->MediaType, value, sizeof(header->MediaType) - 1); + strlcpy(header->MediaType, value, sizeof(header->MediaType)); else if (strcmp(name, "OutputType") == 0) - strncpy(header->OutputType, value, sizeof(header->OutputType) - 1); + strlcpy(header->OutputType, value, sizeof(header->OutputType)); } } @@ -4506,5 +4503,5 @@ make_lut(ib_t *lut, /* I - Lookup table */ /* - * End of "$Id: imagetoraster.c,v 1.64 2002/04/29 15:56:59 mike Exp $". + * End of "$Id: imagetoraster.c,v 1.65 2002/05/16 13:44:56 mike Exp $". */ diff --git a/pstoraster/gdevcups.c b/pstoraster/gdevcups.c index 69569a2b2..07af19f1a 100644 --- a/pstoraster/gdevcups.c +++ b/pstoraster/gdevcups.c @@ -1,5 +1,5 @@ /* - * "$Id: gdevcups.c,v 1.51 2002/04/23 17:28:59 mike Exp $" + * "$Id: gdevcups.c,v 1.52 2002/05/16 13:44:57 mike Exp $" * * GNU Ghostscript raster output driver for the Common UNIX Printing * System (CUPS). @@ -1808,9 +1808,7 @@ cups_put_params(gx_device *pdev, /* I - Device info */ } \ else if (code == 0) \ { \ - strncpy(cups->header.name, (const char *)stringval.data, \ - stringval.size); \ - cups->header.name[stringval.size] = '\0'; \ + strlcpy(cups->header.name, (const char *)stringval.data, 64); \ } #define intoption(name, sname, type) \ @@ -3427,5 +3425,5 @@ cups_print_planar(gx_device_printer *pdev, /* I - Printer device */ /* - * End of "$Id: gdevcups.c,v 1.51 2002/04/23 17:28:59 mike Exp $". + * End of "$Id: gdevcups.c,v 1.52 2002/05/16 13:44:57 mike Exp $". */ diff --git a/scheduler/Dependencies b/scheduler/Dependencies index d98c592e3..7e688d60f 100644 --- a/scheduler/Dependencies +++ b/scheduler/Dependencies @@ -1,95 +1,95 @@ # DO NOT DELETE auth.o: cupsd.h ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h -auth.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/http.h -auth.o: ../cups/ipp.h ../cups/language.h ../cups/debug.h cert.h client.h +auth.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/ipp.h +auth.o: ../cups/http.h ../cups/language.h ../cups/debug.h cert.h client.h auth.o: auth.h printers.h classes.h job.h conf.h banners.h dirsvc.h network.h auth.o: ../cups/md5.h banners.o: cupsd.h ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h -banners.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/http.h -banners.o: ../cups/ipp.h ../cups/language.h ../cups/debug.h cert.h client.h +banners.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/ipp.h +banners.o: ../cups/http.h ../cups/language.h ../cups/debug.h cert.h client.h banners.o: auth.h printers.h classes.h job.h conf.h banners.h dirsvc.h banners.o: network.h cert.o: cupsd.h ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h -cert.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/http.h -cert.o: ../cups/ipp.h ../cups/language.h ../cups/debug.h cert.h client.h +cert.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/ipp.h +cert.o: ../cups/http.h ../cups/language.h ../cups/debug.h cert.h client.h cert.o: auth.h printers.h classes.h job.h conf.h banners.h dirsvc.h network.h classes.o: cupsd.h ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h -classes.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/http.h -classes.o: ../cups/ipp.h ../cups/language.h ../cups/debug.h cert.h client.h +classes.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/ipp.h +classes.o: ../cups/http.h ../cups/language.h ../cups/debug.h cert.h client.h classes.o: auth.h printers.h classes.h job.h conf.h banners.h dirsvc.h classes.o: network.h client.o: cupsd.h ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h -client.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/http.h -client.o: ../cups/ipp.h ../cups/language.h ../cups/debug.h cert.h client.h +client.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/ipp.h +client.o: ../cups/http.h ../cups/language.h ../cups/debug.h cert.h client.h client.o: auth.h printers.h classes.h job.h conf.h banners.h dirsvc.h client.o: network.h conf.o: cupsd.h ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h -conf.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/http.h -conf.o: ../cups/ipp.h ../cups/language.h ../cups/debug.h cert.h client.h +conf.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/ipp.h +conf.o: ../cups/http.h ../cups/language.h ../cups/debug.h cert.h client.h conf.o: auth.h printers.h classes.h job.h conf.h banners.h dirsvc.h network.h devices.o: cupsd.h ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h -devices.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/http.h -devices.o: ../cups/ipp.h ../cups/language.h ../cups/debug.h cert.h client.h +devices.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/ipp.h +devices.o: ../cups/http.h ../cups/language.h ../cups/debug.h cert.h client.h devices.o: auth.h printers.h classes.h job.h conf.h banners.h dirsvc.h devices.o: network.h dirsvc.o: cupsd.h ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h -dirsvc.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/http.h -dirsvc.o: ../cups/ipp.h ../cups/language.h ../cups/debug.h cert.h client.h +dirsvc.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/ipp.h +dirsvc.o: ../cups/http.h ../cups/language.h ../cups/debug.h cert.h client.h dirsvc.o: auth.h printers.h classes.h job.h conf.h banners.h dirsvc.h dirsvc.o: network.h main.o: cupsd.h ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h -main.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/http.h -main.o: ../cups/ipp.h ../cups/language.h ../cups/debug.h cert.h client.h +main.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/ipp.h +main.o: ../cups/http.h ../cups/language.h ../cups/debug.h cert.h client.h main.o: auth.h printers.h classes.h job.h conf.h banners.h dirsvc.h network.h ipp.o: cupsd.h ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h -ipp.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/http.h -ipp.o: ../cups/ipp.h ../cups/language.h ../cups/debug.h cert.h client.h +ipp.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/ipp.h +ipp.o: ../cups/http.h ../cups/language.h ../cups/debug.h cert.h client.h ipp.o: auth.h printers.h classes.h job.h conf.h banners.h dirsvc.h network.h listen.o: cupsd.h ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h -listen.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/http.h -listen.o: ../cups/ipp.h ../cups/language.h ../cups/debug.h cert.h client.h +listen.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/ipp.h +listen.o: ../cups/http.h ../cups/language.h ../cups/debug.h cert.h client.h listen.o: auth.h printers.h classes.h job.h conf.h banners.h dirsvc.h listen.o: network.h job.o: cupsd.h ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h -job.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/http.h -job.o: ../cups/ipp.h ../cups/language.h ../cups/debug.h cert.h client.h +job.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/ipp.h +job.o: ../cups/http.h ../cups/language.h ../cups/debug.h cert.h client.h job.o: auth.h printers.h classes.h job.h conf.h banners.h dirsvc.h network.h log.o: cupsd.h ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h -log.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/http.h -log.o: ../cups/ipp.h ../cups/language.h ../cups/debug.h cert.h client.h +log.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/ipp.h +log.o: ../cups/http.h ../cups/language.h ../cups/debug.h cert.h client.h log.o: auth.h printers.h classes.h job.h conf.h banners.h dirsvc.h network.h network.o: cupsd.h ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h -network.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/http.h -network.o: ../cups/ipp.h ../cups/language.h ../cups/debug.h cert.h client.h +network.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/ipp.h +network.o: ../cups/http.h ../cups/language.h ../cups/debug.h cert.h client.h network.o: auth.h printers.h classes.h job.h conf.h banners.h dirsvc.h network.o: network.h ppds.o: cupsd.h ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h -ppds.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/http.h -ppds.o: ../cups/ipp.h ../cups/language.h ../cups/debug.h cert.h client.h +ppds.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/ipp.h +ppds.o: ../cups/http.h ../cups/language.h ../cups/debug.h cert.h client.h ppds.o: auth.h printers.h classes.h job.h conf.h banners.h dirsvc.h network.h printers.o: cupsd.h ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h -printers.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/http.h -printers.o: ../cups/ipp.h ../cups/language.h ../cups/debug.h cert.h client.h +printers.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/ipp.h +printers.o: ../cups/http.h ../cups/language.h ../cups/debug.h cert.h client.h printers.o: auth.h printers.h classes.h job.h conf.h banners.h dirsvc.h printers.o: network.h quotas.o: cupsd.h ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h -quotas.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/http.h -quotas.o: ../cups/ipp.h ../cups/language.h ../cups/debug.h cert.h client.h +quotas.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/ipp.h +quotas.o: ../cups/http.h ../cups/language.h ../cups/debug.h cert.h client.h quotas.o: auth.h printers.h classes.h job.h conf.h banners.h dirsvc.h quotas.o: network.h server.o: cupsd.h ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h -server.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/http.h -server.o: ../cups/ipp.h ../cups/language.h ../cups/debug.h cert.h client.h +server.o: ../cups/ppd.h ../cups/string.h ../config.h mime.h ../cups/ipp.h +server.o: ../cups/http.h ../cups/language.h ../cups/debug.h cert.h client.h server.o: auth.h printers.h classes.h job.h conf.h banners.h dirsvc.h server.o: network.h -filter.o: ../cups/string.h ../config.h mime.h -mime.o: ../cups/string.h ../config.h mime.h -type.o: ../cups/string.h ../config.h mime.h ../cups/debug.h +filter.o: ../cups/string.h ../config.h mime.h ../cups/ipp.h +mime.o: ../cups/string.h ../config.h mime.h ../cups/ipp.h +type.o: ../cups/string.h ../config.h mime.h ../cups/ipp.h ../cups/debug.h cups-lpd.o: ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h cups-lpd.o: ../cups/ppd.h ../cups/string.h ../config.h ../cups/language.h cups-polld.o: ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h cups-polld.o: ../cups/ppd.h ../cups/language.h ../cups/string.h ../config.h -testmime.o: mime.h +testmime.o: ../cups/string.h ../config.h mime.h ../cups/ipp.h testspeed.o: ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h testspeed.o: ../cups/ppd.h ../cups/language.h ../cups/debug.h diff --git a/scheduler/auth.c b/scheduler/auth.c index 280414f8c..98876505c 100644 --- a/scheduler/auth.c +++ b/scheduler/auth.c @@ -1,5 +1,5 @@ /* - * "$Id: auth.c,v 1.57 2002/03/27 19:59:49 mike Exp $" + * "$Id: auth.c,v 1.58 2002/05/16 13:44:58 mike Exp $" * * Authorization routines for the Common UNIX Printing System (CUPS). * @@ -130,7 +130,7 @@ AddLocation(const char *location) /* I - Location path */ */ memset(temp, 0, sizeof(location_t)); - strncpy(temp->location, location, sizeof(temp->location) - 1); + strlcpy(temp->location, location, sizeof(temp->location)); temp->length = strlen(temp->location); LogMessage(L_DEBUG, "AddLocation: added location \'%s\'", location); @@ -211,8 +211,7 @@ AllowHost(location_t *loc, /* I - Location to add to */ * Allow *interface*... */ - strncpy(ifname, name + 4, sizeof(ifname) - 1); - ifname[sizeof(ifname) - 1] = '\0'; + strlcpy(ifname, name + 4, sizeof(ifname)); ifptr = ifname + strlen(ifname); @@ -587,8 +586,7 @@ DenyHost(location_t *loc, /* I - Location to add to */ * Deny *interface*... */ - strncpy(ifname, name + 4, sizeof(ifname) - 1); - ifname[sizeof(ifname) - 1] = '\0'; + strlcpy(ifname, name + 4, sizeof(ifname)); ifptr = ifname + strlen(ifname); @@ -683,8 +681,7 @@ FindBest(const char *path, /* I - Resource path */ * URIs... */ - strncpy(uri, path, sizeof(uri) - 1); - uri[sizeof(uri) - 1] = '\0'; + strlcpy(uri, path, sizeof(uri)); if (strncmp(uri, "/printers/", 10) == 0 || strncmp(uri, "/classes/", 9) == 0) @@ -1624,5 +1621,5 @@ to64(char *s, /* O - Output string */ /* - * End of "$Id: auth.c,v 1.57 2002/03/27 19:59:49 mike Exp $". + * End of "$Id: auth.c,v 1.58 2002/05/16 13:44:58 mike Exp $". */ diff --git a/scheduler/banners.c b/scheduler/banners.c index 9548eec9a..90d7e67a3 100644 --- a/scheduler/banners.c +++ b/scheduler/banners.c @@ -1,5 +1,5 @@ /* - * "$Id: banners.c,v 1.7 2002/01/02 17:59:13 mike Exp $" + * "$Id: banners.c,v 1.8 2002/05/16 13:44:58 mike Exp $" * * Banner routines for the Common UNIX Printing System (CUPS). * @@ -90,7 +90,7 @@ AddBanner(const char *name, /* I - Name of banner */ NumBanners ++; memset(temp, 0, sizeof(banner_t)); - strncpy(temp->name, name, sizeof(temp->name) - 1); + strlcpy(temp->name, name, sizeof(temp->name)); temp->filetype = filetype; } @@ -105,8 +105,7 @@ FindBanner(const char *name) /* I - Name of banner */ banner_t key; /* Search key */ - strncpy(key.name, name, sizeof(key.name) - 1); - key.name[sizeof(key.name) - 1] = '\0'; + strlcpy(key.name, name, sizeof(key.name)); return ((banner_t *)bsearch(&key, Banners, NumBanners, sizeof(banner_t), (int (*)(const void *, const void *))compare)); @@ -212,5 +211,5 @@ compare(const banner_t *b0, /* I - First banner */ /* - * End of "$Id: banners.c,v 1.7 2002/01/02 17:59:13 mike Exp $". + * End of "$Id: banners.c,v 1.8 2002/05/16 13:44:58 mike Exp $". */ diff --git a/scheduler/cert.c b/scheduler/cert.c index 43424f446..aea440b35 100644 --- a/scheduler/cert.c +++ b/scheduler/cert.c @@ -1,5 +1,5 @@ /* - * "$Id: cert.c,v 1.10 2002/01/02 17:59:13 mike Exp $" + * "$Id: cert.c,v 1.11 2002/05/16 13:44:58 mike Exp $" * * Authentication certificate routines for the Common UNIX * Printing System (CUPS). @@ -69,7 +69,7 @@ AddCert(int pid, /* I - Process ID */ */ cert->pid = pid; - strncpy(cert->username, username, sizeof(cert->username) - 1); + strlcpy(cert->username, username, sizeof(cert->username)); for (i = 0; i < 32; i ++) cert->certificate[i] = hex[random() & 15]; @@ -271,5 +271,5 @@ InitCerts(void) /* - * End of "$Id: cert.c,v 1.10 2002/01/02 17:59:13 mike Exp $". + * End of "$Id: cert.c,v 1.11 2002/05/16 13:44:58 mike Exp $". */ diff --git a/scheduler/classes.c b/scheduler/classes.c index f0c27efd6..c1150820b 100644 --- a/scheduler/classes.c +++ b/scheduler/classes.c @@ -1,5 +1,5 @@ /* - * "$Id: classes.c,v 1.41 2002/01/02 17:59:14 mike Exp $" + * "$Id: classes.c,v 1.42 2002/05/16 13:44:58 mike Exp $" * * Printer class routines for the Common UNIX Printing System (CUPS). * @@ -450,9 +450,9 @@ LoadAllClasses(void) } else if (strcmp(name, "Info") == 0) - strncpy(p->info, value, sizeof(p->info) - 1); + strlcpy(p->info, value, sizeof(p->info)); else if (strcmp(name, "Location") == 0) - strncpy(p->location, value, sizeof(p->location) - 1); + strlcpy(p->location, value, sizeof(p->location)); else if (strcmp(name, "Printer") == 0) { if ((temp = FindPrinter(value)) == NULL) @@ -501,7 +501,7 @@ LoadAllClasses(void) while (isspace(*value)) value ++; - strncpy(p->state_message, value, sizeof(p->state_message) - 1); + strlcpy(p->state_message, value, sizeof(p->state_message)); } else if (strcmp(name, "Accepting") == 0) { @@ -525,7 +525,7 @@ LoadAllClasses(void) if (*valueptr) *valueptr++ = '\0'; - strncpy(p->job_sheets[0], value, sizeof(p->job_sheets[0]) - 1); + strlcpy(p->job_sheets[0], value, sizeof(p->job_sheets[0])); while (isspace(*valueptr)) valueptr ++; @@ -537,7 +537,7 @@ LoadAllClasses(void) if (*valueptr) *valueptr++ = '\0'; - strncpy(p->job_sheets[1], value, sizeof(p->job_sheets[1]) - 1); + strlcpy(p->job_sheets[1], value, sizeof(p->job_sheets[1])); } } else if (strcmp(name, "AllowUser") == 0) @@ -691,5 +691,5 @@ SaveAllClasses(void) /* - * End of "$Id: classes.c,v 1.41 2002/01/02 17:59:14 mike Exp $". + * End of "$Id: classes.c,v 1.42 2002/05/16 13:44:58 mike Exp $". */ diff --git a/scheduler/client.c b/scheduler/client.c index 3be1f2dfd..229f6b1da 100644 --- a/scheduler/client.c +++ b/scheduler/client.c @@ -1,5 +1,5 @@ /* - * "$Id: client.c,v 1.111 2002/05/15 01:52:17 mike Exp $" + * "$Id: client.c,v 1.112 2002/05/16 13:44:59 mike Exp $" * * Client routines for the Common UNIX Printing System (CUPS) scheduler. * @@ -140,7 +140,7 @@ AcceptClient(listener_t *lis) /* I - Listener socket */ * Map accesses from the same host to the server name. */ - strncpy(con->http.hostname, ServerName, sizeof(con->http.hostname) - 1); + strlcpy(con->http.hostname, ServerName, sizeof(con->http.hostname)); } else if (host == NULL) { @@ -165,7 +165,7 @@ AcceptClient(listener_t *lis) /* I - Listener socket */ } } else - strncpy(con->http.hostname, host->h_name, sizeof(con->http.hostname) - 1); + strlcpy(con->http.hostname, host->h_name, sizeof(con->http.hostname)); if (HostNameLookups == 2) { @@ -1949,11 +1949,8 @@ decode_auth(client_t *con) /* I - Client to decode to */ *s++ = '\0'; - strncpy(con->username, value, sizeof(con->username) - 1); - con->username[sizeof(con->username) - 1] = '\0'; - - strncpy(con->password, s, sizeof(con->password) - 1); - con->password[sizeof(con->password) - 1] = '\0'; + strlcpy(con->username, value, sizeof(con->username)); + strlcpy(con->password, s, sizeof(con->password)); } else if (strncmp(s, "Local", 5) == 0) { @@ -1962,10 +1959,7 @@ decode_auth(client_t *con) /* I - Client to decode to */ s ++; if ((username = FindCert(s)) != NULL) - { - strncpy(con->username, username, sizeof(con->username) - 1); - con->username[sizeof(con->username) - 1] = '\0'; - } + strlcpy(con->username, username, sizeof(con->username)); } else if (strncmp(s, "Digest", 5) == 0) { @@ -1975,17 +1969,11 @@ decode_auth(client_t *con) /* I - Client to decode to */ if (httpGetSubField(&(con->http), HTTP_FIELD_AUTHORIZATION, "username", value)) - { - strncpy(con->username, value, sizeof(con->username) - 1); - con->username[sizeof(con->username) - 1] = '\0'; - } + strlcpy(con->username, value, sizeof(con->username)); if (httpGetSubField(&(con->http), HTTP_FIELD_AUTHORIZATION, "response", value)) - { - strncpy(con->password, value, sizeof(con->password) - 1); - con->password[sizeof(con->password) - 1] = '\0'; - } + strlcpy(con->password, value, sizeof(con->password)); } LogMessage(L_DEBUG2, "decode_auth() %d username=\"%s\"", @@ -2050,11 +2038,9 @@ get_file(client_t *con, /* I - Client connection */ if (!status && S_ISDIR(filestats->st_mode)) { if (filename[strlen(filename) - 1] == '/') - strncat(filename, "index.html", sizeof(filename)); + strlcat(filename, "index.html", sizeof(filename)); else - strncat(filename, "/index.html", sizeof(filename)); - - filename[sizeof(filename) - 1] = '\0'; + strlcat(filename, "/index.html", sizeof(filename)); status = stat(filename, filestats); } @@ -2263,8 +2249,7 @@ pipe_command(client_t *con, /* I - Client connection */ * Copy the command string... */ - strncpy(argbuf, options, sizeof(argbuf) - 1); - argbuf[sizeof(argbuf) - 1] = '\0'; + strlcpy(argbuf, options, sizeof(argbuf)); /* * Parse the string; arguments can be separated by + and are terminated @@ -2510,5 +2495,5 @@ pipe_command(client_t *con, /* I - Client connection */ /* - * End of "$Id: client.c,v 1.111 2002/05/15 01:52:17 mike Exp $". + * End of "$Id: client.c,v 1.112 2002/05/16 13:44:59 mike Exp $". */ diff --git a/scheduler/conf.c b/scheduler/conf.c index 57dd0224e..ffd0f73a2 100644 --- a/scheduler/conf.c +++ b/scheduler/conf.c @@ -1,5 +1,5 @@ /* - * "$Id: conf.c,v 1.102 2002/05/15 01:52:17 mike Exp $" + * "$Id: conf.c,v 1.103 2002/05/16 13:44:59 mike Exp $" * * Configuration routines for the Common UNIX Printing System (CUPS). * @@ -246,8 +246,7 @@ ReadConfiguration(void) else if (strcmp(language, "C") == 0 || strcmp(language, "POSIX") == 0) language = "en"; - strncpy(DefaultLanguage, language, sizeof(DefaultLanguage) - 1); - DefaultLanguage[sizeof(DefaultLanguage) - 1] = '\0'; + strlcpy(DefaultLanguage, language, sizeof(DefaultLanguage)); strcpy(DefaultCharset, DEFAULT_CHARSET); @@ -256,10 +255,7 @@ ReadConfiguration(void) if (getenv("TMPDIR") == NULL) strcpy(TempDir, CUPS_REQUESTS "/tmp"); else - { - strncpy(TempDir, getenv("TMPDIR"), sizeof(TempDir) - 1); - TempDir[sizeof(TempDir) - 1] = '\0'; - } + strlcpy(TempDir, getenv("TMPDIR"), sizeof(TempDir)); /* * Find the default system group: "sys", "system", or "root"... @@ -396,30 +392,26 @@ ReadConfiguration(void) if (DocumentRoot[0] != '/') { snprintf(directory, sizeof(directory), "%s/%s", ServerRoot, DocumentRoot); - strncpy(DocumentRoot, directory, sizeof(DocumentRoot) - 1); - DocumentRoot[sizeof(DocumentRoot) - 1] = '\0'; + strlcpy(DocumentRoot, directory, sizeof(DocumentRoot)); } if (RequestRoot[0] != '/') { snprintf(directory, sizeof(directory), "%s/%s", ServerRoot, RequestRoot); - strncpy(RequestRoot, directory, sizeof(RequestRoot) - 1); - RequestRoot[sizeof(RequestRoot) - 1] = '\0'; + strlcpy(RequestRoot, directory, sizeof(RequestRoot)); } if (ServerBin[0] != '/') { snprintf(directory, sizeof(directory), "%s/%s", ServerRoot, ServerBin); - strncpy(ServerBin, directory, sizeof(ServerBin) - 1); - ServerBin[sizeof(ServerBin) - 1] = '\0'; + strlcpy(ServerBin, directory, sizeof(ServerBin)); } #ifdef HAVE_LIBSSL if (ServerCertificate[0] != '/') { snprintf(directory, sizeof(directory), "%s/%s", ServerRoot, ServerCertificate); - strncpy(ServerCertificate, directory, sizeof(ServerCertificate) - 1); - ServerCertificate[sizeof(ServerCertificate) - 1] = '\0'; + strlcpy(ServerCertificate, directory, sizeof(ServerCertificate)); } chown(ServerCertificate, User, Group); @@ -428,8 +420,7 @@ ReadConfiguration(void) if (ServerKey[0] != '/') { snprintf(directory, sizeof(directory), "%s/%s", ServerRoot, ServerKey); - strncpy(ServerKey, directory, sizeof(ServerKey) - 1); - ServerKey[sizeof(ServerKey) - 1] = '\0'; + strlcpy(ServerKey, directory, sizeof(ServerKey)); } chown(ServerKey, User, Group); @@ -679,10 +670,7 @@ read_configuration(FILE *fp) /* I - File to read from */ */ if (value[0] == '/') - { - strncpy(incname, value, sizeof(incname) - 1); - incname[sizeof(incname) - 1] = '\0'; - } + strlcpy(incname, value, sizeof(incname)); else snprintf(incname, sizeof(incname), "%s/%s", ServerRoot, value); @@ -794,8 +782,8 @@ read_configuration(FILE *fp) /* I - File to read from */ * Send browse data to the named interface... */ - strncpy(Browsers[NumBrowsers].iface, value + 4, - sizeof(Browsers[0].iface) - 1); + strlcpy(Browsers[NumBrowsers].iface, value + 4, + sizeof(Browsers[0].iface)); nameptr = Browsers[NumBrowsers].iface + strlen(Browsers[NumBrowsers].iface) - 1; @@ -1246,8 +1234,7 @@ read_configuration(FILE *fp) /* I - File to read from */ if (*valueptr) *valueptr++ = '\0'; - strncpy(SystemGroups[i], value, sizeof(SystemGroups[0])); - SystemGroups[i][sizeof(SystemGroups[0]) - 1] = '\0'; + strlcpy(SystemGroups[i], value, sizeof(SystemGroups[0])); while (*value == ',' || isspace(*value)) value ++; @@ -1381,8 +1368,7 @@ read_configuration(FILE *fp) /* I - File to read from */ break; case VAR_STRING : - strncpy((char *)var->ptr, value, var->size - 1); - value[var->size - 1] = '\0'; + strlcpy((char *)var->ptr, value, var->size); break; } } @@ -1844,8 +1830,7 @@ get_address(char *value, /* I - Value string */ * Hostname is a port number... */ - strncpy(portname, hostname, sizeof(portname) - 1); - portname[sizeof(portname) - 1] = '\0'; + strlcpy(portname, hostname, sizeof(portname)); hostname[0] = '\0'; } else @@ -1897,5 +1882,5 @@ get_address(char *value, /* I - Value string */ /* - * End of "$Id: conf.c,v 1.102 2002/05/15 01:52:17 mike Exp $". + * End of "$Id: conf.c,v 1.103 2002/05/16 13:44:59 mike Exp $". */ diff --git a/scheduler/cups-lpd.c b/scheduler/cups-lpd.c index f39ef137c..d03b3756e 100644 --- a/scheduler/cups-lpd.c +++ b/scheduler/cups-lpd.c @@ -1,5 +1,5 @@ /* - * "$Id: cups-lpd.c,v 1.32 2002/04/29 17:25:26 mike Exp $" + * "$Id: cups-lpd.c,v 1.33 2002/05/16 13:44:59 mike Exp $" * * Line Printer Daemon interface for the Common UNIX Printing System (CUPS). * @@ -139,10 +139,7 @@ main(int argc, /* I - Number of command-line arguments */ hostent = gethostbyaddr((void *)&(hostaddr.sin_addr), hostlen, AF_INET); if (hostent) - { - strncpy(hostname, hostent->h_name, sizeof(hostname) - 1); - hostname[sizeof(hostname) - 1] = '\0'; - } + strlcpy(hostname, hostent->h_name, sizeof(hostname)); else { snprintf(hostname, sizeof(hostname), "%d.%d.%d.%d", @@ -441,8 +438,7 @@ recv_print_job(const char *dest, /* I - Destination */ control[0] = '\0'; - strncpy(queue, dest, sizeof(queue) - 1); - queue[sizeof(queue) - 1] = '\0'; + strlcpy(queue, dest, sizeof(queue)); if ((instance = strrchr(queue, '/')) != NULL) *instance++ = '\0'; @@ -548,8 +544,7 @@ recv_print_job(const char *dest, /* I - Destination */ break; } - strncpy(data[num_data], name, sizeof(data[0]) - 1); - data[num_data][sizeof(data[0]) - 1] = '\0'; + strlcpy(data[num_data], name, sizeof(data[0])); if ((fd = cupsTempFd(temp[num_data], sizeof(temp[0]))) < 0) { @@ -654,16 +649,13 @@ recv_print_job(const char *dest, /* I - Destination */ switch (line[0]) { case 'J' : /* Job name */ - strncpy(title, line + 1, sizeof(title) - 1); - title[sizeof(title) - 1] = '\0'; + strlcpy(title, line + 1, sizeof(title)); break; case 'N' : /* Document name */ - strncpy(docname, line + 1, sizeof(docname) - 1); - docname[sizeof(docname) - 1] = '\0'; + strlcpy(docname, line + 1, sizeof(docname)); break; case 'P' : /* User identification */ - strncpy(user, line + 1, sizeof(user) - 1); - user[sizeof(user) - 1] = '\0'; + strlcpy(user, line + 1, sizeof(user)); break; case 'L' : /* Print banner page */ banner = 1; @@ -962,8 +954,7 @@ send_state(const char *dest, /* I - Destination */ * Remove instance from destination, if any... */ - strncpy(queue, dest, sizeof(queue) - 1); - queue[sizeof(queue) - 1] = '\0'; + strlcpy(queue, dest, sizeof(queue)); if ((instance = strrchr(queue, '/')) != NULL) *instance++ = '\0'; @@ -1212,10 +1203,7 @@ send_state(const char *dest, /* I - Destination */ snprintf(namestr, sizeof(namestr), "%d copies of %s", jobcopies, jobname); else - { - strncpy(namestr, jobname, sizeof(namestr) - 1); - namestr[sizeof(namestr) - 1] = '\0'; - } + strlcpy(namestr, jobname, sizeof(namestr)); printf("%s: %-34.34s[job %d localhost]\n", jobuser, rankstr, jobid); printf(" %-40.40s%d bytes\n", namestr, jobsize); @@ -1301,5 +1289,5 @@ smart_gets(char *s, /* I - Pointer to line buffer */ /* - * End of "$Id: cups-lpd.c,v 1.32 2002/04/29 17:25:26 mike Exp $". + * End of "$Id: cups-lpd.c,v 1.33 2002/05/16 13:44:59 mike Exp $". */ diff --git a/scheduler/devices.c b/scheduler/devices.c index cde824212..07d47ce66 100644 --- a/scheduler/devices.c +++ b/scheduler/devices.c @@ -1,5 +1,5 @@ /* - * "$Id: devices.c,v 1.16 2002/01/02 17:59:15 mike Exp $" + * "$Id: devices.c,v 1.17 2002/05/16 13:45:00 mike Exp $" * * Device scanning routines for the Common UNIX Printing System (CUPS). * @@ -225,11 +225,11 @@ LoadDevices(const char *d) /* I - Directory to scan */ num_devs ++; memset(dev, 0, sizeof(dev_info_t)); - strncpy(dev->device_class, dclass, sizeof(dev->device_class) - 1); - strncpy(dev->device_info, info, sizeof(dev->device_info) - 1); - strncpy(dev->device_make_and_model, make_model, - sizeof(dev->device_make_and_model) - 1); - strncpy(dev->device_uri, uri, sizeof(dev->device_uri) - 1); + strlcpy(dev->device_class, dclass, sizeof(dev->device_class)); + strlcpy(dev->device_info, info, sizeof(dev->device_info)); + strlcpy(dev->device_make_and_model, make_model, + sizeof(dev->device_make_and_model)); + strlcpy(dev->device_uri, uri, sizeof(dev->device_uri)); LogMessage(L_DEBUG, "LoadDevices: Added device \"%s\"...", uri); count ++; @@ -282,7 +282,7 @@ LoadDevices(const char *d) /* I - Directory to scan */ snprintf(dev->device_info, sizeof(dev->device_info), "Unknown Network Device (%s)", dent->d_name); strcpy(dev->device_make_and_model, "Unknown"); - strncpy(dev->device_uri, dent->d_name, sizeof(dev->device_uri) - 1); + strlcpy(dev->device_uri, dent->d_name, sizeof(dev->device_uri)); LogMessage(L_DEBUG, "LoadDevices: Compatibility device \"%s\"...", dent->d_name); @@ -478,5 +478,5 @@ sigalrm_handler(int sig) /* I - Signal number */ /* - * End of "$Id: devices.c,v 1.16 2002/01/02 17:59:15 mike Exp $". + * End of "$Id: devices.c,v 1.17 2002/05/16 13:45:00 mike Exp $". */ diff --git a/scheduler/dirsvc.c b/scheduler/dirsvc.c index 8c5395701..78dd5cfcb 100644 --- a/scheduler/dirsvc.c +++ b/scheduler/dirsvc.c @@ -1,5 +1,5 @@ /* - * "$Id: dirsvc.c,v 1.94 2002/05/12 11:49:29 mike Exp $" + * "$Id: dirsvc.c,v 1.95 2002/05/16 13:45:00 mike Exp $" * * Directory services routines for the Common UNIX Printing System (CUPS). * @@ -139,9 +139,8 @@ ProcessBrowseData(const char *uri, /* I - URI of printer/class */ if (p->type & CUPS_PRINTER_REMOTE) { - /* No "p->var[sizeof(p->var) - 1] = '\0';" because p is zeroed */ - strncat(p->name, "@", sizeof(p->name) - 1); - strncat(p->name, p->hostname, sizeof(p->name) - 1); + strlcat(p->name, "@", sizeof(p->name)); + strlcat(p->name, p->hostname, sizeof(p->name)); SetPrinterAttrs(p); SortPrinters(); } @@ -150,25 +149,20 @@ ProcessBrowseData(const char *uri, /* I - URI of printer/class */ } else if (!p->hostname[0]) { - /* No "p->var[sizeof(p->var) - 1] = '\0';" because p is zeroed */ - strncpy(p->hostname, host, sizeof(p->hostname) - 1); - strncpy(p->uri, uri, sizeof(p->uri) - 1); - strncpy(p->device_uri, uri, sizeof(p->device_uri) - 1); + strlcpy(p->hostname, host, sizeof(p->hostname)); + strlcpy(p->uri, uri, sizeof(p->uri)); + strlcpy(p->device_uri, uri, sizeof(p->device_uri)); update = 1; } } else - { - strncpy(name, resource + 9, sizeof(name) - 1); - name[sizeof(name) - 1] = '\0'; - } + strlcpy(name, resource + 9, sizeof(name)); } else if (p != NULL && !p->hostname[0]) { - /* No "p->var[sizeof(p->var) - 1] = '\0';" because p is zeroed */ - strncpy(p->hostname, host, sizeof(p->hostname) - 1); - strncpy(p->uri, uri, sizeof(p->uri) - 1); - strncpy(p->device_uri, uri, sizeof(p->device_uri) - 1); + strlcpy(p->hostname, host, sizeof(p->hostname)); + strlcpy(p->uri, uri, sizeof(p->uri)); + strlcpy(p->device_uri, uri, sizeof(p->device_uri)); update = 1; } @@ -187,10 +181,9 @@ ProcessBrowseData(const char *uri, /* I - URI of printer/class */ */ p->type = type; - /* No "p->var[sizeof(p->var) - 1] = '\0';" because p is zeroed */ - strncpy(p->uri, uri, sizeof(p->uri) - 1); - strncpy(p->device_uri, uri, sizeof(p->device_uri) - 1); - strncpy(p->hostname, host, sizeof(p->hostname) - 1); + strlcpy(p->uri, uri, sizeof(p->uri)); + strlcpy(p->device_uri, uri, sizeof(p->device_uri)); + strlcpy(p->hostname, host, sizeof(p->hostname)); update = 1; } @@ -220,9 +213,8 @@ ProcessBrowseData(const char *uri, /* I - URI of printer/class */ if (p->type & CUPS_PRINTER_REMOTE) { - /* No "p->var[sizeof(p->var) - 1] = '\0';" because p is zeroed */ - strncat(p->name, "@", sizeof(p->name) - 1); - strncat(p->name, p->hostname, sizeof(p->name) - 1); + strlcat(p->name, "@", sizeof(p->name)); + strlcat(p->name, p->hostname, sizeof(p->name)); SetPrinterAttrs(p); SortPrinters(); } @@ -231,25 +223,20 @@ ProcessBrowseData(const char *uri, /* I - URI of printer/class */ } else if (!p->hostname[0]) { - /* No "p->var[sizeof(p->var) - 1] = '\0';" because p is zeroed */ - strncpy(p->hostname, host, sizeof(p->hostname) - 1); - strncpy(p->uri, uri, sizeof(p->uri) - 1); - strncpy(p->device_uri, uri, sizeof(p->device_uri) - 1); + strlcpy(p->hostname, host, sizeof(p->hostname)); + strlcpy(p->uri, uri, sizeof(p->uri)); + strlcpy(p->device_uri, uri, sizeof(p->device_uri)); update = 1; } } else - { - strncpy(name, resource + 10, sizeof(name) - 1); - name[sizeof(name) - 1] = '\0'; - } + strlcpy(name, resource + 10, sizeof(name)); } else if (p != NULL && !p->hostname[0]) { - /* No "p->var[sizeof(p->var) - 1] = '\0';" because p is zeroed */ - strncpy(p->hostname, host, sizeof(p->hostname) - 1); - strncpy(p->uri, uri, sizeof(p->uri) - 1); - strncpy(p->device_uri, uri, sizeof(p->device_uri) - 1); + strlcpy(p->hostname, host, sizeof(p->hostname)); + strlcpy(p->uri, uri, sizeof(p->uri)); + strlcpy(p->device_uri, uri, sizeof(p->device_uri)); update = 1; } @@ -268,10 +255,9 @@ ProcessBrowseData(const char *uri, /* I - URI of printer/class */ */ p->type = type; - /* No "p->var[sizeof(p->var) - 1] = '\0';" because p is zeroed */ - strncpy(p->hostname, host, sizeof(p->hostname) - 1); - strncpy(p->uri, uri, sizeof(p->uri) - 1); - strncpy(p->device_uri, uri, sizeof(p->device_uri) - 1); + strlcpy(p->hostname, host, sizeof(p->hostname)); + strlcpy(p->uri, uri, sizeof(p->uri)); + strlcpy(p->device_uri, uri, sizeof(p->device_uri)); update = 1; } @@ -293,15 +279,13 @@ ProcessBrowseData(const char *uri, /* I - URI of printer/class */ if (strcmp(p->location, location)) { - /* No "p->var[sizeof(p->var) - 1] = '\0';" because p is zeroed */ - strncpy(p->location, location, sizeof(p->location) - 1); + strlcpy(p->location, location, sizeof(p->location)); update = 1; } if (strcmp(p->info, info)) { - /* No "p->var[sizeof(p->var) - 1] = '\0';" because p is zeroed */ - strncpy(p->info, info, sizeof(p->info) - 1); + strlcpy(p->info, info, sizeof(p->info)); update = 1; } @@ -320,8 +304,7 @@ ProcessBrowseData(const char *uri, /* I - URI of printer/class */ if (strcmp(p->make_model, local_make_model)) { - /* No "p->var[sizeof(p->var) - 1] = '\0';" because p is zeroed */ - strncpy(p->make_model, local_make_model, sizeof(p->make_model) - 1); + strlcpy(p->make_model, local_make_model, sizeof(p->make_model)); update = 1; } @@ -1072,10 +1055,7 @@ UpdateCUPSBrowse(void) sprintf(srcname, "%d.%d.%d.%d", address >> 24, (address >> 16) & 255, (address >> 8) & 255, address & 255); else - { - strncpy(srcname, srchost->h_name, sizeof(srcname) - 1); - srcname[sizeof(srcname) - 1] = '\0'; - } + strlcpy(srcname, srchost->h_name, sizeof(srcname)); len = strlen(srcname); @@ -1411,7 +1391,7 @@ SendSLPBrowse(printer_t *p) /* I - Printer to register */ if (p->type & CUPS_PRINTER_BIND) { if (finishings[0]) - strncat(finishings, ",bind", sizeof(finishings) - 1); + strlcat(finishings, ",bind", sizeof(finishings)); else strcpy(finishings, "bind"); } @@ -1419,7 +1399,7 @@ SendSLPBrowse(printer_t *p) /* I - Printer to register */ if (p->type & CUPS_PRINTER_PUNCH) { if (finishings[0]) - strncat(finishings, ",punch", sizeof(finishings) - 1); + strlcat(finishings, ",punch", sizeof(finishings)); else strcpy(finishings, "punch"); } @@ -1427,7 +1407,7 @@ SendSLPBrowse(printer_t *p) /* I - Printer to register */ if (p->type & CUPS_PRINTER_COVER) { if (finishings[0]) - strncat(finishings, ",cover", sizeof(finishings) - 1); + strlcat(finishings, ",cover", sizeof(finishings)); else strcpy(finishings, "cover"); } @@ -1435,7 +1415,7 @@ SendSLPBrowse(printer_t *p) /* I - Printer to register */ if (p->type & CUPS_PRINTER_SORT) { if (finishings[0]) - strncat(finishings, ",sort", sizeof(finishings) - 1); + strlcat(finishings, ",sort", sizeof(finishings)); else strcpy(finishings, "sort"); } @@ -1443,8 +1423,6 @@ SendSLPBrowse(printer_t *p) /* I - Printer to register */ if (!finishings[0]) strcpy(finishings, "none"); - finishings[sizeof(finishings) - 1] = '\0'; - /* * Quote any commas in the make and model, location, and info strings * (local strings are twice the size of the ones in the printer_t @@ -1732,7 +1710,7 @@ SrvUrlCallback(SLPHandle hslp, /* I - SLP handle */ * Copy the SLP service URL... */ - strncpy(s->url, srvurl, sizeof(s->url)); + strlcpy(s->url, srvurl, sizeof(s->url)); /* * Link the SLP service URL into the head of the list @@ -1839,5 +1817,5 @@ UpdateSLPBrowse(void) /* - * End of "$Id: dirsvc.c,v 1.94 2002/05/12 11:49:29 mike Exp $". + * End of "$Id: dirsvc.c,v 1.95 2002/05/16 13:45:00 mike Exp $". */ diff --git a/scheduler/filter.c b/scheduler/filter.c index 50d50e5b7..6f175fde1 100644 --- a/scheduler/filter.c +++ b/scheduler/filter.c @@ -1,5 +1,5 @@ /* - * "$Id: filter.c,v 1.4 2002/01/02 17:59:15 mike Exp $" + * "$Id: filter.c,v 1.5 2002/05/16 13:45:00 mike Exp $" * * File type conversion routines for the Common UNIX Printing System (CUPS). * @@ -88,8 +88,7 @@ mimeAddFilter(mime_t *mime, /* I - MIME database */ if (temp->cost > cost) { temp->cost = cost; - strncpy(temp->filter, filter, sizeof(temp->filter) - 1); - temp->filter[sizeof(temp->filter) - 1] = '\0'; + strlcpy(temp->filter, filter, sizeof(temp->filter)); } } else @@ -117,8 +116,7 @@ mimeAddFilter(mime_t *mime, /* I - MIME database */ temp->src = src; temp->dst = dst; temp->cost = cost; - strncpy(temp->filter, filter, sizeof(temp->filter) - 1); - temp->filter[sizeof(temp->filter) - 1] = '\0'; + strlcpy(temp->filter, filter, sizeof(temp->filter)); if (mime->num_filters > 1) qsort(mime->filters, mime->num_filters, sizeof(mime_filter_t), @@ -297,5 +295,5 @@ lookup(mime_t *mime, /* I - MIME database */ /* - * End of "$Id: filter.c,v 1.4 2002/01/02 17:59:15 mike Exp $". + * End of "$Id: filter.c,v 1.5 2002/05/16 13:45:00 mike Exp $". */ diff --git a/scheduler/ipp.c b/scheduler/ipp.c index 8903d7b50..85854b38d 100644 --- a/scheduler/ipp.c +++ b/scheduler/ipp.c @@ -1,5 +1,5 @@ /* - * "$Id: ipp.c,v 1.158 2002/05/15 01:52:17 mike Exp $" + * "$Id: ipp.c,v 1.159 2002/05/16 13:45:01 mike Exp $" * * IPP routines for the Common UNIX Printing System (CUPS) scheduler. * @@ -658,16 +658,10 @@ add_class(client_t *con, /* I - Client connection */ */ if ((attr = ippFindAttribute(con->request, "printer-location", IPP_TAG_TEXT)) != NULL) - { - strncpy(pclass->location, attr->values[0].string.text, sizeof(pclass->location) - 1); - pclass->location[sizeof(pclass->location) - 1] = '\0'; - } + strlcpy(pclass->location, attr->values[0].string.text, sizeof(pclass->location)); if ((attr = ippFindAttribute(con->request, "printer-info", IPP_TAG_TEXT)) != NULL) - { - strncpy(pclass->info, attr->values[0].string.text, sizeof(pclass->info) - 1); - pclass->info[sizeof(pclass->info) - 1] = '\0'; - } + strlcpy(pclass->info, attr->values[0].string.text, sizeof(pclass->info)); if ((attr = ippFindAttribute(con->request, "printer-is-accepting-jobs", IPP_TAG_BOOLEAN)) != NULL) { @@ -696,19 +690,16 @@ add_class(client_t *con, /* I - Client connection */ pclass->browse_time = 0; } if ((attr = ippFindAttribute(con->request, "printer-state-message", IPP_TAG_TEXT)) != NULL) - { - strncpy(pclass->state_message, attr->values[0].string.text, - sizeof(pclass->state_message) - 1); - pclass->state_message[sizeof(pclass->state_message) - 1] = '\0'; - } + strlcpy(pclass->state_message, attr->values[0].string.text, + sizeof(pclass->state_message)); if ((attr = ippFindAttribute(con->request, "job-sheets-default", IPP_TAG_ZERO)) != NULL && !Classification[0]) { - strncpy(pclass->job_sheets[0], attr->values[0].string.text, - sizeof(pclass->job_sheets[0]) - 1); + strlcpy(pclass->job_sheets[0], attr->values[0].string.text, + sizeof(pclass->job_sheets[0])); if (attr->num_values > 1) - strncpy(pclass->job_sheets[1], attr->values[1].string.text, - sizeof(pclass->job_sheets[1]) - 1); + strlcpy(pclass->job_sheets[1], attr->values[1].string.text, + sizeof(pclass->job_sheets[1])); else strcpy(pclass->job_sheets[1], "none"); } @@ -1081,16 +1072,12 @@ add_printer(client_t *con, /* I - Client connection */ */ if ((attr = ippFindAttribute(con->request, "printer-location", IPP_TAG_TEXT)) != NULL) - { - strncpy(printer->location, attr->values[0].string.text, sizeof(printer->location) - 1); - printer->location[sizeof(printer->location) - 1] = '\0'; - } + strlcpy(printer->location, attr->values[0].string.text, + sizeof(printer->location)); if ((attr = ippFindAttribute(con->request, "printer-info", IPP_TAG_TEXT)) != NULL) - { - strncpy(printer->info, attr->values[0].string.text, sizeof(printer->info) - 1); - printer->info[sizeof(printer->info) - 1] = '\0'; - } + strlcpy(printer->info, attr->values[0].string.text, + sizeof(printer->info)); if ((attr = ippFindAttribute(con->request, "device-uri", IPP_TAG_URI)) != NULL) { @@ -1136,9 +1123,8 @@ add_printer(client_t *con, /* I - Client connection */ LogMessage(L_INFO, "Setting %s device-uri to \"%s\" (was \"%s\".)", printer->name, attr->values[0].string.text, printer->device_uri); - strncpy(printer->device_uri, attr->values[0].string.text, - sizeof(printer->device_uri) - 1); - printer->device_uri[sizeof(printer->device_uri) - 1] = '\0'; + strlcpy(printer->device_uri, attr->values[0].string.text, + sizeof(printer->device_uri)); } if ((attr = ippFindAttribute(con->request, "printer-is-accepting-jobs", IPP_TAG_BOOLEAN)) != NULL) @@ -1168,19 +1154,16 @@ add_printer(client_t *con, /* I - Client connection */ printer->browse_time = 0; } if ((attr = ippFindAttribute(con->request, "printer-state-message", IPP_TAG_TEXT)) != NULL) - { - strncpy(printer->state_message, attr->values[0].string.text, - sizeof(printer->state_message) - 1); - printer->state_message[sizeof(printer->state_message) - 1] = '\0'; - } + strlcpy(printer->state_message, attr->values[0].string.text, + sizeof(printer->state_message)); if ((attr = ippFindAttribute(con->request, "job-sheets-default", IPP_TAG_ZERO)) != NULL && !Classification[0]) { - strncpy(printer->job_sheets[0], attr->values[0].string.text, - sizeof(printer->job_sheets[0]) - 1); + strlcpy(printer->job_sheets[0], attr->values[0].string.text, + sizeof(printer->job_sheets[0])); if (attr->num_values > 1) - strncpy(printer->job_sheets[1], attr->values[1].string.text, - sizeof(printer->job_sheets[1]) - 1); + strlcpy(printer->job_sheets[1], attr->values[1].string.text, + sizeof(printer->job_sheets[1])); else strcpy(printer->job_sheets[1], "none"); } @@ -1239,10 +1222,7 @@ add_printer(client_t *con, /* I - Client connection */ */ if (con->filename[0]) - { - strncpy(srcfile, con->filename, sizeof(srcfile) - 1); - srcfile[sizeof(srcfile) - 1] = '\0'; - } + strlcpy(srcfile, con->filename, sizeof(srcfile)); else if ((attr = ippFindAttribute(con->request, "ppd-name", IPP_TAG_NAME)) != NULL) { if (strcmp(attr->values[0].string.text, "raw") == 0) @@ -1761,17 +1741,13 @@ check_quotas(client_t *con, /* I - Client connection */ attr = ippFindAttribute(con->request, "requesting-user-name", IPP_TAG_NAME); if (con->username[0]) - { - strncpy(username, con->username, sizeof(username) - 1); - username[sizeof(username) - 1] = '\0'; - } + strlcpy(username, con->username, sizeof(username)); else if (attr != NULL) { LogMessage(L_DEBUG, "check_quotas: requesting-user-name = \'%s\'", attr->values[0].string.text); - strncpy(username, attr->values[0].string.text, sizeof(username) - 1); - username[sizeof(username) - 1] = '\0'; + strlcpy(username, attr->values[0].string.text, sizeof(username)); } else strcpy(username, "anonymous"); @@ -2189,23 +2165,19 @@ create_job(client_t *con, /* I - Client connection */ job->attrs = con->request; con->request = NULL; - strncpy(job->title, title, sizeof(job->title) - 1); + strlcpy(job->title, title, sizeof(job->title)); attr = ippFindAttribute(job->attrs, "requesting-user-name", IPP_TAG_NAME); if (con->username[0]) - { - strncpy(job->username, con->username, sizeof(job->username) - 1); - job->username[sizeof(job->username) - 1] = '\0'; - } + strlcpy(job->username, con->username, sizeof(job->username)); else if (attr != NULL) { LogMessage(L_DEBUG, "create_job: requesting-user-name = \'%s\'", attr->values[0].string.text); - strncpy(job->username, attr->values[0].string.text, - sizeof(job->username) - 1); - job->username[sizeof(job->username) - 1] = '\0'; + strlcpy(job->username, attr->values[0].string.text, + sizeof(job->username)); } else strcpy(job->username, "anonymous"); @@ -3022,15 +2994,9 @@ get_jobs(client_t *con, /* I - Client connection */ attr->values[0].boolean) { if (con->username[0]) - { - strncpy(username, con->username, sizeof(username) - 1); - username[sizeof(username) - 1] = '\0'; - } + strlcpy(username, con->username, sizeof(username)); else if ((attr = ippFindAttribute(con->request, "requesting-user-name", IPP_TAG_NAME)) != NULL) - { - strncpy(username, attr->values[0].string.text, sizeof(username) - 1); - username[sizeof(username) - 1] = '\0'; - } + strlcpy(username, attr->values[0].string.text, sizeof(username)); else strcpy(username, "anonymous"); } @@ -4047,22 +4013,18 @@ print_job(client_t *con, /* I - Client connection */ * Copy the rest of the job info... */ - strncpy(job->title, title, sizeof(job->title) - 1); + strlcpy(job->title, title, sizeof(job->title)); attr = ippFindAttribute(job->attrs, "requesting-user-name", IPP_TAG_NAME); if (con->username[0]) - { - strncpy(job->username, con->username, sizeof(job->username) - 1); - job->username[sizeof(job->username) - 1] = '\0'; - } + strlcpy(job->username, con->username, sizeof(job->username)); else if (attr != NULL) { LogMessage(L_DEBUG, "print_job: requesting-user-name = \'%s\'", attr->values[0].string.text); - strncpy(job->username, attr->values[0].string.text, sizeof(job->username) - 1); - job->username[sizeof(job->username) - 1] = '\0'; + strlcpy(job->username, attr->values[0].string.text, sizeof(job->username)); } else strcpy(job->username, "anonymous"); @@ -4407,11 +4369,8 @@ reject_jobs(client_t *con, /* I - Client connection */ IPP_TAG_TEXT)) == NULL) strcpy(printer->state_message, "Rejecting Jobs"); else - { - strncpy(printer->state_message, attr->values[0].string.text, - sizeof(printer->state_message) - 1); - printer->state_message[sizeof(printer->state_message) - 1] = '\0'; - } + strlcpy(printer->state_message, attr->values[0].string.text, + sizeof(printer->state_message)); if (dtype == CUPS_PRINTER_CLASS) SaveAllClasses(); @@ -5329,7 +5288,7 @@ set_job_attrs(client_t *con, /* I - Client connection */ */ if (strcmp(attr->name, "job-name") == 0) - strncpy(job->title, attr->values[0].string.text, sizeof(job->title) - 1); + strlcpy(job->title, attr->values[0].string.text, sizeof(job->title)); else if (strcmp(attr->name, "job-hold-until") == 0) { SetJobHoldUntil(job->id, attr->values[0].string.text); @@ -5552,9 +5511,8 @@ stop_printer(client_t *con, /* I - Client connection */ strcpy(printer->state_message, "Paused"); else { - strncpy(printer->state_message, attr->values[0].string.text, - sizeof(printer->state_message) - 1); - printer->state_message[sizeof(printer->state_message) - 1] = '\0'; + strlcpy(printer->state_message, attr->values[0].string.text, + sizeof(printer->state_message)); } if (dtype == CUPS_PRINTER_CLASS) @@ -5718,13 +5676,11 @@ validate_user(client_t *con, /* I - Client connection */ */ if (con->username[0]) - strncpy(username, con->username, userlen - 1); + strlcpy(username, con->username, userlen); else if ((attr = ippFindAttribute(con->request, "requesting-user-name", IPP_TAG_NAME)) != NULL) - strncpy(username, attr->values[0].string.text, userlen - 1); + strlcpy(username, attr->values[0].string.text, userlen); else - strncpy(username, "anonymous", userlen - 1); - - username[userlen - 1] = '\0'; + strlcpy(username, "anonymous", userlen); /* * Check the username against the owner... @@ -5775,5 +5731,5 @@ validate_user(client_t *con, /* I - Client connection */ /* - * End of "$Id: ipp.c,v 1.158 2002/05/15 01:52:17 mike Exp $". + * End of "$Id: ipp.c,v 1.159 2002/05/16 13:45:01 mike Exp $". */ diff --git a/scheduler/job.c b/scheduler/job.c index 1c5889057..93400b38a 100644 --- a/scheduler/job.c +++ b/scheduler/job.c @@ -1,5 +1,5 @@ /* - * "$Id: job.c,v 1.153 2002/05/15 01:52:18 mike Exp $" + * "$Id: job.c,v 1.154 2002/05/16 13:45:01 mike Exp $" * * Job management routines for the Common UNIX Printing System (CUPS). * @@ -91,7 +91,7 @@ AddJob(int priority, /* I - Job priority */ job->id = NextJobId ++; job->priority = priority; - strncpy(job->dest, dest, sizeof(job->dest) - 1); + strlcpy(job->dest, dest, sizeof(job->dest)); NumJobs ++; @@ -585,7 +585,7 @@ LoadAllJobs(void) continue; } - strncpy(job->dest, dest, sizeof(job->dest) - 1); + strlcpy(job->dest, dest, sizeof(job->dest)); job->sheets = ippFindAttribute(job->attrs, "job-media-sheets-completed", IPP_TAG_INTEGER); @@ -595,12 +595,12 @@ LoadAllJobs(void) job->priority = attr->values[0].integer; attr = ippFindAttribute(job->attrs, "job-name", IPP_TAG_NAME); - strncpy(job->title, attr->values[0].string.text, - sizeof(job->title) - 1); + strlcpy(job->title, attr->values[0].string.text, + sizeof(job->title)); attr = ippFindAttribute(job->attrs, "job-originating-user-name", IPP_TAG_NAME); - strncpy(job->username, attr->values[0].string.text, - sizeof(job->username) - 1); + strlcpy(job->username, attr->values[0].string.text, + sizeof(job->username)); if (job->state->values[0].integer == IPP_JOB_HELD) { @@ -728,7 +728,7 @@ MoveJob(int id, /* I - Job ID */ if (current->state->values[0].integer >= IPP_JOB_PROCESSING) break; - strncpy(current->dest, dest, sizeof(current->dest) - 1); + strlcpy(current->dest, dest, sizeof(current->dest)); current->dtype = p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_REMOTE); if ((attr = ippFindAttribute(current->attrs, "job-printer-uri", IPP_TAG_URI)) != NULL) @@ -1259,10 +1259,7 @@ StartJob(int id, /* I - Job ID */ else if (strcmp(attr->name, "job-name") == 0 && (attr->value_tag == IPP_TAG_NAME || attr->value_tag == IPP_TAG_NAMELANG)) - { - strncpy(title, attr->values[0].string.text, sizeof(title) - 1); - title[sizeof(title) - 1] = '\0'; - } + strlcpy(title, attr->values[0].string.text, sizeof(title)); else if (attr->group_tag == IPP_TAG_JOB) { /* @@ -1299,18 +1296,18 @@ StartJob(int id, /* I - Job ID */ */ if (optptr > options) - strncat(optptr, " ", sizeof(options) - (optptr - options) - 1); + strlcat(optptr, " ", sizeof(options) - (optptr - options)); if (attr->value_tag != IPP_TAG_BOOLEAN) { - strncat(optptr, attr->name, sizeof(options) - (optptr - options) - 1); - strncat(optptr, "=", sizeof(options) - (optptr - options) - 1); + strlcat(optptr, attr->name, sizeof(options) - (optptr - options)); + strlcat(optptr, "=", sizeof(options) - (optptr - options)); } for (i = 0; i < attr->num_values; i ++) { if (i) - strncat(optptr, ",", sizeof(options) - (optptr - options) - 1); + strlcat(optptr, ",", sizeof(options) - (optptr - options)); optptr += strlen(optptr); @@ -1318,17 +1315,17 @@ StartJob(int id, /* I - Job ID */ { case IPP_TAG_INTEGER : case IPP_TAG_ENUM : - snprintf(optptr, sizeof(options) - (optptr - options) - 1, + snprintf(optptr, sizeof(options) - (optptr - options), "%d", attr->values[i].integer); break; case IPP_TAG_BOOLEAN : if (!attr->values[i].boolean) - strncat(optptr, "no", sizeof(options) - (optptr - options) - 1); + strlcat(optptr, "no", sizeof(options) - (optptr - options)); case IPP_TAG_NOVALUE : - strncat(optptr, attr->name, - sizeof(options) - (optptr - options) - 1); + strlcat(optptr, attr->name, + sizeof(options) - (optptr - options)); break; case IPP_TAG_RANGE : @@ -1359,14 +1356,14 @@ StartJob(int id, /* I - Job ID */ strchr(attr->values[i].string.text, '\t') != NULL || strchr(attr->values[i].string.text, '\n') != NULL) { - strncat(optptr, "\'", sizeof(options) - (optptr - options) - 1); - strncat(optptr, attr->values[i].string.text, - sizeof(options) - (optptr - options) - 1); - strncat(optptr, "\'", sizeof(options) - (optptr - options) - 1); + strlcat(optptr, "\'", sizeof(options) - (optptr - options)); + strlcat(optptr, attr->values[i].string.text, + sizeof(options) - (optptr - options)); + strlcat(optptr, "\'", sizeof(options) - (optptr - options)); } else - strncat(optptr, attr->values[i].string.text, - sizeof(options) - (optptr - options) - 1); + strlcat(optptr, attr->values[i].string.text, + sizeof(options) - (optptr - options)); break; default : @@ -1588,10 +1585,7 @@ StartJob(int id, /* I - Job ID */ snprintf(command, sizeof(command), "%s/filter/%s", ServerBin, filters[i].filter); else - { - strncpy(command, filters[i].filter, sizeof(command) - 1); - command[sizeof(command) - 1] = '\0'; - } + strlcpy(command, filters[i].filter, sizeof(command)); if (i < (num_filters - 1) || strncmp(printer->device_uri, "file:", 5) != 0) @@ -1946,8 +1940,8 @@ UpdateJob(job_t *job) /* I - Job to check */ if ((loglevel == L_INFO && !job->status) || loglevel < L_INFO) - strncpy(job->printer->state_message, message, - sizeof(job->printer->state_message) - 1); + strlcpy(job->printer->state_message, message, + sizeof(job->printer->state_message)); } /* @@ -3062,5 +3056,5 @@ start_process(const char *command, /* I - Full path to command */ /* - * End of "$Id: job.c,v 1.153 2002/05/15 01:52:18 mike Exp $". + * End of "$Id: job.c,v 1.154 2002/05/16 13:45:01 mike Exp $". */ diff --git a/scheduler/log.c b/scheduler/log.c index 36e0016dc..d65653b1c 100644 --- a/scheduler/log.c +++ b/scheduler/log.c @@ -1,5 +1,5 @@ /* - * "$Id: log.c,v 1.25 2002/05/14 01:14:29 mike Exp $" + * "$Id: log.c,v 1.26 2002/05/16 13:45:02 mike Exp $" * * Log file routines for the Common UNIX Printing System (CUPS). * @@ -354,8 +354,8 @@ check_log_file(FILE **log, /* IO - Log file */ if (logname[0] != '/') { - strncpy(filename, ServerRoot, sizeof(filename) - 1); - strncat(filename, "/", sizeof(filename) - 1); + strlcpy(filename, ServerRoot, sizeof(filename)); + strlcat(filename, "/", sizeof(filename)); } else filename[0] = '\0'; @@ -376,7 +376,7 @@ check_log_file(FILE **log, /* IO - Log file */ * Insert the server name... */ - strncpy(ptr, ServerName, sizeof(filename) - (ptr - filename) - 1); + strlcpy(ptr, ServerName, sizeof(filename) - (ptr - filename)); ptr += strlen(ptr); } else @@ -424,8 +424,7 @@ check_log_file(FILE **log, /* IO - Log file */ fclose(*log); strcpy(backname, filename); - strncat(backname, ".O", sizeof(backname) - 1); - backname[sizeof(backname) - 1] = '\0'; + strlcat(backname, ".O", sizeof(backname)); unlink(backname); rename(filename, backname); @@ -442,5 +441,5 @@ check_log_file(FILE **log, /* IO - Log file */ /* - * End of "$Id: log.c,v 1.25 2002/05/14 01:14:29 mike Exp $". + * End of "$Id: log.c,v 1.26 2002/05/16 13:45:02 mike Exp $". */ diff --git a/scheduler/main.c b/scheduler/main.c index 0b5e062d8..75c9637ca 100644 --- a/scheduler/main.c +++ b/scheduler/main.c @@ -1,5 +1,5 @@ /* - * "$Id: main.c,v 1.71 2002/05/12 11:49:29 mike Exp $" + * "$Id: main.c,v 1.72 2002/05/16 13:45:02 mike Exp $" * * Scheduler main loop for the Common UNIX Printing System (CUPS). * @@ -114,8 +114,7 @@ main(int argc, /* I - Number of command-line arguments */ * Absolute directory... */ - strncpy(ConfigurationFile, argv[i], sizeof(ConfigurationFile) - 1); - ConfigurationFile[sizeof(ConfigurationFile) - 1] = '\0'; + strlcpy(ConfigurationFile, argv[i], sizeof(ConfigurationFile)); } else { @@ -124,9 +123,8 @@ main(int argc, /* I - Number of command-line arguments */ */ getcwd(ConfigurationFile, sizeof(ConfigurationFile)); - strncat(ConfigurationFile, "/", sizeof(ConfigurationFile) - 1); - strncat(ConfigurationFile, argv[i], sizeof(ConfigurationFile) - 1); - ConfigurationFile[sizeof(ConfigurationFile) - 1] = '\0'; + strlcat(ConfigurationFile, "/", sizeof(ConfigurationFile)); + strlcat(ConfigurationFile, argv[i], sizeof(ConfigurationFile)); } break; @@ -806,5 +804,5 @@ usage(void) /* - * End of "$Id: main.c,v 1.71 2002/05/12 11:49:29 mike Exp $". + * End of "$Id: main.c,v 1.72 2002/05/16 13:45:02 mike Exp $". */ diff --git a/scheduler/mime.c b/scheduler/mime.c index 3f8b5c470..368f570e1 100644 --- a/scheduler/mime.c +++ b/scheduler/mime.c @@ -1,5 +1,5 @@ /* - * "$Id: mime.c,v 1.11 2002/05/14 01:14:30 mike Exp $" + * "$Id: mime.c,v 1.12 2002/05/16 13:45:02 mike Exp $" * * MIME database file routines for the Common UNIX Printing System (CUPS). * @@ -131,8 +131,7 @@ mimeMerge(mime_t *mime, /* I - MIME database to add to */ if (pathname == NULL) return (NULL); - strncpy(filename, pathname, sizeof(filename) - 1); - filename[sizeof(filename) - 1] = '\0'; + strlcpy(filename, pathname, sizeof(filename)); pathsep = filename + strlen(filename); if ((pathsep - filename + 9) > sizeof(filename)) @@ -508,10 +507,7 @@ load_convs(mime_t *mime, /* I - MIME database */ */ if (filter[0] == '/') - { - strncpy(filterprog, filter, sizeof(filterprog) - 1); - filterprog[sizeof(filterprog) - 1] = '\0'; - } + strlcpy(filterprog, filter, sizeof(filterprog)); else snprintf(filterprog, sizeof(filterprog), "%s/%s", filterpath, filter); @@ -597,5 +593,5 @@ delete_rules(mime_magic_t *rules) /* I - Rules to free */ /* - * End of "$Id: mime.c,v 1.11 2002/05/14 01:14:30 mike Exp $". + * End of "$Id: mime.c,v 1.12 2002/05/16 13:45:02 mike Exp $". */ diff --git a/scheduler/network.c b/scheduler/network.c index 5bbd78126..e52d7287e 100644 --- a/scheduler/network.c +++ b/scheduler/network.c @@ -1,5 +1,5 @@ /* - * "$Id: network.c,v 1.8 2002/04/02 18:58:53 mike Exp $" + * "$Id: network.c,v 1.9 2002/05/16 13:45:02 mike Exp $" * * Network interface functions for the Common UNIX Printing System * (CUPS) scheduler. @@ -180,7 +180,7 @@ NetIFUpdate(void) * Then copy all of the information... */ - strncpy(temp->name, addr->ifa_name, sizeof(temp->name) - 1); + strlcpy(temp->name, addr->ifa_name, sizeof(temp->name)); memcpy(&(temp->address), addr->ifa_addr, sizeof(temp->address)); memcpy(&(temp->mask), addr->ifa_netmask, sizeof(temp->mask)); @@ -215,11 +215,11 @@ NetIFUpdate(void) */ if (host != NULL) - strncpy(temp->hostname, host->h_name, sizeof(temp->hostname) - 1); + strlcpy(temp->hostname, host->h_name, sizeof(temp->hostname)); else if (ntohl(temp->address.sin_addr.s_addr) == 0x7f000001) strcpy(temp->hostname, "localhost"); else if (temp->address.sin_addr.s_addr == ServerAddr.sin_addr.s_addr) - strncpy(temp->hostname, ServerName, sizeof(temp->hostname) - 1); + strlcpy(temp->hostname, ServerName, sizeof(temp->hostname)); else { unsigned ip = ntohl(temp->address.sin_addr.s_addr); @@ -470,5 +470,5 @@ freeifaddrs(struct ifaddrs *addrs) /* I - Interface list to free */ /* - * End of "$Id: network.c,v 1.8 2002/04/02 18:58:53 mike Exp $". + * End of "$Id: network.c,v 1.9 2002/05/16 13:45:02 mike Exp $". */ diff --git a/scheduler/ppds.c b/scheduler/ppds.c index dd91d1d78..f7e55b4a5 100644 --- a/scheduler/ppds.c +++ b/scheduler/ppds.c @@ -1,5 +1,5 @@ /* - * "$Id: ppds.c,v 1.22 2002/01/02 17:59:17 mike Exp $" + * "$Id: ppds.c,v 1.23 2002/05/16 13:45:03 mike Exp $" * * PPD scanning routines for the Common UNIX Printing System (CUPS). * @@ -518,10 +518,7 @@ load_ppds(const char *d, /* I - Actual directory */ if (p[0]) snprintf(name, sizeof(name), "%s/%s", p, dent->d_name); else - { - strncpy(name, dent->d_name, sizeof(name) - 1); - name[sizeof(name) - 1] = '\0'; - } + strlcpy(name, dent->d_name, sizeof(name)); if (stat(filename, &fileinfo)) continue; @@ -658,7 +655,7 @@ load_ppds(const char *d, /* I - Actual directory */ * Nope, copy the first part of the make and model then... */ - strncpy(manufacturer, make_model, sizeof(manufacturer) - 1); + strlcpy(manufacturer, make_model, sizeof(manufacturer)); /* * Truncate at the first space, dash, or slash, or make the @@ -807,14 +804,14 @@ load_ppds(const char *d, /* I - Actual directory */ ppd->record.ppd_mtime = fileinfo.st_mtime; ppd->record.ppd_size = fileinfo.st_size; - strncpy(ppd->record.ppd_name, name, - sizeof(ppd->record.ppd_name) - 1); - strncpy(ppd->record.ppd_make, manufacturer, - sizeof(ppd->record.ppd_make) - 1); - strncpy(ppd->record.ppd_make_and_model, make_model, - sizeof(ppd->record.ppd_make_and_model) - 1); - strncpy(ppd->record.ppd_natural_language, language, - sizeof(ppd->record.ppd_natural_language) - 1); + strlcpy(ppd->record.ppd_name, name, + sizeof(ppd->record.ppd_name)); + strlcpy(ppd->record.ppd_make, manufacturer, + sizeof(ppd->record.ppd_make)); + strlcpy(ppd->record.ppd_make_and_model, make_model, + sizeof(ppd->record.ppd_make_and_model)); + strlcpy(ppd->record.ppd_natural_language, language, + sizeof(ppd->record.ppd_natural_language)); changed_ppd = 1; @@ -893,5 +890,5 @@ ppd_gets(buf_t *fp, /* I - File to read from */ /* - * End of "$Id: ppds.c,v 1.22 2002/01/02 17:59:17 mike Exp $". + * End of "$Id: ppds.c,v 1.23 2002/05/16 13:45:03 mike Exp $". */ diff --git a/scheduler/printers.c b/scheduler/printers.c index eadad2f6c..e008bd48c 100644 --- a/scheduler/printers.c +++ b/scheduler/printers.c @@ -1,5 +1,5 @@ /* - * "$Id: printers.c,v 1.121 2002/05/15 21:00:00 mike Exp $" + * "$Id: printers.c,v 1.122 2002/05/16 13:45:03 mike Exp $" * * Printer routines for the Common UNIX Printing System (CUPS). * @@ -93,8 +93,8 @@ AddPrinter(const char *name) /* I - Name of printer */ if ((p = calloc(1, sizeof(printer_t))) == NULL) return (NULL); - strncpy(p->name, name, sizeof(p->name) - 1); - strncpy(p->hostname, ServerName, sizeof(p->hostname) - 1); + strlcpy(p->name, name, sizeof(p->name)); + strlcpy(p->hostname, ServerName, sizeof(p->hostname)); snprintf(p->uri, sizeof(p->uri), "ipp://%s:%d/printers/%s", ServerName, ntohs(Listeners[0].address.sin_port), name); @@ -597,11 +597,11 @@ LoadAllPrinters(void) return; } else if (strcmp(name, "Info") == 0) - strncpy(p->info, value, sizeof(p->info) - 1); + strlcpy(p->info, value, sizeof(p->info)); else if (strcmp(name, "Location") == 0) - strncpy(p->location, value, sizeof(p->location) - 1); + strlcpy(p->location, value, sizeof(p->location)); else if (strcmp(name, "DeviceURI") == 0) - strncpy(p->device_uri, value, sizeof(p->device_uri) - 1); + strlcpy(p->device_uri, value, sizeof(p->device_uri)); else if (strcmp(name, "State") == 0) { /* @@ -622,7 +622,7 @@ LoadAllPrinters(void) while (isspace(*value)) value ++; - strncpy(p->state_message, value, sizeof(p->state_message) - 1); + strlcpy(p->state_message, value, sizeof(p->state_message)); } else if (strcmp(name, "Accepting") == 0) { @@ -646,7 +646,7 @@ LoadAllPrinters(void) if (*valueptr) *valueptr++ = '\0'; - strncpy(p->job_sheets[0], value, sizeof(p->job_sheets[0]) - 1); + strlcpy(p->job_sheets[0], value, sizeof(p->job_sheets[0])); while (isspace(*valueptr)) valueptr ++; @@ -658,7 +658,7 @@ LoadAllPrinters(void) if (*valueptr) *valueptr++ = '\0'; - strncpy(p->job_sheets[1], value, sizeof(p->job_sheets[1]) - 1); + strlcpy(p->job_sheets[1], value, sizeof(p->job_sheets[1])); } } else if (strcmp(name, "AllowUser") == 0) @@ -1221,9 +1221,9 @@ SetPrinterAttrs(printer_t *p) /* I - Printer to setup */ "pages-per-minute", ppd->throughput); if (ppd->nickname) - strncpy(p->make_model, ppd->nickname, sizeof(p->make_model) - 1); + strlcpy(p->make_model, ppd->nickname, sizeof(p->make_model)); else if (ppd->modelname) - strncpy(p->make_model, ppd->modelname, sizeof(p->make_model) - 1); + strlcpy(p->make_model, ppd->modelname, sizeof(p->make_model)); else strcpy(p->make_model, "Bad PPD File"); @@ -1667,8 +1667,7 @@ ValidateDest(const char *hostname, /* I - Host name */ if (strcasecmp(hostname, "localhost") == 0) hostname = ServerName; - strncpy(localname, hostname, sizeof(localname) - 1); - localname[sizeof(localname) - 1] = '\0'; + strlcpy(localname, hostname, sizeof(localname)); if (strcasecmp(hostname, ServerName) != 0) { @@ -2076,5 +2075,5 @@ write_irix_state(printer_t *p) /* I - Printer to update */ /* - * End of "$Id: printers.c,v 1.121 2002/05/15 21:00:00 mike Exp $". + * End of "$Id: printers.c,v 1.122 2002/05/16 13:45:03 mike Exp $". */ diff --git a/scheduler/quotas.c b/scheduler/quotas.c index add38421b..97d3da02d 100644 --- a/scheduler/quotas.c +++ b/scheduler/quotas.c @@ -1,5 +1,5 @@ /* - * "$Id: quotas.c,v 1.6 2002/01/02 17:59:18 mike Exp $" + * "$Id: quotas.c,v 1.7 2002/05/16 13:45:03 mike Exp $" * * Quota routines for the Common UNIX Printing System (CUPS). * @@ -71,7 +71,7 @@ AddQuota(printer_t *p, /* I - Printer */ p->num_quotas ++; memset(q, 0, sizeof(quota_t)); - strncpy(q->username, username, sizeof(q->username) - 1); + strlcpy(q->username, username, sizeof(q->username)); if (p->num_quotas > 1) qsort(p->quotas, p->num_quotas, sizeof(quota_t), @@ -100,8 +100,7 @@ FindQuota(printer_t *p, /* I - Printer */ q = NULL; else { - strncpy(match.username, username, sizeof(match.username) - 1); - match.username[sizeof(match.username) - 1] = '\0'; + strlcpy(match.username, username, sizeof(match.username)); q = bsearch(&match, p->quotas, p->num_quotas, sizeof(quota_t), (int(*)(const void *, const void *))compare); @@ -232,5 +231,5 @@ compare(const quota_t *q1, /* I - First quota record */ /* - * End of "$Id: quotas.c,v 1.6 2002/01/02 17:59:18 mike Exp $". + * End of "$Id: quotas.c,v 1.7 2002/05/16 13:45:03 mike Exp $". */ diff --git a/scheduler/type.c b/scheduler/type.c index 37841cb95..746eeee7f 100644 --- a/scheduler/type.c +++ b/scheduler/type.c @@ -1,5 +1,5 @@ /* - * "$Id: type.c,v 1.15 2002/05/14 01:14:30 mike Exp $" + * "$Id: type.c,v 1.16 2002/05/16 13:45:03 mike Exp $" * * MIME typing routines for the Common UNIX Printing System (CUPS). * @@ -109,7 +109,7 @@ mimeAddType(mime_t *mime, /* I - MIME database */ mime->num_types ++; *types = temp; - strncpy(temp->super, super, sizeof(temp->super) - 1); + strlcpy(temp->super, super, sizeof(temp->super)); if ((temp->type = strdup(type)) == NULL) { mime->num_types --; @@ -619,8 +619,7 @@ mimeType(mime_t *mime, /* I - MIME database */ * Lookup the type in the array... */ - strncpy(key.super, super, sizeof(key.super) - 1); - key.super[sizeof(key.super) - 1] = '\0'; + strlcpy(key.super, super, sizeof(key.super)); key.type = (char *)type; keyptr = &key; @@ -1093,5 +1092,5 @@ patmatch(const char *s, /* I - String to match against */ /* - * End of "$Id: type.c,v 1.15 2002/05/14 01:14:30 mike Exp $". + * End of "$Id: type.c,v 1.16 2002/05/16 13:45:03 mike Exp $". */ diff --git a/systemv/accept.c b/systemv/accept.c index 5c2d2d784..353cfecdc 100644 --- a/systemv/accept.c +++ b/systemv/accept.c @@ -1,5 +1,5 @@ /* - * "$Id: accept.c,v 1.15 2002/01/02 17:59:19 mike Exp $" + * "$Id: accept.c,v 1.16 2002/05/16 13:45:04 mike Exp $" * * "accept", "disable", "enable", and "reject" commands for the Common * UNIX Printing System (CUPS). @@ -178,10 +178,7 @@ main(int argc, /* I - Number of command-line arguments */ */ if (sscanf(argv[i], "%1023[^@]@%1023s", printer, hostname) == 1) - { - strncpy(hostname, server, sizeof(hostname) - 1); - hostname[sizeof(hostname) - 1] = '\0'; - } + strlcpy(hostname, server, sizeof(hostname)); if (http != NULL && strcasecmp(http->hostname, hostname) != 0) { @@ -312,5 +309,5 @@ main(int argc, /* I - Number of command-line arguments */ /* - * End of "$Id: accept.c,v 1.15 2002/01/02 17:59:19 mike Exp $". + * End of "$Id: accept.c,v 1.16 2002/05/16 13:45:04 mike Exp $". */ diff --git a/systemv/cancel.c b/systemv/cancel.c index 394f500fc..6d07a2ee1 100644 --- a/systemv/cancel.c +++ b/systemv/cancel.c @@ -1,5 +1,5 @@ /* - * "$Id: cancel.c,v 1.22 2002/01/02 17:59:19 mike Exp $" + * "$Id: cancel.c,v 1.23 2002/05/16 13:45:04 mike Exp $" * * "cancel" command for the Common UNIX Printing System (CUPS). * @@ -163,8 +163,7 @@ main(int argc, /* I - Number of command-line arguments */ } else { - strncpy(name, argv[i], sizeof(name) - 1); - name[sizeof(name) - 1] = '\0'; + strlcpy(name, argv[i], sizeof(name)); dest = name; job_id = 0; @@ -282,5 +281,5 @@ main(int argc, /* I - Number of command-line arguments */ /* - * End of "$Id: cancel.c,v 1.22 2002/01/02 17:59:19 mike Exp $". + * End of "$Id: cancel.c,v 1.23 2002/05/16 13:45:04 mike Exp $". */ diff --git a/systemv/cupsaddsmb.c b/systemv/cupsaddsmb.c index d3d317f2c..69612a42b 100644 --- a/systemv/cupsaddsmb.c +++ b/systemv/cupsaddsmb.c @@ -1,5 +1,5 @@ /* - * "$Id: cupsaddsmb.c,v 1.7 2002/04/05 15:37:19 mike Exp $" + * "$Id: cupsaddsmb.c,v 1.8 2002/05/16 13:45:04 mike Exp $" * * "cupsaddsmb" command for the Common UNIX Printing System (CUPS). * @@ -187,10 +187,7 @@ do_samba_command(const char *command, /* I - Command to run */ if (Verbosity) printf("Running command: %s\n", temp); else - { - strncat(temp, " /dev/null 2>/dev/null", sizeof(temp) - 1); - temp[sizeof(temp) - 1] = '\0'; - } + strlcat(temp, " /dev/null 2>/dev/null", sizeof(temp)); if ((status = system(temp)) != 0) { @@ -339,5 +336,5 @@ usage() /* - * End of "$Id: cupsaddsmb.c,v 1.7 2002/04/05 15:37:19 mike Exp $". + * End of "$Id: cupsaddsmb.c,v 1.8 2002/05/16 13:45:04 mike Exp $". */ diff --git a/systemv/lpadmin.c b/systemv/lpadmin.c index 7eb8a95d1..8453d6efc 100644 --- a/systemv/lpadmin.c +++ b/systemv/lpadmin.c @@ -1,5 +1,5 @@ /* - * "$Id: lpadmin.c,v 1.29 2002/03/14 19:11:12 mike Exp $" + * "$Id: lpadmin.c,v 1.30 2002/05/16 13:45:04 mike Exp $" * * "lpadmin" command for the Common UNIX Printing System (CUPS). * @@ -1764,8 +1764,7 @@ set_printer_options(http_t *http, /* I - Server connection */ * Get default option name... */ - strncpy(keyword, line + 8, sizeof(keyword) - 1); - keyword[sizeof(keyword) - 1] = '\0'; + strlcpy(keyword, line + 8, sizeof(keyword)); for (keyptr = keyword; *keyptr; keyptr ++) if (*keyptr == ':' || isspace(*keyptr)) @@ -1864,5 +1863,5 @@ validate_name(const char *name) /* I - Name to check */ /* - * End of "$Id: lpadmin.c,v 1.29 2002/03/14 19:11:12 mike Exp $". + * End of "$Id: lpadmin.c,v 1.30 2002/05/16 13:45:04 mike Exp $". */ diff --git a/test/ipptest.c b/test/ipptest.c index 3eb2bbf69..70c87dd82 100644 --- a/test/ipptest.c +++ b/test/ipptest.c @@ -1,5 +1,5 @@ /* - * "$Id: ipptest.c,v 1.14 2002/04/09 19:27:07 mike Exp $" + * "$Id: ipptest.c,v 1.15 2002/05/16 13:45:05 mike Exp $" * * IPP test command for the Common UNIX Printing System (CUPS). * @@ -276,44 +276,44 @@ do_tests(const char *uri, /* I - URI to connect on */ if (strncasecmp(tempptr + 1, "uri", 3) == 0) { - strncpy(tokenptr, uri, sizeof(token) - 1 - (tokenptr - token)); + strlcpy(tokenptr, uri, sizeof(token) - (tokenptr - token)); tempptr += 4; } else if (strncasecmp(tempptr + 1, "method", 6) == 0) { - strncpy(tokenptr, method, sizeof(token) - 1 - (tokenptr - token)); + strlcpy(tokenptr, method, sizeof(token) - (tokenptr - token)); tempptr += 7; } else if (strncasecmp(tempptr + 1, "username", 8) == 0) { - strncpy(tokenptr, userpass, sizeof(token) - 1 - (tokenptr - token)); + strlcpy(tokenptr, userpass, sizeof(token) - (tokenptr - token)); tempptr += 9; } else if (strncasecmp(tempptr + 1, "hostname", 8) == 0) { - strncpy(tokenptr, server, sizeof(token) - 1 - (tokenptr - token)); + strlcpy(tokenptr, server, sizeof(token) - (tokenptr - token)); tempptr += 9; } else if (strncasecmp(tempptr + 1, "port", 4) == 0) { - snprintf(tokenptr, sizeof(token) - 1 - (tokenptr - token), + snprintf(tokenptr, sizeof(token) - (tokenptr - token), "%d", port); tempptr += 5; } else if (strncasecmp(tempptr + 1, "resource", 8) == 0) { - strncpy(tokenptr, resource, sizeof(token) - 1 - (tokenptr - token)); + strlcpy(tokenptr, resource, sizeof(token) - (tokenptr - token)); tempptr += 9; } else if (strncasecmp(tempptr + 1, "job-id", 6) == 0) { - snprintf(tokenptr, sizeof(token) - 1 - (tokenptr - token), + snprintf(tokenptr, sizeof(token) - (tokenptr - token), "%d", job_id); tempptr += 7; } else if (strncasecmp(tempptr + 1, "user", 4) == 0) { - strncpy(tokenptr, cupsUser(), sizeof(token) - 1 - (tokenptr - token)); + strlcpy(tokenptr, cupsUser(), sizeof(token) - (tokenptr - token)); tempptr += 5; } else @@ -822,5 +822,5 @@ print_attr(ipp_attribute_t *attr) /* I - Attribute to print */ /* - * End of "$Id: ipptest.c,v 1.14 2002/04/09 19:27:07 mike Exp $". + * End of "$Id: ipptest.c,v 1.15 2002/05/16 13:45:05 mike Exp $". */