src/share/vm/runtime/arguments.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File
*** old/src/share/vm/runtime/arguments.cpp	Wed Sep  4 19:27:24 2013
--- new/src/share/vm/runtime/arguments.cpp	Wed Sep  4 19:27:24 2013

*** 1848,1858 **** --- 1848,1858 ---- if (UseGCLogFileRotation) { if ((Arguments::gc_log_filename() == NULL) || (NumberOfGCLogFiles == 0) || (GCLogFileSize == 0)) { jio_fprintf(defaultStream::output_stream(), ! "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" "where num_of_file > 0 and num_of_size > 0\n" "GC log rotation is turned off\n"); UseGCLogFileRotation = false; } }
*** 1862,1871 **** --- 1862,1907 ---- jio_fprintf(defaultStream::output_stream(), "GCLogFileSize changed to minimum 8K\n"); } } + // This function is called for -Xloggc:<filename>, it can be used + // to check if a given file name(or string) conforms to the following + // specification: + // A valid string only contains "[A-Z][a-z][0-9].-_%[p|t]" + // %p and %t only allowed once. + bool is_filename_valid(const char *file_name) { + const char* p = file_name; + int count_p = 0; + int count_t = 0; + while (*p != '\0') { + if ((*p >= '0' && *p <= '9') || + (*p >= 'A' && *p <= 'Z') || + (*p >= 'a' && *p <= 'z') || + *p == '-' || + *p == '_' || + *p == '.') { + p++; + continue; + } + if (*p == '%') { + if(*(p + 1) == 'p') { + p += 2; + count_p ++; + continue; + } + if (*(p + 1) == 't') { + p += 2; + count_t ++; + continue; + } + } + return false; + } + return count_p < 2 && count_t < 2; + } + // Check consistency of GC selection bool Arguments::check_gc_consistency() { check_gclog_consistency(); bool status = true; // Ensure that the user has not selected conflicting sets
*** 2815,2824 **** --- 2851,2866 ---- } else if (match_option(option, "-Xloggc:", &tail)) { // Redirect GC output to the file. -Xloggc:<filename> // ostream_init_log(), when called will use this filename // to initialize a fileStream. _gc_log_filename = strdup(tail); + if (!is_filename_valid(_gc_log_filename)) { + jio_fprintf(defaultStream::output_stream(), + "Filename can only cantain [A-Z][a-z][0-9]-_.%%[p|t]\n" + "%%p and %%t can only show up once\n" ); + return JNI_EINVAL; + } FLAG_SET_CMDLINE(bool, PrintGC, true); FLAG_SET_CMDLINE(bool, PrintGCTimeStamps, true); // JNI hooks } else if (match_option(option, "-Xcheck", &tail)) {

src/share/vm/runtime/arguments.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File