Browse Source

tpws : better gzip checking. fixing missing fclose

pull/33/head
bolvan 6 years ago
parent
commit
5dd7834314
  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. 4
      tpws/gzip.c
  10. 48
      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.

4
tpws/gzip.c

@ -77,5 +77,7 @@ zerr:
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;
bool b = !fseek(F,0,SEEK_SET) && fread(magic, 1, 2, F)==2 && magic[0]==0x1F && magic[1]==0x8B;
fseek(F,0,SEEK_SET);
return b;
}

48
tpws/hostlist.c

@ -41,40 +41,37 @@ bool LoadHostList(strpool **hostlist, char *filename)
fprintf(stderr, "Could not open %s\n", filename);
return false;
}
if ((r=z_readfile(F,&zbuf,&zsize))==Z_OK)
if (is_gzip(F))
{
printf("zlib compression detected. uncompressed size : %zu\n", zsize);
r = z_readfile(F,&zbuf,&zsize);
fclose(F);
p = zbuf;
e = zbuf + zsize;
while(p<e)
if (r==Z_OK)
{
if (!addpool(hostlist,&p,e))
printf("zlib compression detected. uncompressed size : %zu\n", zsize);
p = zbuf;
e = zbuf + zsize;
while(p<e)
{
fprintf(stderr, "Not enough memory to store host list : %s\n", filename);
free(zbuf);
return false;
if (!addpool(hostlist,&p,e))
{
fprintf(stderr, "Not enough memory to store host list : %s\n", filename);
free(zbuf);
return false;
}
ct++;
}
ct++;
free(zbuf);
}
free(zbuf);
}
else if (r!=Z_DATA_ERROR)
{
fprintf(stderr, "zlib decompression failed : result %d\n",r);
return false;
}
else
{
if (is_gzip(F))
else
{
fprintf(stderr, "hostlist is gzip but is broken : %s\n",filename);
fprintf(stderr, "zlib decompression failed : result %d\n",r);
return false;
}
fseek(F,0,SEEK_SET);
}
else
{
printf("loading plain text list\n",r);
while (fgets(s, 256, F))
@ -90,6 +87,7 @@ bool LoadHostList(strpool **hostlist, char *filename)
}
fclose(F);
}
printf("Loaded %d hosts from %s\n", ct, filename);
return true;
}

Loading…
Cancel
Save