You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2019/02/22 15:11:32 UTC

[activemq-artemis] 01/05: ARTEMIS-2260 Fixes a potential NULL pointer dereference on the thin library

This is an automated email from the ASF dual-hosted git repository.

clebertsuconic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git

commit 584a610f6a1c06cedecea565b62cff19ac32cb12
Author: Otavio Rodolfo Piske <op...@redhat.com>
AuthorDate: Tue Jan 29 14:34:42 2019 +0100

    ARTEMIS-2260 Fixes a potential NULL pointer dereference on the thin library
    
    If the code fails to allocate native memory for the error message, it
    will still perform the call to strcpy, which will result in a
    segmentation fault to occur. This may cause the JVM to shutdown abruptly
    potentially causing the original root cause to be hidden.
---
 .../main/c/org_apache_activemq_artemis_jlibaio_LibaioContext.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/artemis-native/src/main/c/org_apache_activemq_artemis_jlibaio_LibaioContext.c b/artemis-native/src/main/c/org_apache_activemq_artemis_jlibaio_LibaioContext.c
index 3a25cee..f8a04e3 100644
--- a/artemis-native/src/main/c/org_apache_activemq_artemis_jlibaio_LibaioContext.c
+++ b/artemis-native/src/main/c/org_apache_activemq_artemis_jlibaio_LibaioContext.c
@@ -113,10 +113,12 @@ char* exceptionMessage(char* msg, int error) {
         error = error * -1;
     }
     //strerror is returning a constant, so no need to free anything coming from strerror
-    char* err = strerror(error);
-    char* result = malloc(strlen(msg) + strlen(err) + 1);
-    strcpy(result, msg);
-    strcat(result, err);
+    char *result = NULL;
+
+    if (asprintf(&result, "%s%s", msg, strerror(error)) == -1) {
+    	fprintf(stderr, "Could not allocate enough memory for the error message: %s/%s\n", msg, strerror(error));
+    }
+
     return result;
 }