utils: replace sprintf use with snprintf to avoid overflows