bug-classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug classpath/24191] Uninitialized output buffer in javax.crypto.Cipher


From: monoman at gmail dot com
Subject: [Bug classpath/24191] Uninitialized output buffer in javax.crypto.CipherOutputStream produces NullPointerException
Date: 31 Jan 2007 20:29:43 -0000


------- Comment #4 from monoman at gmail dot com  2007-01-31 20:29 -------
The previous patch is outdated, now the source for this class is a lot slimmer.
but still contains a problem:

public void write(byte[] buf, int off, int len)

tries to write bytes to the internal stream returned from the cipher.update
call always, but it is valid for the cipher to return null (the ones I need
from BouncyCastle do that).

Here is how I corrected it:

       /**
        * Write a portion of a byte array to the output stream.
        * 
        * @param buf The next bytes.
        * @param off The offset in the byte array to start.
        * @param len The number of bytes to write.
        * @throws IOException If an I/O error occurs, or if the underlying
cipher is
        *           not in the correct state to transform data.
        */
       public void write(byte[] buf, int off, int len)
               throws IOException
       {
               byte[] ciphered = cipher.update(buf, off, len);
               if (ciphered != null)
                       out.write(ciphered);
       }


Formatting follows my preferences that is why I didn't cook a patch.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24191





reply via email to

[Prev in Thread] Current Thread [Next in Thread]