[master] a2482ced6 Coverity polish: 1605312 Overflowed integer argument

Nils Goroll nils.goroll at uplex.de
Thu Sep 12 12:56:04 UTC 2024


commit a2482ced6b039d35dc95e3a3e6034f84c3d9e9cc
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Thu Sep 12 14:43:37 2024 +0200

    Coverity polish: 1605312 Overflowed integer argument
    
    another case where apparently it does not understand the count argument of
    read(2)

diff --git a/lib/libvarnish/vlu.c b/lib/libvarnish/vlu.c
index 8883a350c..c79c65603 100644
--- a/lib/libvarnish/vlu.c
+++ b/lib/libvarnish/vlu.c
@@ -123,14 +123,18 @@ LineUpProcess(struct vlu *l)
 int
 VLU_Fd(struct vlu *l, int fd)
 {
-	int i;
+	ssize_t i;
+	size_t sz;
 
 	CHECK_OBJ_NOTNULL(l, LINEUP_MAGIC);
-	i = read(fd, l->buf + l->bufp, l->bufl - l->bufp);
+	assert(l->bufl >= l->bufp);
+	sz = l->bufl - l->bufp;
+	i = read(fd, l->buf + l->bufp, sz);
 	if (i == 0)
 		return (-2);
 	if (i < 0)
 		return (-1);
+	assert(i <= sz);
 	l->bufp += i;
 	return (LineUpProcess(l));
 }


More information about the varnish-commit mailing list