Created attachment 211703 [details]
Support glibc builds
I would like to add the attached series of patches to unzip:
1. glibc support, since some people on libarchive's GitHub page is showing interest in this replacement util.
2. passsphrase support, both in the unsafe command-line entry form (-P) and in the safe getpassphrase(3) form.
3. minor edit to the manpage, just to remind people that we can decompress fancy ZIPX archives if libarchive can.
I thought about adding the filename iconv stuff from info-zip's unzip beta 6.10b, but doing stuff like iconv_open is a bit too much for me now. It *is* a nice feature though, at least according to the Linux users who came up with unzip-iconv in the first place. I might just add it sometime.
The patch is based against FreeBSD GitHub src tree. The last commit in usr.bin/unzip should be 7551d83.
Created attachment 211704 [details]
Add passphrase support
Created attachment 211705 [details]
Mention ZIPX in unzip(1)
The 'support glibc' and 'mention zipx' patches looks alright, but I think you forgot to free passphrase_buf in 'add passphrase' patch.
Created attachment 211738 [details]
Add passphrase support (v2)
Oops! Here is the patch with the free() added.
Expect a passphrase v3 -- it simply doesn't make sense to free in main() when the only cause of malloc() is planted by unzip().
You might want to open this at https://reviews.freebsd.org so it's easier to comment on the code.
Created attachment 211753 [details]
Add passphrase support (v3)
Created attachment 212674 [details]
Add passphrase support
It seems that unzip fails to build with the last passphrase support patch. I fixed it a little, please check it out.
+ memset(passphrase_buf, 0, PPBUFF_SIZE);
This should probably be using explicit_bzero() to prevent the compiler from optimizing it away.
tar(1) has the same issue.
The explicit_bzero(3) is not portable. So it can't be used in libarchive and it's also absent in NetBSD, which is (still ?) upstream for our unzip.
What about memset_s(), which is in C11?
Looks like NetBSD wants explicit_memset(), which also isn't portable.
readpassphrase() in the same patch is no more portable than explicit_bzero(), so you should just use explicit_bzero.
Yes, memset_s() should work.
The libarchive's cpio and bsdtar use portable version from libarchive_fe if necessary (see use.bin/tar/Makefile). I left readpassphrase() because Free/Open/NetBSD have it. Can be easily changed back to lafe_readpassphrase().