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
MFC after: 2 weeks
Reported by: Coverity
Sponsored by: EMC / Isilon Storage Division
This commit is contained in:
Enji Cooper 2016-04-19 23:59:10 +00:00
parent 02abd40029
commit c1755e5189
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=298311

View File

@ -250,12 +250,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);
}