btf_encoder: Add O_TRUNC to btf_encoder__write_raw_file()
PATCH 1/1 btf_encoder: Add O_TRUNC to btf_encoder__write_raw_file()
When it creates a raw file, it should truncate the content in case there is an old file with the same name. Otherwise it may have some garbage at the end of the file and it could make the kernel fail to verify BTF.
Signed-off-by Namhyung Kim <[email protected]>
--- btf_encoder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
btf_encoder.c +1 -1
@@ -1878,7 +1878,7 @@ static int btf_encoder__write_raw_file(struct btf_encoder *encoder)return -1 ; } - fd =open (filename,O_WRONLY |O_CREAT ,0640 ); + fd =open (filename,O_WRONLY |O_CREAT |O_TRUNC ,0640 );if (fd <0 ) {fprintf (stderr,"%s: Couldn't open %s for writing the raw BTF info: %s\n" , __func__, filename,strerror (errno));return -1 ;
Signature · 1 line
2.55.0.229.g6434b31f56-goog
Alan Maguire
AppliedQuoted 6 lines · Namhyung Kim
When it creates a raw file, it should truncate the content in case there is an old file with the same name. Otherwise it may have some garbage at the end of the file and it could make the kernel fail to verify BTF.
Signed-off-by Namhyung Kim <[email protected]>
Applied, thank you!
Alan
Quoted 20 lines
--- btf_encoder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)btf_encoder.c +1
-1@@ -1878,7 +1878,7 @@ static int btf_encoder__write_raw_file(struct btf_encoder *encoder)return -1 ; } - fd =open (filename,O_WRONLY |O_CREAT ,0640 ); + fd =open (filename,O_WRONLY |O_CREAT |O_TRUNC ,0640 );if (fd <0 ) {fprintf (stderr,"%s: Couldn't open %s for writing the raw BTF info: %s\n" , __func__, filename,strerror (errno));return -1 ;Signature · 1 line
2.55.0.229.g6434b31f56-goog