It appears to appease coverity complaints about tainted data.
*/
if ((end - ptr) < 4) return 0;
- length = (ptr[0] << 8) | ptr[1];
+ length = fr_nbo_to_uint16(ptr);
if (length == 0) return 0;
if ((ptr + length + 3) > end) return 0;
* length.
*/
if (!parent->flags.length || (parent->flags.length % 4)) {
- actual_len = (p[0] << 8) | p[1];
+ actual_len = fr_nbo_to_uint16(p);
if (actual_len > (attr_len - 2)) {
fr_strerror_printf("%s: Actual length field value (%hu) > attribute value length (%zu)",
__FUNCTION__, actual_len, attr_len - 2);
if (attr_len < 2) goto raw; /* Need at least two bytes for the length field */
- res_len = (p[0] << 8) | p[1];
+ res_len = fr_nbo_to_uint16(p);
if (res_len % 8) {
fr_strerror_printf("%s: RES Length (%hu) is not a multiple of 8",
__FUNCTION__, res_len);
*/
case FR_TYPE_STRING:
{
- uint16_t actual_len = (p[0] << 8) | p[1];
+ uint16_t actual_len = fr_nbo_to_uint16(p);
if (actual_len > (attr_len - 2)) {
fr_strerror_printf("%s: Actual length field value (%hu) > attribute value length (%zu)",
* Variable length octets buffer
*/
if (!parent->flags.length) {
- uint16_t actual_len = (p[0] << 8) | p[1];
+ uint16_t actual_len = fr_nbo_to_uint16(p);
if (actual_len > (attr_len - prefix)) {
fr_strerror_printf("%s: Actual length field value (%hu) > attribute value length (%zu)",
if ((len >= 3) && (p[0] == 1)) {
size_t payload_len;
- payload_len = (p[1] << 8) | p[2];
+ payload_len = fr_nbo_to_uint16(p + 1);
if ((payload_len + 3) > len) {
tls_session->invalid = true;
ROPTIONAL(REDEBUG, ERROR, "OpenSSL Heartbeat attack detected. Closing connection");
char *fr_inet_ifid_ntop(char *out, size_t outlen, uint8_t const *ifid)
{
snprintf(out, outlen, "%x:%x:%x:%x",
- (ifid[0] << 8) + ifid[1], (ifid[2] << 8) + ifid[3],
- (ifid[4] << 8) + ifid[5], (ifid[6] << 8) + ifid[7]);
+ fr_nbo_to_uint16(ifid), fr_nbo_to_uint16(ifid + 2),
+ fr_nbo_to_uint16(ifid + 4), fr_nbo_to_uint16(ifid + 6));
return out;
}
if (cnt <= INET6_ADDRSTRLEN) return NULL;
snprintf(dst, cnt, "%x:%x:%x:%x:%x:%x:%x:%x",
- (ipaddr->s6_addr[0] << 8) | ipaddr->s6_addr[1],
- (ipaddr->s6_addr[2] << 8) | ipaddr->s6_addr[3],
- (ipaddr->s6_addr[4] << 8) | ipaddr->s6_addr[5],
- (ipaddr->s6_addr[6] << 8) | ipaddr->s6_addr[7],
- (ipaddr->s6_addr[8] << 8) | ipaddr->s6_addr[9],
- (ipaddr->s6_addr[10] << 8) | ipaddr->s6_addr[11],
- (ipaddr->s6_addr[12] << 8) | ipaddr->s6_addr[13],
- (ipaddr->s6_addr[14] << 8) | ipaddr->s6_addr[15]);
+ fr_nbo_to_uint16(ipaddr->a6_addr),
+ fr_nbo_to_uint16(ipaddr->a6_addr + 2),
+ fr_nbo_to_uint16(ipaddr->a6_addr + 4),
+ fr_nbo_to_uint16(ipaddr->a6_addr + 6),
+ fr_nbo_to_uint16(ipaddr->a6_addr + 8),
+ fr_nbo_to_uint16(ipaddr->a6_addr + 10),
+ fr_nbo_to_uint16(ipaddr->a6_addr + 12),
+ fr_nbo_to_uint16(ipaddr->a6_addr + 14));
return dst;
}
}
arp = (fr_arp_packet_t const *) data;
- request->packet->code = (arp->op[0] << 8) | arp->op[1];
+ request->packet->code = fr_nbo_to_uint16(arp->op);
fr_assert(request->packet->code < FR_ARP_CODE_MAX);
request->packet->data = talloc_memdup(request->packet, data, data_len);
/*
* Hacks for now until we have a lower-level decode routine.
*/
- request->packet->id = (data[4] << 24) | (data[5] << 16) | (data[6] << 8) | data[7];
+ request->packet->id = fr_nbo_to_uint32(data + 4);
request->reply->id = request->packet->id;
memcpy(request->packet->vector, data + 4, sizeof(request->packet->vector));
* proto_dhcpv6 sets the priority
*/
- xid = (packet->transaction_id[0] << 16) | (packet->transaction_id[1] << 8) | packet->transaction_id[2];
+ xid = fr_nbo_to_uint24(packet->transaction_id);
/*
* Print out what we received.
option = fr_dhcpv6_option_find(packet + 2 + 32, packet + packet_len, attr_relay_message->attr);
if (!option) return NULL;
- option_len = (option[2] << 8) | option[3];
+ option_len = fr_nbo_to_uint16(option + 2);
packet = option + 4; /* skip option header */
packet_len = option_len;
option = fr_dhcpv6_option_find(packet + 4, packet + packet_len, attr_client_id->attr);
if (!option) return NULL;
- option_len = (option[2] << 8) | option[3];
+ option_len = fr_nbo_to_uint16(option + 2);
t = (proto_dhcpv6_track_t *) talloc_zero_array(track, uint8_t, t_size + option_len);
if (!t) return NULL;
* @todo -
*/
request->packet->code = packet->opcode;
- request->packet->id = (data[0] << 8) | data[1];
+ request->packet->id = fr_nbo_to_uint16(data);
request->reply->id = request->packet->id;
request->packet->data = talloc_memdup(request->packet, data, data_len);
/*
* Figure out how large the RADIUS packet is.
*/
- packet_len = (buffer[2] << 8) | buffer[3];
+ packet_len = fr_nbo_to_uint16(buffer + 2);
/*
* We don't have a complete RADIUS packet. Tell the
* The MS-Length field is 5 + value_size + length
* of name, which is put after the response.
*/
- length = (eap_round->response->type.data[2] << 8) | eap_round->response->type.data[3];
+ length = fr_nbo_to_uint16(eap_round->response->type.data + 2);
if ((length < (5 + 49)) || (length > (256 + 5 + 49))) {
REDEBUG("Response contains contradictory length %zu %d", length, 5 + 49);
RETURN_MODULE_INVALID;
uint32_t response_length = 0;
uint8_t const *attr, *end;
- end = h->buffer + ((h->buffer[2] << 8) | h->buffer[3]);
+ end = h->buffer + fr_nbo_to_uint16(h->buffer + 2);
for (attr = h->buffer + RADIUS_HEADER_LENGTH;
attr < end;
* Take the 4 most significant octets.
* If less than 256, add 256.
*/
- mip_spi = ((mip_rk_1[0] << 24) | (mip_rk_1[1] << 16) |
- (mip_rk_1[2] << 8) | mip_rk_1[3]);
+ mip_spi = fr_nbo_to_uint32(mip_rk_1);
if (mip_spi < 256) mip_spi += 256;
REDEBUG2("MIP-RK = 0x%pH", fr_box_octets(mip_rk, rk_len));
uint8_t const *secret, size_t secret_len)
{
uint8_t *msg, *end;
- size_t packet_len = (packet[2] << 8) | packet[3];
+ size_t packet_len = fr_nbo_to_uint16(packet + 2);
/*
* No real limit on secret length, this is just
* i.e. We've received 128 bytes, and the packet header
* says it's 256 bytes long.
*/
- totallen = (packet[2] << 8) | packet[3];
+ totallen = fr_nbo_to_uint16(packet + 2);
/*
* Code of 0 is not understood.
bool found_ma;
int rcode;
uint8_t *msg, *end;
- size_t packet_len = (packet[2] << 8) | packet[3];
+ size_t packet_len = fr_nbo_to_uint16(packet + 2);
uint8_t request_authenticator[RADIUS_AUTH_VECTOR_LENGTH];
uint8_t message_authenticator[RADIUS_AUTH_VECTOR_LENGTH];
}
fr_log(log, L_DBG, file, line, " Id : %u", packet->data[1]);
- fr_log(log, L_DBG, file, line, " Length : %u", ((packet->data[2] << 8) | (packet->data[3])));
+ fr_log(log, L_DBG, file, line, " Length : %u", fr_nbo_to_uint16(packet->data + 2));
fr_log(log, L_DBG, file, line, " Vector : %pH", fr_box_octets(packet->data + 4, RADIUS_AUTH_VECTOR_LENGTH));
if (packet->data_len <= 20) return;
p = buffer + strlen(buffer);
if ((attr[0] == FR_VENDOR_SPECIFIC) &&
(attr[1] > 6)) {
- vendor = (attr[2] << 24) | (attr[3] << 16) | (attr[4] << 8) | attr[5];
+ vendor = fr_nbo_to_uint32(attr + 2);
snprintf(p, buffer + sizeof(buffer) - p, "%02x%02x%02x%02x (%u) ",
attr[2], attr[3], attr[4], attr[5], vendor);
return 0;
}
- packet_len = (packet->vector[2] << 8) | packet->vector[3];
+ packet_len = fr_nbo_to_uint16(packet->vector + 2);
if (packet_len < RADIUS_HEADER_LENGTH) {
fr_strerror_const("Discarding packet: Smaller than RFC minimum of 20 bytes");
*
* It's OK for ethernet frames to be longer.
*/
- if ((ptr[3] != 5) &&
- ((ptr[4] != 0) || (ptr[5] > 250))) {
+ attrlen = fr_nbo_to_uint16(ptr + 4);
+ if ((ptr[3] != 5) && (attrlen > 250)) {
fr_strerror_printf("Packet contains attribute with invalid length %02x %02x", ptr[4], ptr[5]);
return false;
}
- attrlen = (ptr[4] << 8) | ptr[5];
ptr += 6 + attrlen;
data_len -= (6 + attrlen);
}
return -1;
}
- attr = (ptr[2] << 8) | ptr[3];
- attr_len = (ptr[4] << 8) | ptr[5];
+ attr = fr_nbo_to_uint16(ptr + 2);
+ attr_len = fr_nbo_to_uint16(ptr + 4);
ptr += 6;
/*
/*
* Length of the data NOT including the header.
*/
- attr_len = (ptr[4] << 8) | ptr[5];
+ attr_len = fr_nbo_to_uint16(ptr + 4);
ptr += 6 + attr_len;
memcpy(&id, attr, 4);
id = ntohl(id);
- length = (attr[4] << 8) | attr[5];
+ length = fr_nbo_to_uint16(attr + 4);
if ((attr + length) > end) break;
fprintf(fp, "\t\t%08x %04x ", id, length);
goto discard;
}
- total_len = (packet[2] << 8) | packet[3];
+ total_len = fr_nbo_to_uint16(packet + 2);
if (total_len < 20) {
MPRINT1("Master ignoring packet (header length %zu)\n", total_len);
goto discard;