]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/bsnprintf.c
kes Add dynamic dll entry point for SHGetFolderPath to Win32 code.
[bacula/bacula] / bacula / src / lib / bsnprintf.c
index 57f556df9d66ed2841112c840df02a4ad64fb5d0..1d1d2553c2352291380f79d58fd4ba4397e04d38 100644 (file)
@@ -7,20 +7,51 @@
  *
  * Adapted for Bacula -- note there were lots of bugs in
  *     the original code: %lld and %s were seriously broken, and
- *     with FP turned off %f seg faults.
+ *     with FP turned off %f seg faulted.
+ *
  *   Kern Sibbald, November MMV
  *
  *   Version $Id$
  */
+/*
+   Bacula® - The Network Backup Solution
+
+   Copyright (C) 2005-2006 Free Software Foundation Europe e.V.
+
+   The main author of Bacula is Kern Sibbald, with contributions from
+   many others, a complete list can be found in the file AUTHORS.
+   This program is Free Software; you can redistribute it and/or
+   modify it under the terms of version two of the GNU General Public
+   License as published by the Free Software Foundation plus additions
+   that are listed in the file LICENSE.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+   Bacula® is a registered trademark of John Walker.
+   The licensor of Bacula is the Free Software Foundation Europe
+   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+   Switzerland, email:ftf@fsfeurope.org.
+*/
+
 
 
 #include "bacula.h"
 #define FP_OUTPUT 1 /* Bacula uses floating point */
-
-/* 
-    Temp only for me -- NOT YET READY FOR USE -- seems to work fine
-    on Linux, but doesn't build correctly on Win32
+/* Define the following if you want all the features of
+ *  normal printf, but with all the security problems.
+ *  For Bacula we turn this off, and it silently ignores
+ *  formats that could pose a security problem.
  */
+#undef SECURITY_PROBLEM 
+
 #ifdef USE_BSNPRINTF
 
 #ifdef HAVE_LONG_DOUBLE
@@ -109,7 +140,6 @@ int bvsnprintf(char *buffer, int32_t maxlen, const char *format, va_list args)
    int cflags;
    int32_t currlen;
    int base;
-   int junk;
 #ifdef FP_OUTPUT
    LDOUBLE fvalue;
 #endif
@@ -165,11 +195,7 @@ int bvsnprintf(char *buffer, int32_t maxlen, const char *format, va_list args)
             min = 10 * min + char_to_int(ch);
             ch = *format++;
          } else if (ch == '*') {
-#ifdef SECURITY_PROBLEM
             min = va_arg(args, int);
-#else
-            junk = va_arg(args, int);
-#endif
             ch = *format++;
             state = DP_S_DOT;
          } else
@@ -190,11 +216,7 @@ int bvsnprintf(char *buffer, int32_t maxlen, const char *format, va_list args)
             max = 10 * max + char_to_int(ch);
             ch = *format++;
          } else if (ch == '*') {
-#ifdef SECURITY_PROBLEM
             max = va_arg(args, int);
-#else
-            junk = va_arg(args, int);
-#endif
             ch = *format++;
             state = DP_S_MOD;
          } else
@@ -218,6 +240,10 @@ int bvsnprintf(char *buffer, int32_t maxlen, const char *format, va_list args)
             cflags = DP_C_LDOUBLE;
             ch = *format++;
             break;
+         case 'q':                 /* same as long long */
+            cflags = DP_C_INT64;
+            ch = *format++;
+            break;
          default:
             break;
          }
@@ -256,11 +282,11 @@ int bvsnprintf(char *buffer, int32_t maxlen, const char *format, va_list args)
             if (cflags == DP_C_INT16) {
                value = va_arg(args, uint32_t);
             } else if (cflags == DP_C_INT32) {
-               value = (long)va_arg(args, uint32_t);
+               value = va_arg(args, uint32_t);
             } else if (cflags == DP_C_INT64) {
-               value = (int64_t) va_arg(args, uint64_t);
+               value = va_arg(args, uint64_t);
             } else {
-               value = (long)va_arg(args, unsigned int);
+               value = va_arg(args, unsigned int);
             }
             currlen = fmtint(buffer, currlen, maxlen, value, base, min, max, flags);
             break;