From c09e99f49b5889811055a7e76c8166c2d004353a Mon Sep 17 00:00:00 2001 From: Christine Caulfield Date: Wed, 14 Oct 2020 10:44:40 +0100 Subject: [PATCH 1/2] doxygen2man: Fix a couple of covscan-detected errors --- doxygen2man/cstring.c | 2 +- doxygen2man/doxygen2man.c | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/doxygen2man/cstring.c b/doxygen2man/cstring.c index 48dcbf305..dfb8cec49 100644 --- a/doxygen2man/cstring.c +++ b/doxygen2man/cstring.c @@ -77,7 +77,7 @@ cstring_t cstring_append_chars(cstring_t cstring, const char *newstring) h = (struct cstring_header *)(char *)cstring; h->allocated = new_allocsize; } - strncat(h->the_string, newstring, h->allocated-1); + strncat(h->the_string, newstring, h->allocated - h->used -1); h->used += strlen(newstring); return cstring; } diff --git a/doxygen2man/doxygen2man.c b/doxygen2man/doxygen2man.c index 3069177c0..de73d8680 100644 --- a/doxygen2man/doxygen2man.c +++ b/doxygen2man/doxygen2man.c @@ -498,10 +498,12 @@ static char *allcaps(const char *name) static char buffer[4096] = {'\0'}; size_t i; - for (i=0; i< strlen(name); i++) { - buffer[i] = toupper(name[i]); + if (name) { + for (i=0; i< strlen(name); i++) { + buffer[i] = toupper(name[i]); + } + buffer[strlen(name)] = '\0'; } - buffer[strlen(name)] = '\0'; return buffer; } From ff985507a318f2621b3a29ca96084cc205ce8508 Mon Sep 17 00:00:00 2001 From: Christine Caulfield Date: Mon, 19 Oct 2020 13:11:55 +0100 Subject: [PATCH 2/2] doxygen2man: Check for strings longer than 4096 --- doxygen2man/doxygen2man.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/doxygen2man/doxygen2man.c b/doxygen2man/doxygen2man.c index de73d8680..d794b78e1 100644 --- a/doxygen2man/doxygen2man.c +++ b/doxygen2man/doxygen2man.c @@ -17,6 +17,7 @@ #define _DEFAULT_SOURCE #define _BSD_SOURCE +#define _GNU_SOURCE #define _XOPEN_SOURCE #define _XOPEN_SOURCE_EXTENDED #include @@ -33,6 +34,7 @@ #include #include #include "cstring.h" + /* * This isn't a maximum size, it just defines how long a parameter * type can get before we decide it's not worth lining everything up. @@ -499,10 +501,11 @@ static char *allcaps(const char *name) size_t i; if (name) { - for (i=0; i< strlen(name); i++) { + size_t len = strnlen(name, 4096); + for (i=0; i< len; i++) { buffer[i] = toupper(name[i]); } - buffer[strlen(name)] = '\0'; + buffer[len] = '\0'; } return buffer; }