diff --git a/binaries/aarch64/tpws b/binaries/aarch64/tpws index 1f3d955..dafe9d3 100755 Binary files a/binaries/aarch64/tpws and b/binaries/aarch64/tpws differ diff --git a/binaries/armhf/tpws b/binaries/armhf/tpws index e2a51bb..a739b34 100755 Binary files a/binaries/armhf/tpws and b/binaries/armhf/tpws differ diff --git a/binaries/mips32r1-lsb/tpws b/binaries/mips32r1-lsb/tpws index 26458f4..0062381 100755 Binary files a/binaries/mips32r1-lsb/tpws and b/binaries/mips32r1-lsb/tpws differ diff --git a/binaries/mips32r1-msb/tpws b/binaries/mips32r1-msb/tpws index 55023c0..c309bb1 100755 Binary files a/binaries/mips32r1-msb/tpws and b/binaries/mips32r1-msb/tpws differ diff --git a/binaries/mips64r2-msb/tpws b/binaries/mips64r2-msb/tpws index 79daa95..c6eed5a 100755 Binary files a/binaries/mips64r2-msb/tpws and b/binaries/mips64r2-msb/tpws differ diff --git a/binaries/ppc/tpws b/binaries/ppc/tpws index 0ea5c18..2aa4c42 100755 Binary files a/binaries/ppc/tpws and b/binaries/ppc/tpws differ diff --git a/binaries/x86/tpws b/binaries/x86/tpws index bbe2efb..591224c 100755 Binary files a/binaries/x86/tpws and b/binaries/x86/tpws differ diff --git a/binaries/x86_64/tpws b/binaries/x86_64/tpws index 0217859..c4e3880 100755 Binary files a/binaries/x86_64/tpws and b/binaries/x86_64/tpws differ diff --git a/tpws/gzip.c b/tpws/gzip.c index e0f1d83..0f22c02 100644 --- a/tpws/gzip.c +++ b/tpws/gzip.c @@ -73,3 +73,9 @@ zerr: } 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; +} diff --git a/tpws/gzip.h b/tpws/gzip.h index 75c3d87..15e30d2 100644 --- a/tpws/gzip.h +++ b/tpws/gzip.h @@ -2,5 +2,7 @@ #include #include +#include int z_readfile(FILE *F,char **buf,size_t *size); +bool is_gzip(FILE* F); diff --git a/tpws/hostlist.c b/tpws/hostlist.c index 553d7d2..dde04b4 100644 --- a/tpws/hostlist.c +++ b/tpws/hostlist.c @@ -28,6 +28,7 @@ bool LoadHostList(strpool **hostlist, char *filename) size_t zsize; int ct = 0; FILE *F; + int r; if (*hostlist) { @@ -40,10 +41,10 @@ bool LoadHostList(strpool **hostlist, char *filename) fprintf(stderr, "Could not open %s\n", filename); 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); p = zbuf; @@ -60,10 +61,22 @@ bool LoadHostList(strpool **hostlist, char *filename) } free(zbuf); } + else if (r!=Z_DATA_ERROR) + { + fprintf(stderr, "zlib decompression failed : result %d\n",r); + return false; + } else { + if (is_gzip(F)) + { + fprintf(stderr, "hostlist is gzip but is broken : %s\n",filename); + return false; + } + fseek(F,0,SEEK_SET); - + printf("loading plain text list\n",r); + while (fgets(s, 256, F)) { p = s;