summaryrefslogtreecommitdiff
path: root/lndir.c
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2022-10-19 16:53:57 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2022-10-19 17:06:52 -0700
commitc7f46ebed5d731361ce96ce0745a7b59a53f32ff (patch)
tree8f74a098f0dcde3faec81e72e344849f8a849fff /lndir.c
parentf8c6c99000e4677ac2d0aab79b8e0ed561f170bc (diff)
Use strlcat and strlcpy if available
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'lndir.c')
-rw-r--r--lndir.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/lndir.c b/lndir.c
index 6eb3803..148d4df 100644
--- a/lndir.c
+++ b/lndir.c
@@ -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