Use a dynamic string for reading symlinks.
authormdw <mdw>
Tue, 18 May 1999 20:49:12 +0000 (20:49 +0000)
committermdw <mdw>
Tue, 18 May 1999 20:49:12 +0000 (20:49 +0000)
checkpath.c
path.c

index 74eb243..f470d49 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: checkpath.c,v 1.1 1999/04/06 20:12:07 mdw Exp $
+ * $Id: checkpath.c,v 1.2 1999/05/18 20:49:12 mdw Exp $
  *
  * Check a path for safety
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: checkpath.c,v $
- * Revision 1.1  1999/04/06 20:12:07  mdw
- * Initial revision
+ * Revision 1.2  1999/05/18 20:49:12  mdw
+ * Use a dynamic string for reading symlinks.
+ *
+ * Revision 1.1.1.1  1999/04/06 20:12:07  mdw
+ * Import new project.
  *
  */
 
@@ -418,18 +421,20 @@ int path_check(const char *p, struct chkpath *cp)
     /* --- Handle symbolic links specially --- */
 
     if (S_ISLNK(st.st_mode)) {
-      char buf[PATH_MAX];
+      dstr buf;
       int i;
 
       /* --- Resolve the link --- */
 
-      if ((i = readlink(d.buf, buf, sizeof(buf))) < 0) {
+      dstr_create(&buf);
+      dstr_ensure(&buf, st.st_size + 1);
+      if ((i = readlink(d.buf, buf.buf, buf.sz)) < 0) {
        report(cp, CP_ERROR, 0, d.buf, "can't readlink: %e");
        bad |= CP_ERROR;
        break;
       }
-      buf[i] = 0;
-      report(cp, CP_SYMLINK, 2, d.buf, "symlink -> `%s'", buf);
+      buf.buf[i] = 0;
+      report(cp, CP_SYMLINK, 2, d.buf, "symlink -> `%s'", buf.buf);
 
       /* --- Handle sticky parents --- *
        *
@@ -448,11 +453,12 @@ int path_check(const char *p, struct chkpath *cp)
 
       /* --- Sort out what to do from here --- */
 
-      if (buf[0] == '/')
+      if (buf.buf[0] == '/')
        popall();
       else
        pop();
-      ee = splitpath(buf, ee);
+      ee = splitpath(buf.buf, ee);
+      dstr_destroy(&buf);
       continue;
     }
 
diff --git a/path.c b/path.c
index fd6271b..4a136b8 100644 (file)
--- a/path.c
+++ b/path.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: path.c,v 1.1 1999/04/06 20:12:07 mdw Exp $
+ * $Id: path.c,v 1.2 1999/05/18 20:49:12 mdw Exp $
  *
  * Check a path for safety
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: path.c,v $
- * Revision 1.1  1999/04/06 20:12:07  mdw
- * Initial revision
+ * Revision 1.2  1999/05/18 20:49:12  mdw
+ * Use a dynamic string for reading symlinks.
+ *
+ * Revision 1.1.1.1  1999/04/06 20:12:07  mdw
+ * Import new project.
  *
  */
 
@@ -418,18 +421,20 @@ int path_check(const char *p, struct chkpath *cp)
     /* --- Handle symbolic links specially --- */
 
     if (S_ISLNK(st.st_mode)) {
-      char buf[PATH_MAX];
+      dstr buf;
       int i;
 
       /* --- Resolve the link --- */
 
-      if ((i = readlink(d.buf, buf, sizeof(buf))) < 0) {
+      dstr_create(&buf);
+      dstr_ensure(&buf, st.st_size + 1);
+      if ((i = readlink(d.buf, buf.buf, buf.sz)) < 0) {
        report(cp, CP_ERROR, 0, d.buf, "can't readlink: %e");
        bad |= CP_ERROR;
        break;
       }
-      buf[i] = 0;
-      report(cp, CP_SYMLINK, 2, d.buf, "symlink -> `%s'", buf);
+      buf.buf[i] = 0;
+      report(cp, CP_SYMLINK, 2, d.buf, "symlink -> `%s'", buf.buf);
 
       /* --- Handle sticky parents --- *
        *
@@ -448,11 +453,12 @@ int path_check(const char *p, struct chkpath *cp)
 
       /* --- Sort out what to do from here --- */
 
-      if (buf[0] == '/')
+      if (buf.buf[0] == '/')
        popall();
       else
        pop();
-      ee = splitpath(buf, ee);
+      ee = splitpath(buf.buf, ee);
+      dstr_destroy(&buf);
       continue;
     }