diff options
author | Jack Lloyd <[email protected]> | 2016-10-25 11:48:25 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-10-25 11:48:25 -0400 |
commit | e8908d4fb671f9aa014c64c4fe6f3105ac5c4907 (patch) | |
tree | 1ad7287b4ef2eab2b1bffd402a78706eaf96c316 /src/tests/test_rng.cpp | |
parent | 85f7f0db9e5f6da2503aaf601b54aa994dc33aba (diff) |
Static analyzer fixes
Check return value of read, found by Clang. See also #677
Remove unused member variable in OpenSSL ECC, found by Clang.
In ECDSA tests, if the pointer is null we should return rather
than dereferencing it. Found by Coverity.
Diffstat (limited to 'src/tests/test_rng.cpp')
-rw-r--r-- | src/tests/test_rng.cpp | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/src/tests/test_rng.cpp b/src/tests/test_rng.cpp index 920afef67..461aaa7c4 100644 --- a/src/tests/test_rng.cpp +++ b/src/tests/test_rng.cpp @@ -394,13 +394,13 @@ class HMAC_DRBG_Unit_Tests : public Test size_t count = counting_rng.randomize_count(); Botan::secure_vector<byte> parent_bytes(16), child_bytes(16); int fd[2]; - int rc = pipe(fd); + int rc = ::pipe(fd); if(rc != 0) { result.test_failure("failed to create pipe"); } - pid_t pid = fork(); + pid_t pid = ::fork(); if ( pid == -1 ) { result.test_failure("failed to fork process"); @@ -409,18 +409,34 @@ class HMAC_DRBG_Unit_Tests : public Test else if ( pid != 0 ) { // parent process, wait for randomize_count from child's rng - close(fd[1]); - read(fd[0], &count, sizeof(count)); - close(fd[0]); + ::close(fd[1]); + ssize_t got = ::read(fd[0], &count, sizeof(count)); + ::close(fd[0]); - - result.test_eq("parent not reseeded", counting_rng.randomize_count(), 1); - result.test_eq("child reseed occurred", count, 2); + if(got > 0) + { + result.test_eq("expected bytes from child", got, sizeof(count)); + result.test_eq("parent not reseeded", counting_rng.randomize_count(), 1); + result.test_eq("child reseed occurred", count, 2); + } + else + { + result.test_failure("Failed to read count size from child process"); + } parent_bytes = rng.random_vec(16); - read(fd[0], &child_bytes[0], child_bytes.size()); - result.test_ne("parent and child output sequences differ", parent_bytes, child_bytes); - close(fd[0]); + got = ::read(fd[0], &child_bytes[0], child_bytes.size()); + + if(got > 0) + { + result.test_eq("expected bytes from child", got, sizeof(count)); + result.test_ne("parent and child output sequences differ", parent_bytes, child_bytes); + } + else + { + result.test_failure("Failed to read count size from child process"); + } + ::close(fd[0]); int status = 0; ::waitpid(pid, &status, 0); @@ -428,14 +444,14 @@ class HMAC_DRBG_Unit_Tests : public Test else { // child process, send randomize_count and first output sequence back to parent - close(fd[0]); + ::close(fd[0]); rng.randomize(&child_bytes[0], child_bytes.size()); count = counting_rng.randomize_count(); - write(fd[1], &count, sizeof(count)); + ::write(fd[1], &count, sizeof(count)); rng.randomize(&child_bytes[0], child_bytes.size()); - write(fd[1], &child_bytes[0], child_bytes.size()); - close(fd[1]); - _exit(0); + ::write(fd[1], &child_bytes[0], child_bytes.size()); + ::close(fd[1]); + ::_exit(0); } #endif return result; |