Fix infinite loop when user/group for -u/-g are invalid.

Fixes #6008