From 195b605e88209772a4b2bc2e0ef32e610e62feb7 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 29 Jun 2009 11:47:20 +0930 Subject: [PATCH] Fix theoretical problem with 0-length records. By faking them out to length 1, we might go oob. Just fake the malloc. --- ccan/tdb/io.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/ccan/tdb/io.c b/ccan/tdb/io.c index c25f1cb4..d8140fea 100644 --- a/ccan/tdb/io.c +++ b/ccan/tdb/io.c @@ -383,11 +383,7 @@ unsigned char *tdb_alloc_read(struct tdb_context *tdb, tdb_off_t offset, tdb_len unsigned char *buf; /* some systems don't like zero length malloc */ - if (len == 0) { - len = 1; - } - - if (!(buf = (unsigned char *)malloc(len))) { + if (!(buf = (unsigned char *)malloc(len ? len : 1))) { /* Ensure ecode is set for log fn. */ tdb->ecode = TDB_ERR_OOM; TDB_LOG((tdb, TDB_DEBUG_ERROR,"tdb_alloc_read malloc failed len=%d (%s)\n", -- 2.39.2