[ZBX-12180] Server crashes when connecting to the IBM DB2 database Created: 2017 May 13  Updated: 2018 Oct 08  Resolved: 2018 Oct 08

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Server (S)
Affects Version/s: 3.2.6
Fix Version/s: None

Type: Problem report Priority: Minor
Reporter: Alexander Vladishev Assignee: Unassigned
Resolution: Unsupported version Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Backtrace:

  2094:20170513:125443.997 ====== Fatal information: ======
  2094:20170513:125443.997 Program counter: 0x7f098a8d45d5
...
  2094:20170513:125443.997 === Backtrace: ===
  2094:20170513:125443.998 12: sbin/zabbix_server(zbx_log_fatal_info+0x1b6) [0x4720b6]
  2094:20170513:125443.998 11: sbin/zabbix_server() [0x47240c]
  2094:20170513:125443.998 10: /lib/x86_64-linux-gnu/libc.so.6(+0x36d40) [0x7f098933dd40]
  2094:20170513:125443.998 9: /opt/ibm/db2/V9.7/lib64/libdb2.so.1(_Z18SQLSetConnectAttr2P15CLI_CONNECTINFOiPvihP5sqlcaP19CLI_ERRORHEADERINFO+0x8c7) [0x7f098a8d45d5]
  2094:20170513:125443.998 8: /opt/ibm/db2/V9.7/lib64/libdb2.so.1(SQLSetConnectAttr+0x338) [0x7f098a8e3afa]
  2094:20170513:125443.998 7: sbin/zabbix_server(zbx_db_connect+0x250) [0x4c957e]
  2094:20170513:125443.998 6: sbin/zabbix_server(DBconnect+0xbb) [0x4a4dad]
  2094:20170513:125443.998 5: sbin/zabbix_server(zbx_db_get_database_type+0x24) [0x4a798a]
  2094:20170513:125443.998 4: sbin/zabbix_server(MAIN_ZABBIX_ENTRY+0x3ed) [0x41a26b]
  2094:20170513:125443.998 3: sbin/zabbix_server(daemon_start+0x2ee) [0x471b09]
  2094:20170513:125443.998 2: sbin/zabbix_server(main+0x638) [0x419d29]
  2094:20170513:125443.998 1: /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) [0x7f0989328ec5]
  2094:20170513:125443.998 0: sbin/zabbix_server() [0x412a89]

This crash is caused by this code, which has been added under ZBX-10076:

src/libs/zbxdb/db.c:342

/* set codepage to utf-8 */
if (ZBX_DB_OK == ret && SUCCEED != zbx_ibm_db2_success(SQLSetConnectAttr(ibm_db2.hdbc, SQL_ATTR_CLIENT_CODEPAGE,
                (SQLPOINTER)(SQLUINTEGER)1208, SQL_IS_UINTEGER)))
{
        ret = ZBX_DB_FAIL;
}

Removing this code allows to see a database connection error message:

 20450:20170513:120539.722 [Z3001] connection to database 'szbxnext2031' failed: [-1001] HY501 [IBM][CLI Driver] SQL1001N  "SZBXNEXT2031" is not a valid database name.  SQLSTATE=2E000
 20450:20170513:120539.722 Cannot connect to the database. Exiting...


 Comments   
Comment by Glebs Ivanovskis (Inactive) [ 2017 May 13 ]

IBM documentation for different versions has different examples regarding setting connection encoding.

In 9.7.0:

SQLINTEGER iUnicode = 1208;
cliRC = SQLSetConnectAttr(hdbc,
      SQL_ATTR_CLIENT_CODEPAGE, 
      (SQLPOINTER)iUnicode, 
SQL_IS_INTEGER);

Starting from 10.1.0:

Unicode = 1208;
cliRC = SQLSetConnectAttr(hdbc,
                          SQL_ATTR_CLIENT_CODEPAGE, 
                          (SQLPOINTER)&unicode,  SQL_NTS);  

Description of function parameters (last two) is very vague, contradicts both examples and hasn't changed between versions:

SQLPOINTER ValuePtr input Pointer to the value to be associated with Attribute. Depending on the value of Attribute, ValuePtr will be a 32-bit unsigned integer value or pointer to a null-terminated character string. Note that if the Attribute argument is a driver-specific value, the value in *ValuePtr can be a signed integer. Refer to the connection attributes list for details.
SQLINTEGER StringLength input If Attribute is an ODBC-defined attribute and ValuePtr points to a character string or a binary buffer, this argument should be the length of *ValuePtr. For character string data, StringLength should contain the number of bytes in the string. If Attribute is an ODBC-defined attribute and ValuePtr is an integer, StringLength is ignored.
If Attribute is a DB2 CLI attribute, the application indicates the nature of the attribute by setting the StringLength argument. StringLength can have the following values:
  • If ValuePtr is a pointer to a character string, then StringLength is the number of bytes needed to store the string or SQL_NTS.
  • If ValuePtr is a pointer to a binary buffer, then the application places the result of the SQL_LEN_BINARY_ATTR(length) macro in StringLength. This places a negative value in StringLength.
  • If ValuePtr is a pointer to a value other than a character string or a binary string, then StringLength should have the value SQL_IS_POINTER.
  • If ValuePtr contains a fixed-length value, then StringLength is either SQL_IS_INTEGER or SQL_IS_UINTEGER, as appropriate.
Comment by Glebs Ivanovskis (Inactive) [ 2017 May 13 ]

By the way, I saw the log, library tries to dereference address 4b8‍16 = 1208‍10.

Comment by Glebs Ivanovskis (Inactive) [ 2017 Jul 28 ]

(1) By the way, instead of 1208 we should probably use SQL_CP_UTF8.

Comment by Aigars Kadikis [ 2018 Oct 08 ]

Closing due to an unsupported version.

Generated at Fri May 09 05:53:39 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.