diff --git a/daemon/rtcp.c b/daemon/rtcp.c index 4d0decf3e..7c197d2f4 100644 --- a/daemon/rtcp.c +++ b/daemon/rtcp.c @@ -774,13 +774,13 @@ INLINE int check_session_keys(struct crypto_context *c) { goto error; err = "Failed to generate SRTCP session keys"; - str_init_len_assert(&s, c->session_key, c->params.crypto_suite->session_key_len); + s = STR_LEN_ASSERT(c->session_key, c->params.crypto_suite->session_key_len); if (crypto_gen_session_key(c, &s, 0x03, SRTCP_R_LENGTH)) goto error; - str_init_len_assert(&s, c->session_auth_key, c->params.crypto_suite->srtcp_auth_key_len); + s = STR_LEN_ASSERT(c->session_auth_key, c->params.crypto_suite->srtcp_auth_key_len); if (crypto_gen_session_key(c, &s, 0x04, SRTCP_R_LENGTH)) goto error; - str_init_len_assert(&s, c->session_salt, c->params.crypto_suite->session_salt_len); + s = STR_LEN_ASSERT(c->session_salt, c->params.crypto_suite->session_salt_len); if (crypto_gen_session_key(c, &s, 0x05, SRTCP_R_LENGTH)) goto error; diff --git a/daemon/rtp.c b/daemon/rtp.c index c2fc9d3c1..b07a8bc25 100644 --- a/daemon/rtp.c +++ b/daemon/rtp.c @@ -23,13 +23,13 @@ INLINE int check_session_keys(struct crypto_context *c) { goto error; err = "Failed to generate SRTP session keys"; - str_init_len_assert(&s, c->session_key, c->params.crypto_suite->session_key_len); + s = STR_LEN_ASSERT(c->session_key, c->params.crypto_suite->session_key_len); if (crypto_gen_session_key(c, &s, 0x00, 6)) goto error; - str_init_len_assert(&s, c->session_auth_key, c->params.crypto_suite->srtp_auth_key_len); + s = STR_LEN_ASSERT(c->session_auth_key, c->params.crypto_suite->srtp_auth_key_len); if (crypto_gen_session_key(c, &s, 0x01, 6)) goto error; - str_init_len_assert(&s, c->session_salt, c->params.crypto_suite->session_salt_len); + s = STR_LEN_ASSERT(c->session_salt, c->params.crypto_suite->session_salt_len); if (crypto_gen_session_key(c, &s, 0x02, 6)) goto error; diff --git a/lib/str.h b/lib/str.h index 3fdabd15f..658ec165a 100644 --- a/lib/str.h +++ b/lib/str.h @@ -40,6 +40,7 @@ TYPED_GQUEUE(str, str) #define STR(s) ((str) { (char *) (s), (s) ? strlen(s) : 0 }) #define STR_GS(s) ((str) { (s)->str, (s)->len }) #define STR_LEN(s, len) ((str) { (char *) (s), len }) +#define STR_LEN_ASSERT(s, len) ({ assert(sizeof(s) >= len); (str) { (char *) (s), len }; }) #define STR_INIT_DUP(s) ((str) { g_strdup(s), strlen(s) }) #define STR_CONST_BUF(buf) ((str) { (char *) &buf, sizeof(buf) }) @@ -81,10 +82,6 @@ INLINE int str_casecmp_str(const str *a, const str *b); ACCESS(read_only, 1) ACCESS(read_only, 2) INLINE int str_cmp_str0(const str *a, const str *b); -/* inits a str object from any binary string. returns out */ -__attribute__((nonnull(1, 2))) -INLINE str *str_init_len_assert_len(str *out, char *s, size_t buflen, size_t len); -#define str_init_len_assert(out, s, len) str_init_len_assert_len(out, s, sizeof(s), len) /* inits a str object from a regular string and duplicates the contents. returns out */ __attribute__((nonnull(1))) ACCESS(write_only, 1) @@ -298,11 +295,6 @@ INLINE int str_cmp_str0(const str *a, const str *b) { } return str_cmp_str(a, b); } -INLINE str *str_init_len_assert_len(str *out, char *s, size_t buflen, size_t len) { - assert(buflen >= len); - *out = STR_LEN(s, len); - return out; -} INLINE str *str_init_dup(str *out, const char *s) { out->s = s ? g_strdup(s) : NULL; out->len = s ? strlen(s) : 0; diff --git a/t/aes-crypt.c b/t/aes-crypt.c index 5a7e652b0..9f8be4c5a 100644 --- a/t/aes-crypt.c +++ b/t/aes-crypt.c @@ -183,13 +183,13 @@ extern void crypto_init_main(void); void check_session_keys(struct crypto_context *c, int i) { str s; - str_init_len_assert(&s, c->session_key, c->params.crypto_suite->session_key_len); + s = STR_LEN_ASSERT(c->session_key, c->params.crypto_suite->session_key_len); if (crypto_gen_session_key(c, &s, i++, 6)) goto error; - str_init_len_assert(&s, c->session_auth_key, c->params.crypto_suite->srtp_auth_key_len); + s = STR_LEN_ASSERT(c->session_auth_key, c->params.crypto_suite->srtp_auth_key_len); if (crypto_gen_session_key(c, &s, i++, 6)) goto error; - str_init_len_assert(&s, c->session_salt, c->params.crypto_suite->session_salt_len); + s = STR_LEN_ASSERT(c->session_salt, c->params.crypto_suite->session_salt_len); if (crypto_gen_session_key(c, &s, i, 6)) goto error;