]> rtime.felk.cvut.cz Git - lisovros/iproute2_canprio.git/blobdiff - ip/ipmaddr.c
Add reference to tc-codel(8) to the SEE ALSO section
[lisovros/iproute2_canprio.git] / ip / ipmaddr.c
index 1014f8321f9e14cfe3f3ffa077ddb9d8e2ee3b64..3ae947800ef4bf1f7e6f1e2e95614b54fcd54a93 100644 (file)
@@ -43,11 +43,11 @@ static void usage(void)
        exit(-1);
 }
 
-static int parse_hex(char *str, unsigned char *addr)
+static int parse_hex(char *str, unsigned char *addr, size_t size)
 {
        int len=0;
 
-       while (*str) {
+       while (*str && (len < 2 * size)) {
                int tmp;
                if (str[1] == 0)
                        return -1;
@@ -104,7 +104,7 @@ void read_dev_mcast(struct ma_info **result_p)
 
                m.addr.family = AF_PACKET;
 
-               len = parse_hex(hexa, (unsigned char*)&m.addr.data);
+               len = parse_hex(hexa, (unsigned char*)&m.addr.data, sizeof (m.addr.data));
                if (len >= 0) {
                        struct ma_info *ma = malloc(sizeof(m));
 
@@ -128,14 +128,17 @@ void read_igmp(struct ma_info **result_p)
        if (!fp)
                return;
        memset(&m, 0, sizeof(m));
-       fgets(buf, sizeof(buf), fp);
+       if (!fgets(buf, sizeof(buf), fp)) {
+               fclose(fp);
+               return;
+       }
 
        m.addr.family = AF_INET;
        m.addr.bitlen = 32;
        m.addr.bytelen = 4;
 
        while (fgets(buf, sizeof(buf), fp)) {
-               struct ma_info *ma = malloc(sizeof(m));
+               struct ma_info *ma;
 
                if (buf[0] != '\t') {
                        sscanf(buf, "%d%s", &m.index, m.name);
@@ -176,7 +179,7 @@ void read_igmp6(struct ma_info **result_p)
 
                m.addr.family = AF_INET6;
 
-               len = parse_hex(hexa, (unsigned char*)&m.addr.data);
+               len = parse_hex(hexa, (unsigned char*)&m.addr.data, sizeof (m.addr.data));
                if (len >= 0) {
                        struct ma_info *ma = malloc(sizeof(m));