From 148d36993eb87d9b89f0abaf19479c0881c3ad18 Mon Sep 17 00:00:00 2001 From: msweet Date: Wed, 30 Oct 2013 15:08:07 +0000 Subject: [PATCH] Fix a few STACK-detected issues: backend/ipp.c: Off-by-one error in quote_string test/ipptool.c: Avoid possible optimizer error by using ippSetCollection API. git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@11369 a1ca3aef-8c08-0410-bb20-df032aa958be --- Makefile | 27 +++++++++++- backend/ipp.c | 2 +- test/ipptool.c | 117 +++++-------------------------------------------- 3 files changed, 38 insertions(+), 108 deletions(-) diff --git a/Makefile b/Makefile index 4a637882f..4fbbb0578 100644 --- a/Makefile +++ b/Makefile @@ -128,8 +128,11 @@ depend: # -# Run the clang.llvm.org static code analysis tool on the C sources. -# (at least checker-231 is required for scan-build to work this way) +# Run the Clang static code analysis tool on the sources, available here: +# +# http://clang-analyzer.llvm.org +# +# At least checker-231 is required. # .PHONY: clang clang-changes @@ -140,6 +143,26 @@ clang-changes: scan-build -V -k -o `pwd`/clang $(MAKE) $(MFLAGS) all +# +# Run the STACK tool on the sources, available here: +# +# http://css.csail.mit.edu/stack/ +# +# Do the following to pass options to configure: +# +# make CONFIGFLAGS="--foo --bar" stack +# + +.PHONY: stack +stack: + stack-build ./configure $(CONFIGFLAGS) + stack-build $(MAKE) $(MFLAGS) clean all + poptck + $(MAKE) $(MFLAGS) distclean + $(RM) */*.ll + $(RM) */*.ll.out + + # # Generate a ctags file... # diff --git a/backend/ipp.c b/backend/ipp.c index d41e1f6db..8c297c5df 100644 --- a/backend/ipp.c +++ b/backend/ipp.c @@ -3009,7 +3009,7 @@ quote_string(const char *s, /* I - String */ { if (*s == '\\' || *s == '\"' || *s == '\'') { - if (q < (qend - 3)) + if (q < (qend - 4)) { *qptr++ = '\\'; *qptr++ = '\\'; diff --git a/test/ipptool.c b/test/ipptool.c index 18f966a82..b04630d2d 100644 --- a/test/ipptool.c +++ b/test/ipptool.c @@ -1,48 +1,18 @@ /* * "$Id$" * - * ipptool command for CUPS. + * ipptool command for CUPS. * - * Copyright 2007-2013 by Apple Inc. - * Copyright 1997-2007 by Easy Software Products. + * Copyright 2007-2013 by Apple Inc. + * Copyright 1997-2007 by Easy Software Products. * - * These coded instructions, statements, and computer programs are the - * property of Apple Inc. and are protected by Federal copyright - * law. Distribution and use rights are outlined in the file "LICENSE.txt" - * which should have been included with this file. If this file is - * file is missing or damaged, see the license at "http://www.cups.org/". + * These coded instructions, statements, and computer programs are the + * property of Apple Inc. and are protected by Federal copyright + * law. Distribution and use rights are outlined in the file "LICENSE.txt" + * which should have been included with this file. If this file is + * file is missing or damaged, see the license at "http://www.cups.org/". * - * This file is subject to the Apple OS-Developed Software exception. - * - * Contents: - * - * main() - Parse options and do tests. - * add_stringf() - Add a formatted string to an array. - * compare_vars() - Compare two variables. - * do_tests() - Do tests as specified in the test file. - * expand_variables() - Expand variables in a string. - * expect_matches() - Return true if the tag matches the specification. - * get_collection() - Get a collection value from the current test file. - * get_filename() - Get a filename based on the current test file. - * get_token() - Get a token from a file. - * get_variable() - Get the value of a variable. - * iso_date() - Return an ISO 8601 date/time string for the given IPP - * dateTime value. - * password_cb() - Password callback for authenticated tests. - * print_attr() - Print an attribute on the screen. - * print_col() - Print a collection attribute on the screen. - * print_csv() - Print a line of CSV text. - * print_fatal_error() - Print a fatal error message. - * print_line() - Print a line of formatted or CSV text. - * print_xml_header() - Print a standard XML plist header. - * print_xml_string() - Print an XML string with escaping. - * print_xml_trailer() - Print the XML trailer with success/fail value. - * set_variable() - Set a variable value. - * sigterm_handler() - Handle SIGINT and SIGTERM. - * timeout_cb() - Handle HTTP timeouts. - * usage() - Show program usage. - * validate_attr() - Determine whether an attribute is valid. - * with_value() - Test a WITH-VALUE predicate. + * This file is subject to the Apple OS-Developed Software exception. */ /* @@ -1292,39 +1262,8 @@ do_tests(_cups_vars_t *vars, /* I - Variables */ if (col) { - ipp_attribute_t *tempcol; /* Pointer to new buffer */ - - - /* - * Reallocate memory... - */ - - if ((tempcol = realloc(lastcol, sizeof(ipp_attribute_t) + - (lastcol->num_values + 1) * - sizeof(_ipp_value_t))) == NULL) - { - print_fatal_error("Unable to allocate memory on line %d.", linenum); - pass = 0; - goto test_exit; - } - - if (tempcol != lastcol) - { - /* - * Reset pointers in the list... - */ - - if (request->prev) - request->prev->next = tempcol; - else - request->attrs = tempcol; - - lastcol = request->current = request->last = tempcol; - } - - lastcol->values[lastcol->num_values].collection = col; - lastcol->num_values ++; - } + ippSetCollection(request, &lastcol, ippGetCount(lastcol), col); + } else { pass = 0; @@ -3540,39 +3479,7 @@ get_collection(_cups_vars_t *vars, /* I - Variables */ /* Collection value */ if (subcol) - { - ipp_attribute_t *tempcol; /* Pointer to new buffer */ - - - /* - * Reallocate memory... - */ - - if ((tempcol = realloc(lastcol, sizeof(ipp_attribute_t) + - (lastcol->num_values + 1) * - sizeof(_ipp_value_t))) == NULL) - { - print_fatal_error("Unable to allocate memory on line %d.", *linenum); - goto col_error; - } - - if (tempcol != lastcol) - { - /* - * Reset pointers in the list... - */ - - if (col->prev) - col->prev->next = tempcol; - else - col->attrs = tempcol; - - lastcol = col->current = col->last = tempcol; - } - - lastcol->values[lastcol->num_values].collection = subcol; - lastcol->num_values ++; - } + ippSetCollection(col, &lastcol, ippGetCount(lastcol), subcol); else goto col_error; } -- 2.39.2