Per paragraph 3 of section 6.5.16.1 "Simple assignment" of ISO 9899:1999 TC3:
If the value being stored in an object is read from another object
that overlaps in any way the storage of the first object, then the overlap
shall be exact and the two objects shall have qualified or unqualified
versions of a compatible type; otherwise, the behavior is undefined.
And that is what exactly violated when one field of the union is
assigned to another; avoid that by introducing separate local variable
where the cast value is stored and then compared.
Fixes: 9deaf8383338 "test/bioprinttest.c: add some checks for integer and string printing"
Resolves: https://scan5.scan.coverity.com/#/project-view/65248/10222?selectedIssue=
1665144
Resolves: https://scan5.scan.coverity.com/#/project-view/65248/10222?selectedIssue=
1665145
Resolves: https://scan5.scan.coverity.com/#/project-view/65248/10222?selectedIssue=
1665146
Resolves: https://scan5.scan.coverity.com/#/project-view/65248/10222?selectedIssue=
1665147
Resolves: https://scan5.scan.coverity.com/#/project-view/65248/10222?selectedIssue=
1665148
Resolves: https://scan5.scan.coverity.com/#/project-view/65248/10222?selectedIssue=
1665150
Resolves: https://scan5.scan.coverity.com/#/project-view/65248/10222?selectedIssue=
1665152
Resolves: https://scan5.scan.coverity.com/#/project-view/65248/10222?selectedIssue=
1665153
Resolves: https://scan5.scan.coverity.com/#/project-view/65248/10222?selectedIssue=
1665156
Resolves: https://scan5.scan.coverity.com/#/project-view/65248/10222?selectedIssue=
1665157
Resolves: https://scan5.scan.coverity.com/#/project-view/65248/10222?selectedIssue=
1665158
Resolves: https://scan5.scan.coverity.com/#/project-view/65248/10222?selectedIssue=
1665159
Resolves: https://scan5.scan.coverity.com/#/project-view/65248/10222?selectedIssue=
1665160
Resolves: https://scan5.scan.coverity.com/#/project-view/65248/10222?selectedIssue=
1665162
References: https://github.com/openssl/project/issues/1362
Signed-off-by: Eugene Syromiatnikov <esyr@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28405)
ossl_ssize_t z;
ptrdiff_t t;
} n = { 0 }, std_n = { 0 };
+ uint64_t n_val, std_n_val;
#if defined(OPENSSL_SYS_WINDOWS)
/*
std_ret = snprintf(std_buf, sizeof(std_buf), data->format, \
data->arg1.i, data->arg2.i, &std_n.field_); \
} \
- n.val = n.field_; \
- std_n.val = std_n.field_; \
+ n_val = n.field_; \
+ std_n_val = std_n.field_; \
} while (0)
case AT_CHAR:
DO_PRINT(hh);
}
if (!TEST_str_eq(bio_buf, data->expected)
- + !TEST_uint64_t_eq(n.val, data->exp_n)
+ + !TEST_uint64_t_eq(n_val, data->exp_n)
+ !TEST_int_eq(bio_ret, exp_ret)) {
TEST_note("Format: \"%s\"", data->format);
return 0;
*/
if (!data->skip_libc_check) {
if (!TEST_str_eq(bio_buf, std_buf)
- + !TEST_uint64_t_eq(n.val, std_n.val)
+ + !TEST_uint64_t_eq(n_val, std_n_val)
+ !(data->skip_libc_ret_check || TEST_int_eq(bio_ret, std_ret))) {
TEST_note("Format: \"%s\"", data->format);
#if defined(OPENSSL_STRICT_LIBC_PRINTF_CHECK)