From 91f94a532eea7c20f643c996b874558118e14a99 Mon Sep 17 00:00:00 2001 From: TLINDEN Date: Sun, 9 Feb 2014 17:50:00 +0100 Subject: [PATCH] removed redundant code and fixed an invalid read of size 1 in ...unpadfour() --- libpcp/z85.c | 62 +++++++-------------------------------------- src/z85util.c | 1 + tests/unittests.cfg | 2 +- 3 files changed, 11 insertions(+), 54 deletions(-) diff --git a/libpcp/z85.c b/libpcp/z85.c index d2b2d8b..4292569 100644 --- a/libpcp/z85.c +++ b/libpcp/z85.c @@ -45,7 +45,7 @@ unsigned char *pcp_unpadfour(unsigned char *src, size_t srclen, size_t *dstlen) outlen = srclen; - for(i=srclen; i>0; --i) { + for(i=srclen-1; i>0; --i) { if(src[i] != '\0') { outlen = i + 1; break; @@ -57,50 +57,27 @@ unsigned char *pcp_unpadfour(unsigned char *src, size_t srclen, size_t *dstlen) } unsigned char *pcp_z85_decode(char *z85block, size_t *dstlen) { - unsigned char *bin; - int i, pos; - size_t zlen, binlen, outlen; + unsigned char *bin = NULL; + unsigned char *raw = NULL; + size_t binlen, outlen; - zlen = strlen(z85block); - char *z85 = ucmalloc(zlen+1); - - /* remove newlines */ - pos = 0; - for(i=0; i= 71) { - *z85block++ = '\r'; - *z85block++ = '\n'; - pos = 1; - } - else { - pos++; - } - *z85block++ = z85[i]; - } - */ - char *z = &z85[0]; char *B = &z85block[0]; @@ -150,9 +109,6 @@ char *pcp_z85_encode(unsigned char *raw, size_t srclen, size_t *dstlen) { } *B = '\0'; - /* fprintf(stderr, "z85block len: %d\n", blocklen, strlen(z85block)); */ - /* fprintf(stderr, "z85block: <%s>\n", z85block); */ - *dstlen = blocklen; free(z85); free(padded); diff --git a/src/z85util.c b/src/z85util.c index 799dd5e..96b06d5 100644 --- a/src/z85util.c +++ b/src/z85util.c @@ -129,6 +129,7 @@ int pcpz85_decode(char *infile, char *outfile) { goto errdz3; } + free(encoded); free(decoded); return 0; diff --git a/tests/unittests.cfg b/tests/unittests.cfg index c48d35b..d1c6e75 100644 --- a/tests/unittests.cfg +++ b/tests/unittests.cfg @@ -347,7 +347,7 @@ temporarily disabled prepare = perl -e 'print "X" x 5000; print "\n"' > testfile-toolong cmd = $pcp -V $vault -P -I testfile-toolong - expect = /line is too long/ + expect = /Error: decoded input/ /*