[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Minios-devel] [UNIKRAFT PATCH] lib/vfscore: Fix error handling in opendir()


  • To: Costin Lupu <costin.lupu@xxxxxxxxx>, "minios-devel@xxxxxxxxxxxxx" <minios-devel@xxxxxxxxxxxxx>
  • From: Vlad-Andrei BĂDOIU (78692) <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
  • Date: Tue, 17 Sep 2019 11:34:42 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=stud.acs.upb.ro; dmarc=pass action=none header.from=stud.acs.upb.ro; dkim=pass header.d=stud.acs.upb.ro; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SXW4WwT1pqTT7X4Df4kdcXSuKltugJKuKu6dAhnVk/o=; b=OrbRvc2gCfOveaP6uVJeHZLtafcsqgcN3Aa6zf9RWEH+E2Yk3X5kGXoj6r7LD/DeBkqw0pTfZ6OxVpwCXQk2lK+8PPtEeEkP2o3teaD5ddwYA/Go+XPt5PiXNmQ/Xm5Tw8wtAdzX8qraLF9x55flNYASJMi/0qAPNLiXTbqbd+r943d3QeXXeZg3miRMfOgNCdRLY4JFJIowrpcm1aU78Gk6cc2Hnm+eq890Lnj130fdJF0CF597VyiIYsOIr8y7F9mR4NkbdNXKtuvV2OEH8sgAPKzDzNEaURzrzx6ye47qNFCkbzlcKYjAIlaQWWqOV4mj3PI/W9y7P2aaGTRw5Q==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AJm5I7UD43sLzPkP1PAtvVk+nv7ELFhD65zMnyVO56oM9pVtmtw+cUd60d99VrBwANzqvbq+HRCZbN4Kcm85cLhBkCxJGWl6lUaXdAWIf8odL8ZuRn01MPvARbsvEoh6kuT2+TlWVlpCaoz0ypc6s7+RhKgnj72ejBDHNbQDoScyS4qcdIPWPPHMyokakbBSaEZ+opRw7YoOoKEcDE0A6hu2lzNOdlLqjT8shuSbZ7py8bIux/Ebenbhl+VJoFITPBUEOSz56c8/gCoPouRbquctBGgMgGMp3wrjC/VseoIZSQL/2JthlR+Kjrl5KkPU6+P2aFEYMDnU35RctwgJMA==
  • Authentication-results: spf=none (sender IP is ) smtp.mailfrom=vlad_andrei.badoiu@xxxxxxxxxxxxxxx;
  • Cc: "felipe.huici@xxxxxxxxx" <felipe.huici@xxxxxxxxx>
  • Delivery-date: Tue, 17 Sep 2019 11:34:51 +0000
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>
  • Thread-index: AQHVaUbCMJwNBXemzkK6VIA9xHWysacvxTsA
  • Thread-topic: [UNIKRAFT PATCH] lib/vfscore: Fix error handling in opendir()

Hi Costin,

This patch looks good. Thanks!

Vlad

Reviewed-by: Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>

On 12.09.2019 11:47, Costin Lupu wrote:
> In case of errors, opendir() should set errno and return -1. If 'path' is not 
> a
> directory then opendir() should set errno to ENOTDIR.
>
> Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
> ---
>   lib/vfscore/main.c | 28 ++++++++++++++++++++++------
>   1 file changed, 22 insertions(+), 6 deletions(-)
>
> diff --git a/lib/vfscore/main.c b/lib/vfscore/main.c
> index 925ce762..39013767 100644
> --- a/lib/vfscore/main.c
> +++ b/lib/vfscore/main.c
> @@ -659,17 +659,33 @@ struct __dirstream
>   
>   DIR *opendir(const char *path)
>   {
> -     DIR *dir = malloc(sizeof(*dir));
> +     DIR *dir;
> +     struct stat st;
>   
> -     if (!dir)
> -             return ERR2PTR(-ENOMEM);
> +     dir = malloc(sizeof(*dir));
> +     if (!dir) {
> +             errno = ENOMEM;
> +             goto out_err;
> +     }
>   
>       dir->fd = open(path, O_RDONLY);
> -     if (dir->fd < 0) {
> -             free(dir);
> -             return NULL;
> +     if (dir->fd < 0)
> +             goto out_free_dir;
> +
> +     if (fstat(dir->fd, &st) < 0)
> +             goto out_free_dir;
> +
> +     if (!S_ISDIR(st.st_mode)) {
> +             errno = ENOTDIR;
> +             goto out_free_dir;
>       }
> +
>       return dir;
> +
> +out_free_dir:
> +     free(dir);
> +out_err:
> +     return NULL;
>   }
>   
>   DIR *fdopendir(int fd)
_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.