]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/bsnprintf.c
ebl add sql_escape to catalog messages
[bacula/bacula] / bacula / src / lib / bsnprintf.c
index bd6c2a19d4c040611c3829717abcc349e65db712..4094e0028357aad9fc70e7c05cd1b27061f1c0eb 100644 (file)
@@ -7,7 +7,8 @@
  *
  * 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$
 
 #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
@@ -75,6 +78,7 @@ static int32_t fmtfp(char *buffer, int32_t currlen, int32_t maxlen,
 #define DP_C_INT64   4
 
 #define char_to_int(p) ((p)- '0')
+#undef MAX
 #define MAX(p,q) (((p) >= (q)) ? (p) : (q))
 
 /*
@@ -108,7 +112,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
@@ -164,11 +167,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
@@ -189,11 +188,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
@@ -217,6 +212,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;
          }