8175510: Null pointer dereference in getModuleObject of JPLISAgent.c:790

Check for NULL pointer return from malloc

Reviewed-by: dholmes, cjplummer
This commit is contained in:
Serguei Spitsyn 2017-10-18 13:52:32 -07:00
parent 41d19c4a10
commit 90b611adc6

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -783,7 +783,10 @@ getModuleObject(jvmtiEnv* jvmti,
int len = (last_slash == NULL) ? 0 : (int)(last_slash - cname);
char* pkg_name_buf = (char*)malloc(len + 1);
jplis_assert_msg(pkg_name_buf != NULL, "OOM error in native tmp buffer allocation");
if (pkg_name_buf == NULL) {
fprintf(stderr, "OOM error in native tmp buffer allocation");
return NULL;
}
if (last_slash != NULL) {
strncpy(pkg_name_buf, cname, len);
}