struct b64_state {
unsigned u;
int v;
+ int error;
};
static struct b64_state *
char *p;
unsigned u, v;
int l;
- *outlen = 0;
- l = 0;
+ *outlen = 0;
u = b64s->u;
v = b64s->v;
- b64s->u = b64s->v = 0;
for (p = s; p < s + len;) {
- if (*p == '\r' || *p == '\n') continue;
- if (size < 3) return (int)(p - s);
+ if (*p == '\r' || *p == '\n') {
+ p++;
+ continue;
+ }
+ if (size < 3) goto done;
for (; v < 4; v++) {
- if (p == s + len) {
- b64s->u = u;
- b64s->v = v;
- return len;
- }
+ if (p >= s + len) goto done;
l = i64[(unsigned int)*p++];
if (l < 0) return -1;
u <<= 6;
}
v = 0;
}
+done: b64s->v = v;
+ b64s->u = u;
return p - s;
}
struct b64_state *b64s = (struct b64_state *)msgproc_getpriv(m);
msgproc *next = msgproc_next(m);
+ if (b64s->error) return;
while (len > 0) {
ret = b64_decode(b64s, buf, len, tmp, sizeof(tmp), &tmplen);
if (ret < 1) {
- /* TODO: handle errors in *b64s; skip all
- text after error, or recover? */
+ b64s->error = 1;
+ break;
}
msgproc_process(next, tmp, tmplen);
buf += ret; len -= ret;