aboutsummaryrefslogtreecommitdiffstats
path: root/libsensors/input.c
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/input.c
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/input.c')
-rw-r--r--libsensors/input.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/libsensors/input.c b/libsensors/input.c
index c48f17f..96ac117 100644
--- a/libsensors/input.c
+++ b/libsensors/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))