Skip to content

Commit

Permalink
core "net:" statistics: Fix an integer signedness bug
Browse files Browse the repository at this point in the history
Due to runaway usage of bitwise shifting, the byte matching code would fail to
work for interfaces having low order bytes with greater values than 128
(e.g. udp:31.32.33.147:5060). Consequently, all "net:" statistics for them
would show up as zeroes.

Thanks to Bogdan and Răzvan for discovering and troubleshooting

(cherry picked from commit 009691c)
  • Loading branch information
liviuchircu committed Mar 30, 2017
1 parent 05ea491 commit 40b6ce5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions socket_info.c
Expand Up @@ -902,7 +902,7 @@ int fix_all_socket_lists(void)
* Therefore it is CRUCIAL that you free ipList when you are done with its
* contents, to avoid a nasty memory leak.
*/
int get_socket_list_from_proto(int **ipList, int protocol) {
int get_socket_list_from_proto(unsigned int **ipList, int protocol) {

struct socket_info *si;
struct socket_info** list;
Expand Down Expand Up @@ -993,17 +993,17 @@ int get_socket_list_from_proto(int **ipList, int protocol) {
* get_socket_list_from_proto() in this file.
*
*/
static int parse_proc_net_line(char *line, int *ipAddress, int *rx_queue)
static int parse_proc_net_line(char *line, unsigned int *ipAddress, int *rx_queue)
{
int i;

int ipOctetExtractionMask = 0xFF;
unsigned int ipOctetExtractionMask = 0xFF;

char *currColonLocation;
char *nextNonNumericalChar;
char *currentLocationInLine = line;

int parsedInteger[4];
unsigned int parsedInteger[4];

/* Example line from /proc/net/tcp or /proc/net/udp:
*
Expand Down Expand Up @@ -1076,7 +1076,7 @@ static int parse_proc_net_line(char *line, int *ipAddress, int *rx_queue)
* get_socket_list_from_proto() in this file.
*
* */
static int match_ip_and_port(int *ipOne, int *ipArray, int sizeOf_ipArray)
static int match_ip_and_port(unsigned int *ipOne, unsigned int *ipArray, int sizeOf_ipArray)
{
int curIPAddrIdx;
int curOctetIdx;
Expand Down Expand Up @@ -1124,13 +1124,13 @@ static int match_ip_and_port(int *ipOne, int *ipArray, int sizeOf_ipArray)
* interface. On other systems, zero will always be returned.
*/
static int get_used_waiting_queue(
int forTCP, int *interfaceList, int listSize)
int forTCP, unsigned int *interfaceList, int listSize)
{
FILE *fp;
char *fileToOpen;

char lineBuffer[MAX_PROC_BUFFER];
int ipAddress[NUM_IP_OCTETS+1];
unsigned int ipAddress[NUM_IP_OCTETS+1];
int rx_queue;
int waitingQueueSize = 0;

Expand Down Expand Up @@ -1186,9 +1186,9 @@ static int get_used_waiting_queue(
*/
int get_total_bytes_waiting(int only_proto)
{
static int *UDPList = NULL;
static int *TCPList = NULL;
static int *TLSList = NULL;
static unsigned int *UDPList = NULL;
static unsigned int *TCPList = NULL;
static unsigned int *TLSList = NULL;

static int numUDPSockets = -1;
static int numTCPSockets = -1;
Expand Down
2 changes: 1 addition & 1 deletion socket_info.h
Expand Up @@ -94,7 +94,7 @@ int fix_socket_list(struct socket_info **);
* Therefore it is CRUCIAL that you free ipList when you are done with
* its contents, to avoid a nasty memory leak.
*/
int get_socket_list_from_proto(int **ipList, int protocol);
int get_socket_list_from_proto(unsigned int **ipList, int protocol);

/*
* Returns the sum of the number of bytes waiting to be consumed on all network
Expand Down

0 comments on commit 40b6ce5

Please sign in to comment.