openlink / iODBC

An open-source ODBC driver manager and SDK that facilitates the development of database-independent applications on linux, freebsd, unix and MacOS X platforms.
http://www.iodbc.org/
Other
162 stars 52 forks source link

DM returns '[iODBC][Driver Manager]Memory allocation error' if SQLDescribeCol is called w/ BufferLength=0 on a unicode driver #69

Closed matthew-wozniczka closed 3 years ago

matthew-wozniczka commented 3 years ago

Noticed this in 3.52.15, it used to work.

in 3.52.8, it did

if (szColName != NULL && cbColNameMax > 0 &&
        ((penv->unicode_driver && waMode != 'W') ||
    (!penv->unicode_driver && waMode == 'W'))
    )
    {
      if (waMode != 'W')
        {
        /* ansi=>unicode*/
          if ((_ColName = _iodbcdm_alloc_var(pstmt, 0,
                         cbColNameMax * sizeof(wchar_t))) == NULL)
        {
              PUSHSQLERR (pstmt->herr, en_HY001);
              return SQL_ERROR;
            }
        }
      else
        {
        /* unicode=>ansi*/
          if ((_ColName = _iodbcdm_alloc_var(pstmt, 0, cbColNameMax)) == NULL)
        {
              PUSHSQLERR (pstmt->herr, en_HY001);
              return SQL_ERROR;
            }
        }
      colNameOut = _ColName;
    }

Note the szColName != NULL && cbColNameMax > 0 checks.

in the new code, it just does

if (conv_direct == CD_A2W || conv_direct == CD_W2W)
    {
      /*ansi<=unicode*/
      if ((_ColName = _iodbcdm_alloc_var(pstmt, 0,
                     cbColNameMax * DRV_WCHARSIZE_ALLOC(conv))) == NULL)
    {
          PUSHSQLERR (pstmt->herr, en_HY001);
          return SQL_ERROR;
        }
      colNameOut = _ColName;
    }
  else if (conv_direct == CD_W2A)
    {
      /*unicode<=ansi*/
      if ((_ColName = _iodbcdm_alloc_var(pstmt, 0, cbColNameMax * MB_CUR_MAX + 1)) == NULL)
    {
          PUSHSQLERR (pstmt->herr, en_HY001);
          return SQL_ERROR;
        }
      colNameOut = _ColName;
    }

and _iodbcdm_alloc_var returns NULL if passed a size of 0.

smalinin commented 3 years ago

Fixed, patch will be in Git soon.

smalinin commented 3 years ago

Patch was commited

TallTed commented 3 years ago

Patch: https://github.com/openlink/iODBC/commit/80b14419e416cc80d7dddd46e3568effe4c5fc19