Browse Source

tpws: check broken gzip and zlib errors

pull/33/head
bolvan 6 years ago
parent
commit
f8dd9f3d23
  1. BIN
      binaries/aarch64/tpws
  2. BIN
      binaries/armhf/tpws
  3. BIN
      binaries/mips32r1-lsb/tpws
  4. BIN
      binaries/mips32r1-msb/tpws
  5. BIN
      binaries/mips64r2-msb/tpws
  6. BIN
      binaries/ppc/tpws
  7. BIN
      binaries/x86/tpws
  8. BIN
      binaries/x86_64/tpws
  9. 6
      tpws/gzip.c
  10. 2
      tpws/gzip.h
  11. 17
      tpws/hostlist.c

BIN
binaries/aarch64/tpws

Binary file not shown.

BIN
binaries/armhf/tpws

Binary file not shown.

BIN
binaries/mips32r1-lsb/tpws

Binary file not shown.

BIN
binaries/mips32r1-msb/tpws

Binary file not shown.

BIN
binaries/mips64r2-msb/tpws

Binary file not shown.

BIN
binaries/ppc/tpws

Binary file not shown.

BIN
binaries/x86/tpws

Binary file not shown.

BIN
binaries/x86_64/tpws

Binary file not shown.

6
tpws/gzip.c

@ -73,3 +73,9 @@ zerr:
} }
return r; return r;
} }
bool is_gzip(FILE* F)
{
unsigned char magic[2];
return !fseek(F,0,SEEK_SET) && fread(magic, 1, 2, F)==2 && magic[0]==0x1F && magic[1]==0x8B;
}

2
tpws/gzip.h

@ -2,5 +2,7 @@
#include <stdio.h> #include <stdio.h>
#include <zlib.h> #include <zlib.h>
#include <stdbool.h>
int z_readfile(FILE *F,char **buf,size_t *size); int z_readfile(FILE *F,char **buf,size_t *size);
bool is_gzip(FILE* F);

17
tpws/hostlist.c

@ -28,6 +28,7 @@ bool LoadHostList(strpool **hostlist, char *filename)
size_t zsize; size_t zsize;
int ct = 0; int ct = 0;
FILE *F; FILE *F;
int r;
if (*hostlist) if (*hostlist)
{ {
@ -40,10 +41,10 @@ bool LoadHostList(strpool **hostlist, char *filename)
fprintf(stderr, "Could not open %s\n", filename); fprintf(stderr, "Could not open %s\n", filename);
return false; return false;
} }
if (z_readfile(F,&zbuf,&zsize)==Z_OK) if ((r=z_readfile(F,&zbuf,&zsize))==Z_OK)
{ {
printf("libz compression detected. uncompressed size : %zu\n", zsize); printf("zlib compression detected. uncompressed size : %zu\n", zsize);
fclose(F); fclose(F);
p = zbuf; p = zbuf;
@ -60,9 +61,21 @@ bool LoadHostList(strpool **hostlist, char *filename)
} }
free(zbuf); free(zbuf);
} }
else if (r!=Z_DATA_ERROR)
{
fprintf(stderr, "zlib decompression failed : result %d\n",r);
return false;
}
else else
{ {
if (is_gzip(F))
{
fprintf(stderr, "hostlist is gzip but is broken : %s\n",filename);
return false;
}
fseek(F,0,SEEK_SET); fseek(F,0,SEEK_SET);
printf("loading plain text list\n",r);
while (fgets(s, 256, F)) while (fgets(s, 256, F))
{ {

Loading…
Cancel
Save