Don't call fwrite() with len == 0 when writing out relcache init file.
authorAndres Freund <[email protected]>
Wed, 23 Mar 2022 20:05:25 +0000 (13:05 -0700)
committerAndres Freund <[email protected]>
Wed, 23 Mar 2022 20:13:33 +0000 (13:13 -0700)
Noticed via -fsanitize=undefined.

Backpatch to all branches, for the same reasons as 46ab07ffda9.

Discussion: https://postgr.es/m/20220323173537[email protected]
Backpatch: 10-

src/backend/utils/cache/relcache.c

index 87651111ee32c8e34640af5c9e6d01e97edb14ec..bad672f51b348fc5d2b72ebfd0fdf54bc0e0f9c1 100644 (file)
@@ -6083,7 +6083,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");
 }