[ZBX-8951] agent crashes on net.if.discovery Created: 2014 Oct 24  Updated: 2017 May 30  Resolved: 2014 Oct 29

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Agent (G)
Affects Version/s: 2.4.0, 2.4.1
Fix Version/s: 2.4.2rc1, 2.5.0

Type: Incident report Priority: Blocker
Reporter: Tyler Burns Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: crash, hp-ux, patch, regression
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

HP-UX 11.31 on Itanium.


Attachments: File net.c    
Issue Links:
Duplicate

 Description   

Hello,

I have been implementing Zabbix in my organization and found/fixed a bug in agent version 2.4.0. The net.if.discovery item sometimes crashes the agent on HP-UX 11.31. I found the problem in src/libs/
zbxsysinfo/hpux/net.c

I inserted the lines:

zbx_json_init(&j, ZBX_JSON_STAT_BUF_LEN);
zbx_json_addarray(&j, ZBX_PROTO_TAG_DATA);

Between lines 187 and 188.

What was happening was the buffer_size member of the zbx_json struct that were being passed to these functions was returning unusual values. After further digging I found that the buffer_size member was never assigned a value, so whatever was at that memory address was being used in the calls to the memory allocation functions. I included a block of code below that shows my change. I inserted lines 187 and 188.

I attached a version of net.c with my change.

Let me know if you have any questions.

#if HPUX_VERSION < 1131
   167        if_list = zbx_malloc(if_list, if_list_alloc);
   168        *if_list = '\0';
   169   
   170        if (FAIL == get_if_names(&if_list, &if_list_alloc, &if_list_offset))
   171        {
   172            SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot obtain network interface information."));
   173            zbx_free(if_list);
   174            return SYSINFO_RET_FAIL;
   175        }
   176   
   177        zbx_json_init(&j, ZBX_JSON_STAT_BUF_LEN);
   178   
   179        zbx_json_addarray(&j, ZBX_PROTO_TAG_DATA);
   180   
   181        if_name = if_list;
   182   
   183        while (NULL != if_name)
   184        {
   185            if (NULL != (if_name_end = strchr(if_name, ZBX_IF_SEP)))
   186                *if_name_end = '\0';
   187    #else
   188        zbx_json_init(&j, ZBX_JSON_STAT_BUF_LEN); /*I added this*/
   189        zbx_json_addarray(&j, ZBX_PROTO_TAG_DATA); /*I added this*/
   190        for (ni = if_nameindex(), i = 0; 0 != ni[i].if_index; i++)
   191        {
   192            if_name = ni[i].if_name;
   193    #endif
   194            zbx_json_addobject(&j, NULL);
   195            zbx_json_addstring(&j, "{#IFNAME}", if_name, ZBX_JSON_TYPE_STRING);
   196            zbx_json_close(&j);
   197    #if HPUX_VERSION < 1131
   198            if (NULL != if_name_end)
   199            {
   200                *if_name_end = ZBX_IF_SEP;
   201                if_name = if_name_end + 1;
   202            }
   203            else
   204                if_name = NULL;
   205    #endif


 Comments   
Comment by Aleksandrs Saveljevs [ 2014 Oct 27 ]

Broken in:

$ svn log -c 45668
------------------------------------------------------------------------
r45668 | asaveljevs | 2014-05-20 14:13:39 +0300 (Tue, 20 May 2014) | 1 line

...GI..PS. [ZBXNEXT-2203] added information on the reason items become not supported
------------------------------------------------------------------------
Comment by Aleksandrs Saveljevs [ 2014 Oct 28 ]

Fixed in development branch svn://svn.zabbix.com/branches/dev/ZBX-8951 .

Comment by Andris Zeila [ 2014 Oct 29 ]

(1) We should check the return value of if_nameindex() for errors (NULL value).

asaveljevs RESOLVED in r50259.

wiper CLOSED

Comment by Andris Zeila [ 2014 Oct 29 ]

(2) The HPUX NET_IF_DISCOVERY() function has a lot of #ifdefs to check for HPUX_VERSION. It appears there are more version specific code than shared code. It might be better to simply have to fully separate code paths for HPUX_VERSION < 1131 and the rest.

asaveljevs RESOLVED in r50258.

wiper CLOSED

Comment by Andris Zeila [ 2014 Oct 29 ]

Successfully tested

Comment by Aleksandrs Saveljevs [ 2014 Oct 29 ]

Fixed in pre-2.4.2 r50278 and pre-2.5.0 (trunk) r50280.

Generated at Thu Mar 28 21:58:32 EET 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.