projects
/
deliverable
/
lttng-tools.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix: conversion from KB to bytes overflow on arm32
[deliverable/lttng-tools.git]
/
src
/
common
/
utils.c
diff --git
a/src/common/utils.c
b/src/common/utils.c
index 5aedb0889896eb41e60dfdefc3e44ba896a9ac9a..febd75c185ddd87c177f388dfb7ba464e44cbf5c 100644
(file)
--- a/
src/common/utils.c
+++ b/
src/common/utils.c
@@
-7,6
+7,7
@@
*/
#include "common/macros.h"
*/
#include "common/macros.h"
+#include <stdint.h>
#define _LGPL_SOURCE
#include <assert.h>
#include <ctype.h>
#define _LGPL_SOURCE
#include <assert.h>
#include <ctype.h>
@@
-1062,7
+1063,7
@@
end:
}
static
}
static
-int read_proc_meminfo_field(const char *field,
size
_t *value)
+int read_proc_meminfo_field(const char *field,
uint64
_t *value)
{
int ret;
FILE *proc_meminfo;
{
int ret;
FILE *proc_meminfo;
@@
-1080,10
+1081,10
@@
int read_proc_meminfo_field(const char *field, size_t *value)
* field.
*/
while (!feof(proc_meminfo)) {
* field.
*/
while (!feof(proc_meminfo)) {
- u
nsigned long
value_kb;
+ u
int64_t
value_kb;
ret = fscanf(proc_meminfo,
ret = fscanf(proc_meminfo,
- "%" MAX_NAME_LEN_SCANF_IS_A_BROKEN_API "s %
lu
kB\n",
+ "%" MAX_NAME_LEN_SCANF_IS_A_BROKEN_API "s %
" SCNu64 "
kB\n",
name, &value_kb);
if (ret == EOF) {
/*
name, &value_kb);
if (ret == EOF) {
/*
@@
-1100,7
+1101,12
@@
int read_proc_meminfo_field(const char *field, size_t *value)
* This number is displayed in kilo-bytes. Return the
* number of bytes.
*/
* This number is displayed in kilo-bytes. Return the
* number of bytes.
*/
- *value = ((size_t) value_kb) * 1024;
+ if (value_kb > UINT64_MAX / 1024) {
+ ERR("Overflow on kb to bytes conversion");
+ break;
+ }
+
+ *value = value_kb * 1024;
ret = 0;
goto found;
}
ret = 0;
goto found;
}
@@
-1120,7
+1126,7
@@
fopen_error:
* a best guess.
*/
LTTNG_HIDDEN
* a best guess.
*/
LTTNG_HIDDEN
-int utils_get_memory_available(
size
_t *value)
+int utils_get_memory_available(
uint64
_t *value)
{
return read_proc_meminfo_field(PROC_MEMINFO_MEMAVAILABLE_LINE, value);
}
{
return read_proc_meminfo_field(PROC_MEMINFO_MEMAVAILABLE_LINE, value);
}
@@
-1130,7
+1136,7
@@
int utils_get_memory_available(size_t *value)
* the information in `/proc/meminfo`.
*/
LTTNG_HIDDEN
* the information in `/proc/meminfo`.
*/
LTTNG_HIDDEN
-int utils_get_memory_total(
size
_t *value)
+int utils_get_memory_total(
uint64
_t *value)
{
return read_proc_meminfo_field(PROC_MEMINFO_MEMTOTAL_LINE, value);
}
{
return read_proc_meminfo_field(PROC_MEMINFO_MEMTOTAL_LINE, value);
}
This page took
0.040594 seconds
and
5
git commands to generate.