Skip to content

Commit ce96c89

Browse files
authored
CDRIVER-6105 do not propagate -fPIC (#2128)
* do not propagate `-fPIC` * update kms-divergence-check.sh to 9fff64216c06099401e2b3b2d5becb77bc17803d * update sources for kms-message
1 parent 0540e99 commit ce96c89

32 files changed

+155
-79
lines changed

.evergreen/scripts/kms-divergence-check.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LIBMONGOCRYPT_DIR="$MONGOC_DIR/libmongocrypt-for-kms-divergence-check"
1313

1414
# LIBMONGOCRYPT_GITREF is expected to refer to the version of libmongocrypt
1515
# where kms-message was last copied.
16-
LIBMONGOCRYPT_GITREF="34a9572c416e0827a1fa988baf88411c4b5f2c7b"
16+
LIBMONGOCRYPT_GITREF="9fff64216c06099401e2b3b2d5becb77bc17803d"
1717

1818
cleanup() {
1919
if [ -d "$LIBMONGOCRYPT_DIR" ]; then

src/kms-message/CMakeLists.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
cmake_minimum_required (VERSION 3.5)
1+
cmake_minimum_required (VERSION 3.15...4.0)
22
project (kms_message
33
VERSION 0.0.1
44
LANGUAGES C
55
)
66

7-
set (CMAKE_C_STANDARD 90)
7+
set (CMAKE_C_STANDARD 99)
88

99
include (CheckCCompilerFlag)
10-
# All targets obey visibility, not just library targets.
11-
cmake_policy (SET CMP0063 NEW)
10+
1211
set (CMAKE_C_VISIBILITY_PRESET hidden)
1312
set (KMS_MESSAGE_SOURCES
1413
src/kms_b64.c
@@ -101,7 +100,7 @@ add_library (
101100

102101
string(FIND "${CMAKE_C_FLAGS}" "-fPIC" FPIC_LOCATION)
103102
if (NOT WIN32 AND ENABLE_PIC AND "${FPIC_LOCATION}" EQUAL "-1")
104-
target_compile_options (kms_message_static PUBLIC -fPIC)
103+
set_property (TARGET kms_message_static PROPERTY POSITION_INDEPENDENT_CODE TRUE)
105104
message ("Adding -fPIC to compilation of kms_message_static components")
106105
endif ()
107106

src/kms-message/src/hexlify.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17+
#include "hexlify.h"
18+
19+
//
20+
1721
#include "kms_message_private.h"
22+
1823
#include <stdint.h>
1924
#include <stdio.h>
2025
#include <stdlib.h>

src/kms-message/src/hexlify.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ char *
2121
hexlify (const uint8_t *buf, size_t len);
2222

2323
int
24-
unhexlify (const char *in, size_t len);
24+
unhexlify (const char *in, size_t len);

src/kms-message/src/kms_azure_request.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,4 @@ kms_azure_request_unwrapkey_new (const char *host,
216216
ciphertext,
217217
ciphertext_len,
218218
opt);
219-
}
219+
}

src/kms-message/src/kms_b64.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ kms_message_raw_to_b64 (const uint8_t *raw, size_t raw_len)
583583

584584
b64_len = (raw_len / 3 + 1) * 4 + 1;
585585
b64 = malloc (b64_len);
586+
KMS_ASSERT (b64);
586587
memset (b64, 0, b64_len);
587588
if (-1 == kms_message_b64_ntop (raw, raw_len, b64, b64_len)) {
588589
free (b64);
@@ -600,6 +601,7 @@ kms_message_b64_to_raw (const char *b64, size_t *out)
600601

601602
b64len = strlen (b64);
602603
raw = (uint8_t *) malloc (b64len + 1);
604+
KMS_ASSERT (raw);
603605
memset (raw, 0, b64len + 1);
604606
ret = kms_message_b64_pton (b64, raw, b64len);
605607
if (ret > 0) {
@@ -642,6 +644,7 @@ kms_message_b64url_to_raw (const char *b64url, size_t *out)
642644
/* Add four for padding '=' characters. */
643645
capacity = b64urllen + 4;
644646
b64 = malloc (capacity);
647+
KMS_ASSERT (b64);
645648
memset (b64, 0, capacity);
646649
if (-1 ==
647650
kms_message_b64url_to_b64 (b64url, b64urllen, b64, capacity)) {

src/kms-message/src/kms_crypto_libcrypto.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ kms_sha256 (void *unused_ctx,
5858
unsigned char *hash_out)
5959
{
6060
EVP_MD_CTX *digest_ctxp = EVP_MD_CTX_new ();
61+
KMS_ASSERT (digest_ctxp);
6162
bool rval = false;
6263

6364
if (1 != EVP_DigestInit_ex (digest_ctxp, EVP_sha256 (), NULL)) {
@@ -108,6 +109,7 @@ kms_sign_rsaes_pkcs1_v1_5 (void *unused_ctx,
108109
size_t signature_out_len = 256;
109110

110111
ctx = EVP_MD_CTX_new ();
112+
KMS_ASSERT (ctx);
111113
KMS_ASSERT (private_key_len <= LONG_MAX);
112114
pkey = d2i_PrivateKey (EVP_PKEY_RSA,
113115
NULL,

src/kms-message/src/kms_crypto_windows.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#ifdef KMS_MESSAGE_ENABLE_CRYPTO_CNG
2020

21+
#include "kms_message_private.h"
22+
2123
// tell windows.h not to include a bunch of headers we don't need:
2224
#define WIN32_LEAN_AND_MEAN
2325

@@ -179,6 +181,7 @@ kms_sign_rsaes_pkcs1_v1_5 (void *unused_ctx,
179181
}
180182

181183
blob_private = (LPBYTE) calloc (1, blob_private_len);
184+
KMS_ASSERT (blob_private);
182185

183186
success = CryptDecodeObjectEx (X509_ASN_ENCODING,
184187
PKCS_PRIVATE_KEY_INFO,
@@ -208,6 +211,7 @@ kms_sign_rsaes_pkcs1_v1_5 (void *unused_ctx,
208211
}
209212

210213
raw_private = (LPBYTE) calloc (1, raw_private_len);
214+
KMS_ASSERT (raw_private);
211215

212216
success = CryptDecodeObjectEx (X509_ASN_ENCODING,
213217
PKCS_RSA_PRIVATE_KEY,
@@ -234,6 +238,7 @@ kms_sign_rsaes_pkcs1_v1_5 (void *unused_ctx,
234238
}
235239

236240
hash_value = calloc (1, SHA_256_HASH_LEN);
241+
KMS_ASSERT (hash_value);
237242

238243
if(!kms_sha256 (NULL, input, input_len, hash_value)) {
239244
goto cleanup;

src/kms-message/src/kms_gcp_request.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ kms_gcp_request_oauth_new (const char *host,
8888
}
8989

9090
jwt_signature = calloc (1, SIGNATURE_LEN);
91+
KMS_ASSERT (jwt_signature);
9192
if (!req->crypto.sign_rsaes_pkcs1_v1_5 (
9293
req->crypto.sign_ctx,
9394
private_key_data,
@@ -283,4 +284,4 @@ kms_gcp_request_decrypt_new (const char *host,
283284
ciphertext,
284285
ciphertext_len,
285286
opt);
286-
}
287+
}

src/kms-message/src/kms_kmip_reader_writer.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ kmip_writer_t *
4343
kmip_writer_new (void)
4444
{
4545
kmip_writer_t *writer = calloc (1, sizeof (kmip_writer_t));
46+
KMS_ASSERT (writer);
4647
writer->buffer = kms_request_str_new ();
4748
return writer;
4849
}
@@ -205,7 +206,7 @@ kmip_writer_begin_struct (kmip_writer_t *writer, kmip_tag_type_t tag)
205206
size_t pos = writer->buffer->len;
206207

207208
kmip_writer_write_u32 (writer, 0);
208-
KMS_ASSERT(writer->cur_pos < MAX_KMIP_WRITER_POSITIONS);
209+
KMS_ASSERT(writer->cur_pos < MAX_KMIP_WRITER_POSITIONS - 1);
209210
writer->cur_pos++;
210211
writer->positions[writer->cur_pos] = pos;
211212
}
@@ -241,6 +242,7 @@ kmip_reader_t *
241242
kmip_reader_new (uint8_t *ptr, size_t len)
242243
{
243244
kmip_reader_t *reader = calloc (1, sizeof (kmip_reader_t));
245+
KMS_ASSERT (reader);
244246
reader->ptr = ptr;
245247
reader->len = len;
246248
return reader;
@@ -279,7 +281,8 @@ kmip_reader_has_data (kmip_reader_t *reader)
279281
#define CHECK_REMAINING_BUFFER_AND_RET(read_size) \
280282
if ((reader->pos + (read_size)) > reader->len) { \
281283
return false; \
282-
}
284+
} else \
285+
((void)0)
283286

284287
bool
285288
kmip_reader_read_u8 (kmip_reader_t *reader, uint8_t *value)
@@ -346,7 +349,8 @@ kmip_reader_read_bytes (kmip_reader_t *reader, uint8_t **ptr, size_t length)
346349
#define CHECK_AND_RET(x) \
347350
if (!(x)) { \
348351
return false; \
349-
}
352+
} else \
353+
((void)0)
350354

351355
bool
352356
kmip_reader_read_tag (kmip_reader_t *reader, kmip_tag_type_t *tag)

0 commit comments

Comments
 (0)