Re: [PATCH] secilc.c: Don't fail if input file is empty

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

 



On Wed, Apr 14, 2021 at 12:32 PM Yi-Yo Chiang <yochiang@xxxxxxxxxx> wrote:
>
> fread(3) returns zero if |size| is zero. This confuses secilc, and
> causes it to fail with a "Failure reading file" error, even though there
> is no error.
>
> Add a shortcut that closes and skips an input file if file size is zero.
>
> Signed-off-by: Yi-Yo Chiang <yochiang@xxxxxxxxxx>

Acked-by: James Carter <jwcart2@xxxxxxxxx>

> ---
>  secilc/secilc.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/secilc/secilc.c b/secilc/secilc.c
> index 186c5a73..9c78e425 100644
> --- a/secilc/secilc.c
> +++ b/secilc/secilc.c
> @@ -268,6 +268,12 @@ int main(int argc, char *argv[])
>                 }
>                 file_size = filedata.st_size;
>
> +               if (!file_size) {
> +                       fclose(file);
> +                       file = NULL;
> +                       continue;
> +               }
> +
>                 buffer = malloc(file_size);
>                 rc = fread(buffer, file_size, 1, file);
>                 if (rc != 1) {
> --
> 2.31.1.295.g9ea45b61b8-goog
>



[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux