apply fixes from https://code.google.com/p/shellinabox/issues/detail?id=245