Mercurial > trustbridge
changeset 64:fb9f78f7ab2f
Improve error handling free memory before exiting. Include line endings in Marker lines
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Tue, 18 Mar 2014 14:14:15 +0000 |
parents | 355800cdefcc |
children | e4088afd5281 |
files | cinst/main.c common/errorcodes.h |
diffstat | 2 files changed, 46 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/cinst/main.c Tue Mar 18 14:11:34 2014 +0000 +++ b/cinst/main.c Tue Mar 18 14:14:15 2014 +0000 @@ -29,6 +29,7 @@ #define MAX_INPUT_SIZE 2000000 /* MAX_LINE_LENGTH * (MAX_LINES *2) */ #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <assert.h> @@ -47,7 +48,7 @@ * * @returns: 0 on success. An error code otherwise. */ -int readInput(char **certificateList, char ***to_install, +int readInput(char **certificate_list, char ***to_install, char ***to_remove) { int lines_read = 0; @@ -60,16 +61,16 @@ printf("Too many lines\n"); return ERR_TOO_MUCH_INPUT; } - if (strcmp("-----BEGIN CERTIFICATE LIST-----", buf) == 0){ + if (strcmp("-----BEGIN CERTIFICATE LIST-----\r\n", buf) == 0){ readingList = 1; continue; } - if (strcmp("-----END CERTIFICATE LIST-----", buf) == 0){ + if (strcmp("-----END CERTIFICATE LIST-----\r\n", buf) == 0){ readingList = 0; continue; } if (readingList) { - str_append_str(certificateList, buf, len); + str_append_str(certificate_list, buf, len); continue; } if (*buf == 'I') { @@ -88,26 +89,55 @@ return 0; } +int validate_instructions(const char *certificate_list, + const size_t listLen, + const char **to_install, + const char **to_remove) +{ + /* TODO */ + return 0; +} + int main() { - char **to_install = NULL; char **to_remove = NULL; - char *certificateList = NULL; + char *certificate_list = NULL; + size_t listLen = 0; int ret = -1; - ret = readInput(&certificateList, &to_install, &to_remove); + ret = readInput(&certificate_list, &to_install, &to_remove); if (ret != 0) { return ret; } - if (!certificateList) { + if (!certificate_list) { return ERR_INVALID_INPUT_NO_LIST; } - ret = verify_list(certificateList, strlen(certificateList)); + listLen = strnlen(certificate_list, MAX_INPUT_SIZE); - printf ("Verify List returned %i\n", ret); + ret = verify_list(certificate_list, listLen); + + if (ret != 0) { + return ERR_INVALID_SIGNATURE; + } + + if (!strv_length(to_install) && !strv_length(to_remove)) { + return ERR_NO_INSTRUCTIONS; + } + + /* Check that the instructions are ok to execute */ + ret = validate_instructions(certificate_list, to_install, to_remove); + + if (ret != 0) { + return ERR_INVALID_INSTRUCTIONS; + } + + /* Make valgrind happy */ + strfreev (to_install); + strfreev (to_remove); + free (certificate_list); return 0; }
--- a/common/errorcodes.h Tue Mar 18 14:11:34 2014 +0000 +++ b/common/errorcodes.h Tue Mar 18 14:14:15 2014 +0000 @@ -5,5 +5,11 @@ #define ERR_INVALID_INPUT_NO_LIST 2 /* Too much input for the installer process */ #define ERR_TOO_MUCH_INPUT 3 +/* Invalid signature */ +#define ERR_INVALID_SIGNATURE 4 +/* No instructions */ +#define ERR_NO_INSTRUCTIONS 5 +/* Instructions not valid (certs not part of certificate list) */ +#define ERR_INVALID_INSTRUCTIONS 6 #endif