Issue 6008 - LDIFReader throws NPE when trying to read an end of stream twice
Summary: LDIFReader throws NPE when trying to read an end of stream twice
Status: UNCONFIRMED
Alias: None
Product: JLDAP
Classification: Unclassified
Component: JLDAP (show other issues)
Version: unspecified
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: OpenLDAP project
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-03-07 20:20 UTC by a8080@hushmail.com
Modified: 2020-03-19 05:43 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description a8080@hushmail.com 2009-03-07 20:20:21 UTC
Full_Name: Art Alliany
Version: CVS HEAD approx 2.4.14
OS: linux
URL: ftp://ftp.openldap.org/incoming/
Submission from: (NULL) (65.102.51.113)


If the end of a LDIF file stream  is reached.  LDIFReader returns a null which
is fine.  The problem is that if the LDIFReader is called again after the end of
stream is reached it throws a NPE as shown below:

java.lang.NullPointerException
	at com.novell.ldap.util.LDIFReader.readRecordFields(LDIFReader.java:333)
	at com.novell.ldap.util.LDIFReader.readMessage(LDIFReader.java:273)

classes in java.io.* return -1 if you invoke them multiple times so invoking
LDIFReader should not throw a null pointer exception if invoked again on a
exhausted stream.

Here is the fix:

I, Art Allisany, hereby place the following modifications to OpenLDAP Software
(and only these modifications) into the public domain. Hence, these
modifications may be freely used and/or redistributed for any purpose with or
without attribution and/or other notice. 

$ diff -u com/novell/ldap/util/LDIFReader.java.old
com/novell/ldap/util/LDIFReader.java.new
--- com/novell/ldap/util/LDIFReader.java.old	2009-03-06 02:30:22.000000000
-0800
+++ com/novell/ldap/util/LDIFReader.java.new	2009-03-06 02:34:29.000000000
-0800
@@ -270,6 +270,12 @@
     public LDAPMessage readMessage()
                 throws IOException, LDAPException
     {
+        if ( this.rFields == null ) { 
+            // end of file has already been reached, this readMessage()
+            // call has been invoked after the end of the 
+            // ldif file has been reached on previous calls to this method
+            return null;
+        }
         readRecordFields();           // read record fields
         if ( this.rFields == null ) { // end of file
             return null;
Comment 1 Howard Chu 2009-03-09 07:41:40 UTC
moved from Incoming to Contrib