Basic checks on file to ensure it's an mdb database. bug # 587739

This commit is contained in:
brianb
2004-01-10 21:46:14 +00:00
parent dd534f39dc
commit 8c68edba1f
7 changed files with 28 additions and 9 deletions

View File

@@ -71,6 +71,8 @@ int type;
/* mdb_table_dump(&msysobj); */
table = mdb_read_table(&msysobj);
if (!table) return NULL;
mdb_read_columns(table);
mdb_bind_column(table, 1, parentid);

View File

@@ -106,18 +106,25 @@ MdbFile *f;
fprintf(stderr,"Couldn't open file %s\n",f->filename);
return NULL;
}
f->refs++;
if (!mdb_read_pg(mdb, 0)) {
fprintf(stderr,"Couldn't read first page.\n");
return NULL;
}
if (mdb->pg_buf[0] != 0) {
close(f->fd);
return NULL;
}
f->jet_version = mdb_pg_get_int32(mdb, 0x14);
if (IS_JET4(mdb)) {
mdb->fmt = &MdbJet4Constants;
} else {
} else if (IS_JET3(mdb)) {
mdb->fmt = &MdbJet3Constants;
} else {
fprintf(stderr,"Unknown Jet version.\n");
return NULL;
}
f->refs++;
return mdb;
}
MdbHandle *mdb_open(char *filename)

View File

@@ -55,6 +55,8 @@ int rownum, row_start, row_end;
table = mdb_alloc_tabledef(entry);
mdb_read_pg(mdb, entry->table_pg);
if (mdb->pg_buf[0] != 0x02) return NULL; /* not a valid table def page */
len = mdb_pg_get_int16(mdb,8);
table->num_rows = mdb_pg_get_int32(mdb, fmt->tab_num_rows_offset);