]> granicus.if.org Git - multimarkdown/commitdiff
FIXED: Improve safety of realpath
authorFletcher T. Penney <fletcher@fletcherpenney.net>
Fri, 21 Jul 2017 14:22:45 +0000 (10:22 -0400)
committerFletcher T. Penney <fletcher@fletcherpenney.net>
Fri, 21 Jul 2017 14:22:45 +0000 (10:22 -0400)
Sources/multimarkdown/main.c

index c4af7612b84dfbf1c4b1b79805184999e35bb7bb..0aedb885b481df61ce421b5b1f9dbcc9c0f95b3e 100644 (file)
@@ -55,6 +55,7 @@
 
 #include <ctype.h>
 #include <libgen.h>
+#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -483,10 +484,16 @@ int main(int argc, char** argv) {
                        // Perform transclusion(s)
             
             // Convert to absolute path for first file to enable proper path resolution
-            char absolute[1025];
-            realpath(a_file->filename[0], absolute);
 
+#ifdef PATH_MAX
+            char absolute[PATH_MAX + 1];
+            realpath(a_file->filename[0], absolute);
             mmd_transclude_source(buffer, folder, absolute, format, NULL, NULL);
+#else
+            char * absolute = realpath(a_file->filename[0], NULL);
+            mmd_transclude_source(buffer, folder, absolute, format, NULL, NULL);
+            free(absolute);
+#endif
                        // Don't free folder -- owned by dirname
                }