mirror of
https://codeberg.org/scip/pcp.git
synced 2025-12-17 12:00:56 +01:00
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:
4
TODO
4
TODO
@@ -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.
|
||||||
|
|||||||
@@ -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 ps_read_raw(Pcpstream *stream, void *buf, size_t readbytes) {
|
||||||
size_t gotbytes = 0;
|
size_t gotbytes = 0;
|
||||||
size_t idx = 0;
|
size_t idx = 0;
|
||||||
|
|
||||||
if(buffer_left(stream->save) > 0) {
|
if(buffer_left(stream->save) > 0) {
|
||||||
/* something left from last rewind, first use this */
|
/* something left from last rewind, first use this */
|
||||||
if(buffer_left(stream->save) >= readbytes) {
|
if(buffer_left(stream->save) >= readbytes) {
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -295,8 +297,8 @@ size_t ps_read(Pcpstream *stream, void *buf, size_t readbytes) {
|
|||||||
int ps_readline(Pcpstream *stream, Buffer *line) {
|
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 */
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user