Skip to content

Commit

Permalink
Add strnlen to compat folder for support on older systems (duosecurit…
Browse files Browse the repository at this point in the history
  • Loading branch information
xdesai authored May 26, 2020
1 parent caaa67e commit 6f1e05a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
5 changes: 5 additions & 0 deletions acconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ int getgrouplist(const char *name, gid_t basegid, gid_t *groups, int *ngroups);
size_t strlcpy(char *dst, const char *src, size_t size);
#endif

#ifndef HAVE_STRNLEN
#include <sys/types.h>

size_t strnlen(const char *str, size_t maxlen);
#endif
34 changes: 34 additions & 0 deletions compat/strnlen.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* $OpenBSD: strnlen.c,v 1.9 2019/01/25 00:19:25 millert Exp $ */

/*
* Copyright (c) 2010 Todd C. Miller <millert@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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.
*/

#include <sys/types.h>

#include <string.h>

size_t
strnlen(const char *str, size_t maxlen)
{
const char *cp;

for (cp = str; maxlen != 0 && *cp != '\0'; cp++, maxlen--)
;

return (size_t)(cp - str);
}
// XXX DUO MOD. Remove weak symbol declaration as it's not supported on all systems
// DEF_WEAK(strnlen);
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ AC_MSG_NOTICE([Using libdir "$libdir"])
# Check for functions
AC_CONFIG_LIBOBJ_DIR([compat])
AC_CHECK_FUNCS([memcpy memset sysconf getaddrinfo open64 fopen64 explicit_bzero memset_s])
AC_REPLACE_FUNCS([asprintf getgrouplist strlcpy vsyslog])
AC_REPLACE_FUNCS([asprintf getgrouplist strlcpy vsyslog strnlen])
AC_SEARCH_LIBS(inet_ntoa, nsl)
AC_SEARCH_LIBS(socket, socket)

Expand Down

0 comments on commit 6f1e05a

Please sign in to comment.