* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 2005 Nokia. All rights reserved.
*
- * Licensed under the OpenSSL license (the "License"). You may not use
+ * Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
#include <stdio.h>
#include <stdlib.h>
-#include "ssl_locl.h"
+#include "ssl_local.h"
#include <openssl/asn1t.h>
#include <openssl/x509.h>
/* Initialise OCTET STRING from buffer and length */
static void ssl_session_oinit(ASN1_OCTET_STRING **dest, ASN1_OCTET_STRING *os,
- unsigned char *data, size_t len)
+ const unsigned char *data, size_t len)
{
- os->data = data;
+ os->data = (unsigned char *)data; /* justified cast: data is not modified */
os->length = (int)len;
os->flags = 0;
*dest = os;
/* Initialise OCTET STRING from string */
static void ssl_session_sinit(ASN1_OCTET_STRING **dest, ASN1_OCTET_STRING *os,
- char *data)
+ const char *data)
{
if (data != NULL)
- ssl_session_oinit(dest, os, (unsigned char *)data, strlen(data));
+ ssl_session_oinit(dest, os, (const unsigned char *)data, strlen(data));
else
*dest = NULL;
}
-int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
+int i2d_SSL_SESSION(const SSL_SESSION *in, unsigned char **pp)
{
SSL_SESSION_ASN1 as;
if (as == NULL)
goto err;
- if (!a || !*a) {
+ if (a == NULL || *a == NULL) {
ret = SSL_SESSION_new();
if (ret == NULL)
goto err;
ret->ext.tick_lifetime_hint = (unsigned long)as->tlsext_tick_lifetime_hint;
ret->ext.tick_age_add = as->tlsext_tick_age_add;
- if (as->tlsext_tick) {
+ OPENSSL_free(ret->ext.tick);
+ if (as->tlsext_tick != NULL) {
ret->ext.tick = as->tlsext_tick->data;
ret->ext.ticklen = as->tlsext_tick->length;
as->tlsext_tick->data = NULL;
ret->flags = (int32_t)as->flags;
ret->ext.max_early_data = as->max_early_data;
+ OPENSSL_free(ret->ext.alpn_selected);
if (as->alpn_selected != NULL) {
- if (!ssl_session_strndup((char **)&ret->ext.alpn_selected,
- as->alpn_selected))
- goto err;
+ ret->ext.alpn_selected = as->alpn_selected->data;
ret->ext.alpn_selected_len = as->alpn_selected->length;
+ as->alpn_selected->data = NULL;
} else {
ret->ext.alpn_selected = NULL;
ret->ext.alpn_selected_len = 0;
ret->ext.max_fragment_len_mode = as->tlsext_max_fragment_len_mode;
+ OPENSSL_free(ret->ticket_appdata);
if (as->ticket_appdata != NULL) {
ret->ticket_appdata = as->ticket_appdata->data;
ret->ticket_appdata_len = as->ticket_appdata->length;