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.
This commit is contained in:
parent
059e56eb6a
commit
584a610f6a
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue