Mercurial > trustbridge
changeset 235:0c4d65a7cd14
Started to write input parser.
Strange problems with b64 decode seemingly to accept invalid input?
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Fri, 28 Mar 2014 13:04:59 +0100 |
parents | 774e944c395b |
children | bd83b038829d |
files | cinst/mozilla.c common/errorcodes.h |
diffstat | 2 files changed, 59 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/cinst/mozilla.c Fri Mar 28 10:50:14 2014 +0100 +++ b/cinst/mozilla.c Fri Mar 28 13:04:59 2014 +0100 @@ -31,6 +31,14 @@ * */ +/** + * @brief Needs to eb defined to get strnlen() + */ +#define _POSIX_C_SOURCE 200809L + +/* REMOVEME: */ +#include <unistd.h> + #include <dirent.h> #include <cert.h> #include <certt.h> @@ -324,11 +332,61 @@ int main () { + char inpl[LINEBUFLEN]; + size_t inpllen; + char *dercert; + size_t dercertlen; char **pdirs; + bool parserr = true; pdirs = get_all_profile_dirs(); + if (pdirs != NULL) { + while ( fgets(inpl, LINEBUFLEN, stdin) != NULL ) + { + inpllen = strnlen(inpl, LINEBUFLEN); + /* Validate input line: + * - must be (much) longer than 3 characters + * - must start with "*:" + */ + if ((inpllen > 3) && (inpl[1] == ':')) + /* Now parse Input */ + switch(inpl[0]) + { + case 'R': + parserr = true; + DEBUGPRINTF("Removing Certificate: %s", &inpl[2]); + if ( str_base64_decode(&dercert, &dercertlen, + &inpl[2], inpllen-2) == 0 ) + { + DEBUGPRINTF("Successfully b64 decoded cert: '"); + write(2, dercert, dercertlen); + fprintf(stderr,"'\n"); + parserr = false; + } + else + DEBUGPRINTF("Base64 decoded failed!\n'"); + break; + case 'I': + DEBUGPRINTF("Installing Certificate: %s", &inpl[2]); + parserr = false; + break; + default: + parserr = true; + } + else + { + parserr = true; + } + + if (parserr) + { + DEBUGPRINTF("FATAL: Invalid input: %s\n", inpl); + exit(ERR_MOZ_INVALID_INPUT); + } + } + for (int i=0; pdirs[i] != NULL; i++) { puts(pdirs[i]);
--- a/common/errorcodes.h Fri Mar 28 10:50:14 2014 +0100 +++ b/common/errorcodes.h Fri Mar 28 13:04:59 2014 +0100 @@ -29,6 +29,7 @@ /* Error: could not determine current users HOME */ #define ERR_MOZ_HOMELESS 0x0081 +#define ERR_MOZ_INVALID_INPUT 0x0082 /* Warning: Failed to read profile.ini */ #define WARN_MOZ_FAILED_TO_OPEN_INI 0x0091