1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-12 09:18:10 +03:00

ldb: detect eof on ldif files

use feof() to detect parsing errors in ldif files

Autobuild-User: Andrew Tridgell <tridge@samba.org>
Autobuild-Date: Tue Mar 29 08:24:04 CEST 2011 on sn-devel-104
This commit is contained in:
Andrew Tridgell 2011-03-29 16:31:17 +11:00
parent daeb6a02ea
commit bd9b2727ef
2 changed files with 20 additions and 0 deletions

View File

@ -281,6 +281,21 @@ static int do_edit(struct ldb_context *ldb, struct ldb_message **msgs1,
msgs2[count2++] = ldif->msg;
}
/* the feof() test works here, even for the last line of the
* file, as we parse ldif files character by character, and
* feof() is only true if we have failed to read a character
* from the file. So if the last line is bad, we don't get
* feof() set, so we know the record was bad. Only if we
* attempt to go to the next record will we get feof() and
* thus consider that the ldif has ended without errors
*/
if (!feof(f)) {
fprintf(stderr, "Error parsing ldif - aborting\n");
fclose(f);
unlink(file_template);
return -1;
}
fclose(f);
unlink(file_template);

View File

@ -87,6 +87,11 @@ static int process_file(struct ldb_context *ldb, FILE *f, unsigned int *count)
ldb_ldif_read_free(ldb, ldif);
}
if (!feof(f)) {
fprintf(stderr, "Failed to parse ldif\n");
return -1;
}
return ret;
}