Bug #47212 Crash in DBUG_PRINT in mysqltest.cc when trying to print octal number
Submitted: 9 Sep 2009 9:14 Modified: 14 Mar 2010 1:10
Reporter: Martin Skold Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.1.37 OS:Any
Assigned to: CPU Architecture:Any

[9 Sep 2009 9:14] Martin Skold
Description:
In mysqltest.cc a DBUG_PRINT statement causes crashes:
3049:  DBUG_PRINT("info", ("chmod %o %s", (uint)mode, ds_file.str));
because formating octal numbers is not supported.

How to repeat:
Run any test with --debug flag.

Suggested fix:
Either remove printout/change it or do something like:
#ifndef DBUG_OFF
{
char dbug_str[2048];
sprintf(dbug_str, "chmod %o %s", (uint)mode, ds_file.str);
DBUG_PRINT("info", ("%s", dbug_str));
}
#endif
[9 Sep 2009 17:35] Sergei Golubchik
and the correct fix is to add support for %o to my_vsnprintf(), not to remove %o from DBUG_PRINT.

When extending my_vsnprintf don't forget to document it in
include/mysql/service_my_snprintf.h
[25 Sep 2009 8:19] Sergei Golubchik
by the way, that's the patch I'll push (but not in 5.1)

=== modified file 'include/mysql/service_my_snprintf.h'
--- include/mysql/service_my_snprintf.h 2009-05-04 17:14:38 +0000
+++ include/mysql/service_my_snprintf.h 2009-09-25 07:54:34 +0000
@@ -47,7 +47,7 @@
   <length modifier> can be 'l', 'll', or 'z'.
 
   Supported formats are 's' (null pointer is accepted, printed as
-  "(null)"), 'b' (extension, see below), 'c', 'f', 'g', 'd', 'u', 'x',
+  "(null)"), 'b' (extension, see below), 'c', 'f', 'g', 'd', 'u', 'x', 'o',
   'X', 'p' (works as 0x%x).
 
   Extensions:

=== modified file 'strings/my_vsnprintf.c'
--- strings/my_vsnprintf.c      2009-07-03 05:54:09 +0000
+++ strings/my_vsnprintf.c      2009-09-25 07:54:06 +0000
@@ -265,6 +265,10 @@ static char *process_int_arg(char *to, c
     store_start[1]= 'x';
     store_end= ll2str(par, store_start + 2, 16, 0);
   }
+  else if (arg_type == 'o')
+  {
+    store_end= ll2str(par, store_start, 8, 0);
+  }
   else
   {
     DBUG_ASSERT(arg_type == 'X' || arg_type =='x');
@@ -595,7 +599,7 @@ size_t my_vsnprintf_ex(CHARSET_INFO *cs,
       to= process_dbl_arg(to, end, width, d, *fmt);
     }
     else if (*fmt == 'd' || *fmt == 'u' || *fmt == 'x' || *fmt == 'X' ||
-             *fmt == 'p')
+             *fmt == 'p' || *fmt == 'o')
     {
       /* Integer parameter */
       longlong larg;
@@ -690,6 +694,7 @@ int main()
   my_printf("Hello hhhhhhhhhhhhhh %d sssssssssssssss\n", 1);
   my_printf("Hello  %u\n", 1);
   my_printf("Hex:   %lx  '%6lx'\n", 32, 65);
+  my_printf("Octal:   %lo  '%6lo'\n", 32, 65);
   my_printf("conn %ld to: '%-.64s' user: '%-.32s' host:\
  `%-.64s' (%-.64s)", 1, 0,0,0,0);
   my_printf("My %.4f test %.4g\n", 5, 5);
[6 Mar 2010 11:07] Bugs System
Pushed into 5.5.3-m3 (revid:alik@sun.com-20100306103849-hha31z2enhh7jwt3) (version source revid:vvaintroub@fedora12-20091225154921-x25a5pyw1pxiwobv) (merge vers: 5.5.99) (pib:16)
[14 Mar 2010 1:10] Paul DuBois
Noted in 5.5.3 changelog.

Attempts to print octal numbers with my_vsnprintf() could cause a
crash.