compile_et: Don't overflow input file buffer
[openafs.git] / src / comerr / compile_et.c
index 3f3f02d..e5b780c 100644 (file)
 #include "internal.h"
 #include "compiler.h"
 
-#ifndef lint
-static const char copyright[] =
-    "Copyright 1987,1988 by MIT Student Information Processing Board";
-#endif
-
 extern char *current_token;
 extern int table_number, current;
 char buffer[BUFSIZ];
@@ -94,8 +89,6 @@ static const char *const language_names[] = {
 };
 
 static const char *const c_src_prolog[] = {
-    "#include <afsconfig.h>\n",
-    "#include <afs/param.h>\n",
     "#include <afs/error_table.h>\n",
     "static const char * const text[] = {\n",
     0,
@@ -124,7 +117,6 @@ static const char msf_warning[] =
 char c_file[MAXPATHLEN];       /* output file */
 char h_file[MAXPATHLEN];       /* output */
 char msf_file[MAXPATHLEN];
-char et_file[MAXPATHLEN];      /* full path to input file */
 
 static void
 usage(void)
@@ -149,6 +141,7 @@ int
 main(int argc, char **argv)
 {
     char *p, *ename;
+    char *et_file;
     char const *const *cpp;
     int got_language = 0;
     char *got_include = 0;
@@ -321,7 +314,10 @@ main(int argc, char **argv)
        filename = p;
     }
 
-    sprintf(et_file, "%s/%s", got_prefix, filename);
+    if (asprintf(&et_file, "%s/%s", got_prefix, filename) < 0) {
+       fprintf(stderr, "Couldn't allocate memory for filename\n");
+       exit(1);
+    }
 
     yyin = fopen(et_file, "r");
     if (!yyin) {
@@ -329,6 +325,8 @@ main(int argc, char **argv)
        exit(1);
     }
 
+    free(et_file);
+
     /* on NT, yyout is not initialized to stdout */
     if (!yyout) {
        yyout = stdout;