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
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.

View File

@@ -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<PSMAXLINE) {
while(c<PSMAXLINE) { // && ps_end(stream) != 1
//fprintf(stderr, " ps_readline: call raw\n");
if(ps_read_raw(stream, b, 1) < 1) {
//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");
continue;
}
else if(*b == '\n' || ps_end(stream) == 1) {
else if(*b == '\n') {
//fprintf(stderr, " ps_readline: raw found NL\n");
c++;
max = 0;
@@ -329,7 +331,8 @@ int ps_readline(Pcpstream *stream, Buffer *line) {
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;
}
@@ -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 */

View File

@@ -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;

View File

@@ -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);
}