Thanks Kit Sunde for the report and Brian Holdefehr for the initial patch. Backport of 6ed6a18a0 from master.