Skip to content
Snippets Groups Projects
Commit ec08da89 authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #9782: fix ARRAYSIZE check

parent 44729d3e
No related branches found
No related tags found
No related merge requests found
......@@ -51,7 +51,8 @@ noinst_HEADERS = \
noncopyable.h \
cc_thread.h \
cc_config.h \
sfl_types.h
sfl_types.h \
array_size.h
libsflphone_la_LIBADD = \
$(top_builddir)/libs/iax2/libiax2.la \
......
/*
* Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
* Author: Tristan Matthews <tristan.matthews@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Additional permission under GNU GPL version 3 section 7:
*
* If you modify this program, or any covered work, by linking or
* combining it with the OpenSSL project's OpenSSL library (or a
* modified version of that library), containing parts covered by the
* terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
* grants you additional permission to convey the resulting work.
* Corresponding Source for a non-source form of such a combination
* shall include the source code for the parts of OpenSSL used as well
* as that of the covered work.
*/
#ifndef ARRAY_SIZE_H_
#define ARRAY_SIZE_H_
// Returns the number of elements in a, calculated at compile-time
#define ARRAYSIZE(a) \
((sizeof(a) / sizeof(*(a))) / \
static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
#endif // ARRAY_SIZE_H_
......@@ -29,6 +29,7 @@
*/
#include "audio_srtp_session.h"
#include "logger.h"
#include "array_size.h"
#include <openssl/sha.h>
#include <openssl/hmac.h>
......@@ -103,12 +104,9 @@ namespace {
std::vector<unsigned char> random_key(length);
// Generate ryptographically strong pseudo-random bytes
int err;
if ((err = RAND_bytes(&(*random_key.begin()), length)) != 1)
if (RAND_bytes(&(*random_key.begin()), length) != 1)
DEBUG("Error occured while generating cryptographically strong pseudo-random key");
assert((sizeof dest / sizeof dest[0]) <= length);
memcpy(dest, &(*random_key.begin()), length);
}
}
......@@ -211,6 +209,7 @@ void AudioSrtpSession::initializeLocalMasterKey()
DEBUG("AudioSrtp: Init local master key");
// @TODO key may have different length depending on cipher suite
localMasterKeyLength_ = sfl::CryptoSuites[localCryptoSuite_].masterKeyLength / 8;
assert(ARRAYSIZE(localMasterKey_) >= localMasterKeyLength_);
DEBUG("AudioSrtp: Local master key length %d", localMasterKeyLength_);
buffer_fill(localMasterKey_, localMasterKeyLength_);
}
......@@ -219,6 +218,7 @@ void AudioSrtpSession::initializeLocalMasterSalt()
{
// @TODO key may have different length depending on cipher suite
localMasterSaltLength_ = sfl::CryptoSuites[localCryptoSuite_].masterSaltLength / 8;
assert(ARRAYSIZE(localMasterSalt_) >= localMasterSaltLength_);
DEBUG("AudioSrtp: Local master salt length %d", localMasterSaltLength_);
buffer_fill(localMasterSalt_, localMasterSaltLength_);
}
......
......@@ -153,22 +153,22 @@ class AudioSrtpSession : public AudioSymmetricRtpSession {
uint8 localMasterKey_[16];
/** local master key length in byte */
int localMasterKeyLength_;
size_t localMasterKeyLength_;
uint8 localMasterSalt_[14];
/** local master salt length in byte */
int localMasterSaltLength_;
size_t localMasterSaltLength_;
uint8 remoteMasterKey_[16];
/** remote master key length in byte */
int remoteMasterKeyLength_;
size_t remoteMasterKeyLength_;
uint8 remoteMasterSalt_[14];
/** remote master salt length in byte */
int remoteMasterSaltLength_;
size_t remoteMasterSaltLength_;
/** Used to make sure remote crypto context not initialized wice. */
bool remoteOfferIsSet_;
......
......@@ -31,6 +31,7 @@
#include "delaydetectiontest.h"
#include <cstring>
#include "array_size.h"
void DelayDetectionTest::testCrossCorrelation()
{
......
......@@ -34,9 +34,4 @@
#define TITLE() DEBUG("-------------------- %s --------------------\n", \
__PRETTY_FUNCTION__)
// Returns the number of elements in a, calculated at compile-time
#define ARRAYSIZE(a) \
((sizeof(a) / sizeof(*(a))) / \
static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
#endif // TEST_UTILS_H_
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment