1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-08 21:18:16 +03:00

tdb: Do not pass non–null‐terminated strings to strcmp() (CID 1449485)

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Joseph Sutton 2023-10-06 13:54:02 +13:00 committed by Andrew Bartlett
parent 8f4aa3508c
commit 757cd49b84

View File

@ -513,7 +513,13 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td
errno = 0;
if (read(tdb->fd, &header, sizeof(header)) != sizeof(header)
|| strcmp(header.magic_food, TDB_MAGIC_FOOD) != 0) {
/*
* Call strncmp() rather than strcmp() in case header.magic_food is
* not zeroterminated. Were still checking the full string for
* equality, as tdb_header::magic_food is larger than
* TDB_MAGIC_FOOD.
*/
|| strncmp(header.magic_food, TDB_MAGIC_FOOD, sizeof(header.magic_food)) != 0) {
if (!(open_flags & O_CREAT) ||
tdb_new_database(tdb, &header, hash_size) == -1) {
if (errno == 0) {