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:
parent
012be880fc
commit
41e76d11df
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user