projects
/
oweals
/
openssl.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Revert "Move random-related defines from e_os.h to rand_unix.c"
[oweals/openssl.git]
/
crypto
/
asn1
/
x_long.c
diff --git
a/crypto/asn1/x_long.c
b/crypto/asn1/x_long.c
index 5895345f9fe1cb02852d53430a560bf655a29643..bf9371ef55aaf123821f32a7fc9d9c6016246dfb 100644
(file)
--- a/
crypto/asn1/x_long.c
+++ b/
crypto/asn1/x_long.c
@@
-1,5
+1,5
@@
/*
/*
- * Copyright 2000-201
6
The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2000-201
7
The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
@@
-11,6
+11,12
@@
#include "internal/cryptlib.h"
#include <openssl/asn1t.h>
#include "internal/cryptlib.h"
#include <openssl/asn1t.h>
+#if !(OPENSSL_API_COMPAT < 0x10200000L)
+NON_EMPTY_TRANSLATION_UNIT
+#else
+
+#define COPY_SIZE(a, b) (sizeof(a) < sizeof(b) ? sizeof(a) : sizeof(b))
+
/*
* Custom primitive type for long handling. This converts between an
* ASN1_INTEGER and a long directly.
/*
* Custom primitive type for long handling. This converts between an
* ASN1_INTEGER and a long directly.
@@
-46,13
+52,13
@@
ASN1_ITEM_end(ZLONG)
static int long_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
{
static int long_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
{
-
*(long *)pval = it->size
;
+
memcpy(pval, &it->size, COPY_SIZE(*pval, it->size))
;
return 1;
}
static void long_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
{
return 1;
}
static void long_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
{
-
*(long *)pval = it->size
;
+
memcpy(pval, &it->size, COPY_SIZE(*pval, it->size))
;
}
/*
}
/*
@@
-86,12
+92,8
@@
static int long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype,
long ltmp;
unsigned long utmp, sign;
int clen, pad, i;
long ltmp;
unsigned long utmp, sign;
int clen, pad, i;
- /* this exists to bypass broken gcc optimization */
- char *cp = (char *)pval;
-
- /* use memcpy, because we may not be long aligned */
- memcpy(<mp, cp, sizeof(long));
+ memcpy(<mp, pval, COPY_SIZE(*pval, ltmp));
if (ltmp == it->size)
return -1;
/*
if (ltmp == it->size)
return -1;
/*
@@
-133,7
+135,6
@@
static int long_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
int i;
long ltmp;
unsigned long utmp = 0, sign = 0x100;
int i;
long ltmp;
unsigned long utmp = 0, sign = 0x100;
- char *cp = (char *)pval;
if (len > 1) {
/*
if (len > 1) {
/*
@@
-185,12
+186,16
@@
static int long_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG);
return 0;
}
ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG);
return 0;
}
- memcpy(
cp, <mp, sizeof(long
));
+ memcpy(
pval, <mp, COPY_SIZE(*pval, ltmp
));
return 1;
}
static int long_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it,
int indent, const ASN1_PCTX *pctx)
{
return 1;
}
static int long_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it,
int indent, const ASN1_PCTX *pctx)
{
- return BIO_printf(out, "%ld\n", *(long *)pval);
+ long l;
+
+ memcpy(&l, pval, COPY_SIZE(*pval, l));
+ return BIO_printf(out, "%ld\n", l);
}
}
+#endif