summaryrefslogtreecommitdiffstats
path: root/lib/libc/tests/stdio/fmemopen2_test.c
diff options
context:
space:
mode:
authorngie <ngie@FreeBSD.org>2016-05-04 00:30:36 +0000
committerngie <ngie@FreeBSD.org>2016-05-04 00:30:36 +0000
commit544322815d0c34f76ef163914c5abeb7a04058ba (patch)
tree1974b320dbd35e8e12bc6ba63f95c89c15cf305e /lib/libc/tests/stdio/fmemopen2_test.c
parente47fda35686eefd0d999881cb8255c6bc4092112 (diff)
downloadFreeBSD-src-544322815d0c34f76ef163914c5abeb7a04058ba.zip
FreeBSD-src-544322815d0c34f76ef163914c5abeb7a04058ba.tar.gz
MFC r298311,r298312:
r298311: Make sure fmemopen succeeds in :test_append_binary_pos before calling ftell on the FILE object This fixes potential null pointer dereferences on failure CID: 1254952 r298312: Fix double fclose of `fp1` when freopen fails freopen handles closing file descriptors on error, with the exception of fdopen'ed descriptors, so closing an already fclose'd file descriptor is incorrect CID: 1338525
Diffstat (limited to 'lib/libc/tests/stdio/fmemopen2_test.c')
-rw-r--r--lib/libc/tests/stdio/fmemopen2_test.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/lib/libc/tests/stdio/fmemopen2_test.c b/lib/libc/tests/stdio/fmemopen2_test.c
index 62831fb..6b6392d 100644
--- a/lib/libc/tests/stdio/fmemopen2_test.c
+++ b/lib/libc/tests/stdio/fmemopen2_test.c
@@ -249,12 +249,14 @@ ATF_TC_BODY(test_append_binary_pos, tc)
FILE *fp;
fp = fmemopen(NULL, 16, "ab+");
+ ATF_REQUIRE(fp != NULL);
ATF_REQUIRE(ftell(fp) == 0L);
fclose(fp);
/* Make sure that a pre-allocated buffer behaves correctly. */
char buf[] = "Hello";
fp = fmemopen(buf, sizeof(buf), "ab+");
+ ATF_REQUIRE(fp != NULL);
ATF_REQUIRE(ftell(fp) == strlen(buf));
fclose(fp);
}
OpenPOWER on IntegriCloud