Skip to content

Commit

Permalink
don't copy short data for complex types
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Feb 6, 2018
1 parent ab2fa93 commit bfae1a6
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/lib/value.c
Expand Up @@ -1014,22 +1014,28 @@ static int value_data_hton(value_data_t *dst, PW_TYPE dst_type, void const *src,

copy:
/*
* Copy it over, but only so much as needed, and
* if the source is smaller than the destination,
* zero out the remaining bytes in the
* destination.
* Not enough information, die.
*/
if (src_len >= dst_len) {
memcpy(dst_ptr, src, dst_len);
} else {
memcpy(dst_ptr, src, src_len);
memset(dst_ptr + src_len, 0, dst_len - src_len);
}
if (src_len < dst_len) return -1;

/*
* Copy only as much as we need from the source.
*/
memcpy(dst_ptr, src, dst_len);
break;

case PW_TYPE_ABINARY:
dst_len = sizeof(dst->filter);
dst_ptr = (uint8_t *) dst->filter;

/*
* Too little data is OK here.
*/
if (src_len < dst_len) {
memcpy(dst_ptr, src, src_len);
memset(dst_ptr + src_len, 0, dst_len - src_len);
break;
}
goto copy;

case PW_TYPE_IFID:
Expand All @@ -1048,7 +1054,7 @@ static int value_data_hton(value_data_t *dst, PW_TYPE dst_type, void const *src,
goto copy;

case PW_TYPE_IPV6_PREFIX:
dst_len = sizeof(dst->ipv6prefix);
dst_len = sizeof(dst->ipv6prefix);
dst_ptr = (uint8_t *) dst->ipv6prefix;
goto copy;

Expand Down

0 comments on commit bfae1a6

Please sign in to comment.