Bug Summary

File:lib/ext/safe_renegotiation.c
Location:line 275, column 5
Description:Value stored to 'priv' is never read

Annotated Source Code

1/*
2 * Copyright (C) 2009-2010, 2012 Free Software Foundation, Inc.
3 *
4 * Author: Steve Dispensa (<dispensa@phonefactor.com>)
5 *
6 * This file is part of GnuTLS.
7 *
8 * The GnuTLS is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 3 of
11 * the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>
20 *
21 */
22
23#include <gnutls_int.h>
24#include <ext/safe_renegotiation.h>
25#include <gnutls_errors.h>
26
27
28static int _gnutls_sr_recv_params (gnutls_session_t state,
29 const opaque * data, size_t data_size);
30static int _gnutls_sr_send_params (gnutls_session_t state, gnutls_buffer_st*);
31static void _gnutls_sr_deinit_data (extension_priv_data_t priv);
32
33extension_entry_st ext_mod_sr = {
34 .name = "SAFE RENEGOTIATION",
35 .type = GNUTLS_EXTENSION_SAFE_RENEGOTIATION,
36 .parse_type = GNUTLS_EXT_MANDATORY,
37
38 .recv_func = _gnutls_sr_recv_params,
39 .send_func = _gnutls_sr_send_params,
40 .pack_func = NULL((void*)0),
41 .unpack_func = NULL((void*)0),
42 .deinit_func = _gnutls_sr_deinit_data,
43};
44
45int
46_gnutls_ext_sr_finished (gnutls_session_t session, void *vdata,
47 size_t vdata_size, int dir)
48{
49 int ret;
50 sr_ext_st *priv;
51 extension_priv_data_t epriv;
52
53 if (session->internals.priorities.sr == SR_DISABLED)
54 {
55 return 0;
56 }
57
58 ret = _gnutls_ext_get_session_data (session,
59 GNUTLS_EXTENSION_SAFE_RENEGOTIATION,
60 &epriv);
61 if (ret < 0)
62 {
63 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "safe_renegotiation.c",63); } while(0
);
;
64 return ret;
65 }
66 priv = epriv.ptr;
67
68 /* Save data for safe renegotiation.
69 */
70 if (vdata_size > MAX_VERIFY_DATA_SIZE36)
71 {
72 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "safe_renegotiation.c",72); } while(0
);
;
73 return GNUTLS_E_INTERNAL_ERROR-59;
74 }
75
76 if ((session->security_parameters.entity == GNUTLS_CLIENT(1<<1) && dir == 0) ||
77 (session->security_parameters.entity == GNUTLS_SERVER1 && dir == 1))
78 {
79 priv->client_verify_data_len = vdata_size;
80 memcpy (priv->client_verify_data, vdata, vdata_size);
81 }
82 else
83 {
84 priv->server_verify_data_len = vdata_size;
85 memcpy (priv->server_verify_data, vdata, vdata_size);
86 }
87
88 return 0;
89}
90
91int
92_gnutls_ext_sr_verify (gnutls_session_t session)
93{
94 int ret;
95 sr_ext_st *priv = NULL((void*)0);
96 extension_priv_data_t epriv;
97
98 if (session->internals.priorities.sr == SR_DISABLED)
99 {
100 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "safe_renegotiation.c",100); } while(
0);
;
101 return 0;
102 }
103
104 ret = _gnutls_ext_get_session_data (session,
105 GNUTLS_EXTENSION_SAFE_RENEGOTIATION,
106 &epriv);
107 if (ret >= 0)
108 priv = epriv.ptr;
109
110 /* Safe renegotiation */
111
112 if (priv && priv->safe_renegotiation_received)
113 {
114 if ((priv->ri_extension_data_len < priv->client_verify_data_len) ||
115 (memcmp (priv->ri_extension_data,
116 priv->client_verify_data, priv->client_verify_data_len)))
117 {
118 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "safe_renegotiation.c",118); } while(
0);
;
119 _gnutls_handshake_log ("HSK[%p]: Safe renegotiation failed [1]\n",do { if (__builtin_expect((_gnutls_log_level >= 3), 0)) _gnutls_log
( 3, "HSK[%p]: Safe renegotiation failed [1]\n", session); } while
(0)
120 session)do { if (__builtin_expect((_gnutls_log_level >= 3), 0)) _gnutls_log
( 3, "HSK[%p]: Safe renegotiation failed [1]\n", session); } while
(0)
;
121 return GNUTLS_E_SAFE_RENEGOTIATION_FAILED-107;
122 }
123
124 if (session->security_parameters.entity == GNUTLS_CLIENT(1<<1))
125 {
126 if ((priv->ri_extension_data_len !=
127 priv->client_verify_data_len + priv->server_verify_data_len) ||
128 memcmp (priv->ri_extension_data + priv->client_verify_data_len,
129 priv->server_verify_data,
130 priv->server_verify_data_len) != 0)
131 {
132 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "safe_renegotiation.c",132); } while(
0);
;
133 _gnutls_handshake_logdo { if (__builtin_expect((_gnutls_log_level >= 3), 0)) _gnutls_log
( 3, "HSK[%p]: Safe renegotiation failed [2]\n", session); } while
(0)
134 ("HSK[%p]: Safe renegotiation failed [2]\n", session)do { if (__builtin_expect((_gnutls_log_level >= 3), 0)) _gnutls_log
( 3, "HSK[%p]: Safe renegotiation failed [2]\n", session); } while
(0)
;
135 return GNUTLS_E_SAFE_RENEGOTIATION_FAILED-107;
136 }
137 }
138 else /* Make sure there are 0 extra bytes */
139 {
140 if (priv->ri_extension_data_len != priv->client_verify_data_len)
141 {
142 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "safe_renegotiation.c",142); } while(
0);
;
143 _gnutls_handshake_logdo { if (__builtin_expect((_gnutls_log_level >= 3), 0)) _gnutls_log
( 3, "HSK[%p]: Safe renegotiation failed [3]\n", session); } while
(0)
144 ("HSK[%p]: Safe renegotiation failed [3]\n", session)do { if (__builtin_expect((_gnutls_log_level >= 3), 0)) _gnutls_log
( 3, "HSK[%p]: Safe renegotiation failed [3]\n", session); } while
(0)
;
145 return GNUTLS_E_SAFE_RENEGOTIATION_FAILED-107;
146 }
147 }
148
149 _gnutls_handshake_log ("HSK[%p]: Safe renegotiation succeeded\n",do { if (__builtin_expect((_gnutls_log_level >= 3), 0)) _gnutls_log
( 3, "HSK[%p]: Safe renegotiation succeeded\n", session); } while
(0)
150 session)do { if (__builtin_expect((_gnutls_log_level >= 3), 0)) _gnutls_log
( 3, "HSK[%p]: Safe renegotiation succeeded\n", session); } while
(0)
;
151 }
152 else /* safe renegotiation not received... */
153 {
154 if (priv && priv->connection_using_safe_renegotiation)
155 {
156 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "safe_renegotiation.c",156); } while(
0);
;
157 _gnutls_handshake_logdo { if (__builtin_expect((_gnutls_log_level >= 3), 0)) _gnutls_log
( 3, "HSK[%p]: Peer previously asked for safe renegotiation\n"
, session); } while(0)
158 ("HSK[%p]: Peer previously asked for safe renegotiation\n",do { if (__builtin_expect((_gnutls_log_level >= 3), 0)) _gnutls_log
( 3, "HSK[%p]: Peer previously asked for safe renegotiation\n"
, session); } while(0)
159 session)do { if (__builtin_expect((_gnutls_log_level >= 3), 0)) _gnutls_log
( 3, "HSK[%p]: Peer previously asked for safe renegotiation\n"
, session); } while(0)
;
160 return GNUTLS_E_SAFE_RENEGOTIATION_FAILED-107;
161 }
162
163 /* Clients can't tell if it's an initial negotiation */
164 if (session->internals.initial_negotiation_completed)
165 {
166 if (session->internals.priorities.sr < SR_PARTIAL)
167 {
168 _gnutls_handshake_logdo { if (__builtin_expect((_gnutls_log_level >= 3), 0)) _gnutls_log
( 3, "HSK[%p]: Allowing unsafe (re)negotiation\n", session); }
while(0)
169 ("HSK[%p]: Allowing unsafe (re)negotiation\n", session)do { if (__builtin_expect((_gnutls_log_level >= 3), 0)) _gnutls_log
( 3, "HSK[%p]: Allowing unsafe (re)negotiation\n", session); }
while(0)
;
170 }
171 else
172 {
173 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "safe_renegotiation.c",173); } while(
0);
;
174 _gnutls_handshake_logdo { if (__builtin_expect((_gnutls_log_level >= 3), 0)) _gnutls_log
( 3, "HSK[%p]: Denying unsafe (re)negotiation\n", session); }
while(0)
175 ("HSK[%p]: Denying unsafe (re)negotiation\n", session)do { if (__builtin_expect((_gnutls_log_level >= 3), 0)) _gnutls_log
( 3, "HSK[%p]: Denying unsafe (re)negotiation\n", session); }
while(0)
;
176 return GNUTLS_E_UNSAFE_RENEGOTIATION_DENIED-108;
177 }
178 }
179 else
180 {
181 if (session->internals.priorities.sr < SR_SAFE)
182 {
183 _gnutls_handshake_logdo { if (__builtin_expect((_gnutls_log_level >= 3), 0)) _gnutls_log
( 3, "HSK[%p]: Allowing unsafe initial negotiation\n", session
); } while(0)
184 ("HSK[%p]: Allowing unsafe initial negotiation\n", session)do { if (__builtin_expect((_gnutls_log_level >= 3), 0)) _gnutls_log
( 3, "HSK[%p]: Allowing unsafe initial negotiation\n", session
); } while(0)
;
185 }
186 else
187 {
188 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "safe_renegotiation.c",188); } while(
0);
;
189 _gnutls_handshake_logdo { if (__builtin_expect((_gnutls_log_level >= 3), 0)) _gnutls_log
( 3, "HSK[%p]: Denying unsafe initial negotiation\n", session
); } while(0)
190 ("HSK[%p]: Denying unsafe initial negotiation\n", session)do { if (__builtin_expect((_gnutls_log_level >= 3), 0)) _gnutls_log
( 3, "HSK[%p]: Denying unsafe initial negotiation\n", session
); } while(0)
;
191 return GNUTLS_E_SAFE_RENEGOTIATION_FAILED-107;
192 }
193 }
194 }
195
196 return 0;
197}
198
199/* if a server received the special ciphersuite.
200 */
201int
202_gnutls_ext_sr_recv_cs (gnutls_session_t session)
203{
204 int ret, set = 0;
205 sr_ext_st *priv;
206 extension_priv_data_t epriv;
207
208 ret = _gnutls_ext_get_session_data (session,
209 GNUTLS_EXTENSION_SAFE_RENEGOTIATION,
210 &epriv);
211 if (ret < 0)
212 {
213 set = 1;
214 }
215 else if (ret < 0)
216 {
217 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "safe_renegotiation.c",217); } while(
0);
;
218 return ret;
219 }
220
221 if (set != 0)
222 {
223 priv = gnutls_calloc (1, sizeof (*priv));
224 if (priv == NULL((void*)0))
225 {
226 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "safe_renegotiation.c",226); } while(
0);
;
227 return GNUTLS_E_MEMORY_ERROR-25;
228 }
229 epriv.ptr = priv;
230 }
231 else
232 priv = epriv.ptr;
233
234 priv->safe_renegotiation_received = 1;
235 priv->connection_using_safe_renegotiation = 1;
236
237 if (set != 0)
238 _gnutls_ext_set_session_data (session,
239 GNUTLS_EXTENSION_SAFE_RENEGOTIATION, epriv);
240
241 return 0;
242}
243
244int
245_gnutls_ext_sr_send_cs (gnutls_session_t session)
246{
247 int ret, set = 0;
248 sr_ext_st *priv;
249 extension_priv_data_t epriv;
250
251 ret = _gnutls_ext_get_session_data (session,
252 GNUTLS_EXTENSION_SAFE_RENEGOTIATION,
253 &epriv);
254 if (ret < 0)
255 {
256 set = 1;
257 }
258 else if (ret < 0)
259 {
260 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "safe_renegotiation.c",260); } while(
0);
;
261 return ret;
262 }
263
264 if (set != 0)
265 {
266 priv = gnutls_calloc (1, sizeof (*priv));
267 if (priv == NULL((void*)0))
268 {
269 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "safe_renegotiation.c",269); } while(
0);
;
270 return GNUTLS_E_MEMORY_ERROR-25;
271 }
272 epriv.ptr = priv;
273 }
274 else
275 priv = epriv.ptr;
Value stored to 'priv' is never read
276
277 if (set != 0)
278 _gnutls_ext_set_session_data (session,
279 GNUTLS_EXTENSION_SAFE_RENEGOTIATION, epriv);
280
281 return 0;
282}
283
284static int
285_gnutls_sr_recv_params (gnutls_session_t session,
286 const opaque * data, size_t _data_size)
287{
288 int len = data[0];
289 ssize_t data_size = _data_size;
290 sr_ext_st *priv;
291 extension_priv_data_t epriv;
292 int set = 0, ret;
293
294 DECR_LEN (data_size, len + 1 /* count the first byte and payload */ )do { data_size-=len + 1; if (data_size<0) {do { if (__builtin_expect
((_gnutls_log_level >= 2), 0)) _gnutls_log( 2, "ASSERT: %s:%d\n"
, "safe_renegotiation.c",294); } while(0);; return -9;} } while
(0)
;
295
296 if (session->internals.priorities.sr == SR_DISABLED)
297 {
298 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "safe_renegotiation.c",298); } while(
0);
;
299 return 0;
300 }
301
302 ret = _gnutls_ext_get_session_data (session,
303 GNUTLS_EXTENSION_SAFE_RENEGOTIATION,
304 &epriv);
305 if (ret < 0 && session->security_parameters.entity == GNUTLS_SERVER1)
306 {
307 set = 1;
308 }
309 else if (ret < 0)
310 {
311 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "safe_renegotiation.c",311); } while(
0);
;
312 return ret;
313 }
314
315 if (set != 0)
316 {
317 priv = gnutls_calloc (1, sizeof (*priv));
318 if (priv == NULL((void*)0))
319 {
320 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "safe_renegotiation.c",320); } while(
0);
;
321 return GNUTLS_E_MEMORY_ERROR-25;
322 }
323 epriv.ptr = priv;
324 }
325 else
326 priv = epriv.ptr;
327
328 /* It is not legal to receive this extension on a renegotiation and
329 * not receive it on the initial negotiation.
330 */
331 if (session->internals.initial_negotiation_completed != 0 &&
332 priv->connection_using_safe_renegotiation == 0)
333 {
334 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "safe_renegotiation.c",334); } while(
0);
;
335 return GNUTLS_E_SAFE_RENEGOTIATION_FAILED-107;
336 }
337
338 if (len > sizeof (priv->ri_extension_data))
339 {
340 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "safe_renegotiation.c",340); } while(
0);
;
341 return GNUTLS_E_SAFE_RENEGOTIATION_FAILED-107;
342 }
343
344 if (len > 0)
345 memcpy (priv->ri_extension_data, &data[1], len);
346 priv->ri_extension_data_len = len;
347
348 /* "safe renegotiation received" means on *this* handshake; "connection using
349 * safe renegotiation" means that the initial hello received on the connection
350 * indicated safe renegotiation.
351 */
352 priv->safe_renegotiation_received = 1;
353 priv->connection_using_safe_renegotiation = 1;
354
355 if (set != 0)
356 _gnutls_ext_set_session_data (session,
357 GNUTLS_EXTENSION_SAFE_RENEGOTIATION, epriv);
358 return 0;
359}
360
361static int
362_gnutls_sr_send_params (gnutls_session_t session, gnutls_buffer_st* extdata)
363{
364 /* The format of this extension is a one-byte length of verify data followed
365 * by the verify data itself. Note that the length byte does not include
366 * itself; IOW, empty verify data is represented as a length of 0. That means
367 * the minimum extension is one byte: 0x00.
368 */
369 sr_ext_st *priv;
370 int ret, set = 0, len;
371 extension_priv_data_t epriv;
372 size_t init_length = extdata->length;
373
374 if (session->internals.priorities.sr == SR_DISABLED)
375 {
376 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "safe_renegotiation.c",376); } while(
0);
;
377 return 0;
378 }
379
380 ret = _gnutls_ext_get_session_data (session,
381 GNUTLS_EXTENSION_SAFE_RENEGOTIATION,
382 &epriv);
383 if (ret < 0)
384 {
385 set = 1;
386 }
387
388 if (set != 0)
389 {
390 priv = gnutls_calloc (1, sizeof (*priv));
391 if (priv == NULL((void*)0))
392 {
393 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "safe_renegotiation.c",393); } while(
0);
;
394 return GNUTLS_E_MEMORY_ERROR-25;
395 }
396 epriv.ptr = priv;
397
398 _gnutls_ext_set_session_data (session,
399 GNUTLS_EXTENSION_SAFE_RENEGOTIATION,
400 epriv);
401 }
402 else
403 priv = epriv.ptr;
404
405 /* Always offer the extension if we're a client */
406 if (priv->connection_using_safe_renegotiation ||
407 session->security_parameters.entity == GNUTLS_CLIENT(1<<1))
408 {
409 len = priv->client_verify_data_len;
410 if (session->security_parameters.entity == GNUTLS_SERVER1)
411 len += priv->server_verify_data_len;
412
413 ret = _gnutls_buffer_append_prefix(extdata, 8, len);
414 if (ret < 0)
415 return gnutls_assert_val(ret)gnutls_assert_val_int(ret, "safe_renegotiation.c", 415);
416
417 ret = _gnutls_buffer_append_data(extdata, priv->client_verify_data,
418 priv->client_verify_data_len);
419 if (ret < 0)
420 return gnutls_assert_val(ret)gnutls_assert_val_int(ret, "safe_renegotiation.c", 420);
421
422 if (session->security_parameters.entity == GNUTLS_SERVER1)
423 {
424 ret = _gnutls_buffer_append_data(extdata, priv->server_verify_data,
425 priv->server_verify_data_len);
426 if (ret < 0)
427 return gnutls_assert_val(ret)gnutls_assert_val_int(ret, "safe_renegotiation.c", 427);
428 }
429 }
430 else
431 return 0;
432
433 return extdata->length - init_length;
434}
435
436static void
437_gnutls_sr_deinit_data (extension_priv_data_t priv)
438{
439 gnutls_free (priv.ptr);
440}
441
442/**
443 * gnutls_safe_renegotiation_status:
444 * @session: is a #gnutls_session_t structure.
445 *
446 * Can be used to check whether safe renegotiation is being used
447 * in the current session.
448 *
449 * Returns: 0 when safe renegotiation is not used and non (0) when
450 * safe renegotiation is used.
451 *
452 * Since: 2.10.0
453 **/
454int
455gnutls_safe_renegotiation_status (gnutls_session_t session)
456{
457 int ret;
458 sr_ext_st *priv;
459 extension_priv_data_t epriv;
460
461 ret = _gnutls_ext_get_session_data (session,
462 GNUTLS_EXTENSION_SAFE_RENEGOTIATION,
463 &epriv);
464 if (ret < 0)
465 {
466 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "safe_renegotiation.c",466); } while(
0);
;
467 return 0;
468 }
469 priv = epriv.ptr;
470
471 return priv->connection_using_safe_renegotiation;
472}