Skip to content

Commit 9dc8a01

Browse files
committed
Limit size of sctp_event_subscribe on Linux
Use only the size which contains the last used option. This will help with compatibility since some vendor kernels have backported SCTP options turning simple backwards compatibility into breaking forward compatibility even for relatively similar versions. The Linux kernel is robust against using arbitrary sized structs.
1 parent 9efd029 commit 9dc8a01

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

erts/emulator/drivers/common/inet_drv.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8831,7 +8831,12 @@ static int sctp_set_opts(inet_descriptor* desc, char* ptr, int len)
88318831
proto = IPPROTO_SCTP;
88328832
type = SCTP_EVENTS;
88338833
arg_ptr = (char*) (&arg.es);
8834+
#if defined(__linux__)
8835+
arg_sz = offsetof(struct sctp_event_subscribe,
8836+
sctp_adaptation_layer_event) + 1;
8837+
#else
88348838
arg_sz = sizeof ( arg.es);
8839+
#endif
88358840
break;
88368841
}
88378842
/* The following is not available on

erts/emulator/nifs/common/prim_socket_nif.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8010,6 +8010,8 @@ ERL_NIF_TERM esock_setopt_sctp_events(ErlNifEnv* env,
80108010
{
80118011
struct sctp_event_subscribe events;
80128012
BOOLEAN_T error;
8013+
int last_opt = offsetof(struct sctp_event_subscribe,
8014+
sctp_adaptation_layer_event) + 1;
80138015

80148016
SSDBG( descP,
80158017
("SOCKET", "esock_setopt_sctp_events {%d} -> entry with"
@@ -8047,20 +8049,28 @@ ERL_NIF_TERM esock_setopt_sctp_events(ErlNifEnv* env,
80478049
#if defined(HAVE_STRUCT_SCTP_EVENT_SUBSCRIBE_SCTP_AUTHENTICATION_EVENT)
80488050
events.sctp_authentication_event =
80498051
esock_setopt_sctp_event(env, eVal, atom_authentication, &error);
8052+
last_opt = offsetof(struct sctp_event_subscribe,
8053+
sctp_authentication_event) + 1;
80508054
#endif
80518055

80528056
#if defined(HAVE_STRUCT_SCTP_EVENT_SUBSCRIBE_SCTP_SENDER_DRY_EVENT)
80538057
events.sctp_sender_dry_event =
80548058
esock_setopt_sctp_event(env, eVal, atom_sender_dry, &error);
8059+
last_opt = offsetof(struct sctp_event_subscribe, sctp_sender_dry_event) + 1;
80558060
#endif
80568061

80578062
if (error) {
80588063
goto invalid;
80598064
} else {
80608065
ERL_NIF_TERM result;
8066+
#if defined(__linux__)
8067+
int arg_sz = last_opt;
8068+
#else
8069+
int arg_sz = sizeof(events);
8070+
#endif
80618071

80628072
result = esock_setopt_level_opt(env, descP, level, opt,
8063-
&events, sizeof(events));
8073+
&events, arg_sz);
80648074
SSDBG( descP,
80658075
("SOCKET",
80668076
"esock_setopt_sctp_events {%d} -> set events -> %T\r\n",

0 commit comments

Comments
 (0)