[asterisk-bugs] [Asterisk 0010520]: Asterisk crashed in function ast_dynamic_str_thread_build_va in utils.c

noreply at bugs.digium.com noreply at bugs.digium.com
Thu Aug 23 12:03:42 CDT 2007


The following issue has been ASSIGNED. 
====================================================================== 
http://bugs.digium.com/view.php?id=10520 
====================================================================== 
Reported By:                johann8384
Assigned To:                russell
====================================================================== 
Project:                    Asterisk
Issue ID:                   10520
Category:                   Addons/General
Reproducibility:            unable to reproduce
Severity:                   crash
Priority:                   normal
Status:                     assigned
Asterisk Version:           1.4.10.1  
SVN Branch (only for SVN checkouts, not tarball releases): N/A  
SVN Revision (number only!):  
Disclaimer on File?:        N/A 
Request Review:              
====================================================================== 
Date Submitted:             08-21-2007 20:42 CDT
Last Modified:              08-23-2007 12:03 CDT
====================================================================== 
Summary:                    Asterisk crashed in function
ast_dynamic_str_thread_build_va in utils.c
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;
}
====================================================================== 

---------------------------------------------------------------------- 
 svnbot - 08-23-07 12:03  
---------------------------------------------------------------------- 
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 http://bugs.digium.com/view.php?id=10520, reported by johann8384,
patch by me)

------------------------------------------------------------------------ 

Issue History 
Date Modified   Username       Field                    Change               
====================================================================== 
08-23-07 12:03  svnbot         Checkin                                      
08-23-07 12:03  svnbot         Note Added: 0069309                          
08-23-07 12:03  svnbot         Status                   new => assigned     
08-23-07 12:03  svnbot         Assigned To               => russell         
======================================================================




More information about the asterisk-bugs mailing list