From c40e4285071e7359bf7c63d2dcabebb434ecac96 Mon Sep 17 00:00:00 2001 From: Jeff Connelly Date: Mon, 2 Jun 2008 21:44:40 -0700 Subject: [PATCH] In base64 decoder, print to stderr if there is a decoding error. --- base64.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/base64.c b/base64.c index 8d2130e..b04718c 100644 --- a/base64.c +++ b/base64.c @@ -38,6 +38,7 @@ RCSID("$Id: base64.c,v 1.4 1999/12/02 16:58:45 joda Exp $"); #endif #include #include +#include #include "base64.h" static char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; @@ -109,8 +110,11 @@ int base64_decode(const char *str, void *data) x = pos(p[1]); if(x >= 0) c += x; - else + else{ + fprintf(stderr, "base64_decode: bad character '%c' (%.2x)\n", + p[1], p[1]); return -1; + } c*=64; if(p[2] == '=') @@ -119,16 +123,22 @@ int base64_decode(const char *str, void *data) x = pos(p[2]); if(x >= 0) c += x; - else + else{ + fprintf(stderr, "base64_decode: bad character '%c' (%.2x)\n", + p[2], p[2]); return -1; + } } c*=64; if(p[3] == '=') done++; else{ - if(done) + if(done){ + fprintf(stderr, "base64_decode: done, '%c' (%.2x)\n", + p[3], p[3]); return -1; + } x = pos(p[3]); if(x >= 0) c += x; -- 2.11.4.GIT