function.
* libamu/util.c (xstrlcpy): new function. Similar to strncpy, but
uses strlcpy to guarantee that the resulting string is null
terminated, and also warn if the resulting string was truncated.
* libamu/xutil.c (get_server_pid): move this function from util.c
which is for general-purpose utilities.
* m4/macros/header_templates.m4: template for HAVE_EXTERN_STRLCPY.
* include/am_defs.h: provide extern definition for strlcpy, if
needed.
* libamu/Makefile.am (EXTRA_DIST): include strlcpy.c in distro.
* configure.in: search for strlcpy and its extern.
2005-04-06 Erez Zadok <ezk@cs.sunysb.edu>
+ * include/am_utils.h: external definition for new xstrlcpy
+ function.
+
+ * libamu/util.c (xstrlcpy): new function. Similar to strncpy, but
+ uses strlcpy to guarantee that the resulting string is null
+ terminated, and also warn if the resulting string was truncated.
+
+ * libamu/xutil.c (get_server_pid): move this function from util.c
+ which is for general-purpose utilities.
+
+ * m4/macros/header_templates.m4: template for HAVE_EXTERN_STRLCPY.
+
+ * include/am_defs.h: provide extern definition for strlcpy, if
+ needed.
+
+ * libamu/Makefile.am (EXTRA_DIST): include strlcpy.c in distro.
+
+ * configure.in: search for strlcpy and its extern.
+
* amq/pawd.c (find_mt): It only handles *some* filesystem types,
so it breaks on direct xfs mounts for example. The fix (from
Christos Zoulas) is simple: We need to exclude toplvl to avoid
dnl
dnl AC_CONFIG_AUX_DIR(m4)
AC_PREREQ(2.52)
-AC_REVISION($Revision: 1.81 $)
+AC_REVISION($Revision: 1.82 $)
AC_COPYRIGHT([Copyright (c) 1997-2005 Erez Zadok])
dnl find out system type
AC_MSG_NOTICE(*** SYSTEM TYPES ***)
sigsuspend \
socket \
strchr \
- strcspn \
strcasecmp \
+ strcspn \
strdup \
strerror \
+ strlcpy \
strspn \
strstr \
svc_getreq \
strcasecmp \
strdup \
strerror \
+ strlcpy \
strstr \
ualarm \
)
setitimer \
strcasecmp \
strdup \
+ strlcpy \
strstr \
ualarm \
usleep \
* SUCH DAMAGE.
*
*
- * $Id: am_defs.h,v 1.54 2005/03/21 19:08:05 ro Exp $
+ * $Id: am_defs.h,v 1.55 2005/04/07 03:50:41 ezk Exp $
*
*/
extern char *strdup(const char *s);
#endif /* not HAVE_EXTERN_STRDUP */
+#ifndef HAVE_EXTERN_STRLCPY
+/*
+ * define this extern even if function does not exist, for it will
+ * be filled in by libamu/strlcpy.c
+ */
+extern size_t strlcpy(char *dst, const char *src, size_t siz);
+#endif /* not HAVE_EXTERN_STRLCPY */
+
#if defined(HAVE_STRSTR) && !defined(HAVE_EXTERN_STRSTR)
extern char *strstr(const char *s1, const char *s2);
#endif /* defined(HAVE_STRSTR) && !defined(HAVE_EXTERN_STRSTR) */
* SUCH DAMAGE.
*
*
- * $Id: am_utils.h,v 1.63 2005/03/09 02:29:55 ezk Exp $
+ * $Id: am_utils.h,v 1.64 2005/04/07 03:50:41 ezk Exp $
*
*/
extern void rpc_msg_init(struct rpc_msg *, u_long, u_long, u_long);
extern void set_amd_program_number(int program);
extern void show_opts(int ch, struct opt_tab *);
+extern void xstrlcpy(char *dst, const char *src, size_t len);
extern void unregister_amq(void);
extern voidp xmalloc(int);
extern voidp xrealloc(voidp, int);
strcasecmp.c \
strdup.c \
strerror.c \
+ strlcpy.c \
strstr.c \
ualarm.c
--- /dev/null
+/*
+ * Copyright (c) 1997-2005 Erez Zadok
+ * Copyright (c) 1990 Jan-Simon Pendry
+ * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Jan-Simon Pendry at Imperial College, London.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgment:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ *
+ *
+ * $Id: strlcpy.c,v 1.1 2005/04/07 03:50:42 ezk Exp $
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif /* HAVE_CONFIG_H */
+#include <am_defs.h>
+#include <amu.h>
+
+/*
+ * Implementation of strlcpy(3) from OpenBSD/NetBSD.
+ */
+
+/*
+ * Copy src to string dst of size siz. At most siz-1 characters
+ * will be copied. Always NUL terminates (unless siz == 0).
+ * Returns strlen(src); if retval >= siz, truncation occurred.
+ */
+size_t
+strlcpy(char *dst, const char *src, size_t siz)
+{
+ char *d = dst;
+ const char *s = src;
+ size_t n = siz;
+
+
+ /* Copy as many bytes as will fit */
+ if (n != 0 && --n != 0) {
+ do {
+ if ((*d++ = *s++) == 0)
+ break;
+ } while (--n != 0);
+ }
+
+ /* Not enough room in dst, add NUL and traverse rest of src */
+ if (n == 0) {
+ if (siz != 0)
+ *d = '\0'; /* NUL-terminate dst */
+ while (*s++)
+ ;
+ }
+
+ return(s - src - 1); /* count does not include NUL */
+}
* SUCH DAMAGE.
*
*
- * $Id: strutil.c,v 1.13 2005/01/17 22:41:28 ezk Exp $
+ * $Id: strutil.c,v 1.14 2005/04/07 03:50:42 ezk Exp $
*
*/
}
+/*
+ * Use generic strlcpy to copy a string more carefully, null-terminating it
+ * as needed. However, if the copied string was truncated due to lack of
+ * space, then warn us.
+ *
+ * For now, xstrlcpy returns VOID because it doesn't look like anywhere in
+ * the Amd code do we actually use the return value of strncpy/strlcpy.
+ */
+void
+xstrlcpy(char *dst, const char *src, size_t len)
+{
+ if (strlcpy(dst, src, len) >= len)
+ plog(XLOG_WARNING, "xstrlcpy: string \"%s\" truncated to \"%s\"", src, dst);
+}
+
+
/*
* Make all the directories in the path.
*/
XFREE(xdp);
}
-
-long
-get_server_pid()
-{
- return (long) (foreground ? am_mypid : getppid());
-}
* SUCH DAMAGE.
*
*
- * $Id: xutil.c,v 1.35 2005/02/27 04:23:09 ezk Exp $
+ * $Id: xutil.c,v 1.36 2005/04/07 03:50:42 ezk Exp $
*
*/
}
+long
+get_server_pid()
+{
+ return (long) (foreground ? am_mypid : getppid());
+}
+
+
voidp
xmalloc(int len)
{
AH_TEMPLATE([HAVE_EXTERN_STRDUP],
[does extern definition for strdup() exist?])
+AH_TEMPLATE([HAVE_EXTERN_STRLCPY],
+[does extern definition for strlcpy() exist?])
+
AH_TEMPLATE([HAVE_EXTERN_STRSTR],
[does extern definition for strstr() exist?])