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;
|
int ret;
|
||||||
DIR *ent;
|
DIR *ent;
|
||||||
struct dirent *buf, *de;
|
struct dirent *buf = NULL, *de;
|
||||||
char *file;
|
char *file;
|
||||||
struct kmscon_module *mod;
|
struct kmscon_module *mod;
|
||||||
|
|
||||||
|
@ -52,9 +52,13 @@ static inline int shl_dirent(const char *path, struct dirent **ent)
|
|||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
struct dirent *tmp;
|
struct dirent *tmp;
|
||||||
|
long name_max;
|
||||||
|
|
||||||
len = offsetof(struct dirent, d_name) +
|
name_max = pathconf(path, _PC_NAME_MAX);
|
||||||
pathconf(path, _PC_NAME_MAX) + 1;
|
if (name_max < 0)
|
||||||
|
return -errno;
|
||||||
|
|
||||||
|
len = offsetof(struct dirent, d_name) + name_max + 1;
|
||||||
tmp = malloc(len);
|
tmp = malloc(len);
|
||||||
if (!tmp)
|
if (!tmp)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user