diff options
| author | jhurst <jhurst@cinecert.com> | 2007-01-19 08:58:05 +0000 |
|---|---|---|
| committer | jhurst <> | 2007-01-19 08:58:05 +0000 |
| commit | 984de376d405e0b68e77d61558d4f798fa1170a5 (patch) | |
| tree | 9767cbae4ad744b88285c8671af60b22c54dfa5d | |
| parent | f0476a3789369459fb91076af4a29372d86d7622 (diff) | |
updated TEST_NULL debug macros
fixed ReadFileIntoString buffer bug
| -rwxr-xr-x | README | 4 | ||||
| -rwxr-xr-x | src/AS_DCP.h | 4 | ||||
| -rwxr-xr-x | src/AS_DCP_AES.cpp | 36 | ||||
| -rw-r--r-- | src/KM_fileio.cpp | 50 | ||||
| -rwxr-xr-x | src/KM_log.h | 20 | ||||
| -rwxr-xr-x | src/KM_util.cpp | 6 | ||||
| -rwxr-xr-x | src/KM_util.h | 4 | ||||
| -rwxr-xr-x | src/asdcp-test.cpp | 14 |
8 files changed, 88 insertions, 50 deletions
@@ -113,6 +113,10 @@ utilities all respond to -h and there are manual pages in man/. Change History +xxx.xx.xx - Bug fixes v1.1.13 + o Removed default parameter to HMACContext::InitKey(). + o Cleaned up messages and CLI arg handling in asdcp-test. + 2006.11.19 - Mo better stuff v1.1.12 o Changed read-only Result_t accessor methods to const. o Added Base64 (-B) option to kmrandgen. diff --git a/src/AS_DCP.h b/src/AS_DCP.h index 5dc358c..4e10d09 100755 --- a/src/AS_DCP.h +++ b/src/AS_DCP.h @@ -144,7 +144,7 @@ namespace ASDCP { // 1.0.1. If changes were also required in AS_DCP.h, the new version would be 1.1.1. const ui32_t VERSION_MAJOR = 1; const ui32_t VERSION_APIMINOR = 1; - const ui32_t VERSION_IMPMINOR = 12; + const ui32_t VERSION_IMPMINOR = 13; const char* Version(); // UUIDs are passed around as strings of UUIDlen bytes @@ -408,7 +408,7 @@ namespace ASDCP { // Initializes HMAC context. The key argument must point to a binary // key that is CBC_KEY_SIZE bytes in length. Returns error if the key // argument is NULL. - Result_t InitKey(const byte_t* key, LabelSet_t = LS_MXF_INTEROP); + Result_t InitKey(const byte_t* key, LabelSet_t); // Reset internal state, allows repeated cycles of Update -> Finalize void Reset(); diff --git a/src/AS_DCP_AES.cpp b/src/AS_DCP_AES.cpp index fc10425..037e68d 100755 --- a/src/AS_DCP_AES.cpp +++ b/src/AS_DCP_AES.cpp @@ -38,12 +38,20 @@ using Kumu::DefaultLogSink; using namespace ASDCP; const int KEY_SIZE_BITS = 128; - #include <openssl/aes.h> #include <openssl/sha.h> #include <openssl/bn.h> #include <openssl/err.h> +#if OPENSSL_VERSION_NUMBER < 0x0090804f +# error OpenSSL version mismatch +#endif + +#ifndef OPENSSL_VERSION_NUMBER +#error OPENSSL_VERSION_NUMBER not defined +#endif + + void print_ssl_error() { @@ -69,7 +77,7 @@ ASDCP::AESEncContext::~AESEncContext() {} ASDCP::Result_t ASDCP::AESEncContext::InitKey(const byte_t* key) { - ASDCP_TEST_NULL(key); + KM_TEST_NULL_L(key); if ( m_Context ) return RESULT_INIT; @@ -92,7 +100,7 @@ ASDCP::AESEncContext::InitKey(const byte_t* key) ASDCP::Result_t ASDCP::AESEncContext::SetIVec(const byte_t* i_vec) { - ASDCP_TEST_NULL(i_vec); + KM_TEST_NULL_L(i_vec); if ( ! m_Context ) return RESULT_INIT; @@ -107,7 +115,7 @@ ASDCP::AESEncContext::SetIVec(const byte_t* i_vec) ASDCP::Result_t ASDCP::AESEncContext::GetIVec(byte_t* i_vec) const { - ASDCP_TEST_NULL(i_vec); + KM_TEST_NULL_L(i_vec); if ( ! m_Context ) return RESULT_INIT; @@ -122,8 +130,8 @@ ASDCP::AESEncContext::GetIVec(byte_t* i_vec) const ASDCP::Result_t ASDCP::AESEncContext::EncryptBlock(const byte_t* pt_buf, byte_t* ct_buf, ui32_t block_size) { - ASDCP_TEST_NULL(pt_buf); - ASDCP_TEST_NULL(ct_buf); + KM_TEST_NULL_L(pt_buf); + KM_TEST_NULL_L(ct_buf); assert(block_size > 0); assert( block_size % CBC_BLOCK_SIZE == 0 ); @@ -170,7 +178,7 @@ ASDCP::AESDecContext::~AESDecContext() {} ASDCP::Result_t ASDCP::AESDecContext::InitKey(const byte_t* key) { - ASDCP_TEST_NULL(key); + KM_TEST_NULL_L(key); if ( m_Context ) return RESULT_INIT; @@ -192,7 +200,7 @@ ASDCP::AESDecContext::InitKey(const byte_t* key) ASDCP::Result_t ASDCP::AESDecContext::SetIVec(const byte_t* i_vec) { - ASDCP_TEST_NULL(i_vec); + KM_TEST_NULL_L(i_vec); if ( ! m_Context ) return RESULT_INIT; @@ -206,8 +214,8 @@ ASDCP::AESDecContext::SetIVec(const byte_t* i_vec) ASDCP::Result_t ASDCP::AESDecContext::DecryptBlock(const byte_t* ct_buf, byte_t* pt_buf, ui32_t block_size) { - ASDCP_TEST_NULL(ct_buf); - ASDCP_TEST_NULL(pt_buf); + KM_TEST_NULL_L(ct_buf); + KM_TEST_NULL_L(pt_buf); assert(block_size > 0); assert( block_size % CBC_BLOCK_SIZE == 0 ); @@ -406,7 +414,7 @@ HMACContext::~HMACContext() Result_t HMACContext::InitKey(const byte_t* key, LabelSet_t SetType) { - ASDCP_TEST_NULL(key); + KM_TEST_NULL_L(key); m_Context = new h__HMACContext; @@ -436,7 +444,7 @@ HMACContext::Reset() Result_t HMACContext::Update(const byte_t* buf, ui32_t buf_len) { - ASDCP_TEST_NULL(buf); + KM_TEST_NULL_L(buf); if ( m_Context.empty() || m_Context->m_Final ) return RESULT_INIT; @@ -462,7 +470,7 @@ HMACContext::Finalize() Result_t HMACContext::GetHMACValue(byte_t* buf) const { - ASDCP_TEST_NULL(buf); + KM_TEST_NULL_L(buf); if ( m_Context.empty() || ! m_Context->m_Final ) return RESULT_INIT; @@ -476,7 +484,7 @@ HMACContext::GetHMACValue(byte_t* buf) const Result_t HMACContext::TestHMACValue(const byte_t* buf) const { - ASDCP_TEST_NULL(buf); + KM_TEST_NULL_L(buf); if ( m_Context.empty() || ! m_Context->m_Final ) return RESULT_INIT; diff --git a/src/KM_fileio.cpp b/src/KM_fileio.cpp index ef1c9dc..e0a83ea 100644 --- a/src/KM_fileio.cpp +++ b/src/KM_fileio.cpp @@ -57,8 +57,8 @@ typedef struct stat fstat_t; static Kumu::Result_t do_stat(const char* path, fstat_t* stat_info) { - KM_TEST_NULL_STR(path); - KM_TEST_NULL(stat_info); + KM_TEST_NULL_STR_L(path); + KM_TEST_NULL_L(stat_info); Kumu::Result_t result = Kumu::RESULT_OK; @@ -86,7 +86,7 @@ do_stat(const char* path, fstat_t* stat_info) static Kumu::Result_t do_fstat(HANDLE handle, fstat_t* stat_info) { - KM_TEST_NULL(stat_info); + KM_TEST_NULL_L(stat_info); Kumu::Result_t result = Kumu::RESULT_OK; @@ -198,7 +198,7 @@ Kumu::FileWriter::Writev(const byte_t* buf, ui32_t buf_len) { assert( ! m_IOVec.empty() ); register h__iovec* iov = m_IOVec; - KM_TEST_NULL(buf); + KM_TEST_NULL_L(buf); if ( iov->m_Count >= IOVecMaxEntries ) { @@ -222,7 +222,7 @@ Kumu::FileWriter::Writev(const byte_t* buf, ui32_t buf_len) Kumu::Result_t Kumu::FileReader::OpenRead(const char* filename) const { - KM_TEST_NULL_STR(filename); + KM_TEST_NULL_STR_L(filename); const_cast<FileReader*>(this)->m_Filename = filename; // suppress popup window on error @@ -285,7 +285,7 @@ Kumu::FileReader::Seek(Kumu::fpos_t position, SeekPos_t whence) const Kumu::Result_t Kumu::FileReader::Tell(Kumu::fpos_t* pos) const { - KM_TEST_NULL(pos); + KM_TEST_NULL_L(pos); if ( m_Handle == (HANDLE)-1L ) return Kumu::RESULT_FILEOPEN; @@ -310,7 +310,7 @@ Kumu::FileReader::Tell(Kumu::fpos_t* pos) const Kumu::Result_t Kumu::FileReader::Read(byte_t* buf, ui32_t buf_len, ui32_t* read_count) const { - KM_TEST_NULL(buf); + KM_TEST_NULL_L(buf); Result_t result = Kumu::RESULT_OK; DWORD tmp_count; ui32_t tmp_int; @@ -347,7 +347,7 @@ Kumu::FileReader::Read(byte_t* buf, ui32_t buf_len, ui32_t* read_count) const Kumu::Result_t Kumu::FileWriter::OpenWrite(const char* filename) { - KM_TEST_NULL_STR(filename); + KM_TEST_NULL_STR_L(filename); m_Filename = filename; // suppress popup window on error @@ -419,7 +419,7 @@ Kumu::FileWriter::Writev(ui32_t* bytes_written) Kumu::Result_t Kumu::FileWriter::Write(const byte_t* buf, ui32_t buf_len, ui32_t* bytes_written) { - KM_TEST_NULL(buf); + KM_TEST_NULL_L(buf); ui32_t tmp_int; if ( bytes_written == 0 ) @@ -444,7 +444,7 @@ Kumu::FileWriter::Write(const byte_t* buf, ui32_t buf_len, ui32_t* bytes_written Kumu::Result_t Kumu::FileReader::OpenRead(const char* filename) const { - KM_TEST_NULL_STR(filename); + KM_TEST_NULL_STR_L(filename); const_cast<FileReader*>(this)->m_Filename = filename; const_cast<FileReader*>(this)->m_Handle = open(filename, O_RDONLY, 0); return ( m_Handle == -1L ) ? RESULT_FILEOPEN : RESULT_OK; @@ -479,7 +479,7 @@ Kumu::FileReader::Seek(Kumu::fpos_t position, SeekPos_t whence) const Kumu::Result_t Kumu::FileReader::Tell(Kumu::fpos_t* pos) const { - KM_TEST_NULL(pos); + KM_TEST_NULL_L(pos); if ( m_Handle == -1L ) return RESULT_FILEOPEN; @@ -497,7 +497,7 @@ Kumu::FileReader::Tell(Kumu::fpos_t* pos) const Kumu::Result_t Kumu::FileReader::Read(byte_t* buf, ui32_t buf_len, ui32_t* read_count) const { - KM_TEST_NULL(buf); + KM_TEST_NULL_L(buf); i32_t tmp_count = 0; ui32_t tmp_int = 0; @@ -524,7 +524,7 @@ Kumu::FileReader::Read(byte_t* buf, ui32_t buf_len, ui32_t* read_count) const Kumu::Result_t Kumu::FileWriter::OpenWrite(const char* filename) { - KM_TEST_NULL_STR(filename); + KM_TEST_NULL_STR_L(filename); m_Filename = filename; m_Handle = open(filename, O_RDWR|O_CREAT|O_TRUNC, 0664); @@ -542,7 +542,7 @@ Kumu::FileWriter::OpenWrite(const char* filename) Kumu::Result_t Kumu::FileWriter::OpenModify(const char* filename) { - KM_TEST_NULL_STR(filename); + KM_TEST_NULL_STR_L(filename); m_Filename = filename; m_Handle = open(filename, O_RDWR|O_CREAT, 0664); @@ -584,7 +584,7 @@ Kumu::FileWriter::Writev(ui32_t* bytes_written) Kumu::Result_t Kumu::FileWriter::Write(const byte_t* buf, ui32_t buf_len, ui32_t* bytes_written) { - KM_TEST_NULL(buf); + KM_TEST_NULL_L(buf); ui32_t tmp_int; if ( bytes_written == 0 ) @@ -620,7 +620,7 @@ Kumu::ReadFileIntoString(const char* filename, std::string& outString, ui32_t ma FileReader File; ByteString ReadBuf; - KM_TEST_NULL_STR(filename); + KM_TEST_NULL_STR_L(filename); Result_t result = File.OpenRead(filename); @@ -630,7 +630,13 @@ Kumu::ReadFileIntoString(const char* filename, std::string& outString, ui32_t ma if ( fsize > (Kumu::fpos_t)max_size ) { - DefaultLogSink().Error("%s: exceeds available buffer size (%u)", filename, max_size); + DefaultLogSink().Error("%s: exceeds available buffer size (%u)\n", filename, max_size); + return RESULT_ALLOC; + } + + if ( fsize == 0 ) + { + DefaultLogSink().Error("%s: zero file size\n", filename); return RESULT_ALLOC; } @@ -653,7 +659,7 @@ Kumu::WriteStringIntoFile(const char* filename, const std::string& inString) { FileWriter File; ui32_t write_count = 0; - KM_TEST_NULL_STR(filename); + KM_TEST_NULL_STR_L(filename); Result_t result = File.OpenWrite(filename); @@ -679,7 +685,7 @@ Kumu::WriteStringIntoFile(const char* filename, const std::string& inString) Result_t Kumu::DirScanner::Open(const char* filename) { - KM_TEST_NULL_STR(filename); + KM_TEST_NULL_STR_L(filename); // we need to append a '*' to read the entire directory ui32_t fn_len = strlen(filename); @@ -732,7 +738,7 @@ Kumu::DirScanner::Close() Result_t Kumu::DirScanner::GetNext(char* filename) { - KM_TEST_NULL(filename); + KM_TEST_NULL_L(filename); if ( m_Handle == -1 ) return RESULT_FILEOPEN; @@ -763,7 +769,7 @@ Kumu::DirScanner::GetNext(char* filename) Result_t Kumu::DirScanner::Open(const char* filename) { - KM_TEST_NULL_STR(filename); + KM_TEST_NULL_STR_L(filename); Result_t result = RESULT_OK; @@ -799,7 +805,7 @@ Kumu::DirScanner::Close() Result_t Kumu::DirScanner::GetNext(char* filename) { - KM_TEST_NULL(filename); + KM_TEST_NULL_L(filename); if ( m_Handle == NULL ) return RESULT_FILEOPEN; diff --git a/src/KM_log.h b/src/KM_log.h index 2bbc330..9838f4c 100755 --- a/src/KM_log.h +++ b/src/KM_log.h @@ -41,6 +41,26 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define LOG_MSG_IMPL(t) va_list args; va_start(args, fmt); vLogf((t), fmt, &args); va_end(args) + +// Returns RESULT_PTR if the given argument is NULL. +# define KM_TEST_NULL_L(p) \ + if ( (p) == 0 ) { \ + DefaultLogSink().Error("NULL pointer in file %s, line %d\n", __FILE__, __LINE__); \ + return Kumu::RESULT_PTR; \ + } + +// Returns RESULT_PTR if the given argument is NULL. It then +// assumes that the argument is a pointer to a string and returns +// RESULT_NULL_STR if the first character is '\0'. +// +# define KM_TEST_NULL_STR_L(p) \ + KM_TEST_NULL_L(p); \ + if ( (p)[0] == '\0' ) { \ + DefaultLogSink().Error("Empty string in file %s, line %d\n", __FILE__, __LINE__); \ + return Kumu::RESULT_NULL_STR; \ + } + + namespace Kumu { // no log message will exceed this length diff --git a/src/KM_util.cpp b/src/KM_util.cpp index 339f78b..867f236 100755 --- a/src/KM_util.cpp +++ b/src/KM_util.cpp @@ -267,9 +267,9 @@ Kumu::base64decode(const char* str, byte_t* buf, ui32_t buf_len, ui32_t* char_co i32_t Kumu::hex2bin(const char* str, byte_t* buf, ui32_t buf_len, ui32_t* conv_size) { - KM_TEST_NULL(str); - KM_TEST_NULL(buf); - KM_TEST_NULL(conv_size); + KM_TEST_NULL_L(str); + KM_TEST_NULL_L(buf); + KM_TEST_NULL_L(conv_size); *conv_size = 0; diff --git a/src/KM_util.h b/src/KM_util.h index f80f028..6b2e78e 100755 --- a/src/KM_util.h +++ b/src/KM_util.h @@ -381,10 +381,10 @@ namespace Kumu inline ui32_t Capacity() const { return m_Capacity; } // returns a const pointer to the essence data - inline const byte_t* RoData() const { return m_Data; } + inline const byte_t* RoData() const { assert(m_Data); return m_Data; } // returns a non-const pointer to the essence data - inline byte_t* Data() { return m_Data; } + inline byte_t* Data() { assert(m_Data); return m_Data; } // set the length of the buffer's contents inline ui32_t Length(ui32_t l) { return m_Length = l; } diff --git a/src/asdcp-test.cpp b/src/asdcp-test.cpp index 3d802e9..a2901da 100755 --- a/src/asdcp-test.cpp +++ b/src/asdcp-test.cpp @@ -330,7 +330,7 @@ public: if ( length != KeyLen ) { - fprintf(stderr, "Unexpected key length: %u, expecting %u characters.\n", KeyLen, length); + fprintf(stderr, "Unexpected key length: %u, expecting %u characters.\n", length, KeyLen); return; } } @@ -344,7 +344,7 @@ public: if ( length != UUIDlen ) { - fprintf(stderr, "Unexpected key ID length: %u, expecting %u characters.\n", UUIDlen, length); + fprintf(stderr, "Unexpected key ID length: %u, expecting %u characters.\n", length, UUIDlen); return; } } @@ -352,30 +352,30 @@ public: case 'f': TEST_EXTRA_ARG(i, 'f'); - start_frame = atoi(argv[i]); // TODO: test for negative value, should use strtol() + start_frame = abs(atoi(argv[i])); break; case 'd': TEST_EXTRA_ARG(i, 'd'); duration_flag = true; - duration = atoi(argv[i]); // TODO: test for negative value, should use strtol() + duration = abs(atoi(argv[i])); break; case 'p': TEST_EXTRA_ARG(i, 'p'); - picture_rate = atoi(argv[i]); + picture_rate = abs(atoi(argv[i])); break; case 's': TEST_EXTRA_ARG(i, 's'); - fb_dump_size = atoi(argv[i]); + fb_dump_size = abs(atoi(argv[i])); break; case 't': mode = MMT_DIGEST; break; case 'b': TEST_EXTRA_ARG(i, 'b'); - fb_size = atoi(argv[i]); + fb_size = abs(atoi(argv[i])); if ( verbose_flag ) fprintf(stderr, "Frame Buffer size: %u bytes.\n", fb_size); |
