1efea58
From 3800cdbaf04b775b091b4b88a40933a2aa800a90 Mon Sep 17 00:00:00 2001
1efea58
From: Daniel Axtens <dja@axtens.net>
1efea58
Date: Tue, 4 Dec 2018 14:29:42 +1100
1efea58
Subject: [PATCH] Skip 0-length ACL fields
1efea58
1efea58
Currently, it is possible to create an archive that crashes bsdtar
1efea58
with a malformed ACL:
1efea58
1efea58
Program received signal SIGSEGV, Segmentation fault.
1efea58
archive_acl_from_text_l (acl=<optimised out>, text=0x7e2e92 "", want_type=<optimised out>, sc=<optimised out>) at libarchive/archive_acl.c:1726
1efea58
1726				switch (*s) {
1efea58
(gdb) p n
1efea58
$1 = 1
1efea58
(gdb) p field[n]
1efea58
$2 = {start = 0x0, end = 0x0}
1efea58
1efea58
Stop this by checking that the length is not zero before beginning
1efea58
the switch statement.
1efea58
1efea58
I am pretty sure this is the bug mentioned in the qsym paper [1],
1efea58
and I was able to replicate it with a qsym + AFL + afl-rb setup.
1efea58
1efea58
[1] https://www.usenix.org/conference/usenixsecurity18/presentation/yun
1efea58
---
1efea58
 libarchive/archive_acl.c | 5 +++++
1efea58
 1 file changed, 5 insertions(+)
1efea58
1efea58
diff --git a/libarchive/archive_acl.c b/libarchive/archive_acl.c
1efea58
index fe42b9b8..cb23ad88 100644
1efea58
--- a/libarchive/archive_acl.c
1efea58
+++ b/libarchive/archive_acl.c
1efea58
@@ -1711,6 +1711,11 @@ archive_acl_from_text_l(struct archive_acl *acl, const char *text,
1efea58
 			st = field[n].start + 1;
1efea58
 			len = field[n].end - field[n].start;
1efea58
 
1efea58
+			if (len == 0) {
1efea58
+				ret = ARCHIVE_WARN;
1efea58
+				continue;
1efea58
+			}
1efea58
+
1efea58
 			switch (*s) {
1efea58
 			case 'u':
1efea58
 				if (len == 1 || (len == 4
1efea58
-- 
1efea58
2.17.1
1efea58