[Home]

Summary:ASTERISK-16946: [patch] Call to SQLDescribeCol returns an invalid ColumnSize paramenter on x64 (Patch included)
Reporter:Pablo Ruiz García (pruiz)Labels:
Date Opened:2010-11-11 16:47:55.000-0600Date Closed:2011-03-10 00:49:02.000-0600
Priority:MinorRegression?No
Status:Closed/CompleteComponents:Functions/func_odbc
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) asterisk-odbc-fix.diff
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.



****** ADDITIONAL INFORMATION ******

The problem is reproducible with asterisk 1.8.0 and svn's trunk.
Comments:By: Pablo Ruiz García (pruiz) 2010-12-20 18:07:50.000-0600

Any chances to get this merged? ;)

By: Digium Subversion (svnbot) 2011-03-09 23:38:45.000-0600

Repository: asterisk
Revision: 310140

U   branches/1.4/apps/app_voicemail.c
U   branches/1.4/res/res_config_odbc.c

------------------------------------------------------------------------
r310140 | tilghman | 2011-03-09 23:38:45 -0600 (Wed, 09 Mar 2011) | 5 lines

Initialize column size to 0 to deal with a potential UnixODBC bug on 64-bit systems.

(closes issue ASTERISK-16946)
Reported by: pruiz

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

http://svn.digium.com/view/asterisk?view=rev&revision=310140

By: Digium Subversion (svnbot) 2011-03-09 23:51:39.000-0600

Repository: asterisk
Revision: 310141

_U  branches/1.6.2/
U   branches/1.6.2/apps/app_voicemail.c
U   branches/1.6.2/funcs/func_odbc.c
U   branches/1.6.2/res/res_config_odbc.c

------------------------------------------------------------------------
r310141 | tilghman | 2011-03-09 23:51:38 -0600 (Wed, 09 Mar 2011) | 12 lines

Merged revisions 310140 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
 r310140 | tilghman | 2011-03-09 23:38:44 -0600 (Wed, 09 Mar 2011) | 5 lines
 
 Initialize column size to 0 to deal with a potential UnixODBC bug on 64-bit systems.
 
 (closes issue ASTERISK-16946)
  Reported by: pruiz
........

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

http://svn.digium.com/view/asterisk?view=rev&revision=310141

By: Digium Subversion (svnbot) 2011-03-09 23:53:30.000-0600

Repository: asterisk
Revision: 310142

_U  branches/1.8/
U   branches/1.8/apps/app_voicemail.c
U   branches/1.8/funcs/func_odbc.c
U   branches/1.8/res/res_config_odbc.c

------------------------------------------------------------------------
r310142 | tilghman | 2011-03-09 23:53:30 -0600 (Wed, 09 Mar 2011) | 19 lines

Merged revisions 310141 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.6.2

................
 r310141 | tilghman | 2011-03-09 23:51:37 -0600 (Wed, 09 Mar 2011) | 12 lines
 
 Merged revisions 310140 via svnmerge from
 https://origsvn.digium.com/svn/asterisk/branches/1.4
 
 ........
   r310140 | tilghman | 2011-03-09 23:38:44 -0600 (Wed, 09 Mar 2011) | 5 lines
   
   Initialize column size to 0 to deal with a potential UnixODBC bug on 64-bit systems.
   
   (closes issue ASTERISK-16946)
    Reported by: pruiz
 ........
................

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

http://svn.digium.com/view/asterisk?view=rev&revision=310142

By: Digium Subversion (svnbot) 2011-03-09 23:54:54.000-0600

Repository: asterisk
Revision: 310143

_U  trunk/
U   trunk/apps/app_voicemail.c
U   trunk/funcs/func_odbc.c
U   trunk/res/res_config_odbc.c

------------------------------------------------------------------------
r310143 | tilghman | 2011-03-09 23:54:53 -0600 (Wed, 09 Mar 2011) | 26 lines

Merged revisions 310142 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8

................
 r310142 | tilghman | 2011-03-09 23:53:29 -0600 (Wed, 09 Mar 2011) | 19 lines
 
 Merged revisions 310141 via svnmerge from
 https://origsvn.digium.com/svn/asterisk/branches/1.6.2
 
 ................
   r310141 | tilghman | 2011-03-09 23:51:37 -0600 (Wed, 09 Mar 2011) | 12 lines
   
   Merged revisions 310140 via svnmerge from
   https://origsvn.digium.com/svn/asterisk/branches/1.4
   
   ........
     r310140 | tilghman | 2011-03-09 23:38:44 -0600 (Wed, 09 Mar 2011) | 5 lines
     
     Initialize column size to 0 to deal with a potential UnixODBC bug on 64-bit systems.
     
     (closes issue ASTERISK-16946)
      Reported by: pruiz
   ........
 ................
................

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

http://svn.digium.com/view/asterisk?view=rev&revision=310143