reformat and rename snprintf-cleanroom patch

This commit is contained in:
Nils Philippsen 2015-06-09 03:13:01 +02:00
parent c8f2d1fb7b
commit 569d49e769
2 changed files with 221 additions and 209 deletions

View File

@ -1,6 +1,31 @@
diff -up sane-backends-1.0.24/lib/snprintf.c.OLD sane-backends-1.0.24/lib/snprintf.c From c5210e5a183c7f0dc90a142a6bc8da96d8a2738a Mon Sep 17 00:00:00 2001
--- sane-backends-1.0.24/lib/snprintf.c.OLD 2013-02-22 21:00:56.000000000 -0500 From: Nils Philippsen <nils@redhat.com>
+++ sane-backends-1.0.24/lib/snprintf.c 2014-05-29 11:22:46.150023325 -0400 Date: Mon, 8 Jun 2015 17:50:42 +0200
Subject: [PATCH] patch: snprintf-license
Squashed commit of the following:
commit 1334efff1a6725f44d8ad11b8ba13ecf47e12ac6
Author: Tom Callaway <spot@fedoraproject.org>
Date: Thu May 29 11:40:08 2014 -0400
update lib/snprintf.c to newer version from LPRng
The old version is licensed under the Artistic License 1.0 which isn't
compatible with the GPL and arguably non-free.
Signed-off-by: Nils Philippsen <nils@redhat.com>
* fix trailing whitespace
(cherry picked from commit aa0129c4e84264a6903d2a7884298834e1be0624)
---
lib/snprintf.c | 1139 ++++++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 863 insertions(+), 276 deletions(-)
diff --git a/lib/snprintf.c b/lib/snprintf.c
index aca8df9..cdf6513 100644
--- a/lib/snprintf.c
+++ b/lib/snprintf.c
@@ -2,180 +2,616 @@ @@ -2,180 +2,616 @@
#ifndef HAVE_SNPRINTF #ifndef HAVE_SNPRINTF
@ -19,92 +44,30 @@ diff -up sane-backends-1.0.24/lib/snprintf.c.OLD sane-backends-1.0.24/lib/snprin
+ * Copyright 1994-2003 Patrick Powell, San Diego, CA <papowell@lprng.com> + * Copyright 1994-2003 Patrick Powell, San Diego, CA <papowell@lprng.com>
**************************************************************************/ **************************************************************************/
-#if 0 -#if 0
-
- The "Artistic License" - The "Artistic License"
- +/*
+ Overview:
- Preamble - Preamble
- + snprintf( char *buffer, int len, const char *format,...)
+ plp_unsafe_snprintf( char *buffer, int len, const char *format,...)
+ its horribly unsafe companion that does NOT protect you from
+ the printing of evil control characters, but may be necessary
+ See the man page documentation below
-The intent of this document is to state the conditions under which a -The intent of this document is to state the conditions under which a
-Package may be copied, such that the Copyright Holder maintains some -Package may be copied, such that the Copyright Holder maintains some
-semblance of artistic control over the development of the package, -semblance of artistic control over the development of the package,
-while giving the users of the package the right to use and distribute -while giving the users of the package the right to use and distribute
-the Package in a more-or-less customary fashion, plus the right to make -the Package in a more-or-less customary fashion, plus the right to make
-reasonable modifications. -reasonable modifications.
-
-Definitions:
-
- "Package" refers to the collection of files distributed by the
- Copyright Holder, and derivatives of that collection of files
- created through textual modification.
-
- "Standard Version" refers to such a Package if it has not been
- modified, or has been modified in accordance with the wishes
- of the Copyright Holder as specified below.
-
- "Copyright Holder" is whoever is named in the copyright or
- copyrights for the package.
-
- "You" is you, if you are thinking about copying or distributing
- this Package.
-
- "Reasonable copying fee" is whatever you can justify on the
- basis of media cost, duplication charges, time of people involved,
- and so on. (You will not be required to justify it to the
- Copyright Holder, but only to the computing community at large
- as a market that must bear the fee.)
- "Freely Available" means that no fee is charged for the item
- itself, though there may be fees involved in handling the item.
- It also means that recipients of the item may redistribute it
- under the same conditions they received it.
-
-1. You may make and give away verbatim copies of the source form of the
-Standard Version of this Package without restriction, provided that you
-duplicate all of the original copyright notices and associated disclaimers.
-
-2. You may apply bug fixes, portability fixes and other modifications
-derived from the Public Domain or from the Copyright Holder. A Package
-modified in such a way shall still be considered the Standard Version.
-
-3. You may otherwise modify your copy of this Package in any way, provided
-that you insert a prominent notice in each changed file stating how and
-when you changed that file, and provided that you do at least ONE of the
-following:
-
- a) place your modifications in the Public Domain or otherwise make them
- Freely Available, such as by posting said modifications to Usenet or
- an equivalent medium, or placing the modifications on a major archive
- site such as uunet.uu.net, or by allowing the Copyright Holder to include
- your modifications in the Standard Version of the Package.
-
- b) use the modified Package only within your corporation or organization.
-
- c) rename any non-standard executables so the names do not conflict
- with standard executables, which must also be provided, and provide
- a separate manual page for each non-standard executable that clearly
- documents how it differs from the Standard Version.
-
- d) make other distribution arrangements with the Copyright Holder.
-
-4. You may distribute the programs of this Package in object code or
-executable form, provided that you do at least ONE of the following:
+/*
+ Overview:
- a) distribute a Standard Version of the executables and library files,
- together with instructions (in the manual page or equivalent) on where
- to get the Standard Version.
+ snprintf( char *buffer, int len, const char *format,...)
+ plp_unsafe_snprintf( char *buffer, int len, const char *format,...)
+ its horribly unsafe companion that does NOT protect you from
+ the printing of evil control characters, but may be necessary
+ See the man page documentation below
+
+ This version of snprintf was developed originally for printing + This version of snprintf was developed originally for printing
+ on a motley collection of specialized hardware that had NO IO + on a motley collection of specialized hardware that had NO IO
+ library. Due to contractual restrictions, a clean room implementation + library. Due to contractual restrictions, a clean room implementation
+ of the printf() code had to be developed. + of the printf() code had to be developed.
+
-Definitions:
+ The method chosen for printf was to be as paranoid as possible, + The method chosen for printf was to be as paranoid as possible,
+ as these platforms had NO memory protection, and very small + as these platforms had NO memory protection, and very small
+ address spaces. This made it possible to try to print + address spaces. This made it possible to try to print
@ -112,14 +75,22 @@ diff -up sane-backends-1.0.24/lib/snprintf.c.OLD sane-backends-1.0.24/lib/snprin
+ against this, all printing was done via a buffer, generous enough + against this, all printing was done via a buffer, generous enough
+ to hold strings, but small enough to protect against overruns, + to hold strings, but small enough to protect against overruns,
+ etc. + etc.
+
- "Package" refers to the collection of files distributed by the
- Copyright Holder, and derivatives of that collection of files
- created through textual modification.
+ Strangely enough, this proved to be of immense importance when + Strangely enough, this proved to be of immense importance when
+ SPRINTFing to a buffer on a stack... The rest, of course, is + SPRINTFing to a buffer on a stack... The rest, of course, is
+ well known, as buffer overruns in the stack are a common way to + well known, as buffer overruns in the stack are a common way to
+ do horrible things to operating systems, security, etc etc. + do horrible things to operating systems, security, etc etc.
+
- "Standard Version" refers to such a Package if it has not been
- modified, or has been modified in accordance with the wishes
- of the Copyright Holder as specified below.
+ This version of snprintf is VERY limited by modern standards. + This version of snprintf is VERY limited by modern standards.
+
- "Copyright Holder" is whoever is named in the copyright or
- copyrights for the package.
+ Revision History: + Revision History:
+ First Released Version - 1994. This version had NO comments. + First Released Version - 1994. This version had NO comments.
+ First Released Version - 1994. This version had NO comments. + First Released Version - 1994. This version had NO comments.
@ -127,46 +98,80 @@ diff -up sane-backends-1.0.24/lib/snprintf.c.OLD sane-backends-1.0.24/lib/snprin
+ Configuration and other items changed. Read this doc. + Configuration and other items changed. Read this doc.
+ Treat this as a new version. + Treat this as a new version.
+ Minor Revision - Mon Apr 1 09:41:28 PST 2002 + Minor Revision - Mon Apr 1 09:41:28 PST 2002
+ - fixed up some constants and casts + - fixed up some constants and casts
+
- "You" is you, if you are thinking about copying or distributing
- this Package.
+ COPYRIGHT AND TERMS OF USE: + COPYRIGHT AND TERMS OF USE:
+
- "Reasonable copying fee" is whatever you can justify on the
- basis of media cost, duplication charges, time of people involved,
- and so on. (You will not be required to justify it to the
- Copyright Holder, but only to the computing community at large
- as a market that must bear the fee.)
+ You may use, copy, distribute, or otherwise incorporate this software + You may use, copy, distribute, or otherwise incorporate this software
+ and documentation into any product or other item, provided that + and documentation into any product or other item, provided that
+ the copyright in the documentation and source code as well as the + the copyright in the documentation and source code as well as the
+ source code generated constant strings in the object, executable + source code generated constant strings in the object, executable
+ or other code remain in place and are present in executable modules + or other code remain in place and are present in executable modules
+ or objects. + or objects.
+
- "Freely Available" means that no fee is charged for the item
- itself, though there may be fees involved in handling the item.
- It also means that recipients of the item may redistribute it
- under the same conditions they received it.
+ You may modify this code as appropriate to your usage; however the + You may modify this code as appropriate to your usage; however the
+ modified version must be identified by changing the various source + modified version must be identified by changing the various source
+ and object code identification strings as is appropriately noted + and object code identification strings as is appropriately noted
+ in the source code. + in the source code.
+
-1. You may make and give away verbatim copies of the source form of the
-Standard Version of this Package without restriction, provided that you
-duplicate all of the original copyright notices and associated disclaimers.
+ You can use this with the GNU CONFIGURE utility. + You can use this with the GNU CONFIGURE utility.
+ This should define the following macros appropriately: + This should define the following macros appropriately:
+
-2. You may apply bug fixes, portability fixes and other modifications
-derived from the Public Domain or from the Copyright Holder. A Package
-modified in such a way shall still be considered the Standard Version.
+ HAVE_STDARG_H - if the <stdargs.h> include file is available + HAVE_STDARG_H - if the <stdargs.h> include file is available
+ HAVE_VARARG_H - if the <varargs.h> include file is available + HAVE_VARARG_H - if the <varargs.h> include file is available
+
-3. You may otherwise modify your copy of this Package in any way, provided
-that you insert a prominent notice in each changed file stating how and
-when you changed that file, and provided that you do at least ONE of the
-following:
+ HAVE_STRERROR - if the strerror() routine is available. + HAVE_STRERROR - if the strerror() routine is available.
+ If it is not available, then examine the lines containing + If it is not available, then examine the lines containing
+ the tests below. + the tests below.
+
- a) place your modifications in the Public Domain or otherwise make them
- Freely Available, such as by posting said modifications to Usenet or
- an equivalent medium, or placing the modifications on a major archive
- site such as uunet.uu.net, or by allowing the Copyright Holder to include
- your modifications in the Standard Version of the Package.
+ HAVE_SYS_ERRLIST - have sys_errlist available + HAVE_SYS_ERRLIST - have sys_errlist available
+ HAVE_DECL_SYS_ERRLIST - sys_errlist declaration in include files + HAVE_DECL_SYS_ERRLIST - sys_errlist declaration in include files
+ HAVE_SYS_NERR - have sys_nerr available + HAVE_SYS_NERR - have sys_nerr available
+ HAVE_DECL_SYS_NERR - sys_nerr declaration in include files + HAVE_DECL_SYS_NERR - sys_nerr declaration in include files
+
- b) use the modified Package only within your corporation or organization.
+ HAVE_QUAD_T - if the quad_t type is defined + HAVE_QUAD_T - if the quad_t type is defined
+ HAVE_LONG_LONG - if the long long type is defined + HAVE_LONG_LONG - if the long long type is defined
+ HAVE_LONG_DOUBLE - if the long double type is defined + HAVE_LONG_DOUBLE - if the long double type is defined
+
- c) rename any non-standard executables so the names do not conflict
- with standard executables, which must also be provided, and provide
- a separate manual page for each non-standard executable that clearly
- documents how it differs from the Standard Version.
+ If you are using the GNU configure (autoconf) facility, add the + If you are using the GNU configure (autoconf) facility, add the
+ following line to the configure.in file, to force checking for the + following line to the configure.in file, to force checking for the
+ quad_t and long long data types: + quad_t and long long data types:
+
+ - d) make other distribution arrangements with the Copyright Holder.
-4. You may distribute the programs of this Package in object code or
-executable form, provided that you do at least ONE of the following:
+ AC_CHECK_HEADERS(stdlib.h,stdio.h,unistd.h,errno.h) + AC_CHECK_HEADERS(stdlib.h,stdio.h,unistd.h,errno.h)
+ AC_CHECK_FUNCS(strerror) + AC_CHECK_FUNCS(strerror)
+ AC_CACHE_CHECK(for errno, + AC_CACHE_CHECK(for errno,
@ -197,7 +202,10 @@ diff -up sane-backends-1.0.24/lib/snprintf.c.OLD sane-backends-1.0.24/lib/snprin
+ AC_DEFINE(HAVE_DECL_ERRNO) + AC_DEFINE(HAVE_DECL_ERRNO)
+ fi; + fi;
+ fi + fi
+
- a) distribute a Standard Version of the executables and library files,
- together with instructions (in the manual page or equivalent) on where
- to get the Standard Version.
+ AC_CACHE_CHECK(for sys_nerr, + AC_CACHE_CHECK(for sys_nerr,
+ ac_cv_sys_nerr, + ac_cv_sys_nerr,
+ [ + [
@ -223,8 +231,13 @@ diff -up sane-backends-1.0.24/lib/snprintf.c.OLD sane-backends-1.0.24/lib/snprin
+ AC_DEFINE(HAVE_DECL_SYS_NERR) + AC_DEFINE(HAVE_DECL_SYS_NERR)
+ fi + fi
+ fi + fi
+
+ - b) accompany the distribution with the machine-readable source of
- the Package with your modifications.
- c) give non-standard executables non-standard names, and clearly
- document the differences in manual pages (or equivalent), together
- with instructions on where to get the Standard Version.
+ AC_CACHE_CHECK(for sys_errlist array, + AC_CACHE_CHECK(for sys_errlist array,
+ ac_cv_sys_errlist, + ac_cv_sys_errlist,
+ [AC_TRY_LINK(,[extern char *sys_errlist[]; + [AC_TRY_LINK(,[extern char *sys_errlist[];
@ -250,9 +263,19 @@ diff -up sane-backends-1.0.24/lib/snprintf.c.OLD sane-backends-1.0.24/lib/snprin
+ AC_DEFINE(HAVE_DECL_SYS_ERRLIST) + AC_DEFINE(HAVE_DECL_SYS_ERRLIST)
+ fi + fi
+ fi + fi
+
+ - d) make other distribution arrangements with the Copyright Holder.
+
-5. You may charge a reasonable copying fee for any distribution of this
-Package. You may charge any fee you choose for support of this
-Package. You may not charge a fee for this Package itself. However,
-you may distribute this Package in aggregate with other (possibly
-commercial) programs as part of a larger (possibly commercial) software
-distribution provided that you do not advertise this Package as a
-product of your own.
-6. The name of the Copyright Holder may not be used to endorse or promote
-products derived from this software without specific prior written permission.
+ AC_CACHE_CHECK(checking for long long, + AC_CACHE_CHECK(checking for long long,
+ ac_cv_long_long, + ac_cv_long_long,
+ [ + [
@ -265,7 +288,10 @@ diff -up sane-backends-1.0.24/lib/snprintf.c.OLD sane-backends-1.0.24/lib/snprin
+ if test $ac_cv_long_long = yes; then + if test $ac_cv_long_long = yes; then
+ AC_DEFINE(HAVE_LONG_LONG) + AC_DEFINE(HAVE_LONG_LONG)
+ fi + fi
+
-7. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
-IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
-WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ AC_CACHE_CHECK(checking for long double, + AC_CACHE_CHECK(checking for long double,
+ ac_cv_long_double, + ac_cv_long_double,
+ [ + [
@ -278,7 +304,10 @@ diff -up sane-backends-1.0.24/lib/snprintf.c.OLD sane-backends-1.0.24/lib/snprin
+ if test $ac_cv_long_double = yes; then + if test $ac_cv_long_double = yes; then
+ AC_DEFINE(HAVE_LONG_DOUBLE) + AC_DEFINE(HAVE_LONG_DOUBLE)
+ fi + fi
+
- The End
-#include "lp.h"
-#endif
+ AC_CACHE_CHECK(checking for quad_t, + AC_CACHE_CHECK(checking for quad_t,
+ ac_cv_quad_t, + ac_cv_quad_t,
+ [ + [
@ -291,9 +320,19 @@ diff -up sane-backends-1.0.24/lib/snprintf.c.OLD sane-backends-1.0.24/lib/snprin
+ if test $ac_cv_quad_t = yes; then + if test $ac_cv_quad_t = yes; then
+ AC_DEFINE(HAVE_QUAD_T) + AC_DEFINE(HAVE_QUAD_T)
+ fi + fi
+
+ -#include <stdarg.h>
+ -#include <errno.h>
-#include <sys/types.h>
-#define HAVE_STDARGS /* let's hope that works everywhere (mj) */
-#define VA_LOCAL_DECL va_list ap;
-#define VA_START(f) va_start(ap, f)
-#define VA_SHIFT(v,t) ; /* no-op for ANSI */
-#define VA_END va_end(ap)
-/**** ENDINCLUDE ****/
-static char *const _id = "$Id$";
+ NAME + NAME
+ snprintf, plp_vsnprintf - formatted output conversion + snprintf, plp_vsnprintf - formatted output conversion
+ +
@ -535,25 +574,12 @@ diff -up sane-backends-1.0.24/lib/snprintf.c.OLD sane-backends-1.0.24/lib/snprin
+ benign effect (i.e., none) of the `#' flag on %n and %p conversions, as + benign effect (i.e., none) of the `#' flag on %n and %p conversions, as
+ well as other nonsensical combinations such as %Ld, are not standard; + well as other nonsensical combinations such as %Ld, are not standard;
+ such combinations should be avoided. + such combinations should be avoided.
+
- b) accompany the distribution with the machine-readable source of
- the Package with your modifications.
+ The typedef names quad_t and u_quad_t are infelicitous. + The typedef names quad_t and u_quad_t are infelicitous.
+
- c) give non-standard executables non-standard names, and clearly
- document the differences in manual pages (or equivalent), together
- with instructions on where to get the Standard Version.
+*/ +*/
+
- d) make other distribution arrangements with the Copyright Holder. +
-5. You may charge a reasonable copying fee for any distribution of this
-Package. You may charge any fee you choose for support of this
-Package. You may not charge a fee for this Package itself. However,
-you may distribute this Package in aggregate with other (possibly
-commercial) programs as part of a larger (possibly commercial) software
-distribution provided that you do not advertise this Package as a
-product of your own.
+#include <sys/types.h> +#include <sys/types.h>
+#include <ctype.h> +#include <ctype.h>
+#include <stdlib.h> +#include <stdlib.h>
@ -568,30 +594,24 @@ diff -up sane-backends-1.0.24/lib/snprintf.c.OLD sane-backends-1.0.24/lib/snprin
+#include <errno.h> +#include <errno.h>
+#endif +#endif
-6. The name of the Copyright Holder may not be used to endorse or promote /*
-products derived from this software without specific prior written permission. - * dopr(): poor man's version of doprintf
+/*
+ * For testing, define these values + * For testing, define these values
+ */ */
+#if 0 +#if 0
+#define HAVE_STDARG_H 1 +#define HAVE_STDARG_H 1
+#define TEST 1 +#define TEST 1
+#define HAVE_QUAD_T 1 +#define HAVE_QUAD_T 1
+#endif +#endif
+
-7. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
-IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
-WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+/**** ENDINCLUDE ****/ +/**** ENDINCLUDE ****/
+
- The End
-#include "lp.h"
+/************************************************* +/*************************************************
+ * KEEP THIS STRING - MODIFY AT THE END WITH YOUR REVISIONS + * KEEP THIS STRING - MODIFY AT THE END WITH YOUR REVISIONS
+ * i.e. - the LOCAL REVISIONS part is for your use + * i.e. - the LOCAL REVISIONS part is for your use
+ *************************************************/ + *************************************************/
+ +
+ +
+ static char *const _id = "plp_snprintf V2000.08.18 Copyright Patrick Powell 1988-2000 " + static char *const _id = "plp_snprintf V2000.08.18 Copyright Patrick Powell 1988-2000 "
+ "$Id: plp_snprintf.c,v 1.4 2005/04/14 20:05:19 papowell Exp $" + "$Id: plp_snprintf.c,v 1.4 2005/04/14 20:05:19 papowell Exp $"
+ " LOCAL REVISIONS: renamed plp_snprintf to snprintf, conditionalized everything on HAVE_SNPRINTF"; + " LOCAL REVISIONS: renamed plp_snprintf to snprintf, conditionalized everything on HAVE_SNPRINTF";
@ -622,18 +642,12 @@ diff -up sane-backends-1.0.24/lib/snprintf.c.OLD sane-backends-1.0.24/lib/snprin
+# else +# else
+ XX ** NO VARARGS ** XX + XX ** NO VARARGS ** XX
+# endif +# endif
#endif +#endif
-#include <stdarg.h> -static char * plp_Errormsg ( int err );
-#include <errno.h> -static void dopr( char *buffer, const char *format, va_list args );
-#include <sys/types.h> -static void fmtstr( char *value, int ljust, int len, int zpad, int precision );
-#define HAVE_STDARGS /* let's hope that works everywhere (mj) */ -static void fmtnum( long value, int base, int dosign,
-#define VA_LOCAL_DECL va_list ap;
-#define VA_START(f) va_start(ap, f)
-#define VA_SHIFT(v,t) ; /* no-op for ANSI */
-#define VA_END va_end(ap)
-
-/**** ENDINCLUDE ****/
+ union value { + union value {
+#if defined(HAVE_QUAD_T) +#if defined(HAVE_QUAD_T)
+ quad_t qvalue; + quad_t qvalue;
@ -645,20 +659,12 @@ diff -up sane-backends-1.0.24/lib/snprintf.c.OLD sane-backends-1.0.24/lib/snprin
+#endif +#endif
+ double dvalue; + double dvalue;
+}; +};
+
-static char *const _id = "$Id$"; +#undef CVAL
+#undef CVAL
+#define CVAL(s) (*((unsigned char *)s)) +#define CVAL(s) (*((unsigned char *)s))
+#define safestrlen(s) ((s)?strlen(s):0) +#define safestrlen(s) ((s)?strlen(s):0)
+
-/* +
- * dopr(): poor man's version of doprintf
- */
-static char * plp_Errormsg ( int err );
-static void dopr( char *buffer, const char *format, va_list args );
-static void fmtstr( char *value, int ljust, int len, int zpad, int precision );
-static void fmtnum( long value, int base, int dosign,
+ static char * plp_Errormsg ( int err, char *buffer ); + static char * plp_Errormsg ( int err, char *buffer );
+ static void dopr( int visible_control, char **buffer, int *left, + static void dopr( int visible_control, char **buffer, int *left,
+ const char *format, va_list args ); + const char *format, va_list args );
@ -697,12 +703,6 @@ diff -up sane-backends-1.0.24/lib/snprintf.c.OLD sane-backends-1.0.24/lib/snprin
- **************************************************************/ - **************************************************************/
- -
-int vsnprintf(char *str, size_t count, const char *fmt, va_list args) -int vsnprintf(char *str, size_t count, const char *fmt, va_list args)
-{
- str[0] = 0;
- end = str+count-1;
- dopr( str, fmt, args );
- if( count>0 ){
- end[0] = 0;
+ static void dostr( char **buffer, int *left, char *str ); + static void dostr( char **buffer, int *left, char *str );
+ static void dopr_outch( char **buffer, int *left, int c ); + static void dopr_outch( char **buffer, int *left, int c );
+/* VARARGS3 */ +/* VARARGS3 */
@ -738,7 +738,12 @@ diff -up sane-backends-1.0.24/lib/snprintf.c.OLD sane-backends-1.0.24/lib/snprin
+#else +#else
+ int plp_unsafe_vsnprintf(char *str, size_t count, const char *fmt, va_list args) + int plp_unsafe_vsnprintf(char *str, size_t count, const char *fmt, va_list args)
+#endif +#endif
+{ {
- str[0] = 0;
- end = str+count-1;
- dopr( str, fmt, args );
- if( count>0 ){
- end[0] = 0;
+ int left; + int left;
+ char *buffer; + char *buffer;
+ if( (int)count < 0 ) count = 0; + if( (int)count < 0 ) count = 0;
@ -822,7 +827,7 @@ diff -up sane-backends-1.0.24/lib/snprintf.c.OLD sane-backends-1.0.24/lib/snprin
char *strvalue; char *strvalue;
int ljust; int ljust;
int len; int len;
@@ -207,22 +669,30 @@ static void dopr( char *buffer, const ch @@ -207,22 +669,30 @@ static void dopr( char *buffer, const char *format, va_list args )
int set_precision; int set_precision;
double dval; double dval;
int err = errno; int err = errno;
@ -837,7 +842,8 @@ diff -up sane-backends-1.0.24/lib/snprintf.c.OLD sane-backends-1.0.24/lib/snprin
+ longflag = quadflag = + longflag = quadflag =
+ ljust = len = zpad = base = signed_val = 0; + ljust = len = zpad = base = signed_val = 0;
precision = -1; set_precision = 0; precision = -1; set_precision = 0;
nextch: - nextch:
+ nextch:
ch = *format++; ch = *format++;
switch( ch ){ switch( ch ){
case 0: case 0:
@ -857,7 +863,7 @@ diff -up sane-backends-1.0.24/lib/snprintf.c.OLD sane-backends-1.0.24/lib/snprin
case '0': /* set zero padding if len not set */ case '0': /* set zero padding if len not set */
if(len==0 && set_precision == 0 ) zpad = '0'; if(len==0 && set_precision == 0 ) zpad = '0';
case '1': case '2': case '3': case '1': case '2': case '3':
@@ -234,76 +704,91 @@ static void dopr( char *buffer, const ch @@ -234,76 +704,91 @@ static void dopr( char *buffer, const char *format, va_list args )
len = len*10 + ch - '0'; len = len*10 + ch - '0';
} }
goto nextch; goto nextch;
@ -992,7 +998,7 @@ diff -up sane-backends-1.0.24/lib/snprintf.c.OLD sane-backends-1.0.24/lib/snprin
} }
/* /*
@@ -312,63 +797,69 @@ static void dopr( char *buffer, const ch @@ -312,63 +797,69 @@ static void dopr( char *buffer, const char *format, va_list args )
* len = minimum length * len = minimum length
* precision = numbers of chars in string to use * precision = numbers of chars in string to use
*/ */
@ -1022,11 +1028,11 @@ diff -up sane-backends-1.0.24/lib/snprintf.c.OLD sane-backends-1.0.24/lib/snprin
+ ++strlenv; + ++strlenv;
} }
+ ++strlenv; + ++strlenv;
} + }
- padlen = len - strlen;
+ if( precision > 0 && strlenv > precision ){ + if( precision > 0 && strlenv > precision ){
+ strlenv = precision; + strlenv = precision;
+ } }
- padlen = len - strlen;
+ padlen = len - strlenv; + padlen = len - strlenv;
if( padlen < 0 ) padlen = 0; if( padlen < 0 ) padlen = 0;
if( ljust ) padlen = -padlen; if( ljust ) padlen = -padlen;
@ -1084,11 +1090,11 @@ diff -up sane-backends-1.0.24/lib/snprintf.c.OLD sane-backends-1.0.24/lib/snprin
+ if( value->value < 0 ) { + if( value->value < 0 ) {
signvalue = '-'; signvalue = '-';
- uvalue = -value; - uvalue = -value;
+ uvalue = -value->value; + uvalue = -value->value;
} }
} }
if( base < 0 ){ if( base < 0 ){
@@ -385,71 +876,148 @@ fmtnum( long value, int base, int dosig @@ -385,71 +876,148 @@ fmtnum( long value, int base, int dosign, int ljust,
padlen = len - place; padlen = len - place;
if( padlen < 0 ) padlen = 0; if( padlen < 0 ) padlen = 0;
if( ljust ) padlen = -padlen; if( ljust ) padlen = -padlen;
@ -1151,28 +1157,23 @@ diff -up sane-backends-1.0.24/lib/snprintf.c.OLD sane-backends-1.0.24/lib/snprin
+ /* fprintf(stderr,"value 0x%x, base %d, dosign %d, ljust %d, len %d, zpad %d\n", + /* fprintf(stderr,"value 0x%x, base %d, dosign %d, ljust %d, len %d, zpad %d\n",
+ value, base, dosign, ljust, len, zpad );/ **/ + value, base, dosign, ljust, len, zpad );/ **/
+ vvalue.qvalue = value->qvalue; + vvalue.qvalue = value->qvalue;
+
+ if( base < 0 ){
+ caps = 1;
+ }
- if( len == 0 ) len = 10; - if( len == 0 ) len = 10;
- if( len > sizeof(convert) - 10 ){ - if( len > sizeof(convert) - 10 ){
- len = sizeof(convert) - 10; - len = sizeof(convert) - 10;
+ if( base < 0 ){ + for( i = 0; i < (int)sizeof(quad_t); ++i ){
+ caps = 1; + c = vvalue.qconvert[i];
+ convert[2*i] =
+ (caps? "0123456789ABCDEF":"0123456789abcdef")[ (c >> 4) & 0xF];
+ convert[2*i+1] =
+ (caps? "0123456789ABCDEF":"0123456789abcdef")[ c & 0xF];
} }
- if( precision > sizeof(convert) - 10 ){ - if( precision > sizeof(convert) - 10 ){
- precision = sizeof(convert) - 10; - precision = sizeof(convert) - 10;
+
+ for( i = 0; i < (int)sizeof(quad_t); ++i ){
+ c = vvalue.qconvert[i];
+ convert[2*i] =
+ (caps? "0123456789ABCDEF":"0123456789abcdef")[ (c >> 4) & 0xF];
+ convert[2*i+1] =
+ (caps? "0123456789ABCDEF":"0123456789abcdef")[ c & 0xF];
}
- if( precision > len ) precision = len;
- strcpy( fmtstr, "%" );
- if( ljust ) strcat(fmtstr, "-" );
- if( len ){
- sprintf( fmtstr+strlen(fmtstr), "%d", len );
+ convert[2*i] = 0; + convert[2*i] = 0;
+ +
+ place = strlen(convert); + place = strlen(convert);
@ -1191,23 +1192,37 @@ diff -up sane-backends-1.0.24/lib/snprintf.c.OLD sane-backends-1.0.24/lib/snprin
+ dopr_outch( buffer, left, zpad ); + dopr_outch( buffer, left, zpad );
+ --padlen; + --padlen;
+ } + }
+ } }
- if( precision > len ) precision = len;
- strcpy( fmtstr, "%" );
- if( ljust ) strcat(fmtstr, "-" );
- if( len ){
- sprintf( fmtstr+strlen(fmtstr), "%d", len );
+ while( padlen > 0 ) { + while( padlen > 0 ) {
+ dopr_outch( buffer, left, ' ' ); + dopr_outch( buffer, left, ' ' );
+ --padlen; + --padlen;
+ } }
- if( precision > 0 ){
- sprintf( fmtstr+strlen(fmtstr), ".%d", precision );
+ if( signvalue ) dopr_outch( buffer, left, signvalue ); + if( signvalue ) dopr_outch( buffer, left, signvalue );
+ while( place > 0 ) dopr_outch( buffer, left, convert[--place] ); + while( place > 0 ) dopr_outch( buffer, left, convert[--place] );
+ while( padlen < 0 ){ + while( padlen < 0 ){
+ dopr_outch( buffer, left, ' ' ); + dopr_outch( buffer, left, ' ' );
+ ++padlen; + ++padlen;
+ } }
+} - l = strlen( fmtstr );
+ - fmtstr[l] = fmt;
- fmtstr[l+1] = 0;
- sprintf( convert, fmtstr, value );
- dostr( convert );
}
-static void dostr( char *str )
+#endif +#endif
+ +
+ static void mystrcat(char *dest, char *src ) + static void mystrcat(char *dest, char *src )
+{ {
- while(*str) dopr_outch(*str++);
+ if( dest && src ){ + if( dest && src ){
+ dest += safestrlen(dest); + dest += safestrlen(dest);
+ strcpy(dest,src); + strcpy(dest,src);
@ -1234,29 +1249,20 @@ diff -up sane-backends-1.0.24/lib/snprintf.c.OLD sane-backends-1.0.24/lib/snprin
+ if( zpad ) mystrcat(formatstr, "0" ); /* 1 */ + if( zpad ) mystrcat(formatstr, "0" ); /* 1 */
+ if( len >= 0 ){ + if( len >= 0 ){
+ sprintf( formatstr+strlen(formatstr), "%d", len ); /* 3 */ + sprintf( formatstr+strlen(formatstr), "%d", len ); /* 3 */
} + }
- if( precision > 0 ){
- sprintf( fmtstr+strlen(fmtstr), ".%d", precision );
+ if( precision >= 0 ){ + if( precision >= 0 ){
+ sprintf( formatstr+strlen(formatstr), ".%d", precision ); /* 3 */ + sprintf( formatstr+strlen(formatstr), ".%d", precision ); /* 3 */
} + }
- l = strlen( fmtstr );
- fmtstr[l] = fmt;
- fmtstr[l+1] = 0;
- sprintf( convert, fmtstr, value );
- dostr( convert );
+ /* format string will be at most 10 chars long ... */ + /* format string will be at most 10 chars long ... */
+ sprintf( formatstr+strlen(formatstr), "%c", fmt ); + sprintf( formatstr+strlen(formatstr), "%c", fmt );
+ /* this is easier than trying to do the portable dtostr */ + /* this is easier than trying to do the portable dtostr */
+ /* fprintf(stderr,"format string '%s'\n", formatstr); */ + /* fprintf(stderr,"format string '%s'\n", formatstr); */
+ sprintf( convert, formatstr, value ); + sprintf( convert, formatstr, value );
+ dostr( buffer, left, convert ); + dostr( buffer, left, convert );
} +}
+
-static void dostr( char *str )
+ static void dostr( char **buffer, int *left, char *str ) + static void dostr( char **buffer, int *left, char *str )
{ +{
- while(*str) dopr_outch(*str++);
+ if(str)while(*str) dopr_outch( buffer, left, *str++ ); + if(str)while(*str) dopr_outch( buffer, left, *str++ );
} }
@ -1388,3 +1394,6 @@ diff -up sane-backends-1.0.24/lib/snprintf.c.OLD sane-backends-1.0.24/lib/snprin
return(0); return(0);
} }
#endif #endif
--
2.4.2

View File

@ -79,7 +79,7 @@ Patch7: sane-backends-1.0.24-scsi-permissions.patch
Patch8: sane-backends-1.0.24-format-security.patch Patch8: sane-backends-1.0.24-format-security.patch
# Update lib/snprintf.c to latest from LPRng to resolve # Update lib/snprintf.c to latest from LPRng to resolve
# license issue (#1102520) # license issue (#1102520)
Patch9: sane-backends-1.0.24-update-to-current-lprng-plp_snprintf.patch Patch9: sane-backends-1.0.24-snprintf-cleanroom.patch
URL: http://www.sane-project.org URL: http://www.sane-project.org
@ -197,7 +197,7 @@ This package contains backend drivers to access digital cameras through SANE.
%patch6 -p1 -b .static-code-check %patch6 -p1 -b .static-code-check
%patch7 -p1 -b .scsi-permissions %patch7 -p1 -b .scsi-permissions
%patch8 -p1 -b .format-security %patch8 -p1 -b .format-security
%patch9 -p1 -b .snprintf %patch9 -p1 -b .snprintf-cleanroom
%build %build
CFLAGS="%optflags -fno-strict-aliasing" CFLAGS="%optflags -fno-strict-aliasing"
@ -319,6 +319,9 @@ udevadm hwdb --update >/dev/null 2>&1 || :
%{_libdir}/sane/*gphoto2.so* %{_libdir}/sane/*gphoto2.so*
%changelog %changelog
* Tue Jun 09 2015 Nils Philippsen <nils@redhat.com>
- reformat and rename snprintf-cleanroom patch
* Mon Jun 08 2015 Nils Philippsen <nils@redhat.com> * Mon Jun 08 2015 Nils Philippsen <nils@redhat.com>
- apply format-security patch, drop format-security2 patch - apply format-security patch, drop format-security2 patch