Aaron Lwe reported that v2 build fails if /tmp and the build directory are on different file systems.
That's due to the rename being performed in build_opt_tbl. Renames can't be done across filesystems. I saw that problem in the original patch, but I didn't want to ruin the mood by complaining.
Anyway, here is a patch to fix it.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: LinuxBIOSv2-build_opt_tbl/util/options/build_opt_tbl.c =================================================================== --- LinuxBIOSv2-build_opt_tbl/util/options/build_opt_tbl.c (Revision 3788) +++ LinuxBIOSv2-build_opt_tbl/util/options/build_opt_tbl.c (Arbeitskopie) @@ -11,7 +11,7 @@ #define INPUT_LINE_MAX 256 #define MAX_VALUE_BYTE_LENGTH 64
-#define TMPFILE_TEMPLATE "/tmp/build_opt_tbl_XXXXXX" +#define TMPFILE_TEMPLATE ".XXXXXX"
static unsigned char cmos_table[4096];
@@ -215,7 +215,7 @@ char *header=0; FILE *fp; int tmpfile; - char tmpfilename[32]; + char *tmpfilename; struct cmos_option_table *ct; struct cmos_entries *ce; struct cmos_enums *c_enums, *c_enums_start; @@ -485,7 +485,9 @@
/* See if we want to output a C source file */ if(option) { - strcpy(tmpfilename, TMPFILE_TEMPLATE); + tmpfilename = malloc(strlen(option) + strlen(TMPFILE_TEMPLATE) + 1); + strcpy(tmpfilename, option); + strcat(tmpfilename, TMPFILE_TEMPLATE); tmpfile = mkstemp(tmpfilename); if(tmpfile == -1) { perror("Error - Could not create temporary file"); @@ -535,7 +537,9 @@ struct cmos_option_table *hdr; struct lb_record *ptr, *end;
- strcpy(tmpfilename, TMPFILE_TEMPLATE); + tmpfilename = malloc(strlen(header) + strlen(TMPFILE_TEMPLATE) + 1); + strcpy(tmpfilename, header); + strcat(tmpfilename, TMPFILE_TEMPLATE); tmpfile = mkstemp(tmpfilename); if(tmpfile == -1) { perror("Error - Could not create temporary file");
That's due to the rename being performed in build_opt_tbl. Renames can't be done across filesystems. I saw that problem in the original patch, but I didn't want to ruin the mood by complaining.
I see compiling errors more important than the mood.
Anyway, here is a patch to fix it.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: LinuxBIOSv2-build_opt_tbl/util/options/build_opt_tbl.c
--- LinuxBIOSv2-build_opt_tbl/util/options/build_opt_tbl.c (Revision 3788) +++ LinuxBIOSv2-build_opt_tbl/util/options/build_opt_tbl.c (Arbeitskopie) @@ -11,7 +11,7 @@ #define INPUT_LINE_MAX 256 #define MAX_VALUE_BYTE_LENGTH 64
-#define TMPFILE_TEMPLATE "/tmp/build_opt_tbl_XXXXXX" +#define TMPFILE_TEMPLATE ".XXXXXX"
static unsigned char cmos_table[4096];
@@ -215,7 +215,7 @@ char *header=0; FILE *fp; int tmpfile;
char tmpfilename[32];
char *tmpfilename; struct cmos_option_table *ct; struct cmos_entries *ce; struct cmos_enums *c_enums, *c_enums_start;
@@ -485,7 +485,9 @@
/* See if we want to output a C source file */ if(option) {
strcpy(tmpfilename, TMPFILE_TEMPLATE);
tmpfilename = malloc(strlen(option) + strlen(TMPFILE_TEMPLATE) + 1);
strcpy(tmpfilename, option);
strcat(tmpfilename, TMPFILE_TEMPLATE); tmpfile = mkstemp(tmpfilename); if(tmpfile == -1) { perror("Error - Could not create temporary file");
@@ -535,7 +537,9 @@ struct cmos_option_table *hdr; struct lb_record *ptr, *end;
strcpy(tmpfilename, TMPFILE_TEMPLATE);
tmpfilename = malloc(strlen(header) + strlen(TMPFILE_TEMPLATE) + 1);
strcpy(tmpfilename, header);
strcat(tmpfilename, TMPFILE_TEMPLATE); tmpfile = mkstemp(tmpfilename); if(tmpfile == -1) { perror("Error - Could not create temporary file");
The patch works well for me and is much better than the statically allocated method which will probablly cause other people complain due to their very long path name.
Acked-by: Aaron Lwe aaron.lwe@gmail.com
Hi Aaron,
could you retest with latest svn and the patch below? Thanks!
On 04.12.2008 04:41, aaron lwe wrote:
That's due to the rename being performed in build_opt_tbl. Renames can't be done across filesystems. I saw that problem in the original patch, but I didn't want to ruin the mood by complaining.
I see compiling errors more important than the mood.
Anyway, here is a patch to fix it.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
The patch works well for me and is much better than the statically allocated method which will probablly cause other people complain due to their very long path name.
Acked-by: Aaron Lwe aaron.lwe@gmail.com
Fix a few bugs introduced in r3789. - Possible NULL pointer dereference in the header code because the header code incorrectly used the option filename instead of the header filename. - Breakage if the path is longer than 234 bytes.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: LinuxBIOSv2-build_opt_tbl/util/options/build_opt_tbl.c =================================================================== --- LinuxBIOSv2-build_opt_tbl/util/options/build_opt_tbl.c (Revision 3794) +++ LinuxBIOSv2-build_opt_tbl/util/options/build_opt_tbl.c (Arbeitskopie) @@ -12,7 +12,6 @@ #define INPUT_LINE_MAX 256 #define MAX_VALUE_BYTE_LENGTH 64
-#define TMPFILE_LEN 256 #define TMPFILE_TEMPLATE "/build_opt_tbl_XXXXXX"
static unsigned char cmos_table[4096]; @@ -217,7 +216,7 @@ char *header=0; FILE *fp; int tmpfile; - char tmpfilename[TMPFILE_LEN]; + char *tmpfilename; struct cmos_option_table *ct; struct cmos_entries *ce; struct cmos_enums *c_enums, *c_enums_start; @@ -487,8 +486,9 @@
/* See if we want to output a C source file */ if(option) { - strncpy(tmpfilename, dirname(option), TMPFILE_LEN); - strncat(tmpfilename, TMPFILE_TEMPLATE, TMPFILE_LEN); + tmpfilename = malloc(strlen(dirname(option)) + strlen(TMPFILE_TEMPLATE) + 1); + strcpy(tmpfilename, dirname(option)); + strcat(tmpfilename, TMPFILE_TEMPLATE); tmpfile = mkstemp(tmpfilename); if(tmpfile == -1) { perror("Error - Could not create temporary file"); @@ -531,6 +531,7 @@ unlink(tmpfilename); exit(1); } + free(tmpfilename); }
/* See if we also want to output a C header file */ @@ -538,8 +539,9 @@ struct cmos_option_table *hdr; struct lb_record *ptr, *end;
- strncpy(tmpfilename, dirname(option), TMPFILE_LEN); - strncat(tmpfilename, TMPFILE_TEMPLATE, TMPFILE_LEN); + tmpfilename = malloc(strlen(dirname(header)) + strlen(TMPFILE_TEMPLATE) + 1); + strcpy(tmpfilename, dirname(header)); + strcat(tmpfilename, TMPFILE_TEMPLATE); tmpfile = mkstemp(tmpfilename); if(tmpfile == -1) { perror("Error - Could not create temporary file"); @@ -586,6 +588,7 @@ unlink(tmpfilename); exit(1); } + free(tmpfilename); } return(0); }
On 04.12.2008 05:06, Peter Stuge wrote:
Carl-Daniel Hailfinger wrote:
tmpfilename = malloc(strlen(option) + strlen(TMPFILE_TEMPLATE) + 1);
..
tmpfilename = malloc(strlen(header) + strlen(TMPFILE_TEMPLATE) + 1);
Watch out for those exploits.
;-)
Regards, Carl-Daniel