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>
This commit is contained in:
Lubomir Rintel 2014-05-24 21:19:33 +02:00 committed by David Herrmann
parent 012be880fc
commit 41e76d11df
2 changed files with 7 additions and 3 deletions

View File

@ -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;

View File

@ -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;