[asterisk-bugs] [Asterisk 0018295]: [patch] Call to SQLDescribeCol returns an invalid ColumnSize paramenter on x64 (Patch included)

Asterisk Bug Tracker noreply at bugs.digium.com
Thu Nov 11 16:51:06 CST 2010


The following issue has been UPDATED. 
====================================================================== 
https://issues.asterisk.org/view.php?id=18295 
====================================================================== 
Reported By:                pruiz
Assigned To:                
====================================================================== 
Project:                    Asterisk
Issue ID:                   18295
Category:                   Functions/func_odbc
Reproducibility:            sometimes
Severity:                   major
Priority:                   normal
Status:                     new
Asterisk Version:           1.8.0 
JIRA:                        
Regression:                 No 
Reviewboard Link:            
SVN Branch (only for SVN checkouts, not tarball releases): N/A 
SVN Revision (number only!):  
Request Review:              
====================================================================== 
Date Submitted:             2010-11-11 16:47 CST
Last Modified:              2010-11-11 16:51 CST
====================================================================== 
Summary:                    [patch] Call to SQLDescribeCol returns an invalid
ColumnSize paramenter on x64 (Patch included)
Description: 
When using func_odbc with freetds odbc driver with asterisk compiled as
x86_64, the following error will appear to logs/console randomly while
making odbc calls:

[Nov 11 00:39:51] DEBUG13196: func_odbc.c:592 acf_odbc_read: Got collength
of 3 and maxcol of 1416 for column 'OP1' (offset 0)
[Nov 11 00:39:51] ERROR13196:
/usr/src/asterisk-1.8.0/include/asterisk/utils.h:513 _ast_realloc: Memory
Allocation Failure in function ast_str_make_space at line 582 of /
usr/src/asterisk-1.8.0/include/asterisk/strings.h

After debugging and tracing the error, it is related to what looks like an
internal unixODBC/freeTDS bug, by which an incorrect value gets returned as
ColumnSize when callig SQLDescribeCol function.

This ColumnSize parameter is a paremeter passed as reference (*SQLULEN),
and  SQLULEN on 64bit machines corresponds to an unsigned long int (8
bytes).

However, looks like  unixODBC/FreeTDS it's casting (internally) this
parameter to an *int32 before asigning the parameter's value. As such, the
function returns a value with has only updated the upper (or lower
depending on endiannes) 4 bytes of the passed SQLULEN parameter, which
makes the next call to ast_str_make_space fail as the size passed
internally to ast_realloc it's often to big to be reserved by the system.

After inspecting the code, I will report the problem to unixODBC people,
however there's a really easy fix which can be done on asterisk side to
allow this setup to work until unixODBC people fixes their problem. 

To fix the issue we just need to initialize the passed parameter (maxcol)
to 0 before passing it to SQLDescribeCol. As such I'm attaching a simple
patch for it.


====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2010-11-11 16:51 pruiz          Summary                  Call to SQLDescribeCol
returns an invalid ColumnSize paramenter on x64 (Patch included) => [patch] Call
to SQLDescribeCol returns an invalid ColumnSize paramenter on x64 (Patch
included)
======================================================================




More information about the asterisk-bugs mailing list