Buffer write operations that do not control the length of data written may overflow. Fix by replacing sprintf() with snprintf().