[Pinfo-devel] r21 - pinfo/trunk/src

Bas Zoetekouw bas at costa.debian.org
Mon Jul 25 16:52:11 UTC 2005


Author: bas
Date: 2005-07-25 16:52:10 +0000 (Mon, 25 Jul 2005)
New Revision: 21

Modified:
   pinfo/trunk/src/mainfunction.c
   pinfo/trunk/src/manual.c
   pinfo/trunk/src/utils.c
   pinfo/trunk/src/utils.h
Log:
The return value of regcom() is now checked for errors.  If a regexp can't be
compiled, show an error message instead of segfaulting.
(fixes Debian bug #222650)


Modified: pinfo/trunk/src/mainfunction.c
===================================================================
--- pinfo/trunk/src/mainfunction.c	2005-07-24 23:13:04 UTC (rev 20)
+++ pinfo/trunk/src/mainfunction.c	2005-07-25 16:52:10 UTC (rev 21)
@@ -546,7 +546,20 @@
 				curs_set(0);
 				noecho();
 				attrset(normal);
-				pinfo_re_comp(token);	/* compile the read token */
+				/* compile the read token */
+				if (pinfo_re_comp(token) != 0)
+				{
+					/* print error message */
+					attrset(bottomline);
+					mymvhline(maxy - 1, 0, ' ', maxx);
+					move(maxy - 1, 0);
+					printw(_("Invalid regular expression;"));
+					printw(" ");
+					printw(_("Press any key to continue..."));
+					getch();
+					goto skip_search;
+					
+				}
 				/* scan for the token in the following lines.  */
 				for (i = pos + 1; i < Lines; i++)
 				{

Modified: pinfo/trunk/src/manual.c
===================================================================
--- pinfo/trunk/src/manual.c	2005-07-24 23:13:04 UTC (rev 20)
+++ pinfo/trunk/src/manual.c	2005-07-25 16:52:10 UTC (rev 21)
@@ -1120,7 +1120,18 @@
 #endif
 				attrset(normal);
 				/* compile regexp expression */
-				pinfo_re_comp(token);
+				if (pinfo_re_comp(token) != 0)
+				{
+					/* print error message */
+					attrset(bottomline);
+					mymvhline(maxy - 1, 0, ' ', maxx);
+					move(maxy - 1, 0);
+					printw(_("Invalid regular expression;"));
+					printw(" ");
+					printw(_("Press any key to continue..."));
+					getch();
+					goto skip_search;
+				}
 				/* and search for it in all subsequential lines */
 				for (i = manualpos + 1; i < ManualLines - 1; i++)
 				{

Modified: pinfo/trunk/src/utils.c
===================================================================
--- pinfo/trunk/src/utils.c	2005-07-24 23:13:04 UTC (rev 20)
+++ pinfo/trunk/src/utils.c	2005-07-25 16:52:10 UTC (rev 21)
@@ -353,7 +353,8 @@
 	select(1, &rdfs, NULL, NULL, NULL);
 }
 
-void
+/* returns 0 on success, 1 on error */
+int
 pinfo_re_comp(char *name)
 {
 #ifdef ___DONT_USE_REGEXP_SEARCH___
@@ -363,6 +364,7 @@
 		pinfo_re_pattern = 0;
 	}
 	pinfo_re_pattern = strdup(name);
+	return 0;
 #else
 	if (pinfo_re_offset == -1)
 	{
@@ -376,7 +378,7 @@
 	{
 		regfree(&h_regexp[pinfo_re_offset]);
 	}
-	regcomp(&h_regexp[pinfo_re_offset], name, REG_ICASE);
+	return regcomp(&h_regexp[pinfo_re_offset], name, REG_ICASE);
 #endif
 }
 

Modified: pinfo/trunk/src/utils.h
===================================================================
--- pinfo/trunk/src/utils.h	2005-07-24 23:13:04 UTC (rev 20)
+++ pinfo/trunk/src/utils.h	2005-07-25 16:52:10 UTC (rev 21)
@@ -13,7 +13,7 @@
 #endif
 
 /* wrappers for re_comp and re_exec */
-void pinfo_re_comp (char *name);
+int pinfo_re_comp (char *name);
 int pinfo_re_exec (char *name);
 
 /* user defined getch, capable of handling ALT keybindings */




More information about the Pinfo-devel mailing list