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