pass-hal: standard: Fix overrun issue of array 76/152576/3 accepted/tizen/4.0/unified/20170929.075606 accepted/tizen/unified/20170928.072145 submit/tizen/20170927.080101 submit/tizen_4.0/20170927.080359
authorChanwoo Choi <cw00.choi@samsung.com>
Tue, 26 Sep 2017 10:36:46 +0000 (19:36 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Wed, 27 Sep 2017 01:22:39 +0000 (10:22 +0900)
The 'len + 1' of argument of read() might access
the out of range of 'buf' string. This patch fixes
the overrun issue.

Change-Id: I68d0bd4404515f492a0dc2624aba2d7f51630118
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
src/shared/sysfs.c

index 57a168b3f09f7eefa841b5d980bb6ad9dd74067c..1256076622589421629828a8210428eb912d6c35 100644 (file)
@@ -35,7 +35,7 @@ static int sysfs_read_buf(char *path, char *buf, int len)
        if (fd == -1)
                return -ENOENT;
 
-       r = read(fd, buf, len + 1);
+       r = read(fd, buf, len);
        close(fd);
 
        if ((r < 0) || (r > len))
@@ -68,7 +68,7 @@ static int sysfs_write_buf(char *path, char *buf)
 
 int sysfs_read_int(char *path, int *val)
 {
-       char buf[MAX_BUF_SIZE];
+       char buf[MAX_BUF_SIZE + 1];
        int r;
 
        if ((!path) || (!val))
@@ -98,7 +98,7 @@ int sysfs_read_str(char *path, char *str, int len)
 
 int sysfs_write_int(char *path, int val)
 {
-       char buf[MAX_BUF_SIZE];
+       char buf[MAX_BUF_SIZE + 1];
        int w;
 
        if (!path)