Make sure not to read beyond end of buffer
[oweals/openssl.git] / crypto / objects / o_names.c
index 2b80243256d96e00e174f05efb31fd7f88624cf9..adb5731f7659f52e3c0de19af53a26e4fee4bb4e 100644 (file)
@@ -2,6 +2,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <openssl/err.h>
 #include <openssl/lhash.h>
 #include <openssl/objects.h>
 #include <openssl/safestack.h>
@@ -79,6 +80,12 @@ int OBJ_NAME_new_index(unsigned long (*hash_func)(const char *),
                {
                MemCheck_off();
                name_funcs = OPENSSL_malloc(sizeof(NAME_FUNCS));
+               MemCheck_on();
+               if (!name_funcs)
+                       {
+                       OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX,ERR_R_MALLOC_FAILURE);
+                       return(0);
+                       }
                name_funcs->hash_func = lh_strhash;
                name_funcs->cmp_func = OPENSSL_strcmp;
                name_funcs->free_func = 0; /* NULL is often declared to
@@ -86,6 +93,7 @@ int OBJ_NAME_new_index(unsigned long (*hash_func)(const char *),
                                                * to Compaq C is not really
                                                * compatible with a function
                                                * pointer.      -- Richard Levitte*/
+               MemCheck_off();
                sk_NAME_FUNCS_push(name_funcs_stack,name_funcs);
                MemCheck_on();
                }
@@ -103,8 +111,8 @@ int OBJ_NAME_new_index(unsigned long (*hash_func)(const char *),
 static int obj_name_cmp(const void *a_void, const void *b_void)
        {
        int ret;
-       OBJ_NAME *a = (OBJ_NAME *)a_void;
-       OBJ_NAME *b = (OBJ_NAME *)b_void;
+       const OBJ_NAME *a = (const OBJ_NAME *)a_void;
+       const OBJ_NAME *b = (const OBJ_NAME *)b_void;
 
        ret=a->type-b->type;
        if (ret == 0)
@@ -125,7 +133,7 @@ static int obj_name_cmp(const void *a_void, const void *b_void)
 static unsigned long obj_name_hash(const void *a_void)
        {
        unsigned long ret;
-       OBJ_NAME *a = (OBJ_NAME *)a_void;
+       const OBJ_NAME *a = (const OBJ_NAME *)a_void;
 
        if ((name_funcs_stack != NULL) && (sk_NAME_FUNCS_num(name_funcs_stack) > a->type))
                {