Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/crypto/external/bsd/netpgp/dist/src/pgp2ssh clean up various...



details:   https://anonhg.NetBSD.org/src/rev/8ebc76551a8e
branches:  trunk
changeset: 757656:8ebc76551a8e
user:      agc <agc%NetBSD.org@localhost>
date:      Fri Sep 10 04:57:17 2010 +0000

description:
clean up various bits of lint, and one outstanding bug:

+ properly terminate base64-encoded output, fixes a bug whereby if the input
  length was divisible by 3, a bad base64 encoding would ensue

diffstat:

 crypto/external/bsd/netpgp/dist/src/pgp2ssh/b64.c |  28 ++++++++++++++--------
 1 files changed, 18 insertions(+), 10 deletions(-)

diffs (67 lines):

diff -r d065b4dc78b7 -r 8ebc76551a8e crypto/external/bsd/netpgp/dist/src/pgp2ssh/b64.c
--- a/crypto/external/bsd/netpgp/dist/src/pgp2ssh/b64.c Thu Sep 09 22:25:38 2010 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/pgp2ssh/b64.c Fri Sep 10 04:57:17 2010 +0000
@@ -246,6 +246,7 @@
        int              blocksout;
        int              wordlen;
 
+       wordlen = 0;
        for (blocksout = 0, inp = in, outp = out; (size_t)(inp - in) < insize && (size_t)(outp - out) < outsize;) {
                for (wordlen = 0, i = 0; i < sizeof(wordin); i++) {
                        wordin[i] = (uint8_t) *inp++;
@@ -262,13 +263,20 @@
                        }
                        blocksout++;
                }
-               if (blocksout >= (int)(linesize / sizeof(wordout)) ||
-                   (size_t)(inp - in) >= insize) {
-                       if (blocksout) {
-                               *outp++ = '\r';
-                               *outp++ = '\n';
+               if (linesize > 0) {
+                       if (blocksout >= (int)(linesize / sizeof(wordout)) ||
+                           (size_t)(inp - in) >= insize) {
+                               if (blocksout) {
+                                       *outp++ = '\r';
+                                       *outp++ = '\n';
+                               }
+                               blocksout = 0;
                        }
-                       blocksout = 0;
+               }
+       }
+       if (wordlen == 3 && (size_t)(outp - out) < outsize - 4) {
+               for (i = 0 ; i < 4 ; i++) {
+                       *outp++ = '=';
                }
        }
        return (int)(outp - out);
@@ -296,16 +304,16 @@
 b64decode(const char *in, const size_t insize, void *vp, size_t outsize)
 {
        const char      *inp;
+       unsigned         wordlen;
+       unsigned         i;
        uint8_t          wordout[3];
        uint8_t          wordin[4];
        uint8_t          v;
        char            *out = vp;
        char            *outp;
-       int              wordlen;
-       int              i;
 
        for (inp = in, outp = out ; (size_t)(inp - in) < insize && (size_t)(outp - out) < outsize ; ) {
-               for (wordlen = 0, i = 0 ; i < 4 && (size_t)(inp - in) < insize ; i++) {
+               for (wordlen = 0, i = 0 ; i < sizeof(wordin) && (size_t)(inp - in) < insize ; i++) {
                        /* get a single character */
                        for (v = 0; (size_t)(inp - in) < insize && v == 0 ; ) {
                                if (*inp == '\r' && *(inp + 1) == '\n') {
@@ -318,7 +326,7 @@
                                        }
                                }
                        }
-                       /* perhaps 0 pad */
+                       /* perhaps 0x0 pad */
                        if ((size_t)(inp - in) < insize) {
                                wordlen += 1;
                                if (v) {



Home | Main Index | Thread Index | Old Index