FreeBSD/contrib/ntp/ntpd/ntp_filegen.c
/*
 * check whether concatenating prefix and basename
 * yields a legal filename
 */
check whether concatenating prefix and basename
yields a legal filename
check whether concatenating prefix and basename yields a legal filename
static int
valid_fileref(
	const char *	dir,
	const char *	fname
	)
{
	const char *p;
	if (NULL == dir || '\0' == dir[0])
		return FALSE;
	if (NULL == fname)
		return FALSE;
#ifdef SYS_WINNT
	if (strchr(fname, '/')) {
		msyslog(LOG_ERR,
			"filegen filenames must not contain '/': %s",
			fname);
		return FALSE;
	}
#endif
	for (p = fname; p != NULL; p = strchr(p, DIR_SEP)) {
		if ('.' == p[0] && '.' == p[1] 
		    && ('\0' == p[2] || DIR_SEP == p[2]))
			return FALSE;
	}
	return TRUE;
}
static int valid_fileref ( const char * dir , const char * fname ) { const char * p ; if ( NULL == dir || ' \0 ' == dir [ 0 ] ) return FALSE ; if ( NULL == fname ) return FALSE ; #ifdef SYS_WINNT if ( strchr ( fname , ' ' ) ) { msyslog ( LOG_ERR , " " , fname ) ; return FALSE ; } #endif for ( p = fname ; p != NULL ; p = strchr ( p , DIR_SEP ) ) { if ( ' ' == p [ 0 ] && ' ' == p [ 1 ] && ( ' \0 ' == p [ 2 ] || DIR_SEP == p [ 2 ] ) ) return FALSE ; } return TRUE ; }
check whether concatenating prefix and basename
 yields a legal filename
check whether concatenating prefix and basename yields a legal filename
/*
	 * dir cannot be changed dynamically
	 * (within the context of filegen)
	 * so just reject basenames containing '..'
	 *
	 * ASSUMPTION:
	 *		file system parts 'below' dir may be
	 *		specified without infringement of security
	 *
	 *		restricting dir to legal values
	 *		has to be ensured by other means
	 * (however, it would be possible to perform some checks here...)
	 */ /*
	 * Just to catch, dumb errors opening up the world...
	 */ /*
	 * Windows treats / equivalent to \, reject any / to ensure
	 * check below for DIR_SEP (\ on windows) are adequate.
	 */