[packages/links] - some content_encoding patch fixes

qboosh qboosh at pld-linux.org
Tue Sep 8 22:10:56 CEST 2020


commit 98b4b74fe81e6c1c82ad282bfea07d99eadf0710
Author: Jakub Bogusz <qboosh at pld-linux.org>
Date:   Tue Sep 8 22:13:32 2020 +0200

    - some content_encoding patch fixes

 links-content_encoding.patch | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)
---
diff --git a/links-content_encoding.patch b/links-content_encoding.patch
index c3fb529..8a9f4d0 100644
--- a/links-content_encoding.patch
+++ b/links-content_encoding.patch
@@ -11,7 +11,7 @@
  LIBS = @LIBS@
 --- /dev/null	Tue May  5 22:32:27 1998
 +++ links-0.97.newer/compress.c	Wed Jul  3 19:28:29 2002
-@@ -0,0 +1,164 @@
+@@ -0,0 +1,169 @@
 +#include "links.h"
 +
 +#define WMAXBITS 15
@@ -45,7 +45,7 @@
 +  int ret;
 +  z_streamp z;
 +
-+  if (buf[0] != 0x1f || buf[1] != 0x8b) return NULL;
++  if ((l < 10) || buf[0] != 0x1f || buf[1] != 0x8b) return NULL;
 +
 +  method = buf[2];
 +  flags = buf[3];
@@ -58,31 +58,32 @@
 +  l -= 10;
 +
 +  if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */
++     if (l < 2) return NULL;
 +     len  =  2 + buf[0] + (buf[1] << 8);
 +     buf += len;
 +     l -= len;
 +  }
-+  if (l <= 0) return NULL;
++  if (l < 0) return NULL;
 +
 +  if ((flags & ORIG_NAME) != 0) {/* skip the original file name */
-+     len = strlen(buf) + 1;
++     len = strnlen(buf, l) + 1;
 +     buf += len;
 +     l -= len;
 +  }
-+  if (l <= 0) return NULL;
++  if (l < 0) return NULL;
 +
 +  if ((flags & COMMENT) != 0) {/* skip the .gz file comment */
-+     len = strlen(buf) + 1;
++     len = strnlen(buf, l) + 1;
 +     buf += len;
 +     l -= len;
 +  }
-+  if (l <= 0) return NULL;
++  if (l < 0) return NULL;
 +
 +  if ((flags & HEAD_CRC) != 0) {  /* skip the header crc */
 +     buf += 2;
 +     l -= 2;
 +  }
-+  if (l <= 0) return NULL;
++  if (l < 0) return NULL;
 +
 +/* initialization of z_stream */
 +  z = (z_streamp)mem_alloc(sizeof(z_stream));
@@ -121,6 +122,10 @@
 +         *dl = -1;
 +         return NULL;
 +      }
++      if ((*z)->avail_in == 0) {
++         *dl = 0;
++         return NULL;
++      }
 +   }
 +   else {
 +      (*z)->next_in = buf;
@@ -195,13 +200,13 @@
 +			if (c->gzip) {
 +				int dl;
 +				unsigned char *data = decompress_gzip(&c->z, rb->data, l, &dl);
-+				if (!data) {
++				if (!data && (dl < 0)) {
 +					setcstate(c, S_OUT_OF_MEM);
 +					abort_connection(c);
 +					return;
 +				}
 +				if (add_fragment(c->cache, c->from, data, dl) == 1) c->tries = 0;
-+				mem_free(data);
++				if (data) mem_free(data);
 +				c->from += dl;
 +			} else {
 +				if (add_fragment(c->cache, c->from, rb->data, l) == 1) c->tries = 0;
@@ -220,16 +225,16 @@
 -			if (add_fragment(c->cache, c->from, rb->data, l) == 1) c->tries = 0;
  			info->chunk_remaining -= l;
 -			c->from += l;
-+			if (c->gzip) {
++			if (c->gzip && (l > 0)) {
 +				int dl;
 +				unsigned char *data = decompress_gzip(&c->z, rb->data, l, &dl);
-+				if (!data) {
++				if (!data && (dl < 0)) {
 +					setcstate(c, S_OUT_OF_MEM);
 +					abort_connection(c);
 +					return;
 +				}
 +				if (add_fragment(c->cache, c->from, data, dl) == 1) c->tries = 0;
-+				mem_free(data);
++				if (data) mem_free(data);
 +				c->from += dl;
 +			} else {
 +				if (add_fragment(c->cache, c->from, rb->data, l) == 1) c->tries = 0;
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/links.git/commitdiff/98b4b74fe81e6c1c82ad282bfea07d99eadf0710



More information about the pld-cvs-commit mailing list