Prevent a possible use after free by mimicing the s3_srvr.c fixes contributed by
Adam Langley close to three years ago, which were commited in
https://git.openssl.org/gitweb/?p=openssl.git;a=commitdiff;h=e7928282d0148af5f28fa3437a625a2006af0214

ok jsing@
merge fix for CVE-2014-3509 -- basically a missing s->hit check; ok guenther
merge CVE-2014-3510; Fix DTLS anonymous EC(DH) denial of service
https://git.openssl.org/gitweb/?p=openssl.git;a=commit;h=17160033765480453be0a41335fa6b833691c049
ok bcook
Fix CVE-2014-3511; TLS downgrade, verbatim diff
https://git.openssl.org/gitweb/?p=openssl.git;a=commit;h=280b1f1ad12131defcd986676a8fc9717aaa601b
ok guenther miod
When you expect a function to return a particular value, don't put a comment
saying that you expect it to return that value and compare it against zero
because it is supposedly faster, for this leads to bugs (especially given the
high rate of sloppy cut'n'paste within ssl3 and dtls1 routines in this
library).

Instead, compare for the exact value it ought to return upon success.

ok deraadt@
Oops, revert changes commited by mistake. The previous commit was supposed
to only apply to s23_srvr.c.
Fix CVE-2014-3506, DTLS handshake message size checks.  From
https://git.openssl.org/gitweb/?p=openssl.git;a=commit;h=1250f12613b61758675848f6600ebd914ccd7636
with comment/whitespace style tweaks

ok bcook@ miod@
Correct test reversed during merge of fix for CVE-2014-3509

pointed out by Watson Ladd (watson (at) matasano.com)
ok deraadt@
Fix CVE-2014-3508, pretty printing and OID validation:
 - make sure the output buffer is always NUL terminated if buf_len
   was initially greater than zero.
 - reject OIDs that are too long, too short, or not in proper base-127

Based on
https://git.openssl.org/gitweb/?p=openssl.git;a=commit;h=0042fb5fd1c9d257d713b15a1f45da05cf5c1c87

ok bcook@
Fix CVE-2014-3507, avoid allocating and then leaking a fresh fragment
structure when a zero-length fragment is received.

Based on
https://git.openssl.org/gitweb/?p=openssl.git;a=commitdiff;h=d0a4b7d1a2948fce38515b8d862f43e7ba0ebf74

diff by miod@, ok guenther@ bcook@ deraadt@
This commit was manufactured by cvs2git to create branch 'OPENBSD_5_6'.

Sprout from master 2014-08-08 05:06:56 UTC guenther 'Fix CVE-2014-3507, avoid allocating and then leaking a fresh fragment'
Cherrypick from OPENSSL 2014-04-15 18:01:18 UTC miod 'Import the OpenSSL libcrypto tests in a form suitable for our rergress':
    src/lib/libssl/src/crypto/aes/asm/aes-ia64.S
    src/lib/libssl/src/crypto/aes/asm/aes-ppc.pl
    src/lib/libssl/src/crypto/aes/asm/aes-sparcv9.pl
    src/lib/libssl/src/crypto/aes/asm/aesni-sha1-x86_64.pl
    src/lib/libssl/src/crypto/aes/asm/aesni-x86.pl
    src/lib/libssl/src/crypto/aes/asm/bsaes-x86_64.pl
    src/lib/libssl/src/crypto/aes/asm/vpaes-x86.pl
    src/lib/libssl/src/crypto/aes/asm/vpaes-x86_64.pl
    src/lib/libssl/src/crypto/bn/asm/armv4-gf2m.pl
    src/lib/libssl/src/crypto/bn/asm/armv4-mont.pl
    src/lib/libssl/src/crypto/bn/asm/ia64-mont.pl
    src/lib/libssl/src/crypto/bn/asm/mips-mont.pl
    src/lib/libssl/src/crypto/bn/asm/mips.pl
    src/lib/libssl/src/crypto/bn/asm/ppc-mont.pl
    src/lib/libssl/src/crypto/bn/asm/ppc64-mont.pl
    src/lib/libssl/src/crypto/bn/asm/s390x-gf2m.pl
    src/lib/libssl/src/crypto/bn/asm/s390x-mont.pl
    src/lib/libssl/src/crypto/bn/asm/s390x.S
    src/lib/libssl/src/crypto/bn/asm/sparcv9-mont.pl
    src/lib/libssl/src/crypto/bn/asm/sparcv9a-mont.pl
    src/lib/libssl/src/crypto/bn/asm/via-mont.pl
    src/lib/libssl/src/crypto/bn/asm/x86-gf2m.pl
    src/lib/libssl/src/crypto/bn/asm/x86-mont.pl
    src/lib/libssl/src/crypto/bn/asm/x86_64-gf2m.pl
    src/lib/libssl/src/crypto/camellia/asm/cmll-x86.pl
    src/lib/libssl/src/crypto/des/asm/des_enc.m4
    src/lib/libssl/src/crypto/md5/asm/md5-ia64.S
    src/lib/libssl/src/crypto/modes/asm/ghash-armv4.pl
    src/lib/libssl/src/crypto/modes/asm/ghash-ia64.pl
    src/lib/libssl/src/crypto/modes/asm/ghash-s390x.pl
    src/lib/libssl/src/crypto/modes/asm/ghash-sparcv9.pl
    src/lib/libssl/src/crypto/modes/asm/ghash-x86.pl
    src/lib/libssl/src/crypto/modes/asm/ghash-x86_64.pl
    src/lib/libssl/src/crypto/objects/obj_xref.txt
    src/lib/libssl/src/crypto/objects/objxref.pl
    src/lib/libssl/src/crypto/perlasm/ppc-xlate.pl
    src/lib/libssl/src/crypto/rc4/asm/rc4-ia64.pl
    src/lib/libssl/src/crypto/sha/asm/sha1-armv4-large.pl
    src/lib/libssl/src/crypto/sha/asm/sha1-mips.pl
    src/lib/libssl/src/crypto/sha/asm/sha1-ppc.pl
    src/lib/libssl/src/crypto/sha/asm/sha1-s390x.pl
    src/lib/libssl/src/crypto/sha/asm/sha1-sparcv9.pl
    src/lib/libssl/src/crypto/sha/asm/sha1-sparcv9a.pl
    src/lib/libssl/src/crypto/sha/asm/sha1-thumb.pl
    src/lib/libssl/src/crypto/sha/asm/sha1-x86_64.pl
    src/lib/libssl/src/crypto/sha/asm/sha256-586.pl
    src/lib/libssl/src/crypto/sha/asm/sha256-armv4.pl
    src/lib/libssl/src/crypto/sha/asm/sha512-586.pl
    src/lib/libssl/src/crypto/sha/asm/sha512-armv4.pl
    src/lib/libssl/src/crypto/sha/asm/sha512-ia64.pl
    src/lib/libssl/src/crypto/sha/asm/sha512-mips.pl
    src/lib/libssl/src/crypto/sha/asm/sha512-ppc.pl
    src/lib/libssl/src/crypto/sha/asm/sha512-s390x.pl
    src/lib/libssl/src/crypto/sha/asm/sha512-sparcv9.pl
    src/lib/libssl/src/crypto/store/README
    src/lib/libssl/src/crypto/whrlpool/asm/wp-mmx.pl
    src/lib/libssl/src/doc/crypto/BIO_new_CMS.pod
    src/lib/libssl/src/doc/crypto/CMS_compress.pod
    src/lib/libssl/src/doc/crypto/ERR_set_mark.pod
    src/lib/libssl/src/doc/crypto/EVP_PKEY_get_default_digest.pod
    src/lib/libssl/src/doc/crypto/PEM_write_bio_PKCS7_stream.pod
    src/lib/libssl/src/doc/crypto/SMIME_read_CMS.pod
    src/lib/libssl/src/doc/crypto/SMIME_write_CMS.pod
    src/lib/libssl/src/doc/crypto/X509_verify_cert.pod
    src/lib/libssl/src/doc/crypto/i2d_CMS_bio_stream.pod
    src/lib/libssl/src/doc/crypto/x509.pod
    src/lib/libssl/src/test/CAtsa.cnf
    src/lib/libssl/src/test/cms-examples.pl
    src/lib/libssl/src/test/cms-test.pl
    src/lib/libssl/src/test/pkits-test.pl
    src/lib/libssl/src/test/smcont.txt
    src/lib/libssl/src/test/smime-certs/smdsa1.pem
    src/lib/libssl/src/test/smime-certs/smdsa2.pem
    src/lib/libssl/src/test/smime-certs/smdsa3.pem
    src/lib/libssl/src/test/smime-certs/smdsap.pem
    src/lib/libssl/src/test/smime-certs/smroot.pem
    src/lib/libssl/src/test/smime-certs/smrsa1.pem
    src/lib/libssl/src/test/smime-certs/smrsa2.pem
    src/lib/libssl/src/test/smime-certs/smrsa3.pem
    src/lib/libssl/src/test/test_padlock
    src/lib/libssl/src/test/testtsa
    src/regress/lib/libcrypto/bf/bftest.c
    src/regress/lib/libcrypto/cast/casttest.c
    src/regress/lib/libcrypto/exp/exptest.c
    src/regress/lib/libcrypto/hmac/hmactest.c
    src/regress/lib/libcrypto/idea/ideatest.c
    src/regress/lib/libcrypto/md4/md4test.c
    src/regress/lib/libcrypto/md5/md5test.c
    src/regress/lib/libcrypto/mdc2/mdc2test.c
    src/regress/lib/libcrypto/rand/randtest.c
    src/regress/lib/libcrypto/rc2/rc2test.c
    src/regress/lib/libcrypto/rmd/rmdtest.c
    src/regress/lib/libcrypto/sha/shatest.c
    src/regress/lib/libcrypto/sha1/sha1test.c
Cherrypick from openssl 2014-04-13 15:16:37 UTC miod 'Import OpenSSL 1.0.1g':
    src/lib/libssl/src/crypto/bf/COPYRIGHT
    src/lib/libssl/src/crypto/bf/INSTALL
    src/lib/libssl/src/crypto/bf/README
    src/lib/libssl/src/crypto/bf/VERSION
    src/lib/libssl/src/crypto/bf/asm/readme
    src/lib/libssl/src/crypto/bn/asm/ppc.pl
    src/lib/libssl/src/crypto/cast/asm/readme
    src/lib/libssl/src/crypto/conf/ssleay.cnf
    src/lib/libssl/src/crypto/des/COPYRIGHT
    src/lib/libssl/src/crypto/dh/dh1024.pem
    src/lib/libssl/src/crypto/dh/dh192.pem
    src/lib/libssl/src/crypto/dh/dh2048.pem
    src/lib/libssl/src/crypto/dh/dh4096.pem
    src/lib/libssl/src/crypto/dh/dh512.pem
    src/lib/libssl/src/crypto/dh/example
    src/lib/libssl/src/crypto/dh/generate
    src/lib/libssl/src/crypto/dsa/README
    src/lib/libssl/src/crypto/dsa/fips186a.txt
    src/lib/libssl/src/crypto/pem/message
    src/lib/libssl/src/crypto/pem/pkcs7.lis
    src/lib/libssl/src/crypto/rc2/rrc2.doc
    src/lib/libssl/src/crypto/rc4/rrc4.doc
    src/lib/libssl/src/crypto/sha/asm/sha1-ia64.pl
    src/lib/libssl/src/doc/apps/s_time.pod
    src/lib/libssl/src/doc/crypto/PKCS12_parse.pod
    src/lib/libssl/src/doc/crypto/SMIME_read_PKCS7.pod
    src/lib/libssl/src/doc/crypto/SMIME_write_PKCS7.pod
    src/lib/libssl/src/doc/crypto/X509_new.pod
    src/lib/libssl/src/test/CAssdh.cnf
    src/lib/libssl/src/test/CAssdsa.cnf
    src/lib/libssl/src/test/CAssrsa.cnf
    src/lib/libssl/src/test/P1ss.cnf
    src/lib/libssl/src/test/P2ss.cnf
    src/lib/libssl/src/test/Sssdsa.cnf
    src/lib/libssl/src/test/Sssrsa.cnf
    src/lib/libssl/src/test/pkcs7-1.pem
    src/lib/libssl/src/test/pkcs7.pem
    src/lib/libssl/src/test/test.cnf
    src/lib/libssl/src/test/testcrl.pem
    src/lib/libssl/src/test/testreq2.pem
    src/lib/libssl/src/test/testrsa.pem
    src/lib/libssl/src/test/testsslproxy
    src/lib/libssl/src/test/testx509.pem
    src/lib/libssl/src/test/v3-cert1.pem
    src/lib/libssl/src/test/v3-cert2.pem