mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2024-12-26 18:20:21 +00:00
test/pkcs7: Fix TOCTOU race condition
Separately checking the state of a file before operating on it may allow an attacker to modify the file between the two operations. (CWE-367) Signed-off-by: Mingjie Shen <shen497@purdue.edu>
This commit is contained in:
parent
31403a4ca8
commit
9f80b23edb
@ -121,12 +121,12 @@ void pkcs7_verify(char *pkcs7_file,
|
||||
TEST_EQUAL(res, 0);
|
||||
}
|
||||
|
||||
res = stat(filetobesigned, &st);
|
||||
TEST_EQUAL(res, 0);
|
||||
|
||||
file = fopen(filetobesigned, "rb");
|
||||
TEST_ASSERT(file != NULL);
|
||||
|
||||
res = fstat(fileno(file), &st);
|
||||
TEST_EQUAL(res, 0);
|
||||
|
||||
datalen = st.st_size;
|
||||
/* Special-case for zero-length input so that data will be non-NULL */
|
||||
TEST_CALLOC(data, datalen == 0 ? 1 : datalen);
|
||||
|
Loading…
Reference in New Issue
Block a user