sock: add assertions checking sock_impl_opts size
Signed-off-by: Konrad Sztyber <konrad.sztyber@intel.com> Change-Id: I5afc3481470f876a59505d9c4c9dc3d699c5cfd9 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13714 Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com> Community-CI: Mellanox Build Bot Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Dong Yi <dongx.yi@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
5e0399cba4
commit
bae771fcdb
@ -130,6 +130,8 @@ posix_sock_impl_get_opts(struct spdk_sock_impl_opts *opts, size_t *len)
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
assert(sizeof(*opts) >= *len);
|
||||
memset(opts, 0, *len);
|
||||
|
||||
posix_sock_copy_impl_opts(opts, &g_spdk_posix_sock_impl_opts, *len);
|
||||
@ -146,6 +148,7 @@ posix_sock_impl_set_opts(const struct spdk_sock_impl_opts *opts, size_t len)
|
||||
return -1;
|
||||
}
|
||||
|
||||
assert(sizeof(*opts) >= len);
|
||||
posix_sock_copy_impl_opts(&g_spdk_posix_sock_impl_opts, opts, len);
|
||||
|
||||
return 0;
|
||||
@ -158,6 +161,7 @@ posix_opts_get_impl_opts(const struct spdk_sock_opts *opts, struct spdk_sock_imp
|
||||
memcpy(dest, &g_spdk_posix_sock_impl_opts, sizeof(*dest));
|
||||
|
||||
if (opts->impl_opts != NULL) {
|
||||
assert(sizeof(*dest) >= opts->impl_opts_size);
|
||||
posix_sock_copy_impl_opts(dest, opts->impl_opts, opts->impl_opts_size);
|
||||
}
|
||||
}
|
||||
|
@ -150,6 +150,8 @@ uring_sock_impl_get_opts(struct spdk_sock_impl_opts *opts, size_t *len)
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
assert(sizeof(*opts) >= *len);
|
||||
memset(opts, 0, *len);
|
||||
|
||||
uring_sock_copy_impl_opts(opts, &g_spdk_uring_sock_impl_opts, *len);
|
||||
@ -166,6 +168,7 @@ uring_sock_impl_set_opts(const struct spdk_sock_impl_opts *opts, size_t len)
|
||||
return -1;
|
||||
}
|
||||
|
||||
assert(sizeof(*opts) >= len);
|
||||
uring_sock_copy_impl_opts(&g_spdk_uring_sock_impl_opts, opts, len);
|
||||
|
||||
return 0;
|
||||
@ -178,6 +181,7 @@ uring_opts_get_impl_opts(const struct spdk_sock_opts *opts, struct spdk_sock_imp
|
||||
memcpy(dest, &g_spdk_uring_sock_impl_opts, sizeof(*dest));
|
||||
|
||||
if (opts->impl_opts != NULL) {
|
||||
assert(sizeof(*dest) >= opts->impl_opts_size);
|
||||
uring_sock_copy_impl_opts(dest, opts->impl_opts, opts->impl_opts_size);
|
||||
}
|
||||
}
|
||||
|
@ -911,7 +911,6 @@ posix_sock_impl_get_set_opts(void)
|
||||
int rc;
|
||||
size_t len = 0;
|
||||
struct spdk_sock_impl_opts opts = {};
|
||||
struct spdk_sock_impl_opts long_opts[2];
|
||||
|
||||
rc = spdk_sock_impl_get_opts("posix", NULL, &len);
|
||||
CU_ASSERT(rc == -1);
|
||||
@ -928,12 +927,6 @@ posix_sock_impl_get_set_opts(void)
|
||||
CU_ASSERT(opts.recv_buf_size == MIN_SO_RCVBUF_SIZE);
|
||||
CU_ASSERT(opts.send_buf_size == MIN_SO_SNDBUF_SIZE);
|
||||
|
||||
/* Try to request more opts */
|
||||
len = sizeof(long_opts);
|
||||
rc = spdk_sock_impl_get_opts("posix", long_opts, &len);
|
||||
CU_ASSERT(rc == 0);
|
||||
CU_ASSERT(len == sizeof(opts));
|
||||
|
||||
/* Try to request zero opts */
|
||||
len = 0;
|
||||
rc = spdk_sock_impl_get_opts("posix", &opts, &len);
|
||||
@ -955,14 +948,6 @@ posix_sock_impl_get_set_opts(void)
|
||||
CU_ASSERT(opts.recv_buf_size == 16);
|
||||
CU_ASSERT(opts.send_buf_size == 4);
|
||||
|
||||
/* Try to set more opts */
|
||||
long_opts[0].recv_buf_size = 4;
|
||||
long_opts[0].send_buf_size = 6;
|
||||
long_opts[1].recv_buf_size = 0;
|
||||
long_opts[1].send_buf_size = 0;
|
||||
rc = spdk_sock_impl_set_opts("posix", long_opts, sizeof(long_opts));
|
||||
CU_ASSERT(rc == 0);
|
||||
|
||||
/* Try to set less opts. Opts in the end should be untouched */
|
||||
opts.recv_buf_size = 5;
|
||||
opts.send_buf_size = 10;
|
||||
@ -973,7 +958,7 @@ posix_sock_impl_get_set_opts(void)
|
||||
rc = spdk_sock_impl_get_opts("posix", &opts, &len);
|
||||
CU_ASSERT(rc == 0);
|
||||
CU_ASSERT(opts.recv_buf_size == 5);
|
||||
CU_ASSERT(opts.send_buf_size == 6);
|
||||
CU_ASSERT(opts.send_buf_size == 4);
|
||||
|
||||
/* Try to set partial option. It should not be changed */
|
||||
opts.recv_buf_size = 1000;
|
||||
|
Loading…
Reference in New Issue
Block a user