Repository: randombit/botan
Pull request #2342 (2020-04-24 13:58:53)

Fixes for Clang 10
Fixes a new ASan error plus some warnings


Patch:
diff --git a/src/lib/math/mp/mp_core.h b/src/lib/math/mp/mp_core.h
index e59be0c39..c4bf8e881 100644
--- a/src/lib/math/mp/mp_core.h
+++ b/src/lib/math/mp/mp_core.h
@@ -429,7 +429,8 @@ inline void bigint_shr1(word x[], size_t x_size,
    {
    const size_t top = x_size >= word_shift ? (x_size - word_shift) : 0;
 
-   copy_mem(x, x + word_shift, top);
+   if(top > 0)
+      copy_mem(x, x + word_shift, top);
    clear_mem(x + top, std::min(word_shift, x_size));
 
    const auto carry_mask = CT::Mask<word>::expand(bit_shift);
@@ -467,7 +468,8 @@ inline void bigint_shr2(word y[], const word x[], size_t x_size,
    {
    const size_t new_size = x_size < word_shift ? 0 : (x_size - word_shift);
 
-   copy_mem(y, x + word_shift, new_size);
+   if(new_size > 0)
+      copy_mem(y, x + word_shift, new_size);
 
    const auto carry_mask = CT::Mask<word>::expand(bit_shift);
    const size_t carry_shift = carry_mask.if_set_return(BOTAN_MP_WORD_BITS - bit_shift);
diff --git a/src/lib/x509/certstor_flatfile/certstor_flatfile.cpp b/src/lib/x509/certstor_flatfile/certstor_flatfile.cpp
index 90feecd24..078bf22a9 100644
--- a/src/lib/x509/certstor_flatfile/certstor_flatfile.cpp
+++ b/src/lib/x509/certstor_flatfile/certstor_flatfile.cpp
@@ -47,7 +47,7 @@ Flatfile_Certificate_Store::Flatfile_Certificate_Store(const std::string& file,
 
    DataSource_Stream file_stream(file);
 
-   for(const std::vector<uint8_t> der : decode_all_certificates(file_stream))
+   for(const std::vector<uint8_t>& der : decode_all_certificates(file_stream))
       {
       std::shared_ptr<const X509_Certificate> cert = std::make_shared<const X509_Certificate>(der.data(), der.size());
 
diff --git a/src/lib/x509/x509path.cpp b/src/lib/x509/x509path.cpp
index 03daee146..a2cfbbb1c 100644
--- a/src/lib/x509/x509path.cpp
+++ b/src/lib/x509/x509path.cpp
@@ -731,12 +731,12 @@ PKIX::build_all_certificate_paths(std::vector<std::vector<std::shared_ptr<const
          // push a deletion marker on the stack for backtracing later
          stack.push_back({std::shared_ptr<const X509_Certificate>(nullptr),false});
 
-         for(const auto trusted_cert : trusted_issuers)
+         for(const auto& trusted_cert : trusted_issuers)
             {
             stack.push_back({trusted_cert,true});
             }
 
-         for(const auto misc : misc_issuers)
+         for(const auto& misc : misc_issuers)
             {
             stack.push_back({misc,false});
             }


Test patch:
diff --git a/src/tests/test_certstor.cpp b/src/tests/test_certstor.cpp
index c05772561..3af56e56c 100644
--- a/src/tests/test_certstor.cpp
+++ b/src/tests/test_certstor.cpp
@@ -53,7 +53,7 @@ Test::Result test_certstor_sqlite3_insert_find_remove_test(const std::vector<Cer
          store.insert_key(a.certificate, *a.private_key);
          }
 
-      for(const auto certandkey : certsandkeys)
+      for(const auto& certandkey : certsandkeys)
          {
          const auto cert = certandkey.certificate;
          const auto key = certandkey.private_key;
@@ -195,7 +195,7 @@ Test::Result test_certstor_sqlite3_all_subjects_test(const std::vector<Certifica
 
       result.test_eq("Check subject list length", subjects.size(), 6);
 
-      for(const auto sub : subjects)
+      for(const auto& sub : subjects)
          {
          std::stringstream ss;
 
@@ -300,7 +300,7 @@ Test::Result test_certstor_find_hash_subject(const std::vector<CertificateAndKey
          store.add_certificate(a.certificate);
          }
 
-      for(const auto certandkey : certsandkeys)
+      for(const auto& certandkey : certsandkeys)
          {
          const auto cert = certandkey.certificate;
          const auto hash = cert.raw_subject_dn_sha256();
diff --git a/src/tests/test_uri.cpp b/src/tests/test_uri.cpp
index c2dd7144e..640efb166 100644
--- a/src/tests/test_uri.cpp
+++ b/src/tests/test_uri.cpp
@@ -60,7 +60,7 @@ class URI_Tests final : public Test
                {"[::1]:61234", Botan::URI::Type::IPv6, "::1", 61234},
             };
 
-         for(const auto t : tests)
+         for(const auto& t : tests)
             {
             auto test_URI = [&result](const Botan::URI& uri, const std::string& host, const unsigned port)
                {