Bug #39997 Logger::write_message() causes an assertion failure
Submitted: 13 Oct 2008 11:59 Modified: 12 Nov 2008 0:18
Reporter: Georgi Kodinov Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Backup Severity:S3 (Non-critical)
Version:6.0-bk OS:Any
Assigned to: Georgi Kodinov CPU Architecture:Any

[13 Oct 2008 11:59] Georgi Kodinov
Description:
 Logger::write_message() supplies a 0 error code to v_write_message and this causes an assertion in push_warning_printf().

Here're the fragments of the functions : 
sql/backup/logger.h:
102 inline
103 int Logger::write_message(log_level::value level, const char *msg, ...)
104 {
105   va_list args;
106    
107   va_start(args, msg);
108   int res= v_write_message(level, 0, msg, args);
109   va_end(args);
110    
111   return res;
112 }  

sql/backup/logger.cc:
105 int Logger::v_write_message(log_level::value level, int error_code,
106                             const char *format, va_list args)
107 { 
108   char buf[ERRMSGSIZE + 20];
109   
110   my_vsnprintf(buf, sizeof(buf), format, args);
111   return write_message(level, error_code, buf);
112 }  

sql/backup/logger.cc:
 33 int Logger::write_message(log_level::value level, int error_code,
 34                           const char *msg)
 35 {
 36    char buf[ERRMSGSIZE + 30];
 37    const char *out= msg; 38 
 39    if (m_state == READY || m_state == RUNNING)
 40    { 
 41      my_snprintf(buf, sizeof(buf), "%s: %s", 
 42                  m_type == BACKUP ? "Backup" : "Restore" , msg);
 43      out= buf;
 44    }
 45    
 46    switch (level) {
 47    case log_level::ERROR:
 48      if (m_save_errors)
 49        errors.push_front(new MYSQL_ERROR(::current_thd, error_code,
 50                                          MYSQL_ERROR::WARN_LEVEL_ERROR, msg)    );
 51      sql_print_error(out);
 52      push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 53                          error_code, msg); 

How to repeat:
check the code.

Suggested fix:
Remove Logger::write_message(log_level::value level, const char *msg, ...) altogether and use 
int Logger::write_message(log_level::value level, int error_code, const char *msg)
instead.
[13 Oct 2008 12:22] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/56114

2873 Georgi Kodinov	2008-10-13
      Bug #39997: Logger::write_message() causes an assertion failure
      
      Fixed by changing the error code from 0 to ER_UNKNOWN_ERROR.
      Updated the offending call to use report_error (and hence the 
      correct error code).
[13 Oct 2008 14:59] Rafal Somla
Good to push.
[10 Nov 2008 10:53] Bugs System
Pushed into 6.0.8-alpha  (revid:kgeorge@mysql.com-20081013122204-cwq58o3vtsi31kgq) (version source revid:kgeorge@mysql.com-20081013122204-cwq58o3vtsi31kgq) (pib:5)
[11 Nov 2008 16:09] Paul DuBois
The version is actually 6.0.9.
[12 Nov 2008 0:18] Paul DuBois
Noted in 6.0.9 changelog.

The MySQL Backup message logger caused an assertion failure.