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

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