Module Name: src
Committed By: agc
Date: Fri Sep 10 04:57:18 UTC 2010
Modified Files:
src/crypto/external/bsd/netpgp/dist/src/pgp2ssh: b64.c
Log Message:
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
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 \
src/crypto/external/bsd/netpgp/dist/src/pgp2ssh/b64.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/crypto/external/bsd/netpgp/dist/src/pgp2ssh/b64.c
diff -u src/crypto/external/bsd/netpgp/dist/src/pgp2ssh/b64.c:1.1 src/crypto/external/bsd/netpgp/dist/src/pgp2ssh/b64.c:1.2
--- src/crypto/external/bsd/netpgp/dist/src/pgp2ssh/b64.c:1.1 Mon Sep 6 18:16:52 2010
+++ src/crypto/external/bsd/netpgp/dist/src/pgp2ssh/b64.c Fri Sep 10 04:57:17 2010
@@ -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) {