Blame SOURCES/cscope-9-fix-access-beyond-end-of-string.patch

9aacf9
From b3ab5461f1a02aa0a07a6f50bc2fa4da057193d1 Mon Sep 17 00:00:00 2001
9aacf9
From: Dominique <dominique.pelle@gmail.com>
9aacf9
Date: Sun, 8 May 2022 08:27:32 +0200
9aacf9
Subject: [PATCH 1/2] fix: access beyond end of string when search called by
9aacf9
 fails
9aacf9
Content-type: text/plain
9aacf9
9aacf9
findcalledby() returned a string which was not '\0' terminated.
9aacf9
That string is later output with the snprintf %s format which
9aacf9
accessed beyond the end of the string. Bug caused a crash on macOS
9aacf9
with M1 processor and was also causing a crash on Linux too when
9aacf9
building with asan (address sanitizer).
9aacf9
9aacf9
Signed-off-by: Vladis Dronov <vdronov@redhat.com>
9aacf9
---
9aacf9
 src/find.c | 12 ++++++------
9aacf9
 1 file changed, 6 insertions(+), 6 deletions(-)
9aacf9
9aacf9
diff --git a/src/find.c b/src/find.c
9aacf9
index d7a66f0..e8f1141 100644
9aacf9
--- a/src/find.c
9aacf9
+++ b/src/find.c
9aacf9
@@ -1044,7 +1044,7 @@ char *
9aacf9
 findcalledby(char *pattern)
9aacf9
 {
9aacf9
 	char	file[PATHLEN + 1];	/* source file name */
9aacf9
-	static char found_caller = 'n'; /* seen calling function? */
9aacf9
+	static char found_caller[2] = "n"; /* seen calling function? */
9aacf9
 	BOOL	macro = NO;
9aacf9
 
9aacf9
 	if (invertedindex == YES) {
9aacf9
@@ -1057,12 +1057,12 @@ findcalledby(char *pattern)
9aacf9
 			case FCNDEF:
9aacf9
 				if (dbseek(p->lineoffset) != -1 &&
9aacf9
 				    scanpast('\t') != NULL) {	/* skip def */
9aacf9
-					found_caller = 'y';
9aacf9
+					found_caller[0] = 'y';
9aacf9
 					findcalledbysub(srcfiles[p->fileindex], macro);
9aacf9
 				}
9aacf9
 			}
9aacf9
 		}
9aacf9
-		return(&found_caller);
9aacf9
+		return(&found_caller[0]);
9aacf9
 	}
9aacf9
 	/* find the function definition(s) */
9aacf9
 	while (scanpast('\t') != NULL) {
9aacf9
@@ -1072,7 +1072,7 @@ findcalledby(char *pattern)
9aacf9
 			skiprefchar();	/* save file name */
9aacf9
 			fetch_string_from_dbase(file, sizeof(file));
9aacf9
 			if (*file == '\0') {	/* if end of symbols */
9aacf9
-				return(&found_caller);
9aacf9
+				return(&found_caller[0]);
9aacf9
 			}
9aacf9
 			progress("Search", searchcount, nsrcfiles);
9aacf9
 			break;
9aacf9
@@ -1087,14 +1087,14 @@ findcalledby(char *pattern)
9aacf9
 		case FCNDEF:
9aacf9
 			skiprefchar();	/* match name to pattern */
9aacf9
 			if (match()) {
9aacf9
-				found_caller = 'y';
9aacf9
+				found_caller[0] = 'y';
9aacf9
 				findcalledbysub(file, macro);
9aacf9
 			}
9aacf9
 			break;
9aacf9
 		}
9aacf9
 	}
9aacf9
 
9aacf9
-	return (&found_caller);
9aacf9
+	return (&found_caller[0]);
9aacf9
 }
9aacf9
 
9aacf9
 /* find this term, which can be a regular expression */
9aacf9
-- 
9aacf9
2.37.3
9aacf9