Fix unsafe use of strncpy() and sprintf().