Skip to contentSkip to conversation

btf_encoder: Add O_TRUNC to btf_encoder__write_raw_file()

PATCH Applied Namhyung Kim 2 participants 2 messages Jul 17 – Jul 23

lore
Share & tools
lore
#0 lore raw

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.

---
 btf_encoder.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
btf_encoder.c +1 -1
index d36984a..b810dd5 100644
@@ -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
Applied
#1 lore raw
Quoted 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.

Applied, thank you!

Alan

Quoted 20 lines
---
 btf_encoder.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
btf_encoder.c +1 -1
index d36984a..b810dd5 100644
@@ -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