mirror of
				https://github.com/postgres/postgres.git
				synced 2025-10-30 00:04:49 -04:00 
			
		
		
		
	Our interface code for Spencer's regexp package was checking for regexp
error conditions during regexp compile, but not during regexp execution; any sort of "can't happen" errors would be treated as no-match instead of being reported as they should be. Noticed while trying to duplicate a reported Tcl bug.
This commit is contained in:
		
							parent
							
								
									cf796cc702
								
							
						
					
					
						commit
						236404fcd1
					
				| @ -8,7 +8,7 @@ | ||||
|  * | ||||
|  * | ||||
|  * IDENTIFICATION | ||||
|  *	  $PostgreSQL: pgsql/src/backend/utils/adt/regexp.c,v 1.54 2004/08/29 04:12:52 momjian Exp $ | ||||
|  *	  $PostgreSQL: pgsql/src/backend/utils/adt/regexp.c,v 1.55 2004/11/24 22:44:07 tgl Exp $ | ||||
|  * | ||||
|  *		Alistair Crooks added the code for the regex caching | ||||
|  *		agc - cached the regular expressions used - there's a good chance | ||||
| @ -107,6 +107,7 @@ RE_compile_and_execute(text *text_re, unsigned char *dat, int dat_len, | ||||
| 	int			regcomp_result; | ||||
| 	int			regexec_result; | ||||
| 	cached_re_str re_temp; | ||||
| 	char		errMsg[100]; | ||||
| 
 | ||||
| 	/* Convert data string to wide characters */ | ||||
| 	data = (pg_wchar *) palloc((dat_len + 1) * sizeof(pg_wchar)); | ||||
| @ -144,7 +145,17 @@ RE_compile_and_execute(text *text_re, unsigned char *dat, int dat_len, | ||||
| 
 | ||||
| 			pfree(data); | ||||
| 
 | ||||
| 			return (regexec_result == 0); | ||||
| 			if (regexec_result != REG_OKAY && regexec_result != REG_NOMATCH) | ||||
| 			{ | ||||
| 				/* re failed??? */ | ||||
| 				pg_regerror(regexec_result, &re_array[0].cre_re, | ||||
| 							errMsg, sizeof(errMsg)); | ||||
| 				ereport(ERROR, | ||||
| 						(errcode(ERRCODE_INVALID_REGULAR_EXPRESSION), | ||||
| 						 errmsg("regular expression failed: %s", errMsg))); | ||||
| 			} | ||||
| 
 | ||||
| 			return (regexec_result == REG_OKAY); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| @ -166,11 +177,9 @@ RE_compile_and_execute(text *text_re, unsigned char *dat, int dat_len, | ||||
| 
 | ||||
| 	pfree(pattern); | ||||
| 
 | ||||
| 	if (regcomp_result != 0) | ||||
| 	if (regcomp_result != REG_OKAY) | ||||
| 	{ | ||||
| 		/* re didn't compile */ | ||||
| 		char		errMsg[100]; | ||||
| 
 | ||||
| 		pg_regerror(regcomp_result, &re_temp.cre_re, errMsg, sizeof(errMsg)); | ||||
| 		/* XXX should we pg_regfree here? */ | ||||
| 		ereport(ERROR, | ||||
| @ -222,7 +231,17 @@ RE_compile_and_execute(text *text_re, unsigned char *dat, int dat_len, | ||||
| 
 | ||||
| 	pfree(data); | ||||
| 
 | ||||
| 	return (regexec_result == 0); | ||||
| 	if (regexec_result != REG_OKAY && regexec_result != REG_NOMATCH) | ||||
| 	{ | ||||
| 		/* re failed??? */ | ||||
| 		pg_regerror(regexec_result, &re_array[0].cre_re, | ||||
| 					errMsg, sizeof(errMsg)); | ||||
| 		ereport(ERROR, | ||||
| 				(errcode(ERRCODE_INVALID_REGULAR_EXPRESSION), | ||||
| 				 errmsg("regular expression failed: %s", errMsg))); | ||||
| 	} | ||||
| 
 | ||||
| 	return (regexec_result == REG_OKAY); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user