+/*
+ * Copyright 1998-2016 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the OpenSSL license (the "License"). You may not use
+ * this file except in compliance with the License. You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "obj_lcl.h"
/*
- * Later versions of DEC C has started to add linkage information to certain
- * functions, which makes it tricky to use them as values to regular function
- * pointers. One way is to define a macro that takes care of casting them
- * correctly.
+ * We define this wrapper for two reasons. Firstly, later versions of
+ * DEC C add linkage information to certain functions, which makes it
+ * tricky to use them as values to regular function pointers.
+ * Secondly, in the EDK2 build environment, the strcmp function is
+ * actually an external function (AsciiStrCmp) with the Microsoft ABI,
+ * so we can't transparently assign function pointers to it.
+ * Arguably the latter is a stupidity of the UEFI environment, but
+ * since the wrapper solves the DEC C issue too, let's just use the
+ * same solution.
*/
-#ifdef OPENSSL_SYS_VMS_DECC
-# define OPENSSL_strcmp (int (*)(const char *,const char *))strcmp
+#if defined(OPENSSL_SYS_VMS_DECC) || defined(OPENSSL_SYS_UEFI)
+static int obj_strcmp(const char *a, const char *b)
+{
+ return strcmp(a, b);
+}
#else
-# define OPENSSL_strcmp strcmp
+#define obj_strcmp strcmp
#endif
/*
int (*cmp_func) (const char *, const char *),
void (*free_func) (const char *, int, const char *))
{
- int ret;
- int i;
+ int ret, i, push;
NAME_FUNCS *name_funcs;
if (name_funcs_stack == NULL) {
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->hash_func = OPENSSL_LH_strhash;
+ name_funcs->cmp_func = obj_strcmp;
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
- sk_NAME_FUNCS_push(name_funcs_stack, name_funcs);
+
+ push = sk_NAME_FUNCS_push(name_funcs_stack, name_funcs);
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
+
+ if (!push) {
+ OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX, ERR_R_MALLOC_FAILURE);
+ OPENSSL_free(name_funcs);
+ return 0;
+ }
}
name_funcs = sk_NAME_FUNCS_value(name_funcs_stack, ret);
if (hash_func != NULL)
sk_NAME_FUNCS_value(name_funcs_stack,
a->type)->hash_func(a->name);
} else {
- ret = lh_strhash(a->name);
+ ret = OPENSSL_LH_strhash(a->name);
}
ret ^= a->type;
return (ret);
onp = OPENSSL_malloc(sizeof(*onp));
if (onp == NULL) {
/* ERROR */
- return (0);
+ return 0;
}
onp->name = name;
} else {
if (lh_OBJ_NAME_error(names_lh)) {
/* ERROR */
- return (0);
+ OPENSSL_free(onp);
+ return 0;
}
}
- return (1);
+ return 1;
}
int OBJ_NAME_remove(const char *name, int type)