Summary: | ASTERISK-10137: Asterisk crashed in function ast_dynamic_str_thread_build_va in utils.c | ||
Reporter: | Jon Creasy (johann8384) | Labels: | |
Date Opened: | 2007-08-21 20:42:03 | Date Closed: | 2007-08-23 12:05:17 |
Priority: | Critical | Regression? | No |
Status: | Closed/Complete | Components: | Addons/General |
Versions: | Frequency of Occurrence | ||
Related Issues: | |||
Environment: | Attachments: | ( 0) output_better.txt | |
Description: | johann8384 - reporter 08-21-07 20:28 I know it will be obvious to you when you look at this but I'm trying to learn a little bit as I go along so hopefully I'll be fixing stuff myself before long. To me the problem looks like it's crashing trying to print to the return value of a vsnprintf to an int res in ast_dynamic_str_thread_build_va. The message is "Variable 'res' is not available". My C is weak, that is line 1200, line 1194 is "int res;". 3 0x080fbf87 in ast_dynamic_str_thread_build_va (buf=0xb7e7233c, max_len=8192, ts=0x825cd60, append=0, fmt=0x281380 "MySQL RealTime: Database Select Failed (%d): %s\n", ap=0xb7e74664 "S%(") at utils.c:1200 res = Variable "res" is not available. /*! * core handler for dynamic strings. * This is not meant to be called directly, but rather through the * various wrapper macros * ast_str_set(...) * ast_str_append(...) * ast_str_set_va(...) * ast_str_append_va(...) */ int __ast_str_helper(struct ast_str **buf, size_t max_len, int append, const char *fmt, va_list ap) { int res, need; int offset = (append && (*buf)->len) ? (*buf)->used : 0; if (max_len < 0) max_len = (*buf)->len; /* don't exceed the allocated space */ /* * Ask vsnprintf how much space we need. Remember that vsnprintf * does not count the final '\0' so we must add 1. */ res = vsnprintf((*buf)->str + offset, (*buf)->len - offset, fmt, ap); need = res + offset + 1; /* * If there is not enough space and we are below the max length, * reallocate the buffer and return a message telling to retry. */ if (need > (*buf)->len && (max_len == 0 || (*buf)->len < max_len) ) { if (max_len && max_len < need) /* truncate as needed */ need = max_len; else if (max_len == 0) /* if unbounded, give more room for next time */ need += 16 + need/4; if (0) /* debugging */ ast_verbose("extend from %d to %d\n", (int)(*buf)->len, need); if (ast_str_make_space(buf, need)) { ast_verbose("failed to extend from %d to %d\n", (int)(*buf)->len, need); return AST_DYNSTR_BUILD_FAILED; } (*buf)->str[offset] = '\0'; /* Truncate the partial write. */ /* va_end() and va_start() must be done before calling * vsnprintf() again. */ return AST_DYNSTR_BUILD_RETRY; } /* update space used, keep in mind the truncation */ (*buf)->used = (res + offset > (*buf)->len) ? (*buf)->len : res + offset; return res; } ****** ADDITIONAL INFORMATION ****** I also mentioned this while trying to debug another problem in 10348 but I don't think this has anything to do with that (I realized later) so I'm posting here in case this is something. | ||
Comments: | By: Digium Subversion (svnbot) 2007-08-23 12:03:42 Repository: asterisk-addons Revision: 428 ------------------------------------------------------------------------ r428 | russell | 2007-08-23 12:03:42 -0500 (Thu, 23 Aug 2007) | 4 lines Fix a format string error that caused a crash. This debug message tried to print something as string that was just an int. (closes issue ASTERISK-10137, reported by johann8384, patch by me) ------------------------------------------------------------------------ By: Digium Subversion (svnbot) 2007-08-23 12:05:17 Repository: asterisk-addons Revision: 429 ------------------------------------------------------------------------ r429 | russell | 2007-08-23 12:05:17 -0500 (Thu, 23 Aug 2007) | 12 lines Merged revisions 428 via svnmerge from https://origsvn.digium.com/svn/asterisk-addons/branches/1.4 ........ r428 | russell | 2007-08-23 12:21:44 -0500 (Thu, 23 Aug 2007) | 4 lines Fix a format string error that caused a crash. This debug message tried to print something as string that was just an int. (closes issue ASTERISK-10137, reported by johann8384, patch by me) ........ ------------------------------------------------------------------------ |