Fix warnings reported by static analysis.

- ensure that strings are \0 terminated (most of this is already
handled on higher level anyway)

- fix resource leak in error path in tcrypt.c

- fix time of check/time of use race in sysfs path processing

- insruct Coverity scanner to ignore constant expression in random.c
(it is intented to stop compile-time misconfiguration of RNG that would be fatal)
This commit is contained in:
Milan Broz
2016-04-24 12:07:31 +02:00
parent 883bde3f1b
commit b282cb2366
7 changed files with 36 additions and 19 deletions

View File

@@ -103,6 +103,7 @@ int crypt_loop_attach(const char *loop, const char *file, int offset,
int autoclear, int *readonly)
{
struct loop_info64 lo64 = {0};
char *lo_file_name;
int loop_fd = -1, file_fd = -1, r = 1;
file_fd = open(file, (*readonly ? O_RDONLY : O_RDWR) | O_EXCL);
@@ -117,7 +118,9 @@ int crypt_loop_attach(const char *loop, const char *file, int offset,
if (loop_fd < 0)
goto out;
strncpy((char*)lo64.lo_file_name, file, LO_NAME_SIZE);
lo_file_name = (char*)lo64.lo_file_name;
lo_file_name[LO_NAME_SIZE-1] = '\0';
strncpy(lo_file_name, file, LO_NAME_SIZE-1);
lo64.lo_offset = offset;
if (autoclear)
lo64.lo_flags |= LO_FLAGS_AUTOCLEAR;