Buffer overflow can occur when an application accepts data more than the space it has for it. It will cause the data to overflow the container which is usually the memory. Buffer overflow can be very dangerous because it can end up with command execution attacks.
Always check the size of the input before processing it. Do not process inputs with a length greater than what your application can handle.