From 21ea1dbb50176a89e7f456f9b31220ff3097fdf2 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 27 May 2014 16:25:43 +0200 Subject: use free() instead of delete() when realloc is used ContentsExtract::~ContentsExtract() needs to use free() because Data got allocated via realloc() Reported-By: clang -fsanitize=address -fno-omit-frame-pointer --- ftparchive/cachedb.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'ftparchive/cachedb.cc') diff --git a/ftparchive/cachedb.cc b/ftparchive/cachedb.cc index e56deae1e..12eac20d8 100644 --- a/ftparchive/cachedb.cc +++ b/ftparchive/cachedb.cc @@ -32,6 +32,19 @@ #include /*}}}*/ +CacheDB::CacheDB(std::string const &DB) + : Dbp(0), Fd(NULL), DebFile(0) +{ + TmpKey[0]='\0'; + ReadyDB(DB); +}; + +CacheDB::~CacheDB() +{ + ReadyDB(); + delete DebFile; +}; + // CacheDB::ReadyDB - Ready the DB2 /*{{{*/ // --------------------------------------------------------------------- /* This opens the DB2 file for caching package information */ -- cgit v1.2.3 From 243b2a381f4a12939d91084ecf100ee6d3dcb007 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 4 Jun 2014 12:39:36 +0200 Subject: Add compat mode for old (32bit FileSize) CacheDB (LP: #1274466) --- ftparchive/cachedb.cc | 69 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 10 deletions(-) (limited to 'ftparchive/cachedb.cc') diff --git a/ftparchive/cachedb.cc b/ftparchive/cachedb.cc index 12eac20d8..0901492f7 100644 --- a/ftparchive/cachedb.cc +++ b/ftparchive/cachedb.cc @@ -99,7 +99,7 @@ bool CacheDB::ReadyDB(std::string const &DB) return _error->Error(_("Unable to open DB file %s: %s"),DB.c_str(), db_strerror(err)); } } - + DBFile = DB; DBLoaded = true; return true; @@ -185,6 +185,45 @@ bool CacheDB::GetFileStat(bool const &doStat) CurStat.mtime = htonl(St.st_mtime); CurStat.Flags |= FlSize; + return true; +} + /*}}}*/ +// CacheDB::GetCurStatCompatOldFormat /*{{{*/ +// --------------------------------------------------------------------- +/* Read the old (32bit FileSize) StateStore format from disk */ +bool CacheDB::GetCurStatCompatOldFormat() +{ + InitQueryStats(); + Data.data = &CurStatOldFormat; + Data.flags = DB_DBT_USERMEM; + Data.ulen = sizeof(CurStatOldFormat); + if (Get() == false) + { + CurStat.Flags = 0; + } else { + CurStat.Flags = CurStatOldFormat.Flags; + CurStat.mtime = CurStatOldFormat.mtime; + CurStat.FileSize = CurStatOldFormat.FileSize; + memcpy(CurStat.MD5, CurStatOldFormat.MD5, sizeof(CurStat.MD5)); + memcpy(CurStat.SHA1, CurStatOldFormat.SHA1, sizeof(CurStat.SHA1)); + memcpy(CurStat.SHA256, CurStatOldFormat.SHA256, sizeof(CurStat.SHA256)); + } + return true; +} + /*}}}*/ +// CacheDB::GetCurStatCompatOldFormat /*{{{*/ +// --------------------------------------------------------------------- +/* Read the new (64bit FileSize) StateStore format from disk */ +bool CacheDB::GetCurStatCompatNewFormat() +{ + InitQueryStats(); + Data.data = &CurStat; + Data.flags = DB_DBT_USERMEM; + Data.ulen = sizeof(CurStat); + if (Get() == false) + { + CurStat.Flags = 0; + } return true; } /*}}}*/ @@ -198,19 +237,29 @@ bool CacheDB::GetCurStat() if (DBLoaded) { - /* First see if there is anything about it - in the database */ - - /* Get the flags (and mtime) */ + // do a first query to just get the size of the data on disk InitQueryStats(); - // Ensure alignment of the returned structure Data.data = &CurStat; - Data.ulen = sizeof(CurStat); Data.flags = DB_DBT_USERMEM; - if (Get() == false) + Data.ulen = 0; + Get(); + + if (Data.size == 0) { - CurStat.Flags = 0; - } + // nothing needs to be done, we just have not data for this deb + } + // check if the record is written in the old format (32bit filesize) + else if(Data.size == sizeof(CurStatOldFormat)) + { + GetCurStatCompatOldFormat(); + } + else if(Data.size == sizeof(CurStat)) + { + GetCurStatCompatNewFormat(); + } else { + return _error->Error("Cache record size mismatch (%ul)", Data.size); + } + CurStat.Flags = ntohl(CurStat.Flags); CurStat.FileSize = ntohl(CurStat.FileSize); } -- cgit v1.2.3