summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHyeongsik Min <hyeongsik.min@samsung.com>2017-04-19 00:11:23 +0900
committerHyeongsik Min <hyeongsik.min@samsung.com>2017-04-19 08:29:13 +0900
commit9af1633870e30c8d2c8b2e4ce9da776ecdf871a7 (patch)
treec60ef489752af4edf918666eeb5fcef7d2e1f2ff
parentffb328612abac49c5b11f2c05a7d043091d7c7a2 (diff)
downloadmemps-tizen_3.0.tar.gz
memps-tizen_3.0.tar.bz2
memps-tizen_3.0.zip
By allocating string buffer, prevent buffer overlow issue with sscanf. Change-Id: I5655f1b7049dc457b525dfbc2d351b67616b3f88 Signed-off-by: Hyeongsik Min <hyeongsik.min@samsung.com>
-rw-r--r--memps.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/memps.c b/memps.c
index d14774e..e29dd9b 100644
--- a/memps.c
+++ b/memps.c
@@ -624,7 +624,7 @@ static int get_tmpfs_info(FILE *output_fp)
{
FILE *fp;
char line[BUF_MAX];
- char tmpfs_mp[NAME_MAX]; /* tmpfs mount point */
+ char *tmpfs_mp; /* tmpfs mount point */
struct statfs tmpfs_info;
if (output_fp == NULL)
@@ -639,7 +639,7 @@ static int get_tmpfs_info(FILE *output_fp)
fprintf(output_fp, "TMPFS INFO\n");
while (fgets(line, BUF_MAX, fp) != NULL) {
- if (sscanf(line, "tmpfs %s tmpfs", tmpfs_mp) == 1) {
+ if (sscanf(line, "tmpfs %ms tmpfs", &tmpfs_mp) == 1) {
statfs(tmpfs_mp, &tmpfs_info);
fprintf(output_fp,
"tmpfs %16s Total %8ld KB, Used %8ld, Avail %8ld\n",
@@ -648,6 +648,7 @@ static int get_tmpfs_info(FILE *output_fp)
tmpfs_info.f_blocks * 4,
(tmpfs_info.f_blocks - tmpfs_info.f_bfree) * 4,
tmpfs_info.f_bfree * 4);
+ free(tmpfs_mp);
}
}
fclose(fp);