key_getsastatbyspi (struct sastat *stat_arg,
u_int32_t max_stat_arg,
struct sastat *stat_res,
+ u_int32_t stat_res_size,
u_int32_t *max_stat_res)
{
int cur, found = 0;
max_stat_res == NULL) {
return -1;
}
+
+ u_int32_t max_stats = stat_res_size / (sizeof(struct sastat));
+ max_stats = ((max_stat_arg <= max_stats) ? max_stat_arg : max_stats);
- for (cur = 0; cur < max_stat_arg; cur++) {
+ for (cur = 0; cur < max_stats; cur++) {
if (key_getsastatbyspi_one(stat_arg[cur].spi,
&stat_res[found]) == 0) {
found++;
return EINVAL;
break;
}
+
+ /* check key bits length */
+ if (ext->sadb_ext_type == SADB_EXT_KEY_AUTH ||
+ ext->sadb_ext_type == SADB_EXT_KEY_ENCRYPT) {
+ struct sadb_key *key = (struct sadb_key *)(uintptr_t)ext;
+ if (len < (sizeof(struct sadb_key) + _KEYLEN(key))) {
+ return EINVAL;
+ }
+ }
return 0;
}
if (key_getsastatbyspi((struct sastat *)(sa_stats_arg + 1),
arg_count,
sa_stats_sav,
+ bufsize,
&res_count)) {
printf("%s: Error finding SAs.\n", __FUNCTION__);
error = ENOENT;