6765546: Wrong sscanf used to parse CompilerOracle command >= 32 characters could lead to crash

Tue, 14 Dec 2010 23:17:00 -0800

author
never
date
Tue, 14 Dec 2010 23:17:00 -0800
changeset 2400
781072b12368
parent 2399
7737fa7ec2b5
child 2401
4042471b7419

6765546: Wrong sscanf used to parse CompilerOracle command >= 32 characters could lead to crash
Reviewed-by: kvn, iveresov

src/share/vm/compiler/compilerOracle.cpp file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/compiler/compilerOracle.cpp	Tue Dec 14 12:44:30 2010 -0800
     1.2 +++ b/src/share/vm/compiler/compilerOracle.cpp	Tue Dec 14 23:17:00 2010 -0800
     1.3 @@ -332,7 +332,7 @@
     1.4           "command_names size mismatch");
     1.5  
     1.6    *bytes_read = 0;
     1.7 -  char command[32];
     1.8 +  char command[33];
     1.9    int result = sscanf(line, "%32[a-z]%n", command, bytes_read);
    1.10    for (uint i = 0; i < ARRAY_SIZE(command_names); i++) {
    1.11      if (strcmp(command, command_names[i]) == 0) {
    1.12 @@ -470,6 +470,12 @@
    1.13    OracleCommand command = parse_command_name(line, &bytes_read);
    1.14    line += bytes_read;
    1.15  
    1.16 +  if (command == UnknownCommand) {
    1.17 +    tty->print_cr("CompilerOracle: unrecognized line");
    1.18 +    tty->print_cr("  \"%s\"", original_line);
    1.19 +    return;
    1.20 +  }
    1.21 +
    1.22    if (command == QuietCommand) {
    1.23      _quiet = true;
    1.24      return;
    1.25 @@ -498,7 +504,7 @@
    1.26      line += bytes_read;
    1.27      // there might be a signature following the method.
    1.28      // signatures always begin with ( so match that by hand
    1.29 -    if (1 == sscanf(line, "%*[ \t](%254[);/" RANGEBASE "]%n", sig + 1, &bytes_read)) {
    1.30 +    if (1 == sscanf(line, "%*[ \t](%254[[);/" RANGEBASE "]%n", sig + 1, &bytes_read)) {
    1.31        sig[0] = '(';
    1.32        line += bytes_read;
    1.33        signature = oopFactory::new_symbol_handle(sig, CHECK);

mercurial