From c7108ec47f932f71960c05619f217d75c0446610 Mon Sep 17 00:00:00 2001 From: "git@daemon.de" Date: Fri, 16 Oct 2015 17:25:17 +0200 Subject: [PATCH] fixed stream-reader bug on aix@ppc, which ignored the last z85 pkt sometimes due invalid call to ps_end() --- TODO | 4 +--- libpcp/pcpstream.c | 21 +++++++++++++-------- libpcp/z85.c | 1 - tests/pipetest.c | 1 - 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/TODO b/TODO index b9d87b6..86d515c 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,4 @@ -AIX@ppc: pipetest fails. encode is correct, same # of pkts as - on bsd + 1 pad. decode misses last pkt. Must be somewhere - in pcpstream.c. +pcpstream.c: use static tmp buffers, avoid alloc mem during each iteration detach keysig generation from pub key export, so that an existing keysig can be verified later. diff --git a/libpcp/pcpstream.c b/libpcp/pcpstream.c index 35df7a8..f44264f 100644 --- a/libpcp/pcpstream.c +++ b/libpcp/pcpstream.c @@ -103,7 +103,7 @@ void ps_rewind(Pcpstream *stream, void *buf, size_t bufsize) { size_t ps_read_raw(Pcpstream *stream, void *buf, size_t readbytes) { size_t gotbytes = 0; size_t idx = 0; - + if(buffer_left(stream->save) > 0) { /* something left from last rewind, first use this */ if(buffer_left(stream->save) >= readbytes) { @@ -137,6 +137,7 @@ size_t ps_read_raw(Pcpstream *stream, void *buf, size_t readbytes) { } else { size_t got = fread(buf+idx, 1, readbytes, stream->fd); + gotbytes += got; if(feof(stream->fd) != 0) stream->eof = 1; @@ -146,7 +147,8 @@ size_t ps_read_raw(Pcpstream *stream, void *buf, size_t readbytes) { 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; } @@ -295,8 +297,8 @@ size_t ps_read(Pcpstream *stream, void *buf, size_t readbytes) { int ps_readline(Pcpstream *stream, Buffer *line) { int c = -1, max = 1; byte b[1]; - - while(c\n", c, b[0]); + //buffer_info(line); 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 */ size_t binlen, outlen; 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); //_dump("bin", bin, binlen); - //fatals_ifany(); + fatals_ifany(ptx); if(bin == NULL) { /* it's not z85 encoded, so threat it as binary */ diff --git a/libpcp/z85.c b/libpcp/z85.c index 83f4fd3..62d6bc7 100755 --- a/libpcp/z85.c +++ b/libpcp/z85.c @@ -173,7 +173,6 @@ byte *pcp_z85_decode(PCPCTX *ptx, char *z85block, size_t *dstlen) { byte padblob[4]; srclen = strlen(z85block); - if(srclen == 0) { /* FIXME: check how this happens, pcpstream decoder call */ *dstlen = 0; diff --git a/tests/pipetest.c b/tests/pipetest.c index cdf20cb..6bd7cdd 100644 --- a/tests/pipetest.c +++ b/tests/pipetest.c @@ -45,7 +45,6 @@ int main(int argc, char **argv) { while(!ps_end(in)) { got = ps_read(in, buf, blocksize); - //fprintf(stderr, "got: %ld\n", got); if(got > 0) ps_write(out, buf, got); }