Apply patch from bug 504342