File: | programs/pluto/ikev2_cp.c |
Warning: | line 67, column 38 Dereference of null pointer (loaded from variable 'ip') |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* IKEv2 Configuration Payload, for Libreswan | |||
2 | * | |||
3 | * Copyright (C) 2007-2008 Michael Richardson <mcr@xelerance.com> | |||
4 | * Copyright (C) 2008-2011 Paul Wouters <paul@xelerance.com> | |||
5 | * Copyright (C) 2008 Antony Antony <antony@xelerance.com> | |||
6 | * Copyright (C) 2008-2009 David McCullough <david_mccullough@securecomputing.com> | |||
7 | * Copyright (C) 2010,2012 Avesh Agarwal <avagarwa@redhat.com> | |||
8 | * Copyright (C) 2010-2019 Tuomo Soini <tis@foobar.fi | |||
9 | * Copyright (C) 2012-2019 Paul Wouters <pwouters@redhat.com> | |||
10 | * Copyright (C) 2012-2018 Antony Antony <antony@phenome.org> | |||
11 | * Copyright (C) 2013-2019 D. Hugh Redelmeier <hugh@mimosa.com> | |||
12 | * Copyright (C) 2013 David McCullough <ucdevel@gmail.com> | |||
13 | * Copyright (C) 2013 Matt Rogers <mrogers@redhat.com> | |||
14 | * Copyright (C) 2015-2019 Andrew Cagney <cagney@gnu.org> | |||
15 | * Copyright (C) 2017-2018 Sahana Prasad <sahana.prasad07@gmail.com> | |||
16 | * Copyright (C) 2017-2018 Vukasin Karadzic <vukasin.karadzic@gmail.com> | |||
17 | * Copyright (C) 2017 Mayank Totale <mtotale@gmail.com> | |||
18 | * Copyright (C) 2020 Yulia Kuzovkova <ukuzovkova@gmail.com> | |||
19 | * | |||
20 | * This program is free software; you can redistribute it and/or modify it | |||
21 | * under the terms of the GNU General Public License as published by the | |||
22 | * Free Software Foundation; either version 2 of the License, or (at your | |||
23 | * option) any later version. See <https://www.gnu.org/licenses/gpl2.txt>. | |||
24 | * | |||
25 | * This program is distributed in the hope that it will be useful, but | |||
26 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |||
27 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |||
28 | * for more details. | |||
29 | */ | |||
30 | ||||
31 | #include "ip_info.h" | |||
32 | ||||
33 | #include "defs.h" | |||
34 | #include "demux.h" | |||
35 | #include "connections.h" | |||
36 | #include "state.h" | |||
37 | #include "log.h" | |||
38 | ||||
39 | #include "ikev2_cp.h" | |||
40 | ||||
41 | /* Misleading name, also used for NULL sized type's */ | |||
42 | static stf_status ikev2_ship_cp_attr_ip(uint16_t type, ip_address *ip, | |||
43 | const char *story, struct pbs_outpacket_byte_stream *outpbs) | |||
44 | { | |||
45 | struct pbs_outpacket_byte_stream a_pbs; | |||
46 | ||||
47 | struct ikev2_cp_attribute attr = { | |||
48 | .type = type, | |||
49 | }; | |||
50 | ||||
51 | /* could be NULL */ | |||
52 | const struct ip_info *afi = address_type(ip); | |||
53 | ||||
54 | if (afi == NULL((void*)0)) { | |||
55 | attr.len = 0; | |||
56 | } else if (afi == &ipv6_info) { | |||
57 | attr.len = INTERNAL_IP6_ADDRESS_SIZE17; /* RFC hack to append IPv6 prefix len */ | |||
58 | } else { | |||
59 | attr.len = address_type(ip)->ip_size; | |||
60 | } | |||
61 | ||||
62 | if (!out_struct(&attr, &ikev2_cp_attribute_desc, outpbs, | |||
63 | &a_pbs)) | |||
64 | return STF_INTERNAL_ERROR; | |||
65 | ||||
66 | if (attr.len
| |||
67 | diag_t d = pbs_out_address(&a_pbs, *ip, story); | |||
| ||||
68 | if (d != NULL((void*)0)) { | |||
69 | llog_diag(RC_LOG_SERIOUS, a_pbs.outs_logger, &d, "%s", ""); | |||
70 | return STF_INTERNAL_ERROR; | |||
71 | } | |||
72 | } | |||
73 | ||||
74 | if (attr.len == INTERNAL_IP6_ADDRESS_SIZE17) { /* IPv6 address add prefix */ | |||
75 | uint8_t ipv6_prefix_len = INTERNL_IP6_PREFIX_LEN128; | |||
76 | diag_t d = pbs_out_raw(&a_pbs, &ipv6_prefix_len, sizeof(uint8_t), "INTERNL_IP6_PREFIX_LEN"); | |||
77 | if (d != NULL((void*)0)) { | |||
78 | llog_diag(RC_LOG_SERIOUS, outpbs->outs_logger, &d, "%s", ""); | |||
79 | return STF_INTERNAL_ERROR; | |||
80 | } | |||
81 | } | |||
82 | ||||
83 | close_output_pbs(&a_pbs); | |||
84 | return STF_OK; | |||
85 | } | |||
86 | ||||
87 | static stf_status ikev2_ship_cp_attr_str(uint16_t type, char *str, | |||
88 | const char *story, pb_stream *outpbs) | |||
89 | { | |||
90 | pb_stream a_pbs; | |||
91 | struct ikev2_cp_attribute attr = { | |||
92 | .type = type, | |||
93 | .len = (str == NULL((void*)0)) ? 0 : strlen(str), | |||
94 | }; | |||
95 | ||||
96 | if (!out_struct(&attr, &ikev2_cp_attribute_desc, outpbs, | |||
97 | &a_pbs)) | |||
98 | return STF_INTERNAL_ERROR; | |||
99 | ||||
100 | if (attr.len > 0) { | |||
101 | diag_t d = pbs_out_raw(&a_pbs, str, attr.len, story); | |||
102 | if (d != NULL((void*)0)) { | |||
103 | llog_diag(RC_LOG_SERIOUS, outpbs->outs_logger, &d, "%s", ""); | |||
104 | return STF_INTERNAL_ERROR; | |||
105 | } | |||
106 | } | |||
107 | ||||
108 | close_output_pbs(&a_pbs); | |||
109 | return STF_OK; | |||
110 | } | |||
111 | ||||
112 | /* | |||
113 | * CHILD is asking for configuration; hence log against child. | |||
114 | */ | |||
115 | ||||
116 | bool_Bool emit_v2_child_configuration_payload(const struct child_sa *child, struct pbs_outpacket_byte_stream *outpbs) | |||
117 | { | |||
118 | struct connection *c = child->sa.st_connection; | |||
119 | pb_stream cp_pbs; | |||
120 | bool_Bool cfg_reply = c->spd.that.has_lease; | |||
121 | struct ikev2_cp cp = { | |||
122 | .isacp_critical = ISAKMP_PAYLOAD_NONCRITICAL0x00, | |||
123 | .isacp_type = cfg_reply ? IKEv2_CP_CFG_REPLY : IKEv2_CP_CFG_REQUEST, | |||
| ||||
124 | }; | |||
125 | ||||
126 | dbg("Send Configuration Payload %s ",{ if ((cur_debugging & (((lset_t)1 << (DBG_BASE_IX) )))) { DBG_log("Send Configuration Payload %s ", cfg_reply ? "reply" : "request"); } } | |||
127 | cfg_reply ? "reply" : "request"){ if ((cur_debugging & (((lset_t)1 << (DBG_BASE_IX) )))) { DBG_log("Send Configuration Payload %s ", cfg_reply ? "reply" : "request"); } }; | |||
128 | ||||
129 | if (!out_struct(&cp, &ikev2_cp_desc, outpbs, &cp_pbs)) | |||
130 | return false0; | |||
131 | ||||
132 | if (cfg_reply
| |||
133 | ip_address that_client_address = selector_prefix(c->spd.that.client); | |||
134 | ikev2_ship_cp_attr_ip(selector_type(&c->spd.that.client) == &ipv4_info ? | |||
135 | IKEv2_INTERNAL_IP4_ADDRESS : IKEv2_INTERNAL_IP6_ADDRESS, | |||
136 | &that_client_address, "Internal IP Address", &cp_pbs); | |||
137 | ||||
138 | if (c->modecfg_dns != NULL((void*)0)) { | |||
139 | char *ipstr; | |||
140 | ||||
141 | ipstr = strtok(c->modecfg_dns, ", "); | |||
142 | while (ipstr != NULL((void*)0)) { | |||
143 | if (strchr(ipstr, '.') != NULL((void*)0)) { | |||
144 | ip_address ip; | |||
145 | err_t e = ttoaddress_num(shunk1(ipstr), &ipv4_info, &ip); | |||
146 | if (e != NULL((void*)0)) { | |||
147 | log_state(RC_LOG_SERIOUS, &child->sa, | |||
148 | "Ignored bogus DNS IP address '%s'", ipstr); | |||
149 | } else { | |||
150 | if (ikev2_ship_cp_attr_ip(IKEv2_INTERNAL_IP4_DNS, &ip, | |||
151 | "IP4_DNS", &cp_pbs) != STF_OK) | |||
152 | return false0; | |||
153 | } | |||
154 | } else if (strchr(ipstr, ':') != NULL((void*)0)) { | |||
155 | ip_address ip; | |||
156 | err_t e = ttoaddress_num(shunk1(ipstr), &ipv6_info, &ip); | |||
157 | if (e != NULL((void*)0)) { | |||
158 | log_state(RC_LOG_SERIOUS, &child->sa, | |||
159 | "Ignored bogus DNS IP address '%s'", ipstr); | |||
160 | } else { | |||
161 | if (ikev2_ship_cp_attr_ip(IKEv2_INTERNAL_IP6_DNS, &ip, | |||
162 | "IP6_DNS", &cp_pbs) != STF_OK) | |||
163 | return false0; | |||
164 | } | |||
165 | } else { | |||
166 | log_state(RC_LOG_SERIOUS, &child->sa, | |||
167 | "Ignored bogus DNS IP address '%s'", ipstr); | |||
168 | } | |||
169 | ipstr = strtok(NULL((void*)0), ", "); | |||
170 | } | |||
171 | } | |||
172 | ||||
173 | if (c->modecfg_domains != NULL((void*)0)) { | |||
174 | char *domain; | |||
175 | ||||
176 | domain = strtok(c->modecfg_domains, ", "); | |||
177 | while (domain != NULL((void*)0)) { | |||
178 | if (ikev2_ship_cp_attr_str(IKEv2_INTERNAL_DNS_DOMAIN, domain, | |||
179 | "IKEv2_INTERNAL_DNS_DOMAIN", &cp_pbs) != STF_OK) | |||
180 | return false0; | |||
181 | domain = strtok(NULL((void*)0), ", "); | |||
182 | } | |||
183 | } | |||
184 | } else { /* cfg request */ | |||
185 | ikev2_ship_cp_attr_ip(IKEv2_INTERNAL_IP4_ADDRESS, NULL((void*)0), "IPV4 Address", &cp_pbs); | |||
186 | ikev2_ship_cp_attr_ip(IKEv2_INTERNAL_IP4_DNS, NULL((void*)0), "DNSv4", &cp_pbs); | |||
187 | ikev2_ship_cp_attr_ip(IKEv2_INTERNAL_IP6_ADDRESS, NULL((void*)0), "IPV6 Address", &cp_pbs); | |||
188 | ikev2_ship_cp_attr_ip(IKEv2_INTERNAL_IP6_DNS, NULL((void*)0), "DNSv6", &cp_pbs); | |||
189 | ikev2_ship_cp_attr_ip(IKEv2_INTERNAL_DNS_DOMAIN, NULL((void*)0), "Domain", &cp_pbs); | |||
190 | } | |||
191 | ||||
192 | close_output_pbs(&cp_pbs); | |||
193 | return true1; | |||
194 | } |