Sun, 28 Apr 2013 18:24:04 -0400
8010428: Special -agentpath checks needed with minimal VM to produce proper error message
Reviewed-by: dholmes, alanb, cjplummer, olagneau
Contributed-by: Carlos Lucasius <carlos.lucasius@oracle.com>
src/share/vm/runtime/arguments.cpp | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/vm/runtime/arguments.cpp Wed Apr 24 21:11:02 2013 -0400 1.2 +++ b/src/share/vm/runtime/arguments.cpp Sun Apr 28 18:24:04 2013 -0400 1.3 @@ -2224,6 +2224,55 @@ 1.4 return JNI_OK; 1.5 } 1.6 1.7 +// Checks if name in command-line argument -agent{lib,path}:name[=options] 1.8 +// represents a valid HPROF of JDWP agent. is_path==true denotes that we 1.9 +// are dealing with -agentpath (case where name is a path), otherwise with 1.10 +// -agentlib 1.11 +bool valid_hprof_or_jdwp_agent(char *name, bool is_path) { 1.12 + char *_name; 1.13 + const char *_hprof = "hprof", *_jdwp = "jdwp"; 1.14 + size_t _len_hprof, _len_jdwp, _len_prefix; 1.15 + 1.16 + if (is_path) { 1.17 + if ((_name = strrchr(name, (int) *os::file_separator())) == NULL) { 1.18 + return false; 1.19 + } 1.20 + 1.21 + _name++; // skip past last path separator 1.22 + _len_prefix = strlen(JNI_LIB_PREFIX); 1.23 + 1.24 + if (strncmp(_name, JNI_LIB_PREFIX, _len_prefix) != 0) { 1.25 + return false; 1.26 + } 1.27 + 1.28 + _name += _len_prefix; 1.29 + _len_hprof = strlen(_hprof); 1.30 + _len_jdwp = strlen(_jdwp); 1.31 + 1.32 + if (strncmp(_name, _hprof, _len_hprof) == 0) { 1.33 + _name += _len_hprof; 1.34 + } 1.35 + else if (strncmp(_name, _jdwp, _len_jdwp) == 0) { 1.36 + _name += _len_jdwp; 1.37 + } 1.38 + else { 1.39 + return false; 1.40 + } 1.41 + 1.42 + if (strcmp(_name, JNI_LIB_SUFFIX) != 0) { 1.43 + return false; 1.44 + } 1.45 + 1.46 + return true; 1.47 + } 1.48 + 1.49 + if (strcmp(name, _hprof) == 0 || strcmp(name, _jdwp) == 0) { 1.50 + return true; 1.51 + } 1.52 + 1.53 + return false; 1.54 +} 1.55 + 1.56 jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, 1.57 SysClassPath* scp_p, 1.58 bool* scp_assembly_required_p, 1.59 @@ -2322,7 +2371,7 @@ 1.60 options = strcpy(NEW_C_HEAP_ARRAY(char, strlen(pos + 1) + 1, mtInternal), pos + 1); 1.61 } 1.62 #if !INCLUDE_JVMTI 1.63 - if ((strcmp(name, "hprof") == 0) || (strcmp(name, "jdwp") == 0)) { 1.64 + if (valid_hprof_or_jdwp_agent(name, is_absolute_path)) { 1.65 jio_fprintf(defaultStream::error_stream(), 1.66 "Profiling and debugging agents are not supported in this VM\n"); 1.67 return JNI_ERR;