From: Lubomir Rintel Date: Sat, 24 May 2014 19:19:33 +0000 (+0200) Subject: shl: handle pathconf() errors X-Git-Tag: 8.0~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=41e76d11dff6dd9bc08bf829751f9634f32cdd38;p=platform%2Fupstream%2Fkmscon.git shl: handle pathconf() errors It can return -1 (feature not supported, denied by a security module, etc.), resulting in wrong allocation later on. Signed-off-by: Lubomir Rintel (remove superfluous errno-checks) Signed-off-by: David Herrmann --- diff --git a/src/kmscon_module.c b/src/kmscon_module.c index 2bf0576..f480914 100644 --- a/src/kmscon_module.c +++ b/src/kmscon_module.c @@ -181,7 +181,7 @@ void kmscon_load_modules(void) { int ret; DIR *ent; - struct dirent *buf, *de; + struct dirent *buf = NULL, *de; char *file; struct kmscon_module *mod; diff --git a/src/shl_misc.h b/src/shl_misc.h index d90fd22..f4a6d90 100644 --- a/src/shl_misc.h +++ b/src/shl_misc.h @@ -52,9 +52,13 @@ static inline int shl_dirent(const char *path, struct dirent **ent) { size_t len; struct dirent *tmp; + long name_max; - len = offsetof(struct dirent, d_name) + - pathconf(path, _PC_NAME_MAX) + 1; + name_max = pathconf(path, _PC_NAME_MAX); + if (name_max < 0) + return -errno; + + len = offsetof(struct dirent, d_name) + name_max + 1; tmp = malloc(len); if (!tmp) return -ENOMEM;