Skip to content

Commit 00bda45

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 00bda45

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-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: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8010,6 +8010,10 @@ ERL_NIF_TERM esock_setopt_sctp_events(ErlNifEnv* env,
80108010
{
80118011
struct sctp_event_subscribe events;
80128012
BOOLEAN_T error;
8013+
#if defined(__linux__)
8014+
int last_opt = offsetof(struct sctp_event_subscribe,
8015+
sctp_adaptation_layer_event) + 1;
8016+
#endif
80138017

80148018
SSDBG( descP,
80158019
("SOCKET", "esock_setopt_sctp_events {%d} -> entry with"
@@ -8047,20 +8051,32 @@ ERL_NIF_TERM esock_setopt_sctp_events(ErlNifEnv* env,
80478051
#if defined(HAVE_STRUCT_SCTP_EVENT_SUBSCRIBE_SCTP_AUTHENTICATION_EVENT)
80488052
events.sctp_authentication_event =
80498053
esock_setopt_sctp_event(env, eVal, atom_authentication, &error);
8054+
#if defined(__linux__)
8055+
last_opt = offsetof(struct sctp_event_subscribe,
8056+
sctp_authentication_event) + 1;
8057+
#endif
80508058
#endif
80518059

80528060
#if defined(HAVE_STRUCT_SCTP_EVENT_SUBSCRIBE_SCTP_SENDER_DRY_EVENT)
80538061
events.sctp_sender_dry_event =
80548062
esock_setopt_sctp_event(env, eVal, atom_sender_dry, &error);
8063+
#if defined(__linux__)
8064+
last_opt = offsetof(struct sctp_event_subscribe, sctp_sender_dry_event) + 1;
8065+
#endif
80558066
#endif
80568067

80578068
if (error) {
80588069
goto invalid;
80598070
} else {
80608071
ERL_NIF_TERM result;
8072+
#if defined(__linux__)
8073+
int arg_sz = last_opt;
8074+
#else
8075+
int arg_sz = sizeof(events);
8076+
#endif
80618077

80628078
result = esock_setopt_level_opt(env, descP, level, opt,
8063-
&events, sizeof(events));
8079+
&events, arg_sz);
80648080
SSDBG( descP,
80658081
("SOCKET",
80668082
"esock_setopt_sctp_events {%d} -> set events -> %T\r\n",

0 commit comments

Comments
 (0)