Small correction to self: when I said "always crash" I meant if it doesn't stop itself by finding a zero byte that happen to be in memory; the exception is a rather obscure exploit scenario where an attacker takes control before you get to that point. But the most common case is of course that it finds a zero which happens to be within a few bytes of the end of the buffer, because zeroes are common.
Comments
Small correction to self: when I said "always crash" I meant if it doesn't stop itself by finding a zero byte that happen to be in memory; the exception is a rather obscure exploit scenario where an attacker takes control before you get to that point. But the most common case is of course that it finds a zero which happens to be within a few bytes of the end of the buffer, because zeroes are common.
Point is, it won't infinite loop.