mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

david_page
03.15.2007 b75f522e223fcee55e9e474bf691f48d54703f3f
Issue [1395] NullPointerException raised by ldapsearch when prompt for bind passwd

When "-w -" is passed to a command-line tool such as ldapsearch, the tool requests the bind password from standard input. OpenDS on Java 6 uses java.io.Console.readPassword method. For prior releases a utility method org.opends.server.util.PasswordReader.readPasswordUsingBackspaces is used, and this routine returns a char[] with the user-supplied password, which is used to initialize a String. In the case no password was supplied (i.e., the user just presses return at the prompt), the routine returns null, which results in an exception. This change returns char[0] in the case of an empty password, which mimics the behavior of the Java 6 java.io.Console.readPassword, and eliminates the exception.
2 files modified
13 ■■■■■ changed files
opendj-sdk/opends/src/server/org/opends/server/tools/LDAPSearch.java 3 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/util/PasswordReader.java 10 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/tools/LDAPSearch.java
@@ -1099,7 +1099,8 @@
        err.println(wrapText(ex.getMessage(), MAX_LINE_WIDTH));
        return 1;
      }
    } else if(bindPasswordValue == null)
    }
    else if(bindPasswordValue == null)
    {
      // Read from file if it exists.
      bindPasswordValue = bindPasswordFile.getValue();
opendj-sdk/opends/src/server/org/opends/server/util/PasswordReader.java
@@ -210,17 +210,13 @@
        if ((charRead == -1) || (charRead == '\n'))
        {
          // This is the end of the value.
          if (pos == 0)
          pwChars = new char[pos];
          if (0 < pos)
          {
            return null;
          }
          else
          {
            pwChars = new char[pos];
            System.arraycopy(pwBuffer, 0, pwChars, 0, pos);
            Arrays.fill(pwBuffer, '\u0000');
            return pwChars;
          }
          return pwChars;
        }
        else if (charRead == '\r')
        {