From a0feda85a5ad0cad1ae3813a33ba35fa86b6d0b0 Mon Sep 17 00:00:00 2001 From: Semun Lee Date: Mon, 30 Jul 2018 10:24:25 +0900 Subject: [PATCH] Add checking return value of stat() Change-Id: I36c4233a17db4b8f28c9a39dc4ddebafed6aa8ff Signed-off-by: Semun Lee --- tool/pkg-db-recovery.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tool/pkg-db-recovery.c b/tool/pkg-db-recovery.c index 58e41e1..00b2063 100644 --- a/tool/pkg-db-recovery.c +++ b/tool/pkg-db-recovery.c @@ -349,6 +349,7 @@ static void _get_user_list() char traverse_path[PATH_MAX]; char abs_dirname[PATH_MAX]; const char *db_path; + int ret; uid_t uid; user_info *info; @@ -364,7 +365,13 @@ static void _get_user_list() while ((ent = readdir(dir)) != NULL) { snprintf(abs_dirname, PATH_MAX, "%s/%s", traverse_path, ent->d_name); - stat(abs_dirname, &stats); + + ret = stat(abs_dirname, &stats); + if (ret != 0) { + printf("failed to stat: %d (%s)", errno, abs_dirname); + continue; + } + if (!strcmp(".", ent->d_name) || !strcmp("..", ent->d_name) || !S_ISDIR(stats.st_mode)) continue; -- 2.7.4