/*
* Copyright (c) 1995 RadioMail Corporation.
- * Copyright (c) 1996-2000 Internet Software Consortium.
- * All rights reserved.
+ * Copyright (C) 2004-2022 Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 1996-2003 by Internet Software Consortium
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of The Internet Software Consortium nor the names
- * of its contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
- * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
+ * Internet Systems Consortium, Inc.
+ * PO Box 360
+ * Newmarket, NH 03857 USA
+ * <info@isc.org>
+ * https://www.isc.org/
*
* This software was written for RadioMail Corporation by Ted Lemon
* under a contract with Vixie Enterprises. Further modifications have
- * been made for the Internet Software Consortium under a contract
+ * been made for Internet Systems Consortium under a contract
* with Vixie Laboratories.
*/
-#ifndef lint
-static char copyright[] =
-"$Id: errwarn.c,v 1.5 2000/06/29 20:05:13 mellon Exp $ Copyright (c) 1996 The Internet Software Consortium. All rights reserved.\n";
-#endif /* not lint */
+#include "dhcpd.h"
#include <omapip/omapip_p.h>
#include <errno.h>
+#include <syslog.h>
#ifdef DEBUG
int log_perror = -1;
#else
int log_perror = 1;
#endif
-int log_priority;
void (*log_cleanup) (void);
-static char mbuf [1024];
-static char fbuf [1024];
+#define CVT_BUF_MAX 1023
+static char mbuf [CVT_BUF_MAX + 1];
+static char fbuf [CVT_BUF_MAX + 1];
/* Log an error message, then exit... */
{
va_list list;
- do_percentm (fbuf, fmt);
+ do_percentm (fbuf, sizeof fbuf, fmt);
+ /* %Audit% This is log output. %2004.06.17,Safe%
+ * If we truncate we hope the user can get a hint from the log.
+ */
va_start (list, fmt);
vsnprintf (mbuf, sizeof mbuf, fbuf, list);
va_end (list);
#ifndef DEBUG
- syslog (log_priority | LOG_ERR, "%s", mbuf);
+ syslog (LOG_ERR, "%s", mbuf);
#endif
/* Also log it to stderr? */
if (log_perror) {
- write (2, mbuf, strlen (mbuf));
- write (2, "\n", 1);
+ IGNORE_RET (write (STDERR_FILENO, mbuf, strlen (mbuf)));
+ IGNORE_RET (write (STDERR_FILENO, "\n", 1));
}
- syslog (LOG_CRIT, "exiting.");
- if (log_perror) {
- fprintf (stderr, "exiting.\n");
- fflush (stderr);
- }
+ log_error ("%s", "");
+ log_error ("If you think you have received this message due to a bug rather");
+ log_error ("than a configuration issue please read the section on submitting");
+ log_error ("bugs on either our web page at www.isc.org or in the README file");
+ log_error ("before submitting a bug. These pages explain the proper");
+ log_error ("process and the information we find helpful for debugging.");
+ log_error ("%s", "");
+ log_error ("exiting.");
+
if (log_cleanup)
(*log_cleanup) ();
exit (1);
{
va_list list;
- do_percentm (fbuf, fmt);
+ do_percentm (fbuf, sizeof fbuf, fmt);
+ /* %Audit% This is log output. %2004.06.17,Safe%
+ * If we truncate we hope the user can get a hint from the log.
+ */
va_start (list, fmt);
vsnprintf (mbuf, sizeof mbuf, fbuf, list);
va_end (list);
#ifndef DEBUG
- syslog (log_priority | LOG_ERR, "%s", mbuf);
+ syslog (LOG_ERR, "%s", mbuf);
#endif
if (log_perror) {
- write (2, mbuf, strlen (mbuf));
- write (2, "\n", 1);
+ IGNORE_RET (write (STDERR_FILENO, mbuf, strlen (mbuf)));
+ IGNORE_RET (write (STDERR_FILENO, "\n", 1));
}
return 0;
{
va_list list;
- do_percentm (fbuf, fmt);
+ do_percentm (fbuf, sizeof fbuf, fmt);
+ /* %Audit% This is log output. %2004.06.17,Safe%
+ * If we truncate we hope the user can get a hint from the log.
+ */
va_start (list, fmt);
vsnprintf (mbuf, sizeof mbuf, fbuf, list);
va_end (list);
#ifndef DEBUG
- syslog (log_priority | LOG_INFO, "%s", mbuf);
+ syslog (LOG_INFO, "%s", mbuf);
#endif
if (log_perror) {
- write (2, mbuf, strlen (mbuf));
- write (2, "\n", 1);
+ IGNORE_RET (write (STDERR_FILENO, mbuf, strlen (mbuf)));
+ IGNORE_RET (write (STDERR_FILENO, "\n", 1));
}
return 0;
{
va_list list;
- do_percentm (fbuf, fmt);
+ do_percentm (fbuf, sizeof fbuf, fmt);
+ /* %Audit% This is log output. %2004.06.17,Safe%
+ * If we truncate we hope the user can get a hint from the log.
+ */
va_start (list, fmt);
vsnprintf (mbuf, sizeof mbuf, fbuf, list);
va_end (list);
#ifndef DEBUG
- syslog (log_priority | LOG_DEBUG, "%s", mbuf);
+ syslog (LOG_DEBUG, "%s", mbuf);
#endif
if (log_perror) {
- write (2, mbuf, strlen (mbuf));
- write (2, "\n", 1);
+ IGNORE_RET (write (STDERR_FILENO, mbuf, strlen (mbuf)));
+ IGNORE_RET (write (STDERR_FILENO, "\n", 1));
}
return 0;
/* Find %m in the input string and substitute an error message string. */
-void do_percentm (obuf, ibuf)
+void do_percentm (obuf, obufsize, ibuf)
char *obuf;
+ size_t obufsize;
const char *ibuf;
{
const char *s = ibuf;
char *p = obuf;
int infmt = 0;
const char *m;
+ int len = 0;
- while (*s)
- {
- if (infmt)
- {
- if (*s == 'm')
- {
+ while (*s) {
+ if (infmt) {
+ if (*s == 'm') {
#ifndef __CYGWIN32__
m = strerror (errno);
#else
#endif
if (!m)
m = "<unknown error>";
+ len += strlen (m);
+ if (len > obufsize - 1)
+ goto out;
strcpy (p - 1, m);
p += strlen (p);
++s;
- }
- else
+ } else {
+ if (++len > obufsize - 1)
+ goto out;
*p++ = *s++;
+ }
infmt = 0;
- }
- else
- {
+ } else {
if (*s == '%')
infmt = 1;
+ if (++len > obufsize - 1)
+ goto out;
*p++ = *s++;
}
}
+ out:
*p = 0;
}