]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Made packet data len "size_t".
authorAlan T. DeKok <aland@freeradius.org>
Sat, 20 Oct 2012 07:37:36 +0000 (09:37 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Sat, 20 Oct 2012 07:40:01 +0000 (09:40 +0200)
Only one place needs it to be negative: the read from the socket.
For the rest of the code, it is ALWAYS positive.

As part of this, changed a few other variables, too.
And uses "%zu" for printing "size_t" variables.  C99 is everywhere.
If you want to build the server on a non-C99 compiler, go away.

src/include/libradius.h
src/lib/radius.c
src/lib/tcp.c
src/lib/vqp.c

index 487bf739c4415ecd8ef9464dd7a6ca21db4e1409..1bce8614a09eb6ff8104ee61233ac77f47ae76ea 100644 (file)
@@ -246,11 +246,11 @@ typedef struct radius_packet {
        uint8_t                 vector[AUTH_VECTOR_LEN];
        struct timeval          timestamp;
        uint8_t                 *data;
-       ssize_t                 data_len;
+       size_t                  data_len;
        VALUE_PAIR              *vps;
        ssize_t                 offset;
 #ifdef WITH_TCP
-       ssize_t                 partial;
+       size_t                  partial;
 #endif
 } RADIUS_PACKET;
 
index 8afa66db68f78e6bd391bfac79c97cd705e49c26..7a39cdd7bd142d7743653c8726572b3f0577aca4 100644 (file)
@@ -2153,7 +2153,7 @@ int rad_tlv_ok(const uint8_t *data, size_t length,
 int rad_packet_ok(RADIUS_PACKET *packet, int flags)
 {
        uint8_t                 *attr;
-       int                     totallen;
+       size_t                  totallen;
        int                     count;
        radius_packet_t         *hdr;
        char                    host_ipaddr[128];
@@ -2169,11 +2169,11 @@ int rad_packet_ok(RADIUS_PACKET *packet, int flags)
         *      "The minimum length is 20 ..."
         */
        if (packet->data_len < AUTH_HDR_LEN) {
-               fr_strerror_printf("WARNING: Malformed RADIUS packet from host %s: too short (received %d < minimum %d)",
+               fr_strerror_printf("WARNING: Malformed RADIUS packet from host %s: too short (received %zu < minimum %d)",
                           inet_ntop(packet->src_ipaddr.af,
                                     &packet->src_ipaddr.ipaddr,
                                     host_ipaddr, sizeof(host_ipaddr)),
-                                  (int) packet->data_len, AUTH_HDR_LEN);
+                                    packet->data_len, AUTH_HDR_LEN);
                return 0;
        }
 
@@ -2183,11 +2183,11 @@ int rad_packet_ok(RADIUS_PACKET *packet, int flags)
         *      " ... and maximum length is 4096."
         */
        if (packet->data_len > MAX_PACKET_LEN) {
-               fr_strerror_printf("WARNING: Malformed RADIUS packet from host %s: too long (received %d > maximum %d)",
+               fr_strerror_printf("WARNING: Malformed RADIUS packet from host %s: too long (received %zu > maximum %d)",
                           inet_ntop(packet->src_ipaddr.af,
                                     &packet->src_ipaddr.ipaddr,
                                     host_ipaddr, sizeof(host_ipaddr)),
-                                  (int) packet->data_len, MAX_PACKET_LEN);
+                                    packet->data_len, MAX_PACKET_LEN);
                return 0;
        }
 
@@ -2236,11 +2236,11 @@ int rad_packet_ok(RADIUS_PACKET *packet, int flags)
         *      "The minimum length is 20 ..."
         */
        if (totallen < AUTH_HDR_LEN) {
-               fr_strerror_printf("WARNING: Malformed RADIUS packet from host %s: too short (length %d < minimum %d)",
+               fr_strerror_printf("WARNING: Malformed RADIUS packet from host %s: too short (length %zu < minimum %d)",
                           inet_ntop(packet->src_ipaddr.af,
                                     &packet->src_ipaddr.ipaddr,
                                     host_ipaddr, sizeof(host_ipaddr)),
-                          totallen, AUTH_HDR_LEN);
+                                    totallen, AUTH_HDR_LEN);
                return 0;
        }
 
@@ -2252,11 +2252,11 @@ int rad_packet_ok(RADIUS_PACKET *packet, int flags)
         *      " ... and maximum length is 4096."
         */
        if (totallen > MAX_PACKET_LEN) {
-               fr_strerror_printf("WARNING: Malformed RADIUS packet from host %s: too long (length %d > maximum %d)",
+               fr_strerror_printf("WARNING: Malformed RADIUS packet from host %s: too long (length %zu > maximum %d)",
                           inet_ntop(packet->src_ipaddr.af,
                                     &packet->src_ipaddr.ipaddr,
                                     host_ipaddr, sizeof(host_ipaddr)),
-                          totallen, MAX_PACKET_LEN);
+                                    totallen, MAX_PACKET_LEN);
                return 0;
        }
 
@@ -2269,11 +2269,11 @@ int rad_packet_ok(RADIUS_PACKET *packet, int flags)
         *      i.e. No response to the NAS.
         */
        if (packet->data_len < totallen) {
-               fr_strerror_printf("WARNING: Malformed RADIUS packet from host %s: received %d octets, packet length says %d",
+               fr_strerror_printf("WARNING: Malformed RADIUS packet from host %s: received %zu octets, packet length says %zu",
                           inet_ntop(packet->src_ipaddr.af,
                                     &packet->src_ipaddr.ipaddr,
                                     host_ipaddr, sizeof(host_ipaddr)),
-                                  (int) packet->data_len, totallen);
+                                    packet->data_len, totallen);
                return 0;
        }
 
@@ -2462,6 +2462,7 @@ int rad_packet_ok(RADIUS_PACKET *packet, int flags)
 RADIUS_PACKET *rad_recv(int fd, int flags)
 {
        int sock_flags = 0;
+       ssize_t data_len;
        RADIUS_PACKET           *packet;
 
        /*
@@ -2478,19 +2479,20 @@ RADIUS_PACKET *rad_recv(int fd, int flags)
                flags &= ~0x02;
        }
 
-       packet->data_len = rad_recvfrom(fd, &packet->data, sock_flags,
+       data_len = rad_recvfrom(fd, &packet->data, sock_flags,
                                        &packet->src_ipaddr, &packet->src_port,
                                        &packet->dst_ipaddr, &packet->dst_port);
 
        /*
         *      Check for socket errors.
         */
-       if (packet->data_len < 0) {
+       if (data_len < 0) {
                fr_strerror_printf("Error receiving packet: %s", strerror(errno));
                /* packet->data is NULL */
                free(packet);
                return NULL;
        }
+       packet->data_len = data_len; /* unsigned vs signed */
 
        /*
         *      If the packet is too big, then rad_recvfrom did NOT
index 6c3906fe3e1f46c68bfd8f8165ddd9ff4f9dfc84..ae80babc7ef115605c7627f216c6b9e88398ffa8 100644 (file)
@@ -329,7 +329,7 @@ int fr_tcp_read_packet(RADIUS_PACKET *packet, int flags)
                        DEBUG("rad_recv: Packet from %s code=%d",
                              buffer, packet->code);
                }
-               DEBUG(", id=%d, length=%zd\n", packet->id, packet->data_len);
+               DEBUG(", id=%d, length=%zu\n", packet->id, packet->data_len);
        }
 
        return 1;               /* done reading the packet */
index 3ceb20c59ea7047788fa9229fdec2bed231d35e2..74d0bf537fa8fc31ccd3c5f39e439dbe6c086779 100644 (file)
@@ -286,20 +286,20 @@ RADIUS_PACKET *vqp_recv(int sockfd)
        }
        memset(packet, 0, sizeof(*packet));
 
-       packet->data_len = vqp_recvfrom(sockfd, &packet->data, 0,
+       length = vqp_recvfrom(sockfd, &packet->data, 0,
                                        &packet->src_ipaddr, &packet->src_port,
                                        &packet->dst_ipaddr, &packet->dst_port);
 
        /*
         *      Check for socket errors.
         */
-       if (packet->data_len < 0) {
+       if (length < 0) {
                fr_strerror_printf("Error receiving packet: %s", strerror(errno));
                /* packet->data is NULL */
                free(packet);
                return NULL;
        }
-
+       packet->data_len = length; /* unsigned vs signed */
 
        /*
         *      We can only receive packets formatted in a way we
@@ -315,9 +315,9 @@ RADIUS_PACKET *vqp_recv(int sockfd)
        ptr = packet->data;
 
        if (0) {
-               int i;
+               size_t i;
                for (i = 0; i < packet->data_len; i++) {
-                       if ((i & 0x0f) == 0) fprintf(stderr, "%02x: ", i);
+                 if ((i & 0x0f) == 0) fprintf(stderr, "%02x: ", (int) i);
                        fprintf(stderr, "%02x ", ptr[i]);
                        if ((i & 0x0f) == 0x0f) fprintf(stderr, "\n");
                }
@@ -651,7 +651,7 @@ int vqp_encode(RADIUS_PACKET *packet, RADIUS_PACKET *original)
         */
        for (i = 0; i < VQP_MAX_ATTRIBUTES; i++) {
                if (!vps[i]) break;
-               if ((ptr - packet->data) >= packet->data_len) break;
+               if (ptr >= (packet->data + packet->data_len)) break;
 
                vp = vps[i];