summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLubomir Rintel <lkundrak@v3.sk>2014-05-24 21:19:33 +0200
committerDavid Herrmann <dh.herrmann@gmail.com>2014-05-25 11:42:27 +0200
commit41e76d11dff6dd9bc08bf829751f9634f32cdd38 (patch)
tree1aa8553ed328071a50ce4a32ac2387f998e93f68 /src
parent012be880fcb34d5c206bfbc9b00cd36e013aa2eb (diff)
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 <lkundrak@v3.sk> (remove superfluous errno-checks) Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/kmscon_module.c2
-rw-r--r--src/shl_misc.h8
2 files changed, 7 insertions, 3 deletions
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;