pulsar-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] hrsakai commented on a change in pull request #2814: Fix memory issue in cpp ZTSClient
Date Wed, 24 Oct 2018 11:17:36 GMT
hrsakai commented on a change in pull request #2814: Fix memory issue in cpp ZTSClient
URL: https://github.com/apache/pulsar/pull/2814#discussion_r227745297
 
 

 ##########
 File path: pulsar-client-cpp/lib/auth/athenz/ZTSClient.cc
 ##########
 @@ -143,14 +143,17 @@ std::string ZTSClient::ybase64Encode(const unsigned char *input, int
length) {
 char *ZTSClient::base64Decode(const char *input) {
     BIO *bio, *b64;
     size_t length = strlen(input);
-    char *result = (char *)malloc(length);
+    char *result = (char *)calloc(length, sizeof(char));
 
     bio = BIO_new_mem_buf((void *)input, -1);
     b64 = BIO_new(BIO_f_base64());
     bio = BIO_push(b64, bio);
 
     BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL);
-    BIO_read(bio, result, length);
+    int decodeStrLen = BIO_read(bio, result, length);
+    if(decodeStrLen > 0) {
+        result[decodeStrLen] = '\0';
+    }
 
 Review comment:
   I implemented it in 2).
   Please check,again.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message