diff options
author | Christian Balster <christian.balster@gmail.com> | 2015-06-15 21:10:09 +0200 |
---|---|---|
committer | Andreas Blaesius <skate4life@gmx.de> | 2015-08-15 14:22:24 -0700 |
commit | 469a3ddad4fc39451250b3bf5b8417c3ca930289 (patch) | |
tree | 633ff1a2c808bf7ecbb522ba1e6a46fda9fea982 /libsensors/geomagneticd | |
parent | f3ef9365e9c5e902cde345826a8260bba05a2676 (diff) | |
download | device_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/geomagneticd')
-rw-r--r-- | libsensors/geomagneticd/geomagneticd.h | 10 | ||||
-rw-r--r-- | libsensors/geomagneticd/input.c | 16 |
2 files changed, 14 insertions, 12 deletions
diff --git a/libsensors/geomagneticd/geomagneticd.h b/libsensors/geomagneticd/geomagneticd.h index cd57eb9..72afbc4 100644 --- a/libsensors/geomagneticd/geomagneticd.h +++ b/libsensors/geomagneticd/geomagneticd.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> @@ -45,14 +47,14 @@ struct geomagneticd_data { */ 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); diff --git a/libsensors/geomagneticd/input.c b/libsensors/geomagneticd/input.c index 7e9ca4a..3aedd05 100644 --- a/libsensors/geomagneticd/input.c +++ b/libsensors/geomagneticd/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)) |