]> git.sur5r.net Git - openldap/blobdiff - clients/tools/ldapsearch.c
ITS#6755 pagedresults loop was accessing a closed FILE*.
[openldap] / clients / tools / ldapsearch.c
index ec3208241b80e138e64ab6a0e337d2d3c026ac08..494898a762f35f7eb5fe97f2768d25c6579090dd 100644 (file)
@@ -918,6 +918,15 @@ main( int argc, char **argv )
        tool_bind( ld );
 
 getNextPage:
+       /* fp may have been closed, need to reopen if code jumps
+        * back here to getNextPage.
+        */
+       if ( !fp && infile ) {
+               if (( fp = fopen( infile, "r" )) == NULL ) {
+                       perror( infile );
+                       return EXIT_FAILURE;
+               }
+       }
        save_nctrls = nctrls;
        i = nctrls;
        if ( nctrls > 0
@@ -1259,6 +1268,7 @@ getNextPage:
                }
                if ( fp != stdin ) {
                        fclose( fp );
+                       fp = NULL;
                }
        }