libtar: Fix restore of e4crypt policies

Change-Id: I457356069330c38299fd326181c1c88b12a08dbd
diff --git a/libtar/block.c b/libtar/block.c
index a94ba44..8b22059 100644
--- a/libtar/block.c
+++ b/libtar/block.c
@@ -347,11 +347,13 @@
 			{
 				start += E4CRYPT_TAG_LEN;
 				char *end = strchr(start, '\n');
+				if(!end)
+					end = strchr(start, '\0');
 				if(end)
 				{
-				    t->th_buf.e4crypt_policy = strndup(start, end-start);
+					t->th_buf.e4crypt_policy = strndup(start, end-start);
 #ifdef DEBUG
-				    printf("    th_read(): E4Crypt policy detected: %s\n", t->th_buf.e4crypt_policy);
+					printf("    th_read(): E4Crypt policy detected: %s\n", t->th_buf.e4crypt_policy);
 #endif
 				}
 			}
@@ -563,7 +565,7 @@
 #endif
 		/* setup size - EXT header has format "*size of this whole tag as ascii numbers* *space* *content* *newline* */
 		//                                                       size   newline
-		sz = E4CRYPT_TAG_LEN + EXT4_KEY_DESCRIPTOR_HEX + 3  +    1;
+		sz = E4CRYPT_TAG_LEN + strlen(t->th_buf.e4crypt_policy) + 3  +    1;
 
 		if(sz >= 100) // another ascci digit for size
 			++sz;