fixed stream-reader bug on aix@ppc, which ignored the last z85 pkt sometimes due invalid call to ps_end()

This commit is contained in:
git@daemon.de
2015-10-16 17:25:17 +02:00
parent 4165e5d996
commit c7108ec47f
4 changed files with 14 additions and 13 deletions

4
TODO
View File

@@ -1,6 +1,4 @@
AIX@ppc: pipetest fails. encode is correct, same # of pkts as pcpstream.c: use static tmp buffers, avoid alloc mem during each iteration
on bsd + 1 pad. decode misses last pkt. Must be somewhere
in pcpstream.c.
detach keysig generation from pub key export, so that an existing detach keysig generation from pub key export, so that an existing
keysig can be verified later. keysig can be verified later.

View File

@@ -137,6 +137,7 @@ size_t ps_read_raw(Pcpstream *stream, void *buf, size_t readbytes) {
} }
else { else {
size_t got = fread(buf+idx, 1, readbytes, stream->fd); size_t got = fread(buf+idx, 1, readbytes, stream->fd);
gotbytes += got; gotbytes += got;
if(feof(stream->fd) != 0) if(feof(stream->fd) != 0)
stream->eof = 1; stream->eof = 1;
@@ -146,7 +147,8 @@ size_t ps_read_raw(Pcpstream *stream, void *buf, size_t readbytes) {
rawdone: rawdone:
//_dump("ps_read_raw", buf, gotbytes); //_dump(" ps_read_raw first byte:", buf, 1);
//fprintf(stderr, " ps_read_raw, gotbytes: %ld\n", gotbytes);
return gotbytes; return gotbytes;
} }
@@ -296,7 +298,7 @@ int ps_readline(Pcpstream *stream, Buffer *line) {
int c = -1, max = 1; int c = -1, max = 1;
byte b[1]; byte b[1];
while(c<PSMAXLINE) { while(c<PSMAXLINE) { // && ps_end(stream) != 1
//fprintf(stderr, " ps_readline: call raw\n"); //fprintf(stderr, " ps_readline: call raw\n");
if(ps_read_raw(stream, b, 1) < 1) { if(ps_read_raw(stream, b, 1) < 1) {
//fprintf(stderr, " ps_readline: raw returned < 1\n"); //fprintf(stderr, " ps_readline: raw returned < 1\n");
@@ -307,7 +309,7 @@ int ps_readline(Pcpstream *stream, Buffer *line) {
//fprintf(stderr, " ps_readline: raw found CR\n"); //fprintf(stderr, " ps_readline: raw found CR\n");
continue; continue;
} }
else if(*b == '\n' || ps_end(stream) == 1) { else if(*b == '\n') {
//fprintf(stderr, " ps_readline: raw found NL\n"); //fprintf(stderr, " ps_readline: raw found NL\n");
c++; c++;
max = 0; max = 0;
@@ -329,7 +331,8 @@ int ps_readline(Pcpstream *stream, Buffer *line) {
return -1; return -1;
} }
// fprintf(stderr, " ps_readline: raw return %d\n", c); //fprintf(stderr, " ps_readline: raw return %d, last b: <%c>\n", c, b[0]);
//buffer_info(line);
return c; return c;
} }
@@ -439,14 +442,16 @@ size_t ps_read_decode(Pcpstream *stream) {
} }
} }
//fprintf(stderr, "%s\n", buffer_get_str(z)); //buffer_info(z);
//buffer_dump(z);
//fprintf(stderr, "\n%s\n", buffer_get_str(z));
/* finally, decode it and put into next */ /* finally, decode it and put into next */
size_t binlen, outlen; size_t binlen, outlen;
byte *bin = pcp_z85_decode(ptx, buffer_get_str(z), &binlen); byte *bin = pcp_z85_decode(ptx, buffer_get_str(z), &binlen);
//fprintf(stderr, "ps_read_decode decoding z: %ld, got: %ld\n", buffer_size(z), binlen); //fprintf(stderr, "ps_read_decode decoding z: %ld, got: %ld\n", buffer_size(z), binlen);
//_dump("bin", bin, binlen); //_dump("bin", bin, binlen);
//fatals_ifany(); fatals_ifany(ptx);
if(bin == NULL) { if(bin == NULL) {
/* it's not z85 encoded, so threat it as binary */ /* it's not z85 encoded, so threat it as binary */

View File

@@ -173,7 +173,6 @@ byte *pcp_z85_decode(PCPCTX *ptx, char *z85block, size_t *dstlen) {
byte padblob[4]; byte padblob[4];
srclen = strlen(z85block); srclen = strlen(z85block);
if(srclen == 0) { if(srclen == 0) {
/* FIXME: check how this happens, pcpstream decoder call */ /* FIXME: check how this happens, pcpstream decoder call */
*dstlen = 0; *dstlen = 0;

View File

@@ -45,7 +45,6 @@ int main(int argc, char **argv) {
while(!ps_end(in)) { while(!ps_end(in)) {
got = ps_read(in, buf, blocksize); got = ps_read(in, buf, blocksize);
//fprintf(stderr, "got: %ld\n", got);
if(got > 0) if(got > 0)
ps_write(out, buf, got); ps_write(out, buf, got);
} }