1.1 --- a/src/share/vm/runtime/arguments.cpp Mon Sep 16 12:43:34 2013 -0700 1.2 +++ b/src/share/vm/runtime/arguments.cpp Mon Sep 16 15:35:04 2013 -0700 1.3 @@ -1839,7 +1839,7 @@ 1.4 (NumberOfGCLogFiles == 0) || 1.5 (GCLogFileSize == 0)) { 1.6 jio_fprintf(defaultStream::output_stream(), 1.7 - "To enable GC log rotation, use -Xloggc:<filename> -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=<num_of_files> -XX:GCLogFileSize=<num_of_size>\n" 1.8 + "To enable GC log rotation, use -Xloggc:<filename> -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=<num_of_files> -XX:GCLogFileSize=<num_of_size>[k|K|m|M|g|G]\n" 1.9 "where num_of_file > 0 and num_of_size > 0\n" 1.10 "GC log rotation is turned off\n"); 1.11 UseGCLogFileRotation = false; 1.12 @@ -1853,6 +1853,51 @@ 1.13 } 1.14 } 1.15 1.16 +// This function is called for -Xloggc:<filename>, it can be used 1.17 +// to check if a given file name(or string) conforms to the following 1.18 +// specification: 1.19 +// A valid string only contains "[A-Z][a-z][0-9].-_%[p|t]" 1.20 +// %p and %t only allowed once. We only limit usage of filename not path 1.21 +bool is_filename_valid(const char *file_name) { 1.22 + const char* p = file_name; 1.23 + char file_sep = os::file_separator()[0]; 1.24 + const char* cp; 1.25 + // skip prefix path 1.26 + for (cp = file_name; *cp != '\0'; cp++) { 1.27 + if (*cp == '/' || *cp == file_sep) { 1.28 + p = cp + 1; 1.29 + } 1.30 + } 1.31 + 1.32 + int count_p = 0; 1.33 + int count_t = 0; 1.34 + while (*p != '\0') { 1.35 + if ((*p >= '0' && *p <= '9') || 1.36 + (*p >= 'A' && *p <= 'Z') || 1.37 + (*p >= 'a' && *p <= 'z') || 1.38 + *p == '-' || 1.39 + *p == '_' || 1.40 + *p == '.') { 1.41 + p++; 1.42 + continue; 1.43 + } 1.44 + if (*p == '%') { 1.45 + if(*(p + 1) == 'p') { 1.46 + p += 2; 1.47 + count_p ++; 1.48 + continue; 1.49 + } 1.50 + if (*(p + 1) == 't') { 1.51 + p += 2; 1.52 + count_t ++; 1.53 + continue; 1.54 + } 1.55 + } 1.56 + return false; 1.57 + } 1.58 + return count_p < 2 && count_t < 2; 1.59 +} 1.60 + 1.61 // Check consistency of GC selection 1.62 bool Arguments::check_gc_consistency() { 1.63 check_gclog_consistency(); 1.64 @@ -2806,6 +2851,13 @@ 1.65 // ostream_init_log(), when called will use this filename 1.66 // to initialize a fileStream. 1.67 _gc_log_filename = strdup(tail); 1.68 + if (!is_filename_valid(_gc_log_filename)) { 1.69 + jio_fprintf(defaultStream::output_stream(), 1.70 + "Invalid file name for use with -Xloggc: Filename can only contain the " 1.71 + "characters [A-Z][a-z][0-9]-_.%%[p|t] but it has been %s\n" 1.72 + "Note %%p or %%t can only be used once\n", _gc_log_filename); 1.73 + return JNI_EINVAL; 1.74 + } 1.75 FLAG_SET_CMDLINE(bool, PrintGC, true); 1.76 FLAG_SET_CMDLINE(bool, PrintGCTimeStamps, true); 1.77