Fix potential buffer overflow in entry_to_env