mg: region.c:preadin() - Also check for read() error

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

mg: region.c:preadin() - Also check for read() error

Mark Lumsden-2
Source Joachim Nilsson:

 Coverity Scan found this interesting buglet.  If read() fails the code,
 before this patch, would trigger a "Negative array index write".

ok?

Index: region.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/region.c,v
retrieving revision 1.36
diff -u -p -u -p -r1.36 region.c
--- region.c 8 Sep 2016 07:50:09 -0000 1.36
+++ region.c 8 Sep 2016 07:56:14 -0000
@@ -650,7 +650,7 @@ preadin(int fd, struct buffer *bp)
  int len;
  char buf[BUFSIZ], *p, *q;
 
- if ((len = read(fd, buf, BUFSIZ - 1)) == 0)
+ if ((len = read(fd, buf, BUFSIZ - 1)) <= 0)
  return (FALSE);
 
  buf[len] = '\0';

Reply | Threaded
Open this post in threaded view
|

Re: mg: region.c:preadin() - Also check for read() error

Florian Obser-2
Haha
OK florian@

On Thu, Sep 08, 2016 at 07:58:29AM +0000, Mark Lumsden wrote:

> Source Joachim Nilsson:
>
>  Coverity Scan found this interesting buglet.  If read() fails the code,
>  before this patch, would trigger a "Negative array index write".
>
> ok?
>
> Index: region.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/mg/region.c,v
> retrieving revision 1.36
> diff -u -p -u -p -r1.36 region.c
> --- region.c 8 Sep 2016 07:50:09 -0000 1.36
> +++ region.c 8 Sep 2016 07:56:14 -0000
> @@ -650,7 +650,7 @@ preadin(int fd, struct buffer *bp)
>   int len;
>   char buf[BUFSIZ], *p, *q;
>  
> - if ((len = read(fd, buf, BUFSIZ - 1)) == 0)
> + if ((len = read(fd, buf, BUFSIZ - 1)) <= 0)
>   return (FALSE);
>  
>   buf[len] = '\0';
>

--
I'm not entirely sure you are real.