Rewrite last strcpy() call in ux_init.c and remove a FILENAME_MAX instance.
authorDavid Griffith <dave@661.org>
Sun, 3 Feb 2019 13:24:55 +0000 (05:24 -0800)
committerDavid Griffith <dave@661.org>
Sun, 3 Feb 2019 13:24:55 +0000 (05:24 -0800)
src/curses/ux_init.c

index 19c72fce29757ca0d17e5230aca5f7dbe90d849a..04ea2948c5fb14cc860dfe4baa5e52a2bb1e28a1 100644 (file)
@@ -724,26 +724,28 @@ int os_storyfile_tell(FILE * fp)
  * that file.  If found, return a pointer to that file
  *
  */
-static FILE *pathopen(const char *name, const char *p, const char *mode)
+static FILE *pathopen(const char *name, const char *path, const char *mode)
 {
        FILE *fp;
-       char buf[FILENAME_MAX + 1];
+       char *buf;
        char *bp, lastch;
 
        lastch = 'a';   /* makes compiler shut up */
 
-       while (*p) {
+       buf = malloc(strlen(path) + strlen(name) + 1);
+
+       while (*path) {
                bp = buf;
-               while (*p && *p != PATHSEP)
-                       lastch = *bp++ = *p++;
+               while (*path && *path != PATHSEP)
+                       lastch = *bp++ = *path++;
                if (lastch != DIRSEP)
                        *bp++ = DIRSEP;
-               strcpy(bp, name);
+               strncpy(bp, name, strlen(path) + strlen(name) + 1);
                if ((fp = fopen(buf, mode)) != NULL) {
                        return fp;
                }
-               if (*p)
-                       p++;
+               if (*path)
+                       path++;
        }
        return NULL;
 } /* FILE *pathopen() */