mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-05 16:00:05 +01:00
Add a few tainted data info for coverity to avoid warnings.
If sysconf is lying, then anything can happen. But check for overflow anyway. Device/partition offset overflow for IV can only cause bad decryption (expected).
This commit is contained in:
26
lib/utils.c
26
lib/utils.c
@@ -45,34 +45,44 @@ unsigned crypt_cpusonline(void)
|
||||
uint64_t crypt_getphysmemory_kb(void)
|
||||
{
|
||||
long pagesize, phys_pages;
|
||||
uint64_t phys_memory_kb;
|
||||
uint64_t phys_memory_kb, page_size_kb;
|
||||
|
||||
pagesize = sysconf(_SC_PAGESIZE);
|
||||
phys_pages = sysconf(_SC_PHYS_PAGES);
|
||||
|
||||
if (pagesize < 0 || phys_pages < 0)
|
||||
if (pagesize <= 0 || phys_pages <= 0)
|
||||
return 0;
|
||||
|
||||
phys_memory_kb = pagesize / 1024;
|
||||
phys_memory_kb *= phys_pages;
|
||||
page_size_kb = pagesize / 1024;
|
||||
phys_memory_kb = page_size_kb * phys_pages;
|
||||
|
||||
/* sanity check for overflow */
|
||||
if (phys_memory_kb / phys_pages != page_size_kb)
|
||||
return 0;
|
||||
|
||||
/* coverity[return_overflow:FALSE] */
|
||||
return phys_memory_kb;
|
||||
}
|
||||
|
||||
uint64_t crypt_getphysmemoryfree_kb(void)
|
||||
{
|
||||
long pagesize, phys_pages;
|
||||
uint64_t phys_memoryfree_kb;
|
||||
uint64_t phys_memoryfree_kb, page_size_kb;
|
||||
|
||||
pagesize = sysconf(_SC_PAGESIZE);
|
||||
phys_pages = sysconf(_SC_AVPHYS_PAGES);
|
||||
|
||||
if (pagesize < 0 || phys_pages < 0)
|
||||
if (pagesize <= 0 || phys_pages <= 0)
|
||||
return 0;
|
||||
|
||||
phys_memoryfree_kb = pagesize / 1024;
|
||||
phys_memoryfree_kb *= phys_pages;
|
||||
page_size_kb = pagesize / 1024;
|
||||
phys_memoryfree_kb = page_size_kb * phys_pages;
|
||||
|
||||
/* sanity check for overflow */
|
||||
if (phys_memoryfree_kb / phys_pages != page_size_kb)
|
||||
return 0;
|
||||
|
||||
/* coverity[return_overflow:FALSE] */
|
||||
return phys_memoryfree_kb;
|
||||
}
|
||||
|
||||
|
||||
@@ -281,6 +281,7 @@ uint64_t crypt_dev_partition_offset(const char *dev_path)
|
||||
&val, "start"))
|
||||
return 0;
|
||||
|
||||
/* coverity[tainted_data_return:FALSE] */
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user