alpine 3.9
integer weakness #15

2

Weakness Breakdown


Definition:

An integer overflow occurs when the answer to an arithmetic operation exceeds the maximum size of the integer type used to store it. The resulting value will appear to have wrapped around the maximum value and started again at the minimum value. This would look like a clock that represents 13:00 by pointing at 1:00. An attacker can use an integer overflow during a buffer length calculation, which results in the allocated buffer being too small to hold the data copied into it, thus causing a buffer overflow.

Warning code(s):

Unless checked, the resulting number can exceed the expected range.

File Name:

captagent/src/captagent-6.3.0/src/modules/transport/hep/transport_hep.c

Context:

The highlighted line of code below is the trigger point of this particular Alpine 3.9 integer weakness.

 {
	int ret = 0;

	ret += snprintf(buf+ret, len-ret, "Total received: [%" PRId64 "]\r\n", stats.received_packets_total);
	ret += snprintf(buf+ret, len-ret, "Reconnect total: [%" PRId64 "]\r\n", stats.reconnect_total);
	ret += snprintf(buf+ret, len-ret, "Errors total: [%" PRId64 "]\r\n", stats.errors_total);
	ret += snprintf(buf+ret, len-ret, "Compressed total: [%" PRId64 "]\r\n", stats.compressed_total);
	ret += snprintf(buf+ret, len-ret, "Total sent: [%" PRId64 "]\r\n", stats.send_packets_total);


	return 1;

}

static void reconnect(int idx)
{
    time_t cur_time = time(NULL);

    // Don't reconnect more then every 2 secs.
    if (cur_time - hep_connection_s[idx].conn_state_changed_time < 2)
        return;

    homer_close(&hep_connection_s[idx]);

    init_tcp_socket(&hep_connection_s[idx], profile_transport[idx].capt_host, atoi(profile_transport[idx].capt_port));
}

static const char* 	get_state_label(conn_state_type_t state)
{
	switch (state)
	{
		case STATE_INIT:
			return "INIT";
		case STATE_CONNECTING:
			return "CONNECTING";
		case STATE_CONNECTED:
			return "CONNECTED";
		case STATE_CLOSING:
			return "CLOSING";
		case STATE_CLOSED:
			return "CLOSED";
		case STATE_SHUTTING_DOWN:
			return "SHUTTING_DOWN";
		case STATE_SHUT_DOWN:
			return "SHUT_DOWN";
		case STATE_ERROR:
			return "ERROR";
		default:
			return "UNKNOWN";
	} 

The registered trademark Linux® is used pursuant to a sublicense from the Linux Foundation, the exclusive licensee of Linus Torvalds, owner of the mark on a world­wide basis.