lib/dns/rdata/in_1/naptr_35.c
/*
 * Check the wire format of the Regexp field.
 * Don't allow embeded NUL's.
 */
Check the wire format of the Regexp field.
Don't allow embeded NUL's.
Check the wire format of the Regexp field . Don ' t allow embeded NUL ' s .
static inline isc_result_t
txt_valid_regex(const unsigned char *txt) {
#ifdef HAVE_REGEX_H
	regex_t preg;
	unsigned int regflags = REG_EXTENDED;
	unsigned int nsub = 0;
	char regex[256];
	char *cp;
#endif
	isc_boolean_t flags = ISC_FALSE;
	isc_boolean_t replace = ISC_FALSE;
	unsigned char c;
	unsigned char delim;
	unsigned int len;
	len = *txt++;
	if (len == 0U)
		return (ISC_R_SUCCESS);
	delim = *txt++;
	len--;
	switch (delim) {
	case '0': case '1': case '2': case '3': case '4':
	case '5': case '6': case '7': case '8': case '9':
	case '\\': case 'i': case 0:
		return (DNS_R_SYNTAX);
	}
#ifdef HAVE_REGEX_H
	memset(&preg, 0, sizeof(preg));
	cp = regex;
#endif
	while (len-- > 0) {
		c = *txt++;
		if (c == 0)
			return (DNS_R_SYNTAX);
		if (c == delim && !replace) {
			replace = ISC_TRUE;
			continue;
		} else if (c == delim && !flags) {
			flags = ISC_TRUE;
			continue;
		} else if (c == delim)
			return (DNS_R_SYNTAX);
		if (flags) {
			switch (c) {
			case 'i':
#ifdef HAVE_REGEX_H
				regflags |= REG_ICASE;
#endif
				continue;
			default:
				return (DNS_R_SYNTAX);
			}
		}
#ifdef HAVE_REGEX_H
		if (!replace)
			*cp++ = c;
#endif
		if (c == '\\') {
			if (len == 0)
				return (DNS_R_SYNTAX);
			c = *txt++;
			if (c == 0)
				return (DNS_R_SYNTAX);
			len--;
			if (replace)
				switch (c) {
				case '0': return (DNS_R_SYNTAX);
#ifdef HAVE_REGEX_H
				case '1': if (nsub < 1) nsub = 1; break;
				case '2': if (nsub < 2) nsub = 2; break;
				case '3': if (nsub < 3) nsub = 3; break;
				case '4': if (nsub < 4) nsub = 4; break;
				case '5': if (nsub < 5) nsub = 5; break;
				case '6': if (nsub < 6) nsub = 6; break;
				case '7': if (nsub < 7) nsub = 7; break;
				case '8': if (nsub < 8) nsub = 8; break;
				case '9': if (nsub < 9) nsub = 9; break;
#endif
				}
#ifdef HAVE_REGEX_H
			if (!replace)
				*cp++ = c;
#endif
		}
	}
	if (!flags)
		return (DNS_R_SYNTAX);
#ifdef HAVE_REGEX_H
	*cp = '\0';
	if (regcomp(&preg, regex, regflags))
		return (DNS_R_SYNTAX);
	if (preg.re_nsub < nsub) {
		regfree(&preg);
		return (DNS_R_SYNTAX);
	}
	regfree(&preg);
#endif
	return (ISC_R_SUCCESS);
}
static inline isc_result_t txt_valid_regex ( const unsigned char * txt ) { #ifdef HAVE_REGEX_H regex_t preg ; unsigned int regflags = REG_EXTENDED ; unsigned int nsub = 0 ; char regex [ 256 ] ; char * cp ; #endif isc_boolean_t flags = ISC_FALSE ; isc_boolean_t replace = ISC_FALSE ; unsigned char c ; unsigned char delim ; unsigned int len ; len = * txt ++ ; if ( len == 0U ) return ( ISC_R_SUCCESS ) ; delim = * txt ++ ; len -- ; switch ( delim ) { case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' \\ ' : case ' ' : case 0 : return ( DNS_R_SYNTAX ) ; } #ifdef HAVE_REGEX_H memset ( & preg , 0 , sizeof ( preg ) ) ; cp = regex ; #endif while ( len -- > 0 ) { c = * txt ++ ; if ( c == 0 ) return ( DNS_R_SYNTAX ) ; if ( c == delim && ! replace ) { replace = ISC_TRUE ; continue ; } else if ( c == delim && ! flags ) { flags = ISC_TRUE ; continue ; } else if ( c == delim ) return ( DNS_R_SYNTAX ) ; if ( flags ) { switch ( c ) { case ' ' : #ifdef HAVE_REGEX_H regflags |= REG_ICASE ; #endif continue ; default : return ( DNS_R_SYNTAX ) ; } } #ifdef HAVE_REGEX_H if ( ! replace ) * cp ++ = c ; #endif if ( c == ' \\ ' ) { if ( len == 0 ) return ( DNS_R_SYNTAX ) ; c = * txt ++ ; if ( c == 0 ) return ( DNS_R_SYNTAX ) ; len -- ; if ( replace ) switch ( c ) { case ' ' : return ( DNS_R_SYNTAX ) ; #ifdef HAVE_REGEX_H case ' ' : if ( nsub < 1 ) nsub = 1 ; break ; case ' ' : if ( nsub < 2 ) nsub = 2 ; break ; case ' ' : if ( nsub < 3 ) nsub = 3 ; break ; case ' ' : if ( nsub < 4 ) nsub = 4 ; break ; case ' ' : if ( nsub < 5 ) nsub = 5 ; break ; case ' ' : if ( nsub < 6 ) nsub = 6 ; break ; case ' ' : if ( nsub < 7 ) nsub = 7 ; break ; case ' ' : if ( nsub < 8 ) nsub = 8 ; break ; case ' ' : if ( nsub < 9 ) nsub = 9 ; break ; #endif } #ifdef HAVE_REGEX_H if ( ! replace ) * cp ++ = c ; #endif } } if ( ! flags ) return ( DNS_R_SYNTAX ) ; #ifdef HAVE_REGEX_H * cp = ' \0 ' ; if ( regcomp ( & preg , regex , regflags ) ) return ( DNS_R_SYNTAX ) ; if ( preg . re_nsub < nsub ) { regfree ( & preg ) ; return ( DNS_R_SYNTAX ) ; } regfree ( & preg ) ; #endif return ( ISC_R_SUCCESS ) ; }
Check the wire format of the Regexp field.
Check the wire format of the Regexp field .
/*
	 * Digits, backslash and flags can't be delimiters.
	 */ /*
		 * Flags are not escaped.
		 */ /*
	 * Check that substitutions in the replacement string are consistant
	 * with the regular expression.
	 */