I had some extra spaces and junk in my ssh config and it was causing this part of the code to fail with an out of range error.