Blame SOURCES/libdb-5.3.21-region-size-check.patch

c7d609
diff -up db-5.3.21/src/env/env_region.c.zero-region db-5.3.21/src/env/env_region.c
c7d609
--- db-5.3.21/src/env/env_region.c.zero-region	2012-05-11 19:57:53.000000000 +0200
c7d609
+++ db-5.3.21/src/env/env_region.c	2017-09-06 08:50:45.310276385 +0200
c7d609
@@ -1060,6 +1060,7 @@ __env_region_attach(env, infop, init, ma
c7d609
 	REGION *rp;
c7d609
 	int ret;
c7d609
 	char buf[sizeof(DB_REGION_FMT) + 20];
c7d609
+	struct stat st;
c7d609
 
c7d609
 	/*
c7d609
 	 * Find or create a REGION structure for this region.  If we create
c7d609
@@ -1090,6 +1091,14 @@ __env_region_attach(env, infop, init, ma
c7d609
 	if ((ret = __env_sys_attach(env, infop, rp)) != 0)
c7d609
 		goto err;
c7d609
 
c7d609
+        /* Check the size of the underlying file */
c7d609
+        if (infop->fhp != NULL && F_ISSET(infop->fhp, DB_FH_OPENED) &&
c7d609
+            infop->fhp->fd != -1 && fstat(infop->fhp->fd, &st) != -1 &&
c7d609
+            st.st_size == 0) {
c7d609
+            ret = DB_RUNRECOVERY;
c7d609
+            goto err;
c7d609
+        }
c7d609
+
c7d609
 	/*
c7d609
 	 * Fault the pages into memory.  Note, do this BEFORE we initialize
c7d609
 	 * anything because we're writing pages in created regions, not just
c7d609
diff -up db-5.3.21/src/os/os_map.c.zero-region db-5.3.21/src/os/os_map.c
c7d609
--- db-5.3.21/src/os/os_map.c.zero-region	2012-05-11 19:57:54.000000000 +0200
c7d609
+++ db-5.3.21/src/os/os_map.c	2017-09-06 08:49:39.144546552 +0200
c7d609
@@ -265,6 +265,9 @@ __os_detach(env, infop, destroy)
c7d609
 	dbenv = env->dbenv;
c7d609
 
c7d609
 	rp = infop->rp;
c7d609
+	/* Do not touch the region information if it no longer exists */
c7d609
+	if (rp == NULL)
c7d609
+	    return EINVAL;
c7d609
 
c7d609
 	/* If the user replaced the unmap call, call through their interface. */
c7d609
 	if (DB_GLOBAL(j_region_unmap) != NULL)