[geany/geany] cdabbe: read: Avoid possible NULL dereference in getNthPrevCFromInputFile()

Colomban Wendling git-noreply at xxxxx
Thu Feb 11 14:36:05 UTC 2016


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Sun, 24 Jan 2016 16:29:38 UTC
Commit:      cdabbecd375be45f13b5e4f8c37053c96cd81499
             https://github.com/geany/geany/commit/cdabbecd375be45f13b5e4f8c37053c96cd81499

Log Message:
-----------
read: Avoid possible NULL dereference in getNthPrevCFromInputFile()

Also, don't perform subtractions to check pointer bounds, to avoid
unsigned value wraparound.  This is very unlikely as it would either
mean a very large `nth` value or a very small value for the current
line pointer, but better safe than sorry.


Modified Paths:
--------------
    tagmanager/ctags/read.c

Modified: tagmanager/ctags/read.c
5 lines changed, 3 insertions(+), 2 deletions(-)
===================================================================
@@ -506,9 +506,10 @@ extern int fileGetc (void)
 extern int fileGetNthPrevC (unsigned int nth, int def)
 {
 	const unsigned char *base = (unsigned char *) vStringValue (File.line);
+	const unsigned int offset = File.ungetchIdx + 1 + nth;
 
-	if (File.currentLine - File.ungetchIdx - 1 - nth >= base)
-		return (int) *(File.currentLine - File.ungetchIdx - 1 - nth);
+	if (File.currentLine != NULL && File.currentLine >= base + offset)
+		return (int) *(File.currentLine - offset);
 	else
 		return def;
 }



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list