postgres.git / summary / log / commit / refs

commit    89a94c24aadd8f40084339ea3d16e2e14fa9f629
Author:   Andres Freund <andres@anarazel.de>
Date:     Wed Mar 23 20:05:25 2022 +0000

    Don't call fwrite() with len == 0 when writing out relcache init file.
    
    Noticed via -fsanitize=undefined.
    
    Backpatch to all branches, for the same reasons as 46ab07ffda9.
    
    Discussion: https://postgr.es/m/20220323173537.ll7klrglnp4gn2um@alap3.anarazel.de
    Backpatch: 10-


src/backend/utils/cache/relcache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index b54c9117669..dcf56d47900 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -6485,7 +6485,7 @@ write_item(const void *data, Size len, FILE *fp) { if (fwrite(&len, 1, sizeof(len), fp) != sizeof(len)) elog(FATAL, "could not write init file"); - if (fwrite(data, 1, len, fp) != len) + if (len > 0 && fwrite(data, 1, len, fp) != len) elog(FATAL, "could not write init file"); } [parent: e52e9bd57f33]