190819Srwatson/*- 291826Srwatson * Copyright (c) 2002 Networks Associates Technology, 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 * 1990819Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 2090819Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2190819Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2290819Srwatson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2390819Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2490819Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2590819Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2690819Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2790819Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2890819Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2990819Srwatson * SUCH DAMAGE. 3090819Srwatson */ 3190819Srwatson 32116189Sobrien#include <sys/cdefs.h> 33116189Sobrien__FBSDID("$FreeBSD$"); 34116189Sobrien 3590819Srwatson#include <sys/types.h> 3690819Srwatson#include <sys/libkern.h> 3790819Srwatson 3890819Srwatson/* 3990819Srwatson * Return (1) if the buffer pointed to by kernel pointer 'buffer' and 4090819Srwatson * of length 'bufferlen' contains a valid NUL-terminated string 4190819Srwatson */ 4290819Srwatsonint 4390819Srwatsonstrvalid(const char *buffer, size_t bufferlen) 4490819Srwatson{ 45140960Srwatson size_t i; 4690819Srwatson 4790819Srwatson /* Must be NUL-terminated. */ 4890819Srwatson for (i = 0; i < bufferlen; i++) 4990819Srwatson if (buffer[i] == '\0') 5090819Srwatson return (1); 5190819Srwatson 5290819Srwatson return (0); 5390819Srwatson} 54