projects
/
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
[lttng-tools.git]
/
src
/
lib
/
lttng-ctl
/
lttng-ctl.c
diff --git
a/src/lib/lttng-ctl/lttng-ctl.c
b/src/lib/lttng-ctl/lttng-ctl.c
index d72250b1e4041a56ea4612f029e00417f6212cbd..c20052bf6c84dd11fab4d2a1b124b07b26c1fdc3 100644
(file)
--- a/
src/lib/lttng-ctl/lttng-ctl.c
+++ b/
src/lib/lttng-ctl/lttng-ctl.c
@@
-15,6
+15,7
@@
#include <grp.h>
#include <stdio.h>
#include <stdlib.h>
#include <grp.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <string.h>
#include <unistd.h>
@@
-292,12
+293,14
@@
end:
return ret;
}
return ret;
}
-static int check_enough_available_memory(size_t num_bytes_requested_per_cpu)
+static enum lttng_error_code check_enough_available_memory(
+ uint64_t num_bytes_requested_per_cpu)
{
int ret;
{
int ret;
+ enum lttng_error_code ret_code;
long num_cpu;
long num_cpu;
-
size
_t best_mem_info;
-
size
_t num_bytes_requested_total;
+
uint64
_t best_mem_info;
+
uint64
_t num_bytes_requested_total;
/*
* Get the number of CPU currently online to compute the amount of
/*
* Get the number of CPU currently online to compute the amount of
@@
-305,10
+308,18
@@
static int check_enough_available_memory(size_t num_bytes_requested_per_cpu)
*/
num_cpu = sysconf(_SC_NPROCESSORS_ONLN);
if (num_cpu == -1) {
*/
num_cpu = sysconf(_SC_NPROCESSORS_ONLN);
if (num_cpu == -1) {
- goto error;
+ ret_code = LTTNG_ERR_FATAL;
+ goto end;
+ }
+
+ if (num_bytes_requested_per_cpu > UINT64_MAX / (uint64_t) num_cpu) {
+ /* Overflow */
+ ret_code = LTTNG_ERR_OVERFLOW;
+ goto end;
}
}
- num_bytes_requested_total = num_bytes_requested_per_cpu * num_cpu;
+ num_bytes_requested_total =
+ num_bytes_requested_per_cpu * (uint64_t) num_cpu;
/*
* Try to get the `MemAvail` field of `/proc/meminfo`. This is the most
/*
* Try to get the `MemAvail` field of `/proc/meminfo`. This is the most
@@
-330,10
+341,18
@@
static int check_enough_available_memory(size_t num_bytes_requested_per_cpu)
goto success;
}
goto success;
}
-error:
- return -1;
+ /* No valid source of information. */
+ ret_code = LTTNG_ERR_NOMEM;
+ goto end;
+
success:
success:
- return best_mem_info >= num_bytes_requested_total;
+ if (best_mem_info >= num_bytes_requested_total) {
+ ret_code = LTTNG_OK;
+ } else {
+ ret_code = LTTNG_ERR_NOMEM;
+ }
+end:
+ return ret_code;
}
/*
}
/*
@@
-1584,9
+1603,10
@@
void lttng_channel_destroy(struct lttng_channel *channel)
int lttng_enable_channel(struct lttng_handle *handle,
struct lttng_channel *in_chan)
{
int lttng_enable_channel(struct lttng_handle *handle,
struct lttng_channel *in_chan)
{
+ enum lttng_error_code ret_code;
int ret;
struct lttcomm_session_msg lsm;
int ret;
struct lttcomm_session_msg lsm;
-
size
_t total_buffer_size_needed_per_cpu = 0;
+
uint64
_t total_buffer_size_needed_per_cpu = 0;
/* NULL arguments are forbidden. No default values. */
if (handle == NULL || in_chan == NULL) {
/* NULL arguments are forbidden. No default values. */
if (handle == NULL || in_chan == NULL) {
@@
-1626,10
+1646,20
@@
int lttng_enable_channel(struct lttng_handle *handle,
* Verify that the amount of memory required to create the requested
* buffer is available on the system at the moment.
*/
* Verify that the amount of memory required to create the requested
* buffer is available on the system at the moment.
*/
+ if (lsm.u.channel.chan.attr.num_subbuf >
+ UINT64_MAX / lsm.u.channel.chan.attr.subbuf_size) {
+ /* Overflow */
+ ret = -LTTNG_ERR_OVERFLOW;
+ goto end;
+ }
+
total_buffer_size_needed_per_cpu = lsm.u.channel.chan.attr.num_subbuf *
lsm.u.channel.chan.attr.subbuf_size;
total_buffer_size_needed_per_cpu = lsm.u.channel.chan.attr.num_subbuf *
lsm.u.channel.chan.attr.subbuf_size;
- if (!check_enough_available_memory(total_buffer_size_needed_per_cpu)) {
- return -LTTNG_ERR_NOMEM;
+ ret_code = check_enough_available_memory(
+ total_buffer_size_needed_per_cpu);
+ if (ret_code != LTTNG_OK) {
+ ret = -ret_code;
+ goto end;
}
lsm.cmd_type = LTTNG_ENABLE_CHANNEL;
}
lsm.cmd_type = LTTNG_ENABLE_CHANNEL;
This page took
0.024309 seconds
and
4
git commands to generate.