qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH] qemu-pr-helper: check the return value of fcntl


From: Paolo Bonzini
Subject: Re: [Qemu-devel] [PATCH] qemu-pr-helper: check the return value of fcntl in do_pr_out
Date: Thu, 21 Mar 2019 11:37:45 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1

On 20/03/19 15:07, Zhengui li wrote:
> The function fcntl maybe return -1, which is not a unsigned type.
> Unsigned type or Negative values should not do bitwise operator with
> O_ACCMODE.

Did you actually find a case in which the fcntl can fail?

Paolo

> Signed-off-by: Zhengui li <address@hidden>
> ---
>  scsi/qemu-pr-helper.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c
> index e7af637..fcbe4d9 100644
> --- a/scsi/qemu-pr-helper.c
> +++ b/scsi/qemu-pr-helper.c
> @@ -551,8 +551,14 @@ static int do_pr_out(int fd, const uint8_t *cdb, uint8_t 
> *sense,
>                       const uint8_t *param, int sz)
>  {
>      int resp_sz;
> +    int flags;
>  
> -    if ((fcntl(fd, F_GETFL) & O_ACCMODE) == O_RDONLY) {
> +    flags = fcntl(fd, F_GETFL);
> +    if (flags < 0) {
> +        return -1;
> +    }
> +
> +    if (((unsigned int) flags & O_ACCMODE) == O_RDONLY) {
>          scsi_build_sense(sense, SENSE_CODE(INVALID_OPCODE));
>          return CHECK_CONDITION;
>      }
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]