diff options
author | Jeremie Courreges-Anglas <jca@cvs.openbsd.org> | 2020-03-09 23:50:02 +0000 |
---|---|---|
committer | Jeremie Courreges-Anglas <jca@cvs.openbsd.org> | 2020-03-09 23:50:02 +0000 |
commit | d8656af2b1b65c394237b4fd1c38113872930368 (patch) | |
tree | 5b8b1554ef6911dc14c65acbf05e84fb40bae62b | |
parent | 51e8ef7fa1271183106d7881857cd8d6f8b99859 (diff) |
Ensure that we properly flush, close and rename temporary output files
Makes sure we don't feed an incomplete/garbage file to consumers.
Input and ok claudio@ deraadt@
-rw-r--r-- | usr.sbin/rpki-client/extern.h | 4 | ||||
-rw-r--r-- | usr.sbin/rpki-client/output.c | 20 |
2 files changed, 15 insertions, 9 deletions
diff --git a/usr.sbin/rpki-client/extern.h b/usr.sbin/rpki-client/extern.h index 9ca0d4d2441..3348c4903aa 100644 --- a/usr.sbin/rpki-client/extern.h +++ b/usr.sbin/rpki-client/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.24 2020/03/06 17:36:42 benno Exp $ */ +/* $OpenBSD: extern.h,v 1.25 2020/03/09 23:50:01 jca Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -372,7 +372,7 @@ extern char* outputdir; int outputfiles(struct vrp_tree *v); FILE *output_createtmp(char *); void output_cleantmp(void); -void output_finish(FILE *); +int output_finish(FILE *); int output_bgpd(FILE *, struct vrp_tree *); int output_bird1v4(FILE *, struct vrp_tree *); int output_bird1v6(FILE *, struct vrp_tree *); diff --git a/usr.sbin/rpki-client/output.c b/usr.sbin/rpki-client/output.c index 31d3b6aba95..431d8bfd1ca 100644 --- a/usr.sbin/rpki-client/output.c +++ b/usr.sbin/rpki-client/output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: output.c,v 1.7 2020/03/09 23:44:32 jca Exp $ */ +/* $OpenBSD: output.c,v 1.8 2020/03/09 23:50:01 jca Exp $ */ /* * Copyright (c) 2019 Theo de Raadt <deraadt@openbsd.org> * @@ -78,7 +78,12 @@ outputfiles(struct vrp_tree *v) rc = 1; continue; } - output_finish(fout); + if (output_finish(fout) != 0) { + warn("finish for %s format failed", outputs[i].name); + output_cleantmp(); + rc = 1; + continue; + } } return rc; @@ -108,14 +113,15 @@ output_createtmp(char *name) return f; } -void +int output_finish(FILE *out) { - fclose(out); - out = NULL; - - rename(output_tmpname, output_name); + if (fclose(out) != 0) + return -1; + if (rename(output_tmpname, output_name) == -1) + return -1; output_tmpname[0] = '\0'; + return 0; } void |