[openssl-commits] [openssl] master update

Rich Salz rsalz at openssl.org
Thu Jun 30 17:01:52 UTC 2016


The branch master has been updated
       via  c0c9c0c026d9676c9ebb6f5b0b900b8c3fac6673 (commit)
       via  7e1445b03e46db64425f63c060b3ff74295067e5 (commit)
      from  3ce2fdabe6e33952bf3011acf5b68107e6352603 (commit)


- Log -----------------------------------------------------------------
commit c0c9c0c026d9676c9ebb6f5b0b900b8c3fac6673
Author: FdaSilvaYY <fdasilvayy at gmail.com>
Date:   Sat Jun 18 15:05:24 2016 +0200

    Constify a bit more OPENSSL_sk_ API
    
    Reviewed-by: Richard Levitte <levitte at openssl.org>
    Reviewed-by: Rich Salz <rsalz at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/1244)

commit 7e1445b03e46db64425f63c060b3ff74295067e5
Author: FdaSilvaYY <fdasilvayy at gmail.com>
Date:   Thu Jun 2 00:59:34 2016 +0200

    Use directly zalloc in OPENSSL_sk_dup and OPENSSL_sk_deep_copy
    
    Reviewed-by: Richard Levitte <levitte at openssl.org>
    Reviewed-by: Rich Salz <rsalz at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/1244)

-----------------------------------------------------------------------

Summary of changes:
 crypto/stack/stack.c           | 41 ++++++++++++++++++-----------------------
 doc/crypto/DEFINE_STACK_OF.pod |  4 ++--
 include/openssl/safestack.h    |  6 +++---
 include/openssl/stack.h        |  4 ++--
 4 files changed, 25 insertions(+), 30 deletions(-)

diff --git a/crypto/stack/stack.c b/crypto/stack/stack.c
index 0076db1..02be8af 100644
--- a/crypto/stack/stack.c
+++ b/crypto/stack/stack.c
@@ -36,49 +36,44 @@ OPENSSL_sk_compfunc OPENSSL_sk_set_cmp_func(OPENSSL_STACK *sk, OPENSSL_sk_compfu
     return old;
 }
 
-OPENSSL_STACK *OPENSSL_sk_dup(OPENSSL_STACK *sk)
+OPENSSL_STACK *OPENSSL_sk_dup(const OPENSSL_STACK *sk)
 {
     OPENSSL_STACK *ret;
-    char **s;
 
-    if ((ret = OPENSSL_sk_new(sk->comp)) == NULL)
-        goto err;
-    s = OPENSSL_realloc((char *)ret->data,
-                        (unsigned int)sizeof(char *) * sk->num_alloc);
-    if (s == NULL)
-        goto err;
-    ret->data = s;
+    if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL)
+        return NULL;
+
+    /* direct structure assignment */
+    *ret = *sk;
 
-    ret->num = sk->num;
+    if ((ret->data = OPENSSL_malloc(sizeof(*ret->data) * sk->num_alloc)) == NULL)
+        goto err;
     memcpy(ret->data, sk->data, sizeof(char *) * sk->num);
-    ret->sorted = sk->sorted;
-    ret->num_alloc = sk->num_alloc;
-    ret->comp = sk->comp;
-    return (ret);
+    return ret;
  err:
     OPENSSL_sk_free(ret);
-    return (NULL);
+    return NULL;
 }
 
-OPENSSL_STACK *OPENSSL_sk_deep_copy(OPENSSL_STACK *sk, OPENSSL_sk_copyfunc copy_func,
+OPENSSL_STACK *OPENSSL_sk_deep_copy(const OPENSSL_STACK *sk,
+                             OPENSSL_sk_copyfunc copy_func,
                              OPENSSL_sk_freefunc free_func)
 {
     OPENSSL_STACK *ret;
     int i;
 
     if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL)
-        return ret;
-    ret->comp = sk->comp;
-    ret->sorted = sk->sorted;
-    ret->num = sk->num;
+        return NULL;
+
+    /* direct structure assignment */
+    *ret = *sk;
+
     ret->num_alloc = sk->num > MIN_NODES ? sk->num : MIN_NODES;
-    ret->data = OPENSSL_malloc(sizeof(*ret->data) * ret->num_alloc);
+    ret->data = OPENSSL_zalloc(sizeof(*ret->data) * ret->num_alloc);
     if (ret->data == NULL) {
         OPENSSL_free(ret);
         return NULL;
     }
-    for (i = 0; i < ret->num_alloc; i++)
-        ret->data[i] = NULL;
 
     for (i = 0; i < ret->num; ++i) {
         if (sk->data[i] == NULL)
diff --git a/doc/crypto/DEFINE_STACK_OF.pod b/doc/crypto/DEFINE_STACK_OF.pod
index 996bfcd..94e483f 100644
--- a/doc/crypto/DEFINE_STACK_OF.pod
+++ b/doc/crypto/DEFINE_STACK_OF.pod
@@ -50,8 +50,8 @@ stack container
  int sk_TYPE_find_ex(STACK_OF(TYPE) *sk, TYPE *ptr);
  void sk_TYPE_sort(const STACK_OF(TYPE) *sk);
  int sk_TYPE_is_sorted(const STACK_OF(TYPE) *sk);
- STACK_OF(TYPE) *sk_TYPE_dup(STACK_OF(TYPE) *sk);
- STACK_OF(TYPE) *sk_TYPE_deep_copy(STACK_OF(TYPE) *sk,
+ STACK_OF(TYPE) *sk_TYPE_dup(const STACK_OF(TYPE) *sk);
+ STACK_OF(TYPE) *sk_TYPE_deep_copy(const STACK_OF(TYPE) *sk,
                                    sk_TYPE_copyfunc copyfunc,
                                    sk_TYPE_freefunc freefunc);
  sk_TYPE_compfunc (*sk_TYPE_set_cmp_func(STACK_OF(TYPE) *sk, sk_TYPE_compfunc compare);
diff --git a/include/openssl/safestack.h b/include/openssl/safestack.h
index fb8d910..7877fd9 100644
--- a/include/openssl/safestack.h
+++ b/include/openssl/safestack.h
@@ -101,11 +101,11 @@ extern "C" {
     { \
         return OPENSSL_sk_is_sorted((const OPENSSL_STACK *)sk); \
     } \
-    static ossl_inline STACK_OF(t1) * sk_##t1##_dup(STACK_OF(t1) *sk) \
+    static ossl_inline STACK_OF(t1) * sk_##t1##_dup(const STACK_OF(t1) *sk) \
     { \
-        return (STACK_OF(t1) *)OPENSSL_sk_dup((OPENSSL_STACK *)sk); \
+        return (STACK_OF(t1) *)OPENSSL_sk_dup((const OPENSSL_STACK *)sk); \
     } \
-    static ossl_inline STACK_OF(t1) *sk_##t1##_deep_copy(STACK_OF(t1) *sk, \
+    static ossl_inline STACK_OF(t1) *sk_##t1##_deep_copy(const STACK_OF(t1) *sk, \
                                                     sk_##t1##_copyfunc copyfunc, \
                                                     sk_##t1##_freefunc freefunc) \
     { \
diff --git a/include/openssl/stack.h b/include/openssl/stack.h
index 9bc550f..ae47be9 100644
--- a/include/openssl/stack.h
+++ b/include/openssl/stack.h
@@ -29,7 +29,7 @@ OPENSSL_STACK *OPENSSL_sk_new(OPENSSL_sk_compfunc cmp);
 OPENSSL_STACK *OPENSSL_sk_new_null(void);
 void OPENSSL_sk_free(OPENSSL_STACK *);
 void OPENSSL_sk_pop_free(OPENSSL_STACK *st, void (*func) (void *));
-OPENSSL_STACK *OPENSSL_sk_deep_copy(OPENSSL_STACK *, OPENSSL_sk_copyfunc c, OPENSSL_sk_freefunc f);
+OPENSSL_STACK *OPENSSL_sk_deep_copy(const OPENSSL_STACK *, OPENSSL_sk_copyfunc c, OPENSSL_sk_freefunc f);
 int OPENSSL_sk_insert(OPENSSL_STACK *sk, void *data, int where);
 void *OPENSSL_sk_delete(OPENSSL_STACK *st, int loc);
 void *OPENSSL_sk_delete_ptr(OPENSSL_STACK *st, const void *p);
@@ -41,7 +41,7 @@ void *OPENSSL_sk_shift(OPENSSL_STACK *st);
 void *OPENSSL_sk_pop(OPENSSL_STACK *st);
 void OPENSSL_sk_zero(OPENSSL_STACK *st);
 OPENSSL_sk_compfunc OPENSSL_sk_set_cmp_func(OPENSSL_STACK *sk, OPENSSL_sk_compfunc cmp);
-OPENSSL_STACK *OPENSSL_sk_dup(OPENSSL_STACK *st);
+OPENSSL_STACK *OPENSSL_sk_dup(const OPENSSL_STACK *st);
 void OPENSSL_sk_sort(OPENSSL_STACK *st);
 int OPENSSL_sk_is_sorted(const OPENSSL_STACK *st);
 


More information about the openssl-commits mailing list