bspatch: Add a sanity-check for malformed patches.

This patch adds an extra sanity-check for malformed patches. A
corrupted patch should be cached by update_engine before reaching
this step anyway.

BUG=chromium:372525
TEST=emerge-link bsdiff && chroot/build/link/usr/bin/bspatch foo bar malformed_patch
bspatch segfaults without the patch and shows the error message with it.

Change-Id: I8007b41cf3ab6558a99ffd6085e382f1c32f9bdf
Reviewed-on: https://chromium-review.googlesource.com/199377
Tested-by: Alex Deymo <deymo@chromium.org>
Reviewed-by: Jorge Lucangeli Obes <jorgelo@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
diff --git a/bspatch.c b/bspatch.c
index 8d95633..ab77722 100644
--- a/bspatch.c
+++ b/bspatch.c
@@ -187,6 +187,10 @@
 		};
 
 		/* Sanity-check */
+		if ((ctrl[0] < 0) || (ctrl[1] < 0))
+			errx(1,"Corrupt patch\n");
+
+		/* Sanity-check */
 		if(newpos+ctrl[0]>newsize)
 			errx(1,"Corrupt patch\n");