strvalid.c revision 90819
190819Srwatson/*-
290819Srwatson * Copyright (c) 2002 Networks Associates Technologies, Inc.
390819Srwatson * All rights reserved.
490819Srwatson *
590819Srwatson * This software was developed for the FreeBSD Project by NAI Labs,
690819Srwatson * the Security Research Division of Network Associates, Inc. under
790819Srwatson * DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA
890819Srwatson * CHATS research program.
990819Srwatson *
1090819Srwatson * Redistribution and use in source and binary forms, with or without
1190819Srwatson * modification, are permitted provided that the following conditions
1290819Srwatson * are met:
1390819Srwatson * 1. Redistributions of source code must retain the above copyright
1490819Srwatson *    notice, this list of conditions and the following disclaimer.
1590819Srwatson * 2. Redistributions in binary form must reproduce the above copyright
1690819Srwatson *    notice, this list of conditions and the following disclaimer in the
1790819Srwatson *    documentation and/or other materials provided with the distribution.
1890819Srwatson * 3. The names of the authors may not be used to endorse or promote
1990819Srwatson *    products derived from this software without specific prior written
2090819Srwatson *    permission.
2190819Srwatson *
2290819Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2390819Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2490819Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2590819Srwatson * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2690819Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2790819Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2890819Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2990819Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3090819Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3190819Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3290819Srwatson * SUCH DAMAGE.
3390819Srwatson *
3490819Srwatson * $FreeBSD: head/sys/libkern/strvalid.c 90819 2002-02-18 00:37:03Z rwatson $
3590819Srwatson */
3690819Srwatson
3790819Srwatson#include <sys/types.h>
3890819Srwatson#include <sys/libkern.h>
3990819Srwatson
4090819Srwatson/*
4190819Srwatson * Return (1) if the buffer pointed to by kernel pointer 'buffer' and
4290819Srwatson * of length 'bufferlen' contains a valid NUL-terminated string
4390819Srwatson */
4490819Srwatsonint
4590819Srwatsonstrvalid(const char *buffer, size_t bufferlen)
4690819Srwatson{
4790819Srwatson	int i;
4890819Srwatson
4990819Srwatson	/* Must be NUL-terminated. */
5090819Srwatson	for (i = 0; i < bufferlen; i++)
5190819Srwatson		if (buffer[i] == '\0')
5290819Srwatson			return (1);
5390819Srwatson
5490819Srwatson	return (0);
5590819Srwatson}
56