Program: 80026
Project: 80026
Buggy source:
/** 
 * processCommands reads and processes NetworkServerControlImpl commands sent to the network server over the socket.  The protocol used is 4 bytes 	- String CMD: 2 bytes		- Protocol version 1 byte		- length of locale (0 for default) n bytes - locale 1 byte		- length of codeset (0 for default) n bytes - codeset 1 byte		- command n bytes		- parameters for the command The server returns 4 bytes		- String RPY: for most commands 1 byte		- command result, 0 - OK, 1 - warning, 2 - error if warning or error 1 bytes		- length of message key n bytes		- message key 1 byte		- number of parameters to message {2 bytes		- length of parameter n bytes		- parameter} for each parameter for sysinfo 1 byte		- command result, 0 - OK, 1 - warning, 2 - error if OK  2 bytes		- length of sysinfo n bytes		- sysinfo Note, the 3rd byte of the command must not be 'D0' to distinquish it  from DSS structures. The protocol for the parameters for each command follows: Command: trace <connection id> {on | off} Protocol: 4 bytes		- connection id - connection id of 0 means all sessions 1 byte		- 0 off, 1 on Command: logConnections {on | off} Protocol: 1 byte		- 0 off, 1 on Command: shutdown // DERBY-2109: transmit user credentials for System Privileges check 2 bytes		- length of user name n bytes		- user name 2 bytes		- length of password n bytes		- password Command: sysinfo No parameters Command: dbstart Protocol: 2 bytes		- length of database name n bytes		- database name 2 bytes		- length of boot password n bytes		- boot password  2 bytes		- length of encryption algorithm n bytes		- encryption algorithm 2 bytes		- length of encryption provider n bytes		- encryption provider 2 bytes		- length of user name n bytes		- user name 2 bytes		- length of password n bytes		- password Command: dbshutdown Protocol: 2 bytes		- length of database name n bytes		- database name 2 bytes		- length of user name n bytes		- user name 2 bytes		- length of password n bytes		- password Command: connpool Protocol: 2 bytes		- length of database name, if 0, default for all databases is set n bytes		- database name 2 bytes		- minimum number of connections, if 0, connection pool not used if value is -1 use default 2 bytes		- maximum number of connections, if 0, connections are created as needed, if value is -1 use default Command: maxthreads Protocol: 2 bytes		- maximum number of threads Command: timeslice  Protocol: 4 bytes		- timeslice value Command: tracedirectory Protocol: 2 bytes		- length of directory name n bytes		- directory name Command: test connection Protocol: 2 bytes		- length of database name if 0, just the connection to the network server is tested and user name and  password aren't sent n bytes		- database name 2 bytes		- length of user name (optional) n bytes		- user name 2 bytes		- length of password  (optional) n bytes		- password The calling routine is synchronized so that multiple threads don't clobber each other. This means that configuration commands will be serialized. This shouldn't be a problem since they should be fairly rare.
 * @param reader	input reader for command
 * @param writer output writer for command
 * @param session	session information
 * @exception Throwable	throws an exception if an error occurs
 */
protected synchronized void processCommands(DDMReader reader,DDMWriter writer,Session session) throws Throwable {
  try {
    String protocolStr=reader.readCmdString(4);
    String locale=DEFAULT_LOCALE;
    String codeset=null;
    int version=reader.readNetworkShort();
    if (version <= 0 || version > MAX_ALLOWED_PROTOCOL_VERSION) {
      throw new Throwable(langUtil.getTextMessage("String_Node_Str",version));
    }
    int localeLen=reader.readByte();
    if (localeLen > 0) {
      currentSession=session;
      locale=reader.readCmdString(localeLen);
      session.langUtil=new LocalizedResource(codeset,locale,DRDA_PROP_MESSAGES);
    }
    String notLocalMessage=null;
    int codesetLen=reader.readByte();
    int command=reader.readByte();
    if (command != COMMAND_TESTCONNECTION) {
      try {
        checkAddressIsLocal(session.clientSocket.getInetAddress());
      }
 catch (      Exception e) {
        notLocalMessage=e.getMessage();
      }
    }
    if (notLocalMessage != null) {
      sendMessage(writer,ERROR,notLocalMessage);
      session.langUtil=null;
      currentSession=null;
      return;
    }
switch (command) {
case COMMAND_SHUTDOWN:
      if (version == SHUTDOWN_WITH_CREDENTIAL_PROTOCOL_VERSION) {
        userArg=reader.readCmdString();
        passwordArg=reader.readCmdString();
      }
    try {
      checkShutdownPrivileges();
      sendOK(writer);
      directShutdownInternal();
    }
 catch (    SQLException sqle) {
      sendSQLMessage(writer,sqle,SQLERROR);
      consolePropertyMessage("String_Node_Str",sqle.getMessage());
    }
  break;
case COMMAND_TRACE:
sessionArg=reader.readNetworkInt();
boolean on=(reader.readByte() == 1);
if (setTrace(on)) {
sendOK(writer);
}
 else {
if (sessionArg != 0) sendMessage(writer,ERROR,localizeMessage("String_Node_Str",(session.langUtil == null) ? langUtil : session.langUtil,new String[]{Integer.toString(sessionArg)}));
 else sendMessage(writer,ERROR,localizeMessage("String_Node_Str",null));
}
break;
case COMMAND_TRACEDIRECTORY:
setTraceDirectory(reader.readCmdString());
sendOK(writer);
consolePropertyMessage("String_Node_Str",traceDirectory);
break;
case COMMAND_TESTCONNECTION:
databaseArg=reader.readCmdString();
userArg=reader.readCmdString();
passwordArg=reader.readCmdString();
if (databaseArg != null) connectToDatabase(writer,databaseArg,userArg,passwordArg);
 else sendOK(writer);
break;
case COMMAND_LOGCONNECTIONS:
boolean log=(reader.readByte() == 1);
setLogConnections(log);
sendOK(writer);
consolePropertyMessage("String_Node_Str",(log ? "String_Node_Str" : "String_Node_Str"));
break;
case COMMAND_SYSINFO:
sendSysInfo(writer);
break;
case COMMAND_PROPERTIES:
sendPropInfo(writer);
break;
case COMMAND_RUNTIME_INFO:
sendRuntimeInfo(writer);
break;
case COMMAND_MAXTHREADS:
int max=reader.readNetworkInt();
try {
setMaxThreads(max);
}
 catch (Exception e) {
sendMessage(writer,ERROR,e.getMessage());
return;
}
int newval=getMaxThreads();
sendOKInt(writer,newval);
consolePropertyMessage("String_Node_Str",String.valueOf(newval));
break;
case COMMAND_TIMESLICE:
int timeslice=reader.readNetworkInt();
try {
setTimeSlice(timeslice);
}
 catch (Exception e) {
sendMessage(writer,ERROR,e.getMessage());
return;
}
newval=getTimeSlice();
sendOKInt(writer,newval);
consolePropertyMessage("String_Node_Str",String.valueOf(newval));
break;
}
}
 catch (DRDAProtocolException e) {
consoleExceptionPrintTrace(e);
}
catch (Exception e) {
consoleExceptionPrintTrace(e);
}
 finally {
session.langUtil=null;
currentSession=null;
}
}

Fixed version (ground truth):
/** 
 * processCommands reads and processes NetworkServerControlImpl commands sent to the network server over the socket.  The protocol used is 4 bytes 	- String CMD: 2 bytes		- Protocol version 1 byte		- length of locale (0 for default) n bytes - locale 1 byte		- length of codeset (0 for default) n bytes - codeset 1 byte		- command n bytes		- parameters for the command The server returns 4 bytes		- String RPY: for most commands 1 byte		- command result, 0 - OK, 1 - warning, 2 - error if warning or error 1 bytes		- length of message key n bytes		- message key 1 byte		- number of parameters to message {2 bytes		- length of parameter n bytes		- parameter} for each parameter for sysinfo 1 byte		- command result, 0 - OK, 1 - warning, 2 - error if OK  2 bytes		- length of sysinfo n bytes		- sysinfo Note, the 3rd byte of the command must not be 'D0' to distinquish it  from DSS structures. The protocol for the parameters for each command follows: Command: trace <connection id> {on | off} Protocol: 4 bytes		- connection id - connection id of 0 means all sessions 1 byte		- 0 off, 1 on Command: logConnections {on | off} Protocol: 1 byte		- 0 off, 1 on Command: shutdown // DERBY-2109: transmit user credentials for System Privileges check 2 bytes		- length of user name n bytes		- user name 2 bytes		- length of password n bytes		- password Command: sysinfo No parameters Command: dbstart Protocol: 2 bytes		- length of database name n bytes		- database name 2 bytes		- length of boot password n bytes		- boot password  2 bytes		- length of encryption algorithm n bytes		- encryption algorithm 2 bytes		- length of encryption provider n bytes		- encryption provider 2 bytes		- length of user name n bytes		- user name 2 bytes		- length of password n bytes		- password Command: dbshutdown Protocol: 2 bytes		- length of database name n bytes		- database name 2 bytes		- length of user name n bytes		- user name 2 bytes		- length of password n bytes		- password Command: connpool Protocol: 2 bytes		- length of database name, if 0, default for all databases is set n bytes		- database name 2 bytes		- minimum number of connections, if 0, connection pool not used if value is -1 use default 2 bytes		- maximum number of connections, if 0, connections are created as needed, if value is -1 use default Command: maxthreads Protocol: 2 bytes		- maximum number of threads Command: timeslice  Protocol: 4 bytes		- timeslice value Command: tracedirectory Protocol: 2 bytes		- length of directory name n bytes		- directory name Command: test connection Protocol: 2 bytes		- length of database name if 0, just the connection to the network server is tested and user name and  password aren't sent n bytes		- database name 2 bytes		- length of user name (optional) n bytes		- user name 2 bytes		- length of password  (optional) n bytes		- password The calling routine is synchronized so that multiple threads don't clobber each other. This means that configuration commands will be serialized. This shouldn't be a problem since they should be fairly rare.
 * @param reader	input reader for command
 * @param writer output writer for command
 * @param session	session information
 * @exception Throwable	throws an exception if an error occurs
 */
protected synchronized void processCommands(DDMReader reader,DDMWriter writer,Session session) throws Throwable {
  try {
    String protocolStr=reader.readCmdString(4);
    String locale=DEFAULT_LOCALE;
    String codeset=null;
    int version=reader.readNetworkShort();
    if (version <= 0 || version > MAX_ALLOWED_PROTOCOL_VERSION) {
      throw new Throwable(langUtil.getTextMessage("String_Node_Str",version));
    }
    int localeLen=reader.readByte();
    if (localeLen > 0) {
      currentSession=session;
      locale=reader.readCmdString(localeLen);
      session.langUtil=new LocalizedResource(codeset,locale,DRDA_PROP_MESSAGES);
    }
    String notLocalMessage=null;
    int codesetLen=reader.readByte();
    int command=reader.readByte();
    if (command != COMMAND_TESTCONNECTION) {
      try {
        checkAddressIsLocal(session.clientSocket.getInetAddress());
      }
 catch (      Exception e) {
        notLocalMessage=e.getMessage();
      }
    }
    if (notLocalMessage != null) {
      sendMessage(writer,ERROR,notLocalMessage);
      session.langUtil=null;
      currentSession=null;
      return;
    }
switch (command) {
case COMMAND_SHUTDOWN:
      if (version == SHUTDOWN_WITH_CREDENTIAL_PROTOCOL_VERSION) {
        userArg=reader.readCmdString();
        passwordArg=reader.readCmdString();
      }
    try {
      checkShutdownPrivileges();
      sendOK(writer);
      directShutdownInternal();
    }
 catch (    SQLException sqle) {
      sendSQLMessage(writer,sqle,SQLERROR);
      consolePropertyMessage("String_Node_Str",sqle.getMessage());
    }
  break;
case COMMAND_TRACE:
sessionArg=reader.readNetworkInt();
boolean on=(reader.readByte() == 1);
if (setTrace(on)) {
sendOK(writer);
}
 else {
if (sessionArg != 0) sendMessage(writer,ERROR,localizeMessage("String_Node_Str",(session.langUtil == null) ? langUtil : session.langUtil,new String[]{Integer.toString(sessionArg)}));
 else sendMessage(writer,ERROR,localizeMessage("String_Node_Str",null));
}
break;
case COMMAND_TRACEDIRECTORY:
setTraceDirectory(reader.readCmdString());
sendOK(writer);
consolePropertyMessage("String_Node_Str",traceDirectory);
break;
case COMMAND_TESTCONNECTION:
databaseArg=reader.readCmdString();
userArg=reader.readCmdString();
passwordArg=reader.readCmdString();
if (databaseArg != null) connectToDatabase(writer,databaseArg,userArg,passwordArg);
 else sendOK(writer);
break;
case COMMAND_LOGCONNECTIONS:
boolean log=(reader.readByte() == 1);
setLogConnections(log);
sendOK(writer);
logConnectionsChange(log);
break;
case COMMAND_SYSINFO:
sendSysInfo(writer);
break;
case COMMAND_PROPERTIES:
sendPropInfo(writer);
break;
case COMMAND_RUNTIME_INFO:
sendRuntimeInfo(writer);
break;
case COMMAND_MAXTHREADS:
int max=reader.readNetworkInt();
try {
setMaxThreads(max);
}
 catch (Exception e) {
sendMessage(writer,ERROR,e.getMessage());
return;
}
int newval=getMaxThreads();
sendOKInt(writer,newval);
consolePropertyMessage("String_Node_Str",String.valueOf(newval));
break;
case COMMAND_TIMESLICE:
int timeslice=reader.readNetworkInt();
try {
setTimeSlice(timeslice);
}
 catch (Exception e) {
sendMessage(writer,ERROR,e.getMessage());
return;
}
newval=getTimeSlice();
sendOKInt(writer,newval);
consolePropertyMessage("String_Node_Str",String.valueOf(newval));
break;
}
}
 catch (DRDAProtocolException e) {
consoleExceptionPrintTrace(e);
}
catch (Exception e) {
consoleExceptionPrintTrace(e);
}
 finally {
session.langUtil=null;
currentSession=null;
}
}