Skip to content
Snippets Groups Projects
Commit d6b3ad8e authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Fix potential buffer overflow and NULL pointer deref in expand_atcodes()

parent f9dc46b7
No related branches found
No related tags found
No related merge requests found
...@@ -2195,7 +2195,7 @@ const char* sbbs_t::atcode(const char* sp, char* str, size_t maxlen, int* pmode, ...@@ -2195,7 +2195,7 @@ const char* sbbs_t::atcode(const char* sp, char* str, size_t maxlen, int* pmode,
char* sbbs_t::expand_atcodes(const char* src, char* buf, size_t size) char* sbbs_t::expand_atcodes(const char* src, char* buf, size_t size)
{ {
char* dst = buf; char* dst = buf;
char* end = dst + size; char* end = dst + (size - 1);
while (*src != '\0' && dst < end) { while (*src != '\0' && dst < end) {
if (*src == '@') { if (*src == '@') {
...@@ -2207,13 +2207,17 @@ char* sbbs_t::expand_atcodes(const char* src, char* buf, size_t size) ...@@ -2207,13 +2207,17 @@ char* sbbs_t::expand_atcodes(const char* src, char* buf, size_t size)
char tmp[128]; char tmp[128];
*at = '\0'; *at = '\0';
src += strlen(str) + 2; src += strlen(str) + 2;
dst += strlcpy(dst, atcode(str, tmp, sizeof tmp, NULL, false, NULL), end - dst); const char* p = atcode(str, tmp, sizeof tmp, NULL, false, NULL);
if(p != NULL)
dst += strlcpy(dst, p, end - dst);
continue; continue;
} }
} }
*(dst++) = *(src++); *(dst++) = *(src++);
} }
if(dst > end)
dst = end;
*dst = '\0'; *dst = '\0';
return buf; return buf;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment