aboutsummaryrefslogtreecommitdiffstats
path: root/libsensors/orientationd
diff options
context:
space:
mode:
authorChristian Balster <christian.balster@gmail.com>2015-06-15 21:10:09 +0200
committerAndreas Blaesius <skate4life@gmx.de>2015-08-15 14:22:24 -0700
commit469a3ddad4fc39451250b3bf5b8417c3ca930289 (patch)
tree633ff1a2c808bf7ecbb522ba1e6a46fda9fea982 /libsensors/orientationd
parentf3ef9365e9c5e902cde345826a8260bba05a2676 (diff)
downloaddevice_samsung_espressowifi-469a3ddad4fc39451250b3bf5b8417c3ca930289.zip
device_samsung_espressowifi-469a3ddad4fc39451250b3bf5b8417c3ca930289.tar.gz
device_samsung_espressowifi-469a3ddad4fc39451250b3bf5b8417c3ca930289.tar.bz2
espresso-common: libsensors: fix buffer overflows
long/int can't hold timestamp values in ns, use int64_t instead Change-Id: Id3e08a45aa556d8858b8b57d03c3b737e999772d
Diffstat (limited to 'libsensors/orientationd')
-rw-r--r--libsensors/orientationd/input.c16
-rw-r--r--libsensors/orientationd/orientationd.c6
-rw-r--r--libsensors/orientationd/orientationd.h12
3 files changed, 18 insertions, 16 deletions
diff --git a/libsensors/orientationd/input.c b/libsensors/orientationd/input.c
index 1afa2b8..f138cfc 100644
--- a/libsensors/orientationd/input.c
+++ b/libsensors/orientationd/input.c
@@ -44,15 +44,15 @@ void input_event_set(struct input_event *event, int type, int code, int value)
gettimeofday(&event->time, NULL);
}
-long int timestamp(struct timeval *time)
+int64_t timestamp(struct timeval *time)
{
if (time == NULL)
return -1;
- return time->tv_sec * 1000000000LL + time->tv_usec * 1000;
+ return (int64_t) (time->tv_sec * 1000000000LL + time->tv_usec * 1000);
}
-long int input_timestamp(struct input_event *event)
+int64_t input_timestamp(struct input_event *event)
{
if (event == NULL)
return -1;
@@ -213,10 +213,10 @@ int sysfs_path_prefix(char *name, char *path_prefix)
return -1;
}
-int sysfs_value_read(char *path)
+int64_t sysfs_value_read(char *path)
{
char buffer[100];
- int value;
+ int64_t value;
int fd = -1;
int rc;
@@ -231,7 +231,7 @@ int sysfs_value_read(char *path)
if (rc <= 0)
goto error;
- value = atoi(buffer);
+ value = (int64_t)strtoimax(buffer, NULL, 10);
goto complete;
error:
@@ -244,7 +244,7 @@ complete:
return value;
}
-int sysfs_value_write(char *path, int value)
+int sysfs_value_write(char *path, int64_t value)
{
char buffer[100];
int fd = -1;
@@ -257,7 +257,7 @@ int sysfs_value_write(char *path, int value)
if (fd < 0)
goto error;
- snprintf((char *) &buffer, sizeof(buffer), "%d\n", value);
+ snprintf((char *) &buffer, sizeof(buffer), "%" PRId64 "\n", value);
rc = write(fd, buffer, strlen(buffer));
if (rc < (int) strlen(buffer))
diff --git a/libsensors/orientationd/orientationd.c b/libsensors/orientationd/orientationd.c
index 8ad84c5..fb2925b 100644
--- a/libsensors/orientationd/orientationd.c
+++ b/libsensors/orientationd/orientationd.c
@@ -95,8 +95,8 @@ void *orientationd_thread(void *thread_data)
struct orientationd_data *data;
struct input_event event;
struct timeval time;
- long int before, after;
- int diff;
+ int64_t before, after;
+ useconds_t diff;
int input_fd;
int rc;
@@ -137,7 +137,7 @@ next:
gettimeofday(&time, NULL);
after = timestamp(&time);
- diff = (int) (data->delay * 1000000 - (after - before)) / 1000;
+ diff = (useconds_t) (data->delay * 1000000 - (after - before)) / 1000;
if (diff <= 0)
continue;
diff --git a/libsensors/orientationd/orientationd.h b/libsensors/orientationd/orientationd.h
index 7e169e4..1eebd90 100644
--- a/libsensors/orientationd/orientationd.h
+++ b/libsensors/orientationd/orientationd.h
@@ -18,6 +18,8 @@
#include <stdint.h>
#include <poll.h>
#include <linux/input.h>
+#define __STDC_FORMAT_MACROS
+#include <inttypes.h>
#include <hardware/sensors.h>
#include <hardware/hardware.h>
@@ -47,7 +49,7 @@ struct orientationd_data {
sensors_vec_t acceleration;
sensors_vec_t magnetic;
- unsigned int delay;
+ int64_t delay;
int input_fd;
int activated;
@@ -65,14 +67,14 @@ extern int orientationd_handlers_count;
*/
void input_event_set(struct input_event *event, int type, int code, int value);
-long int timestamp(struct timeval *time);
-long int input_timestamp(struct input_event *event);
+int64_t timestamp(struct timeval *time);
+int64_t input_timestamp(struct input_event *event);
int uinput_rel_create(const char *name);
void uinput_destroy(int uinput_fd);
int input_open(char *name);
int sysfs_path_prefix(char *name, char *path_prefix);
-int sysfs_value_read(char *path);
-int sysfs_value_write(char *path, int value);
+int64_t sysfs_value_read(char *path);
+int sysfs_value_write(char *path, int64_t value);
int sysfs_string_read(char *path, char *buffer, size_t length);
int sysfs_string_write(char *path, char *buffer, size_t length);