15578933dSRobert Watson /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
38a36da99SPedro F. Giffuni *
46e8a94b2SRobert Watson * Copyright (c) 2002 Networks Associates Technology, Inc.
55578933dSRobert Watson * All rights reserved.
65578933dSRobert Watson *
75578933dSRobert Watson * This software was developed for the FreeBSD Project by NAI Labs,
85578933dSRobert Watson * the Security Research Division of Network Associates, Inc. under
95578933dSRobert Watson * DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA
105578933dSRobert Watson * CHATS research program.
115578933dSRobert Watson *
125578933dSRobert Watson * Redistribution and use in source and binary forms, with or without
135578933dSRobert Watson * modification, are permitted provided that the following conditions
145578933dSRobert Watson * are met:
155578933dSRobert Watson * 1. Redistributions of source code must retain the above copyright
165578933dSRobert Watson * notice, this list of conditions and the following disclaimer.
175578933dSRobert Watson * 2. Redistributions in binary form must reproduce the above copyright
185578933dSRobert Watson * notice, this list of conditions and the following disclaimer in the
195578933dSRobert Watson * documentation and/or other materials provided with the distribution.
205578933dSRobert Watson *
215578933dSRobert Watson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
225578933dSRobert Watson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
235578933dSRobert Watson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
245578933dSRobert Watson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
255578933dSRobert Watson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
265578933dSRobert Watson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
275578933dSRobert Watson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
285578933dSRobert Watson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
295578933dSRobert Watson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
305578933dSRobert Watson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
315578933dSRobert Watson * SUCH DAMAGE.
325578933dSRobert Watson */
335578933dSRobert Watson
345578933dSRobert Watson #include <sys/types.h>
355578933dSRobert Watson #include <sys/libkern.h>
365578933dSRobert Watson
375578933dSRobert Watson /*
385578933dSRobert Watson * Return (1) if the buffer pointed to by kernel pointer 'buffer' and
395578933dSRobert Watson * of length 'bufferlen' contains a valid NUL-terminated string
405578933dSRobert Watson */
415578933dSRobert Watson int
strvalid(const char * buffer,size_t bufferlen)425578933dSRobert Watson strvalid(const char *buffer, size_t bufferlen)
435578933dSRobert Watson {
44dc66c5feSRobert Watson size_t i;
455578933dSRobert Watson
465578933dSRobert Watson /* Must be NUL-terminated. */
475578933dSRobert Watson for (i = 0; i < bufferlen; i++)
485578933dSRobert Watson if (buffer[i] == '\0')
495578933dSRobert Watson return (1);
505578933dSRobert Watson
515578933dSRobert Watson return (0);
525578933dSRobert Watson }
53