Debian Codegraph @

gcc/testsuite/c-c++-common/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early-O2.c

raw
1 /* Reduced from haproxy's src/ssl_sample.c */
2
3 /* { dg-require-effective-target ptr_eq_long } */
4 /* { dg-additional-options "-O2 -Wno-analyzer-symbol-too-complex" } */
5
6 union sample_value {
7 long long int sint;
8 /* [...snip...] */
9 };
10
11 struct sample_data {
12 int type;
13 union sample_value u;
14 };
15
16 enum {
17 /* [...snip...] */
18 SMP_T_BOOL,
19 /* [...snip...] */
20 };
21 struct sample {
22 unsigned int flags;
23 struct sample_data data;
24 /* [...snip...] */
25 struct session *sess;
26 struct stream *strm;
27 /* [...snip...] */
28 };
29 struct arg {
30 /* [...snip...] */
31 };
32 enum obj_type {
33 OBJ_TYPE_NONE = 0,
34 /* [...snip...] */
35 OBJ_TYPE_CONN,
36 /* [...snip...] */
37 OBJ_TYPE_CHECK,
38 OBJ_TYPE_ENTRIES
39 };
40 enum {
41 /* [...snip...] */
42 CO_FL_EARLY_SSL_HS = 0x00004000,
43 CO_FL_EARLY_DATA = 0x00008000,
44 /* [...snip...] */
45 CO_FL_SSL_WAIT_HS = 0x08000000,
46 /* [...snip...] */
47 };
48 struct connection {
49 enum obj_type obj_type;
50 unsigned char err_code;
51 /* [...snip...] */
52 unsigned int flags;
53 /* [...snip...] */
54 };
55
56 static inline enum obj_type obj_type(const enum obj_type *t)
57 {
58 if (!t || *t >= OBJ_TYPE_ENTRIES)
59 return OBJ_TYPE_NONE;
60 return *t;
61 }
62 static inline struct connection *__objt_conn(enum obj_type *t)
63 {
64 return ((struct connection *)(((char *)(t)) - ((long)&((struct connection *)0)->obj_type))); /* { dg-bogus "may result in an unaligned pointer value" "Fixed in r14-6517-gb7e4a4c626e" { target short_enums } } */
65 }
66 static inline struct connection *objt_conn(enum obj_type *t)
67 {
68 if (!t || *t != OBJ_TYPE_CONN)
69 return (struct connection *)((void *)0);
70 return __objt_conn(t);
71 }
72 struct session {
73 /* [...snip...] */
74 enum obj_type *origin;
75 /* [...snip...] */
76 };
77 typedef struct ssl_st SSL;
78 SSL *ssl_sock_get_ssl_object(struct connection *conn);
79
80 /*****************************************************************************/
81
82 int
83 smp_fetch_ssl_fc_has_early(const struct arg *args, struct sample *smp, const char *kw, void *Private)
84 {
85 SSL *ssl;
86 struct connection *conn;
87
88 conn = objt_conn(smp->sess->origin);
89 ssl = ssl_sock_get_ssl_object(conn);
90 if (!ssl)
91 return 0;
92
93 smp->flags = 0;
94 smp->data.type = SMP_T_BOOL;
95 smp->data.u.sint = ((conn->flags & CO_FL_EARLY_DATA) && /* { dg-bogus "dereference of NULL" "PR analyzer/108251" { xfail *-*-*} } */
96 (conn->flags & (CO_FL_EARLY_SSL_HS | CO_FL_SSL_WAIT_HS))) ? 1 : 0;
97
98 return 1;
99 }