diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2022-10-19 16:53:57 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2022-10-19 17:06:52 -0700 |
commit | c7f46ebed5d731361ce96ce0745a7b59a53f32ff (patch) | |
tree | 8f74a098f0dcde3faec81e72e344849f8a849fff | |
parent | f8c6c99000e4677ac2d0aab79b8e0ed561f170bc (diff) |
Use strlcat and strlcpy if available
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r-- | .gitlab-ci.yml | 4 | ||||
-rw-r--r-- | configure.ac | 8 | ||||
-rw-r--r-- | lndir.c | 33 |
3 files changed, 43 insertions, 2 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2fd7c2b..9bc01f0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -30,8 +30,8 @@ variables: # The tag should be updated each time the list of packages is updated. # Changing a tag forces the associated image to be rebuilt. # Note: the tag has no meaning, we use a date format purely for readability - FDO_DISTRIBUTION_TAG: '2022-01-15.0' - FDO_DISTRIBUTION_PACKAGES: 'git gcc pkgconf autoconf automake make xorg-util-macros xorgproto' + FDO_DISTRIBUTION_TAG: '2022-10-19.0' + FDO_DISTRIBUTION_PACKAGES: 'git gcc pkgconf autoconf automake make xorg-util-macros xorgproto libbsd' # diff --git a/configure.ac b/configure.ac index 1679a28..ccc5372 100644 --- a/configure.ac +++ b/configure.ac @@ -43,5 +43,13 @@ AC_SYS_LARGEFILE # Checks for pkg-config packages PKG_CHECK_MODULES(XPROTO, xproto >= 7.0.17) +# Checks for non-standard functions and fallback to libbsd if we can +AC_LINK_IFELSE([AC_LANG_CALL([], [strlcpy])], + [TRY_LIBBSD="no"], [TRY_LIBBSD="yes"]) +AS_IF([test "x$TRY_LIBBSD" = "xyes"], + [PKG_CHECK_MODULES([LIBBSD], [libbsd-overlay], + [CFLAGS="$CFLAGS $LIBBSD_CFLAGS" ; LIBS="$LIBS $LIBBSD_LIBS"], [:])]) +AC_CHECK_FUNCS([strlcat strlcpy]) + AC_CONFIG_FILES([Makefile]) AC_OUTPUT @@ -58,6 +58,7 @@ in this Software without prior written authorization from The Open Group. #include <sys/param.h> #include <errno.h> #include <dirent.h> +#include <string.h> #ifndef MAXPATHLEN #define MAXPATHLEN 2048 @@ -159,10 +160,19 @@ dodir (const char *fn, /* name of "from" directory, either absolute or } if (rel) +#ifdef HAVE_STRLCPY + strlcpy (buf, "../", sizeof(buf)); +#else strcpy (buf, "../"); +#endif else buf[0] = '\0'; +#ifdef HAVE_STRLCAT + if (strlcat (buf, fn, sizeof(buf)) >= sizeof(buf)) + quit(1, "Pathname too long: %s", fn); +#else strcat (buf, fn); +#endif if (!(df = opendir (buf))) { msg ("%s: Cannot opendir", buf); @@ -184,7 +194,16 @@ dodir (const char *fn, /* name of "from" directory, either absolute or !strcmp(dp->d_name, "._.DS_Store")) continue; #endif + +#ifdef HAVE_STRLCAT + *p = '\0'; + if (strlcat (buf, dp->d_name, sizeof(buf)) >= sizeof(buf)) { + *p = '\0'; + quit(1, "Pathname too long: %s%s", buf, dp->d_name); + } +#else strcpy (p, dp->d_name); +#endif if (n_dirs > 0) { if (lstat (buf, &sb) < 0) { @@ -287,7 +306,12 @@ dodir (const char *fn, /* name of "from" directory, either absolute or int i; char *start, *end; +#ifdef HAVE_STRLCPY + if (strlcpy (symbuf, buf, sizeof(symbuf)) >= sizeof(symbuf)) + quit(1, "Pathname too long: %s", buf); +#else strcpy (symbuf, buf); +#endif /* Find the first char after "../" in symbuf. */ start = symbuf; do { @@ -312,7 +336,16 @@ dodir (const char *fn, /* name of "from" directory, either absolute or } if (*end == '/') end++; +#ifdef HAVE_STRLCPY + *end = '\0'; + if (strlcat (symbuf, &basesym[i], sizeof(symbuf)) >= + sizeof(symbuf)) { + *end = '\0'; + quit(1, "Pathname too long: %s%s", symbuf, &basesym[i]); + } +#else strcpy (end, &basesym[i]); +#endif sympath = symbuf; } else |