libprelude/master: Flexelint warnings fixes
[email protected] Mon, 11 Jan 2010 17:04:11 +0100 (CET)
| Newsgroups | gmane.comp.security.ids.prelude.cvs |
|---|---|
| Message-ID | <[email protected]> |
commit 8af3e5fd98cd2b92146b1f433344d44e8ce9372e Author: Yoann Vandoorselaere <[email protected]> Date: Mon Jan 11 17:00:26 2010 +0100 Flexelint warnings fixes Thanks Steve Grubb <[email protected]> for reporting these! prelude-admin/prelude-admin.c: fix possible leak on getpass() error. src/idmef-data.c: fix potential invalid read if sizeof(char) > 1. src/idmef-path.c: idmef_path_set_index() would accept an off by one depth. src/prelude-connection.c: fix invalid pointer dereference in case malloc fail and we are using UNIX socket. ======================================== prelude-admin/prelude-admin.c | 5 ++++- src/idmef-data.c | 6 +++--- src/idmef-path.c | 11 ++++------- src/prelude-connection.c | 6 ++++-- 4 files changed, 15 insertions(+), 13 deletions(-) ======================================== diff --git a/prelude-admin/prelude-admin.c b/prelude-admin/prelude-admin.c index 073cfe2..65f0dbe 100644 --- a/prelude-admin/prelude-admin.c +++ b/prelude-admin/prelude-admin.c @@ -1047,8 +1047,11 @@ static int ask_one_shot_password(char **buf, const char *ask, ...) snprintf(str, sizeof(str), "Confirm %s: ", askbuf); pass2 = getpass(str); - if ( ! pass2 ) + if ( ! pass2 ) { + memset(pass1, 0, strlen(pass1)); + free(pass1); return -1; + } ret = strcmp(pass1, pass2); memset(pass2, 0, strlen(pass2)); diff --git a/src/idmef-data.c b/src/idmef-data.c index edb90b8..e77e1e1 100644 --- a/src/idmef-data.c +++ b/src/idmef-data.c @@ -391,7 +391,7 @@ static int bytes_to_string(prelude_string_t *out, const unsigned char *src, size static const char b64tbl[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; while ( size ) { - ret = prelude_string_ncat(out, &b64tbl[src[0] >> 2], 1); + ret = prelude_string_ncat(out, &b64tbl[(src[0] >> 2) & 0x3f], 1); if ( ret < 0 ) return ret; @@ -582,7 +582,7 @@ int idmef_data_set_char_string_ref(idmef_data_t *data, const char *ptr) int idmef_data_set_char_string_dup(idmef_data_t *data, const char *ptr) { - prelude_return_val_if_fail(data, prelude_error(PRELUDE_ERROR_ASSERTION)); + prelude_return_val_if_fail(data, prelude_error(PRELUDE_ERROR_ASSERTION)); prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION)); return idmef_data_set_char_string_dup_fast(data, ptr, strlen(ptr)); @@ -590,7 +590,7 @@ int idmef_data_set_char_string_dup(idmef_data_t *data, const char *ptr) int idmef_data_set_char_string_nodup(idmef_data_t *data, char *ptr) { - prelude_return_val_if_fail(data, prelude_error(PRELUDE_ERROR_ASSERTION)); + prelude_return_val_if_fail(data, prelude_error(PRELUDE_ERROR_ASSERTION)); prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION)); return idmef_data_set_char_string_nodup_fast(data, ptr, strlen(ptr)); diff --git a/src/idmef-path.c b/src/idmef-path.c index 19e5aea..c7e54cd 100644 --- a/src/idmef-path.c +++ b/src/idmef-path.c @@ -855,9 +855,7 @@ int idmef_path_set_index(idmef_path_t *path, unsigned int depth, unsigned int in int ret; prelude_return_val_if_fail(path, prelude_error(PRELUDE_ERROR_ASSERTION)); - - if ( depth > MAX_DEPTH || depth > path->depth ) - return prelude_error(PRELUDE_ERROR_IDMEF_PATH_DEPTH); + prelude_return_val_if_fail(depth >= path->depth, prelude_error(PRELUDE_ERROR_IDMEF_PATH_DEPTH)); if ( index == INDEX_FORBIDDEN ) return prelude_error(PRELUDE_ERROR_IDMEF_PATH_INDEX_RESERVED); @@ -914,9 +912,7 @@ int idmef_path_undefine_index(idmef_path_t *path, unsigned int depth) int idmef_path_get_index(const idmef_path_t *path, unsigned int depth) { prelude_return_val_if_fail(path, prelude_error(PRELUDE_ERROR_ASSERTION)); - - if ( depth > (path->depth - 1) ) - return prelude_error(PRELUDE_ERROR_IDMEF_PATH_DEPTH); + prelude_return_val_if_fail(depth >= path->depth, prelude_error(PRELUDE_ERROR_IDMEF_PATH_DEPTH)); if ( path->elem[depth].index == INDEX_UNDEFINED ) return prelude_error(PRELUDE_ERROR_IDMEF_PATH_INDEX_UNDEFINED); @@ -1284,13 +1280,14 @@ const char *idmef_path_get_name(const idmef_path_t *path, int depth) const idmef_path_element_t *elem; prelude_return_val_if_fail(path, NULL); + prelude_return_val_if_fail(depth < 0 || depth <= path->depth, NULL); if ( depth < 0 ) return path->name; elem = &path->elem[depth]; - if ( elem->class < 0 || elem->value_type == IDMEF_VALUE_TYPE_ENUM ) + if ( depth > 0 && (elem->class < 0 || elem->value_type == IDMEF_VALUE_TYPE_ENUM) ) ret = idmef_class_get_child_name(path->elem[depth - 1].class, elem->position); else ret = idmef_class_get_name(elem->class); diff --git a/src/prelude-connection.c b/src/prelude-connection.c index 94d1a1a..b8ad538 100644 --- a/src/prelude-connection.c +++ b/src/prelude-connection.c @@ -541,7 +541,7 @@ static int do_getaddrinfo(prelude_connection_t *cnx, struct addrinfo **ai, const static int resolve_addr(prelude_connection_t *cnx, const char *addr) { - struct addrinfo *ai; + struct addrinfo *ai = NULL; int ret, ai_family, ai_addrlen; #if !((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__) struct sockaddr_un *un; @@ -567,7 +567,9 @@ static int resolve_addr(prelude_connection_t *cnx, const char *addr) cnx->sa = malloc(ai_addrlen); if ( ! cnx->sa ) { - freeaddrinfo(ai); + if ( ai ) + freeaddrinfo(ai); + return prelude_error_from_errno(errno); } _______________________________________________ Prelude-cvslog site list [email protected] http://lists.prelude-ids.org/mailman/listinfo/prelude-cvslog