[1.7.x] Fixed #22256 -- Replaced bad fallback for missing PATH

Thanks Baptiste Mispelon for the review.
Backport of acee46fc9 from master.