summaryrefslogtreecommitdiff
path: root/source4/lib/ldb
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2011-03-29 16:31:17 +1100
committerAndrew Tridgell <tridge@samba.org>2011-03-29 08:24:03 +0200
commitbd9b2727ef1cb63630c58afe1bba2f4f93246180 (patch)
tree80411163ca7f4244d70e3886d550632a254a88f7 /source4/lib/ldb
parentdaeb6a02eab5822c557ab167fbc171aebe2ddf05 (diff)
downloadsamba-bd9b2727ef1cb63630c58afe1bba2f4f93246180.tar.gz
samba-bd9b2727ef1cb63630c58afe1bba2f4f93246180.tar.bz2
samba-bd9b2727ef1cb63630c58afe1bba2f4f93246180.zip
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
Diffstat (limited to 'source4/lib/ldb')
-rw-r--r--source4/lib/ldb/tools/ldbedit.c15
-rw-r--r--source4/lib/ldb/tools/ldbmodify.c5
2 files changed, 20 insertions, 0 deletions
diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c
index 36d054e563..aaf6d80352 100644
--- a/source4/lib/ldb/tools/ldbedit.c
+++ b/source4/lib/ldb/tools/ldbedit.c
@@ -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);
diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c
index 1484bbf655..1374765f57 100644
--- a/source4/lib/ldb/tools/ldbmodify.c
+++ b/source4/lib/ldb/tools/ldbmodify.c
@@ -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;
}