aboutsummaryrefslogtreecommitdiffstats
path: root/FICS/utils.c
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2024-07-07 12:54:02 +0200
committerMarkus Uhlin <markus@nifty-networks.net>2024-07-07 12:54:02 +0200
commit6b88b740f6b63731064e1d5267c057a6a86e7cf6 (patch)
tree04e855cb60baccdcb9f0530ee81cd25bafa0303a /FICS/utils.c
parent6715f5fcade7dcff9d74b2a24c88d99b8bd03a30 (diff)
Added parameter 'size' to psprintf_highlight() and replaced unbounded string handling functions
Diffstat (limited to 'FICS/utils.c')
-rw-r--r--FICS/utils.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/FICS/utils.c b/FICS/utils.c
index e81781f..29fe60c 100644
--- a/FICS/utils.c
+++ b/FICS/utils.c
@@ -315,35 +315,37 @@ pprintf_highlight(int p, char *format, ...)
}
PRIVATE void
-sprintf_dohightlight(int p, char *s)
+sprintf_dohightlight(int p, char *s, size_t size)
{
if (parray[p].highlight & 0x01)
- strcat(s, "\033[7m");
+ strlcat(s, "\033[7m", size);
if (parray[p].highlight & 0x02)
- strcat(s, "\033[1m");
+ strlcat(s, "\033[1m", size);
if (parray[p].highlight & 0x04)
- strcat(s, "\033[4m");
+ strlcat(s, "\033[4m", size);
if (parray[p].highlight & 0x08)
- strcat(s, "\033[2m");
+ strlcat(s, "\033[2m", size);
}
PUBLIC int
-psprintf_highlight(int p, char *s, char *format, ...)
+psprintf_highlight(int p, char *s, size_t size, char *format, ...)
{
int retval;
va_list ap;
if (parray[p].highlight) {
- sprintf_dohightlight(p, s);
+ char tmp[1000] = { '\0' };
va_start(ap, format);
- retval = vsprintf(s + strlen(s), format, ap);
+ retval = vsnprintf(tmp, sizeof tmp, format, ap);
va_end(ap);
- strcat(s, "\033[0m");
+ sprintf_dohightlight(p, s, size);
+ strlcat(s, tmp, size);
+ strlcat(s, "\033[0m", size);
} else {
va_start(ap, format);
- retval = vsprintf(s, format, ap);
+ retval = vsnprintf(s, size, format, ap);
va_end(ap);
}