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

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