{"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1i/ssl/ssl_err.c\n- openssl-1.0.1i.orig/ssl/s3_enc.c\n- openssl-1.0.1i.orig/ssl/ssl_lib.c\n- openssl-1.0.1i.orig/ssl/t1_enc.c\n- openssl-1.0.1i/ssl/s23_srvr.c\n\n## Target Source Code\n\n### CHANGES\n\n#### region() [lines 1-50]\n```c\n\n OpenSSL CHANGES\n _______________\n\n Changes between 1.0.1h and 1.0.1i [6 Aug 2014]\n\n *) Fix SRP buffer overrun vulnerability. Invalid parameters passed to the\n SRP code can be overrun an internal buffer. Add sanity check that\n g, A, B < N to SRP code.\n\n Thanks to Sean Devlin and Watson Ladd of Cryptography Services, NCC\n Group for discovering this issue.\n (CVE-2014-3512)\n [Steve Henson]\n\n *) A flaw in the OpenSSL SSL/TLS server code causes the server to negotiate\n TLS 1.0 instead of higher protocol versions when the ClientHello message\n is badly fragmented. This allows a man-in-the-middle attacker to force a\n downgrade to TLS 1.0 even if both the server and the client support a\n higher protocol version\n/* ... truncated ... */\n```\n\n### apps/s_client.c\n\n#### sc_usage() [lines 281-374]\n```c\n\t}\n#endif\n\nstatic void sc_usage(void)\n\t{\n\tBIO_printf(bio_err,\"usage: s_client args\\n\");\n\tBIO_printf(bio_err,\"\\n\");\n\tBIO_printf(bio_err,\" -host host - use -connect instead\\n\");\n\tBIO_printf(bio_err,\" -port port - use -connect instead\\n\");\n\tBIO_printf(bio_err,\" -connect host:port - who to connect to (default is %s:%s)\\n\",SSL_HOST_NAME,PORT_STR);\n\n\tBIO_printf(bio_err,\" -verify arg - turn on peer certificate verification\\n\");\n\tBIO_printf(bio_err,\" -verify_return_error - return verification errors\\n\");\n\tBIO_printf(bio_err,\" -cert arg - certificate file to use, PEM format assumed\\n\");\n\tBIO_printf(bio_err,\" -certform arg - certificate format (PEM or DER) PEM default\\n\");\n\tBIO_printf(bio_err,\" -key arg - Private key file to use, \n/* ... truncated ... */\n```\n\n### crypto/err/openssl.ec\n\n#### region() [lines 32-97]\n```c\nL ECDH\t\tcrypto/ecdh/ecdh.h\t\tcrypto/ecdh/ech_err.c\nL STORE\t\tcrypto/store/store.h\t\tcrypto/store/str_err.c\nL TS\t\tcrypto/ts/ts.h\t\t\tcrypto/ts/ts_err.c\nL HMAC\t\tcrypto/hmac/hmac.h\t\tcrypto/hmac/hmac_err.c\nL CMS\t\tcrypto/cms/cms.h\t\tcrypto/cms/cms_err.c\nL JPAKE\t\tcrypto/jpake/jpake.h\t\tcrypto/jpake/jpake_err.c\n\n# additional header files to be scanned for function names\nL NONE\t\tcrypto/x509/x509_vfy.h\t\tNONE\nL NONE\t\tcrypto/ec/ec_lcl.h\t\tNONE\nL NONE\t\tcrypto/asn1/asn_lcl.h\t\tNONE\nL NONE\t\tcrypto/cms/cms_lcl.h\t\tNONE\n\n\nF RSAREF_F_RSA_BN2BIN\nF RSAREF_F_RSA_PRIVATE_DECRYPT\nF RSAREF_F_RSA_PRIVATE_ENCRYPT\nF RSAREF_F_RSA_PUBLIC_DECRYPT\nF RSAREF_F_RSA_PUBLIC_ENCRYPT\n#F SSL_F_CLIENT_CERTIFICATE\n\nR SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE\t\t1010\nR SSL_R_SSLV3_ALERT_BAD_RECORD_MA\n/* ... truncated ... */\n```\n\n### ssl/d1_lib.c\n\n#### dtls1_ctrl() [lines 248-277]\n```c\n\t\ts->version=DTLS1_VERSION;\n\t}\n\nlong dtls1_ctrl(SSL *s, int cmd, long larg, void *parg)\n\t{\n\tint ret=0;\n\n\tswitch (cmd)\n\t\t{\n\tcase DTLS_CTRL_GET_TIMEOUT:\n\t\tif (dtls1_get_timeout(s, (struct timeval*) parg) != NULL)\n\t\t\t{\n\t\t\tret = 1;\n\t\t\t}\n\t\tbreak;\n\tcase DTLS_CTRL_HANDLE_TIMEOUT:\n\t\tret = dtls1_handle_timeout(s);\n\t\tbreak;\n\tcase DTLS_CTRL_LISTEN:\n\t\tret = dtls1_listen(s, parg);\n\t\tbreak;\n\n\tdefault:\n\t\tret = ssl3_ctrl(s, cmd, larg, parg);\n\t\tbreak;\n\t\t}\n\treturn(ret);\n\t}\n\n/*\n```\n\n### ssl/dtls1.h\n\n#### region() [lines 45-131]\n```c\n * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\n * OF THE POSSIBILITY OF SUCH DAMAGE.\n * ====================================================================\n *\n * This product includes cryptographic software written by Eric Young\n * (eay@cryptsoft.com). This product includes software written by Tim\n * Hudson (tjh@cryptsoft.com).\n *\n */\n\n#ifndef HEADER_DTLS1_H\n#define HEADER_DTLS1_H\n\n#include packet;\n\n\tmemcpy(buf,p,n);\n\n\tif ((p[0] & 0x80) && (p[2] == SSL2_MT_SERVER_HELLO) &&\n\t\t(p[5] == 0x00) && (p[6] == 0x02))\n\t\t{\n#ifdef OPENSSL_NO_SSL2\n\t\tSSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_PROTOCOL);\n\t\tgoto err;\n#else\n\t\t/* we are talking sslv2 */\n\t\t/* we need to clean up the SSLv3 setup and put in the\n\t\t * sslv2 stuff. */\n\t\tint ch_len;\n\n\t\tif (s->options & SSL_OP_NO_SSLv2)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_PROTOCOL);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (s->s2 == NULL)\n\t\t\t{\n\t\t\tif (!ssl2_new(s))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\telse\n/* ... 81 lin\n/* ... truncated ... */\n```\n\n### ssl/s23_srvr.c\n\n#### ssl23_get_client_hello() [lines 235-655]\n```c\n\t}\n\n\nint ssl23_get_client_hello(SSL *s)\n\t{\n\tchar buf_space[11]; /* Request this many bytes in initial read.\n\t * We can detect SSL 3.0/TLS 1.0 Client Hellos\n\t * ('type == 3') correctly only when the following\n\t * is in a single record, which is not guaranteed by\n\t * the protocol specification:\n\t * Byte Content\n\t * 0 type \\\n\t * 1/2 version > record header\n\t * 3/4 length /\n\t * 5 msg_type \\\n\t * 6-8 length > Client Hello message\n\t * 9/10 client_ver\n/* ... truncated ... */\n```\n\n### ssl/s2_lib.c\n\n#### ssl2_ctrl() [lines 382-400]\n```c\n\ts->packet_length=0;\n\t}\n\nlong ssl2_ctrl(SSL *s, int cmd, long larg, void *parg)\n\t{\n\tint ret=0;\n\n\tswitch(cmd)\n\t\t{\n\tcase SSL_CTRL_GET_SESSION_REUSED:\n\t\tret=s->hit;\n\t\tbreak;\n\tdefault:\n\t\tbreak;\n\t\t}\n\treturn(ret);\n\t}\n\nlong ssl2_callback_ctrl(SSL *s, int cmd, void (*fp)(void))\n```\n\n#### ssl2_put_cipher_by_char() [lines 430-448]\n```c\n\t\treturn cp;\n\t}\n\nint ssl2_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p)\n\t{\n\tlong l;\n\n\tif (p != NULL)\n\t\t{\n\t\tl=c->id;\n\t\tif ((l & 0xff000000) != 0x02000000) return(0);\n\t\tp[0]=((unsigned char)(l>>16L))&0xFF;\n\t\tp[1]=((unsigned char)(l>> 8L))&0xFF;\n\t\tp[2]=((unsigned char)(l ))&0xFF;\n\t\t}\n\treturn(3);\n\t}\n\nint ssl2_generate_key_material(SSL *s)\n```\n\n### ssl/s3_enc.c\n\n#### ssl3_alert_code() [lines 866-907]\n```c\n\treturn(ret);\n\t}\n\nint ssl3_alert_code(int code)\n\t{\n\tswitch (code)\n\t\t{\n\tcase SSL_AD_CLOSE_NOTIFY:\treturn(SSL3_AD_CLOSE_NOTIFY);\n\tcase SSL_AD_UNEXPECTED_MESSAGE:\treturn(SSL3_AD_UNEXPECTED_MESSAGE);\n\tcase SSL_AD_BAD_RECORD_MAC:\treturn(SSL3_AD_BAD_RECORD_MAC);\n\tcase SSL_AD_DECRYPTION_FAILED:\treturn(SSL3_AD_BAD_RECORD_MAC);\n\tcase SSL_AD_RECORD_OVERFLOW:\treturn(SSL3_AD_BAD_RECORD_MAC);\n\tcase SSL_AD_DECOMPRESSION_FAILURE:return(SSL3_AD_DECOMPRESSION_FAILURE);\n\tcase SSL_AD_HANDSHAKE_FAILURE:\treturn(SSL3_AD_HANDSHAKE_FAILURE);\n\tcase SSL_AD_NO_CERTIFICATE:\treturn(SSL3_AD_NO_CERTIFICATE);\n\tcase SSL_AD_BAD_CERTIFICATE:\treturn(SSL3_AD_BAD_CERTIFICATE);\n\tcase SSL_AD_UNSUPPORTED_CERTIFICATE:return(SSL3_AD_UNSUPPORTED_CERTIFICATE);\n\tcase SSL_AD_CER\n/* ... truncated ... */\n```\n\n### ssl/s3_lib.c\n\n#### ssl3_ctrl() [lines 3088-3364]\n```c\n\t}\n#endif\n\nlong ssl3_ctrl(SSL *s, int cmd, long larg, void *parg)\n\t{\n\tint ret=0;\n\n#if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_RSA)\n\tif (\n#ifndef OPENSSL_NO_RSA\n\t cmd == SSL_CTRL_SET_TMP_RSA ||\n\t cmd == SSL_CTRL_SET_TMP_RSA_CB ||\n#endif\n#ifndef OPENSSL_NO_DSA\n\t cmd == SSL_CTRL_SET_TMP_DH ||\n\t cmd == SSL_CTRL_SET_TMP_DH_CB ||\n#endif\n\t\t0)\n\t\t{\n\t\tif (!ssl_cert_inst(&s->cert))\n\t\t \t{\n\t\t\tSSLerr(SSL_F_SSL3_CTRL, ERR_R_MALLOC_FAILURE);\n\t\t\treturn(0);\n\t\t\t}\n\t\t}\n#endif\n\n\tswitch (cmd)\n\t\t{\n\tcase SSL_CTRL_GET_SESSION_REUSED:\n\t\tret=s->hit;\n\t\tbreak;\n\tcase SSL_CTRL_GET_CLIENT_CERT_REQUEST:\n\t\tbreak;\n\tcase SSL_CTRL_GET_NUM_RENEGOTIATIONS:\n\t\tret=s->s3->num_renegotiations;\n\t\tbreak;\n\tcase SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS:\n\t\tret=s->s3->nu\n/* ... truncated ... */\n```\n\n### ssl/ssl.h\n\n#### region() [lines 618-704]\n```c\n * zap so we have some more flags.\n */\n/* The next flag deliberately changes the ciphertest, this is a check\n * for the PKCS#1 attack */\n#define SSL_OP_PKCS1_CHECK_1\t\t\t\t0x0\n#define SSL_OP_PKCS1_CHECK_2\t\t\t\t0x0\n\n#define SSL_OP_NETSCAPE_CA_DN_BUG\t\t\t0x20000000L\n#define SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG\t\t0x40000000L\n/* Make server add server-hello extension from early version of\n * cryptopro draft, when GOST ciphersuite is negotiated. \n * Required for interoperability with CryptoPro CSP 3.x \n */\n#define SSL_OP_CRYPTOPRO_TLSEXT_BUG\t\t\t0x80000000L\n\n/* Allow SSL_write(..., n) to return r with 0 < r < n (i.e. report success\n * when just a single record has been written): */\n#define SSL_MODE_ENABLE_PARTIAL_WRITE 0x00000001L\n/* Make it possib\n/* ... truncated ... */\n```\n\n### ssl/ssl3.h\n\n#### region() [lines 89-178]\n```c\n * \"This product includes software developed by the OpenSSL Project\n * for use in the OpenSSL Toolkit (http://www.openssl.org/)\"\n *\n * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\n * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR\n * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n * STRI\n/* ... truncated ... */\n```\n\n### ssl/ssl_err.c\n\n#### region() [lines 344-430]\n```c\n{ERR_REASON(SSL_R_CA_DN_TOO_LONG) ,\"ca dn too long\"},\n{ERR_REASON(SSL_R_CCS_RECEIVED_EARLY) ,\"ccs received early\"},\n{ERR_REASON(SSL_R_CERTIFICATE_VERIFY_FAILED),\"certificate verify failed\"},\n{ERR_REASON(SSL_R_CERT_LENGTH_MISMATCH) ,\"cert length mismatch\"},\n{ERR_REASON(SSL_R_CHALLENGE_IS_DIFFERENT),\"challenge is different\"},\n{ERR_REASON(SSL_R_CIPHER_CODE_WRONG_LENGTH),\"cipher code wrong length\"},\n{ERR_REASON(SSL_R_CIPHER_OR_HASH_UNAVAILABLE),\"cipher or hash unavailable\"},\n{ERR_REASON(SSL_R_CIPHER_TABLE_SRC_ERROR),\"cipher table src error\"},\n{ERR_REASON(SSL_R_CLIENTHELLO_TLSEXT) ,\"clienthello tlsext\"},\n{ERR_REASON(SSL_R_COMPRESSED_LENGTH_TOO_LONG),\"compressed length too long\"},\n{ERR_REASON(SSL_R_COMPRESSION_DISABLED) ,\"compressio\n/* ... truncated ... */\n```\n\n### ssl/ssl_lib.c\n\n#### ssl_cipher_list_to_bytes() [lines 1375-1436]\n```c\n\treturn(buf);\n\t}\n\nint ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p,\n\t\t\t int (*put_cb)(const SSL_CIPHER *, unsigned char *))\n\t{\n\tint i,j=0;\n\tSSL_CIPHER *c;\n\tunsigned char *q;\n#ifndef OPENSSL_NO_KRB5\n\tint nokrb5 = !kssl_tgt_is_available(s->kssl_ctx);\n#endif /* OPENSSL_NO_KRB5 */\n\n\tif (sk == NULL) return(0);\n\tq=p;\n\n\tfor (i=0; ialgorithm_ssl & SSL_TLSV1_2) && \n\t\t\t(TLS1_get_client_version(s) < TLS1_2_VERSION))\n\t\t\tcontinue;\n#ifndef OPENSSL_NO_KRB5\n\t\tif (((c->algorithm_mkey & SSL_kKRB5) || (c->algorithm_auth & SSL_aKRB5)) &&\n\t\t nokrb5)\n\t\t continue;\n#endif /* O\n/* ... truncated ... */\n```\n\n### ssl/t1_enc.c\n\n#### tls1_alert_code() [lines 1207-1251]\n```c\n\treturn(rv);\n\t}\n\nint tls1_alert_code(int code)\n\t{\n\tswitch (code)\n\t\t{\n\tcase SSL_AD_CLOSE_NOTIFY:\treturn(SSL3_AD_CLOSE_NOTIFY);\n\tcase SSL_AD_UNEXPECTED_MESSAGE:\treturn(SSL3_AD_UNEXPECTED_MESSAGE);\n\tcase SSL_AD_BAD_RECORD_MAC:\treturn(SSL3_AD_BAD_RECORD_MAC);\n\tcase SSL_AD_DECRYPTION_FAILED:\treturn(TLS1_AD_DECRYPTION_FAILED);\n\tcase SSL_AD_RECORD_OVERFLOW:\treturn(TLS1_AD_RECORD_OVERFLOW);\n\tcase SSL_AD_DECOMPRESSION_FAILURE:return(SSL3_AD_DECOMPRESSION_FAILURE);\n\tcase SSL_AD_HANDSHAKE_FAILURE:\treturn(SSL3_AD_HANDSHAKE_FAILURE);\n\tcase SSL_AD_NO_CERTIFICATE:\treturn(-1);\n\tcase SSL_AD_BAD_CERTIFICATE:\treturn(SSL3_AD_BAD_CERTIFICATE);\n\tcase SSL_AD_UNSUPPORTED_CERTIFICATE:return(SSL3_AD_UNSUPPORTED_CERTIFICATE);\n\tcase SSL_AD_CERTIFICATE_REVOKE\n/* ... truncated ... */\n```\n\n### ssl/tls1.h\n\n#### region() [lines 120-217]\n```c\n * ECC cipher suite support in OpenSSL originally written by\n * Vipul Gupta and Sumit Gupta of Sun Microsystems Laboratories.\n *\n */\n/* ====================================================================\n * Copyright 2005 Nokia. All rights reserved.\n *\n * The portions of the attached software (\"Contribution\") is developed by\n * Nokia Corporation and is licensed pursuant to the OpenSSL open source\n * license.\n *\n * The Contribution, originally written by Mika Kousa and Pasi Eronen of\n * Nokia Corporation, consists of the \"PSK\" (Pre-Shared Key) ciphersuites\n * support (see RFC 4279) to OpenSSL.\n *\n * No patent licenses or other rights except those expressly stated in\n * the OpenSSL open source license shall be deemed granted or received\n * ex\n/* ... truncated ... */\n```\n\n\n## Upstream Fix\n```diff\ncommit 6bfe55380abbf7528e04e59f18921bd6c896af1c\nAuthor: Bodo Moeller \nDate: Wed Oct 15 04:05:42 2014 +0200\n\n Support TLS_FALLBACK_SCSV.\n \n Reviewed-by: Rich Salz \n\nIndex: openssl-1.0.1i/CHANGES\n===================================================================\n--- openssl-1.0.1i.orig/CHANGES\t2014-10-30 17:13:45.900895822 +0100\n+++ openssl-1.0.1i/CHANGES\t2014-10-30 17:14:58.085762986 +0100\n@@ -3,6 +3,11 @@\n _______________\n \n Changes between 1.0.1h and 1.0.1i [6 Aug 2014]\n+ *) Add support for TLS_FALLBACK_SCSV.\n+ Client applications doing fallback retries should call\n+ SSL_set_mode(s, SSL_MODE_SEND_FALLBACK_SCSV).\n+ (CVE-2014-3566)\n+ [Adam Langley, Bodo Moeller]\n \n *) Fix SRP buffer overrun vulnerability. Invalid parameters passed to the\n SRP code can be overrun an internal buffer. Add sanity check that\nIndex: openssl-1.0.1i/apps/s_client.c\n===================================================================\n--- openssl-1.0.1i.orig/apps/s_client.c\t2014-10-30 17:13:43.387865632 +0100\n+++ openssl-1.0.1i/apps/s_client.c\t2014-10-30 17:13:45.900895822 +0100\n@@ -337,6 +337,7 @@ static void sc_usage(void)\n \tBIO_printf(bio_err,\" -tls1_1 - just use TLSv1.1\\n\");\n \tBIO_printf(bio_err,\" -tls1 - just use TLSv1\\n\");\n \tBIO_printf(bio_err,\" -dtls1 - just use DTLSv1\\n\"); \n+\tBIO_printf(bio_err,\" -fallback_scsv - send TLS_FALLBACK_SCSV\\n\");\n \tBIO_printf(bio_err,\" -mtu - set the link layer MTU\\n\");\n \tBIO_printf(bio_err,\" -no_tls1_2/-no_tls1_1/-no_tls1/-no_ssl3/-no_ssl2 - turn off that protocol\\n\");\n \tBIO_printf(bio_err,\" -bugs - Switch on all SSL implementation bug workarounds\\n\");\n@@ -617,6 +618,7 @@ int MAIN(int argc, char **argv)\n \tchar *sess_out = NULL;\n \tstruct sockaddr peer;\n \tint peerlen = sizeof(peer);\n+\tint fallback_scsv = 0;\n \tint enable_timeouts = 0 ;\n \tlong socket_mtu = 0;\n #ifndef OPENSSL_NO_JPAKE\n@@ -822,6 +824,10 @@ int MAIN(int argc, char **argv)\n \t\t\tmeth=DTLSv1_client_method();\n \t\t\tsocket_type=SOCK_DGRAM;\n \t\t\t}\n+\t\telse if (strcmp(*argv,\"-fallback_scsv\") == 0)\n+\t\t\t{\n+\t\t\tfallback_scsv = 1;\n+\t\t\t}\n \t\telse if (strcmp(*argv,\"-timeout\") == 0)\n \t\t\tenable_timeouts=1;\n \t\telse if (strcmp(*argv,\"-mtu\") == 0)\n@@ -1241,6 +1247,10 @@ bad:\n \t\tSSL_set_session(con, sess);\n \t\tSSL_SESSION_free(sess);\n \t\t}\n+\n+\tif (fallback_scsv)\n+\t\tSSL_set_mode(con, SSL_MODE_SEND_FALLBACK_SCSV);\n+\n #ifndef OPENSSL_NO_TLSEXT\n \tif (servername != NULL)\n \t\t{\nIndex: openssl-1.0.1i/crypto/err/openssl.ec\n===================================================================\n--- openssl-1.0.1i.orig/crypto/err/openssl.ec\t2014-10-30 17:13:43.387865632 +0100\n+++ openssl-1.0.1i/crypto/err/openssl.ec\t2014-10-30 17:13:45.901895834 +0100\n@@ -71,6 +71,7 @@ R SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION\n R SSL_R_TLSV1_ALERT_PROTOCOL_VERSION\t\t1070\n R SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY\t1071\n R SSL_R_TLSV1_ALERT_INTERNAL_ERROR\t\t1080\n+R SSL_R_SSLV3_ALERT_INAPPROPRIATE_FALLBACK\t1086\n R SSL_R_TLSV1_ALERT_USER_CANCELLED\t\t1090\n R SSL_R_TLSV1_ALERT_NO_RENEGOTIATION\t\t1100\n R SSL_R_TLSV1_UNSUPPORTED_EXTENSION\t\t1110\nIndex: openssl-1.0.1i/ssl/d1_lib.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/d1_lib.c\t2014-10-30 17:13:43.387865632 +0100\n+++ openssl-1.0.1i/ssl/d1_lib.c\t2014-10-30 17:13:45.901895834 +0100\n@@ -265,6 +265,16 @@ long dtls1_ctrl(SSL *s, int cmd, long la\n \tcase DTLS_CTRL_LISTEN:\n \t\tret = dtls1_listen(s, parg);\n \t\tbreak;\n+\tcase SSL_CTRL_CHECK_PROTO_VERSION:\n+\t\t/* For library-internal use; checks that the current protocol\n+\t\t * is the highest enabled version (according to s->ctx->method,\n+\t\t * as version negotiation may have changed s->method). */\n+#if DTLS_MAX_VERSION != DTLS1_VERSION\n+# error Code needs update for DTLS_method() support beyond DTLS1_VERSION.\n+#endif\n+\t\t/* Just one protocol version is supported so far;\n+\t\t * fail closed if the version is not as expected. */\n+\t\treturn s->version == DTLS_MAX_VERSION;\n \n \tdefault:\n \t\tret = ssl3_ctrl(s, cmd, larg, parg);\nIndex: openssl-1.0.1i/ssl/dtls1.h\n===================================================================\n--- openssl-1.0.1i.orig/ssl/dtls1.h\t2014-10-30 17:13:43.387865632 +0100\n+++ openssl-1.0.1i/ssl/dtls1.h\t2014-10-30 17:13:45.901895834 +0100\n@@ -84,6 +84,8 @@ extern \"C\" {\n #endif\n \n #define DTLS1_VERSION\t\t\t0xFEFF\n+#define DTLS_MAX_VERSION\t\tDTLS1_VERSION\n+\n #define DTLS1_BAD_VER\t\t\t0x0100\n \n #if 0\n@@ -284,4 +286,3 @@ typedef struct dtls1_record_data_st\n }\n #endif\n #endif\n-\nIndex: openssl-1.0.1i/ssl/s23_clnt.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s23_clnt.c\t2014-10-30 17:13:43.387865632 +0100\n+++ openssl-1.0.1i/ssl/s23_clnt.c\t2014-10-30 17:13:45.901895834 +0100\n@@ -736,6 +736,9 @@ static int ssl23_get_server_hello(SSL *s\n \t\t\tgoto err;\n \t\t\t}\n \n+\t\t/* ensure that TLS_MAX_VERSION is up-to-date */\n+\t\tOPENSSL_assert(s->version <= TLS_MAX_VERSION);\n+\n \t\tif (p[0] == SSL3_RT_ALERT && p[5] != SSL3_AL_WARNING)\n \t\t\t{\n \t\t\t/* fatal alert */\nIndex: openssl-1.0.1i/ssl/s23_srvr.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s23_srvr.c\t2014-10-30 17:13:43.388865644 +0100\n+++ openssl-1.0.1i/ssl/s23_srvr.c\t2014-10-30 17:13:45.901895834 +0100\n@@ -421,6 +421,9 @@ static int ssl23_get_client_hello(SSL *s\n \t\t\t}\n \t\t}\n \n+\t/* ensure that TLS_MAX_VERSION is up-to-date */\n+\tOPENSSL_assert(s->version <= TLS_MAX_VERSION);\n+\n #ifdef OPENSSL_FIPS\n \tif (FIPS_mode() && (s->version < TLS1_VERSION))\n \t\t{\nIndex: openssl-1.0.1i/ssl/s2_lib.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s2_lib.c\t2014-10-30 17:13:43.388865644 +0100\n+++ openssl-1.0.1i/ssl/s2_lib.c\t2014-10-30 17:13:45.901895834 +0100\n@@ -390,6 +390,8 @@ long ssl2_ctrl(SSL *s, int cmd, long lar\n \tcase SSL_CTRL_GET_SESSION_REUSED:\n \t\tret=s->hit;\n \t\tbreak;\n+\tcase SSL_CTRL_CHECK_PROTO_VERSION:\n+\t\treturn ssl3_ctrl(s, SSL_CTRL_CHECK_PROTO_VERSION, larg, parg);\n \tdefault:\n \t\tbreak;\n \t\t}\n@@ -436,7 +438,7 @@ int ssl2_put_cipher_by_char(const SSL_CI\n \tif (p != NULL)\n \t\t{\n \t\tl=c->id;\n-\t\tif ((l & 0xff000000) != 0x02000000) return(0);\n+\t\tif ((l & 0xff000000) != 0x02000000 && l != SSL3_CK_FALLBACK_SCSV) return(0);\n \t\tp[0]=((unsigned char)(l>>16L))&0xFF;\n \t\tp[1]=((unsigned char)(l>> 8L))&0xFF;\n \t\tp[2]=((unsigned char)(l ))&0xFF;\nIndex: openssl-1.0.1i/ssl/s3_enc.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s3_enc.c\t2014-10-30 17:13:43.388865644 +0100\n+++ openssl-1.0.1i/ssl/s3_enc.c\t2014-10-30 17:13:45.901895834 +0100\n@@ -900,7 +900,7 @@ int ssl3_alert_code(int code)\n \tcase SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE: return(SSL3_AD_HANDSHAKE_FAILURE);\n \tcase SSL_AD_BAD_CERTIFICATE_HASH_VALUE: return(SSL3_AD_HANDSHAKE_FAILURE);\n \tcase SSL_AD_UNKNOWN_PSK_IDENTITY:return(TLS1_AD_UNKNOWN_PSK_IDENTITY);\n+\tcase SSL_AD_INAPPROPRIATE_FALLBACK:return(TLS1_AD_INAPPROPRIATE_FALLBACK);\n \tdefault:\t\t\treturn(-1);\n \t\t}\n \t}\n-\nIndex: openssl-1.0.1i/ssl/s3_lib.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s3_lib.c\t2014-10-30 17:13:43.389865657 +0100\n+++ openssl-1.0.1i/ssl/s3_lib.c\t2014-10-30 17:13:45.902895846 +0100\n@@ -3354,6 +3354,33 @@ long ssl3_ctrl(SSL *s, int cmd, long lar\n #endif\n \n #endif /* !OPENSSL_NO_TLSEXT */\n+\n+\tcase SSL_CTRL_CHECK_PROTO_VERSION:\n+\t\t/* For library-internal use; checks that the current protocol\n+\t\t * is the highest enabled version (according to s->ctx->method,\n+\t\t * as version negotiation may have changed s->method). */\n+\t\tif (s->version == s->ctx->method->version)\n+\t\t\treturn 1;\n+\t\t/* Apparently we're using a version-flexible SSL_METHOD\n+\t\t * (not at its highest protocol version). */\n+\t\tif (s->ctx->method->version == SSLv23_method()->version)\n+\t\t\t{\n+#if TLS_MAX_VERSION != TLS1_2_VERSION\n+# error Code needs update for SSLv23_method() support beyond TLS1_2_VERSION.\n+#endif\n+\t\t\tif (!(s->options & SSL_OP_NO_TLSv1_2))\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "commit 6bfe55380abbf7528e04e59f18921bd6c896af1c\nAuthor: Bodo Moeller \nDate: Wed Oct 15 04:05:42 2014 +0200\n\n Support TLS_FALLBACK_SCSV.\n \n Reviewed-by: Rich Salz \n\nIndex: openssl-1.0.1i/CHANGES\n===================================================================\n--- openssl-1.0.1i.orig/CHANGES\t2014-10-30 17:13:45.900895822 +0100\n+++ openssl-1.0.1i/CHANGES\t2014-10-30 17:14:58.085762986 +0100\n@@ -3,6 +3,11 @@\n _______________\n \n Changes between 1.0.1h and 1.0.1i [6 Aug 2014]\n+ *) Add support for TLS_FALLBACK_SCSV.\n+ Client applications doing fallback retries should call\n+ SSL_set_mode(s, SSL_MODE_SEND_FALLBACK_SCSV).\n+ (CVE-2014-3566)\n+ [Adam Langley, Bodo Moeller]\n \n *) Fix SRP buffer overrun vulnerability. Invalid parameters passed to the\n SRP code can be overrun an internal buffer. Add sanity check that\nIndex: openssl-1.0.1i/apps/s_client.c\n===================================================================\n--- openssl-1.0.1i.orig/apps/s_client.c\t2014-10-30 17:13:43.387865632 +0100\n+++ openssl-1.0.1i/apps/s_client.c\t2014-10-30 17:13:45.900895822 +0100\n@@ -337,6 +337,7 @@ static void sc_usage(void)\n \tBIO_printf(bio_err,\" -tls1_1 - just use TLSv1.1\\n\");\n \tBIO_printf(bio_err,\" -tls1 - just use TLSv1\\n\");\n \tBIO_printf(bio_err,\" -dtls1 - just use DTLSv1\\n\"); \n+\tBIO_printf(bio_err,\" -fallback_scsv - send TLS_FALLBACK_SCSV\\n\");\n \tBIO_printf(bio_err,\" -mtu - set the link layer MTU\\n\");\n \tBIO_printf(bio_err,\" -no_tls1_2/-no_tls1_1/-no_tls1/-no_ssl3/-no_ssl2 - turn off that protocol\\n\");\n \tBIO_printf(bio_err,\" -bugs - Switch on all SSL implementation bug workarounds\\n\");\n@@ -617,6 +618,7 @@ int MAIN(int argc, char **argv)\n \tchar *sess_out = NULL;\n \tstruct sockaddr peer;\n \tint peerlen = sizeof(peer);\n+\tint fallback_scsv = 0;\n \tint enable_timeouts = 0 ;\n \tlong socket_mtu = 0;\n #ifndef OPENSSL_NO_JPAKE\n@@ -822,6 +824,10 @@ int MAIN(int argc, char **argv)\n \t\t\tmeth=DTLSv1_client_method();\n \t\t\tsocket_type=SOCK_DGRAM;\n \t\t\t}\n+\t\telse if (strcmp(*argv,\"-fallback_scsv\") == 0)\n+\t\t\t{\n+\t\t\tfallback_scsv = 1;\n+\t\t\t}\n \t\telse if (strcmp(*argv,\"-timeout\") == 0)\n \t\t\tenable_timeouts=1;\n \t\telse if (strcmp(*argv,\"-mtu\") == 0)\n@@ -1241,6 +1247,10 @@ bad:\n \t\tSSL_set_session(con, sess);\n \t\tSSL_SESSION_free(sess);\n \t\t}\n+\n+\tif (fallback_scsv)\n+\t\tSSL_set_mode(con, SSL_MODE_SEND_FALLBACK_SCSV);\n+\n #ifndef OPENSSL_NO_TLSEXT\n \tif (servername != NULL)\n \t\t{\nIndex: openssl-1.0.1i/crypto/err/openssl.ec\n===================================================================\n--- openssl-1.0.1i.orig/crypto/err/openssl.ec\t2014-10-30 17:13:43.387865632 +0100\n+++ openssl-1.0.1i/crypto/err/openssl.ec\t2014-10-30 17:13:45.901895834 +0100\n@@ -71,6 +71,7 @@ R SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION\n R SSL_R_TLSV1_ALERT_PROTOCOL_VERSION\t\t1070\n R SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY\t1071\n R SSL_R_TLSV1_ALERT_INTERNAL_ERROR\t\t1080\n+R SSL_R_SSLV3_ALERT_INAPPROPRIATE_FALLBACK\t1086\n R SSL_R_TLSV1_ALERT_USER_CANCELLED\t\t1090\n R SSL_R_TLSV1_ALERT_NO_RENEGOTIATION\t\t1100\n R SSL_R_TLSV1_UNSUPPORTED_EXTENSION\t\t1110\nIndex: openssl-1.0.1i/ssl/d1_lib.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/d1_lib.c\t2014-10-30 17:13:43.387865632 +0100\n+++ openssl-1.0.1i/ssl/d1_lib.c\t2014-10-30 17:13:45.901895834 +0100\n@@ -265,6 +265,16 @@ long dtls1_ctrl(SSL *s, int cmd, long la\n \tcase DTLS_CTRL_LISTEN:\n \t\tret = dtls1_listen(s, parg);\n \t\tbreak;\n+\tcase SSL_CTRL_CHECK_PROTO_VERSION:\n+\t\t/* For library-internal use; checks that the current protocol\n+\t\t * is the highest enabled version (according to s->ctx->method,\n+\t\t * as version negotiation may have changed s->method). */\n+#if DTLS_MAX_VERSION != DTLS1_VERSION\n+# error Code needs update for DTLS_method() support beyond DTLS1_VERSION.\n+#endif\n+\t\t/* Just one protocol version is supported so far;\n+\t\t * fail closed if the version is not as expected. */\n+\t\treturn s->version == DTLS_MAX_VERSION;\n \n \tdefault:\n \t\tret = ssl3_ctrl(s, cmd, larg, parg);\nIndex: openssl-1.0.1i/ssl/dtls1.h\n===================================================================\n--- openssl-1.0.1i.orig/ssl/dtls1.h\t2014-10-30 17:13:43.387865632 +0100\n+++ openssl-1.0.1i/ssl/dtls1.h\t2014-10-30 17:13:45.901895834 +0100\n@@ -84,6 +84,8 @@ extern \"C\" {\n #endif\n \n #define DTLS1_VERSION\t\t\t0xFEFF\n+#define DTLS_MAX_VERSION\t\tDTLS1_VERSION\n+\n #define DTLS1_BAD_VER\t\t\t0x0100\n \n #if 0\n@@ -284,4 +286,3 @@ typedef struct dtls1_record_data_st\n }\n #endif\n #endif\n-\nIndex: openssl-1.0.1i/ssl/s23_clnt.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s23_clnt.c\t2014-10-30 17:13:43.387865632 +0100\n+++ openssl-1.0.1i/ssl/s23_clnt.c\t2014-10-30 17:13:45.901895834 +0100\n@@ -736,6 +736,9 @@ static int ssl23_get_server_hello(SSL *s\n \t\t\tgoto err;\n \t\t\t}\n \n+\t\t/* ensure that TLS_MAX_VERSION is up-to-date */\n+\t\tOPENSSL_assert(s->version <= TLS_MAX_VERSION);\n+\n \t\tif (p[0] == SSL3_RT_ALERT && p[5] != SSL3_AL_WARNING)\n \t\t\t{\n \t\t\t/* fatal alert */\nIndex: openssl-1.0.1i/ssl/s23_srvr.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s23_srvr.c\t2014-10-30 17:13:43.388865644 +0100\n+++ openssl-1.0.1i/ssl/s23_srvr.c\t2014-10-30 17:13:45.901895834 +0100\n@@ -421,6 +421,9 @@ static int ssl23_get_client_hello(SSL *s\n \t\t\t}\n \t\t}\n \n+\t/* ensure that TLS_MAX_VERSION is up-to-date */\n+\tOPENSSL_assert(s->version <= TLS_MAX_VERSION);\n+\n #ifdef OPENSSL_FIPS\n \tif (FIPS_mode() && (s->version < TLS1_VERSION))\n \t\t{\nIndex: openssl-1.0.1i/ssl/s2_lib.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s2_lib.c\t2014-10-30 17:13:43.388865644 +0100\n+++ openssl-1.0.1i/ssl/s2_lib.c\t2014-10-30 17:13:45.901895834 +0100\n@@ -390,6 +390,8 @@ long ssl2_ctrl(SSL *s, int cmd, long lar\n \tcase SSL_CTRL_GET_SESSION_REUSED:\n \t\tret=s->hit;\n \t\tbreak;\n+\tcase SSL_CTRL_CHECK_PROTO_VERSION:\n+\t\treturn ssl3_ctrl(s, SSL_CTRL_CHECK_PROTO_VERSION, larg, parg);\n \tdefault:\n \t\tbreak;\n \t\t}\n@@ -436,7 +438,7 @@ int ssl2_put_cipher_by_char(const SSL_CI\n \tif (p != NULL)\n \t\t{\n \t\tl=c->id;\n-\t\tif ((l & 0xff000000) != 0x02000000) return(0);\n+\t\tif ((l & 0xff000000) != 0x02000000 && l != SSL3_CK_FALLBACK_SCSV) return(0);\n \t\tp[0]=((unsigned char)(l>>16L))&0xFF;\n \t\tp[1]=((unsigned char)(l>> 8L))&0xFF;\n \t\tp[2]=((unsigned char)(l ))&0xFF;\nIndex: openssl-1.0.1i/ssl/s3_enc.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s3_enc.c\t2014-10-30 17:13:43.388865644 +0100\n+++ openssl-1.0.1i/ssl/s3_enc.c\t2014-10-30 17:13:45.901895834 +0100\n@@ -900,7 +900,7 @@ int ssl3_alert_code(int code)\n \tcase SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE: return(SSL3_AD_HANDSHAKE_FAILURE);\n \tcase SSL_AD_BAD_CERTIFICATE_HASH_VALUE: return(SSL3_AD_HANDSHAKE_FAILURE);\n \tcase SSL_AD_UNKNOWN_PSK_IDENTITY:return(TLS1_AD_UNKNOWN_PSK_IDENTITY);\n+\tcase SSL_AD_INAPPROPRIATE_FALLBACK:return(TLS1_AD_INAPPROPRIATE_FALLBACK);\n \tdefault:\t\t\treturn(-1);\n \t\t}\n \t}\n-\nIndex: openssl-1.0.1i/ssl/s3_lib.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s3_lib.c\t2014-10-30 17:13:43.389865657 +0100\n+++ openssl-1.0.1i/ssl/s3_lib.c\t2014-10-30 17:13:45.902895846 +0100\n@@ -3354,6 +3354,33 @@ long ssl3_ctrl(SSL *s, int cmd, long lar\n #endif\n \n #endif /* !OPENSSL_NO_TLSEXT */\n+\n+\tcase SSL_CTRL_CHECK_PROTO_VERSION:\n+\t\t/* For library-internal use; checks that the current protocol\n+\t\t * is the highest enabled version (according to s->ctx->method,\n+\t\t * as version negotiation may have changed s->method). */\n+\t\tif (s->version == s->ctx->method->version)\n+\t\t\treturn 1;\n+\t\t/* Apparently we're using a version-flexible SSL_METHOD\n+\t\t * (not at its highest protocol version). */\n+\t\tif (s->ctx->method->version == SSLv23_method()->version)\n+\t\t\t{\n+#if TLS_MAX_VERSION != TLS1_2_VERSION\n+# error Code needs update for SSLv23_method() support beyond TLS1_2_VERSION.\n+#endif\n+\t\t\tif (!(s->options & SSL_OP_NO_TLSv1_2))\n+\t\t\t\treturn s->version == TLS1_2_VERSION;\n+\t\t\tif (!(s->options & SSL_OP_NO_TLSv1_1))\n+\t\t\t\treturn s->version == TLS1_1_VERSION;\n+\t\t\tif (!(s->options & SSL_OP_NO_TLSv1))\n+\t\t\t\treturn s->version == TLS1_VERSION;\n+\t\t\tif (!(s->options & SSL_OP_NO_SSLv3))\n+\t\t\t\treturn s->version == SSL3_VERSION;\n+\t\t\tif (!(s->options & SSL_OP_NO_SSLv2))\n+\t\t\t\treturn s->version == SSL2_VERSION;\n+\t\t\t}\n+\t\treturn 0; /* Unexpected state; fail closed. */\n+\n \tdefault:\n \t\tbreak;\n \t\t}\n@@ -3713,6 +3740,7 @@ long ssl3_ctx_callback_ctrl(SSL_CTX *ctx\n \t\tbreak;\n #endif\n #endif\n+\n \tdefault:\n \t\treturn(0);\n \t\t}\n@@ -4290,4 +4318,3 @@ long ssl_get_algorithm2(SSL *s)\n \t\treturn SSL_HANDSHAKE_MAC_SHA256 | TLS1_PRF_SHA256;\n \treturn alg2;\n \t}\n-\t\t\nIndex: openssl-1.0.1i/ssl/ssl.h\n===================================================================\n--- openssl-1.0.1i.orig/ssl/ssl.h\t2014-10-30 17:13:43.390865668 +0100\n+++ openssl-1.0.1i/ssl/ssl.h\t2014-10-30 17:13:45.902895846 +0100\n@@ -657,6 +657,10 @@ struct ssl_session_st\n */\n #define SSL_MODE_SEND_CLIENTHELLO_TIME 0x00000020L\n #define SSL_MODE_SEND_SERVERHELLO_TIME 0x00000040L\n+/* Send TLS_FALLBACK_SCSV in the ClientHello.\n+ * To be set by applications that reconnect with a downgraded protocol\n+ * version; see draft-ietf-tls-downgrade-scsv-00 for details. */\n+#define SSL_MODE_SEND_FALLBACK_SCSV 0x00000080L\n \n /* Note: SSL[_CTX]_set_{options,mode} use |= op on the previous value,\n * they cannot be used to clear bits. */\n@@ -1515,6 +1519,7 @@ DECLARE_PEM_rw(SSL_SESSION, SSL_SESSION)\n #define SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE\n #define SSL_AD_BAD_CERTIFICATE_HASH_VALUE TLS1_AD_BAD_CERTIFICATE_HASH_VALUE\n #define SSL_AD_UNKNOWN_PSK_IDENTITY TLS1_AD_UNKNOWN_PSK_IDENTITY /* fatal */\n+#define SSL_AD_INAPPROPRIATE_FALLBACK\tTLS1_AD_INAPPROPRIATE_FALLBACK /* fatal */\n \n #define SSL_ERROR_NONE\t\t\t0\n #define SSL_ERROR_SSL\t\t\t1\n@@ -1625,6 +1630,8 @@ DECLARE_PEM_rw(SSL_SESSION, SSL_SESSION)\n #define SSL_CTRL_GET_EXTRA_CHAIN_CERTS\t\t82\n #define SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS\t83\n \n+#define SSL_CTRL_CHECK_PROTO_VERSION\t\t119\n+\n #define DTLSv1_get_timeout(ssl, arg) \\\n \tSSL_ctrl(ssl,DTLS_CTRL_GET_TIMEOUT,0, (void *)arg)\n #define DTLSv1_handle_timeout(ssl) \\\n@@ -2383,6 +2390,7 @@ void ERR_load_SSL_strings(void);\n #define SSL_R_HTTPS_PROXY_REQUEST\t\t\t 155\n #define SSL_R_HTTP_REQUEST\t\t\t\t 156\n #define SSL_R_ILLEGAL_PADDING\t\t\t\t 283\n+#define SSL_R_INAPPROPRIATE_FALLBACK\t\t\t 373\n #define SSL_R_INCONSISTENT_COMPRESSION\t\t\t 340\n #define SSL_R_INVALID_CHALLENGE_LENGTH\t\t\t 158\n #define SSL_R_INVALID_COMMAND\t\t\t\t 280\n@@ -2529,6 +2537,7 @@ void ERR_load_SSL_strings(void);\n #define SSL_R_TLSV1_ALERT_DECRYPTION_FAILED\t\t 1021\n #define SSL_R_TLSV1_ALERT_DECRYPT_ERROR\t\t\t 1051\n #define SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION\t\t 1060\n+#define SSL_R_TLSV1_ALERT_INAPPROPRIATE_FALLBACK\t 1086\n #define SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY\t\t 1071\n #define SSL_R_TLSV1_ALERT_INTERNAL_ERROR\t\t 1080\n #define SSL_R_TLSV1_ALERT_NO_RENEGOTIATION\t\t 1100\nIndex: openssl-1.0.1i/ssl/ssl3.h\n===================================================================\n--- openssl-1.0.1i.orig/ssl/ssl3.h\t2014-10-30 17:13:43.390865668 +0100\n+++ openssl-1.0.1i/ssl/ssl3.h\t2014-10-30 17:13:45.903895858 +0100\n@@ -128,9 +128,14 @@\n extern \"C\" {\n #endif\n \n-/* Signalling cipher suite value: from draft-ietf-tls-renegotiation-03.txt */\n+/* Signalling cipher suite value from RFC 5746\n+ * (TLS_EMPTY_RENEGOTIATION_INFO_SCSV) */\n #define SSL3_CK_SCSV\t\t\t\t0x030000FF\n \n+/* Signalling cipher suite value from draft-ietf-tls-downgrade-scsv-00\n+ * (TLS_FALLBACK_SCSV) */\n+#define SSL3_CK_FALLBACK_SCSV\t\t\t0x03005600\n+\n #define SSL3_CK_RSA_NULL_MD5\t\t\t0x03000001\n #define SSL3_CK_RSA_NULL_SHA\t\t\t0x03000002\n #define SSL3_CK_RSA_RC4_40_MD5 \t\t\t0x03000003\nIndex: openssl-1.0.1i/ssl/ssl_err.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/ssl_err.c\t2014-10-30 17:13:43.390865668 +0100\n+++ openssl-1.0.1i/ssl/ssl_err.c\t2014-10-30 17:13:45.903895858 +0100\n@@ -383,6 +383,7 @@ static ERR_STRING_DATA SSL_str_reasons[]\n {ERR_REASON(SSL_R_HTTPS_PROXY_REQUEST) ,\"https proxy request\"},\n {ERR_REASON(SSL_R_HTTP_REQUEST) ,\"http request\"},\n {ERR_REASON(SSL_R_ILLEGAL_PADDING) ,\"illegal padding\"},\n+{ERR_REASON(SSL_R_INAPPROPRIATE_FALLBACK),\"inappropriate fallback\"},\n {ERR_REASON(SSL_R_INCONSISTENT_COMPRESSION),\"inconsistent compression\"},\n {ERR_REASON(SSL_R_INVALID_CHALLENGE_LENGTH),\"invalid challenge length\"},\n {ERR_REASON(SSL_R_INVALID_COMMAND) ,\"invalid command\"},\n@@ -529,6 +530,7 @@ static ERR_STRING_DATA SSL_str_reasons[]\n {ERR_REASON(SSL_R_TLSV1_ALERT_DECRYPTION_FAILED),\"tlsv1 alert decryption failed\"},\n {ERR_REASON(SSL_R_TLSV1_ALERT_DECRYPT_ERROR),\"tlsv1 alert decrypt error\"},\n {ERR_REASON(SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION),\"tlsv1 alert export restriction\"},\n+{ERR_REASON(SSL_R_TLSV1_ALERT_INAPPROPRIATE_FALLBACK),\"tlsv1 alert inappropriate fallback\"},\n {ERR_REASON(SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY),\"tlsv1 alert insufficient security\"},\n {ERR_REASON(SSL_R_TLSV1_ALERT_INTERNAL_ERROR),\"tlsv1 alert internal error\"},\n {ERR_REASON(SSL_R_TLSV1_ALERT_NO_RENEGOTIATION),\"tlsv1 alert no renegotiation\"},\nIndex: openssl-1.0.1i/ssl/ssl_lib.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/ssl_lib.c\t2014-10-30 17:13:43.392865692 +0100\n+++ openssl-1.0.1i/ssl/ssl_lib.c\t2014-10-30 17:13:45.903895858 +0100\n@@ -1386,6 +1386,8 @@ int ssl_cipher_list_to_bytes(SSL *s,STAC\n \n \tif (sk == NULL) return(0);\n \tq=p;\n+\tif (put_cb == NULL)\n+\t\tput_cb = s->method->put_cipher_by_char;\n \n \tfor (i=0; isrp_ctx.srp_Mask & SSL_kSRP))\n \t\t continue;\n #endif /* OPENSSL_NO_SRP */\n-\t\tj = put_cb ? put_cb(c,p) : ssl_put_cipher_by_char(s,c,p);\n+\t\tj = put_cb(c,p);\n \t\tp+=j;\n \t\t}\n-\t/* If p == q, no ciphers and caller indicates an error. Otherwise\n-\t * add SCSV if not renegotiating.\n-\t */\n-\tif (p != q && !s->renegotiate)\n+\t/* If p == q, no ciphers; caller indicates an error.\n+\t * Otherwise, add applicable SCSVs. */\n+\tif (p != q)\n \t\t{\n-\t\tstatic SSL_CIPHER scsv =\n+\t\tif (!s->renegotiate)\n \t\t\t{\n-\t\t\t0, NULL, SSL3_CK_SCSV, 0, 0, 0, 0, 0, 0, 0, 0, 0\n-\t\t\t};\n-\t\tj = put_cb ? put_cb(&scsv,p) : ssl_put_cipher_by_char(s,&scsv,p);\n-\t\tp+=j;\n+\t\t\tstatic SSL_CIPHER scsv =\n+\t\t\t\t{\n+\t\t\t\t0, NULL, SSL3_CK_SCSV, 0, 0, 0, 0, 0, 0, 0, 0, 0\n+\t\t\t\t};\n+\t\t\tj = put_cb(&scsv,p);\n+\t\t\tp+=j;\n #ifdef OPENSSL_RI_DEBUG\n-\t\tfprintf(stderr, \"SCSV sent by client\\n\");\n+\t\t\tfprintf(stderr, \"TLS_EMPTY_RENEGOTIATION_INFO_SCSV sent by client\\n\");\n #endif\n-\t\t}\n+\t\t\t}\n+\n+\t\tif (s->mode & SSL_MODE_SEND_FALLBACK_SCSV)\n+\t\t\t{\n+\t\t\tstatic SSL_CIPHER scsv =\n+\t\t\t\t{\n+\t\t\t\t0, NULL, SSL3_CK_FALLBACK_SCSV, 0, 0, 0, 0, 0, 0, 0, 0, 0\n+\t\t\t\t};\n+\t\t\tj = put_cb(&scsv,p);\n+\t\t\tp+=j;\n+\t\t\t}\n+ \t\t}\n \n \treturn(p-q);\n \t}\n@@ -1438,11 +1452,12 @@ STACK_OF(SSL_CIPHER) *ssl_bytes_to_ciphe\n \tconst SSL_CIPHER *c;\n \tSTACK_OF(SSL_CIPHER) *sk;\n \tint i,n;\n+\n \tif (s->s3)\n \t\ts->s3->send_connection_binding = 0;\n \n \tn=ssl_put_cipher_by_char(s,NULL,NULL);\n-\tif ((num%n) != 0)\n+\tif (n == 0 || (num%n) != 0)\n \t\t{\n \t\tSSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST);\n \t\treturn(NULL);\n@@ -1457,7 +1472,7 @@ STACK_OF(SSL_CIPHER) *ssl_bytes_to_ciphe\n \n \tfor (i=0; is3 && (n != 3 || !p[0]) &&\n \t\t\t(p[n-2] == ((SSL3_CK_SCSV >> 8) & 0xff)) &&\n \t\t\t(p[n-1] == (SSL3_CK_SCSV & 0xff)))\n@@ -1477,6 +1492,23 @@ STACK_OF(SSL_CIPHER) *ssl_bytes_to_ciphe\n \t\t\tcontinue;\n \t\t\t}\n \n+\t\t/* Check for TLS_FALLBACK_SCSV */\n+\t\tif ((n != 3 || !p[0]) &&\n+\t\t\t(p[n-2] == ((SSL3_CK_FALLBACK_SCSV >> 8) & 0xff)) &&\n+\t\t\t(p[n-1] == (SSL3_CK_FALLBACK_SCSV & 0xff)))\n+\t\t\t{\n+\t\t\t/* The SCSV indicates that the client previously tried a higher version.\n+\t\t\t * Fail if the current version is an unexpected downgrade. */\n+\t\t\tif (!SSL_ctrl(s, SSL_CTRL_CHECK_PROTO_VERSION, 0, NULL))\n+\t\t\t\t{\n+\t\t\t\tSSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,SSL_R_INAPPROPRIATE_FALLBACK);\n+\t\t\t\tif (s->s3)\n+\t\t\t\t\tssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_INAPPROPRIATE_FALLBACK);\n+\t\t\t\tgoto err;\n+\t\t\t\t}\n+\t\t\tcontinue;\n+\t\t\t}\n+\n \t\tc=ssl_get_cipher_by_char(s,p);\n \t\tp+=n;\n \t\tif (c != NULL)\nIndex: openssl-1.0.1i/ssl/t1_enc.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/t1_enc.c\t2014-10-30 17:13:43.392865692 +0100\n+++ openssl-1.0.1i/ssl/t1_enc.c\t2014-10-30 17:13:45.903895858 +0100\n@@ -1262,6 +1262,7 @@ int tls1_alert_code(int code)\n \tcase SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE: return(TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE);\n \tcase SSL_AD_BAD_CERTIFICATE_HASH_VALUE: return(TLS1_AD_BAD_CERTIFICATE_HASH_VALUE);\n \tcase SSL_AD_UNKNOWN_PSK_IDENTITY:return(TLS1_AD_UNKNOWN_PSK_IDENTITY);\n+\tcase SSL_AD_INAPPROPRIATE_FALLBACK:return(TLS1_AD_INAPPROPRIATE_FALLBACK);\n #if 0 /* not appropriate for TLS, not used for DTLS */\n \tcase DTLS1_AD_MISSING_HANDSHAKE_MESSAGE: return \n \t\t\t\t\t (DTLS1_AD_MISSING_HANDSHAKE_MESSAGE);\nIndex: openssl-1.0.1i/ssl/tls1.h\n===================================================================\n--- openssl-1.0.1i.orig/ssl/tls1.h\t2014-10-30 17:13:43.392865692 +0100\n+++ openssl-1.0.1i/ssl/tls1.h\t2014-10-30 17:13:45.904895870 +0100\n@@ -159,17 +159,19 @@ extern \"C\" {\n \n #define TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES\t0\n \n+#define TLS1_VERSION\t\t\t0x0301\n+#define TLS1_1_VERSION\t\t\t0x0302\n #define TLS1_2_VERSION\t\t\t0x0303\n-#define TLS1_2_VERSION_MAJOR\t\t0x03\n-#define TLS1_2_VERSION_MINOR\t\t0x03\n+#define TLS_MAX_VERSION\t\t\tTLS1_2_VERSION\n+\n+#define TLS1_VERSION_MAJOR\t\t0x03\n+#define TLS1_VERSION_MINOR\t\t0x01\n \n-#define TLS1_1_VERSION\t\t\t0x0302\n #define TLS1_1_VERSION_MAJOR\t\t0x03\n #define TLS1_1_VERSION_MINOR\t\t0x02\n \n-#define TLS1_VERSION\t\t\t0x0301\n-#define TLS1_VERSION_MAJOR\t\t0x03\n-#define TLS1_VERSION_MINOR\t\t0x01\n+#define TLS1_2_VERSION_MAJOR\t\t0x03\n+#define TLS1_2_VERSION_MINOR\t\t0x03\n \n #define TLS1_get_version(s) \\\n \t\t((s->version >> 8) == TLS1_VERSION_MAJOR ? s->version : 0)\n@@ -187,6 +189,7 @@ extern \"C\" {\n #define TLS1_AD_PROTOCOL_VERSION\t70\t/* fatal */\n #define TLS1_AD_INSUFFICIENT_SECURITY\t71\t/* fatal */\n #define TLS1_AD_INTERNAL_ERROR\t\t80\t/* fatal */\n+#define TLS1_AD_INAPPROPRIATE_FALLBACK\t86\t/* fatal */\n #define TLS1_AD_USER_CANCELLED\t\t90\n #define TLS1_AD_NO_RENEGOTIATION\t100\n /* codes 110-114 are from RFC3546 */"}], "metadata": {"id": "openssl-4769-openssl-CVE-2014-3566.patch", "cve_id": "CVE-2015-3197", "package": "openssl", "tier": "adapted", "has_source_context": true, "context_tokens_est": 3237, "context_files": 16, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2012-1798\n\nThe TIFFGetEXIFProperties function in coders/tiff.c in ImageMagick before 6.7.6-3 allows remote attackers to cause a denial of service (out-of-bounds read and crash) via a crafted EXIF IFD in a TIFF image.\n\n## Package\nImageMagick\n\n## Files to modify\n- magick/profile.c\n- ImageMagick-6.6.5-8.orig/magick/property.c\n- ImageMagick-6.6.5-8.orig/magick/profile.c\n- magick/property.c\n\n## Upstream Fix\n```diff\nhttp://www.imagemagick.org/discourse-server/viewtopic.php?f=4&t=20286 (note the date of announcement in contrast with date of patch)\nIndex: ImageMagick-6.6.5-8/magick/profile.c\n===================================================================\n--- ImageMagick-6.6.5-8.orig/magick/profile.c\n+++ ImageMagick-6.6.5-8/magick/profile.c\n@@ -1827,12 +1827,13 @@ MagickExport MagickBooleanType SyncImage\n EndianType\n endian;\n \n- int\n- offset;\n+ SplayTreeInfo\n+ *exif_resources;\n \n ssize_t\n id,\n- level;\n+ level,\n+ offset;\n \n size_t\n entry,\n@@ -1889,12 +1890,14 @@ MagickExport MagickBooleanType SyncImage\n /*\n This the offset to the first IFD.\n */\n- offset=(int) ReadProfileLong(endian,exif+4);\n- if ((size_t) offset >= length)\n+ offset=(ssize_t) ((int) ReadProfileLong(endian,exif+4));\n+ if ((offset < 0) || ((size_t) offset >= length))\n return(MagickFalse);\n directory=exif+offset;\n level=0;\n entry=0;\n+ exif_resources=NewSplayTree((int (*)(const void *,const void *)) NULL,\n+ (void *(*)(void *)) NULL,(void *(*)(void *)) NULL);\n do\n {\n if (level > 0)\n@@ -1924,6 +1927,9 @@ MagickExport MagickBooleanType SyncImage\n number_bytes;\n \n q=(unsigned char *) (directory+2+(12*entry));\n+ if (GetValueFromSplayTree(exif_resources,q) == q)\n+ break;\n+ (void) AddValueToSplayTree(exif_resources,q,q);\n tag_value=(ssize_t) ReadProfileShort(endian,q);\n format=(ssize_t) ReadProfileShort(endian,q+2);\n if ((format-1) >= EXIF_NUM_FORMATS)\n@@ -1934,13 +1940,15 @@ MagickExport MagickBooleanType SyncImage\n p=q+8;\n else\n {\n- int\n+ ssize_t\n offset;\n \n /*\n The directory entry contains an offset.\n */\n- offset=(int) ReadProfileLong(endian,q+8);\n+ offset=(ssize_t) ((int) ReadProfileLong(endian,q+8));\n+ if ((offset+number_bytes) < offset)\n+ continue; /* prevent overflow */\n if ((size_t) (offset+number_bytes) > length)\n continue;\n p=(unsigned char *) (exif+offset);\n@@ -1949,28 +1957,25 @@ MagickExport MagickBooleanType SyncImage\n {\n case 0x011a:\n {\n- (void) WriteProfileLong(endian,(size_t)\n- (image->x_resolution+0.5),p);\n+ (void) WriteProfileLong(endian,(size_t) (image->x_resolution+0.5),p);\n (void) WriteProfileLong(endian,1UL,p+4);\n break;\n }\n case 0x011b:\n {\n- (void) WriteProfileLong(endian,(size_t)\n- (image->y_resolution+0.5),p);\n+ (void) WriteProfileLong(endian,(size_t) (image->y_resolution+0.5),p);\n (void) WriteProfileLong(endian,1UL,p+4);\n break;\n }\n case 0x0112:\n {\n- (void) WriteProfileShort(endian,(unsigned short)\n- image->orientation,p);\n+ (void) WriteProfileShort(endian,(unsigned short) image->orientation,\n+ p);\n break;\n }\n case 0x0128:\n {\n- (void) WriteProfileShort(endian,(unsigned short)\n- (image->units+1),p);\n+ (void) WriteProfileShort(endian,(unsigned short) (image->units+1),p);\n break;\n }\n default:\n@@ -1978,11 +1983,11 @@ MagickExport MagickBooleanType SyncImage\n }\n if ((tag_value == TAG_EXIF_OFFSET) || (tag_value == TAG_INTEROP_OFFSET))\n {\n- size_t\n+ ssize_t\n offset;\n \n- offset=(size_t) ReadProfileLong(endian,p);\n- if ((offset < length) && (level < (MaxDirectoryStack-2)))\n+ offset=(ssize_t) ((int) ReadProfileLong(endian,p));\n+ if (((size_t) offset < length) && (level < (MaxDirectoryStack-2)))\n {\n directory_stack[level].directory=directory;\n entry++;\n@@ -1993,9 +1998,9 @@ MagickExport MagickBooleanType SyncImage\n level++;\n if ((directory+2+(12*number_entries)) > (exif+length))\n break;\n- offset=(size_t) ReadProfileLong(endian,directory+2+(12*\n- number_entries));\n- if ((offset != 0) && (offset < length) &&\n+ offset=(ssize_t) ((int) ReadProfileLong(endian,directory+2+(12*\n+ number_entries)));\n+ if ((offset != 0) && ((size_t) offset < length) &&\n (level < (MaxDirectoryStack-2)))\n {\n directory_stack[level].directory=exif+offset;\n@@ -2007,5 +2012,6 @@ MagickExport MagickBooleanType SyncImage\n }\n }\n } while (level > 0);\n+ exif_resources=DestroySplayTree(exif_resources);\n return(MagickTrue);\n }\nIndex: ImageMagick-6.6.5-8/magick/property.c\n===================================================================\n--- ImageMagick-6.6.5-8.orig/magick/property.c\n+++ ImageMagick-6.6.5-8/magick/property.c\n@@ -459,6 +459,13 @@ static inline ssize_t MagickMax(const ss\n return(y);\n }\n \n+static inline ssize_t MagickMin(const ssize_t x,const ssize_t y)\n+{\n+ if (x < y)\n+ return(x);\n+ return(y);\n+}\n+\n static inline int ReadPropertyByte(const unsigned char **p,size_t *length)\n {\n int\n@@ -593,7 +600,7 @@ static MagickBooleanType Get8BIMProperty\n continue;\n if (ReadPropertyByte(&info,&length) != (unsigned char) 'M')\n continue;\n- id=(ssize_t) ReadPropertyMSBShort(&info,&length);\n+ id=(ssize_t) ((int) ReadPropertyMSBShort(&info,&length));\n if (id < (ssize_t) start)\n continue;\n if (id > (ssize_t) stop)\n@@ -624,7 +631,7 @@ static MagickBooleanType Get8BIMProperty\n No name match, scroll forward and try next.\n */\n info+=count;\n- length-=count;\n+ length-=MagickMin(count,(ssize_t) length);\n continue;\n }\n if ((*name == '#') && (sub_number != 1))\n@@ -634,7 +641,7 @@ static MagickBooleanType Get8BIMProperty\n */\n sub_number--;\n info+=count;\n- length-=count;\n+ length-=MagickMin(count,(ssize_t) length);\n continue;\n }\n /*\n@@ -649,7 +656,7 @@ static MagickBooleanType Get8BIMProperty\n (void) CopyMagickMemory(attribute,(char *) info,(size_t) count);\n attribute[count]='\\0';\n info+=count;\n- length-=count;\n+ length-=MagickMin(count,(ssize_t) length);\n if ((id <= 1999) || (id >= 2999))\n (void) SetImageProperty((Image *) image,key,(const char *)\n attribute);\n@@ -789,7 +796,9 @@ static MagickBooleanType GetEXIFProperty\n *directory;\n \n size_t\n- entry,\n+ entry;\n+\n+ ssize_t\n offset;\n } DirectoryInfo;\n \n@@ -1095,6 +1104,7 @@ static MagickBooleanType GetEXIFProperty\n all,\n id,\n level,\n+ tag_offset,\n tag_value;\n \n register ssize_t\n@@ -1112,9 +1122,11 @@ static MagickBooleanType GetEXIFProperty\n size_t\n entry,\n number_entries,\n- tag_offset,\n tag;\n \n+ SplayTreeInfo\n+ *exif_resources;\n+\n /*\n If EXIF data exists, then try to parse the request for a tag.\n */\n@@ -1225,7 +1237,7 @@ static MagickBooleanType GetEXIFProperty\n }\n if (length < 16)\n return(MagickFalse);\n- id=(ssize_t) ReadPropertyShort(LSBEndian,exif);\n+ id=(ssize_t) ((int) ReadPropertyShort(LSBEndian,exif));\n endian=LSBEndian;\n if (id == 0x4949)\n endian=LSBEndian;\n@@ -1240,7 +1252,7 @@ static MagickBooleanType GetEXIFProperty\n This the offset to the first IFD.\n */\n offset=(int) ReadPropertyLong(endian,exif+4);\n- if ((size_t) offset >= length)\n+ if ((offset < 0) || (size_t) offset >= length)\n return(MagickFalse);\n /*\n Set the pointer to the first IFD and follow it were it leads.\n@@ -1249,6 +1261,8 @@ static MagickBooleanType GetEXIFProperty\n level=0;\n entry=0;\n tag_offset=0;\n+ exif_resources=NewSplayTree((int (*)(const void *,const void *)) NULL,\n+ (void *(*)(void *)) NULL,(void *(*)(void *)) NULL);\n do\n {\n /*\n@@ -1264,7 +1278,7 @@ static MagickBool\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "http://www.imagemagick.org/discourse-server/viewtopic.php?f=4&t=20286 (note the date of announcement in contrast with date of patch)\nIndex: ImageMagick-6.6.5-8/magick/profile.c\n===================================================================\n--- ImageMagick-6.6.5-8.orig/magick/profile.c\n+++ ImageMagick-6.6.5-8/magick/profile.c\n@@ -1827,12 +1827,13 @@ MagickExport MagickBooleanType SyncImage\n EndianType\n endian;\n \n- int\n- offset;\n+ SplayTreeInfo\n+ *exif_resources;\n \n ssize_t\n id,\n- level;\n+ level,\n+ offset;\n \n size_t\n entry,\n@@ -1889,12 +1890,14 @@ MagickExport MagickBooleanType SyncImage\n /*\n This the offset to the first IFD.\n */\n- offset=(int) ReadProfileLong(endian,exif+4);\n- if ((size_t) offset >= length)\n+ offset=(ssize_t) ((int) ReadProfileLong(endian,exif+4));\n+ if ((offset < 0) || ((size_t) offset >= length))\n return(MagickFalse);\n directory=exif+offset;\n level=0;\n entry=0;\n+ exif_resources=NewSplayTree((int (*)(const void *,const void *)) NULL,\n+ (void *(*)(void *)) NULL,(void *(*)(void *)) NULL);\n do\n {\n if (level > 0)\n@@ -1924,6 +1927,9 @@ MagickExport MagickBooleanType SyncImage\n number_bytes;\n \n q=(unsigned char *) (directory+2+(12*entry));\n+ if (GetValueFromSplayTree(exif_resources,q) == q)\n+ break;\n+ (void) AddValueToSplayTree(exif_resources,q,q);\n tag_value=(ssize_t) ReadProfileShort(endian,q);\n format=(ssize_t) ReadProfileShort(endian,q+2);\n if ((format-1) >= EXIF_NUM_FORMATS)\n@@ -1934,13 +1940,15 @@ MagickExport MagickBooleanType SyncImage\n p=q+8;\n else\n {\n- int\n+ ssize_t\n offset;\n \n /*\n The directory entry contains an offset.\n */\n- offset=(int) ReadProfileLong(endian,q+8);\n+ offset=(ssize_t) ((int) ReadProfileLong(endian,q+8));\n+ if ((offset+number_bytes) < offset)\n+ continue; /* prevent overflow */\n if ((size_t) (offset+number_bytes) > length)\n continue;\n p=(unsigned char *) (exif+offset);\n@@ -1949,28 +1957,25 @@ MagickExport MagickBooleanType SyncImage\n {\n case 0x011a:\n {\n- (void) WriteProfileLong(endian,(size_t)\n- (image->x_resolution+0.5),p);\n+ (void) WriteProfileLong(endian,(size_t) (image->x_resolution+0.5),p);\n (void) WriteProfileLong(endian,1UL,p+4);\n break;\n }\n case 0x011b:\n {\n- (void) WriteProfileLong(endian,(size_t)\n- (image->y_resolution+0.5),p);\n+ (void) WriteProfileLong(endian,(size_t) (image->y_resolution+0.5),p);\n (void) WriteProfileLong(endian,1UL,p+4);\n break;\n }\n case 0x0112:\n {\n- (void) WriteProfileShort(endian,(unsigned short)\n- image->orientation,p);\n+ (void) WriteProfileShort(endian,(unsigned short) image->orientation,\n+ p);\n break;\n }\n case 0x0128:\n {\n- (void) WriteProfileShort(endian,(unsigned short)\n- (image->units+1),p);\n+ (void) WriteProfileShort(endian,(unsigned short) (image->units+1),p);\n break;\n }\n default:\n@@ -1978,11 +1983,11 @@ MagickExport MagickBooleanType SyncImage\n }\n if ((tag_value == TAG_EXIF_OFFSET) || (tag_value == TAG_INTEROP_OFFSET))\n {\n- size_t\n+ ssize_t\n offset;\n \n- offset=(size_t) ReadProfileLong(endian,p);\n- if ((offset < length) && (level < (MaxDirectoryStack-2)))\n+ offset=(ssize_t) ((int) ReadProfileLong(endian,p));\n+ if (((size_t) offset < length) && (level < (MaxDirectoryStack-2)))\n {\n directory_stack[level].directory=directory;\n entry++;\n@@ -1993,9 +1998,9 @@ MagickExport MagickBooleanType SyncImage\n level++;\n if ((directory+2+(12*number_entries)) > (exif+length))\n break;\n- offset=(size_t) ReadProfileLong(endian,directory+2+(12*\n- number_entries));\n- if ((offset != 0) && (offset < length) &&\n+ offset=(ssize_t) ((int) ReadProfileLong(endian,directory+2+(12*\n+ number_entries)));\n+ if ((offset != 0) && ((size_t) offset < length) &&\n (level < (MaxDirectoryStack-2)))\n {\n directory_stack[level].directory=exif+offset;\n@@ -2007,5 +2012,6 @@ MagickExport MagickBooleanType SyncImage\n }\n }\n } while (level > 0);\n+ exif_resources=DestroySplayTree(exif_resources);\n return(MagickTrue);\n }\nIndex: ImageMagick-6.6.5-8/magick/property.c\n===================================================================\n--- ImageMagick-6.6.5-8.orig/magick/property.c\n+++ ImageMagick-6.6.5-8/magick/property.c\n@@ -459,6 +459,13 @@ static inline ssize_t MagickMax(const ss\n return(y);\n }\n \n+static inline ssize_t MagickMin(const ssize_t x,const ssize_t y)\n+{\n+ if (x < y)\n+ return(x);\n+ return(y);\n+}\n+\n static inline int ReadPropertyByte(const unsigned char **p,size_t *length)\n {\n int\n@@ -593,7 +600,7 @@ static MagickBooleanType Get8BIMProperty\n continue;\n if (ReadPropertyByte(&info,&length) != (unsigned char) 'M')\n continue;\n- id=(ssize_t) ReadPropertyMSBShort(&info,&length);\n+ id=(ssize_t) ((int) ReadPropertyMSBShort(&info,&length));\n if (id < (ssize_t) start)\n continue;\n if (id > (ssize_t) stop)\n@@ -624,7 +631,7 @@ static MagickBooleanType Get8BIMProperty\n No name match, scroll forward and try next.\n */\n info+=count;\n- length-=count;\n+ length-=MagickMin(count,(ssize_t) length);\n continue;\n }\n if ((*name == '#') && (sub_number != 1))\n@@ -634,7 +641,7 @@ static MagickBooleanType Get8BIMProperty\n */\n sub_number--;\n info+=count;\n- length-=count;\n+ length-=MagickMin(count,(ssize_t) length);\n continue;\n }\n /*\n@@ -649,7 +656,7 @@ static MagickBooleanType Get8BIMProperty\n (void) CopyMagickMemory(attribute,(char *) info,(size_t) count);\n attribute[count]='\\0';\n info+=count;\n- length-=count;\n+ length-=MagickMin(count,(ssize_t) length);\n if ((id <= 1999) || (id >= 2999))\n (void) SetImageProperty((Image *) image,key,(const char *)\n attribute);\n@@ -789,7 +796,9 @@ static MagickBooleanType GetEXIFProperty\n *directory;\n \n size_t\n- entry,\n+ entry;\n+\n+ ssize_t\n offset;\n } DirectoryInfo;\n \n@@ -1095,6 +1104,7 @@ static MagickBooleanType GetEXIFProperty\n all,\n id,\n level,\n+ tag_offset,\n tag_value;\n \n register ssize_t\n@@ -1112,9 +1122,11 @@ static MagickBooleanType GetEXIFProperty\n size_t\n entry,\n number_entries,\n- tag_offset,\n tag;\n \n+ SplayTreeInfo\n+ *exif_resources;\n+\n /*\n If EXIF data exists, then try to parse the request for a tag.\n */\n@@ -1225,7 +1237,7 @@ static MagickBooleanType GetEXIFProperty\n }\n if (length < 16)\n return(MagickFalse);\n- id=(ssize_t) ReadPropertyShort(LSBEndian,exif);\n+ id=(ssize_t) ((int) ReadPropertyShort(LSBEndian,exif));\n endian=LSBEndian;\n if (id == 0x4949)\n endian=LSBEndian;\n@@ -1240,7 +1252,7 @@ static MagickBooleanType GetEXIFProperty\n This the offset to the first IFD.\n */\n offset=(int) ReadPropertyLong(endian,exif+4);\n- if ((size_t) offset >= length)\n+ if ((offset < 0) || (size_t) offset >= length)\n return(MagickFalse);\n /*\n Set the pointer to the first IFD and follow it were it leads.\n@@ -1249,6 +1261,8 @@ static MagickBooleanType GetEXIFProperty\n level=0;\n entry=0;\n tag_offset=0;\n+ exif_resources=NewSplayTree((int (*)(const void *,const void *)) NULL,\n+ (void *(*)(void *)) NULL,(void *(*)(void *)) NULL);\n do\n {\n /*\n@@ -1264,7 +1278,7 @@ static MagickBooleanType GetEXIFProperty\n /*\n Determine how many entries there are in the current IFD.\n */\n- number_entries=ReadPropertyShort(endian,directory);\n+ number_entries=(size_t) ((int) ReadPropertyShort(endian,directory));\n for ( ; entry < number_entries; entry++)\n {\n ssize_t\n@@ -1280,9 +1294,12 @@ static MagickBooleanType GetEXIFProperty\n size_t\n format;\n \n- q=(unsigned char *) (directory+2+(12*entry));\n- tag_value=(ssize_t) (ReadPropertyShort(endian,q)+tag_offset);\n- format=(size_t) ReadPropertyShort(endian,q+2);\n+ q=(unsigned char *) (directory+(12*entry)+2);\n+ if (GetValueFromSplayTree(exif_resources,q) == q)\n+ break;\n+ (void) AddValueToSplayTree(exif_resources,q,q);\n+ tag_value=(ssize_t) ((int) ReadPropertyShort(endian,q)+tag_offset);\n+ format=(size_t) ((int) ReadPropertyShort(endian,q+2));\n if (format >= (sizeof(tag_bytes)/sizeof(*tag_bytes)))\n break;\n components=(int) ReadPropertyLong(endian,q+4);\n@@ -1298,6 +1315,8 @@ static MagickBooleanType GetEXIFProperty\n The directory entry contains an offset.\n */\n offset=(int) ReadPropertyLong(endian,q+8);\n+ if ((offset+number_bytes) < offset)\n+ continue; /* prevent overflow */\n if ((size_t) (offset+number_bytes) > length)\n continue;\n p=(unsigned char *) (exif+offset);\n@@ -1335,7 +1354,7 @@ static MagickBooleanType GetEXIFProperty\n case EXIF_FMT_ULONG:\n {\n EXIFMultipleValues(4,\"%.20g\",(double)\n- ReadPropertyLong(endian,p1));\n+ ((int) ReadPropertyLong(endian,p1)));\n break;\n }\n case EXIF_FMT_SLONG:\n@@ -1347,8 +1366,8 @@ static MagickBooleanType GetEXIFProperty\n case EXIF_FMT_URATIONAL:\n {\n EXIFMultipleFractions(8,\"%.20g/%.20g\",(double)\n- ReadPropertyLong(endian,p1),(double)\n- ReadPropertyLong(endian,p1+4));\n+ ((int) ReadPropertyLong(endian,p1)),(double)\n+ ((int) ReadPropertyLong(endian,p1+4)));\n break;\n }\n case EXIF_FMT_SRATIONAL:\n@@ -1449,19 +1468,19 @@ static MagickBooleanType GetEXIFProperty\n }\n }\n if ((tag_value == TAG_EXIF_OFFSET) ||\n- (tag_value == TAG_INTEROP_OFFSET) ||\n- (tag_value == TAG_GPS_OFFSET))\n+ (tag_value == TAG_INTEROP_OFFSET) || (tag_value == TAG_GPS_OFFSET))\n {\n- size_t\n+ ssize_t\n offset;\n \n- offset=(size_t) ReadPropertyLong(endian,p);\n- if ((offset < length) && (level < (MaxDirectoryStack-2)))\n+ offset=(ssize_t) ((int) ReadPropertyLong(endian,p));\n+ if (((size_t) offset < length) && (level < (MaxDirectoryStack-2)))\n {\n- size_t\n+ ssize_t\n tag_offset1;\n \n- tag_offset1=(tag_value == TAG_GPS_OFFSET) ? 0x10000UL : 0UL;\n+ tag_offset1=(ssize_t) ((tag_value == TAG_GPS_OFFSET) ? 0x10000 :\n+ 0);\n directory_stack[level].directory=directory;\n entry++;\n directory_stack[level].entry=entry;\n@@ -1473,9 +1492,9 @@ static MagickBooleanType GetEXIFProperty\n level++;\n if ((directory+2+(12*number_entries)) > (exif+length))\n break;\n- offset=(size_t) ReadPropertyLong(endian,directory+2+(12*\n- number_entries));\n- if ((offset != 0) && (offset < length) &&\n+ offset=(ssize_t) ((int) ReadPropertyLong(endian,directory+2+(12*\n+ number_entries)));\n+ if ((offset != 0) && ((size_t) offset < length) &&\n (level < (MaxDirectoryStack-2)))\n {\n directory_stack[level].directory=exif+offset;\n@@ -1488,6 +1507,7 @@ static MagickBooleanType GetEXIFProperty\n }\n }\n } while (level > 0);\n+ exif_resources=DestroySplayTree(exif_resources);\n return(MagickTrue);\n }\n \n@@ -1629,7 +1649,7 @@ static char *TracePSClippath(const unsig\n in_subpath=MagickFalse;\n while (length > 0)\n {\n- selector=(ssize_t) ReadPropertyMSBShort(&blob,&length);\n+ selector=(ssize_t) ((int) ReadPropertyMSBShort(&blob,&length));\n switch (selector)\n {\n case 0:\n@@ -1638,15 +1658,15 @@ static char *TracePSClippath(const unsig\n if (knot_count != 0)\n {\n blob+=24;\n- length-=24;\n+ length-=MagickMin(24,(ssize_t) length);\n break;\n }\n /*\n Expected subpath length record.\n */\n- knot_count=(ssize_t) ReadPropertyMSBShort(&blob,&length);\n+ knot_count=(ssize_t) ((int) ReadPropertyMSBShort(&blob,&length));\n blob+=22;\n- length-=22;\n+ length-=MagickMin(22,(ssize_t) length);\n break;\n }\n case 1:\n@@ -1660,7 +1680,7 @@ static char *TracePSClippath(const unsig\n Unexpected subpath knot\n */\n blob+=24;\n- length-=24;\n+ length-=MagickMin(24,(ssize_t) length);\n break;\n }\n /*\n@@ -1672,8 +1692,8 @@ static char *TracePSClippath(const unsig\n xx,\n yy;\n \n- yy=ReadPropertyMSBLong(&blob,&length);\n- xx=ReadPropertyMSBLong(&blob,&length);\n+ yy=(size_t) ((int) ReadPropertyMSBLong(&blob,&length));\n+ xx=(size_t) ((int) ReadPropertyMSBLong(&blob,&length));\n x=(ssize_t) xx;\n if (xx > 2147483647)\n x=(ssize_t) xx-4294967295-1;\n@@ -1761,7 +1781,7 @@ static char *TracePSClippath(const unsig\n default:\n {\n blob+=24;\n- length-=24;\n+ length-=MagickMin(24,(ssize_t) length);\n break;\n }\n }\n@@ -1826,7 +1846,7 @@ static char *TraceSVGClippath(const unsi\n in_subpath=MagickFalse;\n while (length != 0)\n {\n- selector=(ssize_t) ReadPropertyMSBShort(&blob,&length);\n+ selector=(ssize_t) ((int) ReadPropertyMSBShort(&blob,&length));\n switch (selector)\n {\n case 0:\n@@ -1835,15 +1855,15 @@ static char *TraceSVGClippath(const unsi\n if (knot_count != 0)\n {\n blob+=24;\n- length-=24;\n+ length-=MagickMin(24,(ssize_t) length);\n break;\n }\n /*\n Expected subpath length record.\n */\n- knot_count=(ssize_t) ReadPropertyMSBShort(&blob,&length);\n+ knot_count=(ssize_t) ((int) ReadPropertyMSBShort(&blob,&length));\n blob+=22;\n- length-=22;\n+ length-=MagickMin(22,(ssize_t) length);\n break;\n }\n case 1:\n@@ -1857,7 +1877,7 @@ static char *TraceSVGClippath(const unsi\n Unexpected subpath knot.\n */\n blob+=24;\n- length-=24;\n+ length-=MagickMin(24,(ssize_t) length);\n break;\n }\n /*\n@@ -1932,7 +1952,7 @@ static char *TraceSVGClippath(const unsi\n default:\n {\n blob+=24;\n- length-=24;\n+ length-=MagickMin(24,(ssize_t) length);\n break;\n }\n }"}], "metadata": {"id": "ImageMagick-474-ImageMagick-security-dos.patch", "cve_id": "CVE-2012-1798", "package": "ImageMagick", "tier": "adapted", "has_source_context": false, "license": "ImageMagick"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-1000104\n\nA security Bypass vulnerability exists in the FcgidPassHeader Proxy in mod_fcgid through 2016-07-07.\n\n## Package\napache2-mod_fcgid\n\n## Files to modify\n- mod_fcgid-2.3.9.orig/modules/fcgid/mod_fcgid.c\n- modules/fcgid/mod_fcgid.c\n\n## Upstream Fix\n```diff\nIndex: mod_fcgid-2.3.9/modules/fcgid/mod_fcgid.c\n===================================================================\n--- mod_fcgid-2.3.9.orig/modules/fcgid/mod_fcgid.c\n+++ mod_fcgid-2.3.9/modules/fcgid/mod_fcgid.c\n@@ -155,9 +155,15 @@ static void fcgid_add_cgi_vars(request_r\n * consistent with legacy mod_fcgid behavior and mod_fastcgi\n * prior to 2.4.7\n */\n- apr_table_setn(r->subprocess_env, *hdr, val);\n- /* standard munging of header name (upcase, HTTP_, etc.) */\n- apr_table_setn(r->subprocess_env, http2env(r->pool, *hdr), val);\n+ /* boo#988492 httpoxy don't set HTTP_PROXY */\n+ if ( strcasecmp(*hdr, \"HTTP_PROXY\") != 0 && strcasecmp(*hdr, \"HTTP-PROXY\") != 0) {\n+ apr_table_setn(r->subprocess_env, *hdr, val);\n+ }\n+ /* boo#988492 httpoxy don't set HTTP_PROXY */\n+ if ( strcasecmp(*hdr, \"PROXY\") != 0 ) {\n+ /* standard munging of header name (upcase, HTTP_, etc.) */\n+ apr_table_setn(r->subprocess_env, http2env(r->pool, *hdr), val);\n+ }\n }\n }\n }\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "Index: mod_fcgid-2.3.9/modules/fcgid/mod_fcgid.c\n===================================================================\n--- mod_fcgid-2.3.9.orig/modules/fcgid/mod_fcgid.c\n+++ mod_fcgid-2.3.9/modules/fcgid/mod_fcgid.c\n@@ -155,9 +155,15 @@ static void fcgid_add_cgi_vars(request_r\n * consistent with legacy mod_fcgid behavior and mod_fastcgi\n * prior to 2.4.7\n */\n- apr_table_setn(r->subprocess_env, *hdr, val);\n- /* standard munging of header name (upcase, HTTP_, etc.) */\n- apr_table_setn(r->subprocess_env, http2env(r->pool, *hdr), val);\n+ /* boo#988492 httpoxy don't set HTTP_PROXY */\n+ if ( strcasecmp(*hdr, \"HTTP_PROXY\") != 0 && strcasecmp(*hdr, \"HTTP-PROXY\") != 0) {\n+ apr_table_setn(r->subprocess_env, *hdr, val);\n+ }\n+ /* boo#988492 httpoxy don't set HTTP_PROXY */\n+ if ( strcasecmp(*hdr, \"PROXY\") != 0 ) {\n+ /* standard munging of header name (upcase, HTTP_, etc.) */\n+ apr_table_setn(r->subprocess_env, http2env(r->pool, *hdr), val);\n+ }\n }\n }\n }"}], "metadata": {"id": "apache2-mod_fcgid-5488-mod_fcgid-2.3.9-CVE-2016-10001", "cve_id": "CVE-2016-1000104", "package": "apache2-mod_fcgid", "tier": "identical", "has_source_context": false, "license": "GPL-2.0-or-later"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1i.orig/apps/s_server.c\n- apps/s_server.c\n- openssl-1.0.1i/apps/s_server.c\n\n## Target Source Code\n\n### apps/s_server.c\n\n#### generate_session_id() [lines 3002-3026]\n```c\n#endif\n\n#define MAX_SESSION_ID_ATTEMPTS 10\nstatic int generate_session_id(const SSL *ssl, unsigned char *id,\n\t\t\t\tunsigned int *id_len)\n\t{\n\tunsigned int count = 0;\n\tdo\t{\n\t\tRAND_pseudo_bytes(id, *id_len);\n\t\t/* Prefix the session_id with the required prefix. NB: If our\n\t\t * prefix is too long, clip it - but there will be worse effects\n\t\t * anyway, eg. the server could only possibly create 1 session\n\t\t * ID (ie. the prefix!) so all future session negotiations will\n\t\t * fail due to conflicts. */\n\t\tmemcpy(id, session_id_prefix,\n\t\t\t(strlen(session_id_prefix) < *id_len) ?\n\t\t\tstrlen(session_id_prefix) : *id_len);\n\t\t}\n\twhile(SSL_has_matching_session_id(ssl, id, *id_len) &&\n\t\t(++count < MAX_SESSION_ID_ATTEMPTS));\n\tif(count >= MAX_SESSION_ID_ATTEMPTS)\n\t\treturn 0;\n\treturn 1;\n\t}\n\n```\n\n#### s_server_init() [lines 423-457]\n```c\n#endif\n\n#ifdef MONOLITH\nstatic void s_server_init(void)\n\t{\n\taccept_socket=-1;\n\tcipher=NULL;\n\ts_server_verify=SSL_VERIFY_NONE;\n\ts_dcert_file=NULL;\n\ts_dkey_file=NULL;\n\ts_cert_file=TEST_CERT;\n\ts_key_file=NULL;\n#ifndef OPENSSL_NO_TLSEXT\n\ts_cert_file2=TEST_CERT2;\n\ts_key_file2=NULL;\n\tctx2=NULL;\n#endif\n#ifdef FIONBIO\n\ts_nbio=0;\n#endif\n\ts_nbio_test=0;\n\tctx=NULL;\n\twww=0;\n\n\tbio_s_out=NULL;\n\ts_debug=0;\n\ts_msg=0;\n\ts_quiet=0;\n\thack=0;\n#ifndef OPENSSL_NO_ENGINE\n\tengine_id=NULL;\n#endif\n\t}\n#endif\n\n```\n\n#### region() [lines 1681-1701]\n```c\n\n\t\tSSL_CTX_set_tmp_dh(ctx,dh);\n#ifndef OPENSSL_NO_TLSEXT\n\t\tif (ctx2)\n\t\t\t{\n\t\t\tif (!dhfile)\n\t\t\t\t{ \n\t\t\t\tDH *dh2=load_dh_param(s_cert_file2);\n\t\t\t\tif (dh2 != NULL)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_s_out,\"Setting temp DH parameters\\n\");\n\t\t\t\t\t(void)BIO_flush(bio_s_out);\n\n\t\t\t\t\tDH_free(dh);\n\t\t\t\t\tdh = dh2;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tSSL_CTX_set_tmp_dh(ctx2,dh);\n\t\t\t}\n#endif\n\t\tDH_free(dh);\n```\n\n\n## Upstream Fix\n```diff\nFrom f1612746ec7580132f81fb81a23f6705e63d113b Mon Sep 17 00:00:00 2001\nFrom: Emilia Kasper \nDate: Tue, 12 May 2015 20:15:46 +0200\nSubject: [PATCH] s_server: Use 2048-bit DH parameters by default.\n\nReviewed-by: Rich Salz \n---\n apps/s_server.c | 58 ++++++++++++++++++++++++++++++++++---------------\n 1 file changed, 40 insertions(+), 18 deletions(-)\n\ndiff --git a/apps/s_server.c b/apps/s_server.c\nindex 093a80d583e5b..7e501d21b92ae 100644\n--- a/apps/s_server.c\n+++ b/apps/s_server.c\n@@ -219,7 +219,7 @@ static int generate_session_id(const SSL *ssl, unsigned char *id,\n unsigned int *id_len);\n #ifndef OPENSSL_NO_DH\n static DH *load_dh_param(const char *dhfile);\n-static DH *get_dh512(void);\n+static DH *get_dh2048(void);\n #endif\n \n #ifdef MONOLITH\n@@ -227,30 +227,48 @@ static void s_server_init(void);\n #endif\n \n #ifndef OPENSSL_NO_DH\n-static unsigned char dh512_p[] = {\n- 0xDA, 0x58, 0x3C, 0x16, 0xD9, 0x85, 0x22, 0x89, 0xD0, 0xE4, 0xAF, 0x75,\n- 0x6F, 0x4C, 0xCA, 0x92, 0xDD, 0x4B, 0xE5, 0x33, 0xB8, 0x04, 0xFB, 0x0F,\n- 0xED, 0x94, 0xEF, 0x9C, 0x8A, 0x44, 0x03, 0xED, 0x57, 0x46, 0x50, 0xD3,\n- 0x69, 0x99, 0xDB, 0x29, 0xD7, 0x76, 0x27, 0x6B, 0xA2, 0xD3, 0xD4, 0x12,\n- 0xE2, 0x18, 0xF4, 0xDD, 0x1E, 0x08, 0x4C, 0xF6, 0xD8, 0x00, 0x3E, 0x7C,\n- 0x47, 0x74, 0xE8, 0x33,\n+static unsigned char dh2048_p[] = {\n+ 0xF6,0x42,0x57,0xB7,0x08,0x7F,0x08,0x17,0x72,0xA2,0xBA,0xD6,\n+ 0xA9,0x42,0xF3,0x05,0xE8,0xF9,0x53,0x11,0x39,0x4F,0xB6,0xF1,\n+ 0x6E,0xB9,0x4B,0x38,0x20,0xDA,0x01,0xA7,0x56,0xA3,0x14,0xE9,\n+ 0x8F,0x40,0x55,0xF3,0xD0,0x07,0xC6,0xCB,0x43,0xA9,0x94,0xAD,\n+ 0xF7,0x4C,0x64,0x86,0x49,0xF8,0x0C,0x83,0xBD,0x65,0xE9,0x17,\n+ 0xD4,0xA1,0xD3,0x50,0xF8,0xF5,0x59,0x5F,0xDC,0x76,0x52,0x4F,\n+ 0x3D,0x3D,0x8D,0xDB,0xCE,0x99,0xE1,0x57,0x92,0x59,0xCD,0xFD,\n+ 0xB8,0xAE,0x74,0x4F,0xC5,0xFC,0x76,0xBC,0x83,0xC5,0x47,0x30,\n+ 0x61,0xCE,0x7C,0xC9,0x66,0xFF,0x15,0xF9,0xBB,0xFD,0x91,0x5E,\n+ 0xC7,0x01,0xAA,0xD3,0x5B,0x9E,0x8D,0xA0,0xA5,0x72,0x3A,0xD4,\n+ 0x1A,0xF0,0xBF,0x46,0x00,0x58,0x2B,0xE5,0xF4,0x88,0xFD,0x58,\n+ 0x4E,0x49,0xDB,0xCD,0x20,0xB4,0x9D,0xE4,0x91,0x07,0x36,0x6B,\n+ 0x33,0x6C,0x38,0x0D,0x45,0x1D,0x0F,0x7C,0x88,0xB3,0x1C,0x7C,\n+ 0x5B,0x2D,0x8E,0xF6,0xF3,0xC9,0x23,0xC0,0x43,0xF0,0xA5,0x5B,\n+ 0x18,0x8D,0x8E,0xBB,0x55,0x8C,0xB8,0x5D,0x38,0xD3,0x34,0xFD,\n+ 0x7C,0x17,0x57,0x43,0xA3,0x1D,0x18,0x6C,0xDE,0x33,0x21,0x2C,\n+ 0xB5,0x2A,0xFF,0x3C,0xE1,0xB1,0x29,0x40,0x18,0x11,0x8D,0x7C,\n+ 0x84,0xA7,0x0A,0x72,0xD6,0x86,0xC4,0x03,0x19,0xC8,0x07,0x29,\n+ 0x7A,0xCA,0x95,0x0C,0xD9,0x96,0x9F,0xAB,0xD0,0x0A,0x50,0x9B,\n+ 0x02,0x46,0xD3,0x08,0x3D,0x66,0xA4,0x5D,0x41,0x9F,0x9C,0x7C,\n+ 0xBD,0x89,0x4B,0x22,0x19,0x26,0xBA,0xAB,0xA2,0x5E,0xC3,0x55,\n+ 0xE9,0x32,0x0B,0x3B,\n };\n \n-static unsigned char dh512_g[] = {\n+static unsigned char dh2048_g[] = {\n 0x02,\n };\n \n-static DH *get_dh512(void)\n+DH *get_dh2048()\n {\n- DH *dh = NULL;\n+ DH *dh;\n \n if ((dh = DH_new()) == NULL)\n- return (NULL);\n- dh->p = BN_bin2bn(dh512_p, sizeof(dh512_p), NULL);\n- dh->g = BN_bin2bn(dh512_g, sizeof(dh512_g), NULL);\n- if ((dh->p == NULL) || (dh->g == NULL))\n- return (NULL);\n- return (dh);\n+ return NULL;\n+ dh->p=BN_bin2bn(dh2048_p, sizeof(dh2048_p), NULL);\n+ dh->g=BN_bin2bn(dh2048_g, sizeof(dh2048_g), NULL);\n+ if (dh->p == NULL || dh->g == NULL) {\n+ DH_free(dh);\n+ return NULL;\n+ }\n+ return dh;\n }\n #endif\n \n@@ -1654,7 +1672,11 @@ int MAIN(int argc, char *argv[])\n BIO_printf(bio_s_out, \"Setting temp DH parameters\\n\");\n } else {\n BIO_printf(bio_s_out, \"Using default temp DH parameters\\n\");\n- dh = get_dh512();\n+ dh = get_dh2048();\n+ if (dh == NULL) {\n+ ERR_print_errors(bio_err);\n+ goto end;\n+ }\n }\n (void)BIO_flush(bio_s_out);\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From f1612746ec7580132f81fb81a23f6705e63d113b Mon Sep 17 00:00:00 2001\nFrom: Emilia Kasper \nDate: Tue, 12 May 2015 20:15:46 +0200\nSubject: [PATCH 1/5] s_server: Use 2048-bit DH parameters by default.\n\nReviewed-by: Rich Salz \n---\n apps/s_server.c | 58 +++++++++++++++++++++++++++++++++++++++------------------\n 1 file changed, 40 insertions(+), 18 deletions(-)\n\nIndex: openssl-1.0.1i/apps/s_server.c\n===================================================================\n--- openssl-1.0.1i.orig/apps/s_server.c\t2015-06-12 13:12:46.438719292 +0200\n+++ openssl-1.0.1i/apps/s_server.c\t2015-06-12 13:16:33.563456375 +0200\n@@ -214,7 +214,7 @@ static int generate_session_id(const SSL\n \t\t\t\tunsigned int *id_len);\n #ifndef OPENSSL_NO_DH\n static DH *load_dh_param(const char *dhfile);\n-static DH *get_dh512(void);\n+static DH *get_dh2048(void);\n #endif\n \n #ifdef MONOLITH\n@@ -222,28 +222,46 @@ static void s_server_init(void);\n #endif\n \n #ifndef OPENSSL_NO_DH\n-static unsigned char dh512_p[]={\n-\t0xDA,0x58,0x3C,0x16,0xD9,0x85,0x22,0x89,0xD0,0xE4,0xAF,0x75,\n-\t0x6F,0x4C,0xCA,0x92,0xDD,0x4B,0xE5,0x33,0xB8,0x04,0xFB,0x0F,\n-\t0xED,0x94,0xEF,0x9C,0x8A,0x44,0x03,0xED,0x57,0x46,0x50,0xD3,\n-\t0x69,0x99,0xDB,0x29,0xD7,0x76,0x27,0x6B,0xA2,0xD3,0xD4,0x12,\n-\t0xE2,0x18,0xF4,0xDD,0x1E,0x08,0x4C,0xF6,0xD8,0x00,0x3E,0x7C,\n-\t0x47,0x74,0xE8,0x33,\n+static unsigned char dh2048_p[] = {\n+ 0xF6,0x42,0x57,0xB7,0x08,0x7F,0x08,0x17,0x72,0xA2,0xBA,0xD6,\n+ 0xA9,0x42,0xF3,0x05,0xE8,0xF9,0x53,0x11,0x39,0x4F,0xB6,0xF1,\n+ 0x6E,0xB9,0x4B,0x38,0x20,0xDA,0x01,0xA7,0x56,0xA3,0x14,0xE9,\n+ 0x8F,0x40,0x55,0xF3,0xD0,0x07,0xC6,0xCB,0x43,0xA9,0x94,0xAD,\n+ 0xF7,0x4C,0x64,0x86,0x49,0xF8,0x0C,0x83,0xBD,0x65,0xE9,0x17,\n+ 0xD4,0xA1,0xD3,0x50,0xF8,0xF5,0x59,0x5F,0xDC,0x76,0x52,0x4F,\n+ 0x3D,0x3D,0x8D,0xDB,0xCE,0x99,0xE1,0x57,0x92,0x59,0xCD,0xFD,\n+ 0xB8,0xAE,0x74,0x4F,0xC5,0xFC,0x76,0xBC,0x83,0xC5,0x47,0x30,\n+ 0x61,0xCE,0x7C,0xC9,0x66,0xFF,0x15,0xF9,0xBB,0xFD,0x91,0x5E,\n+ 0xC7,0x01,0xAA,0xD3,0x5B,0x9E,0x8D,0xA0,0xA5,0x72,0x3A,0xD4,\n+ 0x1A,0xF0,0xBF,0x46,0x00,0x58,0x2B,0xE5,0xF4,0x88,0xFD,0x58,\n+ 0x4E,0x49,0xDB,0xCD,0x20,0xB4,0x9D,0xE4,0x91,0x07,0x36,0x6B,\n+ 0x33,0x6C,0x38,0x0D,0x45,0x1D,0x0F,0x7C,0x88,0xB3,0x1C,0x7C,\n+ 0x5B,0x2D,0x8E,0xF6,0xF3,0xC9,0x23,0xC0,0x43,0xF0,0xA5,0x5B,\n+ 0x18,0x8D,0x8E,0xBB,0x55,0x8C,0xB8,0x5D,0x38,0xD3,0x34,0xFD,\n+ 0x7C,0x17,0x57,0x43,0xA3,0x1D,0x18,0x6C,0xDE,0x33,0x21,0x2C,\n+ 0xB5,0x2A,0xFF,0x3C,0xE1,0xB1,0x29,0x40,0x18,0x11,0x8D,0x7C,\n+ 0x84,0xA7,0x0A,0x72,0xD6,0x86,0xC4,0x03,0x19,0xC8,0x07,0x29,\n+ 0x7A,0xCA,0x95,0x0C,0xD9,0x96,0x9F,0xAB,0xD0,0x0A,0x50,0x9B,\n+ 0x02,0x46,0xD3,0x08,0x3D,0x66,0xA4,0x5D,0x41,0x9F,0x9C,0x7C,\n+ 0xBD,0x89,0x4B,0x22,0x19,0x26,0xBA,0xAB,0xA2,0x5E,0xC3,0x55,\n+ 0xE9,0x32,0x0B,0x3B,\n \t};\n-static unsigned char dh512_g[]={\n+static unsigned char dh2048_g[] = {\n \t0x02,\n \t};\n \n-static DH *get_dh512(void)\n+DH *get_dh2048()\n \t{\n-\tDH *dh=NULL;\n+ DH *dh;\n \n \tif ((dh=DH_new()) == NULL) return(NULL);\n-\tdh->p=BN_bin2bn(dh512_p,sizeof(dh512_p),NULL);\n-\tdh->g=BN_bin2bn(dh512_g,sizeof(dh512_g),NULL);\n-\tif ((dh->p == NULL) || (dh->g == NULL))\n-\t\treturn(NULL);\n-\treturn(dh);\n+ dh->p=BN_bin2bn(dh2048_p, sizeof(dh2048_p), NULL);\n+ dh->g=BN_bin2bn(dh2048_g, sizeof(dh2048_g), NULL);\n+ if (dh->p == NULL || dh->g == NULL) {\n+ DH_free(dh);\n+ return NULL;\n+ }\n+ return dh;\n \t}\n #endif\n \n@@ -1685,7 +1703,11 @@ bad:\n \t\telse\n \t\t\t{\n \t\t\tBIO_printf(bio_s_out,\"Using default temp DH parameters\\n\");\n-\t\t\tdh=get_dh512();\n+ dh = get_dh2048();\n+ if (dh == NULL) {\n+ ERR_print_errors(bio_err);\n+ goto end;\n+ }\n \t\t\t}\n \t\t(void)BIO_flush(bio_s_out);"}], "metadata": {"id": "openssl-4598-0001-s_server-Use-2048-bit-DH-", "cve_id": "CVE-2015-3197", "package": "openssl", "upstream_enriched": true, "upstream_commit": "f1612746ec7580132f81fb81a23f6705e63d113b", "upstream_repo": "openssl/openssl", "tier": "adapted", "has_source_context": true, "context_tokens_est": 448, "context_files": 1, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-4658\n\nxpointer.c in libxml2 before 2.9.5 (as used in Apple iOS before 10, OS X before 10.12, tvOS before 10, and watchOS before 3, and other products) does not forbid namespace nodes in XPointer ranges, which allows remote attackers to execute arbitrary code or cause a denial of service (use-after-free and memory corruption) via a crafted XML document.\n\n## Package\nlibxml2\n\n## Files to modify\n- parser.c\n\n## Target Source Code\n\n### parser.c\n\n#### xmlParseMarkupDecl() [lines 6933-7019]\n```c\n return (NULL);\n\n htmlCtxtReset(ctxt);\n\n stream = xmlLoadExternalEntity(filename, NULL, ctxt);\n if (stream == NULL) {\n return (NULL);\n }\n inputPush(ctxt, stream);\n return (htmlDoRead(ctxt, NULL, encoding, options, 1));\n}\n\n/**\n * htmlCtxtReadMemory:\n * @ctxt: an HTML parser context\n * @buffer: a pointer to a char array\n * @size: the size of the array\n * @URL: the base URL to use for the document\n * @encoding: the document encoding, or NULL\n * @options: a combination of htmlParserOption(s)\n *\n * parse an XML in-memory document and build a tree.\n * This reuses the existing @ctxt parser context\n *\n * Returns the resulting document tree\n */\nhtmlDocPtr\nhtmlCtxtReadMemory(htmlParserCtxtPtr ctxt, const char *buffer, int size,\n const char *URL, const char *encoding, int options)\n{\n xmlParserInputBufferPtr input;\n xmlParserInputPtr stream;\n\n if (ctxt == NULL)\n return (NULL);\n if (buffer == NULL)\n return (NULL);\n\n htmlCtxtReset(ctxt);\n\n input = xmlParserInputBufferCreateMem(buffer, size, XML_CHAR_ENCODING_NONE);\n if (input == NULL) {\n\treturn(NULL);\n }\n\n stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE);\n if (stream == NULL) {\n\txmlFreeParserInputBuffer(input);\n\treturn(NULL);\n }\n\n inputPush(ctxt, stream);\n return (htmlDoRead(ctxt, URL, encoding, options, 1));\n}\n\n/**\n * htmlCtxtReadFd:\n * @ctxt: an HTML parser context\n * @fd: an open file descriptor\n * @URL: the base URL to use for the document\n * @encoding: the document encoding, or NULL\n * @options: a combination of htmlParserOption(s)\n *\n * parse an XML from a file descriptor and build a tree.\n * This reuses the existing @ctxt parser context\n *\n * Returns the resulting document tree\n */\nhtmlDocPtr\nhtmlCtxtReadFd(htmlParserCtxtPtr ctxt, int fd,\n const char *URL, const char *encoding, int options)\n{\n xmlParserInputBufferPtr input;\n xmlParserInputPtr stream;\n\n if (fd < 0)\n return (NULL);\n if (ctxt == NULL)\n return (NULL);\n\n htmlCtxtReset(ctxt);\n\n\n input = xmlParserInputBufferCreateFd(fd, XML_CHAR_ENCODING_NONE);\n if (input == NULL)\n return (NULL);\n stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE);\n```\n\n\n## Upstream Fix\n```diff\nFrom ab2b9a93ff19cedde7befbf2fcc48c6e352b6cbe Mon Sep 17 00:00:00 2001\nFrom: Hugh Davenport \nDate: Tue, 3 Nov 2015 20:40:49 +0800\nSubject: [PATCH] Avoid extra processing of MarkupDecl when EOF\n\nFor https://bugzilla.gnome.org/show_bug.cgi?id=756263\n\nOne place where ctxt->instate == XML_PARSER_EOF whic was set up\nby entity detection issues doesn't get noticed, and even overrided\n---\n parser.c | 8 ++++++++\n 1 file changed, 8 insertions(+)\n\ndiff --git a/parser.c b/parser.c\nindex d67b3003b0..134afe7055 100644\n--- a/parser.c\n+++ b/parser.c\n@@ -6972,6 +6972,14 @@ xmlParseMarkupDecl(xmlParserCtxtPtr ctxt) {\n \t xmlParsePI(ctxt);\n \t}\n }\n+\n+ /*\n+ * detect requirement to exit there and act accordingly\n+ * and avoid having instate overriden later on\n+ */\n+ if (ctxt->instate == XML_PARSER_EOF)\n+ return;\n+\n /*\n * This is only for internal subset. On external entities,\n * the replacement is done before parsing stage\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From ab2b9a93ff19cedde7befbf2fcc48c6e352b6cbe Mon Sep 17 00:00:00 2001\nFrom: Hugh Davenport \nDate: Tue, 3 Nov 2015 20:40:49 +0800\nSubject: Avoid extra processing of MarkupDecl when EOF\n\nFor https://bugzilla.gnome.org/show_bug.cgi?id=756263\n\nOne place where ctxt->instate == XML_PARSER_EOF whic was set up\nby entity detection issues doesn't get noticed, and even overrided\n---\n parser.c | 8 ++++++++\n 1 file changed, 8 insertions(+)\n\ndiff --git a/parser.c b/parser.c\nindex d67b300..134afe7 100644\n--- a/parser.c\n+++ b/parser.c\n@@ -6972,6 +6972,14 @@ xmlParseMarkupDecl(xmlParserCtxtPtr ctxt) {\n \t xmlParsePI(ctxt);\n \t}\n }\n+\n+ /*\n+ * detect requirement to exit there and act accordingly\n+ * and avoid having instate overriden later on\n+ */\n+ if (ctxt->instate == XML_PARSER_EOF)\n+ return;\n+\n /*\n * This is only for internal subset. On external entities,\n * the replacement is done before parsing stage\n-- \ncgit v0.11.2"}], "metadata": {"id": "libxml2-5762-libxml2-2.9.1-CVE-2015-8241.pa", "cve_id": "CVE-2016-4658", "package": "libxml2", "upstream_enriched": true, "upstream_commit": "ab2b9a93ff19cedde7befbf2fcc48c6e352b6cbe", "upstream_repo": "GNOME/libxml2", "tier": "adapted", "has_source_context": true, "context_tokens_est": 585, "context_files": 1, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2024-33601\n\nnscd: netgroup cache may terminate daemon on memory allocation failure\n\nThe Name Service Cache Daemon's (nscd) netgroup cache uses xmalloc or\nxrealloc and these functions may terminate the process due to a memory\nallocation failure resulting in a denial of service to the clients. The\nflaw was introduced in glibc 2.15 when the cache was added to nscd.\n\nThis vulnerability is only present in the nscd binary.\n\nSeverity: HIGH\nCVSS Score: 7.3\n\n## Package\nglibc\n\n## Files to modify\n- nscd/netgroupcache.c\n\n## Upstream Fix\n```diff\nFrom c04a21e050d64a1193a6daab872bca2528bda44b Mon Sep 17 00:00:00 2001\nFrom: Florian Weimer \nDate: Thu, 25 Apr 2024 15:01:07 +0200\nSubject: [PATCH 4/4] CVE-2024-33601, CVE-2024-33602: nscd: netgroup: Use two\n buffers in addgetnetgrentX (bug 31680)\n\nThis avoids potential memory corruption when the underlying NSS\ncallback function does not use the buffer space to store all strings\n(e.g., for constant strings).\n\nInstead of custom buffer management, two scratch buffers are used.\nThis increases stack usage somewhat.\n\nScratch buffer allocation failure is handled by return -1\n(an invalid timeout value) instead of terminating the process.\nThis fixes bug 31679.\n\nReviewed-by: Siddhesh Poyarekar \n---\n nscd/netgroupcache.c | 219 ++++++++++++++++++++++++-------------------\n 1 file changed, 121 insertions(+), 98 deletions(-)\n\ndiff --git a/nscd/netgroupcache.c b/nscd/netgroupcache.c\nindex e22ffa5884..e8fe041846 100644\n--- a/nscd/netgroupcache.c\n+++ b/nscd/netgroupcache.c\n@@ -23,6 +23,7 @@\n #include \n #include \n #include \n+#include \n \n #include \"../inet/netgroup.h\"\n #include \"nscd.h\"\n@@ -65,6 +66,16 @@ struct dataset\n char strdata[0];\n };\n \n+/* Send a notfound response to FD. Always returns -1 to indicate an\n+ ephemeral error. */\n+static time_t\n+send_notfound (int fd)\n+{\n+ if (fd != -1)\n+ TEMP_FAILURE_RETRY (send (fd, ¬found, sizeof (notfound), MSG_NOSIGNAL));\n+ return -1;\n+}\n+\n /* Sends a notfound message and prepares a notfound dataset to write to the\n cache. Returns true if there was enough memory to allocate the dataset and\n returns the dataset in DATASETP, total bytes to write in TOTALP and the\n@@ -83,8 +94,7 @@ do_notfound (struct database_dyn *db, int fd, request_header *req,\n total = sizeof (notfound);\n timeout = time (NULL) + db->negtimeout;\n \n- if (fd != -1)\n- TEMP_FAILURE_RETRY (send (fd, ¬found, total, MSG_NOSIGNAL));\n+ send_notfound (fd);\n \n dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len, 1);\n /* If we cannot permanently store the result, so be it. */\n@@ -109,11 +119,78 @@ do_notfound (struct database_dyn *db, int fd, request_header *req,\n return cacheable;\n }\n \n+struct addgetnetgrentX_scratch\n+{\n+ /* This is the result that the caller should use. It can be NULL,\n+ point into buffer, or it can be in the cache. */\n+ struct dataset *dataset;\n+\n+ struct scratch_buffer buffer;\n+\n+ /* Used internally in addgetnetgrentX as a staging area. */\n+ struct scratch_buffer tmp;\n+\n+ /* Number of bytes in buffer that are actually used. */\n+ size_t buffer_used;\n+};\n+\n+static void\n+addgetnetgrentX_scratch_init (struct addgetnetgrentX_scratch *scratch)\n+{\n+ scratch->dataset = NULL;\n+ scratch_buffer_init (&scratch->buffer);\n+ scratch_buffer_init (&scratch->tmp);\n+\n+ /* Reserve space for the header. */\n+ scratch->buffer_used = sizeof (struct dataset);\n+ static_assert (sizeof (struct dataset) < sizeof (scratch->tmp.__space),\n+\t\t \"initial buffer space\");\n+ memset (scratch->tmp.data, 0, sizeof (struct dataset));\n+}\n+\n+static void\n+addgetnetgrentX_scratch_free (struct addgetnetgrentX_scratch *scratch)\n+{\n+ scratch_buffer_free (&scratch->buffer);\n+ scratch_buffer_free (&scratch->tmp);\n+}\n+\n+/* Copy LENGTH bytes from S into SCRATCH. Returns NULL if SCRATCH\n+ could not be resized, otherwise a pointer to the copy. */\n+static char *\n+addgetnetgrentX_append_n (struct addgetnetgrentX_scratch *scratch,\n+\t\t\t const char *s, size_t length)\n+{\n+ while (true)\n+ {\n+ size_t remaining = scratch->buffer.length - scratch->buffer_used;\n+ if (remaining >= length)\n+\tbreak;\n+ if (!scratch_buffer_grow_preserve (&scratch->buffer))\n+\treturn NULL;\n+ }\n+ char *copy = scratch->buffer.data + scratch->buffer_used;\n+ memcpy (copy, s, length);\n+ scratch->buffer_used += length;\n+ return copy;\n+}\n+\n+/* Copy S into SCRATCH, including its null terminator. Returns false\n+ if SCRATCH could not be resized. */\n+static bool\n+addgetnetgrentX_append (struct addgetnetgrentX_scratch *scratch, const char *s)\n+{\n+ if (s == NULL)\n+ s = \"\";\n+ return addgetnetgrentX_append_n (scratch, s, strlen (s) + 1) != NULL;\n+}\n+\n+/* Caller must initialize and free *SCRATCH. If the return value is\n+ negative, this function has sent a notfound response. */\n static time_t\n addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,\n \t\t const char *key, uid_t uid, struct hashentry *he,\n-\t\t struct datahead *dh, struct dataset **resultp,\n-\t\t void **tofreep)\n+\t\t struct datahead *dh, struct addgetnetgrentX_scratch *scratch)\n {\n if (__glibc_unlikely (debug_level > 0))\n {\n@@ -132,14 +209,10 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,\n \n char *key_copy = NULL;\n struct __netgrent data;\n- size_t buflen = MAX (1024, sizeof (*dataset) + req->key_len);\n- size_t buffilled = sizeof (*dataset);\n- char *buffer = NULL;\n size_t nentries = 0;\n size_t group_len = strlen (key) + 1;\n struct name_list *first_needed\n = alloca (sizeof (struct name_list) + group_len);\n- *tofreep = NULL;\n \n if (netgroup_database == NULL\n && !__nss_database_get (nss_database_netgroup, &netgroup_database))\n@@ -151,8 +224,6 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,\n }\n \n memset (&data, '\\0', sizeof (data));\n- buffer = xmalloc (buflen);\n- *tofreep = buffer;\n first_needed->next = first_needed;\n memcpy (first_needed->name, key, group_len);\n data.needed_groups = first_needed;\n@@ -195,8 +266,8 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,\n \t\twhile (1)\n \t\t {\n \t\t int e;\n-\t\t status = getfct.f (&data, buffer + buffilled,\n-\t\t\t\t buflen - buffilled - req->key_len, &e);\n+\t\t status = getfct.f (&data, scratch->tmp.data,\n+\t\t\t\t scratch->tmp.length, &e);\n \t\t if (status == NSS_STATUS_SUCCESS)\n \t\t {\n \t\t\tif (data.type == triple_val)\n@@ -204,68 +275,10 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,\n \t\t\t const char *nhost = data.val.triple.host;\n \t\t\t const char *nuser = data.val.triple.user;\n \t\t\t const char *ndomain = data.val.triple.domain;\n-\n-\t\t\t size_t hostlen = strlen (nhost ?: \"\") + 1;\n-\t\t\t size_t userlen = strlen (nuser ?: \"\") + 1;\n-\t\t\t size_t domainlen = strlen (ndomain ?: \"\") + 1;\n-\n-\t\t\t if (nhost == NULL || nuser == NULL || ndomain == NULL\n-\t\t\t\t|| nhost > nuser || nuser > ndomain)\n-\t\t\t {\n-\t\t\t\tconst char *last = nhost;\n-\t\t\t\tif (last == NULL\n-\t\t\t\t || (nuser != NULL && nuser > last))\n-\t\t\t\t last = nuser;\n-\t\t\t\tif (last == NULL\n-\t\t\t\t || (ndomain != NULL && ndomain > last))\n-\t\t\t\t last = ndomain;\n-\n-\t\t\t\tsize_t bufused\n-\t\t\t\t = (last == NULL\n-\t\t\t\t ? buffilled\n-\t\t\t\t : last + strlen (last) + 1 - buffer);\n-\n-\t\t\t\t/* We have to make temporary copies. */\n-\t\t\t\tsize_t needed = hostlen + userlen + domainlen;\n-\n-\t\t\t\tif (buflen - req->key_len - bufused < needed)\n-\t\t\t\t {\n-\t\t\t\t buflen += MAX (buflen, 2 * needed);\n-\t\t\t\t /* Save offset in the old buffer. We don't\n-\t\t\t\t bother with the NULL check here since\n-\t\t\t\t we'll do that later anyway. */\n-\t\t\t\t size_t nhostdiff = nhost - buffer;\n-\t\t\t\t size_t nuserdiff = nuser - buffer;\n-\t\t\t\t size_t ndomaindiff = ndomain - buffer;\n-\n-\t\t\t\t char *newbuf = xrealloc (buffer, buflen);\n-\t\t\t\t /* Fix up the triplet pointers into the new\n-\t\t\t\t buffer. */\n-\t\t\t\t nhost = (nhost ? newbuf + nhostdiff\n-\t\t\t\t\t : NULL);\n-\t\t\t\t nuser = (nuser ? newbuf + nuserdiff\n-\t\t\t\t\t : NULL);\n-\t\t\t\t ndomain = (ndomain ? newbuf + ndomaindiff\n-\t\t\t\t\t : NULL);\n-\t\t\t\t *tofreep = buffer = newbuf;\n-\t\t\t\t }\n-\n-\t\t\t\tnhost = memcpy (buffer + bufused,\n-\t\t\t\t\t\tnhost ?: \"\", hostlen);\n-\t\t\t\tnuser = memcpy ((char *) nhost + hostlen,\n-\t\t\t\t\t\tnuser ?: \"\", userlen);\n-\t\t\t\tndomain = memcpy ((char *) nuser + userlen,\n-\t\t\t\t\t\t ndomain ?: \"\", domainlen);\n-\t\t\t }\n-\n-\t\t\t char *wp = buffer + buffilled;\n-\t\t\t wp =\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From c04a21e050d64a1193a6daab872bca2528bda44b Mon Sep 17 00:00:00 2001\nFrom: Florian Weimer \nDate: Thu, 25 Apr 2024 15:01:07 +0200\nSubject: [PATCH 4/4] CVE-2024-33601, CVE-2024-33602: nscd: netgroup: Use two\n buffers in addgetnetgrentX (bug 31680)\n\nThis avoids potential memory corruption when the underlying NSS\ncallback function does not use the buffer space to store all strings\n(e.g., for constant strings).\n\nInstead of custom buffer management, two scratch buffers are used.\nThis increases stack usage somewhat.\n\nScratch buffer allocation failure is handled by return -1\n(an invalid timeout value) instead of terminating the process.\nThis fixes bug 31679.\n\nReviewed-by: Siddhesh Poyarekar \n---\n nscd/netgroupcache.c | 219 ++++++++++++++++++++++++-------------------\n 1 file changed, 121 insertions(+), 98 deletions(-)\n\ndiff --git a/nscd/netgroupcache.c b/nscd/netgroupcache.c\nindex e22ffa5884..e8fe041846 100644\n--- a/nscd/netgroupcache.c\n+++ b/nscd/netgroupcache.c\n@@ -23,6 +23,7 @@\n #include \n #include \n #include \n+#include \n \n #include \"../inet/netgroup.h\"\n #include \"nscd.h\"\n@@ -65,6 +66,16 @@ struct dataset\n char strdata[0];\n };\n \n+/* Send a notfound response to FD. Always returns -1 to indicate an\n+ ephemeral error. */\n+static time_t\n+send_notfound (int fd)\n+{\n+ if (fd != -1)\n+ TEMP_FAILURE_RETRY (send (fd, ¬found, sizeof (notfound), MSG_NOSIGNAL));\n+ return -1;\n+}\n+\n /* Sends a notfound message and prepares a notfound dataset to write to the\n cache. Returns true if there was enough memory to allocate the dataset and\n returns the dataset in DATASETP, total bytes to write in TOTALP and the\n@@ -83,8 +94,7 @@ do_notfound (struct database_dyn *db, int fd, request_header *req,\n total = sizeof (notfound);\n timeout = time (NULL) + db->negtimeout;\n \n- if (fd != -1)\n- TEMP_FAILURE_RETRY (send (fd, ¬found, total, MSG_NOSIGNAL));\n+ send_notfound (fd);\n \n dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len, 1);\n /* If we cannot permanently store the result, so be it. */\n@@ -109,11 +119,78 @@ do_notfound (struct database_dyn *db, int fd, request_header *req,\n return cacheable;\n }\n \n+struct addgetnetgrentX_scratch\n+{\n+ /* This is the result that the caller should use. It can be NULL,\n+ point into buffer, or it can be in the cache. */\n+ struct dataset *dataset;\n+\n+ struct scratch_buffer buffer;\n+\n+ /* Used internally in addgetnetgrentX as a staging area. */\n+ struct scratch_buffer tmp;\n+\n+ /* Number of bytes in buffer that are actually used. */\n+ size_t buffer_used;\n+};\n+\n+static void\n+addgetnetgrentX_scratch_init (struct addgetnetgrentX_scratch *scratch)\n+{\n+ scratch->dataset = NULL;\n+ scratch_buffer_init (&scratch->buffer);\n+ scratch_buffer_init (&scratch->tmp);\n+\n+ /* Reserve space for the header. */\n+ scratch->buffer_used = sizeof (struct dataset);\n+ static_assert (sizeof (struct dataset) < sizeof (scratch->tmp.__space),\n+\t\t \"initial buffer space\");\n+ memset (scratch->tmp.data, 0, sizeof (struct dataset));\n+}\n+\n+static void\n+addgetnetgrentX_scratch_free (struct addgetnetgrentX_scratch *scratch)\n+{\n+ scratch_buffer_free (&scratch->buffer);\n+ scratch_buffer_free (&scratch->tmp);\n+}\n+\n+/* Copy LENGTH bytes from S into SCRATCH. Returns NULL if SCRATCH\n+ could not be resized, otherwise a pointer to the copy. */\n+static char *\n+addgetnetgrentX_append_n (struct addgetnetgrentX_scratch *scratch,\n+\t\t\t const char *s, size_t length)\n+{\n+ while (true)\n+ {\n+ size_t remaining = scratch->buffer.length - scratch->buffer_used;\n+ if (remaining >= length)\n+\tbreak;\n+ if (!scratch_buffer_grow_preserve (&scratch->buffer))\n+\treturn NULL;\n+ }\n+ char *copy = scratch->buffer.data + scratch->buffer_used;\n+ memcpy (copy, s, length);\n+ scratch->buffer_used += length;\n+ return copy;\n+}\n+\n+/* Copy S into SCRATCH, including its null terminator. Returns false\n+ if SCRATCH could not be resized. */\n+static bool\n+addgetnetgrentX_append (struct addgetnetgrentX_scratch *scratch, const char *s)\n+{\n+ if (s == NULL)\n+ s = \"\";\n+ return addgetnetgrentX_append_n (scratch, s, strlen (s) + 1) != NULL;\n+}\n+\n+/* Caller must initialize and free *SCRATCH. If the return value is\n+ negative, this function has sent a notfound response. */\n static time_t\n addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,\n \t\t const char *key, uid_t uid, struct hashentry *he,\n-\t\t struct datahead *dh, struct dataset **resultp,\n-\t\t void **tofreep)\n+\t\t struct datahead *dh, struct addgetnetgrentX_scratch *scratch)\n {\n if (__glibc_unlikely (debug_level > 0))\n {\n@@ -132,14 +209,10 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,\n \n char *key_copy = NULL;\n struct __netgrent data;\n- size_t buflen = MAX (1024, sizeof (*dataset) + req->key_len);\n- size_t buffilled = sizeof (*dataset);\n- char *buffer = NULL;\n size_t nentries = 0;\n size_t group_len = strlen (key) + 1;\n struct name_list *first_needed\n = alloca (sizeof (struct name_list) + group_len);\n- *tofreep = NULL;\n \n if (netgroup_database == NULL\n && !__nss_database_get (nss_database_netgroup, &netgroup_database))\n@@ -151,8 +224,6 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,\n }\n \n memset (&data, '\\0', sizeof (data));\n- buffer = xmalloc (buflen);\n- *tofreep = buffer;\n first_needed->next = first_needed;\n memcpy (first_needed->name, key, group_len);\n data.needed_groups = first_needed;\n@@ -195,8 +266,8 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,\n \t\twhile (1)\n \t\t {\n \t\t int e;\n-\t\t status = getfct.f (&data, buffer + buffilled,\n-\t\t\t\t buflen - buffilled - req->key_len, &e);\n+\t\t status = getfct.f (&data, scratch->tmp.data,\n+\t\t\t\t scratch->tmp.length, &e);\n \t\t if (status == NSS_STATUS_SUCCESS)\n \t\t {\n \t\t\tif (data.type == triple_val)\n@@ -204,68 +275,10 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,\n \t\t\t const char *nhost = data.val.triple.host;\n \t\t\t const char *nuser = data.val.triple.user;\n \t\t\t const char *ndomain = data.val.triple.domain;\n-\n-\t\t\t size_t hostlen = strlen (nhost ?: \"\") + 1;\n-\t\t\t size_t userlen = strlen (nuser ?: \"\") + 1;\n-\t\t\t size_t domainlen = strlen (ndomain ?: \"\") + 1;\n-\n-\t\t\t if (nhost == NULL || nuser == NULL || ndomain == NULL\n-\t\t\t\t|| nhost > nuser || nuser > ndomain)\n-\t\t\t {\n-\t\t\t\tconst char *last = nhost;\n-\t\t\t\tif (last == NULL\n-\t\t\t\t || (nuser != NULL && nuser > last))\n-\t\t\t\t last = nuser;\n-\t\t\t\tif (last == NULL\n-\t\t\t\t || (ndomain != NULL && ndomain > last))\n-\t\t\t\t last = ndomain;\n-\n-\t\t\t\tsize_t bufused\n-\t\t\t\t = (last == NULL\n-\t\t\t\t ? buffilled\n-\t\t\t\t : last + strlen (last) + 1 - buffer);\n-\n-\t\t\t\t/* We have to make temporary copies. */\n-\t\t\t\tsize_t needed = hostlen + userlen + domainlen;\n-\n-\t\t\t\tif (buflen - req->key_len - bufused < needed)\n-\t\t\t\t {\n-\t\t\t\t buflen += MAX (buflen, 2 * needed);\n-\t\t\t\t /* Save offset in the old buffer. We don't\n-\t\t\t\t bother with the NULL check here since\n-\t\t\t\t we'll do that later anyway. */\n-\t\t\t\t size_t nhostdiff = nhost - buffer;\n-\t\t\t\t size_t nuserdiff = nuser - buffer;\n-\t\t\t\t size_t ndomaindiff = ndomain - buffer;\n-\n-\t\t\t\t char *newbuf = xrealloc (buffer, buflen);\n-\t\t\t\t /* Fix up the triplet pointers into the new\n-\t\t\t\t buffer. */\n-\t\t\t\t nhost = (nhost ? newbuf + nhostdiff\n-\t\t\t\t\t : NULL);\n-\t\t\t\t nuser = (nuser ? newbuf + nuserdiff\n-\t\t\t\t\t : NULL);\n-\t\t\t\t ndomain = (ndomain ? newbuf + ndomaindiff\n-\t\t\t\t\t : NULL);\n-\t\t\t\t *tofreep = buffer = newbuf;\n-\t\t\t\t }\n-\n-\t\t\t\tnhost = memcpy (buffer + bufused,\n-\t\t\t\t\t\tnhost ?: \"\", hostlen);\n-\t\t\t\tnuser = memcpy ((char *) nhost + hostlen,\n-\t\t\t\t\t\tnuser ?: \"\", userlen);\n-\t\t\t\tndomain = memcpy ((char *) nuser + userlen,\n-\t\t\t\t\t\t ndomain ?: \"\", domainlen);\n-\t\t\t }\n-\n-\t\t\t char *wp = buffer + buffilled;\n-\t\t\t wp = memmove (wp, nhost ?: \"\", hostlen);\n-\t\t\t wp += hostlen;\n-\t\t\t wp = memmove (wp, nuser ?: \"\", userlen);\n-\t\t\t wp += userlen;\n-\t\t\t wp = memmove (wp, ndomain ?: \"\", domainlen);\n-\t\t\t wp += domainlen;\n-\t\t\t buffilled = wp - buffer;\n+\t\t\t if (!(addgetnetgrentX_append (scratch, nhost)\n+\t\t\t\t && addgetnetgrentX_append (scratch, nuser)\n+\t\t\t\t && addgetnetgrentX_append (scratch, ndomain)))\n+\t\t\t return send_notfound (fd);\n \t\t\t ++nentries;\n \t\t\t }\n \t\t\telse\n@@ -317,8 +330,8 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,\n \t\t }\n \t\t else if (status == NSS_STATUS_TRYAGAIN && e == ERANGE)\n \t\t {\n-\t\t\tbuflen *= 2;\n-\t\t\t*tofreep = buffer = xrealloc (buffer, buflen);\n+\t\t\tif (!scratch_buffer_grow (&scratch->tmp))\n+\t\t\t return send_notfound (fd);\n \t\t }\n \t\t else if (status == NSS_STATUS_RETURN\n \t\t\t || status == NSS_STATUS_NOTFOUND\n@@ -351,10 +364,17 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,\n goto maybe_cache_add;\n }\n \n- total = buffilled;\n+ /* Capture the result size without the key appended. */\n+ total = scratch->buffer_used;\n+\n+ /* Make a copy of the key. The scratch buffer must not move after\n+ this point. */\n+ key_copy = addgetnetgrentX_append_n (scratch, key, req->key_len);\n+ if (key_copy == NULL)\n+ return send_notfound (fd);\n \n /* Fill in the dataset. */\n- dataset = (struct dataset *) buffer;\n+ dataset = scratch->buffer.data;\n timeout = datahead_init_pos (&dataset->head, total + req->key_len,\n \t\t\t total - offsetof (struct dataset, resp),\n \t\t\t he == NULL ? 0 : dh->nreloads + 1,\n@@ -363,11 +383,7 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,\n dataset->resp.version = NSCD_VERSION;\n dataset->resp.found = 1;\n dataset->resp.nresults = nentries;\n- dataset->resp.result_len = buffilled - sizeof (*dataset);\n-\n- assert (buflen - buffilled >= req->key_len);\n- key_copy = memcpy (buffer + buffilled, key, req->key_len);\n- buffilled += req->key_len;\n+ dataset->resp.result_len = total - sizeof (*dataset);\n \n /* Now we can determine whether on refill we have to create a new\n record or not. */\n@@ -398,7 +414,7 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,\n if (__glibc_likely (newp != NULL))\n {\n \t/* Adjust pointer into the memory block. */\n-\tkey_copy = (char *) newp + (key_copy - buffer);\n+\tkey_copy = (char *) newp + (key_copy - (char *) dataset);\n \n \tdataset = memcpy (newp, dataset, total + req->key_len);\n \tcacheable = true;\n@@ -439,7 +455,7 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,\n }\n \n out:\n- *resultp = dataset;\n+ scratch->dataset = dataset;\n \n return timeout;\n }\n@@ -460,6 +476,9 @@ addinnetgrX (struct database_dyn *db, int fd, request_header *req,\n if (user != NULL)\n key = strchr (key, '\\0') + 1;\n const char *domain = *key++ ? key : NULL;\n+ struct addgetnetgrentX_scratch scratch;\n+\n+ addgetnetgrentX_scratch_init (&scratch);\n \n if (__glibc_unlikely (debug_level > 0))\n {\n@@ -475,12 +494,8 @@ addinnetgrX (struct database_dyn *db, int fd, request_header *req,\n \t\t\t\t\t\t\t group, group_len,\n \t\t\t\t\t\t\t db, uid);\n time_t timeout;\n- void *tofree;\n if (result != NULL)\n- {\n- timeout = result->head.timeout;\n- tofree = NULL;\n- }\n+ timeout = result->head.timeout;\n else\n {\n request_header req_get =\n@@ -489,7 +504,10 @@ addinnetgrX (struct database_dyn *db, int fd, request_header *req,\n \t .key_len = group_len\n \t};\n timeout = addgetnetgrentX (db, -1, &req_get, group, uid, NULL, NULL,\n-\t\t\t\t &result, &tofree);\n+\t\t\t\t &scratch);\n+ result = scratch.dataset;\n+ if (timeout < 0)\n+\tgoto out;\n }\n \n struct indataset\n@@ -603,7 +621,7 @@ addinnetgrX (struct database_dyn *db, int fd, request_header *req,\n }\n \n out:\n- free (tofree);\n+ addgetnetgrentX_scratch_free (&scratch);\n return timeout;\n }\n \n@@ -613,11 +631,12 @@ addgetnetgrentX_ignore (struct database_dyn *db, int fd, request_header *req,\n \t\t\tconst char *key, uid_t uid, struct hashentry *he,\n \t\t\tstruct datahead *dh)\n {\n- struct dataset *ignore;\n- void *tofree;\n- time_t timeout = addgetnetgrentX (db, fd, req, key, uid, he, dh,\n-\t\t\t\t &ignore, &tofree);\n- free (tofree);\n+ struct addgetnetgrentX_scratch scratch;\n+ addgetnetgrentX_scratch_init (&scratch);\n+ time_t timeout = addgetnetgrentX (db, fd, req, key, uid, he, dh, &scratch);\n+ addgetnetgrentX_scratch_free (&scratch);\n+ if (timeout < 0)\n+ timeout = 0;\n return timeout;\n }\n \n@@ -661,5 +680,9 @@ readdinnetgr (struct database_dyn *db, struct hashentry *he,\n .key_len = he->len\n };\n \n- return addinnetgrX (db, -1, &req, db->data + he->key, he->owner, he, dh);\n+ int timeout = addinnetgrX (db, -1, &req, db->data + he->key, he->owner,\n+\t\t\t he, dh);\n+ if (timeout < 0)\n+ timeout = 0;\n+ return timeout;\n }\n-- \n2.35.3"}], "metadata": {"id": "glibc-CVE-2024-33601-glibc-CVE-2024-33601", "cve_id": "CVE-2024-33601", "package": "glibc", "tier": "adapted", "has_source_context": false, "license": "LGPL-2.1-or-later"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-6250\n\nInteger overflow in the ISO9660 writer in libarchive before 3.2.1 allows remote attackers to cause a denial of service (application crash) or execute arbitrary code via vectors related to verifying filename lengths when writing an ISO9660 archive, which trigger a buffer overflow.\n\n## Package\nlibarchive\n\n## Files to modify\n- libarchive-3.1.2.orig/libarchive/archive_read_support_format_7zip.c\n- libarchive/archive_read_support_format_7zip.c\n\n## Target Source Code\n\n### libarchive/archive_read_support_format_7zip.c\n\n#### region() [lines 285-371]\n```c\n\t\tunsigned char\t\t*next_out;\n\t\tint64_t\t\t\t avail_out;\n\t\tint64_t\t\t\t total_out;\n\t\tint\t\t\t overconsumed;\n\t} ppstream;\n\tint\t\t\t ppmd7_valid;\n\n\t/* Decoding BCJ and BCJ2 data. */\n\tuint32_t\t\t bcj_state;\n\tsize_t\t\t\t odd_bcj_size;\n\tunsigned char\t\t odd_bcj[4];\n\t/* Decoding BCJ data. */\n\tsize_t\t\t\t bcj_prevPosT;\n\tuint32_t\t\t bcj_prevMask;\n\tuint32_t\t\t bcj_ip;\n\n\t/* Decoding BCJ2 data. */\n\tsize_t\t\t\t main_stream_bytes_remaining;\n\tunsigned char\t\t*sub_stream_buff[3];\n\tsize_t\t\t\t sub_stream_size[3];\n\tsize_t\t\t\t sub_stream_bytes_remaining[3];\n\tunsigned char\t\t*tmp_stream_buff;\n\tsize_t\t\t\t tmp_stream_buff_size;\n\tsize_t\t\t\t tmp_stream_bytes_avail;\n\tsize_t\t\t\t tmp_stream_bytes_remaining;\n#ifdef _LZMA_PROB32\n#define CProb uint32_t\n#else\n#define CProb uint16_t\n#endif\n\tCProb\t\t\t bcj2_p[256 + 2];\n\tuint8_t\t\t\t bcj2_prevByte;\n\tuint32_t\t\t bcj2_range;\n\tuint32_t\t\t bcj2_code;\n\tuint64_t\t\t bcj2_outPos;\n\n\t/* Filename character-set conversion data. */\n\tstruct archive_string_conv *sconv;\n\n\tchar\t\t\t format_name[64];\n};\n\nstatic int\tarchive_read_format_7zip_bid(struct archive_read *, int);\nstatic int\tarchive_read_format_7zip_cleanup(struct archive_read *);\nstatic int\tarchive_read_format_7zip_read_data(struct archive_read *,\n\t\t const void **, size_t *, int64_t *);\nstatic int\tarchive_read_format_7zip_read_data_skip(struct archive_read *);\nstatic int\tarchive_read_format_7zip_read_header(struct archive_read *,\n\t\t struct archive_entry *);\nstatic int\tcheck_7zip_header_in_sfx(const char *);\nstatic unsigned long decode_codec_id(const unsigned char *, size_t);\nstatic int\tdecode_encoded_header_info(struct archive_read *,\n\t\t struct _7z_stream_info *);\nstatic int\tdecompress(struct archive_read *, struct _7zip *,\n\t\t void *, size_t *, const void *, size_t *);\nstatic ssize_t\textract_pack_stream(struct archive_read *, size_t);\nstatic void\tfileTimeToUtc(uint64_t, time_t *, long *);\nstatic uint64_t folder_uncompressed_size(struct _7z_folder *);\nstatic void\tfree_CodersInfo(struct _7z_coders_info *);\nstatic void\tfree_Digest(struct _7z_digests *);\nstatic void\tfree_Folder(struct _7z_folder *);\nstatic void\tfree_Header(struct _7z_header_info *);\nstatic void\tfree_PackInfo(struct _7z_pack_info *);\nstatic void\tfree_StreamsInfo(struct _7z_stream_info *);\nstatic void\tfree_SubStreamsInfo(struct _7z_substream_info *);\nstatic int\tfree_decompression(struct archive_read *, struct _7zip *);\nstatic ssize_t\tget_uncompressed_data(struct archive_read *, const void **,\n\t\t size_t, size_t);\nstatic const unsigned char * header_bytes(struct archive_read *, size_t);\nstatic int\tinit_decompression(struct archive_read *, struct _7zip *,\n\t\t const struct _7z_coder *, const struct _7z_coder *);\nstatic int\tparse_7zip_uint64(struct archive_read *, uint64_t *);\nstatic int\tread_Bools(struct archive_read *, unsigned char *, size_t);\nstatic int\tread_CodersInfo(struct archive_read *,\n\t\t struct _7z_coders_info *);\nstatic int\tread_Digests(struct archive_read *, struct _7z_digests *,\n\t\t size_t);\nstatic int\tread_Folder(struct archive_read *, struct _7z_folder *);\nstatic int\tread_Header(struct archive_read *, struct _7z_header_info *,\n\t\t int);\nstatic int\tread_PackInfo(struct archive_read *, struct _7z_pack_info *);\nstatic int\tread_StreamsInfo(struct archive_read *,\n\t\t struct _7z_stream_info *);\nstatic int\tread_SubStreamsInfo(struct archive_read *,\n\t\t struct _7z_substream_info *, struct _7z_folder *, size_t);\nstatic int\tread_Times(struct archive_read *, struct _7z_header_info *,\n\t\t int);\n```\n\n#### read_PackInfo() [lines 1650-1728]\n```c\n}\n\nstatic int\nread_PackInfo(struct archive_read *a, struct _7z_pack_info *pi)\n{\n\tconst unsigned char *p;\n\tunsigned i;\n\n\tmemset(pi, 0, sizeof(*pi));\n\n\t/*\n\t * Read PackPos.\n\t */\n\tif (parse_7zip_uint64(a, &(pi->pos)) < 0)\n\t\treturn (-1);\n\n\t/*\n\t * Read NumPackStreams.\n\t */\n\tif (parse_7zip_uint64(a, &(pi->numPackStreams)) < 0)\n\t\treturn (-1);\n\tif (pi->numPackStreams == 0)\n\t\treturn (-1);\n\tif (1000000 < pi->numPackStreams)\n\t\treturn (-1);\n\n\t/*\n\t * Read PackSizes[num]\n\t */\n\tif ((p = header_bytes(a, 1)) == NULL)\n\t\treturn (-1);\n\tif (*p == kEnd)\n\t\t/* PackSizes[num] are not present. */\n\t\treturn (0);\n\tif (*p != kSize)\n\t\treturn (-1);\n\tpi->sizes = calloc((size_t)pi->numPackStreams, sizeof(uint64_t));\n\tpi->positions = calloc((size_t)pi->numPackStreams, sizeof(uint64_t));\n\tif (pi->sizes == NULL || pi->positions == NULL)\n\t\treturn (-1);\n\n\tfor (i = 0; i < pi->numPackStreams; i++) {\n\t\tif (parse_7zip_uint64(a, &(pi->sizes[i])) < 0)\n\t\t\treturn (-1);\n\t}\n\n\t/*\n\t * Read PackStreamDigests[num]\n\t */\n\tif ((p = header_bytes(a, 1)) == NULL)\n\t\treturn (-1);\n\tif (*p == kEnd) {\n\t\t/* PackStreamDigests[num] are not present. */\n\t\tpi->digest.defineds =\n\t\t calloc((size_t)pi->numPackStreams, sizeof(*pi->digest.defineds));\n\t\tpi->digest.digests =\n\t\t calloc((size_t)pi->numPackStreams, sizeof(*pi->digest.digests));\n\t\tif (pi->digest.defineds == NULL || pi->digest.digests == NULL)\n\t\t\treturn (-1);\n\t\treturn (0);\n\t}\n\n\tif (*p != kSize)\n\t\treturn (-1);\n\n\tif (read_Digests(a, &(pi->digest), (size_t)pi->numPackStreams) < 0)\n\t\treturn (-1);\n\n\t/*\n\t * Must be marked by kEnd.\n\t */\n\tif ((p = header_bytes(a, 1)) == NULL)\n\t\treturn (-1);\n\tif (*p != kEnd)\n\t\treturn (-1);\n\treturn (0);\n}\n\nstatic void\n```\n\n#### read_Folder() [lines 1742-1887]\n```c\n}\n\nstatic int\nread_Folder(struct archive_read *a, struct _7z_folder *f)\n{\n\tstruct _7zip *zip = (struct _7zip *)a->format->data;\n\tconst unsigned char *p;\n\tuint64_t numInStreamsTotal = 0;\n\tuint64_t numOutStreamsTotal = 0;\n\tunsigned i;\n\n\tmemset(f, 0, sizeof(*f));\n\n\t/*\n\t * Read NumCoders.\n\t */\n\tif (parse_7zip_uint64(a, &(f->numCoders)) < 0)\n\t\treturn (-1);\n\tif (f->numCoders > 4)\n\t\t/* Too many coders. */\n\t\treturn (-1);\n\n\tf->coders = calloc((size_t)f->numCoders, sizeof(*f->coders));\n\tif (f->coders == NULL)\n\t\treturn (-1);\n\tfor (i = 0; i< f->numCoders; i++) {\n\t\tsize_t codec_size;\n\t\tint simple, attr;\n\n\t\tif ((p = header_bytes(a, 1)) == NULL)\n\t\t\treturn (-1);\n\t\t/*\n\t\t * 0:3 CodecIdSize\n\t\t * 4: 0 - IsSimple\n\t\t * 1 - Is not Simple\n\t\t * 5: 0 - No Attributes\n\t\t * 1 - There are Attributes;\n\t\t * 7: Must be zero.\n\t\t */\n\t\tcodec_size = *p & 0xf;\n/* ... 8 lines omitted ... */\n\t\tif ((p = header_bytes(a, codec_size)) == NULL)\n\t\t\treturn (-1);\n\n\t\tf->coders[i].codec = decode_codec_id(p, codec_size);\n\n\t\tif (simple) {\n\t\t\tf->coders[i].numInStreams = 1;\n\t\t\tf->coders[i].numOutStreams = 1;\n\t\t} else {\n\t\t\tif (parse_7zip_uint64(\n\t\t\t a, &(f->coders[i].numInStreams)) < 0)\n\t\t\t\treturn (-1);\n\t\t\tif (1000000 < f->coders[i].numInStreams)\n\t\t\t\treturn (-1);\n\t\t\tif (parse_7zip_uint64(\n\t\t\t a, &(f->coders[i].numOutStreams)) < 0)\n\t\t\t\treturn (-1);\n\t\t\tif (1000000 < f->coders[i].numOutStreams)\n\t\t\t\treturn (-1);\n\t\t}\n\n\t\tif (attr) {\n\t\t\tif (parse_7zip_uint64(\n\t\t\t a, &(f->coders[i].propertiesSize)) < 0)\n\t\t\t\treturn (-1);\n\t\t\tif ((p = header_bytes(\n\t\t\t a, (size_t)f->coders[i].propertiesSize)) == NULL)\n\t\t\t\treturn (-1);\n\t\t\tf->coders[i].properties =\n\t\t\t malloc((size_t)f->coders[i].propertiesSize);\n\t\t\tif (f->coders[i].properties == NULL)\n\t\t\t\treturn (-1);\n/* ... 46 lines omitted ... */\n\t\t\t\tbreak;\n\t\t}\n\t\tif (i == numInStreamsTotal)\n\t\t\treturn (-1);\n\t\tf->packedStreams[0] = i;\n\t} else {\n\t\tfor (i = 0; i < f->numPackedStreams; i++) {\n\t\t\tif (parse_7zip_uint64(a, &(f->packedStreams[i])) < 0)\n\t\t\t\treturn (-1);\n\t\t\tif (1000000 < f->packedStreams[i])\n\t\t\t\treturn (-1);\n\t\t}\n\t}\n\tf->numInStreams = numInStreamsTotal;\n\tf->numOutStreams = numOutStreamsTotal;\n\n\treturn (0);\n}\n\nstatic void\n```\n\n#### read_CodersInfo() [lines 1897-1995]\n```c\n}\n\nstatic int\nread_CodersInfo(struct archive_read *a, struct _7z_coders_info *ci)\n{\n\tconst unsigned char *p;\n\tstruct _7z_digests digest;\n\tunsigned i;\n\n\tmemset(ci, 0, sizeof(*ci));\n\tmemset(&digest, 0, sizeof(digest));\n\n\tif ((p = header_bytes(a, 1)) == NULL)\n\t\tgoto failed;\n\tif (*p != kFolder)\n\t\tgoto failed;\n\n\t/*\n\t * Read NumFolders.\n\t */\n\tif (parse_7zip_uint64(a, &(ci->numFolders)) < 0)\n\t\tgoto failed;\n\tif (1000000 < ci->numFolders)\n\t\t\treturn (-1);\n\n\t/*\n\t * Read External.\n\t */\n\tif ((p = header_bytes(a, 1)) == NULL)\n\t\tgoto failed;\n\tswitch (*p) {\n\tcase 0:\n\t\tci->folders =\n\t\t\tcalloc((size_t)ci->numFolders, sizeof(*ci->folders));\n\t\tif (ci->folders == NULL)\n\t\t\treturn (-1);\n\t\tfor (i = 0; i < ci->numFolders; i++) {\n\t\t\tif (read_Folder(a, &(ci->folders[i])) < 0)\n\t\t\t\tgoto failed;\n\t\t}\n\t\tbreak;\n\tcase 1:\n\t\tif (parse_7zip_uint64(a, &(ci->dataStreamIndex)) < 0)\n\t\t\treturn (-1);\n\t\tif (1000000 < ci->dataStreamIndex)\n\t\t\treturn (-1);\n\t\tbreak;\n\t}\n\n\tif ((p = header_bytes(a, 1)) == NULL)\n\t\tgoto failed;\n\tif (*p != kCodersUnPackSize)\n\t\tgoto failed;\n\n\tfor (i = 0; i < ci->numFolders; i++) {\n\t\tstruct _7z_folder *folder = &(ci->folders[i]);\n\t\tunsigned j;\n\n\t\tfolder->unPackSize =\n\t\t calloc((size_t)folder->numOutStreams, sizeof(*folder->unPackSize));\n\t\tif (folder->unPackSize == NULL)\n\t\t\tgoto failed;\n\t\tfor (j = 0; j < folder->numOutStreams; j++) {\n\t\t\tif (parse_7zip_uint64(a, &(folder->unPackSize[j])) < 0)\n\t\t\t\tgoto failed;\n\t\t}\n\t}\n\n\t/*\n\t * Read CRCs.\n\t */\n\tif ((p = header_bytes(a, 1)) == NULL)\n\t\tgoto failed;\n\tif (*p == kEnd)\n\t\treturn (0);\n\tif (*p != kCRC)\n\t\tgoto failed;\n\tif (read_Digests(a, &digest, (size_t)ci->numFolders) < 0)\n\t\tgoto failed;\n\tfor (i = 0; i < ci->numFolders; i++) {\n\t\tci->folders[i].digest_defined = digest.defineds[i];\n\t\tci->folders[i].digest = digest.digests[i];\n\t}\n\n\t/*\n\t * Must be kEnd.\n\t */\n\tif ((p = header_bytes(a, 1)) == NULL)\n\t\tgoto failed;\n\tif (*p != kEnd)\n\t\tgoto failed;\n\tfree_Digest(&digest);\n\treturn (0);\nfailed:\n\tfree_Digest(&digest);\n\treturn (-1);\n}\n\nstatic uint64_t\n```\n\n#### read_SubStreamsInfo() [lines 2019-2146]\n```c\n}\n\nstatic int\nread_SubStreamsInfo(struct archive_read *a, struct _7z_substream_info *ss,\n struct _7z_folder *f, size_t numFolders)\n{\n\tconst unsigned char *p;\n\tuint64_t *usizes;\n\tsize_t unpack_streams;\n\tint type;\n\tunsigned i;\n\tuint32_t numDigests;\n\n\tmemset(ss, 0, sizeof(*ss));\n\n\tfor (i = 0; i < numFolders; i++)\n\t\tf[i].numUnpackStreams = 1;\n\n\tif ((p = header_bytes(a, 1)) == NULL)\n\t\treturn (-1);\n\ttype = *p;\n\n\tif (type == kNumUnPackStream) {\n\t\tunpack_streams = 0;\n\t\tfor (i = 0; i < numFolders; i++) {\n\t\t\tif (parse_7zip_uint64(a, &(f[i].numUnpackStreams)) < 0)\n\t\t\t\treturn (-1);\n\t\t\tif (1000000 < f[i].numUnpackStreams)\n\t\t\t\treturn (-1);\n\t\t\tunpack_streams += (size_t)f[i].numUnpackStreams;\n\t\t}\n\t\tif ((p = header_bytes(a, 1)) == NULL)\n\t\t\treturn (-1);\n\t\ttype = *p;\n\t} else\n\t\tunpack_streams = numFolders;\n\n\tss->unpack_streams = unpack_streams;\n\tif (unpack_streams) {\n\t\tss->unpackSizes = calloc(unpack_streams,\n\t\t sizeof(*ss->unpackSizes));\n\t\tss->digestsDefined = calloc(unpack_streams,\n\t\t sizeof(*ss->digestsDefined));\n\t\tss->digests = calloc(unpack_streams,\n\t\t sizeof(*ss->digests));\n\t\tif (ss->unpackSizes == NULL || ss->digestsDefined == NULL ||\n\t\t ss->digests == NULL)\n\t\t\treturn (-1);\n\t}\n\n\tusizes = ss->unpackSizes;\n\tfor (i = 0; i < numFolders; i++) {\n/* ... 56 lines omitted ... */\n\t\t\t\t\t*digests++ =\n\t\t\t\t\t tmpDigests.digests[di];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfree_Digest(&tmpDigests);\n\t\tif ((p = header_bytes(a, 1)) == NULL)\n\t\t\treturn (-1);\n\t\ttype = *p;\n\t}\n\n\t/*\n\t * Must be kEnd.\n\t */\n\tif (type != kEnd)\n\t\treturn (-1);\n\treturn (0);\n}\n\nstatic void\n```\n\n#### read_Header() [lines 2231-2546]\n```c\n}\n\nstatic int\nread_Header(struct archive_read *a, struct _7z_header_info *h,\n int check_header_id)\n{\n\tstruct _7zip *zip = (struct _7zip *)a->format->data;\n\tconst unsigned char *p;\n\tstruct _7z_folder *folders;\n\tstruct _7z_stream_info *si = &(zip->si);\n\tstruct _7zip_entry *entries;\n\tuint32_t folderIndex, indexInFolder;\n\tunsigned i;\n\tint eindex, empty_streams, sindex;\n\n\tif (check_header_id) {\n\t\t/*\n\t\t * Read Header.\n\t\t */\n\t\tif ((p = header_bytes(a, 1)) == NULL)\n\t\t\treturn (-1);\n\t\tif (*p != kHeader)\n\t\t\treturn (-1);\n\t}\n\n\t/*\n\t * Read ArchiveProperties.\n\t */\n\tif ((p = header_bytes(a, 1)) == NULL)\n\t\treturn (-1);\n\tif (*p == kArchiveProperties) {\n\t\tfor (;;) {\n\t\t\tuint64_t size;\n\t\t\tif ((p = header_bytes(a, 1)) == NULL)\n\t\t\t\treturn (-1);\n\t\t\tif (*p == 0)\n\t\t\t\tbreak;\n\t\t\tif (parse_7zip_uint64(a, &size) < 0)\n\t\t\t\treturn (-1);\n\t\t}\n/* ... 21 lines omitted ... */\n\n\tif (parse_7zip_uint64(a, &(zip->numFiles)) < 0)\n\t\treturn (-1);\n\tif (1000000 < zip->numFiles)\n\t\t\treturn (-1);\n\n\tzip->entries = calloc((size_t)zip->numFiles, sizeof(*zip->entries));\n\tif (zip->entries == NULL)\n\t\treturn (-1);\n\tentries = zip->entries;\n\n\tempty_streams = 0;\n\tfor (;;) {\n\t\tint type;\n\t\tuint64_t size;\n\t\tsize_t ll;\n\n\t\tif ((p = header_bytes(a, 1)) == NULL)\n\t\t\treturn (-1);\n\t\ttype = *p;\n\t\tif (type == kEnd)\n\t\t\tbreak;\n\n\t\tif (parse_7zip_uint64(a, &size) < 0)\n\t\t\treturn (-1);\n\t\tif (zip->header_bytes_remaining < size)\n\t\t\treturn (-1);\n\t\tll = (size_t)size;\n/* ... 207 lines omitted ... */\n\t\t\t\t\treturn (-1);\n\t\t\t\tif (folders[folderIndex].numUnpackStreams)\n\t\t\t\t\tbreak;\n\t\t\t\tfolderIndex++;\n\t\t\t}\n\t\t}\n\t\tentries[i].folderIndex = folderIndex;\n\t\tif ((entries[i].flg & HAS_STREAM) == 0)\n\t\t\tcontinue;\n\t\tindexInFolder++;\n\t\tif (inde\n/* ... truncated ... */\n```\n\n\n## Upstream Fix\n```diff\ncommit e79ef306afe332faf22e9b442a2c6b59cb175573\nAuthor: Tim Kientzle \nDate: Sun Jun 19 14:14:09 2016 -0700\n\n Issue #718: Fix TALOS-CAN-152\n \n If a 7-Zip archive declares a rediculously large number of substreams,\n it can overflow an internal counter, leading a subsequent memory\n allocation to be too small for the substream data.\n \n Thanks to the Open Source and Threat Intelligence project at Cisco\n for reporting this issue.\n\nIndex: libarchive-3.1.2/libarchive/archive_read_support_format_7zip.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_read_support_format_7zip.c\n+++ libarchive-3.1.2/libarchive/archive_read_support_format_7zip.c\n@@ -324,6 +324,11 @@ struct _7zip {\n \tchar\t\t\t format_name[64];\n };\n \n+/* Maximum entry size. This limitation prevents reading intentional\n+ * corrupted 7-zip files on assuming there are not so many entries in\n+ * the files. */\n+#define UMAX_ENTRY ARCHIVE_LITERAL_ULL(100000000)\n+\n static int\tarchive_read_format_7zip_bid(struct archive_read *, int);\n static int\tarchive_read_format_7zip_cleanup(struct archive_read *);\n static int\tarchive_read_format_7zip_read_data(struct archive_read *,\n@@ -1670,7 +1675,7 @@ read_PackInfo(struct archive_read *a, st\n \t\treturn (-1);\n \tif (pi->numPackStreams == 0)\n \t\treturn (-1);\n-\tif (1000000 < pi->numPackStreams)\n+\tif (UMAX_ENTRY < pi->numPackStreams)\n \t\treturn (-1);\n \n \t/*\n@@ -1799,12 +1804,12 @@ read_Folder(struct archive_read *a, stru\n \t\t\tif (parse_7zip_uint64(\n \t\t\t a, &(f->coders[i].numInStreams)) < 0)\n \t\t\t\treturn (-1);\n-\t\t\tif (1000000 < f->coders[i].numInStreams)\n+\t\t\tif (UMAX_ENTRY < f->coders[i].numInStreams)\n \t\t\t\treturn (-1);\n \t\t\tif (parse_7zip_uint64(\n \t\t\t a, &(f->coders[i].numOutStreams)) < 0)\n \t\t\t\treturn (-1);\n-\t\t\tif (1000000 < f->coders[i].numOutStreams)\n+\t\t\tif (UMAX_ENTRY < f->coders[i].numOutStreams)\n \t\t\t\treturn (-1);\n \t\t}\n \n@@ -1844,11 +1849,11 @@ read_Folder(struct archive_read *a, stru\n \tfor (i = 0; i < f->numBindPairs; i++) {\n \t\tif (parse_7zip_uint64(a, &(f->bindPairs[i].inIndex)) < 0)\n \t\t\treturn (-1);\n-\t\tif (1000000 < f->bindPairs[i].inIndex)\n+\t\tif (UMAX_ENTRY < f->bindPairs[i].inIndex)\n \t\t\treturn (-1);\n \t\tif (parse_7zip_uint64(a, &(f->bindPairs[i].outIndex)) < 0)\n \t\t\treturn (-1);\n-\t\tif (1000000 < f->bindPairs[i].outIndex)\n+\t\tif (UMAX_ENTRY < f->bindPairs[i].outIndex)\n \t\t\treturn (-1);\n \t}\n \n@@ -1874,7 +1879,7 @@ read_Folder(struct archive_read *a, stru\n \t\tfor (i = 0; i < f->numPackedStreams; i++) {\n \t\t\tif (parse_7zip_uint64(a, &(f->packedStreams[i])) < 0)\n \t\t\t\treturn (-1);\n-\t\t\tif (1000000 < f->packedStreams[i])\n+\t\t\tif (UMAX_ENTRY < f->packedStreams[i])\n \t\t\t\treturn (-1);\n \t\t}\n \t}\n@@ -1916,8 +1921,8 @@ read_CodersInfo(struct archive_read *a,\n \t */\n \tif (parse_7zip_uint64(a, &(ci->numFolders)) < 0)\n \t\tgoto failed;\n-\tif (1000000 < ci->numFolders)\n-\t\t\treturn (-1);\n+\tif (UMAX_ENTRY < ci->numFolders)\n+\t\treturn (-1);\n \n \t/*\n \t * Read External.\n@@ -1938,7 +1943,7 @@ read_CodersInfo(struct archive_read *a,\n \tcase 1:\n \t\tif (parse_7zip_uint64(a, &(ci->dataStreamIndex)) < 0)\n \t\t\treturn (-1);\n-\t\tif (1000000 < ci->dataStreamIndex)\n+\t\tif (UMAX_ENTRY < ci->dataStreamIndex)\n \t\t\treturn (-1);\n \t\tif (ci->numFolders > 0) {\n \t\t\tarchive_set_error(&a->archive, -1,\n@@ -2052,8 +2057,11 @@ read_SubStreamsInfo(struct archive_read\n \t\tfor (i = 0; i < numFolders; i++) {\n \t\t\tif (parse_7zip_uint64(a, &(f[i].numUnpackStreams)) < 0)\n \t\t\t\treturn (-1);\n-\t\t\tif (1000000 < f[i].numUnpackStreams)\n+\t\t\tif (UMAX_ENTRY < f[i].numUnpackStreams)\n \t\t\t\treturn (-1);\n+\t\t\tif (unpack_streams > SIZE_MAX - UMAX_ENTRY) {\n+\t\t\t return (-1);\n+\t\t\t}\n \t\t\tunpack_streams += (size_t)f[i].numUnpackStreams;\n \t\t}\n \t\tif ((p = header_bytes(a, 1)) == NULL)\n@@ -2301,8 +2309,8 @@ read_Header(struct archive_read *a, stru\n \n \tif (parse_7zip_uint64(a, &(zip->numFiles)) < 0)\n \t\treturn (-1);\n-\tif (1000000 < zip->numFiles)\n-\t\t\treturn (-1);\n+\tif (UMAX_ENTRY < zip->numFiles)\n+\t\treturn (-1);\n \n \tzip->entries = calloc((size_t)zip->numFiles, sizeof(*zip->entries));\n \tif (zip->entries == NULL)\n@@ -2600,7 +2608,7 @@ read_Times(struct archive_read *a, struc\n \tif (*p) {\n \t\tif (parse_7zip_uint64(a, &(h->dataIndex)) < 0)\n \t\t\tgoto failed;\n-\t\tif (1000000 < h->dataIndex)\n+\t\tif (UMAX_ENTRY < h->dataIndex)\n \t\t\tgoto failed;\n \t}\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "commit e79ef306afe332faf22e9b442a2c6b59cb175573\nAuthor: Tim Kientzle \nDate: Sun Jun 19 14:14:09 2016 -0700\n\n Issue #718: Fix TALOS-CAN-152\n \n If a 7-Zip archive declares a rediculously large number of substreams,\n it can overflow an internal counter, leading a subsequent memory\n allocation to be too small for the substream data.\n \n Thanks to the Open Source and Threat Intelligence project at Cisco\n for reporting this issue.\n\nIndex: libarchive-3.1.2/libarchive/archive_read_support_format_7zip.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_read_support_format_7zip.c\n+++ libarchive-3.1.2/libarchive/archive_read_support_format_7zip.c\n@@ -324,6 +324,11 @@ struct _7zip {\n \tchar\t\t\t format_name[64];\n };\n \n+/* Maximum entry size. This limitation prevents reading intentional\n+ * corrupted 7-zip files on assuming there are not so many entries in\n+ * the files. */\n+#define UMAX_ENTRY ARCHIVE_LITERAL_ULL(100000000)\n+\n static int\tarchive_read_format_7zip_bid(struct archive_read *, int);\n static int\tarchive_read_format_7zip_cleanup(struct archive_read *);\n static int\tarchive_read_format_7zip_read_data(struct archive_read *,\n@@ -1670,7 +1675,7 @@ read_PackInfo(struct archive_read *a, st\n \t\treturn (-1);\n \tif (pi->numPackStreams == 0)\n \t\treturn (-1);\n-\tif (1000000 < pi->numPackStreams)\n+\tif (UMAX_ENTRY < pi->numPackStreams)\n \t\treturn (-1);\n \n \t/*\n@@ -1799,12 +1804,12 @@ read_Folder(struct archive_read *a, stru\n \t\t\tif (parse_7zip_uint64(\n \t\t\t a, &(f->coders[i].numInStreams)) < 0)\n \t\t\t\treturn (-1);\n-\t\t\tif (1000000 < f->coders[i].numInStreams)\n+\t\t\tif (UMAX_ENTRY < f->coders[i].numInStreams)\n \t\t\t\treturn (-1);\n \t\t\tif (parse_7zip_uint64(\n \t\t\t a, &(f->coders[i].numOutStreams)) < 0)\n \t\t\t\treturn (-1);\n-\t\t\tif (1000000 < f->coders[i].numOutStreams)\n+\t\t\tif (UMAX_ENTRY < f->coders[i].numOutStreams)\n \t\t\t\treturn (-1);\n \t\t}\n \n@@ -1844,11 +1849,11 @@ read_Folder(struct archive_read *a, stru\n \tfor (i = 0; i < f->numBindPairs; i++) {\n \t\tif (parse_7zip_uint64(a, &(f->bindPairs[i].inIndex)) < 0)\n \t\t\treturn (-1);\n-\t\tif (1000000 < f->bindPairs[i].inIndex)\n+\t\tif (UMAX_ENTRY < f->bindPairs[i].inIndex)\n \t\t\treturn (-1);\n \t\tif (parse_7zip_uint64(a, &(f->bindPairs[i].outIndex)) < 0)\n \t\t\treturn (-1);\n-\t\tif (1000000 < f->bindPairs[i].outIndex)\n+\t\tif (UMAX_ENTRY < f->bindPairs[i].outIndex)\n \t\t\treturn (-1);\n \t}\n \n@@ -1874,7 +1879,7 @@ read_Folder(struct archive_read *a, stru\n \t\tfor (i = 0; i < f->numPackedStreams; i++) {\n \t\t\tif (parse_7zip_uint64(a, &(f->packedStreams[i])) < 0)\n \t\t\t\treturn (-1);\n-\t\t\tif (1000000 < f->packedStreams[i])\n+\t\t\tif (UMAX_ENTRY < f->packedStreams[i])\n \t\t\t\treturn (-1);\n \t\t}\n \t}\n@@ -1916,8 +1921,8 @@ read_CodersInfo(struct archive_read *a,\n \t */\n \tif (parse_7zip_uint64(a, &(ci->numFolders)) < 0)\n \t\tgoto failed;\n-\tif (1000000 < ci->numFolders)\n-\t\t\treturn (-1);\n+\tif (UMAX_ENTRY < ci->numFolders)\n+\t\treturn (-1);\n \n \t/*\n \t * Read External.\n@@ -1938,7 +1943,7 @@ read_CodersInfo(struct archive_read *a,\n \tcase 1:\n \t\tif (parse_7zip_uint64(a, &(ci->dataStreamIndex)) < 0)\n \t\t\treturn (-1);\n-\t\tif (1000000 < ci->dataStreamIndex)\n+\t\tif (UMAX_ENTRY < ci->dataStreamIndex)\n \t\t\treturn (-1);\n \t\tif (ci->numFolders > 0) {\n \t\t\tarchive_set_error(&a->archive, -1,\n@@ -2052,8 +2057,11 @@ read_SubStreamsInfo(struct archive_read\n \t\tfor (i = 0; i < numFolders; i++) {\n \t\t\tif (parse_7zip_uint64(a, &(f[i].numUnpackStreams)) < 0)\n \t\t\t\treturn (-1);\n-\t\t\tif (1000000 < f[i].numUnpackStreams)\n+\t\t\tif (UMAX_ENTRY < f[i].numUnpackStreams)\n \t\t\t\treturn (-1);\n+\t\t\tif (unpack_streams > SIZE_MAX - UMAX_ENTRY) {\n+\t\t\t return (-1);\n+\t\t\t}\n \t\t\tunpack_streams += (size_t)f[i].numUnpackStreams;\n \t\t}\n \t\tif ((p = header_bytes(a, 1)) == NULL)\n@@ -2301,8 +2309,8 @@ read_Header(struct archive_read *a, stru\n \n \tif (parse_7zip_uint64(a, &(zip->numFiles)) < 0)\n \t\treturn (-1);\n-\tif (1000000 < zip->numFiles)\n-\t\t\treturn (-1);\n+\tif (UMAX_ENTRY < zip->numFiles)\n+\t\treturn (-1);\n \n \tzip->entries = calloc((size_t)zip->numFiles, sizeof(*zip->entries));\n \tif (zip->entries == NULL)\n@@ -2600,7 +2608,7 @@ read_Times(struct archive_read *a, struc\n \tif (*p) {\n \t\tif (parse_7zip_uint64(a, &(h->dataIndex)) < 0)\n \t\t\tgoto failed;\n-\t\tif (1000000 < h->dataIndex)\n+\t\tif (UMAX_ENTRY < h->dataIndex)\n \t\t\tgoto failed;\n \t}"}], "metadata": {"id": "libarchive-5940-CVE-2016-4300.patch", "cve_id": "CVE-2016-6250", "package": "libarchive", "tier": "identical", "has_source_context": true, "context_tokens_est": 3217, "context_files": 1, "license": "BSD-2-Clause"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-6250\n\nInteger overflow in the ISO9660 writer in libarchive before 3.2.1 allows remote attackers to cause a denial of service (application crash) or execute arbitrary code via vectors related to verifying filename lengths when writing an ISO9660 archive, which trigger a buffer overflow.\n\n## Package\nlibarchive\n\n## Files to modify\n- libarchive-3.1.2.orig/libarchive/archive_string.c\n- libarchive/archive_string.c\n\n## Target Source Code\n\n### CMakeLists.txt\n\n#### CHECK_FUNCTION_EXISTS() [lines 1087-194]\n```c\n\n```\n\n### configure.ac\n\n#### AC_CHECK_FUNCS() [lines 290-334]\n```c\n AC_CHECK_HEADERS([localcharset.h])\n am_save_LIBS=\"$LIBS\"\n LIBS=\"${LIBS} ${LIBICONV}\"\n AC_CHECK_FUNCS([locale_charset])\n LIBS=\"${am_save_LIBS}\"\n if test \"x$ac_cv_func_locale_charset\" != \"xyes\"; then\n # If locale_charset() is not in libiconv, we have to find libcharset. \n AC_CHECK_LIB(charset,locale_charset)\n fi\n fi\nfi\n\nAC_ARG_WITH([lzma],\n AS_HELP_STRING([--without-lzma], [Don't build support for xz through lzma]))\n\nif test \"x$with_lzma\" != \"xno\"; then\n AC_CHECK_HEADERS([lzma.h])\n AC_CHECK_LIB(lzma,lzma_stream_decoder)\nfi\n\nAC_ARG_WITH([lzo2],\n AS_HELP_STRING([--without-lzo2], [Don't build support for lzop through liblzo2]))\n\nif test \"x$with_lzo2\" != \"xno\"; then\n AC_CHECK_HEADERS([lzo/lzoconf.h lzo/lzo1x.h])\n AC_CHECK_LIB(lzo2,lzo1x_decompress_safe)\nfi\n\nAC_ARG_WITH([nettle],\n AS_HELP_STRING([--without-nettle], [Don't build with crypto support from Nettle]))\nAC_ARG_WITH([openssl],\n AS_HELP_STRING([--without-openssl], [Don't build support for mtree and xar hashes through openssl]))\ncase \"$host_os\" in\n *darwin* ) with_openssl=no ;;\nesac\n\nAC_ARG_WITH([xml2],\n AS_HELP_STRING([--without-xml2], [Don't build support for xar through libxml2]))\nAC_ARG_WITH([expat],\n AS_HELP_STRING([--without-expat], [Don't build support for xar through expat]))\n\nif test \"x$with_xml2\" != \"xno\"; then\n AC_PATH_PROG([XML2_CONFIG], [xml2-config],, [${PATH}])\n if test \"x$XML2_CONFIG\" != \"x\"; then\n CPPFLAGS=\"${CPPFLAGS} `${XML2_CONFIG} --cflags`\"\n```\n\n### libarchive/archive_string.c\n\n#### __FBSDID() [lines 32-118]\n```c\n * strings while minimizing heap activity.\n *\n * In particular, the buffer used by a string object is only grown, it\n * never shrinks, so you can clear and reuse the same string object\n * without incurring additional memory allocations.\n */\n\n#ifdef HAVE_ERRNO_H\n#include \n#endif\n#ifdef HAVE_ICONV_H\n#include \n#endif\n#ifdef HAVE_LANGINFO_H\n#include \n#endif\n#ifdef HAVE_LOCALCHARSET_H\n#include \n#endif\n#ifdef HAVE_STDLIB_H\n#include \n#endif\n#ifdef HAVE_STRING_H\n#include \n#endif\n#ifdef HAVE_WCHAR_H\n#include \n#endif\n#if defined(_WIN32) && !defined(__CYGWIN__)\n#include \n#include \n#endif\n\n#include \"archive_endian.h\"\n#include \"archive_private.h\"\n#include \"archive_string.h\"\n#include \"archive_string_composition.h\"\n\n#if !defined(HAVE_WMEMCPY) && !defined(wmemcpy)\n#define wmemcpy(a,b,i) (wchar_t *)memcpy((a), (b), (i) * sizeof(wchar_t))\n#endif\n\nstruct archive_string_conv {\n\tstruct archive_string_conv\t*next;\n\tchar\t\t\t\t*from_charset;\n\tchar\t\t\t\t*to_charset;\n\tunsigned\t\t\t from_cp;\n\tunsigned\t\t\t to_cp;\n\t/* Set 1 if from_charset and to_charset are the same. */\n\tint\t\t\t\t same;\n\tint\t\t\t\t flag;\n#define SCONV_TO_CHARSET\t1\t/* MBS is being converted to specified\n\t\t\t\t\t * charset. */\n#define SCONV_FROM_CHARSET\t(1<<1)\t/* MBS is being converted from\n\t\t\t\t\t * specified charset. */\n#define SCONV_BEST_EFFORT \t(1<<2)\t/* Copy at least ASCII code. */\n#define SCONV_WIN_CP\t \t(1<<3)\t/* Use Windows API for converting\n\t\t\t\t\t * MBS. */\n#define SCONV_UTF8_LIBARCHIVE_2 (1<<4)\t/* Incorrect UTF-8 made by libarchive\n\t\t\t\t\t * 2.x in the wrong assumption. */\n#define SCONV_NORMALIZATION_C\t(1<<6)\t/* Need normalization to be Form C.\n\t\t\t\t\t * Before UTF-8 characters are actually\n\t\t\t\t\t * processed. */\n#define SCONV_NORMALIZATION_D\t(1<<7)\t/* Need normalization to be Form D.\n\t\t\t\t\t * Before UTF-8 characters are actually\n\t\t\t\t\t * processed.\n\t\t\t\t\t * Currently this only for MAC OS X. */\n#define SCONV_TO_UTF8\t\t(1<<8)\t/* \"to charset\" side is UTF-8. */\n#define SCONV_FROM_UTF8\t\t(1<<9)\t/* \"from charset\" side is UTF-8. */\n#define SCONV_TO_UTF16BE \t(1<<10)\t/* \"to charset\" side is UTF-16BE. */\n#define SCONV_FROM_UTF16BE \t(1<<11)\t/* \"from charset\" side is UTF-16BE. */\n#define SCONV_TO_UTF16LE \t(1<<12)\t/* \"to charset\" side is UTF-16LE. */\n#define SCONV_FROM_UTF16LE \t(1<<13)\t/* \"from charset\" side is UTF-16LE. */\n#define SCONV_TO_UTF16\t\t(SCONV_TO_UTF16BE | SCONV_TO_UTF16LE)\n#define SCONV_FROM_UTF16\t(SCONV_FROM_UTF16BE | SCONV_FROM_UTF16LE)\n\n#if HAVE_ICONV\n\ticonv_t\t\t\t\t cd;\n\ticonv_t\t\t\t\t cd_w;/* Use at archive_mstring on\n\t\t\t\t \t * Windows. */\n#endif\n\t/* A temporary buffer for normalization. */\n\tstruct archive_string\t\t utftmp;\n\tint (*converter[2])(struct archive_string *, const void *, size_t,\n\t struct archive_string_conv *);\n\tint\t\t\t\t nconverter;\n};\n```\n\n#### archive_string_append() [lines 199-212]\n```c\n const void *, size_t, struct archive_string_conv *);\n\nstatic struct archive_string *\narchive_string_append(struct archive_string *as, const char *p, size_t s)\n{\n\tif (archive_string_ensure(as, as->length + s + 1) == NULL)\n\t\treturn (NULL);\n\tmemcpy(as->s + as->length, p, s);\n\tas->length += s;\n\tas->s[as->length] = 0;\n\treturn (as);\n}\n\nstatic struct archive_wstring *\n```\n\n#### archive_wstring_append() [lines 210-223]\n```c\n}\n\nstatic struct archive_wstring *\narchive_wstring_append(struct archive_wstring *as, const wchar_t *p, size_t s)\n{\n\tif (archive_wstring_ensure(as, as->length + s + 1) == NULL)\n\t\treturn (NULL);\n\twmemcpy(as->s + as->length, p, s);\n\tas->length += s;\n\tas->s[as->length] = 0;\n\treturn (as);\n}\n\nvoid\n```\n\n\n## Upstream Fix\n```diff\ncommit b6ba56037f0da44efebfa271cc4b1a736a74c62f\nAuthor: Tim Kientzle \nDate: Fri Feb 6 23:00:30 2015 -0800\n\n Issue 398: Overlapping memcpy\n \n Some of the pathname edits parse a part of the pathname\n in the entry, then try to set the pathname from that part.\n This leads the text routines to memcpy() from within the\n string buffer.\n \n Avoid this by simply using memmove() for low-level string append\n operations.\n\nIndex: libarchive-3.1.2/CMakeLists.txt\n===================================================================\n--- libarchive-3.1.2.orig/CMakeLists.txt\n+++ libarchive-3.1.2/CMakeLists.txt\n@@ -1126,6 +1126,7 @@ CHECK_FUNCTION_EXISTS(strftime HAVE_STRF\n CHECK_FUNCTION_EXISTS(vprintf HAVE_VPRINTF)\n CHECK_FUNCTION_EXISTS(wmemcmp HAVE_WMEMCMP)\n CHECK_FUNCTION_EXISTS(wmemcpy HAVE_WMEMCPY)\n+CHECK_FUNCTION_EXISTS(wmemmove HAVE_WMEMMOVE)\n \n CMAKE_POP_CHECK_STATE()\t# Restore the state of the variables\n \nIndex: libarchive-3.1.2/configure.ac\n===================================================================\n--- libarchive-3.1.2.orig/configure.ac\n+++ libarchive-3.1.2/configure.ac\n@@ -525,7 +525,7 @@ AC_CHECK_FUNCS([nl_langinfo openat pipe\n AC_CHECK_FUNCS([select setenv setlocale sigaction statfs statvfs])\n AC_CHECK_FUNCS([strchr strdup strerror strncpy_s strrchr symlink timegm])\n AC_CHECK_FUNCS([tzset unsetenv utime utimensat utimes vfork])\n-AC_CHECK_FUNCS([wcrtomb wcscmp wcscpy wcslen wctomb wmemcmp wmemcpy])\n+AC_CHECK_FUNCS([wcrtomb wcscmp wcscpy wcslen wctomb wmemcmp wmemcpy wmemmove])\n AC_CHECK_FUNCS([_ctime64_s _fseeki64])\n AC_CHECK_FUNCS([_get_timezone _localtime64_s _mkgmtime64])\n # detects cygwin-1.7, as opposed to older versions\nIndex: libarchive-3.1.2/libarchive/archive_string.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_string.c\n+++ libarchive-3.1.2/libarchive/archive_string.c\n@@ -71,6 +71,10 @@ __FBSDID(\"$FreeBSD: head/lib/libarchive/\n #define wmemcpy(a,b,i) (wchar_t *)memcpy((a), (b), (i) * sizeof(wchar_t))\n #endif\n \n+#if !defined(HAVE_WMEMMOVE) && !defined(wmemmove)\n+#define wmemmove(a,b,i) (wchar_t *)memmove((a), (b), (i) * sizeof(wchar_t))\n+#endif\n+\n struct archive_string_conv {\n \tstruct archive_string_conv\t*next;\n \tchar\t\t\t\t*from_charset;\n@@ -203,7 +207,7 @@ archive_string_append(struct archive_str\n {\n \tif (archive_string_ensure(as, as->length + s + 1) == NULL)\n \t\treturn (NULL);\n-\tmemcpy(as->s + as->length, p, s);\n+\tmemmove(as->s + as->length, p, s);\n \tas->length += s;\n \tas->s[as->length] = 0;\n \treturn (as);\n@@ -214,7 +218,7 @@ archive_wstring_append(struct archive_ws\n {\n \tif (archive_wstring_ensure(as, as->length + s + 1) == NULL)\n \t\treturn (NULL);\n-\twmemcpy(as->s + as->length, p, s);\n+\twmemmove(as->s + as->length, p, s);\n \tas->length += s;\n \tas->s[as->length] = 0;\n \treturn (as);\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "commit b6ba56037f0da44efebfa271cc4b1a736a74c62f\nAuthor: Tim Kientzle \nDate: Fri Feb 6 23:00:30 2015 -0800\n\n Issue 398: Overlapping memcpy\n \n Some of the pathname edits parse a part of the pathname\n in the entry, then try to set the pathname from that part.\n This leads the text routines to memcpy() from within the\n string buffer.\n \n Avoid this by simply using memmove() for low-level string append\n operations.\n\nIndex: libarchive-3.1.2/CMakeLists.txt\n===================================================================\n--- libarchive-3.1.2.orig/CMakeLists.txt\n+++ libarchive-3.1.2/CMakeLists.txt\n@@ -1126,6 +1126,7 @@ CHECK_FUNCTION_EXISTS(strftime HAVE_STRF\n CHECK_FUNCTION_EXISTS(vprintf HAVE_VPRINTF)\n CHECK_FUNCTION_EXISTS(wmemcmp HAVE_WMEMCMP)\n CHECK_FUNCTION_EXISTS(wmemcpy HAVE_WMEMCPY)\n+CHECK_FUNCTION_EXISTS(wmemmove HAVE_WMEMMOVE)\n \n CMAKE_POP_CHECK_STATE()\t# Restore the state of the variables\n \nIndex: libarchive-3.1.2/configure.ac\n===================================================================\n--- libarchive-3.1.2.orig/configure.ac\n+++ libarchive-3.1.2/configure.ac\n@@ -525,7 +525,7 @@ AC_CHECK_FUNCS([nl_langinfo openat pipe\n AC_CHECK_FUNCS([select setenv setlocale sigaction statfs statvfs])\n AC_CHECK_FUNCS([strchr strdup strerror strncpy_s strrchr symlink timegm])\n AC_CHECK_FUNCS([tzset unsetenv utime utimensat utimes vfork])\n-AC_CHECK_FUNCS([wcrtomb wcscmp wcscpy wcslen wctomb wmemcmp wmemcpy])\n+AC_CHECK_FUNCS([wcrtomb wcscmp wcscpy wcslen wctomb wmemcmp wmemcpy wmemmove])\n AC_CHECK_FUNCS([_ctime64_s _fseeki64])\n AC_CHECK_FUNCS([_get_timezone _localtime64_s _mkgmtime64])\n # detects cygwin-1.7, as opposed to older versions\nIndex: libarchive-3.1.2/libarchive/archive_string.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_string.c\n+++ libarchive-3.1.2/libarchive/archive_string.c\n@@ -71,6 +71,10 @@ __FBSDID(\"$FreeBSD: head/lib/libarchive/\n #define wmemcpy(a,b,i) (wchar_t *)memcpy((a), (b), (i) * sizeof(wchar_t))\n #endif\n \n+#if !defined(HAVE_WMEMMOVE) && !defined(wmemmove)\n+#define wmemmove(a,b,i) (wchar_t *)memmove((a), (b), (i) * sizeof(wchar_t))\n+#endif\n+\n struct archive_string_conv {\n \tstruct archive_string_conv\t*next;\n \tchar\t\t\t\t*from_charset;\n@@ -203,7 +207,7 @@ archive_string_append(struct archive_str\n {\n \tif (archive_string_ensure(as, as->length + s + 1) == NULL)\n \t\treturn (NULL);\n-\tmemcpy(as->s + as->length, p, s);\n+\tmemmove(as->s + as->length, p, s);\n \tas->length += s;\n \tas->s[as->length] = 0;\n \treturn (as);\n@@ -214,7 +218,7 @@ archive_wstring_append(struct archive_ws\n {\n \tif (archive_wstring_ensure(as, as->length + s + 1) == NULL)\n \t\treturn (NULL);\n-\twmemcpy(as->s + as->length, p, s);\n+\twmemmove(as->s + as->length, p, s);\n \tas->length += s;\n \tas->s[as->length] = 0;\n \treturn (as);"}], "metadata": {"id": "libarchive-5940-CVE-2015-8918.patch", "cve_id": "CVE-2016-6250", "package": "libarchive", "tier": "identical", "has_source_context": true, "context_tokens_est": 1322, "context_files": 3, "license": "BSD-2-Clause"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-6250\n\nInteger overflow in the ISO9660 writer in libarchive before 3.2.1 allows remote attackers to cause a denial of service (application crash) or execute arbitrary code via vectors related to verifying filename lengths when writing an ISO9660 archive, which trigger a buffer overflow.\n\n## Package\nlibarchive\n\n## Files to modify\n- libarchive-3.1.2.orig/libarchive/archive_read.c\n- libarchive/archive_read.c\n- libarchive/test/test_read_too_many_filters.c\n\n## Target Source Code\n\n### Makefile.am\n\n#### region() [lines 400-486]\n```c\n\tlibarchive/test/test_read_format_iso_xorriso.c\t\t\\\n\tlibarchive/test/test_read_format_isojoliet_bz2.c\t\\\n\tlibarchive/test/test_read_format_isojoliet_long.c\t\\\n\tlibarchive/test/test_read_format_isojoliet_rr.c\t\t\\\n\tlibarchive/test/test_read_format_isojoliet_versioned.c\t\\\n\tlibarchive/test/test_read_format_isorr_bz2.c\t\t\\\n\tlibarchive/test/test_read_format_isorr_ce.c\t\t\\\n\tlibarchive/test/test_read_format_isorr_new_bz2.c\t\\\n\tlibarchive/test/test_read_format_isorr_rr_moved.c\t\\\n\tlibarchive/test/test_read_format_isozisofs_bz2.c\t\\\n\tlibarchive/test/test_read_format_lha.c\t\t\t\\\n\tlibarchive/test/test_read_format_lha_filename.c\t\t\\\n\tlibarchive/test/test_read_format_mtree.c\t\t\\\n\tlibarchive/test/test_read_format_pax_bz2.c\t\t\\\n\tlibarchive/test/test_read_format_rar.c\t\t\t\\\n\tlibarchive/test/test_read_format_raw.c\t\t\t\\\n\tlibarchive/test/test_read_format_tar.c\t\t\t\\\n\tlibarchive/test/test_read_format_tar_empty_filename.c\t\\\n\tlibarchive/test/test_read_format_tar_filename.c\t\t\\\n\tlibarchive/test/test_read_format_tbz.c\t\t\t\\\n\tlibarchive/test/test_read_format_tgz.c\t\t\t\\\n\tlibarchive/test/test_read_format_tlz.c\t\t\t\\\n\tlibarchive/test/test_read_format_txz.c\t\t\t\\\n\tlibarchive/test/test_read_format_tz.c\t\t\t\\\n\tlibarchive/test/test_read_format_ustar_filename.c\t\\\n\tlibarchive/test/test_read_format_xar.c\t\t\t\\\n\tlibarchive/test/test_read_format_zip.c\t\t\t\\\n\tlibarchive/test/test_read_format_zip_comment_stored.c\t\\\n\tlibarchive/test/test_read_format_zip_filename.c\t\t\\\n\tlibarchive/test/test_read_format_zip_mac_metadata.c\t\\\n\tlibarchive/test/test_read_format_zip_sfx.c\t\t\\\n\tlibarchive/test/test_read_large.c\t\t\t\\\n\tlibarchive/test/test_read_pax_truncated.c\t\t\\\n\tlibarchive/test/test_read_position.c\t\t\t\\\n\tlibarchive/test/test_read_set_format.c\t\t\t\\\n\tlibarchive/test/test_read_truncated.c\t\t\t\\\n\tlibarchive/test/test_read_truncated_filter.c\t\t\\\n\tlibarchive/test/test_sparse_basic.c\t\t\t\\\n\tlibarchive/test/test_tar_filenames.c\t\t\t\\\n\tlibarchive/test/test_tar_large.c\t\t\t\\\n\tlibarchive/test/test_ustar_filenames.c\t\t\t\\\n\tlibarchive/test/test_ustar_filename_encoding.c\t\t\\\n\tlibarchive/test/test_write_disk.c\t\t\t\\\n\tlibarchive/test/test_write_disk_appledouble.c\t\t\\\n\tlibarchive/test/test_write_disk_failures.c\t\t\\\n\tlibarchive/test/test_write_disk_hardlink.c\t\t\\\n\tlibarchive/test/test_write_disk_hfs_compression.c\t\\\n\tlibarchive/test/test_write_disk_lookup.c\t\t\\\n\tlibarchive/test/test_write_disk_mac_metadata.c\t\t\\\n\tlibarchive/test/test_write_disk_no_hfs_compression.c\t\\\n\tlibarchive/test/test_write_disk_perms.c\t\t\t\\\n\tlibarchive/test/test_write_disk_secure.c\t\t\\\n\tlibarchive/test/test_write_disk_s\n/* ... truncated ... */\n```\n\n### libarchive/archive_read.c\n\n#### archive_read_open1() [lines 450-539]\n```c\n}\n\nint\narchive_read_open1(struct archive *_a)\n{\n\tstruct archive_read *a = (struct archive_read *)_a;\n\tstruct archive_read_filter *filter, *tmp;\n\tint slot, e;\n\tunsigned int i;\n\n\tarchive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW,\n\t \"archive_read_open\");\n\tarchive_clear_error(&a->archive);\n\n\tif (a->client.reader == NULL) {\n\t\tarchive_set_error(&a->archive, EINVAL,\n\t\t \"No reader function provided to archive_read_open\");\n\t\ta->archive.state = ARCHIVE_STATE_FATAL;\n\t\treturn (ARCHIVE_FATAL);\n\t}\n\n\t/* Open data source. */\n\tif (a->client.opener != NULL) {\n\t\te = (a->client.opener)(&a->archive, a->client.dataset[0].data);\n\t\tif (e != 0) {\n\t\t\t/* If the open failed, call the closer to clean up. */\n\t\t\tif (a->client.closer) {\n\t\t\t\tfor (i = 0; i < a->client.nodes; i++)\n\t\t\t\t\t(a->client.closer)(&a->archive,\n\t\t\t\t\t a->client.dataset[i].data);\n\t\t\t}\n\t\t\treturn (e);\n\t\t}\n\t}\n\n\tfilter = calloc(1, sizeof(*filter));\n\tif (filter == NULL)\n\t\treturn (ARCHIVE_FATAL);\n\tfilter->bidder = NULL;\n\tfilter->upstream = NULL;\n\tfilter->archive = a;\n\tfilter->data = a->client.dataset[0].data;\n\tfilter->open = client_open_proxy;\n\tfilter->read = client_read_proxy;\n\tfilter->skip = client_skip_proxy;\n\tfilter->seek = client_seek_proxy;\n\tfilter->close = client_close_proxy;\n\tfilter->sswitch = client_switch_proxy;\n\tfilter->name = \"none\";\n\tfilter->code = ARCHIVE_FILTER_NONE;\n\n\ta->client.dataset[0].begin_position = 0;\n\tif (!a->filter || !a->bypass_filter_bidding)\n\t{\n\t\ta->filter = filter;\n\t\t/* Build out the input pipeline. */\n\t\te = choose_filters(a);\n\t\tif (e < ARCHIVE_WARN) {\n\t\t\ta->archive.state = ARCHIVE_STATE_FATAL;\n\t\t\treturn (ARCHIVE_FATAL);\n\t\t}\n\t}\n\telse\n\t{\n\t\t/* Need to add \"NONE\" type filter at the end of the filter chain */\n\t\ttmp = a->filter;\n\t\twhile (tmp->upstream)\n\t\t\ttmp = tmp->upstream;\n\t\ttmp->upstream = filter;\n\t}\n\n\tif (!a->format)\n\t{\n\t\tslot = choose_format(a);\n\t\tif (slot < 0) {\n\t\t\t__archive_read_close_filters(a);\n\t\t\ta->archive.state = ARCHIVE_STATE_FATAL;\n\t\t\treturn (ARCHIVE_FATAL);\n\t\t}\n\t\ta->format = &(a->formats[slot]);\n\t}\n\n\ta->archive.state = ARCHIVE_STATE_HEADER;\n\n\t/* Ensure libarchive starts from the first node in a multivolume set */\n\tclient_switch_proxy(a->filter, 0);\n\treturn (e);\n}\n\n/*\n```\n\n#### choose_filters() [lines 542-601]\n```c\n * building the pipeline.\n */\nstatic int\nchoose_filters(struct archive_read *a)\n{\n\tint number_bidders, i, bid, best_bid;\n\tstruct archive_read_filter_bidder *bidder, *best_bidder;\n\tstruct archive_read_filter *filter;\n\tssize_t avail;\n\tint r;\n\n\tfor (;;) {\n\t\tn\n/* ... truncated ... */\n```\n\n### libarchive/test/CMakeLists.txt\n\n#### IF() [lines 111-197]\n```c\n test_read_format_gtar_lzma.c\n test_read_format_gtar_sparse.c\n test_read_format_iso_Z.c\n test_read_format_iso_multi_extent.c\n test_read_format_iso_xorriso.c\n test_read_format_isojoliet_bz2.c\n test_read_format_isojoliet_long.c\n test_read_format_isojoliet_rr.c\n test_read_format_isojoliet_versioned.c\n test_read_format_isorr_bz2.c\n test_read_format_isorr_ce.c\n test_read_format_isorr_new_bz2.c\n test_read_format_isorr_rr_moved.c\n test_read_format_isozisofs_bz2.c\n test_read_format_lha.c\n test_read_format_lha_filename.c\n test_read_format_mtree.c\n test_read_format_pax_bz2.c\n test_read_format_rar.c\n test_read_format_raw.c\n test_read_format_tar.c\n test_read_format_tar_empty_filename.c\n test_read_format_tar_filename.c\n test_read_format_tbz.c\n test_read_format_tgz.c\n test_read_format_tlz.c\n test_read_format_txz.c\n test_read_format_tz.c\n test_read_format_ustar_filename.c\n test_read_format_xar.c\n test_read_format_zip.c\n test_read_format_zip_comment_stored.c\n test_read_format_zip_filename.c\n test_read_format_zip_mac_metadata.c\n test_read_format_zip_sfx.c\n test_read_large.c\n test_read_pax_truncated.c\n test_read_position.c\n test_read_set_format.c\n test_read_truncated.c\n test_read_truncated_filter.c\n test_sparse_basic.c\n test_tar_filenames.c\n test_tar_large.c\n test_ustar_filenames.c\n test_ustar_filename_encoding.c\n test_write_disk.c\n test_write_disk_appledouble.c\n test_write_disk_failures.c\n test_write_disk_hardlink.c\n test_write_disk_hfs_compression.c\n test_write_disk_lookup.c\n test_write_disk_mac_metadata.c\n test_write_disk_no_hfs_compression.c\n test_write_disk_perms.c\n test_write_disk_secure.c\n test_write_disk_sparse.c\n test_write_disk_symlink.c\n test_write_disk_times.c\n test_write_filter_b64encode.c\n test_write_filter_bzip2.c\n test_write_filter_compress.c\n test_write_filter_gzip.c\n test_write_filter_gzip_timestamp.c\n test_write_filter_lrzip.c\n test_write_filter_lzip.c\n test_write_filter_lzma.c\n test_write_filter_lzop.c\n test_write_filter_program.c\n test_write_filter_uuencode.c\n test_write_filter_xz.c\n test_write_format_7zip.c\n test_write_format_7zip_empty.c\n test_write_format_7zip_large.c\n test_write_format_ar.c\n test_write_format_cpio.c\n test_write_format_cpio_empty.c\n test_write_format_cpio_newc.c\n test_write_format_cpio_odc.c\n test_write_format_gn\n/* ... truncated ... */\n```\n\n\n### Type definitions\n\n```c\n/* from archive_private.h */\nstruct archive {\n\t/*\n\t * The magic/state values are used to sanity-check the\n\t * client's usage. If an API function is called at a\n\t * ridiculous time, or the client passes us an invalid\n\t * pointer, these values allow me to catch that.\n\t */\n\tunsigned int\tmagic;\n\tunsigned int\tstate;\n\n\t/*\n\t * Some public API functions depend on the \"real\" type of the\n\t * archive object.\n\t */\n\tstruct archive_vtable *vtable;\n\n\tint\t\t archive_format;\n\tconst char\t *archive_format_name;\n\n\tint\t compression_code;\t/* Currently active compression. */\n\tconst char *compression_name;\n\n\t/* Number of file entries processed. */\n\tint\t\t file_count;\n\n\tint\t\t archive_error_number;\n\tconst char\t *error;\n\tstruct archive_string\terror_string;\n\n\tchar *current_code;\n\tunsigned current_codepage; /* Current ACP(ANSI CodePage). */\n\tunsigned current_oemcp; /* Current OEMCP(OEM CodePage). */\n\tstruct archive_string_conv *sconv;\n};\n\n/* from archive_read_private.h */\nstruct archive_read_filter_bidder {\n\t/* Configuration data for the bidder. */\n\tvoid *data;\n\t/* Name of the filter */\n\tconst char *name;\n\t/* Taste the upstream filter to see if we handle this. */\n\tint (*bid)(struct archive_read_filter_bidder *,\n\t struct archive_read_filter *);\n\t/* Initialize a newly-created filter. */\n\tint (*init)(struct archive_read_filter *);\n\t/* Set an option for the filter bidder. */\n\tint (*options)(struct archive_read_filter_bidder *,\n\t const char *key, const char *value);\n\t/* Release the bidder's configuration data. */\n\tint (*free)(struct archive_read_filter_bidder *);\n};\n\n/* from archive_read_private.h */\nstruct archive_read_filter {\n\tint64_t position;\n\t/* Essentially all filters will need these values, so\n\t * just declare them here. */\n\tstruct archive_read_filter_bidder *bidder; /* My bidder. */\n\tstruct archive_read_filter *upstream; /* Who I read from. */\n\tstruct archive_read *archive; /* Associated archive. */\n\t/* Open a block for reading */\n\tint (*open)(struct archive_read_filter *self);\n\t/* Return next block. */\n\tssize_t (*read)(struct archive_read_filter *, const void **);\n\t/* Skip forward this many bytes. */\n\tint64_t (*skip)(struct archive_read_filter *self, int64_t request);\n\t/* Seek to an absolute location. */\n\tint64_t (*seek)(struct archive_read_filter *self, int64_t offset, int whence);\n\t/* Close (just this filter) and free(self). */\n\tint (*close)(struct archive_read_filter *self);\n\t/* Function that handles switching from reading one block to the next/prev */\n\tint (*sswitch)(struct archive_read_filter *self, unsigned int iindex);\n\t/* My private data. */\n\tvoid *data;\n\n\tconst char\t*name;\n\tint\t\t code;\n\n\t/* Used by reblocking logic. */\n\tchar\t\t*buffer;\n\tsize_t\t\t buffer_size;\n\tchar\t\t*next;\t\t/* Current read location. */\n\tsize_t\t\t avail;\t\t/* Bytes in my buffer. */\n\tconst void\t*client_buff;\t/* Client buffer information. */\n\tsize_t\t\t client_total;\n\tconst char\t*client_next;\n\tsize_t\t\t client_avail;\n\tchar\t\t end_of_file;\n\tchar\t\t closed;\n\tchar\t\t fatal;\n};\n```\n\n\n## Upstream Fix\n```diff\ncommit 6e06b1c89dd0d16f74894eac4cfc1327a06ee4a0\nAuthor: Tim Kientzle \nDate: Sat Jan 10 12:24:58 2015 -0800\n\n Fix a potential crash issue discovered by Alexander Cherepanov:\n \n It seems bsdtar automatically handles stacked compression. This is a\n nice feature but it could be problematic when it's completely\n unlimited. Most clearly it's illustrated with quines:\n \n $ curl -sRO http://www.maximumcompression.com/selfgz.gz\n $ (ulimit -v 10000000 && bsdtar -tvf selfgz.gz)\n bsdtar: Error opening archive: Can't allocate data for gzip decompression\n \n Without ulimit, bsdtar will eat all available memory. This could also\n be a problem for other applications using libarchive.\n\nIndex: libarchive-3.1.2/Makefile.am\n===================================================================\n--- libarchive-3.1.2.orig/Makefile.am\n+++ libarchive-3.1.2/Makefile.am\n@@ -439,6 +439,7 @@ libarchive_test_SOURCES=\t\t\t\t\t\\\n \tlibarchive/test/test_read_pax_truncated.c\t\t\\\n \tlibarchive/test/test_read_position.c\t\t\t\\\n \tlibarchive/test/test_read_set_format.c\t\t\t\\\n+\tlibarchive/test/test_read_too_many_filters.c\t\t\\\n \tlibarchive/test/test_read_truncated.c\t\t\t\\\n \tlibarchive/test/test_read_truncated_filter.c\t\t\\\n \tlibarchive/test/test_sparse_basic.c\t\t\t\\\n@@ -703,6 +704,7 @@ libarchive_test_EXTRA_DIST=\\\n \tlibarchive/test/test_read_splitted_rar_ab.uu\t\t\t\\\n \tlibarchive/test/test_read_splitted_rar_ac.uu\t\t\t\\\n \tlibarchive/test/test_read_splitted_rar_ad.uu\t\t\t\\\n+\tlibarchive/test/test_read_too_many_filters.gz.uu \\\n \tlibarchive/test/test_splitted_rar_seek_support_aa.uu\t\t\\\n \tlibarchive/test/test_splitted_rar_seek_support_ab.uu\t\t\\\n \tlibarchive/test/test_splitted_rar_seek_support_ac.uu\t\t\\\nIndex: libarchive-3.1.2/libarchive/archive_read.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_read.c\n+++ libarchive-3.1.2/libarchive/archive_read.c\n@@ -544,13 +544,13 @@ archive_read_open1(struct archive *_a)\n static int\n choose_filters(struct archive_read *a)\n {\n-\tint number_bidders, i, bid, best_bid;\n+\tint number_bidders, i, bid, best_bid, n;\n \tstruct archive_read_filter_bidder *bidder, *best_bidder;\n \tstruct archive_read_filter *filter;\n \tssize_t avail;\n \tint r;\n \n-\tfor (;;) {\n+\tfor (n = 0; n < 25; ++n) {\n \t\tnumber_bidders = sizeof(a->bidders) / sizeof(a->bidders[0]);\n \n \t\tbest_bid = 0;\n@@ -596,6 +596,9 @@ choose_filters(struct archive_read *a)\n \t\t\treturn (ARCHIVE_FATAL);\n \t\t}\n \t}\n+\tarchive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,\n+\t \"Input requires too many filters for decoding\");\n+\treturn (ARCHIVE_FATAL);\n }\n \n /*\nIndex: libarchive-3.1.2/libarchive/test/CMakeLists.txt\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/test/CMakeLists.txt\n+++ libarchive-3.1.2/libarchive/test/CMakeLists.txt\n@@ -150,6 +150,7 @@ IF(ENABLE_TEST)\n test_read_pax_truncated.c\n test_read_position.c\n test_read_set_format.c\n+ test_read_too_many_filters.c\n test_read_truncated.c\n test_read_truncated_filter.c\n test_sparse_basic.c\nIndex: libarchive-3.1.2/libarchive/test/test_read_too_many_filters.c\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_too_many_filters.c\n@@ -0,0 +1,45 @@\n+/*-\n+ * Copyright (c) 2003-2008,2015 Tim Kientzle\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ * 1. Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in the\n+ * documentation and/or other materials provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR\n+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,\n+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+#include \"test.h\"\n+\n+DEFINE_TEST(test_read_too_many_filters)\n+{\n+\tconst char *name = \"test_read_too_many_filters.gz\";\n+\tstruct archive *a;\n+\tint r;\n+\n+\tassert((a = archive_read_new()) != NULL);\n+\tr = archive_read_support_filter_gzip(a);\n+\tif (r == ARCHIVE_WARN) {\n+\t\tskipping(\"gzip reading not fully supported on this platform\");\n+\t}\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));\n+\textract_reference_file(name);\n+\tassertEqualIntA(a, ARCHIVE_FATAL,\n+\t archive_read_open_filename(a, name, 200));\n+\n+\tassertEqualInt(ARCHIVE_OK, archive_read_close(a));\n+\tassertEqualInt(ARCHIVE_OK, archive_read_free(a));\n+}\nIndex: libarchive-3.1.2/libarchive/test/test_read_too_many_filters.gz.uu\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_too_many_filters.gz.uu\n@@ -0,0 +1,15 @@\n+This is a valid gzip file that decompresses to itself, from\n+ http://www.maximumcompression.com/selfgz.gz\n+\n+This is used in test_read_too_many_filters to try to\n+crash libarchive by forcing it to spawn an unending\n+list of gunzip filters.\n+\n+begin 644 test_read_too_many_filters.gz\n+M'XL(\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "commit 6e06b1c89dd0d16f74894eac4cfc1327a06ee4a0\nAuthor: Tim Kientzle \nDate: Sat Jan 10 12:24:58 2015 -0800\n\n Fix a potential crash issue discovered by Alexander Cherepanov:\n \n It seems bsdtar automatically handles stacked compression. This is a\n nice feature but it could be problematic when it's completely\n unlimited. Most clearly it's illustrated with quines:\n \n $ curl -sRO http://www.maximumcompression.com/selfgz.gz\n $ (ulimit -v 10000000 && bsdtar -tvf selfgz.gz)\n bsdtar: Error opening archive: Can't allocate data for gzip decompression\n \n Without ulimit, bsdtar will eat all available memory. This could also\n be a problem for other applications using libarchive.\n\nIndex: libarchive-3.1.2/Makefile.am\n===================================================================\n--- libarchive-3.1.2.orig/Makefile.am\n+++ libarchive-3.1.2/Makefile.am\n@@ -439,6 +439,7 @@ libarchive_test_SOURCES=\t\t\t\t\t\\\n \tlibarchive/test/test_read_pax_truncated.c\t\t\\\n \tlibarchive/test/test_read_position.c\t\t\t\\\n \tlibarchive/test/test_read_set_format.c\t\t\t\\\n+\tlibarchive/test/test_read_too_many_filters.c\t\t\\\n \tlibarchive/test/test_read_truncated.c\t\t\t\\\n \tlibarchive/test/test_read_truncated_filter.c\t\t\\\n \tlibarchive/test/test_sparse_basic.c\t\t\t\\\n@@ -703,6 +704,7 @@ libarchive_test_EXTRA_DIST=\\\n \tlibarchive/test/test_read_splitted_rar_ab.uu\t\t\t\\\n \tlibarchive/test/test_read_splitted_rar_ac.uu\t\t\t\\\n \tlibarchive/test/test_read_splitted_rar_ad.uu\t\t\t\\\n+\tlibarchive/test/test_read_too_many_filters.gz.uu \\\n \tlibarchive/test/test_splitted_rar_seek_support_aa.uu\t\t\\\n \tlibarchive/test/test_splitted_rar_seek_support_ab.uu\t\t\\\n \tlibarchive/test/test_splitted_rar_seek_support_ac.uu\t\t\\\nIndex: libarchive-3.1.2/libarchive/archive_read.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_read.c\n+++ libarchive-3.1.2/libarchive/archive_read.c\n@@ -544,13 +544,13 @@ archive_read_open1(struct archive *_a)\n static int\n choose_filters(struct archive_read *a)\n {\n-\tint number_bidders, i, bid, best_bid;\n+\tint number_bidders, i, bid, best_bid, n;\n \tstruct archive_read_filter_bidder *bidder, *best_bidder;\n \tstruct archive_read_filter *filter;\n \tssize_t avail;\n \tint r;\n \n-\tfor (;;) {\n+\tfor (n = 0; n < 25; ++n) {\n \t\tnumber_bidders = sizeof(a->bidders) / sizeof(a->bidders[0]);\n \n \t\tbest_bid = 0;\n@@ -596,6 +596,9 @@ choose_filters(struct archive_read *a)\n \t\t\treturn (ARCHIVE_FATAL);\n \t\t}\n \t}\n+\tarchive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,\n+\t \"Input requires too many filters for decoding\");\n+\treturn (ARCHIVE_FATAL);\n }\n \n /*\nIndex: libarchive-3.1.2/libarchive/test/CMakeLists.txt\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/test/CMakeLists.txt\n+++ libarchive-3.1.2/libarchive/test/CMakeLists.txt\n@@ -150,6 +150,7 @@ IF(ENABLE_TEST)\n test_read_pax_truncated.c\n test_read_position.c\n test_read_set_format.c\n+ test_read_too_many_filters.c\n test_read_truncated.c\n test_read_truncated_filter.c\n test_sparse_basic.c\nIndex: libarchive-3.1.2/libarchive/test/test_read_too_many_filters.c\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_too_many_filters.c\n@@ -0,0 +1,45 @@\n+/*-\n+ * Copyright (c) 2003-2008,2015 Tim Kientzle\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ * 1. Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in the\n+ * documentation and/or other materials provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR\n+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,\n+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+#include \"test.h\"\n+\n+DEFINE_TEST(test_read_too_many_filters)\n+{\n+\tconst char *name = \"test_read_too_many_filters.gz\";\n+\tstruct archive *a;\n+\tint r;\n+\n+\tassert((a = archive_read_new()) != NULL);\n+\tr = archive_read_support_filter_gzip(a);\n+\tif (r == ARCHIVE_WARN) {\n+\t\tskipping(\"gzip reading not fully supported on this platform\");\n+\t}\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));\n+\textract_reference_file(name);\n+\tassertEqualIntA(a, ARCHIVE_FATAL,\n+\t archive_read_open_filename(a, name, 200));\n+\n+\tassertEqualInt(ARCHIVE_OK, archive_read_close(a));\n+\tassertEqualInt(ARCHIVE_OK, archive_read_free(a));\n+}\nIndex: libarchive-3.1.2/libarchive/test/test_read_too_many_filters.gz.uu\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_too_many_filters.gz.uu\n@@ -0,0 +1,15 @@\n+This is a valid gzip file that decompresses to itself, from\n+ http://www.maximumcompression.com/selfgz.gz\n+\n+This is used in test_read_too_many_filters to try to\n+crash libarchive by forcing it to spawn an unending\n+list of gunzip filters.\n+\n+begin 644 test_read_too_many_filters.gz\n+M'XL(`````````P`/`/#_'XL(`````````P`/`/#_````__\\```#__X)QH5P`\n+M`!X`X?\\```#__P```/__@G&A7```'@#A_P```/__````__\\```#__P```/__\n+M````__\\```#__\\(FAF`!`!0`Z_\\```#__P```/__PB:&8`$`%`#K_\\(FAF`!\n+M`!0`Z_^9(#6-B\"@Q,C,T`K/`+```%`#K_P*SP\"P``!0`Z_]\"B\"'$`````/__\n+>`P!#2DTAT@```$*((<0`````__\\#`$-*32'2````\n+`\n+end"}], "metadata": {"id": "libarchive-5942-CVE-2016-7166.patch", "cve_id": "CVE-2016-6250", "package": "libarchive", "tier": "adapted", "has_source_context": true, "context_tokens_est": 2705, "context_files": 3, "license": "BSD-2-Clause"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-7555\n\nSecurity vulnerability CVE-2015-7555\n\n## Package\ngiflib\n\n## Files to modify\n- giflib-5.0.5.orig/lib/egif_lib.c\n- lib/egif_lib.c\n\n## Upstream Fix\n```diff\n---\n lib/egif_lib.c | 6 ++++++\n 1 file changed, 6 insertions(+)\n\nIndex: giflib-5.0.5/lib/egif_lib.c\n===================================================================\n--- giflib-5.0.5.orig/lib/egif_lib.c\n+++ giflib-5.0.5/lib/egif_lib.c\n@@ -376,6 +376,12 @@ EGifPutImageDesc(GifFileType *GifFile,\n GifFile->Image.Width = Width;\n GifFile->Image.Height = Height;\n GifFile->Image.Interlace = Interlace;\n+\n+ // We're going to overwrite the Image.ColorMap pointer next, so free it if not NULL first!\n+ if (GifFile->Image.ColorMap != NULL) {\n+ GifFreeMapObject(GifFile->Image.ColorMap);\n+ GifFile->Image.ColorMap = NULL;\n+ }\n if (ColorMap) {\n GifFile->Image.ColorMap = GifMakeMapObject(ColorMap->ColorCount,\n ColorMap->Colors);\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "---\n lib/egif_lib.c | 6 ++++++\n 1 file changed, 6 insertions(+)\n\nIndex: giflib-5.0.5/lib/egif_lib.c\n===================================================================\n--- giflib-5.0.5.orig/lib/egif_lib.c\n+++ giflib-5.0.5/lib/egif_lib.c\n@@ -376,6 +376,12 @@ EGifPutImageDesc(GifFileType *GifFile,\n GifFile->Image.Width = Width;\n GifFile->Image.Height = Height;\n GifFile->Image.Interlace = Interlace;\n+\n+ // We're going to overwrite the Image.ColorMap pointer next, so free it if not NULL first!\n+ if (GifFile->Image.ColorMap != NULL) {\n+ GifFreeMapObject(GifFile->Image.ColorMap);\n+ GifFile->Image.ColorMap = NULL;\n+ }\n if (ColorMap) {\n GifFile->Image.ColorMap = GifMakeMapObject(ColorMap->ColorCount,\n ColorMap->Colors);"}], "metadata": {"id": "giflib-4546-bnc949160-fix-colormap-leak.pa", "cve_id": "CVE-2015-7555", "package": "giflib", "tier": "identical", "has_source_context": false, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2014-3609\n\nHttpHdrRange.cc in Squid 3.x before 3.3.12 and 3.4.x before 3.4.6 allows remote attackers to cause a denial of service (crash) via a request with crafted \"Range headers with unidentifiable byte-range values.\"\n\n## Package\nsquid\n\n## Upstream Fix\n```diff\n------------------------------------------------------------\nrevno: 11826\nrevision-id: squid3@treenet.co.nz-20130713124108-55ve768vfrd4sbkc\nparent: squid3@treenet.co.nz-20130713123806-pteg9ouzldmxpu8h\ncommitter: Amos Jeffries \nbranch nick: 3.2\ntimestamp: Sat 2013-07-13 06:41:08 -0600\nmessage:\n Better handling of strange port values in Host:\n \n We can do better than just producing errors about invalid port details\n and treating it as port-0.\n We can instead undo the port separation and pass it through as part of\n the host name to be verified with the default port number properly\n assumed.\n------------------------------------------------------------\n# Bazaar merge directive format 2 (Bazaar 0.90)\n# revision_id: squid3@treenet.co.nz-20130713124108-55ve768vfrd4sbkc\n# target_branch: http://bzr.squid-cache.org/bzr/squid3/branches\\\n# /SQUID_3_2\n# testament_sha1: a8072203e76e80d4ffb5b6a4cfe7b95f0dd30a4d\n# timestamp: 2013-07-13 12:41:42 +0000\n# source_branch: http://bzr.squid-cache.org/bzr/squid3/branches\\\n# /SQUID_3_2\n# base_revision_id: squid3@treenet.co.nz-20130713123806-\\\n# pteg9ouzldmxpu8h\n# \n# Begin patch\n=== modified file 'src/client_side_request.cc'\n--- src/client_side_request.cc\t2013-03-29 06:13:27 +0000\n+++ src/client_side_request.cc\t2013-07-13 12:41:08 +0000\n@@ -641,8 +641,16 @@\n uint16_t port = 0;\n if (portStr) {\n *portStr = '\\0'; // strip the ':'\n- if (*(++portStr) != '\\0')\n- port = xatoi(portStr);\n+ if (*(++portStr) != '\\0') {\n+ char *end = NULL;\n+ int64_t ret = strtoll(portStr, &end, 10);\n+ if (end == portStr || *end != '\\0' || ret < 1 || ret > 0xFFFF) {\n+ // invalid port details. Replace the ':'\n+ *(--portStr) = ':';\n+ portStr = NULL;\n+ } else\n+ port = (ret & 0xFFFF);\n+ }\n }\n \n debugs(85, 3, HERE << \"validate host=\" << host << \", port=\" << port << \", portStr=\" << (portStr?portStr:\"NULL\"));\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "------------------------------------------------------------\nrevno: 11826\nrevision-id: squid3@treenet.co.nz-20130713124108-55ve768vfrd4sbkc\nparent: squid3@treenet.co.nz-20130713123806-pteg9ouzldmxpu8h\ncommitter: Amos Jeffries \nbranch nick: 3.2\ntimestamp: Sat 2013-07-13 06:41:08 -0600\nmessage:\n Better handling of strange port values in Host:\n \n We can do better than just producing errors about invalid port details\n and treating it as port-0.\n We can instead undo the port separation and pass it through as part of\n the host name to be verified with the default port number properly\n assumed.\n------------------------------------------------------------\n# Bazaar merge directive format 2 (Bazaar 0.90)\n# revision_id: squid3@treenet.co.nz-20130713124108-55ve768vfrd4sbkc\n# target_branch: http://bzr.squid-cache.org/bzr/squid3/branches\\\n# /SQUID_3_2\n# testament_sha1: a8072203e76e80d4ffb5b6a4cfe7b95f0dd30a4d\n# timestamp: 2013-07-13 12:41:42 +0000\n# source_branch: http://bzr.squid-cache.org/bzr/squid3/branches\\\n# /SQUID_3_2\n# base_revision_id: squid3@treenet.co.nz-20130713123806-\\\n# pteg9ouzldmxpu8h\n# \n# Begin patch\n=== modified file 'src/client_side_request.cc'\n--- src/client_side_request.cc\t2013-03-29 06:13:27 +0000\n+++ src/client_side_request.cc\t2013-07-13 12:41:08 +0000\n@@ -641,8 +641,16 @@\n uint16_t port = 0;\n if (portStr) {\n *portStr = '\\0'; // strip the ':'\n- if (*(++portStr) != '\\0')\n- port = xatoi(portStr);\n+ if (*(++portStr) != '\\0') {\n+ char *end = NULL;\n+ int64_t ret = strtoll(portStr, &end, 10);\n+ if (end == portStr || *end != '\\0' || ret < 1 || ret > 0xFFFF) {\n+ // invalid port details. Replace the ':'\n+ *(--portStr) = ':';\n+ portStr = NULL;\n+ } else\n+ port = (ret & 0xFFFF);\n+ }\n }\n \n debugs(85, 3, HERE << \"validate host=\" << host << \", port=\" << port << \", portStr=\" << (portStr?portStr:\"NULL\"));"}], "metadata": {"id": "squid-2990-squid-3.2.x-11823-bnc830319-CV", "cve_id": "CVE-2014-3609", "package": "squid", "tier": "identical", "has_source_context": false, "license": "GPL-2.0-or-later"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-4658\n\nxpointer.c in libxml2 before 2.9.5 (as used in Apple iOS before 10, OS X before 10.12, tvOS before 10, and watchOS before 3, and other products) does not forbid namespace nodes in XPointer ranges, which allows remote attackers to execute arbitrary code or cause a denial of service (use-after-free and memory corruption) via a crafted XML document.\n\n## Package\nlibxml2\n\n## Files to modify\n- parser.c\n- libxml2-2.9.1.orig/parser.c\n\n## Target Source Code\n\n### parser.c\n\n#### xmlParseEncodingDecl() [lines 10308-7078]\n```c\n\n```\n\n#### xmlParseEncodingDecl() [lines 10369-7078]\n```c\n\n```\n\n\n## Upstream Fix\n```diff\nFrom 9aa37588ee78a06ca1379a9d9356eab16686099c Mon Sep 17 00:00:00 2001\nFrom: Daniel Veillard \nDate: Mon, 29 Jun 2015 09:08:25 +0800\nSubject: [PATCH] Do not process encoding values if the declaration if broken\n\nFor https://bugzilla.gnome.org/show_bug.cgi?id=751603\n\nIf the string is not properly terminated do not try to convert\nto the given encoding.\n---\n parser.c | 4 ++++\n 1 file changed, 4 insertions(+)\n\ndiff --git a/parser.c b/parser.c\nindex fe603aca5a..a3a95681fc 100644\n--- a/parser.c\n+++ b/parser.c\n@@ -10404,6 +10404,8 @@ xmlParseEncodingDecl(xmlParserCtxtPtr ctxt) {\n \t encoding = xmlParseEncName(ctxt);\n \t if (RAW != '\"') {\n \t\txmlFatalErr(ctxt, XML_ERR_STRING_NOT_CLOSED, NULL);\n+\t\txmlFree((xmlChar *) encoding);\n+\t\treturn(NULL);\n \t } else\n \t NEXT;\n \t} else if (RAW == '\\''){\n@@ -10411,6 +10413,8 @@ xmlParseEncodingDecl(xmlParserCtxtPtr ctxt) {\n \t encoding = xmlParseEncName(ctxt);\n \t if (RAW != '\\'') {\n \t\txmlFatalErr(ctxt, XML_ERR_STRING_NOT_CLOSED, NULL);\n+\t\txmlFree((xmlChar *) encoding);\n+\t\treturn(NULL);\n \t } else\n \t NEXT;\n \t} else {\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From 9aa37588ee78a06ca1379a9d9356eab16686099c Mon Sep 17 00:00:00 2001\nFrom: Daniel Veillard \nDate: Mon, 29 Jun 2015 09:08:25 +0800\nSubject: Do not process encoding values if the declaration if broken\n\nCVE-2015-8317\n\nFor https://bugzilla.gnome.org/show_bug.cgi?id=751603\n\nIf the string is not properly terminated do not try to convert\nto the given encoding.\n\n\nFrom 709a952110e98621c9b78c4f26462a9d8333102e Mon Sep 17 00:00:00 2001\nFrom: Daniel Veillard \nDate: Mon, 29 Jun 2015 16:10:26 +0800\nSubject: Fail parsing early on if encoding conversion failed\n\nFor https://bugzilla.gnome.org/show_bug.cgi?id=751631\n\nIf we fail conversing the current input stream while\nprocessing the encoding declaration of the XMLDecl\nthen it's safer to just abort there and not try to\nreport further errors.\n---\n parser.c | 4 ++++\n 1 file changed, 4 insertions(+)\n\nIndex: libxml2-2.9.1/parser.c\n===================================================================\n--- libxml2-2.9.1.orig/parser.c\n+++ libxml2-2.9.1/parser.c\n@@ -10347,6 +10347,8 @@ xmlParseEncodingDecl(xmlParserCtxtPtr ct\n \t encoding = xmlParseEncName(ctxt);\n \t if (RAW != '\"') {\n \t\txmlFatalErr(ctxt, XML_ERR_STRING_NOT_CLOSED, NULL);\n+\t\txmlFree((xmlChar *) encoding);\n+\t\treturn(NULL);\n \t } else\n \t NEXT;\n \t} else if (RAW == '\\''){\n@@ -10354,6 +10356,8 @@ xmlParseEncodingDecl(xmlParserCtxtPtr ct\n \t encoding = xmlParseEncName(ctxt);\n \t if (RAW != '\\'') {\n \t\txmlFatalErr(ctxt, XML_ERR_STRING_NOT_CLOSED, NULL);\n+\t\txmlFree((xmlChar *) encoding);\n+\t\treturn(NULL);\n \t } else\n \t NEXT;\n \t} else {\n@@ -10408,7 +10412,11 @@ xmlParseEncodingDecl(xmlParserCtxtPtr ct\n \n handler = xmlFindCharEncodingHandler((const char *) encoding);\n \t if (handler != NULL) {\n-\t\txmlSwitchToEncoding(ctxt, handler);\n+\t\tif (xmlSwitchToEncoding(ctxt, handler) < 0) {\n+\t\t /* failed to convert */\n+\t\t ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING;\n+\t\t return(NULL);\n+\t\t}\n \t } else {\n \t\txmlFatalErrMsgStr(ctxt, XML_ERR_UNSUPPORTED_ENCODING,\n \t\t\t\"Unsupported encoding %s\\n\", encoding);"}], "metadata": {"id": "libxml2-5762-libxml2-2.9.1-CVE-2015-8317.pa", "cve_id": "CVE-2016-4658", "package": "libxml2", "upstream_enriched": true, "upstream_commit": "9aa37588ee78a06ca1379a9d9356eab16686099c", "upstream_repo": "GNOME/libxml2", "tier": "adapted", "has_source_context": true, "context_tokens_est": 32, "context_files": 1, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-5118\n\nThe OpenBlob function in blob.c in GraphicsMagick before 1.3.24 and ImageMagick allows remote attackers to execute arbitrary code via a | (pipe) character at the start of a filename.\n\n## Package\nGraphicsMagick\n\n## Files to modify\n- GraphicsMagick-1.3.18.orig/magick/utility.c\n- magick/tempfile.h\n- GraphicsMagick-1.3.18.orig/magick/tempfile.c\n- GraphicsMagick-1.3.18.orig/magick/symbols.h\n- magick/utility.h\n\n## Upstream Fix\n```diff\nIndex: GraphicsMagick-1.3.18/magick/delegate.c\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/delegate.c\n+++ GraphicsMagick-1.3.18/magick/delegate.c\n@@ -539,7 +539,10 @@ MagickExport unsigned int InvokeDelegate\n char\n *command,\n **commands,\n- filename[MaxTextExtent];\n+ linkedname[MaxTextExtent],\n+ linkedinfoname[MaxTextExtent],\n+ filename[MaxTextExtent],\n+ safechars[]=\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,-_+ /\";\n \n const DelegateInfo\n *delegate_info;\n@@ -559,6 +562,10 @@ MagickExport unsigned int InvokeDelegate\n assert(image != (Image *) NULL);\n assert(image->signature == MagickSignature);\n temporary_image_filename=(*image->filename == '\\0');\n+ linkedname[0]='\\0';\n+ linkedname[MaxTextExtent-1]='\\0';\n+ linkedinfoname[0]='\\0';\n+ linkedinfoname[MaxTextExtent-1]='\\0';\n if (temporary_image_filename)\n {\n /* Allocate a temporary filename if image is unnamed. */\n@@ -568,12 +575,24 @@ MagickExport unsigned int InvokeDelegate\n return(False);\n }\n }\n+ else if (strspn(image->filename, safechars) != strlen(image->filename))\n+ {\n+ strncpy(linkedname,image->filename,MaxTextExtent-1);\n+ if (!AcquireTemporarySymlink(image->filename,linkedname))\n+\t{\n+ (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image->filename);\n+\t return (False);\n+\t}\n+ }\n+\n (void) strlcpy(filename,image->filename,MaxTextExtent);\n delegate_info=GetDelegateInfo(decode,encode,exception);\n if (delegate_info == (DelegateInfo *) NULL)\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+ if (*linkedname)\n+\tstrncpy(image->filename,linkedname,MaxTextExtent-1);\n (void) ThrowException(exception,DelegateError,NoTagFound,\n decode ? decode : encode);\n return(False);\n@@ -594,6 +613,18 @@ MagickExport unsigned int InvokeDelegate\n }\n image_info->temporary=True;\n }\n+ else if (strspn(image_info->filename, safechars) != strlen(image_info->filename))\n+ {\n+ strncpy(linkedinfoname,image_info->filename,MaxTextExtent-1);\n+ if (!AcquireTemporarySymlink(image_info->filename,linkedinfoname))\n+\t{\n+ if (temporary_image_filename)\n+ LiberateTemporaryFile(image->filename);\n+ (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->filename);\n+ return(False);\n+ }\n+ temporary_image_filename=True;\n+ }\n \n if (delegate_info->mode != 0)\n if ((decode && (delegate_info->encode != (char *) NULL)) ||\n@@ -617,6 +648,13 @@ MagickExport unsigned int InvokeDelegate\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->unique);\n return(False);\n }\n@@ -625,6 +663,13 @@ MagickExport unsigned int InvokeDelegate\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n (void) LiberateTemporaryFile(image_info->unique);\n (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->zero);\n return(False);\n@@ -638,6 +683,13 @@ MagickExport unsigned int InvokeDelegate\n (void) LiberateTemporaryFile(image_info->zero);\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n (void) ThrowException(exception,DelegateError,DelegateFailed,\n decode ? decode : encode);\n return(False);\n@@ -663,6 +715,13 @@ MagickExport unsigned int InvokeDelegate\n (void) LiberateTemporaryFile(image_info->zero);\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n DestroyImageInfo(clone_info);\n (void) ThrowException(exception,DelegateError,DelegateFailed,\n decode ? decode : encode);\n@@ -684,6 +743,13 @@ MagickExport unsigned int InvokeDelegate\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+ if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+ if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+ }\n (void) ThrowException(exception,ResourceLimitError,MemoryAllocationFailed,decode ? decode : encode);\n return(False);\n }\n@@ -810,6 +876,13 @@ MagickExport unsigned int InvokeDelegate\n error_exit:\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+ if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+ if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+ }\n for ( ; commands[i] != (char *) NULL; i++)\n MagickFreeMemory(commands[i]);\n MagickFreeMemory(commands);\nIndex: GraphicsMagick-1.3.18/magick/symbols.h\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/symbols.h\n+++ GraphicsMagick-1.3.18/magick/symbols.h\n@@ -43,6 +43,7 @@\n #define AcquireTemporaryFileDescriptor GmAcquireTemporaryFileDescriptor\n #define AcquireTemporaryFileName GmAcquireTemporaryFileName\n #define AcquireTemporaryFileStream GmAcquireTemporaryFileStream\n+#define AcquireTemporarySymlink GmAcquireTemporarySymlink\n #define AdaptiveThresholdImage GmAdaptiveThresholdImage\n #define AddDefinition GmAddDefinition\n #define AddDefinitions GmAddDefinitions\nIndex: GraphicsMagick-1.3.18/magick/tempfile.c\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/tempfile.c\n+++ GraphicsMagick-1.3.18/magick/tempfile.c\n@@ -192,6 +192,93 @@ MagickExport MagickPassFail AcquireTempo\n % %\n % %\n % %\n++ A c q u i r e T e m p o r a r y S y m l i n k %\n+% %\n+% %\n+% %\n+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n+%\n+% AcquireTemporarySymlink replaces the contents of the string buffer pointed\n+% to by filename with the unique name of a symbolic link. True is returned\n+% if a symlink\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "Index: GraphicsMagick-1.3.18/magick/delegate.c\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/delegate.c\n+++ GraphicsMagick-1.3.18/magick/delegate.c\n@@ -539,7 +539,10 @@ MagickExport unsigned int InvokeDelegate\n char\n *command,\n **commands,\n- filename[MaxTextExtent];\n+ linkedname[MaxTextExtent],\n+ linkedinfoname[MaxTextExtent],\n+ filename[MaxTextExtent],\n+ safechars[]=\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,-_+ /\";\n \n const DelegateInfo\n *delegate_info;\n@@ -559,6 +562,10 @@ MagickExport unsigned int InvokeDelegate\n assert(image != (Image *) NULL);\n assert(image->signature == MagickSignature);\n temporary_image_filename=(*image->filename == '\\0');\n+ linkedname[0]='\\0';\n+ linkedname[MaxTextExtent-1]='\\0';\n+ linkedinfoname[0]='\\0';\n+ linkedinfoname[MaxTextExtent-1]='\\0';\n if (temporary_image_filename)\n {\n /* Allocate a temporary filename if image is unnamed. */\n@@ -568,12 +575,24 @@ MagickExport unsigned int InvokeDelegate\n return(False);\n }\n }\n+ else if (strspn(image->filename, safechars) != strlen(image->filename))\n+ {\n+ strncpy(linkedname,image->filename,MaxTextExtent-1);\n+ if (!AcquireTemporarySymlink(image->filename,linkedname))\n+\t{\n+ (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image->filename);\n+\t return (False);\n+\t}\n+ }\n+\n (void) strlcpy(filename,image->filename,MaxTextExtent);\n delegate_info=GetDelegateInfo(decode,encode,exception);\n if (delegate_info == (DelegateInfo *) NULL)\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+ if (*linkedname)\n+\tstrncpy(image->filename,linkedname,MaxTextExtent-1);\n (void) ThrowException(exception,DelegateError,NoTagFound,\n decode ? decode : encode);\n return(False);\n@@ -594,6 +613,18 @@ MagickExport unsigned int InvokeDelegate\n }\n image_info->temporary=True;\n }\n+ else if (strspn(image_info->filename, safechars) != strlen(image_info->filename))\n+ {\n+ strncpy(linkedinfoname,image_info->filename,MaxTextExtent-1);\n+ if (!AcquireTemporarySymlink(image_info->filename,linkedinfoname))\n+\t{\n+ if (temporary_image_filename)\n+ LiberateTemporaryFile(image->filename);\n+ (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->filename);\n+ return(False);\n+ }\n+ temporary_image_filename=True;\n+ }\n \n if (delegate_info->mode != 0)\n if ((decode && (delegate_info->encode != (char *) NULL)) ||\n@@ -617,6 +648,13 @@ MagickExport unsigned int InvokeDelegate\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->unique);\n return(False);\n }\n@@ -625,6 +663,13 @@ MagickExport unsigned int InvokeDelegate\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n (void) LiberateTemporaryFile(image_info->unique);\n (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->zero);\n return(False);\n@@ -638,6 +683,13 @@ MagickExport unsigned int InvokeDelegate\n (void) LiberateTemporaryFile(image_info->zero);\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n (void) ThrowException(exception,DelegateError,DelegateFailed,\n decode ? decode : encode);\n return(False);\n@@ -663,6 +715,13 @@ MagickExport unsigned int InvokeDelegate\n (void) LiberateTemporaryFile(image_info->zero);\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n DestroyImageInfo(clone_info);\n (void) ThrowException(exception,DelegateError,DelegateFailed,\n decode ? decode : encode);\n@@ -684,6 +743,13 @@ MagickExport unsigned int InvokeDelegate\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+ if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+ if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+ }\n (void) ThrowException(exception,ResourceLimitError,MemoryAllocationFailed,decode ? decode : encode);\n return(False);\n }\n@@ -810,6 +876,13 @@ MagickExport unsigned int InvokeDelegate\n error_exit:\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+ if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+ if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+ }\n for ( ; commands[i] != (char *) NULL; i++)\n MagickFreeMemory(commands[i]);\n MagickFreeMemory(commands);\nIndex: GraphicsMagick-1.3.18/magick/symbols.h\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/symbols.h\n+++ GraphicsMagick-1.3.18/magick/symbols.h\n@@ -43,6 +43,7 @@\n #define AcquireTemporaryFileDescriptor GmAcquireTemporaryFileDescriptor\n #define AcquireTemporaryFileName GmAcquireTemporaryFileName\n #define AcquireTemporaryFileStream GmAcquireTemporaryFileStream\n+#define AcquireTemporarySymlink GmAcquireTemporarySymlink\n #define AdaptiveThresholdImage GmAdaptiveThresholdImage\n #define AddDefinition GmAddDefinition\n #define AddDefinitions GmAddDefinitions\nIndex: GraphicsMagick-1.3.18/magick/tempfile.c\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/tempfile.c\n+++ GraphicsMagick-1.3.18/magick/tempfile.c\n@@ -192,6 +192,93 @@ MagickExport MagickPassFail AcquireTempo\n % %\n % %\n % %\n++ A c q u i r e T e m p o r a r y S y m l i n k %\n+% %\n+% %\n+% %\n+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n+%\n+% AcquireTemporarySymlink replaces the contents of the string buffer pointed\n+% to by filename with the unique name of a symbolic link. True is returned\n+% if a symlink waas created, or False is returned if there is a failure.\n+% The allocated symlink should be recovered via the LiberateTemporaryFile()\n+% function once it is no longer required.\n+%\n+% The format of the AcquireTemporarySymlink method is:\n+%\n+% unsigned int AcquireTemporarySymlink(char *linkname, const char *name,\n+% ExceptionInfo *exception)\n+%\n+% A description of each parameter follows.\n+%\n+% o linkname: Specifies a pointer to an array of characters that must be\n+% MaxTextExtent characters of size. The unique\n+% name of the symlink is returned in this array.\n+% o name: Specifies a file name the symlink should point to.\n+*/\n+MagickExport unsigned int AcquireTemporarySymlink(char *linkname, const char *name)\n+{\n+ char\n+ *tempdir,\n+ tempname[MaxTextExtent];\n+\n+ int\n+ fd,\n+ tries;\n+ \n+ assert(linkname != (char *)NULL);\n+ linkname[0]='\\0';\n+ tempname[MaxTextExtent-1]='\\0';\n+\n+ tempdir=getenv(\"MAGICK_TMPDIR\");\n+#if defined(POSIX)\n+ if (!tempdir)\n+ tempdir=getenv(\"TMPDIR\");\n+#endif /* POSIX */\n+#if defined(WIN32)\n+ if (!tempdir)\n+ tempdir=getenv(\"TMP\");\n+ if (!tempdir)\n+ tempdir=getenv(\"TEMP\");\n+#endif /* WIN32 */\n+#if defined(P_tmpdir)\n+ if (!tempdir)\n+ tempdir=P_tmpdir;\n+#endif\n+\n+ for (tries=0; tries < 15; tries++)\n+ {\n+ strncpy(tempname,\"gmXXXXXX\",MaxTextExtent-1);\n+ ComposeTemporaryFileName(tempname);\n+ strncpy(linkname,tempdir,MaxTextExtent-1);\n+ if (tempdir[strlen(tempdir)-1] != DirectorySeparator[0])\n+\tstrncat(linkname,DirectorySeparator,MaxTextExtent-1);\n+ strncat(linkname,tempname,MaxTextExtent-1);\n+ if (*name == '/')\n+ fd=symlink(name, linkname);\n+ else\n+ {\n+ char cname[MaxTextExtent];\n+\t if (!getcwd(cname,(size_t)MaxTextExtent))\n+\t return (False);\n+\t strncat(cname,DirectorySeparator,MaxTextExtent-1);\n+\t strncat(cname,name,MaxTextExtent-1);\n+\t fd=symlink(cname,linkname);\n+\t}\n+ if (fd != -1)\n+\t{\n+\t AddTemporaryFileToList(linkname);\n+\t return (True);\n+\t}\n+ }\n+ return (False);\n+}\n+\f\n+/*\n+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n+% %\n+% %\n+% %\n + A c q u i r e T e m p o r a r y F i l e D e s c r i p t o r %\n % %\n % %\nIndex: GraphicsMagick-1.3.18/magick/tempfile.h\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/tempfile.h\n+++ GraphicsMagick-1.3.18/magick/tempfile.h\n@@ -24,6 +24,7 @@ typedef enum\n \n MagickExport MagickPassFail\n AcquireTemporaryFileName(char *filename),\n+ AcquireTemporarySymlink(char *linkname, const char *name),\n LiberateTemporaryFile(char *filename);\n \n MagickExport int\nIndex: GraphicsMagick-1.3.18/magick/utility.c\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/utility.c\n+++ GraphicsMagick-1.3.18/magick/utility.c\n@@ -1253,6 +1253,72 @@ MagickExport void FormatString(char *str\n % %\n % %\n % %\n+% F o r m a t S t r i n g N u m e r i c %\n+% %\n+% %\n+% %\n+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n+%\n+% Method FormatStringNumeric formats output for a single numeric argument.\n+% It takes into account that the format string given might be untrusted\n+% user input, and returns a pointer to the formatted string.\n+%\n+% The format of the FormatStringNumeric method is:\n+%\n+% char * FormatStringNumeric(char *string,const char *format,int value)\n+%\n+% A description of each parameter follows.\n+%\n+% o format: A string describing the format to use to write the numeric\n+% argument. Only the first numeric format identifier is replaced.\n+%\n+% o value: Numeric value to substitute into format string.\n+%\n+%\n+*/\n+MagickExport char *FormatStringNumeric(const char *format,int value)\n+{\n+ char\n+ *p,\n+ *string;\n+\n+ string = NULL;\n+\n+ (void) CloneString(&string, format);\n+\n+ for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))\n+ { \n+ char\n+ *q;\n+\n+ q=(char *) p+1;\n+ if (*q == '0')\n+ (void) strtol(q,&q,10);\n+ if ((*q == '%') || (*q == 'd') || (*q == 'o') || (*q == 'x'))\n+ {\n+ char\n+ c;\n+\n+ q++;\n+ c=*q;\n+ *q='\\0';\n+ (void) snprintf(string+(p-format),MaxTextExtent-(p-format),p,value);\n+ *q=c;\n+ (void) ConcatenateString(&string,q);\n+ if (*(q-1) == '%')\n+ p++;\n+ else\n+ break;\n+ }\n+ }\n+ return string;\n+}\n+\f\n+/*\n+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n+% %\n+% %\n+% %\n % G e t E x e c u t i o n P a t h %\n % %\n % %\nIndex: GraphicsMagick-1.3.18/magick/utility.h\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/utility.h\n+++ GraphicsMagick-1.3.18/magick/utility.h\n@@ -72,6 +72,7 @@ extern MagickExport char\n *AllocateString(const char *),\n *Base64Encode(const unsigned char *,const size_t,size_t *),\n *EscapeString(const char *,const char),\n+ *FormatStringNumeric(const char *,int),\n *GetPageGeometry(const char *),\n **ListFiles(const char *,const char *,long *),\n **StringToArgv(const char *,int *),"}], "metadata": {"id": "GraphicsMagick-5162-GraphicsMagick-debian-fixed.pa", "cve_id": "CVE-2016-5118", "package": "GraphicsMagick", "tier": "adapted", "has_source_context": false, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2013-4560\n\nUse-after-free vulnerability in lighttpd before 1.4.33 allows remote attackers to cause a denial of service (segmentation fault and crash) via unspecified vectors that trigger FAMMonitorDirectory failures.\n\n## Package\nlighttpd\n\n## Files to modify\n- src/network.c\n- lighttpd-1.4.31.orig/src/network.c\n\n## Target Source Code\n\n### src/network.c\n\n#### region() [lines 739-748]\n```c\n\t\t\t);\n\t\t}\n\n\t\tif (SSL_CTX_use_certificate_file(s->ssl_ctx, s->ssl_pemfile->ptr, SSL_FILETYPE_PEM) < 0) {\n\t\t\tlog_error_write(srv, __FILE__, __LINE__, \"ssb\", \"SSL:\",\n\t\t\t\t\tERR_error_string(ERR_get_error(), NULL), s->ssl_pemfile);\n\t\t\treturn -1;\n\t\t}\n\n\t\tif (SSL_CTX_use_PrivateKey_file (s->ssl_ctx, s->ssl_pemfile->ptr, SSL_FILETYPE_PEM) < 0) {\n```\n\n\n## Upstream Fix\n```diff\norigin: http://redmine.lighttpd.net/projects/lighttpd/repository/revisions/2925/diff/\n\nIndex: lighttpd-1.4.31/src/network.c\n===================================================================\n--- lighttpd-1.4.31.orig/src/network.c\t2013-11-14 10:44:56.000000000 +0100\n+++ lighttpd-1.4.31/src/network.c\t2013-11-14 10:52:56.211535856 +0100\n@@ -743,6 +743,14 @@\n \t\t\treturn -1;\n \t\t}\n \n+\t\t/* completely useless identifier; required for client cert verification to work with sessions */\n+\t\tif (0 == SSL_CTX_set_session_id_context(s->ssl_ctx, (const unsigned char*) CONST_STR_LEN(\"lighttpd\"))) {\n+\t\t\tlog_error_write(srv, __FILE__, __LINE__, \"ss:s\", \"SSL:\",\n+\t\t\t\t\"failed to set session context\",\n+\t\t\t\tERR_error_string(ERR_get_error(), NULL));\n+\t\t\treturn -1;\n+\t\t}\n+\n \t\tSSL_CTX_set_options(s->ssl_ctx, ssloptions);\n \t\tSSL_CTX_set_info_callback(s->ssl_ctx, ssl_info_callback);\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "origin: http://redmine.lighttpd.net/projects/lighttpd/repository/revisions/2925/diff/\n\nIndex: lighttpd-1.4.31/src/network.c\n===================================================================\n--- lighttpd-1.4.31.orig/src/network.c\t2013-11-14 10:44:56.000000000 +0100\n+++ lighttpd-1.4.31/src/network.c\t2013-11-14 10:52:56.211535856 +0100\n@@ -743,6 +743,14 @@\n \t\t\treturn -1;\n \t\t}\n \n+\t\t/* completely useless identifier; required for client cert verification to work with sessions */\n+\t\tif (0 == SSL_CTX_set_session_id_context(s->ssl_ctx, (const unsigned char*) CONST_STR_LEN(\"lighttpd\"))) {\n+\t\t\tlog_error_write(srv, __FILE__, __LINE__, \"ss:s\", \"SSL:\",\n+\t\t\t\t\"failed to set session context\",\n+\t\t\t\tERR_error_string(ERR_get_error(), NULL));\n+\t\t\treturn -1;\n+\t\t}\n+\n \t\tSSL_CTX_set_options(s->ssl_ctx, ssloptions);\n \t\tSSL_CTX_set_info_callback(s->ssl_ctx, ssl_info_callback);"}], "metadata": {"id": "lighttpd-2374-cve-2013-4508-regression-bug72", "cve_id": "CVE-2013-4560", "package": "lighttpd", "tier": "identical", "has_source_context": true, "context_tokens_est": 99, "context_files": 1, "license": "BSD-3-Clause"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-9556\n\nThe IsPixelGray function in MagickCore/pixel-accessor.h in ImageMagick 7.0.3-8 allows remote attackers to cause a denial of service (out-of-bounds heap read) via a crafted image file.\n\n## Package\nGraphicsMagick\n\n## Files to modify\n- GraphicsMagick-1.3.20.orig/coders/sun.c\n- coders/sun.c\n\n## Upstream Fix\n```diff\nIndex: GraphicsMagick-1.3.20/coders/sun.c\n===================================================================\n--- GraphicsMagick-1.3.20.orig/coders/sun.c\t2013-03-10 00:19:31.000000000 +0100\n+++ GraphicsMagick-1.3.20/coders/sun.c\t2016-10-03 15:26:07.822756467 +0200\n@@ -1,5 +1,5 @@\n /*\n-% Copyright (C) 2003 GraphicsMagick Group\n+% Copyright (C) 2003-214 GraphicsMagick Group\n % Copyright (C) 2002 ImageMagick Studio\n % Copyright 1991-1999 E. I. du Pont de Nemours and Company\n %\n@@ -39,6 +39,7 @@\n #include \"magick/analyze.h\"\n #include \"magick/blob.h\"\n #include \"magick/colormap.h\"\n+#include \"magick/log.h\"\n #include \"magick/magick.h\"\n #include \"magick/monitor.h\"\n #include \"magick/pixel_cache.h\"\n@@ -49,6 +50,63 @@\n */\n static unsigned int\n WriteSUNImage(const ImageInfo *,Image *);\n+\n+/* Raster Types */\n+#define RT_STANDARD 1 /* Standard */\n+#define RT_ENCODED 2 /* Byte encoded */\n+#define RT_FORMAT_RGB 3 /* RGB format */\n+\n+/* Color Map Types */\n+#define RMT_NONE 0 /* No color map */\n+#define RMT_EQUAL_RGB 1 /* RGB color map */\n+#define RMT_RAW 2 /* Raw color map */\n+\n+/*\n+ Note that Sun headers described these fields as type 'int'.\n+*/\n+typedef struct _SUNInfo\n+{\n+ magick_uint32_t\n+ magic, /* Magick (identification) number */\n+ width, /* Width of image in pixels */\n+ height, /* Height of image in pixels */\n+ depth, /* Number of bits per pixel */\n+ length, /* Size of image data in bytes */\n+ type, /* Type of raster file */\n+ maptype, /* Type of color map */\n+ maplength; /* Size of the color map in bytes */\n+} SUNInfo;\n+\n+static void LogSUNInfo(const SUNInfo *sun_info)\n+{\n+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n+ \"SunHeader:\\n\"\n+ \" Magic: 0x%04X\\n\"\n+ \" Width: %u\\n\"\n+ \" Height: %u\\n\"\n+ \" Depth: %u\\n\"\n+ \" Length: %u\\n\"\n+ \" Type: %u (%s)\\n\"\n+ \" MapType: %u (%s)\\n\"\n+ \" MapLength: %u\\n\",\n+ sun_info->magic,\n+ sun_info->width,\n+ sun_info->height,\n+ sun_info->depth,\n+ sun_info->length,\n+ sun_info->type,\n+ (sun_info->type == RT_STANDARD ? \"Standard (RT_STANDARD)\" :\n+ (sun_info->type == RT_ENCODED ? \"RLE encoded (RT_ENCODED)\" :\n+ (sun_info->type == RT_FORMAT_RGB ? \"RGB format (RT_FORMAT_RGB)\" :\n+ \"?\"))),\n+ sun_info->maptype,\n+ (sun_info->maptype == RMT_NONE ? \"No color map (RMT_NONE)\" :\n+ (sun_info->maptype == RMT_EQUAL_RGB ? \"RGB color map (RMT_EQUAL_RGB)\" :\n+ (sun_info->maptype == RMT_RAW ? \"Raw color map (RMT_RAW)\" :\n+ \"?\"))),\n+ sun_info->maplength\n+ );\n+}\n \f\n /*\n %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n@@ -115,23 +173,28 @@ static unsigned int IsSUN(const unsigned\n % o compressed_pixels: The address of a byte (8 bits) array of compressed\n % pixel data.\n %\n-% o length: An integer value that is the total number of bytes of the\n-% source image (as just read by ReadBlob)\n+% o compressed_size: An integer value that is the total number of bytes\n+% of the source image (as just read by ReadBlob)\n %\n % o pixels: The address of a byte (8 bits) array of pixel data created by\n % the uncompression process. The number of bytes in this array\n % must be at least equal to the number columns times the number of rows\n % of the source pixels.\n %\n+% o pixels_size: Decompressed pixels buffer size.\n+%\n %\n */\n-static unsigned int DecodeImage(const unsigned char *compressed_pixels,\n- const size_t length,unsigned char *pixels)\n+static MagickPassFail\n+DecodeImage(const unsigned char *compressed_pixels,\n+ const size_t compressed_size,\n+ unsigned char *pixels,\n+ const size_t pixels_size)\n {\n register const unsigned char\n *p;\n \n- register long\n+ register int\n count;\n \n register unsigned char\n@@ -144,7 +207,8 @@ static unsigned int DecodeImage(const un\n assert(pixels != (unsigned char *) NULL);\n p=compressed_pixels;\n q=pixels;\n- while ((size_t) (p-compressed_pixels) < length)\n+ while (((size_t) (p-compressed_pixels) < compressed_size) &&\n+ ((size_t) (q-pixels) < pixels_size))\n {\n byte=(*p++);\n if (byte != 128U)\n@@ -157,14 +221,14 @@ static unsigned int DecodeImage(const un\n count=(*p++);\n if (count > 0)\n byte=(*p++);\n- while (count >= 0)\n+ while ((count >= 0) && ((size_t) (q-pixels) < pixels_size))\n {\n *q++=byte;\n count--;\n }\n }\n }\n- return(True);\n+ return (((size_t) (q-pixels) == pixels_size) ? MagickTrue : MagickFalse);\n }\n \f\n /*\n@@ -200,26 +264,6 @@ static unsigned int DecodeImage(const un\n */\n static Image *ReadSUNImage(const ImageInfo *image_info,ExceptionInfo *exception)\n {\n-#define RMT_EQUAL_RGB 1\n-#define RMT_NONE 0\n-#define RMT_RAW 2\n-#define RT_STANDARD 1\n-#define RT_ENCODED 2\n-#define RT_FORMAT_RGB 3\n-\n- typedef struct _SUNInfo\n- {\n- magick_uint32_t\n- magic,\n- width,\n- height,\n- depth,\n- length,\n- type,\n- maptype,\n- maplength;\n- } SUNInfo;\n-\n Image\n *image;\n \n@@ -245,7 +289,10 @@ static Image *ReadSUNImage(const ImageIn\n *p;\n \n size_t\n- count;\n+ bytes_per_image,\n+ bytes_per_line,\n+ count,\n+ sun_data_length;\n \n SUNInfo\n sun_info;\n@@ -257,9 +304,6 @@ static Image *ReadSUNImage(const ImageIn\n unsigned int\n status;\n \n- unsigned long\n- bytes_per_line;\n-\n /*\n Open image file.\n */\n@@ -290,10 +334,46 @@ static Image *ReadSUNImage(const ImageIn\n sun_info.type=ReadBlobMSBLong(image);\n sun_info.maptype=ReadBlobMSBLong(image);\n sun_info.maplength=ReadBlobMSBLong(image);\n+ LogSUNInfo(&sun_info);\n+ if (EOFBlob(image))\n+ ThrowReaderException(CorruptImageError,UnexpectedEndOfFile,image);\n+ /*\n+ Verify that header values are in positive numeric range of a\n+ 32-bit 'int' even though we store them in an unsigned value.\n+ */\n+ if ((sun_info.magic | sun_info.width | sun_info.height | sun_info.depth |\n+ sun_info.type | sun_info.maptype | sun_info.maplength) & (1U << 31))\n+ ThrowReaderException(CorruptImageError,ImproperImageHeader,image);\n+ /*\n+ Verify that we support the image sub-type\n+ */\n+ if ((sun_info.type != RT_STANDARD) &&\n+ (sun_info.type != RT_ENCODED) &&\n+ (sun_info.type != RT_FORMAT_RGB))\n+ ThrowReaderException(CoderError,DataEncodingSchemeIsNotSupported,image);\n+ /*\n+ Verify that we support the colormap type\n+ */\n+ if ((sun_info.maptype != RMT_NONE) &&\n+ (sun_info.maptype != RMT_EQUAL_RGB) &&\n+ (sun_info.maptype != RMT_RAW))\n+ ThrowReaderException(CoderError,ColormapTypeNotSupported,image);\n+ /*\n+ Insist that map length is zero if there is no colormap.\n+ */\n+ if ((sun_info.maptype == RMT_NONE) && (sun_info.maplength != 0))\n+ ThrowReaderException(CorruptImageError,ImproperImageHeader,image);\n+ /*\n+ Insist on a supported depth\n+ */\n+ if ((sun_info.depth != 1) &&\n+ (sun_info.depth != 8) &&\n+ (sun_info.depth != 24) &&\n+ (sun_info.depth != 32))\n+ ThrowReaderException(CorruptImageError,ImproperImageHeader,image);\n+\n image->columns= sun_info.width;\n image->rows= sun_info.height;\n- if (sun_info.depth == 0 || sun_info.depth > 32)\n- ThrowReaderException(CorruptImageError,ImproperImageHeader,image);\n image->depth\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "Index: GraphicsMagick-1.3.20/coders/sun.c\n===================================================================\n--- GraphicsMagick-1.3.20.orig/coders/sun.c\t2013-03-10 00:19:31.000000000 +0100\n+++ GraphicsMagick-1.3.20/coders/sun.c\t2016-10-03 15:26:07.822756467 +0200\n@@ -1,5 +1,5 @@\n /*\n-% Copyright (C) 2003 GraphicsMagick Group\n+% Copyright (C) 2003-214 GraphicsMagick Group\n % Copyright (C) 2002 ImageMagick Studio\n % Copyright 1991-1999 E. I. du Pont de Nemours and Company\n %\n@@ -39,6 +39,7 @@\n #include \"magick/analyze.h\"\n #include \"magick/blob.h\"\n #include \"magick/colormap.h\"\n+#include \"magick/log.h\"\n #include \"magick/magick.h\"\n #include \"magick/monitor.h\"\n #include \"magick/pixel_cache.h\"\n@@ -49,6 +50,63 @@\n */\n static unsigned int\n WriteSUNImage(const ImageInfo *,Image *);\n+\n+/* Raster Types */\n+#define RT_STANDARD 1 /* Standard */\n+#define RT_ENCODED 2 /* Byte encoded */\n+#define RT_FORMAT_RGB 3 /* RGB format */\n+\n+/* Color Map Types */\n+#define RMT_NONE 0 /* No color map */\n+#define RMT_EQUAL_RGB 1 /* RGB color map */\n+#define RMT_RAW 2 /* Raw color map */\n+\n+/*\n+ Note that Sun headers described these fields as type 'int'.\n+*/\n+typedef struct _SUNInfo\n+{\n+ magick_uint32_t\n+ magic, /* Magick (identification) number */\n+ width, /* Width of image in pixels */\n+ height, /* Height of image in pixels */\n+ depth, /* Number of bits per pixel */\n+ length, /* Size of image data in bytes */\n+ type, /* Type of raster file */\n+ maptype, /* Type of color map */\n+ maplength; /* Size of the color map in bytes */\n+} SUNInfo;\n+\n+static void LogSUNInfo(const SUNInfo *sun_info)\n+{\n+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n+ \"SunHeader:\\n\"\n+ \" Magic: 0x%04X\\n\"\n+ \" Width: %u\\n\"\n+ \" Height: %u\\n\"\n+ \" Depth: %u\\n\"\n+ \" Length: %u\\n\"\n+ \" Type: %u (%s)\\n\"\n+ \" MapType: %u (%s)\\n\"\n+ \" MapLength: %u\\n\",\n+ sun_info->magic,\n+ sun_info->width,\n+ sun_info->height,\n+ sun_info->depth,\n+ sun_info->length,\n+ sun_info->type,\n+ (sun_info->type == RT_STANDARD ? \"Standard (RT_STANDARD)\" :\n+ (sun_info->type == RT_ENCODED ? \"RLE encoded (RT_ENCODED)\" :\n+ (sun_info->type == RT_FORMAT_RGB ? \"RGB format (RT_FORMAT_RGB)\" :\n+ \"?\"))),\n+ sun_info->maptype,\n+ (sun_info->maptype == RMT_NONE ? \"No color map (RMT_NONE)\" :\n+ (sun_info->maptype == RMT_EQUAL_RGB ? \"RGB color map (RMT_EQUAL_RGB)\" :\n+ (sun_info->maptype == RMT_RAW ? \"Raw color map (RMT_RAW)\" :\n+ \"?\"))),\n+ sun_info->maplength\n+ );\n+}\n \f\n /*\n %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n@@ -115,23 +173,28 @@ static unsigned int IsSUN(const unsigned\n % o compressed_pixels: The address of a byte (8 bits) array of compressed\n % pixel data.\n %\n-% o length: An integer value that is the total number of bytes of the\n-% source image (as just read by ReadBlob)\n+% o compressed_size: An integer value that is the total number of bytes\n+% of the source image (as just read by ReadBlob)\n %\n % o pixels: The address of a byte (8 bits) array of pixel data created by\n % the uncompression process. The number of bytes in this array\n % must be at least equal to the number columns times the number of rows\n % of the source pixels.\n %\n+% o pixels_size: Decompressed pixels buffer size.\n+%\n %\n */\n-static unsigned int DecodeImage(const unsigned char *compressed_pixels,\n- const size_t length,unsigned char *pixels)\n+static MagickPassFail\n+DecodeImage(const unsigned char *compressed_pixels,\n+ const size_t compressed_size,\n+ unsigned char *pixels,\n+ const size_t pixels_size)\n {\n register const unsigned char\n *p;\n \n- register long\n+ register int\n count;\n \n register unsigned char\n@@ -144,7 +207,8 @@ static unsigned int DecodeImage(const un\n assert(pixels != (unsigned char *) NULL);\n p=compressed_pixels;\n q=pixels;\n- while ((size_t) (p-compressed_pixels) < length)\n+ while (((size_t) (p-compressed_pixels) < compressed_size) &&\n+ ((size_t) (q-pixels) < pixels_size))\n {\n byte=(*p++);\n if (byte != 128U)\n@@ -157,14 +221,14 @@ static unsigned int DecodeImage(const un\n count=(*p++);\n if (count > 0)\n byte=(*p++);\n- while (count >= 0)\n+ while ((count >= 0) && ((size_t) (q-pixels) < pixels_size))\n {\n *q++=byte;\n count--;\n }\n }\n }\n- return(True);\n+ return (((size_t) (q-pixels) == pixels_size) ? MagickTrue : MagickFalse);\n }\n \f\n /*\n@@ -200,26 +264,6 @@ static unsigned int DecodeImage(const un\n */\n static Image *ReadSUNImage(const ImageInfo *image_info,ExceptionInfo *exception)\n {\n-#define RMT_EQUAL_RGB 1\n-#define RMT_NONE 0\n-#define RMT_RAW 2\n-#define RT_STANDARD 1\n-#define RT_ENCODED 2\n-#define RT_FORMAT_RGB 3\n-\n- typedef struct _SUNInfo\n- {\n- magick_uint32_t\n- magic,\n- width,\n- height,\n- depth,\n- length,\n- type,\n- maptype,\n- maplength;\n- } SUNInfo;\n-\n Image\n *image;\n \n@@ -245,7 +289,10 @@ static Image *ReadSUNImage(const ImageIn\n *p;\n \n size_t\n- count;\n+ bytes_per_image,\n+ bytes_per_line,\n+ count,\n+ sun_data_length;\n \n SUNInfo\n sun_info;\n@@ -257,9 +304,6 @@ static Image *ReadSUNImage(const ImageIn\n unsigned int\n status;\n \n- unsigned long\n- bytes_per_line;\n-\n /*\n Open image file.\n */\n@@ -290,10 +334,46 @@ static Image *ReadSUNImage(const ImageIn\n sun_info.type=ReadBlobMSBLong(image);\n sun_info.maptype=ReadBlobMSBLong(image);\n sun_info.maplength=ReadBlobMSBLong(image);\n+ LogSUNInfo(&sun_info);\n+ if (EOFBlob(image))\n+ ThrowReaderException(CorruptImageError,UnexpectedEndOfFile,image);\n+ /*\n+ Verify that header values are in positive numeric range of a\n+ 32-bit 'int' even though we store them in an unsigned value.\n+ */\n+ if ((sun_info.magic | sun_info.width | sun_info.height | sun_info.depth |\n+ sun_info.type | sun_info.maptype | sun_info.maplength) & (1U << 31))\n+ ThrowReaderException(CorruptImageError,ImproperImageHeader,image);\n+ /*\n+ Verify that we support the image sub-type\n+ */\n+ if ((sun_info.type != RT_STANDARD) &&\n+ (sun_info.type != RT_ENCODED) &&\n+ (sun_info.type != RT_FORMAT_RGB))\n+ ThrowReaderException(CoderError,DataEncodingSchemeIsNotSupported,image);\n+ /*\n+ Verify that we support the colormap type\n+ */\n+ if ((sun_info.maptype != RMT_NONE) &&\n+ (sun_info.maptype != RMT_EQUAL_RGB) &&\n+ (sun_info.maptype != RMT_RAW))\n+ ThrowReaderException(CoderError,ColormapTypeNotSupported,image);\n+ /*\n+ Insist that map length is zero if there is no colormap.\n+ */\n+ if ((sun_info.maptype == RMT_NONE) && (sun_info.maplength != 0))\n+ ThrowReaderException(CorruptImageError,ImproperImageHeader,image);\n+ /*\n+ Insist on a supported depth\n+ */\n+ if ((sun_info.depth != 1) &&\n+ (sun_info.depth != 8) &&\n+ (sun_info.depth != 24) &&\n+ (sun_info.depth != 32))\n+ ThrowReaderException(CorruptImageError,ImproperImageHeader,image);\n+\n image->columns= sun_info.width;\n image->rows= sun_info.height;\n- if (sun_info.depth == 0 || sun_info.depth > 32)\n- ThrowReaderException(CorruptImageError,ImproperImageHeader,image);\n image->depth=sun_info.depth <= 8 ? 8 : QuantumDepth;\n if (sun_info.depth < 24)\n {\n@@ -304,6 +384,7 @@ static Image *ReadSUNImage(const ImageIn\n if (sun_info.maptype == RMT_EQUAL_RGB)\n image->colors=sun_info.maplength/3;\n }\n+\n switch (sun_info.maptype)\n {\n case RMT_NONE:\n@@ -333,17 +414,38 @@ static Image *ReadSUNImage(const ImageIn\n sun_colormap=MagickAllocateMemory(unsigned char *,image->colors);\n if (sun_colormap == (unsigned char *) NULL)\n ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,\n- image);\n- (void) ReadBlob(image,image->colors,(char *) sun_colormap);\n- for (i=0; i < (long) image->colors; i++)\n- image->colormap[i].red=ScaleCharToQuantum(sun_colormap[i]);\n- (void) ReadBlob(image,image->colors,(char *) sun_colormap);\n- for (i=0; i < (long) image->colors; i++)\n- image->colormap[i].green=ScaleCharToQuantum(sun_colormap[i]);\n- (void) ReadBlob(image,image->colors,(char *) sun_colormap);\n- for (i=0; i < (long) image->colors; i++)\n- image->colormap[i].blue=ScaleCharToQuantum(sun_colormap[i]);\n+ image);\n+ do\n+ {\n+ if (ReadBlob(image,image->colors,(char *) sun_colormap) !=\n+ image->colors)\n+ {\n+ status = MagickFail;\n+ break;\n+ }\n+ for (i=0; i < (long) image->colors; i++)\n+ image->colormap[i].red=ScaleCharToQuantum(sun_colormap[i]);\n+ if (ReadBlob(image,image->colors,(char *) sun_colormap) !=\n+ image->colors)\n+ {\n+ status = MagickFail;\n+ break;\n+ }\n+ for (i=0; i < (long) image->colors; i++)\n+ image->colormap[i].green=ScaleCharToQuantum(sun_colormap[i]);\n+ if (ReadBlob(image,image->colors,(char *) sun_colormap) !=\n+ image->colors)\n+ {\n+ status = MagickFail;\n+ break;\n+ }\n+ for (i=0; i < (long) image->colors; i++)\n+ image->colormap[i].blue=ScaleCharToQuantum(sun_colormap[i]);\n+ break;\n+ } while (1);\n MagickFreeMemory(sun_colormap);\n+ if (MagickFail == status)\n+ ThrowReaderException(CorruptImageError,UnexpectedEndOfFile,image);\n break;\n }\n case RMT_RAW:\n@@ -358,8 +460,12 @@ static Image *ReadSUNImage(const ImageIn\n if (sun_colormap == (unsigned char *) NULL)\n ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,\n image);\n- (void) ReadBlob(image,sun_info.maplength,(char *) sun_colormap);\n+ if (ReadBlob(image,sun_info.maplength,(char *) sun_colormap) !=\n+ sun_info.maplength)\n+ status = MagickFail;\n MagickFreeMemory(sun_colormap);\n+ if (MagickFail == status)\n+ ThrowReaderException(CorruptImageError,UnexpectedEndOfFile,image);\n break;\n }\n default:\n@@ -371,41 +477,75 @@ static Image *ReadSUNImage(const ImageIn\n image->depth=8;\n if (sun_info.depth < 8)\n image->depth=sun_info.depth;\n+\n+ /*\n+ Compute bytes per line and bytes per image for an unencoded\n+ image.\n+\n+ \"The width of a scan line is always 16-bits, padded when necessary.\"\n+ */\n+ bytes_per_line=MagickArraySize(sun_info.width,sun_info.depth)/8;\n+ if ((bytes_per_line != 0) && (sun_info.depth == 1))\n+ bytes_per_line += sun_info.width % 8 ? 1 : 0;\n+ if (bytes_per_line != 0)\n+ bytes_per_line=RoundUpToAlignment(bytes_per_line,2);\n+\n+ bytes_per_image=MagickArraySize(sun_info.height,bytes_per_line);\n+\n+ if (bytes_per_line == 0)\n+ ThrowReaderException(CorruptImageError,ImproperImageHeader,image);\n+\n+ if (bytes_per_image == 0)\n+ ThrowReaderException(CorruptImageError,ImproperImageHeader,image);\n+\n+ if ((sun_info.type == RT_STANDARD) || (sun_info.type == RT_FORMAT_RGB))\n+ if (bytes_per_image > sun_info.length)\n+ ThrowReaderException(CorruptImageError,ImproperImageHeader,image);\n+\n if (image_info->ping)\n {\n CloseBlob(image);\n return(image);\n }\n- sun_data=MagickAllocateMemory(unsigned char *,(size_t) sun_info.length);\n+ if (sun_info.type == RT_ENCODED)\n+ sun_data_length=(size_t) sun_info.length;\n+ else\n+ sun_data_length=bytes_per_image;\n+ sun_data=MagickAllocateMemory(unsigned char *,sun_data_length);\n if (sun_data == (unsigned char *) NULL)\n ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,image);\n- count=ReadBlob(image,sun_info.length,(char *) sun_data);\n- if ((count == 0) && (sun_info.type != RT_ENCODED))\n- ThrowReaderException(CorruptImageError,UnableToReadImageData,image);\n+ if ((count=ReadBlob(image,sun_data_length,(char *) sun_data))\n+ != sun_data_length)\n+ {\n+ MagickFreeMemory(sun_data);\n+ ThrowReaderException(CorruptImageError,UnableToReadImageData,image);\n+ }\n sun_pixels=sun_data;\n- bytes_per_line=0;\n if (sun_info.type == RT_ENCODED)\n {\n- unsigned long\n- height;\n-\n /*\n- Read run-length encoded raster pixels.\n+ Read run-length encoded raster pixels (padded to 16-bit boundary).\n */\n- height=sun_info.height;\n- bytes_per_line=2*(sun_info.width*sun_info.depth+15)/16;\n- sun_pixels=MagickAllocateMemory(unsigned char *,bytes_per_line*height);\n+ sun_pixels=MagickAllocateMemory(unsigned char *,bytes_per_image);\n if (sun_pixels == (unsigned char *) NULL)\n ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,\n image);\n- (void) DecodeImage(sun_data,sun_info.length,sun_pixels);\n+ status &= DecodeImage(sun_data,sun_data_length,sun_pixels,bytes_per_image);\n MagickFreeMemory(sun_data);\n+ if (status != MagickPass)\n+ {\n+ MagickFreeMemory(sun_pixels);\n+ ThrowReaderException(CorruptImageError,UnableToRunlengthDecodeImage,image);\n+ }\n }\n /*\n Convert SUN raster image to pixel packets.\n */\n p=sun_pixels;\n if (sun_info.depth == 1)\n+ /*\n+ Bilevel\n+ */\n for (y=0; y < (long) image->rows; y++)\n {\n q=SetImagePixels(image,0,y,image->columns,1);\n@@ -438,10 +578,9 @@ static Image *ReadSUNImage(const ImageIn\n else\n if (image->storage_class == PseudoClass)\n {\n-\t unsigned long n = image->rows*(image->columns+image->columns%2);\n-\t if ((sun_info.type == RT_ENCODED && n > bytes_per_line*image->rows) ||\n-\t (sun_info.type != RT_ENCODED && n > sun_info.length))\n-\t ThrowReaderException(CorruptImageError,ImproperImageHeader,image);\n+ /*\n+ Colormapped\n+ */\n for (y=0; y < (long) image->rows; y++)\n {\n q=SetImagePixels(image,0,y,image->columns,1);\n@@ -464,11 +603,9 @@ static Image *ReadSUNImage(const ImageIn\n \t}\n else\n {\n-\t unsigned long n = image->columns*((image->matte) ? 4 : 3);\n-\t n = image->rows*(n+image->columns%2);\n-\t if ((sun_info.type == RT_ENCODED && n > bytes_per_line*image->rows) ||\n-\t (sun_info.type != RT_ENCODED && n > sun_info.length))\n-\t ThrowReaderException(CorruptImageError,ImproperImageHeader,image);\n+ /*\n+ (A)BGR or (A)RGB\n+ */\n for (y=0; y < (long) image->rows; y++)\n {\n q=SetImagePixels(image,0,y,image->columns,1);\n@@ -650,25 +787,6 @@ ModuleExport void UnregisterSUNImage(voi\n */\n static unsigned int WriteSUNImage(const ImageInfo *image_info,Image *image)\n {\n-#define RMT_EQUAL_RGB 1\n-#define RMT_NONE 0\n-#define RMT_RAW 2\n-#define RT_STANDARD 1\n-#define RT_FORMAT_RGB 3\n-\n- typedef struct _SUNInfo\n- {\n- magick_uint32_t\n- magic,\n- width,\n- height,\n- depth,\n- length,\n- type,\n- maptype,\n- maplength;\n- } SUNInfo;\n-\n long\n y;\n \n@@ -769,6 +887,7 @@ static unsigned int WriteSUNImage(const\n /*\n Write SUN header.\n */\n+ LogSUNInfo(&sun_info);\n (void) WriteBlobMSBLong(image,sun_info.magic);\n (void) WriteBlobMSBLong(image,sun_info.width);\n (void) WriteBlobMSBLong(image,sun_info.height);"}], "metadata": {"id": "GraphicsMagick-5955-GraphicsMagick-CVE-2014-9818,9", "cve_id": "CVE-2016-9556", "package": "GraphicsMagick", "tier": "adapted", "has_source_context": false, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-6250\n\nInteger overflow in the ISO9660 writer in libarchive before 3.2.1 allows remote attackers to cause a denial of service (application crash) or execute arbitrary code via vectors related to verifying filename lengths when writing an ISO9660 archive, which trigger a buffer overflow.\n\n## Package\nlibarchive\n\n## Files to modify\n- libarchive-3.1.2.orig/libarchive/archive_read_support_format_mtree.c\n- libarchive/archive_read_support_format_mtree.c\n- libarchive/test/test_read_format_mtree_crash747.c\n\n## Target Source Code\n\n### Makefile.am\n\n#### region() [lines 375-461]\n```c\n\tlibarchive/test/test_read_format_ar.c\t\t\t\\\n\tlibarchive/test/test_read_format_cab.c\t\t\t\\\n\tlibarchive/test/test_read_format_cab_filename.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_afio.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin_Z.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin_be.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin_bz2.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin_gz.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin_lzip.c\t\\\n\tlibarchive/test/test_read_format_cpio_bin_lzma.c\t\\\n\tlibarchive/test/test_read_format_cpio_bin_xz.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_filename.c\t\\\n\tlibarchive/test/test_read_format_cpio_odc.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_svr4_bzip2_rpm.c\t\\\n\tlibarchive/test/test_read_format_cpio_svr4_gzip.c\t\\\n\tlibarchive/test/test_read_format_cpio_svr4_gzip_rpm.c\t\\\n\tlibarchive/test/test_read_format_cpio_svr4c_Z.c\t\t\\\n\tlibarchive/test/test_read_format_empty.c\t\t\\\n\tlibarchive/test/test_read_format_gtar_filename.c\t\\\n\tlibarchive/test/test_read_format_gtar_gz.c\t\t\\\n\tlibarchive/test/test_read_format_gtar_lzma.c\t\t\\\n\tlibarchive/test/test_read_format_gtar_sparse.c\t\t\\\n\tlibarchive/test/test_read_format_iso_Z.c\t\t\\\n\tlibarchive/test/test_read_format_iso_multi_extent.c\t\\\n\tlibarchive/test/test_read_format_iso_xorriso.c\t\t\\\n\tlibarchive/test/test_read_format_isojoliet_bz2.c\t\\\n\tlibarchive/test/test_read_format_isojoliet_long.c\t\\\n\tlibarchive/test/test_read_format_isojoliet_rr.c\t\t\\\n\tlibarchive/test/test_read_format_isojoliet_versioned.c\t\\\n\tlibarchive/test/test_read_format_isorr_bz2.c\t\t\\\n\tlibarchive/test/test_read_format_isorr_ce.c\t\t\\\n\tlibarchive/test/test_read_format_isorr_new_bz2.c\t\\\n\tlibarchive/test/test_read_format_isorr_rr_moved.c\t\\\n\tlibarchive/test/test_read_format_isozisofs_bz2.c\t\\\n\tlibarchive/test/test_read_format_lha.c\t\t\t\\\n\tlibarchive/test/test_read_format_lha_filename.c\t\t\\\n\tlibarchive/test/test_read_format_mtree.c\t\t\\\n\tlibarchive/test/test_read_format_pax_bz2.c\t\t\\\n\tlibarchive/test/test_read_format_rar.c\t\t\t\\\n\tlibarchive/test/test_read_format_raw.c\t\t\t\\\n\tlibarchive/test/test_read_format_tar.c\t\t\t\\\n\tlibarchive/test/test_read_format_tar_empty_filename.c\t\\\n\tlibarchive/test/test_read_format_tar_filename.c\t\t\\\n\tlibarchive/test/test_read_format_tbz.c\t\t\t\\\n\tlibarchive/test/test_read_format_tgz.c\t\t\t\\\n\tlibarchive/test/test_read_format_tlz.c\t\t\t\\\n\tlibarchive/test/test_read_format_txz.c\t\t\t\\\n\tlibarchive/test/test_read_format_tz.c\t\t\t\\\n\tlibarchive/test/test_read_format_ustar_filename.c\t\\\n\tlibarchive/test/test_read_form\n/* ... truncated ... */\n```\n\n### libarchive/archive_read_support_format_mtree.c\n\n#### get_line_size() [lines 240-276]\n```c\n}\n\nstatic ssize_t\nget_line_size(const char *b, ssize_t avail, ssize_t *nlsize)\n{\n\tssize_t len;\n\n\tlen = 0;\n\twhile (len < avail) {\n\t\tswitch (*b) {\n\t\tcase '\\0':/* Non-ascii character or control character. */\n\t\t\tif (nlsize != NULL)\n\t\t\t\t*nlsize = 0;\n\t\t\treturn (-1);\n\t\tcase '\\r':\n\t\t\tif (avail-len > 1 && b[1] == '\\n') {\n\t\t\t\tif (nlsize != NULL)\n\t\t\t\t\t*nlsize = 2;\n\t\t\t\treturn (len+2);\n\t\t\t}\n\t\t\t/* FALL THROUGH */\n\t\tcase '\\n':\n\t\t\tif (nlsize != NULL)\n\t\t\t\t*nlsize = 1;\n\t\t\treturn (len+1);\n\t\tdefault:\n\t\t\tb++;\n\t\t\tlen++;\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (nlsize != NULL)\n\t\t*nlsize = 0;\n\treturn (avail);\n}\n\nstatic ssize_t\n```\n\n#### next_line() [lines 274-321]\n```c\n}\n\nstatic ssize_t\nnext_line(struct archive_read *a,\n const char **b, ssize_t *avail, ssize_t *ravail, ssize_t *nl)\n{\n\tssize_t len;\n\tint quit;\n\t\n\tquit = 0;\n\tif (*avail == 0) {\n\t\t*nl = 0;\n\t\tlen = 0;\n\t} else\n\t\tlen = get_line_size(*b, *avail, nl);\n\t/*\n\t * Read bytes more while it does not reach the end of line.\n\t */\n\twhile (*nl == 0 && len == *avail && !quit) {\n\t\tssize_t diff = *ravail - *avail;\n\t\tsize_t nbytes_req = (*ravail+1023) & ~1023U;\n\t\tssize_t tested;\n\n\t\t/* Increase reading bytes if it is not enough to at least\n\t\t * new two lines. */\n\t\tif (nbytes_req < (size_t)*ravail + 160)\n\t\t\tnbytes_req <<= 1;\n\n\t\t*b = __archive_read_ahead(a, nbytes_req, avail);\n\t\tif (*b == NULL) {\n\t\t\tif (*ravail >= *avail)\n\t\t\t\treturn (0);\n\t\t\t/* Reading bytes reaches the end of file. */\n\t\t\t*b = __archive_read_ahead(a, *avail, avail);\n\t\t\tquit = 1;\n\t\t}\n\t\t*ravail = *avail;\n\t\t*b += diff;\n\t\t*avail -= diff;\n\t\ttested = len;/* Skip some bytes we already determinated. */\n\t\tlen = get_line_size(*b, *avail, nl);\n\t\tif (len >= 0)\n\t\t\tlen += tested;\n\t}\n\treturn (len);\n}\n\n/*\n```\n\n### libarchive/test/CMakeLists.txt\n\n#### IF() [lines 87-173]\n```c\n test_read_filter_program_signature.c\n test_read_filter_uudecode.c\n test_read_format_7zip.c\n test_read_format_ar.c\n test_read_format_cab.c\n test_read_format_cab_filename.c\n test_read_format_cpio_afio.c\n test_read_format_cpio_bin.c\n test_read_format_cpio_bin_Z.c\n test_read_format_cpio_bin_be.c\n test_read_format_cpio_bin_bz2.c\n test_read_format_cpio_bin_gz.c\n test_read_format_cpio_bin_lzip.c\n test_read_format_cpio_bin_lzma.c\n test_read_format_cpio_bin_xz.c\n test_read_format_cpio_filename.c\n test_read_format_cpio_odc.c\n test_read_format_cpio_svr4_bzip2_rpm.c\n test_read_format_cpio_svr4_gzip.c\n test_read_format_cpio_svr4_gzip_rpm.c\n test_read_format_cpio_svr4c_Z.c\n test_read_format_empty.c\n test_read_format_gtar_filename.c\n test_read_format_gtar_gz.c\n test_read_format_gtar_lzma.c\n test_read_format_gtar_sparse.c\n test_read_format_iso_Z.c\n test_read_format_iso_multi_extent.c\n test_read_format_iso_xorriso.c\n test_read_format_isojoliet_bz2.c\n test_read_format_isojoliet_long.c\n test_read_format_isojoliet_rr.c\n test_read_format_isojoliet_versioned.c\n test_read_format_isorr_bz2.c\n test_read_format_isorr_ce.c\n test_read_format_isorr_new_bz2.c\n test_read_format_isorr_rr_moved.c\n test_read_format_isozisofs_bz2.c\n test_read_format_lha.c\n test_read_format_lha_filename.c\n test_read_format_mtree.c\n test_read_format_pax_bz2.c\n test_read_format_rar.c\n test_read_format_raw.c\n test_read_format_tar.c\n test_read_format_tar_empty_filename.c\n test_read_format_tar_filename.c\n test_read_format_tbz.c\n test_read_format_tgz.c\n test_read_format_tlz.c\n test_read_format_txz.c\n test_read_format_tz.c\n test_read_format_ustar_filename.c\n test_read_format_xar.c\n test_read_format_zip.c\n test_read_format_zip_comment_stored.c\n test_read_format_zip_filename.c\n test_read_format_zip_mac_metadata.c\n test_read_format_zip_sfx.c\n test_read_large.c\n test_read_pax_truncated.c\n test_read_position.c\n test_read_set_format.c\n test_read_truncated.c\n test_read_truncated_filter.c\n test_sparse_basic.c\n test_tar_filenames.c\n test_tar_large.c\n test_ustar_filenames.c\n test_ustar_filename_encoding.c\n test_write_disk.c\n test_write_disk_appledouble.c\n test_write_disk_failures.c\n test_write_disk_hardlink.c\n test_write_disk_hfs_compression.c\n test_write_disk_lookup.c\n test_write_disk_mac_metadata.c\n test_wri\n/* ... truncated ... */\n```\n\n\n### Type definitions\n\n```c\n/* from archive_private.h */\nstruct archive {\n\t/*\n\t * The magic/state values are used to sanity-check the\n\t * client's usage. If an API function is called at a\n\t * ridiculous time, or the client passes us an invalid\n\t * pointer, these values allow me to catch that.\n\t */\n\tunsigned int\tmagic;\n\tunsigned int\tstate;\n\n\t/*\n\t * Some public API functions depend on the \"real\" type of the\n\t * archive object.\n\t */\n\tstruct archive_vtable *vtable;\n\n\tint\t\t archive_format;\n\tconst char\t *archive_format_name;\n\n\tint\t compression_code;\t/* Currently active compression. */\n\tconst char *compression_name;\n\n\t/* Number of file entries processed. */\n\tint\t\t file_count;\n\n\tint\t\t archive_error_number;\n\tconst char\t *error;\n\tstruct archive_string\terror_string;\n\n\tchar *current_code;\n\tunsigned current_codepage; /* Current ACP(ANSI CodePage). */\n\tunsigned current_oemcp; /* Current OEMCP(OEM CodePage). */\n\tstruct archive_string_conv *sconv;\n};\n```\n\n\n## Upstream Fix\n```diff\ncommit eec077f52bfa2d3f7103b4b74d52572ba8a15aca\nAuthor: Tim Kientzle \nDate: Sun Sep 18 17:27:47 2016 -0700\n\n Issue 747 (and others?): Avoid OOB read when parsing multiple long lines\n \n The mtree bidder needs to look several lines ahead\n in the input. It does this by extending the read-ahead\n and parsing subsequent lines from the same growing buffer.\n A bookkeeping error when extending the read-ahead would\n sometimes lead it to significantly over-count the\n size of the line being read.\n\nIndex: libarchive-3.1.2/Makefile.am\n===================================================================\n--- libarchive-3.1.2.orig/Makefile.am\n+++ libarchive-3.1.2/Makefile.am\n@@ -414,6 +414,7 @@ libarchive_test_SOURCES=\t\t\t\t\t\\\n \tlibarchive/test/test_read_format_lha.c\t\t\t\\\n \tlibarchive/test/test_read_format_lha_filename.c\t\t\\\n \tlibarchive/test/test_read_format_mtree.c\t\t\\\n+\tlibarchive/test/test_read_format_mtree_crash747.c\t\\\n \tlibarchive/test/test_read_format_pax_bz2.c\t\t\\\n \tlibarchive/test/test_read_format_rar.c\t\t\t\\\n \tlibarchive/test/test_read_format_rar_invalid1.c\t\t\\\nIndex: libarchive-3.1.2/libarchive/archive_read_support_format_mtree.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_read_support_format_mtree.c\n+++ libarchive-3.1.2/libarchive/archive_read_support_format_mtree.c\n@@ -277,6 +277,15 @@ get_line_size(const char *b, ssize_t ava\n \treturn (avail);\n }\n \n+/*\n+ * <---------------- ravail --------------------->\n+ * <-- diff ------> <--- avail ----------------->\n+ * <---- len ----------->\n+ * | Previous lines | line being parsed nl extra |\n+ * ^\n+ * b\n+ *\n+ */\n static ssize_t\n next_line(struct archive_read *a,\n const char **b, ssize_t *avail, ssize_t *ravail, ssize_t *nl)\n@@ -315,7 +324,7 @@ next_line(struct archive_read *a,\n \t\t*b += diff;\n \t\t*avail -= diff;\n \t\ttested = len;/* Skip some bytes we already determinated. */\n-\t\tlen = get_line_size(*b, *avail, nl);\n+\t\tlen = get_line_size(*b + len, *avail - len, nl);\n \t\tif (len >= 0)\n \t\t\tlen += tested;\n \t}\nIndex: libarchive-3.1.2/libarchive/test/CMakeLists.txt\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/test/CMakeLists.txt\n+++ libarchive-3.1.2/libarchive/test/CMakeLists.txt\n@@ -126,6 +126,7 @@ IF(ENABLE_TEST)\n test_read_format_lha.c\n test_read_format_lha_filename.c\n test_read_format_mtree.c\n+ test_read_format_mtree_crash747.c\n test_read_format_pax_bz2.c\n test_read_format_rar.c\n test_read_format_raw.c\nIndex: libarchive-3.1.2/libarchive/test/test_read_format_mtree_crash747.c\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_format_mtree_crash747.c\n@@ -0,0 +1,44 @@\n+/*-\n+ * Copyright (c) 2003-2016 Tim Kientzle\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ * 1. Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in the\n+ * documentation and/or other materials provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR\n+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,\n+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+#include \"test.h\"\n+\n+\n+/*\n+ * Reproduce the crash reported in Github Issue #747.\n+ */\n+DEFINE_TEST(test_read_format_mtree_crash747)\n+{\n+\tconst char *reffile = \"test_read_format_mtree_crash747.mtree.bz2\";\n+\tstruct archive *a;\n+\n+\textract_reference_file(reffile);\n+\n+\tassert((a = archive_read_new()) != NULL);\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_bzip2(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_mtree(a));\n+\tassertEqualIntA(a, ARCHIVE_FATAL, archive_read_open_filename(a, reffile, 10240));\n+\tassertEqualInt(ARCHIVE_OK, archive_read_free(a));\n+}\n+\nIndex: libarchive-3.1.2/libarchive/test/test_read_format_mtree_crash747.mtree.bz2.uu\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_format_mtree_crash747.mtree.bz2.uu\n@@ -0,0 +1,6 @@\n+begin 600 test_read_format_mtree_crash747.mtree.bz2\n+M0EIH.3%!62936:OH@(@``'/[@,`0`@!``'^\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "commit eec077f52bfa2d3f7103b4b74d52572ba8a15aca\nAuthor: Tim Kientzle \nDate: Sun Sep 18 17:27:47 2016 -0700\n\n Issue 747 (and others?): Avoid OOB read when parsing multiple long lines\n \n The mtree bidder needs to look several lines ahead\n in the input. It does this by extending the read-ahead\n and parsing subsequent lines from the same growing buffer.\n A bookkeeping error when extending the read-ahead would\n sometimes lead it to significantly over-count the\n size of the line being read.\n\nIndex: libarchive-3.1.2/Makefile.am\n===================================================================\n--- libarchive-3.1.2.orig/Makefile.am\n+++ libarchive-3.1.2/Makefile.am\n@@ -414,6 +414,7 @@ libarchive_test_SOURCES=\t\t\t\t\t\\\n \tlibarchive/test/test_read_format_lha.c\t\t\t\\\n \tlibarchive/test/test_read_format_lha_filename.c\t\t\\\n \tlibarchive/test/test_read_format_mtree.c\t\t\\\n+\tlibarchive/test/test_read_format_mtree_crash747.c\t\\\n \tlibarchive/test/test_read_format_pax_bz2.c\t\t\\\n \tlibarchive/test/test_read_format_rar.c\t\t\t\\\n \tlibarchive/test/test_read_format_rar_invalid1.c\t\t\\\nIndex: libarchive-3.1.2/libarchive/archive_read_support_format_mtree.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_read_support_format_mtree.c\n+++ libarchive-3.1.2/libarchive/archive_read_support_format_mtree.c\n@@ -277,6 +277,15 @@ get_line_size(const char *b, ssize_t ava\n \treturn (avail);\n }\n \n+/*\n+ * <---------------- ravail --------------------->\n+ * <-- diff ------> <--- avail ----------------->\n+ * <---- len ----------->\n+ * | Previous lines | line being parsed nl extra |\n+ * ^\n+ * b\n+ *\n+ */\n static ssize_t\n next_line(struct archive_read *a,\n const char **b, ssize_t *avail, ssize_t *ravail, ssize_t *nl)\n@@ -315,7 +324,7 @@ next_line(struct archive_read *a,\n \t\t*b += diff;\n \t\t*avail -= diff;\n \t\ttested = len;/* Skip some bytes we already determinated. */\n-\t\tlen = get_line_size(*b, *avail, nl);\n+\t\tlen = get_line_size(*b + len, *avail - len, nl);\n \t\tif (len >= 0)\n \t\t\tlen += tested;\n \t}\nIndex: libarchive-3.1.2/libarchive/test/CMakeLists.txt\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/test/CMakeLists.txt\n+++ libarchive-3.1.2/libarchive/test/CMakeLists.txt\n@@ -126,6 +126,7 @@ IF(ENABLE_TEST)\n test_read_format_lha.c\n test_read_format_lha_filename.c\n test_read_format_mtree.c\n+ test_read_format_mtree_crash747.c\n test_read_format_pax_bz2.c\n test_read_format_rar.c\n test_read_format_raw.c\nIndex: libarchive-3.1.2/libarchive/test/test_read_format_mtree_crash747.c\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_format_mtree_crash747.c\n@@ -0,0 +1,44 @@\n+/*-\n+ * Copyright (c) 2003-2016 Tim Kientzle\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ * 1. Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in the\n+ * documentation and/or other materials provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR\n+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,\n+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+#include \"test.h\"\n+\n+\n+/*\n+ * Reproduce the crash reported in Github Issue #747.\n+ */\n+DEFINE_TEST(test_read_format_mtree_crash747)\n+{\n+\tconst char *reffile = \"test_read_format_mtree_crash747.mtree.bz2\";\n+\tstruct archive *a;\n+\n+\textract_reference_file(reffile);\n+\n+\tassert((a = archive_read_new()) != NULL);\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_bzip2(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_mtree(a));\n+\tassertEqualIntA(a, ARCHIVE_FATAL, archive_read_open_filename(a, reffile, 10240));\n+\tassertEqualInt(ARCHIVE_OK, archive_read_free(a));\n+}\n+\nIndex: libarchive-3.1.2/libarchive/test/test_read_format_mtree_crash747.mtree.bz2.uu\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_format_mtree_crash747.mtree.bz2.uu\n@@ -0,0 +1,6 @@\n+begin 600 test_read_format_mtree_crash747.mtree.bz2\n+M0EIH.3%!62936:OH@(@``'/[@,`0`@!``'^```)A@9\\`$`@@`'4)049!IIH!\n+MM021-0,F@&@6````9%>$(K!GIC*XFR0`$```J0+:$XP```!D-F)H[#SE9+2'\n+4+E\"L=ASXUI%R(I\"HD'ZA(5?1`Q``\n+`\n+end"}], "metadata": {"id": "libarchive-5942-CVE-2016-8688.patch", "cve_id": "CVE-2016-6250", "package": "libarchive", "tier": "adapted", "has_source_context": true, "context_tokens_est": 1986, "context_files": 3, "license": "BSD-2-Clause"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2013-4560\n\nUse-after-free vulnerability in lighttpd before 1.4.33 allows remote attackers to cause a denial of service (segmentation fault and crash) via unspecified vectors that trigger FAMMonitorDirectory failures.\n\n## Package\nlighttpd\n\n## Files to modify\n- src/request.c\n\n## Upstream Fix\n```diff\nFrom 162bb2fe51552c43192799d4514c4d8b0de3265b Mon Sep 17 00:00:00 2001\nFrom: =?UTF-8?q?Stefan=20B=C3=BChler?= \nDate: Sat, 17 Nov 2012 11:54:18 +0100\nSubject: [PATCH] Fix DoS in header value split (reported by Jesse Sipprell)\n\n---\n src/request.c | 75 +++++++++++++++++++++++++++++----------------------------\n 1 file changed, 38 insertions(+), 37 deletions(-)\n\ndiff --git a/src/request.c b/src/request.c\nindex de1a782..0d749e6 100644\n--- a/src/request.c\n+++ b/src/request.c\n@@ -209,9 +209,11 @@ static int request_check_hostname(server *srv, connection *con, buffer *host) {\n #endif\n \n static int http_request_split_value(array *vals, buffer *b) {\n-\tchar *s;\n \tsize_t i;\n \tint state = 0;\n+\n+\tconst char *current;\n+\tconst char *token_start = NULL, *token_end = NULL;\n \t/*\n \t * parse\n \t *\n@@ -222,53 +224,52 @@ static int http_request_split_value(array *vals, buffer *b) {\n \n \tif (b->used == 0) return 0;\n \n-\ts = b->ptr;\n-\n-\tfor (i =0; i < b->used - 1; ) {\n-\t\tchar *start = NULL, *end = NULL;\n+\tcurrent = b->ptr;\n+\tfor (i = 0; i < b->used; ++i, ++current) {\n \t\tdata_string *ds;\n \n \t\tswitch (state) {\n-\t\tcase 0: /* ws */\n-\n-\t\t\t/* skip ws */\n-\t\t\tfor (; (*s == ' ' || *s == '\\t') && i < b->used - 1; i++, s++);\n-\n-\n-\t\t\tstate = 1;\n-\t\t\tbreak;\n-\t\tcase 1: /* value */\n-\t\t\tstart = s;\n-\n-\t\t\tfor (; *s != ',' && i < b->used - 1; i++, s++);\n-\t\t\tif (start == s) break; /* empty fields are skipped */\n-\t\t\tend = s - 1;\n-\n-\t\t\tfor (; end > start && (*end == ' ' || *end == '\\t'); end--);\n-\t\t\tif (start == end) break; /* empty fields are skipped */\n-\n-\t\t\tif (NULL == (ds = (data_string *)array_get_unused_element(vals, TYPE_STRING))) {\n-\t\t\t\tds = data_string_init();\n+\t\tcase 0: /* find start of a token */\n+\t\t\tswitch (*current) {\n+\t\t\tcase ' ':\n+\t\t\tcase '\\t': /* skip white space */\n+\t\t\tcase ',': /* skip empty token */\n+\t\t\t\tbreak;\n+\t\t\tcase '\\0': /* end of string */\n+\t\t\t\treturn 0;\n+\t\t\tdefault:\n+\t\t\t\t/* found real data, switch to state 1 to find the end of the token */\n+\t\t\t\ttoken_start = token_end = current;\n+\t\t\t\tstate = 1;\n+\t\t\t\tbreak;\n \t\t\t}\n+\t\t\tbreak;\n+\t\tcase 1: /* find end of token and last non white space character */\n+\t\t\tswitch (*current) {\n+\t\t\tcase ' ':\n+\t\t\tcase '\\t':\n+\t\t\t\t/* space - don't update token_end */\n+\t\t\t\tbreak;\n+\t\t\tcase ',':\n+\t\t\tcase '\\0': /* end of string also marks the end of a token */\n+\t\t\t\tif (NULL == (ds = (data_string *)array_get_unused_element(vals, TYPE_STRING))) {\n+\t\t\t\t\tds = data_string_init();\n+\t\t\t\t}\n \n-\t\t\tbuffer_copy_string_len(ds->value, start, end-start+1);\n-\t\t\tarray_insert_unique(vals, (data_unset *)ds);\n+\t\t\t\tbuffer_copy_string_len(ds->value, token_start, token_end-token_start+1);\n+\t\t\t\tarray_insert_unique(vals, (data_unset *)ds);\n \n-\t\t\tif (*s == ',') {\n \t\t\t\tstate = 0;\n-\t\t\t\ti++;\n-\t\t\t\ts++;\n-\t\t\t} else {\n-\t\t\t\t/* end of string */\n-\n-\t\t\t\tstate = 2;\n+\t\t\t\tbreak;\n+\t\t\tdefault:\n+\t\t\t\t/* no white space, update token_end to include current character */\n+\t\t\t\ttoken_end = current;\n+\t\t\t\tbreak;\n \t\t\t}\n \t\t\tbreak;\n-\t\tdefault:\n-\t\t\ti++;\n-\t\t\tbreak;\n \t\t}\n \t}\n+\n \treturn 0;\n }\n \n-- \n1.7.10.4\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From 162bb2fe51552c43192799d4514c4d8b0de3265b Mon Sep 17 00:00:00 2001\nFrom: =?UTF-8?q?Stefan=20B=C3=BChler?= \nDate: Sat, 17 Nov 2012 11:54:18 +0100\nSubject: [PATCH] Fix DoS in header value split (reported by Jesse Sipprell)\n\n---\n src/request.c | 75 +++++++++++++++++++++++++++++----------------------------\n 1 file changed, 38 insertions(+), 37 deletions(-)\n\ndiff --git a/src/request.c b/src/request.c\nindex de1a782..0d749e6 100644\n--- a/src/request.c\n+++ b/src/request.c\n@@ -209,9 +209,11 @@ static int request_check_hostname(server *srv, connection *con, buffer *host) {\n #endif\n \n static int http_request_split_value(array *vals, buffer *b) {\n-\tchar *s;\n \tsize_t i;\n \tint state = 0;\n+\n+\tconst char *current;\n+\tconst char *token_start = NULL, *token_end = NULL;\n \t/*\n \t * parse\n \t *\n@@ -222,53 +224,52 @@ static int http_request_split_value(array *vals, buffer *b) {\n \n \tif (b->used == 0) return 0;\n \n-\ts = b->ptr;\n-\n-\tfor (i =0; i < b->used - 1; ) {\n-\t\tchar *start = NULL, *end = NULL;\n+\tcurrent = b->ptr;\n+\tfor (i = 0; i < b->used; ++i, ++current) {\n \t\tdata_string *ds;\n \n \t\tswitch (state) {\n-\t\tcase 0: /* ws */\n-\n-\t\t\t/* skip ws */\n-\t\t\tfor (; (*s == ' ' || *s == '\\t') && i < b->used - 1; i++, s++);\n-\n-\n-\t\t\tstate = 1;\n-\t\t\tbreak;\n-\t\tcase 1: /* value */\n-\t\t\tstart = s;\n-\n-\t\t\tfor (; *s != ',' && i < b->used - 1; i++, s++);\n-\t\t\tif (start == s) break; /* empty fields are skipped */\n-\t\t\tend = s - 1;\n-\n-\t\t\tfor (; end > start && (*end == ' ' || *end == '\\t'); end--);\n-\t\t\tif (start == end) break; /* empty fields are skipped */\n-\n-\t\t\tif (NULL == (ds = (data_string *)array_get_unused_element(vals, TYPE_STRING))) {\n-\t\t\t\tds = data_string_init();\n+\t\tcase 0: /* find start of a token */\n+\t\t\tswitch (*current) {\n+\t\t\tcase ' ':\n+\t\t\tcase '\\t': /* skip white space */\n+\t\t\tcase ',': /* skip empty token */\n+\t\t\t\tbreak;\n+\t\t\tcase '\\0': /* end of string */\n+\t\t\t\treturn 0;\n+\t\t\tdefault:\n+\t\t\t\t/* found real data, switch to state 1 to find the end of the token */\n+\t\t\t\ttoken_start = token_end = current;\n+\t\t\t\tstate = 1;\n+\t\t\t\tbreak;\n \t\t\t}\n+\t\t\tbreak;\n+\t\tcase 1: /* find end of token and last non white space character */\n+\t\t\tswitch (*current) {\n+\t\t\tcase ' ':\n+\t\t\tcase '\\t':\n+\t\t\t\t/* space - don't update token_end */\n+\t\t\t\tbreak;\n+\t\t\tcase ',':\n+\t\t\tcase '\\0': /* end of string also marks the end of a token */\n+\t\t\t\tif (NULL == (ds = (data_string *)array_get_unused_element(vals, TYPE_STRING))) {\n+\t\t\t\t\tds = data_string_init();\n+\t\t\t\t}\n \n-\t\t\tbuffer_copy_string_len(ds->value, start, end-start+1);\n-\t\t\tarray_insert_unique(vals, (data_unset *)ds);\n+\t\t\t\tbuffer_copy_string_len(ds->value, token_start, token_end-token_start+1);\n+\t\t\t\tarray_insert_unique(vals, (data_unset *)ds);\n \n-\t\t\tif (*s == ',') {\n \t\t\t\tstate = 0;\n-\t\t\t\ti++;\n-\t\t\t\ts++;\n-\t\t\t} else {\n-\t\t\t\t/* end of string */\n-\n-\t\t\t\tstate = 2;\n+\t\t\t\tbreak;\n+\t\t\tdefault:\n+\t\t\t\t/* no white space, update token_end to include current character */\n+\t\t\t\ttoken_end = current;\n+\t\t\t\tbreak;\n \t\t\t}\n \t\t\tbreak;\n-\t\tdefault:\n-\t\t\ti++;\n-\t\t\tbreak;\n \t\t}\n \t}\n+\n \treturn 0;\n }\n \n-- \n1.7.10.4"}], "metadata": {"id": "lighttpd-2374-0001-Fix-DoS-in-header-value-s", "cve_id": "CVE-2013-4560", "package": "lighttpd", "tier": "identical", "has_source_context": false, "license": "BSD-3-Clause"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1g/crypto/ripemd/rmd_locl.h\n- openssl-1.0.1g.orig/crypto/sha/sha_locl.h\n- openssl-1.0.1g/crypto/dsa/dsa_locl.h\n- openssl-1.0.1g/crypto/evp/e_aes.c\n- openssl-1.0.1g/crypto/evp/e_aes_cbc_hmac_sha1.c\n\n## Target Source Code\n\n### apps/Makefile\n\n#### region() [lines 1-68]\n```c\n#\n# apps/Makefile\n#\n\nDIR=\t\tapps\nTOP=\t\t..\nCC=\t\tcc\nINCLUDES=\t-I$(TOP) -I../include $(KRB5_INCLUDES)\nCFLAG=\t\t-g -static\nMAKEFILE=\tMakefile\nPERL=\t\tperl\nRM=\t\trm -f\n# KRB5 stuff\nKRB5_INCLUDES=\nLIBKRB5=\n\nPEX_LIBS=\nEX_LIBS= \nEXE_EXT= \n\nSHLIB_TARGET=\n\nCFLAGS= -DMONOLITH $(INCLUDES) $(CFLAG)\n\nGENERAL=Makefile makeapps.com install.com\n\nDLIBCRYPTO=..\n/* ... truncated ... */\n```\n\n### crypto/asn1/asn1_locl.h\n\n#### region() [lines 19-105]\n```c\n *\n * 3. All advertising materials mentioning features or use of this\n * software must display the following acknowledgment:\n * \"This product includes software developed by the OpenSSL Project\n * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)\"\n *\n * 4. The names \"OpenSSL Toolkit\" and \"OpenSSL Project\" must not be used\n/* ... truncated ... */\n```\n\n### crypto/bn/bn_lcl.h\n\n#### region() [lines 444-516]\n```c\n\th+=(m&BN_MASK2h1)>>(BN_BITS4-1); \\\n\tm =(m&BN_MASK2l)<<(BN_BITS4+1); \\\n\tl=(l+m)&BN_MASK2; if (l < m) h++; \\\n\t(lo)=l; \\\n\t(ho)=h; \\\n\t}\n\n#define mul_add(r,a,bl,bh,c) { \\\n\tBN_ULONG l,h; \\\n \\\n\th= (a); \\\n\tl=LBITS(h); \\\n\th=HBITS(h); \\\n\tmul64(l,h,(bl),(bh)); \\\n \\\n\t/* non-multiply part */ \\\n\tl=(l+(c))&BN_MASK2; if (l < (c)) h++; \\\n\t(c)=(r); \\\n\tl\n/* ... truncated ... */\n```\n\n### crypto/camellia/cmll_locl.h\n\n#### region() [lines 29-87]\n```c\n * 2. Redistributions in binary form must reproduce the above copyright\n * notice, this list of conditions and the following disclaimer in\n * the documentation and/or other materials provided with the\n * distribution.\n *\n * 3. All advertising materials mentioning features or use of this\n * software must display the following a\n/* ... truncated ... */\n```\n\n### crypto/cast/cast_lcl.h\n\n#### region() [lines 178-228]\n```c\n\t\t\tCAST_S_table1+((t<>C_0)&C_M)))&0xffffffffL) OP1 \\\n\t\t*(CAST_LONG *)((unsigned char *) \\\n\t\t\tCAST_S_table3+((t>>C_1)&C_M)))&0xffffffffL; \\\n\t}\n#elif defined(CAST_PTR2)\n#define E_CAST(n,key,L,R,OP1,OP2,OP3) \\\n\t{ \\\n\tint i; \\\n\tCAST_LONG u,v,w; \\\n\tw=(ke\n/* ... truncated ... */\n```\n\n### crypto/cms/cms_lcl.h\n\n#### DECLARE_ASN1_ALLOC_FUNCTIONS() [lines 387-473]\n```c\nstruct CMS_ReceiptRequest_st\n\t{\n\tASN1_OCTET_STRING *signedContentIdentifier;\n\tCMS_ReceiptsFrom *receiptsFrom;\n\tSTACK_OF(GENERAL_NAMES) *receiptsTo;\n\t};\n\n\nstruct CMS_ReceiptsFrom_st\n\t{\n\tint type;\n\tunion\n\t\t{\n\t\tlong allOrFirstTier;\n\t\tSTACK_OF(GENERAL_NAMES) *receiptList;\n\t\t} d;\n\t};\n#endif\n\nstruct CMS_Receipt_st\n\t{\n\tlo\n/* ... truncated ... */\n```\n\n### crypto/des/des_locl.h\n\n#### region() [lines 382-433]\n```c\n\tcan be used to swap and move bits between words.\n\n\tSo l = 0 1 2 3 r = 16 17 18 19\n\t 4 5 6 7 20 21 22 23\n\t 8 9 10 11 24 25 26 27\n\t 12 13 14 15 28 29 30 31\n\tbecomes (for size == 2 and mask == 0x3333)\n\t t = 2^16 3^17 -- -- l = 0 1 16 17 r = 2 3 18 19\n\t\t 6^20 7^21 -- -- 4 5 2\n/* ... truncated ... */\n```\n\n### crypto/dsa/dsa_locl.h\n\n#### region() [lines 18-61]\n```c\n * \"This product includes software developed by the OpenSSL Project\n * for use in the OpenSSL Toolkit. (http://www.openssl.org/)\"\n *\n * 4. The names \"OpenSSL Toolkit\" and \"OpenSSL Project\" must not be used to\n * endorse or promote products derived from this software without\n * prior written permission. For written permission, \n/* ... truncated ... */\n```\n\n### crypto/ec/ec_lcl.h\n\n#### region() [lines 49-135]\n```c\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\n * OF THE POSSIBILITY OF SUCH DAMAGE.\n * ====================================================================\n *\n * This product includes cryptographic software written by Eric Young\n * (eay@cryptsoft.com). This product includes software written by Tim\n * Hudson (tjh\n/* ... truncated ... */\n```\n\n### crypto/ecdh/ech_locl.h\n\n#### region() [lines 19-103]\n```c\n * \"This product includes software developed by the OpenSSL Project\n * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)\"\n *\n * 4. The names \"OpenSSL Toolkit\" and \"OpenSSL Project\" must not be used to\n * endorse or promote products derived from this software without\n * prior written permission. For written permission,\n/* ... truncated ... */\n```\n\n### crypto/ecdsa/ecs_locl.h\n\n#### region() [lines 22-108]\n```c\n * \"This product includes software developed by the OpenSSL Project\n * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)\"\n *\n * 4. The names \"OpenSSL Toolkit\" and \"OpenSSL Project\" must not be used to\n * endorse or promote products derived from this software without\n * prior written permission. For written permission,\n/* ... truncated ... */\n```\n\n### crypto/engine/eng_int.h\n\n#### region() [lines 29-115]\n```c\n *\n * 5. Products derived from this software may not be called \"OpenSSL\"\n * nor may \"OpenSSL\" appear in their names without prior written\n * permission of the OpenSSL Project.\n *\n * 6. Redistributions of any form whatsoever must retain the following\n * acknowledgment:\n * \"This product includes software developed by the OpenSS\n/* ... truncated ... */\n```\n\n### crypto/engine/eng_rsax.c\n\n#### mod_exp_pre_compute_data_512() [lines 390-489]\n```c\n\n\n/* The main 512bit precompute call */\nstatic int mod_exp_pre_compute_data_512(UINT64 *m, struct mod_ctx_512 *data)\n {\n BIGNUM two_768, two_640, two_128, two_512, tmp, _m, tmp2;\n\n /* We need a BN_CTX for the modulo functions */\n BN_CTX* ctx;\n /* Some tmps */\n UINT64 _t[8];\n int i, j, ret = 0;\n\n \n/* ... truncated ... */\n```\n\n### crypto/evp/e_aes.c\n\n#### region() [lines 69-155]\n```c\n\t\tctr128_f ctr;\n\t} stream;\n\t} EVP_AES_KEY;\n\ntypedef struct\n\t{\n\tAES_KEY ks;\t\t/* AES key schedule to use */\n\tint key_set;\t\t/* Set if key initialised */\n\tint iv_set;\t\t/* Set if an iv is set */\n\tGCM128_CONTEXT gcm;\n\tunsigned char *iv;\t/* Temporary IV store */\n\tint ivlen;\t\t/* IV length */\n\tint taglen;\n\tint iv_gen;\t\t/* It is OK to generate IVs\n/* ... truncated ... */\n```\n\n### crypto/evp/e_aes_cbc_hmac_sha1.c\n\n#### region() [lines 58-144]\n```c\n#include \n#include \n#include \n#include \"evp_locl.h\"\n\n#ifndef EVP_CIPH_FLAG_AEAD_CIPHER\n#define EVP_CIPH_FLAG_AEAD_CIPHER\t0x200000\n#define EVP_CTRL_AEAD_TLS1_AAD\t\t0x16\n#define EVP_CTRL_AEAD_SET_MAC_KEY\t0x17\n#endif\n\n#if !defined(EVP_CIPH_FLAG_DEFAULT_ASN1)\n#define EVP_CIPH_FLAG_DEFAULT_ASN1 \n/* ... truncated ... */\n```\n\n### crypto/evp/evp_locl.h\n\n#### region() [lines 224-310]\n```c\n\tsizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\\\n\t\tsizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\\\n\tset_asn1, get_asn1,\\\n\tctrl,\\\n\tNULL \\\n};\\\nconst EVP_CIPHER *EVP_##cname##_ofb(void) { return &cname##_ofb; }\\\nstatic const EVP_CIPHER cname##_ecb = {\\\n\tnid##_ecb, block_size, key_len, iv_len, \\\n\tflags | EVP_CIPH_ECB_MODE,\\\n\t\n/* ... truncated ... */\n```\n\n### crypto/md4/md4_locl.h\n\n#### region() [lines 26-113]\n```c\n * 1. Redistributions of source code must retain the copyright\n * notice, this list of conditions and the following disclaimer.\n * 2. Redistributions in binary form must reproduce the above copyright\n * notice, this list of conditions and the following disclaimer in the\n * documentation and/or other materials provided with the d\n/* ... truncated ... */\n```\n\n### crypto/md5/md5_locl.h\n\n#### region() [lines 35-122]\n```c\n * The word 'cryptographic' can be left out if the rouines from the library\n * being used are not cryptographic related :-).\n * 4. If you include any Windows specific code (or a derivative thereof) from \n * the apps directory (application code) you must include an acknowledgement:\n * \"This product includes software written by\n/* ... truncated ... */\n```\n\n### crypto/modes/modes_lcl.h\n\n#### region() [lines 48-103]\n```c\n\t\t\t: \"+r\"(hi),\"+r\"(lo));\t\t\\\n\t\t\t(u64)hi<<32|lo;\t\t\t})\n# define BSWAP4(x) ({\tu32 ret=(x);\t\t\t\\\n\t\t\tasm (\"bswapl %0\"\t\t\\\n\t\t\t: \"+r\"(ret));\tret;\t\t})\n# elif (defined(__arm__) || defined(__arm)) && !defined(STRICT_ALIGNMENT)\n# define BSWAP8(x) ({\tu32 lo=(u64)(x)>>32,hi=(x);\t\\\n\t\t\tasm (\"rev %0,%0; rev %1,%1\"\t\\\n\t\t\t: \"+r\"(hi),\"+r\"(lo));\t\t\\\n\t\t\t(u64)hi\n/* ... truncated ... */\n```\n\n### crypto/o_str.h\n\n#### region() [lines 22-69]\n```c\n * \"This product includes software developed by the OpenSSL Project\n * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)\"\n *\n * 4. The names \"OpenSSL Toolkit\" and \"OpenSSL Project\" must not be used to\n * endorse or promote products derived from this software without\n * prior written permission. For written permission, \n/* ... truncated ... */\n```\n\n### crypto/o_time.h\n\n#### region() [lines 22-68]\n```c\n * \"This product includes software developed by the OpenSSL Project\n * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)\"\n *\n * 4. The names \"OpenSSL Toolkit\" and \"OpenSSL Project\" must not be used to\n * endorse or promote products derived from this software without\n * prior written permission. For written permission, \n/* ... truncated ... */\n```\n\n### crypto/ripemd/rmd_locl.h\n\n#### region() [lines 37-124]\n```c\n * 4. If you include any Windows specific code (or a derivative thereof) from \n * the apps directory (application code) you must include an acknowledgement:\n * \"This product includes software written by Tim Hudson (tjh@cryptsoft.com)\"\n * \n * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\n * ANY EXPRESS OR IMPLIED WARRANTIES,\n/* ... truncated ... */\n```\n\n### crypto/rsa/rsa_locl.h\n\n#### region() [lines 1-5]\n```c\nextern int int_rsa_verify(int dtype, const unsigned char *m, unsigned int m_len,\n\t\tunsigned char *rm, size_t *prm_len,\n\t\tconst unsigned char *sigbuf, size_t siglen,\n\t\tRSA *rsa);\n\n```\n\n### crypto/sha/sha256.c\n\n#### SHA224_Final() [lines 66-72]\n```c\n\nint SHA224_Update(SHA256_CTX *c, const void *data, size_t len)\n{ return SHA256_Update (c,data,len); }\nint SHA224_Final (unsigned char *md, SHA256_CTX *c)\n{ return SHA256_Final (md,c); }\n\n#define\tDATA_ORDER_IS_BIG_ENDIAN\n```\n\n### crypto/sha/sha512.c\n\n#### fips_md_init() [lines 75-94]\n```c\n return 1;\n\t}\n\nfips_md_init(SHA512)\n\t{\n\tc->h[0]=U64(0x6a09e667f3bcc908);\n\tc->h[1]=U64(0xbb67ae8584caa73b);\n\tc->h[2]=U64(0x3c6ef372fe94f82b);\n\tc->h[3]=U64(0xa54ff53a5f1d36f1);\n\tc->h[4]=U64(0x510e527fade682d1);\n\tc->h[5]=U64(0x9b05688c2b3e6c1f);\n\tc->h[6]=U64(0x1f83d9abfb41bd6b);\n\tc->h[7]=U64(0x5be0cd19137e2179);\n\n c->Nl=0\n/* ... truncated ... */\n```\n\n### crypto/sha/sha_locl.h\n\n#### sha_block_data_order() [lines 69-156]\n```c\n#define HASH_CBLOCK SHA_CBLOCK\n#define HASH_MAKE_STRING(c,s) do {\t\\\n\tunsigned long ll;\t\t\\\n\tll=(c)->h0; (void)HOST_l2c(ll,(s));\t\\\n\tll=(c)->h1; (void)HOST_l2c(ll,(s));\t\\\n\tll=(c)->h2; (void)HOST_l2c(ll,(s));\t\\\n\tll=(c)->h3; (void)HOST_l2c(ll,(s));\t\\\n\tll=(c)->h4; (void)HOST_l2c(ll,(s));\t\\\n\t} while (0)\n\n#if defined(\n/* ... truncated ... */\n```\n\n### crypto/store/str_locl.h\n\n#### region() [lines 23-109]\n```c\n * for use in the OpenSSL Toolkit. (http://www.openssl.org/)\"\n *\n * 4. The names \"OpenSSL Toolkit\" and \"OpenSSL Project\" must not be used to\n * endorse or promote products derived from this software without\n * prior written permission. For written permission, please contact\n * openssl-core@openssl.org.\n *\n * 5. Products deriv\n/* ... truncated ... */\n```\n\n### crypto/ui/ui_locl.h\n\n#### region() [lines 27-113]\n```c\n * prior written permission. For written permission, please contact\n * openssl-core@openssl.org.\n *\n * 5. Products derived from this software may not be called \"OpenSSL\"\n * nor may \"OpenSSL\" appear in their names without prior written\n * permission of the OpenSSL Project.\n *\n * 6. Redistributions of any form whatsoever must r\n/* ... truncated ... */\n```\n\n### crypto/whrlpool/wp_locl.h\n\n#### region() [lines 1-4]\n```c\n#include \n\nvoid whirlpool_block(WHIRLPOOL_CTX *,const void *,size_t);\n\n```\n\n### crypto/x509v3/ext_dat.h\n\n#### region() [lines 18-104]\n```c\n * distribution.\n *\n * 3. All advertising materials mentioning features or use of this\n * software must display the following acknowledgment:\n * \"This product includes software developed by the OpenSSL Project\n * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)\"\n *\n * 4. The names \"OpenSSL Toolkit\" and \"OpenSSL Proje\n/* ... truncated ... */\n```\n\n### crypto/x509v3/pcy_int.h\n\n#### region() [lines 17-103]\n```c\n * the documentation and/or other materials provided with the\n * distribution.\n *\n * 3. All advertising materials mentioning features or use of this\n * software must display the following acknowledgment:\n * \"This product includes software developed by the OpenSSL Project\n * for use in the OpenSSL Toolkit. (http://www.OpenS\n/* ... truncated ... */\n```\n\n### crypto/modes/gcm128.c\n\n#### gcm_gmult_1bit() [lines 582-642]\n```c\n\n#else\t/* TABLE_BITS */\n\nstatic void gcm_gmult_1bit(u64 Xi[2],const u64 H[2])\n{\n\tu128 V,Z = { 0,0 };\n\tlong X;\n\tint i,j;\n\tconst long *xi = (const long *)Xi;\n\tconst union { long one; char little; } is_endian = {1};\n\n\tV.hi = H[0];\t/* H is in host byte order, no byte swapping */\n\tV.lo = H[1];\n\n\tfor (j=0; j<16/sizeof(long); ++j) {\n\t\n/* ... truncated ... */\n```\n\n### crypto/evp/e_rc4_hmac_md5.c\n\n#### region() [lines 39-126]\n```c\n * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n * STRICT LI\n/* ... truncated ... */\n```\n\n\n### Type definitions\n\n```c\n/* from evp_locl.h */\nstruct evp_pkey_ctx_st\n\t{\n\t/* Method associated with this operation */\n\tconst EVP_PKEY_METHOD *pmeth;\n\t/* Engine that implements this method or NULL if builtin */\n\tENGINE *engine;\n\t/* Key: may be NULL */\n\tEVP_PKEY *pkey;\n\t/* Peer key for key agreement, may be NULL */\n\tEVP_PKEY *peerkey;\n\t/* Actual operation */\n\tint operation;\n\t/* Algorithm specific data */\n\tvoid *data;\n\t/* Application specific data */\n\tvoid *app_data;\n\t/* Keygen callback */\n\tEVP_PKEY_gen_cb *pkey_gencb;\n\t/* implementation specific keygen data */\n\tint *keygen_info;\n\tint keygen_info_count;\n\t} /* EVP_PKEY_CTX */;\n\n/* from modes_lcl.h */\nstruct ccm128_context {\n\tunion { u64 u[2]; u8 c[16]; } nonce, cmac;\n\tu64 blocks;\n\tblock128_f block;\n\tvoid *key;\n};\n\n/* from evp_locl.h */\nstruct evp_pkey_ctx_st\n\t{\n\t/* Method associated with this operation */\n\tconst EVP_PKEY_METHOD *pmeth;\n\t/* Engine that implements this method or NULL if builtin */\n\tENGINE *engine;\n\t/* Key: may be NULL */\n\tEVP_PKEY *pkey;\n\t/* Peer key for key agreement, may be NULL */\n\tEVP_PKEY *peerkey;\n\t/* Actual operation */\n\tint operation;\n\t/* Algorithm specific data */\n\tvoid *data;\n\t/* Application specific data */\n\tvoid *app_data;\n\t/* Keygen callback */\n\tEVP_PKEY_gen_cb *pkey_gencb;\n\t/* implementation specific keygen data */\n\tint *keygen_info;\n\tint keygen_info_count;\n\t} /* EVP_PKEY_CTX */;\n\n/* from modes_lcl.h */\nstruct ccm128_context {\n\tunion { u64 u[2]; u8 c[16]; } nonce, cmac;\n\tu64 blocks;\n\tblock128_f block;\n\tvoid *key;\n};\n```\n\n\n## Upstream Fix\n```diff\nFrom c4251c714a2fa6263e77103561b3dc4f6f5fed40 Mon Sep 17 00:00:00 2001\nFrom: =?UTF-8?q?Cristian=20Rodr=C3=ADguez?= \nDate: Mon, 21 Oct 2013 01:48:05 -0300\nSubject: [PATCH] libcrypto: Hide library-private symbols\n\n---\n apps/Makefile | 2 +-\n crypto/asn1/asn1_locl.h | 4 ++++\n crypto/bn/bn_lcl.h | 4 ++++\n crypto/camellia/cmll_locl.h | 3 +++\n crypto/cast/cast_lcl.h | 2 ++\n crypto/cms/cms_lcl.h | 5 ++++-\n crypto/des/des_locl.h | 2 ++\n crypto/dsa/dsa_locl.h | 2 +-\n crypto/ec/ec_lcl.h | 4 ++++\n crypto/ecdh/ech_locl.h | 4 +++-\n crypto/ecdsa/ecs_locl.h | 4 ++++\n crypto/engine/eng_int.h | 4 +++-\n crypto/engine/eng_rsax.c | 2 +-\n crypto/evp/e_aes.c | 10 ++++++++++\n crypto/evp/e_aes_cbc_hmac_sha1.c | 4 ++++\n crypto/evp/evp_locl.h | 4 ++++\n crypto/md4/md4_locl.h | 2 +-\n crypto/md5/md5_locl.h | 2 +-\n crypto/modes/modes_lcl.h | 4 +++-\n crypto/o_str.h | 4 ++++\n crypto/o_time.h | 4 ++++\n crypto/ripemd/rmd_locl.h | 2 +-\n crypto/rsa/rsa_locl.h | 2 +-\n crypto/sha/sha256.c | 2 +-\n crypto/sha/sha512.c | 2 +-\n crypto/sha/sha_locl.h | 2 +-\n crypto/store/str_locl.h | 4 +++-\n crypto/ui/ui_locl.h | 4 +++-\n crypto/whrlpool/wp_locl.h | 2 +-\n crypto/x509v3/ext_dat.h | 3 +++\n crypto/x509v3/pcy_int.h | 3 +++\n 31 files changed, 85 insertions(+), 17 deletions(-)\n\nIndex: openssl-1.0.1g/apps/Makefile\n===================================================================\n--- openssl-1.0.1g.orig/apps/Makefile\n+++ openssl-1.0.1g/apps/Makefile\n@@ -20,7 +20,7 @@ EXE_EXT=\n \n SHLIB_TARGET=\n \n-CFLAGS= -DMONOLITH $(INCLUDES) $(CFLAG)\n+CFLAGS= -fvisibility=hidden -DMONOLITH $(INCLUDES) $(CFLAG)\n \n GENERAL=Makefile makeapps.com install.com\n \nIndex: openssl-1.0.1g/crypto/asn1/asn1_locl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/asn1/asn1_locl.h\n+++ openssl-1.0.1g/crypto/asn1/asn1_locl.h\n@@ -58,6 +58,8 @@\n \n /* Internal ASN1 structures and functions: not for application use */\n \n+#pragma GCC visibility push(hidden)\n+\n /* ASN1 print context structure */\n \n struct asn1_pctx_st\n@@ -143,3 +145,5 @@ struct x509_crl_method_st\n \t\t\t\tASN1_INTEGER *ser, X509_NAME *issuer);\n \tint (*crl_verify)(X509_CRL *crl, EVP_PKEY *pk);\n \t};\n+\n+#pragma GCC visibility pop\nIndex: openssl-1.0.1g/crypto/bn/bn_lcl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/bn/bn_lcl.h\n+++ openssl-1.0.1g/crypto/bn/bn_lcl.h\n@@ -483,6 +483,8 @@ extern \"C\" {\n #undef bn_div_words\n #endif\n \n+#pragma GCC visibility push(hidden)\n+\n void bn_mul_normal(BN_ULONG *r,BN_ULONG *a,int na,BN_ULONG *b,int nb);\n void bn_mul_comba8(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b);\n void bn_mul_comba4(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b);\n@@ -508,6 +510,8 @@ BN_ULONG bn_sub_part_words(BN_ULONG *r,\n \tint cl, int dl);\n int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np,const BN_ULONG *n0, int num);\n \n+#pragma GCC visibility pop\n+\n #ifdef __cplusplus\n }\n #endif\nIndex: openssl-1.0.1g/crypto/camellia/cmll_locl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/camellia/cmll_locl.h\n+++ openssl-1.0.1g/crypto/camellia/cmll_locl.h\n@@ -68,6 +68,8 @@\n #ifndef HEADER_CAMELLIA_LOCL_H\n #define HEADER_CAMELLIA_LOCL_H\n \n+#pragma GCC visibility push(hidden)\n+\n typedef unsigned int u32;\n typedef unsigned char u8;\n \n@@ -83,4 +85,5 @@ void Camellia_DecryptBlock(int keyBitLen\n \t\tconst KEY_TABLE_TYPE keyTable, u8 plaintext[]);\n int private_Camellia_set_key(const unsigned char *userKey, const int bits,\n \t\t\t CAMELLIA_KEY *key);\n+#pragma GCC visibility pop\n #endif /* #ifndef HEADER_CAMELLIA_LOCL_H */\nIndex: openssl-1.0.1g/crypto/cast/cast_lcl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/cast/cast_lcl.h\n+++ openssl-1.0.1g/crypto/cast/cast_lcl.h\n@@ -217,6 +217,7 @@\n \t}\n #endif\n \n+#pragma GCC visibility push(hidden)\n extern const CAST_LONG CAST_S_table0[256];\n extern const CAST_LONG CAST_S_table1[256];\n extern const CAST_LONG CAST_S_table2[256];\n@@ -225,3 +226,4 @@ extern const CAST_LONG CAST_S_table4[256\n extern const CAST_LONG CAST_S_table5[256];\n extern const CAST_LONG CAST_S_table6[256];\n extern const CAST_LONG CAST_S_table7[256];\n+#pragma GCC visibility pop\nIndex: openssl-1.0.1g/crypto/cms/cms_lcl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/cms/cms_lcl.h\n+++ openssl-1.0.1g/crypto/cms/cms_lcl.h\n@@ -426,6 +426,8 @@ DECLARE_ASN1_ALLOC_FUNCTIONS(CMS_IssuerA\n #define CMS_RECIPINFO_ISSUER_SERIAL\t0\n #define CMS_RECIPINFO_KEYIDENTIFIER\t1\n \n+#pragma GCC visibility push(hidden)\n+\n BIO *cms_content_bio(CMS_ContentInfo *cms);\n \n CMS_ContentInfo *cms_Data_create(void);\n@@ -466,7 +468,8 @@ CMS_EnvelopedData *cms_get0_enveloped(CM\n /* PWRI routines */\n int cms_RecipientInfo_pwri_crypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri,\n \t\t\t\t\t\t\tint en_de);\n-\t\n+\n+#pragma GCC visibility pop\n #ifdef __cplusplus\n }\n #endif\nIndex: openssl-1.0.1g/crypto/des/des_locl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/des/des_locl.h\n+++ openssl-1.0.1g/crypto/des/des_locl.h\n@@ -421,10 +421,12 @@\n \tPERM_OP(l,r,tt, 4,0x0f0f0f0fL); \\\n \t}\n \n+#pragma GCC visibility push(hidden)\n extern const DES_LONG DES_SPtrans[8][64];\n \n void fcrypt_body(DES_LONG *out,DES_key_schedule *ks,\n \t\t DES_LONG Eswap0, DES_LONG Eswap1);\n+#pragma GCC visibility pop\n \n #ifdef OPENSSL_SMALL_FOOTPRINT\n #undef DES_UNROLL\nIndex: openssl-1.0.1g/crypto/dsa/dsa_locl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/dsa/dsa_locl.h\n+++ openssl-1.0.1g/crypto/dsa/dsa_locl.h\n@@ -57,4 +57,4 @@\n int dsa_builtin_paramgen(DSA *ret, size_t bits, size_t qbits,\n \tconst EVP_MD *evpmd, const unsigned char *seed_in, size_t seed_len,\n \tunsigned char *seed_out,\n-\tint *counter_ret, unsigned long *h_ret, BN_GENCB *cb);\n+\tint *counter_ret, unsigned long *h_ret, BN_GENCB *cb) __attribute__ ((visibility (\"hidden\")));\nIndex: openssl-1.0.1g/crypto/ec/ec_lcl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/ec/ec_lcl.h\n+++ openssl-1.0.1g/crypto/ec/ec_lcl.h\n@@ -88,6 +88,8 @@\n /* Structure details are not part of the exported interface,\n * so all this may change in future versions. */\n \n+#pragma GCC visibility push(hidden)\n+\n struct ec_method_st {\n \t/* Various method flags */\n \tint flags;\n@@ -444,3 +446,5 @@ void ec_GFp_nistp_points_make_affine_int\n \tvoid (*felem_contract)(void *out, const void *in));\n void ec_GFp_nistp_recode_scalar_bits(unsigned char *sign, unsigned char *digit, unsigned char in);\n #endif\n+\n+#pragma GCC visibility pop\nIndex: openssl-1.0.1g/crypto/ecdh/ech_locl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/ecdh/ech_locl.h\n+++ openssl-1.0.1g/crypto/ecdh/ech_locl.h\n@@ -58,6 +58,8 @@\n \n #include \n \n+#pragma GCC visibility push(hidden)\n+\n #ifdef __cplusplus\n extern \"C\" {\n #endif\n@@ -98,5 +100,5 @@ ECDH_DATA *ecdh_check(EC_KEY *);\n #ifdef __cplusplus\n }\n #endif\n-\n+#pragma GCC visibility pop\n #endif /* HEADER_ECH_LOCL_H */\nIndex: openssl-1.0.1g/crypto/ecdsa/ecs_locl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/ecdsa/ecs_locl.h\n+++ openssl-1.0.1g/crypto/ecdsa/ecs_locl.h\n@@ -61,6 +61,8 @@\n \n #include \n \n+#pragma GCC visibility push(hidden)\n+\n #ifdef __cplusplus\n extern \"C\" {\n #endif\n@@ -112,4 +114,6 @@ ECDSA_DATA *ecdsa_check(EC_KEY *eckey);\n }\n #endif\n \n+#pragma GCC visibility pop\n+\n #endif \n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From c4251c714a2fa6263e77103561b3dc4f6f5fed40 Mon Sep 17 00:00:00 2001\nFrom: =?UTF-8?q?Cristian=20Rodr=C3=ADguez?= \nDate: Mon, 21 Oct 2013 01:48:05 -0300\nSubject: [PATCH] libcrypto: Hide library-private symbols\n\n---\n apps/Makefile | 2 +-\n crypto/asn1/asn1_locl.h | 4 ++++\n crypto/bn/bn_lcl.h | 4 ++++\n crypto/camellia/cmll_locl.h | 3 +++\n crypto/cast/cast_lcl.h | 2 ++\n crypto/cms/cms_lcl.h | 5 ++++-\n crypto/des/des_locl.h | 2 ++\n crypto/dsa/dsa_locl.h | 2 +-\n crypto/ec/ec_lcl.h | 4 ++++\n crypto/ecdh/ech_locl.h | 4 +++-\n crypto/ecdsa/ecs_locl.h | 4 ++++\n crypto/engine/eng_int.h | 4 +++-\n crypto/engine/eng_rsax.c | 2 +-\n crypto/evp/e_aes.c | 10 ++++++++++\n crypto/evp/e_aes_cbc_hmac_sha1.c | 4 ++++\n crypto/evp/evp_locl.h | 4 ++++\n crypto/md4/md4_locl.h | 2 +-\n crypto/md5/md5_locl.h | 2 +-\n crypto/modes/modes_lcl.h | 4 +++-\n crypto/o_str.h | 4 ++++\n crypto/o_time.h | 4 ++++\n crypto/ripemd/rmd_locl.h | 2 +-\n crypto/rsa/rsa_locl.h | 2 +-\n crypto/sha/sha256.c | 2 +-\n crypto/sha/sha512.c | 2 +-\n crypto/sha/sha_locl.h | 2 +-\n crypto/store/str_locl.h | 4 +++-\n crypto/ui/ui_locl.h | 4 +++-\n crypto/whrlpool/wp_locl.h | 2 +-\n crypto/x509v3/ext_dat.h | 3 +++\n crypto/x509v3/pcy_int.h | 3 +++\n 31 files changed, 85 insertions(+), 17 deletions(-)\n\nIndex: openssl-1.0.1g/apps/Makefile\n===================================================================\n--- openssl-1.0.1g.orig/apps/Makefile\n+++ openssl-1.0.1g/apps/Makefile\n@@ -20,7 +20,7 @@ EXE_EXT=\n \n SHLIB_TARGET=\n \n-CFLAGS= -DMONOLITH $(INCLUDES) $(CFLAG)\n+CFLAGS= -fvisibility=hidden -DMONOLITH $(INCLUDES) $(CFLAG)\n \n GENERAL=Makefile makeapps.com install.com\n \nIndex: openssl-1.0.1g/crypto/asn1/asn1_locl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/asn1/asn1_locl.h\n+++ openssl-1.0.1g/crypto/asn1/asn1_locl.h\n@@ -58,6 +58,8 @@\n \n /* Internal ASN1 structures and functions: not for application use */\n \n+#pragma GCC visibility push(hidden)\n+\n /* ASN1 print context structure */\n \n struct asn1_pctx_st\n@@ -143,3 +145,5 @@ struct x509_crl_method_st\n \t\t\t\tASN1_INTEGER *ser, X509_NAME *issuer);\n \tint (*crl_verify)(X509_CRL *crl, EVP_PKEY *pk);\n \t};\n+\n+#pragma GCC visibility pop\nIndex: openssl-1.0.1g/crypto/bn/bn_lcl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/bn/bn_lcl.h\n+++ openssl-1.0.1g/crypto/bn/bn_lcl.h\n@@ -483,6 +483,8 @@ extern \"C\" {\n #undef bn_div_words\n #endif\n \n+#pragma GCC visibility push(hidden)\n+\n void bn_mul_normal(BN_ULONG *r,BN_ULONG *a,int na,BN_ULONG *b,int nb);\n void bn_mul_comba8(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b);\n void bn_mul_comba4(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b);\n@@ -508,6 +510,8 @@ BN_ULONG bn_sub_part_words(BN_ULONG *r,\n \tint cl, int dl);\n int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np,const BN_ULONG *n0, int num);\n \n+#pragma GCC visibility pop\n+\n #ifdef __cplusplus\n }\n #endif\nIndex: openssl-1.0.1g/crypto/camellia/cmll_locl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/camellia/cmll_locl.h\n+++ openssl-1.0.1g/crypto/camellia/cmll_locl.h\n@@ -68,6 +68,8 @@\n #ifndef HEADER_CAMELLIA_LOCL_H\n #define HEADER_CAMELLIA_LOCL_H\n \n+#pragma GCC visibility push(hidden)\n+\n typedef unsigned int u32;\n typedef unsigned char u8;\n \n@@ -83,4 +85,5 @@ void Camellia_DecryptBlock(int keyBitLen\n \t\tconst KEY_TABLE_TYPE keyTable, u8 plaintext[]);\n int private_Camellia_set_key(const unsigned char *userKey, const int bits,\n \t\t\t CAMELLIA_KEY *key);\n+#pragma GCC visibility pop\n #endif /* #ifndef HEADER_CAMELLIA_LOCL_H */\nIndex: openssl-1.0.1g/crypto/cast/cast_lcl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/cast/cast_lcl.h\n+++ openssl-1.0.1g/crypto/cast/cast_lcl.h\n@@ -217,6 +217,7 @@\n \t}\n #endif\n \n+#pragma GCC visibility push(hidden)\n extern const CAST_LONG CAST_S_table0[256];\n extern const CAST_LONG CAST_S_table1[256];\n extern const CAST_LONG CAST_S_table2[256];\n@@ -225,3 +226,4 @@ extern const CAST_LONG CAST_S_table4[256\n extern const CAST_LONG CAST_S_table5[256];\n extern const CAST_LONG CAST_S_table6[256];\n extern const CAST_LONG CAST_S_table7[256];\n+#pragma GCC visibility pop\nIndex: openssl-1.0.1g/crypto/cms/cms_lcl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/cms/cms_lcl.h\n+++ openssl-1.0.1g/crypto/cms/cms_lcl.h\n@@ -426,6 +426,8 @@ DECLARE_ASN1_ALLOC_FUNCTIONS(CMS_IssuerA\n #define CMS_RECIPINFO_ISSUER_SERIAL\t0\n #define CMS_RECIPINFO_KEYIDENTIFIER\t1\n \n+#pragma GCC visibility push(hidden)\n+\n BIO *cms_content_bio(CMS_ContentInfo *cms);\n \n CMS_ContentInfo *cms_Data_create(void);\n@@ -466,7 +468,8 @@ CMS_EnvelopedData *cms_get0_enveloped(CM\n /* PWRI routines */\n int cms_RecipientInfo_pwri_crypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri,\n \t\t\t\t\t\t\tint en_de);\n-\t\n+\n+#pragma GCC visibility pop\n #ifdef __cplusplus\n }\n #endif\nIndex: openssl-1.0.1g/crypto/des/des_locl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/des/des_locl.h\n+++ openssl-1.0.1g/crypto/des/des_locl.h\n@@ -421,10 +421,12 @@\n \tPERM_OP(l,r,tt, 4,0x0f0f0f0fL); \\\n \t}\n \n+#pragma GCC visibility push(hidden)\n extern const DES_LONG DES_SPtrans[8][64];\n \n void fcrypt_body(DES_LONG *out,DES_key_schedule *ks,\n \t\t DES_LONG Eswap0, DES_LONG Eswap1);\n+#pragma GCC visibility pop\n \n #ifdef OPENSSL_SMALL_FOOTPRINT\n #undef DES_UNROLL\nIndex: openssl-1.0.1g/crypto/dsa/dsa_locl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/dsa/dsa_locl.h\n+++ openssl-1.0.1g/crypto/dsa/dsa_locl.h\n@@ -57,4 +57,4 @@\n int dsa_builtin_paramgen(DSA *ret, size_t bits, size_t qbits,\n \tconst EVP_MD *evpmd, const unsigned char *seed_in, size_t seed_len,\n \tunsigned char *seed_out,\n-\tint *counter_ret, unsigned long *h_ret, BN_GENCB *cb);\n+\tint *counter_ret, unsigned long *h_ret, BN_GENCB *cb) __attribute__ ((visibility (\"hidden\")));\nIndex: openssl-1.0.1g/crypto/ec/ec_lcl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/ec/ec_lcl.h\n+++ openssl-1.0.1g/crypto/ec/ec_lcl.h\n@@ -88,6 +88,8 @@\n /* Structure details are not part of the exported interface,\n * so all this may change in future versions. */\n \n+#pragma GCC visibility push(hidden)\n+\n struct ec_method_st {\n \t/* Various method flags */\n \tint flags;\n@@ -444,3 +446,5 @@ void ec_GFp_nistp_points_make_affine_int\n \tvoid (*felem_contract)(void *out, const void *in));\n void ec_GFp_nistp_recode_scalar_bits(unsigned char *sign, unsigned char *digit, unsigned char in);\n #endif\n+\n+#pragma GCC visibility pop\nIndex: openssl-1.0.1g/crypto/ecdh/ech_locl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/ecdh/ech_locl.h\n+++ openssl-1.0.1g/crypto/ecdh/ech_locl.h\n@@ -58,6 +58,8 @@\n \n #include \n \n+#pragma GCC visibility push(hidden)\n+\n #ifdef __cplusplus\n extern \"C\" {\n #endif\n@@ -98,5 +100,5 @@ ECDH_DATA *ecdh_check(EC_KEY *);\n #ifdef __cplusplus\n }\n #endif\n-\n+#pragma GCC visibility pop\n #endif /* HEADER_ECH_LOCL_H */\nIndex: openssl-1.0.1g/crypto/ecdsa/ecs_locl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/ecdsa/ecs_locl.h\n+++ openssl-1.0.1g/crypto/ecdsa/ecs_locl.h\n@@ -61,6 +61,8 @@\n \n #include \n \n+#pragma GCC visibility push(hidden)\n+\n #ifdef __cplusplus\n extern \"C\" {\n #endif\n@@ -112,4 +114,6 @@ ECDSA_DATA *ecdsa_check(EC_KEY *eckey);\n }\n #endif\n \n+#pragma GCC visibility pop\n+\n #endif /* HEADER_ECS_LOCL_H */\nIndex: openssl-1.0.1g/crypto/engine/eng_int.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/engine/eng_int.h\n+++ openssl-1.0.1g/crypto/engine/eng_int.h\n@@ -68,6 +68,8 @@\n /* Take public definitions from engine.h */\n #include \n \n+#pragma GCC visibility push(hidden)\n+\n #ifdef __cplusplus\n extern \"C\" {\n #endif\n@@ -202,5 +204,5 @@ struct engine_st\n #ifdef __cplusplus\n }\n #endif\n-\n+#pragma GCC visibility pop\n #endif /* HEADER_ENGINE_INT_H */\nIndex: openssl-1.0.1g/crypto/engine/eng_rsax.c\n===================================================================\n--- openssl-1.0.1g.orig/crypto/engine/eng_rsax.c\n+++ openssl-1.0.1g/crypto/engine/eng_rsax.c\n@@ -262,7 +262,7 @@ static int mod_exp_pre_compute_data_512(\n void mod_exp_512(UINT64 *result, /* 512 bits, 8 qwords */\n \t\t UINT64 *g, /* 512 bits, 8 qwords */\n \t\t UINT64 *exp, /* 512 bits, 8 qwords */\n-\t\t struct mod_ctx_512 *data);\n+\t\t struct mod_ctx_512 *data) __attribute__ ((visibility (\"hidden\")));\n \n typedef struct st_e_rsax_mod_ctx\n {\nIndex: openssl-1.0.1g/crypto/evp/e_aes.c\n===================================================================\n--- openssl-1.0.1g.orig/crypto/evp/e_aes.c\n+++ openssl-1.0.1g/crypto/evp/e_aes.c\n@@ -108,6 +108,8 @@ typedef struct\n \n #define MAXBITCHUNK\t((size_t)1<<(sizeof(size_t)*8-4))\n \n+#pragma GCC visibility push(hidden)\n+\n #ifdef VPAES_ASM\n int vpaes_set_encrypt_key(const unsigned char *userKey, int bits,\n \t\t\tAES_KEY *key);\n@@ -125,6 +127,7 @@ void vpaes_cbc_encrypt(const unsigned ch\n \t\t\tconst AES_KEY *key,\n \t\t\tunsigned char *ivec, int enc);\n #endif\n+\n #ifdef BSAES_ASM\n void bsaes_cbc_encrypt(const unsigned char *in, unsigned char *out,\n \t\t\tsize_t length, const AES_KEY *key,\n@@ -139,6 +142,9 @@ void bsaes_xts_decrypt(const unsigned ch\n \t\t\tsize_t len, const AES_KEY *key1,\n \t\t\tconst AES_KEY *key2, const unsigned char iv[16]);\n #endif\n+\n+#pragma GCC visibility pop\n+\n #ifdef AES_CTR_ASM\n void AES_ctr32_encrypt(const unsigned char *in, unsigned char *out,\n \t\t\tsize_t blocks, const AES_KEY *key,\n@@ -173,6 +179,8 @@ extern unsigned int OPENSSL_ia32cap_P[2]\n */\n #define\tAESNI_CAPABLE\t(OPENSSL_ia32cap_P[1]&(1<<(57-32)))\n \n+#pragma GCC visibility push(hidden)\n+\n int aesni_set_encrypt_key(const unsigned char *userKey, int bits,\n \t\t\tAES_KEY *key);\n int aesni_set_decrypt_key(const unsigned char *userKey, int bits,\n@@ -226,6 +234,8 @@ void aesni_ccm64_decrypt_blocks (const u\n \t\t\tconst unsigned char ivec[16],\n \t\t\tunsigned char cmac[16]);\n \n+#pragma GCC visibility pop\n+\n static int aesni_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \t\t const unsigned char *iv, int enc)\n \t{\nIndex: openssl-1.0.1g/crypto/evp/e_aes_cbc_hmac_sha1.c\n===================================================================\n--- openssl-1.0.1g.orig/crypto/evp/e_aes_cbc_hmac_sha1.c\n+++ openssl-1.0.1g/crypto/evp/e_aes_cbc_hmac_sha1.c\n@@ -97,6 +97,8 @@ typedef struct\n extern unsigned int OPENSSL_ia32cap_P[2];\n #define AESNI_CAPABLE (1<<(57-32))\n \n+#pragma GCC visibility push(hidden)\n+\n int aesni_set_encrypt_key(const unsigned char *userKey, int bits,\n \t\t\t AES_KEY *key);\n int aesni_set_decrypt_key(const unsigned char *userKey, int bits,\n@@ -112,6 +114,8 @@ void aesni_cbc_sha1_enc (const void *inp\n \t\tconst AES_KEY *key, unsigned char iv[16],\n \t\tSHA_CTX *ctx,const void *in0);\n \n+#pragma GCC visibility pop\n+\n #define data(ctx) ((EVP_AES_HMAC_SHA1 *)(ctx)->cipher_data)\n \n static int aesni_cbc_hmac_sha1_init_key(EVP_CIPHER_CTX *ctx,\nIndex: openssl-1.0.1g/crypto/evp/evp_locl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/evp/evp_locl.h\n+++ openssl-1.0.1g/crypto/evp/evp_locl.h\n@@ -263,6 +263,8 @@ const EVP_CIPHER *EVP_##cname##_ecb(void\n \t\t\t EVP_CIPHER_get_asn1_iv, \\\n \t\t\t NULL)\n \n+#pragma GCC visibility push(hidden)\n+\n struct evp_pkey_ctx_st\n \t{\n \t/* Method associated with this operation */\n@@ -348,6 +350,8 @@ int PKCS5_v2_PBKDF2_keyivgen(EVP_CIPHER_\n \t\t\t ASN1_TYPE *param,\n \t\t\t const EVP_CIPHER *c, const EVP_MD *md, int en_de);\n \n+#pragma GCC visibility pop\n+\n #ifdef OPENSSL_FIPS\n \n #ifdef OPENSSL_DOING_MAKEDEPEND\nIndex: openssl-1.0.1g/crypto/md4/md4_locl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/md4/md4_locl.h\n+++ openssl-1.0.1g/crypto/md4/md4_locl.h\n@@ -65,7 +65,7 @@\n #define MD4_LONG_LOG2 2 /* default to 32 bits */\n #endif\n \n-void md4_block_data_order (MD4_CTX *c, const void *p,size_t num);\n+void md4_block_data_order (MD4_CTX *c, const void *p,size_t num) __attribute__ ((visibility (\"hidden\")));\n \n #define DATA_ORDER_IS_LITTLE_ENDIAN\n \nIndex: openssl-1.0.1g/crypto/md5/md5_locl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/md5/md5_locl.h\n+++ openssl-1.0.1g/crypto/md5/md5_locl.h\n@@ -74,7 +74,7 @@\n # endif\n #endif\n \n-void md5_block_data_order (MD5_CTX *c, const void *p,size_t num);\n+void md5_block_data_order (MD5_CTX *c, const void *p,size_t num) __attribute__ ((visibility (\"hidden\")));\n \n #define DATA_ORDER_IS_LITTLE_ENDIAN\n \nIndex: openssl-1.0.1g/crypto/modes/modes_lcl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/modes/modes_lcl.h\n+++ openssl-1.0.1g/crypto/modes/modes_lcl.h\n@@ -83,6 +83,8 @@ typedef unsigned char u8;\n #define PUTU32(p,v)\t((p)[0]=(u8)((v)>>24),(p)[1]=(u8)((v)>>16),(p)[2]=(u8)((v)>>8),(p)[3]=(u8)(v))\n #endif\n \n+#pragma GCC visibility push(hidden)\n+\n /* GCM definitions */\n \n typedef struct { u64 hi,lo; } u128;\n@@ -125,4 +127,4 @@ struct ccm128_context {\n \tblock128_f block;\n \tvoid *key;\n };\n-\n+#pragma GCC visibility pop\nIndex: openssl-1.0.1g/crypto/o_str.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/o_str.h\n+++ openssl-1.0.1g/crypto/o_str.h\n@@ -61,8 +61,12 @@\n \n #include \t\t/* to get size_t */\n \n+#pragma GCC visibility push(hidden)\n+\n int OPENSSL_strcasecmp(const char *str1, const char *str2);\n int OPENSSL_strncasecmp(const char *str1, const char *str2, size_t n);\n int OPENSSL_memcmp(const void *p1,const void *p2,size_t n);\n \n+#pragma GCC visibility pop\n+\n #endif\nIndex: openssl-1.0.1g/crypto/o_time.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/o_time.h\n+++ openssl-1.0.1g/crypto/o_time.h\n@@ -61,7 +61,11 @@\n \n #include \n \n+#pragma GCC visibility push(hidden)\n+\n struct tm *OPENSSL_gmtime(const time_t *timer, struct tm *result);\n int OPENSSL_gmtime_adj(struct tm *tm, int offset_day, long offset_sec);\n \n+#pragma GCC visibility pop\n+\n #endif\nIndex: openssl-1.0.1g/crypto/ripemd/rmd_locl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/ripemd/rmd_locl.h\n+++ openssl-1.0.1g/crypto/ripemd/rmd_locl.h\n@@ -76,7 +76,7 @@\n # endif\n #endif\n \n-void ripemd160_block_data_order (RIPEMD160_CTX *c, const void *p,size_t num);\n+void ripemd160_block_data_order (RIPEMD160_CTX *c, const void *p,size_t num) __attribute__ ((visibility (\"hidden\")));\n \n #define DATA_ORDER_IS_LITTLE_ENDIAN\n \nIndex: openssl-1.0.1g/crypto/rsa/rsa_locl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/rsa/rsa_locl.h\n+++ openssl-1.0.1g/crypto/rsa/rsa_locl.h\n@@ -1,4 +1,4 @@\n extern int int_rsa_verify(int dtype, const unsigned char *m, unsigned int m_len,\n \t\tunsigned char *rm, size_t *prm_len,\n \t\tconst unsigned char *sigbuf, size_t siglen,\n-\t\tRSA *rsa);\n+\t\tRSA *rsa) __attribute__ ((visibility (\"hidden\")));\nIndex: openssl-1.0.1g/crypto/sha/sha256.c\n===================================================================\n--- openssl-1.0.1g.orig/crypto/sha/sha256.c\n+++ openssl-1.0.1g/crypto/sha/sha256.c\n@@ -110,7 +110,7 @@ int SHA224_Final (unsigned char *md, SHA\n #ifndef SHA256_ASM\n static\n #endif\n-void sha256_block_data_order (SHA256_CTX *ctx, const void *in, size_t num);\n+void sha256_block_data_order (SHA256_CTX *ctx, const void *in, size_t num) __attribute__ ((visibility (\"hidden\")));\n \n #include \"md32_common.h\"\n \nIndex: openssl-1.0.1g/crypto/sha/sha512.c\n===================================================================\n--- openssl-1.0.1g.orig/crypto/sha/sha512.c\n+++ openssl-1.0.1g/crypto/sha/sha512.c\n@@ -94,7 +94,7 @@ fips_md_init(SHA512)\n #ifndef SHA512_ASM\n static\n #endif\n-void sha512_block_data_order (SHA512_CTX *ctx, const void *in, size_t num);\n+void sha512_block_data_order (SHA512_CTX *ctx, const void *in, size_t num) __attribute__ ((visibility (\"hidden\")));\n \n int SHA512_Final (unsigned char *md, SHA512_CTX *c)\n \t{\nIndex: openssl-1.0.1g/crypto/sha/sha_locl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/sha/sha_locl.h\n+++ openssl-1.0.1g/crypto/sha/sha_locl.h\n@@ -108,7 +108,7 @@ static void sha_block_data_order (SHA_CT\n #ifndef SHA1_ASM\n static\n #endif\n-void sha1_block_data_order (SHA_CTX *c, const void *p,size_t num);\n+void sha1_block_data_order (SHA_CTX *c, const void *p,size_t num) __attribute__ ((visibility (\"hidden\")));\n \n #else\n # error \"Either SHA_0 or SHA_1 must be defined.\"\nIndex: openssl-1.0.1g/crypto/store/str_locl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/store/str_locl.h\n+++ openssl-1.0.1g/crypto/store/str_locl.h\n@@ -62,6 +62,8 @@\n #include \n #include \n \n+#pragma GCC visibility push(hidden)\n+\n #ifdef __cplusplus\n extern \"C\" {\n #endif\n@@ -120,5 +122,5 @@ struct store_st\n #ifdef __cplusplus\n }\n #endif\n-\n+#pragma GCC visibility pop\n #endif\nIndex: openssl-1.0.1g/crypto/ui/ui_locl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/ui/ui_locl.h\n+++ openssl-1.0.1g/crypto/ui/ui_locl.h\n@@ -66,6 +66,8 @@\n #undef _\n #endif\n \n+#pragma GCC visibility push(hidden)\n+\n struct ui_method_st\n \t{\n \tchar *name;\n@@ -149,5 +151,5 @@ struct ui_st\n #define UI_FLAG_PRINT_ERRORS\t0x0100\n \tint flags;\n \t};\n-\n+#pragma GCC visibility pop\n #endif\nIndex: openssl-1.0.1g/crypto/whrlpool/wp_locl.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/whrlpool/wp_locl.h\n+++ openssl-1.0.1g/crypto/whrlpool/wp_locl.h\n@@ -1,3 +1,3 @@\n #include \n \n-void whirlpool_block(WHIRLPOOL_CTX *,const void *,size_t);\n+void whirlpool_block(WHIRLPOOL_CTX *,const void *,size_t) __attribute__ ((visibility (\"hidden\")));\nIndex: openssl-1.0.1g/crypto/x509v3/ext_dat.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/x509v3/ext_dat.h\n+++ openssl-1.0.1g/crypto/x509v3/ext_dat.h\n@@ -57,6 +57,8 @@\n */\n /* This file contains a table of \"standard\" extensions */\n \n+#pragma GCC visibility push(hidden)\n+\n extern X509V3_EXT_METHOD v3_bcons, v3_nscert, v3_key_usage, v3_ext_ku;\n extern X509V3_EXT_METHOD v3_pkey_usage_period, v3_sxnet, v3_info, v3_sinfo;\n extern X509V3_EXT_METHOD v3_ns_ia5_list[], v3_alt[], v3_skey_id, v3_akey_id;\n@@ -126,6 +128,7 @@ static const X509V3_EXT_METHOD *standard\n &v3_freshest_crl,\n };\n \n+#pragma GCC visibility pop\n /* Number of standard extensions */\n \n #define STANDARD_EXTENSION_COUNT (sizeof(standard_exts)/sizeof(X509V3_EXT_METHOD *))\nIndex: openssl-1.0.1g/crypto/x509v3/pcy_int.h\n===================================================================\n--- openssl-1.0.1g.orig/crypto/x509v3/pcy_int.h\n+++ openssl-1.0.1g/crypto/x509v3/pcy_int.h\n@@ -56,6 +56,7 @@\n *\n */\n \n+#pragma GCC visibility push(hidden)\n \n typedef struct X509_POLICY_DATA_st X509_POLICY_DATA;\n \n@@ -210,3 +211,5 @@ int policy_node_match(const X509_POLICY_\n \t\t const X509_POLICY_NODE *node, const ASN1_OBJECT *oid);\n \n const X509_POLICY_CACHE *policy_cache_set(X509 *x);\n+\n+#pragma GCC visibility pop\nIndex: openssl-1.0.1g/crypto/modes/gcm128.c\n===================================================================\n--- openssl-1.0.1g.orig/crypto/modes/gcm128.c\n+++ openssl-1.0.1g/crypto/modes/gcm128.c\n@@ -651,9 +651,9 @@ static void gcm_gmult_1bit(u64 Xi[2],con\n # define GCM_FUNCREF_4BIT\n extern unsigned int OPENSSL_ia32cap_P[2];\n \n-void gcm_init_clmul(u128 Htable[16],const u64 Xi[2]);\n-void gcm_gmult_clmul(u64 Xi[2],const u128 Htable[16]);\n-void gcm_ghash_clmul(u64 Xi[2],const u128 Htable[16],const u8 *inp,size_t len);\n+void gcm_init_clmul(u128 Htable[16],const u64 Xi[2]) __attribute__ ((visibility (\"hidden\")));\n+void gcm_gmult_clmul(u64 Xi[2],const u128 Htable[16]) __attribute__ ((visibility (\"hidden\")));\n+void gcm_ghash_clmul(u64 Xi[2],const u128 Htable[16],const u8 *inp,size_t len) __attribute__ ((visibility (\"hidden\")));\n \n # if\tdefined(__i386) || defined(__i386__) || defined(_M_IX86)\n # define GHASH_ASM_X86\nIndex: openssl-1.0.1g/crypto/evp/e_rc4_hmac_md5.c\n===================================================================\n--- openssl-1.0.1g.orig/crypto/evp/e_rc4_hmac_md5.c\n+++ openssl-1.0.1g/crypto/evp/e_rc4_hmac_md5.c\n@@ -78,7 +78,7 @@ typedef struct\n #define NO_PAYLOAD_LENGTH\t((size_t)-1)\n \n void rc4_md5_enc (RC4_KEY *key, const void *in0, void *out,\n-\t\tMD5_CTX *ctx,const void *inp,size_t blocks);\n+\t\tMD5_CTX *ctx,const void *inp,size_t blocks) __attribute__ ((visibility (\"hidden\")));\n \n #define data(ctx) ((EVP_RC4_HMAC_MD5 *)(ctx)->cipher_data)"}], "metadata": {"id": "openssl-4769-0001-libcrypto-Hide-library-pr", "cve_id": "CVE-2015-3197", "package": "openssl", "tier": "adapted", "has_source_context": true, "context_tokens_est": 3783, "context_files": 33, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-4658\n\nxpointer.c in libxml2 before 2.9.5 (as used in Apple iOS before 10, OS X before 10.12, tvOS before 10, and watchOS before 3, and other products) does not forbid namespace nodes in XPointer ranges, which allows remote attackers to execute arbitrary code or cause a denial of service (use-after-free and memory corruption) via a crafted XML document.\n\n## Package\nlibxml2\n\n## Files to modify\n- xzlib.c\n\n## Upstream Fix\n```diff\nFrom f0709e3ca8f8947f2d91ed34e92e38a4c23eae63 Mon Sep 17 00:00:00 2001\nFrom: Daniel Veillard \nDate: Tue, 3 Nov 2015 15:31:25 +0800\nSubject: [PATCH] CVE-2015-8035 Fix XZ compression support loop\n\nFor https://bugzilla.gnome.org/show_bug.cgi?id=757466\nDoS when parsing specially crafted XML document if XZ support\nis compiled in (which wasn't the case for 2.9.2 and master since\nNov 2013, fixed in next commit !)\n---\n xzlib.c | 4 ++++\n 1 file changed, 4 insertions(+)\n\ndiff --git a/xzlib.c b/xzlib.c\nindex 0dcb9f486f..1fab546316 100644\n--- a/xzlib.c\n+++ b/xzlib.c\n@@ -581,6 +581,10 @@ xz_decomp(xz_statep state)\n xz_error(state, LZMA_DATA_ERROR, \"compressed data error\");\n return -1;\n }\n+ if (ret == LZMA_PROG_ERROR) {\n+ xz_error(state, LZMA_PROG_ERROR, \"compression error\");\n+ return -1;\n+ }\n } while (strm->avail_out && ret != LZMA_STREAM_END);\n \n /* update available output and crc check value */\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From f0709e3ca8f8947f2d91ed34e92e38a4c23eae63 Mon Sep 17 00:00:00 2001\nFrom: Daniel Veillard \nDate: Tue, 3 Nov 2015 15:31:25 +0800\nSubject: CVE-2015-8035 Fix XZ compression support loop\n\nFor https://bugzilla.gnome.org/show_bug.cgi?id=757466\nDoS when parsing specially crafted XML document if XZ support\nis compiled in (which wasn't the case for 2.9.2 and master since\nNov 2013, fixed in next commit !)\n---\n xzlib.c | 4 ++++\n 1 file changed, 4 insertions(+)\n\ndiff --git a/xzlib.c b/xzlib.c\nindex 0dcb9f4..1fab546 100644\n--- a/xzlib.c\n+++ b/xzlib.c\n@@ -581,6 +581,10 @@ xz_decomp(xz_statep state)\n xz_error(state, LZMA_DATA_ERROR, \"compressed data error\");\n return -1;\n }\n+ if (ret == LZMA_PROG_ERROR) {\n+ xz_error(state, LZMA_PROG_ERROR, \"compression error\");\n+ return -1;\n+ }\n } while (strm->avail_out && ret != LZMA_STREAM_END);\n \n /* update available output and crc check value */\n-- \ncgit v0.11.2"}], "metadata": {"id": "libxml2-5762-libxml2-2.9.1-CVE-2015-8035.pa", "cve_id": "CVE-2016-4658", "package": "libxml2", "upstream_enriched": true, "upstream_commit": "f0709e3ca8f8947f2d91ed34e92e38a4c23eae63", "upstream_repo": "GNOME/libxml2", "tier": "adapted", "has_source_context": false, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-9556\n\nThe IsPixelGray function in MagickCore/pixel-accessor.h in ImageMagick 7.0.3-8 allows remote attackers to cause a denial of service (out-of-bounds heap read) via a crafted image file.\n\n## Package\nGraphicsMagick\n\n## Files to modify\n- GraphicsMagick-1.3.18.orig/magick/utility.c\n- magick/tempfile.h\n- GraphicsMagick-1.3.18.orig/magick/tempfile.c\n- GraphicsMagick-1.3.18.orig/magick/symbols.h\n- magick/utility.h\n\n## Upstream Fix\n```diff\nIndex: GraphicsMagick-1.3.18/magick/delegate.c\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/delegate.c\n+++ GraphicsMagick-1.3.18/magick/delegate.c\n@@ -539,7 +539,10 @@ MagickExport unsigned int InvokeDelegate\n char\n *command,\n **commands,\n- filename[MaxTextExtent];\n+ linkedname[MaxTextExtent],\n+ linkedinfoname[MaxTextExtent],\n+ filename[MaxTextExtent],\n+ safechars[]=\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,-_+ /\";\n \n const DelegateInfo\n *delegate_info;\n@@ -559,6 +562,10 @@ MagickExport unsigned int InvokeDelegate\n assert(image != (Image *) NULL);\n assert(image->signature == MagickSignature);\n temporary_image_filename=(*image->filename == '\\0');\n+ linkedname[0]='\\0';\n+ linkedname[MaxTextExtent-1]='\\0';\n+ linkedinfoname[0]='\\0';\n+ linkedinfoname[MaxTextExtent-1]='\\0';\n if (temporary_image_filename)\n {\n /* Allocate a temporary filename if image is unnamed. */\n@@ -568,12 +575,24 @@ MagickExport unsigned int InvokeDelegate\n return(False);\n }\n }\n+ else if (strspn(image->filename, safechars) != strlen(image->filename))\n+ {\n+ strncpy(linkedname,image->filename,MaxTextExtent-1);\n+ if (!AcquireTemporarySymlink(image->filename,linkedname))\n+\t{\n+ (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image->filename);\n+\t return (False);\n+\t}\n+ }\n+\n (void) strlcpy(filename,image->filename,MaxTextExtent);\n delegate_info=GetDelegateInfo(decode,encode,exception);\n if (delegate_info == (DelegateInfo *) NULL)\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+ if (*linkedname)\n+\tstrncpy(image->filename,linkedname,MaxTextExtent-1);\n (void) ThrowException(exception,DelegateError,NoTagFound,\n decode ? decode : encode);\n return(False);\n@@ -594,6 +613,18 @@ MagickExport unsigned int InvokeDelegate\n }\n image_info->temporary=True;\n }\n+ else if (strspn(image_info->filename, safechars) != strlen(image_info->filename))\n+ {\n+ strncpy(linkedinfoname,image_info->filename,MaxTextExtent-1);\n+ if (!AcquireTemporarySymlink(image_info->filename,linkedinfoname))\n+\t{\n+ if (temporary_image_filename)\n+ LiberateTemporaryFile(image->filename);\n+ (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->filename);\n+ return(False);\n+ }\n+ temporary_image_filename=True;\n+ }\n \n if (delegate_info->mode != 0)\n if ((decode && (delegate_info->encode != (char *) NULL)) ||\n@@ -617,6 +648,13 @@ MagickExport unsigned int InvokeDelegate\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->unique);\n return(False);\n }\n@@ -625,6 +663,13 @@ MagickExport unsigned int InvokeDelegate\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n (void) LiberateTemporaryFile(image_info->unique);\n (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->zero);\n return(False);\n@@ -638,6 +683,13 @@ MagickExport unsigned int InvokeDelegate\n (void) LiberateTemporaryFile(image_info->zero);\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n (void) ThrowException(exception,DelegateError,DelegateFailed,\n decode ? decode : encode);\n return(False);\n@@ -663,6 +715,13 @@ MagickExport unsigned int InvokeDelegate\n (void) LiberateTemporaryFile(image_info->zero);\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n DestroyImageInfo(clone_info);\n (void) ThrowException(exception,DelegateError,DelegateFailed,\n decode ? decode : encode);\n@@ -684,6 +743,13 @@ MagickExport unsigned int InvokeDelegate\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+ if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+ if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+ }\n (void) ThrowException(exception,ResourceLimitError,MemoryAllocationFailed,decode ? decode : encode);\n return(False);\n }\n@@ -810,6 +876,13 @@ MagickExport unsigned int InvokeDelegate\n error_exit:\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+ if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+ if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+ }\n for ( ; commands[i] != (char *) NULL; i++)\n MagickFreeMemory(commands[i]);\n MagickFreeMemory(commands);\nIndex: GraphicsMagick-1.3.18/magick/symbols.h\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/symbols.h\n+++ GraphicsMagick-1.3.18/magick/symbols.h\n@@ -43,6 +43,7 @@\n #define AcquireTemporaryFileDescriptor GmAcquireTemporaryFileDescriptor\n #define AcquireTemporaryFileName GmAcquireTemporaryFileName\n #define AcquireTemporaryFileStream GmAcquireTemporaryFileStream\n+#define AcquireTemporarySymlink GmAcquireTemporarySymlink\n #define AdaptiveThresholdImage GmAdaptiveThresholdImage\n #define AddDefinition GmAddDefinition\n #define AddDefinitions GmAddDefinitions\nIndex: GraphicsMagick-1.3.18/magick/tempfile.c\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/tempfile.c\n+++ GraphicsMagick-1.3.18/magick/tempfile.c\n@@ -192,6 +192,93 @@ MagickExport MagickPassFail AcquireTempo\n % %\n % %\n % %\n++ A c q u i r e T e m p o r a r y S y m l i n k %\n+% %\n+% %\n+% %\n+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n+%\n+% AcquireTemporarySymlink replaces the contents of the string buffer pointed\n+% to by filename with the unique name of a symbolic link. True is returned\n+% if a symlink\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "Index: GraphicsMagick-1.3.18/magick/delegate.c\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/delegate.c\n+++ GraphicsMagick-1.3.18/magick/delegate.c\n@@ -539,7 +539,10 @@ MagickExport unsigned int InvokeDelegate\n char\n *command,\n **commands,\n- filename[MaxTextExtent];\n+ linkedname[MaxTextExtent],\n+ linkedinfoname[MaxTextExtent],\n+ filename[MaxTextExtent],\n+ safechars[]=\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,-_+ /\";\n \n const DelegateInfo\n *delegate_info;\n@@ -559,6 +562,10 @@ MagickExport unsigned int InvokeDelegate\n assert(image != (Image *) NULL);\n assert(image->signature == MagickSignature);\n temporary_image_filename=(*image->filename == '\\0');\n+ linkedname[0]='\\0';\n+ linkedname[MaxTextExtent-1]='\\0';\n+ linkedinfoname[0]='\\0';\n+ linkedinfoname[MaxTextExtent-1]='\\0';\n if (temporary_image_filename)\n {\n /* Allocate a temporary filename if image is unnamed. */\n@@ -568,12 +575,24 @@ MagickExport unsigned int InvokeDelegate\n return(False);\n }\n }\n+ else if (strspn(image->filename, safechars) != strlen(image->filename))\n+ {\n+ strncpy(linkedname,image->filename,MaxTextExtent-1);\n+ if (!AcquireTemporarySymlink(image->filename,linkedname))\n+\t{\n+ (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image->filename);\n+\t return (False);\n+\t}\n+ }\n+\n (void) strlcpy(filename,image->filename,MaxTextExtent);\n delegate_info=GetDelegateInfo(decode,encode,exception);\n if (delegate_info == (DelegateInfo *) NULL)\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+ if (*linkedname)\n+\tstrncpy(image->filename,linkedname,MaxTextExtent-1);\n (void) ThrowException(exception,DelegateError,NoTagFound,\n decode ? decode : encode);\n return(False);\n@@ -594,6 +613,18 @@ MagickExport unsigned int InvokeDelegate\n }\n image_info->temporary=True;\n }\n+ else if (strspn(image_info->filename, safechars) != strlen(image_info->filename))\n+ {\n+ strncpy(linkedinfoname,image_info->filename,MaxTextExtent-1);\n+ if (!AcquireTemporarySymlink(image_info->filename,linkedinfoname))\n+\t{\n+ if (temporary_image_filename)\n+ LiberateTemporaryFile(image->filename);\n+ (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->filename);\n+ return(False);\n+ }\n+ temporary_image_filename=True;\n+ }\n \n if (delegate_info->mode != 0)\n if ((decode && (delegate_info->encode != (char *) NULL)) ||\n@@ -617,6 +648,13 @@ MagickExport unsigned int InvokeDelegate\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->unique);\n return(False);\n }\n@@ -625,6 +663,13 @@ MagickExport unsigned int InvokeDelegate\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n (void) LiberateTemporaryFile(image_info->unique);\n (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->zero);\n return(False);\n@@ -638,6 +683,13 @@ MagickExport unsigned int InvokeDelegate\n (void) LiberateTemporaryFile(image_info->zero);\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n (void) ThrowException(exception,DelegateError,DelegateFailed,\n decode ? decode : encode);\n return(False);\n@@ -663,6 +715,13 @@ MagickExport unsigned int InvokeDelegate\n (void) LiberateTemporaryFile(image_info->zero);\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n DestroyImageInfo(clone_info);\n (void) ThrowException(exception,DelegateError,DelegateFailed,\n decode ? decode : encode);\n@@ -684,6 +743,13 @@ MagickExport unsigned int InvokeDelegate\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+ if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+ if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+ }\n (void) ThrowException(exception,ResourceLimitError,MemoryAllocationFailed,decode ? decode : encode);\n return(False);\n }\n@@ -810,6 +876,13 @@ MagickExport unsigned int InvokeDelegate\n error_exit:\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+ if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+ if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+ }\n for ( ; commands[i] != (char *) NULL; i++)\n MagickFreeMemory(commands[i]);\n MagickFreeMemory(commands);\nIndex: GraphicsMagick-1.3.18/magick/symbols.h\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/symbols.h\n+++ GraphicsMagick-1.3.18/magick/symbols.h\n@@ -43,6 +43,7 @@\n #define AcquireTemporaryFileDescriptor GmAcquireTemporaryFileDescriptor\n #define AcquireTemporaryFileName GmAcquireTemporaryFileName\n #define AcquireTemporaryFileStream GmAcquireTemporaryFileStream\n+#define AcquireTemporarySymlink GmAcquireTemporarySymlink\n #define AdaptiveThresholdImage GmAdaptiveThresholdImage\n #define AddDefinition GmAddDefinition\n #define AddDefinitions GmAddDefinitions\nIndex: GraphicsMagick-1.3.18/magick/tempfile.c\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/tempfile.c\n+++ GraphicsMagick-1.3.18/magick/tempfile.c\n@@ -192,6 +192,93 @@ MagickExport MagickPassFail AcquireTempo\n % %\n % %\n % %\n++ A c q u i r e T e m p o r a r y S y m l i n k %\n+% %\n+% %\n+% %\n+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n+%\n+% AcquireTemporarySymlink replaces the contents of the string buffer pointed\n+% to by filename with the unique name of a symbolic link. True is returned\n+% if a symlink waas created, or False is returned if there is a failure.\n+% The allocated symlink should be recovered via the LiberateTemporaryFile()\n+% function once it is no longer required.\n+%\n+% The format of the AcquireTemporarySymlink method is:\n+%\n+% unsigned int AcquireTemporarySymlink(char *linkname, const char *name,\n+% ExceptionInfo *exception)\n+%\n+% A description of each parameter follows.\n+%\n+% o linkname: Specifies a pointer to an array of characters that must be\n+% MaxTextExtent characters of size. The unique\n+% name of the symlink is returned in this array.\n+% o name: Specifies a file name the symlink should point to.\n+*/\n+MagickExport unsigned int AcquireTemporarySymlink(char *linkname, const char *name)\n+{\n+ char\n+ *tempdir,\n+ tempname[MaxTextExtent];\n+\n+ int\n+ fd,\n+ tries;\n+ \n+ assert(linkname != (char *)NULL);\n+ linkname[0]='\\0';\n+ tempname[MaxTextExtent-1]='\\0';\n+\n+ tempdir=getenv(\"MAGICK_TMPDIR\");\n+#if defined(POSIX)\n+ if (!tempdir)\n+ tempdir=getenv(\"TMPDIR\");\n+#endif /* POSIX */\n+#if defined(WIN32)\n+ if (!tempdir)\n+ tempdir=getenv(\"TMP\");\n+ if (!tempdir)\n+ tempdir=getenv(\"TEMP\");\n+#endif /* WIN32 */\n+#if defined(P_tmpdir)\n+ if (!tempdir)\n+ tempdir=P_tmpdir;\n+#endif\n+\n+ for (tries=0; tries < 15; tries++)\n+ {\n+ strncpy(tempname,\"gmXXXXXX\",MaxTextExtent-1);\n+ ComposeTemporaryFileName(tempname);\n+ strncpy(linkname,tempdir,MaxTextExtent-1);\n+ if (tempdir[strlen(tempdir)-1] != DirectorySeparator[0])\n+\tstrncat(linkname,DirectorySeparator,MaxTextExtent-1);\n+ strncat(linkname,tempname,MaxTextExtent-1);\n+ if (*name == '/')\n+ fd=symlink(name, linkname);\n+ else\n+ {\n+ char cname[MaxTextExtent];\n+\t if (!getcwd(cname,(size_t)MaxTextExtent))\n+\t return (False);\n+\t strncat(cname,DirectorySeparator,MaxTextExtent-1);\n+\t strncat(cname,name,MaxTextExtent-1);\n+\t fd=symlink(cname,linkname);\n+\t}\n+ if (fd != -1)\n+\t{\n+\t AddTemporaryFileToList(linkname);\n+\t return (True);\n+\t}\n+ }\n+ return (False);\n+}\n+\f\n+/*\n+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n+% %\n+% %\n+% %\n + A c q u i r e T e m p o r a r y F i l e D e s c r i p t o r %\n % %\n % %\nIndex: GraphicsMagick-1.3.18/magick/tempfile.h\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/tempfile.h\n+++ GraphicsMagick-1.3.18/magick/tempfile.h\n@@ -24,6 +24,7 @@ typedef enum\n \n MagickExport MagickPassFail\n AcquireTemporaryFileName(char *filename),\n+ AcquireTemporarySymlink(char *linkname, const char *name),\n LiberateTemporaryFile(char *filename);\n \n MagickExport int\nIndex: GraphicsMagick-1.3.18/magick/utility.c\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/utility.c\n+++ GraphicsMagick-1.3.18/magick/utility.c\n@@ -1253,6 +1253,72 @@ MagickExport void FormatString(char *str\n % %\n % %\n % %\n+% F o r m a t S t r i n g N u m e r i c %\n+% %\n+% %\n+% %\n+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n+%\n+% Method FormatStringNumeric formats output for a single numeric argument.\n+% It takes into account that the format string given might be untrusted\n+% user input, and returns a pointer to the formatted string.\n+%\n+% The format of the FormatStringNumeric method is:\n+%\n+% char * FormatStringNumeric(char *string,const char *format,int value)\n+%\n+% A description of each parameter follows.\n+%\n+% o format: A string describing the format to use to write the numeric\n+% argument. Only the first numeric format identifier is replaced.\n+%\n+% o value: Numeric value to substitute into format string.\n+%\n+%\n+*/\n+MagickExport char *FormatStringNumeric(const char *format,int value)\n+{\n+ char\n+ *p,\n+ *string;\n+\n+ string = NULL;\n+\n+ (void) CloneString(&string, format);\n+\n+ for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))\n+ { \n+ char\n+ *q;\n+\n+ q=(char *) p+1;\n+ if (*q == '0')\n+ (void) strtol(q,&q,10);\n+ if ((*q == '%') || (*q == 'd') || (*q == 'o') || (*q == 'x'))\n+ {\n+ char\n+ c;\n+\n+ q++;\n+ c=*q;\n+ *q='\\0';\n+ (void) snprintf(string+(p-format),MaxTextExtent-(p-format),p,value);\n+ *q=c;\n+ (void) ConcatenateString(&string,q);\n+ if (*(q-1) == '%')\n+ p++;\n+ else\n+ break;\n+ }\n+ }\n+ return string;\n+}\n+\f\n+/*\n+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n+% %\n+% %\n+% %\n % G e t E x e c u t i o n P a t h %\n % %\n % %\nIndex: GraphicsMagick-1.3.18/magick/utility.h\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/utility.h\n+++ GraphicsMagick-1.3.18/magick/utility.h\n@@ -72,6 +72,7 @@ extern MagickExport char\n *AllocateString(const char *),\n *Base64Encode(const unsigned char *,const size_t,size_t *),\n *EscapeString(const char *,const char),\n+ *FormatStringNumeric(const char *,int),\n *GetPageGeometry(const char *),\n **ListFiles(const char *,const char *,long *),\n **StringToArgv(const char *,int *),"}], "metadata": {"id": "GraphicsMagick-5955-GraphicsMagick-debian-fixed.pa", "cve_id": "CVE-2016-9556", "package": "GraphicsMagick", "tier": "adapted", "has_source_context": false, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-4658\n\nxpointer.c in libxml2 before 2.9.5 (as used in Apple iOS before 10, OS X before 10.12, tvOS before 10, and watchOS before 3, and other products) does not forbid namespace nodes in XPointer ranges, which allows remote attackers to execute arbitrary code or cause a denial of service (use-after-free and memory corruption) via a crafted XML document.\n\n## Package\nlibxml2\n\n## Files to modify\n- dict.c\n\n## Upstream Fix\n```diff\nFrom 6360a31a84efe69d155ed96306b9a931a40beab9 Mon Sep 17 00:00:00 2001\nFrom: David Drysdale \nDate: Fri, 20 Nov 2015 10:47:12 +0800\nSubject: [PATCH] CVE-2015-7497 Avoid an heap buffer overflow in\n xmlDictComputeFastQKey\n\nFor https://bugzilla.gnome.org/show_bug.cgi?id=756528\nIt was possible to hit a negative offset in the name indexing\nused to randomize the dictionary key generation\nReported and fix provided by David Drysdale @ Google\n---\n dict.c | 5 ++++-\n 1 file changed, 4 insertions(+), 1 deletion(-)\n\ndiff --git a/dict.c b/dict.c\nindex 5f71d55d73..8c8f93148b 100644\n--- a/dict.c\n+++ b/dict.c\n@@ -486,7 +486,10 @@ xmlDictComputeFastQKey(const xmlChar *prefix, int plen,\n \tvalue += 30 * (*prefix);\n \n if (len > 10) {\n- value += name[len - (plen + 1 + 1)];\n+ int offset = len - (plen + 1 + 1);\n+\tif (offset < 0)\n+\t offset = len - (10 + 1);\n+\tvalue += name[offset];\n len = 10;\n \tif (plen > 10)\n \t plen = 10;\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From 6360a31a84efe69d155ed96306b9a931a40beab9 Mon Sep 17 00:00:00 2001\nFrom: David Drysdale \nDate: Fri, 20 Nov 2015 10:47:12 +0800\nSubject: CVE-2015-7497 Avoid an heap buffer overflow in xmlDictComputeFastQKey\n\nFor https://bugzilla.gnome.org/show_bug.cgi?id=756528\nIt was possible to hit a negative offset in the name indexing\nused to randomize the dictionary key generation\nReported and fix provided by David Drysdale @ Google\n---\n dict.c | 5 ++++-\n 1 file changed, 4 insertions(+), 1 deletion(-)\n\ndiff --git a/dict.c b/dict.c\nindex 5f71d55..8c8f931 100644\n--- a/dict.c\n+++ b/dict.c\n@@ -486,7 +486,10 @@ xmlDictComputeFastQKey(const xmlChar *prefix, int plen,\n \tvalue += 30 * (*prefix);\n \n if (len > 10) {\n- value += name[len - (plen + 1 + 1)];\n+ int offset = len - (plen + 1 + 1);\n+\tif (offset < 0)\n+\t offset = len - (10 + 1);\n+\tvalue += name[offset];\n len = 10;\n \tif (plen > 10)\n \t plen = 10;\n-- \ncgit v0.11.2"}], "metadata": {"id": "libxml2-5762-libxml2-2.9.1-CVE-2015-7497.pa", "cve_id": "CVE-2016-4658", "package": "libxml2", "upstream_enriched": true, "upstream_commit": "6360a31a84efe69d155ed96306b9a931a40beab9", "upstream_repo": "GNOME/libxml2", "tier": "adapted", "has_source_context": false, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-4658\n\nxpointer.c in libxml2 before 2.9.5 (as used in Apple iOS before 10, OS X before 10.12, tvOS before 10, and watchOS before 3, and other products) does not forbid namespace nodes in XPointer ranges, which allows remote attackers to execute arbitrary code or cause a denial of service (use-after-free and memory corruption) via a crafted XML document.\n\n## Package\nlibxml2\n\n## Files to modify\n- parser.c\n\n## Target Source Code\n\n### parser.c\n\n#### xmlParserEntityCheck() [lines 91-177]\n```c\n \"Memory allocation failed : %s\\n\", extra);\n else\n __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER,\n XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0, NULL,\n NULL, NULL, 0, 0, \"Memory allocation failed\\n\");\n}\n\n/**\n * htmlParseErr:\n * @ctxt: an HTML parser context\n * @error: the error number\n * @msg: the error message\n * @str1: string infor\n * @str2: string infor\n *\n * Handle a fatal parser error, i.e. violating Well-Formedness constraints\n */\nstatic void\nhtmlParseErr(xmlParserCtxtPtr ctxt, xmlParserErrors error,\n const char *msg, const xmlChar *str1, const xmlChar *str2)\n{\n if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&\n (ctxt->instate == XML_PARSER_EOF))\n\treturn;\n if (ctxt != NULL)\n\tctxt->errNo = error;\n __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_HTML, error,\n XML_ERR_ERROR, NULL, 0,\n\t\t (const char *) str1, (const char *) str2,\n\t\t NULL, 0, 0,\n\t\t msg, str1, str2);\n if (ctxt != NULL)\n\tctxt->wellFormed = 0;\n}\n\n/**\n * htmlParseErrInt:\n * @ctxt: an HTML parser context\n * @error: the error number\n * @msg: the error message\n * @val: integer info\n *\n * Handle a fatal parser error, i.e. violating Well-Formedness constraints\n */\nstatic void\nhtmlParseErrInt(xmlParserCtxtPtr ctxt, xmlParserErrors error,\n const char *msg, int val)\n{\n if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&\n (ctxt->instate == XML_PARSER_EOF))\n\treturn;\n if (ctxt != NULL)\n\tctxt->errNo = error;\n __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_HTML, error,\n XML_ERR_ERROR, NULL, 0, NULL, NULL,\n\t\t NULL, val, 0, msg, val);\n if (ctxt != NULL)\n\tctxt->wellFormed = 0;\n}\n\n/************************************************************************\n *\t\t\t\t\t\t\t\t\t*\n *\tParser stacks related functions and macros\t\t*\n *\t\t\t\t\t\t\t\t\t*\n ************************************************************************/\n\n/**\n * htmlnamePush:\n * @ctxt: an HTML parser context\n * @value: the element name\n *\n * Pushes a new element name on top of the name stack\n *\n * Returns 0 in case of error, the index in the stack otherwise\n */\nstatic int\nhtmlnamePush(htmlParserCtxtPtr ctxt, const xmlChar * value)\n{\n if ((ctxt->html < 3) && (xmlStrEqual(value, BAD_CAST \"head\")))\n ctxt->html = 3;\n if ((ctxt->html < 10) && (xmlStrEqual(value, BAD_CAST \"body\")))\n ctxt->html = 10;\n if (ctxt->nameNr >= ctxt->nameMax) {\n ctxt->nameMax *= 2;\n ctxt->nameTab = (const xmlChar * *)\n xmlRealloc((xmlChar * *)ctxt->nameTab,\n ctxt->nameMax *\n```\n\n#### xmlParserEntityCheck() [lines 150-239]\n```c\n\n/************************************************************************\n *\t\t\t\t\t\t\t\t\t*\n *\tParser stacks related functions and macros\t\t*\n *\t\t\t\t\t\t\t\t\t*\n ************************************************************************/\n\n/**\n * htmlnamePush:\n * @ctxt: an HTML parser context\n * @value: the element name\n *\n * Pushes a new element name on top of the name stack\n *\n * Returns 0 in case of error, the index in the stack otherwise\n */\nstatic int\nhtmlnamePush(htmlParserCtxtPtr ctxt, const xmlChar * value)\n{\n if ((ctxt->html < 3) && (xmlStrEqual(value, BAD_CAST \"head\")))\n ctxt->html = 3;\n if ((ctxt->html < 10) && (xmlStrEqual(value, BAD_CAST \"body\")))\n ctxt->html = 10;\n if (ctxt->nameNr >= ctxt->nameMax) {\n ctxt->nameMax *= 2;\n ctxt->nameTab = (const xmlChar * *)\n xmlRealloc((xmlChar * *)ctxt->nameTab,\n ctxt->nameMax *\n sizeof(ctxt->nameTab[0]));\n if (ctxt->nameTab == NULL) {\n htmlErrMemory(ctxt, NULL);\n return (0);\n }\n }\n ctxt->nameTab[ctxt->nameNr] = value;\n ctxt->name = value;\n return (ctxt->nameNr++);\n}\n/**\n * htmlnamePop:\n * @ctxt: an HTML parser context\n *\n * Pops the top element name from the name stack\n *\n * Returns the name just removed\n */\nstatic const xmlChar *\nhtmlnamePop(htmlParserCtxtPtr ctxt)\n{\n const xmlChar *ret;\n\n if (ctxt->nameNr <= 0)\n return (NULL);\n ctxt->nameNr--;\n if (ctxt->nameNr < 0)\n return (NULL);\n if (ctxt->nameNr > 0)\n ctxt->name = ctxt->nameTab[ctxt->nameNr - 1];\n else\n ctxt->name = NULL;\n ret = ctxt->nameTab[ctxt->nameNr];\n ctxt->nameTab[ctxt->nameNr] = NULL;\n return (ret);\n}\n\n/**\n * htmlNodeInfoPush:\n * @ctxt: an HTML parser context\n * @value: the node info\n *\n * Pushes a new element name on top of the node info stack\n *\n * Returns 0 in case of error, the index in the stack otherwise\n */\nstatic int\nhtmlNodeInfoPush(htmlParserCtxtPtr ctxt, htmlParserNodeInfo *value)\n{\n if (ctxt->nodeInfoNr >= ctxt->nodeInfoMax) {\n if (ctxt->nodeInfoMax == 0)\n ctxt->nodeInfoMax = 5;\n ctxt->nodeInfoMax *= 2;\n ctxt->nodeInfoTab = (htmlParserNodeInfo *)\n xmlRealloc((htmlParserNodeInfo *)ctxt->nodeInfoTab,\n ctxt->nodeInfoMax *\n sizeof(ctxt->nodeInfoTab[0]));\n if (ctxt->nodeInfoTab == NULL) {\n htmlErrMemory(ctxt, NULL);\n return (0);\n }\n }\n```\n\n#### xmlParserHandlePEReference() [lines 2584-2594]\n```c\n\t\tent = htmlParseEntityRef(ctxt, &name);\n\t\tif (name == NULL) {\n\t\t *out++ = '&';\n\t\t if (out - buffer > buffer_size - 100) {\n\t\t\tint indx = out - buffer;\n\n\t\t\tgrowBuffer(buffer);\n\t\t\tout = &buffer[indx];\n\t\t }\n\t\t} else if (ent == NULL) {\n\t\t *out++ = '&';\n```\n\n#### xmlStringLenDecodeEntities() [lines 2735-2781]\n```c\n NEXT;\n\tret = htmlParseHTMLAttribute(ctxt, '\\'');\n if (CUR != '\\'') {\n\t htmlParseErr(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,\n\t \"AttValue: ' expected\\n\", NULL, NULL);\n\t} else\n\t NEXT;\n } else {\n /*\n\t * That's an HTMLism, the attribute value may not be quoted\n\t */\n\tret = htmlParseHTMLAttribute(ctxt, 0);\n\tif (ret == NULL) {\n\t htmlParseErr(ctxt, XML_ERR_ATTRIBUTE_WITHOUT_VALUE,\n\t \"AttValue: no value found\\n\", NULL, NULL);\n\t}\n }\n return(ret);\n}\n\n/**\n * htmlParseSystemLiteral:\n * @ctxt: an HTML parser context\n *\n * parse an HTML Literal\n *\n * [11] SystemLiteral ::= ('\"' [^\"]* '\"') | (\"'\" [^']* \"'\")\n *\n * Returns the SystemLiteral parsed or NULL\n */\n\nstatic xmlChar *\nhtmlParseSystemLiteral(htmlParserCtxtPtr ctxt) {\n const xmlChar *q;\n xmlChar *ret = NULL;\n\n if (CUR == '\"') {\n NEXT;\n\tq = CUR_PTR;\n\twhile ((IS_CHAR_CH(CUR)) && (CUR != '\"'))\n\t NEXT;\n\tif (!IS_CHAR_CH(CUR)) {\n\t htmlParseErr(ctxt, XML_ERR_LITERAL_NOT_FINISHED,\n\t\t\t \"Unfinished SystemLiteral\\n\", NULL, NULL);\n\t} else {\n\t ret = xmlStrndup(q, CUR_PTR - q);\n\t NEXT;\n```\n\n#### xmlStringLenDecodeEntities() [lines 2771-2857]\n```c\n if (CUR == '\"') {\n NEXT;\n\tq = CUR_PTR;\n\twhile ((IS_CHAR_CH(CUR)) && (CUR != '\"'))\n\t NEXT;\n\tif (!IS_CHAR_CH(CUR)) {\n\t htmlParseErr(ctxt, XML_ERR_LITERAL_NOT_FINISHED,\n\t\t\t \"Unfinished SystemLiteral\\n\", NULL, NULL);\n\t} else {\n\t ret = xmlStrndup(q, CUR_PTR - q);\n\t NEXT;\n }\n } else if (CUR == '\\'') {\n NEXT;\n\tq = CUR_PTR;\n\twhile ((IS_CHAR_CH(CUR)) && (CUR != '\\''))\n\t NEXT;\n\tif (!IS_CHAR_CH(CUR)) {\n\t htmlParseErr(ctxt, XML_ERR_LITERAL_NOT_FINISHED,\n\t\t\t \"Unfinished SystemLiteral\\n\", NULL, NULL);\n\t} else {\n\t ret = xmlStrndup(q, CUR_PTR - q);\n\t NEXT;\n }\n } else {\n\thtmlParseErr(ctxt, XML_ERR_LITERAL_NOT_STARTED,\n\t \" or ' expected\\n\", NULL, NULL);\n }\n\n return(ret);\n}\n\n/**\n * htmlParsePubidLiteral:\n * @ctxt: an HTML parser context\n *\n * parse an HTML public literal\n *\n * [12] PubidLiteral ::= '\"' PubidChar* '\"' | \"'\" (PubidChar - \"'\")* \"'\"\n *\n * Returns the PubidLiteral parsed or NULL.\n */\n\nstatic xmlChar *\nhtmlParsePubidLiteral(htmlParserCtxtPtr ctxt) {\n const xmlChar *q;\n xmlChar *ret = NULL;\n /*\n * Name ::= (Letter | '_') (NameChar)*\n */\n if (CUR == '\"') {\n NEXT;\n\tq = CUR_PTR;\n\twhile (IS_PUBIDCHAR_CH(CUR)) NEXT;\n\tif (CUR != '\"') {\n\t htmlParseErr(ctxt, XML_ERR_LITERAL_NOT_FINISHED,\n\t \"Unfinished PubidLiteral\\n\", NULL, NULL);\n\t} else {\n\t ret = xmlStrndup(q, CUR_PTR - q);\n\t NEXT;\n\t}\n } else if (CUR == '\\'') {\n NEXT;\n\tq = CUR_PTR;\n\twhile ((IS_PUBIDCHAR_CH(CUR)) && (CUR != '\\''))\n\t NEXT;\n\tif (CUR != '\\'') {\n\t htmlParseErr(ctxt, XML_ERR_LITERAL_NOT_FINISHED,\n\t \"Unfinished PubidLiteral\\n\", NULL, NULL);\n\t} else {\n\t ret = xmlStrndup(q, CUR_PTR - q);\n\t NEXT;\n\t}\n } else {\n\thtmlParseErr(ctxt, XML_ERR_LITERAL_NOT_STARTED,\n\t \"PubidLiteral \\\" or ' expected\\n\", NULL, NULL);\n }\n\n return(ret);\n}\n\n/**\n * htmlParseScript:\n * @ctxt: an HTML parser context\n *\n * parse the content of an HTML SCRIPT or STYLE element\n * http://www.w3.org/TR/html4/sgml/dtd.html#Script\n```\n\n#### xmlParseReference() [lines 7273-7078]\n```c\n\n```\n\n#### xmlParseReference() [lines 7379-7078]\n```c\n\n```\n\n#### xmlParseReference() [lines 7427-7078]\n```c\n\n```\n\n#### xmlParseEntityRef() [lines 7613-7078]\n```c\n\n```\n\n#### xmlParseStringEntityRef() [lines 7806-7078]\n```c\n\n```\n\n#### xmlParsePEReference() [lines 7965-7078]\n```c\n\n```\n\n#### xmlParseStringPEReference() [lines 8204-7078]\n```c\n\n```\n\n\n## Upstream Fix\n```diff\nFrom be2a7edaf289c5da74a4f9ed3a0b6c733e775230 Mon Sep 17 00:00:00 2001\nFrom: Daniel Veillard \nDate: Thu, 16 Oct 2014 13:59:47 +0800\nSubject: [PATCH] Fix for CVE-2014-3660\n\nIssues related to the billion laugh entity expansion which happened to\nescape the initial set of fixes\n---\n parser.c | 42 ++++++++++++++++++++++++++++++++++++++----\n 1 file changed, 38 insertions(+), 4 deletions(-)\n\ndiff --git a/parser.c b/parser.c\nindex f51e8d253f..1d9396786b 100644\n--- a/parser.c\n+++ b/parser.c\n@@ -130,6 +130,29 @@ xmlParserEntityCheck(xmlParserCtxtPtr ctxt, size_t size,\n return (0);\n if (ctxt->lastError.code == XML_ERR_ENTITY_LOOP)\n return (1);\n+\n+ /*\n+ * This may look absurd but is needed to detect\n+ * entities problems\n+ */\n+ if ((ent != NULL) && (ent->etype != XML_INTERNAL_PREDEFINED_ENTITY) &&\n+\t(ent->content != NULL) && (ent->checked == 0)) {\n+\tunsigned long oldnbent = ctxt->nbentities;\n+\txmlChar *rep;\n+\n+\tent->checked = 1;\n+\n+\trep = xmlStringDecodeEntities(ctxt, ent->content,\n+\t\t\t\t XML_SUBSTITUTE_REF, 0, 0, 0);\n+\n+\tent->checked = (ctxt->nbentities - oldnbent + 1) * 2;\n+\tif (rep != NULL) {\n+\t if (xmlStrchr(rep, '<'))\n+\t\tent->checked |= 1;\n+\t xmlFree(rep);\n+\t rep = NULL;\n+\t}\n+ }\n if (replacement != 0) {\n \tif (replacement < XML_MAX_TEXT_LENGTH)\n \t return(0);\n@@ -189,9 +212,12 @@ xmlParserEntityCheck(xmlParserCtxtPtr ctxt, size_t size,\n return (0);\n } else {\n /*\n- * strange we got no data for checking just return\n+ * strange we got no data for checking\n */\n- return (0);\n+\tif (((ctxt->lastError.code != XML_ERR_UNDECLARED_ENTITY) &&\n+\t (ctxt->lastError.code != XML_WAR_UNDECLARED_ENTITY)) ||\n+\t (ctxt->nbentities <= 10000))\n+\t return (0);\n }\n xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);\n return (1);\n@@ -2589,6 +2615,7 @@ xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) {\n \t\t\t\t name, NULL);\n \t\t ctxt->valid = 0;\n \t\t}\n+\t\txmlParserEntityCheck(ctxt, 0, NULL, 0);\n \t } else if (ctxt->input->free != deallocblankswrapper) {\n \t\t input = xmlNewBlanksWrapperInputStream(ctxt, entity);\n \t\t if (xmlPushInput(ctxt, input) < 0)\n@@ -2759,6 +2786,7 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int len,\n \t if ((ctxt->lastError.code == XML_ERR_ENTITY_LOOP) ||\n \t (ctxt->lastError.code == XML_ERR_INTERNAL_ERROR))\n \t goto int_error;\n+\t xmlParserEntityCheck(ctxt, 0, ent, 0);\n \t if (ent != NULL)\n \t ctxt->nbentities += ent->checked / 2;\n \t if ((ent != NULL) &&\n@@ -2810,6 +2838,7 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int len,\n \t ent = xmlParseStringPEReference(ctxt, &str);\n \t if (ctxt->lastError.code == XML_ERR_ENTITY_LOOP)\n \t goto int_error;\n+\t xmlParserEntityCheck(ctxt, 0, ent, 0);\n \t if (ent != NULL)\n \t ctxt->nbentities += ent->checked / 2;\n \t if (ent != NULL) {\n@@ -7312,6 +7341,7 @@ xmlParseReference(xmlParserCtxtPtr ctxt) {\n \t\t (ret != XML_WAR_UNDECLARED_ENTITY)) {\n \t xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY,\n \t\t \"Entity '%s' failed to parse\\n\", ent->name);\n+\t xmlParserEntityCheck(ctxt, 0, ent, 0);\n \t} else if (list != NULL) {\n \t xmlFreeNodeList(list);\n \t list = NULL;\n@@ -7418,7 +7448,7 @@ xmlParseReference(xmlParserCtxtPtr ctxt) {\n \t\t/*\n \t\t * We are copying here, make sure there is no abuse\n \t\t */\n-\t\tctxt->sizeentcopy += ent->length;\n+\t\tctxt->sizeentcopy += ent->length + 5;\n \t\tif (xmlParserEntityCheck(ctxt, 0, ent, ctxt->sizeentcopy))\n \t\t return;\n \n@@ -7466,7 +7496,7 @@ xmlParseReference(xmlParserCtxtPtr ctxt) {\n \t\t/*\n \t\t * We are copying here, make sure there is no abuse\n \t\t */\n-\t\tctxt->sizeentcopy += ent->length;\n+\t\tctxt->sizeentcopy += ent->length + 5;\n \t\tif (xmlParserEntityCheck(ctxt, 0, ent, ctxt->sizeentcopy))\n \t\t return;\n \n@@ -7652,6 +7682,7 @@ xmlParseEntityRef(xmlParserCtxtPtr ctxt) {\n \t\tctxt->sax->reference(ctxt->userData, name);\n \t }\n \t}\n+\txmlParserEntityCheck(ctxt, 0, ent, 0);\n \tctxt->valid = 0;\n }\n \n@@ -7845,6 +7876,7 @@ xmlParseStringEntityRef(xmlParserCtxtPtr ctxt, const xmlChar ** str) {\n \t\t\t \"Entity '%s' not defined\\n\",\n \t\t\t name);\n \t}\n+\txmlParserEntityCheck(ctxt, 0, ent, 0);\n \t/* TODO ? check regressions ctxt->valid = 0; */\n }\n \n@@ -8004,6 +8036,7 @@ xmlParsePEReference(xmlParserCtxtPtr ctxt)\n \t\t\t name, NULL);\n \t ctxt->valid = 0;\n \t}\n+\txmlParserEntityCheck(ctxt, 0, NULL, 0);\n } else {\n \t/*\n \t * Internal checking in case the entity quest barfed\n@@ -8243,6 +8276,7 @@ xmlParseStringPEReference(xmlParserCtxtPtr ctxt, const xmlChar **str) {\n \t\t\t name, NULL);\n \t ctxt->valid = 0;\n \t}\n+\txmlParserEntityCheck(ctxt, 0, NULL, 0);\n } else {\n \t/*\n \t * Internal checking in case the entity quest barfed\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From be2a7edaf289c5da74a4f9ed3a0b6c733e775230 Mon Sep 17 00:00:00 2001\nFrom: Daniel Veillard \nDate: Thu, 16 Oct 2014 13:59:47 +0800\nSubject: Fix for CVE-2014-3660\n\nIssues related to the billion laugh entity expansion which happened to\nescape the initial set of fixes\n\ndiff --git a/parser.c b/parser.c\nindex f51e8d2..1d93967 100644\n--- a/parser.c\n+++ b/parser.c\n@@ -130,6 +130,29 @@ xmlParserEntityCheck(xmlParserCtxtPtr ctxt, size_t size,\n return (0);\n if (ctxt->lastError.code == XML_ERR_ENTITY_LOOP)\n return (1);\n+\n+ /*\n+ * This may look absurd but is needed to detect\n+ * entities problems\n+ */\n+ if ((ent != NULL) && (ent->etype != XML_INTERNAL_PREDEFINED_ENTITY) &&\n+\t(ent->content != NULL) && (ent->checked == 0)) {\n+\tunsigned long oldnbent = ctxt->nbentities;\n+\txmlChar *rep;\n+\n+\tent->checked = 1;\n+\n+\trep = xmlStringDecodeEntities(ctxt, ent->content,\n+\t\t\t\t XML_SUBSTITUTE_REF, 0, 0, 0);\n+\n+\tent->checked = (ctxt->nbentities - oldnbent + 1) * 2;\n+\tif (rep != NULL) {\n+\t if (xmlStrchr(rep, '<'))\n+\t\tent->checked |= 1;\n+\t xmlFree(rep);\n+\t rep = NULL;\n+\t}\n+ }\n if (replacement != 0) {\n \tif (replacement < XML_MAX_TEXT_LENGTH)\n \t return(0);\n@@ -189,9 +212,12 @@ xmlParserEntityCheck(xmlParserCtxtPtr ctxt, size_t size,\n return (0);\n } else {\n /*\n- * strange we got no data for checking just return\n+ * strange we got no data for checking\n */\n- return (0);\n+\tif (((ctxt->lastError.code != XML_ERR_UNDECLARED_ENTITY) &&\n+\t (ctxt->lastError.code != XML_WAR_UNDECLARED_ENTITY)) ||\n+\t (ctxt->nbentities <= 10000))\n+\t return (0);\n }\n xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);\n return (1);\n@@ -2589,6 +2615,7 @@ xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) {\n \t\t\t\t name, NULL);\n \t\t ctxt->valid = 0;\n \t\t}\n+\t\txmlParserEntityCheck(ctxt, 0, NULL, 0);\n \t } else if (ctxt->input->free != deallocblankswrapper) {\n \t\t input = xmlNewBlanksWrapperInputStream(ctxt, entity);\n \t\t if (xmlPushInput(ctxt, input) < 0)\n@@ -2759,6 +2786,7 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int len,\n \t if ((ctxt->lastError.code == XML_ERR_ENTITY_LOOP) ||\n \t (ctxt->lastError.code == XML_ERR_INTERNAL_ERROR))\n \t goto int_error;\n+\t xmlParserEntityCheck(ctxt, 0, ent, 0);\n \t if (ent != NULL)\n \t ctxt->nbentities += ent->checked / 2;\n \t if ((ent != NULL) &&\n@@ -2810,6 +2838,7 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int len,\n \t ent = xmlParseStringPEReference(ctxt, &str);\n \t if (ctxt->lastError.code == XML_ERR_ENTITY_LOOP)\n \t goto int_error;\n+\t xmlParserEntityCheck(ctxt, 0, ent, 0);\n \t if (ent != NULL)\n \t ctxt->nbentities += ent->checked / 2;\n \t if (ent != NULL) {\n@@ -7312,6 +7341,7 @@ xmlParseReference(xmlParserCtxtPtr ctxt) {\n \t\t (ret != XML_WAR_UNDECLARED_ENTITY)) {\n \t xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY,\n \t\t \"Entity '%s' failed to parse\\n\", ent->name);\n+\t xmlParserEntityCheck(ctxt, 0, ent, 0);\n \t} else if (list != NULL) {\n \t xmlFreeNodeList(list);\n \t list = NULL;\n@@ -7418,7 +7448,7 @@ xmlParseReference(xmlParserCtxtPtr ctxt) {\n \t\t/*\n \t\t * We are copying here, make sure there is no abuse\n \t\t */\n-\t\tctxt->sizeentcopy += ent->length;\n+\t\tctxt->sizeentcopy += ent->length + 5;\n \t\tif (xmlParserEntityCheck(ctxt, 0, ent, ctxt->sizeentcopy))\n \t\t return;\n \n@@ -7466,7 +7496,7 @@ xmlParseReference(xmlParserCtxtPtr ctxt) {\n \t\t/*\n \t\t * We are copying here, make sure there is no abuse\n \t\t */\n-\t\tctxt->sizeentcopy += ent->length;\n+\t\tctxt->sizeentcopy += ent->length + 5;\n \t\tif (xmlParserEntityCheck(ctxt, 0, ent, ctxt->sizeentcopy))\n \t\t return;\n \n@@ -7652,6 +7682,7 @@ xmlParseEntityRef(xmlParserCtxtPtr ctxt) {\n \t\tctxt->sax->reference(ctxt->userData, name);\n \t }\n \t}\n+\txmlParserEntityCheck(ctxt, 0, ent, 0);\n \tctxt->valid = 0;\n }\n \n@@ -7845,6 +7876,7 @@ xmlParseStringEntityRef(xmlParserCtxtPtr ctxt, const xmlChar ** str) {\n \t\t\t \"Entity '%s' not defined\\n\",\n \t\t\t name);\n \t}\n+\txmlParserEntityCheck(ctxt, 0, ent, 0);\n \t/* TODO ? check regressions ctxt->valid = 0; */\n }\n \n@@ -8004,6 +8036,7 @@ xmlParsePEReference(xmlParserCtxtPtr ctxt)\n \t\t\t name, NULL);\n \t ctxt->valid = 0;\n \t}\n+\txmlParserEntityCheck(ctxt, 0, NULL, 0);\n } else {\n \t/*\n \t * Internal checking in case the entity quest barfed\n@@ -8243,6 +8276,7 @@ xmlParseStringPEReference(xmlParserCtxtPtr ctxt, const xmlChar **str) {\n \t\t\t name, NULL);\n \t ctxt->valid = 0;\n \t}\n+\txmlParserEntityCheck(ctxt, 0, NULL, 0);\n } else {\n \t/*\n \t * Internal checking in case the entity quest barfed\n-- \ncgit v0.10.1"}], "metadata": {"id": "libxml2-5762-libxml2-CVE-2014-3660.patch", "cve_id": "CVE-2016-4658", "package": "libxml2", "upstream_enriched": true, "upstream_commit": "be2a7edaf289c5da74a4f9ed3a0b6c733e775230", "upstream_repo": "GNOME/libxml2", "tier": "adapted", "has_source_context": true, "context_tokens_est": 2358, "context_files": 1, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-4658\n\nxpointer.c in libxml2 before 2.9.5 (as used in Apple iOS before 10, OS X before 10.12, tvOS before 10, and watchOS before 3, and other products) does not forbid namespace nodes in XPointer ranges, which allows remote attackers to execute arbitrary code or cause a denial of service (use-after-free and memory corruption) via a crafted XML document.\n\n## Package\nlibxml2\n\n## Files to modify\n- parser.c\n- libxml2-2.9.1.orig/parser.c\n\n## Target Source Code\n\n### parser.c\n\n#### region() [lines 9371-7078]\n```c\n\n```\n\n#### region() [lines 9444-7078]\n```c\n\n```\n\n\n## Upstream Fix\n```diff\nFrom 38eae571111db3b43ffdeb05487c9f60551906fb Mon Sep 17 00:00:00 2001\nFrom: Pranjal Jumde \nDate: Mon, 7 Mar 2016 14:04:08 -0800\nSubject: Heap use-after-free in xmlSAX2AttributeNs\n\nFor https://bugzilla.gnome.org/show_bug.cgi?id=759020\n\n* parser.c:\n(xmlParseStartTag2): Attribute strings are only valid if the\nbase does not change, so add another check where the base may\nchange. Make sure to set 'attvalue' to NULL after freeing it.\n* result/errors/759020.xml: Added.\n* result/errors/759020.xml.err: Added.\n* result/errors/759020.xml.str: Added.\n* test/errors/759020.xml: Added test case.\n---\n parser.c | 12 ++++++++++--\n result/errors/759020.xml | 0\n result/errors/759020.xml.err | 6 ++++++\n result/errors/759020.xml.str | 7 +++++++\n test/errors/759020.xml | 46 ++++++++++++++++++++++++++++++++++++++++++++\n 5 files changed, 69 insertions(+), 2 deletions(-)\n create mode 100644 result/errors/759020.xml\n create mode 100644 result/errors/759020.xml.err\n create mode 100644 result/errors/759020.xml.str\n create mode 100644 test/errors/759020.xml\n\nIndex: libxml2-2.9.1/parser.c\n===================================================================\n--- libxml2-2.9.1.orig/parser.c\n+++ libxml2-2.9.1/parser.c\n@@ -9410,8 +9410,13 @@ reparse:\n \t\telse\n \t\t if (nsPush(ctxt, NULL, URL) > 0) nbNs++;\n skip_default_ns:\n-\t\tif (alloc != 0) xmlFree(attvalue);\n+\t\tif ((attvalue != NULL) && (alloc != 0)) {\n+\t\t xmlFree(attvalue);\n+\t\t attvalue = NULL;\n+\t\t}\n \t\tSKIP_BLANKS;\n+\t\tif ((ctxt->input->base != base) || (inputNr != ctxt->inputNr))\n+\t\t goto base_changed;\n \t\tcontinue;\n \t }\n if (aprefix == ctxt->str_xmlns) {\n@@ -9483,7 +9488,10 @@ skip_default_ns:\n \t\telse\n \t\t if (nsPush(ctxt, attname, URL) > 0) nbNs++;\n skip_ns:\n-\t\tif (alloc != 0) xmlFree(attvalue);\n+\t\tif ((attvalue != NULL) && (alloc != 0)) {\n+\t\t xmlFree(attvalue);\n+\t\t attvalue = NULL;\n+\t\t}\n \t\tSKIP_BLANKS;\n \t\tif ((ctxt->input->base != base) || (inputNr != ctxt->inputNr))\n \t\t goto base_changed;\nIndex: libxml2-2.9.1/result/errors/759020.xml.err\n===================================================================\n--- /dev/null\n+++ libxml2-2.9.1/result/errors/759020.xml.err\n@@ -0,0 +1,6 @@\n+./test/errors/759020.xml:3: namespace warning : xmlns: URI 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 is not absolute\n+0000000000000000000000000000000000000000000000000000000000000000000000000000000'\n+ ^\n+./test/errors/759020.xml:46: parser error : Couldn't find end of Start Tag s00 line 2\n+ \n+ ^\nIndex: libxml2-2.9.1/result/errors/759020.xml.str\n===================================================================\n--- /dev/null\n+++ libxml2-2.9.1/result/errors/759020.xml.str\n@@ -0,0 +1,7 @@\n+./test/errors/759020.xml:3: namespace warning : xmlns: URI 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 is not absolute\n+0000000000000000000000000000000000000000000000000000000000000000000000000000000'\n+ ^\n+./test/errors/759020.xml:46: parser error : Couldn't find end of Start Tag s00\n+ \n+ ^\n+./test/errors/759020.xml : failed to parse\nIndex: libxml2-2.9.1/test/errors/759020.xml\n===================================================================\n--- /dev/null\n+++ libxml2-2.9.1/test/errors/759020.xml\n@@ -0,0 +1,46 @@\n+\n+\nDate: Mon, 7 Mar 2016 14:04:08 -0800\nSubject: Heap use-after-free in xmlSAX2AttributeNs\n\nFor https://bugzilla.gnome.org/show_bug.cgi?id=759020\n\n* parser.c:\n(xmlParseStartTag2): Attribute strings are only valid if the\nbase does not change, so add another check where the base may\nchange. Make sure to set 'attvalue' to NULL after freeing it.\n* result/errors/759020.xml: Added.\n* result/errors/759020.xml.err: Added.\n* result/errors/759020.xml.str: Added.\n* test/errors/759020.xml: Added test case.\n---\n parser.c | 12 ++++++++++--\n result/errors/759020.xml | 0\n result/errors/759020.xml.err | 6 ++++++\n result/errors/759020.xml.str | 7 +++++++\n test/errors/759020.xml | 46 ++++++++++++++++++++++++++++++++++++++++++++\n 5 files changed, 69 insertions(+), 2 deletions(-)\n create mode 100644 result/errors/759020.xml\n create mode 100644 result/errors/759020.xml.err\n create mode 100644 result/errors/759020.xml.str\n create mode 100644 test/errors/759020.xml\n\nIndex: libxml2-2.9.1/parser.c\n===================================================================\n--- libxml2-2.9.1.orig/parser.c\n+++ libxml2-2.9.1/parser.c\n@@ -9410,8 +9410,13 @@ reparse:\n \t\telse\n \t\t if (nsPush(ctxt, NULL, URL) > 0) nbNs++;\n skip_default_ns:\n-\t\tif (alloc != 0) xmlFree(attvalue);\n+\t\tif ((attvalue != NULL) && (alloc != 0)) {\n+\t\t xmlFree(attvalue);\n+\t\t attvalue = NULL;\n+\t\t}\n \t\tSKIP_BLANKS;\n+\t\tif ((ctxt->input->base != base) || (inputNr != ctxt->inputNr))\n+\t\t goto base_changed;\n \t\tcontinue;\n \t }\n if (aprefix == ctxt->str_xmlns) {\n@@ -9483,7 +9488,10 @@ skip_default_ns:\n \t\telse\n \t\t if (nsPush(ctxt, attname, URL) > 0) nbNs++;\n skip_ns:\n-\t\tif (alloc != 0) xmlFree(attvalue);\n+\t\tif ((attvalue != NULL) && (alloc != 0)) {\n+\t\t xmlFree(attvalue);\n+\t\t attvalue = NULL;\n+\t\t}\n \t\tSKIP_BLANKS;\n \t\tif ((ctxt->input->base != base) || (inputNr != ctxt->inputNr))\n \t\t goto base_changed;\nIndex: libxml2-2.9.1/result/errors/759020.xml.err\n===================================================================\n--- /dev/null\n+++ libxml2-2.9.1/result/errors/759020.xml.err\n@@ -0,0 +1,6 @@\n+./test/errors/759020.xml:3: namespace warning : xmlns: URI 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 is not absolute\n+0000000000000000000000000000000000000000000000000000000000000000000000000000000'\n+ ^\n+./test/errors/759020.xml:46: parser error : Couldn't find end of Start Tag s00 line 2\n+ \n+ ^\nIndex: libxml2-2.9.1/result/errors/759020.xml.str\n===================================================================\n--- /dev/null\n+++ libxml2-2.9.1/result/errors/759020.xml.str\n@@ -0,0 +1,7 @@\n+./test/errors/759020.xml:3: namespace warning : xmlns: URI 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 is not absolute\n+0000000000000000000000000000000000000000000000000000000000000000000000000000000'\n+ ^\n+./test/errors/759020.xml:46: parser error : Couldn't find end of Start Tag s00\n+ \n+ ^\n+./test/errors/759020.xml : failed to parse\nIndex: libxml2-2.9.1/test/errors/759020.xml\n===================================================================\n--- /dev/null\n+++ libxml2-2.9.1/test/errors/759020.xml\n@@ -0,0 +1,46 @@\n+\n+\n\nIndex: client/mysql_upgrade.c\n===================================================================\n--- client/mysql_upgrade.c.orig\n+++ client/mysql_upgrade.c\n@@ -878,7 +878,9 @@ int main(int argc, char **argv)\n printf(\"This installation of MySQL is already upgraded to %s, \"\n \"use --force if you still need to run mysql_upgrade\\n\",\n MYSQL_SERVER_VERSION);\n- die(NULL);\n+ free_used_memory();\n+ my_end(MY_CHECK_ERROR);\n+ exit(0);\n }\n \n /*\nIndex: mysql-test/t/mysql_upgrade.test\n===================================================================\n--- mysql-test/t/mysql_upgrade.test.orig\n+++ mysql-test/t/mysql_upgrade.test\n@@ -41,7 +41,7 @@ file_exists $MYSQLD_DATADIR/mysql_upgrad\n \n --echo Run it again - should say already completed\n --replace_result $MYSQL_SERVER_VERSION VERSION\n---error 1\n+--error 0\n --exec $MYSQL_UPGRADE 2>&1\n \n # It should have created a file in the MySQL Servers datadir\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "PATCH-P0-FEATURE-SUSE: Returning 0 when already upgraded.\n\nReturning non-zero exit status in this case is not nice to scripts using\nmysql_upgrade (eg. our init script)\n\nMaintainer: Michal Hrusecky \n\nIndex: client/mysql_upgrade.c\n===================================================================\n--- client/mysql_upgrade.c.orig\n+++ client/mysql_upgrade.c\n@@ -878,7 +878,9 @@ int main(int argc, char **argv)\n printf(\"This installation of MySQL is already upgraded to %s, \"\n \"use --force if you still need to run mysql_upgrade\\n\",\n MYSQL_SERVER_VERSION);\n- die(NULL);\n+ free_used_memory();\n+ my_end(MY_CHECK_ERROR);\n+ exit(0);\n }\n \n /*\nIndex: mysql-test/t/mysql_upgrade.test\n===================================================================\n--- mysql-test/t/mysql_upgrade.test.orig\n+++ mysql-test/t/mysql_upgrade.test\n@@ -41,7 +41,7 @@ file_exists $MYSQLD_DATADIR/mysql_upgrad\n \n --echo Run it again - should say already completed\n --replace_result $MYSQL_SERVER_VERSION VERSION\n---error 1\n+--error 0\n --exec $MYSQL_UPGRADE 2>&1\n \n # It should have created a file in the MySQL Servers datadir"}], "metadata": {"id": "mariadb-499-mariadb-5.1.50-upgrade-exit-st", "cve_id": "CVE-2012-0113", "package": "mariadb", "tier": "identical", "has_source_context": false, "license": "GPL-2.0-only"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-7555\n\nHeap-based buffer overflow in giffix.c in giffix in giflib 5.1.1 allows attackers to cause a denial of service (program crash) via crafted image and logical screen width fields in a GIF file.\n\n## Package\ngiflib\n\n## Files to modify\n- giflib-5.0.5.orig/lib/egif_lib.c\n- lib/egif_lib.c\n\n## Upstream Fix\n```diff\n---\n lib/egif_lib.c | 6 ++++++\n 1 file changed, 6 insertions(+)\n\nIndex: giflib-5.0.5/lib/egif_lib.c\n===================================================================\n--- giflib-5.0.5.orig/lib/egif_lib.c\n+++ giflib-5.0.5/lib/egif_lib.c\n@@ -376,6 +376,12 @@ EGifPutImageDesc(GifFileType *GifFile,\n GifFile->Image.Width = Width;\n GifFile->Image.Height = Height;\n GifFile->Image.Interlace = Interlace;\n+\n+ // We're going to overwrite the Image.ColorMap pointer next, so free it if not NULL first!\n+ if (GifFile->Image.ColorMap != NULL) {\n+ GifFreeMapObject(GifFile->Image.ColorMap);\n+ GifFile->Image.ColorMap = NULL;\n+ }\n if (ColorMap) {\n GifFile->Image.ColorMap = GifMakeMapObject(ColorMap->ColorCount,\n ColorMap->Colors);\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "---\n lib/egif_lib.c | 6 ++++++\n 1 file changed, 6 insertions(+)\n\nIndex: giflib-5.0.5/lib/egif_lib.c\n===================================================================\n--- giflib-5.0.5.orig/lib/egif_lib.c\n+++ giflib-5.0.5/lib/egif_lib.c\n@@ -376,6 +376,12 @@ EGifPutImageDesc(GifFileType *GifFile,\n GifFile->Image.Width = Width;\n GifFile->Image.Height = Height;\n GifFile->Image.Interlace = Interlace;\n+\n+ // We're going to overwrite the Image.ColorMap pointer next, so free it if not NULL first!\n+ if (GifFile->Image.ColorMap != NULL) {\n+ GifFreeMapObject(GifFile->Image.ColorMap);\n+ GifFile->Image.ColorMap = NULL;\n+ }\n if (ColorMap) {\n GifFile->Image.ColorMap = GifMakeMapObject(ColorMap->ColorCount,\n ColorMap->Colors);"}], "metadata": {"id": "giflib-4560-bnc949160-fix-colormap-leak.pa", "cve_id": "CVE-2015-7555", "package": "giflib", "tier": "identical", "has_source_context": false, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-4658\n\nxpointer.c in libxml2 before 2.9.5 (as used in Apple iOS before 10, OS X before 10.12, tvOS before 10, and watchOS before 3, and other products) does not forbid namespace nodes in XPointer ranges, which allows remote attackers to execute arbitrary code or cause a denial of service (use-after-free and memory corruption) via a crafted XML document.\n\n## Package\nlibxml2\n\n## Files to modify\n- parser.c\n- parserInternals.c\n\n## Target Source Code\n\n### parser.c\n\n#### xmlParseXMLDecl() [lines 10626-7078]\n```c\n\n```\n\n#### xmlParseDocument() [lines 10750-7078]\n```c\n\n```\n\n#### xmlParseDocument() [lines 10767-7078]\n```c\n\n```\n\n\n## Upstream Fix\n```diff\nFrom afd27c21f6b36e22682b7da20d726bce2dcb2f43 Mon Sep 17 00:00:00 2001\nFrom: Daniel Veillard \nDate: Mon, 9 Nov 2015 18:07:18 +0800\nSubject: [PATCH] Avoid processing entities after encoding conversion failures\n\nFor https://bugzilla.gnome.org/show_bug.cgi?id=756527\nand was also raised by Chromium team in the past\n\nWhen we hit a convwersion failure when switching encoding\nit is bestter to stop parsing there, this was treated as a\nfatal error but the parser was continuing to process to extract\nmore errors, unfortunately that makes little sense as the data\nis obviously corrupt and can potentially lead to unexpected behaviour.\n---\n parser.c | 7 +++++--\n parserInternals.c | 11 ++++++++++-\n 2 files changed, 15 insertions(+), 3 deletions(-)\n\ndiff --git a/parser.c b/parser.c\nindex 134afe7055..c79b4e85de 100644\n--- a/parser.c\n+++ b/parser.c\n@@ -10665,7 +10665,8 @@ xmlParseXMLDecl(xmlParserCtxtPtr ctxt) {\n \txmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, \"Blank needed here\\n\");\n }\n xmlParseEncodingDecl(ctxt);\n- if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) {\n+ if ((ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) ||\n+ (ctxt->instate == XML_PARSER_EOF)) {\n \t/*\n \t * The XML REC instructs us to stop parsing right here\n \t */\n@@ -10789,6 +10790,7 @@ xmlParseDocument(xmlParserCtxtPtr ctxt) {\n \n if (CUR == 0) {\n \txmlFatalErr(ctxt, XML_ERR_DOCUMENT_EMPTY, NULL);\n+\treturn(-1);\n }\n \n /*\n@@ -10806,7 +10808,8 @@ xmlParseDocument(xmlParserCtxtPtr ctxt) {\n \t * Note that we will switch encoding on the fly.\n \t */\n \txmlParseXMLDecl(ctxt);\n-\tif (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) {\n+\tif ((ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) ||\n+\t (ctxt->instate == XML_PARSER_EOF)) {\n \t /*\n \t * The XML REC instructs us to stop parsing right here\n \t */\ndiff --git a/parserInternals.c b/parserInternals.c\nindex df204fde63..c8230c1c64 100644\n--- a/parserInternals.c\n+++ b/parserInternals.c\n@@ -937,6 +937,7 @@ xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc)\n {\n xmlCharEncodingHandlerPtr handler;\n int len = -1;\n+ int ret;\n \n if (ctxt == NULL) return(-1);\n switch (enc) {\n@@ -1097,7 +1098,15 @@ xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc)\n if (handler == NULL)\n \treturn(-1);\n ctxt->charset = XML_CHAR_ENCODING_UTF8;\n- return(xmlSwitchToEncodingInt(ctxt, handler, len));\n+ ret = xmlSwitchToEncodingInt(ctxt, handler, len);\n+ if ((ret < 0) || (ctxt->errNo == XML_I18N_CONV_FAILED)) {\n+ /*\n+\t * on encoding conversion errors, stop the parser\n+\t */\n+ xmlStopParser(ctxt);\n+\tctxt->errNo = XML_I18N_CONV_FAILED;\n+ }\n+ return(ret);\n }\n \n /**\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From afd27c21f6b36e22682b7da20d726bce2dcb2f43 Mon Sep 17 00:00:00 2001\nFrom: Daniel Veillard \nDate: Mon, 9 Nov 2015 18:07:18 +0800\nSubject: Avoid processing entities after encoding conversion failures\n\nFor https://bugzilla.gnome.org/show_bug.cgi?id=756527\nand was also raised by Chromium team in the past\n\nWhen we hit a convwersion failure when switching encoding\nit is bestter to stop parsing there, this was treated as a\nfatal error but the parser was continuing to process to extract\nmore errors, unfortunately that makes little sense as the data\nis obviously corrupt and can potentially lead to unexpected behaviour.\n---\n parser.c | 7 +++++--\n parserInternals.c | 11 ++++++++++-\n 2 files changed, 15 insertions(+), 3 deletions(-)\n\ndiff --git a/parser.c b/parser.c\nindex 134afe7..c79b4e8 100644\n--- a/parser.c\n+++ b/parser.c\n@@ -10665,7 +10665,8 @@ xmlParseXMLDecl(xmlParserCtxtPtr ctxt) {\n \txmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, \"Blank needed here\\n\");\n }\n xmlParseEncodingDecl(ctxt);\n- if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) {\n+ if ((ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) ||\n+ (ctxt->instate == XML_PARSER_EOF)) {\n \t/*\n \t * The XML REC instructs us to stop parsing right here\n \t */\n@@ -10789,6 +10790,7 @@ xmlParseDocument(xmlParserCtxtPtr ctxt) {\n \n if (CUR == 0) {\n \txmlFatalErr(ctxt, XML_ERR_DOCUMENT_EMPTY, NULL);\n+\treturn(-1);\n }\n \n /*\n@@ -10806,7 +10808,8 @@ xmlParseDocument(xmlParserCtxtPtr ctxt) {\n \t * Note that we will switch encoding on the fly.\n \t */\n \txmlParseXMLDecl(ctxt);\n-\tif (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) {\n+\tif ((ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) ||\n+\t (ctxt->instate == XML_PARSER_EOF)) {\n \t /*\n \t * The XML REC instructs us to stop parsing right here\n \t */\ndiff --git a/parserInternals.c b/parserInternals.c\nindex df204fd..c8230c1 100644\n--- a/parserInternals.c\n+++ b/parserInternals.c\n@@ -937,6 +937,7 @@ xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc)\n {\n xmlCharEncodingHandlerPtr handler;\n int len = -1;\n+ int ret;\n \n if (ctxt == NULL) return(-1);\n switch (enc) {\n@@ -1097,7 +1098,15 @@ xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc)\n if (handler == NULL)\n \treturn(-1);\n ctxt->charset = XML_CHAR_ENCODING_UTF8;\n- return(xmlSwitchToEncodingInt(ctxt, handler, len));\n+ ret = xmlSwitchToEncodingInt(ctxt, handler, len);\n+ if ((ret < 0) || (ctxt->errNo == XML_I18N_CONV_FAILED)) {\n+ /*\n+\t * on encoding conversion errors, stop the parser\n+\t */\n+ xmlStopParser(ctxt);\n+\tctxt->errNo = XML_I18N_CONV_FAILED;\n+ }\n+ return(ret);\n }\n \n /**\n-- \ncgit v0.11.2"}], "metadata": {"id": "libxml2-5762-libxml2-2.9.1-CVE-2015-7498.pa", "cve_id": "CVE-2016-4658", "package": "libxml2", "upstream_enriched": true, "upstream_commit": "afd27c21f6b36e22682b7da20d726bce2dcb2f43", "upstream_repo": "GNOME/libxml2", "tier": "adapted", "has_source_context": true, "context_tokens_est": 43, "context_files": 1, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-9556\n\nThe IsPixelGray function in MagickCore/pixel-accessor.h in ImageMagick 7.0.3-8 allows remote attackers to cause a denial of service (out-of-bounds heap read) via a crafted image file.\n\n## Package\nGraphicsMagick\n\n## Files to modify\n- GraphicsMagick-1.3.20.orig/coders/meta.c\n- coders/meta.c\n\n## Upstream Fix\n```diff\nff -r 4f748e625c82 -r 8da95e3e5e81 coders/meta.c\nIndex: GraphicsMagick-1.3.20/coders/meta.c\n===================================================================\n--- GraphicsMagick-1.3.20.orig/coders/meta.c\t2013-03-10 00:19:31.000000000 +0100\n+++ GraphicsMagick-1.3.20/coders/meta.c\t2016-10-06 15:21:19.580881195 +0200\n@@ -129,14 +129,16 @@ static unsigned int IsMETA(const unsigne\n \n typedef struct _html_code\n {\n- short\n+ unsigned short\n len;\n+\n const char\n *code,\n val;\n+\n } html_code;\n \n-static html_code html_codes[] = {\n+static html_code const html_codes[] = {\n #ifdef HANDLE_GT_LT\n { 4,\"<\",'<' },\n { 4,\">\",'>' },\n@@ -179,29 +181,36 @@ static int stringnicmp(const char *p,con\n return(toupper((int) *p)-toupper((int) *q));\n }\n \n-static int convertHTMLcodes(char *s, int len)\n+static size_t convertHTMLcodes(char *s, const size_t len)\n {\n- if (len <=0 || s==(char*)NULL || *s=='\\0')\n+ int val;\n+\n+ if ((len == 0) || (s == (char*) NULL) || (*s=='\\0'))\n return 0;\n \n- if (s[1] == '#')\n- {\n- int val, o;\n+ /*\n+ Check for hex or decimal character escape.\n \n- if (sscanf(s,\"&#%d;\",&val) == 1)\n- {\n- o = 3;\n- while (s[o] != ';')\n+ e.g. hex: \" \", decimal \" \"\n+\n+ Note that scanf is expected to parse the number in hex or decimal\n+ and that it does not require the terminating ';' to appear in\n+ order to parse the numeric argument.\n+ */\n+ if ((len > 3) && (s[1] == '#') && (strchr(s,';') != (char *) NULL) &&\n+ (sscanf(s,\"&#%d;\",&val) == 1))\n+ {\n+ size_t o = 3;\n+ while (s[o] != ';')\n {\n o++;\n if (o > 5)\n break;\n }\n- if (o < 6)\n- (void) strcpy(s+1, s+1+o);\n- *s = val;\n- return o;\n- }\n+ if (o < 6)\n+ (void) memmove(s+1,s+1+o,strlen(s+1+o)+1);\n+ *s = val;\n+ return o;\n }\n else\n {\n@@ -214,7 +223,7 @@ static int convertHTMLcodes(char *s, int\n if (html_codes[i].len <= len)\n if (stringnicmp(s, html_codes[i].code, (size_t) (html_codes[i].len)) == 0)\n {\n- (void) strcpy(s+1, s+html_codes[i].len);\n+ (void) memmove(s+1, s+html_codes[i].len, strlen(s+html_codes[i].len)+1);\n *s = html_codes[i].val;\n return html_codes[i].len-1;\n }\n@@ -281,10 +290,10 @@ static long parse8BIM(Image *ifile, Imag\n char\n brkused,\n quoted,\n- *line,\n- *token,\n- *newstr,\n- *name;\n+ *line = (char *) NULL,\n+ *token = (char *) NULL,\n+ *newstr = (char *) NULL,\n+ *name = (char *) NULL;\n \n int\n state,\n@@ -299,7 +308,7 @@ static long parse8BIM(Image *ifile, Imag\n size_t\n inputlen = BUFFER_SZ;\n \n- long\n+ ssize_t\n savedolen = 0L,\n outputlen = 0L;\n \n@@ -313,7 +322,8 @@ static long parse8BIM(Image *ifile, Imag\n dataset = 0;\n recnum = 0;\n line = MagickAllocateMemory(char *,inputlen);\n- name = token = (char *)NULL;\n+ if (line == (char *) NULL)\n+ goto parse8BIM_failure;\n savedpos = 0;\n while(super_fgets(&line,&inputlen,ifile)!=NULL)\n {\n@@ -321,7 +331,11 @@ static long parse8BIM(Image *ifile, Imag\n next=0;\n \n token = MagickAllocateMemory(char *,inputlen);\n+ if (token == (char *) NULL)\n+ goto parse8BIM_failure;\n newstr = MagickAllocateMemory(char *,inputlen);\n+ if (newstr == (char *) NULL)\n+ goto parse8BIM_failure;\n while (Tokenizer(&token_info, 0, token, inputlen, line,\n (char *) \"\", (char *) \"=\",\n (char *) \"\\\"\", 0, &brkused,&next,"ed)==0)\n@@ -354,8 +368,9 @@ static long parse8BIM(Image *ifile, Imag\n break;\n case 2:\n name = MagickAllocateMemory(char *,strlen(newstr)+1);\n- if (name)\n- (void) strcpy(name,newstr);\n+ if (name == (char *) NULL)\n+ goto parse8BIM_failure;\n+ (void) strcpy(name,newstr);\n break;\n }\n state++;\n@@ -367,7 +382,7 @@ static long parse8BIM(Image *ifile, Imag\n int\n next;\n \n- unsigned long\n+ size_t\n len;\n \n char\n@@ -384,7 +399,7 @@ static long parse8BIM(Image *ifile, Imag\n char\n *s = &token[next-1];\n \n- len -= convertHTMLcodes(s, (int) strlen(s));\n+ len -= convertHTMLcodes(s, strlen(s));\n }\n }\n \n@@ -400,6 +415,8 @@ static long parse8BIM(Image *ifile, Imag\n {\n long diff = outputlen - savedolen;\n currentpos = TellBlob(ofile);\n+ if (currentpos < 0)\n+ goto parse8BIM_failure;\n (void) SeekBlob(ofile,savedpos,SEEK_SET);\n (void) WriteBlobMSBLong(ofile,diff);\n (void) SeekBlob(ofile,currentpos,SEEK_SET);\n@@ -433,7 +450,7 @@ static long parse8BIM(Image *ifile, Imag\n next=0;\n outputlen += len;\n while (len--)\n- (void) WriteBlobByte(ofile,token[next++]);\n+ (void) WriteBlobByte(ofile,token[next++]); /* boom */\n \n if (outputlen & 1)\n {\n@@ -445,6 +462,8 @@ static long parse8BIM(Image *ifile, Imag\n {\n /* patch in a fake length for now and fix it later */\n savedpos = TellBlob(ofile);\n+ if (savedpos < 0)\n+ goto parse8BIM_failure;\n (void) WriteBlobMSBLong(ofile,0xFFFFFFFFUL);\n outputlen += 4;\n savedolen = outputlen;\n@@ -478,12 +497,22 @@ static long parse8BIM(Image *ifile, Imag\n long diff = outputlen - savedolen;\n \n currentpos = TellBlob(ofile);\n+ if (currentpos < 0)\n+ goto parse8BIM_failure;\n+\n (void) SeekBlob(ofile,savedpos,SEEK_SET);\n (void) WriteBlobMSBLong(ofile,diff);\n (void) SeekBlob(ofile,currentpos,SEEK_SET);\n savedolen = 0L;\n }\n return outputlen;\n+\n+ parse8BIM_failure:\n+ MagickFreeMemory(token);\n+ MagickFreeMemory(newstr);\n+ MagickFreeMemory(name);\n+ MagickFreeMemory(line);\n+ return 0L;\n }\n \n static char *super_fgets_w(char **b, size_t *blen, Image *file)\n@@ -542,10 +571,10 @@ static long parse8BIMW(Image *ifile, Ima\n char\n brkused,\n quoted,\n- *line,\n- *token,\n- *newstr,\n- *name;\n+ *line = (char *) NULL,\n+ *token = (char *) NULL,\n+ *newstr = (char *) NULL,\n+ *name = (char *) NULL;\n \n int\n state,\n@@ -560,7 +589,7 @@ static long parse8BIMW(Image *ifile, Ima\n size_t\n inputlen = BUFFER_SZ;\n \n- long\n+ ssize_t\n savedolen = 0L,\n outputlen = 0L;\n \n@@ -574,6 +603,8 @@ static long parse8BIMW(Image *ifile, Ima\n dataset = 0;\n recnum = 0;\n line = MagickAllocateMemory(char *,inputlen);\n+ if (line == (char *) NULL)\n+ goto parse8BIMW_failure;\n name = token = (char *)NULL;\n savedpos = 0;\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n@@ -586,7 +617,11 @@ static long parse8BIMW(Image *ifile, Ima\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \"META CODER Parse8BIM: %s (%lu)\",line, (unsigned long) inputlen);\n token = MagickAllocateMemory(char *,inputlen);\n+ if (token == (char *) NULL)\n+ goto parse8BIMW_failure;\n newstr = MagickAllocateMemory(char *,inputlen);\n+ if (newstr == (char *) NULL)\n+ goto parse8BIMW_failure;\n while (Tokenizer(&token_info, 0, token, inputlen, line,\n (char *) \"\", (char *) \"=\",\n (char *) \"\\\"\", 0, &brkused,&next,"ed)==0)\n@@ -619,8 +654,9 @@ static long parse8BIMW(Image *ifile, Ima\n break;\n case 2:\n name = MagickAllocateMemory(char *,strlen(newstr)+1);\n- if (name)\n- (void) strcpy(name,newstr);\n+ \n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "ff -r 4f748e625c82 -r 8da95e3e5e81 coders/meta.c\nIndex: GraphicsMagick-1.3.20/coders/meta.c\n===================================================================\n--- GraphicsMagick-1.3.20.orig/coders/meta.c\t2013-03-10 00:19:31.000000000 +0100\n+++ GraphicsMagick-1.3.20/coders/meta.c\t2016-10-06 15:21:19.580881195 +0200\n@@ -129,14 +129,16 @@ static unsigned int IsMETA(const unsigne\n \n typedef struct _html_code\n {\n- short\n+ unsigned short\n len;\n+\n const char\n *code,\n val;\n+\n } html_code;\n \n-static html_code html_codes[] = {\n+static html_code const html_codes[] = {\n #ifdef HANDLE_GT_LT\n { 4,\"<\",'<' },\n { 4,\">\",'>' },\n@@ -179,29 +181,36 @@ static int stringnicmp(const char *p,con\n return(toupper((int) *p)-toupper((int) *q));\n }\n \n-static int convertHTMLcodes(char *s, int len)\n+static size_t convertHTMLcodes(char *s, const size_t len)\n {\n- if (len <=0 || s==(char*)NULL || *s=='\\0')\n+ int val;\n+\n+ if ((len == 0) || (s == (char*) NULL) || (*s=='\\0'))\n return 0;\n \n- if (s[1] == '#')\n- {\n- int val, o;\n+ /*\n+ Check for hex or decimal character escape.\n \n- if (sscanf(s,\"&#%d;\",&val) == 1)\n- {\n- o = 3;\n- while (s[o] != ';')\n+ e.g. hex: \" \", decimal \" \"\n+\n+ Note that scanf is expected to parse the number in hex or decimal\n+ and that it does not require the terminating ';' to appear in\n+ order to parse the numeric argument.\n+ */\n+ if ((len > 3) && (s[1] == '#') && (strchr(s,';') != (char *) NULL) &&\n+ (sscanf(s,\"&#%d;\",&val) == 1))\n+ {\n+ size_t o = 3;\n+ while (s[o] != ';')\n {\n o++;\n if (o > 5)\n break;\n }\n- if (o < 6)\n- (void) strcpy(s+1, s+1+o);\n- *s = val;\n- return o;\n- }\n+ if (o < 6)\n+ (void) memmove(s+1,s+1+o,strlen(s+1+o)+1);\n+ *s = val;\n+ return o;\n }\n else\n {\n@@ -214,7 +223,7 @@ static int convertHTMLcodes(char *s, int\n if (html_codes[i].len <= len)\n if (stringnicmp(s, html_codes[i].code, (size_t) (html_codes[i].len)) == 0)\n {\n- (void) strcpy(s+1, s+html_codes[i].len);\n+ (void) memmove(s+1, s+html_codes[i].len, strlen(s+html_codes[i].len)+1);\n *s = html_codes[i].val;\n return html_codes[i].len-1;\n }\n@@ -281,10 +290,10 @@ static long parse8BIM(Image *ifile, Imag\n char\n brkused,\n quoted,\n- *line,\n- *token,\n- *newstr,\n- *name;\n+ *line = (char *) NULL,\n+ *token = (char *) NULL,\n+ *newstr = (char *) NULL,\n+ *name = (char *) NULL;\n \n int\n state,\n@@ -299,7 +308,7 @@ static long parse8BIM(Image *ifile, Imag\n size_t\n inputlen = BUFFER_SZ;\n \n- long\n+ ssize_t\n savedolen = 0L,\n outputlen = 0L;\n \n@@ -313,7 +322,8 @@ static long parse8BIM(Image *ifile, Imag\n dataset = 0;\n recnum = 0;\n line = MagickAllocateMemory(char *,inputlen);\n- name = token = (char *)NULL;\n+ if (line == (char *) NULL)\n+ goto parse8BIM_failure;\n savedpos = 0;\n while(super_fgets(&line,&inputlen,ifile)!=NULL)\n {\n@@ -321,7 +331,11 @@ static long parse8BIM(Image *ifile, Imag\n next=0;\n \n token = MagickAllocateMemory(char *,inputlen);\n+ if (token == (char *) NULL)\n+ goto parse8BIM_failure;\n newstr = MagickAllocateMemory(char *,inputlen);\n+ if (newstr == (char *) NULL)\n+ goto parse8BIM_failure;\n while (Tokenizer(&token_info, 0, token, inputlen, line,\n (char *) \"\", (char *) \"=\",\n (char *) \"\\\"\", 0, &brkused,&next,"ed)==0)\n@@ -354,8 +368,9 @@ static long parse8BIM(Image *ifile, Imag\n break;\n case 2:\n name = MagickAllocateMemory(char *,strlen(newstr)+1);\n- if (name)\n- (void) strcpy(name,newstr);\n+ if (name == (char *) NULL)\n+ goto parse8BIM_failure;\n+ (void) strcpy(name,newstr);\n break;\n }\n state++;\n@@ -367,7 +382,7 @@ static long parse8BIM(Image *ifile, Imag\n int\n next;\n \n- unsigned long\n+ size_t\n len;\n \n char\n@@ -384,7 +399,7 @@ static long parse8BIM(Image *ifile, Imag\n char\n *s = &token[next-1];\n \n- len -= convertHTMLcodes(s, (int) strlen(s));\n+ len -= convertHTMLcodes(s, strlen(s));\n }\n }\n \n@@ -400,6 +415,8 @@ static long parse8BIM(Image *ifile, Imag\n {\n long diff = outputlen - savedolen;\n currentpos = TellBlob(ofile);\n+ if (currentpos < 0)\n+ goto parse8BIM_failure;\n (void) SeekBlob(ofile,savedpos,SEEK_SET);\n (void) WriteBlobMSBLong(ofile,diff);\n (void) SeekBlob(ofile,currentpos,SEEK_SET);\n@@ -433,7 +450,7 @@ static long parse8BIM(Image *ifile, Imag\n next=0;\n outputlen += len;\n while (len--)\n- (void) WriteBlobByte(ofile,token[next++]);\n+ (void) WriteBlobByte(ofile,token[next++]); /* boom */\n \n if (outputlen & 1)\n {\n@@ -445,6 +462,8 @@ static long parse8BIM(Image *ifile, Imag\n {\n /* patch in a fake length for now and fix it later */\n savedpos = TellBlob(ofile);\n+ if (savedpos < 0)\n+ goto parse8BIM_failure;\n (void) WriteBlobMSBLong(ofile,0xFFFFFFFFUL);\n outputlen += 4;\n savedolen = outputlen;\n@@ -478,12 +497,22 @@ static long parse8BIM(Image *ifile, Imag\n long diff = outputlen - savedolen;\n \n currentpos = TellBlob(ofile);\n+ if (currentpos < 0)\n+ goto parse8BIM_failure;\n+\n (void) SeekBlob(ofile,savedpos,SEEK_SET);\n (void) WriteBlobMSBLong(ofile,diff);\n (void) SeekBlob(ofile,currentpos,SEEK_SET);\n savedolen = 0L;\n }\n return outputlen;\n+\n+ parse8BIM_failure:\n+ MagickFreeMemory(token);\n+ MagickFreeMemory(newstr);\n+ MagickFreeMemory(name);\n+ MagickFreeMemory(line);\n+ return 0L;\n }\n \n static char *super_fgets_w(char **b, size_t *blen, Image *file)\n@@ -542,10 +571,10 @@ static long parse8BIMW(Image *ifile, Ima\n char\n brkused,\n quoted,\n- *line,\n- *token,\n- *newstr,\n- *name;\n+ *line = (char *) NULL,\n+ *token = (char *) NULL,\n+ *newstr = (char *) NULL,\n+ *name = (char *) NULL;\n \n int\n state,\n@@ -560,7 +589,7 @@ static long parse8BIMW(Image *ifile, Ima\n size_t\n inputlen = BUFFER_SZ;\n \n- long\n+ ssize_t\n savedolen = 0L,\n outputlen = 0L;\n \n@@ -574,6 +603,8 @@ static long parse8BIMW(Image *ifile, Ima\n dataset = 0;\n recnum = 0;\n line = MagickAllocateMemory(char *,inputlen);\n+ if (line == (char *) NULL)\n+ goto parse8BIMW_failure;\n name = token = (char *)NULL;\n savedpos = 0;\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n@@ -586,7 +617,11 @@ static long parse8BIMW(Image *ifile, Ima\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \"META CODER Parse8BIM: %s (%lu)\",line, (unsigned long) inputlen);\n token = MagickAllocateMemory(char *,inputlen);\n+ if (token == (char *) NULL)\n+ goto parse8BIMW_failure;\n newstr = MagickAllocateMemory(char *,inputlen);\n+ if (newstr == (char *) NULL)\n+ goto parse8BIMW_failure;\n while (Tokenizer(&token_info, 0, token, inputlen, line,\n (char *) \"\", (char *) \"=\",\n (char *) \"\\\"\", 0, &brkused,&next,"ed)==0)\n@@ -619,8 +654,9 @@ static long parse8BIMW(Image *ifile, Ima\n break;\n case 2:\n name = MagickAllocateMemory(char *,strlen(newstr)+1);\n- if (name)\n- (void) strcpy(name,newstr);\n+ if (name == (char *) NULL)\n+ goto parse8BIMW_failure;\n+ (void) strcpy(name,newstr);\n break;\n }\n state++;\n@@ -632,7 +668,7 @@ static long parse8BIMW(Image *ifile, Ima\n int\n next;\n \n- unsigned long\n+ size_t\n len;\n \n char\n@@ -649,7 +685,7 @@ static long parse8BIMW(Image *ifile, Ima\n char\n *s = &token[next-1];\n \n- len -= convertHTMLcodes(s, (int) strlen(s));\n+ len -= convertHTMLcodes(s, strlen(s));\n }\n }\n \n@@ -665,6 +701,8 @@ static long parse8BIMW(Image *ifile, Ima\n {\n long diff = outputlen - savedolen;\n currentpos = TellBlob(ofile);\n+ if (currentpos < 0)\n+ goto parse8BIMW_failure;\n (void) SeekBlob(ofile,savedpos,SEEK_SET);\n (void) WriteBlobMSBLong(ofile,diff);\n (void) SeekBlob(ofile,currentpos,SEEK_SET);\n@@ -710,6 +748,8 @@ static long parse8BIMW(Image *ifile, Ima\n {\n /* patch in a fake length for now and fix it later */\n savedpos = TellBlob(ofile);\n+ if (savedpos < 0)\n+ goto parse8BIMW_failure;\n (void) WriteBlobMSBLong(ofile,0xFFFFFFFFUL);\n outputlen += 4;\n savedolen = outputlen;\n@@ -743,12 +783,21 @@ static long parse8BIMW(Image *ifile, Ima\n long diff = outputlen - savedolen;\n \n currentpos = TellBlob(ofile);\n+ if (currentpos < 0)\n+ goto parse8BIMW_failure;\n (void) SeekBlob(ofile,savedpos,SEEK_SET);\n (void) WriteBlobMSBLong(ofile,diff);\n (void) SeekBlob(ofile,currentpos,SEEK_SET);\n savedolen = 0L;\n }\n return outputlen;\n+\n+ parse8BIMW_failure:\n+ MagickFreeMemory(token);\n+ MagickFreeMemory(newstr);\n+ MagickFreeMemory(name);\n+ MagickFreeMemory(line);\n+ return 0L;\n }\n \n /* some defines for the different JPEG block types */\n@@ -835,11 +884,12 @@ static int jpeg_skip_variable(Image *ifi\n return 0;\n }\n \n-static int jpeg_skip_variable2(Image *ifile, Image *ARGUNUSED(ofile))\n+static int jpeg_skip_variable2(Image *ifile, Image *ofile)\n {\n unsigned int length;\n int c1,c2;\n \n+ ARG_NOT_USED(ofile);\n if ((c1 = ReadBlobByte(ifile)) == EOF) return M_EOI;\n if ((c2 = ReadBlobByte(ifile)) == EOF) return M_EOI;\n \n@@ -908,8 +958,6 @@ static int jpeg_skip_till_marker(Image *\n }\n #endif\n \n-static char psheader[] = \"\\xFF\\xED\\0\\0Photoshop 3.0\\08BIM\\x04\\x04\\0\\0\\0\\0\";\n-\n /* Embed binary IPTC data into a JPEG image. */\n static int jpeg_embed(Image *ifile, Image *ofile, Image *iptc)\n {\n@@ -952,9 +1000,12 @@ static int jpeg_embed(Image *ifile, Imag\n \n if (iptc != (Image *)NULL)\n {\n+ static const char psheader_base[] = \"\\xFF\\xED\\0\\0Photoshop 3.0\\08BIM\\x04\\x04\\0\\0\\0\\0\";\n+ char psheader[sizeof(psheader_base)];\n len=GetBlobSize(iptc);\n if (len & 1)\n len++; /* make the length even */\n+ (void) strlcpy(psheader,psheader_base,sizeof(psheader));\n psheader[ 2 ] = (len+16)>>8;\n psheader[ 3 ] = (len+16)&0xff;\n for (inx = 0; inx < 18; inx++)\n@@ -1250,7 +1301,7 @@ static Image *ReadMETAImage(const ImageI\n \n DestroyImage(buff);\n }\n- if (LocaleCompare(image_info->magick,\"IPTC\") == 0)\n+ if (LocaleNCompare(image_info->magick,\"IPTC\",4) == 0)\n {\n buff=AllocateImage((ImageInfo *) NULL);\n if (buff == (Image *) NULL)\n@@ -1260,7 +1311,7 @@ static Image *ReadMETAImage(const ImageI\n {\n DestroyImage(buff);\n ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,\n- image)\n+ image);\n }\n AttachBlob(buff->blob,blob,length);\n /* write out the header - length field patched below */\n@@ -1286,14 +1337,21 @@ static Image *ReadMETAImage(const ImageI\n }\n \n /* subtract off the length of the 8BIM stuff */\n+ blob=GetBlobStreamData(buff); /* blob may be realloced */\n+ if ((blob == (const unsigned char *) NULL) || (GetBlobSize(buff) < 12))\n+ {\n+ DestroyImage(buff);\n+ ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,\n+ image);\n+ }\n length=GetBlobSize(buff)-12;\n blob[10]=(unsigned char) ((length >> 8) & 0xff);\n blob[11]=(unsigned char) (length & 0xff);\n blob=GetBlobStreamData(buff);\n length=GetBlobSize(buff);\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n- \"Store IPTC profile, size %lu bytes\",\n- (unsigned long) length);\n+ \"Store IPTC profile, size %\" MAGICK_SIZE_T_F\n+ \"u bytes\",(MAGICK_SIZE_T) length);\n (void) SetImageProfile(image,\"IPTC\",blob,length);\n DetachBlob(buff->blob);\n MagickFreeMemory(blob)\n@@ -1840,9 +1898,14 @@ static int formatIPTC(Image *ifile, Imag\n else\n {\n if (foundiptc)\n- return -1;\n+ {\n+ return -1;\n+ }\n else\n- continue;\n+ {\n+ c = ReadBlobByte(ifile);\n+ continue;\n+ }\n }\n \n /* we found the 0x1c tag and now grab the dataset and record number tags */\n@@ -1888,7 +1951,11 @@ static int formatIPTC(Image *ifile, Imag\n for (tagindx=0; tagindxsignature == MagickSignature);\n temporary_image_filename=(*image->filename == '\\0');\n+ linkedname[0]='\\0';\n+ linkedname[MaxTextExtent-1]='\\0';\n+ linkedinfoname[0]='\\0';\n+ linkedinfoname[MaxTextExtent-1]='\\0';\n if (temporary_image_filename)\n {\n /* Allocate a temporary filename if image is unnamed. */\n@@ -568,12 +575,24 @@ MagickExport unsigned int InvokeDelegate\n return(False);\n }\n }\n+ else if (strspn(image->filename, safechars) != strlen(image->filename))\n+ {\n+ strncpy(linkedname,image->filename,MaxTextExtent-1);\n+ if (!AcquireTemporarySymlink(image->filename,linkedname))\n+\t{\n+ (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image->filename);\n+\t return (False);\n+\t}\n+ }\n+\n (void) strlcpy(filename,image->filename,MaxTextExtent);\n delegate_info=GetDelegateInfo(decode,encode,exception);\n if (delegate_info == (DelegateInfo *) NULL)\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+ if (*linkedname)\n+\tstrncpy(image->filename,linkedname,MaxTextExtent-1);\n (void) ThrowException(exception,DelegateError,NoTagFound,\n decode ? decode : encode);\n return(False);\n@@ -594,6 +613,18 @@ MagickExport unsigned int InvokeDelegate\n }\n image_info->temporary=True;\n }\n+ else if (strspn(image_info->filename, safechars) != strlen(image_info->filename))\n+ {\n+ strncpy(linkedinfoname,image_info->filename,MaxTextExtent-1);\n+ if (!AcquireTemporarySymlink(image_info->filename,linkedinfoname))\n+\t{\n+ if (temporary_image_filename)\n+ LiberateTemporaryFile(image->filename);\n+ (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->filename);\n+ return(False);\n+ }\n+ temporary_image_filename=True;\n+ }\n \n if (delegate_info->mode != 0)\n if ((decode && (delegate_info->encode != (char *) NULL)) ||\n@@ -617,6 +648,13 @@ MagickExport unsigned int InvokeDelegate\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->unique);\n return(False);\n }\n@@ -625,6 +663,13 @@ MagickExport unsigned int InvokeDelegate\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n (void) LiberateTemporaryFile(image_info->unique);\n (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->zero);\n return(False);\n@@ -638,6 +683,13 @@ MagickExport unsigned int InvokeDelegate\n (void) LiberateTemporaryFile(image_info->zero);\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n (void) ThrowException(exception,DelegateError,DelegateFailed,\n decode ? decode : encode);\n return(False);\n@@ -663,6 +715,13 @@ MagickExport unsigned int InvokeDelegate\n (void) LiberateTemporaryFile(image_info->zero);\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n DestroyImageInfo(clone_info);\n (void) ThrowException(exception,DelegateError,DelegateFailed,\n decode ? decode : encode);\n@@ -684,6 +743,13 @@ MagickExport unsigned int InvokeDelegate\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+ if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+ if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+ }\n (void) ThrowException(exception,ResourceLimitError,MemoryAllocationFailed,decode ? decode : encode);\n return(False);\n }\n@@ -810,6 +876,13 @@ MagickExport unsigned int InvokeDelegate\n error_exit:\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+ if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+ if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+ }\n for ( ; commands[i] != (char *) NULL; i++)\n MagickFreeMemory(commands[i]);\n MagickFreeMemory(commands);\nIndex: GraphicsMagick-1.3.18/magick/symbols.h\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/symbols.h\n+++ GraphicsMagick-1.3.18/magick/symbols.h\n@@ -43,6 +43,7 @@\n #define AcquireTemporaryFileDescriptor GmAcquireTemporaryFileDescriptor\n #define AcquireTemporaryFileName GmAcquireTemporaryFileName\n #define AcquireTemporaryFileStream GmAcquireTemporaryFileStream\n+#define AcquireTemporarySymlink GmAcquireTemporarySymlink\n #define AdaptiveThresholdImage GmAdaptiveThresholdImage\n #define AddDefinition GmAddDefinition\n #define AddDefinitions GmAddDefinitions\nIndex: GraphicsMagick-1.3.18/magick/tempfile.c\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/tempfile.c\n+++ GraphicsMagick-1.3.18/magick/tempfile.c\n@@ -192,6 +192,93 @@ MagickExport MagickPassFail AcquireTempo\n % %\n % %\n % %\n++ A c q u i r e T e m p o r a r y S y m l i n k %\n+% %\n+% %\n+% %\n+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n+%\n+% AcquireTemporarySymlink replaces the contents of the string buffer pointed\n+% to by filename with the unique name of a symbolic link. True is returned\n+% if a symlink\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "Index: GraphicsMagick-1.3.18/magick/delegate.c\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/delegate.c\n+++ GraphicsMagick-1.3.18/magick/delegate.c\n@@ -539,7 +539,10 @@ MagickExport unsigned int InvokeDelegate\n char\n *command,\n **commands,\n- filename[MaxTextExtent];\n+ linkedname[MaxTextExtent],\n+ linkedinfoname[MaxTextExtent],\n+ filename[MaxTextExtent],\n+ safechars[]=\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,-_+ /\";\n \n const DelegateInfo\n *delegate_info;\n@@ -559,6 +562,10 @@ MagickExport unsigned int InvokeDelegate\n assert(image != (Image *) NULL);\n assert(image->signature == MagickSignature);\n temporary_image_filename=(*image->filename == '\\0');\n+ linkedname[0]='\\0';\n+ linkedname[MaxTextExtent-1]='\\0';\n+ linkedinfoname[0]='\\0';\n+ linkedinfoname[MaxTextExtent-1]='\\0';\n if (temporary_image_filename)\n {\n /* Allocate a temporary filename if image is unnamed. */\n@@ -568,12 +575,24 @@ MagickExport unsigned int InvokeDelegate\n return(False);\n }\n }\n+ else if (strspn(image->filename, safechars) != strlen(image->filename))\n+ {\n+ strncpy(linkedname,image->filename,MaxTextExtent-1);\n+ if (!AcquireTemporarySymlink(image->filename,linkedname))\n+\t{\n+ (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image->filename);\n+\t return (False);\n+\t}\n+ }\n+\n (void) strlcpy(filename,image->filename,MaxTextExtent);\n delegate_info=GetDelegateInfo(decode,encode,exception);\n if (delegate_info == (DelegateInfo *) NULL)\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+ if (*linkedname)\n+\tstrncpy(image->filename,linkedname,MaxTextExtent-1);\n (void) ThrowException(exception,DelegateError,NoTagFound,\n decode ? decode : encode);\n return(False);\n@@ -594,6 +613,18 @@ MagickExport unsigned int InvokeDelegate\n }\n image_info->temporary=True;\n }\n+ else if (strspn(image_info->filename, safechars) != strlen(image_info->filename))\n+ {\n+ strncpy(linkedinfoname,image_info->filename,MaxTextExtent-1);\n+ if (!AcquireTemporarySymlink(image_info->filename,linkedinfoname))\n+\t{\n+ if (temporary_image_filename)\n+ LiberateTemporaryFile(image->filename);\n+ (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->filename);\n+ return(False);\n+ }\n+ temporary_image_filename=True;\n+ }\n \n if (delegate_info->mode != 0)\n if ((decode && (delegate_info->encode != (char *) NULL)) ||\n@@ -617,6 +648,13 @@ MagickExport unsigned int InvokeDelegate\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->unique);\n return(False);\n }\n@@ -625,6 +663,13 @@ MagickExport unsigned int InvokeDelegate\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n (void) LiberateTemporaryFile(image_info->unique);\n (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->zero);\n return(False);\n@@ -638,6 +683,13 @@ MagickExport unsigned int InvokeDelegate\n (void) LiberateTemporaryFile(image_info->zero);\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n (void) ThrowException(exception,DelegateError,DelegateFailed,\n decode ? decode : encode);\n return(False);\n@@ -663,6 +715,13 @@ MagickExport unsigned int InvokeDelegate\n (void) LiberateTemporaryFile(image_info->zero);\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n DestroyImageInfo(clone_info);\n (void) ThrowException(exception,DelegateError,DelegateFailed,\n decode ? decode : encode);\n@@ -684,6 +743,13 @@ MagickExport unsigned int InvokeDelegate\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+ if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+ if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+ }\n (void) ThrowException(exception,ResourceLimitError,MemoryAllocationFailed,decode ? decode : encode);\n return(False);\n }\n@@ -810,6 +876,13 @@ MagickExport unsigned int InvokeDelegate\n error_exit:\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+ if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+ if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+ }\n for ( ; commands[i] != (char *) NULL; i++)\n MagickFreeMemory(commands[i]);\n MagickFreeMemory(commands);\nIndex: GraphicsMagick-1.3.18/magick/symbols.h\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/symbols.h\n+++ GraphicsMagick-1.3.18/magick/symbols.h\n@@ -43,6 +43,7 @@\n #define AcquireTemporaryFileDescriptor GmAcquireTemporaryFileDescriptor\n #define AcquireTemporaryFileName GmAcquireTemporaryFileName\n #define AcquireTemporaryFileStream GmAcquireTemporaryFileStream\n+#define AcquireTemporarySymlink GmAcquireTemporarySymlink\n #define AdaptiveThresholdImage GmAdaptiveThresholdImage\n #define AddDefinition GmAddDefinition\n #define AddDefinitions GmAddDefinitions\nIndex: GraphicsMagick-1.3.18/magick/tempfile.c\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/tempfile.c\n+++ GraphicsMagick-1.3.18/magick/tempfile.c\n@@ -192,6 +192,93 @@ MagickExport MagickPassFail AcquireTempo\n % %\n % %\n % %\n++ A c q u i r e T e m p o r a r y S y m l i n k %\n+% %\n+% %\n+% %\n+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n+%\n+% AcquireTemporarySymlink replaces the contents of the string buffer pointed\n+% to by filename with the unique name of a symbolic link. True is returned\n+% if a symlink waas created, or False is returned if there is a failure.\n+% The allocated symlink should be recovered via the LiberateTemporaryFile()\n+% function once it is no longer required.\n+%\n+% The format of the AcquireTemporarySymlink method is:\n+%\n+% unsigned int AcquireTemporarySymlink(char *linkname, const char *name,\n+% ExceptionInfo *exception)\n+%\n+% A description of each parameter follows.\n+%\n+% o linkname: Specifies a pointer to an array of characters that must be\n+% MaxTextExtent characters of size. The unique\n+% name of the symlink is returned in this array.\n+% o name: Specifies a file name the symlink should point to.\n+*/\n+MagickExport unsigned int AcquireTemporarySymlink(char *linkname, const char *name)\n+{\n+ char\n+ *tempdir,\n+ tempname[MaxTextExtent];\n+\n+ int\n+ fd,\n+ tries;\n+ \n+ assert(linkname != (char *)NULL);\n+ linkname[0]='\\0';\n+ tempname[MaxTextExtent-1]='\\0';\n+\n+ tempdir=getenv(\"MAGICK_TMPDIR\");\n+#if defined(POSIX)\n+ if (!tempdir)\n+ tempdir=getenv(\"TMPDIR\");\n+#endif /* POSIX */\n+#if defined(WIN32)\n+ if (!tempdir)\n+ tempdir=getenv(\"TMP\");\n+ if (!tempdir)\n+ tempdir=getenv(\"TEMP\");\n+#endif /* WIN32 */\n+#if defined(P_tmpdir)\n+ if (!tempdir)\n+ tempdir=P_tmpdir;\n+#endif\n+\n+ for (tries=0; tries < 15; tries++)\n+ {\n+ strncpy(tempname,\"gmXXXXXX\",MaxTextExtent-1);\n+ ComposeTemporaryFileName(tempname);\n+ strncpy(linkname,tempdir,MaxTextExtent-1);\n+ if (tempdir[strlen(tempdir)-1] != DirectorySeparator[0])\n+\tstrncat(linkname,DirectorySeparator,MaxTextExtent-1);\n+ strncat(linkname,tempname,MaxTextExtent-1);\n+ if (*name == '/')\n+ fd=symlink(name, linkname);\n+ else\n+ {\n+ char cname[MaxTextExtent];\n+\t if (!getcwd(cname,(size_t)MaxTextExtent))\n+\t return (False);\n+\t strncat(cname,DirectorySeparator,MaxTextExtent-1);\n+\t strncat(cname,name,MaxTextExtent-1);\n+\t fd=symlink(cname,linkname);\n+\t}\n+ if (fd != -1)\n+\t{\n+\t AddTemporaryFileToList(linkname);\n+\t return (True);\n+\t}\n+ }\n+ return (False);\n+}\n+\f\n+/*\n+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n+% %\n+% %\n+% %\n + A c q u i r e T e m p o r a r y F i l e D e s c r i p t o r %\n % %\n % %\nIndex: GraphicsMagick-1.3.18/magick/tempfile.h\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/tempfile.h\n+++ GraphicsMagick-1.3.18/magick/tempfile.h\n@@ -24,6 +24,7 @@ typedef enum\n \n MagickExport MagickPassFail\n AcquireTemporaryFileName(char *filename),\n+ AcquireTemporarySymlink(char *linkname, const char *name),\n LiberateTemporaryFile(char *filename);\n \n MagickExport int\nIndex: GraphicsMagick-1.3.18/magick/utility.c\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/utility.c\n+++ GraphicsMagick-1.3.18/magick/utility.c\n@@ -1253,6 +1253,72 @@ MagickExport void FormatString(char *str\n % %\n % %\n % %\n+% F o r m a t S t r i n g N u m e r i c %\n+% %\n+% %\n+% %\n+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n+%\n+% Method FormatStringNumeric formats output for a single numeric argument.\n+% It takes into account that the format string given might be untrusted\n+% user input, and returns a pointer to the formatted string.\n+%\n+% The format of the FormatStringNumeric method is:\n+%\n+% char * FormatStringNumeric(char *string,const char *format,int value)\n+%\n+% A description of each parameter follows.\n+%\n+% o format: A string describing the format to use to write the numeric\n+% argument. Only the first numeric format identifier is replaced.\n+%\n+% o value: Numeric value to substitute into format string.\n+%\n+%\n+*/\n+MagickExport char *FormatStringNumeric(const char *format,int value)\n+{\n+ char\n+ *p,\n+ *string;\n+\n+ string = NULL;\n+\n+ (void) CloneString(&string, format);\n+\n+ for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))\n+ { \n+ char\n+ *q;\n+\n+ q=(char *) p+1;\n+ if (*q == '0')\n+ (void) strtol(q,&q,10);\n+ if ((*q == '%') || (*q == 'd') || (*q == 'o') || (*q == 'x'))\n+ {\n+ char\n+ c;\n+\n+ q++;\n+ c=*q;\n+ *q='\\0';\n+ (void) snprintf(string+(p-format),MaxTextExtent-(p-format),p,value);\n+ *q=c;\n+ (void) ConcatenateString(&string,q);\n+ if (*(q-1) == '%')\n+ p++;\n+ else\n+ break;\n+ }\n+ }\n+ return string;\n+}\n+\f\n+/*\n+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n+% %\n+% %\n+% %\n % G e t E x e c u t i o n P a t h %\n % %\n % %\nIndex: GraphicsMagick-1.3.18/magick/utility.h\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/utility.h\n+++ GraphicsMagick-1.3.18/magick/utility.h\n@@ -72,6 +72,7 @@ extern MagickExport char\n *AllocateString(const char *),\n *Base64Encode(const unsigned char *,const size_t,size_t *),\n *EscapeString(const char *,const char),\n+ *FormatStringNumeric(const char *,int),\n *GetPageGeometry(const char *),\n **ListFiles(const char *,const char *,long *),\n **StringToArgv(const char *,int *),"}], "metadata": {"id": "GraphicsMagick-5161-GraphicsMagick-debian-fixed.pa", "cve_id": "CVE-2016-5118", "package": "GraphicsMagick", "tier": "adapted", "has_source_context": false, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1i/crypto/rand/rand_lib.c\n- openssl-1.0.1i.orig/crypto/rand/rand.h\n- openssl-1.0.1i.orig/crypto/fips/fips_drbg_rand.c\n- openssl-1.0.1i.orig/crypto/rand/rand_lib.c\n- openssl-1.0.1i/crypto/fips/fips_drbg_rand.c\n\n## Target Source Code\n\n### crypto/rand/md_rand.c\n\n#### region() [lines 104-196]\n```c\n * ====================================================================\n *\n * This product includes cryptographic software written by Eric Young\n * (eay@cryptsoft.com). This product includes software written by Tim\n * Hudson (tjh@cryptsoft.com).\n *\n */\n\n#define OPENSSL_FIPSEVP\n\n#ifdef MD_RAND_DEBUG\n# ifndef NDEBUG\n# define NDEBUG\n# endif\n#endif\n\n#include \n#include \n#include \n\n#include \"e_os.h\"\n\n#include \n#include \n#include \"rand_lcl.h\"\n\n#include \n\n#ifdef BN_DEBUG\n# define PREDICT\n#endif\n\n/* #define PREDICT\t1 */\n\n#define STATE_SIZE\t1023\nstatic int state_num=0,state_index=0;\nstatic unsigned char state[STATE_SIZE+MD_DIGEST_LENGTH];\nstatic unsigned char md[MD_DIGEST_LENGTH];\nstatic long md_count[2]={0,0};\nstatic double entropy=0;\nstatic int initialized=0;\n\nstatic unsigned int crypto_lock_rand = 0; /* may be set only when a thread\n * holds CRYPTO_LOCK_RAND\n * (to prevent double locking) */\n/* access to lockin_thread is synchronized by CRYPTO_LOCK_RAND2 */\nstatic CRYPTO_THREADID locking_threadid; /* valid iff crypto_lock_rand is set */\n\n\n#ifdef PREDICT\nint rand_predictable=0;\n#endif\n\nconst char RAND_version[]=\"RAND\" OPENSSL_VERSION_PTEXT;\n\nstatic void ssleay_rand_cleanup(void);\nstatic void ssleay_rand_seed(const void *buf, int num);\nstatic void ssleay_rand_add(const void *buf, int num, double add_entropy);\nstatic int ssleay_rand_nopseudo_bytes(unsigned char *buf, int num);\nstatic int ssleay_rand_pseudo_bytes(unsigned char *buf, int num);\nstatic int ssleay_rand_status(void);\n\nRAND_METHOD rand_ssleay_meth={\n\tssleay_rand_seed,\n\tssleay_rand_nopseudo_bytes,\n\tssleay_rand_cleanup,\n\tssleay_rand_add,\n\tssleay_rand_pseudo_bytes,\n\tssleay_rand_status\n\t}; \n\nRAND_METHOD *RAND_SSLeay(void)\n\t{\n\treturn(&rand_ssleay_meth);\n\t}\n\nstatic void ssleay_rand_cleanup(void)\n\t{\n\tOPENSSL_cleanse(state,sizeof(state));\n\tstate_num=0;\n\tstate_index=0;\n\tOPENSSL_cleanse(md,MD_DIGEST_LENGTH);\n\tmd_count[0]=0;\n\tmd_count[1]=0;\n\tentropy=0;\n\tinitialized=0;\n\t}\n\nstatic void ssleay_rand_add(const void *buf, int num, double add)\n\t{\n\tint i,j,k,st_idx;\n\tlong md_c[2];\n\tunsigned char local_md[MD_DIGEST_LENGTH];\n```\n\n#### ssleay_rand_add() [lines 189-331]\n```c\n\tinitialized=0;\n\t}\n\nstatic void ssleay_rand_add(const void *buf, int num, double add)\n\t{\n\tint i,j,k,st_idx;\n\tlong md_c[2];\n\tunsigned char local_md[MD_DIGEST_LENGTH];\n\tEVP_MD_CTX m;\n\tint do_not_lock;\n\n\tif (!num)\n\t\treturn;\n\n\t/*\n\t * (Based on the rand(3) manpage)\n\t *\n\t * The input is chopped up into units of 20 bytes (or less for\n\t * the last block). Each of these blocks is run through the hash\n\t * function as follows: The data passed to the hash function\n\t * is the current 'md', the same number of bytes from the 'state'\n\t * (the location determined by in incremented looping index) as\n\t * the current 'block', the new key data 'block', and 'count'\n\t * (which is incremented after each use).\n\t * The result of this is kept in 'md' and also xored into the\n\t * 'state' at the same locations that were used as input into the\n * hash function.\n\t */\n\n\t/* check if we already have the lock */\n\tif (crypto_lock_rand)\n\t\t{\n\t\tCRYPTO_THREADID cur;\n\t\tCRYPTO_THREADID_current(&cur);\n\t\tCRYPTO_r_lock(CRYPTO_LOCK_RAND2);\n\t\tdo_not_lock = !CRYPTO_THREADID_cmp(&locking_threadid, &cur);\n\t\tCRYPTO_r_unlock(CRYPTO_LOCK_RAND2);\n\t\t}\n\telse\n\t\tdo_not_lock = 0;\n/* ... 96 lines omitted ... */\n\n\tif (!do_not_lock) CRYPTO_w_lock(CRYPTO_LOCK_RAND);\n\t/* Don't just copy back local_md into md -- this could mean that\n\t * other thread's seeding remains without effect (except for\n\t * the incremented counter). By XORing it we keep at least as\n\t * much entropy as fits into md. */\n\tfor (k = 0; k < (int)sizeof(md); k++)\n\t\t{\n\t\tmd[k] ^= local_md[k];\n\t\t}\n\tif (entropy < ENTROPY_NEEDED) /* stop counting when we have enough */\n\t entropy += add;\n\tif (!do_not_lock) CRY\n/* ... truncated ... */\n```\n\n### crypto/rand/rand.h\n\n#### RAND_set_fips_drbg_type() [lines 85-151]\n```c\n\tvoid (*cleanup)(void);\n\tvoid (*add)(const void *buf, int num, double entropy);\n\tint (*pseudorand)(unsigned char *buf, int num);\n\tint (*status)(void);\n\t};\n\n#ifdef BN_DEBUG\nextern int rand_predictable;\n#endif\n\nint RAND_set_rand_method(const RAND_METHOD *meth);\nconst RAND_METHOD *RAND_get_rand_method(void);\n#ifndef OPENSSL_NO_ENGINE\nint RAND_set_rand_engine(ENGINE *engine);\n#endif\nRAND_METHOD *RAND_SSLeay(void);\nvoid RAND_cleanup(void );\nint RAND_bytes(unsigned char *buf,int num);\nint RAND_pseudo_bytes(unsigned char *buf,int num);\nvoid RAND_seed(const void *buf,int num);\nvoid RAND_add(const void *buf,int num,double entropy);\nint RAND_load_file(const char *file,long max_bytes);\nint RAND_write_file(const char *file);\nconst char *RAND_file_name(char *file,size_t num);\nint RAND_status(void);\nint RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes);\nint RAND_egd(const char *path);\nint RAND_egd_bytes(const char *path,int bytes);\nint RAND_poll(void);\n\n#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)\n\nvoid RAND_screen(void);\nint RAND_event(UINT, WPARAM, LPARAM);\n\n#endif\n\n#ifdef OPENSSL_FIPS\nvoid RAND_set_fips_drbg_type(int type, int flags);\nint RAND_init_fips(void);\n#endif\n\n/* BEGIN ERROR CODES */\n/* The following lines are auto generated by the script mkerr.pl. Any changes\n * made after this point may be overwritten when the script is next run.\n */\nvoid ERR_load_RAND_strings(void);\n\n/* Error codes for the RAND functions. */\n\n/* Function codes. */\n#define RAND_F_RAND_GET_RAND_METHOD\t\t\t 101\n#define RAND_F_RAND_INIT_FIPS\t\t\t\t 102\n#define RAND_F_SSLEAY_RAND_BYTES\t\t\t 100\n\n/* Reason codes. */\n#define RAND_R_DUAL_EC_DRBG_DISABLED\t\t\t 104\n#define RAND_R_ERROR_INITIALISING_DRBG\t\t\t 102\n#define RAND_R_ERROR_INSTANTIATING_DRBG\t\t\t 103\n#define RAND_R_NO_FIPS_RANDOM_METHOD_SET\t\t 101\n#define RAND_R_PRNG_NOT_SEEDED\t\t\t\t 100\n\n#ifdef __cplusplus\n}\n#endif\n#endif\n\n```\n\n### crypto/rand/rand_lib.c\n\n#### RAND_status() [lines 174-185]\n```c\n\treturn(-1);\n\t}\n\nint RAND_status(void)\n\t{\n\tconst RAND_METHOD *meth = RAND_get_rand_method();\n\tif (meth && meth->status)\n\t\treturn meth->status();\n\treturn 0;\n\t}\n\n#ifdef OPENSSL_FIPS\n```\n\n#### drbg_rand_add() [lines 236-246]\n```c\n * correctly seeded by RAND_poll().\n */\n\nstatic int drbg_rand_add(DRBG_CTX *ctx, const void *in, int inlen,\n\t\t\t\tdouble entropy)\n\t{\n\tRAND_SSLeay()->add(in, inlen, entropy);\n\treturn 1;\n\t}\n\nstatic int drbg_rand_seed(DRBG_CTX *ctx, const void *in, int inlen)\n```\n\n#### drbg_rand_seed() [lines 243-252]\n```c\n\treturn 1;\n\t}\n\nstatic int drbg_rand_seed(DRBG_CTX *ctx, const void *in, int inlen)\n\t{\n\tRAND_SSLeay()->seed(in, inlen);\n\treturn 1;\n\t}\n\n#ifndef OPENSSL_DRBG_DEFAULT_TYPE\n```\n\n\n## Upstream Fix\n```diff\nIndex: openssl-1.0.1i/crypto/fips/fips_drbg_rand.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/fips/fips_drbg_rand.c\t2014-10-15 14:16:52.709471327 +0200\n+++ openssl-1.0.1i/crypto/fips/fips_drbg_rand.c\t2014-10-15 14:16:52.834472848 +0200\n@@ -77,7 +77,8 @@ static int fips_drbg_bytes(unsigned char\n \tint rv = 0;\n \tunsigned char *adin = NULL;\n \tsize_t adinlen = 0;\n-\tCRYPTO_w_lock(CRYPTO_LOCK_RAND);\n+\tint locked;\n+\tlocked = private_RAND_lock(1);\n \tdo \n \t\t{\n \t\tsize_t rcnt;\n@@ -109,7 +110,8 @@ static int fips_drbg_bytes(unsigned char\n \twhile (count);\n \trv = 1;\n \terr:\n-\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n \treturn rv;\n \t}\n \n@@ -124,35 +126,51 @@ static int fips_drbg_status(void)\n \t{\n \tDRBG_CTX *dctx = &ossl_dctx;\n \tint rv;\n-\tCRYPTO_r_lock(CRYPTO_LOCK_RAND);\n+\tint locked;\n+\tlocked = private_RAND_lock(1);\n \trv = dctx->status == DRBG_STATUS_READY ? 1 : 0;\n-\tCRYPTO_r_unlock(CRYPTO_LOCK_RAND);\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n \treturn rv;\n \t}\n \n static void fips_drbg_cleanup(void)\n \t{\n \tDRBG_CTX *dctx = &ossl_dctx;\n-\tCRYPTO_w_lock(CRYPTO_LOCK_RAND);\n+\tint locked;\n+\tlocked = private_RAND_lock(1);\n \tFIPS_drbg_uninstantiate(dctx);\n-\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n \t}\n \n static int fips_drbg_seed(const void *seed, int seedlen)\n \t{\n \tDRBG_CTX *dctx = &ossl_dctx;\n+\tint locked;\n+\tint ret = 1;\n+\n+\tlocked = private_RAND_lock(1);\n \tif (dctx->rand_seed_cb)\n-\t\treturn dctx->rand_seed_cb(dctx, seed, seedlen);\n-\treturn 1;\n+\t\tret = dctx->rand_seed_cb(dctx, seed, seedlen);\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n+\treturn ret;\n \t}\n \n static int fips_drbg_add(const void *seed, int seedlen,\n \t\t\t\t\tdouble add_entropy)\n \t{\n \tDRBG_CTX *dctx = &ossl_dctx;\n+\tint locked;\n+\tint ret = 1;\n+\n+\tlocked = private_RAND_lock(1);\n \tif (dctx->rand_add_cb)\n-\t\treturn dctx->rand_add_cb(dctx, seed, seedlen, add_entropy);\n-\treturn 1;\n+\t\tret = dctx->rand_add_cb(dctx, seed, seedlen, add_entropy);\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n+\treturn ret;\n \t}\n \n static const RAND_METHOD rand_drbg_meth =\nIndex: openssl-1.0.1i/crypto/rand/md_rand.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/rand/md_rand.c\t2014-10-15 14:16:52.715471400 +0200\n+++ openssl-1.0.1i/crypto/rand/md_rand.c\t2014-10-15 14:16:52.834472848 +0200\n@@ -143,12 +143,6 @@ static long md_count[2]={0,0};\n static double entropy=0;\n static int initialized=0;\n \n-static unsigned int crypto_lock_rand = 0; /* may be set only when a thread\n- * holds CRYPTO_LOCK_RAND\n- * (to prevent double locking) */\n-/* access to lockin_thread is synchronized by CRYPTO_LOCK_RAND2 */\n-static CRYPTO_THREADID locking_threadid; /* valid iff crypto_lock_rand is set */\n-\n \n #ifdef PREDICT\n int rand_predictable=0;\n@@ -195,7 +189,7 @@ static void ssleay_rand_add(const void *\n \tlong md_c[2];\n \tunsigned char local_md[MD_DIGEST_LENGTH];\n \tEVP_MD_CTX m;\n-\tint do_not_lock;\n+\tint locked;\n \n \tif (!num)\n \t\treturn;\n@@ -215,19 +209,8 @@ static void ssleay_rand_add(const void *\n * hash function.\n \t */\n \n-\t/* check if we already have the lock */\n-\tif (crypto_lock_rand)\n-\t\t{\n-\t\tCRYPTO_THREADID cur;\n-\t\tCRYPTO_THREADID_current(&cur);\n-\t\tCRYPTO_r_lock(CRYPTO_LOCK_RAND2);\n-\t\tdo_not_lock = !CRYPTO_THREADID_cmp(&locking_threadid, &cur);\n-\t\tCRYPTO_r_unlock(CRYPTO_LOCK_RAND2);\n-\t\t}\n-\telse\n-\t\tdo_not_lock = 0;\n+\tlocked = private_RAND_lock(1);\n \n-\tif (!do_not_lock) CRYPTO_w_lock(CRYPTO_LOCK_RAND);\n \tst_idx=state_index;\n \n \t/* use our own copies of the counters so that even\n@@ -259,7 +242,8 @@ static void ssleay_rand_add(const void *\n \n \tmd_count[1] += (num / MD_DIGEST_LENGTH) + (num % MD_DIGEST_LENGTH > 0);\n \n-\tif (!do_not_lock) CRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n \n \tEVP_MD_CTX_init(&m);\n \tfor (i=0; i 0)\n \t\t{\n@@ -519,11 +498,11 @@ int ssleay_rand_bytes(unsigned char *buf\n \tMD_Update(&m,(unsigned char *)&(md_c[0]),sizeof(md_c));\n \tMD_Update(&m,local_md,MD_DIGEST_LENGTH);\n \tif (lock)\n-\t\tCRYPTO_w_lock(CRYPTO_LOCK_RAND);\n+\t\tlocked = private_RAND_lock(1);\n \tMD_Update(&m,md,MD_DIGEST_LENGTH);\n \tMD_Final(&m,md);\n-\tif (lock)\n-\t\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n+\tif (lock && locked)\n+\t\tprivate_RAND_lock(0);\n \n \tEVP_MD_CTX_cleanup(&m);\n \tif (ok)\n@@ -553,32 +532,10 @@ static int ssleay_rand_pseudo_bytes(unsi\n \n static int ssleay_rand_status(void)\n \t{\n-\tCRYPTO_THREADID cur;\n \tint ret;\n-\tint do_not_lock;\n+\tint locked;\n \n-\tCRYPTO_THREADID_current(&cur);\n-\t/* check if we already have the lock\n-\t * (could happen if a RAND_poll() implementation calls RAND_status()) */\n-\tif (crypto_lock_rand)\n-\t\t{\n-\t\tCRYPTO_r_lock(CRYPTO_LOCK_RAND2);\n-\t\tdo_not_lock = !CRYPTO_THREADID_cmp(&locking_threadid, &cur);\n-\t\tCRYPTO_r_unlock(CRYPTO_LOCK_RAND2);\n-\t\t}\n-\telse\n-\t\tdo_not_lock = 0;\n-\t\n-\tif (!do_not_lock)\n-\t\t{\n-\t\tCRYPTO_w_lock(CRYPTO_LOCK_RAND);\n-\t\t\n-\t\t/* prevent ssleay_rand_bytes() from trying to obtain the lock again */\n-\t\tCRYPTO_w_lock(CRYPTO_LOCK_RAND2);\n-\t\tCRYPTO_THREADID_cpy(&locking_threadid, &cur);\n-\t\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND2);\n-\t\tcrypto_lock_rand = 1;\n-\t\t}\n+\tlocked = private_RAND_lock(1);\n \t\n \tif (!initialized)\n \t\t{\n@@ -588,13 +545,8 @@ static int ssleay_rand_status(void)\n \n \tret = entropy >= ENTROPY_NEEDED;\n \n-\tif (!do_not_lock)\n-\t\t{\n-\t\t/* before unlocking, we must clear 'crypto_lock_rand' */\n-\t\tcrypto_lock_rand = 0;\n-\t\t\n-\t\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n-\t\t}\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n \t\n \treturn ret;\n \t}\nIndex: openssl-1.0.1i/crypto/rand/rand.h\n===================================================================\n--- openssl-1.0.1i.orig/crypto/rand/rand.h\t2014-10-15 14:16:52.715471400 +0200\n+++ openssl-1.0.1i/crypto/rand/rand.h\t2014-10-15 14:16:52.834472848 +0200\n@@ -124,6 +124,8 @@ void RAND_set_fips_drbg_type(int type, i\n int RAND_init_fips(void);\n #endif\n \n+int private_RAND_lock(int lock);\n+\n /* BEGIN ERROR CODES */\n /* The following lines are auto generated by the script mkerr.pl. Any changes\n * made after this point may be overwritten when the script is next run.\nIndex: openssl-1.0.1i/crypto/rand/rand_lib.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/rand/rand_lib.c\t2\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "Index: openssl-1.0.1i/crypto/fips/fips_drbg_rand.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/fips/fips_drbg_rand.c\t2014-10-15 14:16:52.709471327 +0200\n+++ openssl-1.0.1i/crypto/fips/fips_drbg_rand.c\t2014-10-15 14:16:52.834472848 +0200\n@@ -77,7 +77,8 @@ static int fips_drbg_bytes(unsigned char\n \tint rv = 0;\n \tunsigned char *adin = NULL;\n \tsize_t adinlen = 0;\n-\tCRYPTO_w_lock(CRYPTO_LOCK_RAND);\n+\tint locked;\n+\tlocked = private_RAND_lock(1);\n \tdo \n \t\t{\n \t\tsize_t rcnt;\n@@ -109,7 +110,8 @@ static int fips_drbg_bytes(unsigned char\n \twhile (count);\n \trv = 1;\n \terr:\n-\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n \treturn rv;\n \t}\n \n@@ -124,35 +126,51 @@ static int fips_drbg_status(void)\n \t{\n \tDRBG_CTX *dctx = &ossl_dctx;\n \tint rv;\n-\tCRYPTO_r_lock(CRYPTO_LOCK_RAND);\n+\tint locked;\n+\tlocked = private_RAND_lock(1);\n \trv = dctx->status == DRBG_STATUS_READY ? 1 : 0;\n-\tCRYPTO_r_unlock(CRYPTO_LOCK_RAND);\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n \treturn rv;\n \t}\n \n static void fips_drbg_cleanup(void)\n \t{\n \tDRBG_CTX *dctx = &ossl_dctx;\n-\tCRYPTO_w_lock(CRYPTO_LOCK_RAND);\n+\tint locked;\n+\tlocked = private_RAND_lock(1);\n \tFIPS_drbg_uninstantiate(dctx);\n-\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n \t}\n \n static int fips_drbg_seed(const void *seed, int seedlen)\n \t{\n \tDRBG_CTX *dctx = &ossl_dctx;\n+\tint locked;\n+\tint ret = 1;\n+\n+\tlocked = private_RAND_lock(1);\n \tif (dctx->rand_seed_cb)\n-\t\treturn dctx->rand_seed_cb(dctx, seed, seedlen);\n-\treturn 1;\n+\t\tret = dctx->rand_seed_cb(dctx, seed, seedlen);\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n+\treturn ret;\n \t}\n \n static int fips_drbg_add(const void *seed, int seedlen,\n \t\t\t\t\tdouble add_entropy)\n \t{\n \tDRBG_CTX *dctx = &ossl_dctx;\n+\tint locked;\n+\tint ret = 1;\n+\n+\tlocked = private_RAND_lock(1);\n \tif (dctx->rand_add_cb)\n-\t\treturn dctx->rand_add_cb(dctx, seed, seedlen, add_entropy);\n-\treturn 1;\n+\t\tret = dctx->rand_add_cb(dctx, seed, seedlen, add_entropy);\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n+\treturn ret;\n \t}\n \n static const RAND_METHOD rand_drbg_meth =\nIndex: openssl-1.0.1i/crypto/rand/md_rand.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/rand/md_rand.c\t2014-10-15 14:16:52.715471400 +0200\n+++ openssl-1.0.1i/crypto/rand/md_rand.c\t2014-10-15 14:16:52.834472848 +0200\n@@ -143,12 +143,6 @@ static long md_count[2]={0,0};\n static double entropy=0;\n static int initialized=0;\n \n-static unsigned int crypto_lock_rand = 0; /* may be set only when a thread\n- * holds CRYPTO_LOCK_RAND\n- * (to prevent double locking) */\n-/* access to lockin_thread is synchronized by CRYPTO_LOCK_RAND2 */\n-static CRYPTO_THREADID locking_threadid; /* valid iff crypto_lock_rand is set */\n-\n \n #ifdef PREDICT\n int rand_predictable=0;\n@@ -195,7 +189,7 @@ static void ssleay_rand_add(const void *\n \tlong md_c[2];\n \tunsigned char local_md[MD_DIGEST_LENGTH];\n \tEVP_MD_CTX m;\n-\tint do_not_lock;\n+\tint locked;\n \n \tif (!num)\n \t\treturn;\n@@ -215,19 +209,8 @@ static void ssleay_rand_add(const void *\n * hash function.\n \t */\n \n-\t/* check if we already have the lock */\n-\tif (crypto_lock_rand)\n-\t\t{\n-\t\tCRYPTO_THREADID cur;\n-\t\tCRYPTO_THREADID_current(&cur);\n-\t\tCRYPTO_r_lock(CRYPTO_LOCK_RAND2);\n-\t\tdo_not_lock = !CRYPTO_THREADID_cmp(&locking_threadid, &cur);\n-\t\tCRYPTO_r_unlock(CRYPTO_LOCK_RAND2);\n-\t\t}\n-\telse\n-\t\tdo_not_lock = 0;\n+\tlocked = private_RAND_lock(1);\n \n-\tif (!do_not_lock) CRYPTO_w_lock(CRYPTO_LOCK_RAND);\n \tst_idx=state_index;\n \n \t/* use our own copies of the counters so that even\n@@ -259,7 +242,8 @@ static void ssleay_rand_add(const void *\n \n \tmd_count[1] += (num / MD_DIGEST_LENGTH) + (num % MD_DIGEST_LENGTH > 0);\n \n-\tif (!do_not_lock) CRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n \n \tEVP_MD_CTX_init(&m);\n \tfor (i=0; i 0)\n \t\t{\n@@ -519,11 +498,11 @@ int ssleay_rand_bytes(unsigned char *buf\n \tMD_Update(&m,(unsigned char *)&(md_c[0]),sizeof(md_c));\n \tMD_Update(&m,local_md,MD_DIGEST_LENGTH);\n \tif (lock)\n-\t\tCRYPTO_w_lock(CRYPTO_LOCK_RAND);\n+\t\tlocked = private_RAND_lock(1);\n \tMD_Update(&m,md,MD_DIGEST_LENGTH);\n \tMD_Final(&m,md);\n-\tif (lock)\n-\t\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n+\tif (lock && locked)\n+\t\tprivate_RAND_lock(0);\n \n \tEVP_MD_CTX_cleanup(&m);\n \tif (ok)\n@@ -553,32 +532,10 @@ static int ssleay_rand_pseudo_bytes(unsi\n \n static int ssleay_rand_status(void)\n \t{\n-\tCRYPTO_THREADID cur;\n \tint ret;\n-\tint do_not_lock;\n+\tint locked;\n \n-\tCRYPTO_THREADID_current(&cur);\n-\t/* check if we already have the lock\n-\t * (could happen if a RAND_poll() implementation calls RAND_status()) */\n-\tif (crypto_lock_rand)\n-\t\t{\n-\t\tCRYPTO_r_lock(CRYPTO_LOCK_RAND2);\n-\t\tdo_not_lock = !CRYPTO_THREADID_cmp(&locking_threadid, &cur);\n-\t\tCRYPTO_r_unlock(CRYPTO_LOCK_RAND2);\n-\t\t}\n-\telse\n-\t\tdo_not_lock = 0;\n-\t\n-\tif (!do_not_lock)\n-\t\t{\n-\t\tCRYPTO_w_lock(CRYPTO_LOCK_RAND);\n-\t\t\n-\t\t/* prevent ssleay_rand_bytes() from trying to obtain the lock again */\n-\t\tCRYPTO_w_lock(CRYPTO_LOCK_RAND2);\n-\t\tCRYPTO_THREADID_cpy(&locking_threadid, &cur);\n-\t\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND2);\n-\t\tcrypto_lock_rand = 1;\n-\t\t}\n+\tlocked = private_RAND_lock(1);\n \t\n \tif (!initialized)\n \t\t{\n@@ -588,13 +545,8 @@ static int ssleay_rand_status(void)\n \n \tret = entropy >= ENTROPY_NEEDED;\n \n-\tif (!do_not_lock)\n-\t\t{\n-\t\t/* before unlocking, we must clear 'crypto_lock_rand' */\n-\t\tcrypto_lock_rand = 0;\n-\t\t\n-\t\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n-\t\t}\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n \t\n \treturn ret;\n \t}\nIndex: openssl-1.0.1i/crypto/rand/rand.h\n===================================================================\n--- openssl-1.0.1i.orig/crypto/rand/rand.h\t2014-10-15 14:16:52.715471400 +0200\n+++ openssl-1.0.1i/crypto/rand/rand.h\t2014-10-15 14:16:52.834472848 +0200\n@@ -124,6 +124,8 @@ void RAND_set_fips_drbg_type(int type, i\n int RAND_init_fips(void);\n #endif\n \n+int private_RAND_lock(int lock);\n+\n /* BEGIN ERROR CODES */\n /* The following lines are auto generated by the script mkerr.pl. Any changes\n * made after this point may be overwritten when the script is next run.\nIndex: openssl-1.0.1i/crypto/rand/rand_lib.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/rand/rand_lib.c\t2014-10-15 14:16:52.741471717 +0200\n+++ openssl-1.0.1i/crypto/rand/rand_lib.c\t2014-10-15 14:16:52.835472860 +0200\n@@ -182,6 +182,41 @@ int RAND_status(void)\n \treturn 0;\n \t}\n \n+int private_RAND_lock(int lock)\n+\t{\n+\tstatic int crypto_lock_rand;\n+\tstatic CRYPTO_THREADID locking_threadid;\n+\tint do_lock;\n+\n+\tif (!lock)\n+\t\t{\n+\t\tcrypto_lock_rand = 0;\n+\t\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n+\t\treturn 0;\n+\t\t}\n+\n+\t/* check if we already have the lock */\n+\tif (crypto_lock_rand)\n+\t\t{\n+\t\tCRYPTO_THREADID cur;\n+\t\tCRYPTO_THREADID_current(&cur);\n+\t\tCRYPTO_r_lock(CRYPTO_LOCK_RAND2);\n+\t\tdo_lock = !!CRYPTO_THREADID_cmp(&locking_threadid, &cur);\n+\t\tCRYPTO_r_unlock(CRYPTO_LOCK_RAND2);\n+\t\t}\n+ else\n+\t\tdo_lock = 1;\n+\tif (do_lock)\n+\t\t{\n+\t\tCRYPTO_w_lock(CRYPTO_LOCK_RAND);\n+\t\tCRYPTO_w_lock(CRYPTO_LOCK_RAND2);\n+\t\tCRYPTO_THREADID_current(&locking_threadid);\n+\t\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND2);\n+\t\tcrypto_lock_rand = 1;\n+\t\t}\n+\treturn do_lock;\n+\t}\n+\n #ifdef OPENSSL_FIPS\n \n /* FIPS DRBG initialisation code. This sets up the DRBG for use by the\n@@ -242,9 +277,9 @@ static int drbg_rand_add(DRBG_CTX *ctx,\n \tRAND_SSLeay()->add(in, inlen, entropy);\n \tif (FIPS_rand_status())\n \t\t{\n-\t\tCRYPTO_w_lock(CRYPTO_LOCK_RAND);\n+\t\tint locked = private_RAND_lock(1);\n \t\tFIPS_drbg_reseed(ctx, NULL, 0);\n-\t\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n+\t\tif (locked) private_RAND_lock(0);\n \t\t}\n \treturn 1;\n \t}\n@@ -254,9 +289,9 @@ static int drbg_rand_seed(DRBG_CTX *ctx,\n \tRAND_SSLeay()->seed(in, inlen);\n \tif (FIPS_rand_status())\n \t\t{\n-\t\tCRYPTO_w_lock(CRYPTO_LOCK_RAND);\n+\t\tint locked = private_RAND_lock(1);\n \t\tFIPS_drbg_reseed(ctx, NULL, 0);\n-\t\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n+\t\tif (locked) private_RAND_lock(0);\n \t\t}\n \treturn 1;\n \t}"}], "metadata": {"id": "openssl-4769-openssl-1.0.1i-fipslocking.pat", "cve_id": "CVE-2015-3197", "package": "openssl", "tier": "adapted", "has_source_context": true, "context_tokens_est": 1698, "context_files": 3, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-6250\n\nInteger overflow in the ISO9660 writer in libarchive before 3.2.1 allows remote attackers to cause a denial of service (application crash) or execute arbitrary code via vectors related to verifying filename lengths when writing an ISO9660 archive, which trigger a buffer overflow.\n\n## Package\nlibarchive\n\n## Files to modify\n- libarchive-3.1.2.orig/libarchive/archive_read_support_format_mtree.c\n- libarchive/archive_read_support_format_mtree.c\n- libarchive/test/test_read_format_mtree_crash747.c\n\n## Target Source Code\n\n### Makefile.am\n\n#### region() [lines 375-461]\n```c\n\tlibarchive/test/test_read_format_ar.c\t\t\t\\\n\tlibarchive/test/test_read_format_cab.c\t\t\t\\\n\tlibarchive/test/test_read_format_cab_filename.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_afio.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin_Z.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin_be.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin_bz2.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin_gz.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin_lzip.c\t\\\n\tlibarchive/test/test_read_format_cpio_bin_lzma.c\t\\\n\tlibarchive/test/test_read_format_cpio_bin_xz.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_filename.c\t\\\n\tlibarchive/test/test_read_format_cpio_odc.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_svr4_bzip2_rpm.c\t\\\n\tlibarchive/test/test_read_format_cpio_svr4_gzip.c\t\\\n\tlibarchive/test/test_read_format_cpio_svr4_gzip_rpm.c\t\\\n\tlibarchive/test/test_read_format_cpio_svr4c_Z.c\t\t\\\n\tlibarchive/test/test_read_format_empty.c\t\t\\\n\tlibarchive/test/test_read_format_gtar_filename.c\t\\\n\tlibarchive/test/test_read_format_gtar_gz.c\t\t\\\n\tlibarchive/test/test_read_format_gtar_lzma.c\t\t\\\n\tlibarchive/test/test_read_format_gtar_sparse.c\t\t\\\n\tlibarchive/test/test_read_format_iso_Z.c\t\t\\\n\tlibarchive/test/test_read_format_iso_multi_extent.c\t\\\n\tlibarchive/test/test_read_format_iso_xorriso.c\t\t\\\n\tlibarchive/test/test_read_format_isojoliet_bz2.c\t\\\n\tlibarchive/test/test_read_format_isojoliet_long.c\t\\\n\tlibarchive/test/test_read_format_isojoliet_rr.c\t\t\\\n\tlibarchive/test/test_read_format_isojoliet_versioned.c\t\\\n\tlibarchive/test/test_read_format_isorr_bz2.c\t\t\\\n\tlibarchive/test/test_read_format_isorr_ce.c\t\t\\\n\tlibarchive/test/test_read_format_isorr_new_bz2.c\t\\\n\tlibarchive/test/test_read_format_isorr_rr_moved.c\t\\\n\tlibarchive/test/test_read_format_isozisofs_bz2.c\t\\\n\tlibarchive/test/test_read_format_lha.c\t\t\t\\\n\tlibarchive/test/test_read_format_lha_filename.c\t\t\\\n\tlibarchive/test/test_read_format_mtree.c\t\t\\\n\tlibarchive/test/test_read_format_pax_bz2.c\t\t\\\n\tlibarchive/test/test_read_format_rar.c\t\t\t\\\n\tlibarchive/test/test_read_format_raw.c\t\t\t\\\n\tlibarchive/test/test_read_format_tar.c\t\t\t\\\n\tlibarchive/test/test_read_format_tar_empty_filename.c\t\\\n\tlibarchive/test/test_read_format_tar_filename.c\t\t\\\n\tlibarchive/test/test_read_format_tbz.c\t\t\t\\\n\tlibarchive/test/test_read_format_tgz.c\t\t\t\\\n\tlibarchive/test/test_read_format_tlz.c\t\t\t\\\n\tlibarchive/test/test_read_format_txz.c\t\t\t\\\n\tlibarchive/test/test_read_format_tz.c\t\t\t\\\n\tlibarchive/test/test_read_format_ustar_filename.c\t\\\n\tlibarchive/test/test_read_form\n/* ... truncated ... */\n```\n\n### libarchive/archive_read_support_format_mtree.c\n\n#### get_line_size() [lines 240-276]\n```c\n}\n\nstatic ssize_t\nget_line_size(const char *b, ssize_t avail, ssize_t *nlsize)\n{\n\tssize_t len;\n\n\tlen = 0;\n\twhile (len < avail) {\n\t\tswitch (*b) {\n\t\tcase '\\0':/* Non-ascii character or control character. */\n\t\t\tif (nlsize != NULL)\n\t\t\t\t*nlsize = 0;\n\t\t\treturn (-1);\n\t\tcase '\\r':\n\t\t\tif (avail-len > 1 && b[1] == '\\n') {\n\t\t\t\tif (nlsize != NULL)\n\t\t\t\t\t*nlsize = 2;\n\t\t\t\treturn (len+2);\n\t\t\t}\n\t\t\t/* FALL THROUGH */\n\t\tcase '\\n':\n\t\t\tif (nlsize != NULL)\n\t\t\t\t*nlsize = 1;\n\t\t\treturn (len+1);\n\t\tdefault:\n\t\t\tb++;\n\t\t\tlen++;\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (nlsize != NULL)\n\t\t*nlsize = 0;\n\treturn (avail);\n}\n\nstatic ssize_t\n```\n\n#### next_line() [lines 274-321]\n```c\n}\n\nstatic ssize_t\nnext_line(struct archive_read *a,\n const char **b, ssize_t *avail, ssize_t *ravail, ssize_t *nl)\n{\n\tssize_t len;\n\tint quit;\n\t\n\tquit = 0;\n\tif (*avail == 0) {\n\t\t*nl = 0;\n\t\tlen = 0;\n\t} else\n\t\tlen = get_line_size(*b, *avail, nl);\n\t/*\n\t * Read bytes more while it does not reach the end of line.\n\t */\n\twhile (*nl == 0 && len == *avail && !quit) {\n\t\tssize_t diff = *ravail - *avail;\n\t\tsize_t nbytes_req = (*ravail+1023) & ~1023U;\n\t\tssize_t tested;\n\n\t\t/* Increase reading bytes if it is not enough to at least\n\t\t * new two lines. */\n\t\tif (nbytes_req < (size_t)*ravail + 160)\n\t\t\tnbytes_req <<= 1;\n\n\t\t*b = __archive_read_ahead(a, nbytes_req, avail);\n\t\tif (*b == NULL) {\n\t\t\tif (*ravail >= *avail)\n\t\t\t\treturn (0);\n\t\t\t/* Reading bytes reaches the end of file. */\n\t\t\t*b = __archive_read_ahead(a, *avail, avail);\n\t\t\tquit = 1;\n\t\t}\n\t\t*ravail = *avail;\n\t\t*b += diff;\n\t\t*avail -= diff;\n\t\ttested = len;/* Skip some bytes we already determinated. */\n\t\tlen = get_line_size(*b, *avail, nl);\n\t\tif (len >= 0)\n\t\t\tlen += tested;\n\t}\n\treturn (len);\n}\n\n/*\n```\n\n### libarchive/test/CMakeLists.txt\n\n#### IF() [lines 87-173]\n```c\n test_read_filter_program_signature.c\n test_read_filter_uudecode.c\n test_read_format_7zip.c\n test_read_format_ar.c\n test_read_format_cab.c\n test_read_format_cab_filename.c\n test_read_format_cpio_afio.c\n test_read_format_cpio_bin.c\n test_read_format_cpio_bin_Z.c\n test_read_format_cpio_bin_be.c\n test_read_format_cpio_bin_bz2.c\n test_read_format_cpio_bin_gz.c\n test_read_format_cpio_bin_lzip.c\n test_read_format_cpio_bin_lzma.c\n test_read_format_cpio_bin_xz.c\n test_read_format_cpio_filename.c\n test_read_format_cpio_odc.c\n test_read_format_cpio_svr4_bzip2_rpm.c\n test_read_format_cpio_svr4_gzip.c\n test_read_format_cpio_svr4_gzip_rpm.c\n test_read_format_cpio_svr4c_Z.c\n test_read_format_empty.c\n test_read_format_gtar_filename.c\n test_read_format_gtar_gz.c\n test_read_format_gtar_lzma.c\n test_read_format_gtar_sparse.c\n test_read_format_iso_Z.c\n test_read_format_iso_multi_extent.c\n test_read_format_iso_xorriso.c\n test_read_format_isojoliet_bz2.c\n test_read_format_isojoliet_long.c\n test_read_format_isojoliet_rr.c\n test_read_format_isojoliet_versioned.c\n test_read_format_isorr_bz2.c\n test_read_format_isorr_ce.c\n test_read_format_isorr_new_bz2.c\n test_read_format_isorr_rr_moved.c\n test_read_format_isozisofs_bz2.c\n test_read_format_lha.c\n test_read_format_lha_filename.c\n test_read_format_mtree.c\n test_read_format_pax_bz2.c\n test_read_format_rar.c\n test_read_format_raw.c\n test_read_format_tar.c\n test_read_format_tar_empty_filename.c\n test_read_format_tar_filename.c\n test_read_format_tbz.c\n test_read_format_tgz.c\n test_read_format_tlz.c\n test_read_format_txz.c\n test_read_format_tz.c\n test_read_format_ustar_filename.c\n test_read_format_xar.c\n test_read_format_zip.c\n test_read_format_zip_comment_stored.c\n test_read_format_zip_filename.c\n test_read_format_zip_mac_metadata.c\n test_read_format_zip_sfx.c\n test_read_large.c\n test_read_pax_truncated.c\n test_read_position.c\n test_read_set_format.c\n test_read_truncated.c\n test_read_truncated_filter.c\n test_sparse_basic.c\n test_tar_filenames.c\n test_tar_large.c\n test_ustar_filenames.c\n test_ustar_filename_encoding.c\n test_write_disk.c\n test_write_disk_appledouble.c\n test_write_disk_failures.c\n test_write_disk_hardlink.c\n test_write_disk_hfs_compression.c\n test_write_disk_lookup.c\n test_write_disk_mac_metadata.c\n test_wri\n/* ... truncated ... */\n```\n\n\n### Type definitions\n\n```c\n/* from archive_private.h */\nstruct archive {\n\t/*\n\t * The magic/state values are used to sanity-check the\n\t * client's usage. If an API function is called at a\n\t * ridiculous time, or the client passes us an invalid\n\t * pointer, these values allow me to catch that.\n\t */\n\tunsigned int\tmagic;\n\tunsigned int\tstate;\n\n\t/*\n\t * Some public API functions depend on the \"real\" type of the\n\t * archive object.\n\t */\n\tstruct archive_vtable *vtable;\n\n\tint\t\t archive_format;\n\tconst char\t *archive_format_name;\n\n\tint\t compression_code;\t/* Currently active compression. */\n\tconst char *compression_name;\n\n\t/* Number of file entries processed. */\n\tint\t\t file_count;\n\n\tint\t\t archive_error_number;\n\tconst char\t *error;\n\tstruct archive_string\terror_string;\n\n\tchar *current_code;\n\tunsigned current_codepage; /* Current ACP(ANSI CodePage). */\n\tunsigned current_oemcp; /* Current OEMCP(OEM CodePage). */\n\tstruct archive_string_conv *sconv;\n};\n```\n\n\n## Upstream Fix\n```diff\ncommit eec077f52bfa2d3f7103b4b74d52572ba8a15aca\nAuthor: Tim Kientzle \nDate: Sun Sep 18 17:27:47 2016 -0700\n\n Issue 747 (and others?): Avoid OOB read when parsing multiple long lines\n \n The mtree bidder needs to look several lines ahead\n in the input. It does this by extending the read-ahead\n and parsing subsequent lines from the same growing buffer.\n A bookkeeping error when extending the read-ahead would\n sometimes lead it to significantly over-count the\n size of the line being read.\n\nIndex: libarchive-3.1.2/Makefile.am\n===================================================================\n--- libarchive-3.1.2.orig/Makefile.am\n+++ libarchive-3.1.2/Makefile.am\n@@ -414,6 +414,7 @@ libarchive_test_SOURCES=\t\t\t\t\t\\\n \tlibarchive/test/test_read_format_lha.c\t\t\t\\\n \tlibarchive/test/test_read_format_lha_filename.c\t\t\\\n \tlibarchive/test/test_read_format_mtree.c\t\t\\\n+\tlibarchive/test/test_read_format_mtree_crash747.c\t\\\n \tlibarchive/test/test_read_format_pax_bz2.c\t\t\\\n \tlibarchive/test/test_read_format_rar.c\t\t\t\\\n \tlibarchive/test/test_read_format_rar_invalid1.c\t\t\\\nIndex: libarchive-3.1.2/libarchive/archive_read_support_format_mtree.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_read_support_format_mtree.c\n+++ libarchive-3.1.2/libarchive/archive_read_support_format_mtree.c\n@@ -277,6 +277,15 @@ get_line_size(const char *b, ssize_t ava\n \treturn (avail);\n }\n \n+/*\n+ * <---------------- ravail --------------------->\n+ * <-- diff ------> <--- avail ----------------->\n+ * <---- len ----------->\n+ * | Previous lines | line being parsed nl extra |\n+ * ^\n+ * b\n+ *\n+ */\n static ssize_t\n next_line(struct archive_read *a,\n const char **b, ssize_t *avail, ssize_t *ravail, ssize_t *nl)\n@@ -315,7 +324,7 @@ next_line(struct archive_read *a,\n \t\t*b += diff;\n \t\t*avail -= diff;\n \t\ttested = len;/* Skip some bytes we already determinated. */\n-\t\tlen = get_line_size(*b, *avail, nl);\n+\t\tlen = get_line_size(*b + len, *avail - len, nl);\n \t\tif (len >= 0)\n \t\t\tlen += tested;\n \t}\nIndex: libarchive-3.1.2/libarchive/test/CMakeLists.txt\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/test/CMakeLists.txt\n+++ libarchive-3.1.2/libarchive/test/CMakeLists.txt\n@@ -126,6 +126,7 @@ IF(ENABLE_TEST)\n test_read_format_lha.c\n test_read_format_lha_filename.c\n test_read_format_mtree.c\n+ test_read_format_mtree_crash747.c\n test_read_format_pax_bz2.c\n test_read_format_rar.c\n test_read_format_raw.c\nIndex: libarchive-3.1.2/libarchive/test/test_read_format_mtree_crash747.c\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_format_mtree_crash747.c\n@@ -0,0 +1,44 @@\n+/*-\n+ * Copyright (c) 2003-2016 Tim Kientzle\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ * 1. Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in the\n+ * documentation and/or other materials provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR\n+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,\n+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+#include \"test.h\"\n+\n+\n+/*\n+ * Reproduce the crash reported in Github Issue #747.\n+ */\n+DEFINE_TEST(test_read_format_mtree_crash747)\n+{\n+\tconst char *reffile = \"test_read_format_mtree_crash747.mtree.bz2\";\n+\tstruct archive *a;\n+\n+\textract_reference_file(reffile);\n+\n+\tassert((a = archive_read_new()) != NULL);\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_bzip2(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_mtree(a));\n+\tassertEqualIntA(a, ARCHIVE_FATAL, archive_read_open_filename(a, reffile, 10240));\n+\tassertEqualInt(ARCHIVE_OK, archive_read_free(a));\n+}\n+\nIndex: libarchive-3.1.2/libarchive/test/test_read_format_mtree_crash747.mtree.bz2.uu\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_format_mtree_crash747.mtree.bz2.uu\n@@ -0,0 +1,6 @@\n+begin 600 test_read_format_mtree_crash747.mtree.bz2\n+M0EIH.3%!62936:OH@(@``'/[@,`0`@!``'^\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "commit eec077f52bfa2d3f7103b4b74d52572ba8a15aca\nAuthor: Tim Kientzle \nDate: Sun Sep 18 17:27:47 2016 -0700\n\n Issue 747 (and others?): Avoid OOB read when parsing multiple long lines\n \n The mtree bidder needs to look several lines ahead\n in the input. It does this by extending the read-ahead\n and parsing subsequent lines from the same growing buffer.\n A bookkeeping error when extending the read-ahead would\n sometimes lead it to significantly over-count the\n size of the line being read.\n\nIndex: libarchive-3.1.2/Makefile.am\n===================================================================\n--- libarchive-3.1.2.orig/Makefile.am\n+++ libarchive-3.1.2/Makefile.am\n@@ -414,6 +414,7 @@ libarchive_test_SOURCES=\t\t\t\t\t\\\n \tlibarchive/test/test_read_format_lha.c\t\t\t\\\n \tlibarchive/test/test_read_format_lha_filename.c\t\t\\\n \tlibarchive/test/test_read_format_mtree.c\t\t\\\n+\tlibarchive/test/test_read_format_mtree_crash747.c\t\\\n \tlibarchive/test/test_read_format_pax_bz2.c\t\t\\\n \tlibarchive/test/test_read_format_rar.c\t\t\t\\\n \tlibarchive/test/test_read_format_rar_invalid1.c\t\t\\\nIndex: libarchive-3.1.2/libarchive/archive_read_support_format_mtree.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_read_support_format_mtree.c\n+++ libarchive-3.1.2/libarchive/archive_read_support_format_mtree.c\n@@ -277,6 +277,15 @@ get_line_size(const char *b, ssize_t ava\n \treturn (avail);\n }\n \n+/*\n+ * <---------------- ravail --------------------->\n+ * <-- diff ------> <--- avail ----------------->\n+ * <---- len ----------->\n+ * | Previous lines | line being parsed nl extra |\n+ * ^\n+ * b\n+ *\n+ */\n static ssize_t\n next_line(struct archive_read *a,\n const char **b, ssize_t *avail, ssize_t *ravail, ssize_t *nl)\n@@ -315,7 +324,7 @@ next_line(struct archive_read *a,\n \t\t*b += diff;\n \t\t*avail -= diff;\n \t\ttested = len;/* Skip some bytes we already determinated. */\n-\t\tlen = get_line_size(*b, *avail, nl);\n+\t\tlen = get_line_size(*b + len, *avail - len, nl);\n \t\tif (len >= 0)\n \t\t\tlen += tested;\n \t}\nIndex: libarchive-3.1.2/libarchive/test/CMakeLists.txt\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/test/CMakeLists.txt\n+++ libarchive-3.1.2/libarchive/test/CMakeLists.txt\n@@ -126,6 +126,7 @@ IF(ENABLE_TEST)\n test_read_format_lha.c\n test_read_format_lha_filename.c\n test_read_format_mtree.c\n+ test_read_format_mtree_crash747.c\n test_read_format_pax_bz2.c\n test_read_format_rar.c\n test_read_format_raw.c\nIndex: libarchive-3.1.2/libarchive/test/test_read_format_mtree_crash747.c\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_format_mtree_crash747.c\n@@ -0,0 +1,44 @@\n+/*-\n+ * Copyright (c) 2003-2016 Tim Kientzle\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ * 1. Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in the\n+ * documentation and/or other materials provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR\n+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,\n+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+#include \"test.h\"\n+\n+\n+/*\n+ * Reproduce the crash reported in Github Issue #747.\n+ */\n+DEFINE_TEST(test_read_format_mtree_crash747)\n+{\n+\tconst char *reffile = \"test_read_format_mtree_crash747.mtree.bz2\";\n+\tstruct archive *a;\n+\n+\textract_reference_file(reffile);\n+\n+\tassert((a = archive_read_new()) != NULL);\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_bzip2(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_mtree(a));\n+\tassertEqualIntA(a, ARCHIVE_FATAL, archive_read_open_filename(a, reffile, 10240));\n+\tassertEqualInt(ARCHIVE_OK, archive_read_free(a));\n+}\n+\nIndex: libarchive-3.1.2/libarchive/test/test_read_format_mtree_crash747.mtree.bz2.uu\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_format_mtree_crash747.mtree.bz2.uu\n@@ -0,0 +1,6 @@\n+begin 600 test_read_format_mtree_crash747.mtree.bz2\n+M0EIH.3%!62936:OH@(@``'/[@,`0`@!``'^```)A@9\\`$`@@`'4)049!IIH!\n+MM021-0,F@&@6````9%>$(K!GIC*XFR0`$```J0+:$XP```!D-F)H[#SE9+2'\n+4+E\"L=ASXUI%R(I\"HD'ZA(5?1`Q``\n+`\n+end"}], "metadata": {"id": "libarchive-5940-CVE-2016-8688.patch", "cve_id": "CVE-2016-6250", "package": "libarchive", "tier": "adapted", "has_source_context": true, "context_tokens_est": 1986, "context_files": 3, "license": "BSD-2-Clause"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1i/crypto/x509/x509_req.c\n- openssl-1.0.1i.orig/crypto/x509/x509_req.c\n\n## Target Source Code\n\n### crypto/x509/x509_req.c\n\n#### region() [lines 53-139]\n```c\n * The licence and distribution terms for any publically available version or\n * derivative of this code cannot be changed. i.e. this code cannot simply be\n * copied and put under another distribution licence\n * [including the GNU Public Licence.]\n */\n\n#include \n#include \"cryptlib.h\"\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nX509_REQ *X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md)\n\t{\n\tX509_REQ *ret;\n\tX509_REQ_INFO *ri;\n\tint i;\n\tEVP_PKEY *pktmp;\n\n\tret=X509_REQ_new();\n\tif (ret == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_TO_X509_REQ,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\n\tri=ret->req_info;\n\n\tri->version->length=1;\n\tri->version->data=(unsigned char *)OPENSSL_malloc(1);\n\tif (ri->version->data == NULL) goto err;\n\tri->version->data[0]=0; /* version == 0 */\n\n\tif (!X509_REQ_set_subject_name(ret,X509_get_subject_name(x)))\n\t\tgoto err;\n\n\tpktmp = X509_get_pubkey(x);\n\ti=X509_REQ_set_pubkey(ret,pktmp);\n\tEVP_PKEY_free(pktmp);\n\tif (!i) goto err;\n\n\tif (pkey != NULL)\n\t\t{\n\t\tif (!X509_REQ_sign(ret,pkey,md))\n\t\t\tgoto err;\n\t\t}\n\treturn(ret);\nerr:\n\tX509_REQ_free(ret);\n\treturn(NULL);\n\t}\n\nEVP_PKEY *X509_REQ_get_pubkey(X509_REQ *req)\n\t{\n\tif ((req == NULL) || (req->req_info == NULL))\n\t\treturn(NULL);\n\treturn(X509_PUBKEY_get(req->req_info->pubkey));\n\t}\n\nint X509_REQ_check_private_key(X509_REQ *x, EVP_PKEY *k)\n\t{\n\tEVP_PKEY *xk=NULL;\n\tint ok=0;\n\n\txk=X509_REQ_get_pubkey(x);\n\tswitch (EVP_PKEY_cmp(xk, k))\n\t\t{\n\tcase 1:\n\t\tok=1;\n\t\tbreak;\n\tcase 0:\n\t\tX509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY,X509_R_KEY_VALUES_MISMATCH);\n\t\tbreak;\n\tcase -1:\n\t\tX509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY,X509_R_KEY_TYPE_MISMATCH);\n\t\tbreak;\n\tcase -2:\n#ifndef OPENSSL_NO_EC\n\t\tif (k->type == EVP_PKEY_EC)\n\t\t\t{\n\t\t\tX509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY, ERR_R_EC_LIB);\n\t\t\tbreak;\n```\n\n\n## Upstream Fix\n```diff\nFrom 28a00bcd8e318da18031b2ac8778c64147cd54f9 Mon Sep 17 00:00:00 2001\nFrom: \"Dr. Stephen Henson\" \nDate: Wed, 18 Feb 2015 00:34:59 +0000\nSubject: [PATCH] Check public key is not NULL.\n\nCVE-2015-0288\nPR#3708\n\nReviewed-by: Matt Caswell \n---\n crypto/x509/x509_req.c | 2 ++\n 1 file changed, 2 insertions(+)\n\ndiff --git a/crypto/x509/x509_req.c b/crypto/x509/x509_req.c\nindex bc6e566c95b42..01795f4b3f370 100644\n--- a/crypto/x509/x509_req.c\n+++ b/crypto/x509/x509_req.c\n@@ -92,6 +92,8 @@ X509_REQ *X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md)\n goto err;\n \n pktmp = X509_get_pubkey(x);\n+ if (pktmp == NULL)\n+ goto err;\n i = X509_REQ_set_pubkey(ret, pktmp);\n EVP_PKEY_free(pktmp);\n if (!i)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "commit 51527f1e3564f210e984fe5b654c45d34e4f03d7\nAuthor: Dr. Stephen Henson \nDate: Wed Feb 18 00:34:59 2015 +0000\n\n Check public key is not NULL.\n \n CVE-2015-0288\n PR#3708\n \n Reviewed-by: Matt Caswell \n (cherry picked from commit 28a00bcd8e318da18031b2ac8778c64147cd54f9)\n\nIndex: openssl-1.0.1i/crypto/x509/x509_req.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/x509/x509_req.c\t2015-03-17 13:22:30.712726374 +0100\n+++ openssl-1.0.1i/crypto/x509/x509_req.c\t2015-03-17 13:23:20.486453016 +0100\n@@ -92,6 +92,8 @@ X509_REQ *X509_to_X509_REQ(X509 *x, EVP_\n \t\tgoto err;\n \n \tpktmp = X509_get_pubkey(x);\n+\tif (pktmp == NULL)\n+\t\tgoto err;\n \ti=X509_REQ_set_pubkey(ret,pktmp);\n \tEVP_PKEY_free(pktmp);\n \tif (!i) goto err;"}], "metadata": {"id": "openssl-4769-openssl-CVE-2015-0288.patch", "cve_id": "CVE-2015-3197", "package": "openssl", "upstream_enriched": true, "upstream_commit": "28a00bcd8e318da18031b2ac8778c64147cd54f9", "upstream_repo": "openssl/openssl", "tier": "adapted", "has_source_context": true, "context_tokens_est": 497, "context_files": 1, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-4658\n\nxpointer.c in libxml2 before 2.9.5 (as used in Apple iOS before 10, OS X before 10.12, tvOS before 10, and watchOS before 3, and other products) does not forbid namespace nodes in XPointer ranges, which allows remote attackers to execute arbitrary code or cause a denial of service (use-after-free and memory corruption) via a crafted XML document.\n\n## Package\nlibxml2\n\n## Files to modify\n- libxml2-2.9.1/parser.c\n\n## Target Source Code\n\n### parser.c\n\n#### xmlParseEntityDecl() [lines 5620-5636]\n```c\n\t\t/*\n\t\t * Check for an Empty Element labeled the XML/SGML way\n\t\t */\n\t\tif ((CUR == '/') && (NXT(1) == '>')) {\n\t\t SKIP(2);\n\t\t if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL))\n\t\t\tctxt->sax->endElement(ctxt->userData, name);\n\t\t htmlnamePop(ctxt);\n\t\t ctxt->instate = XML_PARSER_CONTENT;\n#ifdef DEBUG_PUSH\n\t\t xmlGenericError(xmlGenericErrorContext,\n\t\t\t \"HPP: entering CONTENT\\n\");\n#endif\n\t\t break;\n\t\t}\n\n\t\tif (CUR == '>') {\n```\n\n#### xmlParseConditionalSections() [lines 6704-6790]\n```c\n ret = ctxt->myDoc;\n ctxt->myDoc = NULL;\n if (!reuse) {\n if ((ctxt->dictNames) &&\n\t (ret != NULL) &&\n\t (ret->dict == ctxt->dict))\n\t ctxt->dict = NULL;\n\txmlFreeParserCtxt(ctxt);\n }\n return (ret);\n}\n\n/**\n * htmlReadDoc:\n * @cur: a pointer to a zero terminated string\n * @URL: the base URL to use for the document\n * @encoding: the document encoding, or NULL\n * @options: a combination of htmlParserOption(s)\n *\n * parse an XML in-memory document and build a tree.\n *\n * Returns the resulting document tree\n */\nhtmlDocPtr\nhtmlReadDoc(const xmlChar * cur, const char *URL, const char *encoding, int options)\n{\n htmlParserCtxtPtr ctxt;\n\n if (cur == NULL)\n return (NULL);\n\n xmlInitParser();\n ctxt = htmlCreateDocParserCtxt(cur, NULL);\n if (ctxt == NULL)\n return (NULL);\n return (htmlDoRead(ctxt, URL, encoding, options, 0));\n}\n\n/**\n * htmlReadFile:\n * @filename: a file or URL\n * @encoding: the document encoding, or NULL\n * @options: a combination of htmlParserOption(s)\n *\n * parse an XML file from the filesystem or the network.\n *\n * Returns the resulting document tree\n */\nhtmlDocPtr\nhtmlReadFile(const char *filename, const char *encoding, int options)\n{\n htmlParserCtxtPtr ctxt;\n\n xmlInitParser();\n ctxt = htmlCreateFileParserCtxt(filename, encoding);\n if (ctxt == NULL)\n return (NULL);\n return (htmlDoRead(ctxt, NULL, NULL, options, 0));\n}\n\n/**\n * htmlReadMemory:\n * @buffer: a pointer to a char array\n * @size: the size of the array\n * @URL: the base URL to use for the document\n * @encoding: the document encoding, or NULL\n * @options: a combination of htmlParserOption(s)\n *\n * parse an XML in-memory document and build a tree.\n *\n * Returns the resulting document tree\n */\nhtmlDocPtr\nhtmlReadMemory(const char *buffer, int size, const char *URL, const char *encoding, int options)\n{\n htmlParserCtxtPtr ctxt;\n\n xmlInitParser();\n ctxt = xmlCreateMemoryParserCtxt(buffer, size);\n if (ctxt == NULL)\n return (NULL);\n htmlDefaultSAXHandlerInit();\n if (ctxt->sax != NULL)\n memcpy(ctxt->sax, &htmlDefaultSAXHandler, sizeof(xmlSAXHandlerV1));\n return (htmlDoRead(ctxt, URL, encoding, options, 0));\n}\n\n```\n\n#### xmlParseConditionalSections() [lines 6764-6850]\n```c\n/**\n * htmlReadMemory:\n * @buffer: a pointer to a char array\n * @size: the size of the array\n * @URL: the base URL to use for the document\n * @encoding: the document encoding, or NULL\n * @options: a combination of htmlParserOption(s)\n *\n * parse an XML in-memory document and build a tree.\n *\n * Returns the resulting document tree\n */\nhtmlDocPtr\nhtmlReadMemory(const char *buffer, int size, const char *URL, const char *encoding, int options)\n{\n htmlParserCtxtPtr ctxt;\n\n xmlInitParser();\n ctxt = xmlCreateMemoryParserCtxt(buffer, size);\n if (ctxt == NULL)\n return (NULL);\n htmlDefaultSAXHandlerInit();\n if (ctxt->sax != NULL)\n memcpy(ctxt->sax, &htmlDefaultSAXHandler, sizeof(xmlSAXHandlerV1));\n return (htmlDoRead(ctxt, URL, encoding, options, 0));\n}\n\n/**\n * htmlReadFd:\n * @fd: an open file descriptor\n * @URL: the base URL to use for the document\n * @encoding: the document encoding, or NULL\n * @options: a combination of htmlParserOption(s)\n *\n * parse an XML from a file descriptor and build a tree.\n *\n * Returns the resulting document tree\n */\nhtmlDocPtr\nhtmlReadFd(int fd, const char *URL, const char *encoding, int options)\n{\n htmlParserCtxtPtr ctxt;\n xmlParserInputBufferPtr input;\n xmlParserInputPtr stream;\n\n if (fd < 0)\n return (NULL);\n\n xmlInitParser();\n input = xmlParserInputBufferCreateFd(fd, XML_CHAR_ENCODING_NONE);\n if (input == NULL)\n return (NULL);\n ctxt = xmlNewParserCtxt();\n if (ctxt == NULL) {\n xmlFreeParserInputBuffer(input);\n return (NULL);\n }\n stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE);\n if (stream == NULL) {\n xmlFreeParserInputBuffer(input);\n\txmlFreeParserCtxt(ctxt);\n return (NULL);\n }\n inputPush(ctxt, stream);\n return (htmlDoRead(ctxt, URL, encoding, options, 0));\n}\n\n/**\n * htmlReadIO:\n * @ioread: an I/O read function\n * @ioclose: an I/O close function\n * @ioctx: an I/O handler\n * @URL: the base URL to use for the document\n * @encoding: the document encoding, or NULL\n * @options: a combination of htmlParserOption(s)\n *\n * parse an HTML document from I/O functions and source and build a tree.\n *\n * Returns the resulting document tree\n */\nhtmlDocPtr\nhtmlReadIO(xmlInputReadCallback ioread, xmlInputCloseCallback ioclose,\n void *ioctx, const char *URL, const char *encoding, int options)\n{\n htmlParserCtxtPtr ctxt;\n xmlParserInputBufferPtr input;\n xmlParserInputPtr stream;\n```\n\n#### xmlParseConditionalSections() [lines 6855-6864]\n```c\n\n input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,\n XML_CHAR_ENCODING_NONE);\n if (input == NULL) {\n if (ioclose != NULL)\n ioclose(ioctx);\n return (NULL);\n }\n ctxt = htmlNewParserCtxt();\n if (ctxt == NULL) {\n```\n\n\n## Upstream Fix\n```diff\n--- libxml2-2.9.1/parser.c\t\n+++ libxml2-2.9.1/parser.c\t\n@@ -5632,6 +5632,7 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt\n \tif (RAW != '>') {\n \t xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_NOT_FINISHED,\n \t \"xmlParseEntityDecl: entity %s not terminated\\n\", name);\n+\t xmlStopParser(ctxt);\n \t} else {\n \t if (input != ctxt->input) {\n \t\txmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,\n@@ -6743,6 +6744,8 @@ xmlParseConditionalSections(xmlParserCtx\n \tSKIP_BLANKS;\n \tif (RAW != '[') {\n \t xmlFatalErr(ctxt, XML_ERR_CONDSEC_INVALID, NULL);\n+\t xmlStopParser(ctxt);\n+\t return;\n \t} else {\n \t if (ctxt->input->id != id) {\n \t\txmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY,\n@@ -6803,6 +6806,8 @@ xmlParseConditionalSections(xmlParserCtx\n \tSKIP_BLANKS;\n \tif (RAW != '[') {\n \t xmlFatalErr(ctxt, XML_ERR_CONDSEC_INVALID, NULL);\n+\t xmlStopParser(ctxt);\n+\t return;\n \t} else {\n \t if (ctxt->input->id != id) {\n \t\txmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY,\n@@ -6858,6 +6863,8 @@ xmlParseConditionalSections(xmlParserCtx\n \n } else {\n \txmlFatalErr(ctxt, XML_ERR_CONDSEC_INVALID_KEYWORD, NULL);\n+\txmlStopParser(ctxt);\n+\treturn;\n }\n \n if (RAW == 0)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "--- libxml2-2.9.1/parser.c\t\n+++ libxml2-2.9.1/parser.c\t\n@@ -5632,6 +5632,7 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt\n \tif (RAW != '>') {\n \t xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_NOT_FINISHED,\n \t \"xmlParseEntityDecl: entity %s not terminated\\n\", name);\n+\t xmlStopParser(ctxt);\n \t} else {\n \t if (input != ctxt->input) {\n \t\txmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,\n@@ -6743,6 +6744,8 @@ xmlParseConditionalSections(xmlParserCtx\n \tSKIP_BLANKS;\n \tif (RAW != '[') {\n \t xmlFatalErr(ctxt, XML_ERR_CONDSEC_INVALID, NULL);\n+\t xmlStopParser(ctxt);\n+\t return;\n \t} else {\n \t if (ctxt->input->id != id) {\n \t\txmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY,\n@@ -6803,6 +6806,8 @@ xmlParseConditionalSections(xmlParserCtx\n \tSKIP_BLANKS;\n \tif (RAW != '[') {\n \t xmlFatalErr(ctxt, XML_ERR_CONDSEC_INVALID, NULL);\n+\t xmlStopParser(ctxt);\n+\t return;\n \t} else {\n \t if (ctxt->input->id != id) {\n \t\txmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY,\n@@ -6858,6 +6863,8 @@ xmlParseConditionalSections(xmlParserCtx\n \n } else {\n \txmlFatalErr(ctxt, XML_ERR_CONDSEC_INVALID_KEYWORD, NULL);\n+\txmlStopParser(ctxt);\n+\treturn;\n }\n \n if (RAW == 0)"}], "metadata": {"id": "libxml2-5762-libxml2-2.9.1-CVE-2015-7941.pa", "cve_id": "CVE-2016-4658", "package": "libxml2", "tier": "identical", "has_source_context": true, "context_tokens_est": 1432, "context_files": 1, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-5118\n\nThe OpenBlob function in blob.c in GraphicsMagick before 1.3.24 and ImageMagick allows remote attackers to execute arbitrary code via a | (pipe) character at the start of a filename.\n\n## Package\nImageMagick\n\n## Files to modify\n- coders/ps2.c\n- coders/pdf.c\n- coders/ps.c\n- coders/ps3.c\n\n## Upstream Fix\n```diff\nFrom 931847a85bfc941d8ae5e85d34c74461ad2083ff Mon Sep 17 00:00:00 2001\nFrom: cristy \nDate: Fri, 21 Feb 2014 14:48:05 +0000\nSubject: [PATCH]\n\n---\n coders/pdf.c | 2 +-\n coders/ps.c | 14 ++++++++++----\n coders/ps2.c | 2 +-\n coders/ps3.c | 2 +-\n 4 files changed, 13 insertions(+), 7 deletions(-)\n\ndiff --git a/coders/pdf.c b/coders/pdf.c\nindex 37c13f8fa2f..02bf2e04af3 100644\n--- a/coders/pdf.c\n+++ b/coders/pdf.c\n@@ -1222,7 +1222,7 @@ RestoreMSCWarning\n scene=0;\n do\n {\n- compression=UndefinedCompression;\n+ compression=image->compression;\n if (image_info->compression != UndefinedCompression)\n compression=image_info->compression;\n switch (compression)\ndiff --git a/coders/ps.c b/coders/ps.c\nindex 0addc1f6723..42e5d92fb2b 100644\n--- a/coders/ps.c\n+++ b/coders/ps.c\n@@ -1362,6 +1362,9 @@ static MagickBooleanType WritePSImage(const ImageInfo *image_info,Image *image)\n **labels,\n page_geometry[MaxTextExtent];\n \n+ CompressionType\n+ compression;\n+\n const char\n **s,\n *value;\n@@ -1446,6 +1449,9 @@ static MagickBooleanType WritePSImage(const ImageInfo *image_info,Image *image)\n if (status == MagickFalse)\n return(status);\n (void) ResetMagickMemory(&bounds,0,sizeof(bounds));\n+ compression=image->compression;\n+ if (image_info->compression != UndefinedCompression)\n+ compression=image_info->compression;\n page=1;\n scene=0;\n do\n@@ -1901,9 +1907,9 @@ RestoreMSCWarning\n */\n (void) FormatLocaleString(buffer,MaxTextExtent,\"%.20g %.20g\\n0\\n%d\\n\",\n (double) image->columns,(double) image->rows,\n- image_info->compression == RLECompression ? 1 : 0);\n+ compression == RLECompression ? 1 : 0);\n (void) WriteBlobString(image,buffer);\n- switch (image_info->compression)\n+ switch (compression)\n {\n case RLECompression:\n {\n@@ -2031,7 +2037,7 @@ RestoreMSCWarning\n (void) FormatLocaleString(buffer,MaxTextExtent,\n \"%.20g %.20g\\n%d\\n%d\\n0\\n\",(double) image->columns,(double)\n image->rows,image->storage_class == PseudoClass ? 1 : 0,\n- image_info->compression == RLECompression ? 1 : 0);\n+ compression == RLECompression ? 1 : 0);\n (void) WriteBlobString(image,buffer);\n /*\n Dump number of colors and colormap.\n@@ -2047,7 +2053,7 @@ RestoreMSCWarning\n ScaleQuantumToChar(image->colormap[i].blue));\n (void) WriteBlobString(image,buffer);\n }\n- switch (image_info->compression)\n+ switch (compression)\n {\n case RLECompression:\n {\ndiff --git a/coders/ps2.c b/coders/ps2.c\nindex d3d52adcef4..aab2098f31a 100644\n--- a/coders/ps2.c\n+++ b/coders/ps2.c\n@@ -465,7 +465,7 @@ static MagickBooleanType WritePS2Image(const ImageInfo *image_info,Image *image)\n status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);\n if (status == MagickFalse)\n return(status);\n- compression=UndefinedCompression;\n+ compression=image->compression;\n if (image_info->compression != UndefinedCompression)\n compression=image_info->compression;\n switch (compression)\ndiff --git a/coders/ps3.c b/coders/ps3.c\nindex cde85283e37..fe090e3e8a5 100644\n--- a/coders/ps3.c\n+++ b/coders/ps3.c\n@@ -885,7 +885,7 @@ static MagickBooleanType WritePS3Image(const ImageInfo *image_info,Image *image)\n status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);\n if (status == MagickFalse)\n return(MagickFalse);\n- compression=UndefinedCompression;\n+ compression=image->compression;\n if (image_info->compression != UndefinedCompression)\n compression=image_info->compression;\n switch (compression)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From 931847a85bfc941d8ae5e85d34c74461ad2083ff Mon Sep 17 00:00:00 2001\nFrom: cristy \nDate: Fri, 21 Feb 2014 14:48:05 +0000\nSubject: [PATCH] \n\n---\n coders/pdf.c | 2 +-\n coders/ps.c | 14 ++++++++++----\n coders/ps2.c | 2 +-\n coders/ps3.c | 2 +-\n 4 files changed, 13 insertions(+), 7 deletions(-)\n\n--- coders/pdf.c\n+++ coders/pdf.c\n@@ -1222,7 +1222,7 @@ RestoreMSCWarning\n scene=0;\n do\n {\n- compression=UndefinedCompression;\n+ compression=image->compression;\n if (image_info->compression != UndefinedCompression)\n compression=image_info->compression;\n switch (compression)\n--- coders/ps.c\n+++ coders/ps.c\n@@ -1362,6 +1362,9 @@ static MagickBooleanType WritePSImage(const ImageInfo *image_info,Image *image)\n **labels,\n page_geometry[MaxTextExtent];\n \n+ CompressionType\n+ compression;\n+\n const char\n **s,\n *value;\n@@ -1446,6 +1449,9 @@ static MagickBooleanType WritePSImage(const ImageInfo *image_info,Image *image)\n if (status == MagickFalse)\n return(status);\n (void) ResetMagickMemory(&bounds,0,sizeof(bounds));\n+ compression=image->compression;\n+ if (image_info->compression != UndefinedCompression)\n+ compression=image_info->compression;\n page=1;\n scene=0;\n do\n@@ -1901,9 +1907,9 @@ RestoreMSCWarning\n */\n (void) FormatLocaleString(buffer,MaxTextExtent,\"%.20g %.20g\\n0\\n%d\\n\",\n (double) image->columns,(double) image->rows,\n- image_info->compression == RLECompression ? 1 : 0);\n+ compression == RLECompression ? 1 : 0);\n (void) WriteBlobString(image,buffer);\n- switch (image_info->compression)\n+ switch (compression)\n {\n case RLECompression:\n {\n@@ -2031,7 +2037,7 @@ RestoreMSCWarning\n (void) FormatLocaleString(buffer,MaxTextExtent,\n \"%.20g %.20g\\n%d\\n%d\\n0\\n\",(double) image->columns,(double)\n image->rows,image->storage_class == PseudoClass ? 1 : 0,\n- image_info->compression == RLECompression ? 1 : 0);\n+ compression == RLECompression ? 1 : 0);\n (void) WriteBlobString(image,buffer);\n /*\n Dump number of colors and colormap.\n@@ -2047,7 +2053,7 @@ RestoreMSCWarning\n ScaleQuantumToChar(image->colormap[i].blue));\n (void) WriteBlobString(image,buffer);\n }\n- switch (image_info->compression)\n+ switch (compression)\n {\n case RLECompression:\n {\n--- coders/ps2.c\n+++ coders/ps2.c\n@@ -465,7 +465,7 @@ static MagickBooleanType WritePS2Image(const ImageInfo *image_info,Image *image)\n status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);\n if (status == MagickFalse)\n return(status);\n- compression=UndefinedCompression;\n+ compression=image->compression;\n if (image_info->compression != UndefinedCompression)\n compression=image_info->compression;\n switch (compression)\n--- coders/ps3.c\n+++ coders/ps3.c\n@@ -885,7 +885,7 @@ static MagickBooleanType WritePS3Image(const ImageInfo *image_info,Image *image)\n status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);\n if (status == MagickFalse)\n return(MagickFalse);\n- compression=UndefinedCompression;\n+ compression=image->compression;\n if (image_info->compression != UndefinedCompression)\n compression=image_info->compression;\n switch (compression)\n--\nlibgit2 0.22.2"}], "metadata": {"id": "ImageMagick-5225-ImageMagick-pdf-img-compressio", "cve_id": "CVE-2016-5118", "package": "ImageMagick", "upstream_enriched": true, "upstream_commit": "931847a85bfc941d8ae5e85d34c74461ad2083ff", "upstream_repo": "ImageMagick/ImageMagick", "tier": "adapted", "has_source_context": false, "license": "ImageMagick"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1k/ssl/ssl.h\n- openssl-1.0.1k.orig/ssl/ssl.h\n- openssl-1.0.1k/ssl/ssl_err.c\n- openssl-1.0.1k.orig/ssl/s3_clnt.c\n- openssl-1.0.1k/ssl/s3_clnt.c\n\n## Target Source Code\n\n### CHANGES\n\n#### region() [lines 144-230]\n```c\n whether SRTP is used or configured. Implementations of OpenSSL that\n have been compiled with OPENSSL_NO_SRTP defined are not affected.\n\n The fix was developed by the OpenSSL team.\n (CVE-2014-3513)\n [OpenSSL team]\n\n *) Session Ticket Memory Leak.\n\n When an OpenSSL SSL/TLS/DTLS server receives a session ticket the\n integrity of that ticket is first verified. In the event of a session\n ticket integrity check failing, OpenSSL will fail to free memory\n causing a memory leak. By sending a large number of invalid session\n tickets an attacker could exploit this issue in a Denial Of Service\n attack.\n (CVE-2014-3567)\n [Steve Henson]\n\n *) Build option no-ssl3 is incomplete.\n\n When OpenSSL is configured with \"no-ssl3\" as a build option, servers\n could accept and complete a SSL 3.0 handshake, and clients could be\n configured to send them.\n (CVE-2014-3568)\n [Akamai and the OpenSSL team]\n\n *) Add support for TLS_FALLBACK_SCSV.\n Client applications doing fallback retries should call\n SSL_set_mode(s, SSL_MODE_SEND_FALLBACK_SCSV).\n (CVE-2014-3566)\n [Adam Langley, Bodo Moeller]\n\n *) Add additional DigestInfo checks.\n \n Reencode DigestInto in DER and check against the original when\n verifying RSA signature: this will reject any improperly encoded\n DigestInfo structures.\n\n Note: this is a precautionary measure and no attacks are currently known.\n\n [Steve Henson]\n\n Changes between 1.0.1h and 1.0.1i [6 Aug 2014]\n\n *) Fix SRP buffer overrun vulnerability. Invalid parameters passed to the\n SRP code can be overrun an internal buffer. Add sanity check that\n g, A, B < N to SRP code.\n\n Thanks to Sean Devlin and Watson Ladd of Cryptography Services, NCC\n Group for discovering this issue.\n (CVE-2014-3512)\n [Steve Henson]\n\n *) A flaw in the OpenSSL SSL/TLS server code causes the server to negotiate\n TLS 1.0 instead of higher protocol versions when the ClientHello message\n is badly fragmented. This allows a man-in-the-middle attacker to force a\n downgrade to TLS 1.0 even if both the server and the client support a\n higher protocol version, by modifying the client's TLS records.\n\n Thanks to David Benjamin and Adam Langley (Google) for discovering and\n researching this issue.\n (CVE-2014-3511)\n [David Benjamin]\n\n *) OpenSSL DTLS clients enabling anonymous (EC)DH ciphersuites are subject\n to a denial of service attack. A malicious server can crash the client\n with a null pointer dereference (read) by specifying an anonymous (EC)DH\n ciphersuite and sending carefully crafted handshake messages.\n\n Thanks to Felix Gr�bert (Google) for discovering and researching this\n issue.\n (CVE-2014-3510)\n [Emilia K�sper]\n\n *) By sending carefully crafted DTLS packets an attacker could cause openssl\n to leak memory. This can be exploited through a Denial of Service attack.\n Thanks to Adam Langley for discovering and researching this issue.\n (CVE-2014-3507)\n [Adam Langley]\n\n *) An attacker can force openssl to consume large amounts of memory whilst\n processing DTLS handshake messages. This can be exploited through a\n Denial of Service attack.\n Thanks to Adam Langley for discovering and researching this issue.\n (CVE-2014-3506)\n [Adam Langley]\n\n```\n\n### ssl/s3_clnt.c\n\n#### ssl3_check_cert_and_algorithm() [lines 353-362]\n```c\n\n\t\t\t/* at this point we check that we have the\n\t\t\t * required stuff from the server */\n\t\t\tif (!ssl3_check_cert_and_algorithm(s))\n\t\t\t\t{\n\t\t\t\tret= -1;\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tbreak;\n\n```\n\n### ssl/ssl.h\n\n#### ERR_load_SSL_strings() [lines 2344-2430]\n```c\n#define SSL_R_BAD_SRP_B_LENGTH\t\t\t\t 348\n#define SSL_R_BAD_SRP_G_LENGTH\t\t\t\t 349\n#define SSL_R_BAD_SRP_N_LENGTH\t\t\t\t 350\n#define SSL_R_BAD_SRP_PARAMETERS\t\t\t 371\n#define SSL_R_BAD_SRP_S_LENGTH\t\t\t\t 351\n#define SSL_R_BAD_SRTP_MKI_VALUE\t\t\t 352\n#define SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST\t\t 353\n#define SSL_R_BAD_SSL_FILETYPE\t\t\t\t 124\n#define SSL_R_BAD_SSL_SESSION_ID_LENGTH\t\t\t 125\n#define SSL_R_BAD_STATE\t\t\t\t\t 126\n#define SSL_R_BAD_WRITE_RETRY\t\t\t\t 127\n#define SSL_R_BIO_NOT_SET\t\t\t\t 128\n#define SSL_R_BLOCK_CIPHER_PAD_IS_WRONG\t\t\t 129\n#define SSL_R_BN_LIB\t\t\t\t\t 130\n#define SSL_R_CA_DN_LENGTH_MISMATCH\t\t\t 131\n#define SSL_R_CA_DN_TOO_LONG\t\t\t\t 132\n#define SSL_R_CCS_RECEIVED_EARLY\t\t\t 133\n#define SSL_R_CERTIFICATE_VERIFY_FAILED\t\t\t 134\n#define SSL_R_CERT_LENGTH_MISMATCH\t\t\t 135\n#define SSL_R_CHALLENGE_IS_DIFFERENT\t\t\t 136\n#define SSL_R_CIPHER_CODE_WRONG_LENGTH\t\t\t 137\n#define SSL_R_CIPHER_OR_HASH_UNAVAILABLE\t\t 138\n#define SSL_R_CIPHER_TABLE_SRC_ERROR\t\t\t 139\n#define SSL_R_CLIENTHELLO_TLSEXT\t\t\t 226\n#define SSL_R_COMPRESSED_LENGTH_TOO_LONG\t\t 140\n#define SSL_R_COMPRESSION_DISABLED\t\t\t 343\n#define SSL_R_COMPRESSION_FAILURE\t\t\t 141\n#define SSL_R_COMPRESSION_ID_NOT_WITHIN_PRIVATE_RANGE\t 307\n#define SSL_R_COMPRESSION_LIBRARY_ERROR\t\t\t 142\n#define SSL_R_CONNECTION_ID_IS_DIFFERENT\t\t 143\n#define SSL_R_CONNECTION_TYPE_NOT_SET\t\t\t 144\n#define SSL_R_COOKIE_MISMATCH\t\t\t\t 308\n#define SSL_R_DATA_BETWEEN_CCS_AND_FINISHED\t\t 145\n#define SSL_R_DATA_LENGTH_TOO_LONG\t\t\t 146\n#define SSL_R_DECRYPTION_FAILED\t\t\t\t 147\n#define SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC\t 281\n#define SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG\t\t 148\n#define SSL_R_DIGEST_CHECK_FAILED\t\t\t 149\n#define SSL_R_DTLS_MESSAGE_TOO_BIG\t\t\t 334\n#define SSL_R_DUPLICATE_COMPRESSION_ID\t\t\t 309\n#define SSL_R_ECC_CERT_NOT_FOR_KEY_AGREEMENT\t\t 317\n#define SSL_R_ECC_CERT_NOT_FOR_SIGNING\t\t\t 318\n#define SSL_R_ECC_CERT_SHOULD_HAVE_RSA_SIGNATURE\t 322\n#define SSL_R_ECC_CERT_SHOULD_HAVE_SHA1_SIGNATURE\t 323\n#define SSL_R_ECGROUP_TOO_LARGE_FOR_CIPHER\t\t 310\n#define SSL_R_EMPTY_SRTP_PROTECTION_PROFILE_LIST\t 354\n#define SSL_R_ENCRYPTED_LENGTH_TOO_LONG\t\t\t 150\n#define SSL_R_ERROR_GENERATING_TMP_RSA_KEY\t\t 282\n#define SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST\t\t 151\n#define SSL_R_EXCESSIVE_MESSAGE_SIZE\t\t\t 152\n#define SSL_R_EXTRA_DATA_IN_MESSAGE\t\t\t 153\n#define SSL_R_GOT_A_FIN_BEFORE_A_CCS\t\t\t 154\n#define SSL_R_GOT_NEXT_PROTO_BEFORE_A_CCS\t\t 355\n#define SSL_R_GOT_NEXT_PROTO_WITHOUT_EXTENSION\t\t 356\n#define SSL_R_HTTPS_PROXY_REQUEST\t\t\t 155\n#define SSL_R_HTTP_REQUEST\t\t\t\t 156\n#define SSL_R_ILLEGAL_PADDING\t\t\t\t 283\n#define SSL_R_INAPPROPRIATE_FALLBACK\t\t\t 373\n#define SSL_R_INCONSISTENT_COMPRESSION\t\t\t 340\n#define SSL_R_INVALID_CHALLENGE_LENGTH\t\t\t 158\n#define SSL_R_INVALID_COMMAND\t\t\t\t 280\n#define SSL_R_INVALID_COMPRESSION_ALGORITHM\t\t 341\n#define SSL_R_INVALID_PURPOSE\t\t\t\t 278\n#define SSL_R_INVALID_SRP_USERNAME\t\t\t 357\n#define SSL_R_INVALID_STATUS_RESPONSE\t\t\t 328\n#define SSL_R_INVALID_TICKET_KEYS_LENGTH\t\t 325\n#define SSL_R_INVALID_TRUST\t\t\t\t 279\n#define SSL_R_KEY_ARG_TOO_LONG\t\t\t\t 284\n#define SSL_R_KRB5\t\t\t\t\t 285\n#define SSL_R_KRB5_C_CC_PRINC\t\t\t\t 286\n#define SSL_R_KRB5_C_GET_CRED\t\t\t\t 287\n#define SSL_R_KRB5_C_INIT\t\t\t\t 288\n#define SSL_R_KRB5_C_MK_REQ\t\t\t\t 289\n#define SSL_R_KRB5_S_BAD_TICKET\t\t\t\t 290\n#define SSL_R_KRB5_S_INIT\t\t\t\t 291\n#define SSL_R_KRB5_S_RD_REQ\t\t\t\t 292\n#define SSL_R_KRB5_S_TKT_EXPIRED\t\t\t 293\n#define SSL_R_KRB5_S_TKT_NYV\t\t\t\t 294\n#define SSL_R_KRB5_S_TKT_SKEW\t\t\t\t 295\n#define SSL_R_LENGTH_MISMATCH\t\t\t\t 159\n#define SSL_R_LENGTH_TOO_SHORT\t\t\t\t 160\n#define SSL_R_LIBRARY_BUG\t\t\t\t 274\n#define SSL_R_LIBRARY_HAS_NO_CIPHERS\t\t\t 161\n#define SSL_R_MESSAGE_TOO_LONG\t\t\t\t 296\n#define SSL_R_MISSING_DH_DSA_CERT\t\t\t 162\n#define SSL_R_MISSING_DH_KEY\t\t\t\t 163\n#define SSL_R_MISSING_DH_RSA_CERT\t\t\t 164\n```\n\n### ssl/ssl_err.c\n\n#### region() [lines 324-410]\n```c\n{ERR_REASON(SSL_R_BAD_RSA_E_LENGTH) ,\"bad rsa e length\"},\n{ERR_REASON(SSL_R_BAD_RSA_MODULUS_LENGTH),\"bad rsa modulus length\"},\n{ERR_REASON(SSL_R_BAD_RSA_SIGNATURE) ,\"bad rsa signature\"},\n{ERR_REASON(SSL_R_BAD_SIGNATURE) ,\"bad signature\"},\n{ERR_REASON(SSL_R_BAD_SRP_A_LENGTH) ,\"bad srp a length\"},\n{ERR_REASON(SSL_R_BAD_SRP_B_LENGTH) ,\"bad srp b length\"},\n{ERR_REASON(SSL_R_BAD_SRP_G_LENGTH) ,\"bad srp g length\"},\n{ERR_REASON(SSL_R_BAD_SRP_N_LENGTH) ,\"bad srp n length\"},\n{ERR_REASON(SSL_R_BAD_SRP_PARAMETERS) ,\"bad srp parameters\"},\n{ERR_REASON(SSL_R_BAD_SRP_S_LENGTH) ,\"bad srp s length\"},\n{ERR_REASON(SSL_R_BAD_SRTP_MKI_VALUE) ,\"bad srtp mki value\"},\n{ERR_REASON(SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST),\"bad srtp protection profile list\"},\n{ERR_REASON(SSL_R_BAD_SSL_FILETYPE) ,\"bad ssl filetype\"},\n{ERR_REASON(SSL_R_BAD_SSL_SESSION_ID_LENGTH),\"bad ssl session id length\"},\n{ERR_REASON(SSL_R_BAD_STATE) ,\"bad state\"},\n{ERR_REASON(SSL_R_BAD_WRITE_RETRY) ,\"bad write retry\"},\n{ERR_REASON(SSL_R_BIO_NOT_SET) ,\"bio not set\"},\n{ERR_REASON(SSL_R_BLOCK_CIPHER_PAD_IS_WRONG),\"block cipher pad is wrong\"},\n{ERR_REASON(SSL_R_BN_LIB) ,\"bn lib\"},\n{ERR_REASON(SSL_R_CA_DN_LENGTH_MISMATCH) ,\"ca dn length mismatch\"},\n{ERR_REASON(SSL_R_CA_DN_TOO_LONG) ,\"ca dn too long\"},\n{ERR_REASON(SSL_R_CCS_RECEIVED_EARLY) ,\"ccs received early\"},\n{ERR_REASON(SSL_R_CERTIFICATE_VERIFY_FAILED),\"certificate verify failed\"},\n{ERR_REASON(SSL_R_CERT_LENGTH_MISMATCH) ,\"cert length mismatch\"},\n{ERR_REASON(SSL_R_CHALLENGE_IS_DIFFERENT),\"challenge is different\"},\n{ERR_REASON(SSL_R_CIPHER_CODE_WRONG_LENGTH),\"cipher code wrong length\"},\n{ERR_REASON(SSL_R_CIPHER_OR_HASH_UNAVAILABLE),\"cipher or hash unavailable\"},\n{ERR_REASON(SSL_R_CIPHER_TABLE_SRC_ERROR),\"cipher table src error\"},\n{ERR_REASON(SSL_R_CLIENTHELLO_TLSEXT) ,\"clienthello tlsext\"},\n{ERR_REASON(SSL_R_COMPRESSED_LENGTH_TOO_LONG),\"compressed length too long\"},\n{ERR_REASON(SSL_R_COMPRESSION_DISABLED) ,\"compression disabled\"},\n{ERR_REASON(SSL_R_COMPRESSION_FAILURE) ,\"compression failure\"},\n{ERR_REASON(SSL_R_COMPRESSION_ID_NOT_WITHIN_PRIVATE_RANGE),\"compression id not within private range\"},\n{ERR_REASON(SSL_R_COMPRESSION_LIBRARY_ERROR),\"compression library error\"},\n{ERR_REASON(SSL_R_CONNECTION_ID_IS_DIFFERENT),\"connection id is different\"},\n{ERR_REASON(SSL_R_CONNECTION_TYPE_NOT_SET),\"connection type not set\"},\n{ERR_REASON(SSL_R_COOKIE_MISMATCH) ,\"cookie mismatch\"},\n{ERR_REASON(SSL_R_DATA_BETWEEN_CCS_AND_FINISHED),\"data between ccs and finished\"},\n{ERR_REASON(SSL_R_DATA_LENGTH_TOO_LONG) ,\"data length too long\"},\n{ERR_REASON(SSL_R_DECRYPTION_FAILED) ,\"decryption failed\"},\n{ERR_REASON(SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC),\"decryption failed or bad record mac\"},\n{ERR_REASON(SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG),\"dh public value length is wrong\"},\n{ERR_REASON(SSL_R_DIGEST_CHECK_FAILED) ,\"digest check failed\"},\n{ERR_REASON(SSL_R_DTLS_MESSAGE_TOO_BIG) ,\"dtls message too big\"},\n{ERR_REASON(SSL_R_DUPLICATE_COMPRESSION_ID),\"duplicate compression id\"},\n{ERR_REASON(SSL_R_ECC_CERT_NOT_FOR_KEY_AGREEMENT),\"ecc cert not for key agreement\"},\n{ERR_REASON(SSL_R_ECC_CERT_NOT_FOR_SIGNING),\"ecc cert not for signing\"},\n{ERR_REASON(SSL_R_ECC_CERT_SHOULD_HAVE_RSA_SIGNATURE),\"ecc cert should have rsa signature\"},\n{ERR_REASON(SSL_R_ECC_CERT_SHOULD_HAVE_SHA1_SIGNATURE),\"ecc cert should have sha1 signature\"},\n{ERR_REASON(SSL_R_ECGROUP_TOO_LARGE_FOR_CIPHER),\"ecgroup too large for cipher\"},\n{ERR_REASON(SSL_R_EMPTY_SRTP_PROTECTION_PROFILE_LIST),\"empty srtp protection profile list\"},\n{ERR_REASON(SSL_R_ENCRYPTED_LENGTH_TOO_LONG),\"encrypted length too long\"},\n{ERR_REASON(SSL_R_ERROR_GENERATING_TMP_RSA_KEY),\"error generating tmp rsa key\"},\n{ERR_REASON(SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST),\"error in received cipher list\"},\n{ERR_REASON(SSL_R_EXCESSIVE_MESSAGE_SIZE),\"excessive message size\"},\n{E\n/* ... truncated ... */\n```\n\n\n## Upstream Fix\n```diff\nFrom 63830384e90d9b36d2793d4891501ec024827433 Mon Sep 17 00:00:00 2001\nFrom: Emilia Kasper \nDate: Tue, 19 May 2015 12:05:22 +0200\nSubject: [PATCH] client: reject handshakes with DH parameters < 768 bits.\n\nSince the client has no way of communicating her supported parameter\nrange to the server, connections to servers that choose weak DH will\nsimply fail.\n\nReviewed-by: Kurt Roeckx \n---\n CHANGES | 3 ++-\n ssl/s3_clnt.c | 22 ++++++++++++++++------\n ssl/ssl.h | 1 +\n ssl/ssl_err.c | 1 +\n 4 files changed, 20 insertions(+), 7 deletions(-)\n\ndiff --git a/CHANGES b/CHANGES\nindex 11bdbbd6926de..9d2f9f9fa8bd2 100644\n--- a/CHANGES\n+++ b/CHANGES\n@@ -4,7 +4,8 @@\n \n Changes between 1.0.1m and 1.0.1n [xx XXX xxxx]\n \n- *)\n+ *) Reject DH handshakes with parameters shorter than 768 bits.\n+ [Kurt Roeckx and Emilia Kasper]\n \n Changes between 1.0.1l and 1.0.1m [19 Mar 2015]\n \ndiff --git a/ssl/s3_clnt.c b/ssl/s3_clnt.c\nindex a521d56fe4fdf..780a03f1e6e85 100644\n--- a/ssl/s3_clnt.c\n+++ b/ssl/s3_clnt.c\n@@ -3295,23 +3295,33 @@ int ssl3_check_cert_and_algorithm(SSL *s)\n }\n #endif\n #ifndef OPENSSL_NO_DH\n- if ((alg_k & SSL_kEDH) &&\n- !(has_bits(i, EVP_PK_DH | EVP_PKT_EXCH) || (dh != NULL))) {\n- SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM, SSL_R_MISSING_DH_KEY);\n+ if ((alg_k & SSL_kEDH) && dh == NULL) {\n+ SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM, ERR_R_INTERNAL_ERROR);\n goto f_err;\n- } else if ((alg_k & SSL_kDHr) && !has_bits(i, EVP_PK_DH | EVP_PKS_RSA)) {\n+ }\n+ if ((alg_k & SSL_kDHr) && !has_bits(i, EVP_PK_DH | EVP_PKS_RSA)) {\n SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,\n SSL_R_MISSING_DH_RSA_CERT);\n goto f_err;\n }\n # ifndef OPENSSL_NO_DSA\n- else if ((alg_k & SSL_kDHd) && !has_bits(i, EVP_PK_DH | EVP_PKS_DSA)) {\n+ if ((alg_k & SSL_kDHd) && !has_bits(i, EVP_PK_DH | EVP_PKS_DSA)) {\n SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,\n SSL_R_MISSING_DH_DSA_CERT);\n goto f_err;\n }\n # endif\n-#endif\n+\n+ /* Check DHE only: static DH not implemented. */\n+ if (alg_k & SSL_kEDH) {\n+ int dh_size = BN_num_bits(dh->p);\n+ if ((!SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) && dh_size < 768)\n+ || (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) && dh_size < 512)) {\n+ SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM, SSL_R_DH_KEY_TOO_SMALL);\n+ goto f_err;\n+ }\n+ }\n+#endif /* !OPENSSL_NO_DH */\n \n if (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) && !has_bits(i, EVP_PKT_EXP)) {\n #ifndef OPENSSL_NO_RSA\ndiff --git a/ssl/ssl.h b/ssl/ssl.h\nindex 62472a1e3c016..32e27c6fbf91b 100644\n--- a/ssl/ssl.h\n+++ b/ssl/ssl.h\n@@ -2524,6 +2524,7 @@ void ERR_load_SSL_strings(void);\n # define SSL_R_DATA_LENGTH_TOO_LONG 146\n # define SSL_R_DECRYPTION_FAILED 147\n # define SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC 281\n+# define SSL_R_DH_KEY_TOO_SMALL 372\n # define SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG 148\n # define SSL_R_DIGEST_CHECK_FAILED 149\n # define SSL_R_DTLS_MESSAGE_TOO_BIG 334\ndiff --git a/ssl/ssl_err.c b/ssl/ssl_err.c\nindex 835b43ce67cbd..fef324d46295b 100644\n--- a/ssl/ssl_err.c\n+++ b/ssl/ssl_err.c\n@@ -441,6 +441,7 @@ static ERR_STRING_DATA SSL_str_reasons[] = {\n {ERR_REASON(SSL_R_DECRYPTION_FAILED), \"decryption failed\"},\n {ERR_REASON(SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC),\n \"decryption failed or bad record mac\"},\n+ {ERR_REASON(SSL_R_DH_KEY_TOO_SMALL), \"dh key too small\"},\n {ERR_REASON(SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG),\n \"dh public value length is wrong\"},\n {ERR_REASON(SSL_R_DIGEST_CHECK_FAILED), \"digest check failed\"},\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From 63830384e90d9b36d2793d4891501ec024827433 Mon Sep 17 00:00:00 2001\nFrom: Emilia Kasper \nDate: Tue, 19 May 2015 12:05:22 +0200\nSubject: [PATCH 5/5] client: reject handshakes with DH parameters < 768 bits.\n\nSince the client has no way of communicating her supported parameter\nrange to the server, connections to servers that choose weak DH will\nsimply fail.\n\nReviewed-by: Kurt Roeckx \n---\n CHANGES | 3 ++-\n ssl/s3_clnt.c | 22 ++++++++++++++++------\n ssl/ssl.h | 1 +\n ssl/ssl_err.c | 1 +\n 4 files changed, 20 insertions(+), 7 deletions(-)\n\nIndex: openssl-1.0.1k/CHANGES\n===================================================================\n--- openssl-1.0.1k.orig/CHANGES\t2015-01-08 15:03:40.000000000 +0100\n+++ openssl-1.0.1k/CHANGES\t2015-06-12 14:41:15.091141190 +0200\n@@ -183,6 +183,9 @@\n \n [Steve Henson]\n \n+ *) Reject DH handshakes with parameters shorter than 768 bits.\n+ [Kurt Roeckx and Emilia Kasper]\n+\n Changes between 1.0.1h and 1.0.1i [6 Aug 2014]\n \n *) Fix SRP buffer overrun vulnerability. Invalid parameters passed to the\nIndex: openssl-1.0.1k/ssl/s3_clnt.c\n===================================================================\n--- openssl-1.0.1k.orig/ssl/s3_clnt.c\t2015-06-12 14:35:09.321393147 +0200\n+++ openssl-1.0.1k/ssl/s3_clnt.c\t2015-06-12 14:41:15.092141203 +0200\n@@ -3425,26 +3425,34 @@ int ssl3_check_cert_and_algorithm(SSL *s\n \t\t}\n #endif\n #ifndef OPENSSL_NO_DH\n-\tif ((alg_k & SSL_kEDH) &&\n-\t\t!(has_bits(i,EVP_PK_DH|EVP_PKT_EXCH) || (dh != NULL)))\n-\t\t{\n-\t\tSSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_KEY);\n+ if ((alg_k & SSL_kEDH) && dh == NULL) {\n+ SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM, ERR_R_INTERNAL_ERROR);\n \t\tgoto f_err;\n-\t\t}\n-\telse if ((alg_k & SSL_kDHr) && !has_bits(i,EVP_PK_DH|EVP_PKS_RSA))\n+ }\n+ if ((alg_k & SSL_kDHr) && !has_bits(i, EVP_PK_DH | EVP_PKS_RSA))\n \t\t{\n \t\tSSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_RSA_CERT);\n \t\tgoto f_err;\n \t\t}\n #ifndef OPENSSL_NO_DSA\n-\telse if ((alg_k & SSL_kDHd) && !has_bits(i,EVP_PK_DH|EVP_PKS_DSA))\n+ if ((alg_k & SSL_kDHd) && !has_bits(i, EVP_PK_DH | EVP_PKS_DSA))\n \t\t{\n \t\tSSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_DSA_CERT);\n \t\tgoto f_err;\n \t\t}\n #endif\n-#endif\n \n+ /* Check DHE only: static DH not implemented. */\n+ if (alg_k & SSL_kEDH) {\n+ int dh_size = BN_num_bits(dh->p);\n+ if ((!SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) && dh_size < 768)\n+ || (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) && dh_size < 512)) {\n+ SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM, SSL_R_DH_KEY_TOO_SMALL);\n+ goto f_err;\n+ }\n+ }\n+#endif /* !OPENSSL_NO_DH */\n+ \n \tif (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) && !has_bits(i,EVP_PKT_EXP))\n \t\t{\n #ifndef OPENSSL_NO_RSA\nIndex: openssl-1.0.1k/ssl/ssl.h\n===================================================================\n--- openssl-1.0.1k.orig/ssl/ssl.h\t2015-06-12 14:35:09.320393134 +0200\n+++ openssl-1.0.1k/ssl/ssl.h\t2015-06-12 14:41:15.092141203 +0200\n@@ -2383,6 +2383,7 @@ void ERR_load_SSL_strings(void);\n #define SSL_R_DATA_LENGTH_TOO_LONG\t\t\t 146\n #define SSL_R_DECRYPTION_FAILED\t\t\t\t 147\n #define SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC\t 281\n+#define SSL_R_DH_KEY_TOO_SMALL 372\n #define SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG\t\t 148\n #define SSL_R_DIGEST_CHECK_FAILED\t\t\t 149\n #define SSL_R_DTLS_MESSAGE_TOO_BIG\t\t\t 334\nIndex: openssl-1.0.1k/ssl/ssl_err.c\n===================================================================\n--- openssl-1.0.1k.orig/ssl/ssl_err.c\t2015-06-12 14:35:09.321393147 +0200\n+++ openssl-1.0.1k/ssl/ssl_err.c\t2015-06-12 14:41:15.092141203 +0200\n@@ -363,6 +363,7 @@ static ERR_STRING_DATA SSL_str_reasons[]\n {ERR_REASON(SSL_R_DATA_LENGTH_TOO_LONG) ,\"data length too long\"},\n {ERR_REASON(SSL_R_DECRYPTION_FAILED) ,\"decryption failed\"},\n {ERR_REASON(SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC),\"decryption failed or bad record mac\"},\n+{ERR_REASON(SSL_R_DH_KEY_TOO_SMALL), \"dh key too small\"},\n {ERR_REASON(SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG),\"dh public value length is wrong\"},\n {ERR_REASON(SSL_R_DIGEST_CHECK_FAILED) ,\"digest check failed\"},\n {ERR_REASON(SSL_R_DTLS_MESSAGE_TOO_BIG) ,\"dtls message too big\"},"}], "metadata": {"id": "openssl-4598-0005-client-reject-handshakes-", "cve_id": "CVE-2015-3197", "package": "openssl", "upstream_enriched": true, "upstream_commit": "63830384e90d9b36d2793d4891501ec024827433", "upstream_repo": "openssl/openssl", "tier": "adapted", "has_source_context": true, "context_tokens_est": 2876, "context_files": 4, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-6250\n\nInteger overflow in the ISO9660 writer in libarchive before 3.2.1 allows remote attackers to cause a denial of service (application crash) or execute arbitrary code via vectors related to verifying filename lengths when writing an ISO9660 archive, which trigger a buffer overflow.\n\n## Package\nlibarchive\n\n## Files to modify\n- libarchive/archive_write_disk_posix.c\n- libarchive-3.1.2.orig/libarchive/archive_write_disk_posix.c\n\n## Target Source Code\n\n### libarchive/archive_write_disk_posix.c\n\n#### region() [lines 287-379]\n```c\n * Note that POSIX specifies 0777 for implicitly-created dirs, \"modified\n * by the process' file creation mask.\"\n */\n#define\tDEFAULT_DIR_MODE 0777\n/*\n * Dir modes are restored in two steps: During the extraction, the permissions\n * in the archive are modified to match the following limits. During\n * the post-extract fixup pass, the permissions from the archive are\n * applied.\n */\n#define\tMINIMUM_DIR_MODE 0700\n#define\tMAXIMUM_DIR_MODE 0775\n\n/*\n * Maxinum uncompressed size of a decmpfs block.\n */\n#define MAX_DECMPFS_BLOCK_SIZE\t(64 * 1024)\n/*\n * HFS+ compression type.\n */\n#define CMP_XATTR\t\t3/* Compressed data in xattr. */\n#define CMP_RESOURCE_FORK\t4/* Compressed data in resource fork. */\n/*\n * HFS+ compression resource fork.\n */\n#define RSRC_H_SIZE\t260\t/* Base size of Resource fork header. */\n#define RSRC_F_SIZE\t50\t/* Size of Resource fork footer. */\n/* Size to write compressed data to resource fork. */\n#define COMPRESSED_W_SIZE\t(64 * 1024)\n/* decmpfs difinitions. */\n#define MAX_DECMPFS_XATTR_SIZE\t\t3802\n#ifndef DECMPFS_XATTR_NAME\n#define DECMPFS_XATTR_NAME\t\t\"com.apple.decmpfs\"\n#endif\n#define DECMPFS_MAGIC\t\t\t0x636d7066\n#define DECMPFS_COMPRESSION_MAGIC\t0\n#define DECMPFS_COMPRESSION_TYPE\t4\n#define DECMPFS_UNCOMPRESSED_SIZE\t8\n#define DECMPFS_HEADER_SIZE\t\t16\n\n#define HFS_BLOCKS(s)\t((s) >> 12)\n\nstatic int\tcheck_symlinks(struct archive_write_disk *);\nstatic int\tcreate_filesystem_object(struct archive_write_disk *);\nstatic struct fixup_entry *current_fixup(struct archive_write_disk *, const char *pathname);\n#if defined(HAVE_FCHDIR) && defined(PATH_MAX)\nstatic void\tedit_deep_directories(struct archive_write_disk *ad);\n#endif\nstatic int\tcleanup_pathname(struct archive_write_disk *);\nstatic int\tcreate_dir(struct archive_write_disk *, char *);\nstatic int\tcreate_parent_dir(struct archive_write_disk *, char *);\nstatic ssize_t\thfs_write_data_block(struct archive_write_disk *,\n\t\t const char *, size_t);\nstatic int\tfixup_appledouble(struct archive_write_disk *, const char *);\nstatic int\tolder(struct stat *, struct archive_entry *);\nstatic int\trestore_entry(struct archive_write_disk *);\nstatic int\tset_mac_metadata(struct archive_write_disk *, const char *,\n\t\t\t\t const void *, size_t);\nstatic int\tset_xattrs(struct archive_write_disk *);\nstatic int\tset_fflags(struct archive_write_disk *);\nstatic int\tset_fflags_platform(struct archive_write_disk *, int fd,\n\t\t const char *name, mode_t mode,\n\t\t unsigned long fflags_set, unsigned long fflags_clear);\nstatic int\tset_ownership(struct archive_write_disk *);\nstatic int\tset_mode(struct archive_write_disk *, int mode);\nstatic int\tset_time(int, int, const char *, time_t, long, time_t, long);\nstatic int\tset_times(struct archive_write_disk *, int, int, const char *,\n\t\t time_t, long, time_t, long, time_t, long, time_t, long);\nstatic int\tset_times_from_entry(struct archive_write_disk *);\nstatic struct fixup_entry *sort_dir_list(struct fixup_entry *p);\nstatic ssize_t\twrite_data_block(struct archive_write_disk *,\n\t\t const char *, size_t);\n\nstatic struct archive_vtable *archive_write_disk_vtable(void);\n\nstatic int\t_archive_write_disk_close(struct archive *);\nstatic int\t_archive_write_disk_free(struct archive *);\nstatic int\t_archive_write_disk_header(struct archive *, struct archive_entry *);\nstatic int64_t\t_archive_write_disk_filter_bytes(struct archive *, int);\nstatic int\t_archive_write_disk_finish_entry(struct archive *);\nstatic ssize_t\t_archive_write_disk_data(struct archive *, const void *, size_t);\nstatic ssize_t\t_archive_write_disk_data_block(struct archive *, const void *, size_t, int64_t);\n\nstatic int\nlazy_stat(struct archive_write_disk *a)\n{\n\tif (a->pst != NULL) {\n\t\t/* Already have stat() data available. */\n\t\treturn (ARCHIVE_OK);\n\t}\n#ifdef HAVE_FSTAT\n\tif (a->fd >= 0 && fstat(a->fd, &a->st) == 0) {\n\t\ta->pst = &a->st;\n```\n\n#### edit_deep_directories() [lines 1785-1827]\n```c\n */\n#if defined(HAVE_FCHDIR) && defined(PATH_MAX)\nstatic void\nedit_deep_directories(struct archive_write_disk *a)\n{\n\tint ret;\n\tchar *tail = a->name;\n\n\t/* If path is short, avoid the open() below. */\n\tif (strlen(tail) <= PATH_MAX)\n\t\treturn;\n\n\t/* Try to record our starting dir. */\n\ta->restore_pwd = open(\".\", O_RDONLY | O_BINARY | O_CLOEXEC);\n\t__archive_ensure_cloexec_flag(a->restore_pwd);\n\tif (a->restore_pwd < 0)\n\t\treturn;\n\n\t/* As long as the path is too long... */\n\twhile (strlen(tail) > PATH_MAX) {\n\t\t/* Locate a dir prefix shorter than PATH_MAX. */\n\t\ttail += PATH_MAX - 8;\n\t\twhile (tail > a->name && *tail != '/')\n\t\t\ttail--;\n\t\t/* Exit if we find a too-long path component. */\n\t\tif (tail <= a->name)\n\t\t\treturn;\n\t\t/* Create the intermediate dir and chdir to it. */\n\t\t*tail = '\\0'; /* Terminate dir portion */\n\t\tret = create_dir(a, a->name);\n\t\tif (ret == ARCHIVE_OK && chdir(a->name) != 0)\n\t\t\tret = ARCHIVE_FAILED;\n\t\t*tail = '/'; /* Restore the / we removed. */\n\t\tif (ret != ARCHIVE_OK)\n\t\t\treturn;\n\t\ttail++;\n\t\t/* The chdir() succeeded; we've now shortened the path. */\n\t\ta->name = tail;\n\t}\n\treturn;\n}\n#endif\n\n```\n\n#### create_filesystem_object() [lines 1990-2126]\n```c\n * a single system call.\n */\nstatic int\ncreate_filesystem_object(struct archive_write_disk *a)\n{\n\t/* Create the entry. */\n\tconst char *linkname;\n\tmode_t final_mode, mode;\n\tint r;\n\n\t/* We identify hard/symlinks according to the link names. */\n\t/* Since link(2) and symlink(2) don't handle modes, we're done here. */\n\tlinkname = archive_entry_hardlink(a->entry);\n\tif (linkname != NULL) {\n#if !HAVE_LINK\n\t\treturn (EPERM);\n#else\n\t\tr = link(linkname, a->name) ? errno : 0;\n\t\t/*\n\t\t * New cpio and pax formats allow hardlink entries\n\t\t * to carry data, so we may have to open the file\n\t\t * for hardlink entries.\n\t\t *\n\t\t * If the hardlink was successfully created and\n\t\t * the archive doesn't have carry data for it,\n\t\t * consider it to be non-authoritative for meta data.\n\t\t * This is consistent with GNU tar and BSD pax.\n\t\t * If the hardlink does carry data, let the last\n\t\t * archive entry decide ownership.\n\t\t */\n\t\tif (r == 0 && a->filesize <= 0) {\n\t\t\ta->todo = 0;\n\t\t\ta->deferred = 0;\n\t\t} else if (r == 0 && a->filesize > 0) {\n\t\t\ta->fd = open(a->name,\n\t\t\t\t O_WRONLY | O_TRUNC | O_BINARY | O_CLOEXEC);\n\t\t\t__archive_ensure_cloexec_flag(a->fd);\n\t\t\tif (a->fd < 0)\n\t\t\t\tr = errno;\n\t\t}\n/* ... 91 lines omitted ... */\n\t\tr = mkfifo(a->name, mode);\n\t\tbreak;\n#else\n\t\t/* TODO: Find a better way to warn about our inability\n\t\t * to restore a fifo. */\n\t\treturn (EINVAL);\n#endif /* HAVE_MKFIFO */\n\t}\n\n\t/* All the system calls above set errno on failure. */\n\tif (r)\n\t\treturn (errno);\n\n\t/* If we managed to set the final mode, we've avoided a chmod(). */\n\tif (mode == final_mode)\n\t\ta->todo &= ~TODO_MODE;\n\treturn (0);\n}\n\n/*\n```\n\n#### current_fixup() [lines 2325-2335]\n```c\n * Returns a fixup structure for the current entry.\n */\nstatic struct fixup_entry *\ncurrent_fixup(struct archive_write_disk *a, const char *pathname)\n{\n\tif (a->current_fixup == NULL)\n\t\ta->current_fixup = new_fixup(a, pathname);\n\treturn (a->current_fixup);\n}\n\n/* TODO: Make this work. */\n```\n\n#### cleanup_pathname_win() [lines 2446-2503]\n```c\n * See also : http://msdn.microsoft.com/en-us/library/aa365247.aspx\n */\nstatic void\ncleanup_pathname_win(struct archive_write_disk *a)\n{\n\twchar_t wc;\n\tchar *p;\n\tsize_t alen, l;\n\tint mb, complete, utf8;\n\n\talen = 0;\n\tmb = 0;\n\tcomplete = 1;\n\tutf8 = (strcmp(nl_langinfo(CODESET), \"UTF-8\") == 0)? 1: 0;\n\tfor (p = a->name; *p != '\\0'; p++) {\n\t\t++alen;\n\t\tif (*p == '\\\\') {\n\t\t\t/* If previous byte is smaller than 128,\n\t\t\t * this is not second byte of multibyte characters,\n\t\t\t * so we can replace '\\' with '/'. */\n\t\t\tif (utf8 || !mb)\n\t\t\t\t*p = '/';\n\t\t\telse\n\t\t\t\tcomplete = 0;/* uncompleted. */\n\t\t} else if (*(unsigned char *)p > 127)\n\t\t\tmb = 1;\n\t\telse\n\t\t\tmb = 0;\n\t\t/* Rewrite the path name if its next character is unusable. */\n\t\tif (*p == ':' || *p == '*' || *p == '?' || *p == '\"' ||\n\t\t *p == '<' || *p == '>' || *p == '|')\n\t\t\t*p = '_';\n\t}\n\tif (complete)\n\t\treturn;\n\n\t/*\n\t * Convert path separator in wide-character.\n\t */\n\tp = a->name;\n\twhile (*p != '\\0' && alen) {\n\t\tl = mbtowc(&wc, p, alen);\n\t\tif (l == (size_t)-1) {\n\t\t\twhile (*p != '\\0') {\n\t\t\t\tif (*p == '\\\\')\n\t\t\t\t\t*p = '/';\n\t\t\t\t++p;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tif (l == 1 && wc == L'\\\\')\n\t\t\t*p = '/';\n\t\tp += l;\n\t\talen -= l;\n\t}\n}\n#endif\n\n```\n\n#### cleanup_pathname() [lines 2508-2599]\n```c\n * set) any '..' in the path.\n */\nstatic int\ncleanup_pathname(struct archive_write_disk *a)\n{\n\tchar *dest, *src;\n\tchar separator = '\\0';\n\n\tdest = src = a->name;\n\tif (*src == '\\0') {\n\t\tarchive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,\n\t\t \"Invalid empty pathname\");\n\t\treturn (ARCHIVE_FAILED);\n\t}\n\n#if defined(__CYGWIN__)\n\tcleanup_pathname_win(a);\n#endif\n\t/* Skip leading '/'. */\n\tif (*src == '/')\n\t\tseparator = *src++;\n\n\t/* Scan the pathname one element at a time. */\n\tfor (;;) {\n\t\t/* src points to first char after '/' */\n\t\tif (src[0] == '\\0') {\n\t\t\tbreak;\n\t\t} else if (src[0] == '/') {\n\t\t\t/* Found '//', ignore second one. */\n\t\t\tsrc++;\n\t\t\tcontinue;\n\t\t} else if (src[0] == '.') {\n\t\t\tif (src[1] == '\\0') {\n\t\t\t\t/* Ignore trailing '.' */\n\t\t\t\tbreak;\n\t\t\t} else if (src[1] == '/') {\n\t\t\t\t/* Skip './'. */\n\t\t\t\tsrc += 2;\n\t\t\t\tcontinue;\n\t\t\t} else if (src[1] == '.') {\n\t\t\t\tif (src[2] == '/' || src[2] == '\\0') {\n\t\t\t\t\t/* Conditionally warn about '..' */\n\t\t\t\t\tif (a->flags & ARCHIVE_EXTRACT_SECURE_NODOTDOT) {\n\t\t\t\t\t\tarchive_set_error(&a->archive,\n\t\t\t\t\t\t ARCHIVE_ERRNO_MISC,\n\t\t\t\t\t\t \"Path contains '..'\");\n\t\t\t\t\t\treturn (ARCHIVE_FAILED);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t/*\n\t\t\t\t * Note: Under no circumstances do we\n\t\t\t\t * remove '..' elements. In\n\t\t\t\t * particular, restoring\n\t\t\t\t * '/foo/../bar/' should create the\n\t\t\t\t * 'foo' dir as a side-effect.\n\t\t\t\t */\n\t\t\t}\n\t\t}\n\n\t\t/* Copy current element, including leading '/'. */\n\t\tif (separator)\n\t\t\t*dest++ = '/';\n\t\twhile (*src != '\\0' && *src != '/') {\n\t\t\t*dest++ = *src++;\n\t\t}\n\n\t\tif (*src == '\\0')\n\t\t\tbreak;\n\n\t\t/* Skip '/' separator. */\n\t\tseparator = *src++;\n\t}\n\t/*\n\t * We've just copied zero or more path elements, not including the\n\t * final '/'.\n\t */\n\tif (dest == a->name) {\n\t\t/*\n\t\t * Nothing got copied. The path must have been something\n\t\t * like '.' or '/' or './' or '/././././/./'.\n\t\t */\n\t\tif (separator)\n\t\t\t*dest++ = '/';\n\t\telse\n\t\t\t*dest++ = '.';\n\t}\n\t/* Terminate the result. */\n\t*dest = '\\0';\n\treturn (ARCHIVE_OK);\n}\n\n/*\n```\n\n\n### Type definitions\n\n```c\n/* from archive_string.h */\nstruct archive_string {\n\tchar\t*s; /* Pointer to the storage */\n\tsize_t\t length; /* Length of 's' in characters */\n\tsize_t\t buffer_length; /* Length of malloc-ed storage in bytes. */\n};\n```\n\n\n## Upstream Fix\n```diff\nIndex: libarchive-3.1.2/libarchive/archive_write_disk_posix.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_write_disk_posix.c\n+++ libarchive-3.1.2/libarchive/archive_write_disk_posix.c\n@@ -326,12 +326,14 @@ struct archive_write_disk {\n \n #define HFS_BLOCKS(s)\t((s) >> 12)\n \n+static int\tcheck_symlinks_fsobj(char *path, int *error_number, struct archive_string *error_string, int flags);\n static int\tcheck_symlinks(struct archive_write_disk *);\n static int\tcreate_filesystem_object(struct archive_write_disk *);\n static struct fixup_entry *current_fixup(struct archive_write_disk *, const char *pathname);\n #if defined(HAVE_FCHDIR) && defined(PATH_MAX)\n static void\tedit_deep_directories(struct archive_write_disk *ad);\n #endif\n+static int\tcleanup_pathname_fsobj(char *path, int *error_number, struct archive_string *error_string, int flags);\n static int\tcleanup_pathname(struct archive_write_disk *);\n static int\tcreate_dir(struct archive_write_disk *, char *);\n static int\tcreate_parent_dir(struct archive_write_disk *, char *);\n@@ -1791,7 +1793,7 @@ edit_deep_directories(struct archive_wri\n \tchar *tail = a->name;\n \n \t/* If path is short, avoid the open() below. */\n-\tif (strlen(tail) <= PATH_MAX)\n+\tif (strlen(tail) < PATH_MAX)\n \t\treturn;\n \n \t/* Try to record our starting dir. */\n@@ -1801,7 +1803,7 @@ edit_deep_directories(struct archive_wri\n \t\treturn;\n \n \t/* As long as the path is too long... */\n-\twhile (strlen(tail) > PATH_MAX) {\n+\twhile (strlen(tail) >= PATH_MAX) {\n \t\t/* Locate a dir prefix shorter than PATH_MAX. */\n \t\ttail += PATH_MAX - 8;\n \t\twhile (tail > a->name && *tail != '/')\n@@ -1996,6 +1998,10 @@ create_filesystem_object(struct archive_\n \tconst char *linkname;\n \tmode_t final_mode, mode;\n \tint r;\n+\t/* these for check_symlinks_fsobj */\n+\tchar *linkname_copy;\t/* non-const copy of linkname */\n+\tstruct archive_string error_string;\n+\tint error_number;\n \n \t/* We identify hard/symlinks according to the link names. */\n \t/* Since link(2) and symlink(2) don't handle modes, we're done here. */\n@@ -2004,6 +2010,27 @@ create_filesystem_object(struct archive_\n #if !HAVE_LINK\n \t\treturn (EPERM);\n #else\n+\t\tarchive_string_init(&error_string);\n+\t\tlinkname_copy = strdup(linkname);\n+\t\tif (linkname_copy == NULL) {\n+\t\t return (EPERM);\n+\t\t}\n+\t\t/* TODO: consider using the cleaned-up path as the link target? */\n+\t\tr = cleanup_pathname_fsobj(linkname_copy, &error_number, &error_string, a->flags);\n+\t\tif (r != ARCHIVE_OK) {\n+\t\t\tarchive_set_error(&a->archive, error_number, \"%s\", error_string.s);\n+\t\t\tfree(linkname_copy);\n+\t\t\t/* EPERM is more appropriate than error_number for our callers */\n+\t\t\treturn (EPERM);\n+\t\t}\n+\t\tr = check_symlinks_fsobj(linkname_copy, &error_number, &error_string, a->flags);\n+\t\tif (r != ARCHIVE_OK) {\n+\t\t\tarchive_set_error(&a->archive, error_number, \"%s\", error_string.s);\n+\t\t\tfree(linkname_copy);\n+\t\t\t/* EPERM is more appropriate than error_number for our callers */\n+\t\t\treturn (EPERM);\n+\t\t}\n+\t\tfree(linkname_copy);\n \t\tr = link(linkname, a->name) ? errno : 0;\n \t\t/*\n \t\t * New cpio and pax formats allow hardlink entries\n@@ -2343,99 +2370,215 @@ current_fixup(struct archive_write_disk\n * recent paths.\n */\n /* TODO: Extend this to support symlinks on Windows Vista and later. */\n+\n+/*\n+ * Checks the given path to see if any elements along it are symlinks. Returns\n+ * ARCHIVE_OK if there are none, otherwise puts an error in errmsg.\n+ */\n static int\n-check_symlinks(struct archive_write_disk *a)\n+check_symlinks_fsobj(char *path, int *error_number, struct archive_string *error_string, int flags)\n {\n #if !defined(HAVE_LSTAT)\n \t/* Platform doesn't have lstat, so we can't look for symlinks. */\n-\t(void)a; /* UNUSED */\n+\t(void)path; /* UNUSED */\n+\t(void)error_number; /* UNUSED */\n+\t(void)error_string; /* UNUSED */\n+\t(void)flags; /* UNUSED */\n \treturn (ARCHIVE_OK);\n #else\n-\tchar *pn;\n+\tint res = ARCHIVE_OK;\n+\tchar *tail;\n+\tchar *head;\n+\tint last;\n \tchar c;\n \tint r;\n \tstruct stat st;\n+\tint restore_pwd;\n+\n+\t/* Nothing to do here if name is empty */\n+\tif(path[0] == '\\0')\n+\t return (ARCHIVE_OK);\n \n \t/*\n \t * Guard against symlink tricks. Reject any archive entry whose\n \t * destination would be altered by a symlink.\n-\t */\n-\t/* Whatever we checked last time doesn't need to be re-checked. */\n-\tpn = a->name;\n-\tif (archive_strlen(&(a->path_safe)) > 0) {\n-\t\tchar *p = a->path_safe.s;\n-\t\twhile ((*pn != '\\0') && (*p == *pn))\n-\t\t\t++p, ++pn;\n-\t}\n-\tc = pn[0];\n-\t/* Keep going until we've checked the entire name. */\n-\twhile (pn[0] != '\\0' && (pn[0] != '/' || pn[1] != '\\0')) {\n+\t *\n+\t * Walk the filename in chunks separated by '/'. For each segment:\n+\t * - if it doesn't exist, continue\n+\t * - if it's symlink, abort or remove it\n+\t * - if it's a directory and it's not the last chunk, cd into it\n+\t * As we go:\n+\t * head points to the current (relative) path\n+\t * tail points to the temporary \\0 terminating the segment we're currently examining\n+\t * c holds what used to be in *tail\n+\t * last is 1 if this is the last tail\n+\t */\n+\trestore_pwd = open(\".\", O_RDONLY | O_BINARY | O_CLOEXEC);\n+\t__archive_ensure_cloexec_flag(restore_pwd);\n+\tif (restore_pwd < 0)\n+\t\treturn (ARCHIVE_FATAL);\n+\thead = path;\n+\ttail = path;\n+\tlast = 0;\n+\n+\t/* TODO: reintroduce a safe cache here? */\n+\n+\t/* Keep going until we've checked the entire name.\n+\t * head, tail, path all alias the same string, which is\n+\t * temporarily zeroed at tail, so be careful restoring the\n+\t * stashed (c=tail[0]) for error messages.\n+\t * Exiting the loop with break is okay; continue is not.\n+\t */\n+\twhile (!last) {\n+\t\t/* Skip the separator we just consumed, plus any adjacent ones */\n+\t\twhile (*tail == '/')\n+\t\t ++tail;\n \t\t/* Skip the next path element. */\n-\t\twhile (*pn != '\\0' && *pn != '/')\n-\t\t\t++pn;\n-\t\tc = pn[0];\n-\t\tpn[0] = '\\0';\n+\t\twhile (*tail != '\\0' && *tail != '/')\n+\t\t\t++tail;\n+\t\t/* is this the last path component? */\n+\t\tlast = (tail[0] == '\\0') || (tail[0] == '/' && tail[1] == '\\0');\n+\t\t/* temporarily truncate the string here */\n+\t\tc = tail[0];\n+\t\ttail[0] = '\\0';\n \t\t/* Check that we haven't hit a symlink. */\n-\t\tr = lstat(a->name, &st);\n+\t\tr = lstat(head, &st);\n \t\tif (r != 0) {\n+\t\t\ttail[0] = c;\n \t\t\t/* We've hit a dir that doesn't exist; stop now. */\n \t\t\tif (errno == ENOENT)\n \t\t\t\tbreak;\n+\t\t\t/* Treat any other error as fatal - best to be paranoid here */\n+\t\t\tif(error_number) *error_number = errno;\n+\t\t\tif(error_string)\n+\t\t\t\tarchive_string_sprintf(error_string,\n+\t\t\t\t\t\"Could not stat %s\",\n+\t\t\t\t\tpath);\n+\t\t\tres = (ARCHIVE_FATAL);\n+\t\t\tbreak;\n+\t\t} else if (S_ISDIR(st.st_mode)) {\n+\t\t\tif (!last) {\n+\t\t\t\tif (chdir(head) != 0) {\n+\t\t\t\t\ttail[0] = c;\n+\t\t\t\t\tif(error_number) *error_number = errno;\n+\t\t\t\t\tif(error_string)\n+\t\t\t\t\t\tarchive_string_sprintf(error_string,\n+\t\t\t\t\t\t\t\"Could not chdir %s\",\n+\t\t\t\t\t\t\tpath);\n+\t\t\t\t\tres = (ARCHIVE_FATAL);\n+\t\t\t\t\tbreak;\n+\t\t\t\t}\n+\t\t\t\t/* Our view is now from inside this dir: */\n+\t\t\t\thead = tail + 1;\n+\t\t\t}\n \t\t} else if (S_ISLNK(st.st_mode)) {\n-\t\t\tif (c == '\\0') {\n+\t\t\tif (last) {\n \t\t\t\t/*\n \t\t\t\t * Last element is symlink; remove it\n \t\t\t\t * so we can overwrite it with the\n \t\t\t\t * item being extracted.\n \t\t\t\t */\n-\t\t\t\tif (unlink(a->name)) {\n-\t\t\t\t\tarchive_set_error(&a->archive, errno,\n-\t\t\t\t\t \"Could not remove symlink %s\",\n-\t\t\t\t\t a->name);\n-\t\t\t\t\tpn[0] = c;\n-\t\t\t\t\treturn (ARCHIVE_FAILED);\n+\t\t\t\tif (unlink(head)) {\n+\t\t\t\t\ttail[0] = c;\n+\t\t\t\t\tif(error_number) *error_number = errno;\n+\t\t\t\t\tif(error_string)\n+\t\t\t\t\t\tarchive_string_sprintf(error_string,\n+\t\t\t\t\t\t\t\"Could not remove symlink %s\",\n+\t\t\t\t\t\t\tpath);\n+\t\t\t\t\tres = (ARCHIVE_FAILED);\n+\t\t\t\t\tbreak;\n \t\t\t\t}\n-\t\t\t\ta->pst = NULL;\n \t\t\t\t/*\n \t\t\t\t * Even if we did remove it, a warning\n \t\t\t\t * is in order. The warning is silly,\n \t\t\t\t * though, if we're just replacing one\n \t\t\t\t * symlink with another symlink.\n \t\t\t\t */\n+\t\t\t\ttail[0] = c;\n+\t\t\t\t/* FIXME: not sure how important this is to restore\n \t\t\t\tif (!S_ISLNK(a->mode)) {\n-\t\t\t\t\tarchive_set_error(&a->archive, 0,\n-\t\t\t\t\t \"Removing symlink %s\",\n-\t\t\t\t\t a->name);\n+\t\t\t\t\tif(error_numbe\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "Index: libarchive-3.1.2/libarchive/archive_write_disk_posix.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_write_disk_posix.c\n+++ libarchive-3.1.2/libarchive/archive_write_disk_posix.c\n@@ -326,12 +326,14 @@ struct archive_write_disk {\n \n #define HFS_BLOCKS(s)\t((s) >> 12)\n \n+static int\tcheck_symlinks_fsobj(char *path, int *error_number, struct archive_string *error_string, int flags);\n static int\tcheck_symlinks(struct archive_write_disk *);\n static int\tcreate_filesystem_object(struct archive_write_disk *);\n static struct fixup_entry *current_fixup(struct archive_write_disk *, const char *pathname);\n #if defined(HAVE_FCHDIR) && defined(PATH_MAX)\n static void\tedit_deep_directories(struct archive_write_disk *ad);\n #endif\n+static int\tcleanup_pathname_fsobj(char *path, int *error_number, struct archive_string *error_string, int flags);\n static int\tcleanup_pathname(struct archive_write_disk *);\n static int\tcreate_dir(struct archive_write_disk *, char *);\n static int\tcreate_parent_dir(struct archive_write_disk *, char *);\n@@ -1791,7 +1793,7 @@ edit_deep_directories(struct archive_wri\n \tchar *tail = a->name;\n \n \t/* If path is short, avoid the open() below. */\n-\tif (strlen(tail) <= PATH_MAX)\n+\tif (strlen(tail) < PATH_MAX)\n \t\treturn;\n \n \t/* Try to record our starting dir. */\n@@ -1801,7 +1803,7 @@ edit_deep_directories(struct archive_wri\n \t\treturn;\n \n \t/* As long as the path is too long... */\n-\twhile (strlen(tail) > PATH_MAX) {\n+\twhile (strlen(tail) >= PATH_MAX) {\n \t\t/* Locate a dir prefix shorter than PATH_MAX. */\n \t\ttail += PATH_MAX - 8;\n \t\twhile (tail > a->name && *tail != '/')\n@@ -1996,6 +1998,10 @@ create_filesystem_object(struct archive_\n \tconst char *linkname;\n \tmode_t final_mode, mode;\n \tint r;\n+\t/* these for check_symlinks_fsobj */\n+\tchar *linkname_copy;\t/* non-const copy of linkname */\n+\tstruct archive_string error_string;\n+\tint error_number;\n \n \t/* We identify hard/symlinks according to the link names. */\n \t/* Since link(2) and symlink(2) don't handle modes, we're done here. */\n@@ -2004,6 +2010,27 @@ create_filesystem_object(struct archive_\n #if !HAVE_LINK\n \t\treturn (EPERM);\n #else\n+\t\tarchive_string_init(&error_string);\n+\t\tlinkname_copy = strdup(linkname);\n+\t\tif (linkname_copy == NULL) {\n+\t\t return (EPERM);\n+\t\t}\n+\t\t/* TODO: consider using the cleaned-up path as the link target? */\n+\t\tr = cleanup_pathname_fsobj(linkname_copy, &error_number, &error_string, a->flags);\n+\t\tif (r != ARCHIVE_OK) {\n+\t\t\tarchive_set_error(&a->archive, error_number, \"%s\", error_string.s);\n+\t\t\tfree(linkname_copy);\n+\t\t\t/* EPERM is more appropriate than error_number for our callers */\n+\t\t\treturn (EPERM);\n+\t\t}\n+\t\tr = check_symlinks_fsobj(linkname_copy, &error_number, &error_string, a->flags);\n+\t\tif (r != ARCHIVE_OK) {\n+\t\t\tarchive_set_error(&a->archive, error_number, \"%s\", error_string.s);\n+\t\t\tfree(linkname_copy);\n+\t\t\t/* EPERM is more appropriate than error_number for our callers */\n+\t\t\treturn (EPERM);\n+\t\t}\n+\t\tfree(linkname_copy);\n \t\tr = link(linkname, a->name) ? errno : 0;\n \t\t/*\n \t\t * New cpio and pax formats allow hardlink entries\n@@ -2343,99 +2370,215 @@ current_fixup(struct archive_write_disk\n * recent paths.\n */\n /* TODO: Extend this to support symlinks on Windows Vista and later. */\n+\n+/*\n+ * Checks the given path to see if any elements along it are symlinks. Returns\n+ * ARCHIVE_OK if there are none, otherwise puts an error in errmsg.\n+ */\n static int\n-check_symlinks(struct archive_write_disk *a)\n+check_symlinks_fsobj(char *path, int *error_number, struct archive_string *error_string, int flags)\n {\n #if !defined(HAVE_LSTAT)\n \t/* Platform doesn't have lstat, so we can't look for symlinks. */\n-\t(void)a; /* UNUSED */\n+\t(void)path; /* UNUSED */\n+\t(void)error_number; /* UNUSED */\n+\t(void)error_string; /* UNUSED */\n+\t(void)flags; /* UNUSED */\n \treturn (ARCHIVE_OK);\n #else\n-\tchar *pn;\n+\tint res = ARCHIVE_OK;\n+\tchar *tail;\n+\tchar *head;\n+\tint last;\n \tchar c;\n \tint r;\n \tstruct stat st;\n+\tint restore_pwd;\n+\n+\t/* Nothing to do here if name is empty */\n+\tif(path[0] == '\\0')\n+\t return (ARCHIVE_OK);\n \n \t/*\n \t * Guard against symlink tricks. Reject any archive entry whose\n \t * destination would be altered by a symlink.\n-\t */\n-\t/* Whatever we checked last time doesn't need to be re-checked. */\n-\tpn = a->name;\n-\tif (archive_strlen(&(a->path_safe)) > 0) {\n-\t\tchar *p = a->path_safe.s;\n-\t\twhile ((*pn != '\\0') && (*p == *pn))\n-\t\t\t++p, ++pn;\n-\t}\n-\tc = pn[0];\n-\t/* Keep going until we've checked the entire name. */\n-\twhile (pn[0] != '\\0' && (pn[0] != '/' || pn[1] != '\\0')) {\n+\t *\n+\t * Walk the filename in chunks separated by '/'. For each segment:\n+\t * - if it doesn't exist, continue\n+\t * - if it's symlink, abort or remove it\n+\t * - if it's a directory and it's not the last chunk, cd into it\n+\t * As we go:\n+\t * head points to the current (relative) path\n+\t * tail points to the temporary \\0 terminating the segment we're currently examining\n+\t * c holds what used to be in *tail\n+\t * last is 1 if this is the last tail\n+\t */\n+\trestore_pwd = open(\".\", O_RDONLY | O_BINARY | O_CLOEXEC);\n+\t__archive_ensure_cloexec_flag(restore_pwd);\n+\tif (restore_pwd < 0)\n+\t\treturn (ARCHIVE_FATAL);\n+\thead = path;\n+\ttail = path;\n+\tlast = 0;\n+\n+\t/* TODO: reintroduce a safe cache here? */\n+\n+\t/* Keep going until we've checked the entire name.\n+\t * head, tail, path all alias the same string, which is\n+\t * temporarily zeroed at tail, so be careful restoring the\n+\t * stashed (c=tail[0]) for error messages.\n+\t * Exiting the loop with break is okay; continue is not.\n+\t */\n+\twhile (!last) {\n+\t\t/* Skip the separator we just consumed, plus any adjacent ones */\n+\t\twhile (*tail == '/')\n+\t\t ++tail;\n \t\t/* Skip the next path element. */\n-\t\twhile (*pn != '\\0' && *pn != '/')\n-\t\t\t++pn;\n-\t\tc = pn[0];\n-\t\tpn[0] = '\\0';\n+\t\twhile (*tail != '\\0' && *tail != '/')\n+\t\t\t++tail;\n+\t\t/* is this the last path component? */\n+\t\tlast = (tail[0] == '\\0') || (tail[0] == '/' && tail[1] == '\\0');\n+\t\t/* temporarily truncate the string here */\n+\t\tc = tail[0];\n+\t\ttail[0] = '\\0';\n \t\t/* Check that we haven't hit a symlink. */\n-\t\tr = lstat(a->name, &st);\n+\t\tr = lstat(head, &st);\n \t\tif (r != 0) {\n+\t\t\ttail[0] = c;\n \t\t\t/* We've hit a dir that doesn't exist; stop now. */\n \t\t\tif (errno == ENOENT)\n \t\t\t\tbreak;\n+\t\t\t/* Treat any other error as fatal - best to be paranoid here */\n+\t\t\tif(error_number) *error_number = errno;\n+\t\t\tif(error_string)\n+\t\t\t\tarchive_string_sprintf(error_string,\n+\t\t\t\t\t\"Could not stat %s\",\n+\t\t\t\t\tpath);\n+\t\t\tres = (ARCHIVE_FATAL);\n+\t\t\tbreak;\n+\t\t} else if (S_ISDIR(st.st_mode)) {\n+\t\t\tif (!last) {\n+\t\t\t\tif (chdir(head) != 0) {\n+\t\t\t\t\ttail[0] = c;\n+\t\t\t\t\tif(error_number) *error_number = errno;\n+\t\t\t\t\tif(error_string)\n+\t\t\t\t\t\tarchive_string_sprintf(error_string,\n+\t\t\t\t\t\t\t\"Could not chdir %s\",\n+\t\t\t\t\t\t\tpath);\n+\t\t\t\t\tres = (ARCHIVE_FATAL);\n+\t\t\t\t\tbreak;\n+\t\t\t\t}\n+\t\t\t\t/* Our view is now from inside this dir: */\n+\t\t\t\thead = tail + 1;\n+\t\t\t}\n \t\t} else if (S_ISLNK(st.st_mode)) {\n-\t\t\tif (c == '\\0') {\n+\t\t\tif (last) {\n \t\t\t\t/*\n \t\t\t\t * Last element is symlink; remove it\n \t\t\t\t * so we can overwrite it with the\n \t\t\t\t * item being extracted.\n \t\t\t\t */\n-\t\t\t\tif (unlink(a->name)) {\n-\t\t\t\t\tarchive_set_error(&a->archive, errno,\n-\t\t\t\t\t \"Could not remove symlink %s\",\n-\t\t\t\t\t a->name);\n-\t\t\t\t\tpn[0] = c;\n-\t\t\t\t\treturn (ARCHIVE_FAILED);\n+\t\t\t\tif (unlink(head)) {\n+\t\t\t\t\ttail[0] = c;\n+\t\t\t\t\tif(error_number) *error_number = errno;\n+\t\t\t\t\tif(error_string)\n+\t\t\t\t\t\tarchive_string_sprintf(error_string,\n+\t\t\t\t\t\t\t\"Could not remove symlink %s\",\n+\t\t\t\t\t\t\tpath);\n+\t\t\t\t\tres = (ARCHIVE_FAILED);\n+\t\t\t\t\tbreak;\n \t\t\t\t}\n-\t\t\t\ta->pst = NULL;\n \t\t\t\t/*\n \t\t\t\t * Even if we did remove it, a warning\n \t\t\t\t * is in order. The warning is silly,\n \t\t\t\t * though, if we're just replacing one\n \t\t\t\t * symlink with another symlink.\n \t\t\t\t */\n+\t\t\t\ttail[0] = c;\n+\t\t\t\t/* FIXME: not sure how important this is to restore\n \t\t\t\tif (!S_ISLNK(a->mode)) {\n-\t\t\t\t\tarchive_set_error(&a->archive, 0,\n-\t\t\t\t\t \"Removing symlink %s\",\n-\t\t\t\t\t a->name);\n+\t\t\t\t\tif(error_number) *error_number = 0;\n+\t\t\t\t\tif(error_string)\n+\t\t\t\t\t\tarchive_string_sprintf(error_string,\n+\t\t\t\t\t\t\t\"Removing symlink %s\",\n+\t\t\t\t\t\t\tpath);\n \t\t\t\t}\n+\t\t\t\t*/\n \t\t\t\t/* Symlink gone. No more problem! */\n-\t\t\t\tpn[0] = c;\n-\t\t\t\treturn (0);\n-\t\t\t} else if (a->flags & ARCHIVE_EXTRACT_UNLINK) {\n+\t\t\t\tres = (ARCHIVE_OK);\n+\t\t\t\tbreak;\n+\t\t\t} else if (flags & ARCHIVE_EXTRACT_UNLINK) {\n \t\t\t\t/* User asked us to remove problems. */\n-\t\t\t\tif (unlink(a->name) != 0) {\n-\t\t\t\t\tarchive_set_error(&a->archive, 0,\n-\t\t\t\t\t \"Cannot remove intervening symlink %s\",\n-\t\t\t\t\t a->name);\n-\t\t\t\t\tpn[0] = c;\n-\t\t\t\t\treturn (ARCHIVE_FAILED);\n+\t\t\t\tif (unlink(head) != 0) {\n+\t\t\t\t\ttail[0] = c;\n+\t\t\t\t\tif(error_number) *error_number = 0;\n+\t\t\t\t\tif(error_string)\n+\t\t\t\t\t\tarchive_string_sprintf(error_string,\n+\t\t\t\t\t\t\t\"Cannot remove intervening symlink %s\",\n+\t\t\t\t\t\t\tpath);\n+\t\t\t\t\tres = (ARCHIVE_FAILED);\n+\t\t\t\t\tbreak;\n \t\t\t\t}\n-\t\t\t\ta->pst = NULL;\n \t\t\t} else {\n-\t\t\t\tarchive_set_error(&a->archive, 0,\n-\t\t\t\t \"Cannot extract through symlink %s\",\n-\t\t\t\t a->name);\n-\t\t\t\tpn[0] = c;\n-\t\t\t\treturn (ARCHIVE_FAILED);\n+\t\t\t\ttail[0] = c;\n+\t\t\t\tif(error_number) *error_number = 0;\n+\t\t\t\tif(error_string)\n+\t\t\t\t\tarchive_string_sprintf(error_string,\n+\t\t\t\t\t\t\"Cannot extract through symlink %s\",\n+\t\t\t\t\t\tpath);\n+\t\t\t\tres = (ARCHIVE_FAILED);\n+\t\t\t\tbreak;\n \t\t\t}\n \t\t}\n+\t\t/* be sure to always maintain this */\n+\t\ttail[0] = c;\n \t}\n-\tpn[0] = c;\n-\t/* We've checked and/or cleaned the whole path, so remember it. */\n-\tarchive_strcpy(&a->path_safe, a->name);\n-\treturn (ARCHIVE_OK);\n+\t/* Catches loop exits via break */\n+\ttail[0] = c;\n+#ifdef HAVE_FCHDIR\n+\t/* If we changed directory above, restore it here. */\n+\tif (restore_pwd >= 0) {\n+\t\tr = fchdir(restore_pwd);\n+\t\tif (r != 0) {\n+\t\t\tif(error_number) *error_number = 0;\n+\t\t\tif(error_string)\n+\t\t\t\tarchive_string_sprintf(error_string,\n+\t\t\t\t\t\"Cannot extract through symlink %s\",\n+\t\t\t\t\tpath);\n+\t\t}\n+\t\tclose(restore_pwd);\n+\t\trestore_pwd = -1;\n+\t\tif (r != 0) {\n+\t\t\tres = (ARCHIVE_FATAL);\n+\t\t}\n+\t}\n+#endif\n+\t/* TODO: reintroduce a safe cache here? */\n+\treturn res;\n #endif\n }\n \n+/*\n+ * Check a->name for symlinks, returning ARCHIVE_OK if its clean, otherwise\n+ * calls archive_set_error and returns ARCHIVE_{FATAL,FAILED}\n+ */\n+static int\n+check_symlinks(struct archive_write_disk *a)\n+{\n+\tstruct archive_string error_string;\n+\tint error_number;\n+\tint rc;\n+\tarchive_string_init(&error_string);\n+\trc = check_symlinks_fsobj(a->name, &error_number, &error_string, a->flags);\n+\tif (rc != ARCHIVE_OK) {\n+\t\tarchive_set_error(&a->archive, error_number, \"%s\", error_string.s);\n+\t}\n+\tarchive_string_free(&error_string);\n+\ta->pst = NULL;\t/* to be safe */\n+\treturn rc;\n+}\n+\n+\n #if defined(__CYGWIN__)\n /*\n * 1. Convert a path separator from '\\' to '/' .\n@@ -2509,15 +2652,17 @@ cleanup_pathname_win(struct archive_writ\n * is set) if the path is absolute.\n */\n static int\n-cleanup_pathname(struct archive_write_disk *a)\n+cleanup_pathname_fsobj(char *path, int *error_number, struct archive_string *error_string, int flags)\n {\n \tchar *dest, *src;\n \tchar separator = '\\0';\n \n-\tdest = src = a->name;\n+\tdest = src = path;\n \tif (*src == '\\0') {\n-\t\tarchive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,\n-\t\t \"Invalid empty pathname\");\n+\t\tif (error_number) *error_number = ARCHIVE_ERRNO_MISC;\n+\t\tif (error_string)\n+\t\t\tarchive_string_sprintf(error_string,\n+\t\t\t\t\"Invalid empty pathname\");\n \t\treturn (ARCHIVE_FAILED);\n \t}\n \n@@ -2555,10 +2700,11 @@ cleanup_pathname(struct archive_write_di\n \t\t\t} else if (src[1] == '.') {\n \t\t\t\tif (src[2] == '/' || src[2] == '\\0') {\n \t\t\t\t\t/* Conditionally warn about '..' */\n-\t\t\t\t\tif (a->flags & ARCHIVE_EXTRACT_SECURE_NODOTDOT) {\n-\t\t\t\t\t\tarchive_set_error(&a->archive,\n-\t\t\t\t\t\t ARCHIVE_ERRNO_MISC,\n-\t\t\t\t\t\t \"Path contains '..'\");\n+\t\t\t\t\tif (flags & ARCHIVE_EXTRACT_SECURE_NODOTDOT) {\n+\t\t\t\t\t\tif (error_number) *error_number = ARCHIVE_ERRNO_MISC;\n+\t\t\t\t\t\tif (error_string)\n+\t\t\t\t\t\t\tarchive_string_sprintf(error_string,\n+\t\t\t\t\t\t\t\t\"Path contains '..'\");\n \t\t\t\t\t\treturn (ARCHIVE_FAILED);\n \t\t\t\t\t}\n \t\t\t\t}\n@@ -2589,7 +2735,7 @@ cleanup_pathname(struct archive_write_di\n \t * We've just copied zero or more path elements, not including the\n \t * final '/'.\n \t */\n-\tif (dest == a->name) {\n+\tif (dest == path) {\n \t\t/*\n \t\t * Nothing got copied. The path must have been something\n \t\t * like '.' or '/' or './' or '/././././/./'.\n@@ -2604,6 +2750,21 @@ cleanup_pathname(struct archive_write_di\n \treturn (ARCHIVE_OK);\n }\n \n+static int\n+cleanup_pathname(struct archive_write_disk *a)\n+{\n+\tstruct archive_string error_string;\n+\tint error_number;\n+\tint rc;\n+\tarchive_string_init(&error_string);\n+\trc = cleanup_pathname_fsobj(a->name, &error_number, &error_string, a->flags);\n+\tif (rc != ARCHIVE_OK) {\n+\t\tarchive_set_error(&a->archive, error_number, \"%s\", error_string.s);\n+\t}\n+\tarchive_string_free(&error_string);\n+\treturn rc;\n+}\n+\n /*\n * Create the parent directory of the specified path, assuming path\n * is already in mutable storage."}], "metadata": {"id": "libarchive-5940-CVE-2016-5418.patch", "cve_id": "CVE-2016-6250", "package": "libarchive", "tier": "adapted", "has_source_context": true, "context_tokens_est": 2640, "context_files": 1, "license": "BSD-2-Clause"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3455\n\nSquid 3.2.x before 3.2.14, 3.3.x before 3.3.14, 3.4.x before 3.4.13, and 3.5.x before 3.5.4, when configured with client-first SSL-bump, do not properly validate the domain or hostname fields of X.509 certificates, which allows man-in-the-middle attackers to spoof SSL servers via a valid certificate.\n\n## Package\nsquid\n\n## Upstream Fix\n```diff\nIndex: squid-3.3.13/src/tunnel.cc\n===================================================================\n--- squid-3.3.13.orig/src/tunnel.cc\n+++ squid-3.3.13/src/tunnel.cc\n@@ -45,6 +45,7 @@\n #include \"fde.h\"\n #include \"http.h\"\n #include \"HttpRequest.h\"\n+#include \"HttpReply.h\"\n #include \"HttpStateFlags.h\"\n #include \"ip/QosConfig.h\"\n #include \"MemBuf.h\"\n@@ -76,6 +77,12 @@ public:\n static void WriteClientDone(const Comm::ConnectionPointer &, char *buf, size_t len, comm_err_t flag, int xerrno, void *data);\n static void WriteServerDone(const Comm::ConnectionPointer &, char *buf, size_t len, comm_err_t flag, int xerrno, void *data);\n \n+ /// Starts reading peer response to our CONNECT request.\n+ void readConnectResponse();\n+\n+ /// Called when we may be done handling a CONNECT exchange with the peer.\n+ void connectExchangeCheckpoint();\n+\n bool noConnections() const;\n char *url;\n HttpRequest *request;\n@@ -86,6 +93,23 @@ public:\n return (server.conn != NULL && server.conn->getPeer() ? server.conn->getPeer()->host : request->GetHost());\n };\n \n+ /// Whether we are writing a CONNECT request to a peer.\n+ bool waitingForConnectRequest() const { return connectReqWriting; }\n+ /// Whether we are reading a CONNECT response from a peer.\n+ bool waitingForConnectResponse() const { return connectRespBuf; }\n+ /// Whether we are waiting for the CONNECT request/response exchange with the peer.\n+ bool waitingForConnectExchange() const { return waitingForConnectRequest() || waitingForConnectResponse(); }\n+\n+ /// Whether the client sent a CONNECT request to us.\n+ bool clientExpectsConnectResponse() const {\n+ return !(request != NULL &&\n+ (request->flags.spoofClientIp || request->flags.intercepted));\n+ }\n+\n+ /// Sends \"502 Bad Gateway\" error response to the client,\n+ /// if it is waiting for Squid CONNECT response, closing connections.\n+ void informUserOfPeerError(const char *errMsg);\n+\n class Connection\n {\n \n@@ -105,9 +129,13 @@ public:\n int debugLevelForError(int const xerrno) const;\n void closeIfOpen();\n void dataSent (size_t amount);\n+ /// writes 'b' buffer, setting the 'writer' member to\n+ //'callback'.\n+ void write(const char *b, int size, AsyncCall::Pointer &callback, FREE * free_func);\n int len;\n char *buf;\n int64_t *size_ptr;\t\t/* pointer to size in an ConnStateData for logging */\n+ AsyncCall::Pointer writer; ///< pending Comm::Write callback\n \n Comm::ConnectionPointer conn; ///< The currently connected connection.\n \n@@ -121,15 +149,23 @@ public:\n \n Connection client, server;\n int *status_ptr;\t\t/* pointer to status for logging */\n+ MemBuf *connectRespBuf; ///< accumulates peer CONNECT response when we need it\n+ bool connectReqWriting; ///< whether we are writing a CONNECT request to a peer\n+\n void copyRead(Connection &from, IOCB *completion);\n \n private:\n CBDATA_CLASS(TunnelStateData);\n- void copy (size_t len, comm_err_t errcode, int xerrno, Connection &from, Connection &to, IOCB *);\n+ bool keepGoingAfterRead(size_t len, comm_err_t errcode, int xerrno, Connection &from, Connection &to);\n+ void copy (size_t len, Connection &from, Connection &to, IOCB *);\n+ void handleConnectResponse(const size_t chunkSize);\n void readServer(char *buf, size_t len, comm_err_t errcode, int xerrno);\n void readClient(char *buf, size_t len, comm_err_t errcode, int xerrno);\n void writeClientDone(char *buf, size_t len, comm_err_t flag, int xerrno);\n void writeServerDone(char *buf, size_t len, comm_err_t flag, int xerrno);\n+\n+ static void ReadConnectResponseDone(const Comm::ConnectionPointer &, char *buf, size_t len, comm_err_t errcode, int xerrno, void *data);\n+ void readConnectResponseDone(char *buf, size_t len, comm_err_t errcode, int xerrno);\n };\n \n static const char *const conn_established = \"HTTP/1.1 200 Connection established\\r\\n\\r\\n\";\n@@ -150,13 +186,14 @@ tunnelServerClosed(const CommCloseCbPara\n TunnelStateData *tunnelState = (TunnelStateData *)params.data;\n debugs(26, 3, HERE << tunnelState->server.conn);\n tunnelState->server.conn = NULL;\n+ tunnelState->server.writer = NULL;\n \n if (tunnelState->noConnections()) {\n tunnelStateFree(tunnelState);\n return;\n }\n \n- if (!tunnelState->server.len) {\n+ if (!tunnelState->client.writer) {\n tunnelState->client.conn->close();\n return;\n }\n@@ -168,13 +205,14 @@ tunnelClientClosed(const CommCloseCbPara\n TunnelStateData *tunnelState = (TunnelStateData *)params.data;\n debugs(26, 3, HERE << tunnelState->client.conn);\n tunnelState->client.conn = NULL;\n+ tunnelState->client.writer = NULL;\n \n if (tunnelState->noConnections()) {\n tunnelStateFree(tunnelState);\n return;\n }\n \n- if (!tunnelState->client.len) {\n+ if (!tunnelState->server.writer) {\n tunnelState->server.conn->close();\n return;\n }\n@@ -265,9 +303,122 @@ TunnelStateData::readServer(char *buf, s\n kb_incr(&(statCounter.server.other.kbytes_in), len);\n }\n \n- copy (len, errcode, xerrno, server, client, WriteClientDone);\n+ if (keepGoingAfterRead(len, errcode, xerrno, server, client))\n+ copy (len, server, client, WriteClientDone);\n+}\n+\n+/// Called when we read [a part of] CONNECT response from the peer\n+void\n+TunnelStateData::readConnectResponseDone(char *buf, size_t len, comm_err_t errcode, int xerrno)\n+{\n+ debugs(26, 3, server.conn << \", read \" << len << \" bytes, err=\" << errcode);\n+ assert(waitingForConnectResponse());\n+\n+ if (errcode == COMM_ERR_CLOSING)\n+ return;\n+\n+ if (len > 0) {\n+ connectRespBuf->appended(len);\n+ server.bytesIn(len);\n+ kb_incr(&(statCounter.server.all.kbytes_in), len);\n+ kb_incr(&(statCounter.server.other.kbytes_in), len);\n+ }\n+\n+ if (keepGoingAfterRead(len, errcode, xerrno, server, client))\n+ handleConnectResponse(len);\n+}\n+\n+/* Read from client side and queue it for writing to the server */\n+void\n+TunnelStateData::ReadConnectResponseDone(const Comm::ConnectionPointer &, char *buf, size_t len, comm_err_t errcode, int xerrno, void *data)\n+{\n+ TunnelStateData *tunnelState = (TunnelStateData *)data;\n+ assert (cbdataReferenceValid (tunnelState));\n+\n+ tunnelState->readConnectResponseDone(buf, len, errcode, xerrno);\n+}\n+\n+void\n+TunnelStateData::informUserOfPeerError(const char *errMsg)\n+{\n+ server.len = 0;\n+ if (!clientExpectsConnectResponse()) {\n+ // closing the connection is the best we can do here\n+ debugs(50, 3, server.conn << \" closing on error: \" << errMsg);\n+ server.conn->close();\n+ return;\n+ }\n+ ErrorState *err = new ErrorState(ERR_CONNECT_FAIL, HTTP_BAD_GATEWAY, request);\n+ err->callback = tunnelErrorComplete;\n+ err->callback_data = this;\n+ *status_ptr = HTTP_BAD_GATEWAY;\n+ errorSend(client.conn, err);\n+}\n+\n+/// Parses [possibly incomplete] CONNECT response and reacts to it.\n+/// If the tunnel is being closed or more response data is needed, returns false.\n+/// Otherwise, the caller should handle the remaining read data, if any.\n+void\n+TunnelStateData::handleConnectResponse(const size_t chunkSize)\n+{\n+ assert(waitingForConnectResponse());\n+\n+ // Ideally, client and server should use MemBuf or better, but current code\n+ // never accumulates more than one read when shoveling data (XXX) so it does\n+ // not need to deal with MemBuf complexity. To keep it simple, we use a\n+ // dedicated MemBuf for accumulating CONNECT responses. TODO: When shoveling\n+ // is optimized, reuse server.buf for CONNEC response accumulation instead.\n+\n+ /* mimic the basic parts of HttpStateData::processReplyHeader() */\n+ HttpReply *rep = new HttpReply;\n+ http_status parseErr = HTTP_STATUS_NONE;\n+ int eof = !chunkSize;\n+ const bool parsed = rep->parse(connectRes\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "Index: squid-3.3.13/src/tunnel.cc\n===================================================================\n--- squid-3.3.13.orig/src/tunnel.cc\n+++ squid-3.3.13/src/tunnel.cc\n@@ -45,6 +45,7 @@\n #include \"fde.h\"\n #include \"http.h\"\n #include \"HttpRequest.h\"\n+#include \"HttpReply.h\"\n #include \"HttpStateFlags.h\"\n #include \"ip/QosConfig.h\"\n #include \"MemBuf.h\"\n@@ -76,6 +77,12 @@ public:\n static void WriteClientDone(const Comm::ConnectionPointer &, char *buf, size_t len, comm_err_t flag, int xerrno, void *data);\n static void WriteServerDone(const Comm::ConnectionPointer &, char *buf, size_t len, comm_err_t flag, int xerrno, void *data);\n \n+ /// Starts reading peer response to our CONNECT request.\n+ void readConnectResponse();\n+\n+ /// Called when we may be done handling a CONNECT exchange with the peer.\n+ void connectExchangeCheckpoint();\n+\n bool noConnections() const;\n char *url;\n HttpRequest *request;\n@@ -86,6 +93,23 @@ public:\n return (server.conn != NULL && server.conn->getPeer() ? server.conn->getPeer()->host : request->GetHost());\n };\n \n+ /// Whether we are writing a CONNECT request to a peer.\n+ bool waitingForConnectRequest() const { return connectReqWriting; }\n+ /// Whether we are reading a CONNECT response from a peer.\n+ bool waitingForConnectResponse() const { return connectRespBuf; }\n+ /// Whether we are waiting for the CONNECT request/response exchange with the peer.\n+ bool waitingForConnectExchange() const { return waitingForConnectRequest() || waitingForConnectResponse(); }\n+\n+ /// Whether the client sent a CONNECT request to us.\n+ bool clientExpectsConnectResponse() const {\n+ return !(request != NULL &&\n+ (request->flags.spoofClientIp || request->flags.intercepted));\n+ }\n+\n+ /// Sends \"502 Bad Gateway\" error response to the client,\n+ /// if it is waiting for Squid CONNECT response, closing connections.\n+ void informUserOfPeerError(const char *errMsg);\n+\n class Connection\n {\n \n@@ -105,9 +129,13 @@ public:\n int debugLevelForError(int const xerrno) const;\n void closeIfOpen();\n void dataSent (size_t amount);\n+ /// writes 'b' buffer, setting the 'writer' member to\n+ //'callback'.\n+ void write(const char *b, int size, AsyncCall::Pointer &callback, FREE * free_func);\n int len;\n char *buf;\n int64_t *size_ptr;\t\t/* pointer to size in an ConnStateData for logging */\n+ AsyncCall::Pointer writer; ///< pending Comm::Write callback\n \n Comm::ConnectionPointer conn; ///< The currently connected connection.\n \n@@ -121,15 +149,23 @@ public:\n \n Connection client, server;\n int *status_ptr;\t\t/* pointer to status for logging */\n+ MemBuf *connectRespBuf; ///< accumulates peer CONNECT response when we need it\n+ bool connectReqWriting; ///< whether we are writing a CONNECT request to a peer\n+\n void copyRead(Connection &from, IOCB *completion);\n \n private:\n CBDATA_CLASS(TunnelStateData);\n- void copy (size_t len, comm_err_t errcode, int xerrno, Connection &from, Connection &to, IOCB *);\n+ bool keepGoingAfterRead(size_t len, comm_err_t errcode, int xerrno, Connection &from, Connection &to);\n+ void copy (size_t len, Connection &from, Connection &to, IOCB *);\n+ void handleConnectResponse(const size_t chunkSize);\n void readServer(char *buf, size_t len, comm_err_t errcode, int xerrno);\n void readClient(char *buf, size_t len, comm_err_t errcode, int xerrno);\n void writeClientDone(char *buf, size_t len, comm_err_t flag, int xerrno);\n void writeServerDone(char *buf, size_t len, comm_err_t flag, int xerrno);\n+\n+ static void ReadConnectResponseDone(const Comm::ConnectionPointer &, char *buf, size_t len, comm_err_t errcode, int xerrno, void *data);\n+ void readConnectResponseDone(char *buf, size_t len, comm_err_t errcode, int xerrno);\n };\n \n static const char *const conn_established = \"HTTP/1.1 200 Connection established\\r\\n\\r\\n\";\n@@ -150,13 +186,14 @@ tunnelServerClosed(const CommCloseCbPara\n TunnelStateData *tunnelState = (TunnelStateData *)params.data;\n debugs(26, 3, HERE << tunnelState->server.conn);\n tunnelState->server.conn = NULL;\n+ tunnelState->server.writer = NULL;\n \n if (tunnelState->noConnections()) {\n tunnelStateFree(tunnelState);\n return;\n }\n \n- if (!tunnelState->server.len) {\n+ if (!tunnelState->client.writer) {\n tunnelState->client.conn->close();\n return;\n }\n@@ -168,13 +205,14 @@ tunnelClientClosed(const CommCloseCbPara\n TunnelStateData *tunnelState = (TunnelStateData *)params.data;\n debugs(26, 3, HERE << tunnelState->client.conn);\n tunnelState->client.conn = NULL;\n+ tunnelState->client.writer = NULL;\n \n if (tunnelState->noConnections()) {\n tunnelStateFree(tunnelState);\n return;\n }\n \n- if (!tunnelState->client.len) {\n+ if (!tunnelState->server.writer) {\n tunnelState->server.conn->close();\n return;\n }\n@@ -265,9 +303,122 @@ TunnelStateData::readServer(char *buf, s\n kb_incr(&(statCounter.server.other.kbytes_in), len);\n }\n \n- copy (len, errcode, xerrno, server, client, WriteClientDone);\n+ if (keepGoingAfterRead(len, errcode, xerrno, server, client))\n+ copy (len, server, client, WriteClientDone);\n+}\n+\n+/// Called when we read [a part of] CONNECT response from the peer\n+void\n+TunnelStateData::readConnectResponseDone(char *buf, size_t len, comm_err_t errcode, int xerrno)\n+{\n+ debugs(26, 3, server.conn << \", read \" << len << \" bytes, err=\" << errcode);\n+ assert(waitingForConnectResponse());\n+\n+ if (errcode == COMM_ERR_CLOSING)\n+ return;\n+\n+ if (len > 0) {\n+ connectRespBuf->appended(len);\n+ server.bytesIn(len);\n+ kb_incr(&(statCounter.server.all.kbytes_in), len);\n+ kb_incr(&(statCounter.server.other.kbytes_in), len);\n+ }\n+\n+ if (keepGoingAfterRead(len, errcode, xerrno, server, client))\n+ handleConnectResponse(len);\n+}\n+\n+/* Read from client side and queue it for writing to the server */\n+void\n+TunnelStateData::ReadConnectResponseDone(const Comm::ConnectionPointer &, char *buf, size_t len, comm_err_t errcode, int xerrno, void *data)\n+{\n+ TunnelStateData *tunnelState = (TunnelStateData *)data;\n+ assert (cbdataReferenceValid (tunnelState));\n+\n+ tunnelState->readConnectResponseDone(buf, len, errcode, xerrno);\n+}\n+\n+void\n+TunnelStateData::informUserOfPeerError(const char *errMsg)\n+{\n+ server.len = 0;\n+ if (!clientExpectsConnectResponse()) {\n+ // closing the connection is the best we can do here\n+ debugs(50, 3, server.conn << \" closing on error: \" << errMsg);\n+ server.conn->close();\n+ return;\n+ }\n+ ErrorState *err = new ErrorState(ERR_CONNECT_FAIL, HTTP_BAD_GATEWAY, request);\n+ err->callback = tunnelErrorComplete;\n+ err->callback_data = this;\n+ *status_ptr = HTTP_BAD_GATEWAY;\n+ errorSend(client.conn, err);\n+}\n+\n+/// Parses [possibly incomplete] CONNECT response and reacts to it.\n+/// If the tunnel is being closed or more response data is needed, returns false.\n+/// Otherwise, the caller should handle the remaining read data, if any.\n+void\n+TunnelStateData::handleConnectResponse(const size_t chunkSize)\n+{\n+ assert(waitingForConnectResponse());\n+\n+ // Ideally, client and server should use MemBuf or better, but current code\n+ // never accumulates more than one read when shoveling data (XXX) so it does\n+ // not need to deal with MemBuf complexity. To keep it simple, we use a\n+ // dedicated MemBuf for accumulating CONNECT responses. TODO: When shoveling\n+ // is optimized, reuse server.buf for CONNEC response accumulation instead.\n+\n+ /* mimic the basic parts of HttpStateData::processReplyHeader() */\n+ HttpReply *rep = new HttpReply;\n+ http_status parseErr = HTTP_STATUS_NONE;\n+ int eof = !chunkSize;\n+ const bool parsed = rep->parse(connectRespBuf, eof, &parseErr);\n+ if (!parsed) {\n+ if (parseErr > 0) { // unrecoverable parsing error\n+ informUserOfPeerError(\"malformed CONNECT response from peer\");\n+ return;\n+ }\n+\n+ // need more data\n+ assert(!eof);\n+ assert(!parseErr);\n+\n+ if (!connectRespBuf->hasSpace()) {\n+ informUserOfPeerError(\"huge CONNECT response from peer\");\n+ return;\n+ }\n+\n+ // keep reading\n+ readConnectResponse();\n+ return;\n+ }\n+\n+ // CONNECT response was successfully parsed\n+ *status_ptr = rep->sline.status;\n+\n+ // bail if we did not get an HTTP 200 (Connection Established) response\n+ if (rep->sline.status != HTTP_OK) {\n+ // if we ever decide to reuse the peer connection, we must extract the error response first\n+ informUserOfPeerError(\"unsupported CONNECT response status code\");\n+ return;\n+ }\n+\n+ if (rep->hdr_sz < connectRespBuf->contentSize()) {\n+ // preserve bytes that the server already sent after the CONNECT response\n+ server.len = connectRespBuf->contentSize() - rep->hdr_sz;\n+ memcpy(server.buf, connectRespBuf->content() + rep->hdr_sz, server.len);\n+ } else {\n+ // reset; delay pools were using this field to throttle CONNECT response\n+ server.len = 0;\n+ }\n+\n+ delete connectRespBuf;\n+ connectRespBuf = NULL;\n+ connectExchangeCheckpoint();\n }\n \n+\n void\n TunnelStateData::Connection::error(int const xerrno)\n {\n@@ -308,11 +459,14 @@ TunnelStateData::readClient(char *buf, s\n kb_incr(&(statCounter.client_http.kbytes_in), len);\n }\n \n- copy (len, errcode, xerrno, client, server, WriteServerDone);\n+ if (keepGoingAfterRead(len, errcode, xerrno, client, server))\n+ copy (len, client, server, WriteServerDone);\n }\n \n-void\n-TunnelStateData::copy (size_t len, comm_err_t errcode, int xerrno, Connection &from, Connection &to, IOCB *completion)\n+/// Updates state after reading from client or server.\n+/// Returns whether the caller should use the data just read.\n+bool\n+TunnelStateData::keepGoingAfterRead(size_t len, comm_err_t errcode, int xerrno, Connection &from, Connection &to)\n {\n debugs(26, 3, HERE << \"from={\" << from.conn << \"}, to={\" << to.conn << \"}\");\n \n@@ -348,13 +502,21 @@ TunnelStateData::copy (size_t len, comm_\n to.conn->close();\n }\n } else if (cbdataReferenceValid(this)) {\n- debugs(26, 3, HERE << \"Schedule Write\");\n- AsyncCall::Pointer call = commCbCall(5,5, \"TunnelBlindCopyWriteHandler\",\n- CommIoCbPtrFun(completion, this));\n- Comm::Write(to.conn, from.buf, len, call, NULL);\n+ cbdataInternalUnlock(this); /* ??? */\n+ return true;\n }\n \n cbdataInternalUnlock(this);\t/* ??? */\n+ return false;\n+}\n+\n+void\n+TunnelStateData::copy (size_t len, Connection &from, Connection &to, IOCB *completion)\n+{\n+ debugs(26, 3, HERE << \"Schedule Write\");\n+ AsyncCall::Pointer call = commCbCall(5,5,\"TunnelBlindCopyWriteHandler\",\n+ CommIoCbPtrFun(completion, this));\n+ to.write(from.buf, len, call, NULL);\n }\n \n /* Writes data from the client buffer to the server side */\n@@ -363,6 +525,7 @@ TunnelStateData::WriteServerDone(const C\n {\n TunnelStateData *tunnelState = (TunnelStateData *)data;\n assert (cbdataReferenceValid (tunnelState));\n+ tunnelState->server.writer = NULL;\n \n tunnelState->writeServerDone(buf, len, flag, xerrno);\n }\n@@ -414,6 +577,7 @@ TunnelStateData::WriteClientDone(const C\n {\n TunnelStateData *tunnelState = (TunnelStateData *)data;\n assert (cbdataReferenceValid (tunnelState));\n+ tunnelState->client.writer = NULL;\n \n tunnelState->writeClientDone(buf, len, flag, xerrno);\n }\n@@ -431,7 +595,14 @@ TunnelStateData::Connection::dataSent(si\n }\n \n void\n-TunnelStateData::writeClientDone(char *buf, size_t len, comm_err_t flag, int xerrno)\n+TunnelStateData::Connection::write(const char *b, int size, AsyncCall::Pointer &callback, FREE * free_func)\n+{\n+ writer = callback;\n+ Comm::Write(conn, b, size, callback, free_func);\n+}\n+\n+void\n+TunnelStateData::writeClientDone(char *, size_t len, comm_err_t flag, int xerrno)\n {\n debugs(26, 3, HERE << client.conn << \", \" << len << \" bytes written, flag=\" << flag);\n \n@@ -499,6 +670,32 @@ TunnelStateData::copyRead(Connection &fr\n comm_read(from.conn, from.buf, from.bytesWanted(1, SQUID_TCP_SO_RCVBUF), call);\n }\n \n+void\n+TunnelStateData::connectExchangeCheckpoint()\n+{\n+ if (waitingForConnectResponse()) {\n+ debugs(26, 5, \"still reading CONNECT response on \" << server.conn);\n+ } else if (waitingForConnectRequest()) {\n+ debugs(26, 5, \"still writing CONNECT request on \" << server.conn);\n+ } else {\n+ assert(!waitingForConnectExchange());\n+ debugs(26, 3, \"done with CONNECT exchange on \" << server.conn);\n+ tunnelConnected(server.conn, this);\n+ }\n+}\n+\n+void\n+TunnelStateData::readConnectResponse()\n+{\n+ assert(waitingForConnectResponse());\n+\n+ AsyncCall::Pointer call = commCbCall(5,4, \"readConnectResponseDone\",\n+ CommIoCbPtrFun(ReadConnectResponseDone, this));\n+ comm_read(server.conn, connectRespBuf->space(),\n+ server.bytesWanted(1, connectRespBuf->spaceSize()), call);\n+}\n+\n+\n /**\n * Set the HTTP status for this request and sets the read handlers for client\n * and server side connections.\n@@ -523,6 +720,7 @@ tunnelConnectedWriteDone(const Comm::Con\n {\n TunnelStateData *tunnelState = (TunnelStateData *)data;\n debugs(26, 3, HERE << conn << \", flag=\" << flag);\n+ tunnelState->client.writer = NULL;\n \n if (flag != COMM_OK) {\n *tunnelState->status_ptr = HTTP_INTERNAL_SERVER_ERROR;\n@@ -733,7 +931,17 @@ tunnelRelayConnectRequest(const Comm::Co\n \n AsyncCall::Pointer writeCall = commCbCall(5,5, \"tunnelConnectedWriteDone\",\n CommIoCbPtrFun(tunnelConnectedWriteDone, tunnelState));\n- Comm::Write(srv, &mb, writeCall);\n+ tunnelState->server.write(mb.buf, mb.size, writeCall, mb.freeFunc());\n+ tunnelState->connectReqWriting = true;\n+\n+ tunnelState->connectRespBuf = new MemBuf;\n+ // SQUID_TCP_SO_RCVBUF: we should not accumulate more than regular I/O buffer\n+ // can hold since any CONNECT response leftovers have to fit into server.buf.\n+ // 2*SQUID_TCP_SO_RCVBUF: HttpMsg::parse() zero-terminates, which uses space.\n+ tunnelState->connectRespBuf->init(SQUID_TCP_SO_RCVBUF, 2*SQUID_TCP_SO_RCVBUF);\n+ tunnelState->readConnectResponse();\n+\n+ assert(tunnelState->waitingForConnectExchange());\n \n AsyncCall::Pointer timeoutCall = commCbCall(5, 4, \"tunnelTimeout\",\n CommTimeoutCbPtrFun(tunnelTimeout, tunnelState));\n@@ -782,6 +990,8 @@ TunnelStateData::operator new (size_t)\n {\n CBDATA_INIT_TYPE(TunnelStateData);\n TunnelStateData *result = cbdataAlloc(TunnelStateData);\n+ result->connectReqWriting = false;\n+ result->connectRespBuf = NULL;\n return result;\n }\n \n@@ -789,6 +999,7 @@ void\n TunnelStateData::operator delete (void *address)\n {\n TunnelStateData *t = static_cast(address);\n+ delete t->connectRespBuf;\n cbdataFree(t);\n }"}], "metadata": {"id": "squid-5473-SQUID_2015_2_port.patch", "cve_id": "CVE-2015-3455", "package": "squid", "tier": "adapted", "has_source_context": false, "license": "GPL-2.0-or-later"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-6250\n\nInteger overflow in the ISO9660 writer in libarchive before 3.2.1 allows remote attackers to cause a denial of service (application crash) or execute arbitrary code via vectors related to verifying filename lengths when writing an ISO9660 archive, which trigger a buffer overflow.\n\n## Package\nlibarchive\n\n## Files to modify\n- libarchive/archive_read_support_format_iso9660.c\n\n## Upstream Fix\n```diff\ncommit 3ad08e01b4d253c66ae56414886089684155af22\nAuthor: Tim Kientzle \nDate: Sun Jun 19 14:34:37 2016 -0700\n\n Issue 717: Fix integer overflow when computing location of volume descriptor\n \n The multiplication here defaulted to 'int' but calculations\n of file positions should always use int64_t. A simple cast\n suffices to fix this since the base location is always 32 bits\n for ISO, so multiplying by the sector size will never overflow\n a 64-bit integer.\n\ndiff --git a/libarchive/archive_read_support_format_iso9660.c b/libarchive/archive_read_support_format_iso9660.c\nindex 6934cee..f41ba38 100644\n--- a/libarchive/archive_read_support_format_iso9660.c\n+++ b/libarchive/archive_read_support_format_iso9660.c\n@@ -1091,7 +1091,7 @@ choose_volume(struct archive_read *a, struct iso9660 *iso9660)\n \t\t/* This condition is unlikely; by way of caution. */\n \t\tvd = &(iso9660->joliet);\n \n-\tskipsize = LOGICAL_BLOCK_SIZE * vd->location;\n+\tskipsize = LOGICAL_BLOCK_SIZE * (int64_t)vd->location;\n \tskipsize = __archive_read_consume(a, skipsize);\n \tif (skipsize < 0)\n \t\treturn ((int)skipsize);\n@@ -1129,7 +1129,7 @@ choose_volume(struct archive_read *a, struct iso9660 *iso9660)\n \t && iso9660->seenJoliet) {\n \t\t/* Switch reading data from primary to joliet. */\n \t\tvd = &(iso9660->joliet);\n-\t\tskipsize = LOGICAL_BLOCK_SIZE * vd->location;\n+\t\tskipsize = LOGICAL_BLOCK_SIZE * (int64_t)vd->location;\n \t\tskipsize -= iso9660->current_position;\n \t\tskipsize = __archive_read_consume(a, skipsize);\n \t\tif (skipsize < 0)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "commit 3ad08e01b4d253c66ae56414886089684155af22\nAuthor: Tim Kientzle \nDate: Sun Jun 19 14:34:37 2016 -0700\n\n Issue 717: Fix integer overflow when computing location of volume descriptor\n \n The multiplication here defaulted to 'int' but calculations\n of file positions should always use int64_t. A simple cast\n suffices to fix this since the base location is always 32 bits\n for ISO, so multiplying by the sector size will never overflow\n a 64-bit integer.\n\ndiff --git a/libarchive/archive_read_support_format_iso9660.c b/libarchive/archive_read_support_format_iso9660.c\nindex 6934cee..f41ba38 100644\n--- a/libarchive/archive_read_support_format_iso9660.c\n+++ b/libarchive/archive_read_support_format_iso9660.c\n@@ -1091,7 +1091,7 @@ choose_volume(struct archive_read *a, struct iso9660 *iso9660)\n \t\t/* This condition is unlikely; by way of caution. */\n \t\tvd = &(iso9660->joliet);\n \n-\tskipsize = LOGICAL_BLOCK_SIZE * vd->location;\n+\tskipsize = LOGICAL_BLOCK_SIZE * (int64_t)vd->location;\n \tskipsize = __archive_read_consume(a, skipsize);\n \tif (skipsize < 0)\n \t\treturn ((int)skipsize);\n@@ -1129,7 +1129,7 @@ choose_volume(struct archive_read *a, struct iso9660 *iso9660)\n \t && iso9660->seenJoliet) {\n \t\t/* Switch reading data from primary to joliet. */\n \t\tvd = &(iso9660->joliet);\n-\t\tskipsize = LOGICAL_BLOCK_SIZE * vd->location;\n+\t\tskipsize = LOGICAL_BLOCK_SIZE * (int64_t)vd->location;\n \t\tskipsize -= iso9660->current_position;\n \t\tskipsize = __archive_read_consume(a, skipsize);\n \t\tif (skipsize < 0)"}], "metadata": {"id": "libarchive-5942-CVE-2016-5844.patch", "cve_id": "CVE-2016-6250", "package": "libarchive", "tier": "identical", "has_source_context": false, "license": "BSD-2-Clause"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2024-2466\n\nlibcurl did not check the server certificate of TLS connections done to a host specified as an IP address, when built to use mbedTLS. libcurl would wrongly avoid using the set hostname function when the specified hostname was given as an IP address, therefore completely skipping the certificate check. This affects all uses of TLS protocols (HTTPS, FTPS, IMAPS, POPS3, SMTPS, etc).\n\nSeverity: MEDIUM\nCVSS Score: 6.5\n\n## Package\ncurl\n\n## Files to modify\n- lib/vtls/mbedtls.c\n\n## Target Source Code\n\n### lib/vtls/mbedtls.c\n\n#### mbed_connect_step1() [lines 322-714]\n```c\n}\n\nstatic CURLcode\nmbed_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data)\n{\n struct ssl_connect_data *connssl = cf->ctx;\n struct mbed_ssl_backend_data *backend =\n (struct mbed_ssl_backend_data *)connssl->backend;\n struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf);\n const struct curl_blob *ca_info_blob = conn_config->ca_info_blob;\n struct ssl_config_data *ssl_config = Curl_ssl_cf_get_config(cf, data);\n const char * const ssl_cafile =\n /* CURLOPT_CAINFO_BLOB overrides CURLOPT_CAINFO */\n (ca_info_blob ? NULL : conn_config->CAfile);\n const bool verifypeer = conn_config->verifypeer;\n const char * const ssl_capath = conn_config->CApath;\n char * const ssl_cert = ssl_config->primary.clientcert;\n const struct curl_blob *ssl_cert_blob = ssl_config->primary.cert_blob;\n const char * const ssl_crlfile = ssl_config->primary.CRLfile;\n const char *hostname = connssl->peer.hostname;\n int ret = -1;\n char errorbuf[128];\n\n DEBUGASSERT(backend);\n\n if((conn_config->version == CURL_SSLVERSION_SSLv2) ||\n (conn_config->version == CURL_SSLVERSION_SSLv3)) {\n failf(data, \"Not supported SSL version\");\n return CURLE_NOT_BUILT_IN;\n }\n\n#ifdef THREADING_SUPPORT\n entropy_init_mutex(&ts_entropy);\n mbedtls_ctr_drbg_init(&backend->ctr_drbg);\n\n ret = mbedtls_ctr_drbg_seed(&backend->ctr_drbg, entropy_func_mutex,\n &ts_entropy, NULL, 0);\n if(ret) {\n mbedtls_strerror(ret, errorbuf, sizeof(errorbuf));\n failf(data, \"mbedtls_ctr_drbg_seed returned (-0x%04X) %s\",\n/* ... 283 lines omitted ... */\n &backend->cacert,\n#ifdef MBEDTLS_X509_CRL_PARSE_C\n &backend->crl);\n#else\n NULL);\n#endif\n\n if(ssl_config->key || ssl_config->key_blob) {\n mbedtls_ssl_conf_own_cert(&backend->config,\n &backend->clicert, &backend->pk);\n }\n\n if(connssl->peer.sni) {\n if(mbedtls_ssl_set_hostname(&backend->ssl, connssl->peer.sni)) {\n /* mbedtls_ssl_set_hostname() sets the name to use in CN/SAN checks and\n the name to set in the SNI extension. So even if curl connects to a\n host specified as an IP address, this function must be used. */\n failf(data, \"Failed to set SNI\");\n return CURLE_SSL_CONNECT_ERROR;\n }\n }\n\n#ifdef HAS_ALPN\n if(connssl->alpn) {\n struct alpn_proto_buf proto;\n size_t i;\n\n for(i = 0; i < connssl->alpn->count; ++i) {\n backend->protocols[i] = connssl->alpn->entries[i];\n }\n /* this function doesn't clone the protocols array, which is why we need\n to keep it around */\n if(mbedtls_ssl_conf_alpn_protocols(&backend->config,\n &backend->protocols[0])) {\n/* ... 16 lines omitted ... */\n */\n mbedtls_debug_set_threshold(4);\n#endif\n\n /* give application a chance to interfere with mbedTLS set up. */\n if(data->set.ssl.fsslctx) {\n ret = (*data->set.ssl.fsslctx)(data, &backend->config,\n data->set.ssl.fsslctxp);\n if(ret) {\n failf(data, \"error signaled by ssl ctx callback\");\n return ret;\n }\n }\n\n connssl->connecting_state = ssl_connect_2;\n\n return CURLE_OK;\n}\n\nstatic CURLcode\n```\n\n\n## Upstream Fix\n```diff\nFrom 3d0fd382a29b95561b90b7ea3e7eb04dfdd43538 Mon Sep 17 00:00:00 2001\nFrom: Stefan Eissing \nDate: Fri, 15 Mar 2024 10:10:13 +0100\nSubject: [PATCH] mbedtls: fix pytest for newer versions\n\nFix the expectations in pytest for newer versions of mbedtls\n\nCloses #13132\n---\n lib/vtls/mbedtls.c | 15 +++++++--------\n tests/http/test_10_proxy.py | 8 ++++++--\n tests/http/testenv/env.py | 14 +++++++++++---\n 3 files changed, 24 insertions(+), 13 deletions(-)\n\ndiff --git a/lib/vtls/mbedtls.c b/lib/vtls/mbedtls.c\nindex 3fefb612bd1a..5f07e78ef7cf 100644\n--- a/lib/vtls/mbedtls.c\n+++ b/lib/vtls/mbedtls.c\n@@ -687,14 +687,13 @@ mbed_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data)\n &backend->clicert, &backend->pk);\n }\n \n- if(connssl->peer.sni) {\n- if(mbedtls_ssl_set_hostname(&backend->ssl, connssl->peer.sni)) {\n- /* mbedtls_ssl_set_hostname() sets the name to use in CN/SAN checks and\n- the name to set in the SNI extension. So even if curl connects to a\n- host specified as an IP address, this function must be used. */\n- failf(data, \"Failed to set SNI\");\n- return CURLE_SSL_CONNECT_ERROR;\n- }\n+ if(mbedtls_ssl_set_hostname(&backend->ssl, connssl->peer.sni?\n+ connssl->peer.sni : connssl->peer.hostname)) {\n+ /* mbedtls_ssl_set_hostname() sets the name to use in CN/SAN checks and\n+ the name to set in the SNI extension. So even if curl connects to a\n+ host specified as an IP address, this function must be used. */\n+ failf(data, \"Failed to set SNI\");\n+ return CURLE_SSL_CONNECT_ERROR;\n }\n \n #ifdef HAS_ALPN\ndiff --git a/tests/http/test_10_proxy.py b/tests/http/test_10_proxy.py\nindex ad3a5990f1cc..c191432fb045 100644\n--- a/tests/http/test_10_proxy.py\n+++ b/tests/http/test_10_proxy.py\n@@ -362,6 +362,10 @@ def test_10_14_proxys_ip_addr(self, env: Env, httpd, proto, repeat):\n xargs = curl.get_proxy_args(proto=proto, use_ip=True)\n r = curl.http_download(urls=[url], alpn_proto='http/1.1', with_stats=True,\n extra_args=xargs)\n- r.check_response(count=1, http_status=200,\n- protocol='HTTP/2' if proto == 'h2' else 'HTTP/1.1')\n+ if env.curl_uses_lib('mbedtls') and \\\n+ not env.curl_lib_version_at_least('mbedtls', '3.5.0'):\n+ r.check_exit_code(60) # CURLE_PEER_FAILED_VERIFICATION\n+ else:\n+ r.check_response(count=1, http_status=200,\n+ protocol='HTTP/2' if proto == 'h2' else 'HTTP/1.1')\n \ndiff --git a/tests/http/testenv/env.py b/tests/http/testenv/env.py\nindex 29f9726f7bd6..a207059dcd57 100644\n--- a/tests/http/testenv/env.py\n+++ b/tests/http/testenv/env.py\n@@ -185,15 +185,15 @@ def httpd_version(self):\n log.error(f'{self.apxs} failed to run: {e}')\n return self._httpd_version\n \n- def _versiontuple(self, v):\n+ def versiontuple(self, v):\n v = re.sub(r'(\\d+\\.\\d+(\\.\\d+)?)(-\\S+)?', r'\\1', v)\n return tuple(map(int, v.split('.')))\n \n def httpd_is_at_least(self, minv):\n if self.httpd_version is None:\n return False\n- hv = self._versiontuple(self.httpd_version)\n- return hv >= self._versiontuple(minv)\n+ hv = self.versiontuple(self.httpd_version)\n+ return hv >= self.versiontuple(minv)\n \n def is_complete(self) -> bool:\n return os.path.isfile(self.httpd) and \\\n@@ -275,6 +275,14 @@ def curl_lib_version(libname: str) -> str:\n return lversion[len(prefix):]\n return 'unknown'\n \n+ @staticmethod\n+ def curl_lib_version_at_least(libname: str, min_version) -> str:\n+ lversion = Env.curl_lib_version(libname)\n+ if lversion != 'unknown':\n+ return Env.CONFIG.versiontuple(min_version) <= \\\n+ Env.CONFIG.versiontuple(lversion)\n+ return False\n+\n @staticmethod\n def curl_os() -> str:\n return Env.CONFIG.curl_props['os']\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From 3d0fd382a29b95561b90b7ea3e7eb04dfdd43538 Mon Sep 17 00:00:00 2001\nFrom: Stefan Eissing \nDate: Fri, 15 Mar 2024 10:10:13 +0100\nSubject: [PATCH] mbedtls: fix pytest for newer versions\n\nFix the expectations in pytest for newer versions of mbedtls\n\nCloses #13132\n---\n lib/vtls/mbedtls.c | 15 +++++++--------\n tests/http/test_10_proxy.py | 8 ++++++--\n tests/http/testenv/env.py | 14 +++++++++++---\n 3 files changed, 24 insertions(+), 13 deletions(-)\n\nIndex: curl-8.6.0/lib/vtls/mbedtls.c\n===================================================================\n--- curl-8.6.0.orig/lib/vtls/mbedtls.c\n+++ curl-8.6.0/lib/vtls/mbedtls.c\n@@ -654,14 +654,13 @@ mbed_connect_step1(struct Curl_cfilter *\n &backend->clicert, &backend->pk);\n }\n \n- if(connssl->peer.sni) {\n- if(mbedtls_ssl_set_hostname(&backend->ssl, connssl->peer.sni)) {\n- /* mbedtls_ssl_set_hostname() sets the name to use in CN/SAN checks and\n- the name to set in the SNI extension. So even if curl connects to a\n- host specified as an IP address, this function must be used. */\n- failf(data, \"Failed to set SNI\");\n- return CURLE_SSL_CONNECT_ERROR;\n- }\n+ if(mbedtls_ssl_set_hostname(&backend->ssl, connssl->peer.sni?\n+ connssl->peer.sni : connssl->peer.hostname)) {\n+ /* mbedtls_ssl_set_hostname() sets the name to use in CN/SAN checks and\n+ the name to set in the SNI extension. So even if curl connects to a\n+ host specified as an IP address, this function must be used. */\n+ failf(data, \"Failed to set SNI\");\n+ return CURLE_SSL_CONNECT_ERROR;\n }\n \n #ifdef HAS_ALPN"}], "metadata": {"id": "curl-CVE-2024-2466-curl-CVE-2024-2466", "cve_id": "CVE-2024-2466", "package": "curl", "upstream_enriched": true, "upstream_commit": "3d0fd382a29b95561b90b7ea3e7eb04dfdd43538", "upstream_repo": "curl/curl", "tier": "adapted", "has_source_context": true, "context_tokens_est": 829, "context_files": 1, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-6250\n\nInteger overflow in the ISO9660 writer in libarchive before 3.2.1 allows remote attackers to cause a denial of service (application crash) or execute arbitrary code via vectors related to verifying filename lengths when writing an ISO9660 archive, which trigger a buffer overflow.\n\n## Package\nlibarchive\n\n## Files to modify\n- libarchive/test/test_read_format_zip_msdos.c\n- libarchive/test/test_read_filter_compress.c\n- libarchive/archive_read_support_filter_compress.c\n- libarchive-3.1.2.orig/libarchive/archive_read_support_filter_compress.c\n\n## Target Source Code\n\n### libarchive/archive_read_support_filter_compress.c\n\n#### compress_bidder_bid() [lines 176-205]\n```c\n * This logic returns zero if any part of the signature fails.\n */\nstatic int\ncompress_bidder_bid(struct archive_read_filter_bidder *self,\n struct archive_read_filter *filter)\n{\n\tconst unsigned char *buffer;\n\tssize_t avail;\n\tint bits_checked;\n\n\t(void)self; /* UNUSED */\n\n\tbuffer = __archive_read_filter_ahead(filter, 2, &avail);\n\n\tif (buffer == NULL)\n\t\treturn (0);\n\n\tbits_checked = 0;\n\tif (buffer[0] != 0x1F || buffer[1] != 0x9D)\n\t\treturn (0);\n\tbits_checked += 16;\n\n\t/*\n\t * TODO: Verify more.\n\t */\n\n\treturn (bits_checked);\n}\n\n/*\n```\n\n#### compress_bidder_init() [lines 206-264]\n```c\n * Setup the callbacks.\n */\nstatic int\ncompress_bidder_init(struct archive_read_filter *self)\n{\n\tstruct private_data *state;\n\tstatic const size_t out_block_size = 64 * 1024;\n\tvoid *out_block;\n\tint code;\n\n\tself->code = ARCHIVE_FILTER_COMPRESS;\n\tself->name = \"compress (.Z)\";\n\n\tstate = (struct private_data *)calloc(sizeof(*state), 1);\n\tout_block = malloc(out_block_size);\n\tif (state == NULL || out_block == NULL) {\n\t\tfree(out_block);\n\t\tfree(state);\n\t\tarchive_set_error(&self->archive->archive, ENOMEM,\n\t\t \"Can't allocate data for %s decompression\",\n\t\t self->name);\n\t\treturn (ARCHIVE_FATAL);\n\t}\n\n\tself->data = state;\n\tstate->out_block_size = out_block_size;\n\tstate->out_block = out_block;\n\tself->read = compress_filter_read;\n\tself->skip = NULL; /* not supported */\n\tself->close = compress_filter_close;\n\n\t/* XXX MOVE THE FOLLOWING OUT OF INIT() XXX */\n\n\t(void)getbits(self, 8); /* Skip first signature byte. */\n\t(void)getbits(self, 8); /* Skip second signature byte. */\n\n\tcode = getbits(self, 8);\n\tstate->maxcode_bits = code & 0x1f;\n\tstate->maxcode = (1 << state->maxcode_bits);\n\tstate->use_reset_code = code & 0x80;\n\n\t/* Initialize decompressor. */\n\tstate->free_ent = 256;\n\tstate->stackp = state->stack;\n\tif (state->use_reset_code)\n\t\tstate->free_ent++;\n\tstate->bits = 9;\n\tstate->section_end_code = (1<bits) - 1;\n\tstate->oldcode = -1;\n\tfor (code = 255; code >= 0; code--) {\n\t\tstate->prefix[code] = 0;\n\t\tstate->suffix[code] = code;\n\t}\n\tnext_code(self);\n\n\treturn (ARCHIVE_OK);\n}\n\n/*\n```\n\n### Makefile.am\n\n#### region() [lines 325-411]\n```c\n\tlibarchive/test/test_archive_string_conversion.c\t\\\n\tlibarchive/test/test_archive_write_add_filter_by_name.c\t\\\n\tlibarchive/test/test_archive_write_set_filter_option.c\t\\\n\tlibarchive/test/test_archive_write_set_format_by_name.c\t\\\n\tlibarchive/test/test_archive_write_set_format_option.c\t\\\n\tlibarchive/test/test_archive_write_set_option.c\t\t\\\n\tlibarchive/test/test_archive_write_set_options.c\t\\\n\tlibarchive/test/test_bad_fd.c\t\t\t\t\\\n\tlibarchive/test/test_compat_bzip2.c\t\t\t\\\n\tlibarchive/test/test_compat_cpio.c\t\t\t\\\n\tlibarchive/test/test_compat_gtar.c\t\t\t\\\n\tlibarchive/test/test_compat_gzip.c\t\t\t\\\n\tlibarchive/test/test_compat_lzip.c\t\t\t\\\n\tlibarchive/test/test_compat_lzma.c\t\t\t\\\n\tlibarchive/test/test_compat_lzop.c\t\t\t\\\n\tlibarchive/test/test_compat_mac.c\t\t\t\\\n\tlibarchive/test/test_compat_pax_libarchive_2x.c\t\t\\\n\tlibarchive/test/test_compat_solaris_tar_acl.c\t\t\\\n\tlibarchive/test/test_compat_solaris_pax_sparse.c\t\\\n\tlibarchive/test/test_compat_tar_hardlink.c\t\t\\\n\tlibarchive/test/test_compat_uudecode.c\t\t\t\\\n\tlibarchive/test/test_compat_xz.c\t\t\t\\\n\tlibarchive/test/test_compat_zip.c\t\t\t\\\n\tlibarchive/test/test_empty_write.c\t\t\t\\\n\tlibarchive/test/test_entry.c\t\t\t\t\\\n\tlibarchive/test/test_entry_strmode.c\t\t\t\\\n\tlibarchive/test/test_extattr_freebsd.c\t\t\t\\\n\tlibarchive/test/test_filter_count.c\t\t\t\\\n\tlibarchive/test/test_fuzz.c\t\t\t\t\\\n\tlibarchive/test/test_gnutar_filename_encoding.c\t\t\\\n\tlibarchive/test/test_link_resolver.c\t\t\t\\\n\tlibarchive/test/test_open_failure.c\t\t\t\\\n\tlibarchive/test/test_open_fd.c\t\t\t\t\\\n\tlibarchive/test/test_open_file.c\t\t\t\\\n\tlibarchive/test/test_open_filename.c\t\t\t\\\n\tlibarchive/test/test_pax_filename_encoding.c\t\t\\\n\tlibarchive/test/test_read_data_large.c\t\t\t\\\n\tlibarchive/test/test_read_disk.c\t\t\t\\\n\tlibarchive/test/test_read_disk_directory_traversals.c\t\\\n\tlibarchive/test/test_read_disk_entry_from_file.c\t\\\n\tlibarchive/test/test_read_extract.c\t\t\t\\\n\tlibarchive/test/test_read_file_nonexistent.c\t\t\\\n\tlibarchive/test/test_read_filter_grzip.c\t\t\\\n\tlibarchive/test/test_read_filter_lrzip.c\t\t\\\n\tlibarchive/test/test_read_filter_lzop.c\t\t\t\\\n\tlibarchive/test/test_read_filter_lzop_multiple_parts.c\t\\\n\tliba\n/* ... truncated ... */\n```\n\n### libarchive/test/CMakeLists.txt\n\n#### IF() [lines 40-126]\n```c\n test_archive_string_conversion.c\n test_archive_write_add_filter_by_name.c\n test_archive_write_set_filter_option.c\n test_archive_write_set_format_by_name.c\n test_archive_write_set_format_option.c\n test_archive_write_set_option.c\n test_archive_write_set_options.c\n test_bad_fd.c\n test_compat_bzip2.c\n test_compat_cpio.c\n test_compat_gtar.c\n test_compat_gzip.c\n test_compat_lzip.c\n test_compat_lzma.c\n test_compat_lzop.c\n test_compat_mac.c\n test_compat_pax_libarchive_2x.c\n test_compat_solaris_tar_acl.c\n test_compat_solaris_pax_sparse.c\n test_compat_tar_hardlink.c\n test_compat_uudecode.c\n test_compat_xz.c\n test_compat_zip.c\n test_empty_write.c\n test_entry.c\n test_entry_strmode.c\n test_extattr_freebsd.c\n test_filter_count.c\n test_fuzz.c\n test_gnutar_filename_encoding.c\n test_link_resolver.c\n test_open_failure.c\n test_open_fd.c\n test_open_file.c\n test_open_filename.c\n test_pax_filename_encoding.c\n test_read_data_large.c\n test_read_disk.c\n test_read_disk_directory_traversals.c\n test_read_disk_entry_from_file.c\n test_read_extract.c\n test_read_file_nonexistent.c\n test_read_filter_grzip.c\n test_read_filter_lrzip.c\n test_read_filter_lzop.c\n test_read_filter_lzop_multiple_parts.c\n test_read_filter_program.c\n test_read_filter_program_signature.c\n test_read_filter_uudecode.c\n test_read_format_7zip.c\n test_read_format_ar.c\n test_read_format_cab.c\n test_read_format_cab_filename.c\n test_read_format_cpio_afio.c\n test_read_format_cpio_bin.c\n test_read_format_cpio_bin_Z.c\n test_read_format_cpio_bin_be.c\n test_read_format_cpio_bin_bz2.c\n test_read_format_cpio_bin_gz.c\n test_read_format_cpio_bin_lzip.c\n test_read_format_cpio_bin_lzma.c\n test_read_format_cpio_bin_xz.c\n test_read_format_cpio_filename.c\n test_read_format_cpio_odc.c\n test_read_format_cpio_svr4_bzip2_rpm.c\n test_read_format_cpio_svr4_gzip.c\n test_read_format_cpio_svr4_gzip_rpm.c\n test_read_format_cpio_svr4c_Z.c\n \n/* ... truncated ... */\n```\n\n\n### Type definitions\n\n```c\n/* from archive_private.h */\nstruct archive {\n\t/*\n\t * The magic/state values are used to sanity-check the\n\t * client's usage. If an API function is called at a\n\t * ridiculous time, or the client passes us an invalid\n\t * pointer, these values allow me to catch that.\n\t */\n\tunsigned int\tmagic;\n\tunsigned int\tstate;\n\n\t/*\n\t * Some public API functions depend on the \"real\" type of the\n\t * archive object.\n\t */\n\tstruct archive_vtable *vtable;\n\n\tint\t\t archive_format;\n\tconst char\t *archive_format_name;\n\n\tint\t compression_code;\t/* Currently active compression. */\n\tconst char *compression_name;\n\n\t/* Number of file entries processed. */\n\tint\t\t file_count;\n\n\tint\t\t archive_error_number;\n\tconst char\t *error;\n\tstruct archive_string\terror_string;\n\n\tchar *current_code;\n\tunsigned current_codepage; /* Current ACP(ANSI CodePage). */\n\tunsigned current_oemcp; /* Current OEMCP(OEM CodePage). */\n\tstruct archive_string_conv *sconv;\n};\n```\n\n\n## Upstream Fix\n```diff\ncommit f0b1dbbc325a2d922015eee402b72edd422cb9ea\nAuthor: Tim Kientzle \nDate: Sat Aug 8 21:47:43 2015 -0700\n\n Issue 547: problems with compress bidder\n \n The code previously was not very careful about verifying the\n compression parameters. This led to cases where it failed to\n reject invalid compressed data at the beginning. The invalid\n left shift was one symptom of this.\n \n The code is now more careful: It verifies that the compression\n parameter byte exists and verifies that the maximum code size\n is <= 16 bits.\n \n This also includes some new tests to verify that truncated or\n otherwise invalid compressed data is rejected.\n\nIndex: libarchive-3.1.2/libarchive/archive_read_support_filter_compress.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_read_support_filter_compress.c\n+++ libarchive-3.1.2/libarchive/archive_read_support_filter_compress.c\n@@ -185,19 +185,22 @@ compress_bidder_bid(struct archive_read_\n \n \t(void)self; /* UNUSED */\n \n-\tbuffer = __archive_read_filter_ahead(filter, 2, &avail);\n+\t/* Shortest valid compress file is 3 bytes. */\n+\tbuffer = __archive_read_filter_ahead(filter, 3, &avail);\n \n \tif (buffer == NULL)\n \t\treturn (0);\n \n \tbits_checked = 0;\n+\t/* First two bytes are the magic value */\n \tif (buffer[0] != 0x1F || buffer[1] != 0x9D)\n \t\treturn (0);\n-\tbits_checked += 16;\n-\n-\t/*\n-\t * TODO: Verify more.\n-\t */\n+\t/* Third byte holds compression parameters. */\n+\tif (buffer[2] & 0x20) /* Reserved bit, must be zero. */\n+\t\treturn (0);\n+\tif (buffer[2] & 0x40) /* Reserved bit, must be zero. */\n+\t\treturn (0);\n+\tbits_checked += 18;\n \n \treturn (bits_checked);\n }\n@@ -239,7 +242,13 @@ compress_bidder_init(struct archive_read\n \t(void)getbits(self, 8); /* Skip first signature byte. */\n \t(void)getbits(self, 8); /* Skip second signature byte. */\n \n+\t/* Get compression parameters. */\n \tcode = getbits(self, 8);\n+\tif ((code & 0x1f) > 16) {\n+\t\tarchive_set_error(&self->archive->archive, -1,\n+\t\t \"Invalid compressed data\");\n+\t\treturn (ARCHIVE_FATAL);\n+\t}\n \tstate->maxcode_bits = code & 0x1f;\n \tstate->maxcode = (1 << state->maxcode_bits);\n \tstate->use_reset_code = code & 0x80;\nIndex: libarchive-3.1.2/libarchive/test/test_read_filter_compress.c\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_filter_compress.c\n@@ -0,0 +1,80 @@\n+/*-\n+ * Copyright (c) 2003-2008 Tim Kientzle\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ * 1. Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in the\n+ * documentation and/or other materials provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR\n+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,\n+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+#include \"test.h\"\n+\n+DEFINE_TEST(test_read_filter_compress_truncated)\n+{\n+\tconst char data[] = {0x1f, 0x9d};\n+\tstruct archive *a;\n+\n+\tassert((a = archive_read_new()) != NULL);\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_compress(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));\n+\tassertEqualIntA(a, ARCHIVE_FATAL,\n+\t archive_read_open_memory(a, data, sizeof(data)));\n+\n+\tassertEqualInt(ARCHIVE_OK, archive_read_close(a));\n+\tassertEqualInt(ARCHIVE_OK, archive_read_free(a));\n+}\n+\n+\n+DEFINE_TEST(test_read_filter_compress_empty2)\n+{\n+\tconst char data[] = {0x1f, 0x9d, 0x10};\n+\tstruct archive *a;\n+\tstruct archive_entry *ae;\n+\n+\tassert((a = archive_read_new()) != NULL);\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_compress(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));\n+\tassertEqualIntA(a, ARCHIVE_OK,\n+\t archive_read_open_memory(a, data, sizeof(data)));\n+\n+\tassertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));\n+\n+\t/* Verify that the format detection worked. */\n+\tassertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);\n+\tassertEqualString(archive_filter_name(a, 0), \"compress (.Z)\");\n+\tassertEqualInt(archive_format(a), ARCHIVE_FORMAT_EMPTY);\n+\n+\tassertEqualInt(ARCHIVE_OK, archive_read_close(a));\n+\tassertEqualInt(ARCHIVE_OK, archive_read_free(a));\n+}\n+\n+\n+DEFINE_TEST(test_read_filter_compress_invalid)\n+{\n+\tconst char data[] = {0x1f, 0x9d, 0x11};\n+\tstruct archive *a;\n+\n+\tassert((a = archive_read_new()) != NULL);\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_compress(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));\n+\tassertEqualIntA(a, ARCHIVE_FATAL,\n+\t archive_read_open_memory(a, data, sizeof(data)));\n+\n+\tassertEqualInt(ARCHIVE_OK, archive_read_close(a));\n+\tassertEqualInt(ARCHIVE_OK, archive_read_free(a));\n+}\nIndex: libarchive-3.1.2/Makefile.am\n===================================================================\n--- libarchive-3.1.2.orig/Makefile.am\n+++ libarchive-3.1.2/Makefile.am\n@@ -364,6 +364,7 @@ libarchive_test_SOURCES=\t\t\t\t\t\\\n \tlibarchive/test/test_read_disk_entry_from_file.c\t\\\n \tlibarchive/test/test_read_extract.c\t\t\t\\\n \tlibarchive/test/test_read_file_nonexistent.c\t\t\\\n+\tlibarchive/test/test_read_filter_compress.c\t\t\\\n \tlibarchive/test/test_read_filter_grzip.c\t\t\\\n \tlibarchive/test/test_read_filter_lrzip.c\t\t\\\n \tlibarchive/test/test_read_filter_lzop.c\t\t\t\\\n@@ -427,6 +428,7 @@ libarchive_test_SOURCES=\t\t\t\t\t\\\n \tlibarchive/test/test_read_format_zip_comment_stored.c\t\\\n \tlibarchive/test/test_read_format_zip_filename.c\t\t\\\n \tlibarchive/test/test_read_format_zip_mac_metadata.c\t\\\n+\tlibarchive/test/test_read_format_zip_msdos.c\t\t\\\n \tlibarchive/test/test_read_format_zip_sfx.c\t\t\\\n \tlibarchive/test/test_read_large.c\t\t\t\\\n \tlibarchive/test/test_read_pax_truncated.c\t\t\\\nIndex: libarchive-3.1.2/libarchive/test/CMakeLists.txt\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/test/CMakeLists.txt\n+++ libarchive-3.1.2/libarchive/test/CMakeLists.txt\n@@ -79,6 +79,7 @@ IF(ENABLE_TEST)\n test_read_disk_entry_from_file.c\n test_read_extract.c\n test_read_file_nonexistent.c\n+ test_read_filter_compress.c\n test_read_filter_grzip.c\n test_read_filter_lrzip.c\n test_read_filter_lzop.c\n@@ -142,6 +143,7 @@ IF(ENABLE_TEST)\n test_read_format_zip_comment_stored.c\n test_read_format_zip_filename.c\n test_read_format_zip_mac_metadata.c\n+ test_read_format_zip_msdos.c\n test_read_format_zip_sfx.c\n test_read_large.c\n test_read_pax_truncated.c\n@@ -154,6 +156,7 @@ IF(ENABLE_TEST)\n test_tar_large.c\n test_ustar_filenames.c\n test_ustar_filename_encoding.c\n+ test_warn_missing_hardlink_target.c\n test_write_disk.c\n test_write_disk_appledouble.c\n test_write_disk_failures.c\nIndex: libarchive-3.1.2/libarchive/test/test_read_format_zip_msdos.c\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_format_zip_msdos.c\n@@ -0,0 +1,63 @@\n+/*-\n+ * Copyright (c) 2003-2007 Tim Kientzle\n+ * Copyright (c) 2011 Michihiro NAKAJIMA\n+\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "commit f0b1dbbc325a2d922015eee402b72edd422cb9ea\nAuthor: Tim Kientzle \nDate: Sat Aug 8 21:47:43 2015 -0700\n\n Issue 547: problems with compress bidder\n \n The code previously was not very careful about verifying the\n compression parameters. This led to cases where it failed to\n reject invalid compressed data at the beginning. The invalid\n left shift was one symptom of this.\n \n The code is now more careful: It verifies that the compression\n parameter byte exists and verifies that the maximum code size\n is <= 16 bits.\n \n This also includes some new tests to verify that truncated or\n otherwise invalid compressed data is rejected.\n\nIndex: libarchive-3.1.2/libarchive/archive_read_support_filter_compress.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_read_support_filter_compress.c\n+++ libarchive-3.1.2/libarchive/archive_read_support_filter_compress.c\n@@ -185,19 +185,22 @@ compress_bidder_bid(struct archive_read_\n \n \t(void)self; /* UNUSED */\n \n-\tbuffer = __archive_read_filter_ahead(filter, 2, &avail);\n+\t/* Shortest valid compress file is 3 bytes. */\n+\tbuffer = __archive_read_filter_ahead(filter, 3, &avail);\n \n \tif (buffer == NULL)\n \t\treturn (0);\n \n \tbits_checked = 0;\n+\t/* First two bytes are the magic value */\n \tif (buffer[0] != 0x1F || buffer[1] != 0x9D)\n \t\treturn (0);\n-\tbits_checked += 16;\n-\n-\t/*\n-\t * TODO: Verify more.\n-\t */\n+\t/* Third byte holds compression parameters. */\n+\tif (buffer[2] & 0x20) /* Reserved bit, must be zero. */\n+\t\treturn (0);\n+\tif (buffer[2] & 0x40) /* Reserved bit, must be zero. */\n+\t\treturn (0);\n+\tbits_checked += 18;\n \n \treturn (bits_checked);\n }\n@@ -239,7 +242,13 @@ compress_bidder_init(struct archive_read\n \t(void)getbits(self, 8); /* Skip first signature byte. */\n \t(void)getbits(self, 8); /* Skip second signature byte. */\n \n+\t/* Get compression parameters. */\n \tcode = getbits(self, 8);\n+\tif ((code & 0x1f) > 16) {\n+\t\tarchive_set_error(&self->archive->archive, -1,\n+\t\t \"Invalid compressed data\");\n+\t\treturn (ARCHIVE_FATAL);\n+\t}\n \tstate->maxcode_bits = code & 0x1f;\n \tstate->maxcode = (1 << state->maxcode_bits);\n \tstate->use_reset_code = code & 0x80;\nIndex: libarchive-3.1.2/libarchive/test/test_read_filter_compress.c\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_filter_compress.c\n@@ -0,0 +1,80 @@\n+/*-\n+ * Copyright (c) 2003-2008 Tim Kientzle\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ * 1. Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in the\n+ * documentation and/or other materials provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR\n+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,\n+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+#include \"test.h\"\n+\n+DEFINE_TEST(test_read_filter_compress_truncated)\n+{\n+\tconst char data[] = {0x1f, 0x9d};\n+\tstruct archive *a;\n+\n+\tassert((a = archive_read_new()) != NULL);\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_compress(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));\n+\tassertEqualIntA(a, ARCHIVE_FATAL,\n+\t archive_read_open_memory(a, data, sizeof(data)));\n+\n+\tassertEqualInt(ARCHIVE_OK, archive_read_close(a));\n+\tassertEqualInt(ARCHIVE_OK, archive_read_free(a));\n+}\n+\n+\n+DEFINE_TEST(test_read_filter_compress_empty2)\n+{\n+\tconst char data[] = {0x1f, 0x9d, 0x10};\n+\tstruct archive *a;\n+\tstruct archive_entry *ae;\n+\n+\tassert((a = archive_read_new()) != NULL);\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_compress(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));\n+\tassertEqualIntA(a, ARCHIVE_OK,\n+\t archive_read_open_memory(a, data, sizeof(data)));\n+\n+\tassertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));\n+\n+\t/* Verify that the format detection worked. */\n+\tassertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);\n+\tassertEqualString(archive_filter_name(a, 0), \"compress (.Z)\");\n+\tassertEqualInt(archive_format(a), ARCHIVE_FORMAT_EMPTY);\n+\n+\tassertEqualInt(ARCHIVE_OK, archive_read_close(a));\n+\tassertEqualInt(ARCHIVE_OK, archive_read_free(a));\n+}\n+\n+\n+DEFINE_TEST(test_read_filter_compress_invalid)\n+{\n+\tconst char data[] = {0x1f, 0x9d, 0x11};\n+\tstruct archive *a;\n+\n+\tassert((a = archive_read_new()) != NULL);\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_compress(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));\n+\tassertEqualIntA(a, ARCHIVE_FATAL,\n+\t archive_read_open_memory(a, data, sizeof(data)));\n+\n+\tassertEqualInt(ARCHIVE_OK, archive_read_close(a));\n+\tassertEqualInt(ARCHIVE_OK, archive_read_free(a));\n+}\nIndex: libarchive-3.1.2/Makefile.am\n===================================================================\n--- libarchive-3.1.2.orig/Makefile.am\n+++ libarchive-3.1.2/Makefile.am\n@@ -364,6 +364,7 @@ libarchive_test_SOURCES=\t\t\t\t\t\\\n \tlibarchive/test/test_read_disk_entry_from_file.c\t\\\n \tlibarchive/test/test_read_extract.c\t\t\t\\\n \tlibarchive/test/test_read_file_nonexistent.c\t\t\\\n+\tlibarchive/test/test_read_filter_compress.c\t\t\\\n \tlibarchive/test/test_read_filter_grzip.c\t\t\\\n \tlibarchive/test/test_read_filter_lrzip.c\t\t\\\n \tlibarchive/test/test_read_filter_lzop.c\t\t\t\\\n@@ -427,6 +428,7 @@ libarchive_test_SOURCES=\t\t\t\t\t\\\n \tlibarchive/test/test_read_format_zip_comment_stored.c\t\\\n \tlibarchive/test/test_read_format_zip_filename.c\t\t\\\n \tlibarchive/test/test_read_format_zip_mac_metadata.c\t\\\n+\tlibarchive/test/test_read_format_zip_msdos.c\t\t\\\n \tlibarchive/test/test_read_format_zip_sfx.c\t\t\\\n \tlibarchive/test/test_read_large.c\t\t\t\\\n \tlibarchive/test/test_read_pax_truncated.c\t\t\\\nIndex: libarchive-3.1.2/libarchive/test/CMakeLists.txt\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/test/CMakeLists.txt\n+++ libarchive-3.1.2/libarchive/test/CMakeLists.txt\n@@ -79,6 +79,7 @@ IF(ENABLE_TEST)\n test_read_disk_entry_from_file.c\n test_read_extract.c\n test_read_file_nonexistent.c\n+ test_read_filter_compress.c\n test_read_filter_grzip.c\n test_read_filter_lrzip.c\n test_read_filter_lzop.c\n@@ -142,6 +143,7 @@ IF(ENABLE_TEST)\n test_read_format_zip_comment_stored.c\n test_read_format_zip_filename.c\n test_read_format_zip_mac_metadata.c\n+ test_read_format_zip_msdos.c\n test_read_format_zip_sfx.c\n test_read_large.c\n test_read_pax_truncated.c\n@@ -154,6 +156,7 @@ IF(ENABLE_TEST)\n test_tar_large.c\n test_ustar_filenames.c\n test_ustar_filename_encoding.c\n+ test_warn_missing_hardlink_target.c\n test_write_disk.c\n test_write_disk_appledouble.c\n test_write_disk_failures.c\nIndex: libarchive-3.1.2/libarchive/test/test_read_format_zip_msdos.c\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_format_zip_msdos.c\n@@ -0,0 +1,63 @@\n+/*-\n+ * Copyright (c) 2003-2007 Tim Kientzle\n+ * Copyright (c) 2011 Michihiro NAKAJIMA\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ * 1. Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in the\n+ * documentation and/or other materials provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR\n+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,\n+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+#include \"test.h\"\n+\n+DEFINE_TEST(test_read_format_zip_msdos)\n+{\n+\tconst char *refname = \"test_read_format_zip_msdos.zip\";\n+\tstruct archive *a;\n+\tstruct archive_entry *ae;\n+\n+\textract_reference_file(refname);\n+\n+\t/* Verify with seeking reader. */\n+\tassert((a = archive_read_new()) != NULL);\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 17));\n+\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));\n+\tassertEqualString(\"a/\", archive_entry_pathname(ae));\n+\tassertEqualInt(AE_IFDIR | 0775, archive_entry_mode(ae));\n+\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));\n+\tassertEqualString(\"a/gru\\xCC\\x88n.png\", archive_entry_pathname(ae));\n+\tassertEqualInt(AE_IFREG | 0664, archive_entry_mode(ae));\n+\n+\tassertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));\n+\tassertEqualInt(ARCHIVE_OK, archive_read_free(a));\n+\t\n+\t/* Verify with streaming reader. */\n+#if 0\n+\tp = slurpfile(&s, refname);\n+\tassert((a = archive_read_new()) != NULL);\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, read_open_memory(a, p, s, 31));\n+\tverify_basic(a, 0);\n+#endif\n+}\nIndex: libarchive-3.1.2/libarchive/test/test_read_format_zip_msdos.zip.uu\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_format_zip_msdos.zip.uu\n@@ -0,0 +1,9 @@\n+begin 644 test_read_format_zip_msdos.zip\n+M4$L#!!0``````&9A3D,````````````````\"````82]02P,$\"@``````M)QO\n+M/-&'5C4&````!@````P```!A+V=R=\ncommitter: Amos Jeffries \nbranch nick: 3.2\ntimestamp: Wed 2013-07-10 06:45:05 -0600\nmessage:\n Protect against buffer overrun in DNS query generation\n \n see SQUID-2013:2.\n \n This bug has been present as long as the internal DNS component however\n most code reaching this point is passing through URL validation first.\n With Squid-3.2 Host header verification using DNS directly we may have\n problems.\n------------------------------------------------------------\n# Bazaar merge directive format 2 (Bazaar 0.90)\n# revision_id: squid3@treenet.co.nz-20130710124505-g0e8esasxasgsrvw\n# target_branch: http://bzr.squid-cache.org/bzr/squid3/branches\\\n# /SQUID_3_2\n# testament_sha1: 673e11100b7775ee7221e56b8e60ea0a52af4639\n# timestamp: 2013-07-10 12:49:26 +0000\n# source_branch: http://bzr.squid-cache.org/bzr/squid3/branches\\\n# /SQUID_3_2\n# base_revision_id: squid3@treenet.co.nz-20130520060224-\\\n# upc98530u9iq0tro\n# \n# Begin patch\n=== modified file 'src/dns_internal.cc'\n--- src/dns_internal.cc\t2012-11-30 13:34:49 +0000\n+++ src/dns_internal.cc\t2013-07-10 12:45:05 +0000\n@@ -1660,23 +1660,29 @@\n void\n idnsALookup(const char *name, IDNSCB * callback, void *data)\n {\n- unsigned int i;\n+ size_t nameLength = strlen(name);\n+\n+ // Prevent buffer overflow on q->name\n+ if (nameLength > NS_MAXDNAME) {\n+ debugs(23, DBG_IMPORTANT, \"SECURITY ALERT: DNS name too long to perform lookup: '\" << name << \"'. see access.log for details.\");\n+ callback(data, NULL, 0, \"Internal error\");\n+ return;\n+ }\n+\n+ if (idnsCachedLookup(name, callback, data))\n+ return;\n+\n+ idns_query *q = cbdataAlloc(idns_query);\n+ // idns_query is POD so no constructors are called after allocation\n+ q->xact_id.change();\n+ q->query_id = idnsQueryID();\n+\n int nd = 0;\n- idns_query *q;\n-\n- if (idnsCachedLookup(name, callback, data))\n- return;\n-\n- q = cbdataAlloc(idns_query);\n- // idns_query is POD so no constructors are called after allocation\n- q->xact_id.change();\n- q->query_id = idnsQueryID();\n-\n- for (i = 0; i < strlen(name); ++i)\n+ for (unsigned int i = 0; i < nameLength; ++i)\n if (name[i] == '.')\n ++nd;\n \n- if (Config.onoff.res_defnames && npc > 0 && name[strlen(name)-1] != '.') {\n+ if (Config.onoff.res_defnames && npc > 0 && name[nameLength-1] != '.') {\n q->do_searchpath = 1;\n } else {\n q->do_searchpath = 0;\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "------------------------------------------------------------\nrevno: 11823\nrevision-id: squid3@treenet.co.nz-20130710124505-g0e8esasxasgsrvw\nparent: squid3@treenet.co.nz-20130520060224-upc98530u9iq0tro\nauthor: Nathan Hoad \ncommitter: Amos Jeffries \nbranch nick: 3.2\ntimestamp: Wed 2013-07-10 06:45:05 -0600\nmessage:\n Protect against buffer overrun in DNS query generation\n \n see SQUID-2013:2.\n \n This bug has been present as long as the internal DNS component however\n most code reaching this point is passing through URL validation first.\n With Squid-3.2 Host header verification using DNS directly we may have\n problems.\n------------------------------------------------------------\n# Bazaar merge directive format 2 (Bazaar 0.90)\n# revision_id: squid3@treenet.co.nz-20130710124505-g0e8esasxasgsrvw\n# target_branch: http://bzr.squid-cache.org/bzr/squid3/branches\\\n# /SQUID_3_2\n# testament_sha1: 673e11100b7775ee7221e56b8e60ea0a52af4639\n# timestamp: 2013-07-10 12:49:26 +0000\n# source_branch: http://bzr.squid-cache.org/bzr/squid3/branches\\\n# /SQUID_3_2\n# base_revision_id: squid3@treenet.co.nz-20130520060224-\\\n# upc98530u9iq0tro\n# \n# Begin patch\n=== modified file 'src/dns_internal.cc'\n--- src/dns_internal.cc\t2012-11-30 13:34:49 +0000\n+++ src/dns_internal.cc\t2013-07-10 12:45:05 +0000\n@@ -1660,23 +1660,29 @@\n void\n idnsALookup(const char *name, IDNSCB * callback, void *data)\n {\n- unsigned int i;\n+ size_t nameLength = strlen(name);\n+\n+ // Prevent buffer overflow on q->name\n+ if (nameLength > NS_MAXDNAME) {\n+ debugs(23, DBG_IMPORTANT, \"SECURITY ALERT: DNS name too long to perform lookup: '\" << name << \"'. see access.log for details.\");\n+ callback(data, NULL, 0, \"Internal error\");\n+ return;\n+ }\n+\n+ if (idnsCachedLookup(name, callback, data))\n+ return;\n+\n+ idns_query *q = cbdataAlloc(idns_query);\n+ // idns_query is POD so no constructors are called after allocation\n+ q->xact_id.change();\n+ q->query_id = idnsQueryID();\n+\n int nd = 0;\n- idns_query *q;\n-\n- if (idnsCachedLookup(name, callback, data))\n- return;\n-\n- q = cbdataAlloc(idns_query);\n- // idns_query is POD so no constructors are called after allocation\n- q->xact_id.change();\n- q->query_id = idnsQueryID();\n-\n- for (i = 0; i < strlen(name); ++i)\n+ for (unsigned int i = 0; i < nameLength; ++i)\n if (name[i] == '.')\n ++nd;\n \n- if (Config.onoff.res_defnames && npc > 0 && name[strlen(name)-1] != '.') {\n+ if (Config.onoff.res_defnames && npc > 0 && name[nameLength-1] != '.') {\n q->do_searchpath = 1;\n } else {\n q->do_searchpath = 0;"}], "metadata": {"id": "squid-2990-squid-3.2.x-11823-bnc829084-CV", "cve_id": "CVE-2014-3609", "package": "squid", "tier": "identical", "has_source_context": false, "license": "GPL-2.0-or-later"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-7555\n\nHeap-based buffer overflow in giffix.c in giffix in giflib 5.1.1 allows attackers to cause a denial of service (program crash) via crafted image and logical screen width fields in a GIF file.\n\n## Package\ngiflib\n\n## Files to modify\n- giflib-5.0.4.orig/lib/gif_lib_private.h\n- lib/gif_hash.h\n- giflib-5.0.4.orig/lib/gif_hash.h\n- lib/gif_lib_private.h\n\n## Upstream Fix\n```diff\n---\n configure.ac | 7 +++++--\n lib/gif_hash.h | 4 ++++\n lib/gif_lib_private.h | 3 +++\n 3 files changed, 12 insertions(+), 2 deletions(-)\n\nIndex: giflib-5.0.4/configure.ac\n===================================================================\n--- giflib-5.0.4.orig/configure.ac\n+++ giflib-5.0.4/configure.ac\n@@ -8,11 +8,14 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_R\n dnl Note: config.h is not used in the current build\n dnl We leave this in place only to suppress an error message at autogen time\n AM_CONFIG_HEADER(config.h)\n+AC_CONFIG_MACRO_DIR([m4])\n \n dnl Checks for programs.\n-AC_PROG_LIBTOOL\n-AC_PROG_CC\n+AC_PROG_CC_STDC\n+AC_USE_SYSTEM_EXTENSIONS\n+AC_SYS_LARGEFILE\n AC_PROG_CPP\n+LT_INIT([pic-only disable-static])\n AC_PROG_INSTALL\n AC_PROG_LN_S\n AC_PROG_MAKE_SET\nIndex: giflib-5.0.4/lib/gif_hash.h\n===================================================================\n--- giflib-5.0.4.orig/lib/gif_hash.h\n+++ giflib-5.0.4/lib/gif_hash.h\n@@ -25,6 +25,8 @@ gif_hash.h - magfic constants and declar\n #define HT_PUT_KEY(l)\t(l << 12)\n #define HT_PUT_CODE(l)\t(l & 0x0FFF)\n \n+#pragma GCC visibility push(hidden)\n+\n typedef struct GifHashTableType {\n uint32_t HTable[HT_SIZE];\n } GifHashTableType;\n@@ -34,6 +36,8 @@ void _ClearHashTable(GifHashTableType *H\n void _InsertHashTable(GifHashTableType *HashTable, uint32_t Key, int Code);\n int _ExistsHashTable(GifHashTableType *HashTable, uint32_t Key);\n \n+#pragma GCC visibility pop\n+\n #endif /* _GIF_HASH_H_ */\n \n /* end */\nIndex: giflib-5.0.4/lib/gif_lib_private.h\n===================================================================\n--- giflib-5.0.4.orig/lib/gif_lib_private.h\n+++ giflib-5.0.4/lib/gif_lib_private.h\n@@ -29,6 +29,8 @@ gif_lib_private.h - internal giflib rout\n #define IS_READABLE(Private) (Private->FileState & FILE_STATE_READ)\n #define IS_WRITEABLE(Private) (Private->FileState & FILE_STATE_WRITE)\n \n+#pragma GCC visibility push(hidden)\n+\n typedef struct GifFilePrivateType {\n GifWord FileState, FileHandle, /* Where all this data goes to! */\n BitsPerPixel, /* Bits per pixel (Codes uses at least this + 1). */\n@@ -54,6 +56,7 @@ typedef struct GifFilePrivateType {\n bool gif89;\n } GifFilePrivateType;\n \n+#pragma GCC visibility pop\n #endif /* _GIF_LIB_PRIVATE_H */\n \n /* end */\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "---\n configure.ac | 7 +++++--\n lib/gif_hash.h | 4 ++++\n lib/gif_lib_private.h | 3 +++\n 3 files changed, 12 insertions(+), 2 deletions(-)\n\nIndex: giflib-5.0.4/configure.ac\n===================================================================\n--- giflib-5.0.4.orig/configure.ac\n+++ giflib-5.0.4/configure.ac\n@@ -8,11 +8,14 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_R\n dnl Note: config.h is not used in the current build\n dnl We leave this in place only to suppress an error message at autogen time\n AM_CONFIG_HEADER(config.h)\n+AC_CONFIG_MACRO_DIR([m4])\n \n dnl Checks for programs.\n-AC_PROG_LIBTOOL\n-AC_PROG_CC\n+AC_PROG_CC_STDC\n+AC_USE_SYSTEM_EXTENSIONS\n+AC_SYS_LARGEFILE\n AC_PROG_CPP\n+LT_INIT([pic-only disable-static])\n AC_PROG_INSTALL\n AC_PROG_LN_S\n AC_PROG_MAKE_SET\nIndex: giflib-5.0.4/lib/gif_hash.h\n===================================================================\n--- giflib-5.0.4.orig/lib/gif_hash.h\n+++ giflib-5.0.4/lib/gif_hash.h\n@@ -25,6 +25,8 @@ gif_hash.h - magfic constants and declar\n #define HT_PUT_KEY(l)\t(l << 12)\n #define HT_PUT_CODE(l)\t(l & 0x0FFF)\n \n+#pragma GCC visibility push(hidden)\n+\n typedef struct GifHashTableType {\n uint32_t HTable[HT_SIZE];\n } GifHashTableType;\n@@ -34,6 +36,8 @@ void _ClearHashTable(GifHashTableType *H\n void _InsertHashTable(GifHashTableType *HashTable, uint32_t Key, int Code);\n int _ExistsHashTable(GifHashTableType *HashTable, uint32_t Key);\n \n+#pragma GCC visibility pop\n+\n #endif /* _GIF_HASH_H_ */\n \n /* end */\nIndex: giflib-5.0.4/lib/gif_lib_private.h\n===================================================================\n--- giflib-5.0.4.orig/lib/gif_lib_private.h\n+++ giflib-5.0.4/lib/gif_lib_private.h\n@@ -29,6 +29,8 @@ gif_lib_private.h - internal giflib rout\n #define IS_READABLE(Private) (Private->FileState & FILE_STATE_READ)\n #define IS_WRITEABLE(Private) (Private->FileState & FILE_STATE_WRITE)\n \n+#pragma GCC visibility push(hidden)\n+\n typedef struct GifFilePrivateType {\n GifWord FileState, FileHandle, /* Where all this data goes to! */\n BitsPerPixel, /* Bits per pixel (Codes uses at least this + 1). */\n@@ -54,6 +56,7 @@ typedef struct GifFilePrivateType {\n bool gif89;\n } GifFilePrivateType;\n \n+#pragma GCC visibility pop\n #endif /* _GIF_LIB_PRIVATE_H */\n \n /* end */"}], "metadata": {"id": "giflib-4560-giflib-visibility.patch", "cve_id": "CVE-2015-7555", "package": "giflib", "tier": "identical", "has_source_context": false, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1i/crypto/srp/srp_vfy.c\n- openssl-1.0.1i.orig/apps/s_server.c\n- openssl-1.0.1i/apps/s_server.c\n- openssl-1.0.1i.orig/crypto/srp/srp_vfy.c\n- openssl-1.0.1i/crypto/srp/srp.h\n\n## Target Source Code\n\n### apps/s_server.c\n\n#### region() [lines 392-423]\n```c\n (which would normally occur after a worker has finished) and we\n set the user parameters. \n*/\nstatic int MS_CALLBACK ssl_srp_server_param_cb(SSL *s, int *ad, void *arg)\n\t{\n\tsrpsrvparm *p = (srpsrvparm *)arg;\n\tif (p->login == NULL && p->user == NULL )\n\t\t{\n\t\tp->login = SSL_get_srp_username(s);\n\t\tBIO_printf(bio_err, \"SRP username = \\\"%s\\\"\\n\", p->login);\n\t\treturn (-1) ;\n\t\t}\n\n\tif (p->user == NULL)\n\t\t{\n\t\tBIO_printf(bio_err, \"User %s doesn't exist\\n\", p->login);\n\t\treturn SSL3_AL_FATAL;\n\t\t}\n\tif (SSL_set_srp_server_param(s, p->user->N, p->user->g, p->user->s, p->user->v,\n\t\t\t\t p->user->info) < 0)\n\t\t{\n\t\t*ad = SSL_AD_INTERNAL_ERROR;\n\t\treturn SSL3_AL_FATAL;\n\t\t}\n\tBIO_printf(bio_err, \"SRP parameters set: username = \\\"%s\\\" info=\\\"%s\\\" \\n\", p->login,p->user->info);\n\t/* need to check whether there are memory leaks */\n\tp->user = NULL;\n\tp->login = NULL;\n\treturn SSL_ERROR_NONE;\n\t}\n\n#endif\n```\n\n#### region() [lines 384-483]\n```c\n\tSRP_VBASE *vb;\n\tSRP_user_pwd *user;\n\t} srpsrvparm;\n\n/* This callback pretends to require some asynchronous logic in order to obtain\n a verifier. When the callback is called for a new connection we return\n with a negative value. This will provoke the accept etc to return with\n an LOOKUP_X509. The main logic of the reinvokes the suspended call \n (which would normally occur after a worker has finished) and we\n set the user parameters. \n*/\nstatic int MS_CALLBACK ssl_srp_server_param_cb(SSL *s, int *ad, void *arg)\n\t{\n\tsrpsrvparm *p = (srpsrvparm *)arg;\n\tif (p->login == NULL && p->user == NULL )\n\t\t{\n\t\tp->login = SSL_get_srp_username(s);\n\t\tBIO_printf(bio_err, \"SRP username = \\\"%s\\\"\\n\", p->login);\n\t\treturn (-1) ;\n\t\t}\n\n\tif (p->user == NULL)\n\t\t{\n\t\tBIO_printf(bio_err, \"User %s doesn't exist\\n\", p->login);\n\t\treturn SSL3_AL_FATAL;\n\t\t}\n\tif (SSL_set_srp_server_param(s, p->user->N, p->user->g, p->user->s, p->user->v,\n\t\t\t\t p->user->info) < 0)\n\t\t{\n\t\t*ad = SSL_AD_INTERNAL_ERROR;\n\t\treturn SSL3_AL_FATAL;\n\t\t}\n\tBIO_printf(bio_err, \"SRP parameters set: username = \\\"%s\\\" info=\\\"%s\\\" \\n\", p->login,p->user->info);\n\t/* need to check whether there are memory leaks */\n\tp->user = NULL;\n\tp->login = NULL;\n\treturn SSL_ERROR_NONE;\n\t}\n\n#endif\n\n#ifdef MONOLITH\nstatic void s_server_init(void)\n\t{\n\taccept_socket=-1;\n\tcipher=NULL;\n\ts_server_verify=SSL_VERIFY_NONE;\n\ts_dcert_file=NULL;\n\ts_dkey_file=NULL;\n\ts_cert_file=TEST_CERT;\n\ts_key_file=NULL;\n#ifndef OPENSSL_NO_TLSEXT\n\ts_cert_file2=TEST_CERT2;\n\ts_key_file2=NULL;\n\tctx2=NULL;\n#endif\n#ifdef FIONBIO\n\ts_nbio=0;\n#endif\n\ts_nbio_test=0;\n\tctx=NULL;\n\twww=0;\n\n\tbio_s_out=NULL;\n\ts_debug=0;\n\ts_msg=0;\n\ts_quiet=0;\n\thack=0;\n#ifndef OPENSSL_NO_ENGINE\n\tengine_id=NULL;\n#endif\n\t}\n#endif\n\nstatic void sv_usage(void)\n\t{\n\tBIO_printf(bio_err,\"usage: s_server [args ...]\\n\");\n\tBIO_printf(bio_err,\"\\n\");\n\tBIO_printf(bio_err,\" -accept arg - port to accept on (default is %d)\\n\",PORT);\n\tBIO_printf(bio_err,\" -context arg - set session ID context\\n\");\n\tBIO_printf(bio_err,\" -verify arg - turn on peer certificate verification\\n\");\n\tBIO_printf(bio_err,\" -Verify arg - turn on peer certificate verification, must have a cert.\\n\");\n\tBIO_printf(bio_err,\" -verify_return_error - return verificat\n/* ... truncated ... */\n```\n\n### crypto/srp/srp.h\n\n#### region() [lines 44-140]\n```c\n * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\n * OF THE POSSIBILITY OF SUCH DAMAGE.\n * ====================================================================\n *\n * This product includes cryptographic software written by Eric Young\n * (eay@cryptsoft.com). This product includes software written by Tim\n * Hudson (tjh@cryptsoft.com).\n *\n */\n#ifndef __SRP_H__\n#define __SRP_H__\n\n#ifndef OPENSSL_NO_SRP\n\n#include \n#include \n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#include \n#include \n#include \n\ntypedef struct SRP_gN_cache_st\n\t{\n\tchar *b64_bn;\n\tBIGNUM *bn;\n\t} SRP_gN_cache;\n\n\nDECLARE_STACK_OF(SRP_gN_cache)\n\ntypedef struct SRP_user_pwd_st\n\t{\n\tchar *id;\n\tBIGNUM *s;\n\tBIGNUM *v;\n\tconst BIGNUM *g;\n\tconst BIGNUM *N;\n\tchar *info;\n\t} SRP_user_pwd;\n\nDECLARE_STACK_OF(SRP_user_pwd)\n\ntypedef struct SRP_VBASE_st\n\t{\n\tSTACK_OF(SRP_user_pwd) *users_pwd;\n\tSTACK_OF(SRP_gN_cache) *gN_cache;\n/* to simulate a user */\n\tchar *seed_key;\n\tBIGNUM *default_g;\n\tBIGNUM *default_N;\n\t} SRP_VBASE;\n\n\n/*Structure interne pour retenir les couples N et g*/\ntypedef struct SRP_gN_st\n\t{\n\tchar *id;\n\tBIGNUM *g;\n\tBIGNUM *N;\n\t} SRP_gN;\n\nDECLARE_STACK_OF(SRP_gN)\n\nSRP_VBASE *SRP_VBASE_new(char *seed_key);\nint SRP_VBASE_free(SRP_VBASE *vb);\nint SRP_VBASE_init(SRP_VBASE *vb, char * verifier_file);\nSRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username);\nchar *SRP_create_verifier(const char *user, const char *pass, char **salt,\n\t\t\t char **verifier, const char *N, const char *g);\nint SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt, BIGNUM **verifier, BIGNUM *N, BIGNUM *g);\n\n\n#define SRP_NO_ERROR 0\n#define SRP_ERR_VBASE_INCOMPLETE_FILE 1\n#define SRP_ERR_VBASE_BN_LIB 2\n#define SRP_ERR_OPEN_FILE 3\n#define SRP_ERR_MEMORY 4\n\n#define DB_srptype\t0\n#define DB_srpverifier\t1\n#define DB_srpsalt \t2\n#define DB_srpid\t3 \n#define DB_srpgN\t4 \n#define DB_srpinfo\t5 \n#undef DB_NUMBER \n#define DB_NUMBER 6\n\n```\n\n#### region() [lines 78-165]\n```c\n\tBIGNUM *bn;\n\t} SRP_gN_cache;\n\n\nDECLARE_STACK_OF(SRP_gN_cache)\n\ntypedef struct SRP_user_pwd_st\n\t{\n\tchar *id;\n\tBIGNUM *s;\n\tBIGNUM *v;\n\tconst BIGNUM *g;\n\tconst BIGNUM *N;\n\tchar *info;\n\t} SRP_user_pwd;\n\nDECLARE_STACK_OF(SRP_user_pwd)\n\ntypedef struct SRP_VBASE_st\n\t{\n\tSTACK_OF(SRP_user_pwd) *users_pwd;\n\tSTACK_OF(SRP_gN_cache) *gN_cache;\n/* to simulate a user */\n\tchar *seed_key;\n\tBIGNUM *default_g;\n\tBIGNUM *default_N;\n\t} SRP_VBASE;\n\n\n/*Structure interne pour retenir les couples N et g*/\ntypedef struct SRP_gN_st\n\t{\n\tchar *id;\n\tBIGNUM *g;\n\tBIGNUM *N;\n\t} SRP_gN;\n\nDECLARE_STACK_OF(SRP_gN)\n\nSRP_VBASE *SRP_VBASE_new(char *seed_key);\nint SRP_VBASE_free(SRP_VBASE *vb);\nint SRP_VBASE_init(SRP_VBASE *vb,\n/* ... truncated ... */\n```\n\n### crypto/srp/srp_vfy.c\n\n#### region() [lines 143-230]\n```c\n\t\tbreak;\n\t\t}\n\n\twhile(1)\n\t\t{\n\t\tc = (b0 & 0xfc) >> 2;\n\t\tif(notleading || c != 0)\n\t\t\t{\n\t\t\t*dst++ = b64table[c];\n\t\t\tnotleading = 1;\n\t\t\t}\n\t\tc = ((b0 & 3) << 4) | ((b1 & 0xf0) >> 4);\n\t\tif(notleading || c != 0)\n\t\t\t{\n\t\t\t*dst++ = b64table[c];\n\t\t\tnotleading = 1;\n\t\t\t}\n\t\tc = ((b1 & 0xf) << 2) | ((b2 & 0xc0) >> 6);\n\t\tif(notleading || c != 0)\n\t\t\t{\n\t\t\t*dst++ = b64table[c];\n\t\t\tnotleading = 1;\n\t\t\t}\n\t\tc = b2 & 0x3f;\n\t\tif(notleading || c != 0)\n\t\t\t{\n\t\t\t*dst++ = b64table[c];\n\t\t\tnotleading = 1;\n\t\t\t}\n\t\tif(pos >= size) break;\n\t\telse\n\t\t\t{\n\t\t\tb0 = src[pos++];\n\t\t\tb1 = src[pos++];\n\t\t\tb2 = src[pos++];\n\t\t\t}\n\t\t}\n\n\t*dst++ = '\\0';\n\treturn olddst;\n\t}\n\nstatic void SRP_user_pwd_free(SRP_user_pwd *user_pwd)\n\t{\n\tif (user_pwd == NULL) \n\t\treturn;\n\tBN_free(user_pwd->s);\n\tBN_clear_free(user_pwd->v);\n\tOPENSSL_free(user_pwd->id);\n\tOPENSSL_free(user_pwd->info);\n\tOPENSSL_free(user_pwd);\n\t}\n\nstatic SRP_user_pwd *SRP_user_pwd_new()\n\t{\n\tSRP_user_pwd *ret = OPENSSL_malloc(sizeof(SRP_user_pwd));\n\tif (ret == NULL)\n\t\treturn NULL;\t\t\t\t\t\t\t\t\n\tret->N = NULL;\n\tret->g = NULL;\t\n\tret->s = NULL;\n\tret->v = NULL;\n\tret->id = NULL ;\n\tret->info = NULL;\n\treturn ret;\n\t}\n\nstatic void SRP_user_pwd_set_gN(SRP_user_pwd *vinfo, const BIGNUM *g,\n\t\t\t\tconst BIGNUM *N)\n\t{\n\tvinfo->N = N;\n\tvinfo->g = g;\t\n\t}\n\nstatic int SRP_user_pwd_set_ids(SRP_user_pwd *vinfo, const char *id,\n\t\t\t\tconst char *info)\n\t{\n\tif (id != NULL && NULL == (vinfo->id = BUF_strdup(id)))\n\t\treturn 0;\n\treturn (info == NULL || NULL != (vinfo->info = BUF_strdup(info))) ;\n\t}\n\nstatic int SRP_user_pwd_set_sv(SRP_user_pwd *vinfo, const char *s,\n\t\t\t const char *v)\n\t{\n\tunsigned char tmp[MAX_LEN];\n\tint len;\n\n```\n\n#### region() [lines 237-247]\n```c\n\treturn ((vinfo->s = BN_bin2bn(tmp, len, NULL)) != NULL) ;\n\t}\n\nstatic int SRP_user_pwd_set_sv_BN(SRP_user_pwd *vinfo, BIGNUM *s, BIGNUM *v)\n\t{\n\tvinfo->v = v;\n\tvinfo->s = s;\n\treturn (vinfo->s != NULL && vinfo->v != NULL) ;\n\t}\n\nSRP_VBASE *SRP_VBASE_new(char *seed_key)\n```\n\n#### region() [lines 360-477]\n```c\n */\n\n\nint SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file)\n\t{\n\tint error_code ;\n\tSTACK_OF(SRP_gN) *SRP_gN_tab = sk_SRP_gN_new_null();\n\tchar *last_index = NULL;\n\tint i;\n\tchar **pp;\n\n\tSRP_gN *gN = NULL;\n\tSRP_user_pwd *user_pwd = NULL ;\n\n\tTXT_DB *tmpdb = NULL;\n\tBIO *in = BIO_new(BIO_s_file());\n\n\terror_code = SRP_ERR_OPEN_FILE;\n\n\tif (in == NULL || BIO_read_filename(in,verifier_file) <= 0)\n\t\tgoto err;\n\n\terror_code = SRP_ERR_VBASE_INCOMPLETE_FILE;\n\n\tif ((tmpdb =TXT_DB_read(in,DB_NUMBER)) == NULL)\n\t\tgoto err;\n\n\terror_code = SRP_ERR_MEMORY;\n\n\n\tif (vb->seed_key)\n\t\t{\n\t\tlast_index = SRP_get_default_gN(NULL)->id;\n\t\t}\n\tfor (i = 0; i < sk_OPENSSL_PSTRING_num(tmpdb->data); i++)\n\t\t{\n\t\tpp = sk_OPENSSL_PSTRING_value(tmpdb->data,i);\n\t\tif (pp[DB_srptype][0] == DB_SRP_INDEX)\n\t\t\t{\n\t\t\t/*we add this couple in the internal Stack */\n\n\t\t\tif ((gN = (SRP_gN *)OPENSSL_malloc(sizeof(SRP_gN))) == NULL) \n \t\t\t\tgoto err;\n\n\t\t\tif (!(gN->id = BUF_strdup(pp[DB_srpid]))\n\t || !(gN->N = SRP_gN_place_bn(vb->gN_cache,pp[DB_srpverifier]))\n\t\t\t|| !(gN->g = SRP_gN_place_bn(vb->gN_cache,pp[DB_srpsalt]))\n\t\t\t|| sk_SRP_gN_insert(SRP_gN_tab,gN,0) == 0)\n\t\t\t\tgoto err;\n\n\t\t\tgN = NULL;\n\n\t\t\tif (vb->seed_k\n/* ... truncated ... */\n```\n\n### util/libeay.num\n\n#### region() [lines 1767-1853]\n```c\nDSO_new_method 2260\tEXIST::FUNCTION:\nDSO_free 2261\tEXIST::FUNCTION:\nDSO_flags 2262\tEXIST::FUNCTION:\nDSO_up 2263\tNOEXIST::FUNCTION:\nDSO_set_default_method 2264\tEXIST::FUNCTION:\nDSO_get_default_method 2265\tEXIST::FUNCTION:\nDSO_get_method 2266\tEXIST::FUNCTION:\nDSO_set_method 2267\tEXIST::FUNCTION:\nDSO_load 2268\tEXIST::FUNCTION:\nDSO_bind_var 2269\tEXIST::FUNCTION:\nDSO_METHOD_null 2270\tEXIST::FUNCTION:\nDSO_METHOD_openssl 2271\tEXIST::FUNCTION:\nDSO_METHOD_dlfcn 2272\tEXIST::FUNCTION:\nDSO_METHOD_win32 2273\tEXIST::FUNCTION:\nERR_load_DSO_strings 2274\tEXIST::FUNCTION:\nDSO_METHOD_dl 2275\tEXIST::FUNCTION:\nNCONF_load 2276\tEXIST::FUNCTION:\nNCONF_load_fp 2278\tEXIST::FUNCTION:FP_API\nNCONF_new 2279\tEXIST::FUNCTION:\nNCONF_get_string 2280\tEXIST::FUNCTION:\nNCONF_free 2281\tEXIST::FUNCTION:\nNCONF_get_number 2282\tNOEXIST::FUNCTION:\nCONF_dump_fp 2283\tEXIST::FUNCTION:\nNCONF_load_bio 2284\tEXIST::FUNCTION:\nNCONF_dump_fp 2285\tEXIST::FUNCTION:\nNCONF_get_section 2286\tEXIST::FUNCTION:\nNCONF_dump_bio 2287\tEXIST::FUNCTION:\nCONF_dump_bio 2288\tEXIST::FUNCTION:\nNCONF_free_data 2289\tEXIST::FUNCTION:\nCONF_set_default_method 2290\tEXIST::FUNCTION:\nERR_error_string_n 2291\tEXIST::FUNCTION:\nBIO_snprintf 2292\tEXIST::FUNCTION:\nDSO_ctrl 2293\tEXIST::FUNCTION:\ni2d_ASN1_SET_OF_ASN1_INTEGER 2317\tNOEXIST::FUNCTION:\ni2d_ASN1_SET_OF_PKCS12_SAFEBAG 2320\tNOEXIST::FUNCTION:\ni2d_ASN1_SET_OF_PKCS7 2328\tNOEXIST::FUNCTION:\nBIO_vfree 2334\tEXIST::FUNCTION:\nd2i_ASN1_SET_OF_ASN1_INTEGER 2339\tNOEXIST::FUNCTION:\nd2i_ASN1_SET_OF_PKCS12_SAFEBAG 2341\tNOEXIST::FUNCTION:\nASN1_UTCTIME_get 2350\tNOEXIST::FUNCTION:\nX509_REQ_digest 2362\tEXIST::FUNCTION:EVP\nX509_CRL_digest 2391\tEXIST::FUNCTION:EVP\nd2i_ASN1_SET_OF_PKCS7 2397\tNOEXIST::FUNCTION:\nEVP_CIPHER_CTX_set_key_length 2399\tEXIST::FUNCTION:\nEVP_CIPHER_CTX_ctrl 2400\tEXIST::FUNCTION:\nBN_mod_exp_mont_word 2401\tEXIST::FUNCTION:\nRAND_egd_bytes 2402\tEXIST::FUNCTION:\nX509_REQ_get1_email 2403\tEXIST::FUNCTION:\nX509_get1_email 2404\tEXIST::FUNCTION:\nX509_email_free 2405\tEXIST::FUNCTION:\ni2d_RSA_NET \n/* ... truncated ... */\n```\n\n\n## Upstream Fix\n```diff\ncommit 59a908f1e8380412a81392c468b83bf6071beb2a\nAuthor: Emilia Kasper \nDate: Wed Feb 24 12:59:59 2016 +0100\n\n CVE-2016-0798: avoid memory leak in SRP\n \n The SRP user database lookup method SRP_VBASE_get_by_user had confusing\n memory management semantics; the returned pointer was sometimes newly\n allocated, and sometimes owned by the callee. The calling code has no\n way of distinguishing these two cases.\n \n Specifically, SRP servers that configure a secret seed to hide valid\n login information are vulnerable to a memory leak: an attacker\n connecting with an invalid username can cause a memory leak of around\n 300 bytes per connection.\n \n Servers that do not configure SRP, or configure SRP but do not configure\n a seed are not vulnerable.\n \n In Apache, the seed directive is known as SSLSRPUnknownUserSeed.\n \n To mitigate the memory leak, the seed handling in SRP_VBASE_get_by_user\n is now disabled even if the user has configured a seed.\n \n Applications are advised to migrate to SRP_VBASE_get1_by_user. However,\n note that OpenSSL makes no strong guarantees about the\n indistinguishability of valid and invalid logins. In particular,\n computations are currently not carried out in constant time.\n \n Reviewed-by: Rich Salz \n\nIndex: openssl-1.0.1i/apps/s_server.c\n===================================================================\n--- openssl-1.0.1i.orig/apps/s_server.c\t2016-02-26 09:45:21.967034547 +0100\n+++ openssl-1.0.1i/apps/s_server.c\t2016-02-26 09:55:55.582705403 +0100\n@@ -413,6 +413,8 @@\n static int MS_CALLBACK ssl_srp_server_param_cb(SSL *s, int *ad, void *arg)\n \t{\n \tsrpsrvparm *p = (srpsrvparm *)arg;\n+ int ret = SSL3_AL_FATAL;\n+\n \tif (p->login == NULL && p->user == NULL )\n \t\t{\n \t\tp->login = SSL_get_srp_username(s);\n@@ -423,19 +425,23 @@\n \tif (p->user == NULL)\n \t\t{\n \t\tBIO_printf(bio_err, \"User %s doesn't exist\\n\", p->login);\n-\t\treturn SSL3_AL_FATAL;\n+ goto err;\n \t\t}\n+\n \tif (SSL_set_srp_server_param(s, p->user->N, p->user->g, p->user->s, p->user->v,\n \t\t\t\t p->user->info) < 0)\n \t\t{\n \t\t*ad = SSL_AD_INTERNAL_ERROR;\n-\t\treturn SSL3_AL_FATAL;\n+ goto err;\n \t\t}\n \tBIO_printf(bio_err, \"SRP parameters set: username = \\\"%s\\\" info=\\\"%s\\\" \\n\", p->login,p->user->info);\n-\t/* need to check whether there are memory leaks */\n+ ret = SSL_ERROR_NONE;\n+\n+err:\n+ SRP_user_pwd_free(p->user);\n \tp->user = NULL;\n \tp->login = NULL;\n-\treturn SSL_ERROR_NONE;\n+\treturn ret;\n \t}\n \n #endif\n@@ -2300,7 +2306,8 @@\n \t\t\t\twhile (SSL_get_error(con,k) == SSL_ERROR_WANT_X509_LOOKUP)\n \t\t\t\t\t{\n \t\t\t\t\tBIO_printf(bio_s_out,\"LOOKUP renego during write\\n\");\n-\t\t\t\t\tsrp_callback_parm.user = SRP_VBASE_get_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n+ SRP_user_pwd_free(srp_callback_parm.user);\n+\t\t\t\t\tsrp_callback_parm.user = SRP_VBASE_get1_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n \t\t\t\t\tif (srp_callback_parm.user) \n \t\t\t\t\t\tBIO_printf(bio_s_out,\"LOOKUP done %s\\n\",srp_callback_parm.user->info);\n \t\t\t\t\telse \n@@ -2359,7 +2366,8 @@\n \t\t\t\twhile (SSL_get_error(con,i) == SSL_ERROR_WANT_X509_LOOKUP)\n \t\t\t\t\t{\n \t\t\t\t\tBIO_printf(bio_s_out,\"LOOKUP renego during read\\n\");\n-\t\t\t\t\tsrp_callback_parm.user = SRP_VBASE_get_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n+ SRP_user_pwd_free(srp_callback_parm.user);\n+\t\t\t\t\tsrp_callback_parm.user = SRP_VBASE_get1_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n \t\t\t\t\tif (srp_callback_parm.user) \n \t\t\t\t\t\tBIO_printf(bio_s_out,\"LOOKUP done %s\\n\",srp_callback_parm.user->info);\n \t\t\t\t\telse \n@@ -2448,7 +2456,8 @@\n \twhile (i <= 0 && SSL_get_error(con,i) == SSL_ERROR_WANT_X509_LOOKUP) \n \t\t{\n \t\t\tBIO_printf(bio_s_out,\"LOOKUP during accept %s\\n\",srp_callback_parm.login);\n-\t\t\tsrp_callback_parm.user = SRP_VBASE_get_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n+ SRP_user_pwd_free(srp_callback_parm.user);\n+\t\t\tsrp_callback_parm.user = SRP_VBASE_get1_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n \t\t\tif (srp_callback_parm.user) \n \t\t\t\tBIO_printf(bio_s_out,\"LOOKUP done %s\\n\",srp_callback_parm.user->info);\n \t\t\telse \n@@ -2690,7 +2699,8 @@\n \t\t\twhile (i <= 0 && SSL_get_error(con,i) == SSL_ERROR_WANT_X509_LOOKUP) \n \t\t{\n \t\t\tBIO_printf(bio_s_out,\"LOOKUP during accept %s\\n\",srp_callback_parm.login);\n-\t\t\tsrp_callback_parm.user = SRP_VBASE_get_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n+ SRP_user_pwd_free(srp_callback_parm.user);\n+\t\t\tsrp_callback_parm.user = SRP_VBASE_get1_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n \t\t\tif (srp_callback_parm.user) \n \t\t\t\tBIO_printf(bio_s_out,\"LOOKUP done %s\\n\",srp_callback_parm.user->info);\n \t\t\telse \nIndex: openssl-1.0.1i/crypto/srp/srp.h\n===================================================================\n--- openssl-1.0.1i.orig/crypto/srp/srp.h\t2016-02-26 09:45:21.967034547 +0100\n+++ openssl-1.0.1i/crypto/srp/srp.h\t2016-02-26 09:59:30.355828026 +0100\n@@ -83,16 +83,21 @@\n \n typedef struct SRP_user_pwd_st\n \t{\n+ /* Owned by us. */\n \tchar *id;\n \tBIGNUM *s;\n \tBIGNUM *v;\n+ /* Not owned by us. */\n \tconst BIGNUM *g;\n \tconst BIGNUM *N;\n+ /* Owned by us. */\n \tchar *info;\n \t} SRP_user_pwd;\n \n DECLARE_STACK_OF(SRP_user_pwd)\n \n+void SRP_user_pwd_free(SRP_user_pwd *user_pwd);\n+\n typedef struct SRP_VBASE_st\n \t{\n \tSTACK_OF(SRP_user_pwd) *users_pwd;\n@@ -117,7 +122,12 @@\n SRP_VBASE *SRP_VBASE_new(char *seed_key);\n int SRP_VBASE_free(SRP_VBASE *vb);\n int SRP_VBASE_init(SRP_VBASE *vb, char * verifier_file);\n+\n+/* This method ignores the configured seed and fails for an unknown user. */\n SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username);\n+/* NOTE: unlike in SRP_VBASE_get_by_user, caller owns the returned pointer.*/\n+SRP_user_pwd *SRP_VBASE_get1_by_user(SRP_VBASE *vb, char *username);\n+\n char *SRP_create_verifier(const char *user, const char *pass, char **salt,\n \t\t\t char **verifier, const char *N, const char *g);\n int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt, BIGNUM **verifier, BIGNUM *N, BIGNUM *g);\nIndex: openssl-1.0.1i/crypto/srp/srp_vfy.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/srp/srp_vfy.c\t2016-02-26 09:45:14.998989106 +0100\n+++ openssl-1.0.1i/crypto/srp/srp_vfy.c\t2016-02-26 10:01:19.740387786 +0100\n@@ -182,7 +182,7 @@\n \treturn olddst;\n \t}\n \n-static void SRP_user_pwd_free(SRP_user_pwd *user_pwd)\n+void SRP_user_pwd_free(SRP_user_pwd *user_pwd)\n \t{\n \tif (user_pwd == NULL) \n \t\treturn;\n@@ -244,6 +244,24 @@\n \treturn (vinfo->s != NULL && vinfo->v != NULL) ;\n \t}\n \n+static SRP_user_pwd *srp_user_pwd_dup(SRP_user_pwd *src)\n+{\n+ SRP_user_pwd *ret;\n+\n+ if (src == NULL)\n+ return NULL;\n+ if ((ret = SRP_user_pwd_new()) == NULL)\n+ return NULL;\n+\n+ SRP_user_pwd_set_gN(ret, src->g, src->N);\n+ if (!SRP_user_pwd_set_ids(ret, src->id, src->info)\n+ || !SRP_user_pwd_set_sv_BN(ret, BN_dup(src->s), BN_dup(src->v))) {\n+ SRP_user_pwd_free(ret);\n+ return NULL;\n+ }\n+ return ret;\n+}\n+\n SRP_VBASE *SRP_VBASE_new(char *seed_key)\n \t{\n \tSRP_VBASE *vb = (SRP_VBASE *) OPENSSL_malloc(sizeof(SRP_VBASE));\n@@ -474,23 +492,51 @@\n \n \t}\n \n-\n-SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username)\n+static SRP_user_pwd *find_user(SRP_VBASE *vb, char *username)\n \t{\n \tint i;\n \tSRP_user_pwd *user;\n-\tunsigned char digv[SHA_DIGEST_LENGTH];\n-\tunsigned char digs[SHA_DIGEST_LENGTH];\n-\tEVP_MD_CTX ctxt;\n \n \tif (vb == NULL)\n \t\treturn NULL;\n+\n \tfor(i = 0; i < sk_SRP_user_pwd_num(vb->users_pwd); i++)\n \t\t{\n \t\tuser = sk_SRP_user_pwd_value(vb->users_pwd, i);\n \t\tif (strcmp(user->id,username)==0)\n \t\t\treturn user;\n \t\t}\n+\n+ return NULL;\n+}\n+\n+/*\n+ * This method ignores the configured seed and fails for an unknown user.\n+ * Ownership of the returned pointer is not released to the caller.\n+ * In other wor\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "commit 59a908f1e8380412a81392c468b83bf6071beb2a\nAuthor: Emilia Kasper \nDate: Wed Feb 24 12:59:59 2016 +0100\n\n CVE-2016-0798: avoid memory leak in SRP\n \n The SRP user database lookup method SRP_VBASE_get_by_user had confusing\n memory management semantics; the returned pointer was sometimes newly\n allocated, and sometimes owned by the callee. The calling code has no\n way of distinguishing these two cases.\n \n Specifically, SRP servers that configure a secret seed to hide valid\n login information are vulnerable to a memory leak: an attacker\n connecting with an invalid username can cause a memory leak of around\n 300 bytes per connection.\n \n Servers that do not configure SRP, or configure SRP but do not configure\n a seed are not vulnerable.\n \n In Apache, the seed directive is known as SSLSRPUnknownUserSeed.\n \n To mitigate the memory leak, the seed handling in SRP_VBASE_get_by_user\n is now disabled even if the user has configured a seed.\n \n Applications are advised to migrate to SRP_VBASE_get1_by_user. However,\n note that OpenSSL makes no strong guarantees about the\n indistinguishability of valid and invalid logins. In particular,\n computations are currently not carried out in constant time.\n \n Reviewed-by: Rich Salz \n\nIndex: openssl-1.0.1i/apps/s_server.c\n===================================================================\n--- openssl-1.0.1i.orig/apps/s_server.c\t2016-02-26 09:45:21.967034547 +0100\n+++ openssl-1.0.1i/apps/s_server.c\t2016-02-26 09:55:55.582705403 +0100\n@@ -413,6 +413,8 @@\n static int MS_CALLBACK ssl_srp_server_param_cb(SSL *s, int *ad, void *arg)\n \t{\n \tsrpsrvparm *p = (srpsrvparm *)arg;\n+ int ret = SSL3_AL_FATAL;\n+\n \tif (p->login == NULL && p->user == NULL )\n \t\t{\n \t\tp->login = SSL_get_srp_username(s);\n@@ -423,19 +425,23 @@\n \tif (p->user == NULL)\n \t\t{\n \t\tBIO_printf(bio_err, \"User %s doesn't exist\\n\", p->login);\n-\t\treturn SSL3_AL_FATAL;\n+ goto err;\n \t\t}\n+\n \tif (SSL_set_srp_server_param(s, p->user->N, p->user->g, p->user->s, p->user->v,\n \t\t\t\t p->user->info) < 0)\n \t\t{\n \t\t*ad = SSL_AD_INTERNAL_ERROR;\n-\t\treturn SSL3_AL_FATAL;\n+ goto err;\n \t\t}\n \tBIO_printf(bio_err, \"SRP parameters set: username = \\\"%s\\\" info=\\\"%s\\\" \\n\", p->login,p->user->info);\n-\t/* need to check whether there are memory leaks */\n+ ret = SSL_ERROR_NONE;\n+\n+err:\n+ SRP_user_pwd_free(p->user);\n \tp->user = NULL;\n \tp->login = NULL;\n-\treturn SSL_ERROR_NONE;\n+\treturn ret;\n \t}\n \n #endif\n@@ -2300,7 +2306,8 @@\n \t\t\t\twhile (SSL_get_error(con,k) == SSL_ERROR_WANT_X509_LOOKUP)\n \t\t\t\t\t{\n \t\t\t\t\tBIO_printf(bio_s_out,\"LOOKUP renego during write\\n\");\n-\t\t\t\t\tsrp_callback_parm.user = SRP_VBASE_get_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n+ SRP_user_pwd_free(srp_callback_parm.user);\n+\t\t\t\t\tsrp_callback_parm.user = SRP_VBASE_get1_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n \t\t\t\t\tif (srp_callback_parm.user) \n \t\t\t\t\t\tBIO_printf(bio_s_out,\"LOOKUP done %s\\n\",srp_callback_parm.user->info);\n \t\t\t\t\telse \n@@ -2359,7 +2366,8 @@\n \t\t\t\twhile (SSL_get_error(con,i) == SSL_ERROR_WANT_X509_LOOKUP)\n \t\t\t\t\t{\n \t\t\t\t\tBIO_printf(bio_s_out,\"LOOKUP renego during read\\n\");\n-\t\t\t\t\tsrp_callback_parm.user = SRP_VBASE_get_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n+ SRP_user_pwd_free(srp_callback_parm.user);\n+\t\t\t\t\tsrp_callback_parm.user = SRP_VBASE_get1_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n \t\t\t\t\tif (srp_callback_parm.user) \n \t\t\t\t\t\tBIO_printf(bio_s_out,\"LOOKUP done %s\\n\",srp_callback_parm.user->info);\n \t\t\t\t\telse \n@@ -2448,7 +2456,8 @@\n \twhile (i <= 0 && SSL_get_error(con,i) == SSL_ERROR_WANT_X509_LOOKUP) \n \t\t{\n \t\t\tBIO_printf(bio_s_out,\"LOOKUP during accept %s\\n\",srp_callback_parm.login);\n-\t\t\tsrp_callback_parm.user = SRP_VBASE_get_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n+ SRP_user_pwd_free(srp_callback_parm.user);\n+\t\t\tsrp_callback_parm.user = SRP_VBASE_get1_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n \t\t\tif (srp_callback_parm.user) \n \t\t\t\tBIO_printf(bio_s_out,\"LOOKUP done %s\\n\",srp_callback_parm.user->info);\n \t\t\telse \n@@ -2690,7 +2699,8 @@\n \t\t\twhile (i <= 0 && SSL_get_error(con,i) == SSL_ERROR_WANT_X509_LOOKUP) \n \t\t{\n \t\t\tBIO_printf(bio_s_out,\"LOOKUP during accept %s\\n\",srp_callback_parm.login);\n-\t\t\tsrp_callback_parm.user = SRP_VBASE_get_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n+ SRP_user_pwd_free(srp_callback_parm.user);\n+\t\t\tsrp_callback_parm.user = SRP_VBASE_get1_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n \t\t\tif (srp_callback_parm.user) \n \t\t\t\tBIO_printf(bio_s_out,\"LOOKUP done %s\\n\",srp_callback_parm.user->info);\n \t\t\telse \nIndex: openssl-1.0.1i/crypto/srp/srp.h\n===================================================================\n--- openssl-1.0.1i.orig/crypto/srp/srp.h\t2016-02-26 09:45:21.967034547 +0100\n+++ openssl-1.0.1i/crypto/srp/srp.h\t2016-02-26 09:59:30.355828026 +0100\n@@ -83,16 +83,21 @@\n \n typedef struct SRP_user_pwd_st\n \t{\n+ /* Owned by us. */\n \tchar *id;\n \tBIGNUM *s;\n \tBIGNUM *v;\n+ /* Not owned by us. */\n \tconst BIGNUM *g;\n \tconst BIGNUM *N;\n+ /* Owned by us. */\n \tchar *info;\n \t} SRP_user_pwd;\n \n DECLARE_STACK_OF(SRP_user_pwd)\n \n+void SRP_user_pwd_free(SRP_user_pwd *user_pwd);\n+\n typedef struct SRP_VBASE_st\n \t{\n \tSTACK_OF(SRP_user_pwd) *users_pwd;\n@@ -117,7 +122,12 @@\n SRP_VBASE *SRP_VBASE_new(char *seed_key);\n int SRP_VBASE_free(SRP_VBASE *vb);\n int SRP_VBASE_init(SRP_VBASE *vb, char * verifier_file);\n+\n+/* This method ignores the configured seed and fails for an unknown user. */\n SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username);\n+/* NOTE: unlike in SRP_VBASE_get_by_user, caller owns the returned pointer.*/\n+SRP_user_pwd *SRP_VBASE_get1_by_user(SRP_VBASE *vb, char *username);\n+\n char *SRP_create_verifier(const char *user, const char *pass, char **salt,\n \t\t\t char **verifier, const char *N, const char *g);\n int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt, BIGNUM **verifier, BIGNUM *N, BIGNUM *g);\nIndex: openssl-1.0.1i/crypto/srp/srp_vfy.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/srp/srp_vfy.c\t2016-02-26 09:45:14.998989106 +0100\n+++ openssl-1.0.1i/crypto/srp/srp_vfy.c\t2016-02-26 10:01:19.740387786 +0100\n@@ -182,7 +182,7 @@\n \treturn olddst;\n \t}\n \n-static void SRP_user_pwd_free(SRP_user_pwd *user_pwd)\n+void SRP_user_pwd_free(SRP_user_pwd *user_pwd)\n \t{\n \tif (user_pwd == NULL) \n \t\treturn;\n@@ -244,6 +244,24 @@\n \treturn (vinfo->s != NULL && vinfo->v != NULL) ;\n \t}\n \n+static SRP_user_pwd *srp_user_pwd_dup(SRP_user_pwd *src)\n+{\n+ SRP_user_pwd *ret;\n+\n+ if (src == NULL)\n+ return NULL;\n+ if ((ret = SRP_user_pwd_new()) == NULL)\n+ return NULL;\n+\n+ SRP_user_pwd_set_gN(ret, src->g, src->N);\n+ if (!SRP_user_pwd_set_ids(ret, src->id, src->info)\n+ || !SRP_user_pwd_set_sv_BN(ret, BN_dup(src->s), BN_dup(src->v))) {\n+ SRP_user_pwd_free(ret);\n+ return NULL;\n+ }\n+ return ret;\n+}\n+\n SRP_VBASE *SRP_VBASE_new(char *seed_key)\n \t{\n \tSRP_VBASE *vb = (SRP_VBASE *) OPENSSL_malloc(sizeof(SRP_VBASE));\n@@ -474,23 +492,51 @@\n \n \t}\n \n-\n-SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username)\n+static SRP_user_pwd *find_user(SRP_VBASE *vb, char *username)\n \t{\n \tint i;\n \tSRP_user_pwd *user;\n-\tunsigned char digv[SHA_DIGEST_LENGTH];\n-\tunsigned char digs[SHA_DIGEST_LENGTH];\n-\tEVP_MD_CTX ctxt;\n \n \tif (vb == NULL)\n \t\treturn NULL;\n+\n \tfor(i = 0; i < sk_SRP_user_pwd_num(vb->users_pwd); i++)\n \t\t{\n \t\tuser = sk_SRP_user_pwd_value(vb->users_pwd, i);\n \t\tif (strcmp(user->id,username)==0)\n \t\t\treturn user;\n \t\t}\n+\n+ return NULL;\n+}\n+\n+/*\n+ * This method ignores the configured seed and fails for an unknown user.\n+ * Ownership of the returned pointer is not released to the caller.\n+ * In other words, caller must not free the result.\n+ */\n+SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username)\n+{\n+ return find_user(vb, username);\n+}\n+\n+/*\n+ * Ownership of the returned pointer is released to the caller.\n+ * In other words, caller must free the result once done.\n+ */\n+SRP_user_pwd *SRP_VBASE_get1_by_user(SRP_VBASE *vb, char *username)\n+{\n+ SRP_user_pwd *user;\n+ unsigned char digv[SHA_DIGEST_LENGTH];\n+ unsigned char digs[SHA_DIGEST_LENGTH];\n+ EVP_MD_CTX ctxt;\n+\n+ if (vb == NULL)\n+ return NULL;\n+\n+ if ((user = find_user(vb, username)) != NULL)\n+ return srp_user_pwd_dup(user);\n+\n \tif ((vb->seed_key == NULL) ||\n \t\t(vb->default_g == NULL) ||\n \t\t(vb->default_N == NULL))\nIndex: openssl-1.0.1i/util/libeay.num\n===================================================================\n--- openssl-1.0.1i.orig/util/libeay.num\t2016-02-26 09:45:21.967034547 +0100\n+++ openssl-1.0.1i/util/libeay.num\t2016-02-26 09:58:37.423554553 +0100\n@@ -1806,6 +1806,8 @@\n ASN1_UTCTIME_get 2350\tNOEXIST::FUNCTION:\n X509_REQ_digest 2362\tEXIST::FUNCTION:EVP\n X509_CRL_digest 2391\tEXIST::FUNCTION:EVP\n+SRP_VBASE_get1_by_user 2393\tEXIST::FUNCTION:SRP\n+SRP_user_pwd_free 2394\tEXIST::FUNCTION:SRP\n d2i_ASN1_SET_OF_PKCS7 2397\tNOEXIST::FUNCTION:\n EVP_CIPHER_CTX_set_key_length 2399\tEXIST::FUNCTION:\n EVP_CIPHER_CTX_ctrl 2400\tEXIST::FUNCTION:"}], "metadata": {"id": "openssl-4769-openssl-CVE-2016-0798-101.patc", "cve_id": "CVE-2015-3197", "package": "openssl", "tier": "adapted", "has_source_context": true, "context_tokens_est": 3239, "context_files": 4, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-4658\n\nxpointer.c in libxml2 before 2.9.5 (as used in Apple iOS before 10, OS X before 10.12, tvOS before 10, and watchOS before 3, and other products) does not forbid namespace nodes in XPointer ranges, which allows remote attackers to execute arbitrary code or cause a denial of service (use-after-free and memory corruption) via a crafted XML document.\n\n## Package\nlibxml2\n\n## Files to modify\n- HTMLparser.c\n\n## Upstream Fix\n```diff\nFrom 11ed4a7a90d5ce156a18980a4ad4e53e77384852 Mon Sep 17 00:00:00 2001\nFrom: Pranjal Jumde \nDate: Wed, 2 Mar 2016 15:52:24 -0800\nSubject: [PATCH] Heap use-after-free in htmlParsePubidLiteral and\n htmlParseSystemiteral\n\nFor https://bugzilla.gnome.org/show_bug.cgi?id=760263\n\n* HTMLparser.c: Add BASE_PTR convenience macro.\n(htmlParseSystemLiteral): Store length and start position instead\nof a pointer while iterating through the public identifier since\nthe underlying buffer may change, resulting in a stale pointer\nbeing used.\n(htmlParsePubidLiteral): Ditto.\n---\n HTMLparser.c | 58 ++++++++++++++++++++++++++++++++++++++--------------\n 1 file changed, 43 insertions(+), 15 deletions(-)\n\ndiff --git a/HTMLparser.c b/HTMLparser.c\nindex 0985d1d91c..d1395fa507 100644\n--- a/HTMLparser.c\n+++ b/HTMLparser.c\n@@ -303,6 +303,7 @@ htmlNodeInfoPop(htmlParserCtxtPtr ctxt)\n #define UPP(val) (toupper(ctxt->input->cur[(val)]))\n \n #define CUR_PTR ctxt->input->cur\n+#define BASE_PTR ctxt->input->base\n \n #define SHRINK if ((ctxt->input->cur - ctxt->input->base > 2 * INPUT_CHUNK) && \\\n \t\t (ctxt->input->end - ctxt->input->cur < 2 * INPUT_CHUNK)) \\\n@@ -2781,31 +2782,43 @@ htmlParseAttValue(htmlParserCtxtPtr ctxt) {\n \n static xmlChar *\n htmlParseSystemLiteral(htmlParserCtxtPtr ctxt) {\n- const xmlChar *q;\n+ size_t len = 0, startPosition = 0;\n xmlChar *ret = NULL;\n \n if (CUR == '\"') {\n NEXT;\n-\tq = CUR_PTR;\n-\twhile ((IS_CHAR_CH(CUR)) && (CUR != '\"'))\n+\n+ if (CUR_PTR < BASE_PTR)\n+ return(ret);\n+ startPosition = CUR_PTR - BASE_PTR;\n+\n+\twhile ((IS_CHAR_CH(CUR)) && (CUR != '\"')) {\n \t NEXT;\n+\t len++;\n+\t}\n \tif (!IS_CHAR_CH(CUR)) {\n \t htmlParseErr(ctxt, XML_ERR_LITERAL_NOT_FINISHED,\n \t\t\t \"Unfinished SystemLiteral\\n\", NULL, NULL);\n \t} else {\n-\t ret = xmlStrndup(q, CUR_PTR - q);\n+\t ret = xmlStrndup((BASE_PTR+startPosition), len);\n \t NEXT;\n }\n } else if (CUR == '\\'') {\n NEXT;\n-\tq = CUR_PTR;\n-\twhile ((IS_CHAR_CH(CUR)) && (CUR != '\\''))\n+\n+ if (CUR_PTR < BASE_PTR)\n+ return(ret);\n+ startPosition = CUR_PTR - BASE_PTR;\n+\n+\twhile ((IS_CHAR_CH(CUR)) && (CUR != '\\'')) {\n \t NEXT;\n+\t len++;\n+\t}\n \tif (!IS_CHAR_CH(CUR)) {\n \t htmlParseErr(ctxt, XML_ERR_LITERAL_NOT_FINISHED,\n \t\t\t \"Unfinished SystemLiteral\\n\", NULL, NULL);\n \t} else {\n-\t ret = xmlStrndup(q, CUR_PTR - q);\n+\t ret = xmlStrndup((BASE_PTR+startPosition), len);\n \t NEXT;\n }\n } else {\n@@ -2829,32 +2842,47 @@ htmlParseSystemLiteral(htmlParserCtxtPtr ctxt) {\n \n static xmlChar *\n htmlParsePubidLiteral(htmlParserCtxtPtr ctxt) {\n- const xmlChar *q;\n+ size_t len = 0, startPosition = 0;\n xmlChar *ret = NULL;\n /*\n * Name ::= (Letter | '_') (NameChar)*\n */\n if (CUR == '\"') {\n NEXT;\n-\tq = CUR_PTR;\n-\twhile (IS_PUBIDCHAR_CH(CUR)) NEXT;\n+\n+ if (CUR_PTR < BASE_PTR)\n+ return(ret);\n+ startPosition = CUR_PTR - BASE_PTR;\n+\n+ while (IS_PUBIDCHAR_CH(CUR)) {\n+ len++;\n+ NEXT;\n+ }\n+\n \tif (CUR != '\"') {\n \t htmlParseErr(ctxt, XML_ERR_LITERAL_NOT_FINISHED,\n \t \"Unfinished PubidLiteral\\n\", NULL, NULL);\n \t} else {\n-\t ret = xmlStrndup(q, CUR_PTR - q);\n+\t ret = xmlStrndup((BASE_PTR + startPosition), len);\n \t NEXT;\n \t}\n } else if (CUR == '\\'') {\n NEXT;\n-\tq = CUR_PTR;\n-\twhile ((IS_PUBIDCHAR_CH(CUR)) && (CUR != '\\''))\n-\t NEXT;\n+\n+ if (CUR_PTR < BASE_PTR)\n+ return(ret);\n+ startPosition = CUR_PTR - BASE_PTR;\n+\n+ while ((IS_PUBIDCHAR_CH(CUR)) && (CUR != '\\'')){\n+ len++;\n+ NEXT;\n+ }\n+\n \tif (CUR != '\\'') {\n \t htmlParseErr(ctxt, XML_ERR_LITERAL_NOT_FINISHED,\n \t \"Unfinished PubidLiteral\\n\", NULL, NULL);\n \t} else {\n-\t ret = xmlStrndup(q, CUR_PTR - q);\n+\t ret = xmlStrndup((BASE_PTR + startPosition), len);\n \t NEXT;\n \t}\n } else {\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From 11ed4a7a90d5ce156a18980a4ad4e53e77384852 Mon Sep 17 00:00:00 2001\nFrom: Pranjal Jumde \nDate: Wed, 2 Mar 2016 15:52:24 -0800\nSubject: Heap use-after-free in htmlParsePubidLiteral and\n htmlParseSystemiteral\n\nFor https://bugzilla.gnome.org/show_bug.cgi?id=760263\n\n* HTMLparser.c: Add BASE_PTR convenience macro.\n(htmlParseSystemLiteral): Store length and start position instead\nof a pointer while iterating through the public identifier since\nthe underlying buffer may change, resulting in a stale pointer\nbeing used.\n(htmlParsePubidLiteral): Ditto.\n---\n HTMLparser.c | 58 +++++++++++++++++++++++++++++++++++++++++++---------------\n 1 file changed, 43 insertions(+), 15 deletions(-)\n\ndiff --git a/HTMLparser.c b/HTMLparser.c\nindex 0985d1d..d1395fa 100644\n--- a/HTMLparser.c\n+++ b/HTMLparser.c\n@@ -303,6 +303,7 @@ htmlNodeInfoPop(htmlParserCtxtPtr ctxt)\n #define UPP(val) (toupper(ctxt->input->cur[(val)]))\n \n #define CUR_PTR ctxt->input->cur\n+#define BASE_PTR ctxt->input->base\n \n #define SHRINK if ((ctxt->input->cur - ctxt->input->base > 2 * INPUT_CHUNK) && \\\n \t\t (ctxt->input->end - ctxt->input->cur < 2 * INPUT_CHUNK)) \\\n@@ -2781,31 +2782,43 @@ htmlParseAttValue(htmlParserCtxtPtr ctxt) {\n \n static xmlChar *\n htmlParseSystemLiteral(htmlParserCtxtPtr ctxt) {\n- const xmlChar *q;\n+ size_t len = 0, startPosition = 0;\n xmlChar *ret = NULL;\n \n if (CUR == '\"') {\n NEXT;\n-\tq = CUR_PTR;\n-\twhile ((IS_CHAR_CH(CUR)) && (CUR != '\"'))\n+\n+ if (CUR_PTR < BASE_PTR)\n+ return(ret);\n+ startPosition = CUR_PTR - BASE_PTR;\n+\n+\twhile ((IS_CHAR_CH(CUR)) && (CUR != '\"')) {\n \t NEXT;\n+\t len++;\n+\t}\n \tif (!IS_CHAR_CH(CUR)) {\n \t htmlParseErr(ctxt, XML_ERR_LITERAL_NOT_FINISHED,\n \t\t\t \"Unfinished SystemLiteral\\n\", NULL, NULL);\n \t} else {\n-\t ret = xmlStrndup(q, CUR_PTR - q);\n+\t ret = xmlStrndup((BASE_PTR+startPosition), len);\n \t NEXT;\n }\n } else if (CUR == '\\'') {\n NEXT;\n-\tq = CUR_PTR;\n-\twhile ((IS_CHAR_CH(CUR)) && (CUR != '\\''))\n+\n+ if (CUR_PTR < BASE_PTR)\n+ return(ret);\n+ startPosition = CUR_PTR - BASE_PTR;\n+\n+\twhile ((IS_CHAR_CH(CUR)) && (CUR != '\\'')) {\n \t NEXT;\n+\t len++;\n+\t}\n \tif (!IS_CHAR_CH(CUR)) {\n \t htmlParseErr(ctxt, XML_ERR_LITERAL_NOT_FINISHED,\n \t\t\t \"Unfinished SystemLiteral\\n\", NULL, NULL);\n \t} else {\n-\t ret = xmlStrndup(q, CUR_PTR - q);\n+\t ret = xmlStrndup((BASE_PTR+startPosition), len);\n \t NEXT;\n }\n } else {\n@@ -2829,32 +2842,47 @@ htmlParseSystemLiteral(htmlParserCtxtPtr ctxt) {\n \n static xmlChar *\n htmlParsePubidLiteral(htmlParserCtxtPtr ctxt) {\n- const xmlChar *q;\n+ size_t len = 0, startPosition = 0;\n xmlChar *ret = NULL;\n /*\n * Name ::= (Letter | '_') (NameChar)*\n */\n if (CUR == '\"') {\n NEXT;\n-\tq = CUR_PTR;\n-\twhile (IS_PUBIDCHAR_CH(CUR)) NEXT;\n+\n+ if (CUR_PTR < BASE_PTR)\n+ return(ret);\n+ startPosition = CUR_PTR - BASE_PTR;\n+\n+ while (IS_PUBIDCHAR_CH(CUR)) {\n+ len++;\n+ NEXT;\n+ }\n+\n \tif (CUR != '\"') {\n \t htmlParseErr(ctxt, XML_ERR_LITERAL_NOT_FINISHED,\n \t \"Unfinished PubidLiteral\\n\", NULL, NULL);\n \t} else {\n-\t ret = xmlStrndup(q, CUR_PTR - q);\n+\t ret = xmlStrndup((BASE_PTR + startPosition), len);\n \t NEXT;\n \t}\n } else if (CUR == '\\'') {\n NEXT;\n-\tq = CUR_PTR;\n-\twhile ((IS_PUBIDCHAR_CH(CUR)) && (CUR != '\\''))\n-\t NEXT;\n+\n+ if (CUR_PTR < BASE_PTR)\n+ return(ret);\n+ startPosition = CUR_PTR - BASE_PTR;\n+\n+ while ((IS_PUBIDCHAR_CH(CUR)) && (CUR != '\\'')){\n+ len++;\n+ NEXT;\n+ }\n+\n \tif (CUR != '\\'') {\n \t htmlParseErr(ctxt, XML_ERR_LITERAL_NOT_FINISHED,\n \t \"Unfinished PubidLiteral\\n\", NULL, NULL);\n \t} else {\n-\t ret = xmlStrndup(q, CUR_PTR - q);\n+\t ret = xmlStrndup((BASE_PTR + startPosition), len);\n \t NEXT;\n \t}\n } else {\n-- \ncgit v0.12"}], "metadata": {"id": "libxml2-5762-libxml2-2.9.1-CVE-2016-1837.pa", "cve_id": "CVE-2016-4658", "package": "libxml2", "upstream_enriched": true, "upstream_commit": "11ed4a7a90d5ce156a18980a4ad4e53e77384852", "upstream_repo": "GNOME/libxml2", "tier": "adapted", "has_source_context": false, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2012-0113\n\nUnspecified vulnerability in the MySQL Server component in Oracle MySQL 5.1.x and 5.5.x allows remote authenticated users to affect confidentiality and availability via unknown vectors, a different vulnerability than CVE-2012-0118.\n\n## Package\nmariadb\n\n## Files to modify\n- storage/xtradb/ut/ut0ut.c\n- storage/innodb_plugin/ut/ut0ut.c\n- storage/ndb/src/common/util/ndb_init.c\n\n## Upstream Fix\n```diff\nPATCH-P0-HACK-SUSE: Fixing few compilation problems\n\nMostly minor things. Mostly just to make compiler happy as it can't determine\nthat everything is ok. But few things might actually worth reporting as they\ncould be handled better (mostly the write calls).\n\nMaintainer: Michal Hrusecky \n\nIndex: storage/innodb_plugin/ut/ut0ut.c\n===================================================================\n--- storage/innodb_plugin/ut/ut0ut.c.orig\n+++ storage/innodb_plugin/ut/ut0ut.c\n@@ -553,7 +553,9 @@ ut_print_namel(\n \t\t\t\t trx ? trx->mysql_thd : NULL,\n \t\t\t\t table_id);\n \n-\tfwrite(buf, 1, bufend - buf, f);\n+\tif(fwrite(buf, 1, bufend - buf, f) != (size_t)max(0,(bufend - buf))) {\n+\t\tfprintf(stderr, \"fwrite failed in ut_print_namel!!!\\n\");\n+\t}\n }\n \n /**********************************************************************//**\n@@ -574,7 +576,8 @@ ut_copy_file(\n \t\t\t? (size_t) len\n \t\t\t: sizeof buf;\n \t\tsize_t\tsize = fread(buf, 1, maxs, src);\n-\t\tfwrite(buf, 1, size, dest);\n+\t\tif(fwrite(buf, size, 1, dest)is_null())\n- fwrite(\"NULL\", sizeof(char), 4, DBUG_FILE);\n+ if(fwrite(\"NULL\", sizeof(char), 4, DBUG_FILE) != sizeof(char) * 4)\n+ \tbreak;\n \n if (field->type() == MYSQL_TYPE_BIT)\n (void) field->val_int_as_str(&tmp, 1);\n else\n field->val_str(&tmp);\n \n- fwrite(tmp.ptr(),sizeof(char),tmp.length(),DBUG_FILE);\n+ if(fwrite(tmp.ptr(),sizeof(char),tmp.length(),DBUG_FILE) !=\n+ sizeof(char) * tmp.length())\n+ break;\n if (pfield[1])\n- fwrite(\", \", sizeof(char), 2, DBUG_FILE);\n+ if(fwrite(\", \", sizeof(char), 2, DBUG_FILE) != sizeof(char) * 2)\n+ break;\n }\n fprintf(DBUG_FILE, \")\");\n if (print_rowid)\nIndex: sql/opt_range.cc\n===================================================================\n--- sql/opt_range.cc.orig\n+++ sql/opt_range.cc\n@@ -11369,7 +11369,8 @@ print_key(KEY_PART *key_part, const ucha\n {\n if (*key)\n {\n-\tfwrite(\"NULL\",sizeof(char),4,DBUG_FILE);\n+\tif(fwrite(\"NULL\",sizeof(char),4,DBUG_FILE)!=4*sizeof(char))\n+\t break;\n \tcontinue;\n }\n key++;\t\t\t\t\t// Skip null byte\n@@ -11380,7 +11381,8 @@ print_key(KEY_PART *key_part, const ucha\n (void) field->val_int_as_str(&tmp, 1);\n else\n field->val_str(&tmp);\n- fwrite(tmp.ptr(),sizeof(char),tmp.length(),DBUG_FILE);\n+ if(fwrite(tmp.ptr(),sizeof(char),tmp.length(),DBUG_FILE)!=sizeof(char)*tmp.length())\n+ break;\n if (key+store_length < key_end)\n fputc('/',DBUG_FILE);\n }\nIndex: storage/xtradb/ut/ut0ut.c\n===================================================================\n--- storage/xtradb/ut/ut0ut.c.orig\n+++ storage/xtradb/ut/ut0ut.c\n@@ -553,7 +553,9 @@ ut_print_namel(\n \t\t\t\t trx ? trx->mysql_thd : NULL,\n \t\t\t\t table_id);\n \n-\t(void) fwrite(buf, 1, bufend - buf, f);\n+\tif(fwrite(buf, 1, bufend - buf, f) != (size_t)max(0,(bufend - buf))) {\n+\t\tfprintf(stderr, \"fwrite failed in ut_print_namel!!!\\n\");\n+\t}\n }\n \n /**********************************************************************//**\n@@ -574,7 +576,7 @@ ut_copy_file(\n \t\t\t? (size_t) len\n \t\t\t: sizeof buf;\n \t\tsize_t\tsize = fread(buf, 1, maxs, src);\n-\t\t(void) fwrite(buf, 1, size, dest);\n+\t\tsize=fwrite(buf, 1, size, dest);\n \t\tlen -= (long) size;\n \t\tif (size < maxs) {\n \t\t\tbreak;\nIndex: storage/maria/ha_maria.cc\n===================================================================\n--- storage/maria/ha_maria.cc.orig\n+++ storage/maria/ha_maria.cc\n@@ -2789,7 +2789,7 @@ int ha_maria::create(const char *name, r\n HA_CREATE_INFO *ha_create_info)\n {\n int error;\n- uint create_flags= 0, record_count, i;\n+ uint create_flags= 0, record_count=0, i;\n char buff[FN_REFLEN];\n MARIA_KEYDEF *keydef;\n MARIA_COLUMNDEF *recinfo;\nIndex: storage/pbxt/src/discover_xt.cc\n===================================================================\n--- storage/pbxt/src/discover_xt.cc.orig\n+++ storage/pbxt/src/discover_xt.cc\n@@ -1337,8 +1337,8 @@ static bool mysql_create_table_no_lock(T\n char\t\t\tpath[FN_REFLEN];\n uint path_length;\n const char\t*alias;\n- uint\t\t\tdb_options, key_count;\n- KEY\t\t\t*key_info_buffer;\n+ uint\t\t\tdb_options, key_count=0;\n+ KEY\t\t\t*key_info_buffer=NULL;\n handler\t\t*file;\n bool\t\t\terror= TRUE;\n DBUG_ENTER(\"mysql_create_table_no_lock\");\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "PATCH-P0-HACK-SUSE: Fixing few compilation problems\n\nMostly minor things. Mostly just to make compiler happy as it can't determine\nthat everything is ok. But few things might actually worth reporting as they\ncould be handled better (mostly the write calls).\n\nMaintainer: Michal Hrusecky \n\nIndex: storage/innodb_plugin/ut/ut0ut.c\n===================================================================\n--- storage/innodb_plugin/ut/ut0ut.c.orig\n+++ storage/innodb_plugin/ut/ut0ut.c\n@@ -553,7 +553,9 @@ ut_print_namel(\n \t\t\t\t trx ? trx->mysql_thd : NULL,\n \t\t\t\t table_id);\n \n-\tfwrite(buf, 1, bufend - buf, f);\n+\tif(fwrite(buf, 1, bufend - buf, f) != (size_t)max(0,(bufend - buf))) {\n+\t\tfprintf(stderr, \"fwrite failed in ut_print_namel!!!\\n\");\n+\t}\n }\n \n /**********************************************************************//**\n@@ -574,7 +576,8 @@ ut_copy_file(\n \t\t\t? (size_t) len\n \t\t\t: sizeof buf;\n \t\tsize_t\tsize = fread(buf, 1, maxs, src);\n-\t\tfwrite(buf, 1, size, dest);\n+\t\tif(fwrite(buf, size, 1, dest)is_null())\n- fwrite(\"NULL\", sizeof(char), 4, DBUG_FILE);\n+ if(fwrite(\"NULL\", sizeof(char), 4, DBUG_FILE) != sizeof(char) * 4)\n+ \tbreak;\n \n if (field->type() == MYSQL_TYPE_BIT)\n (void) field->val_int_as_str(&tmp, 1);\n else\n field->val_str(&tmp);\n \n- fwrite(tmp.ptr(),sizeof(char),tmp.length(),DBUG_FILE);\n+ if(fwrite(tmp.ptr(),sizeof(char),tmp.length(),DBUG_FILE) !=\n+ sizeof(char) * tmp.length())\n+ break;\n if (pfield[1])\n- fwrite(\", \", sizeof(char), 2, DBUG_FILE);\n+ if(fwrite(\", \", sizeof(char), 2, DBUG_FILE) != sizeof(char) * 2)\n+ break;\n }\n fprintf(DBUG_FILE, \")\");\n if (print_rowid)\nIndex: sql/opt_range.cc\n===================================================================\n--- sql/opt_range.cc.orig\n+++ sql/opt_range.cc\n@@ -11369,7 +11369,8 @@ print_key(KEY_PART *key_part, const ucha\n {\n if (*key)\n {\n-\tfwrite(\"NULL\",sizeof(char),4,DBUG_FILE);\n+\tif(fwrite(\"NULL\",sizeof(char),4,DBUG_FILE)!=4*sizeof(char))\n+\t break;\n \tcontinue;\n }\n key++;\t\t\t\t\t// Skip null byte\n@@ -11380,7 +11381,8 @@ print_key(KEY_PART *key_part, const ucha\n (void) field->val_int_as_str(&tmp, 1);\n else\n field->val_str(&tmp);\n- fwrite(tmp.ptr(),sizeof(char),tmp.length(),DBUG_FILE);\n+ if(fwrite(tmp.ptr(),sizeof(char),tmp.length(),DBUG_FILE)!=sizeof(char)*tmp.length())\n+ break;\n if (key+store_length < key_end)\n fputc('/',DBUG_FILE);\n }\nIndex: storage/xtradb/ut/ut0ut.c\n===================================================================\n--- storage/xtradb/ut/ut0ut.c.orig\n+++ storage/xtradb/ut/ut0ut.c\n@@ -553,7 +553,9 @@ ut_print_namel(\n \t\t\t\t trx ? trx->mysql_thd : NULL,\n \t\t\t\t table_id);\n \n-\t(void) fwrite(buf, 1, bufend - buf, f);\n+\tif(fwrite(buf, 1, bufend - buf, f) != (size_t)max(0,(bufend - buf))) {\n+\t\tfprintf(stderr, \"fwrite failed in ut_print_namel!!!\\n\");\n+\t}\n }\n \n /**********************************************************************//**\n@@ -574,7 +576,7 @@ ut_copy_file(\n \t\t\t? (size_t) len\n \t\t\t: sizeof buf;\n \t\tsize_t\tsize = fread(buf, 1, maxs, src);\n-\t\t(void) fwrite(buf, 1, size, dest);\n+\t\tsize=fwrite(buf, 1, size, dest);\n \t\tlen -= (long) size;\n \t\tif (size < maxs) {\n \t\t\tbreak;\nIndex: storage/maria/ha_maria.cc\n===================================================================\n--- storage/maria/ha_maria.cc.orig\n+++ storage/maria/ha_maria.cc\n@@ -2789,7 +2789,7 @@ int ha_maria::create(const char *name, r\n HA_CREATE_INFO *ha_create_info)\n {\n int error;\n- uint create_flags= 0, record_count, i;\n+ uint create_flags= 0, record_count=0, i;\n char buff[FN_REFLEN];\n MARIA_KEYDEF *keydef;\n MARIA_COLUMNDEF *recinfo;\nIndex: storage/pbxt/src/discover_xt.cc\n===================================================================\n--- storage/pbxt/src/discover_xt.cc.orig\n+++ storage/pbxt/src/discover_xt.cc\n@@ -1337,8 +1337,8 @@ static bool mysql_create_table_no_lock(T\n char\t\t\tpath[FN_REFLEN];\n uint path_length;\n const char\t*alias;\n- uint\t\t\tdb_options, key_count;\n- KEY\t\t\t*key_info_buffer;\n+ uint\t\t\tdb_options, key_count=0;\n+ KEY\t\t\t*key_info_buffer=NULL;\n handler\t\t*file;\n bool\t\t\terror= TRUE;\n DBUG_ENTER(\"mysql_create_table_no_lock\");"}], "metadata": {"id": "mariadb-499-mariadb-5.1.60-compilation-fix", "cve_id": "CVE-2012-0113", "package": "mariadb", "tier": "identical", "has_source_context": false, "license": "GPL-2.0-only"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- ssl/s3_srvr.c\n\n## Target Source Code\n\n### ssl/s3_srvr.c\n\n#### ssl3_get_client_key_exchange() [lines 2126-2912]\n```c\n\treturn(-1);\n\t}\n\nint ssl3_get_client_key_exchange(SSL *s)\n\t{\n\tint i,al,ok;\n\tlong n;\n\tunsigned long alg_k;\n\tunsigned char *p;\n#ifndef OPENSSL_NO_RSA\n\tRSA *rsa=NULL;\n\tEVP_PKEY *pkey=NULL;\n#endif\n#ifndef OPENSSL_NO_DH\n\tBIGNUM *pub=NULL;\n\tDH *dh_srvr;\n#endif\n#ifndef OPENSSL_NO_KRB5\n\tKSSL_ERR kssl_err;\n#endif /* OPENSSL_NO_KRB5 */\n\n#ifndef OPENSSL_NO_ECDH\n\tEC_KEY *srvr_ecdh = NULL;\n\tEVP_PKEY *clnt_pub_pkey = NULL;\n\tEC_POINT *clnt_ecpoint = NULL;\n\tBN_CTX *bn_ctx = NULL; \n#endif\n\n\tn=s->method->ssl_get_message(s,\n\t\tSSL3_ST_SR_KEY_EXCH_A,\n\t\tSSL3_ST_SR_KEY_EXCH_B,\n\t\tSSL3_MT_CLIENT_KEY_EXCHANGE,\n\t\t2048, /* ??? */\n\t\t&ok);\n\n\tif (!ok) return((int)n);\n\tp=(unsigned char *)s->init_msg;\n\n\talg_k=s->s3->tmp.new_cipher->algorithm_mkey;\n\n#ifndef OPENSSL_NO_RSA\n\tif (alg_k & SSL_kRSA)\n\t\t{\n\t\t/* FIX THIS UP EAY EAY EAY EAY */\n\t\tif (s->s3->tmp.use_rsa_tmp)\n\t\t\t{\n\t\t\tif ((s->cert != NULL) && (s->cert->rsa_tmp != NULL))\n\t\t\t\trsa=s->cert->rsa_tmp;\n\t\t\t/* Don't do a callback because rsa_tmp should\n\t\t\t * be sent already */\n\t\t\tif (rsa == NULL)\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_RSA_PKEY);\n\t\t\t\tgoto f_err;\n\n\t\t\t\t}\n\t\t\t}\n/* ... 709 lines omitted ... */\n\t\tgoto f_err;\n\t\t}\n\n\treturn(1);\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,al);\n#if !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_ECDH) || defined(OPENSSL_NO_SRP)\nerr:\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tEVP_PKEY_free(clnt_pub_pkey);\n\tEC_POINT_free(clnt_ecpoint);\n\tif (srvr_ecdh != NULL) \n\t\tEC_KEY_free(srvr_ecdh);\n\tBN_CTX_free(bn_ctx);\n#endif\n\treturn(-1);\n\t}\n\nint ssl3_get_cert_verify(SSL *s)\n```\n\n\n## Upstream Fix\n```diff\nFrom adb46dbc6dd7347750df2468c93e8c34bcb93a4b Mon Sep 17 00:00:00 2001\nFrom: Adam Langley \nDate: Wed, 24 Apr 2013 14:45:44 -0400\nSubject: [PATCH] This change alters the processing of invalid, RSA pre-master\n secrets so that bad encryptions are treated like random session keys in\n constant time.\n\n---\n ssl/s3_srvr.c | 134 +++++++++++++++++++++++++++++++++-----------------\n 1 file changed, 89 insertions(+), 45 deletions(-)\n\ndiff --git a/ssl/s3_srvr.c b/ssl/s3_srvr.c\nindex ea4e132d979ca..28d5bed483f85 100644\n--- a/ssl/s3_srvr.c\n+++ b/ssl/s3_srvr.c\n@@ -2195,6 +2195,10 @@ int ssl3_get_client_key_exchange(SSL *s)\n #ifndef OPENSSL_NO_RSA\n \tif (alg_k & SSL_kRSA)\n \t\t{\n+\t\tunsigned char rand_premaster_secret[SSL_MAX_MASTER_KEY_LENGTH];\n+\t\tint decrypt_len, decrypt_good_mask;\n+\t\tunsigned char version_good;\n+\n \t\t/* FIX THIS UP EAY EAY EAY EAY */\n \t\tif (s->s3->tmp.use_rsa_tmp)\n \t\t\t{\n@@ -2242,54 +2246,94 @@ int ssl3_get_client_key_exchange(SSL *s)\n \t\t\t\tn=i;\n \t\t\t}\n \n-\t\ti=RSA_private_decrypt((int)n,p,p,rsa,RSA_PKCS1_PADDING);\n-\n-\t\tal = -1;\n-\t\t\n-\t\tif (i != SSL_MAX_MASTER_KEY_LENGTH)\n-\t\t\t{\n-\t\t\tal=SSL_AD_DECODE_ERROR;\n-\t\t\t/* SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_DECRYPT); */\n-\t\t\t}\n-\n-\t\tif ((al == -1) && !((p[0] == (s->client_version>>8)) && (p[1] == (s->client_version & 0xff))))\n-\t\t\t{\n-\t\t\t/* The premaster secret must contain the same version number as the\n-\t\t\t * ClientHello to detect version rollback attacks (strangely, the\n-\t\t\t * protocol does not offer such protection for DH ciphersuites).\n-\t\t\t * However, buggy clients exist that send the negotiated protocol\n-\t\t\t * version instead if the server does not support the requested\n-\t\t\t * protocol version.\n-\t\t\t * If SSL_OP_TLS_ROLLBACK_BUG is set, tolerate such clients. */\n-\t\t\tif (!((s->options & SSL_OP_TLS_ROLLBACK_BUG) &&\n-\t\t\t\t(p[0] == (s->version>>8)) && (p[1] == (s->version & 0xff))))\n-\t\t\t\t{\n-\t\t\t\tal=SSL_AD_DECODE_ERROR;\n-\t\t\t\t/* SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_PROTOCOL_VERSION_NUMBER); */\n+\t\t/* We must not leak whether a decryption failure occurs because\n+\t\t * of Bleichenbacher's attack on PKCS #1 v1.5 RSA padding (see\n+\t\t * RFC 2246, section 7.4.7.1). The code follows that advice of\n+\t\t * the TLS RFC and generates a random premaster secret for the\n+\t\t * case that the decrypt fails. See\n+\t\t * https://tools.ietf.org/html/rfc5246#section-7.4.7.1 */\n \n-\t\t\t\t/* The Klima-Pokorny-Rosa extension of Bleichenbacher's attack\n-\t\t\t\t * (http://eprint.iacr.org/2003/052/) exploits the version\n-\t\t\t\t * number check as a \"bad version oracle\" -- an alert would\n-\t\t\t\t * reveal that the plaintext corresponding to some ciphertext\n-\t\t\t\t * made up by the adversary is properly formatted except\n-\t\t\t\t * that the version number is wrong. To avoid such attacks,\n-\t\t\t\t * we should treat this just like any other decryption error. */\n-\t\t\t\t}\n+\t\t/* should be RAND_bytes, but we cannot work around a failure. */\n+\t\tif (RAND_pseudo_bytes(rand_premaster_secret,\n+\t\t\t\t sizeof(rand_premaster_secret)) <= 0)\n+\t\t\tgoto err;\n+\t\tdecrypt_len = RSA_private_decrypt((int)n,p,p,rsa,RSA_PKCS1_PADDING);\n+\t\tERR_clear_error();\n+\n+\t\t/* decrypt_len should be SSL_MAX_MASTER_KEY_LENGTH.\n+\t\t * decrypt_good_mask will be zero if so and non-zero otherwise. */\n+\t\tdecrypt_good_mask = decrypt_len ^ SSL_MAX_MASTER_KEY_LENGTH;\n+\n+\t\t/* If the version in the decrypted pre-master secret is correct\n+\t\t * then version_good will be zero. The Klima-Pokorny-Rosa\n+\t\t * extension of Bleichenbacher's attack\n+\t\t * (http://eprint.iacr.org/2003/052/) exploits the version\n+\t\t * number check as a \"bad version oracle\". Thus version checks\n+\t\t * are done in constant time and are treated like any other\n+\t\t * decryption error. */\n+\t\tversion_good = p[0] ^ (s->client_version>>8);\n+\t\tversion_good |= p[1] ^ (s->client_version&0xff);\n+\n+\t\t/* The premaster secret must contain the same version number as\n+\t\t * the ClientHello to detect version rollback attacks\n+\t\t * (strangely, the protocol does not offer such protection for\n+\t\t * DH ciphersuites). However, buggy clients exist that send the\n+\t\t * negotiated protocol version instead if the server does not\n+\t\t * support the requested protocol version. If\n+\t\t * SSL_OP_TLS_ROLLBACK_BUG is set, tolerate such clients. */\n+\t\tif (s->options & SSL_OP_TLS_ROLLBACK_BUG)\n+\t\t\t{\n+\t\t\tunsigned char workaround_mask = version_good;\n+\t\t\tunsigned char workaround;\n+\n+\t\t\t/* workaround_mask will be 0xff if version_good is\n+\t\t\t * non-zero (i.e. the version match failed). Otherwise\n+\t\t\t * it'll be 0x00. */\n+\t\t\tworkaround_mask |= workaround_mask >> 4;\n+\t\t\tworkaround_mask |= workaround_mask >> 2;\n+\t\t\tworkaround_mask |= workaround_mask >> 1;\n+\t\t\tworkaround_mask = ~((workaround_mask & 1) - 1);\n+\n+\t\t\tworkaround = p[0] ^ (s->version>>8);\n+\t\t\tworkaround |= p[1] ^ (s->version&0xff);\n+\n+\t\t\t/* If workaround_mask is 0xff (i.e. there was a version\n+\t\t\t * mismatch) then we copy the value of workaround over\n+\t\t\t * version_good. */\n+\t\t\tversion_good = (workaround & workaround_mask) |\n+\t\t\t\t (version_good & ~workaround_mask);\n+\t\t\t}\n+\n+\t\t/* If any bits in version_good are set then they'll poision\n+\t\t * decrypt_good_mask and cause rand_premaster_secret to be\n+\t\t * used. */\n+\t\tdecrypt_good_mask |= version_good;\n+\n+\t\t/* decrypt_good_mask will be zero iff decrypt_len ==\n+\t\t * SSL_MAX_MASTER_KEY_LENGTH and the version check passed. We\n+\t\t * fold the bottom 32 bits of it with an OR so that the LSB\n+\t\t * will be zero iff everything is good. This assumes that we'll\n+\t\t * never decrypt a value > 2**31 bytes, which seems safe. */\n+\t\tdecrypt_good_mask |= decrypt_good_mask >> 16;\n+\t\tdecrypt_good_mask |= decrypt_good_mask >> 8;\n+\t\tdecrypt_good_mask |= decrypt_good_mask >> 4;\n+\t\tdecrypt_good_mask |= decrypt_good_mask >> 2;\n+\t\tdecrypt_good_mask |= decrypt_good_mask >> 1;\n+\t\t/* Now select only the LSB and subtract one. If decrypt_len ==\n+\t\t * SSL_MAX_MASTER_KEY_LENGTH and the version check passed then\n+\t\t * decrypt_good_mask will be all ones. Otherwise it'll be all\n+\t\t * zeros. */\n+\t\tdecrypt_good_mask &= 1;\n+\t\tdecrypt_good_mask--;\n+\n+\t\t/* Now copy rand_premaster_secret over p using\n+\t\t * decrypt_good_mask. */\n+\t\tfor (i = 0; i < (int) sizeof(rand_premaster_secret); i++)\n+\t\t\t{\n+\t\t\tp[i] = (p[i] & decrypt_good_mask) |\n+\t\t\t (rand_premaster_secret[i] & ~decrypt_good_mask);\n \t\t\t}\n \n-\t\tif (al != -1)\n-\t\t\t{\n-\t\t\t/* Some decryption failure -- use random value instead as countermeasure\n-\t\t\t * against Bleichenbacher's attack on PKCS #1 v1.5 RSA padding\n-\t\t\t * (see RFC 2246, section 7.4.7.1). */\n-\t\t\tERR_clear_error();\n-\t\t\ti = SSL_MAX_MASTER_KEY_LENGTH;\n-\t\t\tp[0] = s->client_version >> 8;\n-\t\t\tp[1] = s->client_version & 0xff;\n-\t\t\tif (RAND_pseudo_bytes(p+2, i-2) <= 0) /* should be RAND_bytes, but we cannot work around a failure */\n-\t\t\t\tgoto err;\n-\t\t\t}\n-\t\n \t\ts->session->master_key_length=\n \t\t\ts->method->ssl3_enc->generate_master_secret(s,\n \t\t\t\ts->session->master_key,\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "commit 133145686e054a28f78b94e8a996ef7ae13d30b7\nAuthor: Adam Langley \nDate: Wed Apr 24 14:45:44 2013 -0400\n\n This change alters the processing of invalid, RSA pre-master secrets so\n that bad encryptions are treated like random session keys in constant\n time.\n \n (cherry picked from commit adb46dbc6dd7347750df2468c93e8c34bcb93a4b)\n \n Reviewed-by: Rich Salz \n\ndiff --git a/ssl/s3_srvr.c b/ssl/s3_srvr.c\nindex c907f2b..127185a 100644\n--- a/ssl/s3_srvr.c\n+++ b/ssl/s3_srvr.c\n@@ -2167,6 +2167,10 @@ int ssl3_get_client_key_exchange(SSL *s)\n #ifndef OPENSSL_NO_RSA\n \tif (alg_k & SSL_kRSA)\n \t\t{\n+\t\tunsigned char rand_premaster_secret[SSL_MAX_MASTER_KEY_LENGTH];\n+\t\tint decrypt_len, decrypt_good_mask;\n+\t\tunsigned char version_good;\n+\n \t\t/* FIX THIS UP EAY EAY EAY EAY */\n \t\tif (s->s3->tmp.use_rsa_tmp)\n \t\t\t{\n@@ -2214,54 +2218,94 @@ int ssl3_get_client_key_exchange(SSL *s)\n \t\t\t\tn=i;\n \t\t\t}\n \n-\t\ti=RSA_private_decrypt((int)n,p,p,rsa,RSA_PKCS1_PADDING);\n-\n-\t\tal = -1;\n-\t\t\n-\t\tif (i != SSL_MAX_MASTER_KEY_LENGTH)\n-\t\t\t{\n-\t\t\tal=SSL_AD_DECODE_ERROR;\n-\t\t\t/* SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_DECRYPT); */\n-\t\t\t}\n-\n-\t\tif ((al == -1) && !((p[0] == (s->client_version>>8)) && (p[1] == (s->client_version & 0xff))))\n-\t\t\t{\n-\t\t\t/* The premaster secret must contain the same version number as the\n-\t\t\t * ClientHello to detect version rollback attacks (strangely, the\n-\t\t\t * protocol does not offer such protection for DH ciphersuites).\n-\t\t\t * However, buggy clients exist that send the negotiated protocol\n-\t\t\t * version instead if the server does not support the requested\n-\t\t\t * protocol version.\n-\t\t\t * If SSL_OP_TLS_ROLLBACK_BUG is set, tolerate such clients. */\n-\t\t\tif (!((s->options & SSL_OP_TLS_ROLLBACK_BUG) &&\n-\t\t\t\t(p[0] == (s->version>>8)) && (p[1] == (s->version & 0xff))))\n-\t\t\t\t{\n-\t\t\t\tal=SSL_AD_DECODE_ERROR;\n-\t\t\t\t/* SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_PROTOCOL_VERSION_NUMBER); */\n+\t\t/* We must not leak whether a decryption failure occurs because\n+\t\t * of Bleichenbacher's attack on PKCS #1 v1.5 RSA padding (see\n+\t\t * RFC 2246, section 7.4.7.1). The code follows that advice of\n+\t\t * the TLS RFC and generates a random premaster secret for the\n+\t\t * case that the decrypt fails. See\n+\t\t * https://tools.ietf.org/html/rfc5246#section-7.4.7.1 */\n \n-\t\t\t\t/* The Klima-Pokorny-Rosa extension of Bleichenbacher's attack\n-\t\t\t\t * (http://eprint.iacr.org/2003/052/) exploits the version\n-\t\t\t\t * number check as a \"bad version oracle\" -- an alert would\n-\t\t\t\t * reveal that the plaintext corresponding to some ciphertext\n-\t\t\t\t * made up by the adversary is properly formatted except\n-\t\t\t\t * that the version number is wrong. To avoid such attacks,\n-\t\t\t\t * we should treat this just like any other decryption error. */\n-\t\t\t\t}\n+\t\t/* should be RAND_bytes, but we cannot work around a failure. */\n+\t\tif (RAND_pseudo_bytes(rand_premaster_secret,\n+\t\t\t\t sizeof(rand_premaster_secret)) <= 0)\n+\t\t\tgoto err;\n+\t\tdecrypt_len = RSA_private_decrypt((int)n,p,p,rsa,RSA_PKCS1_PADDING);\n+\t\tERR_clear_error();\n+\n+\t\t/* decrypt_len should be SSL_MAX_MASTER_KEY_LENGTH.\n+\t\t * decrypt_good_mask will be zero if so and non-zero otherwise. */\n+\t\tdecrypt_good_mask = decrypt_len ^ SSL_MAX_MASTER_KEY_LENGTH;\n+\n+\t\t/* If the version in the decrypted pre-master secret is correct\n+\t\t * then version_good will be zero. The Klima-Pokorny-Rosa\n+\t\t * extension of Bleichenbacher's attack\n+\t\t * (http://eprint.iacr.org/2003/052/) exploits the version\n+\t\t * number check as a \"bad version oracle\". Thus version checks\n+\t\t * are done in constant time and are treated like any other\n+\t\t * decryption error. */\n+\t\tversion_good = p[0] ^ (s->client_version>>8);\n+\t\tversion_good |= p[1] ^ (s->client_version&0xff);\n+\n+\t\t/* The premaster secret must contain the same version number as\n+\t\t * the ClientHello to detect version rollback attacks\n+\t\t * (strangely, the protocol does not offer such protection for\n+\t\t * DH ciphersuites). However, buggy clients exist that send the\n+\t\t * negotiated protocol version instead if the server does not\n+\t\t * support the requested protocol version. If\n+\t\t * SSL_OP_TLS_ROLLBACK_BUG is set, tolerate such clients. */\n+\t\tif (s->options & SSL_OP_TLS_ROLLBACK_BUG)\n+\t\t\t{\n+\t\t\tunsigned char workaround_mask = version_good;\n+\t\t\tunsigned char workaround;\n+\n+\t\t\t/* workaround_mask will be 0xff if version_good is\n+\t\t\t * non-zero (i.e. the version match failed). Otherwise\n+\t\t\t * it'll be 0x00. */\n+\t\t\tworkaround_mask |= workaround_mask >> 4;\n+\t\t\tworkaround_mask |= workaround_mask >> 2;\n+\t\t\tworkaround_mask |= workaround_mask >> 1;\n+\t\t\tworkaround_mask = ~((workaround_mask & 1) - 1);\n+\n+\t\t\tworkaround = p[0] ^ (s->version>>8);\n+\t\t\tworkaround |= p[1] ^ (s->version&0xff);\n+\n+\t\t\t/* If workaround_mask is 0xff (i.e. there was a version\n+\t\t\t * mismatch) then we copy the value of workaround over\n+\t\t\t * version_good. */\n+\t\t\tversion_good = (workaround & workaround_mask) |\n+\t\t\t\t (version_good & ~workaround_mask);\n+\t\t\t}\n+\n+\t\t/* If any bits in version_good are set then they'll poision\n+\t\t * decrypt_good_mask and cause rand_premaster_secret to be\n+\t\t * used. */\n+\t\tdecrypt_good_mask |= version_good;\n+\n+\t\t/* decrypt_good_mask will be zero iff decrypt_len ==\n+\t\t * SSL_MAX_MASTER_KEY_LENGTH and the version check passed. We\n+\t\t * fold the bottom 32 bits of it with an OR so that the LSB\n+\t\t * will be zero iff everything is good. This assumes that we'll\n+\t\t * never decrypt a value > 2**31 bytes, which seems safe. */\n+\t\tdecrypt_good_mask |= decrypt_good_mask >> 16;\n+\t\tdecrypt_good_mask |= decrypt_good_mask >> 8;\n+\t\tdecrypt_good_mask |= decrypt_good_mask >> 4;\n+\t\tdecrypt_good_mask |= decrypt_good_mask >> 2;\n+\t\tdecrypt_good_mask |= decrypt_good_mask >> 1;\n+\t\t/* Now select only the LSB and subtract one. If decrypt_len ==\n+\t\t * SSL_MAX_MASTER_KEY_LENGTH and the version check passed then\n+\t\t * decrypt_good_mask will be all ones. Otherwise it'll be all\n+\t\t * zeros. */\n+\t\tdecrypt_good_mask &= 1;\n+\t\tdecrypt_good_mask--;\n+\n+\t\t/* Now copy rand_premaster_secret over p using\n+\t\t * decrypt_good_mask. */\n+\t\tfor (i = 0; i < (int) sizeof(rand_premaster_secret); i++)\n+\t\t\t{\n+\t\t\tp[i] = (p[i] & decrypt_good_mask) |\n+\t\t\t (rand_premaster_secret[i] & ~decrypt_good_mask);\n \t\t\t}\n \n-\t\tif (al != -1)\n-\t\t\t{\n-\t\t\t/* Some decryption failure -- use random value instead as countermeasure\n-\t\t\t * against Bleichenbacher's attack on PKCS #1 v1.5 RSA padding\n-\t\t\t * (see RFC 2246, section 7.4.7.1). */\n-\t\t\tERR_clear_error();\n-\t\t\ti = SSL_MAX_MASTER_KEY_LENGTH;\n-\t\t\tp[0] = s->client_version >> 8;\n-\t\t\tp[1] = s->client_version & 0xff;\n-\t\t\tif (RAND_pseudo_bytes(p+2, i-2) <= 0) /* should be RAND_bytes, but we cannot work around a failure */\n-\t\t\t\tgoto err;\n-\t\t\t}\n-\t\n \t\ts->session->master_key_length=\n \t\t\ts->method->ssl3_enc->generate_master_secret(s,\n \t\t\t\ts->session->master_key,"}], "metadata": {"id": "openssl-4769-openssl-RSA_premaster_secret_i", "cve_id": "CVE-2015-3197", "package": "openssl", "upstream_enriched": true, "upstream_commit": "adb46dbc6dd7347750df2468c93e8c34bcb93a4b", "upstream_repo": "openssl/openssl", "tier": "adapted", "has_source_context": true, "context_tokens_est": 423, "context_files": 1, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-6250\n\nInteger overflow in the ISO9660 writer in libarchive before 3.2.1 allows remote attackers to cause a denial of service (application crash) or execute arbitrary code via vectors related to verifying filename lengths when writing an ISO9660 archive, which trigger a buffer overflow.\n\n## Package\nlibarchive\n\n## Files to modify\n- libarchive-3.1.2.orig/libarchive/archive_read_support_format_rar.c\n- libarchive/test/test_read_format_rar_invalid1.c\n- libarchive/archive_read_support_format_rar.c\n\n## Target Source Code\n\n### Makefile.am\n\n#### region() [lines 374-460]\n```c\n\tlibarchive/test/test_read_format_7zip.c\t\t\t\\\n\tlibarchive/test/test_read_format_ar.c\t\t\t\\\n\tlibarchive/test/test_read_format_cab.c\t\t\t\\\n\tlibarchive/test/test_read_format_cab_filename.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_afio.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin_Z.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin_be.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin_bz2.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin_gz.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin_lzip.c\t\\\n\tlibarchive/test/test_read_format_cpio_bin_lzma.c\t\\\n\tlibarchive/test/test_read_format_cpio_bin_xz.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_filename.c\t\\\n\tlibarchive/test/test_read_format_cpio_odc.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_svr4_bzip2_rpm.c\t\\\n\tlibarchive/test/test_read_format_cpio_svr4_gzip.c\t\\\n\tlibarchive/test/test_read_format_cpio_svr4_gzip_rpm.c\t\\\n\tlibarchive/test/test_read_format_cpio_svr4c_Z.c\t\t\\\n\tlibarchive/test/test_read_format_empty.c\t\t\\\n\tlibarchive/test/test_read_format_gtar_filename.c\t\\\n\tlibarchive/test/test_read_format_gtar_gz.c\t\t\\\n\tlibarchive/test/test_read_format_gtar_lzma.c\t\t\\\n\tlibarchive/test/test_read_format_gtar_sparse.c\t\t\\\n\tlibarchive/test/test_read_format_iso_Z.c\t\t\\\n\tlibarchive/test/test_read_format_iso_multi_extent.c\t\\\n\tlibarchive/test/test_read_format_iso_xorriso.c\t\t\\\n\tlibarchive/test/test_read_format_isojoliet_bz2.c\t\\\n\tlibarchive/test/test_read_format_isojoliet_long.c\t\\\n\tlibarchive/test/test_read_format_isojoliet_rr.c\t\t\\\n\tlibarchive/test/test_read_format_isojoliet_versioned.c\t\\\n\tlibarchive/test/test_read_format_isorr_bz2.c\t\t\\\n\tlibarchive/test/test_read_format_isorr_ce.c\t\t\\\n\tlibarchive/test/test_read_format_isorr_new_bz2.c\t\\\n\tlibarchive/test/test_read_format_isorr_rr_moved.c\t\\\n\tlibarchive/test/test_read_format_isozisofs_bz2.c\t\\\n\tlibarchive/test/test_read_format_lha.c\t\t\t\\\n\tlibarchive/test/test_read_format_lha_filename.c\t\t\\\n\tlibarchive/test/test_read_format_mtree.c\t\t\\\n\tlibarchive/test/test_read_format_pax_bz2.c\t\t\\\n\tlibarchive/test/test_read_format_rar.c\t\t\t\\\n\tlibarchive/test/test_read_format_raw.c\t\t\t\\\n\tlibarchive/test/test_read_format_tar.c\t\t\t\\\n\tlibarchive/test/test_read_format_tar_empty_filename.c\t\\\n\tlibarchive/test/test_read_format_tar_filename.c\t\t\\\n\tlibarchive/test/test_read_format_tbz.c\t\t\t\\\n\tlibarchive/test/test_read_format_tgz.c\t\t\t\\\n\tlibarchive/test/test_read_format_tlz.c\t\t\t\\\n\tlibarchive/test/test_read_format_txz.c\t\t\t\\\n\tlibarchive/test/test_read_format_tz.c\t\t\t\\\n\tlibarchive/test/test_read_format_ustar_filename.c\t\\\n\tlibarchive/test/test_read_format_xar.c\t\t\t\\\n\tlibarchive/test/test_read_format_zip.c\t\t\t\\\n\tlibarchive/test/test_read_format_zip_comment_stored.c\t\\\n\tlibarchive/test/test_read_format_zip_filename.c\t\t\\\n\tlibarchive/test/test_read_format_zip_mac_metadata.c\t\\\n\tlibarchive/test/test_read_format_zip_sfx.c\t\t\\\n\tlibarchive/test/test_read_large.c\t\t\t\\\n\tlibarchive/test/test_read_pax_truncated.c\t\t\\\n\tlibarchive/test/test_read_position.c\t\t\t\\\n\tlibarchive/test/test_read_set_format.c\t\t\t\\\n\tlibarchive/test/test_read_truncated.c\t\t\t\\\n\tlibarchive/test/test_read_truncated_filter.c\t\t\\\n\tlibarchive/test/test_sparse_basic.c\t\t\t\\\n\tlibarchive/test/test_t\n/* ... truncated ... */\n```\n\n### libarchive/archive_read_support_format_rar.c\n\n#### copy_from_lzss_window() [lines 2781-2829]\n```c\n}\n\nstatic int\ncopy_from_lzss_window(struct archive_read *a, const void **buffer,\n int64_t startpos, int length)\n{\n int windowoffs, firstpart;\n struct rar *rar = (struct rar *)(a->format->data);\n\n if (!rar->unp_buffer)\n {\n if ((rar->unp_buffer = malloc(rar->unp_buffer_size)) == NULL)\n {\n archive_set_error(&a->archive, ENOMEM,\n \"Unable to allocate memory for uncompressed data.\");\n return (ARCHIVE_FATAL);\n }\n }\n\n windowoffs = lzss_offset_for_position(&rar->lzss, startpos);\n if(windowoffs + length <= lzss_size(&rar->lzss))\n memcpy(&rar->unp_buffer[rar->unp_offset], &rar->lzss.window[windowoffs],\n length);\n else\n {\n firstpart = lzss_size(&rar->lzss) - windowoffs;\n if (firstpart < 0) {\n archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,\n \"Bad RAR file data\");\n return (ARCHIVE_FATAL);\n }\n if (firstpart < length) {\n memcpy(&rar->unp_buffer[rar->unp_offset],\n &rar->lzss.window[windowoffs], firstpart);\n memcpy(&rar->unp_buffer[rar->unp_offset + firstpart],\n &rar->lzss.window[0], length - firstpart);\n } else\n memcpy(&rar->unp_buffer[rar->unp_offset],\n &rar->lzss.window[windowoffs], length);\n }\n rar->unp_offset += length;\n if (rar->unp_offset >= rar->unp_buffer_size)\n *buffer = rar->unp_buffer;\n else\n *buffer = NULL;\n return (ARCHIVE_OK);\n}\n\nstatic const void *\n```\n\n\n### Type definitions\n\n```c\n/* from archive_private.h */\nstruct archive {\n\t/*\n\t * The magic/state values are used to sanity-check the\n\t * client's usage. If an API function is called at a\n\t * ridiculous time, or the client passes us an invalid\n\t * pointer, these values allow me to catch that.\n\t */\n\tunsigned int\tmagic;\n\tunsigned int\tstate;\n\n\t/*\n\t * Some public API functions depend on the \"real\" type of the\n\t * archive object.\n\t */\n\tstruct archive_vtable *vtable;\n\n\tint\t\t archive_format;\n\tconst char\t *archive_format_name;\n\n\tint\t compression_code;\t/* Currently active compression. */\n\tconst char *compression_name;\n\n\t/* Number of file entries processed. */\n\tint\t\t file_count;\n\n\tint\t\t archive_error_number;\n\tconst char\t *error;\n\tstruct archive_string\terror_string;\n\n\tchar *current_code;\n\tunsigned current_codepage; /* Current ACP(ANSI CodePage). */\n\tunsigned current_oemcp; /* Current OEMCP(OEM CodePage). */\n\tstruct archive_string_conv *sconv;\n};\n```\n\n\n## Upstream Fix\n```diff\ncommit 603454ec03040c29bd051fcc749e3c1433c11a8e\nAuthor: Tim Kientzle \nDate: Sun Jun 19 15:31:46 2016 -0700\n\n Issue 521: Properly check reading from lzss decompression buffer\n \n Prior code could be tricked into trying to copy data\n from beyond the end of the internal decompression buffer.\n \n Thanks to Hanno Böck for his ongoing fuzz-testing work with libarchive.\n\nIndex: libarchive-3.1.2/Makefile.am\n===================================================================\n--- libarchive-3.1.2.orig/Makefile.am\n+++ libarchive-3.1.2/Makefile.am\n@@ -413,6 +413,7 @@ libarchive_test_SOURCES=\t\t\t\t\t\\\n \tlibarchive/test/test_read_format_mtree.c\t\t\\\n \tlibarchive/test/test_read_format_pax_bz2.c\t\t\\\n \tlibarchive/test/test_read_format_rar.c\t\t\t\\\n+\tlibarchive/test/test_read_format_rar_invalid1.c\t\t\\\n \tlibarchive/test/test_read_format_raw.c\t\t\t\\\n \tlibarchive/test/test_read_format_tar.c\t\t\t\\\n \tlibarchive/test/test_read_format_tar_empty_filename.c\t\\\nIndex: libarchive-3.1.2/libarchive/archive_read_support_format_rar.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_read_support_format_rar.c\n+++ libarchive-3.1.2/libarchive/archive_read_support_format_rar.c\n@@ -2798,11 +2798,10 @@ copy_from_lzss_window(struct archive_rea\n }\n \n windowoffs = lzss_offset_for_position(&rar->lzss, startpos);\n- if(windowoffs + length <= lzss_size(&rar->lzss))\n+ if(windowoffs + length <= lzss_size(&rar->lzss)) {\n memcpy(&rar->unp_buffer[rar->unp_offset], &rar->lzss.window[windowoffs],\n length);\n- else\n- {\n+ } else if (length <= lzss_size(&rar->lzss)) {\n firstpart = lzss_size(&rar->lzss) - windowoffs;\n if (firstpart < 0) {\n archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,\n@@ -2814,9 +2813,14 @@ copy_from_lzss_window(struct archive_rea\n &rar->lzss.window[windowoffs], firstpart);\n memcpy(&rar->unp_buffer[rar->unp_offset + firstpart],\n &rar->lzss.window[0], length - firstpart);\n- } else\n+ } else {\n memcpy(&rar->unp_buffer[rar->unp_offset],\n &rar->lzss.window[windowoffs], length);\n+ }\n+ } else {\n+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,\n+ \"Bad RAR file data\");\n+ return (ARCHIVE_FATAL);\n }\n rar->unp_offset += length;\n if (rar->unp_offset >= rar->unp_buffer_size)\nIndex: libarchive-3.1.2/libarchive/test/test_read_format_rar_invalid1.c\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_format_rar_invalid1.c\n@@ -0,0 +1,44 @@\n+/*-\n+ * Copyright (c) 2003-2016 Tim Kientzle\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ * 1. Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in the\n+ * documentation and/or other materials provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR\n+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,\n+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+#include \"test.h\"\n+__FBSDID(\"$FreeBSD$\");\n+\n+DEFINE_TEST(test_read_format_rar_invalid1)\n+{\n+\tconst char *refname = \"test_read_format_rar_invalid1.rar\";\n+\tstruct archive *a;\n+\tstruct archive_entry *ae;\n+\tchar *buff[100];\n+\n+\textract_reference_file(refname);\n+\tassert((a = archive_read_new()) != NULL);\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 10240));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));\n+\tassertEqualIntA(a, ARCHIVE_FATAL, archive_read_data(a, buff, 99));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));\n+\tassertEqualInt(ARCHIVE_OK, archive_read_free(a));\n+}\nIndex: libarchive-3.1.2/libarchive/test/test_read_format_rar_invalid1.rar.uu\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_format_rar_invalid1.rar.uu\n@@ -0,0 +1,5 @@\n+begin 644 test_read_format_rar_invalid1.rar\n+M4F%R(1H'`,^0\nDate: Sun Jun 19 15:31:46 2016 -0700\n\n Issue 521: Properly check reading from lzss decompression buffer\n \n Prior code could be tricked into trying to copy data\n from beyond the end of the internal decompression buffer.\n \n Thanks to Hanno Böck for his ongoing fuzz-testing work with libarchive.\n\nIndex: libarchive-3.1.2/Makefile.am\n===================================================================\n--- libarchive-3.1.2.orig/Makefile.am\n+++ libarchive-3.1.2/Makefile.am\n@@ -413,6 +413,7 @@ libarchive_test_SOURCES=\t\t\t\t\t\\\n \tlibarchive/test/test_read_format_mtree.c\t\t\\\n \tlibarchive/test/test_read_format_pax_bz2.c\t\t\\\n \tlibarchive/test/test_read_format_rar.c\t\t\t\\\n+\tlibarchive/test/test_read_format_rar_invalid1.c\t\t\\\n \tlibarchive/test/test_read_format_raw.c\t\t\t\\\n \tlibarchive/test/test_read_format_tar.c\t\t\t\\\n \tlibarchive/test/test_read_format_tar_empty_filename.c\t\\\nIndex: libarchive-3.1.2/libarchive/archive_read_support_format_rar.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_read_support_format_rar.c\n+++ libarchive-3.1.2/libarchive/archive_read_support_format_rar.c\n@@ -2798,11 +2798,10 @@ copy_from_lzss_window(struct archive_rea\n }\n \n windowoffs = lzss_offset_for_position(&rar->lzss, startpos);\n- if(windowoffs + length <= lzss_size(&rar->lzss))\n+ if(windowoffs + length <= lzss_size(&rar->lzss)) {\n memcpy(&rar->unp_buffer[rar->unp_offset], &rar->lzss.window[windowoffs],\n length);\n- else\n- {\n+ } else if (length <= lzss_size(&rar->lzss)) {\n firstpart = lzss_size(&rar->lzss) - windowoffs;\n if (firstpart < 0) {\n archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,\n@@ -2814,9 +2813,14 @@ copy_from_lzss_window(struct archive_rea\n &rar->lzss.window[windowoffs], firstpart);\n memcpy(&rar->unp_buffer[rar->unp_offset + firstpart],\n &rar->lzss.window[0], length - firstpart);\n- } else\n+ } else {\n memcpy(&rar->unp_buffer[rar->unp_offset],\n &rar->lzss.window[windowoffs], length);\n+ }\n+ } else {\n+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,\n+ \"Bad RAR file data\");\n+ return (ARCHIVE_FATAL);\n }\n rar->unp_offset += length;\n if (rar->unp_offset >= rar->unp_buffer_size)\nIndex: libarchive-3.1.2/libarchive/test/test_read_format_rar_invalid1.c\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_format_rar_invalid1.c\n@@ -0,0 +1,44 @@\n+/*-\n+ * Copyright (c) 2003-2016 Tim Kientzle\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ * 1. Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in the\n+ * documentation and/or other materials provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR\n+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,\n+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+#include \"test.h\"\n+__FBSDID(\"$FreeBSD$\");\n+\n+DEFINE_TEST(test_read_format_rar_invalid1)\n+{\n+\tconst char *refname = \"test_read_format_rar_invalid1.rar\";\n+\tstruct archive *a;\n+\tstruct archive_entry *ae;\n+\tchar *buff[100];\n+\n+\textract_reference_file(refname);\n+\tassert((a = archive_read_new()) != NULL);\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 10240));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));\n+\tassertEqualIntA(a, ARCHIVE_FATAL, archive_read_data(a, buff, 99));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));\n+\tassertEqualInt(ARCHIVE_OK, archive_read_free(a));\n+}\nIndex: libarchive-3.1.2/libarchive/test/test_read_format_rar_invalid1.rar.uu\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_format_rar_invalid1.rar.uu\n@@ -0,0 +1,5 @@\n+begin 644 test_read_format_rar_invalid1.rar\n+M4F%R(1H'`,^0B$4=\n+2,P0`I($``'1E\nDate: Sun, 10 Jun 2012 14:58:54 +0000\nSubject: use setoverprintmode only if rip knows it\n\n---\n(limited to 'poppler/PSOutputDev.cc')\n\ndiff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc\nindex dac10d0..c655652 100644\n--- a/poppler/PSOutputDev.cc\n+++ b/poppler/PSOutputDev.cc\n@@ -258,7 +258,7 @@ static const char *prolog[] = {\n \"} def\",\n \"~3n\",\n \"/opm { dup /pdfOPM exch def\",\n- \" setoverprintmode } def\",\n+ \" /setoverprintmode where{pop setoverprintmode}{pop}ifelse } def\",\n \"~23n\",\n \"/cs { /pdfFillXform exch def dup /pdfFillCS exch def\",\n \" setcolorspace } def\",\n@@ -292,7 +292,7 @@ static const char *prolog[] = {\n \"} def\",\n \"~3s\",\n \"/opm { dup /pdfOPM exch def\",\n- \" setoverprintmode } def\",\n+ \" /setoverprintmode where{pop setoverprintmode}{pop}ifelse } def\",\n \"~23s\",\n \"/k { 4 copy 4 array astore /pdfFill exch def setcmykcolor\",\n \" /pdfLastFill true def /pdfLastStroke false def } def\",\n@@ -390,7 +390,7 @@ static const char *prolog[] = {\n \"~3sn\",\n \" /pdfOPM where {\",\n \" pop\",\n- \" pdfOPM setoverprintmode\",\n+ \" pdfOPM /setoverprintmode where{pop setoverprintmode}{pop}ifelse \",\n \" } if\",\n \"~23sn\",\n \"} def\",\n--\ncgit v0.9.0.2-2-gbebe\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From 92ef16e3699da949c80716c3fd4b438fe79c134d Mon Sep 17 00:00:00 2001\nFrom: Thomas Freitag \nDate: Sun, 10 Jun 2012 14:58:54 +0000\nSubject: use setoverprintmode only if rip knows it\n\n---\n(limited to 'poppler/PSOutputDev.cc')\n\ndiff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc\nindex dac10d0..c655652 100644\n--- a/poppler/PSOutputDev.cc\n+++ b/poppler/PSOutputDev.cc\n@@ -258,7 +258,7 @@ static const char *prolog[] = {\n \"} def\",\n \"~3n\",\n \"/opm { dup /pdfOPM exch def\",\n- \" setoverprintmode } def\",\n+ \" /setoverprintmode where{pop setoverprintmode}{pop}ifelse } def\",\n \"~23n\",\n \"/cs { /pdfFillXform exch def dup /pdfFillCS exch def\",\n \" setcolorspace } def\",\n@@ -292,7 +292,7 @@ static const char *prolog[] = {\n \"} def\",\n \"~3s\",\n \"/opm { dup /pdfOPM exch def\",\n- \" setoverprintmode } def\",\n+ \" /setoverprintmode where{pop setoverprintmode}{pop}ifelse } def\",\n \"~23s\",\n \"/k { 4 copy 4 array astore /pdfFill exch def setcmykcolor\",\n \" /pdfLastFill true def /pdfLastStroke false def } def\",\n@@ -390,7 +390,7 @@ static const char *prolog[] = {\n \"~3sn\",\n \" /pdfOPM where {\",\n \" pop\",\n- \" pdfOPM setoverprintmode\",\n+ \" pdfOPM /setoverprintmode where{pop setoverprintmode}{pop}ifelse \",\n \" } if\",\n \"~23sn\",\n \"} def\",\n--\ncgit v0.9.0.2-2-gbebe"}], "metadata": {"id": "poppler-qt-1943-poppler-fix-postscript-error-s", "cve_id": "CVE-2012-2142", "package": "poppler-qt", "tier": "identical", "has_source_context": false, "license": "GPL-2.0-only OR GPL-3.0-only"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-6250\n\nInteger overflow in the ISO9660 writer in libarchive before 3.2.1 allows remote attackers to cause a denial of service (application crash) or execute arbitrary code via vectors related to verifying filename lengths when writing an ISO9660 archive, which trigger a buffer overflow.\n\n## Package\nlibarchive\n\n## Files to modify\n- libarchive-3.1.2.orig/libarchive/archive_read_support_format_rar.c\n- libarchive/test/test_read_format_rar_invalid1.c\n- libarchive/archive_read_support_format_rar.c\n\n## Target Source Code\n\n### Makefile.am\n\n#### region() [lines 374-460]\n```c\n\tlibarchive/test/test_read_format_7zip.c\t\t\t\\\n\tlibarchive/test/test_read_format_ar.c\t\t\t\\\n\tlibarchive/test/test_read_format_cab.c\t\t\t\\\n\tlibarchive/test/test_read_format_cab_filename.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_afio.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin_Z.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin_be.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin_bz2.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin_gz.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin_lzip.c\t\\\n\tlibarchive/test/test_read_format_cpio_bin_lzma.c\t\\\n\tlibarchive/test/test_read_format_cpio_bin_xz.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_filename.c\t\\\n\tlibarchive/test/test_read_format_cpio_odc.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_svr4_bzip2_rpm.c\t\\\n\tlibarchive/test/test_read_format_cpio_svr4_gzip.c\t\\\n\tlibarchive/test/test_read_format_cpio_svr4_gzip_rpm.c\t\\\n\tlibarchive/test/test_read_format_cpio_svr4c_Z.c\t\t\\\n\tlibarchive/test/test_read_format_empty.c\t\t\\\n\tlibarchive/test/test_read_format_gtar_filename.c\t\\\n\tlibarchive/test/test_read_format_gtar_gz.c\t\t\\\n\tlibarchive/test/test_read_format_gtar_lzma.c\t\t\\\n\tlibarchive/test/test_read_format_gtar_sparse.c\t\t\\\n\tlibarchive/test/test_read_format_iso_Z.c\t\t\\\n\tlibarchive/test/test_read_format_iso_multi_extent.c\t\\\n\tlibarchive/test/test_read_format_iso_xorriso.c\t\t\\\n\tlibarchive/test/test_read_format_isojoliet_bz2.c\t\\\n\tlibarchive/test/test_read_format_isojoliet_long.c\t\\\n\tlibarchive/test/test_read_format_isojoliet_rr.c\t\t\\\n\tlibarchive/test/test_read_format_isojoliet_versioned.c\t\\\n\tlibarchive/test/test_read_format_isorr_bz2.c\t\t\\\n\tlibarchive/test/test_read_format_isorr_ce.c\t\t\\\n\tlibarchive/test/test_read_format_isorr_new_bz2.c\t\\\n\tlibarchive/test/test_read_format_isorr_rr_moved.c\t\\\n\tlibarchive/test/test_read_format_isozisofs_bz2.c\t\\\n\tlibarchive/test/test_read_format_lha.c\t\t\t\\\n\tlibarchive/test/test_read_format_lha_filename.c\t\t\\\n\tlibarchive/test/test_read_format_mtree.c\t\t\\\n\tlibarchive/test/test_read_format_pax_bz2.c\t\t\\\n\tlibarchive/test/test_read_format_rar.c\t\t\t\\\n\tlibarchive/test/test_read_format_raw.c\t\t\t\\\n\tlibarchive/test/test_read_format_tar.c\t\t\t\\\n\tlibarchive/test/test_read_format_tar_empty_filename.c\t\\\n\tlibarchive/test/test_read_format_tar_filename.c\t\t\\\n\tlibarchive/test/test_read_format_tbz.c\t\t\t\\\n\tlibarchive/test/test_read_format_tgz.c\t\t\t\\\n\tlibarchive/test/test_read_format_tlz.c\t\t\t\\\n\tlibarchive/test/test_read_format_txz.c\t\t\t\\\n\tlibarchive/test/test_read_format_tz.c\t\t\t\\\n\tlibarchive/test/test_read_format_ustar_filename.c\t\\\n\tlibarchive/test/test_read_format_xar.c\t\t\t\\\n\tlibarchive/test/test_read_format_zip.c\t\t\t\\\n\tlibarchive/test/test_read_format_zip_comment_stored.c\t\\\n\tlibarchive/test/test_read_format_zip_filename.c\t\t\\\n\tlibarchive/test/test_read_format_zip_mac_metadata.c\t\\\n\tlibarchive/test/test_read_format_zip_sfx.c\t\t\\\n\tlibarchive/test/test_read_large.c\t\t\t\\\n\tlibarchive/test/test_read_pax_truncated.c\t\t\\\n\tlibarchive/test/test_read_position.c\t\t\t\\\n\tlibarchive/test/test_read_set_format.c\t\t\t\\\n\tlibarchive/test/test_read_truncated.c\t\t\t\\\n\tlibarchive/test/test_read_truncated_filter.c\t\t\\\n\tlibarchive/test/test_sparse_basic.c\t\t\t\\\n\tlibarchive/test/test_t\n/* ... truncated ... */\n```\n\n### libarchive/archive_read_support_format_rar.c\n\n#### copy_from_lzss_window() [lines 2781-2829]\n```c\n}\n\nstatic int\ncopy_from_lzss_window(struct archive_read *a, const void **buffer,\n int64_t startpos, int length)\n{\n int windowoffs, firstpart;\n struct rar *rar = (struct rar *)(a->format->data);\n\n if (!rar->unp_buffer)\n {\n if ((rar->unp_buffer = malloc(rar->unp_buffer_size)) == NULL)\n {\n archive_set_error(&a->archive, ENOMEM,\n \"Unable to allocate memory for uncompressed data.\");\n return (ARCHIVE_FATAL);\n }\n }\n\n windowoffs = lzss_offset_for_position(&rar->lzss, startpos);\n if(windowoffs + length <= lzss_size(&rar->lzss))\n memcpy(&rar->unp_buffer[rar->unp_offset], &rar->lzss.window[windowoffs],\n length);\n else\n {\n firstpart = lzss_size(&rar->lzss) - windowoffs;\n if (firstpart < 0) {\n archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,\n \"Bad RAR file data\");\n return (ARCHIVE_FATAL);\n }\n if (firstpart < length) {\n memcpy(&rar->unp_buffer[rar->unp_offset],\n &rar->lzss.window[windowoffs], firstpart);\n memcpy(&rar->unp_buffer[rar->unp_offset + firstpart],\n &rar->lzss.window[0], length - firstpart);\n } else\n memcpy(&rar->unp_buffer[rar->unp_offset],\n &rar->lzss.window[windowoffs], length);\n }\n rar->unp_offset += length;\n if (rar->unp_offset >= rar->unp_buffer_size)\n *buffer = rar->unp_buffer;\n else\n *buffer = NULL;\n return (ARCHIVE_OK);\n}\n\nstatic const void *\n```\n\n\n### Type definitions\n\n```c\n/* from archive_private.h */\nstruct archive {\n\t/*\n\t * The magic/state values are used to sanity-check the\n\t * client's usage. If an API function is called at a\n\t * ridiculous time, or the client passes us an invalid\n\t * pointer, these values allow me to catch that.\n\t */\n\tunsigned int\tmagic;\n\tunsigned int\tstate;\n\n\t/*\n\t * Some public API functions depend on the \"real\" type of the\n\t * archive object.\n\t */\n\tstruct archive_vtable *vtable;\n\n\tint\t\t archive_format;\n\tconst char\t *archive_format_name;\n\n\tint\t compression_code;\t/* Currently active compression. */\n\tconst char *compression_name;\n\n\t/* Number of file entries processed. */\n\tint\t\t file_count;\n\n\tint\t\t archive_error_number;\n\tconst char\t *error;\n\tstruct archive_string\terror_string;\n\n\tchar *current_code;\n\tunsigned current_codepage; /* Current ACP(ANSI CodePage). */\n\tunsigned current_oemcp; /* Current OEMCP(OEM CodePage). */\n\tstruct archive_string_conv *sconv;\n};\n```\n\n\n## Upstream Fix\n```diff\ncommit 603454ec03040c29bd051fcc749e3c1433c11a8e\nAuthor: Tim Kientzle \nDate: Sun Jun 19 15:31:46 2016 -0700\n\n Issue 521: Properly check reading from lzss decompression buffer\n \n Prior code could be tricked into trying to copy data\n from beyond the end of the internal decompression buffer.\n \n Thanks to Hanno Böck for his ongoing fuzz-testing work with libarchive.\n\nIndex: libarchive-3.1.2/Makefile.am\n===================================================================\n--- libarchive-3.1.2.orig/Makefile.am\n+++ libarchive-3.1.2/Makefile.am\n@@ -413,6 +413,7 @@ libarchive_test_SOURCES=\t\t\t\t\t\\\n \tlibarchive/test/test_read_format_mtree.c\t\t\\\n \tlibarchive/test/test_read_format_pax_bz2.c\t\t\\\n \tlibarchive/test/test_read_format_rar.c\t\t\t\\\n+\tlibarchive/test/test_read_format_rar_invalid1.c\t\t\\\n \tlibarchive/test/test_read_format_raw.c\t\t\t\\\n \tlibarchive/test/test_read_format_tar.c\t\t\t\\\n \tlibarchive/test/test_read_format_tar_empty_filename.c\t\\\nIndex: libarchive-3.1.2/libarchive/archive_read_support_format_rar.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_read_support_format_rar.c\n+++ libarchive-3.1.2/libarchive/archive_read_support_format_rar.c\n@@ -2798,11 +2798,10 @@ copy_from_lzss_window(struct archive_rea\n }\n \n windowoffs = lzss_offset_for_position(&rar->lzss, startpos);\n- if(windowoffs + length <= lzss_size(&rar->lzss))\n+ if(windowoffs + length <= lzss_size(&rar->lzss)) {\n memcpy(&rar->unp_buffer[rar->unp_offset], &rar->lzss.window[windowoffs],\n length);\n- else\n- {\n+ } else if (length <= lzss_size(&rar->lzss)) {\n firstpart = lzss_size(&rar->lzss) - windowoffs;\n if (firstpart < 0) {\n archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,\n@@ -2814,9 +2813,14 @@ copy_from_lzss_window(struct archive_rea\n &rar->lzss.window[windowoffs], firstpart);\n memcpy(&rar->unp_buffer[rar->unp_offset + firstpart],\n &rar->lzss.window[0], length - firstpart);\n- } else\n+ } else {\n memcpy(&rar->unp_buffer[rar->unp_offset],\n &rar->lzss.window[windowoffs], length);\n+ }\n+ } else {\n+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,\n+ \"Bad RAR file data\");\n+ return (ARCHIVE_FATAL);\n }\n rar->unp_offset += length;\n if (rar->unp_offset >= rar->unp_buffer_size)\nIndex: libarchive-3.1.2/libarchive/test/test_read_format_rar_invalid1.c\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_format_rar_invalid1.c\n@@ -0,0 +1,44 @@\n+/*-\n+ * Copyright (c) 2003-2016 Tim Kientzle\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ * 1. Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in the\n+ * documentation and/or other materials provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR\n+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,\n+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+#include \"test.h\"\n+__FBSDID(\"$FreeBSD$\");\n+\n+DEFINE_TEST(test_read_format_rar_invalid1)\n+{\n+\tconst char *refname = \"test_read_format_rar_invalid1.rar\";\n+\tstruct archive *a;\n+\tstruct archive_entry *ae;\n+\tchar *buff[100];\n+\n+\textract_reference_file(refname);\n+\tassert((a = archive_read_new()) != NULL);\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 10240));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));\n+\tassertEqualIntA(a, ARCHIVE_FATAL, archive_read_data(a, buff, 99));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));\n+\tassertEqualInt(ARCHIVE_OK, archive_read_free(a));\n+}\nIndex: libarchive-3.1.2/libarchive/test/test_read_format_rar_invalid1.rar.uu\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_format_rar_invalid1.rar.uu\n@@ -0,0 +1,5 @@\n+begin 644 test_read_format_rar_invalid1.rar\n+M4F%R(1H'`,^0\nDate: Sun Jun 19 15:31:46 2016 -0700\n\n Issue 521: Properly check reading from lzss decompression buffer\n \n Prior code could be tricked into trying to copy data\n from beyond the end of the internal decompression buffer.\n \n Thanks to Hanno Böck for his ongoing fuzz-testing work with libarchive.\n\nIndex: libarchive-3.1.2/Makefile.am\n===================================================================\n--- libarchive-3.1.2.orig/Makefile.am\n+++ libarchive-3.1.2/Makefile.am\n@@ -413,6 +413,7 @@ libarchive_test_SOURCES=\t\t\t\t\t\\\n \tlibarchive/test/test_read_format_mtree.c\t\t\\\n \tlibarchive/test/test_read_format_pax_bz2.c\t\t\\\n \tlibarchive/test/test_read_format_rar.c\t\t\t\\\n+\tlibarchive/test/test_read_format_rar_invalid1.c\t\t\\\n \tlibarchive/test/test_read_format_raw.c\t\t\t\\\n \tlibarchive/test/test_read_format_tar.c\t\t\t\\\n \tlibarchive/test/test_read_format_tar_empty_filename.c\t\\\nIndex: libarchive-3.1.2/libarchive/archive_read_support_format_rar.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_read_support_format_rar.c\n+++ libarchive-3.1.2/libarchive/archive_read_support_format_rar.c\n@@ -2798,11 +2798,10 @@ copy_from_lzss_window(struct archive_rea\n }\n \n windowoffs = lzss_offset_for_position(&rar->lzss, startpos);\n- if(windowoffs + length <= lzss_size(&rar->lzss))\n+ if(windowoffs + length <= lzss_size(&rar->lzss)) {\n memcpy(&rar->unp_buffer[rar->unp_offset], &rar->lzss.window[windowoffs],\n length);\n- else\n- {\n+ } else if (length <= lzss_size(&rar->lzss)) {\n firstpart = lzss_size(&rar->lzss) - windowoffs;\n if (firstpart < 0) {\n archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,\n@@ -2814,9 +2813,14 @@ copy_from_lzss_window(struct archive_rea\n &rar->lzss.window[windowoffs], firstpart);\n memcpy(&rar->unp_buffer[rar->unp_offset + firstpart],\n &rar->lzss.window[0], length - firstpart);\n- } else\n+ } else {\n memcpy(&rar->unp_buffer[rar->unp_offset],\n &rar->lzss.window[windowoffs], length);\n+ }\n+ } else {\n+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,\n+ \"Bad RAR file data\");\n+ return (ARCHIVE_FATAL);\n }\n rar->unp_offset += length;\n if (rar->unp_offset >= rar->unp_buffer_size)\nIndex: libarchive-3.1.2/libarchive/test/test_read_format_rar_invalid1.c\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_format_rar_invalid1.c\n@@ -0,0 +1,44 @@\n+/*-\n+ * Copyright (c) 2003-2016 Tim Kientzle\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ * 1. Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in the\n+ * documentation and/or other materials provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR\n+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,\n+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+#include \"test.h\"\n+__FBSDID(\"$FreeBSD$\");\n+\n+DEFINE_TEST(test_read_format_rar_invalid1)\n+{\n+\tconst char *refname = \"test_read_format_rar_invalid1.rar\";\n+\tstruct archive *a;\n+\tstruct archive_entry *ae;\n+\tchar *buff[100];\n+\n+\textract_reference_file(refname);\n+\tassert((a = archive_read_new()) != NULL);\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 10240));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));\n+\tassertEqualIntA(a, ARCHIVE_FATAL, archive_read_data(a, buff, 99));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));\n+\tassertEqualInt(ARCHIVE_OK, archive_read_free(a));\n+}\nIndex: libarchive-3.1.2/libarchive/test/test_read_format_rar_invalid1.rar.uu\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_format_rar_invalid1.rar.uu\n@@ -0,0 +1,5 @@\n+begin 644 test_read_format_rar_invalid1.rar\n+M4F%R(1H'`,^0B$4=\n+2,P0`I($``'1E\ncommitter: Amos Jeffries \nbranch nick: 3.3\ntimestamp: Thu 2016-03-31 03:16:06 +1300\nmessage:\n pinger: Fix buffer overflow in Icmp6::Recv\n------------------------------------------------------------\n# Bazaar merge directive format 2 (Bazaar 0.90)\n# revision_id: squid3@treenet.co.nz-20160330141606-19rqzzip0grq9a77\n# target_branch: http://bzr.squid-cache.org/bzr/squid3/3.3\n# testament_sha1: 0d5d026b8b9e62ec11be84c9b2a81060c8b1ca02\n# timestamp: 2016-03-30 14:50:53 +0000\n# source_branch: http://bzr.squid-cache.org/bzr/squid3/3.3\n# base_revision_id: squid3@treenet.co.nz-20150828132515-\\\n# nvi7c9u05ih9t77y\n# \n# Begin patch\n=== modified file 'src/icmp/Icmp6.cc'\n--- src/icmp/Icmp6.cc\t2014-09-15 05:07:44 +0000\n+++ src/icmp/Icmp6.cc\t2016-03-30 14:16:06 +0000\n@@ -277,7 +277,7 @@\n #define ip6_hops\t// HOPS!!! (can it be true??)\n \n ip = (struct ip6_hdr *) pkt;\n- pkt += sizeof(ip6_hdr);\n+ NP: echo size needs to +sizeof(ip6_hdr);\n \n debugs(42, DBG_CRITICAL, HERE << \"ip6_nxt=\" << ip->ip6_nxt <<\n \t\t\", ip6_plen=\" << ip->ip6_plen <<\n@@ -288,7 +288,6 @@\n */\n \n icmp6header = (struct icmp6_hdr *) pkt;\n- pkt += sizeof(icmp6_hdr);\n \n if (icmp6header->icmp6_type != ICMP6_ECHO_REPLY) {\n \n@@ -313,7 +312,7 @@\n return;\n }\n \n- echo = (icmpEchoData *) pkt;\n+ echo = (icmpEchoData *) (pkt + sizeof(icmp6_hdr));\n \n preply.opcode = echo->opcode;\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "------------------------------------------------------------\nrevno: 12694\nrevision-id: squid3@treenet.co.nz-20160330141606-19rqzzip0grq9a77\nparent: squid3@treenet.co.nz-20150828132515-nvi7c9u05ih9t77y\nauthor: Yuriy M. Kaminskiy \ncommitter: Amos Jeffries \nbranch nick: 3.3\ntimestamp: Thu 2016-03-31 03:16:06 +1300\nmessage:\n pinger: Fix buffer overflow in Icmp6::Recv\n------------------------------------------------------------\n# Bazaar merge directive format 2 (Bazaar 0.90)\n# revision_id: squid3@treenet.co.nz-20160330141606-19rqzzip0grq9a77\n# target_branch: http://bzr.squid-cache.org/bzr/squid3/3.3\n# testament_sha1: 0d5d026b8b9e62ec11be84c9b2a81060c8b1ca02\n# timestamp: 2016-03-30 14:50:53 +0000\n# source_branch: http://bzr.squid-cache.org/bzr/squid3/3.3\n# base_revision_id: squid3@treenet.co.nz-20150828132515-\\\n# nvi7c9u05ih9t77y\n# \n# Begin patch\n=== modified file 'src/icmp/Icmp6.cc'\n--- src/icmp/Icmp6.cc\t2014-09-15 05:07:44 +0000\n+++ src/icmp/Icmp6.cc\t2016-03-30 14:16:06 +0000\n@@ -277,7 +277,7 @@\n #define ip6_hops\t// HOPS!!! (can it be true??)\n \n ip = (struct ip6_hdr *) pkt;\n- pkt += sizeof(ip6_hdr);\n+ NP: echo size needs to +sizeof(ip6_hdr);\n \n debugs(42, DBG_CRITICAL, HERE << \"ip6_nxt=\" << ip->ip6_nxt <<\n \t\t\", ip6_plen=\" << ip->ip6_plen <<\n@@ -288,7 +288,6 @@\n */\n \n icmp6header = (struct icmp6_hdr *) pkt;\n- pkt += sizeof(icmp6_hdr);\n \n if (icmp6header->icmp6_type != ICMP6_ECHO_REPLY) {\n \n@@ -313,7 +312,7 @@\n return;\n }\n \n- echo = (icmpEchoData *) pkt;\n+ echo = (icmpEchoData *) (pkt + sizeof(icmp6_hdr));\n \n preply.opcode = echo->opcode;"}], "metadata": {"id": "squid-5473-SQUID_2016_3.patch", "cve_id": "CVE-2015-3455", "package": "squid", "tier": "identical", "has_source_context": false, "license": "GPL-2.0-or-later"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-4658\n\nxpointer.c in libxml2 before 2.9.5 (as used in Apple iOS before 10, OS X before 10.12, tvOS before 10, and watchOS before 3, and other products) does not forbid namespace nodes in XPointer ranges, which allows remote attackers to execute arbitrary code or cause a denial of service (use-after-free and memory corruption) via a crafted XML document.\n\n## Package\nlibxml2\n\n## Files to modify\n- parser.c\n\n## Target Source Code\n\n### parser.c\n\n#### xmlStringLenDecodeEntities() [lines 2767-2853]\n```c\nhtmlParseSystemLiteral(htmlParserCtxtPtr ctxt) {\n const xmlChar *q;\n xmlChar *ret = NULL;\n\n if (CUR == '\"') {\n NEXT;\n\tq = CUR_PTR;\n\twhile ((IS_CHAR_CH(CUR)) && (CUR != '\"'))\n\t NEXT;\n\tif (!IS_CHAR_CH(CUR)) {\n\t htmlParseErr(ctxt, XML_ERR_LITERAL_NOT_FINISHED,\n\t\t\t \"Unfinished SystemLiteral\\n\", NULL, NULL);\n\t} else {\n\t ret = xmlStrndup(q, CUR_PTR - q);\n\t NEXT;\n }\n } else if (CUR == '\\'') {\n NEXT;\n\tq = CUR_PTR;\n\twhile ((IS_CHAR_CH(CUR)) && (CUR != '\\''))\n\t NEXT;\n\tif (!IS_CHAR_CH(CUR)) {\n\t htmlParseErr(ctxt, XML_ERR_LITERAL_NOT_FINISHED,\n\t\t\t \"Unfinished SystemLiteral\\n\", NULL, NULL);\n\t} else {\n\t ret = xmlStrndup(q, CUR_PTR - q);\n\t NEXT;\n }\n } else {\n\thtmlParseErr(ctxt, XML_ERR_LITERAL_NOT_STARTED,\n\t \" or ' expected\\n\", NULL, NULL);\n }\n\n return(ret);\n}\n\n/**\n * htmlParsePubidLiteral:\n * @ctxt: an HTML parser context\n *\n * parse an HTML public literal\n *\n * [12] PubidLiteral ::= '\"' PubidChar* '\"' | \"'\" (PubidChar - \"'\")* \"'\"\n *\n * Returns the PubidLiteral parsed or NULL.\n */\n\nstatic xmlChar *\nhtmlParsePubidLiteral(htmlParserCtxtPtr ctxt) {\n const xmlChar *q;\n xmlChar *ret = NULL;\n /*\n * Name ::= (Letter | '_') (NameChar)*\n */\n if (CUR == '\"') {\n NEXT;\n\tq = CUR_PTR;\n\twhile (IS_PUBIDCHAR_CH(CUR)) NEXT;\n\tif (CUR != '\"') {\n\t htmlParseErr(ctxt, XML_ERR_LITERAL_NOT_FINISHED,\n\t \"Unfinished PubidLiteral\\n\", NULL, NULL);\n\t} else {\n\t ret = xmlStrndup(q, CUR_PTR - q);\n\t NEXT;\n\t}\n } else if (CUR == '\\'') {\n NEXT;\n\tq = CUR_PTR;\n\twhile ((IS_PUBIDCHAR_CH(CUR)) && (CUR != '\\''))\n\t NEXT;\n\tif (CUR != '\\'') {\n\t htmlParseErr(ctxt, XML_ERR_LITERAL_NOT_FINISHED,\n\t \"Unfinished PubidLiteral\\n\", NULL, NULL);\n\t} else {\n\t ret = xmlStrndup(q, CUR_PTR - q);\n\t NEXT;\n\t}\n } else {\n\thtmlParseErr(ctxt, XML_ERR_LITERAL_NOT_STARTED,\n\t \"PubidLiteral \\\" or ' expected\\n\", NULL, NULL);\n }\n\n return(ret);\n}\n\n/**\n * htmlParseScript:\n```\n\n\n## Upstream Fix\n```diff\nFrom 69030714cde66d525a8884bda01b9e8f0abf8e1e Mon Sep 17 00:00:00 2001\nFrom: David Drysdale \nDate: Fri, 20 Nov 2015 11:13:45 +0800\nSubject: [PATCH] CVE-2015-5312 Another entity expansion issue\n\nFor https://bugzilla.gnome.org/show_bug.cgi?id=756733\nIt is one case where the code in place to detect entities expansions\nfailed to exit when the situation was detected, leading to DoS\nProblem reported by Kostya Serebryany @ Google\nPatch provided by David Drysdale @ Google\n---\n parser.c | 4 ++++\n 1 file changed, 4 insertions(+)\n\ndiff --git a/parser.c b/parser.c\nindex b7b6668286..da6e7292dc 100644\n--- a/parser.c\n+++ b/parser.c\n@@ -2806,6 +2806,10 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int len,\n \t\t\t 0, 0, 0);\n \t\tctxt->depth--;\n \n+\t\tif ((ctxt->lastError.code == XML_ERR_ENTITY_LOOP) ||\n+\t\t (ctxt->lastError.code == XML_ERR_INTERNAL_ERROR))\n+\t\t goto int_error;\n+\n \t\tif (rep != NULL) {\n \t\t current = rep;\n \t\t while (*current != 0) { /* non input consuming loop */\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From 69030714cde66d525a8884bda01b9e8f0abf8e1e Mon Sep 17 00:00:00 2001\nFrom: David Drysdale \nDate: Fri, 20 Nov 2015 11:13:45 +0800\nSubject: CVE-2015-5312 Another entity expansion issue\n\nFor https://bugzilla.gnome.org/show_bug.cgi?id=756733\nIt is one case where the code in place to detect entities expansions\nfailed to exit when the situation was detected, leading to DoS\nProblem reported by Kostya Serebryany @ Google\nPatch provided by David Drysdale @ Google\n---\n parser.c | 4 ++++\n 1 file changed, 4 insertions(+)\n\ndiff --git a/parser.c b/parser.c\nindex b7b6668..da6e729 100644\n--- a/parser.c\n+++ b/parser.c\n@@ -2806,6 +2806,10 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int len,\n \t\t\t 0, 0, 0);\n \t\tctxt->depth--;\n \n+\t\tif ((ctxt->lastError.code == XML_ERR_ENTITY_LOOP) ||\n+\t\t (ctxt->lastError.code == XML_ERR_INTERNAL_ERROR))\n+\t\t goto int_error;\n+\n \t\tif (rep != NULL) {\n \t\t current = rep;\n \t\t while (*current != 0) { /* non input consuming loop */\n-- \ncgit v0.11.2"}], "metadata": {"id": "libxml2-5762-libxml2-2.9.1-CVE-2015-5312.pa", "cve_id": "CVE-2016-4658", "package": "libxml2", "upstream_enriched": true, "upstream_commit": "69030714cde66d525a8884bda01b9e8f0abf8e1e", "upstream_repo": "GNOME/libxml2", "tier": "adapted", "has_source_context": true, "context_tokens_est": 521, "context_files": 1, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-4658\n\nxpointer.c in libxml2 before 2.9.5 (as used in Apple iOS before 10, OS X before 10.12, tvOS before 10, and watchOS before 3, and other products) does not forbid namespace nodes in XPointer ranges, which allows remote attackers to execute arbitrary code or cause a denial of service (use-after-free and memory corruption) via a crafted XML document.\n\n## Package\nlibxml2\n\n## Files to modify\n- xmlsave.c\n\n## Upstream Fix\n```diff\nFrom c97750d11bb8b6f3303e7131fe526a61ac65bcfd Mon Sep 17 00:00:00 2001\nFrom: Daniel Veillard \nDate: Mon, 23 May 2016 13:39:13 +0800\nSubject: [PATCH] Avoid an out of bound access when serializing malformed\n strings\n\nFor https://bugzilla.gnome.org/show_bug.cgi?id=766414\n\n* xmlsave.c: xmlBufAttrSerializeTxtContent() if an attribute value\n is not UTF-8 be more careful when serializing it as we may do an\n out of bound access as a result.\n---\n xmlsave.c | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/xmlsave.c b/xmlsave.c\nindex 774404b884..4a8e3f3903 100644\n--- a/xmlsave.c\n+++ b/xmlsave.c\n@@ -2097,8 +2097,8 @@ xmlBufAttrSerializeTxtContent(xmlBufPtr buf, xmlDocPtr doc,\n xmlBufAdd(buf, BAD_CAST \"&\", 5);\n cur++;\n base = cur;\n- } else if ((*cur >= 0x80) && ((doc == NULL) ||\n- (doc->encoding == NULL))) {\n+ } else if ((*cur >= 0x80) && (cur[1] != 0) &&\n+\t ((doc == NULL) || (doc->encoding == NULL))) {\n /*\n * We assume we have UTF-8 content.\n */\n@@ -2121,14 +2121,14 @@ xmlBufAttrSerializeTxtContent(xmlBufPtr buf, xmlDocPtr doc,\n val <<= 6;\n val |= (cur[1]) & 0x3F;\n l = 2;\n- } else if (*cur < 0xF0) {\n+ } else if ((*cur < 0xF0) && (cur [2] != 0)) {\n val = (cur[0]) & 0x0F;\n val <<= 6;\n val |= (cur[1]) & 0x3F;\n val <<= 6;\n val |= (cur[2]) & 0x3F;\n l = 3;\n- } else if (*cur < 0xF8) {\n+ } else if ((*cur < 0xF8) && (cur [2] != 0) && (cur[3] != 0)) {\n val = (cur[0]) & 0x07;\n val <<= 6;\n val |= (cur[1]) & 0x3F;\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From c97750d11bb8b6f3303e7131fe526a61ac65bcfd Mon Sep 17 00:00:00 2001\nFrom: Daniel Veillard \nDate: Mon, 23 May 2016 13:39:13 +0800\nSubject: Avoid an out of bound access when serializing malformed strings\n\nFor https://bugzilla.gnome.org/show_bug.cgi?id=766414\n\n* xmlsave.c: xmlBufAttrSerializeTxtContent() if an attribute value\n is not UTF-8 be more careful when serializing it as we may do an\n out of bound access as a result.\n---\n xmlsave.c | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/xmlsave.c b/xmlsave.c\nindex 774404b..4a8e3f3 100644\n--- a/xmlsave.c\n+++ b/xmlsave.c\n@@ -2097,8 +2097,8 @@ xmlBufAttrSerializeTxtContent(xmlBufPtr buf, xmlDocPtr doc,\n xmlBufAdd(buf, BAD_CAST \"&\", 5);\n cur++;\n base = cur;\n- } else if ((*cur >= 0x80) && ((doc == NULL) ||\n- (doc->encoding == NULL))) {\n+ } else if ((*cur >= 0x80) && (cur[1] != 0) &&\n+\t ((doc == NULL) || (doc->encoding == NULL))) {\n /*\n * We assume we have UTF-8 content.\n */\n@@ -2121,14 +2121,14 @@ xmlBufAttrSerializeTxtContent(xmlBufPtr buf, xmlDocPtr doc,\n val <<= 6;\n val |= (cur[1]) & 0x3F;\n l = 2;\n- } else if (*cur < 0xF0) {\n+ } else if ((*cur < 0xF0) && (cur [2] != 0)) {\n val = (cur[0]) & 0x0F;\n val <<= 6;\n val |= (cur[1]) & 0x3F;\n val <<= 6;\n val |= (cur[2]) & 0x3F;\n l = 3;\n- } else if (*cur < 0xF8) {\n+ } else if ((*cur < 0xF8) && (cur [2] != 0) && (cur[3] != 0)) {\n val = (cur[0]) & 0x07;\n val <<= 6;\n val |= (cur[1]) & 0x3F;\n-- \ncgit v0.12"}], "metadata": {"id": "libxml2-5762-libxml2-2.9.1-CVE-2016-4483.pa", "cve_id": "CVE-2016-4658", "package": "libxml2", "upstream_enriched": true, "upstream_commit": "c97750d11bb8b6f3303e7131fe526a61ac65bcfd", "upstream_repo": "GNOME/libxml2", "tier": "adapted", "has_source_context": false, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-6250\n\nInteger overflow in the ISO9660 writer in libarchive before 3.2.1 allows remote attackers to cause a denial of service (application crash) or execute arbitrary code via vectors related to verifying filename lengths when writing an ISO9660 archive, which trigger a buffer overflow.\n\n## Package\nlibarchive\n\n## Files to modify\n- libarchive-3.1.2.orig/libarchive/archive_read_support_format_mtree.c\n- libarchive-3.1.2.orig/libarchive/archive_platform.h\n- libarchive/archive_pack_dev.h\n- libarchive/archive_platform.h\n- libarchive/archive_read_support_format_mtree.c\n\n## Target Source Code\n\n### libarchive/CMakeLists.txt\n\n#### SET() [lines 1-82]\n```c\n\n############################################\n#\n# How to build libarchive\n#\n############################################\n\n# Public headers\nSET(include_HEADERS\n archive.h\n archive_entry.h\n)\n\n# Sources and private headers\nSET(libarchive_SOURCES\n archive_acl.c\n archive_check_magic.c\n archive_cmdline.c\n archive_cmdline_private.h\n archive_crc32.h\n archive_crypto.c\n archive_crypto_private.h\n archive_endian.h\n archive_entry.c\n archive_entry.h\n archive_entry_copy_stat.c\n archive_entry_link_resolver.c\n archive_entry_locale.h\n archive_entry_private.h\n archive_entry_sparse.c\n archive_entry_stat.c\n archive_entry_strmode.c\n archive_entry_xattr.c\n archive_getdate.c\n archive_match.c\n archive_options.c\n archive_options_private.h\n archive_pathmatch.c\n archive_pathmatch.h\n archive_platform.h\n archive_ppmd_private.h\n archive_ppmd7.c\n archive_ppmd7_private.h\n archive_private.h\n archive_rb.c\n archive_rb.h\n archive_read.c\n archive_read_append_filter.c\n archive_read_data_into_fd.c\n archive_read_disk_entry_from_file.c\n archive_read_disk_posix.c\n archive_read_disk_private.h\n archive_read_disk_set_standard_lookup.c\n archive_read_extract.c\n archive_read_open_fd.c\n archive_read_open_file.c\n archive_read_open_filename.c\n archive_read_open_memory.c\n archive_read_private.h\n archive_read_set_format.c\n archive_read_set_options.c\n archive_read_support_filter_all.c\n archive_read_support_filter_bzip2.c\n archive_read_support_filter_compress.c\n archive_read_support_filter_gzip.c\n archive_read_support_filter_grzip.c\n archive_read_support_filter_lrzip.c\n archive_read_support_filter_lzop.c\n archive_read_support_filter_none.c\n archive_read_support_filter_program.c\n archive_read_support_filter_rpm.c\n archive_read_support_filter_uu.c\n archive_read_support_filter_xz.c\n archive_read_support_format_7zip.c\n archive_read_support_format_all.c\n archive_read_support_format_ar.c\n archive_read_support_format_by_code.c\n archive_read_support_format_cab.c\n archive_read_support_format_cpio.c\n archive_read_support_format_empty.c\n archive_read_su\n/* ... truncated ... */\n```\n\n### libarchive/archive_platform.h\n\n#### region() [lines 27-122]\n```c\n\n/* !!ONLY FOR USE INTERNALLY TO LIBARCHIVE!! */\n\n/*\n * This header is the first thing included in any of the libarchive\n * source files. As far as possible, platform-specific issues should\n * be dealt with here and not within individual source files. I'm\n * actively trying to minimize #if blocks within the main source,\n * since they obfuscate the code.\n */\n\n#ifndef ARCHIVE_PLATFORM_H_INCLUDED\n#define\tARCHIVE_PLATFORM_H_INCLUDED\n\n/* archive.h and archive_entry.h require this. */\n#define\t__LIBARCHIVE_BUILD 1\n\n#if defined(PLATFORM_CONFIG_H)\n/* Use hand-built config.h in environments that need it. */\n#include PLATFORM_CONFIG_H\n#elif defined(HAVE_CONFIG_H)\n/* Most POSIX platforms use the 'configure' script to build config.h */\n#include \"config.h\"\n#else\n/* Warn if the library hasn't been (automatically or manually) configured. */\n#error Oops: No config.h and no pre-built configuration in archive_platform.h.\n#endif\n\n/* It should be possible to get rid of this by extending the feature-test\n * macros to cover Windows API functions, probably along with non-trivial\n * refactoring of code to find structures that sit more cleanly on top of\n * either Windows or Posix APIs. */\n#if (defined(__WIN32__) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__)\n#include \"archive_windows.h\"\n#endif\n\n/*\n * The config files define a lot of feature macros. The following\n * uses those macros to select/define replacements and include key\n * headers as required.\n */\n\n/* Get a real definition for __FBSDID if we can */\n#if HAVE_SYS_CDEFS_H\n#include \n#endif\n\n/* If not, define it so as to avoid dangling semicolons. */\n#ifndef __FBSDID\n#define\t__FBSDID(a) struct _undefined_hack\n#endif\n\n/* Try to get standard C99-style integer type definitions. */\n#if HAVE_INTTYPES_H\n#include \n#endif\n#if HAVE_STDINT_H\n#include \n#endif\n\n/* Borland warns about its own constants! */\n#if defined(__BORLANDC__)\n# if HAVE_DECL_UINT64_MAX\n# undef\tUINT64_MAX\n# undef\tHAVE_DECL_UINT64_MAX\n# endif\n# if HAVE_DECL_UINT64_MIN\n# undef\tUINT64_MIN\n# undef\tHAVE_DE\n/* ... truncated ... */\n```\n\n### libarchive/archive_read_support_format_mtree.c\n\n#### __FBSDID() [lines 12-98]\n```c\n * 2. Redistributions in binary form must reproduce the above copyright\n * notice, this list of conditions and the following disclaimer in the\n * documentation and/or other materials provided with the distribution.\n *\n * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR\n * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,\n * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\n#include \"archive_platform.h\"\n__FBSDID(\"$FreeBSD: head/lib/libarchive/archive_read_support_format_mtree.c 201165 2009-12-29 05:52:13Z kientzle $\");\n\n#ifdef HAVE_SYS_STAT_H\n#include \n#endif\n#ifdef HAVE_ERRNO_H\n#include \n#endif\n#ifdef HAVE_FCNTL_H\n#include \n#endif\n#include \n/* #include */ /* See archive_platform.h */\n#ifdef HAVE_STDLIB_H\n#include \n#endif\n#ifdef HAVE_STRING_H\n#include \n#endif\n\n#include \"archive.h\"\n#include \"archive_entry.h\"\n#include \"archive_private.h\"\n#include \"archive_read_private.h\"\n#include \"archive_string.h\"\n\n#ifndef O_BINARY\n#define\tO_BINARY 0\n#endif\n#ifndef O_CLOEXEC\n#define O_CLOEXEC\t0\n#endif\n\n#define\tMTREE_HAS_DEVICE\t0x0001\n#define\tMTREE_HAS_FFLAGS\t0x0002\n#define\tMTREE_HAS_GID\t\t0x0004\n#define\tMTREE_HAS_GNAME\t\t0x0008\n#define\tMTREE_HAS_MTIME\t\t0x0010\n#define\tMTREE_HAS_NLINK\t\t0x0020\n#define\tMTREE_HAS_PERM\t\t0x0040\n#define\tMTREE_HAS_SIZE\t\t0x0080\n#define\tMTREE_HAS_TYPE\t\t0x0100\n#define\tMTREE_HAS_UID\t\t0x0200\n#define\tMTREE_HAS_UNAME\t\t0x0400\n\n#define\tMTREE_HAS_OPTIONAL\t0x0800\n#define\tMTREE_HAS_NOCHANGE\t0x1000 /* Free\n/* ... truncated ... */\n```\n\n### Makefile.am\n\n#### region() [lines 71-157]\n```c\ndistclean-local:\n\t-rm -rf .ref\n\t-rm -rf autom4te.cache/\n\t-rm -f *~\n\t-[ -f libarchive/Makefile ] && cd libarchive && make clean\n\t-[ -f libarchive/test/Makefile ] && cd libarchive/test && make clean\n\t-[ -f tar/Makefile ] && cd tar && make clean\n\t-[ -f tar/test/Makefile ] && cd tar/test && make clean\n\t-[ -f cpio/Makefile ] && cd cpio && make clean\n\t-[ -f cpio/test/Makefile ] && cd cpio/test && make clean\n\n#\n# Libarchive headers, source, etc.\n#\n#\n\ninclude_HEADERS= libarchive/archive.h libarchive/archive_entry.h\n\nlibarchive_la_SOURCES=\t\t\t\t\t\t\\\n\tlibarchive/archive_acl.c\t\t\t\t\\\n\tlibarchive/archive_acl_private.h\t\t\t\\\n\tlibarchive/archive_check_magic.c\t\t\t\\\n\tlibarchive/archive_cmdline.c\t\t\t\t\\\n\tlibarchive/archive_cmdline_private.h\t\t\t\\\n\tlibarchive/archive_crc32.h\t\t\t\t\\\n\tlibarchive/archive_crypto.c\t\t\t\t\\\n\tlibarchive/archive_crypto_private.h\t\t\t\\\n\tlibarchive/archive_endian.h\t\t\t\t\\\n\tlibarchive/archive_entry.c\t\t\t\t\\\n\tlibarchive/archive_entry.h\t\t\t\t\\\n\tlibarchive/archive_entry_copy_stat.c\t\t\t\\\n\tlibarchive/archive_entry_link_resolver.c\t\t\\\n\tlibarchive/archive_entry_locale.h\t\t\t\\\n\tlibarchive/archive_entry_private.h\t\t\t\\\n\tlibarchive/archive_entry_sparse.c\t\t\t\\\n\tlibarchive/archive_entry_stat.c\t\t\t\t\\\n\tlibarchive/archive_entry_strmode.c\t\t\t\\\n\tlibarchive/archive_entry_xattr.c\t\t\t\\\n\tlibarchive/archive_getdate.c\t\t\t\t\\\n\tlibarchive/archive_match.c\t\t\t\t\\\n\tlibarchive/archive_options.c\t\t\t\t\\\n\tlibarchive/archive_options_private.h\t\t\t\\\n\tlibarchive/archive_pathmatch.c\t\t\t\t\\\n\tlibarchive/archive_pathmatch.h\t\t\t\t\\\n\tlibarchive/archive_platform.h\t\t\t\t\\\n\tlibarchive/archive_ppmd_private.h\t\t\t\\\n\tlibarchive/archive_ppmd7.c\t\t\t\t\\\n\tlibarchive/archive_ppmd7_private.h\t\t\t\\\n\tlibarchive/archive_private.h\t\t\t\t\\\n\tlibarchive/archive_rb.c\t\t\t\t\t\\\n\tlibarchive/archive_rb.h\t\t\t\t\t\\\n\tlibarchive/archive_read.c\t\t\t\t\\\n\tlibarchive/archive_read_append_filter.c\t\t\t\\\n\tlibarchive/archive_read_data_into_fd.c\t\t\t\\\n\tlibarchive/archive_read_disk_entry_from_file.c\t\t\\\n\tlibarchive/archive_read_disk_posix.c\t\t\t\\\n\tlibarchive/archive_read_disk_private.h\t\t\t\\\n\tlibarchive/archive_read_disk_set_standard_lookup.c\t\\\n\tlibarchive/archive_read_extract.c\t\t\t\\\n\tlibarchive/a\n/* ... truncated ... */\n```\n\n\n### Type definitions\n\n```c\n/* from archive_private.h */\nstruct archive {\n\t/*\n\t * The magic/state values are used to sanity-check the\n\t * client's usage. If an API function is called at a\n\t * ridiculous time, or the client passes us an invalid\n\t * pointer, these values allow me to catch that.\n\t */\n\tunsigned int\tmagic;\n\tunsigned int\tstate;\n\n\t/*\n\t * Some public API functions depend on the \"real\" type of the\n\t * archive object.\n\t */\n\tstruct archive_vtable *vtable;\n\n\tint\t\t archive_format;\n\tconst char\t *archive_format_name;\n\n\tint\t compression_code;\t/* Currently active compression. */\n\tconst char *compression_name;\n\n\t/* Number of file entries processed. */\n\tint\t\t file_count;\n\n\tint\t\t archive_error_number;\n\tconst char\t *error;\n\tstruct archive_string\terror_string;\n\n\tchar *current_code;\n\tunsigned current_codepage; /* Current ACP(ANSI CodePage). */\n\tunsigned current_oemcp; /* Current OEMCP(OEM CodePage). */\n\tstruct archive_string_conv *sconv;\n};\n```\n\n\n## Upstream Fix\n```diff\ncommit 4e002d9a92ecd7cec0fb98b0bedbace8aad81f6e\nAuthor: Jean-Yves Migeon \nDate: Tue Sep 3 16:12:37 2013 +0200\n\n Add the device parsing logic. It allows mtree's libarchive to\n parse device entries like NetBSD's mtree and its multiple possible\n format: native, 386bsd, 4bsd, bsdos, freebsd, hpux, isc, linux, netbsd,\n osf1, sco, solaris, sunos, svr3, svr4, and ultrix.\n\nIndex: libarchive-3.1.2/libarchive/CMakeLists.txt\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/CMakeLists.txt\n+++ libarchive-3.1.2/libarchive/CMakeLists.txt\n@@ -35,6 +35,8 @@ SET(libarchive_SOURCES\n archive_match.c\n archive_options.c\n archive_options_private.h\n+ archive_pack_dev.h\n+ archive_pack_dev.c\n archive_pathmatch.c\n archive_pathmatch.h\n archive_platform.h\nIndex: libarchive-3.1.2/libarchive/archive_pack_dev.c\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/archive_pack_dev.c\n@@ -0,0 +1,304 @@\n+/*\t$NetBSD: pack_dev.c,v 1.12 2013/06/14 16:28:20 tsutsui Exp $\t*/\n+\n+/*-\n+ * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.\n+ * All rights reserved.\n+ *\n+ * This code is derived from software contributed to The NetBSD Foundation\n+ * by Charles M. Hannum.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ * 1. Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in the\n+ * documentation and/or other materials provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\n+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\n+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\n+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n+ * POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+/* Originally from NetBSD's mknod(8) source. */\n+\n+#include \"archive_platform.h\"\n+\n+#if HAVE_SYS_CDEFS_H\n+#include \n+#endif\n+#if !defined(lint)\n+__RCSID(\"$NetBSD$\");\n+#endif /* not lint */\n+\n+#ifdef HAVE_LIMITS_H\n+#include \n+#endif\n+\n+#include \n+#ifdef HAVE_STDLIB_H\n+#include \n+#endif\n+#ifdef HAVE_STRING_H\n+#include \n+#endif\n+#ifdef HAVE_SYS_TYPES_H\n+#include \n+#endif\n+#ifdef HAVE_SYS_STAT_H\n+#include \n+#endif\n+#ifdef HAVE_UNISTD_H\n+#include \n+#endif\n+\n+#include \"archive_pack_dev.h\"\n+\n+static\tpack_t\tpack_netbsd;\n+static\tpack_t\tpack_freebsd;\n+static\tpack_t\tpack_8_8;\n+static\tpack_t\tpack_12_20;\n+static\tpack_t\tpack_14_18;\n+static\tpack_t\tpack_8_24;\n+static\tpack_t\tpack_bsdos;\n+static\tint\tcompare_format(const void *, const void *);\n+\n+static const char iMajorError[] = \"invalid major number\";\n+static const char iMinorError[] = \"invalid minor number\";\n+static const char tooManyFields[] = \"too many fields for format\";\n+\n+\t/* exported */\n+dev_t\n+pack_native(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev(numbers[0], numbers[1]);\n+\t\tif ((u_long)major(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\telse if ((u_long)minor(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+static dev_t\n+pack_netbsd(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev_netbsd(numbers[0], numbers[1]);\n+\t\tif ((u_long)major_netbsd(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\telse if ((u_long)minor_netbsd(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+#define\tmajor_freebsd(x)\t((int32_t)(((x) & 0x0000ff00) >> 8))\n+#define\tminor_freebsd(x)\t((int32_t)(((x) & 0xffff00ff) >> 0))\n+#define\tmakedev_freebsd(x,y)\t((dev_t)((((x) << 8) & 0x0000ff00) | \\\n+\t\t\t\t\t (((y) << 0) & 0xffff00ff)))\n+\n+static dev_t\n+pack_freebsd(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev_freebsd(numbers[0], numbers[1]);\n+\t\tif ((u_long)major_freebsd(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\tif ((u_long)minor_freebsd(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+#define\tmajor_8_8(x)\t\t((int32_t)(((x) & 0x0000ff00) >> 8))\n+#define\tminor_8_8(x)\t\t((int32_t)(((x) & 0x000000ff) >> 0))\n+#define\tmakedev_8_8(x,y)\t((dev_t)((((x) << 8) & 0x0000ff00) | \\\n+\t\t\t\t\t (((y) << 0) & 0x000000ff)))\n+\n+static dev_t\n+pack_8_8(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev_8_8(numbers[0], numbers[1]);\n+\t\tif ((u_long)major_8_8(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\tif ((u_long)minor_8_8(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+#define\tmajor_12_20(x)\t\t((int32_t)(((x) & 0xfff00000) >> 20))\n+#define\tminor_12_20(x)\t\t((int32_t)(((x) & 0x000fffff) >> 0))\n+#define\tmakedev_12_20(x,y)\t((dev_t)((((x) << 20) & 0xfff00000) | \\\n+\t\t\t\t\t (((y) << 0) & 0x000fffff)))\n+\n+static dev_t\n+pack_12_20(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev_12_20(numbers[0], numbers[1]);\n+\t\tif ((u_long)major_12_20(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\tif ((u_long)minor_12_20(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+#define\tmajor_14_18(x)\t\t((int32_t)(((x) & 0xfffc0000) >> 18))\n+#define\tminor_14_18(x)\t\t((int32_t)(((x) & 0x0003ffff) >> 0))\n+#define\tmakedev_14_18(x,y)\t((dev_t)((((x) << 18) & 0xfffc0000) | \\\n+\t\t\t\t\t (((y) << 0) & 0x0003ffff)))\n+\n+static dev_t\n+pack_14_18(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev_14_18(numbers[0], numbers[1]);\n+\t\tif ((u_long)major_14_18(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\tif ((u_long)minor_14_18(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+#define\tmajor_8_24(x)\t\t((int32_t)(((x) & 0xff000000) >> 24))\n+#define\tminor_8_24(x)\t\t((int32_t)(((x) & 0x00ffffff) >> 0))\n+#define\tmakedev_8_24(x,y)\t((dev_t)((((x) << 24) & 0xff000000) | \\\n+\t\t\t\t\t (((y) << 0) & 0x00ffffff)))\n+\n+static dev_t\n+pack_8_24(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev_8_24(numbers[0], numbers[1]);\n+\t\tif ((u_long)major_8_24(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\tif ((u_long)minor_8_24(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+#define\tmajor_12_12_8(x)\t((int32_t)(((x) & 0xfff00000) >> 20))\n+#define\tunit_12_12_8(x)\t\t((int32_t)(((x) & 0x000fff00) >> 8))\n+#define\tsubunit_12_12_8(x)\t((int32_t)(((x) & 0x000000ff) >> 0))\n+#define\tmakedev_12_12_8(x,y,z)\t((dev_t)((((x) << 20) & 0xfff00000) | \\\n+\t\t\t\t\t (((y) << 8) & 0x000fff00) | \\\n+\t\t\t\t\t (((z) << 0) & 0x000000ff)))\n+\n+static dev_t\n+pack_bsdos(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev_12_20(numbers[0], numbers[1]);\n+\t\tif ((u_long)major_12_20(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\tif ((u_long)minor_12_20(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else \n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "commit 4e002d9a92ecd7cec0fb98b0bedbace8aad81f6e\nAuthor: Jean-Yves Migeon \nDate: Tue Sep 3 16:12:37 2013 +0200\n\n Add the device parsing logic. It allows mtree's libarchive to\n parse device entries like NetBSD's mtree and its multiple possible\n format: native, 386bsd, 4bsd, bsdos, freebsd, hpux, isc, linux, netbsd,\n osf1, sco, solaris, sunos, svr3, svr4, and ultrix.\n\nIndex: libarchive-3.1.2/libarchive/CMakeLists.txt\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/CMakeLists.txt\n+++ libarchive-3.1.2/libarchive/CMakeLists.txt\n@@ -35,6 +35,8 @@ SET(libarchive_SOURCES\n archive_match.c\n archive_options.c\n archive_options_private.h\n+ archive_pack_dev.h\n+ archive_pack_dev.c\n archive_pathmatch.c\n archive_pathmatch.h\n archive_platform.h\nIndex: libarchive-3.1.2/libarchive/archive_pack_dev.c\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/archive_pack_dev.c\n@@ -0,0 +1,304 @@\n+/*\t$NetBSD: pack_dev.c,v 1.12 2013/06/14 16:28:20 tsutsui Exp $\t*/\n+\n+/*-\n+ * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.\n+ * All rights reserved.\n+ *\n+ * This code is derived from software contributed to The NetBSD Foundation\n+ * by Charles M. Hannum.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ * 1. Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in the\n+ * documentation and/or other materials provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\n+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\n+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\n+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n+ * POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+/* Originally from NetBSD's mknod(8) source. */\n+\n+#include \"archive_platform.h\"\n+\n+#if HAVE_SYS_CDEFS_H\n+#include \n+#endif\n+#if !defined(lint)\n+__RCSID(\"$NetBSD$\");\n+#endif /* not lint */\n+\n+#ifdef HAVE_LIMITS_H\n+#include \n+#endif\n+\n+#include \n+#ifdef HAVE_STDLIB_H\n+#include \n+#endif\n+#ifdef HAVE_STRING_H\n+#include \n+#endif\n+#ifdef HAVE_SYS_TYPES_H\n+#include \n+#endif\n+#ifdef HAVE_SYS_STAT_H\n+#include \n+#endif\n+#ifdef HAVE_UNISTD_H\n+#include \n+#endif\n+\n+#include \"archive_pack_dev.h\"\n+\n+static\tpack_t\tpack_netbsd;\n+static\tpack_t\tpack_freebsd;\n+static\tpack_t\tpack_8_8;\n+static\tpack_t\tpack_12_20;\n+static\tpack_t\tpack_14_18;\n+static\tpack_t\tpack_8_24;\n+static\tpack_t\tpack_bsdos;\n+static\tint\tcompare_format(const void *, const void *);\n+\n+static const char iMajorError[] = \"invalid major number\";\n+static const char iMinorError[] = \"invalid minor number\";\n+static const char tooManyFields[] = \"too many fields for format\";\n+\n+\t/* exported */\n+dev_t\n+pack_native(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev(numbers[0], numbers[1]);\n+\t\tif ((u_long)major(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\telse if ((u_long)minor(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+static dev_t\n+pack_netbsd(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev_netbsd(numbers[0], numbers[1]);\n+\t\tif ((u_long)major_netbsd(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\telse if ((u_long)minor_netbsd(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+#define\tmajor_freebsd(x)\t((int32_t)(((x) & 0x0000ff00) >> 8))\n+#define\tminor_freebsd(x)\t((int32_t)(((x) & 0xffff00ff) >> 0))\n+#define\tmakedev_freebsd(x,y)\t((dev_t)((((x) << 8) & 0x0000ff00) | \\\n+\t\t\t\t\t (((y) << 0) & 0xffff00ff)))\n+\n+static dev_t\n+pack_freebsd(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev_freebsd(numbers[0], numbers[1]);\n+\t\tif ((u_long)major_freebsd(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\tif ((u_long)minor_freebsd(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+#define\tmajor_8_8(x)\t\t((int32_t)(((x) & 0x0000ff00) >> 8))\n+#define\tminor_8_8(x)\t\t((int32_t)(((x) & 0x000000ff) >> 0))\n+#define\tmakedev_8_8(x,y)\t((dev_t)((((x) << 8) & 0x0000ff00) | \\\n+\t\t\t\t\t (((y) << 0) & 0x000000ff)))\n+\n+static dev_t\n+pack_8_8(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev_8_8(numbers[0], numbers[1]);\n+\t\tif ((u_long)major_8_8(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\tif ((u_long)minor_8_8(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+#define\tmajor_12_20(x)\t\t((int32_t)(((x) & 0xfff00000) >> 20))\n+#define\tminor_12_20(x)\t\t((int32_t)(((x) & 0x000fffff) >> 0))\n+#define\tmakedev_12_20(x,y)\t((dev_t)((((x) << 20) & 0xfff00000) | \\\n+\t\t\t\t\t (((y) << 0) & 0x000fffff)))\n+\n+static dev_t\n+pack_12_20(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev_12_20(numbers[0], numbers[1]);\n+\t\tif ((u_long)major_12_20(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\tif ((u_long)minor_12_20(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+#define\tmajor_14_18(x)\t\t((int32_t)(((x) & 0xfffc0000) >> 18))\n+#define\tminor_14_18(x)\t\t((int32_t)(((x) & 0x0003ffff) >> 0))\n+#define\tmakedev_14_18(x,y)\t((dev_t)((((x) << 18) & 0xfffc0000) | \\\n+\t\t\t\t\t (((y) << 0) & 0x0003ffff)))\n+\n+static dev_t\n+pack_14_18(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev_14_18(numbers[0], numbers[1]);\n+\t\tif ((u_long)major_14_18(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\tif ((u_long)minor_14_18(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+#define\tmajor_8_24(x)\t\t((int32_t)(((x) & 0xff000000) >> 24))\n+#define\tminor_8_24(x)\t\t((int32_t)(((x) & 0x00ffffff) >> 0))\n+#define\tmakedev_8_24(x,y)\t((dev_t)((((x) << 24) & 0xff000000) | \\\n+\t\t\t\t\t (((y) << 0) & 0x00ffffff)))\n+\n+static dev_t\n+pack_8_24(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev_8_24(numbers[0], numbers[1]);\n+\t\tif ((u_long)major_8_24(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\tif ((u_long)minor_8_24(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+#define\tmajor_12_12_8(x)\t((int32_t)(((x) & 0xfff00000) >> 20))\n+#define\tunit_12_12_8(x)\t\t((int32_t)(((x) & 0x000fff00) >> 8))\n+#define\tsubunit_12_12_8(x)\t((int32_t)(((x) & 0x000000ff) >> 0))\n+#define\tmakedev_12_12_8(x,y,z)\t((dev_t)((((x) << 20) & 0xfff00000) | \\\n+\t\t\t\t\t (((y) << 8) & 0x000fff00) | \\\n+\t\t\t\t\t (((z) << 0) & 0x000000ff)))\n+\n+static dev_t\n+pack_bsdos(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev_12_20(numbers[0], numbers[1]);\n+\t\tif ((u_long)major_12_20(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\tif ((u_long)minor_12_20(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else if (n == 3) {\n+\t\tdev = makedev_12_12_8(numbers[0], numbers[1], numbers[2]);\n+\t\tif ((u_long)major_12_12_8(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\tif ((u_long)unit_12_12_8(dev) != numbers[1])\n+\t\t\t*error = \"invalid unit number\";\n+\t\tif ((u_long)subunit_12_12_8(dev) != numbers[2])\n+\t\t\t*error = \"invalid subunit number\";\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+\t\t/* list of formats and pack functions */\n+\t\t/* this list must be sorted lexically */\n+static struct format {\n+\tconst char\t*name;\n+\tpack_t\t\t*pack;\n+} formats[] = {\n+\t{\"386bsd\", pack_8_8},\n+\t{\"4bsd\", pack_8_8},\n+\t{\"bsdos\", pack_bsdos},\n+\t{\"freebsd\", pack_freebsd},\n+\t{\"hpux\", pack_8_24},\n+\t{\"isc\", pack_8_8},\n+\t{\"linux\", pack_8_8},\n+\t{\"native\", pack_native},\n+\t{\"netbsd\", pack_netbsd},\n+\t{\"osf1\", pack_12_20},\n+\t{\"sco\", pack_8_8},\n+\t{\"solaris\", pack_14_18},\n+\t{\"sunos\", pack_8_8},\n+\t{\"svr3\", pack_8_8},\n+\t{\"svr4\", pack_14_18},\n+\t{\"ultrix\", pack_8_8},\n+};\n+\n+static int\n+compare_format(const void *key, const void *element)\n+{\n+\tconst char\t\t*name;\n+\tconst struct format\t*format;\n+\n+\tname = key;\n+\tformat = element;\n+\n+\treturn (strcmp(name, format->name));\n+}\n+\n+\n+pack_t *\n+pack_find(const char *name)\n+{\n+\tstruct format\t*format;\n+\n+\tformat = bsearch(name, formats,\n+\t sizeof(formats)/sizeof(formats[0]),\n+\t sizeof(formats[0]), compare_format);\n+\tif (format == 0)\n+\t\treturn (NULL);\n+\treturn (format->pack);\n+}\nIndex: libarchive-3.1.2/libarchive/archive_pack_dev.h\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/archive_pack_dev.h\n@@ -0,0 +1,50 @@\n+/*\t$NetBSD: pack_dev.h,v 1.8 2013/06/14 16:28:20 tsutsui Exp $\t*/\n+\n+/*-\n+ * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.\n+ * All rights reserved.\n+ *\n+ * This code is derived from software contributed to The NetBSD Foundation\n+ * by Charles M. Hannum.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ * 1. Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in the\n+ * documentation and/or other materials provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\n+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\n+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\n+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n+ * POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+/* Originally from NetBSD's mknod(8) source. */\n+\n+#ifndef\t_PACK_DEV_H\n+#define\t_PACK_DEV_H\n+\n+typedef\tdev_t pack_t(int, u_long [], const char **);\n+typedef unsigned long u_long;\n+\n+pack_t\t*pack_find(const char *);\n+pack_t\t pack_native;\n+\n+#define\tmajor_netbsd(x)\t\t((int32_t)((((x) & 0x000fff00) >> 8)))\n+#define\tminor_netbsd(x)\t\t((int32_t)((((x) & 0xfff00000) >> 12) | \\\n+\t\t\t\t\t (((x) & 0x000000ff) >> 0)))\n+#define\tmakedev_netbsd(x,y)\t((dev_t)((((x) << 8) & 0x000fff00) | \\\n+\t\t\t\t\t (((y) << 12) & 0xfff00000) | \\\n+\t\t\t\t\t (((y) << 0) & 0x000000ff)))\n+\n+#endif\t/* _PACK_DEV_H */\nIndex: libarchive-3.1.2/libarchive/archive_platform.h\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_platform.h\n+++ libarchive-3.1.2/libarchive/archive_platform.h\n@@ -66,15 +66,18 @@\n * headers as required.\n */\n \n-/* Get a real definition for __FBSDID if we can */\n+/* Get a real definition for __FBSDID or __RCSID if we can */\n #if HAVE_SYS_CDEFS_H\n #include \n #endif\n \n-/* If not, define it so as to avoid dangling semicolons. */\n+/* If not, define them so as to avoid dangling semicolons. */\n #ifndef __FBSDID\n #define\t__FBSDID(a) struct _undefined_hack\n #endif\n+#ifndef __RCSID\n+#define\t__RCSID(a) struct _undefined_hack\n+#endif\n \n /* Try to get standard C99-style integer type definitions. */\n #if HAVE_INTTYPES_H\nIndex: libarchive-3.1.2/libarchive/archive_read_support_format_mtree.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_read_support_format_mtree.c\n+++ libarchive-3.1.2/libarchive/archive_read_support_format_mtree.c\n@@ -51,6 +51,7 @@ __FBSDID(\"$FreeBSD: head/lib/libarchive/\n #include \"archive_private.h\"\n #include \"archive_read_private.h\"\n #include \"archive_string.h\"\n+#include \"archive_pack_dev.h\"\n \n #ifndef O_BINARY\n #define\tO_BINARY 0\n@@ -1300,33 +1301,63 @@ parse_line(struct archive_read *a, struc\n \n /*\n * Device entries have one of the following forms:\n- * raw dev_t\n- * format,major,minor[,subdevice]\n- *\n- * Just use major and minor, no translation etc is done\n- * between formats.\n+ * - raw dev_t\n+ * - format,major,minor[,subdevice]\n */\n static int\n parse_device(struct archive *a, struct archive_entry *entry, char *val)\n {\n-\tchar *comma1, *comma2;\n+#define MAX_PACK_ARGS 3\n+\tunsigned long numbers[MAX_PACK_ARGS];\n+\tchar *p, *dev;\n+\tint argc;\n+\tpack_t *pack;\n+\tdev_t result;\n+\tconst char *error = NULL;\n \n-\tcomma1 = strchr(val, ',');\n-\tif (comma1 == NULL) {\n-\t\tarchive_entry_set_dev(entry, (dev_t)mtree_atol10(&val));\n-\t\treturn (ARCHIVE_OK);\n-\t}\n-\t++comma1;\n-\tcomma2 = strchr(comma1, ',');\n-\tif (comma2 == NULL) {\n-\t\tarchive_set_error(a, ARCHIVE_ERRNO_FILE_FORMAT,\n-\t\t \"Malformed device attribute\");\n-\t\treturn (ARCHIVE_WARN);\n+\tif ((dev = strchr(val, ',')) != NULL) {\n+\t\t/*\n+\t\t * Device's major/minor are given in a specified format.\n+\t\t * Decode and pack it accordingly.\n+\t\t */\n+\t\t*dev++ = '\\0';\n+\t\tif ((pack = pack_find(val)) == NULL) {\n+\t\t\tarchive_set_error(a, ARCHIVE_ERRNO_FILE_FORMAT,\n+\t\t\t \"Unknown format `%s'\", val);\n+\t\t\treturn ARCHIVE_WARN;\n+\t\t}\n+\t\targc = 0;\n+\t\twhile ((p = strsep(&dev, \",\")) != NULL) {\n+\t\t\tif (*p == '\\0') {\n+\t\t\t\tarchive_set_error(a, ARCHIVE_ERRNO_FILE_FORMAT,\n+\t\t\t\t \"Missing number\");\n+\t\t\t\treturn ARCHIVE_WARN;\n+\t\t\t}\n+\t\t\tnumbers[argc++] = mtree_atol(&p);\n+\t\t\tif (argc > MAX_PACK_ARGS) {\n+\t\t\t\tarchive_set_error(a, ARCHIVE_ERRNO_FILE_FORMAT,\n+\t\t\t\t \"Too many arguments\");\n+\t\t\t\treturn ARCHIVE_WARN;\n+\t\t\t}\n+\t\t}\n+\t\tif (argc < 2) {\n+\t\t\tarchive_set_error(a, ARCHIVE_ERRNO_FILE_FORMAT,\n+\t\t\t \"Not enough arguments\");\n+\t\t\treturn ARCHIVE_WARN;\n+\t\t}\n+\t\tresult = (*pack)(argc, numbers, &error);\n+\t\tif (error != NULL) {\n+\t\t\tarchive_set_error(a, ARCHIVE_ERRNO_FILE_FORMAT,\n+\t\t\t \"%s\", error);\n+\t\t\treturn ARCHIVE_WARN;\n+\t\t}\n+\t\tarchive_entry_set_rdev(entry, result);\n+\t} else {\n+\t\t/* file system raw value. */\n+\t\tarchive_entry_set_rdev(entry, (dev_t)mtree_atol(&val));\n \t}\n-\t++comma2;\n-\tarchive_entry_set_rdevmajor(entry, (dev_t)mtree_atol(&comma1));\n-\tarchive_entry_set_rdevminor(entry, (dev_t)mtree_atol(&comma2));\n-\treturn (ARCHIVE_OK);\n+\treturn ARCHIVE_OK;\n+#undef MAX_PACK_ARGS\n }\n \n /*\nIndex: libarchive-3.1.2/Makefile.am\n===================================================================\n--- libarchive-3.1.2.orig/Makefile.am\n+++ libarchive-3.1.2/Makefile.am\n@@ -110,6 +110,8 @@ libarchive_la_SOURCES=\t\t\t\t\t\t\\\n \tlibarchive/archive_match.c\t\t\t\t\\\n \tlibarchive/archive_options.c\t\t\t\t\\\n \tlibarchive/archive_options_private.h\t\t\t\\\n+\tlibarchive/archive_pack_dev.h\t\t\t\t\\\n+\tlibarchive/archive_pack_dev.c\t\t\t\t\\\n \tlibarchive/archive_pathmatch.c\t\t\t\t\\\n \tlibarchive/archive_pathmatch.h\t\t\t\t\\\n \tlibarchive/archive_platform.h\t\t\t\t\\"}], "metadata": {"id": "libarchive-5940-CVE-2016-4301-base.patch", "cve_id": "CVE-2016-6250", "package": "libarchive", "tier": "adapted", "has_source_context": true, "context_tokens_est": 2422, "context_files": 4, "license": "BSD-2-Clause"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2012-0027\n\nThe GOST ENGINE in OpenSSL before 1.0.0f does not properly handle invalid parameters for the GOST block cipher, which allows remote attackers to cause a denial of service (daemon crash) via crafted data from a TLS client.\n\n## Package\nopenssl\n\n## Files to modify\n- crypto/engine/eng_all.c\n\n## Upstream Fix\n```diff\nAdd call to ENGINE_register_all_complete() to ENGINE_load_builtin_engines(), this means that some implementations will be used automatically, e.g. aesni,\nSetup cpuid in ENGINE_load_builtin_engines() too as some ENGINEs use it.\nOrigin: UPSTREAM\nURL: http://cvs.openssl.org/chngview?cn=19781\n\n--- crypto/engine/eng_all.c.orig\n+++ crypto/engine/eng_all.c\n@@ -61,6 +61,8 @@\n \n void ENGINE_load_builtin_engines(void)\n \t{\n+ /* Some ENGINEs need this */\n+ OPENSSL_cpuid_setup();\n #if 0\n \t/* There's no longer any need for an \"openssl\" ENGINE unless, one day,\n \t * it is the *only* way for standard builtin implementations to be be\n@@ -115,6 +117,7 @@ void ENGINE_load_builtin_engines(void)\n \tENGINE_load_capi();\n #endif\n #endif\n+ ENGINE_register_all_complete();\n \t}\n \n #if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "Add call to ENGINE_register_all_complete() to ENGINE_load_builtin_engines(), this means that some implementations will be used automatically, e.g. aesni,\nSetup cpuid in ENGINE_load_builtin_engines() too as some ENGINEs use it.\nOrigin: UPSTREAM\nURL: http://cvs.openssl.org/chngview?cn=19781\n\n--- crypto/engine/eng_all.c.orig\n+++ crypto/engine/eng_all.c\n@@ -61,6 +61,8 @@\n \n void ENGINE_load_builtin_engines(void)\n \t{\n+ /* Some ENGINEs need this */\n+ OPENSSL_cpuid_setup();\n #if 0\n \t/* There's no longer any need for an \"openssl\" ENGINE unless, one day,\n \t * it is the *only* way for standard builtin implementations to be be\n@@ -115,6 +117,7 @@ void ENGINE_load_builtin_engines(void)\n \tENGINE_load_capi();\n #endif\n #endif\n+ ENGINE_register_all_complete();\n \t}\n \n #if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV)"}], "metadata": {"id": "openssl-1345-openssl-call-engine-reg-comp.p", "cve_id": "CVE-2012-0027", "package": "openssl", "tier": "identical", "has_source_context": false, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-9556\n\nThe IsPixelGray function in MagickCore/pixel-accessor.h in ImageMagick 7.0.3-8 allows remote attackers to cause a denial of service (out-of-bounds heap read) via a crafted image file.\n\n## Package\nGraphicsMagick\n\n## Files to modify\n- coders/meta.c\n- GraphicsMagick-1.3.21.orig/coders/meta.c\n\n## Upstream Fix\n```diff\nff -r 4f748e625c82 -r 8da95e3e5e81 coders/meta.c\nIndex: GraphicsMagick-1.3.21/coders/meta.c\n===================================================================\n--- GraphicsMagick-1.3.21.orig/coders/meta.c\t2015-02-28 21:51:58.000000000 +0100\n@@ -129,14 +129,16 @@ static unsigned int IsMETA(const unsigne\n \n typedef struct _html_code\n {\n- short\n+ unsigned short\n len;\n+\n const char\n *code,\n val;\n+\n } html_code;\n \n-static html_code html_codes[] = {\n+static html_code const html_codes[] = {\n #ifdef HANDLE_GT_LT\n { 4,\"<\",'<' },\n { 4,\">\",'>' },\n@@ -179,29 +181,36 @@ static int stringnicmp(const char *p,con\n return(toupper((int) *p)-toupper((int) *q));\n }\n \n-static int convertHTMLcodes(char *s, int len)\n+static size_t convertHTMLcodes(char *s, const size_t len)\n {\n- if (len <=0 || s==(char*)NULL || *s=='\\0')\n+ int val;\n+\n+ if ((len == 0) || (s == (char*) NULL) || (*s=='\\0'))\n return 0;\n \n- if (s[1] == '#')\n- {\n- int val, o;\n+ /*\n+ Check for hex or decimal character escape.\n \n- if (sscanf(s,\"&#%d;\",&val) == 1)\n- {\n- o = 3;\n- while (s[o] != ';')\n+ e.g. hex: \" \", decimal \" \"\n+\n+ Note that scanf is expected to parse the number in hex or decimal\n+ and that it does not require the terminating ';' to appear in\n+ order to parse the numeric argument.\n+ */\n+ if ((len > 3) && (s[1] == '#') && (strchr(s,';') != (char *) NULL) &&\n+ (sscanf(s,\"&#%d;\",&val) == 1))\n+ {\n+ size_t o = 3;\n+ while (s[o] != ';')\n {\n o++;\n if (o > 5)\n break;\n }\n- if (o < 6)\n- (void) memmove(s+1,s+1+o,strlen(s+1+o)+1);\n- *s = val;\n- return o;\n- }\n+ if (o < 6)\n+ (void) memmove(s+1,s+1+o,strlen(s+1+o)+1);\n+ *s = val;\n+ return o;\n }\n else\n {\n@@ -281,10 +290,10 @@ static long parse8BIM(Image *ifile, Imag\n char\n brkused,\n quoted,\n- *line,\n- *token,\n- *newstr,\n- *name;\n+ *line = (char *) NULL,\n+ *token = (char *) NULL,\n+ *newstr = (char *) NULL,\n+ *name = (char *) NULL;\n \n int\n state,\n@@ -299,7 +308,7 @@ static long parse8BIM(Image *ifile, Imag\n size_t\n inputlen = BUFFER_SZ;\n \n- long\n+ ssize_t\n savedolen = 0L,\n outputlen = 0L;\n \n@@ -313,7 +322,8 @@ static long parse8BIM(Image *ifile, Imag\n dataset = 0;\n recnum = 0;\n line = MagickAllocateMemory(char *,inputlen);\n- name = token = (char *)NULL;\n+ if (line == (char *) NULL)\n+ goto parse8BIM_failure;\n savedpos = 0;\n while(super_fgets(&line,&inputlen,ifile)!=NULL)\n {\n@@ -321,7 +331,11 @@ static long parse8BIM(Image *ifile, Imag\n next=0;\n \n token = MagickAllocateMemory(char *,inputlen);\n+ if (token == (char *) NULL)\n+ goto parse8BIM_failure;\n newstr = MagickAllocateMemory(char *,inputlen);\n+ if (newstr == (char *) NULL)\n+ goto parse8BIM_failure;\n while (Tokenizer(&token_info, 0, token, inputlen, line,\n (char *) \"\", (char *) \"=\",\n (char *) \"\\\"\", 0, &brkused,&next,"ed)==0)\n@@ -354,8 +368,9 @@ static long parse8BIM(Image *ifile, Imag\n break;\n case 2:\n name = MagickAllocateMemory(char *,strlen(newstr)+1);\n- if (name)\n- (void) strcpy(name,newstr);\n+ if (name == (char *) NULL)\n+ goto parse8BIM_failure;\n+ (void) strcpy(name,newstr);\n break;\n }\n state++;\n@@ -367,7 +382,7 @@ static long parse8BIM(Image *ifile, Imag\n int\n next;\n \n- unsigned long\n+ size_t\n len;\n \n char\n@@ -384,7 +399,7 @@ static long parse8BIM(Image *ifile, Imag\n char\n *s = &token[next-1];\n \n- len -= convertHTMLcodes(s, (int) strlen(s));\n+ len -= convertHTMLcodes(s, strlen(s));\n }\n }\n \n@@ -400,6 +415,8 @@ static long parse8BIM(Image *ifile, Imag\n {\n long diff = outputlen - savedolen;\n currentpos = TellBlob(ofile);\n+ if (currentpos < 0)\n+ goto parse8BIM_failure;\n (void) SeekBlob(ofile,savedpos,SEEK_SET);\n (void) WriteBlobMSBLong(ofile,diff);\n (void) SeekBlob(ofile,currentpos,SEEK_SET);\n@@ -433,7 +450,7 @@ static long parse8BIM(Image *ifile, Imag\n next=0;\n outputlen += len;\n while (len--)\n- (void) WriteBlobByte(ofile,token[next++]);\n+ (void) WriteBlobByte(ofile,token[next++]); /* boom */\n \n if (outputlen & 1)\n {\n@@ -445,6 +462,8 @@ static long parse8BIM(Image *ifile, Imag\n {\n /* patch in a fake length for now and fix it later */\n savedpos = TellBlob(ofile);\n+ if (savedpos < 0)\n+ goto parse8BIM_failure;\n (void) WriteBlobMSBLong(ofile,0xFFFFFFFFUL);\n outputlen += 4;\n savedolen = outputlen;\n@@ -478,12 +497,22 @@ static long parse8BIM(Image *ifile, Imag\n long diff = outputlen - savedolen;\n \n currentpos = TellBlob(ofile);\n+ if (currentpos < 0)\n+ goto parse8BIM_failure;\n+\n (void) SeekBlob(ofile,savedpos,SEEK_SET);\n (void) WriteBlobMSBLong(ofile,diff);\n (void) SeekBlob(ofile,currentpos,SEEK_SET);\n savedolen = 0L;\n }\n return outputlen;\n+\n+ parse8BIM_failure:\n+ MagickFreeMemory(token);\n+ MagickFreeMemory(newstr);\n+ MagickFreeMemory(name);\n+ MagickFreeMemory(line);\n+ return 0L;\n }\n \n static char *super_fgets_w(char **b, size_t *blen, Image *file)\n@@ -542,10 +571,10 @@ static long parse8BIMW(Image *ifile, Ima\n char\n brkused,\n quoted,\n- *line,\n- *token,\n- *newstr,\n- *name;\n+ *line = (char *) NULL,\n+ *token = (char *) NULL,\n+ *newstr = (char *) NULL,\n+ *name = (char *) NULL;\n \n int\n state,\n@@ -560,7 +589,7 @@ static long parse8BIMW(Image *ifile, Ima\n size_t\n inputlen = BUFFER_SZ;\n \n- long\n+ ssize_t\n savedolen = 0L,\n outputlen = 0L;\n \n@@ -574,6 +603,8 @@ static long parse8BIMW(Image *ifile, Ima\n dataset = 0;\n recnum = 0;\n line = MagickAllocateMemory(char *,inputlen);\n+ if (line == (char *) NULL)\n+ goto parse8BIMW_failure;\n name = token = (char *)NULL;\n savedpos = 0;\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n@@ -586,7 +617,11 @@ static long parse8BIMW(Image *ifile, Ima\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \"META CODER Parse8BIM: %s (%lu)\",line, (unsigned long) inputlen);\n token = MagickAllocateMemory(char *,inputlen);\n+ if (token == (char *) NULL)\n+ goto parse8BIMW_failure;\n newstr = MagickAllocateMemory(char *,inputlen);\n+ if (newstr == (char *) NULL)\n+ goto parse8BIMW_failure;\n while (Tokenizer(&token_info, 0, token, inputlen, line,\n (char *) \"\", (char *) \"=\",\n (char *) \"\\\"\", 0, &brkused,&next,"ed)==0)\n@@ -619,8 +654,9 @@ static long parse8BIMW(Image *ifile, Ima\n break;\n case 2:\n name = MagickAllocateMemory(char *,strlen(newstr)+1);\n- if (name)\n- (void) strcpy(name,newstr);\n+ if (name == (char *) NULL)\n+ goto parse8BIMW_failure;\n+ (void) strcpy(name,newstr);\n break;\n }\n state++;\n@@ -632,7 +668,7 @@ static long parse8BIMW(Image *ifile, Ima\n int\n next;\n \n- unsigned long\n+ size_t\n len;\n \n char\n@@ -649,7 +685,7 @@ static long parse8BIMW(Image *ifile, Ima\n char\n *s = &token[next-1];\n \n- \n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "ff -r 4f748e625c82 -r 8da95e3e5e81 coders/meta.c\nIndex: GraphicsMagick-1.3.21/coders/meta.c\n===================================================================\n--- GraphicsMagick-1.3.21.orig/coders/meta.c\t2015-02-28 21:51:58.000000000 +0100\n@@ -129,14 +129,16 @@ static unsigned int IsMETA(const unsigne\n \n typedef struct _html_code\n {\n- short\n+ unsigned short\n len;\n+\n const char\n *code,\n val;\n+\n } html_code;\n \n-static html_code html_codes[] = {\n+static html_code const html_codes[] = {\n #ifdef HANDLE_GT_LT\n { 4,\"<\",'<' },\n { 4,\">\",'>' },\n@@ -179,29 +181,36 @@ static int stringnicmp(const char *p,con\n return(toupper((int) *p)-toupper((int) *q));\n }\n \n-static int convertHTMLcodes(char *s, int len)\n+static size_t convertHTMLcodes(char *s, const size_t len)\n {\n- if (len <=0 || s==(char*)NULL || *s=='\\0')\n+ int val;\n+\n+ if ((len == 0) || (s == (char*) NULL) || (*s=='\\0'))\n return 0;\n \n- if (s[1] == '#')\n- {\n- int val, o;\n+ /*\n+ Check for hex or decimal character escape.\n \n- if (sscanf(s,\"&#%d;\",&val) == 1)\n- {\n- o = 3;\n- while (s[o] != ';')\n+ e.g. hex: \" \", decimal \" \"\n+\n+ Note that scanf is expected to parse the number in hex or decimal\n+ and that it does not require the terminating ';' to appear in\n+ order to parse the numeric argument.\n+ */\n+ if ((len > 3) && (s[1] == '#') && (strchr(s,';') != (char *) NULL) &&\n+ (sscanf(s,\"&#%d;\",&val) == 1))\n+ {\n+ size_t o = 3;\n+ while (s[o] != ';')\n {\n o++;\n if (o > 5)\n break;\n }\n- if (o < 6)\n- (void) memmove(s+1,s+1+o,strlen(s+1+o)+1);\n- *s = val;\n- return o;\n- }\n+ if (o < 6)\n+ (void) memmove(s+1,s+1+o,strlen(s+1+o)+1);\n+ *s = val;\n+ return o;\n }\n else\n {\n@@ -281,10 +290,10 @@ static long parse8BIM(Image *ifile, Imag\n char\n brkused,\n quoted,\n- *line,\n- *token,\n- *newstr,\n- *name;\n+ *line = (char *) NULL,\n+ *token = (char *) NULL,\n+ *newstr = (char *) NULL,\n+ *name = (char *) NULL;\n \n int\n state,\n@@ -299,7 +308,7 @@ static long parse8BIM(Image *ifile, Imag\n size_t\n inputlen = BUFFER_SZ;\n \n- long\n+ ssize_t\n savedolen = 0L,\n outputlen = 0L;\n \n@@ -313,7 +322,8 @@ static long parse8BIM(Image *ifile, Imag\n dataset = 0;\n recnum = 0;\n line = MagickAllocateMemory(char *,inputlen);\n- name = token = (char *)NULL;\n+ if (line == (char *) NULL)\n+ goto parse8BIM_failure;\n savedpos = 0;\n while(super_fgets(&line,&inputlen,ifile)!=NULL)\n {\n@@ -321,7 +331,11 @@ static long parse8BIM(Image *ifile, Imag\n next=0;\n \n token = MagickAllocateMemory(char *,inputlen);\n+ if (token == (char *) NULL)\n+ goto parse8BIM_failure;\n newstr = MagickAllocateMemory(char *,inputlen);\n+ if (newstr == (char *) NULL)\n+ goto parse8BIM_failure;\n while (Tokenizer(&token_info, 0, token, inputlen, line,\n (char *) \"\", (char *) \"=\",\n (char *) \"\\\"\", 0, &brkused,&next,"ed)==0)\n@@ -354,8 +368,9 @@ static long parse8BIM(Image *ifile, Imag\n break;\n case 2:\n name = MagickAllocateMemory(char *,strlen(newstr)+1);\n- if (name)\n- (void) strcpy(name,newstr);\n+ if (name == (char *) NULL)\n+ goto parse8BIM_failure;\n+ (void) strcpy(name,newstr);\n break;\n }\n state++;\n@@ -367,7 +382,7 @@ static long parse8BIM(Image *ifile, Imag\n int\n next;\n \n- unsigned long\n+ size_t\n len;\n \n char\n@@ -384,7 +399,7 @@ static long parse8BIM(Image *ifile, Imag\n char\n *s = &token[next-1];\n \n- len -= convertHTMLcodes(s, (int) strlen(s));\n+ len -= convertHTMLcodes(s, strlen(s));\n }\n }\n \n@@ -400,6 +415,8 @@ static long parse8BIM(Image *ifile, Imag\n {\n long diff = outputlen - savedolen;\n currentpos = TellBlob(ofile);\n+ if (currentpos < 0)\n+ goto parse8BIM_failure;\n (void) SeekBlob(ofile,savedpos,SEEK_SET);\n (void) WriteBlobMSBLong(ofile,diff);\n (void) SeekBlob(ofile,currentpos,SEEK_SET);\n@@ -433,7 +450,7 @@ static long parse8BIM(Image *ifile, Imag\n next=0;\n outputlen += len;\n while (len--)\n- (void) WriteBlobByte(ofile,token[next++]);\n+ (void) WriteBlobByte(ofile,token[next++]); /* boom */\n \n if (outputlen & 1)\n {\n@@ -445,6 +462,8 @@ static long parse8BIM(Image *ifile, Imag\n {\n /* patch in a fake length for now and fix it later */\n savedpos = TellBlob(ofile);\n+ if (savedpos < 0)\n+ goto parse8BIM_failure;\n (void) WriteBlobMSBLong(ofile,0xFFFFFFFFUL);\n outputlen += 4;\n savedolen = outputlen;\n@@ -478,12 +497,22 @@ static long parse8BIM(Image *ifile, Imag\n long diff = outputlen - savedolen;\n \n currentpos = TellBlob(ofile);\n+ if (currentpos < 0)\n+ goto parse8BIM_failure;\n+\n (void) SeekBlob(ofile,savedpos,SEEK_SET);\n (void) WriteBlobMSBLong(ofile,diff);\n (void) SeekBlob(ofile,currentpos,SEEK_SET);\n savedolen = 0L;\n }\n return outputlen;\n+\n+ parse8BIM_failure:\n+ MagickFreeMemory(token);\n+ MagickFreeMemory(newstr);\n+ MagickFreeMemory(name);\n+ MagickFreeMemory(line);\n+ return 0L;\n }\n \n static char *super_fgets_w(char **b, size_t *blen, Image *file)\n@@ -542,10 +571,10 @@ static long parse8BIMW(Image *ifile, Ima\n char\n brkused,\n quoted,\n- *line,\n- *token,\n- *newstr,\n- *name;\n+ *line = (char *) NULL,\n+ *token = (char *) NULL,\n+ *newstr = (char *) NULL,\n+ *name = (char *) NULL;\n \n int\n state,\n@@ -560,7 +589,7 @@ static long parse8BIMW(Image *ifile, Ima\n size_t\n inputlen = BUFFER_SZ;\n \n- long\n+ ssize_t\n savedolen = 0L,\n outputlen = 0L;\n \n@@ -574,6 +603,8 @@ static long parse8BIMW(Image *ifile, Ima\n dataset = 0;\n recnum = 0;\n line = MagickAllocateMemory(char *,inputlen);\n+ if (line == (char *) NULL)\n+ goto parse8BIMW_failure;\n name = token = (char *)NULL;\n savedpos = 0;\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n@@ -586,7 +617,11 @@ static long parse8BIMW(Image *ifile, Ima\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \"META CODER Parse8BIM: %s (%lu)\",line, (unsigned long) inputlen);\n token = MagickAllocateMemory(char *,inputlen);\n+ if (token == (char *) NULL)\n+ goto parse8BIMW_failure;\n newstr = MagickAllocateMemory(char *,inputlen);\n+ if (newstr == (char *) NULL)\n+ goto parse8BIMW_failure;\n while (Tokenizer(&token_info, 0, token, inputlen, line,\n (char *) \"\", (char *) \"=\",\n (char *) \"\\\"\", 0, &brkused,&next,"ed)==0)\n@@ -619,8 +654,9 @@ static long parse8BIMW(Image *ifile, Ima\n break;\n case 2:\n name = MagickAllocateMemory(char *,strlen(newstr)+1);\n- if (name)\n- (void) strcpy(name,newstr);\n+ if (name == (char *) NULL)\n+ goto parse8BIMW_failure;\n+ (void) strcpy(name,newstr);\n break;\n }\n state++;\n@@ -632,7 +668,7 @@ static long parse8BIMW(Image *ifile, Ima\n int\n next;\n \n- unsigned long\n+ size_t\n len;\n \n char\n@@ -649,7 +685,7 @@ static long parse8BIMW(Image *ifile, Ima\n char\n *s = &token[next-1];\n \n- len -= convertHTMLcodes(s, (int) strlen(s));\n+ len -= convertHTMLcodes(s, strlen(s));\n }\n }\n \n@@ -665,6 +701,8 @@ static long parse8BIMW(Image *ifile, Ima\n {\n long diff = outputlen - savedolen;\n currentpos = TellBlob(ofile);\n+ if (currentpos < 0)\n+ goto parse8BIMW_failure;\n (void) SeekBlob(ofile,savedpos,SEEK_SET);\n (void) WriteBlobMSBLong(ofile,diff);\n (void) SeekBlob(ofile,currentpos,SEEK_SET);\n@@ -710,6 +748,8 @@ static long parse8BIMW(Image *ifile, Ima\n {\n /* patch in a fake length for now and fix it later */\n savedpos = TellBlob(ofile);\n+ if (savedpos < 0)\n+ goto parse8BIMW_failure;\n (void) WriteBlobMSBLong(ofile,0xFFFFFFFFUL);\n outputlen += 4;\n savedolen = outputlen;\n@@ -743,12 +783,21 @@ static long parse8BIMW(Image *ifile, Ima\n long diff = outputlen - savedolen;\n \n currentpos = TellBlob(ofile);\n+ if (currentpos < 0)\n+ goto parse8BIMW_failure;\n (void) SeekBlob(ofile,savedpos,SEEK_SET);\n (void) WriteBlobMSBLong(ofile,diff);\n (void) SeekBlob(ofile,currentpos,SEEK_SET);\n savedolen = 0L;\n }\n return outputlen;\n+\n+ parse8BIMW_failure:\n+ MagickFreeMemory(token);\n+ MagickFreeMemory(newstr);\n+ MagickFreeMemory(name);\n+ MagickFreeMemory(line);\n+ return 0L;\n }\n \n /* some defines for the different JPEG block types */\n@@ -835,11 +884,12 @@ static int jpeg_skip_variable(Image *ifi\n return 0;\n }\n \n-static int jpeg_skip_variable2(Image *ifile, Image *ARGUNUSED(ofile))\n+static int jpeg_skip_variable2(Image *ifile, Image *ofile)\n {\n unsigned int length;\n int c1,c2;\n \n+ ARG_NOT_USED(ofile);\n if ((c1 = ReadBlobByte(ifile)) == EOF) return M_EOI;\n if ((c2 = ReadBlobByte(ifile)) == EOF) return M_EOI;\n \n@@ -908,8 +958,6 @@ static int jpeg_skip_till_marker(Image *\n }\n #endif\n \n-static char psheader[] = \"\\xFF\\xED\\0\\0Photoshop 3.0\\08BIM\\x04\\x04\\0\\0\\0\\0\";\n-\n /* Embed binary IPTC data into a JPEG image. */\n static int jpeg_embed(Image *ifile, Image *ofile, Image *iptc)\n {\n@@ -952,9 +1000,12 @@ static int jpeg_embed(Image *ifile, Imag\n \n if (iptc != (Image *)NULL)\n {\n+ static const char psheader_base[] = \"\\xFF\\xED\\0\\0Photoshop 3.0\\08BIM\\x04\\x04\\0\\0\\0\\0\";\n+ char psheader[sizeof(psheader_base)];\n len=GetBlobSize(iptc);\n if (len & 1)\n len++; /* make the length even */\n+ (void) strlcpy(psheader,psheader_base,sizeof(psheader));\n psheader[ 2 ] = (len+16)>>8;\n psheader[ 3 ] = (len+16)&0xff;\n for (inx = 0; inx < 18; inx++)\n@@ -1250,7 +1301,7 @@ static Image *ReadMETAImage(const ImageI\n \n DestroyImage(buff);\n }\n- if (LocaleCompare(image_info->magick,\"IPTC\") == 0)\n+ if (LocaleNCompare(image_info->magick,\"IPTC\",4) == 0)\n {\n buff=AllocateImage((ImageInfo *) NULL);\n if (buff == (Image *) NULL)\n@@ -1260,7 +1311,7 @@ static Image *ReadMETAImage(const ImageI\n {\n DestroyImage(buff);\n ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,\n- image)\n+ image);\n }\n AttachBlob(buff->blob,blob,length);\n /* write out the header - length field patched below */\n@@ -1286,14 +1337,21 @@ static Image *ReadMETAImage(const ImageI\n }\n \n /* subtract off the length of the 8BIM stuff */\n+ blob=GetBlobStreamData(buff); /* blob may be realloced */\n+ if ((blob == (const unsigned char *) NULL) || (GetBlobSize(buff) < 12))\n+ {\n+ DestroyImage(buff);\n+ ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,\n+ image);\n+ }\n length=GetBlobSize(buff)-12;\n blob[10]=(unsigned char) ((length >> 8) & 0xff);\n blob[11]=(unsigned char) (length & 0xff);\n blob=GetBlobStreamData(buff);\n length=GetBlobSize(buff);\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n- \"Store IPTC profile, size %lu bytes\",\n- (unsigned long) length);\n+ \"Store IPTC profile, size %\" MAGICK_SIZE_T_F\n+ \"u bytes\",(MAGICK_SIZE_T) length);\n (void) SetImageProfile(image,\"IPTC\",blob,length);\n DetachBlob(buff->blob);\n MagickFreeMemory(blob)\n@@ -1840,9 +1898,14 @@ static int formatIPTC(Image *ifile, Imag\n else\n {\n if (foundiptc)\n- return -1;\n+ {\n+ return -1;\n+ }\n else\n- continue;\n+ {\n+ c = ReadBlobByte(ifile);\n+ continue;\n+ }\n }\n \n /* we found the 0x1c tag and now grab the dataset and record number tags */\n@@ -1888,7 +1951,11 @@ static int formatIPTC(Image *ifile, Imag\n for (tagindx=0; tagindxpkey.rsa, indent, 0);\n\t}\n\n\nstatic int rsa_priv_print(BIO *bp, const EVP_PKEY *pkey, int indent,\n\t\t\t\t\t\t\tASN1_PCTX *ctx)\n\t{\n\treturn do_rsa_print(bp, pkey->pkey.rsa, indent, 1);\n\t}\n\nstatic RSA_PSS_PARAMS *rsa_pss_decode(const X509_ALGOR *alg,\n\t\t\t\t\tX509_ALGOR **pmaskHash)\n\t{\n\tconst unsigned char *p;\n\tint plen;\n\tRSA_PSS_PARAMS *pss;\n\n\t*pmaskHash = NULL;\n\n\tif (!alg->parameter || alg->parameter->type != V_ASN1_SEQUENCE)\n\t\treturn NULL;\n\tp = alg->parameter->value.sequence->data;\n\tplen = alg->parameter->value.sequence->length;\n\tpss = d2i_RSA_PSS_PARAMS(NULL, &p, plen);\n\n\tif (!pss)\n\t\treturn NULL;\n\t\n\tif (pss->maskGenAlgorithm)\n\t\t{\n\t\tASN1_TYPE *param = pss->maskGenAlgorithm->parameter;\n\t\tif (OBJ_obj2nid(pss->maskGenAlgorithm->algorithm) == NID_mgf1\n\t\t\t&& param->type == V_ASN1_SEQUENCE)\n\t\t\t{\n\t\t\tp = param->value.sequence->data;\n\t\t\tplen = param->value.sequence->length;\n\t\t\t*pmaskHash = d2i_X509_ALGOR(NULL, &p, plen);\n\t\t\t}\n\t\t}\n\n\treturn pss;\n\t}\n\nstatic int rsa_pss_param_print(BIO *bp, RSA_PSS_PARAMS *pss, \n\t\t\t\tX509_ALGOR *maskHash, int indent)\n\t{\n\tint rv = 0;\n\tif (!pss)\n\t\t{\n\t\tif (BIO_puts(bp, \" (INVALID PSS PARAMETERS)\\n\") <= 0)\n\t\t\treturn 0;\n\t\treturn 1;\n\t\t}\n\tif (BIO_puts(bp, \"\\n\") <= 0)\n\t\tgoto err;\n\tif (!BIO_indent(bp, indent, 128))\n\t\tgoto err;\n\tif (BIO_puts(bp, \"Hash Algorithm: \") <= 0)\n\t\tgoto err;\n\n\tif (pss->hashAlgorithm)\n\t\t{\n\t\tif (i2a_ASN1_OBJECT(bp, pss->hashAlgorithm->algorithm) <= 0)\n\t\t\tgoto err;\n\t\t}\n\telse if (BIO_puts(bp, \"sha1 (default)\") <= 0)\n\t\tgoto err;\n\n\tif (BIO_puts(bp, \"\\n\") <= 0)\n\t\tgoto err;\n\n\tif (!BIO_indent(bp, indent, 128))\n\t\tgoto err;\n\n\tif (BIO_puts(bp, \"Mask Algorithm: \") <= 0)\n\t\t\tgoto err;\n\tif (pss->maskGenAlgorithm)\n\t\t{\n```\n\n\n## Upstream Fix\n```diff\nFrom d8541d7e9e63bf5f343af24644046c8d96498c17 Mon Sep 17 00:00:00 2001\nFrom: \"Dr. Stephen Henson\" \nDate: Fri, 2 Oct 2015 13:10:29 +0100\nSubject: [PATCH] Add PSS parameter check.\nMIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\n\nAvoid seg fault by checking mgf1 parameter is not NULL. This can be\ntriggered during certificate verification so could be a DoS attack\nagainst a client or a server enabling client authentication.\n\nThanks to Loïc Jonas Etienne (Qnective AG) for discovering this bug.\n\nCVE-2015-3194\n\nReviewed-by: Matt Caswell \n---\n crypto/rsa/rsa_ameth.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/crypto/rsa/rsa_ameth.c b/crypto/rsa/rsa_ameth.c\nindex 93e071de75e2a..c7f1148a1ded1 100644\n--- a/crypto/rsa/rsa_ameth.c\n+++ b/crypto/rsa/rsa_ameth.c\n@@ -279,7 +279,7 @@ static RSA_PSS_PARAMS *rsa_pss_decode(const X509_ALGOR *alg,\n if (pss->maskGenAlgorithm) {\n ASN1_TYPE *param = pss->maskGenAlgorithm->parameter;\n if (OBJ_obj2nid(pss->maskGenAlgorithm->algorithm) == NID_mgf1\n- && param->type == V_ASN1_SEQUENCE) {\n+ && param && param->type == V_ASN1_SEQUENCE) {\n p = param->value.sequence->data;\n plen = param->value.sequence->length;\n *pmaskHash = d2i_X509_ALGOR(NULL, &p, plen);\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From d8541d7e9e63bf5f343af24644046c8d96498c17 Mon Sep 17 00:00:00 2001\nFrom: \"Dr. Stephen Henson\" \nDate: Fri, 2 Oct 2015 13:10:29 +0100\nSubject: [PATCH] Add PSS parameter check.\nMIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\n\nAvoid seg fault by checking mgf1 parameter is not NULL. This can be\ntriggered during certificate verification so could be a DoS attack\nagainst a client or a server enabling client authentication.\n\nThanks to Loïc Jonas Etienne (Qnective AG) for discovering this bug.\n\nCVE-2015-3194\n\nReviewed-by: Matt Caswell \n---\n crypto/rsa/rsa_ameth.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\nIndex: openssl-1.0.1i/crypto/rsa/rsa_ameth.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/rsa/rsa_ameth.c\t2015-12-03 17:56:38.292632624 +0100\n+++ openssl-1.0.1i/crypto/rsa/rsa_ameth.c\t2015-12-03 17:58:11.106130819 +0100\n@@ -287,7 +287,7 @@ static RSA_PSS_PARAMS *rsa_pss_decode(co\n \t\t{\n \t\tASN1_TYPE *param = pss->maskGenAlgorithm->parameter;\n \t\tif (OBJ_obj2nid(pss->maskGenAlgorithm->algorithm) == NID_mgf1\n-\t\t\t&& param->type == V_ASN1_SEQUENCE)\n+\t\t\t&& param && param->type == V_ASN1_SEQUENCE)\n \t\t\t{\n \t\t\tp = param->value.sequence->data;\n \t\t\tplen = param->value.sequence->length;"}], "metadata": {"id": "openssl-4769-openssl-CVE-2015-3194.patch", "cve_id": "CVE-2015-3197", "package": "openssl", "upstream_enriched": true, "upstream_commit": "d8541d7e9e63bf5f343af24644046c8d96498c17", "upstream_repo": "openssl/openssl", "tier": "adapted", "has_source_context": true, "context_tokens_est": 478, "context_files": 1, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-4658\n\nxpointer.c in libxml2 before 2.9.5 (as used in Apple iOS before 10, OS X before 10.12, tvOS before 10, and watchOS before 3, and other products) does not forbid namespace nodes in XPointer ranges, which allows remote attackers to execute arbitrary code or cause a denial of service (use-after-free and memory corruption) via a crafted XML document.\n\n## Package\nlibxml2\n\n## Files to modify\n- xmlregexp.c\n\n## Upstream Fix\n```diff\nFrom cbb271655cadeb8dbb258a64701d9a3a0c4835b4 Mon Sep 17 00:00:00 2001\nFrom: Pranjal Jumde \nDate: Mon, 7 Mar 2016 06:34:26 -0800\nSubject: [PATCH] Bug 757711: heap-buffer-overflow in xmlFAParsePosCharGroup\n \n\n* xmlregexp.c:\n(xmlFAParseCharRange): Only advance to the next character if\nthere is no error. Advancing to the next character in case of\nan error while parsing regexp leads to an out of bounds access.\n---\n xmlregexp.c | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/xmlregexp.c b/xmlregexp.c\nindex 727fef4d70..ca3b4f46dc 100644\n--- a/xmlregexp.c\n+++ b/xmlregexp.c\n@@ -5057,11 +5057,12 @@ xmlFAParseCharRange(xmlRegParserCtxtPtr ctxt) {\n \tERROR(\"Expecting the end of a char range\");\n \treturn;\n }\n- NEXTL(len);\n+\n /* TODO check that the values are acceptable character ranges for XML */\n if (end < start) {\n \tERROR(\"End of range is before start of range\");\n } else {\n+ NEXTL(len);\n xmlRegAtomAddRange(ctxt, ctxt->atom, ctxt->neg,\n \t\t XML_REGEXP_CHARVAL, start, end, NULL);\n }\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From cbb271655cadeb8dbb258a64701d9a3a0c4835b4 Mon Sep 17 00:00:00 2001\nFrom: Pranjal Jumde \nDate: Mon, 7 Mar 2016 06:34:26 -0800\nSubject: Bug 757711: heap-buffer-overflow in xmlFAParsePosCharGroup\n \n\n* xmlregexp.c:\n(xmlFAParseCharRange): Only advance to the next character if\nthere is no error. Advancing to the next character in case of\nan error while parsing regexp leads to an out of bounds access.\n---\n xmlregexp.c | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/xmlregexp.c b/xmlregexp.c\nindex 727fef4..ca3b4f4 100644\n--- a/xmlregexp.c\n+++ b/xmlregexp.c\n@@ -5057,11 +5057,12 @@ xmlFAParseCharRange(xmlRegParserCtxtPtr ctxt) {\n \tERROR(\"Expecting the end of a char range\");\n \treturn;\n }\n- NEXTL(len);\n+\n /* TODO check that the values are acceptable character ranges for XML */\n if (end < start) {\n \tERROR(\"End of range is before start of range\");\n } else {\n+ NEXTL(len);\n xmlRegAtomAddRange(ctxt, ctxt->atom, ctxt->neg,\n \t\t XML_REGEXP_CHARVAL, start, end, NULL);\n }\n-- \ncgit v0.12"}], "metadata": {"id": "libxml2-5762-libxml2-2.9.1-CVE-2016-1840.pa", "cve_id": "CVE-2016-4658", "package": "libxml2", "upstream_enriched": true, "upstream_commit": "cbb271655cadeb8dbb258a64701d9a3a0c4835b4", "upstream_repo": "GNOME/libxml2", "tier": "adapted", "has_source_context": false, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1i/ssl/ssl_err.c\n- openssl-1.0.1i.orig/ssl/ssl_locl.h\n- openssl-1.0.1i.orig/ssl/ssl_sess.c\n- openssl-1.0.1i.orig/ssl/s3_clnt.c\n- openssl-1.0.1i/ssl/ssl_locl.h\n\n## Target Source Code\n\n### ssl/ssl.h\n\n#### ERR_load_SSL_strings() [lines 2215-2301]\n```c\n#define SSL_F_SSL_CTX_USE_CERTIFICATE\t\t\t 171\n#define SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1\t\t 172\n#define SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE\t 220\n#define SSL_F_SSL_CTX_USE_CERTIFICATE_FILE\t\t 173\n#define SSL_F_SSL_CTX_USE_PRIVATEKEY\t\t\t 174\n#define SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1\t\t 175\n#define SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE\t\t 176\n#define SSL_F_SSL_CTX_USE_PSK_IDENTITY_HINT\t\t 272\n#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY\t\t\t 177\n#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1\t\t 178\n#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE\t\t 179\n#define SSL_F_SSL_DO_HANDSHAKE\t\t\t\t 180\n#define SSL_F_SSL_GET_NEW_SESSION\t\t\t 181\n#define SSL_F_SSL_GET_PREV_SESSION\t\t\t 217\n#define SSL_F_SSL_GET_SERVER_SEND_CERT\t\t\t 182\n#define SSL_F_SSL_GET_SERVER_SEND_PKEY\t\t\t 317\n#define SSL_F_SSL_GET_SIGN_PKEY\t\t\t\t 183\n#define SSL_F_SSL_INIT_WBIO_BUFFER\t\t\t 184\n#define SSL_F_SSL_LOAD_CLIENT_CA_FILE\t\t\t 185\n#define SSL_F_SSL_NEW\t\t\t\t\t 186\n#define SSL_F_SSL_PARSE_CLIENTHELLO_RENEGOTIATE_EXT\t 300\n#define SSL_F_SSL_PARSE_CLIENTHELLO_TLSEXT\t\t 302\n#define SSL_F_SSL_PARSE_CLIENTHELLO_USE_SRTP_EXT\t 310\n#define SSL_F_SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT\t 301\n#define SSL_F_SSL_PARSE_SERVERHELLO_TLSEXT\t\t 303\n#define SSL_F_SSL_PARSE_SERVERHELLO_USE_SRTP_EXT\t 311\n#define SSL_F_SSL_PEEK\t\t\t\t\t 270\n#define SSL_F_SSL_PREPARE_CLIENTHELLO_TLSEXT\t\t 281\n#define SSL_F_SSL_PREPARE_SERVERHELLO_TLSEXT\t\t 282\n#define SSL_F_SSL_READ\t\t\t\t\t 223\n#define SSL_F_SSL_RSA_PRIVATE_DECRYPT\t\t\t 187\n#define SSL_F_SSL_RSA_PUBLIC_ENCRYPT\t\t\t 188\n#define SSL_F_SSL_SESSION_NEW\t\t\t\t 189\n#define SSL_F_SSL_SESSION_PRINT_FP\t\t\t 190\n#define SSL_F_SSL_SESSION_SET1_ID_CONTEXT\t\t 312\n#define SSL_F_SSL_SESS_CERT_NEW\t\t\t\t 225\n#define SSL_F_SSL_SET_CERT\t\t\t\t 191\n#define SSL_F_SSL_SET_CIPHER_LIST\t\t\t 271\n#define SSL_F_SSL_SET_FD\t\t\t\t 192\n#define SSL_F_SSL_SET_PKEY\t\t\t\t 193\n#define SSL_F_SSL_SET_PURPOSE\t\t\t\t 227\n#define SSL_F_SSL_SET_RFD\t\t\t\t 194\n#define SSL_F_SSL_SET_SESSION\t\t\t\t 195\n#define SSL_F_SSL_SET_SESSION_ID_CONTEXT\t\t 218\n#define SSL_F_SSL_SET_SESSION_TICKET_EXT\t\t 294\n#define SSL_F_SSL_SET_TRUST\t\t\t\t 228\n#define SSL_F_SSL_SET_WFD\t\t\t\t 196\n#define SSL_F_SSL_SHUTDOWN\t\t\t\t 224\n#define SSL_F_SSL_SRP_CTX_INIT\t\t\t\t 313\n#define SSL_F_SSL_UNDEFINED_CONST_FUNCTION\t\t 243\n#define SSL_F_SSL_UNDEFINED_FUNCTION\t\t\t 197\n#define SSL_F_SSL_UNDEFINED_VOID_FUNCTION\t\t 244\n#define SSL_F_SSL_USE_CERTIFICATE\t\t\t 198\n#define SSL_F_SSL_USE_CERTIFICATE_ASN1\t\t\t 199\n#define SSL_F_SSL_USE_CERTIFICATE_FILE\t\t\t 200\n#define SSL_F_SSL_USE_PRIVATEKEY\t\t\t 201\n#define SSL_F_SSL_USE_PRIVATEKEY_ASN1\t\t\t 202\n#define SSL_F_SSL_USE_PRIVATEKEY_FILE\t\t\t 203\n#define SSL_F_SSL_USE_PSK_IDENTITY_HINT\t\t\t 273\n#define SSL_F_SSL_USE_RSAPRIVATEKEY\t\t\t 204\n#define SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1\t\t 205\n#define SSL_F_SSL_USE_RSAPRIVATEKEY_FILE\t\t 206\n#define SSL_F_SSL_VERIFY_CERT_CHAIN\t\t\t 207\n#define SSL_F_SSL_WRITE\t\t\t\t\t 208\n#define SSL_F_TLS1_CERT_VERIFY_MAC\t\t\t 286\n#define SSL_F_TLS1_CHANGE_CIPHER_STATE\t\t\t 209\n#define SSL_F_TLS1_CHECK_SERVERHELLO_TLSEXT\t\t 274\n#define SSL_F_TLS1_ENC\t\t\t\t\t 210\n#define SSL_F_TLS1_EXPORT_KEYING_MATERIAL\t\t 314\n#define SSL_F_TLS1_HEARTBEAT\t\t\t\t 315\n#define SSL_F_TLS1_PREPARE_CLIENTHELLO_TLSEXT\t\t 275\n#define SSL_F_TLS1_PR\n/* ... truncated ... */\n```\n\n### ssl/s3_clnt.c\n\n#### ssl3_get_new_session_ticket() [lines 2049-2141]\n```c\n\treturn(X509_NAME_cmp(*a,*b));\n\t}\n#ifndef OPENSSL_NO_TLSEXT\nint ssl3_get_new_session_ticket(SSL *s)\n\t{\n\tint ok,al,ret=0, ticklen;\n\tlong n;\n\tconst unsigned char *p;\n\tunsigned char *d;\n\n\tn=s->method->ssl_get_message(s,\n\t\tSSL3_ST_CR_SESSION_TICKET_A,\n\t\tSSL3_ST_CR_SESSION_TICKET_B,\n\t\t-1,\n\t\t16384,\n\t\t&ok);\n\n\tif (!ok)\n\t\treturn((int)n);\n\n\tif (s->s3->tmp.message_type == SSL3_MT_FINISHED)\n\t\t{\n\t\ts->s3->tmp.reuse_message=1;\n\t\treturn(1);\n\t\t}\n\tif (s->s3->tmp.message_type != SSL3_MT_NEWSESSION_TICKET)\n\t\t{\n\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\tSSLerr(SSL_F_SSL3_GET_NEW_SESSION_TICKET,SSL_R_BAD_MESSAGE_TYPE);\n\t\tgoto f_err;\n\t\t}\n\tif (n < 6)\n\t\t{\n\t\t/* need at least ticket_lifetime_hint + ticket length */\n\t\tal = SSL_AD_DECODE_ERROR;\n\t\tSSLerr(SSL_F_SSL3_GET_NEW_SESSION_TICKET,SSL_R_LENGTH_MISMATCH);\n\t\tgoto f_err;\n\t\t}\n\n\tp=d=(unsigned char *)s->init_msg;\n\tn2l(p, s->session->tlsext_tick_lifetime_hint);\n\tn2s(p, ticklen);\n\t/* ticket_lifetime_hint + ticket_length + ticket */\n\tif (ticklen + 6 != n)\n\t\t{\n\t\tal = SSL_AD_DECODE_ERROR;\n\t\tSSLerr(SSL_F_SSL3_GET_NEW_SESSION_TICKET,SSL_R_LENGTH_MISMATCH);\n\t\tgoto f_err;\n\t\t}\n\tif (s->session->tlsext_tick)\n\t\t{\n\t\tOPENSSL_free(s->session->tlsext_tick);\n\t\ts->session->tlsext_ticklen = 0;\n\t\t}\n\ts->session->tlsext_tick = OPENSSL_malloc(ticklen);\n\tif (!s->session->tlsext_tick)\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_GET_NEW_SESSION_TICKET,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tmemcpy(s->session->tlsext_tick, p, ticklen);\n\ts->session->tlsext_ticklen = ticklen;\n\t/* There are two ways to detect a resumed ticket sesion.\n\t * One is to set an appropriate session ID and then the server\n\t * must return a match in ServerHello. This allows the normal\n\t * client session ID matching to work and we know much \n\t * earlier that the ticket has been accepted.\n\t * \n\t * The other way is to set zero length session ID when the\n\t * ticket is presented and rely on the handshake to determine\n\t * session resumption.\n\t *\n\t * We choose the former approach because this fits in with\n\t * assumptions elsewhere in OpenSSL. The session ID is set\n\t * to the SHA256 (or SHA1 is SHA256 is disabled) hash of the\n\t * ticket.\n\t */ \n\tEVP_Digest(p, ticklen,\n\t\t\ts->session->session_id, &s->session->session_id_length,\n#ifndef OPENSSL_NO_SHA256\n\t\t\t\t\t\t\tEVP_sha256(), NULL);\n#else\n\t\t\t\t\t\t\tEVP_sha1(), NULL);\n#endif\n\tret=1;\n\treturn(ret);\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,al);\nerr:\n\treturn(-1);\n\t}\n\nint ssl3_get_cert_status(SSL *s)\n```\n\n### ssl/ssl_err.c\n\n#### region() [lines 206-292]\n```c\n{ERR_FUNC(SSL_F_SSL_CTRL),\t\"SSL_ctrl\"},\n{ERR_FUNC(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY),\t\"SSL_CTX_check_private_key\"},\n{ERR_FUNC(SSL_F_SSL_CTX_MAKE_PROFILES),\t\"SSL_CTX_MAKE_PROFILES\"},\n{ERR_FUNC(SSL_F_SSL_CTX_NEW),\t\"SSL_CTX_new\"},\n{ERR_FUNC(SSL_F_SSL_CTX_SET_CIPHER_LIST),\t\"SSL_CTX_set_cipher_list\"},\n{ERR_FUNC(SSL_F_SSL_CTX_SET_CLIENT_CERT_ENGINE),\t\"SSL_CTX_set_client_cert_engine\"},\n{ERR_FUNC(SSL_F_SSL_CTX_SET_PURPOSE),\t\"SSL_CTX_set_purpose\"},\n{ERR_FUNC(SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT),\t\"SSL_CTX_set_session_id_context\"},\n{ERR_FUNC(SSL_F_SSL_CTX_SET_SSL_VERSION),\t\"SSL_CTX_set_ssl_version\"},\n{ERR_FUNC(SSL_F_SSL_CTX_SET_TRUST),\t\"SSL_CTX_set_trust\"},\n{ERR_FUNC(SSL_F_SSL_CTX_USE_CERTIFICATE),\t\"SSL_CTX_use_certificate\"},\n{ERR_FUNC(SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1),\t\"SSL_CTX_use_certificate_ASN1\"},\n{ERR_FUNC(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE),\t\"SSL_CTX_use_certificate_chain_file\"},\n{ERR_FUNC(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE),\t\"SSL_CTX_use_certificate_file\"},\n{ERR_FUNC(SSL_F_SSL_CTX_USE_PRIVATEKEY),\t\"SSL_CTX_use_PrivateKey\"},\n{ERR_FUNC(SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1),\t\"SSL_CTX_use_PrivateKey_ASN1\"},\n{ERR_FUNC(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE),\t\"SSL_CTX_use_PrivateKey_file\"},\n{ERR_FUNC(SSL_F_SSL_CTX_USE_PSK_IDENTITY_HINT),\t\"SSL_CTX_use_psk_identity_hint\"},\n{ERR_FUNC(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY),\t\"SSL_CTX_use_RSAPrivateKey\"},\n{ERR_FUNC(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1),\t\"SSL_CTX_use_RSAPrivateKey_ASN1\"},\n{ERR_FUNC(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE),\t\"SSL_CTX_use_RSAPrivateKey_file\"},\n{ERR_FUNC(SSL_F_SSL_DO_HANDSHAKE),\t\"SSL_do_handshake\"},\n{ERR_FUNC(SSL_F_SSL_GET_NEW_SESSION),\t\"SSL_GET_NEW_SESSION\"},\n{ERR_FUNC(SSL_F_SSL_GET_PREV_SESSION),\t\"SSL_GET_PREV_SESSION\"},\n{ERR_FUNC(SSL_F_SSL_GET_SERVER_SEND_CERT),\t\"SSL_GET_SERVER_SEND_CERT\"},\n{ERR_FUNC(SSL_F_SSL_GET_SERVER_SEND_PKEY),\t\"SSL_GET_SERVER_SEND_PKEY\"},\n{ERR_FUNC(SSL_F_SSL_GET_SIGN_PKEY),\t\"SSL_GET_SIGN_PKEY\"},\n{ERR_FUNC(SSL_F_SSL_INIT_WBIO_BUFFER),\t\"SSL_INIT_WBIO_BUFFER\"},\n{ERR_FUNC(SSL_F_SSL_LOAD_CLIENT_CA_FILE),\t\"SSL_load_client_CA_file\"},\n{ERR_FUNC(SSL_F_SSL_NEW),\t\"SSL_new\"},\n{ERR_FUNC(SSL_F_SSL_PARSE_CLIENTHELLO_RENEGOTIATE_EXT),\t\"SSL_PARSE_CLIENTHELLO_RENEGOTIATE_EXT\"},\n{ERR_FUNC(SSL_F_SSL_PARSE_CLIENTHELLO_TLSEXT),\t\"SSL_PARSE_CLIENTHELLO_TLSEXT\"},\n{ERR_FUNC(SSL_F_SSL_PARSE_CLIENTHELLO_USE_SRTP_EXT),\t\"SSL_PARSE_CLIENTHELLO_USE_SRTP_EXT\"},\n{ERR_FUNC(SSL_F_SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT),\t\"SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT\"},\n{ERR_FUNC(SSL_F_SSL_PARSE_SERVERHELLO_TLSEXT),\t\"SSL_PARSE_SERVERHELLO_TLSEXT\"},\n{ERR_FUNC(SSL_F_SSL_PARSE_SERVERHELLO_USE_SRTP_EXT),\t\"SSL_PARSE_SERVERHELLO_USE_SRTP_EXT\"},\n{ERR_FUNC(SSL_F_SSL_PEEK),\t\"SSL_peek\"},\n{ERR_FUNC(SSL_F_SSL_PREPARE_CLIENTHELLO_TLSEXT),\t\"SSL_PREPARE_CLIENTHELLO_TLSEXT\"},\n{ERR_FUNC(SSL_F_SSL_PREPARE_SERVERHELLO_TLSEXT),\t\"SSL_PREPARE_SERVERHELLO_TLSEXT\"},\n{ERR_FUNC(SSL_F_SSL_READ),\t\"SSL_read\"},\n{ERR_FUNC(SSL_F_SSL_RSA_PRIVATE_DECRYPT),\t\"SSL_RSA_PRIVATE_DECRYPT\"},\n{ERR_FUNC(SSL_F_SSL_RSA_PUBLIC_ENCRYPT),\t\"SSL_RSA_PUBLIC_ENCRYPT\"},\n{ERR_FUNC(SSL_F_SSL_SESSION_NEW),\t\"SSL_SESSION_new\"},\n{ERR_FUNC(SSL_F_SSL_SESSION_PRINT_FP),\t\"SSL_SESSION_print_fp\"},\n{ERR_FUNC(SSL_F_SSL_SESSION\n/* ... truncated ... */\n```\n\n### ssl/ssl_locl.h\n\n#### ssl_sess_cert_free() [lines 796-882]\n```c\n\t\tdtls1_ctrl, \\\n\t\tssl3_ctx_ctrl, \\\n\t\tssl3_get_cipher_by_char, \\\n\t\tssl3_put_cipher_by_char, \\\n\t\tssl3_pending, \\\n\t\tssl3_num_ciphers, \\\n\t\tdtls1_get_cipher, \\\n\t\ts_get_meth, \\\n\t\tdtls1_default_timeout, \\\n\t\t&DTLSv1_enc_data, \\\n\t\tssl_undefined_void_function, \\\n\t\tssl3_callback_ctrl, \\\n\t\tssl3_ctx_callback_ctrl, \\\n\t}; \\\n\treturn &func_name##_data; \\\n\t}\n\nstruct openssl_ssl_test_functions\n\t{\n\tint (*p_ssl_init_wbio_buffer)(SSL *s, int push);\n\tint (*p_ssl3_setup_buffers)(SSL *s);\n\tint (*p_tls1_process_heartbeat)(SSL *s);\n\tint (*p_dtls1_process_heartbeat)(SSL *s);\n\t};\n\n#ifndef OPENSSL_UNIT_TEST\n\nvoid ssl_clear_cipher_ctx(SSL *s);\nint ssl_clear_bad_session(SSL *s);\nCERT *ssl_cert_new(void);\nCERT *ssl_cert_dup(CERT *cert);\nint ssl_cert_inst(CERT **o);\nvoid ssl_cert_free(CERT *c);\nSESS_CERT *ssl_sess_cert_new(void);\nvoid ssl_sess_cert_free(SESS_CERT *sc);\nint ssl_set_peer_cert_type(SESS_CERT *c, int type);\nint ssl_get_new_session(SSL *s, int session);\nint ssl_get_prev_session(SSL *s, unsigned char *session,int len, const unsigned char *limit);\nint ssl_cipher_id_cmp(const SSL_CIPHER *a,const SSL_CIPHER *b);\nDECLARE_OBJ_BSEARCH_GLOBAL_CMP_FN(SSL_CIPHER, SSL_CIPHER,\n\t\t\t\t ssl_cipher_id);\nint ssl_cipher_ptr_id_cmp(const SSL_CIPHER * const *ap,\n\t\t\tconst SSL_CIPHER * const *bp);\nSTACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num,\n\t\t\t\t\t STACK_OF(SSL_CIPHER) **skp);\nint ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p,\n int (*put_cb)(const SSL_CIPHER *, unsigned char *));\nSTACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *meth,\n\t\t\t\t\t STACK_OF(SSL_CIPHER) **pref,\n\t\t\t\t\t STACK_OF(SSL_CIPHER) **sorted,\n\t\t\t\t\t const char *rule_str);\nvoid ssl_update_cache(SSL *s, int mode);\nint ssl_cipher_get_evp(const SSL_SESSION *s,const EVP_CIPHER **enc,\n\t\t const EVP_MD **md,int *mac_pkey_type,int *mac_secret_size, SSL_COMP **comp);\nint ssl_get_handshake_digest(int i,long *mask,const EVP_MD **md);\t\t\t \nint ssl_verify_cert_chain(SSL *s,STACK_OF(X509) *sk);\nint ssl_undefined_function(SSL *s);\nint ssl_undefined_void_function(void);\nint ssl_undefined_const_function(const SSL *s);\nCERT_PKEY *ssl_get_server_send_pkey(const SSL *s);\nX509 *ssl_get_server_send_cert(const SSL *);\nEVP_PKEY *ssl_get_sign_pkey(SSL *s,const SSL_CIPHER *c, const EVP_MD **pmd);\nint ssl_cert_type(X509 *x,EVP_PKEY *pkey);\nvoid ssl_set_cert_masks(CERT *c, const SSL_CIPHER *cipher);\nSTACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s);\nint ssl_verify_alarm_type(long type);\nvoid ssl_load_ciphers(void);\nint ssl_fill_hello_random(SSL *s, int server, unsigned char *field, int len);\n\nint ssl2_enc_init(SSL *s, int client);\nint ssl2_generate_key_material(SSL *s);\nvoid ssl2_enc(SSL *s,int send_data);\nvoid ssl2_mac(SSL *s,unsigned char *mac,int send_data);\nconst SSL_CIPHER *ssl2_get_cipher_by_char(const unsigned char *p);\nint ssl2_put_cipher_by_char(const SSL_CIPHER *c,unsigned char *p);\nint ssl2_part_read(SSL *s, unsigned long f, int i);\nint ssl2_do_write(SSL *s);\nint ssl2_set_certificate(SSL *s, int type, int len, const unsigned char *data);\nvoid ssl2_return_\n/* ... truncated ... */\n```\n\n### ssl/ssl_sess.c\n\n#### region() [lines 185-271]\n```c\n\treturn(CRYPTO_get_ex_data(&s->ex_data,idx));\n\t}\n\nSSL_SESSION *SSL_SESSION_new(void)\n\t{\n\tSSL_SESSION *ss;\n\n\tss=(SSL_SESSION *)OPENSSL_malloc(sizeof(SSL_SESSION));\n\tif (ss == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_SESSION_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(0);\n\t\t}\n\tmemset(ss,0,sizeof(SSL_SESSION));\n\n\tss->verify_result = 1; /* avoid 0 (= X509_V_OK) just in case */\n\tss->references=1;\n\tss->timeout=60*5+4; /* 5 minute timeout by default */\n\tss->time=(unsigned long)time(NULL);\n\tss->prev=NULL;\n\tss->next=NULL;\n\tss->compress_meth=0;\n#ifndef OPENSSL_NO_TLSEXT\n\tss->tlsext_hostname = NULL; \n#ifndef OPENSSL_NO_EC\n\tss->tlsext_ecpointformatlist_length = 0;\n\tss->tlsext_ecpointformatlist = NULL;\n\tss->tlsext_ellipticcurvelist_length = 0;\n\tss->tlsext_ellipticcurvelist = NULL;\n#endif\n#endif\n\tCRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data);\n#ifndef OPENSSL_NO_PSK\n\tss->psk_identity_hint=NULL;\n\tss->psk_identity=NULL;\n#endif\n#ifndef OPENSSL_NO_SRP\n\tss->srp_username=NULL;\n#endif\n\treturn(ss);\n\t}\n\nconst unsigned char *SSL_SESSION_get_id(const SSL_SESSION *s, unsigned int *len)\n\t{\n\tif(len)\n\t\t*len = s->session_id_length;\n\treturn s->session_id;\n\t}\n\nunsigned int SSL_SESSION_get_compress_id(const SSL_SESSION *s)\n\t{\n\treturn s->compress_meth;\n\t}\n\n/* Even with SSLv2, we have 16 bytes (128 bits) of session ID space. SSLv3/TLSv1\n * has 32 bytes (256 bits). As such, filling the ID with random gunk repeatedly\n * until we have no conflict is going to complete in one iteration pretty much\n * \"most\" of the time (btw: understatement). So, if it takes us 10 iterations\n * and we still can't avoid a conflict - well that's a reasonable point to call\n * it quits. Either the RAND code is broken or someone is trying to open roughly\n * very close to 2^128 (or 2^256) SSL sessions to our server. How you might\n * store that many sessions is perhaps a more interesting question ... */\n\n#define MAX_SESS_ID_ATTEMPTS 10\nstatic int def_generate_session_id(const SSL *ssl, unsigned char *id,\n\t\t\t\tunsigned int *id_len)\n{\n\tunsigned int retry = 0;\n\tdo\n\t\tif (RAND_pseudo_bytes(id, *id_len) <= 0)\n\t\t\treturn 0;\n\twhile(SSL_has_matching_session_id(ssl, id, *id_len) &&\n\t\t(++retry < MAX_SESS_ID_ATTEMPTS));\n\tif(retry < MAX_SESS_ID_ATTEMPTS)\n\t\treturn 1;\n\t/* else - woops a session_id match */\n\t/* XXX We should also check the external cache --\n\t * but the probability of a collision is negligible, and\n\t * we could not prevent the concurrent creation of sessions\n\t * with identical IDs since we currently don't have means\n\t * to atomically check whether a session ID already exists\n\t * and make a reservation for it if it does not\n\t * (this problem applies to the internal cache as well).\n\t */\n\treturn 0;\n}\n\n```\n\n\n## Upstream Fix\n```diff\ncommit 98ece4eebfb6cd45cc8d550c6ac0022965071afc\nAuthor: Matt Caswell \nDate: Mon May 18 16:27:48 2015 +0100\n\n Fix race condition in NewSessionTicket\n \n If a NewSessionTicket is received by a multi-threaded client when\n attempting to reuse a previous ticket then a race condition can occur\n potentially leading to a double free of the ticket data.\n \n CVE-2015-1791\n \n This also fixes RT#3808 where a session ID is changed for a session already\n in the client session cache. Since the session ID is the key to the cache\n this breaks the cache access.\n \n Parts of this patch were inspired by this Akamai change:\n https://github.com/akamai/openssl/commit/c0bf69a791239ceec64509f9f19fcafb2461b0d3\n \n Reviewed-by: Rich Salz \n\ncommit 907f04a30354615e54beaa2bc0b986083f7793ee\nAuthor: Matt Caswell \nDate: Thu Jun 11 01:30:06 2015 +0100\n\n More ssl_session_dup fixes\n \n Fix error handling in ssl_session_dup, as well as incorrect setting up of\n the session ticket. Follow on from CVE-2015-1791.\n \n Thanks to LibreSSL project for reporting these issues.\n \n Conflicts:\n \tssl/ssl_sess.c\n \n Reviewed-by: Tim Hudson \n\nIndex: openssl-1.0.1i/ssl/ssl.h\n===================================================================\n--- openssl-1.0.1i.orig/ssl/ssl.h\t2015-06-12 19:15:11.549954732 +0200\n+++ openssl-1.0.1i/ssl/ssl.h\t2015-06-12 19:15:13.279975926 +0200\n@@ -2254,6 +2254,7 @@ void ERR_load_SSL_strings(void);\n #define SSL_F_SSL_READ\t\t\t\t\t 223\n #define SSL_F_SSL_RSA_PRIVATE_DECRYPT\t\t\t 187\n #define SSL_F_SSL_RSA_PUBLIC_ENCRYPT\t\t\t 188\n+#define SSL_F_SSL_SESSION_DUP\t\t\t\t 348\n #define SSL_F_SSL_SESSION_NEW\t\t\t\t 189\n #define SSL_F_SSL_SESSION_PRINT_FP\t\t\t 190\n #define SSL_F_SSL_SESSION_SET1_ID_CONTEXT\t\t 312\nIndex: openssl-1.0.1i/ssl/s3_clnt.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s3_clnt.c\t2015-06-12 19:15:11.549954732 +0200\n+++ openssl-1.0.1i/ssl/s3_clnt.c\t2015-06-12 19:15:13.279975926 +0200\n@@ -2105,6 +2105,38 @@ int ssl3_get_new_session_ticket(SSL *s)\n \t\t}\n \n \tp=d=(unsigned char *)s->init_msg;\n+\n+ if (s->session->session_id_length > 0) {\n+ int i = s->session_ctx->session_cache_mode;\n+ SSL_SESSION *new_sess;\n+ /*\n+ * We reused an existing session, so we need to replace it with a new\n+ * one\n+ */\n+ if (i & SSL_SESS_CACHE_CLIENT) {\n+ /*\n+ * Remove the old session from the cache\n+ */\n+ if (i & SSL_SESS_CACHE_NO_INTERNAL_STORE) {\n+ if (s->session_ctx->remove_session_cb != NULL)\n+ s->session_ctx->remove_session_cb(s->session_ctx,\n+ s->session);\n+ } else {\n+ /* We carry on if this fails */\n+ SSL_CTX_remove_session(s->session_ctx, s->session);\n+ }\n+ }\n+\n+ if ((new_sess = ssl_session_dup(s->session, 0)) == 0) {\n+ al = SSL_AD_INTERNAL_ERROR;\n+ SSLerr(SSL_F_SSL3_GET_NEW_SESSION_TICKET, ERR_R_MALLOC_FAILURE);\n+ goto f_err;\n+ }\n+\n+ SSL_SESSION_free(s->session);\n+ s->session = new_sess;\n+ }\n+\n \tn2l(p, s->session->tlsext_tick_lifetime_hint);\n \tn2s(p, ticklen);\n \t/* ticket_lifetime_hint + ticket_length + ticket */\nIndex: openssl-1.0.1i/ssl/ssl_err.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/ssl_err.c\t2015-06-12 19:15:11.549954732 +0200\n+++ openssl-1.0.1i/ssl/ssl_err.c\t2015-06-12 19:15:13.280975939 +0200\n@@ -245,6 +245,7 @@ static ERR_STRING_DATA SSL_str_functs[]=\n {ERR_FUNC(SSL_F_SSL_READ),\t\"SSL_read\"},\n {ERR_FUNC(SSL_F_SSL_RSA_PRIVATE_DECRYPT),\t\"SSL_RSA_PRIVATE_DECRYPT\"},\n {ERR_FUNC(SSL_F_SSL_RSA_PUBLIC_ENCRYPT),\t\"SSL_RSA_PUBLIC_ENCRYPT\"},\n+{ERR_FUNC(SSL_F_SSL_SESSION_DUP), \"ssl_session_dup\"},\n {ERR_FUNC(SSL_F_SSL_SESSION_NEW),\t\"SSL_SESSION_new\"},\n {ERR_FUNC(SSL_F_SSL_SESSION_PRINT_FP),\t\"SSL_SESSION_print_fp\"},\n {ERR_FUNC(SSL_F_SSL_SESSION_SET1_ID_CONTEXT),\t\"SSL_SESSION_set1_id_context\"},\nIndex: openssl-1.0.1i/ssl/ssl_locl.h\n===================================================================\n--- openssl-1.0.1i.orig/ssl/ssl_locl.h\t2015-06-12 19:15:11.549954732 +0200\n+++ openssl-1.0.1i/ssl/ssl_locl.h\t2015-06-12 19:15:13.280975939 +0200\n@@ -835,6 +835,7 @@ void ssl_sess_cert_free(SESS_CERT *sc);\n int ssl_set_peer_cert_type(SESS_CERT *c, int type);\n int ssl_get_new_session(SSL *s, int session);\n int ssl_get_prev_session(SSL *s, unsigned char *session,int len, const unsigned char *limit);\n+SSL_SESSION *ssl_session_dup(SSL_SESSION *src, int ticket);\n int ssl_cipher_id_cmp(const SSL_CIPHER *a,const SSL_CIPHER *b);\n DECLARE_OBJ_BSEARCH_GLOBAL_CMP_FN(SSL_CIPHER, SSL_CIPHER,\n \t\t\t\t ssl_cipher_id);\nIndex: openssl-1.0.1i/ssl/ssl_sess.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/ssl_sess.c\t2015-06-12 19:15:11.549954732 +0200\n+++ openssl-1.0.1i/ssl/ssl_sess.c\t2015-06-12 19:26:20.502163556 +0200\n@@ -224,6 +224,129 @@ SSL_SESSION *SSL_SESSION_new(void)\n \treturn(ss);\n \t}\n \n+/*\n+ * Create a new SSL_SESSION and duplicate the contents of |src| into it. If\n+ * ticket == 0 then no ticket information is duplicated, otherwise it is.\n+ */\n+SSL_SESSION *ssl_session_dup(SSL_SESSION *src, int ticket)\n+{\n+ SSL_SESSION *dest;\n+\n+ dest = OPENSSL_malloc(sizeof(*src));\n+ if (dest == NULL) {\n+ goto err;\n+ }\n+ memcpy(dest, src, sizeof(*dest));\n+\n+ /* Set the various pointers to NULL so that we can call SSL_SESSION_free in\n+ * the case of an error whilst halfway through constructing dest\n+ */\n+#ifndef OPENSSL_NO_PSK\n+ dest->psk_identity_hint = NULL;\n+ dest->psk_identity = NULL;\n+#endif\n+ dest->ciphers = NULL;\n+#ifndef OPENSSL_NO_TLSEXT\n+ dest->tlsext_hostname = NULL;\n+# ifndef OPENSSL_NO_EC\n+ dest->tlsext_ecpointformatlist = NULL;\n+ dest->tlsext_ellipticcurvelist = NULL;\n+# endif\n+#endif\n+ dest->tlsext_tick = NULL;\n+#ifndef OPENSSL_NO_SRP\n+ dest->srp_username = NULL;\n+#endif\n+ memset(&dest->ex_data, 0, sizeof(dest->ex_data));\n+\n+ /* We deliberately don't copy the prev and next pointers */\n+ dest->prev = NULL;\n+ dest->next = NULL;\n+\n+ dest->references = 1;\n+\n+ if (src->sess_cert != NULL)\n+ CRYPTO_add(&src->sess_cert->references, 1, CRYPTO_LOCK_SSL_SESS_CERT);\n+\n+ if (src->peer != NULL)\n+ CRYPTO_add(&src->peer->references, 1, CRYPTO_LOCK_X509);\n+#ifndef OPENSSL_NO_PSK\n+ if (src->psk_identity_hint) {\n+ dest->psk_identity_hint = BUF_strdup(src->psk_identity_hint);\n+ if (dest->psk_identity_hint == NULL) {\n+ goto err;\n+ }\n+ }\n+ if (src->psk_identity) {\n+ dest->psk_identity = BUF_strdup(src->psk_identity);\n+ if (dest->psk_identity == NULL) {\n+ goto err;\n+ }\n+ }\n+#endif\n+\n+ if(src->ciphers != NULL) {\n+ dest->ciphers = sk_SSL_CIPHER_dup(src->ciphers);\n+ if (dest->ciphers == NULL)\n+ goto err;\n+ }\n+\n+ if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_SSL_SESSION,\n+ &dest->ex_data, &src->ex_data)) {\n+ goto err;\n+ }\n+\n+#ifndef OPENSSL_NO_TLSEXT\n+ if (src->tlsext_hostname) {\n+ dest->tlsext_hostname = BUF_strdup(src->tlsext_hostname);\n+ if (dest->tlsext_hostname == NULL) {\n+ goto err;\n+ }\n+ }\n+# ifndef OPENSSL_NO_EC\n+ if (src->tlsext_ecpointformatlist) {\n+ dest->tlsext_ecpointformatlist =\n+ BUF_memdup(src->tlsext_ecpointformatlist,\n+ src->tlsext_ecpointformatlist_length);\n+ if (dest->tlsext_ecpointformatlist == NULL)\n+ goto err;\n+ }\n+ if (src->tlsext_ellipticcurvelist) {\n+ dest->tlsext_ellipticcurvelist =\n+ BUF_memdup(src->tlsext_ellipticcurvelist,\n+ src->t\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "commit 98ece4eebfb6cd45cc8d550c6ac0022965071afc\nAuthor: Matt Caswell \nDate: Mon May 18 16:27:48 2015 +0100\n\n Fix race condition in NewSessionTicket\n \n If a NewSessionTicket is received by a multi-threaded client when\n attempting to reuse a previous ticket then a race condition can occur\n potentially leading to a double free of the ticket data.\n \n CVE-2015-1791\n \n This also fixes RT#3808 where a session ID is changed for a session already\n in the client session cache. Since the session ID is the key to the cache\n this breaks the cache access.\n \n Parts of this patch were inspired by this Akamai change:\n https://github.com/akamai/openssl/commit/c0bf69a791239ceec64509f9f19fcafb2461b0d3\n \n Reviewed-by: Rich Salz \n\ncommit 907f04a30354615e54beaa2bc0b986083f7793ee\nAuthor: Matt Caswell \nDate: Thu Jun 11 01:30:06 2015 +0100\n\n More ssl_session_dup fixes\n \n Fix error handling in ssl_session_dup, as well as incorrect setting up of\n the session ticket. Follow on from CVE-2015-1791.\n \n Thanks to LibreSSL project for reporting these issues.\n \n Conflicts:\n \tssl/ssl_sess.c\n \n Reviewed-by: Tim Hudson \n\nIndex: openssl-1.0.1i/ssl/ssl.h\n===================================================================\n--- openssl-1.0.1i.orig/ssl/ssl.h\t2015-06-12 19:15:11.549954732 +0200\n+++ openssl-1.0.1i/ssl/ssl.h\t2015-06-12 19:15:13.279975926 +0200\n@@ -2254,6 +2254,7 @@ void ERR_load_SSL_strings(void);\n #define SSL_F_SSL_READ\t\t\t\t\t 223\n #define SSL_F_SSL_RSA_PRIVATE_DECRYPT\t\t\t 187\n #define SSL_F_SSL_RSA_PUBLIC_ENCRYPT\t\t\t 188\n+#define SSL_F_SSL_SESSION_DUP\t\t\t\t 348\n #define SSL_F_SSL_SESSION_NEW\t\t\t\t 189\n #define SSL_F_SSL_SESSION_PRINT_FP\t\t\t 190\n #define SSL_F_SSL_SESSION_SET1_ID_CONTEXT\t\t 312\nIndex: openssl-1.0.1i/ssl/s3_clnt.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s3_clnt.c\t2015-06-12 19:15:11.549954732 +0200\n+++ openssl-1.0.1i/ssl/s3_clnt.c\t2015-06-12 19:15:13.279975926 +0200\n@@ -2105,6 +2105,38 @@ int ssl3_get_new_session_ticket(SSL *s)\n \t\t}\n \n \tp=d=(unsigned char *)s->init_msg;\n+\n+ if (s->session->session_id_length > 0) {\n+ int i = s->session_ctx->session_cache_mode;\n+ SSL_SESSION *new_sess;\n+ /*\n+ * We reused an existing session, so we need to replace it with a new\n+ * one\n+ */\n+ if (i & SSL_SESS_CACHE_CLIENT) {\n+ /*\n+ * Remove the old session from the cache\n+ */\n+ if (i & SSL_SESS_CACHE_NO_INTERNAL_STORE) {\n+ if (s->session_ctx->remove_session_cb != NULL)\n+ s->session_ctx->remove_session_cb(s->session_ctx,\n+ s->session);\n+ } else {\n+ /* We carry on if this fails */\n+ SSL_CTX_remove_session(s->session_ctx, s->session);\n+ }\n+ }\n+\n+ if ((new_sess = ssl_session_dup(s->session, 0)) == 0) {\n+ al = SSL_AD_INTERNAL_ERROR;\n+ SSLerr(SSL_F_SSL3_GET_NEW_SESSION_TICKET, ERR_R_MALLOC_FAILURE);\n+ goto f_err;\n+ }\n+\n+ SSL_SESSION_free(s->session);\n+ s->session = new_sess;\n+ }\n+\n \tn2l(p, s->session->tlsext_tick_lifetime_hint);\n \tn2s(p, ticklen);\n \t/* ticket_lifetime_hint + ticket_length + ticket */\nIndex: openssl-1.0.1i/ssl/ssl_err.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/ssl_err.c\t2015-06-12 19:15:11.549954732 +0200\n+++ openssl-1.0.1i/ssl/ssl_err.c\t2015-06-12 19:15:13.280975939 +0200\n@@ -245,6 +245,7 @@ static ERR_STRING_DATA SSL_str_functs[]=\n {ERR_FUNC(SSL_F_SSL_READ),\t\"SSL_read\"},\n {ERR_FUNC(SSL_F_SSL_RSA_PRIVATE_DECRYPT),\t\"SSL_RSA_PRIVATE_DECRYPT\"},\n {ERR_FUNC(SSL_F_SSL_RSA_PUBLIC_ENCRYPT),\t\"SSL_RSA_PUBLIC_ENCRYPT\"},\n+{ERR_FUNC(SSL_F_SSL_SESSION_DUP), \"ssl_session_dup\"},\n {ERR_FUNC(SSL_F_SSL_SESSION_NEW),\t\"SSL_SESSION_new\"},\n {ERR_FUNC(SSL_F_SSL_SESSION_PRINT_FP),\t\"SSL_SESSION_print_fp\"},\n {ERR_FUNC(SSL_F_SSL_SESSION_SET1_ID_CONTEXT),\t\"SSL_SESSION_set1_id_context\"},\nIndex: openssl-1.0.1i/ssl/ssl_locl.h\n===================================================================\n--- openssl-1.0.1i.orig/ssl/ssl_locl.h\t2015-06-12 19:15:11.549954732 +0200\n+++ openssl-1.0.1i/ssl/ssl_locl.h\t2015-06-12 19:15:13.280975939 +0200\n@@ -835,6 +835,7 @@ void ssl_sess_cert_free(SESS_CERT *sc);\n int ssl_set_peer_cert_type(SESS_CERT *c, int type);\n int ssl_get_new_session(SSL *s, int session);\n int ssl_get_prev_session(SSL *s, unsigned char *session,int len, const unsigned char *limit);\n+SSL_SESSION *ssl_session_dup(SSL_SESSION *src, int ticket);\n int ssl_cipher_id_cmp(const SSL_CIPHER *a,const SSL_CIPHER *b);\n DECLARE_OBJ_BSEARCH_GLOBAL_CMP_FN(SSL_CIPHER, SSL_CIPHER,\n \t\t\t\t ssl_cipher_id);\nIndex: openssl-1.0.1i/ssl/ssl_sess.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/ssl_sess.c\t2015-06-12 19:15:11.549954732 +0200\n+++ openssl-1.0.1i/ssl/ssl_sess.c\t2015-06-12 19:26:20.502163556 +0200\n@@ -224,6 +224,129 @@ SSL_SESSION *SSL_SESSION_new(void)\n \treturn(ss);\n \t}\n \n+/*\n+ * Create a new SSL_SESSION and duplicate the contents of |src| into it. If\n+ * ticket == 0 then no ticket information is duplicated, otherwise it is.\n+ */\n+SSL_SESSION *ssl_session_dup(SSL_SESSION *src, int ticket)\n+{\n+ SSL_SESSION *dest;\n+\n+ dest = OPENSSL_malloc(sizeof(*src));\n+ if (dest == NULL) {\n+ goto err;\n+ }\n+ memcpy(dest, src, sizeof(*dest));\n+\n+ /* Set the various pointers to NULL so that we can call SSL_SESSION_free in\n+ * the case of an error whilst halfway through constructing dest\n+ */\n+#ifndef OPENSSL_NO_PSK\n+ dest->psk_identity_hint = NULL;\n+ dest->psk_identity = NULL;\n+#endif\n+ dest->ciphers = NULL;\n+#ifndef OPENSSL_NO_TLSEXT\n+ dest->tlsext_hostname = NULL;\n+# ifndef OPENSSL_NO_EC\n+ dest->tlsext_ecpointformatlist = NULL;\n+ dest->tlsext_ellipticcurvelist = NULL;\n+# endif\n+#endif\n+ dest->tlsext_tick = NULL;\n+#ifndef OPENSSL_NO_SRP\n+ dest->srp_username = NULL;\n+#endif\n+ memset(&dest->ex_data, 0, sizeof(dest->ex_data));\n+\n+ /* We deliberately don't copy the prev and next pointers */\n+ dest->prev = NULL;\n+ dest->next = NULL;\n+\n+ dest->references = 1;\n+\n+ if (src->sess_cert != NULL)\n+ CRYPTO_add(&src->sess_cert->references, 1, CRYPTO_LOCK_SSL_SESS_CERT);\n+\n+ if (src->peer != NULL)\n+ CRYPTO_add(&src->peer->references, 1, CRYPTO_LOCK_X509);\n+#ifndef OPENSSL_NO_PSK\n+ if (src->psk_identity_hint) {\n+ dest->psk_identity_hint = BUF_strdup(src->psk_identity_hint);\n+ if (dest->psk_identity_hint == NULL) {\n+ goto err;\n+ }\n+ }\n+ if (src->psk_identity) {\n+ dest->psk_identity = BUF_strdup(src->psk_identity);\n+ if (dest->psk_identity == NULL) {\n+ goto err;\n+ }\n+ }\n+#endif\n+\n+ if(src->ciphers != NULL) {\n+ dest->ciphers = sk_SSL_CIPHER_dup(src->ciphers);\n+ if (dest->ciphers == NULL)\n+ goto err;\n+ }\n+\n+ if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_SSL_SESSION,\n+ &dest->ex_data, &src->ex_data)) {\n+ goto err;\n+ }\n+\n+#ifndef OPENSSL_NO_TLSEXT\n+ if (src->tlsext_hostname) {\n+ dest->tlsext_hostname = BUF_strdup(src->tlsext_hostname);\n+ if (dest->tlsext_hostname == NULL) {\n+ goto err;\n+ }\n+ }\n+# ifndef OPENSSL_NO_EC\n+ if (src->tlsext_ecpointformatlist) {\n+ dest->tlsext_ecpointformatlist =\n+ BUF_memdup(src->tlsext_ecpointformatlist,\n+ src->tlsext_ecpointformatlist_length);\n+ if (dest->tlsext_ecpointformatlist == NULL)\n+ goto err;\n+ }\n+ if (src->tlsext_ellipticcurvelist) {\n+ dest->tlsext_ellipticcurvelist =\n+ BUF_memdup(src->tlsext_ellipticcurvelist,\n+ src->tlsext_ellipticcurvelist_length);\n+ if (dest->tlsext_ellipticcurvelist == NULL)\n+ goto err;\n+ }\n+# endif\n+#endif\n+\n+ if (ticket != 0) {\n+ dest->tlsext_tick = BUF_memdup(src->tlsext_tick, src->tlsext_ticklen);\n+ if(dest->tlsext_tick == NULL)\n+ goto err;\n+ } else {\n+ dest->tlsext_tick_lifetime_hint = 0;\n+ dest->tlsext_ticklen = 0;\n+ }\n+\n+#ifndef OPENSSL_NO_SRP\n+ if (src->srp_username) {\n+ dest->srp_username = BUF_strdup(src->srp_username);\n+ if (dest->srp_username == NULL) {\n+ goto err;\n+ }\n+ }\n+#endif\n+\n+ return dest;\n+err:\n+ SSLerr(SSL_F_SSL_SESSION_DUP, ERR_R_MALLOC_FAILURE);\n+ SSL_SESSION_free(dest);\n+ return NULL;\n+}\n+\n+\n const unsigned char *SSL_SESSION_get_id(const SSL_SESSION *s, unsigned int *len)\n \t{\n \tif(len)"}], "metadata": {"id": "openssl-4769-openssl-CVE-2015-1791.patch", "cve_id": "CVE-2015-3197", "package": "openssl", "tier": "adapted", "has_source_context": true, "context_tokens_est": 3732, "context_files": 5, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1h/apps/s_client.c\n- openssl-1.0.1h/apps/s_socket.c\n- openssl-1.0.1h.orig/apps/s_client.c\n- openssl-1.0.1h/apps/s_server.c\n- openssl-1.0.1h.orig/apps/s_server.c\n\n## Target Source Code\n\n### apps/s_apps.h\n\n#### region() [lines 109-177]\n```c\n *\n */\n#if !defined(OPENSSL_SYS_NETWARE) /* conflicts with winsock2 stuff on netware */\n#include \n#endif\n#include \n\n#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS)\n#include \n#endif\n\n#if defined(OPENSSL_SYS_MSDOS) && !defined(_WIN32)\n#define _kbhit kbhit\n#endif\n\n#if defined(OPENSSL_SYS_VMS) && !defined(FD_SET)\n/* VAX C does not defined fd_set and friends, but it's actually quite simple */\n/* These definitions are borrowed from SOCKETSHR.\t/Richard Levitte */\n#define MAX_NOFILE\t32\n#define\tNBBY\t\t 8\t\t/* number of bits in a byte\t*/\n\n#ifndef\tFD_SETSIZE\n#define\tFD_SETSIZE\tMAX_NOFILE\n#endif\t/* FD_SETSIZE */\n\n/* How many things we'll allow select to use. 0 if unlimited */\n#define MAXSELFD\tMAX_NOFILE\ntypedef int\tfd_mask;\t/* int here! VMS prototypes int, not long */\n#define NFDBITS\t(sizeof(fd_mask) * NBBY)\t/* bits per mask (power of 2!)*/\n#define NFDSHIFT 5\t\t\t\t/* Shift based on above */\n\ntypedef fd_mask fd_set;\n#define\tFD_SET(n, p)\t(*(p) |= (1 << ((n) % NFDBITS)))\n#define\tFD_CLR(n, p)\t(*(p) &= ~(1 << ((n) % NFDBITS)))\n#define\tFD_ISSET(n, p)\t(*(p) & (1 << ((n) % NFDBITS)))\n#define FD_ZERO(p)\tmemset((char *)(p), 0, sizeof(*(p)))\n#endif\n\n#define PORT 4433\n#define PORT_STR \"4433\"\n#define PROTOCOL \"tcp\"\n\nint do_server(int port, int type, int *ret, int (*cb) (char *hostname, int s, unsigned char *context), unsigned char *context);\n#ifdef HEADER_X509_H\nint MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx);\n#endif\n#ifdef HEADER_SSL_H\nint set_cert_stuff(SSL_CTX *ctx, char *cert_file, char *key_file);\nint set_cert_key_stuff(SSL_CTX *ctx, X509 *cert, EVP_PKEY *key);\n#endif\nint init_client(int *sock, char *server, int port, int type);\nint should_retry(int i);\nint extract_port(char *str, short *port_ptr);\nint extract_host_port(char *str,char **host_ptr,unsigned char *ip,short *p);\n\nlong MS_CALLBACK bio_dump_callback(BIO *bio, int cmd, const char *argp,\n\t\t\t\t int argi, long argl, long ret);\n\n#ifdef HEADER_SSL_H\nvoid MS_CALLBACK apps_ssl_info_callback(const SSL *s, int where, int ret);\nvoid MS_CALLBACK msg_cb(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg);\nvoid MS_CALLBACK tlsext_cb(SSL *s, int client_server, int type,\n\t\t\t\t\tunsigned char *data, int len,\n\t\t\t\t\tvoid *arg);\n#endif\n\nint MS_CALLBACK generate_cookie_callback(SSL *ssl, unsigned char *cookie, unsigned int *cookie_len);\nint MS_CALLBACK verify_cookie_callback(SSL *ssl, unsigned char *cookie, unsigned int cookie_len);\n\n```\n\n### apps/s_client.c\n\n#### MAIN() [lines 555-1926]\n```c\n\nint MAIN(int, char **);\n\nint MAIN(int argc, char **argv)\n\t{\n\tunsigned int off=0, clr=0;\n\tSSL *con=NULL;\n#ifndef OPENSSL_NO_KRB5\n\tKSSL_CTX *kctx;\n#endif\n\tint s,k,width,state=0;\n\tchar *cbuf=NULL,*sbuf=NULL,*mbuf=NULL;\n\tint cbuf_len,cbuf_off;\n\tint sbuf_len,sbuf_off;\n\tfd_set readfds,writefds;\n\tshort port=PORT;\n\tint full_log=1;\n\tchar *host=SSL_HOST_NAME;\n\tchar *cert_file=NULL,*key_file=NULL;\n\tint cert_format = FORMAT_PEM, key_format = FORMAT_PEM;\n\tchar *passarg = NULL, *pass = NULL;\n\tX509 *cert = NULL;\n\tEVP_PKEY *key = NULL;\n\tchar *CApath=NULL,*CAfile=NULL,*cipher=NULL;\n\tint reconnect=0,badop=0,verify=SSL_VERIFY_NONE,bugs=0;\n\tint crlf=0;\n\tint write_tty,read_tty,write_ssl,read_ssl,tty_on,ssl_pending;\n\tSSL_CTX *ctx=NULL;\n\tint ret=1,in_init=1,i,nbio_test=0;\n\tint starttls_proto = PROTO_OFF;\n\tint prexit = 0;\n\tX509_VERIFY_PARAM *vpm = NULL;\n\tint badarg = 0;\n\tconst SSL_METHOD *meth=NULL;\n\tint socket_type=SOCK_STREAM;\n\tBIO *sbio;\n\tchar *inrand=NULL;\n\tint mbuf_len=0;\n\tstruct timeval timeout, *timeoutp;\n#ifndef OPENSSL_NO_ENGINE\n/* ... 1322 lines omitted ... */\n\t\tX509_free(cert);\n\tif (key)\n\t\tEVP_PKEY_free(key);\n\tif (pass)\n\t\tOPENSSL_free(pass);\n\tif (vpm)\n\t\tX509_VERIFY_PARAM_free(vpm);\n\tif (cbuf != NULL) { OPENSSL_cleanse(cbuf,BUFSIZZ); OPENSSL_free(cbuf); }\n\tif (sbuf != NULL) { OPENSSL_cleanse(sbuf,BUFSIZZ); OPENSSL_free(sbuf); }\n\tif (mbuf != NULL) { OPENSSL_cleanse(mbuf,BUFSIZZ); OPENSSL_free(mbuf); }\n\tif (bio_c_out != NULL)\n\t\t{\n\t\tBIO_free(bio_c_out);\n\t\tbio_c_out=NULL;\n\t\t}\n\tapps_shutdown();\n\tOPENSSL_EXIT(ret);\n\t}\n\n\n```\n\n#### region() [lines 1228-1315]\n```c\n\t\t\tBIO_printf(bio_err, \"Can't open session file %s\\n\",\n\t\t\t\t\t\tsess_in);\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\tSSL_set_session(con, sess);\n\t\tSSL_SESSION_free(sess);\n\t\t}\n#ifndef OPENSSL_NO_TLSEXT\n\tif (servername != NULL)\n\t\t{\n\t\tif (!SSL_set_tlsext_host_name(con,servername))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,\"Unable to set TLS servername extension.\\n\");\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_KRB5\n\tif (con && (kctx = kssl_ctx_new()) != NULL)\n {\n\t\tSSL_set0_kssl_ctx(con, kctx);\n kssl_ctx_setstring(kctx, KSSL_SERVER, host);\n\t\t}\n#endif\t/* OPENSSL_NO_KRB5 */\n/*\tSSL_set_cipher_list(con,\"RC4-MD5\"); */\n#if 0\n#ifdef TLSEXT_TYPE_opaque_prf_input\n\tSSL_set_tlsext_opaque_prf_input(con, \"Test client\", 11);\n#endif\n#endif\n\nre_start:\n\n\tif (init_client(&s,host,port,socket_type) == 0)\n\t\t{\n\t\tBIO_printf(bio_err,\"connect:errno=%d\\n\",get_last_socket_error());\n\t\tSHUTDOWN(s);\n\t\tgoto end;\n\t\t}\n\tBIO_printf(bio_c_out,\"CONNECTED(%08X)\\n\",s);\n\n#ifdef FIONBIO\n\tif (c_nbio)\n\t\t{\n\t\tunsigned long l=1;\n\t\tBIO_printf(bio_c_out,\"turning on non blocking io\\n\");\n\t\tif (BIO_socket_ioctl(s,FIONBIO,&l) < 0)\n\t\t\t{\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n#endif \n\tif (c_Pause & 0x01) SSL_set_debug(con, 1);\n\n\tif ( SSL_version(con) == DTLS1_VERSION)\n\t\t{\n\n\t\tsbio=BIO_new_dgram(s,BIO_NOCLOSE);\n\t\tif (getsockname(s, &peer, (void *)&peerlen) < 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, \"getsockname:errno=%d\\n\",\n\t\t\t\tget_last_socket_error());\n\t\t\tSHUTDOWN(s);\n\t\t\tgoto end;\n\t\t\t}\n\n\t\t(void)BIO_ctrl_set_connec\n/* ... truncated ... */\n```\n\n### apps/s_server.c\n\n#### MAIN() [lines 929-1927]\n```c\nstatic char *srtp_profiles = NULL;\n#endif\n\nint MAIN(int argc, char *argv[])\n\t{\n\tX509_VERIFY_PARAM *vpm = NULL;\n\tint badarg = 0;\n\tshort port=PORT;\n\tchar *CApath=NULL,*CAfile=NULL;\n\tunsigned char *context = NULL;\n\tchar *dhfile = NULL;\n#ifndef OPENSSL_NO_ECDH\n\tchar *named_curve = NULL;\n#endif\n\tint badop=0,bugs=0;\n\tint ret=1;\n\tint off=0;\n\tint no_tmp_rsa=0,no_dhe=0,no_ecdhe=0,nocert=0;\n\tint state=0;\n\tconst SSL_METHOD *meth=NULL;\n\tint socket_type=SOCK_STREAM;\n\tENGINE *e=NULL;\n\tchar *inrand=NULL;\n\tint s_cert_format = FORMAT_PEM, s_key_format = FORMAT_PEM;\n\tchar *passarg = NULL, *pass = NULL;\n\tchar *dpassarg = NULL, *dpass = NULL;\n\tint s_dcert_format = FORMAT_PEM, s_dkey_format = FORMAT_PEM;\n\tX509 *s_cert = NULL, *s_dcert = NULL;\n\tEVP_PKEY *s_key = NULL, *s_dkey = NULL;\n\tint no_cache = 0;\n#ifndef OPENSSL_NO_TLSEXT\n\tEVP_PKEY *s_key2 = NULL;\n\tX509 *s_cert2 = NULL;\n tlsextctx tlsextcbp = {NULL, NULL, SSL_TLSEXT_ERR_ALERT_WARNING};\n# ifndef OPENSSL_NO_NEXTPROTONEG\n\tconst char *next_proto_neg_in = NULL;\n\ttlsextnextprotoctx next_proto;\n# endif\n#endif\n#ifndef OPENSSL_NO_PSK\n/* ... 952 lines omitted ... */\n\tif (tlscstatp.port)\n\t\tOPENSSL_free(tlscstatp.port);\n\tif (tlscstatp.path)\n\t\tOPENSSL_free(tlscstatp.path);\n\tif (ctx2 != NULL) SSL_CTX_free(ctx2);\n\tif (s_cert2)\n\t\tX509_free(s_cert2);\n\tif (s_key2)\n\t\tEVP_PKEY_free(s_key2);\n#endif\n\tif (bio_s_out != NULL)\n\t\t{\n BIO_free(bio_s_out);\n\t\tbio_s_out=NULL;\n\t\t}\n\tapps_shutdown();\n\tOPENSSL_EXIT(ret);\n\t}\n\nstatic void print_stats(BIO *bio, SSL_CTX *ssl_ctx)\n```\n\n#### region() [lines 1853-1942]\n```c\n#ifndef OPENSSL_NO_SRP\n\tif (srp_verifier_file != NULL)\n\t\t{\n\t\tsrp_callback_parm.vb = SRP_VBASE_new(srpuserseed);\n\t\tsrp_callback_parm.user = NULL;\n\t\tsrp_callback_parm.login = NULL;\n\t\tif ((ret = SRP_VBASE_init(srp_callback_parm.vb, srp_verifier_file)) != SRP_NO_ERROR)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,\n\t\t\t\t \"Cannot initialize SRP verifier file \\\"%s\\\":ret=%d\\n\",\n\t\t\t\t srp_verifier_file, ret);\n\t\t\t\tgoto end;\n\t\t\t}\n\t\tSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE,verify_callback);\n\t\tSSL_CTX_set_srp_cb_arg(ctx, &srp_callback_parm); \t\t\t\n\t\tSSL_CTX_set_srp_username_callback(ctx, ssl_srp_server_param_cb);\n\t\t}\n\telse\n#endif\n\tif (CAfile != NULL)\n\t\t{\n\t\tSSL_CTX_set_client_CA_list(ctx,SSL_load_client_CA_file(CAfile));\n#ifndef OPENSSL_NO_TLSEXT\n\t\tif (ctx2) \n\t\t\tSSL_CTX_set_client_CA_list(ctx2,SSL_load_client_CA_file(CAfile));\n#endif\n\t\t}\n\n\tBIO_printf(bio_s_out,\"ACCEPT\\n\");\n\t(void)BIO_flush(bio_s_out);\n\tif (www)\n\t\tdo_server(port,socket_type,&accept_socket,www_body, context);\n\telse\n\t\tdo_server(port,socket_type,&accept_socket,sv_body, context);\n\tprint_stats(bio_s_out,ctx);\n\tret=0;\nend:\n\tif (ctx != NULL) SSL_CTX_free(ctx);\n\tif (s_cert)\n\t\tX509_free(s_cert);\n\tif (s_dcert)\n\t\tX509_free(s_dcert);\n\tif (s_key)\n\t\tEVP_PKEY_free(s_key);\n\tif (s_dkey)\n\t\tEVP_PKEY_free(s_dkey);\n\tif (pass)\n\t\tOPENSSL_free(pass);\n\tif (dpass)\n\t\tOPENSSL_free(dpass);\n\tif (vpm)\n\t\tX509_VERIFY_PARAM_free(vpm);\n#ifndef OPENSSL_NO_TLSEXT\n\tif (tlscstatp.host)\n\t\tOPENSSL_free(tlscstatp.host);\n\tif (tlscstatp.port)\n\t\tOPENSSL_free(tlscstatp.port);\n\tif (tlscstatp.path)\n\t\tOPENSSL_free(tlscstatp.path);\n\tif (ctx2 != NULL) SSL_CTX_free(ctx2);\n\tif (s_cert2)\n\t\n/* ... truncated ... */\n```\n\n### apps/s_socket.c\n\n#### region() [lines 63-152]\n```c\n#include \n\n#ifdef FLAT_INC\n#include \"e_os2.h\"\n#else\n#include \"../e_os2.h\"\n#endif\n\n/* With IPv6, it looks like Digital has mixed up the proper order of\n recursive header file inclusion, resulting in the compiler complaining\n that u_int isn't defined, but only if _POSIX_C_SOURCE is defined, which\n is needed to have fileno() declared correctly... So let's define u_int */\n#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__U_INT)\n#define __U_INT\ntypedef unsigned int u_int;\n#endif\n\n#define USE_SOCKETS\n#define NON_MAIN\n#include \"apps.h\"\n#undef USE_SOCKETS\n#undef NON_MAIN\n#include \"s_apps.h\"\n#include \n\n#ifdef FLAT_INC\n#include \"e_os.h\"\n#else\n#include \"../e_os.h\"\n#endif\n\n#ifndef OPENSSL_NO_SOCK\n\n#if defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_BSDSOCK)\n#include \"netdb.h\"\n#endif\n\nstatic struct hostent *GetHostByName(char *name);\n#if defined(OPENSSL_SYS_WINDOWS) || (defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK))\nstatic void ssl_sock_cleanup(void);\n#endif\nstatic int ssl_sock_init(void);\nstatic int init_client_ip(int *sock,unsigned char ip[4], int port, int type);\nstatic int init_server(int *sock, int port, int type);\nstatic int init_server_long(int *sock, int port,char *ip, int type);\nstatic int do_accept(int acc_sock, int *sock, char **host);\nstatic int host_ip(char *str, unsigned char ip[4]);\n\n#ifdef OPENSSL_SYS_WIN16\n#define SOCKET_PROTOCOL\t0 /* more microsoft stupidity */\n#else\n#define SOCKET_PROTOCOL\tIPPROTO_TCP\n#endif\n\n#if defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK)\nstatic int wsa_init_done=0;\n#endif\n\n#ifdef OPENSSL_SYS_WINDOWS\nstatic struct WSAData wsa_state;\nstatic int wsa_init_done=0;\n\n#ifdef OPENSSL_SYS_WIN16\nstatic HWND topWnd=0;\nstatic FARPROC lpTopWndProc=NULL;\nstatic FARPROC lpTopHookProc=NULL;\nextern HINSTANCE _hInstance; /* nice global CRT provides */\n\nstatic LONG FAR PASCAL topHookProc(HWND hwnd, UINT message, WPARAM wParam,\n\t LPARAM lParam)\n\t{\n\tif (hwnd == topWnd)\n\t\t{\n\t\tswitch(message)\n\t\t\t{\n\t\tcase WM_DESTROY:\n\t\tcase WM_CLOSE:\n\t\t\tSetWindowLong(topWnd,GWL_WNDPROC,(LONG)lpTopWndProc);\n\t\t\tssl_sock_cleanup();\n\t\t\tbreak;\n\t\t\t}\n\t\t}\n\treturn CallWindowProc(lpTopWndProc,hwnd,message,wParam,lParam);\n\t}\n\nstatic BOOL CALLBACK enumproc(HWND hwnd,LPARAM lParam)\n\t{\n\ttopWnd=hwnd;\n\treturn(FALSE);\n\t}\n```\n\n#### ssl_sock_init() [lines 177-237]\n```c\n\t}\n#endif\n\nstatic int ssl_sock_init(void)\n\t{\n#ifdef WATT32\n\textern int _watt_do_exit;\n\t_watt_do_exit = 0;\n\tif (sock_init())\n\t\treturn (0);\n#elif defined(OPENSSL_SYS_WINDOWS)\n\tif (!wsa_init_done)\n\t\t{\n\t\tint err;\n\t \n#ifdef SIGINT\n\t\tsignal(SIGINT,(void (*)(int))ssl_sock_cleanup);\n#endif\n\t\twsa_init_done=1;\n\t\tmemset(&wsa_state,0,sizeof(wsa_state));\n\t\tif (WSAStartup(0x0101,&wsa_state)!=0)\n\t\t\t{\n\t\t\terr=WSAGetLastError();\n\t\t\tBIO_printf(bio_err,\"unable to start WINSOCK, error code=%d\\n\",err);\n\t\t\treturn(0);\n\t\t\t}\n\n#ifdef OPENSSL_SYS_WIN16\n\t\tEnumTaskWindows(GetCurrentTask(),enumproc,0L);\n\t\tlpTopWndProc=(FARPROC)GetWindowLong(topWnd,GWL_WNDPROC);\n\t\tlpTopHookProc=MakeProcInstance((FARPROC)topHookProc,_hInstance);\n\n\t\tSetWindowLong(topWnd,GWL_WNDPROC,(LONG)lpTopHookProc);\n#endif /* OPENSSL_SYS_WIN16 */\n\t\t}\n#elif defined(OPEN\n/* ... truncated ... */\n```\n\n\n## Upstream Fix\n```diff\nIndex: openssl-1.0.1h/apps/s_apps.h\n===================================================================\n--- openssl-1.0.1h.orig/apps/s_apps.h\n+++ openssl-1.0.1h/apps/s_apps.h\n@@ -148,7 +148,7 @@ typedef fd_mask fd_set;\n #define PORT_STR \"4433\"\n #define PROTOCOL \"tcp\"\n \n-int do_server(int port, int type, int *ret, int (*cb) (char *hostname, int s, unsigned char *context), unsigned char *context);\n+int do_server(char *port, int type, int *ret, int (*cb) (char *hostname, int s, unsigned char *context), unsigned char *context);\n #ifdef HEADER_X509_H\n int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx);\n #endif\n@@ -156,10 +156,9 @@ int MS_CALLBACK verify_callback(int ok,\n int set_cert_stuff(SSL_CTX *ctx, char *cert_file, char *key_file);\n int set_cert_key_stuff(SSL_CTX *ctx, X509 *cert, EVP_PKEY *key);\n #endif\n-int init_client(int *sock, char *server, int port, int type);\n+int init_client(int *sock, char *server, char *port, int type);\n int should_retry(int i);\n-int extract_port(char *str, short *port_ptr);\n-int extract_host_port(char *str,char **host_ptr,unsigned char *ip,short *p);\n+int extract_host_port(char *str,char **host_ptr,char **port_ptr);\n \n long MS_CALLBACK bio_dump_callback(BIO *bio, int cmd, const char *argp,\n \t\t\t\t int argi, long argl, long ret);\nIndex: openssl-1.0.1h/apps/s_client.c\n===================================================================\n--- openssl-1.0.1h.orig/apps/s_client.c\n+++ openssl-1.0.1h/apps/s_client.c\n@@ -567,7 +567,7 @@ int MAIN(int argc, char **argv)\n \tint cbuf_len,cbuf_off;\n \tint sbuf_len,sbuf_off;\n \tfd_set readfds,writefds;\n-\tshort port=PORT;\n+\tchar *port_str = PORT_STR;\n \tint full_log=1;\n \tchar *host=SSL_HOST_NAME;\n \tchar *cert_file=NULL,*key_file=NULL;\n@@ -668,13 +668,12 @@ int MAIN(int argc, char **argv)\n \t\telse if\t(strcmp(*argv,\"-port\") == 0)\n \t\t\t{\n \t\t\tif (--argc < 1) goto bad;\n-\t\t\tport=atoi(*(++argv));\n-\t\t\tif (port == 0) goto bad;\n+\t\t\tport_str= *(++argv);\n \t\t\t}\n \t\telse if (strcmp(*argv,\"-connect\") == 0)\n \t\t\t{\n \t\t\tif (--argc < 1) goto bad;\n-\t\t\tif (!extract_host_port(*(++argv),&host,NULL,&port))\n+\t\t\tif (!extract_host_port(*(++argv),&host,&port_str))\n \t\t\t\tgoto bad;\n \t\t\t}\n \t\telse if\t(strcmp(*argv,\"-verify\") == 0)\n@@ -1267,7 +1266,7 @@ bad:\n \n re_start:\n \n-\tif (init_client(&s,host,port,socket_type) == 0)\n+\tif (init_client(&s,host,port_str,socket_type) == 0)\n \t\t{\n \t\tBIO_printf(bio_err,\"connect:errno=%d\\n\",get_last_socket_error());\n \t\tSHUTDOWN(s);\nIndex: openssl-1.0.1h/apps/s_server.c\n===================================================================\n--- openssl-1.0.1h.orig/apps/s_server.c\n+++ openssl-1.0.1h/apps/s_server.c\n@@ -933,7 +933,7 @@ int MAIN(int argc, char *argv[])\n \t{\n \tX509_VERIFY_PARAM *vpm = NULL;\n \tint badarg = 0;\n-\tshort port=PORT;\n+\tchar *port_str = PORT_STR;\n \tchar *CApath=NULL,*CAfile=NULL;\n \tunsigned char *context = NULL;\n \tchar *dhfile = NULL;\n@@ -1004,8 +1004,7 @@ int MAIN(int argc, char *argv[])\n \t\t\t (strcmp(*argv,\"-accept\") == 0))\n \t\t\t{\n \t\t\tif (--argc < 1) goto bad;\n-\t\t\tif (!extract_port(*(++argv),&port))\n-\t\t\t\tgoto bad;\n+\t\t\tport_str= *(++argv);\n \t\t\t}\n \t\telse if\t(strcmp(*argv,\"-verify\") == 0)\n \t\t\t{\n@@ -1892,9 +1891,9 @@ bad:\n \tBIO_printf(bio_s_out,\"ACCEPT\\n\");\n \t(void)BIO_flush(bio_s_out);\n \tif (www)\n-\t\tdo_server(port,socket_type,&accept_socket,www_body, context);\n+\t\tdo_server(port_str,socket_type,&accept_socket,www_body, context);\n \telse\n-\t\tdo_server(port,socket_type,&accept_socket,sv_body, context);\n+\t\tdo_server(port_str,socket_type,&accept_socket,sv_body, context);\n \tprint_stats(bio_s_out,ctx);\n \tret=0;\n end:\nIndex: openssl-1.0.1h/apps/s_socket.c\n===================================================================\n--- openssl-1.0.1h.orig/apps/s_socket.c\n+++ openssl-1.0.1h/apps/s_socket.c\n@@ -102,9 +102,7 @@ static struct hostent *GetHostByName(cha\n static void ssl_sock_cleanup(void);\n #endif\n static int ssl_sock_init(void);\n-static int init_client_ip(int *sock,unsigned char ip[4], int port, int type);\n-static int init_server(int *sock, int port, int type);\n-static int init_server_long(int *sock, int port,char *ip, int type);\n+static int init_server(int *sock, char *port, int type);\n static int do_accept(int acc_sock, int *sock, char **host);\n static int host_ip(char *str, unsigned char ip[4]);\n \n@@ -234,57 +232,70 @@ static int ssl_sock_init(void)\n \treturn(1);\n \t}\n \n-int init_client(int *sock, char *host, int port, int type)\n+int init_client(int *sock, char *host, char *port, int type)\n \t{\n-\tunsigned char ip[4];\n-\n-\tmemset(ip, '\\0', sizeof ip);\n-\tif (!host_ip(host,&(ip[0])))\n-\t\treturn 0;\n-\treturn init_client_ip(sock,ip,port,type);\n-\t}\n-\n-static int init_client_ip(int *sock, unsigned char ip[4], int port, int type)\n-\t{\n-\tunsigned long addr;\n-\tstruct sockaddr_in them;\n-\tint s,i;\n+\tstruct addrinfo *res, *res0, hints;\n+\tchar * failed_call = NULL;\n+\tint s;\n+\tint e;\n \n \tif (!ssl_sock_init()) return(0);\n \n-\tmemset((char *)&them,0,sizeof(them));\n-\tthem.sin_family=AF_INET;\n-\tthem.sin_port=htons((unsigned short)port);\n-\taddr=(unsigned long)\n-\t\t((unsigned long)ip[0]<<24L)|\n-\t\t((unsigned long)ip[1]<<16L)|\n-\t\t((unsigned long)ip[2]<< 8L)|\n-\t\t((unsigned long)ip[3]);\n-\tthem.sin_addr.s_addr=htonl(addr);\n-\n-\tif (type == SOCK_STREAM)\n-\t\ts=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);\n-\telse /* ( type == SOCK_DGRAM) */\n-\t\ts=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);\n-\t\t\t\n-\tif (s == INVALID_SOCKET) { perror(\"socket\"); return(0); }\n+\tmemset(&hints, '\\0', sizeof(hints));\n+\thints.ai_socktype = type;\n+\thints.ai_flags = AI_ADDRCONFIG;\n+\n+\te = getaddrinfo(host, port, &hints, &res);\n+\tif (e)\n+\t{\n+\t\tfprintf(stderr, \"getaddrinfo: %s\\n\", gai_strerror(e));\n+\t\tif (e == EAI_SYSTEM)\n+\t\t\tperror(\"getaddrinfo\");\n+\t\treturn (0);\n+\t\t}\n \n+\tres0 = res;\n+\twhile (res)\n+\t\t{\n+\t\ts = socket(res->ai_family, res->ai_socktype, res->ai_protocol);\n+\t\tif (s == INVALID_SOCKET)\n+\t\t\t{\n+\t\t\tfailed_call = \"socket\";\n+\t\t\tgoto nextres;\n+\t\t\t}\n #if defined(SO_KEEPALIVE) && !defined(OPENSSL_SYS_MPE)\n \tif (type == SOCK_STREAM)\n \t\t{\n-\t\ti=0;\n-\t\ti=setsockopt(s,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i));\n-\t\tif (i < 0) { closesocket(s); perror(\"keepalive\"); return(0); }\n+\t\t\tint i=0;\n+\t\t\ti=setsockopt(s,SOL_SOCKET,SO_KEEPALIVE,\n+\t\t\t\t(char *)&i,sizeof(i));\n+\t\t\tif (i < 0) {\n+\t\t\t\tfailed_call = \"keepalive\";\n+\t\t\t\tgoto nextres;\n+\t\t\t\t}\n \t\t}\n #endif\n-\n-\tif (connect(s,(struct sockaddr *)&them,sizeof(them)) == -1)\n-\t\t{ closesocket(s); perror(\"connect\"); return(0); }\n+\t\tif (connect(s,(struct sockaddr *)res->ai_addr,\n+\t\t\tres->ai_addrlen) == 0)\n+\t\t\t{\n+\t\t\tfreeaddrinfo(res0);\n \t*sock=s;\n \treturn(1);\n \t}\n \n-int do_server(int port, int type, int *ret, int (*cb)(char *hostname, int s, unsigned char *context), unsigned char *context)\n+\t\tfailed_call = \"socket\";\n+nextres:\n+\t\tif (s != INVALID_SOCKET)\n+\t\t\tclose(s);\n+\t\tres = res->ai_next;\n+\t\t}\n+\tfreeaddrinfo(res0);\n+\n+\tperror(failed_call);\n+\treturn(0);\n+\t}\n+\n+int do_server(char *port, int type, int *ret, int (*cb)(char *hostname, int s, unsigned char *context), unsigned char *context)\n \t{\n \tint sock;\n \tchar *name = NULL;\n@@ -322,33 +333,50 @@ int do_server(int port, int type, int *r\n \t\t}\n \t}\n \n-static int init_server_long(int *sock, int port, char *ip, int type)\n+static int init_server(int *sock, char *port, int type)\n \t{\n-\tint ret=0;\n-\tstruct sockaddr_in server;\n-\tint s= -1;\n+\tstruct addrinfo *res, *res0 = NULL, hints;\n+\tchar * failed_call = NULL;\n+\tint s = INVALID_SOCKET;\n+\tint e;\n \n \tif (!ssl_sock_init()) return(0);\n \n-\tmemset((char *)&server,0,sizeof(server));\n-\tserver.sin_family=AF_INET;\n-\tserver.sin_port=htons((unsigned short)port);\n-\tif (ip == NULL)\n-\t\tserver.sin_addr.s_addr=INADDR_ANY;\n-\telse\n-/* Added for T3E, address-of fails on bit field (beckman@acl.lanl.gov) */\n-#ifndef BIT_FIELD_LIMITS\n-\t\tmemcpy(&server.sin_addr.s_addr,ip,4);\n-#else\n-\t\tmemcpy(&server.sin_addr,ip,4);\n-#endif\n+\tmemset(&hints, '\\0', sizeof(hints));\n+\thints.ai_family = AF_INET6;\n+tryipv4:\n+\thints.ai_socktype = type;\n+\thints.ai_flags = AI_PASSIVE;\n \t\n-\t\tif (type == SOCK_STREAM)\n-\t\t\ts=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);\n-\t\telse \n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "Index: openssl-1.0.1h/apps/s_apps.h\n===================================================================\n--- openssl-1.0.1h.orig/apps/s_apps.h\n+++ openssl-1.0.1h/apps/s_apps.h\n@@ -148,7 +148,7 @@ typedef fd_mask fd_set;\n #define PORT_STR \"4433\"\n #define PROTOCOL \"tcp\"\n \n-int do_server(int port, int type, int *ret, int (*cb) (char *hostname, int s, unsigned char *context), unsigned char *context);\n+int do_server(char *port, int type, int *ret, int (*cb) (char *hostname, int s, unsigned char *context), unsigned char *context);\n #ifdef HEADER_X509_H\n int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx);\n #endif\n@@ -156,10 +156,9 @@ int MS_CALLBACK verify_callback(int ok,\n int set_cert_stuff(SSL_CTX *ctx, char *cert_file, char *key_file);\n int set_cert_key_stuff(SSL_CTX *ctx, X509 *cert, EVP_PKEY *key);\n #endif\n-int init_client(int *sock, char *server, int port, int type);\n+int init_client(int *sock, char *server, char *port, int type);\n int should_retry(int i);\n-int extract_port(char *str, short *port_ptr);\n-int extract_host_port(char *str,char **host_ptr,unsigned char *ip,short *p);\n+int extract_host_port(char *str,char **host_ptr,char **port_ptr);\n \n long MS_CALLBACK bio_dump_callback(BIO *bio, int cmd, const char *argp,\n \t\t\t\t int argi, long argl, long ret);\nIndex: openssl-1.0.1h/apps/s_client.c\n===================================================================\n--- openssl-1.0.1h.orig/apps/s_client.c\n+++ openssl-1.0.1h/apps/s_client.c\n@@ -567,7 +567,7 @@ int MAIN(int argc, char **argv)\n \tint cbuf_len,cbuf_off;\n \tint sbuf_len,sbuf_off;\n \tfd_set readfds,writefds;\n-\tshort port=PORT;\n+\tchar *port_str = PORT_STR;\n \tint full_log=1;\n \tchar *host=SSL_HOST_NAME;\n \tchar *cert_file=NULL,*key_file=NULL;\n@@ -668,13 +668,12 @@ int MAIN(int argc, char **argv)\n \t\telse if\t(strcmp(*argv,\"-port\") == 0)\n \t\t\t{\n \t\t\tif (--argc < 1) goto bad;\n-\t\t\tport=atoi(*(++argv));\n-\t\t\tif (port == 0) goto bad;\n+\t\t\tport_str= *(++argv);\n \t\t\t}\n \t\telse if (strcmp(*argv,\"-connect\") == 0)\n \t\t\t{\n \t\t\tif (--argc < 1) goto bad;\n-\t\t\tif (!extract_host_port(*(++argv),&host,NULL,&port))\n+\t\t\tif (!extract_host_port(*(++argv),&host,&port_str))\n \t\t\t\tgoto bad;\n \t\t\t}\n \t\telse if\t(strcmp(*argv,\"-verify\") == 0)\n@@ -1267,7 +1266,7 @@ bad:\n \n re_start:\n \n-\tif (init_client(&s,host,port,socket_type) == 0)\n+\tif (init_client(&s,host,port_str,socket_type) == 0)\n \t\t{\n \t\tBIO_printf(bio_err,\"connect:errno=%d\\n\",get_last_socket_error());\n \t\tSHUTDOWN(s);\nIndex: openssl-1.0.1h/apps/s_server.c\n===================================================================\n--- openssl-1.0.1h.orig/apps/s_server.c\n+++ openssl-1.0.1h/apps/s_server.c\n@@ -933,7 +933,7 @@ int MAIN(int argc, char *argv[])\n \t{\n \tX509_VERIFY_PARAM *vpm = NULL;\n \tint badarg = 0;\n-\tshort port=PORT;\n+\tchar *port_str = PORT_STR;\n \tchar *CApath=NULL,*CAfile=NULL;\n \tunsigned char *context = NULL;\n \tchar *dhfile = NULL;\n@@ -1004,8 +1004,7 @@ int MAIN(int argc, char *argv[])\n \t\t\t (strcmp(*argv,\"-accept\") == 0))\n \t\t\t{\n \t\t\tif (--argc < 1) goto bad;\n-\t\t\tif (!extract_port(*(++argv),&port))\n-\t\t\t\tgoto bad;\n+\t\t\tport_str= *(++argv);\n \t\t\t}\n \t\telse if\t(strcmp(*argv,\"-verify\") == 0)\n \t\t\t{\n@@ -1892,9 +1891,9 @@ bad:\n \tBIO_printf(bio_s_out,\"ACCEPT\\n\");\n \t(void)BIO_flush(bio_s_out);\n \tif (www)\n-\t\tdo_server(port,socket_type,&accept_socket,www_body, context);\n+\t\tdo_server(port_str,socket_type,&accept_socket,www_body, context);\n \telse\n-\t\tdo_server(port,socket_type,&accept_socket,sv_body, context);\n+\t\tdo_server(port_str,socket_type,&accept_socket,sv_body, context);\n \tprint_stats(bio_s_out,ctx);\n \tret=0;\n end:\nIndex: openssl-1.0.1h/apps/s_socket.c\n===================================================================\n--- openssl-1.0.1h.orig/apps/s_socket.c\n+++ openssl-1.0.1h/apps/s_socket.c\n@@ -102,9 +102,7 @@ static struct hostent *GetHostByName(cha\n static void ssl_sock_cleanup(void);\n #endif\n static int ssl_sock_init(void);\n-static int init_client_ip(int *sock,unsigned char ip[4], int port, int type);\n-static int init_server(int *sock, int port, int type);\n-static int init_server_long(int *sock, int port,char *ip, int type);\n+static int init_server(int *sock, char *port, int type);\n static int do_accept(int acc_sock, int *sock, char **host);\n static int host_ip(char *str, unsigned char ip[4]);\n \n@@ -234,57 +232,70 @@ static int ssl_sock_init(void)\n \treturn(1);\n \t}\n \n-int init_client(int *sock, char *host, int port, int type)\n+int init_client(int *sock, char *host, char *port, int type)\n \t{\n-\tunsigned char ip[4];\n-\n-\tmemset(ip, '\\0', sizeof ip);\n-\tif (!host_ip(host,&(ip[0])))\n-\t\treturn 0;\n-\treturn init_client_ip(sock,ip,port,type);\n-\t}\n-\n-static int init_client_ip(int *sock, unsigned char ip[4], int port, int type)\n-\t{\n-\tunsigned long addr;\n-\tstruct sockaddr_in them;\n-\tint s,i;\n+\tstruct addrinfo *res, *res0, hints;\n+\tchar * failed_call = NULL;\n+\tint s;\n+\tint e;\n \n \tif (!ssl_sock_init()) return(0);\n \n-\tmemset((char *)&them,0,sizeof(them));\n-\tthem.sin_family=AF_INET;\n-\tthem.sin_port=htons((unsigned short)port);\n-\taddr=(unsigned long)\n-\t\t((unsigned long)ip[0]<<24L)|\n-\t\t((unsigned long)ip[1]<<16L)|\n-\t\t((unsigned long)ip[2]<< 8L)|\n-\t\t((unsigned long)ip[3]);\n-\tthem.sin_addr.s_addr=htonl(addr);\n-\n-\tif (type == SOCK_STREAM)\n-\t\ts=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);\n-\telse /* ( type == SOCK_DGRAM) */\n-\t\ts=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);\n-\t\t\t\n-\tif (s == INVALID_SOCKET) { perror(\"socket\"); return(0); }\n+\tmemset(&hints, '\\0', sizeof(hints));\n+\thints.ai_socktype = type;\n+\thints.ai_flags = AI_ADDRCONFIG;\n+\n+\te = getaddrinfo(host, port, &hints, &res);\n+\tif (e)\n+\t{\n+\t\tfprintf(stderr, \"getaddrinfo: %s\\n\", gai_strerror(e));\n+\t\tif (e == EAI_SYSTEM)\n+\t\t\tperror(\"getaddrinfo\");\n+\t\treturn (0);\n+\t\t}\n \n+\tres0 = res;\n+\twhile (res)\n+\t\t{\n+\t\ts = socket(res->ai_family, res->ai_socktype, res->ai_protocol);\n+\t\tif (s == INVALID_SOCKET)\n+\t\t\t{\n+\t\t\tfailed_call = \"socket\";\n+\t\t\tgoto nextres;\n+\t\t\t}\n #if defined(SO_KEEPALIVE) && !defined(OPENSSL_SYS_MPE)\n \tif (type == SOCK_STREAM)\n \t\t{\n-\t\ti=0;\n-\t\ti=setsockopt(s,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i));\n-\t\tif (i < 0) { closesocket(s); perror(\"keepalive\"); return(0); }\n+\t\t\tint i=0;\n+\t\t\ti=setsockopt(s,SOL_SOCKET,SO_KEEPALIVE,\n+\t\t\t\t(char *)&i,sizeof(i));\n+\t\t\tif (i < 0) {\n+\t\t\t\tfailed_call = \"keepalive\";\n+\t\t\t\tgoto nextres;\n+\t\t\t\t}\n \t\t}\n #endif\n-\n-\tif (connect(s,(struct sockaddr *)&them,sizeof(them)) == -1)\n-\t\t{ closesocket(s); perror(\"connect\"); return(0); }\n+\t\tif (connect(s,(struct sockaddr *)res->ai_addr,\n+\t\t\tres->ai_addrlen) == 0)\n+\t\t\t{\n+\t\t\tfreeaddrinfo(res0);\n \t*sock=s;\n \treturn(1);\n \t}\n \n-int do_server(int port, int type, int *ret, int (*cb)(char *hostname, int s, unsigned char *context), unsigned char *context)\n+\t\tfailed_call = \"socket\";\n+nextres:\n+\t\tif (s != INVALID_SOCKET)\n+\t\t\tclose(s);\n+\t\tres = res->ai_next;\n+\t\t}\n+\tfreeaddrinfo(res0);\n+\n+\tperror(failed_call);\n+\treturn(0);\n+\t}\n+\n+int do_server(char *port, int type, int *ret, int (*cb)(char *hostname, int s, unsigned char *context), unsigned char *context)\n \t{\n \tint sock;\n \tchar *name = NULL;\n@@ -322,33 +333,50 @@ int do_server(int port, int type, int *r\n \t\t}\n \t}\n \n-static int init_server_long(int *sock, int port, char *ip, int type)\n+static int init_server(int *sock, char *port, int type)\n \t{\n-\tint ret=0;\n-\tstruct sockaddr_in server;\n-\tint s= -1;\n+\tstruct addrinfo *res, *res0 = NULL, hints;\n+\tchar * failed_call = NULL;\n+\tint s = INVALID_SOCKET;\n+\tint e;\n \n \tif (!ssl_sock_init()) return(0);\n \n-\tmemset((char *)&server,0,sizeof(server));\n-\tserver.sin_family=AF_INET;\n-\tserver.sin_port=htons((unsigned short)port);\n-\tif (ip == NULL)\n-\t\tserver.sin_addr.s_addr=INADDR_ANY;\n-\telse\n-/* Added for T3E, address-of fails on bit field (beckman@acl.lanl.gov) */\n-#ifndef BIT_FIELD_LIMITS\n-\t\tmemcpy(&server.sin_addr.s_addr,ip,4);\n-#else\n-\t\tmemcpy(&server.sin_addr,ip,4);\n-#endif\n+\tmemset(&hints, '\\0', sizeof(hints));\n+\thints.ai_family = AF_INET6;\n+tryipv4:\n+\thints.ai_socktype = type;\n+\thints.ai_flags = AI_PASSIVE;\n \t\n-\t\tif (type == SOCK_STREAM)\n-\t\t\ts=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);\n-\t\telse /* type == SOCK_DGRAM */\n-\t\t\ts=socket(AF_INET, SOCK_DGRAM,IPPROTO_UDP);\n+\te = getaddrinfo(NULL, port, &hints, &res);\n+\tif (e)\n+\t\t{\n+\t\tif (hints.ai_family == AF_INET)\n+\t\t\t{\n+\t\t\tfprintf(stderr, \"getaddrinfo: %s\\n\", gai_strerror(e));\n+\t\t\tif (e == EAI_SYSTEM)\n+\t\t\t\tperror(\"getaddrinfo\");\n+\t\t\treturn (0);\n+\t\t\t}\n+\t\t\telse\n+\t\t\t\tres = NULL;\n+\t\t}\n \n-\tif (s == INVALID_SOCKET) goto err;\n+\tres0 = res;\n+\twhile (res)\n+\t\t{\n+\t\ts = socket(res->ai_family, res->ai_socktype, res->ai_protocol);\n+\t\tif (s == INVALID_SOCKET)\n+\t\t\t{\n+\t\t\tfailed_call = \"socket\";\n+\t\t\tgoto nextres;\n+\t\t\t}\n+\t\tif (hints.ai_family == AF_INET6)\n+\t\t\t{\n+\t\t\tint j = 0;\n+\t\t\tsetsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY,\n+\t\t\t\t (void *) &j, sizeof j);\n+\t\t\t}\n #if defined SOL_SOCKET && defined SO_REUSEADDR\n \t\t{\n \t\tint j = 1;\n@@ -356,35 +384,49 @@ static int init_server_long(int *sock, i\n \t\t\t (void *) &j, sizeof j);\n \t\t}\n #endif\n-\tif (bind(s,(struct sockaddr *)&server,sizeof(server)) == -1)\n+\n+\t\tif (bind(s,(struct sockaddr *)res->ai_addr, res->ai_addrlen) == -1)\n \t\t{\n-#ifndef OPENSSL_SYS_WINDOWS\n-\t\tperror(\"bind\");\n-#endif\n-\t\tgoto err;\n+\t\t\tfailed_call = \"bind\";\n+\t\t\tgoto nextres;\n \t\t}\n-\t/* Make it 128 for linux */\n-\tif (type==SOCK_STREAM && listen(s,128) == -1) goto err;\n-\t*sock=s;\n-\tret=1;\n-err:\n-\tif ((ret == 0) && (s != -1))\n+\t\tif (type==SOCK_STREAM && listen(s,128) == -1)\n \t\t{\n-\t\tSHUTDOWN(s);\n+\t\t\tfailed_call = \"listen\";\n+\t\t\tgoto nextres;\n \t\t}\n-\treturn(ret);\n+\n+\t\t*sock=s;\n+\t\treturn(1);\n+\n+nextres:\n+\t\tif (s != INVALID_SOCKET)\n+\t\t\tclose(s);\n+\t\tres = res->ai_next;\n \t}\n+\tif (res0)\n+\t\tfreeaddrinfo(res0);\n \n-static int init_server(int *sock, int port, int type)\n+\tif (s == INVALID_SOCKET)\n \t{\n-\treturn(init_server_long(sock, port, NULL, type));\n+\t\tif (hints.ai_family == AF_INET6)\n+\t\t{\n+\t\t\thints.ai_family = AF_INET;\n+\t\t\tgoto tryipv4;\n+\t\t}\n+\t\tperror(\"socket\");\n+\t\treturn(0);\n+\t}\n+\n+\tperror(failed_call);\n+\treturn(0);\n \t}\n \n static int do_accept(int acc_sock, int *sock, char **host)\n \t{\n+\tstatic struct sockaddr_storage from;\n+\tchar buffer[NI_MAXHOST];\n \tint ret;\n-\tstruct hostent *h1,*h2;\n-\tstatic struct sockaddr_in from;\n \tint len;\n /*\tstruct linger ling; */\n \n@@ -431,138 +473,59 @@ redoit:\n */\n \n \tif (host == NULL) goto end;\n-#ifndef BIT_FIELD_LIMITS\n-\t/* I should use WSAAsyncGetHostByName() under windows */\n-\th1=gethostbyaddr((char *)&from.sin_addr.s_addr,\n-\t\tsizeof(from.sin_addr.s_addr),AF_INET);\n-#else\n-\th1=gethostbyaddr((char *)&from.sin_addr,\n-\t\tsizeof(struct in_addr),AF_INET);\n-#endif\n-\tif (h1 == NULL)\n+\n+\tif (getnameinfo((struct sockaddr *)&from, sizeof(from),\n+\t\tbuffer, sizeof(buffer),\n+\t\tNULL, 0, 0))\n \t\t{\n-\t\tBIO_printf(bio_err,\"bad gethostbyaddr\\n\");\n+\t\tBIO_printf(bio_err,\"getnameinfo failed\\n\");\n \t\t*host=NULL;\n \t\t/* return(0); */\n \t\t}\n \telse\n \t\t{\n-\t\tif ((*host=(char *)OPENSSL_malloc(strlen(h1->h_name)+1)) == NULL)\n+\t\tif ((*host=(char *)OPENSSL_malloc(strlen(buffer)+1)) == NULL)\n \t\t\t{\n \t\t\tperror(\"OPENSSL_malloc\");\n \t\t\tclosesocket(ret);\n \t\t\treturn(0);\n \t\t\t}\n-\t\tBUF_strlcpy(*host,h1->h_name,strlen(h1->h_name)+1);\n-\n-\t\th2=GetHostByName(*host);\n-\t\tif (h2 == NULL)\n-\t\t\t{\n-\t\t\tBIO_printf(bio_err,\"gethostbyname failure\\n\");\n-\t\t\tclosesocket(ret);\n-\t\t\treturn(0);\n-\t\t\t}\n-\t\tif (h2->h_addrtype != AF_INET)\n-\t\t\t{\n-\t\t\tBIO_printf(bio_err,\"gethostbyname addr is not AF_INET\\n\");\n-\t\t\tclosesocket(ret);\n-\t\t\treturn(0);\n-\t\t\t}\n+\t\tstrcpy(*host, buffer);\n \t\t}\n end:\n \t*sock=ret;\n \treturn(1);\n \t}\n \n-int extract_host_port(char *str, char **host_ptr, unsigned char *ip,\n-\t short *port_ptr)\n+int extract_host_port(char *str, char **host_ptr, \n+\t char **port_ptr)\n \t{\n-\tchar *h,*p;\n+\tchar *h,*p,*x;\n \n-\th=str;\n-\tp=strchr(str,':');\n+\tx=h=str;\n+\tif (*h == '[')\n+\t\t{\n+\t\th++;\n+\t\tp=strchr(h,']');\n \tif (p == NULL)\n \t\t{\n-\t\tBIO_printf(bio_err,\"no port defined\\n\");\n+\t\t\tBIO_printf(bio_err,\"no ending bracket for IPv6 address\\n\");\n \t\treturn(0);\n \t\t}\n \t*(p++)='\\0';\n-\n-\tif ((ip != NULL) && !host_ip(str,ip))\n-\t\tgoto err;\n-\tif (host_ptr != NULL) *host_ptr=h;\n-\n-\tif (!extract_port(p,port_ptr))\n-\t\tgoto err;\n-\treturn(1);\n-err:\n-\treturn(0);\n+\t\tx = p;\n \t}\n-\n-static int host_ip(char *str, unsigned char ip[4])\n-\t{\n-\tunsigned int in[4]; \n-\tint i;\n-\n-\tif (sscanf(str,\"%u.%u.%u.%u\",&(in[0]),&(in[1]),&(in[2]),&(in[3])) == 4)\n-\t\t{\n-\t\tfor (i=0; i<4; i++)\n-\t\t\tif (in[i] > 255)\n-\t\t\t\t{\n-\t\t\t\tBIO_printf(bio_err,\"invalid IP address\\n\");\n-\t\t\t\tgoto err;\n-\t\t\t\t}\n-\t\tip[0]=in[0];\n-\t\tip[1]=in[1];\n-\t\tip[2]=in[2];\n-\t\tip[3]=in[3];\n-\t\t}\n-\telse\n-\t\t{ /* do a gethostbyname */\n-\t\tstruct hostent *he;\n-\n-\t\tif (!ssl_sock_init()) return(0);\n-\n-\t\the=GetHostByName(str);\n-\t\tif (he == NULL)\n-\t\t\t{\n-\t\t\tBIO_printf(bio_err,\"gethostbyname failure\\n\");\n-\t\t\tgoto err;\n-\t\t\t}\n-\t\t/* cast to short because of win16 winsock definition */\n-\t\tif ((short)he->h_addrtype != AF_INET)\n+\tp=strchr(x,':');\n+\tif (p == NULL)\n \t\t\t{\n-\t\t\tBIO_printf(bio_err,\"gethostbyname addr is not AF_INET\\n\");\n-\t\t\treturn(0);\n-\t\t\t}\n-\t\tip[0]=he->h_addr_list[0][0];\n-\t\tip[1]=he->h_addr_list[0][1];\n-\t\tip[2]=he->h_addr_list[0][2];\n-\t\tip[3]=he->h_addr_list[0][3];\n-\t\t}\n-\treturn(1);\n-err:\n+\t\tBIO_printf(bio_err,\"no port defined\\n\");\n \treturn(0);\n \t}\n+\t*(p++)='\\0';\n \n-int extract_port(char *str, short *port_ptr)\n-\t{\n-\tint i;\n-\tstruct servent *s;\n+\tif (host_ptr != NULL) *host_ptr=h;\n+\tif (port_ptr != NULL) *port_ptr=p;\n \n-\ti=atoi(str);\n-\tif (i != 0)\n-\t\t*port_ptr=(unsigned short)i;\n-\telse\n-\t\t{\n-\t\ts=getservbyname(str,\"tcp\");\n-\t\tif (s == NULL)\n-\t\t\t{\n-\t\t\tBIO_printf(bio_err,\"getservbyname failure for %s\\n\",str);\n-\t\t\treturn(0);\n-\t\t\t}\n-\t\t*port_ptr=ntohs((unsigned short)s->s_port);\n-\t\t}\n \treturn(1);\n \t}"}], "metadata": {"id": "openssl-4769-openssl-1.0.1c-ipv6-apps.patch", "cve_id": "CVE-2015-3197", "package": "openssl", "tier": "adapted", "has_source_context": true, "context_tokens_est": 3075, "context_files": 4, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-6250\n\nInteger overflow in the ISO9660 writer in libarchive before 3.2.1 allows remote attackers to cause a denial of service (application crash) or execute arbitrary code via vectors related to verifying filename lengths when writing an ISO9660 archive, which trigger a buffer overflow.\n\n## Package\nlibarchive\n\n## Files to modify\n- libarchive/archive_read_support_format_lha.c\n- libarchive-3.1.2.orig/libarchive/archive_read_support_format_lha.c\n\n## Target Source Code\n\n### libarchive/archive_read_support_format_lha.c\n\n#### lha_read_file_extended_header() [lines 1137-1378]\n```c\n *\n */\nstatic int\nlha_read_file_extended_header(struct archive_read *a, struct lha *lha,\n uint16_t *crc, int sizefield_length, size_t limitsize, size_t *total_size)\n{\n\tconst void *h;\n\tconst unsigned char *extdheader;\n\tsize_t\textdsize;\n\tsize_t\tdatasize;\n\tunsigned int i;\n\tunsigned char extdtype;\n\n#define EXT_HEADER_CRC\t\t0x00\t\t/* Header CRC and information*/\n#define EXT_FILENAME\t\t0x01\t\t/* Filename \t\t */\n#define EXT_DIRECTORY\t\t0x02\t\t/* Directory name\t */\n#define EXT_DOS_ATTR\t\t0x40\t\t/* MS-DOS attribute\t */\n#define EXT_TIMESTAMP\t\t0x41\t\t/* Windows time stamp\t */\n#define EXT_FILESIZE\t\t0x42\t\t/* Large file size\t */\n#define EXT_TIMEZONE\t\t0x43\t\t/* Time zone\t\t */\n#define EXT_UTF16_FILENAME\t0x44\t\t/* UTF-16 filename \t */\n#define EXT_UTF16_DIRECTORY\t0x45\t\t/* UTF-16 directory name */\n#define EXT_CODEPAGE\t\t0x46\t\t/* Codepage\t\t */\n#define EXT_UNIX_MODE\t\t0x50\t\t/* File permission\t */\n#define EXT_UNIX_GID_UID\t0x51\t\t/* gid,uid\t\t */\n#define EXT_UNIX_GNAME\t\t0x52\t\t/* Group name\t\t */\n#define EXT_UNIX_UNAME\t\t0x53\t\t/* User name\t\t */\n#define EXT_UNIX_MTIME\t\t0x54\t\t/* Modified time\t */\n#define EXT_OS2_NEW_ATTR\t0x7f\t\t/* new attribute(OS/2 only) */\n#define EXT_NEW_ATTR\t\t0xff\t\t/* new attribute\t */\n\n\t*total_size = sizefield_length;\n\n\tfor (;;) {\n\t\t/* Read an extended header size. */\n\t\tif ((h =\n\t\t __archive_read_ahead(a, sizefield_length, NULL)) == NULL)\n\t\t\treturn (truncated_error(a));\n\t\t/* Check if the size is the zero indicates the end of the\n\t\t * extended header. */\n/* ... 44 lines omitted ... */\n\t\t\t\t\t*crc = lha_crc16(*crc, zeros, 2);\n\t\t\t\t\t*crc = lha_crc16(*crc,\n\t\t\t\t\t extdheader+2, datasize - 2);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase EXT_FILENAME:\n\t\t\tif (datasize == 0) {\n\t\t\t\t/* maybe directory header */\n\t\t\t\tarchive_string_empty(&lha->filename);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tarchive_strncpy(&lha->filename,\n\t\t\t (const char *)extdheader, datasize);\n\t\t\tbreak;\n\t\tcase EXT_DIRECTORY:\n\t\t\tif (datasize == 0)\n\t\t\t\t/* no directory name data. exit this case. */\n\t\t\t\tbreak;\n\n\t\t\tarchive_strncpy(&lha->dirname,\n\t\t \t (const char *)extdheader, datasize);\n\t\t\t/*\n\t\t\t * Convert directory delimiter from 0xFF\n\t\t\t * to '/' for local system.\n\t \t\t */\n\t\t\tfor (i = 0; i < lha->dirname.length; i++) {\n\t\t\t\tif ((unsigned char)lha->dirname.s[i] == 0xFF)\n\t\t\t\t\tlha->dirname.s[i] = '/';\n\t\t\t}\n\t\t\t/* Is last character directory separator? */\n\t\t\tif (lha->dirname.s[lha->dirname.length-1] != '/')\n\t\t\t\t/* invalid directory data */\n/* ... 105 lines omitted ... */\n\t\t\t\tlha->setflag |= UNIX_MODE_IS_SET\n\t\t\t\t | BIRTHTIME_IS_SET | ATIME_IS_SET;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase EXT_TIMEZONE:\t\t/* Not supported */\n\t\tcase EXT_UTF16_FILENAME:\t/* Not supported */\n\t\tcase EXT_UTF16_DIRECTORY:\t/* Not supported */\n\t\tdefault:\n\t\t\tbreak;\n\t\t}\n\n\t\t__archive_read_consume(a, extdsize);\n\t}\ninvalid:\n\tarchive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,\n\t \"Invalid extended LHa header\");\n\treturn (ARCHIVE_FATAL);\n}\n\nstatic int\n```\n\n\n## Upstream Fix\n```diff\ncommit e8a2e4d2e6b450a239bb8f9d74239fa434bf7d35\nAuthor: Tim Kientzle \nDate: Sat Feb 7 13:32:58 2015 -0800\n\n Issue 402: Failed to recognize empty dir name in lha/lzh file\n \n When parsing a directory name, we checked for the name\n length being zero, but not for the first byte being a\n null byte. Add a similar check for the file case.\n\nIndex: libarchive-3.1.2/libarchive/archive_read_support_format_lha.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_read_support_format_lha.c\n+++ libarchive-3.1.2/libarchive/archive_read_support_format_lha.c\n@@ -1230,13 +1230,15 @@ lha_read_file_extended_header(struct arc\n \t\t\t\tarchive_string_empty(&lha->filename);\n \t\t\t\tbreak;\n \t\t\t}\n+\t\t\tif (extdheader[0] == '\\0')\n+\t\t\t\tgoto invalid;\n \t\t\tarchive_strncpy(&lha->filename,\n \t\t\t (const char *)extdheader, datasize);\n \t\t\tbreak;\n \t\tcase EXT_DIRECTORY:\n-\t\t\tif (datasize == 0)\n+\t\t\tif (datasize == 0 || extdheader[0] == '\\0')\n \t\t\t\t/* no directory name data. exit this case. */\n-\t\t\t\tbreak;\n+\t\t\t\tgoto invalid;\n \n \t\t\tarchive_strncpy(&lha->dirname,\n \t\t \t (const char *)extdheader, datasize);\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "commit e8a2e4d2e6b450a239bb8f9d74239fa434bf7d35\nAuthor: Tim Kientzle \nDate: Sat Feb 7 13:32:58 2015 -0800\n\n Issue 402: Failed to recognize empty dir name in lha/lzh file\n \n When parsing a directory name, we checked for the name\n length being zero, but not for the first byte being a\n null byte. Add a similar check for the file case.\n\nIndex: libarchive-3.1.2/libarchive/archive_read_support_format_lha.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_read_support_format_lha.c\n+++ libarchive-3.1.2/libarchive/archive_read_support_format_lha.c\n@@ -1230,13 +1230,15 @@ lha_read_file_extended_header(struct arc\n \t\t\t\tarchive_string_empty(&lha->filename);\n \t\t\t\tbreak;\n \t\t\t}\n+\t\t\tif (extdheader[0] == '\\0')\n+\t\t\t\tgoto invalid;\n \t\t\tarchive_strncpy(&lha->filename,\n \t\t\t (const char *)extdheader, datasize);\n \t\t\tbreak;\n \t\tcase EXT_DIRECTORY:\n-\t\t\tif (datasize == 0)\n+\t\t\tif (datasize == 0 || extdheader[0] == '\\0')\n \t\t\t\t/* no directory name data. exit this case. */\n-\t\t\t\tbreak;\n+\t\t\t\tgoto invalid;\n \n \t\t\tarchive_strncpy(&lha->dirname,\n \t\t \t (const char *)extdheader, datasize);"}], "metadata": {"id": "libarchive-5940-CVE-2015-8919.patch", "cve_id": "CVE-2016-6250", "package": "libarchive", "tier": "identical", "has_source_context": true, "context_tokens_est": 754, "context_files": 1, "license": "BSD-2-Clause"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- ssl/s3_clnt.c\n- openssl-1.0.1i.orig/ssl/s3_clnt.c\n- openssl-1.0.1i/ssl/s3_clnt.c\n- openssl-1.0.1i/ssl/s3_srvr.c\n- openssl-1.0.1i.orig/ssl/s3_srvr.c\n\n## Target Source Code\n\n### ssl/s3_clnt.c\n\n#### ssl3_get_key_exchange() [lines 1270-1877]\n```c\n\treturn(ret);\n\t}\n\nint ssl3_get_key_exchange(SSL *s)\n\t{\n#ifndef OPENSSL_NO_RSA\n\tunsigned char *q,md_buf[EVP_MAX_MD_SIZE*2];\n#endif\n\tEVP_MD_CTX md_ctx;\n\tunsigned char *param,*p;\n\tint al,i,j,param_len,ok;\n\tlong n,alg_k,alg_a;\n\tEVP_PKEY *pkey=NULL;\n\tconst EVP_MD *md = NULL;\n#ifndef OPENSSL_NO_RSA\n\tRSA *rsa=NULL;\n#endif\n#ifndef OPENSSL_NO_DH\n\tDH *dh=NULL;\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tEC_KEY *ecdh = NULL;\n\tBN_CTX *bn_ctx = NULL;\n\tEC_POINT *srvr_ecpoint = NULL;\n\tint curve_nid = 0;\n\tint encoded_pt_len = 0;\n#endif\n\n\t/* use same message size as in ssl3_get_certificate_request()\n\t * as ServerKeyExchange message may be skipped */\n\tn=s->method->ssl_get_message(s,\n\t\tSSL3_ST_CR_KEY_EXCH_A,\n\t\tSSL3_ST_CR_KEY_EXCH_B,\n\t\t-1,\n\t\ts->max_cert_list,\n\t\t&ok);\n\tif (!ok) return((int)n);\n\n\tif (s->s3->tmp.message_type != SSL3_MT_SERVER_KEY_EXCHANGE)\n\t\t{\n/* ... 55 lines omitted ... */\n\t\tchar tmp_id_hint[PSK_MAX_IDENTITY_LEN+1];\n\n\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\tn2s(p,i);\n\t\tparam_len=i+2;\n\t\t/* Store PSK identity hint for later use, hint is used\n\t\t * in ssl3_send_client_key_exchange. Assume that the\n\t\t * maximum length of a PSK identity hint can be as\n\t\t * long as the maximum length of a PSK identity. */\n\t\tif (i > PSK_MAX_IDENTITY_LEN)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,\n\t\t\t\tSSL_R_DATA_LENGTH_TOO_LONG);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif (param_len > n)\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,\n\t\t\t\tSSL_R_BAD_PSK_IDENTITY_HINT_LENGTH);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\t/* If received PSK identity hint contains NULL\n\t\t * characters, the hint is truncated from the first\n\t\t * NULL. p may not be ending with NULL, so create a\n\t\t * NULL-terminated string. */\n\t\tmemcpy(tmp_id_hint, p, i);\n\t\tmemset(tmp_id_hint+i, 0, PSK_MAX_IDENTITY_LEN+1-i);\n/* ... 465 lines omitted ... */\n\tEVP_PKEY_free(pkey);\n#ifndef OPENSSL_NO_RSA\n\tif (rsa != NULL)\n\t\tRSA_free(rsa);\n#endif\n#ifndef OPENSSL_NO_DH\n\tif (dh != NULL)\n\t\tDH_free(dh);\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tBN_CTX_free(bn_ctx);\n\tEC_POINT_free(srvr_ecpoint);\n\tif (ecdh != NULL)\n\t\tEC_KEY_free(ecdh);\n#endif\n\tEVP_MD_CTX_cleanup(&md_ctx);\n\treturn(-1);\n\t}\n\nint ssl3_get_certificate_request(SSL *s)\n```\n\n#### ssl3_send_client_key_exchange() [lines 2232-2959]\n```c\n\t}\n\n\nint ssl3_send_client_key_exchange(SSL *s)\n\t{\n\tunsigned char *p,*d;\n\tint n;\n\tunsigned long alg_k;\n#ifndef OPENSSL_NO_RSA\n\tunsigned char *q;\n\tEVP_PKEY *pkey=NULL;\n#endif\n#ifndef OPENSSL_NO_KRB5\n\tKSSL_ERR kssl_err;\n#endif /* OPENSSL_NO_KRB5 */\n#ifndef OPENSSL_NO_ECDH\n\tEC_KEY *clnt_ecdh = NULL;\n\tconst EC_POINT *srvr_ecpoint = NULL;\n\tEVP_PKEY *srvr_pub_pkey = NULL;\n\tunsigned char *encodedPoint = NULL;\n\tint encoded_pt_len = 0;\n\tBN_CTX * bn_ctx = NULL;\n#endif\n\n\tif (s->state == SSL3_ST_CW_KEY_EXCH_A)\n\t\t{\n\t\td=(unsigned char *)s->init_buf->data;\n\t\tp= &(d[4]);\n\n\t\talg_k=s->s3->tmp.new_cipher->algorithm_mkey;\n\n\t\t/* Fool emacs indentation */\n\t\tif (0) {}\n#ifndef OPENSSL_NO_RSA\n\t\telse if (alg_k & SSL_kRSA)\n\t\t\t{\n\t\t\tRSA *rsa;\n\t\t\tunsigned char tmp_buf[SSL_MAX_MASTER_KEY_LENGTH];\n\n\t\t\tif (s->session->sess_cert == NULL)\n/* ... 630 lines omitted ... */\n\t\t\tif (s->session->psk_identity == NULL)\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,\n\t\t\t\t\tERR_R_MALLOC_FAILURE);\n\t\t\t\tgoto psk_err;\n\t\t\t\t}\n\n\t\t\ts->session->master_key_length =\n\t\t\t\ts->method->ssl3_enc->generate_master_secret(s,\n\t\t\t\t\ts->session->master_key,\n\t\t\t\t\tpsk_or_pre_ms, pre_ms_len); \n\t\t\tn = strlen(identity);\n\t\t\ts2n(n, p);\n\t\t\tmemcpy(p, identity, n);\n\t\t\tn+=2;\n\t\t\tpsk_err = 0;\n\t\tpsk_err:\n\t\t\tOPENSSL_cleanse(identity, PSK_MAX_IDENTITY_LEN);\n\t\t\tOPENSSL_cleanse(psk_or_pre_ms, sizeof(psk_or_pre_ms));\n\t\t\tif (psk_err != 0)\n\t\t\t\t{\n\t\t\t\tssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t}\n#endif\n\t\telse\n/* ... 11 lines omitted ... */\n\t\ts->state=SSL3_ST_CW_KEY_EXCH_B;\n\t\t/* number of bytes to write */\n\t\ts->init_num=n+4;\n\t\ts->init_off=0;\n\t\t}\n\n\t/* SSL3_ST_CW_KEY_EXCH_B */\n\treturn(ssl3_do_write(s,SSL3_RT_HANDSHAKE));\nerr:\n#ifndef OPENSSL_NO_ECDH\n\tBN_CTX_free(bn_ctx);\n\tif (encodedPoint != NULL) OPENSSL_free(encodedPoint);\n\tif (clnt_ecdh != NULL) \n\t\tEC_KEY_free(clnt_ecdh);\n\tEVP_PKEY_free(srvr_pub_pkey);\n#endif\n\treturn(-1);\n\t}\n\nint ssl3_send_client_verify(SSL *s)\n```\n\n### ssl/s3_srvr.c\n\n#### ssl3_get_client_key_exchange() [lines 2126-2912]\n```c\n\treturn(-1);\n\t}\n\nint ssl3_get_client_key_exchange(SSL *s)\n\t{\n\tint i,al,ok;\n\tlong n;\n\tunsigned long alg_k;\n\tunsigned char *p;\n#ifndef OPENSSL_NO_RSA\n\tRSA *rsa=NULL;\n\tEVP_PKEY *pkey=NULL;\n#endif\n#ifndef OPENSSL_NO_DH\n\tBIGNUM *pub=NULL;\n\tDH *dh_srvr;\n#endif\n#ifndef OPENSSL_NO_KRB5\n\tKSSL_ERR kssl_err;\n#endif /* OPENSSL_NO_KRB5 */\n\n#ifndef OPENSSL_NO_ECDH\n\tEC_KEY *srvr_ecdh = NULL;\n\tEVP_PKEY *clnt_pub_pkey = NULL;\n\tEC_POINT *clnt_ecpoint = NULL;\n\tBN_CTX *bn_ctx = NULL; \n#endif\n\n\tn=s->method->ssl_get_message(s,\n\t\tSSL3_ST_SR_KEY_EXCH_A,\n\t\tSSL3_ST_SR_KEY_EXCH_B,\n\t\tSSL3_MT_CLIENT_KEY_EXCHANGE,\n\t\t2048, /* ??? */\n\t\t&ok);\n\n\tif (!ok) return((int)n);\n\tp=(unsigned char *)s->init_msg;\n\n\talg_k=s->s3->tmp.new_cipher->algorithm_mkey;\n\n/* ... 607 lines omitted ... */\n\t\tpsk_err:\n\t\t\tOPENSSL_cleanse(psk_or_pre_ms, sizeof(psk_or_pre_ms));\n\t\t\tif (psk_err != 0)\n\t\t\t\tgoto f_err;\n\t\t\t}\n\t\telse\n#endif\n#ifndef OPENSSL_NO_SRP\n\t\tif (alg_k & SSL_kSRP)\n\t\t\t{\n\t\t\tint param_len;\n\n\t\t\tn2s(p,i);\n\t\t\tparam_len=i+2;\n\t\t\tif (param_len > n)\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_SRP_A_LENGTH);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\tif (!(s->srp_ctx.A=BN_bin2bn(p,i,NULL)))\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,ERR_R_BN_LIB);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tif (BN_ucmp(s->srp_ctx.A, s->srp_ctx.N) >= 0\n\t\t\t\t|| BN_is_zero(s->srp_ctx.A))\n/* ... 93 lines omitted ... */\n\t\tgoto f_err;\n\t\t}\n\n\treturn(1);\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,al);\n#if !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_ECDH) || defined(OPENSSL_NO_SRP)\nerr:\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tEVP_PKEY_free(clnt_pub_pkey);\n\tEC_POINT_free(clnt_ecpoint);\n\tif (srvr_ecdh != NULL) \n\t\tEC_KEY_free(srvr_ecdh);\n\tBN_CTX_free(bn_ctx);\n#endif\n\treturn(-1);\n\t}\n\nint ssl3_get_cert_verify(SSL *s)\n```\n\n\n## Upstream Fix\n```diff\nFrom 3c66a669dfc7b3792f7af0758ea26fe8502ce70c Mon Sep 17 00:00:00 2001\nFrom: \"Dr. Stephen Henson\" \nDate: Wed, 1 Jul 2015 23:40:03 +0100\nSubject: [PATCH] Fix PSK handling.\n\nThe PSK identity hint should be stored in the SSL_SESSION structure\nand not in the parent context (which will overwrite values used\nby other SSL structures with the same SSL_CTX).\n\nUse BUF_strndup when copying identity as it may not be null terminated.\n\nReviewed-by: Tim Hudson \n---\n ssl/s3_clnt.c | 17 +++--------------\n ssl/s3_srvr.c | 2 +-\n 2 files changed, 4 insertions(+), 15 deletions(-)\n\ndiff --git a/ssl/s3_clnt.c b/ssl/s3_clnt.c\nindex 2346ce50c0701..6af145a8b744d 100644\n--- a/ssl/s3_clnt.c\n+++ b/ssl/s3_clnt.c\n@@ -1456,8 +1456,6 @@ int ssl3_get_key_exchange(SSL *s)\n \n #ifndef OPENSSL_NO_PSK\n if (alg_k & SSL_kPSK) {\n- char tmp_id_hint[PSK_MAX_IDENTITY_LEN + 1];\n-\n param_len = 2;\n if (param_len > n) {\n SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE, SSL_R_LENGTH_TOO_SHORT);\n@@ -1483,17 +1481,8 @@ int ssl3_get_key_exchange(SSL *s)\n }\n param_len += i;\n \n- /*\n- * If received PSK identity hint contains NULL characters, the hint\n- * is truncated from the first NULL. p may not be ending with NULL,\n- * so create a NULL-terminated string.\n- */\n- memcpy(tmp_id_hint, p, i);\n- memset(tmp_id_hint + i, 0, PSK_MAX_IDENTITY_LEN + 1 - i);\n- if (s->ctx->psk_identity_hint != NULL)\n- OPENSSL_free(s->ctx->psk_identity_hint);\n- s->ctx->psk_identity_hint = BUF_strdup(tmp_id_hint);\n- if (s->ctx->psk_identity_hint == NULL) {\n+ s->session->psk_identity_hint = BUF_strndup((char *)p, i);\n+ if (s->session->psk_identity_hint == NULL) {\n al = SSL_AD_HANDSHAKE_FAILURE;\n SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE, ERR_R_MALLOC_FAILURE);\n goto f_err;\n@@ -3077,7 +3066,7 @@ int ssl3_send_client_key_exchange(SSL *s)\n }\n \n memset(identity, 0, sizeof(identity));\n- psk_len = s->psk_client_callback(s, s->ctx->psk_identity_hint,\n+ psk_len = s->psk_client_callback(s, s->session->psk_identity_hint,\n identity, sizeof(identity) - 1,\n psk_or_pre_ms,\n sizeof(psk_or_pre_ms));\ndiff --git a/ssl/s3_srvr.c b/ssl/s3_srvr.c\nindex 8885694c02b34..acd3b9e964a23 100644\n--- a/ssl/s3_srvr.c\n+++ b/ssl/s3_srvr.c\n@@ -2780,7 +2780,7 @@ int ssl3_get_client_key_exchange(SSL *s)\n \n if (s->session->psk_identity != NULL)\n OPENSSL_free(s->session->psk_identity);\n- s->session->psk_identity = BUF_strdup((char *)p);\n+ s->session->psk_identity = BUF_strndup((char *)p, i);\n if (s->session->psk_identity == NULL) {\n SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, ERR_R_MALLOC_FAILURE);\n goto psk_err;\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From d6be3124f22870f1888c532523b74ea5d89795eb Mon Sep 17 00:00:00 2001\nFrom: \"Dr. Stephen Henson\" \nDate: Wed, 1 Jul 2015 23:40:03 +0100\nSubject: [PATCH] Fix PSK handling.\n\nThe PSK identity hint should be stored in the SSL_SESSION structure\nand not in the parent context (which will overwrite values used\nby other SSL structures with the same SSL_CTX).\n\nUse BUF_strndup when copying identity as it may not be null terminated.\n\nReviewed-by: Tim Hudson \n(cherry picked from commit 3c66a669dfc7b3792f7af0758ea26fe8502ce70c)\n---\n ssl/s3_clnt.c | 17 +++--------------\n ssl/s3_srvr.c | 2 +-\n 2 files changed, 4 insertions(+), 15 deletions(-)\n\nIndex: openssl-1.0.1i/ssl/s3_clnt.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s3_clnt.c\t2015-12-04 14:10:29.276897903 +0100\n+++ openssl-1.0.1i/ssl/s3_clnt.c\t2015-12-04 14:10:30.131911388 +0100\n@@ -1374,8 +1374,6 @@ int ssl3_get_key_exchange(SSL *s)\n #ifndef OPENSSL_NO_PSK\n \tif (alg_k & SSL_kPSK)\n \t\t{\n-\t\tchar tmp_id_hint[PSK_MAX_IDENTITY_LEN+1];\n-\n \t\tal=SSL_AD_HANDSHAKE_FAILURE;\n \t\tn2s(p,i);\n \t\tparam_len=i+2;\n@@ -1396,16 +1394,9 @@ int ssl3_get_key_exchange(SSL *s)\n \t\t\t\tSSL_R_BAD_PSK_IDENTITY_HINT_LENGTH);\n \t\t\tgoto f_err;\n \t\t\t}\n-\t\t/* If received PSK identity hint contains NULL\n-\t\t * characters, the hint is truncated from the first\n-\t\t * NULL. p may not be ending with NULL, so create a\n-\t\t * NULL-terminated string. */\n-\t\tmemcpy(tmp_id_hint, p, i);\n-\t\tmemset(tmp_id_hint+i, 0, PSK_MAX_IDENTITY_LEN+1-i);\n-\t\tif (s->ctx->psk_identity_hint != NULL)\n-\t\t\tOPENSSL_free(s->ctx->psk_identity_hint);\n-\t\ts->ctx->psk_identity_hint = BUF_strdup(tmp_id_hint);\n-\t\tif (s->ctx->psk_identity_hint == NULL)\n+\n+\t s->session->psk_identity_hint = BUF_strndup((char *)p, i);\n+ \tif (s->session->psk_identity_hint == NULL)\n \t\t\t{\n \t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE, ERR_R_MALLOC_FAILURE);\n \t\t\tgoto f_err;\n@@ -2911,7 +2902,7 @@ int ssl3_send_client_key_exchange(SSL *s\n \t\t\t\tgoto err;\n \t\t\t\t}\n \n-\t\t\tpsk_len = s->psk_client_callback(s, s->ctx->psk_identity_hint,\n+\t\t\tpsk_len = s->psk_client_callback(s, s->session->psk_identity_hint,\n \t\t\t\tidentity, PSK_MAX_IDENTITY_LEN,\n \t\t\t\tpsk_or_pre_ms, sizeof(psk_or_pre_ms));\n \t\t\tif (psk_len > PSK_MAX_PSK_LEN)\nIndex: openssl-1.0.1i/ssl/s3_srvr.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s3_srvr.c\t2015-12-04 14:10:30.132911404 +0100\n+++ openssl-1.0.1i/ssl/s3_srvr.c\t2015-12-04 14:11:57.400287544 +0100\n@@ -2782,7 +2782,7 @@ int ssl3_get_client_key_exchange(SSL *s)\n \n \t\t\tif (s->session->psk_identity != NULL)\n \t\t\t\tOPENSSL_free(s->session->psk_identity);\n-\t\t\ts->session->psk_identity = BUF_strdup((char *)p);\n+\t\t\ts->session->psk_identity = BUF_strndup((char *)p, i);\n \t\t\tif (s->session->psk_identity == NULL)\n \t\t\t\t{\n \t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,"}], "metadata": {"id": "openssl-4769-openssl-CVE-2015-3196.patch", "cve_id": "CVE-2015-3197", "package": "openssl", "upstream_enriched": true, "upstream_commit": "3c66a669dfc7b3792f7af0758ea26fe8502ce70c", "upstream_repo": "openssl/openssl", "tier": "adapted", "has_source_context": true, "context_tokens_est": 1525, "context_files": 2, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2013-4560\n\nUse-after-free vulnerability in lighttpd before 1.4.33 allows remote attackers to cause a denial of service (segmentation fault and crash) via unspecified vectors that trigger FAMMonitorDirectory failures.\n\n## Package\nlighttpd\n\n## Files to modify\n- src/request.c\n\n## Upstream Fix\n```diff\nFrom 5ceca33c83803b171d61acc203bace0e8f7d4e0b Mon Sep 17 00:00:00 2001\nFrom: =?UTF-8?q?Stefan=20B=C3=BChler?= \nDate: Sat, 17 Nov 2012 18:22:39 +0100\nSubject: [PATCH] remove whitespace at end of header keys\n\n---\n src/request.c | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/src/request.c b/src/request.c\nindex 0d749e6..8c6c170 100644\n--- a/src/request.c\n+++ b/src/request.c\n@@ -643,10 +643,11 @@ int http_request_parse(server *srv, connection *con) {\n \t\t\t\t\t\t/* skip WS */\n \t\t\t\t\t\tcontinue;\n \t\t\t\t\tcase ':':\n-\t\t\t\t\t\t/* ok, done */\n+\t\t\t\t\t\t/* ok, done; handle the colon the usual way */\n \n \t\t\t\t\t\ti += j - 1;\n \t\t\t\t\t\tgot_colon = 1;\n+\t\t\t\t\t\tis_ws_after_key = 1; /* we already know the key length */\n \n \t\t\t\t\t\tbreak;\n \t\t\t\t\tdefault:\n-- \n1.7.10.4\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From 5ceca33c83803b171d61acc203bace0e8f7d4e0b Mon Sep 17 00:00:00 2001\nFrom: =?UTF-8?q?Stefan=20B=C3=BChler?= \nDate: Sat, 17 Nov 2012 18:22:39 +0100\nSubject: [PATCH] remove whitespace at end of header keys\n\n---\n src/request.c | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/src/request.c b/src/request.c\nindex 0d749e6..8c6c170 100644\n--- a/src/request.c\n+++ b/src/request.c\n@@ -643,10 +643,11 @@ int http_request_parse(server *srv, connection *con) {\n \t\t\t\t\t\t/* skip WS */\n \t\t\t\t\t\tcontinue;\n \t\t\t\t\tcase ':':\n-\t\t\t\t\t\t/* ok, done */\n+\t\t\t\t\t\t/* ok, done; handle the colon the usual way */\n \n \t\t\t\t\t\ti += j - 1;\n \t\t\t\t\t\tgot_colon = 1;\n+\t\t\t\t\t\tis_ws_after_key = 1; /* we already know the key length */\n \n \t\t\t\t\t\tbreak;\n \t\t\t\t\tdefault:\n-- \n1.7.10.4"}], "metadata": {"id": "lighttpd-2374-0001-remove-whitespace-at-end-", "cve_id": "CVE-2013-4560", "package": "lighttpd", "tier": "identical", "has_source_context": false, "license": "BSD-3-Clause"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-9556\n\nThe IsPixelGray function in MagickCore/pixel-accessor.h in ImageMagick 7.0.3-8 allows remote attackers to cause a denial of service (out-of-bounds heap read) via a crafted image file.\n\n## Package\nGraphicsMagick\n\n## Files to modify\n- coders/svg.c\n- GraphicsMagick-1.3.20.orig/coders/svg.c\n- magick/render.c\n- GraphicsMagick-1.3.20.orig/magick/render.c\n\n## Upstream Fix\n```diff\nIndex: GraphicsMagick-1.3.20/coders/svg.c\n===================================================================\n--- GraphicsMagick-1.3.20.orig/coders/svg.c\t2013-03-10 00:19:31.000000000 +0100\n+++ GraphicsMagick-1.3.20/coders/svg.c\t2016-06-23 10:05:21.805840780 +0200\n@@ -316,25 +316,22 @@ static char **GetTransformTokens(void *c\n *p,\n *q;\n \n- register long\n+ register size_t\n i;\n \n SVGInfo\n *svg_info;\n \n+ size_t\n+ alloc_tokens;\n+\n svg_info=(SVGInfo *) context;\n *number_tokens=0;\n if (text == (const char *) NULL)\n return((char **) NULL);\n- /*\n- Determine the number of arguments.\n- */\n- for (p=text; *p != '\\0'; p++)\n- {\n- if (*p == '(')\n- (*number_tokens)+=2;\n- }\n- tokens=MagickAllocateMemory(char **,(*number_tokens+2)*sizeof(*tokens));\n+\n+ alloc_tokens=8;\n+ tokens=MagickAllocateMemory(char **,(alloc_tokens+2)*sizeof(*tokens));\n if (tokens == (char **) NULL)\n {\n ThrowException3(svg_info->exception,ResourceLimitError,\n@@ -350,15 +347,28 @@ static char **GetTransformTokens(void *c\n {\n if ((*q != '(') && (*q != ')') && (*q != '\\0'))\n continue;\n+ if (i == alloc_tokens)\n+ {\n+ alloc_tokens <<= 1;\n+ MagickReallocMemory(char **,tokens,(alloc_tokens+2)*sizeof(*tokens));\n+ if (tokens == (char **) NULL)\n+ {\n+ ThrowException3(svg_info->exception,ResourceLimitError,\n+ MemoryAllocationFailed,UnableToConvertStringToTokens);\n+ return((char **) NULL);\n+ }\n+ }\n tokens[i]=AllocateString(p);\n (void) strlcpy(tokens[i],p,q-p+1);\n- Strip(tokens[i++]);\n+ Strip(tokens[i]);\n+ i++;\n p=q+1;\n }\n tokens[i]=AllocateString(p);\n (void) strlcpy(tokens[i],p,q-p+1);\n Strip(tokens[i++]);\n tokens[i]=(char *) NULL;\n+ *number_tokens=i;\n return(tokens);\n }\n \n@@ -1177,18 +1187,20 @@ static void SVGStartElement(void *contex\n IdentityAffine(&transform);\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\" \");\n tokens=GetTransformTokens(context,value,&number_tokens);\n- for (j=0; j < (number_tokens-1); j+=2)\n+ if ((tokens != (char **) NULL) && (number_tokens > 0))\n {\n- keyword=(char *) tokens[j];\n- if (keyword == (char *) NULL)\n- continue;\n- value=(char *) tokens[j+1];\n- (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n- \" %.1024s: %.1024s\",keyword,value);\n- current=transform;\n- IdentityAffine(&affine);\n- switch (*keyword)\n+ for (j=0; j < (number_tokens-1); j+=2)\n {\n+ keyword=(char *) tokens[j];\n+ if (keyword == (char *) NULL)\n+ continue;\n+ value=(char *) tokens[j+1];\n+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n+ \" %.1024s: %.1024s\",keyword,value);\n+ current=transform;\n+ IdentityAffine(&affine);\n+ switch (*keyword)\n+ {\n case 'M':\n case 'm':\n {\n@@ -1293,22 +1305,23 @@ static void SVGStartElement(void *contex\n }\n default:\n break;\n- }\n- transform.sx=current.sx*affine.sx+current.ry*affine.rx;\n- transform.rx=current.rx*affine.sx+current.sy*affine.rx;\n- transform.ry=current.sx*affine.ry+current.ry*affine.sy;\n- transform.sy=current.rx*affine.ry+current.sy*affine.sy;\n- transform.tx=current.sx*affine.tx+current.ry*affine.ty+\n- current.tx;\n- transform.ty=current.rx*affine.tx+current.sy*affine.ty+\n- current.ty;\n- }\n- MVGPrintf(svg_info->file,\"affine %g %g %g %g %g %g\\n\",\n- transform.sx,transform.rx,transform.ry,transform.sy,\n- transform.tx,transform.ty);\n- for (j=0; tokens[j] != (char *) NULL; j++)\n- MagickFreeMemory(tokens[j]);\n- MagickFreeMemory(tokens);\n+ } /* end switch */\n+ transform.sx=current.sx*affine.sx+current.ry*affine.rx;\n+ transform.rx=current.rx*affine.sx+current.sy*affine.rx;\n+ transform.ry=current.sx*affine.ry+current.ry*affine.sy;\n+ transform.sy=current.rx*affine.ry+current.sy*affine.sy;\n+ transform.tx=current.sx*affine.tx+current.ry*affine.ty+\n+ current.tx;\n+ transform.ty=current.rx*affine.tx+current.sy*affine.ty+\n+ current.ty;\n+ } /* end for */\n+ MVGPrintf(svg_info->file,\"affine %g %g %g %g %g %g\\n\",\n+ transform.sx,transform.rx,transform.ry,transform.sy,\n+ transform.tx,transform.ty);\n+ for (j=0; tokens[j] != (char *) NULL; j++)\n+ MagickFreeMemory(tokens[j]);\n+ MagickFreeMemory(tokens);\n+ } /* end if */\n break;\n }\n if (LocaleCompare(keyword,\"gradientUnits\") == 0)\n@@ -1746,6 +1759,8 @@ static void SVGStartElement(void *contex\n IdentityAffine(&transform);\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\" \");\n tokens=GetTransformTokens(context,value,&number_tokens);\n+ if ((tokens != (char **) NULL) && (number_tokens > 0))\n+ {\n for (j=0; j < (number_tokens-1); j+=2)\n {\n keyword=(char *) tokens[j];\n@@ -1873,8 +1888,10 @@ static void SVGStartElement(void *contex\n MVGPrintf(svg_info->file,\"affine %g %g %g %g %g %g\\n\",\n transform.sx,transform.rx,transform.ry,transform.sy,\n transform.tx,transform.ty);\n- for (j=0; tokens[j] != (char *) NULL; j++)\n- MagickFreeMemory(tokens[j]);\n+ }\n+ if (number_tokens > 0)\n+ for (j=0; tokens[j] != (char *) NULL; j++)\n+ MagickFreeMemory(tokens[j]);\n MagickFreeMemory(tokens);\n break;\n }\nIndex: GraphicsMagick-1.3.20/magick/render.c\n===================================================================\n--- GraphicsMagick-1.3.20.orig/magick/render.c\t2016-06-23 10:05:21.649838266 +0200\n+++ GraphicsMagick-1.3.20/magick/render.c\t2016-06-23 10:05:21.805840780 +0200\n@@ -432,7 +432,7 @@ ConvertPathToPolygon(const PathInfo *pat\n {\n number_edges<<=1;\n MagickReallocMemory(EdgeInfo *,polygon_info->edges,\n- number_edges*sizeof(EdgeInfo));\n+ MagickArraySize(number_edges,sizeof(EdgeInfo)));\n if (polygon_info->edges == (EdgeInfo *) NULL)\n return((PolygonInfo *) NULL);\n }\n@@ -484,7 +484,7 @@ ConvertPathToPolygon(const PathInfo *pat\n {\n number_edges<<=1;\n MagickReallocMemory(EdgeInfo *,polygon_info->edges,\n- number_edges*sizeof(EdgeInfo));\n+ MagickArraySize(number_edges,sizeof(EdgeInfo)));\n if (polygon_info->edges == (EdgeInfo *) NULL)\n return((PolygonInfo *) NULL);\n }\n@@ -517,7 +517,7 @@ ConvertPathToPolygon(const PathInfo *pat\n if (n == number_points)\n {\n number_points<<=1;\n- MagickReallocMemory(PointInfo *,points,number_points*sizeof(PointInfo));\n+ MagickReallocMemory(PointInfo *,points,MagickArraySize(number_points,sizeof(PointInfo)));\n if (points == (PointInfo *) NULL)\n return((PolygonInfo *) NULL);\n }\n@@ -541,7 +541,7 @@ ConvertPathToPolygon(const PathInfo *p\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "Index: GraphicsMagick-1.3.20/coders/svg.c\n===================================================================\n--- GraphicsMagick-1.3.20.orig/coders/svg.c\t2013-03-10 00:19:31.000000000 +0100\n+++ GraphicsMagick-1.3.20/coders/svg.c\t2016-06-23 10:05:21.805840780 +0200\n@@ -316,25 +316,22 @@ static char **GetTransformTokens(void *c\n *p,\n *q;\n \n- register long\n+ register size_t\n i;\n \n SVGInfo\n *svg_info;\n \n+ size_t\n+ alloc_tokens;\n+\n svg_info=(SVGInfo *) context;\n *number_tokens=0;\n if (text == (const char *) NULL)\n return((char **) NULL);\n- /*\n- Determine the number of arguments.\n- */\n- for (p=text; *p != '\\0'; p++)\n- {\n- if (*p == '(')\n- (*number_tokens)+=2;\n- }\n- tokens=MagickAllocateMemory(char **,(*number_tokens+2)*sizeof(*tokens));\n+\n+ alloc_tokens=8;\n+ tokens=MagickAllocateMemory(char **,(alloc_tokens+2)*sizeof(*tokens));\n if (tokens == (char **) NULL)\n {\n ThrowException3(svg_info->exception,ResourceLimitError,\n@@ -350,15 +347,28 @@ static char **GetTransformTokens(void *c\n {\n if ((*q != '(') && (*q != ')') && (*q != '\\0'))\n continue;\n+ if (i == alloc_tokens)\n+ {\n+ alloc_tokens <<= 1;\n+ MagickReallocMemory(char **,tokens,(alloc_tokens+2)*sizeof(*tokens));\n+ if (tokens == (char **) NULL)\n+ {\n+ ThrowException3(svg_info->exception,ResourceLimitError,\n+ MemoryAllocationFailed,UnableToConvertStringToTokens);\n+ return((char **) NULL);\n+ }\n+ }\n tokens[i]=AllocateString(p);\n (void) strlcpy(tokens[i],p,q-p+1);\n- Strip(tokens[i++]);\n+ Strip(tokens[i]);\n+ i++;\n p=q+1;\n }\n tokens[i]=AllocateString(p);\n (void) strlcpy(tokens[i],p,q-p+1);\n Strip(tokens[i++]);\n tokens[i]=(char *) NULL;\n+ *number_tokens=i;\n return(tokens);\n }\n \n@@ -1177,18 +1187,20 @@ static void SVGStartElement(void *contex\n IdentityAffine(&transform);\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\" \");\n tokens=GetTransformTokens(context,value,&number_tokens);\n- for (j=0; j < (number_tokens-1); j+=2)\n+ if ((tokens != (char **) NULL) && (number_tokens > 0))\n {\n- keyword=(char *) tokens[j];\n- if (keyword == (char *) NULL)\n- continue;\n- value=(char *) tokens[j+1];\n- (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n- \" %.1024s: %.1024s\",keyword,value);\n- current=transform;\n- IdentityAffine(&affine);\n- switch (*keyword)\n+ for (j=0; j < (number_tokens-1); j+=2)\n {\n+ keyword=(char *) tokens[j];\n+ if (keyword == (char *) NULL)\n+ continue;\n+ value=(char *) tokens[j+1];\n+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n+ \" %.1024s: %.1024s\",keyword,value);\n+ current=transform;\n+ IdentityAffine(&affine);\n+ switch (*keyword)\n+ {\n case 'M':\n case 'm':\n {\n@@ -1293,22 +1305,23 @@ static void SVGStartElement(void *contex\n }\n default:\n break;\n- }\n- transform.sx=current.sx*affine.sx+current.ry*affine.rx;\n- transform.rx=current.rx*affine.sx+current.sy*affine.rx;\n- transform.ry=current.sx*affine.ry+current.ry*affine.sy;\n- transform.sy=current.rx*affine.ry+current.sy*affine.sy;\n- transform.tx=current.sx*affine.tx+current.ry*affine.ty+\n- current.tx;\n- transform.ty=current.rx*affine.tx+current.sy*affine.ty+\n- current.ty;\n- }\n- MVGPrintf(svg_info->file,\"affine %g %g %g %g %g %g\\n\",\n- transform.sx,transform.rx,transform.ry,transform.sy,\n- transform.tx,transform.ty);\n- for (j=0; tokens[j] != (char *) NULL; j++)\n- MagickFreeMemory(tokens[j]);\n- MagickFreeMemory(tokens);\n+ } /* end switch */\n+ transform.sx=current.sx*affine.sx+current.ry*affine.rx;\n+ transform.rx=current.rx*affine.sx+current.sy*affine.rx;\n+ transform.ry=current.sx*affine.ry+current.ry*affine.sy;\n+ transform.sy=current.rx*affine.ry+current.sy*affine.sy;\n+ transform.tx=current.sx*affine.tx+current.ry*affine.ty+\n+ current.tx;\n+ transform.ty=current.rx*affine.tx+current.sy*affine.ty+\n+ current.ty;\n+ } /* end for */\n+ MVGPrintf(svg_info->file,\"affine %g %g %g %g %g %g\\n\",\n+ transform.sx,transform.rx,transform.ry,transform.sy,\n+ transform.tx,transform.ty);\n+ for (j=0; tokens[j] != (char *) NULL; j++)\n+ MagickFreeMemory(tokens[j]);\n+ MagickFreeMemory(tokens);\n+ } /* end if */\n break;\n }\n if (LocaleCompare(keyword,\"gradientUnits\") == 0)\n@@ -1746,6 +1759,8 @@ static void SVGStartElement(void *contex\n IdentityAffine(&transform);\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\" \");\n tokens=GetTransformTokens(context,value,&number_tokens);\n+ if ((tokens != (char **) NULL) && (number_tokens > 0))\n+ {\n for (j=0; j < (number_tokens-1); j+=2)\n {\n keyword=(char *) tokens[j];\n@@ -1873,8 +1888,10 @@ static void SVGStartElement(void *contex\n MVGPrintf(svg_info->file,\"affine %g %g %g %g %g %g\\n\",\n transform.sx,transform.rx,transform.ry,transform.sy,\n transform.tx,transform.ty);\n- for (j=0; tokens[j] != (char *) NULL; j++)\n- MagickFreeMemory(tokens[j]);\n+ }\n+ if (number_tokens > 0)\n+ for (j=0; tokens[j] != (char *) NULL; j++)\n+ MagickFreeMemory(tokens[j]);\n MagickFreeMemory(tokens);\n break;\n }\nIndex: GraphicsMagick-1.3.20/magick/render.c\n===================================================================\n--- GraphicsMagick-1.3.20.orig/magick/render.c\t2016-06-23 10:05:21.649838266 +0200\n+++ GraphicsMagick-1.3.20/magick/render.c\t2016-06-23 10:05:21.805840780 +0200\n@@ -432,7 +432,7 @@ ConvertPathToPolygon(const PathInfo *pat\n {\n number_edges<<=1;\n MagickReallocMemory(EdgeInfo *,polygon_info->edges,\n- number_edges*sizeof(EdgeInfo));\n+ MagickArraySize(number_edges,sizeof(EdgeInfo)));\n if (polygon_info->edges == (EdgeInfo *) NULL)\n return((PolygonInfo *) NULL);\n }\n@@ -484,7 +484,7 @@ ConvertPathToPolygon(const PathInfo *pat\n {\n number_edges<<=1;\n MagickReallocMemory(EdgeInfo *,polygon_info->edges,\n- number_edges*sizeof(EdgeInfo));\n+ MagickArraySize(number_edges,sizeof(EdgeInfo)));\n if (polygon_info->edges == (EdgeInfo *) NULL)\n return((PolygonInfo *) NULL);\n }\n@@ -517,7 +517,7 @@ ConvertPathToPolygon(const PathInfo *pat\n if (n == number_points)\n {\n number_points<<=1;\n- MagickReallocMemory(PointInfo *,points,number_points*sizeof(PointInfo));\n+ MagickReallocMemory(PointInfo *,points,MagickArraySize(number_points,sizeof(PointInfo)));\n if (points == (PointInfo *) NULL)\n return((PolygonInfo *) NULL);\n }\n@@ -541,7 +541,7 @@ ConvertPathToPolygon(const PathInfo *pat\n {\n number_edges<<=1;\n MagickReallocMemory(EdgeInfo *,polygon_info->edges,\n- number_edges*sizeof(EdgeInfo));\n+ MagickArraySize(number_edges,sizeof(EdgeInfo)));\n if (polygon_info->edges == (EdgeInfo *) NULL)\n return((PolygonInfo *) NULL);\n }\n@@ -2309,7 +2309,7 @@ DrawImage(Image *image,const DrawInfo *d\n {\n n++;\n MagickReallocMemory(DrawInfo **,graphic_context,\n- (n+1)*sizeof(DrawInfo *));\n+ MagickArraySize((n+1),sizeof(DrawInfo *)));\n if (graphic_context == (DrawInfo **) NULL)\n {\n ThrowException3(&image->exception,ResourceLimitError,\n@@ -2671,7 +2671,7 @@ DrawImage(Image *image,const DrawInfo *d\n continue;\n number_points<<=1;\n MagickReallocMemory(PrimitiveInfo *,primitive_info,\n- number_points*sizeof(PrimitiveInfo));\n+ MagickArraySize(number_points,sizeof(PrimitiveInfo)));\n if (primitive_info == (PrimitiveInfo *) NULL)\n {\n ThrowException3(&image->exception,ResourceLimitError,\n@@ -2777,7 +2777,7 @@ DrawImage(Image *image,const DrawInfo *d\n {\n number_points+=length+1;\n MagickReallocMemory(PrimitiveInfo *,primitive_info,\n- number_points*sizeof(PrimitiveInfo));\n+ MagickArraySize(number_points,sizeof(PrimitiveInfo)));\n if (primitive_info == (PrimitiveInfo *) NULL)\n {\n ThrowException3(&image->exception,ResourceLimitError,\n@@ -5468,8 +5468,8 @@ TraceStrokePolygon(const DrawInfo *draw_\n if (q >= (max_strokes-6*BezierQuantum-360))\n {\n max_strokes+=6*BezierQuantum+360;\n- MagickReallocMemory(PointInfo *,path_p,max_strokes*sizeof(PointInfo));\n- MagickReallocMemory(PointInfo *,path_q,max_strokes*sizeof(PointInfo));\n+ MagickReallocMemory(PointInfo *,path_p,MagickArraySize(max_strokes,sizeof(PointInfo)));\n+ MagickReallocMemory(PointInfo *,path_q,MagickArraySize(max_strokes,sizeof(PointInfo)));\n if ((path_p == (PointInfo *) NULL) || (path_q == (PointInfo *) NULL))\n {\n MagickFreeMemory(polygon_primitive);"}], "metadata": {"id": "GraphicsMagick-5956-GraphicsMagick-CVE-2016-2317.p", "cve_id": "CVE-2016-9556", "package": "GraphicsMagick", "tier": "adapted", "has_source_context": false, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2012-0113\n\nUnspecified vulnerability in the MySQL Server component in Oracle MySQL 5.1.x and 5.5.x allows remote authenticated users to affect confidentiality and availability via unknown vectors, a different vulnerability than CVE-2012-0118.\n\n## Package\nmariadb\n\n## Files to modify\n- mysys/mf_keycache.c\n\n## Upstream Fix\n```diff\nPATCH-P0-FEATURE-UPSTREAM: Better handling of memcpy\nBUGS: upstream#19975\n\nStandard memcpy should behave better then self made one.\n\nMaintainer: Michal Hrusecky \n\nIndex: mysys/mf_keycache.c\n===================================================================\n--- mysys/mf_keycache.c.orig\n+++ mysys/mf_keycache.c\n@@ -2646,10 +2646,7 @@ uchar *key_cache_read(KEY_CACHE *keycach\n #endif\n \n /* Copy data from the cache buffer */\n- if (!(read_length & 511))\n- bmove512(buff, block->buffer+offset, read_length);\n- else\n- memcpy(buff, block->buffer+offset, (size_t) read_length);\n+ memcpy(buff, block->buffer+offset, (size_t) read_length);\n \n #if !defined(SERIALIZED_READ_FROM_CACHE)\n keycache_pthread_mutex_lock(&keycache->cache_lock);\n@@ -2857,10 +2854,7 @@ int key_cache_insert(KEY_CACHE *keycache\n #endif\n \n /* Copy data from buff */\n- if (!(read_length & 511))\n- bmove512(block->buffer+offset, buff, read_length);\n- else\n- memcpy(block->buffer+offset, buff, (size_t) read_length);\n+ memcpy(block->buffer+offset, buff, (size_t) read_length);\n \n #if !defined(SERIALIZED_READ_FROM_CACHE)\n keycache_pthread_mutex_lock(&keycache->cache_lock);\n@@ -3164,10 +3158,7 @@ int key_cache_write(KEY_CACHE *keycache,\n #if !defined(SERIALIZED_READ_FROM_CACHE)\n keycache_pthread_mutex_unlock(&keycache->cache_lock);\n #endif\n- if (!(read_length & 511))\n-\t bmove512(block->buffer+offset, buff, read_length);\n- else\n- memcpy(block->buffer+offset, buff, (size_t) read_length);\n+ memcpy(block->buffer+offset, buff, (size_t) read_length);\n \n #if !defined(SERIALIZED_READ_FROM_CACHE)\n keycache_pthread_mutex_lock(&keycache->cache_lock);\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "PATCH-P0-FEATURE-UPSTREAM: Better handling of memcpy\nBUGS: upstream#19975\n\nStandard memcpy should behave better then self made one.\n\nMaintainer: Michal Hrusecky \n\nIndex: mysys/mf_keycache.c\n===================================================================\n--- mysys/mf_keycache.c.orig\n+++ mysys/mf_keycache.c\n@@ -2646,10 +2646,7 @@ uchar *key_cache_read(KEY_CACHE *keycach\n #endif\n \n /* Copy data from the cache buffer */\n- if (!(read_length & 511))\n- bmove512(buff, block->buffer+offset, read_length);\n- else\n- memcpy(buff, block->buffer+offset, (size_t) read_length);\n+ memcpy(buff, block->buffer+offset, (size_t) read_length);\n \n #if !defined(SERIALIZED_READ_FROM_CACHE)\n keycache_pthread_mutex_lock(&keycache->cache_lock);\n@@ -2857,10 +2854,7 @@ int key_cache_insert(KEY_CACHE *keycache\n #endif\n \n /* Copy data from buff */\n- if (!(read_length & 511))\n- bmove512(block->buffer+offset, buff, read_length);\n- else\n- memcpy(block->buffer+offset, buff, (size_t) read_length);\n+ memcpy(block->buffer+offset, buff, (size_t) read_length);\n \n #if !defined(SERIALIZED_READ_FROM_CACHE)\n keycache_pthread_mutex_lock(&keycache->cache_lock);\n@@ -3164,10 +3158,7 @@ int key_cache_write(KEY_CACHE *keycache,\n #if !defined(SERIALIZED_READ_FROM_CACHE)\n keycache_pthread_mutex_unlock(&keycache->cache_lock);\n #endif\n- if (!(read_length & 511))\n-\t bmove512(block->buffer+offset, buff, read_length);\n- else\n- memcpy(block->buffer+offset, buff, (size_t) read_length);\n+ memcpy(block->buffer+offset, buff, (size_t) read_length);\n \n #if !defined(SERIALIZED_READ_FROM_CACHE)\n keycache_pthread_mutex_lock(&keycache->cache_lock);"}], "metadata": {"id": "mariadb-499-mysql-community-server-5.1.36-", "cve_id": "CVE-2012-0113", "package": "mariadb", "tier": "identical", "has_source_context": false, "license": "GPL-2.0-only"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-4658\n\nxpointer.c in libxml2 before 2.9.5 (as used in Apple iOS before 10, OS X before 10.12, tvOS before 10, and watchOS before 3, and other products) does not forbid namespace nodes in XPointer ranges, which allows remote attackers to execute arbitrary code or cause a denial of service (use-after-free and memory corruption) via a crafted XML document.\n\n## Package\nlibxml2\n\n## Files to modify\n- xmlstring.c\n\n## Upstream Fix\n```diff\nFrom 8fbbf5513d609c1770b391b99e33314cd0742704 Mon Sep 17 00:00:00 2001\nFrom: Pranjal Jumde \nDate: Tue, 8 Mar 2016 17:29:00 -0800\nSubject: [PATCH] Bug 763071: heap-buffer-overflow in xmlStrncat\n \n\n* xmlstring.c:\n(xmlStrncat): Return NULL if xmlStrlen returns a negative length.\n(xmlStrncatNew): Ditto.\n---\n xmlstring.c | 9 ++++++++-\n 1 file changed, 8 insertions(+), 1 deletion(-)\n\ndiff --git a/xmlstring.c b/xmlstring.c\nindex b89c9e9f88..00287d4c7f 100644\n--- a/xmlstring.c\n+++ b/xmlstring.c\n@@ -457,6 +457,8 @@ xmlStrncat(xmlChar *cur, const xmlChar *add, int len) {\n return(xmlStrndup(add, len));\n \n size = xmlStrlen(cur);\n+ if (size < 0)\n+ return(NULL);\n ret = (xmlChar *) xmlRealloc(cur, (size + len + 1) * sizeof(xmlChar));\n if (ret == NULL) {\n xmlErrMemory(NULL, NULL);\n@@ -484,14 +486,19 @@ xmlStrncatNew(const xmlChar *str1, const xmlChar *str2, int len) {\n int size;\n xmlChar *ret;\n \n- if (len < 0)\n+ if (len < 0) {\n len = xmlStrlen(str2);\n+ if (len < 0)\n+ return(NULL);\n+ }\n if ((str2 == NULL) || (len == 0))\n return(xmlStrdup(str1));\n if (str1 == NULL)\n return(xmlStrndup(str2, len));\n \n size = xmlStrlen(str1);\n+ if (size < 0)\n+ return(NULL);\n ret = (xmlChar *) xmlMalloc((size + len + 1) * sizeof(xmlChar));\n if (ret == NULL) {\n xmlErrMemory(NULL, NULL);\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From 8fbbf5513d609c1770b391b99e33314cd0742704 Mon Sep 17 00:00:00 2001\nFrom: Pranjal Jumde \nDate: Tue, 8 Mar 2016 17:29:00 -0800\nSubject: Bug 763071: heap-buffer-overflow in xmlStrncat\n \n\n* xmlstring.c:\n(xmlStrncat): Return NULL if xmlStrlen returns a negative length.\n(xmlStrncatNew): Ditto.\n---\n xmlstring.c | 9 ++++++++-\n 1 file changed, 8 insertions(+), 1 deletion(-)\n\ndiff --git a/xmlstring.c b/xmlstring.c\nindex b89c9e9..00287d4 100644\n--- a/xmlstring.c\n+++ b/xmlstring.c\n@@ -457,6 +457,8 @@ xmlStrncat(xmlChar *cur, const xmlChar *add, int len) {\n return(xmlStrndup(add, len));\n \n size = xmlStrlen(cur);\n+ if (size < 0)\n+ return(NULL);\n ret = (xmlChar *) xmlRealloc(cur, (size + len + 1) * sizeof(xmlChar));\n if (ret == NULL) {\n xmlErrMemory(NULL, NULL);\n@@ -484,14 +486,19 @@ xmlStrncatNew(const xmlChar *str1, const xmlChar *str2, int len) {\n int size;\n xmlChar *ret;\n \n- if (len < 0)\n+ if (len < 0) {\n len = xmlStrlen(str2);\n+ if (len < 0)\n+ return(NULL);\n+ }\n if ((str2 == NULL) || (len == 0))\n return(xmlStrdup(str1));\n if (str1 == NULL)\n return(xmlStrndup(str2, len));\n \n size = xmlStrlen(str1);\n+ if (size < 0)\n+ return(NULL);\n ret = (xmlChar *) xmlMalloc((size + len + 1) * sizeof(xmlChar));\n if (ret == NULL) {\n xmlErrMemory(NULL, NULL);\n-- \ncgit v0.12"}], "metadata": {"id": "libxml2-5762-libxml2-2.9.1-CVE-2016-1834.pa", "cve_id": "CVE-2016-4658", "package": "libxml2", "upstream_enriched": true, "upstream_commit": "8fbbf5513d609c1770b391b99e33314cd0742704", "upstream_repo": "GNOME/libxml2", "tier": "adapted", "has_source_context": false, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-7555\n\nHeap-based buffer overflow in giffix.c in giffix in giflib 5.1.1 allows attackers to cause a denial of service (program crash) via crafted image and logical screen width fields in a GIF file.\n\n## Package\ngiflib\n\n## Files to modify\n- util/giffix.c\n\n## Upstream Fix\n```diff\nFrom 179510be300bf11115e37528d79619b53c884a63 Mon Sep 17 00:00:00 2001\nFrom: \"Eric S. Raymond\" \nDate: Tue, 5 Jan 2016 23:01:45 -0500\nSubject: [PATCH] Address SF bug #71: Buffer overwrite when giffixing a\n malformed gif.\n\n---\n util/giffix.c | 2 ++\n 1 file changed, 2 insertions(+)\n\ndiff --git a/util/giffix.c b/util/giffix.c\nindex 6fba84a..c14c45b 100644\n--- a/util/giffix.c\n+++ b/util/giffix.c\n@@ -112,6 +112,8 @@ int main(int argc, char **argv)\n \t\tHeight = GifFileIn->Image.Height;\n \t\tGifQprintf(\"\\n%s: Image %d at (%d, %d) [%dx%d]: \",\n \t\t PROGRAM_NAME, ++ImageNum, Col, Row, Width, Height);\n+\t\tif (Width > GifFileIn->SWidth)\n+\t\t GIF_EXIT(\"Image is wider than total\");\n \n \t\t/* Put the image descriptor to out file: */\n \t\tif (EGifPutImageDesc(GifFileOut, Col, Row, Width, Height,\n-- \n2.7.0\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From 179510be300bf11115e37528d79619b53c884a63 Mon Sep 17 00:00:00 2001\nFrom: \"Eric S. Raymond\" \nDate: Tue, 5 Jan 2016 23:01:45 -0500\nSubject: [PATCH] Address SF bug #71: Buffer overwrite when giffixing a\n malformed gif.\n\n---\n util/giffix.c | 2 ++\n 1 file changed, 2 insertions(+)\n\ndiff --git a/util/giffix.c b/util/giffix.c\nindex 6fba84a..c14c45b 100644\n--- a/util/giffix.c\n+++ b/util/giffix.c\n@@ -112,6 +112,8 @@ int main(int argc, char **argv)\n \t\tHeight = GifFileIn->Image.Height;\n \t\tGifQprintf(\"\\n%s: Image %d at (%d, %d) [%dx%d]: \",\n \t\t PROGRAM_NAME, ++ImageNum, Col, Row, Width, Height);\n+\t\tif (Width > GifFileIn->SWidth)\n+\t\t GIF_EXIT(\"Image is wider than total\");\n \n \t\t/* Put the image descriptor to out file: */\n \t\tif (EGifPutImageDesc(GifFileOut, Col, Row, Width, Height,\n-- \n2.7.0"}], "metadata": {"id": "giflib-4560-giflib-CVE-2015-7555.patch", "cve_id": "CVE-2015-7555", "package": "giflib", "tier": "identical", "has_source_context": false, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-5118\n\nThe OpenBlob function in blob.c in GraphicsMagick before 1.3.24 and ImageMagick allows remote attackers to execute arbitrary code via a | (pipe) character at the start of a filename.\n\n## Package\nGraphicsMagick\n\n## Files to modify\n- coders/mvg.c\n\n## Upstream Fix\n```diff\ndiff -r 33200fc645f6 coders/mvg.c\n--- a/coders/mvg.c\tSat Nov 07 14:49:16 2015 -0600\n+++ b/coders/mvg.c\tSat May 07 20:11:54 2016 -0500\n@@ -234,6 +234,7 @@\n entry->seekable_stream=True;\n entry->description=\"Magick Vector Graphics\";\n entry->module=\"MVG\";\n+ entry->extension_treatment=IgnoreExtensionTreatment;\n (void) RegisterMagickInfo(entry);\n }\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "diff -r 33200fc645f6 coders/mvg.c\n--- a/coders/mvg.c\tSat Nov 07 14:49:16 2015 -0600\n+++ b/coders/mvg.c\tSat May 07 20:11:54 2016 -0500\n@@ -234,6 +234,7 @@\n entry->seekable_stream=True;\n entry->description=\"Magick Vector Graphics\";\n entry->module=\"MVG\";\n+ entry->extension_treatment=IgnoreExtensionTreatment;\n (void) RegisterMagickInfo(entry);\n }"}], "metadata": {"id": "GraphicsMagick-5161-GraphicsMagick-upstream-disabl", "cve_id": "CVE-2016-5118", "package": "GraphicsMagick", "tier": "identical", "has_source_context": false, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2012-0113\n\nUnspecified vulnerability in the MySQL Server component in Oracle MySQL 5.1.x and 5.5.x allows remote authenticated users to affect confidentiality and availability via unknown vectors, a different vulnerability than CVE-2012-0118.\n\n## Package\nmariadb\n\n## Files to modify\n- vio/viosslfactories.c\n\n## Upstream Fix\n```diff\nPATCH-P0-FIX-UPSTREAM: Incompatible types in ssl\n\nSometimes argument of this function can be const and function doesn't change\nthe variable so there is no reason not to make that argument const;\n\nMaintainer: Michal Hrusecky \n\nIndex: vio/viosslfactories.c\n===================================================================\n--- vio/viosslfactories.c.orig\n+++ vio/viosslfactories.c\n@@ -198,7 +198,7 @@ static void check_ssl_init()\n static struct st_VioSSLFd *\n new_VioSSLFd(const char *key_file, const char *cert_file,\n const char *ca_file, const char *ca_path,\n- const char *cipher, SSL_METHOD *method, \n+ const char *cipher, const SSL_METHOD *method,\n enum enum_ssl_init_error* error)\n {\n DH *dh;\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "PATCH-P0-FIX-UPSTREAM: Incompatible types in ssl\n\nSometimes argument of this function can be const and function doesn't change\nthe variable so there is no reason not to make that argument const;\n\nMaintainer: Michal Hrusecky \n\nIndex: vio/viosslfactories.c\n===================================================================\n--- vio/viosslfactories.c.orig\n+++ vio/viosslfactories.c\n@@ -198,7 +198,7 @@ static void check_ssl_init()\n static struct st_VioSSLFd *\n new_VioSSLFd(const char *key_file, const char *cert_file,\n const char *ca_file, const char *ca_path,\n- const char *cipher, SSL_METHOD *method, \n+ const char *cipher, const SSL_METHOD *method,\n enum enum_ssl_init_error* error)\n {\n DH *dh;"}], "metadata": {"id": "mariadb-499-mysql-community-server-5.1.53-", "cve_id": "CVE-2012-0113", "package": "mariadb", "tier": "identical", "has_source_context": false, "license": "GPL-2.0-only"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-6250\n\nInteger overflow in the ISO9660 writer in libarchive before 3.2.1 allows remote attackers to cause a denial of service (application crash) or execute arbitrary code via vectors related to verifying filename lengths when writing an ISO9660 archive, which trigger a buffer overflow.\n\n## Package\nlibarchive\n\n## Files to modify\n- libarchive/test/test_read_format_zip_msdos.c\n- libarchive/test/test_read_filter_compress.c\n- libarchive/archive_read_support_filter_compress.c\n- libarchive-3.1.2.orig/libarchive/archive_read_support_filter_compress.c\n\n## Target Source Code\n\n### libarchive/archive_read_support_filter_compress.c\n\n#### compress_bidder_bid() [lines 176-205]\n```c\n * This logic returns zero if any part of the signature fails.\n */\nstatic int\ncompress_bidder_bid(struct archive_read_filter_bidder *self,\n struct archive_read_filter *filter)\n{\n\tconst unsigned char *buffer;\n\tssize_t avail;\n\tint bits_checked;\n\n\t(void)self; /* UNUSED */\n\n\tbuffer = __archive_read_filter_ahead(filter, 2, &avail);\n\n\tif (buffer == NULL)\n\t\treturn (0);\n\n\tbits_checked = 0;\n\tif (buffer[0] != 0x1F || buffer[1] != 0x9D)\n\t\treturn (0);\n\tbits_checked += 16;\n\n\t/*\n\t * TODO: Verify more.\n\t */\n\n\treturn (bits_checked);\n}\n\n/*\n```\n\n#### compress_bidder_init() [lines 206-264]\n```c\n * Setup the callbacks.\n */\nstatic int\ncompress_bidder_init(struct archive_read_filter *self)\n{\n\tstruct private_data *state;\n\tstatic const size_t out_block_size = 64 * 1024;\n\tvoid *out_block;\n\tint code;\n\n\tself->code = ARCHIVE_FILTER_COMPRESS;\n\tself->name = \"compress (.Z)\";\n\n\tstate = (struct private_data *)calloc(sizeof(*state), 1);\n\tout_block = malloc(out_block_size);\n\tif (state == NULL || out_block == NULL) {\n\t\tfree(out_block);\n\t\tfree(state);\n\t\tarchive_set_error(&self->archive->archive, ENOMEM,\n\t\t \"Can't allocate data for %s decompression\",\n\t\t self->name);\n\t\treturn (ARCHIVE_FATAL);\n\t}\n\n\tself->data = state;\n\tstate->out_block_size = out_block_size;\n\tstate->out_block = out_block;\n\tself->read = compress_filter_read;\n\tself->skip = NULL; /* not supported */\n\tself->close = compress_filter_close;\n\n\t/* XXX MOVE THE FOLLOWING OUT OF INIT() XXX */\n\n\t(void)getbits(self, 8); /* Skip first signature byte. */\n\t(void)getbits(self, 8); /* Skip second signature byte. */\n\n\tcode = getbits(self, 8);\n\tstate->maxcode_bits = code & 0x1f;\n\tstate->maxcode = (1 << state->maxcode_bits);\n\tstate->use_reset_code = code & 0x80;\n\n\t/* Initialize decompressor. */\n\tstate->free_ent = 256;\n\tstate->stackp = state->stack;\n\tif (state->use_reset_code)\n\t\tstate->free_ent++;\n\tstate->bits = 9;\n\tstate->section_end_code = (1<bits) - 1;\n\tstate->oldcode = -1;\n\tfor (code = 255; code >= 0; code--) {\n\t\tstate->prefix[code] = 0;\n\t\tstate->suffix[code] = code;\n\t}\n\tnext_code(self);\n\n\treturn (ARCHIVE_OK);\n}\n\n/*\n```\n\n### Makefile.am\n\n#### region() [lines 325-411]\n```c\n\tlibarchive/test/test_archive_string_conversion.c\t\\\n\tlibarchive/test/test_archive_write_add_filter_by_name.c\t\\\n\tlibarchive/test/test_archive_write_set_filter_option.c\t\\\n\tlibarchive/test/test_archive_write_set_format_by_name.c\t\\\n\tlibarchive/test/test_archive_write_set_format_option.c\t\\\n\tlibarchive/test/test_archive_write_set_option.c\t\t\\\n\tlibarchive/test/test_archive_write_set_options.c\t\\\n\tlibarchive/test/test_bad_fd.c\t\t\t\t\\\n\tlibarchive/test/test_compat_bzip2.c\t\t\t\\\n\tlibarchive/test/test_compat_cpio.c\t\t\t\\\n\tlibarchive/test/test_compat_gtar.c\t\t\t\\\n\tlibarchive/test/test_compat_gzip.c\t\t\t\\\n\tlibarchive/test/test_compat_lzip.c\t\t\t\\\n\tlibarchive/test/test_compat_lzma.c\t\t\t\\\n\tlibarchive/test/test_compat_lzop.c\t\t\t\\\n\tlibarchive/test/test_compat_mac.c\t\t\t\\\n\tlibarchive/test/test_compat_pax_libarchive_2x.c\t\t\\\n\tlibarchive/test/test_compat_solaris_tar_acl.c\t\t\\\n\tlibarchive/test/test_compat_solaris_pax_sparse.c\t\\\n\tlibarchive/test/test_compat_tar_hardlink.c\t\t\\\n\tlibarchive/test/test_compat_uudecode.c\t\t\t\\\n\tlibarchive/test/test_compat_xz.c\t\t\t\\\n\tlibarchive/test/test_compat_zip.c\t\t\t\\\n\tlibarchive/test/test_empty_write.c\t\t\t\\\n\tlibarchive/test/test_entry.c\t\t\t\t\\\n\tlibarchive/test/test_entry_strmode.c\t\t\t\\\n\tlibarchive/test/test_extattr_freebsd.c\t\t\t\\\n\tlibarchive/test/test_filter_count.c\t\t\t\\\n\tlibarchive/test/test_fuzz.c\t\t\t\t\\\n\tlibarchive/test/test_gnutar_filename_encoding.c\t\t\\\n\tlibarchive/test/test_link_resolver.c\t\t\t\\\n\tlibarchive/test/test_open_failure.c\t\t\t\\\n\tlibarchive/test/test_open_fd.c\t\t\t\t\\\n\tlibarchive/test/test_open_file.c\t\t\t\\\n\tlibarchive/test/test_open_filename.c\t\t\t\\\n\tlibarchive/test/test_pax_filename_encoding.c\t\t\\\n\tlibarchive/test/test_read_data_large.c\t\t\t\\\n\tlibarchive/test/test_read_disk.c\t\t\t\\\n\tlibarchive/test/test_read_disk_directory_traversals.c\t\\\n\tlibarchive/test/test_read_disk_entry_from_file.c\t\\\n\tlibarchive/test/test_read_extract.c\t\t\t\\\n\tlibarchive/test/test_read_file_nonexistent.c\t\t\\\n\tlibarchive/test/test_read_filter_grzip.c\t\t\\\n\tlibarchive/test/test_read_filter_lrzip.c\t\t\\\n\tlibarchive/test/test_read_filter_lzop.c\t\t\t\\\n\tlibarchive/test/test_read_filter_lzop_multiple_parts.c\t\\\n\tliba\n/* ... truncated ... */\n```\n\n### libarchive/test/CMakeLists.txt\n\n#### IF() [lines 40-126]\n```c\n test_archive_string_conversion.c\n test_archive_write_add_filter_by_name.c\n test_archive_write_set_filter_option.c\n test_archive_write_set_format_by_name.c\n test_archive_write_set_format_option.c\n test_archive_write_set_option.c\n test_archive_write_set_options.c\n test_bad_fd.c\n test_compat_bzip2.c\n test_compat_cpio.c\n test_compat_gtar.c\n test_compat_gzip.c\n test_compat_lzip.c\n test_compat_lzma.c\n test_compat_lzop.c\n test_compat_mac.c\n test_compat_pax_libarchive_2x.c\n test_compat_solaris_tar_acl.c\n test_compat_solaris_pax_sparse.c\n test_compat_tar_hardlink.c\n test_compat_uudecode.c\n test_compat_xz.c\n test_compat_zip.c\n test_empty_write.c\n test_entry.c\n test_entry_strmode.c\n test_extattr_freebsd.c\n test_filter_count.c\n test_fuzz.c\n test_gnutar_filename_encoding.c\n test_link_resolver.c\n test_open_failure.c\n test_open_fd.c\n test_open_file.c\n test_open_filename.c\n test_pax_filename_encoding.c\n test_read_data_large.c\n test_read_disk.c\n test_read_disk_directory_traversals.c\n test_read_disk_entry_from_file.c\n test_read_extract.c\n test_read_file_nonexistent.c\n test_read_filter_grzip.c\n test_read_filter_lrzip.c\n test_read_filter_lzop.c\n test_read_filter_lzop_multiple_parts.c\n test_read_filter_program.c\n test_read_filter_program_signature.c\n test_read_filter_uudecode.c\n test_read_format_7zip.c\n test_read_format_ar.c\n test_read_format_cab.c\n test_read_format_cab_filename.c\n test_read_format_cpio_afio.c\n test_read_format_cpio_bin.c\n test_read_format_cpio_bin_Z.c\n test_read_format_cpio_bin_be.c\n test_read_format_cpio_bin_bz2.c\n test_read_format_cpio_bin_gz.c\n test_read_format_cpio_bin_lzip.c\n test_read_format_cpio_bin_lzma.c\n test_read_format_cpio_bin_xz.c\n test_read_format_cpio_filename.c\n test_read_format_cpio_odc.c\n test_read_format_cpio_svr4_bzip2_rpm.c\n test_read_format_cpio_svr4_gzip.c\n test_read_format_cpio_svr4_gzip_rpm.c\n test_read_format_cpio_svr4c_Z.c\n \n/* ... truncated ... */\n```\n\n\n### Type definitions\n\n```c\n/* from archive_private.h */\nstruct archive {\n\t/*\n\t * The magic/state values are used to sanity-check the\n\t * client's usage. If an API function is called at a\n\t * ridiculous time, or the client passes us an invalid\n\t * pointer, these values allow me to catch that.\n\t */\n\tunsigned int\tmagic;\n\tunsigned int\tstate;\n\n\t/*\n\t * Some public API functions depend on the \"real\" type of the\n\t * archive object.\n\t */\n\tstruct archive_vtable *vtable;\n\n\tint\t\t archive_format;\n\tconst char\t *archive_format_name;\n\n\tint\t compression_code;\t/* Currently active compression. */\n\tconst char *compression_name;\n\n\t/* Number of file entries processed. */\n\tint\t\t file_count;\n\n\tint\t\t archive_error_number;\n\tconst char\t *error;\n\tstruct archive_string\terror_string;\n\n\tchar *current_code;\n\tunsigned current_codepage; /* Current ACP(ANSI CodePage). */\n\tunsigned current_oemcp; /* Current OEMCP(OEM CodePage). */\n\tstruct archive_string_conv *sconv;\n};\n```\n\n\n## Upstream Fix\n```diff\ncommit f0b1dbbc325a2d922015eee402b72edd422cb9ea\nAuthor: Tim Kientzle \nDate: Sat Aug 8 21:47:43 2015 -0700\n\n Issue 547: problems with compress bidder\n \n The code previously was not very careful about verifying the\n compression parameters. This led to cases where it failed to\n reject invalid compressed data at the beginning. The invalid\n left shift was one symptom of this.\n \n The code is now more careful: It verifies that the compression\n parameter byte exists and verifies that the maximum code size\n is <= 16 bits.\n \n This also includes some new tests to verify that truncated or\n otherwise invalid compressed data is rejected.\n\nIndex: libarchive-3.1.2/libarchive/archive_read_support_filter_compress.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_read_support_filter_compress.c\n+++ libarchive-3.1.2/libarchive/archive_read_support_filter_compress.c\n@@ -185,19 +185,22 @@ compress_bidder_bid(struct archive_read_\n \n \t(void)self; /* UNUSED */\n \n-\tbuffer = __archive_read_filter_ahead(filter, 2, &avail);\n+\t/* Shortest valid compress file is 3 bytes. */\n+\tbuffer = __archive_read_filter_ahead(filter, 3, &avail);\n \n \tif (buffer == NULL)\n \t\treturn (0);\n \n \tbits_checked = 0;\n+\t/* First two bytes are the magic value */\n \tif (buffer[0] != 0x1F || buffer[1] != 0x9D)\n \t\treturn (0);\n-\tbits_checked += 16;\n-\n-\t/*\n-\t * TODO: Verify more.\n-\t */\n+\t/* Third byte holds compression parameters. */\n+\tif (buffer[2] & 0x20) /* Reserved bit, must be zero. */\n+\t\treturn (0);\n+\tif (buffer[2] & 0x40) /* Reserved bit, must be zero. */\n+\t\treturn (0);\n+\tbits_checked += 18;\n \n \treturn (bits_checked);\n }\n@@ -239,7 +242,13 @@ compress_bidder_init(struct archive_read\n \t(void)getbits(self, 8); /* Skip first signature byte. */\n \t(void)getbits(self, 8); /* Skip second signature byte. */\n \n+\t/* Get compression parameters. */\n \tcode = getbits(self, 8);\n+\tif ((code & 0x1f) > 16) {\n+\t\tarchive_set_error(&self->archive->archive, -1,\n+\t\t \"Invalid compressed data\");\n+\t\treturn (ARCHIVE_FATAL);\n+\t}\n \tstate->maxcode_bits = code & 0x1f;\n \tstate->maxcode = (1 << state->maxcode_bits);\n \tstate->use_reset_code = code & 0x80;\nIndex: libarchive-3.1.2/libarchive/test/test_read_filter_compress.c\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_filter_compress.c\n@@ -0,0 +1,80 @@\n+/*-\n+ * Copyright (c) 2003-2008 Tim Kientzle\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ * 1. Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in the\n+ * documentation and/or other materials provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR\n+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,\n+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+#include \"test.h\"\n+\n+DEFINE_TEST(test_read_filter_compress_truncated)\n+{\n+\tconst char data[] = {0x1f, 0x9d};\n+\tstruct archive *a;\n+\n+\tassert((a = archive_read_new()) != NULL);\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_compress(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));\n+\tassertEqualIntA(a, ARCHIVE_FATAL,\n+\t archive_read_open_memory(a, data, sizeof(data)));\n+\n+\tassertEqualInt(ARCHIVE_OK, archive_read_close(a));\n+\tassertEqualInt(ARCHIVE_OK, archive_read_free(a));\n+}\n+\n+\n+DEFINE_TEST(test_read_filter_compress_empty2)\n+{\n+\tconst char data[] = {0x1f, 0x9d, 0x10};\n+\tstruct archive *a;\n+\tstruct archive_entry *ae;\n+\n+\tassert((a = archive_read_new()) != NULL);\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_compress(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));\n+\tassertEqualIntA(a, ARCHIVE_OK,\n+\t archive_read_open_memory(a, data, sizeof(data)));\n+\n+\tassertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));\n+\n+\t/* Verify that the format detection worked. */\n+\tassertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);\n+\tassertEqualString(archive_filter_name(a, 0), \"compress (.Z)\");\n+\tassertEqualInt(archive_format(a), ARCHIVE_FORMAT_EMPTY);\n+\n+\tassertEqualInt(ARCHIVE_OK, archive_read_close(a));\n+\tassertEqualInt(ARCHIVE_OK, archive_read_free(a));\n+}\n+\n+\n+DEFINE_TEST(test_read_filter_compress_invalid)\n+{\n+\tconst char data[] = {0x1f, 0x9d, 0x11};\n+\tstruct archive *a;\n+\n+\tassert((a = archive_read_new()) != NULL);\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_compress(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));\n+\tassertEqualIntA(a, ARCHIVE_FATAL,\n+\t archive_read_open_memory(a, data, sizeof(data)));\n+\n+\tassertEqualInt(ARCHIVE_OK, archive_read_close(a));\n+\tassertEqualInt(ARCHIVE_OK, archive_read_free(a));\n+}\nIndex: libarchive-3.1.2/Makefile.am\n===================================================================\n--- libarchive-3.1.2.orig/Makefile.am\n+++ libarchive-3.1.2/Makefile.am\n@@ -364,6 +364,7 @@ libarchive_test_SOURCES=\t\t\t\t\t\\\n \tlibarchive/test/test_read_disk_entry_from_file.c\t\\\n \tlibarchive/test/test_read_extract.c\t\t\t\\\n \tlibarchive/test/test_read_file_nonexistent.c\t\t\\\n+\tlibarchive/test/test_read_filter_compress.c\t\t\\\n \tlibarchive/test/test_read_filter_grzip.c\t\t\\\n \tlibarchive/test/test_read_filter_lrzip.c\t\t\\\n \tlibarchive/test/test_read_filter_lzop.c\t\t\t\\\n@@ -427,6 +428,7 @@ libarchive_test_SOURCES=\t\t\t\t\t\\\n \tlibarchive/test/test_read_format_zip_comment_stored.c\t\\\n \tlibarchive/test/test_read_format_zip_filename.c\t\t\\\n \tlibarchive/test/test_read_format_zip_mac_metadata.c\t\\\n+\tlibarchive/test/test_read_format_zip_msdos.c\t\t\\\n \tlibarchive/test/test_read_format_zip_sfx.c\t\t\\\n \tlibarchive/test/test_read_large.c\t\t\t\\\n \tlibarchive/test/test_read_pax_truncated.c\t\t\\\nIndex: libarchive-3.1.2/libarchive/test/CMakeLists.txt\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/test/CMakeLists.txt\n+++ libarchive-3.1.2/libarchive/test/CMakeLists.txt\n@@ -79,6 +79,7 @@ IF(ENABLE_TEST)\n test_read_disk_entry_from_file.c\n test_read_extract.c\n test_read_file_nonexistent.c\n+ test_read_filter_compress.c\n test_read_filter_grzip.c\n test_read_filter_lrzip.c\n test_read_filter_lzop.c\n@@ -142,6 +143,7 @@ IF(ENABLE_TEST)\n test_read_format_zip_comment_stored.c\n test_read_format_zip_filename.c\n test_read_format_zip_mac_metadata.c\n+ test_read_format_zip_msdos.c\n test_read_format_zip_sfx.c\n test_read_large.c\n test_read_pax_truncated.c\n@@ -154,6 +156,7 @@ IF(ENABLE_TEST)\n test_tar_large.c\n test_ustar_filenames.c\n test_ustar_filename_encoding.c\n+ test_warn_missing_hardlink_target.c\n test_write_disk.c\n test_write_disk_appledouble.c\n test_write_disk_failures.c\nIndex: libarchive-3.1.2/libarchive/test/test_read_format_zip_msdos.c\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_format_zip_msdos.c\n@@ -0,0 +1,63 @@\n+/*-\n+ * Copyright (c) 2003-2007 Tim Kientzle\n+ * Copyright (c) 2011 Michihiro NAKAJIMA\n+\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "commit f0b1dbbc325a2d922015eee402b72edd422cb9ea\nAuthor: Tim Kientzle \nDate: Sat Aug 8 21:47:43 2015 -0700\n\n Issue 547: problems with compress bidder\n \n The code previously was not very careful about verifying the\n compression parameters. This led to cases where it failed to\n reject invalid compressed data at the beginning. The invalid\n left shift was one symptom of this.\n \n The code is now more careful: It verifies that the compression\n parameter byte exists and verifies that the maximum code size\n is <= 16 bits.\n \n This also includes some new tests to verify that truncated or\n otherwise invalid compressed data is rejected.\n\nIndex: libarchive-3.1.2/libarchive/archive_read_support_filter_compress.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_read_support_filter_compress.c\n+++ libarchive-3.1.2/libarchive/archive_read_support_filter_compress.c\n@@ -185,19 +185,22 @@ compress_bidder_bid(struct archive_read_\n \n \t(void)self; /* UNUSED */\n \n-\tbuffer = __archive_read_filter_ahead(filter, 2, &avail);\n+\t/* Shortest valid compress file is 3 bytes. */\n+\tbuffer = __archive_read_filter_ahead(filter, 3, &avail);\n \n \tif (buffer == NULL)\n \t\treturn (0);\n \n \tbits_checked = 0;\n+\t/* First two bytes are the magic value */\n \tif (buffer[0] != 0x1F || buffer[1] != 0x9D)\n \t\treturn (0);\n-\tbits_checked += 16;\n-\n-\t/*\n-\t * TODO: Verify more.\n-\t */\n+\t/* Third byte holds compression parameters. */\n+\tif (buffer[2] & 0x20) /* Reserved bit, must be zero. */\n+\t\treturn (0);\n+\tif (buffer[2] & 0x40) /* Reserved bit, must be zero. */\n+\t\treturn (0);\n+\tbits_checked += 18;\n \n \treturn (bits_checked);\n }\n@@ -239,7 +242,13 @@ compress_bidder_init(struct archive_read\n \t(void)getbits(self, 8); /* Skip first signature byte. */\n \t(void)getbits(self, 8); /* Skip second signature byte. */\n \n+\t/* Get compression parameters. */\n \tcode = getbits(self, 8);\n+\tif ((code & 0x1f) > 16) {\n+\t\tarchive_set_error(&self->archive->archive, -1,\n+\t\t \"Invalid compressed data\");\n+\t\treturn (ARCHIVE_FATAL);\n+\t}\n \tstate->maxcode_bits = code & 0x1f;\n \tstate->maxcode = (1 << state->maxcode_bits);\n \tstate->use_reset_code = code & 0x80;\nIndex: libarchive-3.1.2/libarchive/test/test_read_filter_compress.c\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_filter_compress.c\n@@ -0,0 +1,80 @@\n+/*-\n+ * Copyright (c) 2003-2008 Tim Kientzle\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ * 1. Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in the\n+ * documentation and/or other materials provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR\n+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,\n+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+#include \"test.h\"\n+\n+DEFINE_TEST(test_read_filter_compress_truncated)\n+{\n+\tconst char data[] = {0x1f, 0x9d};\n+\tstruct archive *a;\n+\n+\tassert((a = archive_read_new()) != NULL);\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_compress(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));\n+\tassertEqualIntA(a, ARCHIVE_FATAL,\n+\t archive_read_open_memory(a, data, sizeof(data)));\n+\n+\tassertEqualInt(ARCHIVE_OK, archive_read_close(a));\n+\tassertEqualInt(ARCHIVE_OK, archive_read_free(a));\n+}\n+\n+\n+DEFINE_TEST(test_read_filter_compress_empty2)\n+{\n+\tconst char data[] = {0x1f, 0x9d, 0x10};\n+\tstruct archive *a;\n+\tstruct archive_entry *ae;\n+\n+\tassert((a = archive_read_new()) != NULL);\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_compress(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));\n+\tassertEqualIntA(a, ARCHIVE_OK,\n+\t archive_read_open_memory(a, data, sizeof(data)));\n+\n+\tassertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));\n+\n+\t/* Verify that the format detection worked. */\n+\tassertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);\n+\tassertEqualString(archive_filter_name(a, 0), \"compress (.Z)\");\n+\tassertEqualInt(archive_format(a), ARCHIVE_FORMAT_EMPTY);\n+\n+\tassertEqualInt(ARCHIVE_OK, archive_read_close(a));\n+\tassertEqualInt(ARCHIVE_OK, archive_read_free(a));\n+}\n+\n+\n+DEFINE_TEST(test_read_filter_compress_invalid)\n+{\n+\tconst char data[] = {0x1f, 0x9d, 0x11};\n+\tstruct archive *a;\n+\n+\tassert((a = archive_read_new()) != NULL);\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_compress(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));\n+\tassertEqualIntA(a, ARCHIVE_FATAL,\n+\t archive_read_open_memory(a, data, sizeof(data)));\n+\n+\tassertEqualInt(ARCHIVE_OK, archive_read_close(a));\n+\tassertEqualInt(ARCHIVE_OK, archive_read_free(a));\n+}\nIndex: libarchive-3.1.2/Makefile.am\n===================================================================\n--- libarchive-3.1.2.orig/Makefile.am\n+++ libarchive-3.1.2/Makefile.am\n@@ -364,6 +364,7 @@ libarchive_test_SOURCES=\t\t\t\t\t\\\n \tlibarchive/test/test_read_disk_entry_from_file.c\t\\\n \tlibarchive/test/test_read_extract.c\t\t\t\\\n \tlibarchive/test/test_read_file_nonexistent.c\t\t\\\n+\tlibarchive/test/test_read_filter_compress.c\t\t\\\n \tlibarchive/test/test_read_filter_grzip.c\t\t\\\n \tlibarchive/test/test_read_filter_lrzip.c\t\t\\\n \tlibarchive/test/test_read_filter_lzop.c\t\t\t\\\n@@ -427,6 +428,7 @@ libarchive_test_SOURCES=\t\t\t\t\t\\\n \tlibarchive/test/test_read_format_zip_comment_stored.c\t\\\n \tlibarchive/test/test_read_format_zip_filename.c\t\t\\\n \tlibarchive/test/test_read_format_zip_mac_metadata.c\t\\\n+\tlibarchive/test/test_read_format_zip_msdos.c\t\t\\\n \tlibarchive/test/test_read_format_zip_sfx.c\t\t\\\n \tlibarchive/test/test_read_large.c\t\t\t\\\n \tlibarchive/test/test_read_pax_truncated.c\t\t\\\nIndex: libarchive-3.1.2/libarchive/test/CMakeLists.txt\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/test/CMakeLists.txt\n+++ libarchive-3.1.2/libarchive/test/CMakeLists.txt\n@@ -79,6 +79,7 @@ IF(ENABLE_TEST)\n test_read_disk_entry_from_file.c\n test_read_extract.c\n test_read_file_nonexistent.c\n+ test_read_filter_compress.c\n test_read_filter_grzip.c\n test_read_filter_lrzip.c\n test_read_filter_lzop.c\n@@ -142,6 +143,7 @@ IF(ENABLE_TEST)\n test_read_format_zip_comment_stored.c\n test_read_format_zip_filename.c\n test_read_format_zip_mac_metadata.c\n+ test_read_format_zip_msdos.c\n test_read_format_zip_sfx.c\n test_read_large.c\n test_read_pax_truncated.c\n@@ -154,6 +156,7 @@ IF(ENABLE_TEST)\n test_tar_large.c\n test_ustar_filenames.c\n test_ustar_filename_encoding.c\n+ test_warn_missing_hardlink_target.c\n test_write_disk.c\n test_write_disk_appledouble.c\n test_write_disk_failures.c\nIndex: libarchive-3.1.2/libarchive/test/test_read_format_zip_msdos.c\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_format_zip_msdos.c\n@@ -0,0 +1,63 @@\n+/*-\n+ * Copyright (c) 2003-2007 Tim Kientzle\n+ * Copyright (c) 2011 Michihiro NAKAJIMA\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ * 1. Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in the\n+ * documentation and/or other materials provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR\n+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,\n+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+#include \"test.h\"\n+\n+DEFINE_TEST(test_read_format_zip_msdos)\n+{\n+\tconst char *refname = \"test_read_format_zip_msdos.zip\";\n+\tstruct archive *a;\n+\tstruct archive_entry *ae;\n+\n+\textract_reference_file(refname);\n+\n+\t/* Verify with seeking reader. */\n+\tassert((a = archive_read_new()) != NULL);\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 17));\n+\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));\n+\tassertEqualString(\"a/\", archive_entry_pathname(ae));\n+\tassertEqualInt(AE_IFDIR | 0775, archive_entry_mode(ae));\n+\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));\n+\tassertEqualString(\"a/gru\\xCC\\x88n.png\", archive_entry_pathname(ae));\n+\tassertEqualInt(AE_IFREG | 0664, archive_entry_mode(ae));\n+\n+\tassertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));\n+\tassertEqualInt(ARCHIVE_OK, archive_read_free(a));\n+\t\n+\t/* Verify with streaming reader. */\n+#if 0\n+\tp = slurpfile(&s, refname);\n+\tassert((a = archive_read_new()) != NULL);\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));\n+\tassertEqualIntA(a, ARCHIVE_OK, read_open_memory(a, p, s, 31));\n+\tverify_basic(a, 0);\n+#endif\n+}\nIndex: libarchive-3.1.2/libarchive/test/test_read_format_zip_msdos.zip.uu\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_format_zip_msdos.zip.uu\n@@ -0,0 +1,9 @@\n+begin 644 test_read_format_zip_msdos.zip\n+M4$L#!!0``````&9A3D,````````````````\"````82]02P,$\"@``````M)QO\n+M/-&'5C4&````!@````P```!A+V=R=\n\nIndex: support-files/my-medium.cnf.sh\n===================================================================\n--- support-files/my-medium.cnf.sh.orig\n+++ support-files/my-medium.cnf.sh\n@@ -154,3 +154,46 @@ write_buffer = 2M\n \n [mysqlhotcopy]\n interactive-timeout\n+\n+[mysqld_multi]\n+mysqld = /usr/bin/mysqld_safe\n+mysqladmin = /usr/bin/mysqladmin\n+log = /var/log/mysqld_multi.log\n+# user = multi_admin\n+# password = secret\n+\n+# If you want to use mysqld_multi uncomment 1 or more mysqld sections\n+# below or add your own ones.\n+\n+# WARNING\n+# --------\n+# If you uncomment mysqld1 than make absolutely sure, that database mysql,\n+# configured above, is not started. This may result in corrupted data!\n+# [mysqld1]\n+# port = @MYSQL_TCP_PORT@\n+# datadir = /var/lib/mysql\n+# pid-file = /var/lib/mysql/mysqld.pid\n+# socket = /var/lib/mysql/mysql.sock\n+# user = mysql\n+\n+# [mysqld2]\n+# port = 3307\n+# datadir = /var/lib/mysql-databases/mysqld2\n+# pid-file = /var/lib/mysql-databases/mysqld2/mysql.pid\n+# socket = /var/lib/mysql-databases/mysqld2/mysql.sock\n+# user = mysql\n+\n+# [mysqld3]\n+# port = 3308\n+# datadir = /var/lib/mysql-databases/mysqld3\n+# pid-file = /var/lib/mysql-databases/mysqld3/mysql.pid\n+# socket = /var/lib/mysql-databases/mysqld3/mysql.sock\n+# user = mysql\n+\n+# [mysqld6]\n+# port = 3309\n+# datadir = /var/lib/mysql-databases/mysqld6\n+# pid-file = /var/lib/mysql-databases/mysqld6/mysql.pid\n+# socket = /var/lib/mysql-databases/mysqld6/mysql.sock\n+# user = mysql\n+\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "PATCH-P0-FEATURE-SUSE: Add multi configuration\n\nThis patch adds example of how to setup multiple running MySQL servers. It is\nby default commented out, but it can be used as an example and help people\nstart with new configuration.\n\nMaintainer: Michal Hrusecky \n\nIndex: support-files/my-medium.cnf.sh\n===================================================================\n--- support-files/my-medium.cnf.sh.orig\n+++ support-files/my-medium.cnf.sh\n@@ -154,3 +154,46 @@ write_buffer = 2M\n \n [mysqlhotcopy]\n interactive-timeout\n+\n+[mysqld_multi]\n+mysqld = /usr/bin/mysqld_safe\n+mysqladmin = /usr/bin/mysqladmin\n+log = /var/log/mysqld_multi.log\n+# user = multi_admin\n+# password = secret\n+\n+# If you want to use mysqld_multi uncomment 1 or more mysqld sections\n+# below or add your own ones.\n+\n+# WARNING\n+# --------\n+# If you uncomment mysqld1 than make absolutely sure, that database mysql,\n+# configured above, is not started. This may result in corrupted data!\n+# [mysqld1]\n+# port = @MYSQL_TCP_PORT@\n+# datadir = /var/lib/mysql\n+# pid-file = /var/lib/mysql/mysqld.pid\n+# socket = /var/lib/mysql/mysql.sock\n+# user = mysql\n+\n+# [mysqld2]\n+# port = 3307\n+# datadir = /var/lib/mysql-databases/mysqld2\n+# pid-file = /var/lib/mysql-databases/mysqld2/mysql.pid\n+# socket = /var/lib/mysql-databases/mysqld2/mysql.sock\n+# user = mysql\n+\n+# [mysqld3]\n+# port = 3308\n+# datadir = /var/lib/mysql-databases/mysqld3\n+# pid-file = /var/lib/mysql-databases/mysqld3/mysql.pid\n+# socket = /var/lib/mysql-databases/mysqld3/mysql.sock\n+# user = mysql\n+\n+# [mysqld6]\n+# port = 3309\n+# datadir = /var/lib/mysql-databases/mysqld6\n+# pid-file = /var/lib/mysql-databases/mysqld6/mysql.pid\n+# socket = /var/lib/mysql-databases/mysqld6/mysql.sock\n+# user = mysql\n+"}], "metadata": {"id": "mariadb-499-mysql-community-server-5.1.45-", "cve_id": "CVE-2012-0113", "package": "mariadb", "tier": "identical", "has_source_context": false, "license": "GPL-2.0-only"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-4658\n\nxpointer.c in libxml2 before 2.9.5 (as used in Apple iOS before 10, OS X before 10.12, tvOS before 10, and watchOS before 3, and other products) does not forbid namespace nodes in XPointer ranges, which allows remote attackers to execute arbitrary code or cause a denial of service (use-after-free and memory corruption) via a crafted XML document.\n\n## Package\nlibxml2\n\n## Files to modify\n- xpointer.c\n\n## Upstream Fix\n```diff\nFrom c1d1f7121194036608bf555f08d3062a36fd344b Mon Sep 17 00:00:00 2001\nFrom: Nick Wellnhofer \nDate: Tue, 28 Jun 2016 18:34:52 +0200\nSubject: [PATCH] Disallow namespace nodes in XPointer ranges\n\nNamespace nodes must be copied to avoid use-after-free errors.\nBut they don't necessarily have a physical representation in a\ndocument, so simply disallow them in XPointer ranges.\n\nFound with afl-fuzz.\n\nFixes CVE-2016-4658.\n---\n xpointer.c | 149 ++++++++++++++++++++---------------------------------\n 1 file changed, 56 insertions(+), 93 deletions(-)\n\ndiff --git a/xpointer.c b/xpointer.c\nindex a7b03fbdae..694d120e2e 100644\n--- a/xpointer.c\n+++ b/xpointer.c\n@@ -319,6 +319,45 @@ xmlXPtrRangesEqual(xmlXPathObjectPtr range1, xmlXPathObjectPtr range2) {\n return(1);\n }\n \n+/**\n+ * xmlXPtrNewRangeInternal:\n+ * @start: the starting node\n+ * @startindex: the start index\n+ * @end: the ending point\n+ * @endindex: the ending index\n+ *\n+ * Internal function to create a new xmlXPathObjectPtr of type range\n+ *\n+ * Returns the newly created object.\n+ */\n+static xmlXPathObjectPtr\n+xmlXPtrNewRangeInternal(xmlNodePtr start, int startindex,\n+ xmlNodePtr end, int endindex) {\n+ xmlXPathObjectPtr ret;\n+\n+ /*\n+ * Namespace nodes must be copied (see xmlXPathNodeSetDupNs).\n+ * Disallow them for now.\n+ */\n+ if ((start != NULL) && (start->type == XML_NAMESPACE_DECL))\n+\treturn(NULL);\n+ if ((end != NULL) && (end->type == XML_NAMESPACE_DECL))\n+\treturn(NULL);\n+\n+ ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n+ if (ret == NULL) {\n+ xmlXPtrErrMemory(\"allocating range\");\n+\treturn(NULL);\n+ }\n+ memset(ret, 0, sizeof(xmlXPathObject));\n+ ret->type = XPATH_RANGE;\n+ ret->user = start;\n+ ret->index = startindex;\n+ ret->user2 = end;\n+ ret->index2 = endindex;\n+ return(ret);\n+}\n+\n /**\n * xmlXPtrNewRange:\n * @start: the starting node\n@@ -344,17 +383,7 @@ xmlXPtrNewRange(xmlNodePtr start, int startindex,\n if (endindex < 0)\n \treturn(NULL);\n \n- ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n- if (ret == NULL) {\n- xmlXPtrErrMemory(\"allocating range\");\n-\treturn(NULL);\n- }\n- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));\n- ret->type = XPATH_RANGE;\n- ret->user = start;\n- ret->index = startindex;\n- ret->user2 = end;\n- ret->index2 = endindex;\n+ ret = xmlXPtrNewRangeInternal(start, startindex, end, endindex);\n xmlXPtrRangeCheckOrder(ret);\n return(ret);\n }\n@@ -381,17 +410,8 @@ xmlXPtrNewRangePoints(xmlXPathObjectPtr start, xmlXPathObjectPtr end) {\n if (end->type != XPATH_POINT)\n \treturn(NULL);\n \n- ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n- if (ret == NULL) {\n- xmlXPtrErrMemory(\"allocating range\");\n-\treturn(NULL);\n- }\n- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));\n- ret->type = XPATH_RANGE;\n- ret->user = start->user;\n- ret->index = start->index;\n- ret->user2 = end->user;\n- ret->index2 = end->index;\n+ ret = xmlXPtrNewRangeInternal(start->user, start->index, end->user,\n+ end->index);\n xmlXPtrRangeCheckOrder(ret);\n return(ret);\n }\n@@ -416,17 +436,7 @@ xmlXPtrNewRangePointNode(xmlXPathObjectPtr start, xmlNodePtr end) {\n if (start->type != XPATH_POINT)\n \treturn(NULL);\n \n- ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n- if (ret == NULL) {\n- xmlXPtrErrMemory(\"allocating range\");\n-\treturn(NULL);\n- }\n- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));\n- ret->type = XPATH_RANGE;\n- ret->user = start->user;\n- ret->index = start->index;\n- ret->user2 = end;\n- ret->index2 = -1;\n+ ret = xmlXPtrNewRangeInternal(start->user, start->index, end, -1);\n xmlXPtrRangeCheckOrder(ret);\n return(ret);\n }\n@@ -453,17 +463,7 @@ xmlXPtrNewRangeNodePoint(xmlNodePtr start, xmlXPathObjectPtr end) {\n if (end->type != XPATH_POINT)\n \treturn(NULL);\n \n- ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n- if (ret == NULL) {\n- xmlXPtrErrMemory(\"allocating range\");\n-\treturn(NULL);\n- }\n- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));\n- ret->type = XPATH_RANGE;\n- ret->user = start;\n- ret->index = -1;\n- ret->user2 = end->user;\n- ret->index2 = end->index;\n+ ret = xmlXPtrNewRangeInternal(start, -1, end->user, end->index);\n xmlXPtrRangeCheckOrder(ret);\n return(ret);\n }\n@@ -486,17 +486,7 @@ xmlXPtrNewRangeNodes(xmlNodePtr start, xmlNodePtr end) {\n if (end == NULL)\n \treturn(NULL);\n \n- ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n- if (ret == NULL) {\n- xmlXPtrErrMemory(\"allocating range\");\n-\treturn(NULL);\n- }\n- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));\n- ret->type = XPATH_RANGE;\n- ret->user = start;\n- ret->index = -1;\n- ret->user2 = end;\n- ret->index2 = -1;\n+ ret = xmlXPtrNewRangeInternal(start, -1, end, -1);\n xmlXPtrRangeCheckOrder(ret);\n return(ret);\n }\n@@ -516,17 +506,7 @@ xmlXPtrNewCollapsedRange(xmlNodePtr start) {\n if (start == NULL)\n \treturn(NULL);\n \n- ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n- if (ret == NULL) {\n- xmlXPtrErrMemory(\"allocating range\");\n-\treturn(NULL);\n- }\n- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));\n- ret->type = XPATH_RANGE;\n- ret->user = start;\n- ret->index = -1;\n- ret->user2 = NULL;\n- ret->index2 = -1;\n+ ret = xmlXPtrNewRangeInternal(start, -1, NULL, -1);\n return(ret);\n }\n \n@@ -541,6 +521,8 @@ xmlXPtrNewCollapsedRange(xmlNodePtr start) {\n */\n xmlXPathObjectPtr\n xmlXPtrNewRangeNodeObject(xmlNodePtr start, xmlXPathObjectPtr end) {\n+ xmlNodePtr endNode;\n+ int endIndex;\n xmlXPathObjectPtr ret;\n \n if (start == NULL)\n@@ -549,7 +531,12 @@ xmlXPtrNewRangeNodeObject(xmlNodePtr start, xmlXPathObjectPtr end) {\n \treturn(NULL);\n switch (end->type) {\n \tcase XPATH_POINT:\n+\t endNode = end->user;\n+\t endIndex = end->index;\n+\t break;\n \tcase XPATH_RANGE:\n+\t endNode = end->user2;\n+\t endIndex = end->index2;\n \t break;\n \tcase XPATH_NODESET:\n \t /*\n@@ -557,39 +544,15 @@ xmlXPtrNewRangeNodeObject(xmlNodePtr start, xmlXPathObjectPtr end) {\n \t */\n \t if (end->nodesetval->nodeNr <= 0)\n \t\treturn(NULL);\n+\t endNode = end->nodesetval->nodeTab[end->nodesetval->nodeNr - 1];\n+\t endIndex = -1;\n \t break;\n \tdefault:\n \t /* TODO */\n \t return(NULL);\n }\n \n- ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n- if (ret == NULL) {\n- xmlXPtrErrMemory(\"allocating range\");\n-\treturn(NULL);\n- }\n- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));\n- ret->type = XPATH_RANGE;\n- ret->user = start;\n- ret->index = -1;\n- switch (end->type) {\n-\tcase XPATH_POINT:\n-\t ret->user2 = end->user;\n-\t ret->index2 = end->index;\n-\t break;\n-\tcase XPATH_RANGE:\n-\t ret->user2 = end->user2;\n-\t ret->index2 = end->index2;\n-\t break;\n-\tcase XPATH_NODESET: {\n-\t ret->user2 = end->nodesetval->nodeTab[end->nodesetval->nodeNr - 1];\n-\t ret->index2 = -1;\n-\t break;\n-\t}\n-\tdefault:\n-\t STRANGE\n-\t return(NULL);\n- }\n+ ret = xmlXPtrNewRangeInternal(start, -1, endNode, endIndex);\n xmlXPtrRangeCheckOrder(ret);\n return(ret);\n }\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From c1d1f7121194036608bf555f08d3062a36fd344b Mon Sep 17 00:00:00 2001\nFrom: Nick Wellnhofer \nDate: Tue, 28 Jun 2016 18:34:52 +0200\nSubject: [PATCH 1/5] Disallow namespace nodes in XPointer ranges\n\nNamespace nodes must be copied to avoid use-after-free errors.\nBut they don't necessarily have a physical representation in a\ndocument, so simply disallow them in XPointer ranges.\n\nFound with afl-fuzz.\n\nFixes CVE-2016-4658.\n---\n xpointer.c | 149 +++++++++++++++++++++++--------------------------------------\n 1 file changed, 56 insertions(+), 93 deletions(-)\n\ndiff --git a/xpointer.c b/xpointer.c\nindex a7b03fb..694d120 100644\n--- a/xpointer.c\n+++ b/xpointer.c\n@@ -320,6 +320,45 @@ xmlXPtrRangesEqual(xmlXPathObjectPtr range1, xmlXPathObjectPtr range2) {\n }\n \n /**\n+ * xmlXPtrNewRangeInternal:\n+ * @start: the starting node\n+ * @startindex: the start index\n+ * @end: the ending point\n+ * @endindex: the ending index\n+ *\n+ * Internal function to create a new xmlXPathObjectPtr of type range\n+ *\n+ * Returns the newly created object.\n+ */\n+static xmlXPathObjectPtr\n+xmlXPtrNewRangeInternal(xmlNodePtr start, int startindex,\n+ xmlNodePtr end, int endindex) {\n+ xmlXPathObjectPtr ret;\n+\n+ /*\n+ * Namespace nodes must be copied (see xmlXPathNodeSetDupNs).\n+ * Disallow them for now.\n+ */\n+ if ((start != NULL) && (start->type == XML_NAMESPACE_DECL))\n+\treturn(NULL);\n+ if ((end != NULL) && (end->type == XML_NAMESPACE_DECL))\n+\treturn(NULL);\n+\n+ ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n+ if (ret == NULL) {\n+ xmlXPtrErrMemory(\"allocating range\");\n+\treturn(NULL);\n+ }\n+ memset(ret, 0, sizeof(xmlXPathObject));\n+ ret->type = XPATH_RANGE;\n+ ret->user = start;\n+ ret->index = startindex;\n+ ret->user2 = end;\n+ ret->index2 = endindex;\n+ return(ret);\n+}\n+\n+/**\n * xmlXPtrNewRange:\n * @start: the starting node\n * @startindex: the start index\n@@ -344,17 +383,7 @@ xmlXPtrNewRange(xmlNodePtr start, int startindex,\n if (endindex < 0)\n \treturn(NULL);\n \n- ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n- if (ret == NULL) {\n- xmlXPtrErrMemory(\"allocating range\");\n-\treturn(NULL);\n- }\n- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));\n- ret->type = XPATH_RANGE;\n- ret->user = start;\n- ret->index = startindex;\n- ret->user2 = end;\n- ret->index2 = endindex;\n+ ret = xmlXPtrNewRangeInternal(start, startindex, end, endindex);\n xmlXPtrRangeCheckOrder(ret);\n return(ret);\n }\n@@ -381,17 +410,8 @@ xmlXPtrNewRangePoints(xmlXPathObjectPtr start, xmlXPathObjectPtr end) {\n if (end->type != XPATH_POINT)\n \treturn(NULL);\n \n- ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n- if (ret == NULL) {\n- xmlXPtrErrMemory(\"allocating range\");\n-\treturn(NULL);\n- }\n- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));\n- ret->type = XPATH_RANGE;\n- ret->user = start->user;\n- ret->index = start->index;\n- ret->user2 = end->user;\n- ret->index2 = end->index;\n+ ret = xmlXPtrNewRangeInternal(start->user, start->index, end->user,\n+ end->index);\n xmlXPtrRangeCheckOrder(ret);\n return(ret);\n }\n@@ -416,17 +436,7 @@ xmlXPtrNewRangePointNode(xmlXPathObjectPtr start, xmlNodePtr end) {\n if (start->type != XPATH_POINT)\n \treturn(NULL);\n \n- ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n- if (ret == NULL) {\n- xmlXPtrErrMemory(\"allocating range\");\n-\treturn(NULL);\n- }\n- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));\n- ret->type = XPATH_RANGE;\n- ret->user = start->user;\n- ret->index = start->index;\n- ret->user2 = end;\n- ret->index2 = -1;\n+ ret = xmlXPtrNewRangeInternal(start->user, start->index, end, -1);\n xmlXPtrRangeCheckOrder(ret);\n return(ret);\n }\n@@ -453,17 +463,7 @@ xmlXPtrNewRangeNodePoint(xmlNodePtr start, xmlXPathObjectPtr end) {\n if (end->type != XPATH_POINT)\n \treturn(NULL);\n \n- ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n- if (ret == NULL) {\n- xmlXPtrErrMemory(\"allocating range\");\n-\treturn(NULL);\n- }\n- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));\n- ret->type = XPATH_RANGE;\n- ret->user = start;\n- ret->index = -1;\n- ret->user2 = end->user;\n- ret->index2 = end->index;\n+ ret = xmlXPtrNewRangeInternal(start, -1, end->user, end->index);\n xmlXPtrRangeCheckOrder(ret);\n return(ret);\n }\n@@ -486,17 +486,7 @@ xmlXPtrNewRangeNodes(xmlNodePtr start, xmlNodePtr end) {\n if (end == NULL)\n \treturn(NULL);\n \n- ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n- if (ret == NULL) {\n- xmlXPtrErrMemory(\"allocating range\");\n-\treturn(NULL);\n- }\n- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));\n- ret->type = XPATH_RANGE;\n- ret->user = start;\n- ret->index = -1;\n- ret->user2 = end;\n- ret->index2 = -1;\n+ ret = xmlXPtrNewRangeInternal(start, -1, end, -1);\n xmlXPtrRangeCheckOrder(ret);\n return(ret);\n }\n@@ -516,17 +506,7 @@ xmlXPtrNewCollapsedRange(xmlNodePtr start) {\n if (start == NULL)\n \treturn(NULL);\n \n- ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n- if (ret == NULL) {\n- xmlXPtrErrMemory(\"allocating range\");\n-\treturn(NULL);\n- }\n- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));\n- ret->type = XPATH_RANGE;\n- ret->user = start;\n- ret->index = -1;\n- ret->user2 = NULL;\n- ret->index2 = -1;\n+ ret = xmlXPtrNewRangeInternal(start, -1, NULL, -1);\n return(ret);\n }\n \n@@ -541,6 +521,8 @@ xmlXPtrNewCollapsedRange(xmlNodePtr start) {\n */\n xmlXPathObjectPtr\n xmlXPtrNewRangeNodeObject(xmlNodePtr start, xmlXPathObjectPtr end) {\n+ xmlNodePtr endNode;\n+ int endIndex;\n xmlXPathObjectPtr ret;\n \n if (start == NULL)\n@@ -549,7 +531,12 @@ xmlXPtrNewRangeNodeObject(xmlNodePtr start, xmlXPathObjectPtr end) {\n \treturn(NULL);\n switch (end->type) {\n \tcase XPATH_POINT:\n+\t endNode = end->user;\n+\t endIndex = end->index;\n+\t break;\n \tcase XPATH_RANGE:\n+\t endNode = end->user2;\n+\t endIndex = end->index2;\n \t break;\n \tcase XPATH_NODESET:\n \t /*\n@@ -557,39 +544,15 @@ xmlXPtrNewRangeNodeObject(xmlNodePtr start, xmlXPathObjectPtr end) {\n \t */\n \t if (end->nodesetval->nodeNr <= 0)\n \t\treturn(NULL);\n+\t endNode = end->nodesetval->nodeTab[end->nodesetval->nodeNr - 1];\n+\t endIndex = -1;\n \t break;\n \tdefault:\n \t /* TODO */\n \t return(NULL);\n }\n \n- ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n- if (ret == NULL) {\n- xmlXPtrErrMemory(\"allocating range\");\n-\treturn(NULL);\n- }\n- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));\n- ret->type = XPATH_RANGE;\n- ret->user = start;\n- ret->index = -1;\n- switch (end->type) {\n-\tcase XPATH_POINT:\n-\t ret->user2 = end->user;\n-\t ret->index2 = end->index;\n-\t break;\n-\tcase XPATH_RANGE:\n-\t ret->user2 = end->user2;\n-\t ret->index2 = end->index2;\n-\t break;\n-\tcase XPATH_NODESET: {\n-\t ret->user2 = end->nodesetval->nodeTab[end->nodesetval->nodeNr - 1];\n-\t ret->index2 = -1;\n-\t break;\n-\t}\n-\tdefault:\n-\t STRANGE\n-\t return(NULL);\n- }\n+ ret = xmlXPtrNewRangeInternal(start, -1, endNode, endIndex);\n xmlXPtrRangeCheckOrder(ret);\n return(ret);\n }\n-- \n2.10.1"}], "metadata": {"id": "libxml2-5762-libxml2-2.9.4-CVE-2016-4658.pa", "cve_id": "CVE-2016-4658", "package": "libxml2", "upstream_enriched": true, "upstream_commit": "c1d1f7121194036608bf555f08d3062a36fd344b", "upstream_repo": "GNOME/libxml2", "tier": "adapted", "has_source_context": false, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1i/ssl/d1_srvr.c\n- openssl-1.0.1i.orig/ssl/s3_clnt.c\n- openssl-1.0.1i.orig/ssl/d1_srvr.c\n- openssl-1.0.1i/ssl/ssl.h\n- openssl-1.0.1i/ssl/s3_clnt.c\n\n## Target Source Code\n\n### doc/ssl/SSL_CTX_set_options.pod\n\n#### region() [lines 119-214]\n```c\nimplementations.\n\n=item SSL_OP_ALL\n\nAll of the above bug workarounds.\n\n=back\n\nIt is usually safe to use B to enable the bug workaround\noptions if compatibility with somewhat broken implementations is\ndesired.\n\nThe following B options are available:\n\n=over 4\n\n=item SSL_OP_TLS_ROLLBACK_BUG\n\nDisable version rollback attack detection.\n\nDuring the client key exchange, the client must send the same information\nabout acceptable SSL/TLS protocol levels as during the first hello. Some\nclients violate this rule by adapting to the server's answer. (Example:\nthe client sends a SSLv2 hello and accepts up to SSLv3.1=TLSv1, the server\nonly understands up to SSLv3. In this case the client must still use the\nsame SSLv3.1=TLSv1 announcement. Some clients step down to SSLv3 with respect\nto the server's answer and violate the version rollback protection.)\n\n=item SSL_OP_SINGLE_DH_USE\n\nAlways create a new key when using temporary/ephemeral DH parameters\n(see L).\nThis option must be used to prevent small subgroup attacks, when\nthe DH parameters were not generated using \"strong\" primes\n(e.g. when using DSA-parameters, see L).\nIf \"strong\" primes were used, it is not strictly necessary to generate\na new DH key during each handshake but it is also recommended.\nB should therefore be enabled whenever\ntemporary/ephemeral DH parameters are used.\n\n=item SSL_OP_EPHEMERAL_RSA\n\nAlways use ephemeral (temporary) RSA key when doing RSA operations\n(see L).\nAccording to the specifications this is only done, when a RSA key\ncan only be used for signature operations (namely under export ciphers\nwith restricted RSA keylength). By setting this option, ephemeral\nRSA keys are always used. This option breaks compatibility with the\nSSL/TLS specifications and may lead to interoperability problems with\nclients and should therefore never be used. Ciphers with EDH (ephemeral\nDiffie-Hellman) key exchange shou\n/* ... truncated ... */\n```\n\n### doc/ssl/SSL_CTX_set_tmp_rsa_callback.pod\n\n#### EDH() [lines 35-136]\n```c\nfor RSA-based strength-limited 'exportable' ciphersuites because a RSA key\nwith a keysize larger than 512 bits is installed.\n\nSSL_set_tmp_rsa_callback() sets the callback only for B.\n\nSSL_set_tmp_rsa() sets the key only for B.\n\nSSL_need_tmp_rsa() returns 1, if a temporary/ephemeral RSA key is needed,\nfor RSA-based strength-limited 'exportable' ciphersuites because a RSA key\nwith a keysize larger than 512 bits is installed.\n\nThese functions apply to SSL/TLS servers only.\n\n=head1 NOTES\n\nWhen using a cipher with RSA authentication, an ephemeral RSA key exchange\ncan take place. In this case the session data are negotiated using the\nephemeral/temporary RSA key and the RSA key supplied and certified\nby the certificate chain is only used for signing.\n\nUnder previous export restrictions, ciphers with RSA keys shorter (512 bits)\nthan the usual key length of 1024 bits were created. To use these ciphers\nwith RSA keys of usual length, an ephemeral key exchange must be performed,\nas the normal (certified) key cannot be directly used.\n\nUsing ephemeral RSA key exchange yields forward secrecy, as the connection\ncan only be decrypted, when the RSA key is known. By generating a temporary\nRSA key inside the server application that is lost when the application\nis left, it becomes impossible for an attacker to decrypt past sessions,\neven if he gets hold of the normal (certified) RSA key, as this key was\nused for signing only. The downside is that creating a RSA key is\ncomputationally expensive.\n\nAdditionally, the use of ephemeral RSA key exchange is only allowed in\nthe TLS standard, when the RSA key can be used for signing only, that is\nfor export ciphers. Using ephemeral RSA key exchange for other purposes\nviolates the standard and can break interoperability with clients.\nIt is therefore strongly recommended to not use ephemeral RSA key\nexchange and use EDH (Ephemeral Diffie-Hellman) key exchange instead\nin order to achieve forward secrecy (see\nL).\n\nOn OpenSSL servers ephemeral RSA key exchange is th\n/* ... truncated ... */\n```\n\n### ssl/d1_srvr.c\n\n#### dtls1_accept() [lines 142-846]\n```c\n\t\t\tssl_undefined_function,\n\t\t\tdtls1_get_server_method)\n\nint dtls1_accept(SSL *s)\n\t{\n\tBUF_MEM *buf;\n\tunsigned long Time=(unsigned long)time(NULL);\n\tvoid (*cb)(const SSL *ssl,int type,int val)=NULL;\n\tunsigned long alg_k;\n\tint ret= -1;\n\tint new_state,state,skip=0;\n\tint listen;\n#ifndef OPENSSL_NO_SCTP\n\tunsigned char sctpauthkey[64];\n\tchar labelbuffer[sizeof(DTLS1_SCTP_AUTH_LABEL)];\n#endif\n\n\tRAND_add(&Time,sizeof(Time),0);\n\tERR_clear_error();\n\tclear_sys_error();\n\n\tif (s->info_callback != NULL)\n\t\tcb=s->info_callback;\n\telse if (s->ctx->info_callback != NULL)\n\t\tcb=s->ctx->info_callback;\n\t\n\tlisten = s->d1->listen;\n\n\t/* init things to blank */\n\ts->in_handshake++;\n\tif (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);\n\n\ts->d1->listen = listen;\n#ifndef OPENSSL_NO_SCTP\n\t/* Notify SCTP BIO socket to enter handshake\n\t * mode and prevent stream identifier other\n\t * than 0. Will be ignored if no SCTP is used.\n\t */\n\tBIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE, s->in_handshake, NULL);\n#endif\n/* ... 259 lines omitted ... */\n\t\t\telse\n\t\t\t\tskip=1;\n\n\t\t\ts->state=SSL3_ST_SW_KEY_EXCH_A;\n#endif\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\n\t\tcase SSL3_ST_SW_KEY_EXCH_A:\n\t\tcase SSL3_ST_SW_KEY_EXCH_B:\n\t\t\talg_k = s->s3->tmp.new_cipher->algorithm_mkey;\n\n\t\t\t/* clear this, it may get reset by\n\t\t\t * send_server_key_exchange */\n\t\t\tif ((s->options & SSL_OP_EPHEMERAL_RSA)\n#ifndef OPENSSL_NO_KRB5\n\t\t\t\t&& !(alg_k & SSL_kKRB5)\n#endif /* OPENSSL_NO_KRB5 */\n\t\t\t\t)\n\t\t\t\t/* option SSL_OP_EPHEMERAL_RSA sends temporary RSA key\n\t\t\t\t * even when forbidden by protocol specs\n\t\t\t\t * (handshake may fail as clients are not required to\n\t\t\t\t * be able to handle this) */\n\t\t\t\ts->s3->tmp.use_rsa_tmp=1;\n\t\t\telse\n\t\t\t\ts->s3->tmp.use_rsa_tmp=0;\n\n\t\t\t/* only send if a DH key exchange or\n\t\t\t * RSA but we have a sign only certificate */\n\t\t\tif (s->s3->tmp.use_rsa_tmp\n\t\t\t/* PSK: send ServerKeyExchange if PSK identity\n\t\t\t * hint if provided */\n#ifndef OPENSSL_NO_PSK\n\t\t\t || ((alg_k & SSL_kPSK) && s->ctx->psk_identity_hint)\n#endif\n\t\t\t || (alg_k & (SSL_kEDH|SSL_kDHr|SSL_kDHd))\n\t\t\t || (alg_k & SSL_kEECDH)\n\t\t\t\n/* ... truncated ... */\n```\n\n### ssl/s3_clnt.c\n\n#### ssl3_get_key_exchange() [lines 1270-1877]\n```c\n\treturn(ret);\n\t}\n\nint ssl3_get_key_exchange(SSL *s)\n\t{\n#ifndef OPENSSL_NO_RSA\n\tunsigned char *q,md_buf[EVP_MAX_MD_SIZE*2];\n#endif\n\tEVP_MD_CTX md_ctx;\n\tunsigned char *param,*p;\n\tint al,i,j,param_len,ok;\n\tlong n,alg_k,alg_a;\n\tEVP_PKEY *pkey=NULL;\n\tconst EVP_MD *md = NULL;\n#ifndef OPENSSL_NO_RSA\n\tRSA *rsa=NULL;\n#endif\n#ifndef OPENSSL_NO_DH\n\tDH *dh=NULL;\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tEC_KEY *ecdh = NULL;\n\tBN_CTX *bn_ctx = NULL;\n\tEC_POINT *srvr_ecpoint = NULL;\n\tint curve_nid = 0;\n\tint encoded_pt_len = 0;\n#endif\n\n\t/* use same message size as in ssl3_get_certificate_request()\n\t * as ServerKeyExchange message may be skipped */\n\tn=s->method->ssl_get_message(s,\n\t\tSSL3_ST_CR_KEY_EXCH_A,\n\t\tSSL3_ST_CR_KEY_EXCH_B,\n\t\t-1,\n\t\ts->max_cert_list,\n\t\t&ok);\n\tif (!ok) return((int)n);\n\n\tif (s->s3->tmp.message_type != SSL3_MT_SERVER_KEY_EXCHANGE)\n\t\t{\n/* ... 186 lines omitted ... */\n\t\tif ((rsa=RSA_new()) == NULL)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE);\n\t\t\tgoto err;\n\t\t\t}\n\t\tn2s(p,i);\n\t\tparam_len=i+2;\n\t\tif (param_len > n)\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_MODULUS_LENGTH);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif (!(rsa->n=BN_bin2bn(p,i,rsa->n)))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\tp+=i;\n\n\t\tn2s(p,i);\n\t\tparam_len+=i+2;\n\t\tif (param_len > n)\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_E_LENGTH);\n/* ... 336 lines omitted ... */\n\tEVP_PKEY_free(pkey);\n#ifndef OPENSSL_NO_RSA\n\tif (rsa != NULL)\n\t\tRSA_free(rsa);\n#endif\n#ifndef OPENSSL_NO_DH\n\tif (dh != NULL)\n\t\tDH_free(dh);\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tBN_CTX_free(bn_ctx);\n\tEC_POINT_free(srvr_ecpoint);\n\tif (ecdh != NULL)\n\t\tEC_KEY_free(ecdh);\n#endif\n\tEVP_MD_CTX_cleanup(&md_ctx);\n\treturn(-1);\n\t}\n\nint ssl3_get_certificate_request(SSL *s)\n```\n\n### ssl/s3_srvr.c\n\n#### ssl3_accept() [lines 210-845]\n```c\n\t\t\tssl_undefined_function,\n\t\t\tssl3_get_server_method)\n\nint ssl3_accept(SSL *s)\n\t{\n\tBUF_MEM *buf;\n\tunsigned long alg_k,Time=(unsigned long)time(NULL);\n\tvoid (*cb)(const SSL *ssl,int type,int val)=NULL;\n\tint ret= -1;\n\tint new_state,state,skip=0;\n\n\tRAND_add(&Time,sizeof(Time),0);\n\tERR_clear_error();\n\tclear_sys_error();\n\n\tif (s->info_callback != NULL)\n\t\tcb=s->info_callback;\n\telse if (s->ctx->info_callback != NULL)\n\t\tcb=s->ctx->info_callback;\n\n\t/* init things to blank */\n\ts->in_handshake++;\n\tif (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);\n\n\tif (s->cert == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_ACCEPT,SSL_R_NO_CERTIFICATE_SET);\n\t\treturn(-1);\n\t\t}\n\n#ifndef OPENSSL_NO_HEARTBEATS\n\t/* If we're awaiting a HeartbeatResponse, pretend we\n\t * already got and don't await it anymore, because\n\t * Heartbeats don't make sense during handshakes anyway.\n\t */\n\tif (s->tlsext_hb_pending)\n\t\t{\n\t\ts->tlsext_hb_pending = 0;\n\t\ts->tlsext_hb_seq++;\n\t\t}\n/* ... 182 lines omitted ... */\n\t\t\telse\n\t\t\t\tskip=1;\n\n\t\t\ts->state=SSL3_ST_SW_KEY_EXCH_A;\n#endif\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\n\t\tcase SSL3_ST_SW_KEY_EXCH_A:\n\t\tcase SSL3_ST_SW_KEY_EXCH_B:\n\t\t\talg_k = s->s3->tmp.new_cipher->algorithm_mkey;\n\n\t\t\t/* clear this, it may get reset by\n\t\t\t * send_server_key_exchange */\n\t\t\tif ((s->options & SSL_OP_EPHEMERAL_RSA)\n#ifndef OPENSSL_NO_KRB5\n\t\t\t\t&& !(alg_k & SSL_kKRB5)\n#endif /* OPENSSL_NO_KRB5 */\n\t\t\t\t)\n\t\t\t\t/* option SSL_OP_EPHEMERAL_RSA sends temporary RSA key\n\t\t\t\t * even when forbidden by protocol specs\n\t\t\t\t * (handshake may fail as clients are not required to\n\t\t\t\t * be able to handle this) */\n\t\t\t\ts->s3->tmp.use_rsa_tmp=1;\n\t\t\telse\n\t\t\t\ts->s3->tmp.use_rsa_tmp=0;\n\n\n\t\t\t/* only send if a DH key exchange, fortezza or\n\t\t\t * RSA but we have a sign only certificate\n\t\t\t *\n\t\t\t * PSK: may send PSK identity hints\n\t\t\t *\n\t\t\t * For ECC ciphersuites, we send a serverKeyExchange\n\t\t\t * message only if the cipher suite is either\n\t\t\t * ECDH-anon or ECDHE. In other cases, the\n\t\t\t * server certificate contains the server's\n\t\t\t * public key for key exchange.\n\t\t\t */\n\t\t\tif (s->s3->tmp.use_rsa_tmp\n/* ... 354 lines omitted ...\n/* ... truncated ... */\n```\n\n### ssl/ssl.h\n\n#### region() [lines 561-650]\n```c\n#define SSL_OP_TLS_D5_BUG\t\t\t\t0x00000100L\n#define SSL_OP_TLS_BLOCK_PADDING_BUG\t\t\t0x00000200L\n\n/* Hasn't done anything since OpenSSL 0.9.7h, retained for compatibility */\n#define SSL_OP_MSIE_SSLV2_RSA_PADDING\t\t\t0x0\n/* Refers to ancient SSLREF and SSLv2, retained for compatibility */\n#define SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG\t\t0x0\n\n/* Disable SSL 3.0/TLS 1.0 CBC vulnerability workaround that was added\n * in OpenSSL 0.9.6d. Usually (depending on the application protocol)\n * the workaround is not needed. Unfortunately some broken SSL/TLS\n * implementations cannot handle it at all, which is why we include\n * it in SSL_OP_ALL. */\n#define SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS 0x00000800L /* added in 0.9.6e */\n\n/* SSL_OP_ALL: various bug workarounds that should be rather harmless.\n * This used to be 0x000FFFFFL before 0.9.7. */\n#define SSL_OP_ALL\t\t\t\t\t0x80000BFFL\n\n/* DTLS options */\n#define SSL_OP_NO_QUERY_MTU 0x00001000L\n/* Turn on Cookie Exchange (on relevant for servers) */\n#define SSL_OP_COOKIE_EXCHANGE 0x00002000L\n/* Don't use RFC4507 ticket extension */\n#define SSL_OP_NO_TICKET\t 0x00004000L\n/* Use Cisco's \"speshul\" version of DTLS_BAD_VER (as client) */\n#define SSL_OP_CISCO_ANYCONNECT\t\t 0x00008000L\n\n/* As server, disallow session resumption on renegotiation */\n#define SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION\t0x00010000L\n/* Don't use compression even if supported */\n#define SSL_OP_NO_COMPRESSION\t\t\t\t0x00020000L\n/* Permit unsafe legacy renegotiation */\n#define SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION\t0x00040000L\n/* If set, always create a new key when using tmp_ecdh parameters */\n#define SSL_OP_SINGLE_ECDH_USE\t\t\t\t0x00080000L\n/* If set, always create a new key when using tmp_dh parameters */\n#define SSL_OP_SINGLE_DH_USE\t\t\t\t0x00100000L\n/* Set to always use the tmp_rsa key when doing RSA operations,\n * even when this violates protocol specs */\n#define SSL_OP_EPHEMERAL_RSA\t\t\t\t0x00200000L\n/* Set on servers to choose the cipher according to the server's\n * preferences */\n#define SSL_OP_CIP\n/* ... truncated ... */\n```\n\n\n## Upstream Fix\n```diff\ncommit 37580f43b5a39f5f4e920d17273fab9713d3a744\nAuthor: Dr. Stephen Henson \nDate: Thu Oct 23 17:09:57 2014 +0100\n\n Only allow ephemeral RSA keys in export ciphersuites.\n \n OpenSSL clients would tolerate temporary RSA keys in non-export\n ciphersuites. It also had an option SSL_OP_EPHEMERAL_RSA which\n enabled this server side. Remove both options as they are a\n protocol violation.\n \n Thanks to Karthikeyan Bhargavan for reporting this issue.\n (CVE-2015-0204)\n Reviewed-by: Matt Caswell \n Reviewed-by: Tim Hudson \n \n (cherry picked from commit 4b4c1fcc88aec8c9e001b0a0077d3cd4de1ed0e6)\n \n Conflicts:\n \tdoc/ssl/SSL_CTX_set_options.pod\n\nIndex: openssl-1.0.1i/doc/ssl/SSL_CTX_set_options.pod\n===================================================================\n--- openssl-1.0.1i.orig/doc/ssl/SSL_CTX_set_options.pod\t2015-01-08 13:44:59.674089192 +0100\n+++ openssl-1.0.1i/doc/ssl/SSL_CTX_set_options.pod\t2015-01-08 13:45:07.828184260 +0100\n@@ -158,15 +158,7 @@ temporary/ephemeral DH parameters are us\n \n =item SSL_OP_EPHEMERAL_RSA\n \n-Always use ephemeral (temporary) RSA key when doing RSA operations\n-(see L).\n-According to the specifications this is only done, when a RSA key\n-can only be used for signature operations (namely under export ciphers\n-with restricted RSA keylength). By setting this option, ephemeral\n-RSA keys are always used. This option breaks compatibility with the\n-SSL/TLS specifications and may lead to interoperability problems with\n-clients and should therefore never be used. Ciphers with EDH (ephemeral\n-Diffie-Hellman) key exchange should be used instead.\n+This option is no longer implemented and is treated as no op.\n \n =item SSL_OP_CIPHER_SERVER_PREFERENCE\n \nIndex: openssl-1.0.1i/doc/ssl/SSL_CTX_set_tmp_rsa_callback.pod\n===================================================================\n--- openssl-1.0.1i.orig/doc/ssl/SSL_CTX_set_tmp_rsa_callback.pod\t2015-01-08 13:44:59.674089192 +0100\n+++ openssl-1.0.1i/doc/ssl/SSL_CTX_set_tmp_rsa_callback.pod\t2015-01-08 13:45:07.829184272 +0100\n@@ -74,21 +74,14 @@ exchange and use EDH (Ephemeral Diffie-H\n in order to achieve forward secrecy (see\n L).\n \n-On OpenSSL servers ephemeral RSA key exchange is therefore disabled by default\n-and must be explicitly enabled using the SSL_OP_EPHEMERAL_RSA option of\n-L, violating the TLS/SSL\n-standard. When ephemeral RSA key exchange is required for export ciphers,\n-it will automatically be used without this option!\n-\n-An application may either directly specify the key or can supply the key via\n-a callback function. The callback approach has the advantage, that the\n-callback may generate the key only in case it is actually needed. As the\n-generation of a RSA key is however costly, it will lead to a significant\n-delay in the handshake procedure. Another advantage of the callback function\n-is that it can supply keys of different size (e.g. for SSL_OP_EPHEMERAL_RSA\n-usage) while the explicit setting of the key is only useful for key size of\n-512 bits to satisfy the export restricted ciphers and does give away key length\n-if a longer key would be allowed.\n+An application may either directly specify the key or can supply the key via a\n+callback function. The callback approach has the advantage, that the callback\n+may generate the key only in case it is actually needed. As the generation of a\n+RSA key is however costly, it will lead to a significant delay in the handshake\n+procedure. Another advantage of the callback function is that it can supply\n+keys of different size while the explicit setting of the key is only useful for\n+key size of 512 bits to satisfy the export restricted ciphers and does give\n+away key length if a longer key would be allowed.\n \n The B is called with the B needed and\n the B information. The B flag is set, when the\nIndex: openssl-1.0.1i/ssl/d1_srvr.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/d1_srvr.c\t2015-01-08 13:44:59.675089204 +0100\n+++ openssl-1.0.1i/ssl/d1_srvr.c\t2015-01-08 13:45:07.829184272 +0100\n@@ -450,24 +450,15 @@ int dtls1_accept(SSL *s)\n \t\tcase SSL3_ST_SW_KEY_EXCH_B:\n \t\t\talg_k = s->s3->tmp.new_cipher->algorithm_mkey;\n \n-\t\t\t/* clear this, it may get reset by\n-\t\t\t * send_server_key_exchange */\n-\t\t\tif ((s->options & SSL_OP_EPHEMERAL_RSA)\n-#ifndef OPENSSL_NO_KRB5\n-\t\t\t\t&& !(alg_k & SSL_kKRB5)\n-#endif /* OPENSSL_NO_KRB5 */\n-\t\t\t\t)\n-\t\t\t\t/* option SSL_OP_EPHEMERAL_RSA sends temporary RSA key\n-\t\t\t\t * even when forbidden by protocol specs\n-\t\t\t\t * (handshake may fail as clients are not required to\n-\t\t\t\t * be able to handle this) */\n-\t\t\t\ts->s3->tmp.use_rsa_tmp=1;\n-\t\t\telse\n-\t\t\t\ts->s3->tmp.use_rsa_tmp=0;\n+\t\t\t/*\n+\t\t\t * clear this, it may get reset by\n+\t\t\t * send_server_key_exchange\n+\t\t\t */\n+\t\t\ts->s3->tmp.use_rsa_tmp=0;\n \n \t\t\t/* only send if a DH key exchange or\n \t\t\t * RSA but we have a sign only certificate */\n-\t\t\tif (s->s3->tmp.use_rsa_tmp\n+\t\t\tif (0\n \t\t\t/* PSK: send ServerKeyExchange if PSK identity\n \t\t\t * hint if provided */\n #ifndef OPENSSL_NO_PSK\nIndex: openssl-1.0.1i/ssl/s3_clnt.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s3_clnt.c\t2015-01-08 13:44:59.675089204 +0100\n+++ openssl-1.0.1i/ssl/s3_clnt.c\t2015-01-08 13:45:07.830184283 +0100\n@@ -1505,6 +1505,13 @@ int ssl3_get_key_exchange(SSL *s)\n #ifndef OPENSSL_NO_RSA\n \tif (alg_k & SSL_kRSA)\n \t\t{\n+\t\t/* Temporary RSA keys only allowed in export ciphersuites */\n+\t\tif (!SSL_C_IS_EXPORT(s->s3->tmp.new_cipher))\n+\t\t\t{\n+\t\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n+\t\t\tSSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_UNEXPECTED_MESSAGE);\n+\t\t\tgoto f_err;\n+\t\t\t}\n \t\tif ((rsa=RSA_new()) == NULL)\n \t\t\t{\n \t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE);\nIndex: openssl-1.0.1i/ssl/s3_srvr.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s3_srvr.c\t2015-01-08 13:44:59.676089215 +0100\n+++ openssl-1.0.1i/ssl/s3_srvr.c\t2015-01-08 13:45:07.830184283 +0100\n@@ -441,20 +441,11 @@ int ssl3_accept(SSL *s)\n \t\tcase SSL3_ST_SW_KEY_EXCH_B:\n \t\t\talg_k = s->s3->tmp.new_cipher->algorithm_mkey;\n \n-\t\t\t/* clear this, it may get reset by\n-\t\t\t * send_server_key_exchange */\n-\t\t\tif ((s->options & SSL_OP_EPHEMERAL_RSA)\n-#ifndef OPENSSL_NO_KRB5\n-\t\t\t\t&& !(alg_k & SSL_kKRB5)\n-#endif /* OPENSSL_NO_KRB5 */\n-\t\t\t\t)\n-\t\t\t\t/* option SSL_OP_EPHEMERAL_RSA sends temporary RSA key\n-\t\t\t\t * even when forbidden by protocol specs\n-\t\t\t\t * (handshake may fail as clients are not required to\n-\t\t\t\t * be able to handle this) */\n-\t\t\t\ts->s3->tmp.use_rsa_tmp=1;\n-\t\t\telse\n-\t\t\t\ts->s3->tmp.use_rsa_tmp=0;\n+\t\t\t/*\n+\t\t\t * clear this, it may get reset by\n+\t\t\t * send_server_key_exchange\n+\t\t\t */\n+\t\t\ts->s3->tmp.use_rsa_tmp=0;\n \n \n \t\t\t/* only send if a DH key exchange, fortezza or\n@@ -468,7 +459,7 @@ int ssl3_accept(SSL *s)\n \t\t\t * server certificate contains the server's\n \t\t\t * public key for key exchange.\n \t\t\t */\n-\t\t\tif (s->s3->tmp.use_rsa_tmp\n+\t\t\tif (0\n \t\t\t/* PSK: send ServerKeyExchange if PSK identity\n \t\t\t * hint if provided */\n #ifndef OPENSSL_NO_PSK\nIndex: openssl-1.0.1i/ssl/ssl.h\n===================================================================\n--- openssl-1.0.1i.orig/ssl/ssl.h\t2015-01-08 13:44:59.677089227 +0100\n+++ openssl-1.0.1i/ssl/ssl.h\t2015-01-08 13:45:07.831184295 +0100\n@@ -600,9 +600,8 @@ struct ssl_session_st\n #define SSL_OP_SINGLE_ECDH_USE\t\t\t\t0x00080000L\n /* If set, always create a new key when using tmp_dh parameters */\n #define SSL_OP_SINGLE_DH_USE\t\t\t\t0x00100000L\n-/* Set to always use the tmp_rsa key when doing RSA operations,\n- * even when this violates protocol specs */\n-#define SSL_OP_EPHEMERAL_RSA\t\t\t\t0x00200000L\n+/* Does nothing: retained for compatibiity */\n+#define SSL_OP_EPHEMERAL_RSA\t\t\t\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "commit 37580f43b5a39f5f4e920d17273fab9713d3a744\nAuthor: Dr. Stephen Henson \nDate: Thu Oct 23 17:09:57 2014 +0100\n\n Only allow ephemeral RSA keys in export ciphersuites.\n \n OpenSSL clients would tolerate temporary RSA keys in non-export\n ciphersuites. It also had an option SSL_OP_EPHEMERAL_RSA which\n enabled this server side. Remove both options as they are a\n protocol violation.\n \n Thanks to Karthikeyan Bhargavan for reporting this issue.\n (CVE-2015-0204)\n Reviewed-by: Matt Caswell \n Reviewed-by: Tim Hudson \n \n (cherry picked from commit 4b4c1fcc88aec8c9e001b0a0077d3cd4de1ed0e6)\n \n Conflicts:\n \tdoc/ssl/SSL_CTX_set_options.pod\n\nIndex: openssl-1.0.1i/doc/ssl/SSL_CTX_set_options.pod\n===================================================================\n--- openssl-1.0.1i.orig/doc/ssl/SSL_CTX_set_options.pod\t2015-01-08 13:44:59.674089192 +0100\n+++ openssl-1.0.1i/doc/ssl/SSL_CTX_set_options.pod\t2015-01-08 13:45:07.828184260 +0100\n@@ -158,15 +158,7 @@ temporary/ephemeral DH parameters are us\n \n =item SSL_OP_EPHEMERAL_RSA\n \n-Always use ephemeral (temporary) RSA key when doing RSA operations\n-(see L).\n-According to the specifications this is only done, when a RSA key\n-can only be used for signature operations (namely under export ciphers\n-with restricted RSA keylength). By setting this option, ephemeral\n-RSA keys are always used. This option breaks compatibility with the\n-SSL/TLS specifications and may lead to interoperability problems with\n-clients and should therefore never be used. Ciphers with EDH (ephemeral\n-Diffie-Hellman) key exchange should be used instead.\n+This option is no longer implemented and is treated as no op.\n \n =item SSL_OP_CIPHER_SERVER_PREFERENCE\n \nIndex: openssl-1.0.1i/doc/ssl/SSL_CTX_set_tmp_rsa_callback.pod\n===================================================================\n--- openssl-1.0.1i.orig/doc/ssl/SSL_CTX_set_tmp_rsa_callback.pod\t2015-01-08 13:44:59.674089192 +0100\n+++ openssl-1.0.1i/doc/ssl/SSL_CTX_set_tmp_rsa_callback.pod\t2015-01-08 13:45:07.829184272 +0100\n@@ -74,21 +74,14 @@ exchange and use EDH (Ephemeral Diffie-H\n in order to achieve forward secrecy (see\n L).\n \n-On OpenSSL servers ephemeral RSA key exchange is therefore disabled by default\n-and must be explicitly enabled using the SSL_OP_EPHEMERAL_RSA option of\n-L, violating the TLS/SSL\n-standard. When ephemeral RSA key exchange is required for export ciphers,\n-it will automatically be used without this option!\n-\n-An application may either directly specify the key or can supply the key via\n-a callback function. The callback approach has the advantage, that the\n-callback may generate the key only in case it is actually needed. As the\n-generation of a RSA key is however costly, it will lead to a significant\n-delay in the handshake procedure. Another advantage of the callback function\n-is that it can supply keys of different size (e.g. for SSL_OP_EPHEMERAL_RSA\n-usage) while the explicit setting of the key is only useful for key size of\n-512 bits to satisfy the export restricted ciphers and does give away key length\n-if a longer key would be allowed.\n+An application may either directly specify the key or can supply the key via a\n+callback function. The callback approach has the advantage, that the callback\n+may generate the key only in case it is actually needed. As the generation of a\n+RSA key is however costly, it will lead to a significant delay in the handshake\n+procedure. Another advantage of the callback function is that it can supply\n+keys of different size while the explicit setting of the key is only useful for\n+key size of 512 bits to satisfy the export restricted ciphers and does give\n+away key length if a longer key would be allowed.\n \n The B is called with the B needed and\n the B information. The B flag is set, when the\nIndex: openssl-1.0.1i/ssl/d1_srvr.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/d1_srvr.c\t2015-01-08 13:44:59.675089204 +0100\n+++ openssl-1.0.1i/ssl/d1_srvr.c\t2015-01-08 13:45:07.829184272 +0100\n@@ -450,24 +450,15 @@ int dtls1_accept(SSL *s)\n \t\tcase SSL3_ST_SW_KEY_EXCH_B:\n \t\t\talg_k = s->s3->tmp.new_cipher->algorithm_mkey;\n \n-\t\t\t/* clear this, it may get reset by\n-\t\t\t * send_server_key_exchange */\n-\t\t\tif ((s->options & SSL_OP_EPHEMERAL_RSA)\n-#ifndef OPENSSL_NO_KRB5\n-\t\t\t\t&& !(alg_k & SSL_kKRB5)\n-#endif /* OPENSSL_NO_KRB5 */\n-\t\t\t\t)\n-\t\t\t\t/* option SSL_OP_EPHEMERAL_RSA sends temporary RSA key\n-\t\t\t\t * even when forbidden by protocol specs\n-\t\t\t\t * (handshake may fail as clients are not required to\n-\t\t\t\t * be able to handle this) */\n-\t\t\t\ts->s3->tmp.use_rsa_tmp=1;\n-\t\t\telse\n-\t\t\t\ts->s3->tmp.use_rsa_tmp=0;\n+\t\t\t/*\n+\t\t\t * clear this, it may get reset by\n+\t\t\t * send_server_key_exchange\n+\t\t\t */\n+\t\t\ts->s3->tmp.use_rsa_tmp=0;\n \n \t\t\t/* only send if a DH key exchange or\n \t\t\t * RSA but we have a sign only certificate */\n-\t\t\tif (s->s3->tmp.use_rsa_tmp\n+\t\t\tif (0\n \t\t\t/* PSK: send ServerKeyExchange if PSK identity\n \t\t\t * hint if provided */\n #ifndef OPENSSL_NO_PSK\nIndex: openssl-1.0.1i/ssl/s3_clnt.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s3_clnt.c\t2015-01-08 13:44:59.675089204 +0100\n+++ openssl-1.0.1i/ssl/s3_clnt.c\t2015-01-08 13:45:07.830184283 +0100\n@@ -1505,6 +1505,13 @@ int ssl3_get_key_exchange(SSL *s)\n #ifndef OPENSSL_NO_RSA\n \tif (alg_k & SSL_kRSA)\n \t\t{\n+\t\t/* Temporary RSA keys only allowed in export ciphersuites */\n+\t\tif (!SSL_C_IS_EXPORT(s->s3->tmp.new_cipher))\n+\t\t\t{\n+\t\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n+\t\t\tSSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_UNEXPECTED_MESSAGE);\n+\t\t\tgoto f_err;\n+\t\t\t}\n \t\tif ((rsa=RSA_new()) == NULL)\n \t\t\t{\n \t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE);\nIndex: openssl-1.0.1i/ssl/s3_srvr.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s3_srvr.c\t2015-01-08 13:44:59.676089215 +0100\n+++ openssl-1.0.1i/ssl/s3_srvr.c\t2015-01-08 13:45:07.830184283 +0100\n@@ -441,20 +441,11 @@ int ssl3_accept(SSL *s)\n \t\tcase SSL3_ST_SW_KEY_EXCH_B:\n \t\t\talg_k = s->s3->tmp.new_cipher->algorithm_mkey;\n \n-\t\t\t/* clear this, it may get reset by\n-\t\t\t * send_server_key_exchange */\n-\t\t\tif ((s->options & SSL_OP_EPHEMERAL_RSA)\n-#ifndef OPENSSL_NO_KRB5\n-\t\t\t\t&& !(alg_k & SSL_kKRB5)\n-#endif /* OPENSSL_NO_KRB5 */\n-\t\t\t\t)\n-\t\t\t\t/* option SSL_OP_EPHEMERAL_RSA sends temporary RSA key\n-\t\t\t\t * even when forbidden by protocol specs\n-\t\t\t\t * (handshake may fail as clients are not required to\n-\t\t\t\t * be able to handle this) */\n-\t\t\t\ts->s3->tmp.use_rsa_tmp=1;\n-\t\t\telse\n-\t\t\t\ts->s3->tmp.use_rsa_tmp=0;\n+\t\t\t/*\n+\t\t\t * clear this, it may get reset by\n+\t\t\t * send_server_key_exchange\n+\t\t\t */\n+\t\t\ts->s3->tmp.use_rsa_tmp=0;\n \n \n \t\t\t/* only send if a DH key exchange, fortezza or\n@@ -468,7 +459,7 @@ int ssl3_accept(SSL *s)\n \t\t\t * server certificate contains the server's\n \t\t\t * public key for key exchange.\n \t\t\t */\n-\t\t\tif (s->s3->tmp.use_rsa_tmp\n+\t\t\tif (0\n \t\t\t/* PSK: send ServerKeyExchange if PSK identity\n \t\t\t * hint if provided */\n #ifndef OPENSSL_NO_PSK\nIndex: openssl-1.0.1i/ssl/ssl.h\n===================================================================\n--- openssl-1.0.1i.orig/ssl/ssl.h\t2015-01-08 13:44:59.677089227 +0100\n+++ openssl-1.0.1i/ssl/ssl.h\t2015-01-08 13:45:07.831184295 +0100\n@@ -600,9 +600,8 @@ struct ssl_session_st\n #define SSL_OP_SINGLE_ECDH_USE\t\t\t\t0x00080000L\n /* If set, always create a new key when using tmp_dh parameters */\n #define SSL_OP_SINGLE_DH_USE\t\t\t\t0x00100000L\n-/* Set to always use the tmp_rsa key when doing RSA operations,\n- * even when this violates protocol specs */\n-#define SSL_OP_EPHEMERAL_RSA\t\t\t\t0x00200000L\n+/* Does nothing: retained for compatibiity */\n+#define SSL_OP_EPHEMERAL_RSA\t\t\t\t0x0\n /* Set on servers to choose the cipher according to the server's\n * preferences */\n #define SSL_OP_CIPHER_SERVER_PREFERENCE\t\t\t0x00400000L"}], "metadata": {"id": "openssl-4769-openssl-CVE-2015-0204.patch", "cve_id": "CVE-2015-3197", "package": "openssl", "tier": "adapted", "has_source_context": true, "context_tokens_est": 3193, "context_files": 6, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2013-2487\n\nepan/dissectors/packet-reload.c in the REsource LOcation And Discovery (aka RELOAD) dissector in Wireshark 1.8.x before 1.8.6 uses incorrect integer data types, which allows remote attackers to cause a denial of service (infinite loop) via crafted integer values in a packet, related to the (1) dissect_icecandidates, (2) dissect_kinddata, (3) dissect_nodeid_list, (4) dissect_storeans, (5) dissect_storereq, (6) dissect_storeddataspecifier, (7) dissect_fetchreq, (8) dissect_findans, (9) dissect_diagnosticinfo, (10) dissect_diagnosticresponse, (11) dissect_reload_messagecontents, and (12) dissect_reload_message functions, a different vulnerability than CVE-2013-2486.\n\n## Package\nwireshark\n\n## Files to modify\n- epan/geoip_db.c\n\n## Upstream Fix\n```diff\nIndex: epan/geoip_db.c\n===================================================================\n--- epan/geoip_db.c.orig\t2012-06-05 17:33:40.000000000 +0100\n+++ epan/geoip_db.c\t2012-06-21 21:55:14.000000000 +0100\n@@ -177,6 +177,9 @@ geoip_db_init(void) {\n geoip_dat_scan_dir(geoip_db_paths[i].path);\n }\n }\n+ if (num_geoip_db_paths < 1) {\n+ geoip_dat_scan_dir(\"/var/lib/GeoIP\");\n+ }\n \n /* add fake databases for latitude and longitude (using \"City\" in reality) */\n {\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "Index: epan/geoip_db.c\n===================================================================\n--- epan/geoip_db.c.orig\t2012-06-05 17:33:40.000000000 +0100\n+++ epan/geoip_db.c\t2012-06-21 21:55:14.000000000 +0100\n@@ -177,6 +177,9 @@ geoip_db_init(void) {\n geoip_dat_scan_dir(geoip_db_paths[i].path);\n }\n }\n+ if (num_geoip_db_paths < 1) {\n+ geoip_dat_scan_dir(\"/var/lib/GeoIP\");\n+ }\n \n /* add fake databases for latitude and longitude (using \"City\" in reality) */\n {"}], "metadata": {"id": "wireshark-1689-wireshark-1.2.0-geoip.patch", "cve_id": "CVE-2013-2487", "package": "wireshark", "tier": "identical", "has_source_context": false, "license": "GPL-2.0-or-later AND GPL-3.0-or-later"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-2804\n\nMultiple unspecified vulnerabilities in the browser engine in Mozilla Firefox before 46.0 allow remote attackers to cause a denial of service (memory corruption and application crash) or possibly execute arbitrary code via unknown vectors.\n\n## Package\nmozilla-nss\n\n## Files to modify\n- nss/cmd/vfychain/vfychain.c\n- nss.orig/cmd/vfychain/vfychain.c\n- nss.orig/cmd/bltest/blapitest.c\n- nss.orig/lib/dbm/src/h_page.c\n- cmd/bltest/blapitest.c\n\n## Upstream Fix\n```diff\nFrom: Michel Normand \nSubject: nss gcc6 change\nDate: Mon, 18 Apr 2016 19:11:03 +0200\n\nnss changes required to avoid build error with gcc6 like:\n===\n[ 58s] h_page.c: In function 'new_lseek':\n[ 58s] h_page.c:117:8: error: this 'if' clause does not guard... [-Werror=misleading-indentation]\n[ 58s] if(offset < 1)\n[ 58s] ^~\n[ 58s] h_page.c:120:3: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'\n[ 58s] cur_pos = lseek(fd, 0, SEEK_CUR);\n[ 58s] ^~~~~~~\n===\n\nSigned-off-by: Michel Normand \n---\n cmd/bltest/blapitest.c | 4 +--\n cmd/vfychain/vfychain.c | 3 +-\n lib/dbm/src/h_page.c | 55 +++++++++++++++++++++-----------------------\n lib/dbm/src/hash.c | 60 ++++++++++++++++++++++++------------------------\n 4 files changed, 61 insertions(+), 61 deletions(-)\n\nIndex: nss/lib/dbm/src/h_page.c\n===================================================================\n--- nss.orig/lib/dbm/src/h_page.c\n+++ nss/lib/dbm/src/h_page.c\n@@ -112,26 +112,25 @@ long new_lseek(int fd, long offset, int\n \tlong end_pos=0;\n \tlong seek_pos=0;\n \n-\tif(origin == SEEK_CUR)\n- {\t\n- \tif(offset < 1)\t\t\t\t\t\t\t \n-\t \treturn(lseek(fd, offset, SEEK_CUR));\n+\tif (origin == SEEK_CUR) {\n+\t if (offset < 1)\n+\t\treturn(lseek(fd, offset, SEEK_CUR));\n \n-\t\tcur_pos = lseek(fd, 0, SEEK_CUR);\n+\t cur_pos = lseek(fd, 0, SEEK_CUR);\n+\n+\t if (cur_pos < 0)\n+\t\treturn(cur_pos);\n+\t}\n \n-\t\tif(cur_pos < 0)\n-\t\t\treturn(cur_pos);\n-\t }\n-\t\t\t\t\t\t\t\t\t\t \n \tend_pos = lseek(fd, 0, SEEK_END);\n-\tif(end_pos < 0)\n+\tif (end_pos < 0)\n \t\treturn(end_pos);\n \n-\tif(origin == SEEK_SET)\n+\tif (origin == SEEK_SET)\n \t\tseek_pos = offset;\n-\telse if(origin == SEEK_CUR)\n+\telse if (origin == SEEK_CUR)\n \t\tseek_pos = cur_pos + offset;\n-\telse if(origin == SEEK_END)\n+\telse if (origin == SEEK_END)\n \t\tseek_pos = end_pos + offset;\n \telse\n \t {\n@@ -143,7 +142,7 @@ long new_lseek(int fd, long offset, int\n \t * end of the file. We don't need\n \t * to do anything special except the seek.\n \t */\n- \tif(seek_pos <= end_pos)\n+ \tif (seek_pos <= end_pos)\n \t\treturn(lseek(fd, seek_pos, SEEK_SET));\n \t\t\n \t /* the seek position is beyond the end of the\n@@ -161,7 +160,7 @@ long new_lseek(int fd, long offset, int\n \t \tmemset(buffer, 0, 1024);\n \t \twhile(len > 0)\n \t {\n-\t if(write(fd, buffer, (size_t)(1024 > len ? len : 1024)) < 0)\n+\t if (write(fd, buffer, (size_t)(1024 > len ? len : 1024)) < 0)\n \t\t\t\treturn(-1);\n \t\t len -= 1024;\n \t\t }\n@@ -245,10 +244,10 @@ __delpair(HTAB *hashp, BUFHEAD *bufp, in\n \t\t * Once we know dst_offset is < BSIZE, we can subtract it from BSIZE\n \t\t * to get an upper bound on length.\n \t\t */\n-\t\tif(dst_offset > (uint32)hashp->BSIZE)\n+\t\tif (dst_offset > (uint32)hashp->BSIZE)\n \t\t\treturn(DATABASE_CORRUPTED_ERROR);\n \n-\t\tif(length > (uint32)(hashp->BSIZE - dst_offset))\n+\t\tif (length > (uint32)(hashp->BSIZE - dst_offset))\n \t\t\treturn(DATABASE_CORRUPTED_ERROR);\n \n \t\tmemmove(dst, src, length);\n@@ -324,7 +323,7 @@ __split_page(HTAB *hashp, uint32 obucket\n \t\t * off. If it is then the database has\n \t\t * been corrupted.\n \t\t */\n-\t\tif(ino[n] > off)\n+\t\tif (ino[n] > off)\n \t\t\treturn(DATABASE_CORRUPTED_ERROR);\n \n \t\tkey.size = off - ino[n];\n@@ -355,7 +354,7 @@ __split_page(HTAB *hashp, uint32 obucket\n \t\t\t * wrong. LJM\n \t\t\t */\n \t\t\ttmp_uint16_array = (uint16*)np;\n-\t\t\tif(!PAIRFITS(tmp_uint16_array, &key, &val))\n+\t\t\tif (!PAIRFITS(tmp_uint16_array, &key, &val))\n \t\t\t\treturn(DATABASE_CORRUPTED_ERROR);\n \n \t\t\tputpair(np, &key, &val);\n@@ -440,7 +439,7 @@ ugly_split(HTAB *hashp, uint32 obucket,\n */\n loop_detection++;\n \n- if(loop_detection > MAX_UGLY_SPLIT_LOOPS)\n+ if (loop_detection > MAX_UGLY_SPLIT_LOOPS)\n return DATABASE_CORRUPTED_ERROR;\n \n \t\tif (ino[2] < REAL_KEY && ino[2] != OVFLPAGE) {\n@@ -736,7 +735,7 @@ __get_page(HTAB *hashp,\n \t \t\t * the maximum number of entries\n \t \t\t * in the array\n \t \t\t */\n-\t\t\t\tif((unsigned)max > (size / sizeof(uint16)))\n+\t\t\t\tif ((unsigned)max > (size / sizeof(uint16)))\n \t\t\t\t\treturn(DATABASE_CORRUPTED_ERROR);\n \n \t\t\t\t/* do the byte order swap\n@@ -749,7 +748,7 @@ __get_page(HTAB *hashp,\n \t\t/* check the validity of the page here\n \t\t * (after doing byte order swaping if necessary)\n \t\t */\n-\t\tif(!is_bitmap && bp[0] != 0)\n+\t\tif (!is_bitmap && bp[0] != 0)\n \t\t {\n \t\t\tuint16 num_keys = bp[0];\n \t\t\tuint16 offset;\n@@ -760,11 +759,11 @@ __get_page(HTAB *hashp,\n \t\t\t * bp[0] is too large (larger than the whole\n \t\t\t * page) then the page is corrupted\n \t\t\t */\n-\t\t\tif(bp[0] > (size / sizeof(uint16)))\n+\t\t\tif (bp[0] > (size / sizeof(uint16)))\n \t\t\t\treturn(DATABASE_CORRUPTED_ERROR);\n \t\t\t\n \t\t\t/* bound free space */\n-\t\t\tif(FREESPACE(bp) > size)\n+\t\t\tif (FREESPACE(bp) > size)\n \t\t\t\treturn(DATABASE_CORRUPTED_ERROR);\n \t\t\n \t\t\t/* check each key and data offset to make\n@@ -776,10 +775,10 @@ __get_page(HTAB *hashp,\n \t\t\tfor(i=1 ; i <= num_keys; i+=2)\n \t\t\t {\n \t\t\t\t/* ignore overflow pages etc. */\n-\t\t\t\tif(bp[i+1] >= REAL_KEY)\n+\t\t\t\tif (bp[i+1] >= REAL_KEY)\n \t \t\t\t {\n \t\t\t\t\t\t\n-\t\t\t\t\tif(bp[i] > offset || bp[i+1] > bp[i])\t\t\t\n+\t\t\t\t\tif (bp[i] > offset || bp[i+1] > bp[i])\n \t\t\t\t\t\treturn(DATABASE_CORRUPTED_ERROR);\n \t\t\t\n \t\t\t\t\toffset = bp[i+1];\n@@ -832,7 +831,7 @@ __put_page(HTAB *hashp, char *p, uint32\n * the maximum number of entries\n * in the array\n */\n- if((unsigned)max > (size / sizeof(uint16)))\n+ if ((unsigned)max > (size / sizeof(uint16)))\n return(DATABASE_CORRUPTED_ERROR);\n \n \t\t\tfor (i = 0; i <= max; i++)\n@@ -1091,7 +1090,7 @@ __free_ovflpage(HTAB *hashp, BUFHEAD *ob\n \tuint32 bit_address, free_page, free_bit;\n \tuint16 ndx;\n \n-\tif(!obufp || !obufp->addr)\n+\tif (!obufp || !obufp->addr)\n \t return;\n \n \taddr = obufp->addr;\nIndex: nss/lib/dbm/src/hash.c\n===================================================================\n--- nss.orig/lib/dbm/src/hash.c\n+++ nss/lib/dbm/src/hash.c\n@@ -154,7 +154,7 @@ __hash_open(const char *file, int flags,\n \t\treturn NULL;\n \t}\n \thashp->fp = NO_FILE;\n-\tif(file)\n+\tif (file)\n \t\thashp->filename = strdup(file);\n \n \t/*\n@@ -172,7 +172,7 @@ __hash_open(const char *file, int flags,\n \t\t\terrno = 0; /* Just in case someone looks at errno */\n \t\tnew_table = 1;\n \t}\n-\telse if(statbuf.st_mtime && statbuf.st_size == 0)\n+\telse if (statbuf.st_mtime && statbuf.st_size == 0)\n \t{\n \t\t/* check for a zero length file and delete it\n \t \t * if it exists\n@@ -288,7 +288,7 @@ hash_close(DB *dbp)\n \t\treturn (DBM_ERROR);\n \n \thashp = (HTAB *)dbp->internal;\n-\tif(!hashp)\n+\tif (!hashp)\n \t\treturn (DBM_ERROR);\n \n \tretval = hdestroy(hashp);\n@@ -304,7 +304,7 @@ static int hash_fd(const DB *dbp)\n \t\treturn (DBM_ERROR);\n \n \thashp = (HTAB *)dbp->internal;\n-\tif(!hashp)\n+\tif (!hashp)\n \t\treturn (DBM_ERROR);\n \n \tif (hashp->fp == -1) {\n@@ -480,7 +480,7 @@ hdestroy(HTAB *hashp)\n \tif (hashp->fp != -1)\n \t\t(void)close(hashp->fp);\n \n-\tif(hashp->filename) {\n+\tif (hashp->filename) {\n #if defined(_WIN32) || defined(_WINDOWS) || defined(XP_OS2)\n \t\tif (hashp->is_temp)\n \t\t\t(void)unlink(hashp->filename);\n@@ -578,7 +578,7 @@ hash_sync(const DB *dbp, uint flags)\n \t\treturn (DBM_ERROR);\n \n \thashp = (HTAB *)dbp->internal;\n-\tif(!hashp)\n+\tif (!hashp)\n \t\treturn (DBM_ERROR);\n \n \tif (!hashp->save_file)\n@@ -670,7 +670,7 @@ hash_get(\n \n \trv = hash_access(hashp, HASH_GET, (DBT *)key, data);\n \n-\tif(rv == DATABASE_CORRUPTED_ERROR)\n+\tif (rv == DATABASE_CORRUPTED_ERROR)\n \t {\n #if defined(unix) && defined(DEBUG)\n \t\tprintf(\"\\n\\nDBM Database has been corrupted, tell Lou...\\n\\n\");\n@@ -707,7 +707,7 @@ hash_put(\n \trv = hash_access(hashp, flag == R_NOOVERWRITE ?\n \t HASH_PUTNEW : HASH_PUT, (DBT *)key, (DBT *)data);\n \n-\tif(rv == DATABASE_CORRUPTED_ERROR)\n+\tif (rv == DATABASE_CORRUPTED_ERROR)\n \t {\n #if defined(unix) && defined(DEBUG)\n \t\tprintf(\"\\n\\nDBM Database has been corrupted, tell Lou...\\n\\n\");\n@@ -741,7 +741,7 @@ hash_delete(\n \t}\n \trv = hash_access(hashp, HASH_DELETE, (DBT *)key, NULL);\n \n-\tif(rv == DATABASE_CORRUPTED_ERROR)\n+\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From: Michel Normand \nSubject: nss gcc6 change\nDate: Mon, 18 Apr 2016 19:11:03 +0200\n\nnss changes required to avoid build error with gcc6 like:\n===\n[ 58s] h_page.c: In function 'new_lseek':\n[ 58s] h_page.c:117:8: error: this 'if' clause does not guard... [-Werror=misleading-indentation]\n[ 58s] if(offset < 1)\n[ 58s] ^~\n[ 58s] h_page.c:120:3: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'\n[ 58s] cur_pos = lseek(fd, 0, SEEK_CUR);\n[ 58s] ^~~~~~~\n===\n\nSigned-off-by: Michel Normand \n---\n cmd/bltest/blapitest.c | 4 +--\n cmd/vfychain/vfychain.c | 3 +-\n lib/dbm/src/h_page.c | 55 +++++++++++++++++++++-----------------------\n lib/dbm/src/hash.c | 60 ++++++++++++++++++++++++------------------------\n 4 files changed, 61 insertions(+), 61 deletions(-)\n\nIndex: nss/lib/dbm/src/h_page.c\n===================================================================\n--- nss.orig/lib/dbm/src/h_page.c\n+++ nss/lib/dbm/src/h_page.c\n@@ -112,26 +112,25 @@ long new_lseek(int fd, long offset, int\n \tlong end_pos=0;\n \tlong seek_pos=0;\n \n-\tif(origin == SEEK_CUR)\n- {\t\n- \tif(offset < 1)\t\t\t\t\t\t\t \n-\t \treturn(lseek(fd, offset, SEEK_CUR));\n+\tif (origin == SEEK_CUR) {\n+\t if (offset < 1)\n+\t\treturn(lseek(fd, offset, SEEK_CUR));\n \n-\t\tcur_pos = lseek(fd, 0, SEEK_CUR);\n+\t cur_pos = lseek(fd, 0, SEEK_CUR);\n+\n+\t if (cur_pos < 0)\n+\t\treturn(cur_pos);\n+\t}\n \n-\t\tif(cur_pos < 0)\n-\t\t\treturn(cur_pos);\n-\t }\n-\t\t\t\t\t\t\t\t\t\t \n \tend_pos = lseek(fd, 0, SEEK_END);\n-\tif(end_pos < 0)\n+\tif (end_pos < 0)\n \t\treturn(end_pos);\n \n-\tif(origin == SEEK_SET)\n+\tif (origin == SEEK_SET)\n \t\tseek_pos = offset;\n-\telse if(origin == SEEK_CUR)\n+\telse if (origin == SEEK_CUR)\n \t\tseek_pos = cur_pos + offset;\n-\telse if(origin == SEEK_END)\n+\telse if (origin == SEEK_END)\n \t\tseek_pos = end_pos + offset;\n \telse\n \t {\n@@ -143,7 +142,7 @@ long new_lseek(int fd, long offset, int\n \t * end of the file. We don't need\n \t * to do anything special except the seek.\n \t */\n- \tif(seek_pos <= end_pos)\n+ \tif (seek_pos <= end_pos)\n \t\treturn(lseek(fd, seek_pos, SEEK_SET));\n \t\t\n \t /* the seek position is beyond the end of the\n@@ -161,7 +160,7 @@ long new_lseek(int fd, long offset, int\n \t \tmemset(buffer, 0, 1024);\n \t \twhile(len > 0)\n \t {\n-\t if(write(fd, buffer, (size_t)(1024 > len ? len : 1024)) < 0)\n+\t if (write(fd, buffer, (size_t)(1024 > len ? len : 1024)) < 0)\n \t\t\t\treturn(-1);\n \t\t len -= 1024;\n \t\t }\n@@ -245,10 +244,10 @@ __delpair(HTAB *hashp, BUFHEAD *bufp, in\n \t\t * Once we know dst_offset is < BSIZE, we can subtract it from BSIZE\n \t\t * to get an upper bound on length.\n \t\t */\n-\t\tif(dst_offset > (uint32)hashp->BSIZE)\n+\t\tif (dst_offset > (uint32)hashp->BSIZE)\n \t\t\treturn(DATABASE_CORRUPTED_ERROR);\n \n-\t\tif(length > (uint32)(hashp->BSIZE - dst_offset))\n+\t\tif (length > (uint32)(hashp->BSIZE - dst_offset))\n \t\t\treturn(DATABASE_CORRUPTED_ERROR);\n \n \t\tmemmove(dst, src, length);\n@@ -324,7 +323,7 @@ __split_page(HTAB *hashp, uint32 obucket\n \t\t * off. If it is then the database has\n \t\t * been corrupted.\n \t\t */\n-\t\tif(ino[n] > off)\n+\t\tif (ino[n] > off)\n \t\t\treturn(DATABASE_CORRUPTED_ERROR);\n \n \t\tkey.size = off - ino[n];\n@@ -355,7 +354,7 @@ __split_page(HTAB *hashp, uint32 obucket\n \t\t\t * wrong. LJM\n \t\t\t */\n \t\t\ttmp_uint16_array = (uint16*)np;\n-\t\t\tif(!PAIRFITS(tmp_uint16_array, &key, &val))\n+\t\t\tif (!PAIRFITS(tmp_uint16_array, &key, &val))\n \t\t\t\treturn(DATABASE_CORRUPTED_ERROR);\n \n \t\t\tputpair(np, &key, &val);\n@@ -440,7 +439,7 @@ ugly_split(HTAB *hashp, uint32 obucket,\n */\n loop_detection++;\n \n- if(loop_detection > MAX_UGLY_SPLIT_LOOPS)\n+ if (loop_detection > MAX_UGLY_SPLIT_LOOPS)\n return DATABASE_CORRUPTED_ERROR;\n \n \t\tif (ino[2] < REAL_KEY && ino[2] != OVFLPAGE) {\n@@ -736,7 +735,7 @@ __get_page(HTAB *hashp,\n \t \t\t * the maximum number of entries\n \t \t\t * in the array\n \t \t\t */\n-\t\t\t\tif((unsigned)max > (size / sizeof(uint16)))\n+\t\t\t\tif ((unsigned)max > (size / sizeof(uint16)))\n \t\t\t\t\treturn(DATABASE_CORRUPTED_ERROR);\n \n \t\t\t\t/* do the byte order swap\n@@ -749,7 +748,7 @@ __get_page(HTAB *hashp,\n \t\t/* check the validity of the page here\n \t\t * (after doing byte order swaping if necessary)\n \t\t */\n-\t\tif(!is_bitmap && bp[0] != 0)\n+\t\tif (!is_bitmap && bp[0] != 0)\n \t\t {\n \t\t\tuint16 num_keys = bp[0];\n \t\t\tuint16 offset;\n@@ -760,11 +759,11 @@ __get_page(HTAB *hashp,\n \t\t\t * bp[0] is too large (larger than the whole\n \t\t\t * page) then the page is corrupted\n \t\t\t */\n-\t\t\tif(bp[0] > (size / sizeof(uint16)))\n+\t\t\tif (bp[0] > (size / sizeof(uint16)))\n \t\t\t\treturn(DATABASE_CORRUPTED_ERROR);\n \t\t\t\n \t\t\t/* bound free space */\n-\t\t\tif(FREESPACE(bp) > size)\n+\t\t\tif (FREESPACE(bp) > size)\n \t\t\t\treturn(DATABASE_CORRUPTED_ERROR);\n \t\t\n \t\t\t/* check each key and data offset to make\n@@ -776,10 +775,10 @@ __get_page(HTAB *hashp,\n \t\t\tfor(i=1 ; i <= num_keys; i+=2)\n \t\t\t {\n \t\t\t\t/* ignore overflow pages etc. */\n-\t\t\t\tif(bp[i+1] >= REAL_KEY)\n+\t\t\t\tif (bp[i+1] >= REAL_KEY)\n \t \t\t\t {\n \t\t\t\t\t\t\n-\t\t\t\t\tif(bp[i] > offset || bp[i+1] > bp[i])\t\t\t\n+\t\t\t\t\tif (bp[i] > offset || bp[i+1] > bp[i])\n \t\t\t\t\t\treturn(DATABASE_CORRUPTED_ERROR);\n \t\t\t\n \t\t\t\t\toffset = bp[i+1];\n@@ -832,7 +831,7 @@ __put_page(HTAB *hashp, char *p, uint32\n * the maximum number of entries\n * in the array\n */\n- if((unsigned)max > (size / sizeof(uint16)))\n+ if ((unsigned)max > (size / sizeof(uint16)))\n return(DATABASE_CORRUPTED_ERROR);\n \n \t\t\tfor (i = 0; i <= max; i++)\n@@ -1091,7 +1090,7 @@ __free_ovflpage(HTAB *hashp, BUFHEAD *ob\n \tuint32 bit_address, free_page, free_bit;\n \tuint16 ndx;\n \n-\tif(!obufp || !obufp->addr)\n+\tif (!obufp || !obufp->addr)\n \t return;\n \n \taddr = obufp->addr;\nIndex: nss/lib/dbm/src/hash.c\n===================================================================\n--- nss.orig/lib/dbm/src/hash.c\n+++ nss/lib/dbm/src/hash.c\n@@ -154,7 +154,7 @@ __hash_open(const char *file, int flags,\n \t\treturn NULL;\n \t}\n \thashp->fp = NO_FILE;\n-\tif(file)\n+\tif (file)\n \t\thashp->filename = strdup(file);\n \n \t/*\n@@ -172,7 +172,7 @@ __hash_open(const char *file, int flags,\n \t\t\terrno = 0; /* Just in case someone looks at errno */\n \t\tnew_table = 1;\n \t}\n-\telse if(statbuf.st_mtime && statbuf.st_size == 0)\n+\telse if (statbuf.st_mtime && statbuf.st_size == 0)\n \t{\n \t\t/* check for a zero length file and delete it\n \t \t * if it exists\n@@ -288,7 +288,7 @@ hash_close(DB *dbp)\n \t\treturn (DBM_ERROR);\n \n \thashp = (HTAB *)dbp->internal;\n-\tif(!hashp)\n+\tif (!hashp)\n \t\treturn (DBM_ERROR);\n \n \tretval = hdestroy(hashp);\n@@ -304,7 +304,7 @@ static int hash_fd(const DB *dbp)\n \t\treturn (DBM_ERROR);\n \n \thashp = (HTAB *)dbp->internal;\n-\tif(!hashp)\n+\tif (!hashp)\n \t\treturn (DBM_ERROR);\n \n \tif (hashp->fp == -1) {\n@@ -480,7 +480,7 @@ hdestroy(HTAB *hashp)\n \tif (hashp->fp != -1)\n \t\t(void)close(hashp->fp);\n \n-\tif(hashp->filename) {\n+\tif (hashp->filename) {\n #if defined(_WIN32) || defined(_WINDOWS) || defined(XP_OS2)\n \t\tif (hashp->is_temp)\n \t\t\t(void)unlink(hashp->filename);\n@@ -578,7 +578,7 @@ hash_sync(const DB *dbp, uint flags)\n \t\treturn (DBM_ERROR);\n \n \thashp = (HTAB *)dbp->internal;\n-\tif(!hashp)\n+\tif (!hashp)\n \t\treturn (DBM_ERROR);\n \n \tif (!hashp->save_file)\n@@ -670,7 +670,7 @@ hash_get(\n \n \trv = hash_access(hashp, HASH_GET, (DBT *)key, data);\n \n-\tif(rv == DATABASE_CORRUPTED_ERROR)\n+\tif (rv == DATABASE_CORRUPTED_ERROR)\n \t {\n #if defined(unix) && defined(DEBUG)\n \t\tprintf(\"\\n\\nDBM Database has been corrupted, tell Lou...\\n\\n\");\n@@ -707,7 +707,7 @@ hash_put(\n \trv = hash_access(hashp, flag == R_NOOVERWRITE ?\n \t HASH_PUTNEW : HASH_PUT, (DBT *)key, (DBT *)data);\n \n-\tif(rv == DATABASE_CORRUPTED_ERROR)\n+\tif (rv == DATABASE_CORRUPTED_ERROR)\n \t {\n #if defined(unix) && defined(DEBUG)\n \t\tprintf(\"\\n\\nDBM Database has been corrupted, tell Lou...\\n\\n\");\n@@ -741,7 +741,7 @@ hash_delete(\n \t}\n \trv = hash_access(hashp, HASH_DELETE, (DBT *)key, NULL);\n \n-\tif(rv == DATABASE_CORRUPTED_ERROR)\n+\tif (rv == DATABASE_CORRUPTED_ERROR)\n \t {\n #if defined(unix) && defined(DEBUG)\n \t\tprintf(\"\\n\\nDBM Database has been corrupted, tell Lou...\\n\\n\");\n@@ -802,27 +802,27 @@ hash_access(\n \t\t\tndx += 2;\n \t\t} else if (bp[1] == OVFLPAGE) {\n \n- /* database corruption: overflow loop detection */\n- if(last_overflow_page_no == (int32)*bp)\n- \t\t\treturn (DATABASE_CORRUPTED_ERROR);\n-\n- last_overflow_page_no = *bp;\n-\n-\t\t\trbufp = __get_buf(hashp, *bp, rbufp, 0);\n-\t\t\tif (!rbufp) {\n-\t\t\t\tsave_bufp->flags &= ~BUF_PIN;\n-\t\t\t\treturn (DBM_ERROR);\n-\t\t\t}\n-\n- ovfl_loop_count++;\n- if(ovfl_loop_count > MAX_OVERFLOW_HASH_ACCESS_LOOPS)\n- \t\t\treturn (DATABASE_CORRUPTED_ERROR);\n-\n-\t\t\t/* FOR LOOP INIT */\n-\t\t\tbp = (uint16 *)rbufp->page;\n-\t\t\tn = *bp++;\n-\t\t\tndx = 1;\n-\t\t\toff = hashp->BSIZE;\n+\t\t /* database corruption: overflow loop detection */\n+\t\t if (last_overflow_page_no == (int32)*bp)\n+\t\t\treturn (DATABASE_CORRUPTED_ERROR);\n+\n+\t\t last_overflow_page_no = *bp;\n+\n+\t\t rbufp = __get_buf(hashp, *bp, rbufp, 0);\n+\t\t if (!rbufp) {\n+\t\t\t save_bufp->flags &= ~BUF_PIN;\n+\t\t\t return (DBM_ERROR);\n+\t\t }\n+\n+\t\t ovfl_loop_count++;\n+\t\t if (ovfl_loop_count > MAX_OVERFLOW_HASH_ACCESS_LOOPS)\n+\t\t\treturn (DATABASE_CORRUPTED_ERROR);\n+\n+\t\t /* FOR LOOP INIT */\n+\t\t bp = (uint16 *)rbufp->page;\n+\t\t n = *bp++;\n+\t\t ndx = 1;\n+\t\t off = hashp->BSIZE;\n \t\t} else if (bp[1] < REAL_KEY) {\n \t\t\tif ((ndx =\n \t\t\t __find_bigpair(hashp, rbufp, ndx, kp, (int)size)) > 0)\nIndex: nss/cmd/bltest/blapitest.c\n===================================================================\n--- nss.orig/cmd/bltest/blapitest.c\n+++ nss/cmd/bltest/blapitest.c\n@@ -1571,8 +1571,8 @@ bltest_seed_init(bltestCipherInfo *ciphe\n \tcipherInfo->cipher.symmkeyCipher = seed_Encrypt;\n else\n \tcipherInfo->cipher.symmkeyCipher = seed_Decrypt;\n-\t\n-\treturn SECSuccess;\n+\n+ return SECSuccess;\n }\n \n SECStatus\nIndex: nss/cmd/vfychain/vfychain.c\n===================================================================\n--- nss.orig/cmd/vfychain/vfychain.c\n+++ nss/cmd/vfychain/vfychain.c\n@@ -439,7 +439,8 @@ main(int argc, char *argv[], char *envp[\n \tcase 0 : /* positional parameter */ goto breakout;\n \tcase 'a' : isAscii = PR_TRUE; break;\n \tcase 'b' : secStatus = DER_AsciiToTime(&time, optstate->value);\n-\t if (secStatus != SECSuccess) Usage(progName); break;\n+\t if (secStatus != SECSuccess) Usage(progName);\n+\t\t break;\n \tcase 'd' : certDir = PL_strdup(optstate->value); break;\n \tcase 'e' : ocsp_fetchingFailureIsAFailure = PR_FALSE; break;\n \tcase 'f' : certFetching = PR_TRUE; break;"}], "metadata": {"id": "mozilla-nss-5017-nss_gcc6_change.patch", "cve_id": "CVE-2016-2804", "package": "mozilla-nss", "tier": "adapted", "has_source_context": false, "license": "MPL-2.0"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-4658\n\nxpointer.c in libxml2 before 2.9.5 (as used in Apple iOS before 10, OS X before 10.12, tvOS before 10, and watchOS before 3, and other products) does not forbid namespace nodes in XPointer ranges, which allows remote attackers to execute arbitrary code or cause a denial of service (use-after-free and memory corruption) via a crafted XML document.\n\n## Package\nlibxml2\n\n## Files to modify\n- parser.c\n- libxml2-2.9.1.orig/parser.c\n\n## Target Source Code\n\n### parser.c\n\n#### xmlParseInternalSubset() [lines 8398-7078]\n```c\n\n```\n\n### result/errors/content1.xml.err\n\n#### region() [lines 1-17]\n```c\n./test/errors/content1.xml:7: parser error : ContentDecl : ',' '|' or ')' expected\n\n ^\n./test/errors/content1.xml:7: parser error : expected '>'\n\n ^\n./test/errors/content1.xml:7: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration\n\n\n ^\n./test/errors/content1.xml:7: parser error : DOCTYPE improperly terminated\n\n ^\n./test/errors/content1.xml:7: parser error : Start tag expected, '<' not found\n\n ^\n\n```\n\n### result/valid/t8.xml.err\n\n#### region() [lines 1-20]\n```c\nEntity: line 1: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration\n\n %defroot; \n ^\nEntity: line 1: \n<!ELEMENT root (middle) >\n^\nEntity: line 1: parser error : DOCTYPE improperly terminated\n %defroot; \n ^\nEntity: line 1: \n<!ELEMENT root (middle) >\n^\nEntity: line 1: parser error : Start tag expected, '<' not found\n %defroot; \n ^\nEntity: line 1: \n<!ELEMENT root (middle) >\n ^\n\n```\n\n### result/valid/t8a.xml.err\n\n#### region() [lines 1-20]\n```c\nEntity: line 1: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration\n\n %defroot; \n ^\nEntity: line 1: \n<!ELEMENT root (middle) >\n^\nEntity: line 1: parser error : DOCTYPE improperly terminated\n %defroot; \n ^\nEntity: line 1: \n<!ELEMENT root (middle) >\n^\nEntity: line 1: parser error : Start tag expected, '<' not found\n %defroot; \n ^\nEntity: line 1: \n<!ELEMENT root (middle) >\n ^\n\n```\n\n\n## Upstream Fix\n```diff\nFrom a7a94612aa3b16779e2c74e1fa353b5d9786c602 Mon Sep 17 00:00:00 2001\nFrom: Daniel Veillard \nDate: Tue, 9 Feb 2016 12:55:29 +0100\nSubject: [PATCH] Heap-based buffer overread in xmlNextChar\n\nFor https://bugzilla.gnome.org/show_bug.cgi?id=759671\n\nwhen the end of the internal subset isn't properly detected\nxmlParseInternalSubset should just return instead of trying\nto process input further.\n---\n parser.c | 1 +\n result/errors/754946.xml.err | 10 +++++-----\n result/errors/content1.xml.err | 2 +-\n result/valid/t8.xml.err | 2 +-\n result/valid/t8a.xml.err | 2 +-\n 5 files changed, 9 insertions(+), 8 deletions(-)\n\ndiff --git a/parser.c b/parser.c\nindex c5741e3b8c..0677030c2d 100644\n--- a/parser.c\n+++ b/parser.c\n@@ -8468,6 +8468,7 @@ xmlParseInternalSubset(xmlParserCtxtPtr ctxt) {\n */\n if (RAW != '>') {\n \txmlFatalErr(ctxt, XML_ERR_DOCTYPE_NOT_FINISHED, NULL);\n+\treturn;\n }\n NEXT;\n }\ndiff --git a/result/errors/754946.xml.err b/result/errors/754946.xml.err\nindex a75088b982..c03e35bf76 100644\n--- a/result/errors/754946.xml.err\n+++ b/result/errors/754946.xml.err\n@@ -11,9 +11,9 @@ Entity: line 1: parser error : DOCTYPE improperly terminated\n Entity: line 1: \n A%SYSTEM;%SYSTEM;\n- ^\n+ ^\ndiff --git a/result/valid/t8.xml.err b/result/valid/t8.xml.err\nindex d795788c88..1a3c006d40 100644\n--- a/result/valid/t8.xml.err\n+++ b/result/valid/t8.xml.err\n@@ -16,4 +16,4 @@ Entity: line 1: parser error : Start tag expected, '<' not found\n ^\n Entity: line 1: \n <!ELEMENT root (middle) >\n- ^\n+^\ndiff --git a/result/valid/t8a.xml.err b/result/valid/t8a.xml.err\nindex d795788c88..1a3c006d40 100644\n--- a/result/valid/t8a.xml.err\n+++ b/result/valid/t8a.xml.err\n@@ -16,4 +16,4 @@ Entity: line 1: parser error : Start tag expected, '<' not found\n ^\n Entity: line 1: \n <!ELEMENT root (middle) >\n- ^\n+^\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From a7a94612aa3b16779e2c74e1fa353b5d9786c602 Mon Sep 17 00:00:00 2001\nFrom: Daniel Veillard \nDate: Tue, 9 Feb 2016 12:55:29 +0100\nSubject: Heap-based buffer overread in xmlNextChar\n\nFor https://bugzilla.gnome.org/show_bug.cgi?id=759671\n\nwhen the end of the internal subset isn't properly detected\nxmlParseInternalSubset should just return instead of trying\nto process input further.\n---\n parser.c | 1 +\n result/errors/content1.xml.err | 2 +-\n result/valid/t8.xml.err | 2 +-\n result/valid/t8a.xml.err | 2 +-\n 5 files changed, 9 insertions(+), 8 deletions(-)\n\nIndex: libxml2-2.9.1/parser.c\n===================================================================\n--- libxml2-2.9.1.orig/parser.c\n+++ libxml2-2.9.1/parser.c\n@@ -8437,6 +8437,7 @@ xmlParseInternalSubset(xmlParserCtxtPtr\n */\n if (RAW != '>') {\n \txmlFatalErr(ctxt, XML_ERR_DOCTYPE_NOT_FINISHED, NULL);\n+\treturn;\n }\n NEXT;\n }\nIndex: libxml2-2.9.1/result/errors/content1.xml.err\n===================================================================\n--- libxml2-2.9.1.orig/result/errors/content1.xml.err\n+++ libxml2-2.9.1/result/errors/content1.xml.err\n@@ -13,4 +13,4 @@\n ^\n ./test/errors/content1.xml:7: parser error : Start tag expected, '<' not found\n \n- ^\n+ ^\nIndex: libxml2-2.9.1/result/valid/t8.xml.err\n===================================================================\n--- libxml2-2.9.1.orig/result/valid/t8.xml.err\n+++ libxml2-2.9.1/result/valid/t8.xml.err\n@@ -16,4 +16,4 @@ Entity: line 1: parser error : Start tag\n ^\n Entity: line 1: \n <!ELEMENT root (middle) >\n- ^\n+^\nIndex: libxml2-2.9.1/result/valid/t8a.xml.err\n===================================================================\n--- libxml2-2.9.1.orig/result/valid/t8a.xml.err\n+++ libxml2-2.9.1/result/valid/t8a.xml.err\n@@ -16,4 +16,4 @@ Entity: line 1: parser error : Start tag\n ^\n Entity: line 1: \n <!ELEMENT root (middle) >\n- ^\n+^"}], "metadata": {"id": "libxml2-5762-libxml2-2.9.1-CVE-2016-1762.pa", "cve_id": "CVE-2016-4658", "package": "libxml2", "upstream_enriched": true, "upstream_commit": "a7a94612aa3b16779e2c74e1fa353b5d9786c602", "upstream_repo": "GNOME/libxml2", "tier": "adapted", "has_source_context": true, "context_tokens_est": 471, "context_files": 4, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-4658\n\nxpointer.c in libxml2 before 2.9.5 (as used in Apple iOS before 10, OS X before 10.12, tvOS before 10, and watchOS before 3, and other products) does not forbid namespace nodes in XPointer ranges, which allows remote attackers to execute arbitrary code or cause a denial of service (use-after-free and memory corruption) via a crafted XML document.\n\n## Package\nlibxml2\n\n## Files to modify\n- parser.c\n\n## Target Source Code\n\n### parser.c\n\n#### xmlParseReference() [lines 7196-7078]\n```c\n\n```\n\n\n## Upstream Fix\n```diff\nFrom 72a46a519ce7326d9a00f0b6a7f2a8e958cd1675 Mon Sep 17 00:00:00 2001\nFrom: Daniel Veillard \nDate: Thu, 23 Oct 2014 11:35:36 +0800\nSubject: [PATCH] Fix missing entities after CVE-2014-3660 fix\n\nFor https://bugzilla.gnome.org/show_bug.cgi?id=738805\n\nThe fix for CVE-2014-3660 introduced a regression in some case\nwhere entity substitution is required and the entity is used\nfirst in anotther entity referenced from an attribute value\n---\n parser.c | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/parser.c b/parser.c\nindex 67c9dfd9ad..a8d1b67316 100644\n--- a/parser.c\n+++ b/parser.c\n@@ -7235,7 +7235,8 @@ xmlParseReference(xmlParserCtxtPtr ctxt) {\n * far more secure as the parser will only process data coming from\n * the document entity by default.\n */\n- if ((ent->checked == 0) &&\n+ if (((ent->checked == 0) ||\n+ ((ent->children == NULL) && (ctxt->options & XML_PARSE_NOENT))) &&\n ((ent->etype != XML_EXTERNAL_GENERAL_PARSED_ENTITY) ||\n (ctxt->options & (XML_PARSE_NOENT | XML_PARSE_DTDVALID)))) {\n \tunsigned long oldnbent = ctxt->nbentities;\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From 72a46a519ce7326d9a00f0b6a7f2a8e958cd1675 Mon Sep 17 00:00:00 2001\nFrom: Daniel Veillard \nDate: Thu, 23 Oct 2014 11:35:36 +0800\nSubject: [PATCH 1/2] Fix missing entities after CVE-2014-3660 fix\n\nFor https://bugzilla.gnome.org/show_bug.cgi?id=738805\n\nThe fix for CVE-2014-3660 introduced a regression in some case\nwhere entity substitution is required and the entity is used\nfirst in anotther entity referenced from an attribute value\n---\n parser.c | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/parser.c b/parser.c\nindex 67c9dfd..a8d1b67 100644\n--- a/parser.c\n+++ b/parser.c\n@@ -7235,7 +7235,8 @@ xmlParseReference(xmlParserCtxtPtr ctxt) {\n * far more secure as the parser will only process data coming from\n * the document entity by default.\n */\n- if ((ent->checked == 0) &&\n+ if (((ent->checked == 0) ||\n+ ((ent->children == NULL) && (ctxt->options & XML_PARSE_NOENT))) &&\n ((ent->etype != XML_EXTERNAL_GENERAL_PARSED_ENTITY) ||\n (ctxt->options & (XML_PARSE_NOENT | XML_PARSE_DTDVALID)))) {\n \tunsigned long oldnbent = ctxt->nbentities;\n-- \n2.1.2"}], "metadata": {"id": "libxml2-5762-0001-Fix-missing-entities-afte", "cve_id": "CVE-2016-4658", "package": "libxml2", "upstream_enriched": true, "upstream_commit": "72a46a519ce7326d9a00f0b6a7f2a8e958cd1675", "upstream_repo": "GNOME/libxml2", "tier": "adapted", "has_source_context": true, "context_tokens_est": 16, "context_files": 1, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-4658\n\nxpointer.c in libxml2 before 2.9.5 (as used in Apple iOS before 10, OS X before 10.12, tvOS before 10, and watchOS before 3, and other products) does not forbid namespace nodes in XPointer ranges, which allows remote attackers to execute arbitrary code or cause a denial of service (use-after-free and memory corruption) via a crafted XML document.\n\n## Package\nlibxml2\n\n## Files to modify\n- parser.c\n- libxml2-2.9.1.orig/parser.c\n\n## Target Source Code\n\n### parser.c\n\n#### xmlParseConditionalSections() [lines 6839-6926]\n```c\n *\n * parse an HTML document from I/O functions and source and build a tree.\n *\n * Returns the resulting document tree\n */\nhtmlDocPtr\nhtmlReadIO(xmlInputReadCallback ioread, xmlInputCloseCallback ioclose,\n void *ioctx, const char *URL, const char *encoding, int options)\n{\n htmlParserCtxtPtr ctxt;\n xmlParserInputBufferPtr input;\n xmlParserInputPtr stream;\n\n if (ioread == NULL)\n return (NULL);\n xmlInitParser();\n\n input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,\n XML_CHAR_ENCODING_NONE);\n if (input == NULL) {\n if (ioclose != NULL)\n ioclose(ioctx);\n return (NULL);\n }\n ctxt = htmlNewParserCtxt();\n if (ctxt == NULL) {\n xmlFreeParserInputBuffer(input);\n return (NULL);\n }\n stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE);\n if (stream == NULL) {\n xmlFreeParserInputBuffer(input);\n\txmlFreeParserCtxt(ctxt);\n return (NULL);\n }\n inputPush(ctxt, stream);\n return (htmlDoRead(ctxt, URL, encoding, options, 0));\n}\n\n/**\n * htmlCtxtReadDoc:\n * @ctxt: an HTML parser context\n * @cur: a pointer to a zero terminated string\n * @URL: the base URL to use for the document\n * @encoding: the document encoding, or NULL\n * @options: a combination of htmlParserOption(s)\n *\n * parse an XML in-memory document and build a tree.\n * This reuses the existing @ctxt parser context\n *\n * Returns the resulting document tree\n */\nhtmlDocPtr\nhtmlCtxtReadDoc(htmlParserCtxtPtr ctxt, const xmlChar * cur,\n const char *URL, const char *encoding, int options)\n{\n xmlParserInputPtr stream;\n\n if (cur == NULL)\n return (NULL);\n if (ctxt == NULL)\n return (NULL);\n\n htmlCtxtReset(ctxt);\n\n stream = xmlNewStringInputStream(ctxt, cur);\n if (stream == NULL) {\n return (NULL);\n }\n inputPush(ctxt, stream);\n return (htmlDoRead(ctxt, URL, encoding, options, 1));\n}\n\n/**\n * htmlCtxtReadFile:\n * @ctxt: an HTML parser context\n * @filename: a file or URL\n * @encoding: the document encoding, or NULL\n * @options: a combination of htmlParserOption(s)\n *\n * parse an XML file from the filesystem or the network.\n * This reuses the existing @ctxt parser context\n *\n * Returns the resulting document tree\n */\nhtmlDocPtr\nhtmlCtxtReadFile(htmlParserCtxtPtr ctxt, const char *filename,\n const char *encoding, int options)\n```\n\n\n## Upstream Fix\n```diff\nIndex: libxml2-2.9.1/parser.c\n===================================================================\n--- libxml2-2.9.1.orig/parser.c\n+++ libxml2-2.9.1/parser.c\n@@ -6878,7 +6878,9 @@ xmlParseConditionalSections(xmlParserCtx\n \t\"All markup of the conditional section is not in the same entity\\n\",\n \t\t\t\t NULL, NULL);\n \t}\n- SKIP(3);\n+\tif ((ctxt-> instate != XML_PARSER_EOF) &&\n+\t ((ctxt->input->cur + 3) <= ctxt->input->end))\n+\t SKIP(3);\n }\n }\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "Index: libxml2-2.9.1/parser.c\n===================================================================\n--- libxml2-2.9.1.orig/parser.c\n+++ libxml2-2.9.1/parser.c\n@@ -6878,7 +6878,9 @@ xmlParseConditionalSections(xmlParserCtx\n \t\"All markup of the conditional section is not in the same entity\\n\",\n \t\t\t\t NULL, NULL);\n \t}\n- SKIP(3);\n+\tif ((ctxt-> instate != XML_PARSER_EOF) &&\n+\t ((ctxt->input->cur + 3) <= ctxt->input->end))\n+\t SKIP(3);\n }\n }"}], "metadata": {"id": "libxml2-5762-libxml2-2.9.1-CVE-2015-7942.pa", "cve_id": "CVE-2016-4658", "package": "libxml2", "tier": "identical", "has_source_context": true, "context_tokens_est": 630, "context_files": 1, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2014-3609\n\nHttpHdrRange.cc in Squid 3.x before 3.3.12 and 3.4.x before 3.4.6 allows remote attackers to cause a denial of service (crash) via a request with crafted \"Range headers with unidentifiable byte-range values.\"\n\n## Package\nsquid\n\n## Upstream Fix\n```diff\n------------------------------------------------------------\nrevno: 11828\nrevision-id: squid3@treenet.co.nz-20140827143622-aj6y1q5khr7txsa7\nparent: squid3@treenet.co.nz-20130713132208-e91nzzf0usz2ytp6\ncommitter: Amos Jeffries \nbranch nick: 3.2\ntimestamp: Wed 2014-08-27 08:36:22 -0600\nmessage:\n Ignore Range headers with unidentifiable byte-range values\n \n If squid is unable to determine the byte value for ranges, treat the\n header as invalid.\n------------------------------------------------------------\n# Bazaar merge directive format 2 (Bazaar 0.90)\n# revision_id: squid3@treenet.co.nz-20140827143622-aj6y1q5khr7txsa7\n# target_branch: http://bzr.squid-cache.org/bzr/squid3/branches\\\n# /SQUID_3_2\n# testament_sha1: befb9d196a5292711a18d9503d5c50a60f1fa66a\n# timestamp: 2014-08-27 14:36:44 +0000\n# source_branch: http://bzr.squid-cache.org/bzr/squid3/branches\\\n# /SQUID_3_2\n# base_revision_id: squid3@treenet.co.nz-20130713132208-\\\n# e91nzzf0usz2ytp6\n# \n# Begin patch\n=== modified file 'src/HttpHdrRange.cc'\n--- src/HttpHdrRange.cc\t2012-07-28 05:38:50 +0000\n+++ src/HttpHdrRange.cc\t2014-08-27 14:36:22 +0000\n@@ -93,7 +93,7 @@\n \n /* is it a suffix-byte-range-spec ? */\n if (*field == '-') {\n- if (!httpHeaderParseOffset(field + 1, &length))\n+ if (!httpHeaderParseOffset(field + 1, &length) || !known_spec(length))\n return false;\n } else\n /* must have a '-' somewhere in _this_ field */\n@@ -101,7 +101,7 @@\n debugs(64, 2, \"invalid (missing '-') range-spec near: '\" << field << \"'\");\n return false;\n } else {\n- if (!httpHeaderParseOffset(field, &offset))\n+ if (!httpHeaderParseOffset(field, &offset) || !known_spec(offset))\n return false;\n \n ++p;\n@@ -110,7 +110,7 @@\n if (p - field < flen) {\n int64_t last_pos;\n \n- if (!httpHeaderParseOffset(p, &last_pos))\n+ if (!httpHeaderParseOffset(p, &last_pos) || !known_spec(last_pos))\n return false;\n \n // RFC 2616 s14.35.1 MUST: last-byte-pos >= first-byte-pos\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "------------------------------------------------------------\nrevno: 11828\nrevision-id: squid3@treenet.co.nz-20140827143622-aj6y1q5khr7txsa7\nparent: squid3@treenet.co.nz-20130713132208-e91nzzf0usz2ytp6\ncommitter: Amos Jeffries \nbranch nick: 3.2\ntimestamp: Wed 2014-08-27 08:36:22 -0600\nmessage:\n Ignore Range headers with unidentifiable byte-range values\n \n If squid is unable to determine the byte value for ranges, treat the\n header as invalid.\n------------------------------------------------------------\n# Bazaar merge directive format 2 (Bazaar 0.90)\n# revision_id: squid3@treenet.co.nz-20140827143622-aj6y1q5khr7txsa7\n# target_branch: http://bzr.squid-cache.org/bzr/squid3/branches\\\n# /SQUID_3_2\n# testament_sha1: befb9d196a5292711a18d9503d5c50a60f1fa66a\n# timestamp: 2014-08-27 14:36:44 +0000\n# source_branch: http://bzr.squid-cache.org/bzr/squid3/branches\\\n# /SQUID_3_2\n# base_revision_id: squid3@treenet.co.nz-20130713132208-\\\n# e91nzzf0usz2ytp6\n# \n# Begin patch\n=== modified file 'src/HttpHdrRange.cc'\n--- src/HttpHdrRange.cc\t2012-07-28 05:38:50 +0000\n+++ src/HttpHdrRange.cc\t2014-08-27 14:36:22 +0000\n@@ -93,7 +93,7 @@\n \n /* is it a suffix-byte-range-spec ? */\n if (*field == '-') {\n- if (!httpHeaderParseOffset(field + 1, &length))\n+ if (!httpHeaderParseOffset(field + 1, &length) || !known_spec(length))\n return false;\n } else\n /* must have a '-' somewhere in _this_ field */\n@@ -101,7 +101,7 @@\n debugs(64, 2, \"invalid (missing '-') range-spec near: '\" << field << \"'\");\n return false;\n } else {\n- if (!httpHeaderParseOffset(field, &offset))\n+ if (!httpHeaderParseOffset(field, &offset) || !known_spec(offset))\n return false;\n \n ++p;\n@@ -110,7 +110,7 @@\n if (p - field < flen) {\n int64_t last_pos;\n \n- if (!httpHeaderParseOffset(p, &last_pos))\n+ if (!httpHeaderParseOffset(p, &last_pos) || !known_spec(last_pos))\n return false;\n \n // RFC 2616 s14.35.1 MUST: last-byte-pos >= first-byte-pos"}], "metadata": {"id": "squid-2990-squid-3.2.x-11828-bnc893649-CV", "cve_id": "CVE-2014-3609", "package": "squid", "tier": "identical", "has_source_context": false, "license": "GPL-2.0-or-later"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2012-2142\n\nThe error function in Error.cc in poppler before 0.21.4 allows remote attackers to execute arbitrary commands via a PDF containing an escape sequence for a terminal emulator.\n\n## Package\npoppler-qt\n\n## Upstream Fix\n```diff\nFrom 71bad47ed6a36d825b0d08992c8db56845c71e40 Mon Sep 17 00:00:00 2001\nFrom: Marek Kasik \nDate: Sun, 09 Dec 2012 19:20:00 +0000\nSubject: Filter stuff that might end up in the shell\n\nSince it seems shells don't know how to filter stuff and might causing bad things to happen\n---\ndiff --git a/poppler/Error.cc b/poppler/Error.cc\nindex 9d044bc..ce71820 100644\n--- a/poppler/Error.cc\n+++ b/poppler/Error.cc\n@@ -16,6 +16,7 @@\n // Copyright (C) 2005, 2007 Jeff Muizelaar \n // Copyright (C) 2005 Albert Astals Cid \n // Copyright (C) 2007 Krzysztof Kowalczyk \n+// Copyright (C) 2012 Marek Kasik \n //\n // To see a description of the changes please see the Changelog file that\n // came with your tarball or type make ChangeLog if you are building from git\n@@ -59,7 +60,7 @@ void setErrorCallback(void (*cbk)(void *data, ErrorCategory category,\n \n void CDECL error(ErrorCategory category, int pos, const char *msg, ...) {\n va_list args;\n- GooString *s;\n+ GooString *s, *sanitized;\n \n // NB: this can be called before the globalParams object is created\n if (!errorCbk && globalParams && globalParams->getErrQuiet()) {\n@@ -68,17 +69,29 @@ void CDECL error(ErrorCategory category, int pos, const char *msg, ...) {\n va_start(args, msg);\n s = GooString::formatv(msg, args);\n va_end(args);\n+\n+ sanitized = new GooString ();\n+ for (int i = 0; i < s->getLength(); ++i) {\n+ const char c = s->getChar(i);\n+ if (c < (char)0x20 || c >= (char)0x7f) {\n+ sanitized->appendf(\"<{0:02x}>\", c & 0xff);\n+ } else {\n+ sanitized->append(c);\n+ }\n+ }\n+\n if (errorCbk) {\n- (*errorCbk)(errorCbkData, category, pos, s->getCString());\n+ (*errorCbk)(errorCbkData, category, pos, sanitized->getCString());\n } else {\n if (pos >= 0) {\n fprintf(stderr, \"%s (%d): %s\\n\",\n-\t errorCategoryNames[category], pos, s->getCString());\n+\t errorCategoryNames[category], pos, sanitized->getCString());\n } else {\n fprintf(stderr, \"%s: %s\\n\",\n-\t errorCategoryNames[category], s->getCString());\n+\t errorCategoryNames[category], sanitized->getCString());\n }\n fflush(stderr);\n }\n delete s;\n+ delete sanitized;\n }\n--\ncgit v0.9.0.2-2-gbebe\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From 71bad47ed6a36d825b0d08992c8db56845c71e40 Mon Sep 17 00:00:00 2001\nFrom: Marek Kasik \nDate: Sun, 09 Dec 2012 19:20:00 +0000\nSubject: Filter stuff that might end up in the shell\n\nSince it seems shells don't know how to filter stuff and might causing bad things to happen\n---\ndiff --git a/poppler/Error.cc b/poppler/Error.cc\nindex 9d044bc..ce71820 100644\n--- a/poppler/Error.cc\n+++ b/poppler/Error.cc\n@@ -16,6 +16,7 @@\n // Copyright (C) 2005, 2007 Jeff Muizelaar \n // Copyright (C) 2005 Albert Astals Cid \n // Copyright (C) 2007 Krzysztof Kowalczyk \n+// Copyright (C) 2012 Marek Kasik \n //\n // To see a description of the changes please see the Changelog file that\n // came with your tarball or type make ChangeLog if you are building from git\n@@ -59,7 +60,7 @@ void setErrorCallback(void (*cbk)(void *data, ErrorCategory category,\n \n void CDECL error(ErrorCategory category, int pos, const char *msg, ...) {\n va_list args;\n- GooString *s;\n+ GooString *s, *sanitized;\n \n // NB: this can be called before the globalParams object is created\n if (!errorCbk && globalParams && globalParams->getErrQuiet()) {\n@@ -68,17 +69,29 @@ void CDECL error(ErrorCategory category, int pos, const char *msg, ...) {\n va_start(args, msg);\n s = GooString::formatv(msg, args);\n va_end(args);\n+\n+ sanitized = new GooString ();\n+ for (int i = 0; i < s->getLength(); ++i) {\n+ const char c = s->getChar(i);\n+ if (c < (char)0x20 || c >= (char)0x7f) {\n+ sanitized->appendf(\"<{0:02x}>\", c & 0xff);\n+ } else {\n+ sanitized->append(c);\n+ }\n+ }\n+\n if (errorCbk) {\n- (*errorCbk)(errorCbkData, category, pos, s->getCString());\n+ (*errorCbk)(errorCbkData, category, pos, sanitized->getCString());\n } else {\n if (pos >= 0) {\n fprintf(stderr, \"%s (%d): %s\\n\",\n-\t errorCategoryNames[category], pos, s->getCString());\n+\t errorCategoryNames[category], pos, sanitized->getCString());\n } else {\n fprintf(stderr, \"%s: %s\\n\",\n-\t errorCategoryNames[category], s->getCString());\n+\t errorCategoryNames[category], sanitized->getCString());\n }\n fflush(stderr);\n }\n delete s;\n+ delete sanitized;\n }\n--\ncgit v0.9.0.2-2-gbebe"}], "metadata": {"id": "poppler-qt-1943-poppler-bnc834476.patch", "cve_id": "CVE-2012-2142", "package": "poppler-qt", "tier": "identical", "has_source_context": false, "license": "GPL-2.0-only OR GPL-3.0-only"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-2804\n\nMultiple unspecified vulnerabilities in the browser engine in Mozilla Firefox before 46.0 allow remote attackers to cause a denial of service (memory corruption and application crash) or possibly execute arbitrary code via unknown vectors.\n\n## Package\nmozilla-nss\n\n## Files to modify\n- lib/ssl/sslsock.c\n\n## Upstream Fix\n```diff\ndiff --git a/lib/ssl/sslsock.c b/lib/ssl/sslsock.c\nindex e6b2387..87fbe1d 100644\n--- a/lib/ssl/sslsock.c\n+++ b/lib/ssl/sslsock.c\n@@ -74,7 +74,7 @@ static sslOptions ssl_defaults = {\n PR_FALSE, /* noLocks */\n PR_FALSE, /* enableSessionTickets */\n PR_FALSE, /* enableDeflate */\n- 2, /* enableRenegotiation (default: requires extension) */\n+ 3, /* enableRenegotiation (default: requires extension) */\n PR_FALSE, /* requireSafeNegotiation */\n PR_FALSE, /* enableFalseStart */\n PR_TRUE, /* cbcRandomIV */\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "diff --git a/lib/ssl/sslsock.c b/lib/ssl/sslsock.c\nindex e6b2387..87fbe1d 100644\n--- a/lib/ssl/sslsock.c\n+++ b/lib/ssl/sslsock.c\n@@ -74,7 +74,7 @@ static sslOptions ssl_defaults = {\n PR_FALSE, /* noLocks */\n PR_FALSE, /* enableSessionTickets */\n PR_FALSE, /* enableDeflate */\n- 2, /* enableRenegotiation (default: requires extension) */\n+ 3, /* enableRenegotiation (default: requires extension) */\n PR_FALSE, /* requireSafeNegotiation */\n PR_FALSE, /* enableFalseStart */\n PR_TRUE, /* cbcRandomIV */"}], "metadata": {"id": "mozilla-nss-5017-renegotiate-transitional.patch", "cve_id": "CVE-2016-2804", "package": "mozilla-nss", "tier": "identical", "has_source_context": false, "license": "MPL-2.0"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2013-4560\n\nUse-after-free vulnerability in lighttpd before 1.4.33 allows remote attackers to cause a denial of service (segmentation fault and crash) via unspecified vectors that trigger FAMMonitorDirectory failures.\n\n## Package\nlighttpd\n\n## Files to modify\n- src/server.c\n- lighttpd-1.4.33.orig/src/server.c\n\n## Target Source Code\n\n### src/server.c\n\n#### region() [lines 816-827]\n```c\n\t\t * Change group before chroot, when we have access\n\t\t * to /etc/group\n\t\t * */\n\t\tif (NULL != grp) {\n\t\t\tsetgid(grp->gr_gid);\n\t\t\tsetgroups(0, NULL);\n\t\t\tif (srv->srvconf.username->used) {\n\t\t\t\tinitgroups(srv->srvconf.username->ptr, grp->gr_gid);\n\t\t\t}\n\t\t}\n#endif\n#ifdef HAVE_CHROOT\n```\n\n#### region() [lines 840-847]\n```c\n#endif\n#ifdef HAVE_PWD_H\n\t\t/* drop root privs */\n\t\tif (NULL != pwd) {\n\t\t\tsetuid(pwd->pw_uid);\n\t\t}\n#endif\n#if defined(HAVE_SYS_PRCTL_H) && defined(PR_SET_DUMPABLE)\n```\n\n\n## Upstream Fix\n```diff\norigin: http://download.lighttpd.net/lighttpd/security/lighttpd_sa_2013_02.txt\n\ncommit d22f4164a9e26c252e1874a29ba658eec85a3ddc\nAuthor: Stefan Bühler \nDate: Sun Nov 10 19:00:08 2013 +0100\n\n [core] check success of setuid,setgid,setgroups\n\nIndex: lighttpd-1.4.33/src/server.c\n===================================================================\n--- lighttpd-1.4.33.orig/src/server.c\t2013-11-13 02:36:01.510535924 +0000\n+++ lighttpd-1.4.33/src/server.c\t2013-11-13 02:36:01.510535924 +0000\n@@ -820,8 +820,14 @@\n \t\t * to /etc/group\n \t\t * */\n \t\tif (NULL != grp) {\n-\t\t\tsetgid(grp->gr_gid);\n-\t\t\tsetgroups(0, NULL);\n+\t\t\tif (-1 == setgid(grp->gr_gid)) {\n+\t\t\t\tlog_error_write(srv, __FILE__, __LINE__, \"ss\", \"setgid failed: \", strerror(errno));\n+\t\t\t\treturn -1;\n+\t\t\t}\n+\t\t\tif (-1 == setgroups(0, NULL)) {\n+\t\t\t\tlog_error_write(srv, __FILE__, __LINE__, \"ss\", \"setgroups failed: \", strerror(errno));\n+\t\t\t\treturn -1;\n+\t\t\t}\n \t\t\tif (srv->srvconf.username->used) {\n \t\t\t\tinitgroups(srv->srvconf.username->ptr, grp->gr_gid);\n \t\t\t}\n@@ -844,7 +850,10 @@\n #ifdef HAVE_PWD_H\n \t\t/* drop root privs */\n \t\tif (NULL != pwd) {\n-\t\t\tsetuid(pwd->pw_uid);\n+\t\t\tif (-1 == setuid(pwd->pw_uid)) {\n+\t\t\t\tlog_error_write(srv, __FILE__, __LINE__, \"ss\", \"setuid failed: \", strerror(errno));\n+\t\t\t\treturn -1;\n+\t\t\t}\n \t\t}\n #endif\n #if defined(HAVE_SYS_PRCTL_H) && defined(PR_SET_DUMPABLE)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "origin: http://download.lighttpd.net/lighttpd/security/lighttpd_sa_2013_02.txt\n\ncommit d22f4164a9e26c252e1874a29ba658eec85a3ddc\nAuthor: Stefan Bühler \nDate: Sun Nov 10 19:00:08 2013 +0100\n\n [core] check success of setuid,setgid,setgroups\n\nIndex: lighttpd-1.4.33/src/server.c\n===================================================================\n--- lighttpd-1.4.33.orig/src/server.c\t2013-11-13 02:36:01.510535924 +0000\n+++ lighttpd-1.4.33/src/server.c\t2013-11-13 02:36:01.510535924 +0000\n@@ -820,8 +820,14 @@\n \t\t * to /etc/group\n \t\t * */\n \t\tif (NULL != grp) {\n-\t\t\tsetgid(grp->gr_gid);\n-\t\t\tsetgroups(0, NULL);\n+\t\t\tif (-1 == setgid(grp->gr_gid)) {\n+\t\t\t\tlog_error_write(srv, __FILE__, __LINE__, \"ss\", \"setgid failed: \", strerror(errno));\n+\t\t\t\treturn -1;\n+\t\t\t}\n+\t\t\tif (-1 == setgroups(0, NULL)) {\n+\t\t\t\tlog_error_write(srv, __FILE__, __LINE__, \"ss\", \"setgroups failed: \", strerror(errno));\n+\t\t\t\treturn -1;\n+\t\t\t}\n \t\t\tif (srv->srvconf.username->used) {\n \t\t\t\tinitgroups(srv->srvconf.username->ptr, grp->gr_gid);\n \t\t\t}\n@@ -844,7 +850,10 @@\n #ifdef HAVE_PWD_H\n \t\t/* drop root privs */\n \t\tif (NULL != pwd) {\n-\t\t\tsetuid(pwd->pw_uid);\n+\t\t\tif (-1 == setuid(pwd->pw_uid)) {\n+\t\t\t\tlog_error_write(srv, __FILE__, __LINE__, \"ss\", \"setuid failed: \", strerror(errno));\n+\t\t\t\treturn -1;\n+\t\t\t}\n \t\t}\n #endif\n #if defined(HAVE_SYS_PRCTL_H) && defined(PR_SET_DUMPABLE)"}], "metadata": {"id": "lighttpd-2374-cve-2013-4559.patch", "cve_id": "CVE-2013-4560", "package": "lighttpd", "tier": "identical", "has_source_context": true, "context_tokens_est": 134, "context_files": 1, "license": "BSD-3-Clause"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- crypto/bio/b_print.c\n\n## Target Source Code\n\n### crypto/bio/b_print.c\n\n#### region() [lines 17-114]\n```c\n * the code are not to be removed.\n * If this package is used in a product, Eric Young should be given attribution\n * as the author of the parts of the library used.\n * This can be in the form of a textual message at program startup or\n * in documentation (online or textual) provided with the package.\n * \n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions\n * are met:\n * 1. Redistributions of source code must retain the copyright\n * notice, this list of conditions and the following disclaimer.\n * 2. Redistributions in binary form must reproduce the above copyright\n * notice, this list of conditions and the following disclaimer in the\n * documentation and/or other materials provided with the distribution.\n * 3. All advertising materials mentioning features or use of this software\n * must display the following acknowledgement:\n * \"This product includes cryptographic software written by\n * Eric Young (eay@cryptsoft.com)\"\n * The word 'cryptographic' can be left out if the rouines from the library\n * being used are not cryptographic related :-).\n * 4. If you include any Windows specific code (or a derivative thereof) from \n * the apps directory (application code) you must include an acknowledgement:\n * \"This product includes software written by Tim Hudson (tjh@cryptsoft.com)\"\n * \n * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\n * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\n * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n * SUCH DAMAGE.\n * \n * The licence and distribution terms for any publically available version or\n * derivative of this code cannot be changed. i.e. this code cannot simply be\n * copied and put under another distribution licence\n * [including the GNU Public Licence.]\n */\n\n/* disable assert() unless BIO_DEBUG has been defined */\n#ifndef BIO_DEBUG\n# ifndef NDEBUG\n# define NDEBUG\n# endif\n#endif\n\n/* \n * Stolen from tjh's ssl/ssl_trc.c stuff.\n */\n\n#include \n#include \n#include \n#include \n#include \n#include \"cryptlib.h\"\n#ifndef NO_SYS_TYPES_H\n#include \n#endif\n#include /* To get BN_LLONG properly defined */\n#include \n\n#if defined(BN_LLONG) || defined(SIXTY_FOUR_BIT)\n# ifndef HAVE_LONG_LONG\n# define HAVE_LONG_LONG 1\n# endif\n#endif\n\n/***************************************************************************/\n\n/*\n * Copyright Patrick Powell 1995\n * This code is based on code written by Patrick Powell \n * It may be used for any purpose as long as this notice remains intact\n * on all source code distributions.\n */\n\n/*\n * This code contains numerious changes and enhancements which were\n * made by lots of contributors over the last years to Patrick Powell's\n * original code:\n *\n * o Patrick Powell (1995)\n * o Brandon Long (1996, for Mutt)\n * o Thomas Roessler (1998, for Mutt)\n * o Michael Elkins (1998, for Mutt)\n * o Andrew Tridgell (1998, for Samba)\n * o Luke Mewburn (1999, for LukemFTP)\n * o Ralf S. Engelschall (1999, for Pth)\n * o ... (for OpenSSL)\n */\n\n#ifdef HAVE_LONG_DOUBLE\n#define LDOUBLE long double\n#else\n```\n\n#### region() [lines 40-810]\n```c\n * \n * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\n * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\n * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n * SUCH DAMAGE.\n * \n * The licence and distribution terms for any publically available version or\n * derivative of this code cannot be changed. i.e. this code cannot simply be\n * copied and put under another distribution licence\n * [including the GNU Public Licence.]\n */\n\n/* disable assert() unless BIO_DEBUG has been defined */\n#ifndef BIO_DEBUG\n# ifndef NDEBUG\n# define NDEBUG\n# endif\n#endif\n\n/* \n * Stolen from tjh's ssl/ssl_trc.c stuff.\n */\n\n#include \n#include \n#include \n#include \n#include \n#include \"cryptlib.h\"\n#ifndef NO_SYS_TYPES_H\n#include \n#endif\n#include /* To get BN_LLONG properly defined */\n#include \n\n#if defined(BN_LLONG) || defined(SIXTY_FOUR_BIT)\n# ifndef HAVE_LONG_LONG\n# define HAVE_LONG_LONG 1\n# endif\n#endif\n\n/***************************************************************************/\n\n/*\n * Copyright Patrick Powell 1995\n * This code is based on code written by Patrick Powell \n * It may be used for any purpose as long as this notice remains intact\n * on all source code distributions.\n */\n\n/*\n * This code contains numerious changes and enhancements which were\n * made by lots of contributors over the last years to Patrick Powell's\n * original code:\n *\n * o Patrick Powell (1995)\n * o Brandon Long (1996, for Mutt)\n * o Thomas Roessler (1998, for Mutt)\n * o Michael Elkins (1998, for Mutt)\n * o Andrew Tridgell (1998, for Samba)\n * o Luke Mewburn (1999, for LukemFTP)\n * o Ralf S. Engelschall (1999, for Pth)\n * o ... (for OpenSSL)\n */\n\n#ifdef HAVE_LONG_DOUBLE\n#define LDOUBLE long double\n#else\n#define LDOUBLE double\n#endif\n\n#ifdef HAVE_LONG_LONG\n# if defined(_WIN32) && !defined(__GNUC__)\n# define LLONG __int64\n# else\n# define LLONG long long\n# endif\n#else\n#define LLONG long\n#endif\n\nstatic void fmtstr (char **, char **, size_t *, size_t *,\n\t\t\tconst char *, int, int, int);\nstatic void fmtint (char **, char **, size_t *, size_t *,\n\t\t\tLLONG, int, int, int, int);\nstatic void fmtfp (char **, char **, size_t *, size_t *,\n\t\t\tLDOUBLE, int, int, int);\nstatic void doapr_outch (char **, char **, size_t *, size_t *, int);\nstatic void _dopr(char **sbuffer, char **buffer,\n\t\t size_t *maxlen, size_t *retlen, int *truncated,\n\t\t const char *format, va_list args);\n\n/* format read states */\n#define DP_S_DEFAULT 0\n#define DP_S_FLAGS 1\n#define DP_S_MIN 2\n#define DP_S_DOT 3\n#define DP_S_MAX 4\n#define DP_S_MOD 5\n#define DP_S_CONV 6\n#define DP_S_DONE 7\n\n/* format flags - Bits */\n#define DP_F_MINUS (1 << 0)\n#define DP_F_PLUS (1 << 1)\n#define DP_F_SPACE (1 << 2)\n#define DP_F_NUM (1 << 3)\n#define DP_F_ZERO (1 << 4)\n#define DP_F_UP (1 << 5)\n#define DP_F_UNSIGNED (1 << 6)\n\n/* conversion flags */\n#define DP_C_SHORT 1\n#define DP_C_LONG 2\n#define DP_C_LDOUBLE 3\n#define DP_C_LLONG 4\n\n/* some handy macros */\n#define char_to_int(p) (p - '0')\n#define OSSL_MAX(p,q) ((p >= q) ? p : q)\n\nstatic void\n_dopr(\n char **sbuffer,\n char **buffer,\n size_t *maxlen,\n size_t *retlen,\n int *truncated,\n const char *format,\n va_list args)\n{\n char ch;\n LLONG value;\n LDOUBLE fvalue;\n char *strvalue;\n int min;\n int max;\n int state;\n int flags;\n int cflags;\n size_t currlen;\n\n state = DP_S_DEFAULT;\n flags = currlen = cflags = min = 0;\n max = -1;\n ch = *format++;\n\n while (state != DP_S_DONE) {\n if (ch == '\\0' || (buffer == NULL && currlen >= *maxlen))\n state = DP_S_DONE;\n\n switch (state) {\n case DP_S_DEFAULT:\n if (ch == '%')\n state = DP_S_FLAGS;\n else\n doapr_outch(sbuffer,buffer, &currlen, maxlen, ch);\n ch = *format++;\n break;\n case DP_S_FLAGS:\n switch (ch) {\n case '-':\n flags |= DP_F_MINUS;\n ch = *format++;\n break;\n case '+':\n flags |= DP_F_PLUS;\n ch = *format++;\n break;\n case ' ':\n flags |= DP_F_SPACE;\n ch = *format++;\n break;\n case '#':\n flags |= DP_F_NUM;\n ch = *format++;\n break;\n case '0':\n flags |= DP_F_ZERO;\n ch = *format++;\n break;\n default:\n state = DP_S_MIN;\n break;\n }\n break;\n case DP_S_MIN:\n if (isdigit((unsigned char)ch)) {\n min = 10 * min + char_to_int(ch);\n ch = *format++;\n } else if (ch == '*') {\n min = va_arg(args, int);\n ch = *format++;\n state = DP_S_DOT;\n } else\n state = DP_S_DOT;\n break;\n case DP_S_DOT:\n if (ch == '.') {\n state = DP_S_MAX;\n ch = *format++;\n } else\n state = DP_S_MOD;\n break;\n case DP_S_MAX:\n if (isdigit((unsigned char)ch)) {\n if (max < 0)\n max = 0;\n max = 10 * max + char_to_int(ch);\n ch = *format++;\n } else if (ch == '*') {\n max = va_arg(args, int);\n ch = *format++;\n state = DP_S_MOD;\n } else\n state = DP_S_MOD;\n break;\n case DP_S_MOD:\n switch (ch) {\n case 'h':\n cflags = DP_C_SHORT;\n ch = *format++;\n break;\n case 'l':\n if (*format == 'l') {\n cflags = DP_C_LLONG;\n format++;\n } else\n cflags = DP_C_LONG;\n ch = *format++;\n break;\n case 'q':\n cflags = DP_C_LLONG;\n ch = *format++;\n break;\n case 'L':\n cflags = DP_C_LDOUBLE;\n ch = *format++;\n break;\n default:\n break;\n }\n state = DP_S_CONV;\n break;\n case DP_S_CONV:\n switch (ch) {\n case 'd':\n case 'i':\n switch (cflags) {\n case DP_C_SHORT:\n value = (short int)va_arg(args, int);\n break;\n case DP_C_LONG:\n value = va_arg(args, long int);\n break;\n case DP_C_LLONG:\n value = va_arg(args, LLONG);\n break;\n default:\n value = va_arg(args, int);\n break;\n }\n fmtint(sbuffer, buffer, &currlen, maxlen,\n value, 10, min, max, flags);\n break;\n case 'X':\n flags |= DP_F_UP;\n /* FALLTHROUGH */\n case 'x':\n case 'o':\n case 'u':\n flags |= DP_F_UNSIGNED;\n switch (cflags) {\n case DP_C_SHORT:\n value = (unsigned short int)va_arg(args, unsigned int);\n break;\n case DP_C_LONG:\n value = (LLONG) va_arg(args,\n unsigned long int);\n break;\n case DP_C_LLONG:\n value = va_arg(args, unsigned LLONG);\n break;\n default:\n value = (LLONG) va_arg(args,\n unsigned int);\n break;\n }\n fmtint(sbuffer, buffer, &currlen, maxlen, value,\n ch == 'o' ? 8 : (ch == 'u' ? 10 : 16),\n min, max, flags);\n break;\n case 'f':\n if (cflags == DP_C_LDOUBLE)\n fvalue = va_arg(args, LDOUBLE);\n else\n fvalue = va_arg(args, double);\n fmtfp(sbuffer, buffer, &currlen, maxlen,\n fvalue, min, max, flags);\n break;\n case 'E':\n flags |= DP_F_UP;\n case 'e':\n if (cflags == DP_C_LDOUBLE)\n fvalue = va_arg(args, LDOUBLE);\n else\n fvalue = va_arg(args, double);\n break;\n case 'G':\n flags |= DP_F_UP;\n case 'g':\n if (cflags == DP_C_LDOUBLE)\n fvalue = va_arg(args, LDOUBLE);\n else\n fvalue = va_arg(args, double);\n break;\n case 'c':\n doapr_outch(sbuffer, buffer, &currlen, maxlen,\n va_arg(args, int));\n break;\n case 's':\n strvalue = va_arg(args, char *);\n if (max < 0) {\n\t\t if (buffer)\n\t\t\tmax = INT_MAX;\n\t\t else\n\t\t\tmax = *maxlen;\n\t\t}\n fmtstr(sbuffer, buffer, &currlen, maxlen, strvalue,\n flags, min, max);\n break;\n case 'p':\n value = (long)va_arg(args, void *);\n fmtint(sbuffer, buffer, &currlen, maxlen,\n value, 16, min, max, flags|DP_F_NUM);\n break;\n case 'n': /* XXX */\n if (cflags == DP_C_SHORT) {\n short int *num;\n num = va_arg(args, short int *);\n *num = currlen;\n } else if (cflags == DP_C_LONG) { /* XXX */\n long int *num;\n num = va_arg(args, long int *);\n *num = (long int) currlen;\n } else if (cflags == DP_C_LLONG) { /* XXX */\n LLONG *num;\n num = va_arg(args, LLONG *);\n *num = (LLONG) currlen;\n } else {\n int *num;\n num = va_arg(args, int *);\n *num = currlen;\n }\n break;\n case '%':\n doapr_outch(sbuffer, buffer, &currlen, maxlen, ch);\n break;\n case 'w':\n /* not supported yet, treat as next char */\n ch = *format++;\n break;\n default:\n /* unknown, skip */\n break;\n }\n ch = *format++;\n state = DP_S_DEFAULT;\n flags = cflags = min = 0;\n max = -1;\n break;\n case DP_S_DONE:\n break;\n default:\n break;\n }\n }\n *truncated = (currlen > *maxlen - \n/* ... truncated ... */\n\n## Upstream Fix\n```diff\nFrom fd708c2242408187cff392e8b0850275ac99376f Mon Sep 17 00:00:00 2001\nFrom: =?UTF-8?q?Cristian=20Rodr=C3=ADguez?= \nDate: Sun, 4 May 2014 23:36:54 -0400\nSubject: [PATCH] Axe builtin printf implementation, use glibc instead\n\n\ndiff --git a/crypto/bio/b_print.c b/crypto/bio/b_print.c\nindex 143a7cf..657beb7 100644\n--- a/crypto/bio/b_print.c\n+++ b/crypto/bio/b_print.c\n@@ -56,17 +56,9 @@\n * [including the GNU Public Licence.]\n */\n \n-/* disable assert() unless BIO_DEBUG has been defined */\n-#ifndef BIO_DEBUG\n-# ifndef NDEBUG\n-# define NDEBUG\n-# endif\n+#ifndef _GNU_SOURCE\n+#define _GNU_SOURCE\n #endif\n-\n-/* \n- * Stolen from tjh's ssl/ssl_trc.c stuff.\n- */\n-\n #include \n #include \n #include \n@@ -79,690 +71,6 @@\n #include /* To get BN_LLONG properly defined */\n #include \n \n-#if defined(BN_LLONG) || defined(SIXTY_FOUR_BIT)\n-# ifndef HAVE_LONG_LONG\n-# define HAVE_LONG_LONG 1\n-# endif\n-#endif\n-\n-/***************************************************************************/\n-\n-/*\n- * Copyright Patrick Powell 1995\n- * This code is based on code written by Patrick Powell \n- * It may be used for any purpose as long as this notice remains intact\n- * on all source code distributions.\n- */\n-\n-/*\n- * This code contains numerious changes and enhancements which were\n- * made by lots of contributors over the last years to Patrick Powell's\n- * original code:\n- *\n- * o Patrick Powell (1995)\n- * o Brandon Long (1996, for Mutt)\n- * o Thomas Roessler (1998, for Mutt)\n- * o Michael Elkins (1998, for Mutt)\n- * o Andrew Tridgell (1998, for Samba)\n- * o Luke Mewburn (1999, for LukemFTP)\n- * o Ralf S. Engelschall (1999, for Pth)\n- * o ... (for OpenSSL)\n- */\n-\n-#ifdef HAVE_LONG_DOUBLE\n-#define LDOUBLE long double\n-#else\n-#define LDOUBLE double\n-#endif\n-\n-#ifdef HAVE_LONG_LONG\n-# if defined(_WIN32) && !defined(__GNUC__)\n-# define LLONG __int64\n-# else\n-# define LLONG long long\n-# endif\n-#else\n-#define LLONG long\n-#endif\n-\n-static void fmtstr (char **, char **, size_t *, size_t *,\n-\t\t\tconst char *, int, int, int);\n-static void fmtint (char **, char **, size_t *, size_t *,\n-\t\t\tLLONG, int, int, int, int);\n-static void fmtfp (char **, char **, size_t *, size_t *,\n-\t\t\tLDOUBLE, int, int, int);\n-static void doapr_outch (char **, char **, size_t *, size_t *, int);\n-static void _dopr(char **sbuffer, char **buffer,\n-\t\t size_t *maxlen, size_t *retlen, int *truncated,\n-\t\t const char *format, va_list args);\n-\n-/* format read states */\n-#define DP_S_DEFAULT 0\n-#define DP_S_FLAGS 1\n-#define DP_S_MIN 2\n-#define DP_S_DOT 3\n-#define DP_S_MAX 4\n-#define DP_S_MOD 5\n-#define DP_S_CONV 6\n-#define DP_S_DONE 7\n-\n-/* format flags - Bits */\n-#define DP_F_MINUS (1 << 0)\n-#define DP_F_PLUS (1 << 1)\n-#define DP_F_SPACE (1 << 2)\n-#define DP_F_NUM (1 << 3)\n-#define DP_F_ZERO (1 << 4)\n-#define DP_F_UP (1 << 5)\n-#define DP_F_UNSIGNED (1 << 6)\n-\n-/* conversion flags */\n-#define DP_C_SHORT 1\n-#define DP_C_LONG 2\n-#define DP_C_LDOUBLE 3\n-#define DP_C_LLONG 4\n-\n-/* some handy macros */\n-#define char_to_int(p) (p - '0')\n-#define OSSL_MAX(p,q) ((p >= q) ? p : q)\n-\n-static void\n-_dopr(\n- char **sbuffer,\n- char **buffer,\n- size_t *maxlen,\n- size_t *retlen,\n- int *truncated,\n- const char *format,\n- va_list args)\n-{\n- char ch;\n- LLONG value;\n- LDOUBLE fvalue;\n- char *strvalue;\n- int min;\n- int max;\n- int state;\n- int flags;\n- int cflags;\n- size_t currlen;\n-\n- state = DP_S_DEFAULT;\n- flags = currlen = cflags = min = 0;\n- max = -1;\n- ch = *format++;\n-\n- while (state != DP_S_DONE) {\n- if (ch == '\\0' || (buffer == NULL && currlen >= *maxlen))\n- state = DP_S_DONE;\n-\n- switch (state) {\n- case DP_S_DEFAULT:\n- if (ch == '%')\n- state = DP_S_FLAGS;\n- else\n- doapr_outch(sbuffer,buffer, &currlen, maxlen, ch);\n- ch = *format++;\n- break;\n- case DP_S_FLAGS:\n- switch (ch) {\n- case '-':\n- flags |= DP_F_MINUS;\n- ch = *format++;\n- break;\n- case '+':\n- flags |= DP_F_PLUS;\n- ch = *format++;\n- break;\n- case ' ':\n- flags |= DP_F_SPACE;\n- ch = *format++;\n- break;\n- case '#':\n- flags |= DP_F_NUM;\n- ch = *format++;\n- break;\n- case '0':\n- flags |= DP_F_ZERO;\n- ch = *format++;\n- break;\n- default:\n- state = DP_S_MIN;\n- break;\n- }\n- break;\n- case DP_S_MIN:\n- if (isdigit((unsigned char)ch)) {\n- min = 10 * min + char_to_int(ch);\n- ch = *format++;\n- } else if (ch == '*') {\n- min = va_arg(args, int);\n- ch = *format++;\n- state = DP_S_DOT;\n- } else\n- state = DP_S_DOT;\n- break;\n- case DP_S_DOT:\n- if (ch == '.') {\n- state = DP_S_MAX;\n- ch = *format++;\n- } else\n- state = DP_S_MOD;\n- break;\n- case DP_S_MAX:\n- if (isdigit((unsigned char)ch)) {\n- if (max < 0)\n- max = 0;\n- max = 10 * max + char_to_int(ch);\n- ch = *format++;\n- } else if (ch == '*') {\n- max = va_arg(args, int);\n- ch = *format++;\n- state = DP_S_MOD;\n- } else\n- state = DP_S_MOD;\n- break;\n- case DP_S_MOD:\n- switch (ch) {\n- case 'h':\n- cflags = DP_C_SHORT;\n- ch = *format++;\n- break;\n- case 'l':\n- if (*format == 'l') {\n- cflags = DP_C_LLONG;\n- format++;\n- } else\n- cflags = DP_C_LONG;\n- ch = *format++;\n- break;\n- case 'q':\n- cflags = DP_C_LLONG;\n- ch = *format++;\n- break;\n- case 'L':\n- cflags = DP_C_LDOUBLE;\n- ch = *format++;\n- break;\n- default:\n- break;\n- }\n- state = DP_S_CONV;\n- break;\n- case DP_S_CONV:\n- switch (ch) {\n- case 'd':\n- case 'i':\n- switch (cflags) {\n- case DP_C_SHORT:\n- value = (short int)va_arg(args, int);\n- break;\n- case DP_C_LONG:\n- value = va_arg(args, long int);\n- break;\n- case DP_C_LLONG:\n- value = va_arg(args, LLONG);\n- break;\n- default:\n- value = va_arg(args, int);\n- break;\n- }\n- fmtint(sbuffer, buffer, &currlen, maxlen,\n- value, 10, min, max, flags);\n- break;\n- case 'X':\n- flags |= DP_F_UP;\n- /* FALLTHROUGH */\n- case 'x':\n- case 'o':\n- case 'u':\n- flags |= DP_F_UNSIGNED;\n- switch (cflags) {\n- case DP_C_SHORT:\n- value = (unsigned short int)va_arg(args, unsigned int);\n- brea\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From fd708c2242408187cff392e8b0850275ac99376f Mon Sep 17 00:00:00 2001\nFrom: =?UTF-8?q?Cristian=20Rodr=C3=ADguez?= \nDate: Sun, 4 May 2014 23:36:54 -0400\nSubject: [PATCH] Axe builtin printf implementation, use glibc instead\n\n\ndiff --git a/crypto/bio/b_print.c b/crypto/bio/b_print.c\nindex 143a7cf..657beb7 100644\n--- a/crypto/bio/b_print.c\n+++ b/crypto/bio/b_print.c\n@@ -56,17 +56,9 @@\n * [including the GNU Public Licence.]\n */\n \n-/* disable assert() unless BIO_DEBUG has been defined */\n-#ifndef BIO_DEBUG\n-# ifndef NDEBUG\n-# define NDEBUG\n-# endif\n+#ifndef _GNU_SOURCE\n+#define _GNU_SOURCE\n #endif\n-\n-/* \n- * Stolen from tjh's ssl/ssl_trc.c stuff.\n- */\n-\n #include \n #include \n #include \n@@ -79,690 +71,6 @@\n #include /* To get BN_LLONG properly defined */\n #include \n \n-#if defined(BN_LLONG) || defined(SIXTY_FOUR_BIT)\n-# ifndef HAVE_LONG_LONG\n-# define HAVE_LONG_LONG 1\n-# endif\n-#endif\n-\n-/***************************************************************************/\n-\n-/*\n- * Copyright Patrick Powell 1995\n- * This code is based on code written by Patrick Powell \n- * It may be used for any purpose as long as this notice remains intact\n- * on all source code distributions.\n- */\n-\n-/*\n- * This code contains numerious changes and enhancements which were\n- * made by lots of contributors over the last years to Patrick Powell's\n- * original code:\n- *\n- * o Patrick Powell (1995)\n- * o Brandon Long (1996, for Mutt)\n- * o Thomas Roessler (1998, for Mutt)\n- * o Michael Elkins (1998, for Mutt)\n- * o Andrew Tridgell (1998, for Samba)\n- * o Luke Mewburn (1999, for LukemFTP)\n- * o Ralf S. Engelschall (1999, for Pth)\n- * o ... (for OpenSSL)\n- */\n-\n-#ifdef HAVE_LONG_DOUBLE\n-#define LDOUBLE long double\n-#else\n-#define LDOUBLE double\n-#endif\n-\n-#ifdef HAVE_LONG_LONG\n-# if defined(_WIN32) && !defined(__GNUC__)\n-# define LLONG __int64\n-# else\n-# define LLONG long long\n-# endif\n-#else\n-#define LLONG long\n-#endif\n-\n-static void fmtstr (char **, char **, size_t *, size_t *,\n-\t\t\tconst char *, int, int, int);\n-static void fmtint (char **, char **, size_t *, size_t *,\n-\t\t\tLLONG, int, int, int, int);\n-static void fmtfp (char **, char **, size_t *, size_t *,\n-\t\t\tLDOUBLE, int, int, int);\n-static void doapr_outch (char **, char **, size_t *, size_t *, int);\n-static void _dopr(char **sbuffer, char **buffer,\n-\t\t size_t *maxlen, size_t *retlen, int *truncated,\n-\t\t const char *format, va_list args);\n-\n-/* format read states */\n-#define DP_S_DEFAULT 0\n-#define DP_S_FLAGS 1\n-#define DP_S_MIN 2\n-#define DP_S_DOT 3\n-#define DP_S_MAX 4\n-#define DP_S_MOD 5\n-#define DP_S_CONV 6\n-#define DP_S_DONE 7\n-\n-/* format flags - Bits */\n-#define DP_F_MINUS (1 << 0)\n-#define DP_F_PLUS (1 << 1)\n-#define DP_F_SPACE (1 << 2)\n-#define DP_F_NUM (1 << 3)\n-#define DP_F_ZERO (1 << 4)\n-#define DP_F_UP (1 << 5)\n-#define DP_F_UNSIGNED (1 << 6)\n-\n-/* conversion flags */\n-#define DP_C_SHORT 1\n-#define DP_C_LONG 2\n-#define DP_C_LDOUBLE 3\n-#define DP_C_LLONG 4\n-\n-/* some handy macros */\n-#define char_to_int(p) (p - '0')\n-#define OSSL_MAX(p,q) ((p >= q) ? p : q)\n-\n-static void\n-_dopr(\n- char **sbuffer,\n- char **buffer,\n- size_t *maxlen,\n- size_t *retlen,\n- int *truncated,\n- const char *format,\n- va_list args)\n-{\n- char ch;\n- LLONG value;\n- LDOUBLE fvalue;\n- char *strvalue;\n- int min;\n- int max;\n- int state;\n- int flags;\n- int cflags;\n- size_t currlen;\n-\n- state = DP_S_DEFAULT;\n- flags = currlen = cflags = min = 0;\n- max = -1;\n- ch = *format++;\n-\n- while (state != DP_S_DONE) {\n- if (ch == '\\0' || (buffer == NULL && currlen >= *maxlen))\n- state = DP_S_DONE;\n-\n- switch (state) {\n- case DP_S_DEFAULT:\n- if (ch == '%')\n- state = DP_S_FLAGS;\n- else\n- doapr_outch(sbuffer,buffer, &currlen, maxlen, ch);\n- ch = *format++;\n- break;\n- case DP_S_FLAGS:\n- switch (ch) {\n- case '-':\n- flags |= DP_F_MINUS;\n- ch = *format++;\n- break;\n- case '+':\n- flags |= DP_F_PLUS;\n- ch = *format++;\n- break;\n- case ' ':\n- flags |= DP_F_SPACE;\n- ch = *format++;\n- break;\n- case '#':\n- flags |= DP_F_NUM;\n- ch = *format++;\n- break;\n- case '0':\n- flags |= DP_F_ZERO;\n- ch = *format++;\n- break;\n- default:\n- state = DP_S_MIN;\n- break;\n- }\n- break;\n- case DP_S_MIN:\n- if (isdigit((unsigned char)ch)) {\n- min = 10 * min + char_to_int(ch);\n- ch = *format++;\n- } else if (ch == '*') {\n- min = va_arg(args, int);\n- ch = *format++;\n- state = DP_S_DOT;\n- } else\n- state = DP_S_DOT;\n- break;\n- case DP_S_DOT:\n- if (ch == '.') {\n- state = DP_S_MAX;\n- ch = *format++;\n- } else\n- state = DP_S_MOD;\n- break;\n- case DP_S_MAX:\n- if (isdigit((unsigned char)ch)) {\n- if (max < 0)\n- max = 0;\n- max = 10 * max + char_to_int(ch);\n- ch = *format++;\n- } else if (ch == '*') {\n- max = va_arg(args, int);\n- ch = *format++;\n- state = DP_S_MOD;\n- } else\n- state = DP_S_MOD;\n- break;\n- case DP_S_MOD:\n- switch (ch) {\n- case 'h':\n- cflags = DP_C_SHORT;\n- ch = *format++;\n- break;\n- case 'l':\n- if (*format == 'l') {\n- cflags = DP_C_LLONG;\n- format++;\n- } else\n- cflags = DP_C_LONG;\n- ch = *format++;\n- break;\n- case 'q':\n- cflags = DP_C_LLONG;\n- ch = *format++;\n- break;\n- case 'L':\n- cflags = DP_C_LDOUBLE;\n- ch = *format++;\n- break;\n- default:\n- break;\n- }\n- state = DP_S_CONV;\n- break;\n- case DP_S_CONV:\n- switch (ch) {\n- case 'd':\n- case 'i':\n- switch (cflags) {\n- case DP_C_SHORT:\n- value = (short int)va_arg(args, int);\n- break;\n- case DP_C_LONG:\n- value = va_arg(args, long int);\n- break;\n- case DP_C_LLONG:\n- value = va_arg(args, LLONG);\n- break;\n- default:\n- value = va_arg(args, int);\n- break;\n- }\n- fmtint(sbuffer, buffer, &currlen, maxlen,\n- value, 10, min, max, flags);\n- break;\n- case 'X':\n- flags |= DP_F_UP;\n- /* FALLTHROUGH */\n- case 'x':\n- case 'o':\n- case 'u':\n- flags |= DP_F_UNSIGNED;\n- switch (cflags) {\n- case DP_C_SHORT:\n- value = (unsigned short int)va_arg(args, unsigned int);\n- break;\n- case DP_C_LONG:\n- value = (LLONG) va_arg(args,\n- unsigned long int);\n- break;\n- case DP_C_LLONG:\n- value = va_arg(args, unsigned LLONG);\n- break;\n- default:\n- value = (LLONG) va_arg(args,\n- unsigned int);\n- break;\n- }\n- fmtint(sbuffer, buffer, &currlen, maxlen, value,\n- ch == 'o' ? 8 : (ch == 'u' ? 10 : 16),\n- min, max, flags);\n- break;\n- case 'f':\n- if (cflags == DP_C_LDOUBLE)\n- fvalue = va_arg(args, LDOUBLE);\n- else\n- fvalue = va_arg(args, double);\n- fmtfp(sbuffer, buffer, &currlen, maxlen,\n- fvalue, min, max, flags);\n- break;\n- case 'E':\n- flags |= DP_F_UP;\n- case 'e':\n- if (cflags == DP_C_LDOUBLE)\n- fvalue = va_arg(args, LDOUBLE);\n- else\n- fvalue = va_arg(args, double);\n- break;\n- case 'G':\n- flags |= DP_F_UP;\n- case 'g':\n- if (cflags == DP_C_LDOUBLE)\n- fvalue = va_arg(args, LDOUBLE);\n- else\n- fvalue = va_arg(args, double);\n- break;\n- case 'c':\n- doapr_outch(sbuffer, buffer, &currlen, maxlen,\n- va_arg(args, int));\n- break;\n- case 's':\n- strvalue = va_arg(args, char *);\n- if (max < 0) {\n-\t\t if (buffer)\n-\t\t\tmax = INT_MAX;\n-\t\t else\n-\t\t\tmax = *maxlen;\n-\t\t}\n- fmtstr(sbuffer, buffer, &currlen, maxlen, strvalue,\n- flags, min, max);\n- break;\n- case 'p':\n- value = (long)va_arg(args, void *);\n- fmtint(sbuffer, buffer, &currlen, maxlen,\n- value, 16, min, max, flags|DP_F_NUM);\n- break;\n- case 'n': /* XXX */\n- if (cflags == DP_C_SHORT) {\n- short int *num;\n- num = va_arg(args, short int *);\n- *num = currlen;\n- } else if (cflags == DP_C_LONG) { /* XXX */\n- long int *num;\n- num = va_arg(args, long int *);\n- *num = (long int) currlen;\n- } else if (cflags == DP_C_LLONG) { /* XXX */\n- LLONG *num;\n- num = va_arg(args, LLONG *);\n- *num = (LLONG) currlen;\n- } else {\n- int *num;\n- num = va_arg(args, int *);\n- *num = currlen;\n- }\n- break;\n- case '%':\n- doapr_outch(sbuffer, buffer, &currlen, maxlen, ch);\n- break;\n- case 'w':\n- /* not supported yet, treat as next char */\n- ch = *format++;\n- break;\n- default:\n- /* unknown, skip */\n- break;\n- }\n- ch = *format++;\n- state = DP_S_DEFAULT;\n- flags = cflags = min = 0;\n- max = -1;\n- break;\n- case DP_S_DONE:\n- break;\n- default:\n- break;\n- }\n- }\n- *truncated = (currlen > *maxlen - 1);\n- if (*truncated)\n- currlen = *maxlen - 1;\n- doapr_outch(sbuffer, buffer, &currlen, maxlen, '\\0');\n- *retlen = currlen - 1;\n- return;\n-}\n-\n-static void\n-fmtstr(\n- char **sbuffer,\n- char **buffer,\n- size_t *currlen,\n- size_t *maxlen,\n- const char *value,\n- int flags,\n- int min,\n- int max)\n-{\n- int padlen, strln;\n- int cnt = 0;\n-\n- if (value == 0)\n- value = \"\";\n- for (strln = 0; value[strln]; ++strln)\n- ;\n- padlen = min - strln;\n- if (padlen < 0)\n- padlen = 0;\n- if (flags & DP_F_MINUS)\n- padlen = -padlen;\n-\n- while ((padlen > 0) && (cnt < max)) {\n- doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');\n- --padlen;\n- ++cnt;\n- }\n- while (*value && (cnt < max)) {\n- doapr_outch(sbuffer, buffer, currlen, maxlen, *value++);\n- ++cnt;\n- }\n- while ((padlen < 0) && (cnt < max)) {\n- doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');\n- ++padlen;\n- ++cnt;\n- }\n-}\n-\n-static void\n-fmtint(\n- char **sbuffer,\n- char **buffer,\n- size_t *currlen,\n- size_t *maxlen,\n- LLONG value,\n- int base,\n- int min,\n- int max,\n- int flags)\n-{\n- int signvalue = 0;\n- const char *prefix = \"\";\n- unsigned LLONG uvalue;\n- char convert[DECIMAL_SIZE(value)+3];\n- int place = 0;\n- int spadlen = 0;\n- int zpadlen = 0;\n- int caps = 0;\n-\n- if (max < 0)\n- max = 0;\n- uvalue = value;\n- if (!(flags & DP_F_UNSIGNED)) {\n- if (value < 0) {\n- signvalue = '-';\n- uvalue = -value;\n- } else if (flags & DP_F_PLUS)\n- signvalue = '+';\n- else if (flags & DP_F_SPACE)\n- signvalue = ' ';\n- }\n- if (flags & DP_F_NUM) {\n-\tif (base == 8) prefix = \"0\";\n-\tif (base == 16) prefix = \"0x\";\n- }\n- if (flags & DP_F_UP)\n- caps = 1;\n- do {\n- convert[place++] =\n- (caps ? \"0123456789ABCDEF\" : \"0123456789abcdef\")\n- [uvalue % (unsigned) base];\n- uvalue = (uvalue / (unsigned) base);\n- } while (uvalue && (place < (int)sizeof(convert)));\n- if (place == sizeof(convert))\n- place--;\n- convert[place] = 0;\n-\n- zpadlen = max - place;\n- spadlen = min - OSSL_MAX(max, place) - (signvalue ? 1 : 0) - strlen(prefix);\n- if (zpadlen < 0)\n- zpadlen = 0;\n- if (spadlen < 0)\n- spadlen = 0;\n- if (flags & DP_F_ZERO) {\n- zpadlen = OSSL_MAX(zpadlen, spadlen);\n- spadlen = 0;\n- }\n- if (flags & DP_F_MINUS)\n- spadlen = -spadlen;\n-\n- /* spaces */\n- while (spadlen > 0) {\n- doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');\n- --spadlen;\n- }\n-\n- /* sign */\n- if (signvalue)\n- doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);\n-\n- /* prefix */\n- while (*prefix) {\n-\tdoapr_outch(sbuffer, buffer, currlen, maxlen, *prefix);\n-\tprefix++;\n- }\n-\n- /* zeros */\n- if (zpadlen > 0) {\n- while (zpadlen > 0) {\n- doapr_outch(sbuffer, buffer, currlen, maxlen, '0');\n- --zpadlen;\n- }\n- }\n- /* digits */\n- while (place > 0)\n- doapr_outch(sbuffer, buffer, currlen, maxlen, convert[--place]);\n-\n- /* left justified spaces */\n- while (spadlen < 0) {\n- doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');\n- ++spadlen;\n- }\n- return;\n-}\n-\n-static LDOUBLE\n-abs_val(LDOUBLE value)\n-{\n- LDOUBLE result = value;\n- if (value < 0)\n- result = -value;\n- return result;\n-}\n-\n-static LDOUBLE\n-pow_10(int in_exp)\n-{\n- LDOUBLE result = 1;\n- while (in_exp) {\n- result *= 10;\n- in_exp--;\n- }\n- return result;\n-}\n-\n-static long\n-roundv(LDOUBLE value)\n-{\n- long intpart;\n- intpart = (long) value;\n- value = value - intpart;\n- if (value >= 0.5)\n- intpart++;\n- return intpart;\n-}\n-\n-static void\n-fmtfp(\n- char **sbuffer,\n- char **buffer,\n- size_t *currlen,\n- size_t *maxlen,\n- LDOUBLE fvalue,\n- int min,\n- int max,\n- int flags)\n-{\n- int signvalue = 0;\n- LDOUBLE ufvalue;\n- char iconvert[20];\n- char fconvert[20];\n- int iplace = 0;\n- int fplace = 0;\n- int padlen = 0;\n- int zpadlen = 0;\n- int caps = 0;\n- long intpart;\n- long fracpart;\n- long max10;\n-\n- if (max < 0)\n- max = 6;\n- ufvalue = abs_val(fvalue);\n- if (fvalue < 0)\n- signvalue = '-';\n- else if (flags & DP_F_PLUS)\n- signvalue = '+';\n- else if (flags & DP_F_SPACE)\n- signvalue = ' ';\n-\n- intpart = (long)ufvalue;\n-\n- /* sorry, we only support 9 digits past the decimal because of our\n- conversion method */\n- if (max > 9)\n- max = 9;\n-\n- /* we \"cheat\" by converting the fractional part to integer by\n- multiplying by a factor of 10 */\n- max10 = roundv(pow_10(max));\n- fracpart = roundv(pow_10(max) * (ufvalue - intpart));\n-\n- if (fracpart >= max10) {\n- intpart++;\n- fracpart -= max10;\n- }\n-\n- /* convert integer part */\n- do {\n- iconvert[iplace++] =\n- (caps ? \"0123456789ABCDEF\"\n- : \"0123456789abcdef\")[intpart % 10];\n- intpart = (intpart / 10);\n- } while (intpart && (iplace < (int)sizeof(iconvert)));\n- if (iplace == sizeof iconvert)\n- iplace--;\n- iconvert[iplace] = 0;\n-\n- /* convert fractional part */\n- do {\n- fconvert[fplace++] =\n- (caps ? \"0123456789ABCDEF\"\n- : \"0123456789abcdef\")[fracpart % 10];\n- fracpart = (fracpart / 10);\n- } while (fplace < max);\n- if (fplace == sizeof fconvert)\n- fplace--;\n- fconvert[fplace] = 0;\n-\n- /* -1 for decimal point, another -1 if we are printing a sign */\n- padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0);\n- zpadlen = max - fplace;\n- if (zpadlen < 0)\n- zpadlen = 0;\n- if (padlen < 0)\n- padlen = 0;\n- if (flags & DP_F_MINUS)\n- padlen = -padlen;\n-\n- if ((flags & DP_F_ZERO) && (padlen > 0)) {\n- if (signvalue) {\n- doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);\n- --padlen;\n- signvalue = 0;\n- }\n- while (padlen > 0) {\n- doapr_outch(sbuffer, buffer, currlen, maxlen, '0');\n- --padlen;\n- }\n- }\n- while (padlen > 0) {\n- doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');\n- --padlen;\n- }\n- if (signvalue)\n- doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);\n-\n- while (iplace > 0)\n- doapr_outch(sbuffer, buffer, currlen, maxlen, iconvert[--iplace]);\n-\n- /*\n- * Decimal point. This should probably use locale to find the correct\n- * char to print out.\n- */\n- if (max > 0 || (flags & DP_F_NUM)) {\n- doapr_outch(sbuffer, buffer, currlen, maxlen, '.');\n-\n- while (fplace > 0)\n- doapr_outch(sbuffer, buffer, currlen, maxlen, fconvert[--fplace]);\n- }\n- while (zpadlen > 0) {\n- doapr_outch(sbuffer, buffer, currlen, maxlen, '0');\n- --zpadlen;\n- }\n-\n- while (padlen < 0) {\n- doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');\n- ++padlen;\n- }\n-}\n-\n-static void\n-doapr_outch(\n- char **sbuffer,\n- char **buffer,\n- size_t *currlen,\n- size_t *maxlen,\n- int c)\n-{\n- /* If we haven't at least one buffer, someone has doe a big booboo */\n- assert(*sbuffer != NULL || buffer != NULL);\n-\n- if (buffer) {\n-\twhile (*currlen >= *maxlen) {\n-\t if (*buffer == NULL) {\n-\t\tif (*maxlen == 0)\n-\t\t *maxlen = 1024;\n-\t\t*buffer = OPENSSL_malloc(*maxlen);\n-\t\tif (*currlen > 0) {\n-\t\t assert(*sbuffer != NULL);\n-\t\t memcpy(*buffer, *sbuffer, *currlen);\n-\t\t}\n-\t\t*sbuffer = NULL;\n-\t } else {\n-\t\t*maxlen += 1024;\n-\t\t*buffer = OPENSSL_realloc(*buffer, *maxlen);\n-\t }\n-\t}\n-\t/* What to do if *buffer is NULL? */\n-\tassert(*sbuffer != NULL || *buffer != NULL);\n- }\n-\n- if (*currlen < *maxlen) {\n-\tif (*sbuffer)\n-\t (*sbuffer)[(*currlen)++] = (char)c;\n-\telse\n-\t (*buffer)[(*currlen)++] = (char)c;\n- }\n-\n- return;\n-}\n-\n /***************************************************************************/\n \n int BIO_printf (BIO *bio, const char *format, ...)\n@@ -778,65 +86,70 @@ int BIO_printf (BIO *bio, const char *format, ...)\n \treturn(ret);\n \t}\n \n+static ssize_t cookie_BIO_write(void *cookie, const char *buf, size_t size)\n+{\n+ int ret;\n+ ret = BIO_write(cookie, buf, size);\n+ /* BIO_write may return negative value on error,\n+ * but we must return 0 on that case\n+ */\n+ return (ret < 0) ? 0 : ret;\n+}\n+\n int BIO_vprintf (BIO *bio, const char *format, va_list args)\n-\t{\n+{\n+ FILE *fp;\n \tint ret;\n-\tsize_t retlen;\n-\tchar hugebuf[1024*2];\t/* Was previously 10k, which is unreasonable\n-\t\t\t\t in small-stack environments, like threads\n-\t\t\t\t or DOS programs. */\n-\tchar *hugebufp = hugebuf;\n-\tsize_t hugebufsize = sizeof(hugebuf);\n-\tchar *dynbuf = NULL;\n-\tint ignored;\n+ \n+ cookie_io_functions_t bio_funcs = {\n+ .read = NULL,\n+ .write = cookie_BIO_write,\n+ .seek = NULL,\n+ .close = NULL,\n+ };\n+\n+ fp = fopencookie(bio, \"w\", bio_funcs);\n+\n+ if (fp == NULL) \n+ return -1;\n+\n+ ret = vfprintf(fp, format, args);\n+\n+ fclose(fp);\n \n-\tdynbuf = NULL;\n-\tCRYPTO_push_info(\"doapr()\");\n-\t_dopr(&hugebufp, &dynbuf, &hugebufsize,\n-\t\t&retlen, &ignored, format, args);\n-\tif (dynbuf)\n-\t\t{\n-\t\tret=BIO_write(bio, dynbuf, (int)retlen);\n-\t\tOPENSSL_free(dynbuf);\n-\t\t}\n-\telse\n-\t\t{\n-\t\tret=BIO_write(bio, hugebuf, (int)retlen);\n-\t\t}\n-\tCRYPTO_pop_info();\n \treturn(ret);\n-\t}\n+}\n \n /* As snprintf is not available everywhere, we provide our own implementation.\n * This function has nothing to do with BIOs, but it's closely related\n * to BIO_printf, and we need *some* name prefix ...\n * (XXX the function should be renamed, but to what?) */\n int BIO_snprintf(char *buf, size_t n, const char *format, ...)\n-\t{\n+{\n \tva_list args;\n \tint ret;\n \n \tva_start(args, format);\n \n-\tret = BIO_vsnprintf(buf, n, format, args);\n+\tret = vsnprintf(buf, n, format, args);\n \n \tva_end(args);\n+\n+\tif (ret >= n || ret == -1) return (-1);\n+\n \treturn(ret);\n-\t}\n+}\n \n int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)\n-\t{\n-\tsize_t retlen;\n-\tint truncated;\n+{\n+\t\n+\tint ret;\n+\t\n+\tret = vsnprintf(buf, n, format, args);\n \n-\t_dopr(&buf, NULL, &n, &retlen, &truncated, format, args);\n+\tif (ret >= n || ret == -1)\n+\t\treturn (-1);\n \n-\tif (truncated)\n-\t\t/* In case of truncation, return -1 like traditional snprintf.\n-\t\t * (Current drafts for ISO/IEC 9899 say snprintf should return\n-\t\t * the number of characters that would have been written,\n-\t\t * had the buffer been large enough.) */\n-\t\treturn -1;\n-\telse\n-\t\treturn (retlen <= INT_MAX) ? (int)retlen : -1;\n-\t}\n+\treturn (ret);\n+\n+}\n-- \n1.8.4.5"}], "metadata": {"id": "openssl-4598-0001-Axe-builtin-printf-implem", "cve_id": "CVE-2015-3197", "package": "openssl", "tier": "adapted", "has_source_context": true, "context_tokens_est": 4006, "context_files": 1, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3455\n\nSquid 3.2.x before 3.2.14, 3.3.x before 3.3.14, 3.4.x before 3.4.13, and 3.5.x before 3.5.4, when configured with client-first SSL-bump, do not properly validate the domain or hostname fields of X.509 certificates, which allows man-in-the-middle attackers to spoof SSL servers via a valid certificate.\n\n## Package\nsquid\n\n## Upstream Fix\n```diff\nIndex: squid-3.3.13/src/auth/digest/UserRequest.cc\n===================================================================\n--- squid-3.3.13.orig/src/auth/digest/UserRequest.cc\n+++ squid-3.3.13/src/auth/digest/UserRequest.cc\n@@ -152,10 +152,13 @@ Auth::Digest::UserRequest::authenticate(\n }\n \n /* check for stale nonce */\n- if (!authDigestNonceIsValid(digest_request->nonce, digest_request->nc)) {\n- debugs(29, 3, \"user '\" << auth_user->username() << \"' validated OK but nonce stale\");\n- auth_user->credentials(Auth::Failed);\n- digest_request->setDenyMessage(\"Stale nonce\");\n+ /* check Auth::Pending to avoid loop */\n+ if (!authDigestNonceIsValid(digest_request->nonce, digest_request->nc) && user()->credentials() != Auth::Pending) {\n+ debugs(29, 3, auth_user->username() << \"' validated OK but nonce stale: \" << digest_request->nonceb64);\n+ /* Pending prevent banner and makes a ldap control */\n+ auth_user->credentials(Auth::Pending);\n+ nonce->flags.valid = false;\n+ authDigestNoncePurge(nonce);\n return;\n }\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "Index: squid-3.3.13/src/auth/digest/UserRequest.cc\n===================================================================\n--- squid-3.3.13.orig/src/auth/digest/UserRequest.cc\n+++ squid-3.3.13/src/auth/digest/UserRequest.cc\n@@ -152,10 +152,13 @@ Auth::Digest::UserRequest::authenticate(\n }\n \n /* check for stale nonce */\n- if (!authDigestNonceIsValid(digest_request->nonce, digest_request->nc)) {\n- debugs(29, 3, \"user '\" << auth_user->username() << \"' validated OK but nonce stale\");\n- auth_user->credentials(Auth::Failed);\n- digest_request->setDenyMessage(\"Stale nonce\");\n+ /* check Auth::Pending to avoid loop */\n+ if (!authDigestNonceIsValid(digest_request->nonce, digest_request->nc) && user()->credentials() != Auth::Pending) {\n+ debugs(29, 3, auth_user->username() << \"' validated OK but nonce stale: \" << digest_request->nonceb64);\n+ /* Pending prevent banner and makes a ldap control */\n+ auth_user->credentials(Auth::Pending);\n+ nonce->flags.valid = false;\n+ authDigestNoncePurge(nonce);\n return;\n }"}], "metadata": {"id": "squid-5473-CVE-2014-9749-WIP.patch", "cve_id": "CVE-2015-3455", "package": "squid", "tier": "identical", "has_source_context": false, "license": "GPL-2.0-or-later"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3455\n\nSquid 3.2.x before 3.2.14, 3.3.x before 3.3.14, 3.4.x before 3.4.13, and 3.5.x before 3.5.4, when configured with client-first SSL-bump, do not properly validate the domain or hostname fields of X.509 certificates, which allows man-in-the-middle attackers to spoof SSL servers via a valid certificate.\n\n## Package\nsquid\n\n## Files to modify\n- src/MemObject.h\n- squid-3.3.13.orig/src/MemObject.h\n- src/HttpRequest.h\n- src/http.h\n- squid-3.3.13.orig/src/http.h\n\n## Upstream Fix\n```diff\nIndex: squid-3.3.13/src/HttpRequest.cc\n===================================================================\n--- squid-3.3.13.orig/src/HttpRequest.cc\n+++ squid-3.3.13/src/HttpRequest.cc\n@@ -112,7 +112,7 @@ HttpRequest::init()\n errDetail = ERR_DETAIL_NONE;\n peer_login = NULL;\t\t// not allocated/deallocated by this class\n peer_domain = NULL;\t\t// not allocated/deallocated by this class\n- vary_headers = NULL;\n+ vary_headers = SBuf();\n myportname = null_string;\n tag = null_string;\n #if USE_AUTH\n@@ -145,8 +145,7 @@ HttpRequest::clean()\n #endif\n safe_free(canonical);\n \n- safe_free(vary_headers);\n-\n+ vary_headers.clear();\n urlpath.clean();\n \n header.clean();\n@@ -220,7 +219,7 @@ HttpRequest::clone() const\n \n copy->lastmod = lastmod;\n copy->etag = etag;\n- copy->vary_headers = vary_headers ? xstrdup(vary_headers) : NULL;\n+ copy->vary_headers = vary_headers;\n // XXX: what to do with copy->peer_domain?\n \n copy->tag = tag;\nIndex: squid-3.3.13/src/HttpRequest.h\n===================================================================\n--- squid-3.3.13.orig/src/HttpRequest.h\n+++ squid-3.3.13/src/HttpRequest.h\n@@ -38,6 +38,7 @@\n #include \"HttpMsg.h\"\n #include \"HttpRequestMethod.h\"\n #include \"RequestFlags.h\"\n+#include \"SBuf.h\"\n \n #if USE_AUTH\n #include \"auth/UserRequest.h\"\n@@ -191,7 +192,8 @@ public:\n \n time_t lastmod;\t\t/* Used on refreshes */\n \n- const char *vary_headers;\t/* Used when varying entities are detected. Changes how the store key is calculated */\n+ /// The variant second-stage cache key. Generated from Vary header pattern for this request.\n+ SBuf vary_headers;\n \n char *peer_domain;\t\t/* Configured peer forceddomain */\n \nIndex: squid-3.3.13/src/MemObject.cc\n===================================================================\n--- squid-3.3.13.orig/src/MemObject.cc\n+++ squid-3.3.13/src/MemObject.cc\n@@ -138,8 +138,6 @@ MemObject::~MemObject()\n safe_free(url);\n \n safe_free(log_url); /* XXX account log_url */\n-\n- safe_free(vary_headers);\n }\n \n void\n@@ -226,8 +224,8 @@ MemObject::stat(MemBuf * mb) const\n {\n mb->Printf(\"\\t%s %s\\n\",\n RequestMethodStr(method), log_url);\n- if (vary_headers)\n- mb->Printf(\"\\tvary_headers: %s\\n\", vary_headers);\n+ if (!vary_headers.isEmpty())\n+ mb->Printf(\"\\tvary_headers: \" SQUIDSBUFPH \"\\n\", SQUIDSBUFPRINT(vary_headers));\n mb->Printf(\"\\tinmem_lo: %\" PRId64 \"\\n\", inmem_lo);\n mb->Printf(\"\\tinmem_hi: %\" PRId64 \"\\n\", data_hdr.endOffset());\n mb->Printf(\"\\tswapout: %\" PRId64 \" bytes queued\\n\",\nIndex: squid-3.3.13/src/MemObject.h\n===================================================================\n--- squid-3.3.13.orig/src/MemObject.h\n+++ squid-3.3.13/src/MemObject.h\n@@ -35,6 +35,7 @@\n #include \"dlink.h\"\n #include \"HttpRequestMethod.h\"\n #include \"RemovalPolicy.h\"\n+#include \"SBuf.h\"\n #include \"stmem.h\"\n #include \"StoreIOBuffer.h\"\n #include \"StoreIOState.h\"\n@@ -147,7 +148,7 @@ public:\n unsigned int chksum;\n #endif\n \n- const char *vary_headers;\n+ SBuf vary_headers;\n \n void delayRead(DeferredRead const &);\n void kickReads();\nIndex: squid-3.3.13/src/MemStore.cc\n===================================================================\n--- squid-3.3.13.orig/src/MemStore.cc\n+++ squid-3.3.13/src/MemStore.cc\n@@ -310,7 +310,7 @@ MemStore::considerKeeping(StoreEntry &e)\n return;\n }\n \n- if (e.mem_obj->vary_headers) {\n+ if (!e.mem_obj->vary_headers.isEmpty()) {\n // XXX: We must store/load SerialisedMetaData to cache Vary in RAM\n debugs(20, 5, \"Vary not yet supported: \" << e.mem_obj->vary_headers);\n return;\nIndex: squid-3.3.13/src/StoreMetaVary.cc\n===================================================================\n--- squid-3.3.13.orig/src/StoreMetaVary.cc\n+++ squid-3.3.13/src/StoreMetaVary.cc\n@@ -41,14 +41,14 @@ StoreMetaVary::checkConsistency(StoreEnt\n {\n assert (getType() == STORE_META_VARY_HEADERS);\n \n- if (!e->mem_obj->vary_headers) {\n+ if (e->mem_obj->vary_headers.isEmpty()) {\n /* XXX separate this mutator from the query */\n /* Assume the object is OK.. remember the vary request headers */\n- e->mem_obj->vary_headers = xstrdup((char *)value);\n+ e->mem_obj->vary_headers.assign(static_cast(value), length);\n return true;\n }\n \n- if (strcmp(e->mem_obj->vary_headers, (char *)value) != 0)\n+ if (e->mem_obj->vary_headers.cmp(static_cast(value), length) != 0)\n return false;\n \n return true;\nIndex: squid-3.3.13/src/client_side.cc\n===================================================================\n--- squid-3.3.13.orig/src/client_side.cc\n+++ squid-3.3.13/src/client_side.cc\n@@ -4178,20 +4178,19 @@ clientHttpConnectionsClose(void)\n int\n varyEvaluateMatch(StoreEntry * entry, HttpRequest * request)\n {\n- const char *vary = request->vary_headers;\n+ SBuf vary(request->vary_headers);\n int has_vary = entry->getReply()->header.has(HDR_VARY);\n #if X_ACCELERATOR_VARY\n-\n has_vary |=\n entry->getReply()->header.has(HDR_X_ACCELERATOR_VARY);\n #endif\n \n- if (!has_vary || !entry->mem_obj->vary_headers) {\n- if (vary) {\n+ if (!has_vary || entry->mem_obj->vary_headers.isEmpty()) {\n+ if (!vary.isEmpty()) {\n /* Oops... something odd is going on here.. */\n debugs(33, DBG_IMPORTANT, \"varyEvaluateMatch: Oops. Not a Vary object on second attempt, '\" <<\n entry->mem_obj->url << \"' '\" << vary << \"'\");\n- safe_free(request->vary_headers);\n+ request->vary_headers.clear();\n return VARY_CANCEL;\n }\n \n@@ -4205,8 +4204,8 @@ varyEvaluateMatch(StoreEntry * entry, Ht\n */\n vary = httpMakeVaryMark(request, entry->getReply());\n \n- if (vary) {\n- request->vary_headers = xstrdup(vary);\n+ if (!vary.isEmpty()) {\n+ request->vary_headers = vary;\n return VARY_OTHER;\n } else {\n /* Ouch.. we cannot handle this kind of variance */\n@@ -4214,18 +4213,18 @@ varyEvaluateMatch(StoreEntry * entry, Ht\n return VARY_CANCEL;\n }\n } else {\n- if (!vary) {\n+ if (vary.isEmpty()) {\n vary = httpMakeVaryMark(request, entry->getReply());\n \n- if (vary)\n- request->vary_headers = xstrdup(vary);\n+ if (!vary.isEmpty())\n+ request->vary_headers = vary;\n }\n \n- if (!vary) {\n+ if (vary.isEmpty()) {\n /* Ouch.. we cannot handle this kind of variance */\n /* XXX This cannot really happen, but just to be complete */\n return VARY_CANCEL;\n- } else if (strcmp(vary, entry->mem_obj->vary_headers) == 0) {\n+ } else if (vary.cmp(entry->mem_obj->vary_headers) == 0) {\n return VARY_MATCH;\n } else {\n /* Oops.. we have already been here and still haven't\nIndex: squid-3.3.13/src/client_side_reply.cc\n===================================================================\n--- squid-3.3.13.orig/src/client_side_reply.cc\n+++ squid-3.3.13/src/client_side_reply.cc\n@@ -982,8 +982,8 @@ clientReplyContext::purgeDoPurgeHead(Sto\n \n /* And for Vary, release the base URI if none of the headers was included in the request */\n \n- if (http->request->vary_headers\n- && !strstr(http->request->vary_headers, \"=\")) {\n+ if (!http->request->vary_headers.isEmpty()\n+ && http->request->vary_headers.find('=') != SBuf::npos) {\n StoreEntry *entry = storeGetPublic(urlCanonical(http->request), METHOD_GET);\n \n if (entry) {\nIndex: squid-3.3.13/src/http.cc\n===================================================================\n--- squid-3.3.13.orig/src/http.cc\n+++ squid-3.3.13/src/http.cc\n@@ -598,9 +598,9 @@ HttpStateData::cacheableReply()\n /*\n * For Vary, store the relevant request headers as\n * virtual headers in the reply\n- * Returns false if the variance cannot be sto\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "Index: squid-3.3.13/src/HttpRequest.cc\n===================================================================\n--- squid-3.3.13.orig/src/HttpRequest.cc\n+++ squid-3.3.13/src/HttpRequest.cc\n@@ -112,7 +112,7 @@ HttpRequest::init()\n errDetail = ERR_DETAIL_NONE;\n peer_login = NULL;\t\t// not allocated/deallocated by this class\n peer_domain = NULL;\t\t// not allocated/deallocated by this class\n- vary_headers = NULL;\n+ vary_headers = SBuf();\n myportname = null_string;\n tag = null_string;\n #if USE_AUTH\n@@ -145,8 +145,7 @@ HttpRequest::clean()\n #endif\n safe_free(canonical);\n \n- safe_free(vary_headers);\n-\n+ vary_headers.clear();\n urlpath.clean();\n \n header.clean();\n@@ -220,7 +219,7 @@ HttpRequest::clone() const\n \n copy->lastmod = lastmod;\n copy->etag = etag;\n- copy->vary_headers = vary_headers ? xstrdup(vary_headers) : NULL;\n+ copy->vary_headers = vary_headers;\n // XXX: what to do with copy->peer_domain?\n \n copy->tag = tag;\nIndex: squid-3.3.13/src/HttpRequest.h\n===================================================================\n--- squid-3.3.13.orig/src/HttpRequest.h\n+++ squid-3.3.13/src/HttpRequest.h\n@@ -38,6 +38,7 @@\n #include \"HttpMsg.h\"\n #include \"HttpRequestMethod.h\"\n #include \"RequestFlags.h\"\n+#include \"SBuf.h\"\n \n #if USE_AUTH\n #include \"auth/UserRequest.h\"\n@@ -191,7 +192,8 @@ public:\n \n time_t lastmod;\t\t/* Used on refreshes */\n \n- const char *vary_headers;\t/* Used when varying entities are detected. Changes how the store key is calculated */\n+ /// The variant second-stage cache key. Generated from Vary header pattern for this request.\n+ SBuf vary_headers;\n \n char *peer_domain;\t\t/* Configured peer forceddomain */\n \nIndex: squid-3.3.13/src/MemObject.cc\n===================================================================\n--- squid-3.3.13.orig/src/MemObject.cc\n+++ squid-3.3.13/src/MemObject.cc\n@@ -138,8 +138,6 @@ MemObject::~MemObject()\n safe_free(url);\n \n safe_free(log_url); /* XXX account log_url */\n-\n- safe_free(vary_headers);\n }\n \n void\n@@ -226,8 +224,8 @@ MemObject::stat(MemBuf * mb) const\n {\n mb->Printf(\"\\t%s %s\\n\",\n RequestMethodStr(method), log_url);\n- if (vary_headers)\n- mb->Printf(\"\\tvary_headers: %s\\n\", vary_headers);\n+ if (!vary_headers.isEmpty())\n+ mb->Printf(\"\\tvary_headers: \" SQUIDSBUFPH \"\\n\", SQUIDSBUFPRINT(vary_headers));\n mb->Printf(\"\\tinmem_lo: %\" PRId64 \"\\n\", inmem_lo);\n mb->Printf(\"\\tinmem_hi: %\" PRId64 \"\\n\", data_hdr.endOffset());\n mb->Printf(\"\\tswapout: %\" PRId64 \" bytes queued\\n\",\nIndex: squid-3.3.13/src/MemObject.h\n===================================================================\n--- squid-3.3.13.orig/src/MemObject.h\n+++ squid-3.3.13/src/MemObject.h\n@@ -35,6 +35,7 @@\n #include \"dlink.h\"\n #include \"HttpRequestMethod.h\"\n #include \"RemovalPolicy.h\"\n+#include \"SBuf.h\"\n #include \"stmem.h\"\n #include \"StoreIOBuffer.h\"\n #include \"StoreIOState.h\"\n@@ -147,7 +148,7 @@ public:\n unsigned int chksum;\n #endif\n \n- const char *vary_headers;\n+ SBuf vary_headers;\n \n void delayRead(DeferredRead const &);\n void kickReads();\nIndex: squid-3.3.13/src/MemStore.cc\n===================================================================\n--- squid-3.3.13.orig/src/MemStore.cc\n+++ squid-3.3.13/src/MemStore.cc\n@@ -310,7 +310,7 @@ MemStore::considerKeeping(StoreEntry &e)\n return;\n }\n \n- if (e.mem_obj->vary_headers) {\n+ if (!e.mem_obj->vary_headers.isEmpty()) {\n // XXX: We must store/load SerialisedMetaData to cache Vary in RAM\n debugs(20, 5, \"Vary not yet supported: \" << e.mem_obj->vary_headers);\n return;\nIndex: squid-3.3.13/src/StoreMetaVary.cc\n===================================================================\n--- squid-3.3.13.orig/src/StoreMetaVary.cc\n+++ squid-3.3.13/src/StoreMetaVary.cc\n@@ -41,14 +41,14 @@ StoreMetaVary::checkConsistency(StoreEnt\n {\n assert (getType() == STORE_META_VARY_HEADERS);\n \n- if (!e->mem_obj->vary_headers) {\n+ if (e->mem_obj->vary_headers.isEmpty()) {\n /* XXX separate this mutator from the query */\n /* Assume the object is OK.. remember the vary request headers */\n- e->mem_obj->vary_headers = xstrdup((char *)value);\n+ e->mem_obj->vary_headers.assign(static_cast(value), length);\n return true;\n }\n \n- if (strcmp(e->mem_obj->vary_headers, (char *)value) != 0)\n+ if (e->mem_obj->vary_headers.cmp(static_cast(value), length) != 0)\n return false;\n \n return true;\nIndex: squid-3.3.13/src/client_side.cc\n===================================================================\n--- squid-3.3.13.orig/src/client_side.cc\n+++ squid-3.3.13/src/client_side.cc\n@@ -4178,20 +4178,19 @@ clientHttpConnectionsClose(void)\n int\n varyEvaluateMatch(StoreEntry * entry, HttpRequest * request)\n {\n- const char *vary = request->vary_headers;\n+ SBuf vary(request->vary_headers);\n int has_vary = entry->getReply()->header.has(HDR_VARY);\n #if X_ACCELERATOR_VARY\n-\n has_vary |=\n entry->getReply()->header.has(HDR_X_ACCELERATOR_VARY);\n #endif\n \n- if (!has_vary || !entry->mem_obj->vary_headers) {\n- if (vary) {\n+ if (!has_vary || entry->mem_obj->vary_headers.isEmpty()) {\n+ if (!vary.isEmpty()) {\n /* Oops... something odd is going on here.. */\n debugs(33, DBG_IMPORTANT, \"varyEvaluateMatch: Oops. Not a Vary object on second attempt, '\" <<\n entry->mem_obj->url << \"' '\" << vary << \"'\");\n- safe_free(request->vary_headers);\n+ request->vary_headers.clear();\n return VARY_CANCEL;\n }\n \n@@ -4205,8 +4204,8 @@ varyEvaluateMatch(StoreEntry * entry, Ht\n */\n vary = httpMakeVaryMark(request, entry->getReply());\n \n- if (vary) {\n- request->vary_headers = xstrdup(vary);\n+ if (!vary.isEmpty()) {\n+ request->vary_headers = vary;\n return VARY_OTHER;\n } else {\n /* Ouch.. we cannot handle this kind of variance */\n@@ -4214,18 +4213,18 @@ varyEvaluateMatch(StoreEntry * entry, Ht\n return VARY_CANCEL;\n }\n } else {\n- if (!vary) {\n+ if (vary.isEmpty()) {\n vary = httpMakeVaryMark(request, entry->getReply());\n \n- if (vary)\n- request->vary_headers = xstrdup(vary);\n+ if (!vary.isEmpty())\n+ request->vary_headers = vary;\n }\n \n- if (!vary) {\n+ if (vary.isEmpty()) {\n /* Ouch.. we cannot handle this kind of variance */\n /* XXX This cannot really happen, but just to be complete */\n return VARY_CANCEL;\n- } else if (strcmp(vary, entry->mem_obj->vary_headers) == 0) {\n+ } else if (vary.cmp(entry->mem_obj->vary_headers) == 0) {\n return VARY_MATCH;\n } else {\n /* Oops.. we have already been here and still haven't\nIndex: squid-3.3.13/src/client_side_reply.cc\n===================================================================\n--- squid-3.3.13.orig/src/client_side_reply.cc\n+++ squid-3.3.13/src/client_side_reply.cc\n@@ -982,8 +982,8 @@ clientReplyContext::purgeDoPurgeHead(Sto\n \n /* And for Vary, release the base URI if none of the headers was included in the request */\n \n- if (http->request->vary_headers\n- && !strstr(http->request->vary_headers, \"=\")) {\n+ if (!http->request->vary_headers.isEmpty()\n+ && http->request->vary_headers.find('=') != SBuf::npos) {\n StoreEntry *entry = storeGetPublic(urlCanonical(http->request), METHOD_GET);\n \n if (entry) {\nIndex: squid-3.3.13/src/http.cc\n===================================================================\n--- squid-3.3.13.orig/src/http.cc\n+++ squid-3.3.13/src/http.cc\n@@ -598,9 +598,9 @@ HttpStateData::cacheableReply()\n /*\n * For Vary, store the relevant request headers as\n * virtual headers in the reply\n- * Returns false if the variance cannot be stored\n+ * Returns an empty SBuf if the variance cannot be stored\n */\n-const char *\n+SBuf\n httpMakeVaryMark(HttpRequest * request, HttpReply const * reply)\n {\n String vary, hdr;\n@@ -608,9 +608,9 @@ httpMakeVaryMark(HttpRequest * request,\n const char *item;\n const char *value;\n int ilen;\n- static String vstr;\n+ SBuf vstr;\n+ static const SBuf asterisk(\"*\");\n \n- vstr.clean();\n vary = reply->header.getList(HDR_VARY);\n \n while (strListGetItem(&vary, ',', &item, &ilen, &pos)) {\n@@ -621,11 +621,13 @@ httpMakeVaryMark(HttpRequest * request,\n if (strcmp(name, \"*\") == 0) {\n /* Can not handle \"Vary: *\" withtout ETag support */\n safe_free(name);\n- vstr.clean();\n+ vstr.clear();\n break;\n }\n \n- strListAdd(&vstr, name, ',');\n+ if (!vstr.isEmpty())\n+ vstr.append(\", \", 2);\n+ vstr.append(name);\n hdr = request->header.getByName(name);\n safe_free(name);\n value = hdr.termedBuf();\n@@ -650,7 +652,17 @@ httpMakeVaryMark(HttpRequest * request,\n char *name = (char *)xmalloc(ilen + 1);\n xstrncpy(name, item, ilen + 1);\n Tolower(name);\n- strListAdd(&vstr, name, ',');\n+\n+ if (strcmp(name, \"*\") == 0) {\n+ /* Can not handle \"Vary: *\" withtout ETag support */\n+ safe_free(name);\n+ vstr.clear();\n+ break;\n+ }\n+\n+ if (!vstr.isEmpty())\n+ vstr.append(\", \", 2);\n+ vstr.append(name);\n hdr = request->header.getByName(name);\n safe_free(name);\n value = hdr.termedBuf();\n@@ -668,8 +680,8 @@ httpMakeVaryMark(HttpRequest * request,\n vary.clean();\n #endif\n \n- debugs(11, 3, \"httpMakeVaryMark: \" << vstr);\n- return vstr.termedBuf();\n+ debugs(11, 3, vstr);\n+ return vstr;\n }\n \n void\n@@ -938,16 +950,16 @@ HttpStateData::haveParsedReplyHeaders()\n || rep->header.has(HDR_X_ACCELERATOR_VARY)\n #endif\n ) {\n- const char *vary = httpMakeVaryMark(request, rep);\n+ const SBuf vary(httpMakeVaryMark(request, rep));\n \n- if (!vary) {\n+ if (vary.isEmpty()) {\n entry->makePrivate();\n if (!fwd->reforwardableStatus(rep->sline.status))\n EBIT_CLR(entry->flags, ENTRY_FWD_HDR_WAIT);\n goto no_cache;\n }\n \n- entry->mem_obj->vary_headers = xstrdup(vary);\n+ entry->mem_obj->vary_headers = vary;\n }\n \n /*\nIndex: squid-3.3.13/src/http.h\n===================================================================\n--- squid-3.3.13.orig/src/http.h\n+++ squid-3.3.13/src/http.h\n@@ -34,6 +34,7 @@\n \n #include \"comm.h\"\n #include \"HttpStateFlags.h\"\n+#include \"SBuf.h\"\n #include \"Server.h\"\n \n class ChunkedCodingParser;\n@@ -138,6 +139,6 @@ private:\n \n int httpCachable(const HttpRequestMethod&);\n void httpStart(FwdState *);\n-const char *httpMakeVaryMark(HttpRequest * request, HttpReply const * reply);\n+SBuf httpMakeVaryMark(HttpRequest * request, HttpReply const * reply);\n \n #endif /* SQUID_HTTP_H */\nIndex: squid-3.3.13/src/store.cc\n===================================================================\n--- squid-3.3.13.orig/src/store.cc\n+++ squid-3.3.13/src/store.cc\n@@ -729,15 +729,15 @@ StoreEntry::setPublicKey()\n if (mem_obj->request) {\n HttpRequest *request = mem_obj->request;\n \n- if (!mem_obj->vary_headers) {\n+ if (mem_obj->vary_headers.isEmpty()) {\n /* First handle the case where the object no longer varies */\n- safe_free(request->vary_headers);\n+ request->vary_headers.clear();\n } else {\n- if (request->vary_headers && strcmp(request->vary_headers, mem_obj->vary_headers) != 0) {\n+ if (!request->vary_headers.isEmpty() && request->vary_headers.cmp(mem_obj->vary_headers) != 0) {\n /* Oops.. the variance has changed. Kill the base object\n * to record the new variance key\n */\n- safe_free(request->vary_headers); /* free old \"bad\" variance key */\n+ request->vary_headers.clear(); /* free old \"bad\" variance key */\n StoreEntry *pe = storeGetPublic(mem_obj->url, mem_obj->method);\n \n if (pe)\n@@ -745,17 +745,14 @@ StoreEntry::setPublicKey()\n }\n \n /* Make sure the request knows the variance status */\n- if (!request->vary_headers) {\n- const char *vary = httpMakeVaryMark(request, mem_obj->getReply());\n-\n- if (vary)\n- request->vary_headers = xstrdup(vary);\n+ if (request->vary_headers.isEmpty()) {\n+ request->vary_headers = httpMakeVaryMark(request, mem_obj->getReply());\n }\n }\n \n // TODO: storeGetPublic() calls below may create unlocked entries.\n // We should add/use storeHas() API or lock/unlock those entries.\n- if (mem_obj->vary_headers && !storeGetPublic(mem_obj->url, mem_obj->method)) {\n+ if (!mem_obj->vary_headers.isEmpty() && !storeGetPublic(mem_obj->url, mem_obj->method)) {\n /* Create \"vary\" base object */\n String vary;\n StoreEntry *pe = storeCreateEntry(mem_obj->url, mem_obj->log_url, request->flags, request->method);\nIndex: squid-3.3.13/src/store_key_md5.cc\n===================================================================\n--- squid-3.3.13.orig/src/store_key_md5.cc\n+++ squid-3.3.13/src/store_key_md5.cc\n@@ -145,8 +145,8 @@ storeKeyPublicByRequestMethod(HttpReques\n SquidMD5Update(&M, &m, sizeof(m));\n SquidMD5Update(&M, (unsigned char *) url, strlen(url));\n \n- if (request->vary_headers)\n- SquidMD5Update(&M, (unsigned char *) request->vary_headers, strlen(request->vary_headers));\n+ if (!request->vary_headers.isEmpty())\n+ SquidMD5Update(&M, request->vary_headers.rawContent(), request->vary_headers.length());\n \n SquidMD5Final(digest, &M);\n \nIndex: squid-3.3.13/src/store_swapmeta.cc\n===================================================================\n--- squid-3.3.13.orig/src/store_swapmeta.cc\n+++ squid-3.3.13/src/store_swapmeta.cc\n@@ -63,7 +63,6 @@ storeSwapMetaBuild(StoreEntry * e)\n tlv *TLV = NULL;\t\t/* we'll return this */\n tlv **T = &TLV;\n const char *url;\n- const char *vary;\n assert(e->mem_obj != NULL);\n const int64_t objsize = e->mem_obj->expectedReplySize();\n assert(e->swap_status == SWAPOUT_WRITING);\n@@ -103,10 +102,12 @@ storeSwapMetaBuild(StoreEntry * e)\n }\n \n T = StoreMeta::Add(T, t);\n- vary = e->mem_obj->vary_headers;\n+ SBuf vary(e->mem_obj->vary_headers);\n \n- if (vary) {\n- t =StoreMeta::Factory(STORE_META_VARY_HEADERS, strlen(vary) + 1, vary);\n+ if (!vary.isEmpty()) {\n+ // TODO: do we still need +1 here? StoreMetaVary::checkConsistency\n+ // no longer relies on nul-termination, but other things might.\n+ t = StoreMeta::Factory(STORE_META_VARY_HEADERS, vary.length() + 1, vary.c_str());\n \n if (!t) {\n storeSwapTLVFree(TLV);\nIndex: squid-3.3.13/src/tests/stub_MemObject.cc\n===================================================================\n--- squid-3.3.13.orig/src/tests/stub_MemObject.cc\n+++ squid-3.3.13/src/tests/stub_MemObject.cc\n@@ -32,7 +32,6 @@ MemObject::MemObject(char const *, char\n id(0),\n object_sz(-1),\n swap_hdr_sz(0),\n- vary_headers(NULL),\n _reply(NULL)\n {\n memset(&clients, 0, sizeof(clients));\nIndex: squid-3.3.13/src/tests/stub_http.cc\n===================================================================\n--- squid-3.3.13.orig/src/tests/stub_http.cc\n+++ squid-3.3.13/src/tests/stub_http.cc\n@@ -6,4 +6,4 @@\n #define STUB_API \"http.cc\"\n #include \"tests/STUB.h\"\n \n-const char * httpMakeVaryMark(HttpRequest * request, HttpReply const * reply) STUB_RETVAL(NULL)\n+SBuf httpMakeVaryMark(HttpRequest * request, HttpReply const * reply) STUB_RETVAL(SBuf())"}], "metadata": {"id": "squid-5473-SQUID_2016_4_port.patch", "cve_id": "CVE-2015-3455", "package": "squid", "tier": "adapted", "has_source_context": false, "license": "GPL-2.0-or-later"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-6250\n\nInteger overflow in the ISO9660 writer in libarchive before 3.2.1 allows remote attackers to cause a denial of service (application crash) or execute arbitrary code via vectors related to verifying filename lengths when writing an ISO9660 archive, which trigger a buffer overflow.\n\n## Package\nlibarchive\n\n## Files to modify\n- libarchive-3.1.2.orig/libarchive/archive_read_support_format_mtree.c\n- libarchive-3.1.2.orig/libarchive/archive_platform.h\n- libarchive/archive_pack_dev.h\n- libarchive/archive_platform.h\n- libarchive/archive_read_support_format_mtree.c\n\n## Target Source Code\n\n### libarchive/CMakeLists.txt\n\n#### SET() [lines 1-82]\n```c\n\n############################################\n#\n# How to build libarchive\n#\n############################################\n\n# Public headers\nSET(include_HEADERS\n archive.h\n archive_entry.h\n)\n\n# Sources and private headers\nSET(libarchive_SOURCES\n archive_acl.c\n archive_check_magic.c\n archive_cmdline.c\n archive_cmdline_private.h\n archive_crc32.h\n archive_crypto.c\n archive_crypto_private.h\n archive_endian.h\n archive_entry.c\n archive_entry.h\n archive_entry_copy_stat.c\n archive_entry_link_resolver.c\n archive_entry_locale.h\n archive_entry_private.h\n archive_entry_sparse.c\n archive_entry_stat.c\n archive_entry_strmode.c\n archive_entry_xattr.c\n archive_getdate.c\n archive_match.c\n archive_options.c\n archive_options_private.h\n archive_pathmatch.c\n archive_pathmatch.h\n archive_platform.h\n archive_ppmd_private.h\n archive_ppmd7.c\n archive_ppmd7_private.h\n archive_private.h\n archive_rb.c\n archive_rb.h\n archive_read.c\n archive_read_append_filter.c\n archive_read_data_into_fd.c\n archive_read_disk_entry_from_file.c\n archive_read_disk_posix.c\n archive_read_disk_private.h\n archive_read_disk_set_standard_lookup.c\n archive_read_extract.c\n archive_read_open_fd.c\n archive_read_open_file.c\n archive_read_open_filename.c\n archive_read_open_memory.c\n archive_read_private.h\n archive_read_set_format.c\n archive_read_set_options.c\n archive_read_support_filter_all.c\n archive_read_support_filter_bzip2.c\n archive_read_support_filter_compress.c\n archive_read_support_filter_gzip.c\n archive_read_support_filter_grzip.c\n archive_read_support_filter_lrzip.c\n archive_read_support_filter_lzop.c\n archive_read_support_filter_none.c\n archive_read_support_filter_program.c\n archive_read_support_filter_rpm.c\n archive_read_support_filter_uu.c\n archive_read_support_filter_xz.c\n archive_read_support_format_7zip.c\n archive_read_support_format_all.c\n archive_read_support_format_ar.c\n archive_read_support_format_by_code.c\n archive_read_support_format_cab.c\n archive_read_support_format_cpio.c\n archive_read_support_format_empty.c\n archive_read_su\n/* ... truncated ... */\n```\n\n### libarchive/archive_platform.h\n\n#### region() [lines 27-122]\n```c\n\n/* !!ONLY FOR USE INTERNALLY TO LIBARCHIVE!! */\n\n/*\n * This header is the first thing included in any of the libarchive\n * source files. As far as possible, platform-specific issues should\n * be dealt with here and not within individual source files. I'm\n * actively trying to minimize #if blocks within the main source,\n * since they obfuscate the code.\n */\n\n#ifndef ARCHIVE_PLATFORM_H_INCLUDED\n#define\tARCHIVE_PLATFORM_H_INCLUDED\n\n/* archive.h and archive_entry.h require this. */\n#define\t__LIBARCHIVE_BUILD 1\n\n#if defined(PLATFORM_CONFIG_H)\n/* Use hand-built config.h in environments that need it. */\n#include PLATFORM_CONFIG_H\n#elif defined(HAVE_CONFIG_H)\n/* Most POSIX platforms use the 'configure' script to build config.h */\n#include \"config.h\"\n#else\n/* Warn if the library hasn't been (automatically or manually) configured. */\n#error Oops: No config.h and no pre-built configuration in archive_platform.h.\n#endif\n\n/* It should be possible to get rid of this by extending the feature-test\n * macros to cover Windows API functions, probably along with non-trivial\n * refactoring of code to find structures that sit more cleanly on top of\n * either Windows or Posix APIs. */\n#if (defined(__WIN32__) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__)\n#include \"archive_windows.h\"\n#endif\n\n/*\n * The config files define a lot of feature macros. The following\n * uses those macros to select/define replacements and include key\n * headers as required.\n */\n\n/* Get a real definition for __FBSDID if we can */\n#if HAVE_SYS_CDEFS_H\n#include \n#endif\n\n/* If not, define it so as to avoid dangling semicolons. */\n#ifndef __FBSDID\n#define\t__FBSDID(a) struct _undefined_hack\n#endif\n\n/* Try to get standard C99-style integer type definitions. */\n#if HAVE_INTTYPES_H\n#include \n#endif\n#if HAVE_STDINT_H\n#include \n#endif\n\n/* Borland warns about its own constants! */\n#if defined(__BORLANDC__)\n# if HAVE_DECL_UINT64_MAX\n# undef\tUINT64_MAX\n# undef\tHAVE_DECL_UINT64_MAX\n# endif\n# if HAVE_DECL_UINT64_MIN\n# undef\tUINT64_MIN\n# undef\tHAVE_DE\n/* ... truncated ... */\n```\n\n### libarchive/archive_read_support_format_mtree.c\n\n#### __FBSDID() [lines 12-98]\n```c\n * 2. Redistributions in binary form must reproduce the above copyright\n * notice, this list of conditions and the following disclaimer in the\n * documentation and/or other materials provided with the distribution.\n *\n * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR\n * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,\n * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\n#include \"archive_platform.h\"\n__FBSDID(\"$FreeBSD: head/lib/libarchive/archive_read_support_format_mtree.c 201165 2009-12-29 05:52:13Z kientzle $\");\n\n#ifdef HAVE_SYS_STAT_H\n#include \n#endif\n#ifdef HAVE_ERRNO_H\n#include \n#endif\n#ifdef HAVE_FCNTL_H\n#include \n#endif\n#include \n/* #include */ /* See archive_platform.h */\n#ifdef HAVE_STDLIB_H\n#include \n#endif\n#ifdef HAVE_STRING_H\n#include \n#endif\n\n#include \"archive.h\"\n#include \"archive_entry.h\"\n#include \"archive_private.h\"\n#include \"archive_read_private.h\"\n#include \"archive_string.h\"\n\n#ifndef O_BINARY\n#define\tO_BINARY 0\n#endif\n#ifndef O_CLOEXEC\n#define O_CLOEXEC\t0\n#endif\n\n#define\tMTREE_HAS_DEVICE\t0x0001\n#define\tMTREE_HAS_FFLAGS\t0x0002\n#define\tMTREE_HAS_GID\t\t0x0004\n#define\tMTREE_HAS_GNAME\t\t0x0008\n#define\tMTREE_HAS_MTIME\t\t0x0010\n#define\tMTREE_HAS_NLINK\t\t0x0020\n#define\tMTREE_HAS_PERM\t\t0x0040\n#define\tMTREE_HAS_SIZE\t\t0x0080\n#define\tMTREE_HAS_TYPE\t\t0x0100\n#define\tMTREE_HAS_UID\t\t0x0200\n#define\tMTREE_HAS_UNAME\t\t0x0400\n\n#define\tMTREE_HAS_OPTIONAL\t0x0800\n#define\tMTREE_HAS_NOCHANGE\t0x1000 /* Free\n/* ... truncated ... */\n```\n\n### Makefile.am\n\n#### region() [lines 71-157]\n```c\ndistclean-local:\n\t-rm -rf .ref\n\t-rm -rf autom4te.cache/\n\t-rm -f *~\n\t-[ -f libarchive/Makefile ] && cd libarchive && make clean\n\t-[ -f libarchive/test/Makefile ] && cd libarchive/test && make clean\n\t-[ -f tar/Makefile ] && cd tar && make clean\n\t-[ -f tar/test/Makefile ] && cd tar/test && make clean\n\t-[ -f cpio/Makefile ] && cd cpio && make clean\n\t-[ -f cpio/test/Makefile ] && cd cpio/test && make clean\n\n#\n# Libarchive headers, source, etc.\n#\n#\n\ninclude_HEADERS= libarchive/archive.h libarchive/archive_entry.h\n\nlibarchive_la_SOURCES=\t\t\t\t\t\t\\\n\tlibarchive/archive_acl.c\t\t\t\t\\\n\tlibarchive/archive_acl_private.h\t\t\t\\\n\tlibarchive/archive_check_magic.c\t\t\t\\\n\tlibarchive/archive_cmdline.c\t\t\t\t\\\n\tlibarchive/archive_cmdline_private.h\t\t\t\\\n\tlibarchive/archive_crc32.h\t\t\t\t\\\n\tlibarchive/archive_crypto.c\t\t\t\t\\\n\tlibarchive/archive_crypto_private.h\t\t\t\\\n\tlibarchive/archive_endian.h\t\t\t\t\\\n\tlibarchive/archive_entry.c\t\t\t\t\\\n\tlibarchive/archive_entry.h\t\t\t\t\\\n\tlibarchive/archive_entry_copy_stat.c\t\t\t\\\n\tlibarchive/archive_entry_link_resolver.c\t\t\\\n\tlibarchive/archive_entry_locale.h\t\t\t\\\n\tlibarchive/archive_entry_private.h\t\t\t\\\n\tlibarchive/archive_entry_sparse.c\t\t\t\\\n\tlibarchive/archive_entry_stat.c\t\t\t\t\\\n\tlibarchive/archive_entry_strmode.c\t\t\t\\\n\tlibarchive/archive_entry_xattr.c\t\t\t\\\n\tlibarchive/archive_getdate.c\t\t\t\t\\\n\tlibarchive/archive_match.c\t\t\t\t\\\n\tlibarchive/archive_options.c\t\t\t\t\\\n\tlibarchive/archive_options_private.h\t\t\t\\\n\tlibarchive/archive_pathmatch.c\t\t\t\t\\\n\tlibarchive/archive_pathmatch.h\t\t\t\t\\\n\tlibarchive/archive_platform.h\t\t\t\t\\\n\tlibarchive/archive_ppmd_private.h\t\t\t\\\n\tlibarchive/archive_ppmd7.c\t\t\t\t\\\n\tlibarchive/archive_ppmd7_private.h\t\t\t\\\n\tlibarchive/archive_private.h\t\t\t\t\\\n\tlibarchive/archive_rb.c\t\t\t\t\t\\\n\tlibarchive/archive_rb.h\t\t\t\t\t\\\n\tlibarchive/archive_read.c\t\t\t\t\\\n\tlibarchive/archive_read_append_filter.c\t\t\t\\\n\tlibarchive/archive_read_data_into_fd.c\t\t\t\\\n\tlibarchive/archive_read_disk_entry_from_file.c\t\t\\\n\tlibarchive/archive_read_disk_posix.c\t\t\t\\\n\tlibarchive/archive_read_disk_private.h\t\t\t\\\n\tlibarchive/archive_read_disk_set_standard_lookup.c\t\\\n\tlibarchive/archive_read_extract.c\t\t\t\\\n\tlibarchive/a\n/* ... truncated ... */\n```\n\n\n### Type definitions\n\n```c\n/* from archive_private.h */\nstruct archive {\n\t/*\n\t * The magic/state values are used to sanity-check the\n\t * client's usage. If an API function is called at a\n\t * ridiculous time, or the client passes us an invalid\n\t * pointer, these values allow me to catch that.\n\t */\n\tunsigned int\tmagic;\n\tunsigned int\tstate;\n\n\t/*\n\t * Some public API functions depend on the \"real\" type of the\n\t * archive object.\n\t */\n\tstruct archive_vtable *vtable;\n\n\tint\t\t archive_format;\n\tconst char\t *archive_format_name;\n\n\tint\t compression_code;\t/* Currently active compression. */\n\tconst char *compression_name;\n\n\t/* Number of file entries processed. */\n\tint\t\t file_count;\n\n\tint\t\t archive_error_number;\n\tconst char\t *error;\n\tstruct archive_string\terror_string;\n\n\tchar *current_code;\n\tunsigned current_codepage; /* Current ACP(ANSI CodePage). */\n\tunsigned current_oemcp; /* Current OEMCP(OEM CodePage). */\n\tstruct archive_string_conv *sconv;\n};\n```\n\n\n## Upstream Fix\n```diff\ncommit 4e002d9a92ecd7cec0fb98b0bedbace8aad81f6e\nAuthor: Jean-Yves Migeon \nDate: Tue Sep 3 16:12:37 2013 +0200\n\n Add the device parsing logic. It allows mtree's libarchive to\n parse device entries like NetBSD's mtree and its multiple possible\n format: native, 386bsd, 4bsd, bsdos, freebsd, hpux, isc, linux, netbsd,\n osf1, sco, solaris, sunos, svr3, svr4, and ultrix.\n\nIndex: libarchive-3.1.2/libarchive/CMakeLists.txt\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/CMakeLists.txt\n+++ libarchive-3.1.2/libarchive/CMakeLists.txt\n@@ -35,6 +35,8 @@ SET(libarchive_SOURCES\n archive_match.c\n archive_options.c\n archive_options_private.h\n+ archive_pack_dev.h\n+ archive_pack_dev.c\n archive_pathmatch.c\n archive_pathmatch.h\n archive_platform.h\nIndex: libarchive-3.1.2/libarchive/archive_pack_dev.c\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/archive_pack_dev.c\n@@ -0,0 +1,304 @@\n+/*\t$NetBSD: pack_dev.c,v 1.12 2013/06/14 16:28:20 tsutsui Exp $\t*/\n+\n+/*-\n+ * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.\n+ * All rights reserved.\n+ *\n+ * This code is derived from software contributed to The NetBSD Foundation\n+ * by Charles M. Hannum.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ * 1. Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in the\n+ * documentation and/or other materials provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\n+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\n+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\n+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n+ * POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+/* Originally from NetBSD's mknod(8) source. */\n+\n+#include \"archive_platform.h\"\n+\n+#if HAVE_SYS_CDEFS_H\n+#include \n+#endif\n+#if !defined(lint)\n+__RCSID(\"$NetBSD$\");\n+#endif /* not lint */\n+\n+#ifdef HAVE_LIMITS_H\n+#include \n+#endif\n+\n+#include \n+#ifdef HAVE_STDLIB_H\n+#include \n+#endif\n+#ifdef HAVE_STRING_H\n+#include \n+#endif\n+#ifdef HAVE_SYS_TYPES_H\n+#include \n+#endif\n+#ifdef HAVE_SYS_STAT_H\n+#include \n+#endif\n+#ifdef HAVE_UNISTD_H\n+#include \n+#endif\n+\n+#include \"archive_pack_dev.h\"\n+\n+static\tpack_t\tpack_netbsd;\n+static\tpack_t\tpack_freebsd;\n+static\tpack_t\tpack_8_8;\n+static\tpack_t\tpack_12_20;\n+static\tpack_t\tpack_14_18;\n+static\tpack_t\tpack_8_24;\n+static\tpack_t\tpack_bsdos;\n+static\tint\tcompare_format(const void *, const void *);\n+\n+static const char iMajorError[] = \"invalid major number\";\n+static const char iMinorError[] = \"invalid minor number\";\n+static const char tooManyFields[] = \"too many fields for format\";\n+\n+\t/* exported */\n+dev_t\n+pack_native(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev(numbers[0], numbers[1]);\n+\t\tif ((u_long)major(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\telse if ((u_long)minor(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+static dev_t\n+pack_netbsd(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev_netbsd(numbers[0], numbers[1]);\n+\t\tif ((u_long)major_netbsd(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\telse if ((u_long)minor_netbsd(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+#define\tmajor_freebsd(x)\t((int32_t)(((x) & 0x0000ff00) >> 8))\n+#define\tminor_freebsd(x)\t((int32_t)(((x) & 0xffff00ff) >> 0))\n+#define\tmakedev_freebsd(x,y)\t((dev_t)((((x) << 8) & 0x0000ff00) | \\\n+\t\t\t\t\t (((y) << 0) & 0xffff00ff)))\n+\n+static dev_t\n+pack_freebsd(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev_freebsd(numbers[0], numbers[1]);\n+\t\tif ((u_long)major_freebsd(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\tif ((u_long)minor_freebsd(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+#define\tmajor_8_8(x)\t\t((int32_t)(((x) & 0x0000ff00) >> 8))\n+#define\tminor_8_8(x)\t\t((int32_t)(((x) & 0x000000ff) >> 0))\n+#define\tmakedev_8_8(x,y)\t((dev_t)((((x) << 8) & 0x0000ff00) | \\\n+\t\t\t\t\t (((y) << 0) & 0x000000ff)))\n+\n+static dev_t\n+pack_8_8(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev_8_8(numbers[0], numbers[1]);\n+\t\tif ((u_long)major_8_8(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\tif ((u_long)minor_8_8(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+#define\tmajor_12_20(x)\t\t((int32_t)(((x) & 0xfff00000) >> 20))\n+#define\tminor_12_20(x)\t\t((int32_t)(((x) & 0x000fffff) >> 0))\n+#define\tmakedev_12_20(x,y)\t((dev_t)((((x) << 20) & 0xfff00000) | \\\n+\t\t\t\t\t (((y) << 0) & 0x000fffff)))\n+\n+static dev_t\n+pack_12_20(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev_12_20(numbers[0], numbers[1]);\n+\t\tif ((u_long)major_12_20(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\tif ((u_long)minor_12_20(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+#define\tmajor_14_18(x)\t\t((int32_t)(((x) & 0xfffc0000) >> 18))\n+#define\tminor_14_18(x)\t\t((int32_t)(((x) & 0x0003ffff) >> 0))\n+#define\tmakedev_14_18(x,y)\t((dev_t)((((x) << 18) & 0xfffc0000) | \\\n+\t\t\t\t\t (((y) << 0) & 0x0003ffff)))\n+\n+static dev_t\n+pack_14_18(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev_14_18(numbers[0], numbers[1]);\n+\t\tif ((u_long)major_14_18(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\tif ((u_long)minor_14_18(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+#define\tmajor_8_24(x)\t\t((int32_t)(((x) & 0xff000000) >> 24))\n+#define\tminor_8_24(x)\t\t((int32_t)(((x) & 0x00ffffff) >> 0))\n+#define\tmakedev_8_24(x,y)\t((dev_t)((((x) << 24) & 0xff000000) | \\\n+\t\t\t\t\t (((y) << 0) & 0x00ffffff)))\n+\n+static dev_t\n+pack_8_24(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev_8_24(numbers[0], numbers[1]);\n+\t\tif ((u_long)major_8_24(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\tif ((u_long)minor_8_24(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+#define\tmajor_12_12_8(x)\t((int32_t)(((x) & 0xfff00000) >> 20))\n+#define\tunit_12_12_8(x)\t\t((int32_t)(((x) & 0x000fff00) >> 8))\n+#define\tsubunit_12_12_8(x)\t((int32_t)(((x) & 0x000000ff) >> 0))\n+#define\tmakedev_12_12_8(x,y,z)\t((dev_t)((((x) << 20) & 0xfff00000) | \\\n+\t\t\t\t\t (((y) << 8) & 0x000fff00) | \\\n+\t\t\t\t\t (((z) << 0) & 0x000000ff)))\n+\n+static dev_t\n+pack_bsdos(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev_12_20(numbers[0], numbers[1]);\n+\t\tif ((u_long)major_12_20(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\tif ((u_long)minor_12_20(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else \n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "commit 4e002d9a92ecd7cec0fb98b0bedbace8aad81f6e\nAuthor: Jean-Yves Migeon \nDate: Tue Sep 3 16:12:37 2013 +0200\n\n Add the device parsing logic. It allows mtree's libarchive to\n parse device entries like NetBSD's mtree and its multiple possible\n format: native, 386bsd, 4bsd, bsdos, freebsd, hpux, isc, linux, netbsd,\n osf1, sco, solaris, sunos, svr3, svr4, and ultrix.\n\nIndex: libarchive-3.1.2/libarchive/CMakeLists.txt\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/CMakeLists.txt\n+++ libarchive-3.1.2/libarchive/CMakeLists.txt\n@@ -35,6 +35,8 @@ SET(libarchive_SOURCES\n archive_match.c\n archive_options.c\n archive_options_private.h\n+ archive_pack_dev.h\n+ archive_pack_dev.c\n archive_pathmatch.c\n archive_pathmatch.h\n archive_platform.h\nIndex: libarchive-3.1.2/libarchive/archive_pack_dev.c\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/archive_pack_dev.c\n@@ -0,0 +1,304 @@\n+/*\t$NetBSD: pack_dev.c,v 1.12 2013/06/14 16:28:20 tsutsui Exp $\t*/\n+\n+/*-\n+ * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.\n+ * All rights reserved.\n+ *\n+ * This code is derived from software contributed to The NetBSD Foundation\n+ * by Charles M. Hannum.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ * 1. Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in the\n+ * documentation and/or other materials provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\n+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\n+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\n+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n+ * POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+/* Originally from NetBSD's mknod(8) source. */\n+\n+#include \"archive_platform.h\"\n+\n+#if HAVE_SYS_CDEFS_H\n+#include \n+#endif\n+#if !defined(lint)\n+__RCSID(\"$NetBSD$\");\n+#endif /* not lint */\n+\n+#ifdef HAVE_LIMITS_H\n+#include \n+#endif\n+\n+#include \n+#ifdef HAVE_STDLIB_H\n+#include \n+#endif\n+#ifdef HAVE_STRING_H\n+#include \n+#endif\n+#ifdef HAVE_SYS_TYPES_H\n+#include \n+#endif\n+#ifdef HAVE_SYS_STAT_H\n+#include \n+#endif\n+#ifdef HAVE_UNISTD_H\n+#include \n+#endif\n+\n+#include \"archive_pack_dev.h\"\n+\n+static\tpack_t\tpack_netbsd;\n+static\tpack_t\tpack_freebsd;\n+static\tpack_t\tpack_8_8;\n+static\tpack_t\tpack_12_20;\n+static\tpack_t\tpack_14_18;\n+static\tpack_t\tpack_8_24;\n+static\tpack_t\tpack_bsdos;\n+static\tint\tcompare_format(const void *, const void *);\n+\n+static const char iMajorError[] = \"invalid major number\";\n+static const char iMinorError[] = \"invalid minor number\";\n+static const char tooManyFields[] = \"too many fields for format\";\n+\n+\t/* exported */\n+dev_t\n+pack_native(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev(numbers[0], numbers[1]);\n+\t\tif ((u_long)major(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\telse if ((u_long)minor(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+static dev_t\n+pack_netbsd(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev_netbsd(numbers[0], numbers[1]);\n+\t\tif ((u_long)major_netbsd(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\telse if ((u_long)minor_netbsd(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+#define\tmajor_freebsd(x)\t((int32_t)(((x) & 0x0000ff00) >> 8))\n+#define\tminor_freebsd(x)\t((int32_t)(((x) & 0xffff00ff) >> 0))\n+#define\tmakedev_freebsd(x,y)\t((dev_t)((((x) << 8) & 0x0000ff00) | \\\n+\t\t\t\t\t (((y) << 0) & 0xffff00ff)))\n+\n+static dev_t\n+pack_freebsd(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev_freebsd(numbers[0], numbers[1]);\n+\t\tif ((u_long)major_freebsd(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\tif ((u_long)minor_freebsd(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+#define\tmajor_8_8(x)\t\t((int32_t)(((x) & 0x0000ff00) >> 8))\n+#define\tminor_8_8(x)\t\t((int32_t)(((x) & 0x000000ff) >> 0))\n+#define\tmakedev_8_8(x,y)\t((dev_t)((((x) << 8) & 0x0000ff00) | \\\n+\t\t\t\t\t (((y) << 0) & 0x000000ff)))\n+\n+static dev_t\n+pack_8_8(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev_8_8(numbers[0], numbers[1]);\n+\t\tif ((u_long)major_8_8(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\tif ((u_long)minor_8_8(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+#define\tmajor_12_20(x)\t\t((int32_t)(((x) & 0xfff00000) >> 20))\n+#define\tminor_12_20(x)\t\t((int32_t)(((x) & 0x000fffff) >> 0))\n+#define\tmakedev_12_20(x,y)\t((dev_t)((((x) << 20) & 0xfff00000) | \\\n+\t\t\t\t\t (((y) << 0) & 0x000fffff)))\n+\n+static dev_t\n+pack_12_20(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev_12_20(numbers[0], numbers[1]);\n+\t\tif ((u_long)major_12_20(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\tif ((u_long)minor_12_20(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+#define\tmajor_14_18(x)\t\t((int32_t)(((x) & 0xfffc0000) >> 18))\n+#define\tminor_14_18(x)\t\t((int32_t)(((x) & 0x0003ffff) >> 0))\n+#define\tmakedev_14_18(x,y)\t((dev_t)((((x) << 18) & 0xfffc0000) | \\\n+\t\t\t\t\t (((y) << 0) & 0x0003ffff)))\n+\n+static dev_t\n+pack_14_18(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev_14_18(numbers[0], numbers[1]);\n+\t\tif ((u_long)major_14_18(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\tif ((u_long)minor_14_18(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+#define\tmajor_8_24(x)\t\t((int32_t)(((x) & 0xff000000) >> 24))\n+#define\tminor_8_24(x)\t\t((int32_t)(((x) & 0x00ffffff) >> 0))\n+#define\tmakedev_8_24(x,y)\t((dev_t)((((x) << 24) & 0xff000000) | \\\n+\t\t\t\t\t (((y) << 0) & 0x00ffffff)))\n+\n+static dev_t\n+pack_8_24(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev_8_24(numbers[0], numbers[1]);\n+\t\tif ((u_long)major_8_24(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\tif ((u_long)minor_8_24(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+#define\tmajor_12_12_8(x)\t((int32_t)(((x) & 0xfff00000) >> 20))\n+#define\tunit_12_12_8(x)\t\t((int32_t)(((x) & 0x000fff00) >> 8))\n+#define\tsubunit_12_12_8(x)\t((int32_t)(((x) & 0x000000ff) >> 0))\n+#define\tmakedev_12_12_8(x,y,z)\t((dev_t)((((x) << 20) & 0xfff00000) | \\\n+\t\t\t\t\t (((y) << 8) & 0x000fff00) | \\\n+\t\t\t\t\t (((z) << 0) & 0x000000ff)))\n+\n+static dev_t\n+pack_bsdos(int n, u_long numbers[], const char **error)\n+{\n+\tdev_t dev = 0;\n+\n+\tif (n == 2) {\n+\t\tdev = makedev_12_20(numbers[0], numbers[1]);\n+\t\tif ((u_long)major_12_20(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\tif ((u_long)minor_12_20(dev) != numbers[1])\n+\t\t\t*error = iMinorError;\n+\t} else if (n == 3) {\n+\t\tdev = makedev_12_12_8(numbers[0], numbers[1], numbers[2]);\n+\t\tif ((u_long)major_12_12_8(dev) != numbers[0])\n+\t\t\t*error = iMajorError;\n+\t\tif ((u_long)unit_12_12_8(dev) != numbers[1])\n+\t\t\t*error = \"invalid unit number\";\n+\t\tif ((u_long)subunit_12_12_8(dev) != numbers[2])\n+\t\t\t*error = \"invalid subunit number\";\n+\t} else\n+\t\t*error = tooManyFields;\n+\treturn (dev);\n+}\n+\n+\n+\t\t/* list of formats and pack functions */\n+\t\t/* this list must be sorted lexically */\n+static struct format {\n+\tconst char\t*name;\n+\tpack_t\t\t*pack;\n+} formats[] = {\n+\t{\"386bsd\", pack_8_8},\n+\t{\"4bsd\", pack_8_8},\n+\t{\"bsdos\", pack_bsdos},\n+\t{\"freebsd\", pack_freebsd},\n+\t{\"hpux\", pack_8_24},\n+\t{\"isc\", pack_8_8},\n+\t{\"linux\", pack_8_8},\n+\t{\"native\", pack_native},\n+\t{\"netbsd\", pack_netbsd},\n+\t{\"osf1\", pack_12_20},\n+\t{\"sco\", pack_8_8},\n+\t{\"solaris\", pack_14_18},\n+\t{\"sunos\", pack_8_8},\n+\t{\"svr3\", pack_8_8},\n+\t{\"svr4\", pack_14_18},\n+\t{\"ultrix\", pack_8_8},\n+};\n+\n+static int\n+compare_format(const void *key, const void *element)\n+{\n+\tconst char\t\t*name;\n+\tconst struct format\t*format;\n+\n+\tname = key;\n+\tformat = element;\n+\n+\treturn (strcmp(name, format->name));\n+}\n+\n+\n+pack_t *\n+pack_find(const char *name)\n+{\n+\tstruct format\t*format;\n+\n+\tformat = bsearch(name, formats,\n+\t sizeof(formats)/sizeof(formats[0]),\n+\t sizeof(formats[0]), compare_format);\n+\tif (format == 0)\n+\t\treturn (NULL);\n+\treturn (format->pack);\n+}\nIndex: libarchive-3.1.2/libarchive/archive_pack_dev.h\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/archive_pack_dev.h\n@@ -0,0 +1,50 @@\n+/*\t$NetBSD: pack_dev.h,v 1.8 2013/06/14 16:28:20 tsutsui Exp $\t*/\n+\n+/*-\n+ * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.\n+ * All rights reserved.\n+ *\n+ * This code is derived from software contributed to The NetBSD Foundation\n+ * by Charles M. Hannum.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ * 1. Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in the\n+ * documentation and/or other materials provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\n+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\n+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\n+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n+ * POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+/* Originally from NetBSD's mknod(8) source. */\n+\n+#ifndef\t_PACK_DEV_H\n+#define\t_PACK_DEV_H\n+\n+typedef\tdev_t pack_t(int, u_long [], const char **);\n+typedef unsigned long u_long;\n+\n+pack_t\t*pack_find(const char *);\n+pack_t\t pack_native;\n+\n+#define\tmajor_netbsd(x)\t\t((int32_t)((((x) & 0x000fff00) >> 8)))\n+#define\tminor_netbsd(x)\t\t((int32_t)((((x) & 0xfff00000) >> 12) | \\\n+\t\t\t\t\t (((x) & 0x000000ff) >> 0)))\n+#define\tmakedev_netbsd(x,y)\t((dev_t)((((x) << 8) & 0x000fff00) | \\\n+\t\t\t\t\t (((y) << 12) & 0xfff00000) | \\\n+\t\t\t\t\t (((y) << 0) & 0x000000ff)))\n+\n+#endif\t/* _PACK_DEV_H */\nIndex: libarchive-3.1.2/libarchive/archive_platform.h\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_platform.h\n+++ libarchive-3.1.2/libarchive/archive_platform.h\n@@ -66,15 +66,18 @@\n * headers as required.\n */\n \n-/* Get a real definition for __FBSDID if we can */\n+/* Get a real definition for __FBSDID or __RCSID if we can */\n #if HAVE_SYS_CDEFS_H\n #include \n #endif\n \n-/* If not, define it so as to avoid dangling semicolons. */\n+/* If not, define them so as to avoid dangling semicolons. */\n #ifndef __FBSDID\n #define\t__FBSDID(a) struct _undefined_hack\n #endif\n+#ifndef __RCSID\n+#define\t__RCSID(a) struct _undefined_hack\n+#endif\n \n /* Try to get standard C99-style integer type definitions. */\n #if HAVE_INTTYPES_H\nIndex: libarchive-3.1.2/libarchive/archive_read_support_format_mtree.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_read_support_format_mtree.c\n+++ libarchive-3.1.2/libarchive/archive_read_support_format_mtree.c\n@@ -51,6 +51,7 @@ __FBSDID(\"$FreeBSD: head/lib/libarchive/\n #include \"archive_private.h\"\n #include \"archive_read_private.h\"\n #include \"archive_string.h\"\n+#include \"archive_pack_dev.h\"\n \n #ifndef O_BINARY\n #define\tO_BINARY 0\n@@ -1300,33 +1301,63 @@ parse_line(struct archive_read *a, struc\n \n /*\n * Device entries have one of the following forms:\n- * raw dev_t\n- * format,major,minor[,subdevice]\n- *\n- * Just use major and minor, no translation etc is done\n- * between formats.\n+ * - raw dev_t\n+ * - format,major,minor[,subdevice]\n */\n static int\n parse_device(struct archive *a, struct archive_entry *entry, char *val)\n {\n-\tchar *comma1, *comma2;\n+#define MAX_PACK_ARGS 3\n+\tunsigned long numbers[MAX_PACK_ARGS];\n+\tchar *p, *dev;\n+\tint argc;\n+\tpack_t *pack;\n+\tdev_t result;\n+\tconst char *error = NULL;\n \n-\tcomma1 = strchr(val, ',');\n-\tif (comma1 == NULL) {\n-\t\tarchive_entry_set_dev(entry, (dev_t)mtree_atol10(&val));\n-\t\treturn (ARCHIVE_OK);\n-\t}\n-\t++comma1;\n-\tcomma2 = strchr(comma1, ',');\n-\tif (comma2 == NULL) {\n-\t\tarchive_set_error(a, ARCHIVE_ERRNO_FILE_FORMAT,\n-\t\t \"Malformed device attribute\");\n-\t\treturn (ARCHIVE_WARN);\n+\tif ((dev = strchr(val, ',')) != NULL) {\n+\t\t/*\n+\t\t * Device's major/minor are given in a specified format.\n+\t\t * Decode and pack it accordingly.\n+\t\t */\n+\t\t*dev++ = '\\0';\n+\t\tif ((pack = pack_find(val)) == NULL) {\n+\t\t\tarchive_set_error(a, ARCHIVE_ERRNO_FILE_FORMAT,\n+\t\t\t \"Unknown format `%s'\", val);\n+\t\t\treturn ARCHIVE_WARN;\n+\t\t}\n+\t\targc = 0;\n+\t\twhile ((p = strsep(&dev, \",\")) != NULL) {\n+\t\t\tif (*p == '\\0') {\n+\t\t\t\tarchive_set_error(a, ARCHIVE_ERRNO_FILE_FORMAT,\n+\t\t\t\t \"Missing number\");\n+\t\t\t\treturn ARCHIVE_WARN;\n+\t\t\t}\n+\t\t\tnumbers[argc++] = mtree_atol(&p);\n+\t\t\tif (argc > MAX_PACK_ARGS) {\n+\t\t\t\tarchive_set_error(a, ARCHIVE_ERRNO_FILE_FORMAT,\n+\t\t\t\t \"Too many arguments\");\n+\t\t\t\treturn ARCHIVE_WARN;\n+\t\t\t}\n+\t\t}\n+\t\tif (argc < 2) {\n+\t\t\tarchive_set_error(a, ARCHIVE_ERRNO_FILE_FORMAT,\n+\t\t\t \"Not enough arguments\");\n+\t\t\treturn ARCHIVE_WARN;\n+\t\t}\n+\t\tresult = (*pack)(argc, numbers, &error);\n+\t\tif (error != NULL) {\n+\t\t\tarchive_set_error(a, ARCHIVE_ERRNO_FILE_FORMAT,\n+\t\t\t \"%s\", error);\n+\t\t\treturn ARCHIVE_WARN;\n+\t\t}\n+\t\tarchive_entry_set_rdev(entry, result);\n+\t} else {\n+\t\t/* file system raw value. */\n+\t\tarchive_entry_set_rdev(entry, (dev_t)mtree_atol(&val));\n \t}\n-\t++comma2;\n-\tarchive_entry_set_rdevmajor(entry, (dev_t)mtree_atol(&comma1));\n-\tarchive_entry_set_rdevminor(entry, (dev_t)mtree_atol(&comma2));\n-\treturn (ARCHIVE_OK);\n+\treturn ARCHIVE_OK;\n+#undef MAX_PACK_ARGS\n }\n \n /*\nIndex: libarchive-3.1.2/Makefile.am\n===================================================================\n--- libarchive-3.1.2.orig/Makefile.am\n+++ libarchive-3.1.2/Makefile.am\n@@ -110,6 +110,8 @@ libarchive_la_SOURCES=\t\t\t\t\t\t\\\n \tlibarchive/archive_match.c\t\t\t\t\\\n \tlibarchive/archive_options.c\t\t\t\t\\\n \tlibarchive/archive_options_private.h\t\t\t\\\n+\tlibarchive/archive_pack_dev.h\t\t\t\t\\\n+\tlibarchive/archive_pack_dev.c\t\t\t\t\\\n \tlibarchive/archive_pathmatch.c\t\t\t\t\\\n \tlibarchive/archive_pathmatch.h\t\t\t\t\\\n \tlibarchive/archive_platform.h\t\t\t\t\\"}], "metadata": {"id": "libarchive-5942-CVE-2016-4301-base.patch", "cve_id": "CVE-2016-6250", "package": "libarchive", "tier": "adapted", "has_source_context": true, "context_tokens_est": 2422, "context_files": 4, "license": "BSD-2-Clause"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3455\n\nSquid 3.2.x before 3.2.14, 3.3.x before 3.3.14, 3.4.x before 3.4.13, and 3.5.x before 3.5.4, when configured with client-first SSL-bump, do not properly validate the domain or hostname fields of X.509 certificates, which allows man-in-the-middle attackers to spoof SSL servers via a valid certificate.\n\n## Package\nsquid\n\n## Files to modify\n- src/comm.h\n- src/forward.h\n- squid-3.3.13.orig/src/forward.h\n- squid-3.3.13.orig/src/comm.h\n- src/Server.h\n\n## Upstream Fix\n```diff\nIndex: squid-3.3.13/src/forward.h\n===================================================================\n--- squid-3.3.13.orig/src/forward.h\n+++ squid-3.3.13/src/forward.h\n@@ -86,6 +86,9 @@ private:\n ErrorState *makeConnectingError(const err_type type) const;\n static void RegisterWithCacheManager(void);\n \n+ /// stops monitoring server connection for closure and updates pconn stats\n+ void closeServerConnection(const char *reason);\n+\n public:\n StoreEntry *entry;\n HttpRequest *request;\n@@ -116,6 +119,8 @@ private:\n \n Comm::ConnectionPointer serverConn; ///< a successfully opened connection to a server.\n \n+ AsyncCall::Pointer closeHandler; ///< The serverConn close handler\n+\n /// possible pconn race states\n typedef enum { raceImpossible, racePossible, raceHappened } PconnRace;\n PconnRace pconnRace; ///< current pconn race state\nIndex: squid-3.3.13/src/forward.cc\n===================================================================\n--- squid-3.3.13.orig/src/forward.cc\n+++ squid-3.3.13/src/forward.cc\n@@ -102,10 +102,7 @@ FwdState::abort(void* d)\n Pointer tmp = fwd; // Grab a temporary pointer to keep the object alive during our scope.\n \n if (Comm::IsConnOpen(fwd->serverConnection())) {\n- comm_remove_close_handler(fwd->serverConnection()->fd, fwdServerClosedWrapper, fwd);\n- debugs(17, 3, HERE << \"store entry aborted; closing \" <<\n- fwd->serverConnection());\n- fwd->serverConnection()->close();\n+ fwd->closeServerConnection(\"store entry aborted\");\n } else {\n debugs(17, 7, HERE << \"store entry aborted; no connection to close\");\n }\n@@ -113,6 +110,16 @@ FwdState::abort(void* d)\n fwd->self = NULL;\n }\n \n+void\n+FwdState::closeServerConnection(const char *reason)\n+{\n+ debugs(17, 3, \"because \" << reason << \"; \" << serverConn);\n+ comm_remove_close_handler(serverConn->fd, closeHandler);\n+ closeHandler = NULL;\n+ fwdPconnPool->noteUses(fd_table[serverConn->fd].pconn.uses);\n+ serverConn->close();\n+}\n+\n /**** PUBLIC INTERFACE ********************************************************/\n \n FwdState::FwdState(const Comm::ConnectionPointer &client, StoreEntry * e, HttpRequest * r, const AccessLogEntryPointer &alp):\n@@ -268,9 +275,7 @@ FwdState::~FwdState()\n }\n \n if (Comm::IsConnOpen(serverConn)) {\n- comm_remove_close_handler(serverConnection()->fd, fwdServerClosedWrapper, this);\n- debugs(17, 3, HERE << \"closing FD \" << serverConnection()->fd);\n- serverConn->close();\n+ closeServerConnection(__FUNCTION__);\n }\n \n serverDestinations.clean();\n@@ -426,7 +431,8 @@ FwdState::unregister(Comm::ConnectionPoi\n debugs(17, 3, HERE << entry->url() );\n assert(serverConnection() == conn);\n assert(Comm::IsConnOpen(conn));\n- comm_remove_close_handler(conn->fd, fwdServerClosedWrapper, this);\n+ comm_remove_close_handler(conn->fd, closeHandler);\n+ closeHandler = NULL;\n serverConn = NULL;\n }\n \n@@ -884,7 +890,7 @@ FwdState::connectDone(const Comm::Connec\n \n debugs(17, 3, HERE << serverConnection() << \": '\" << entry->url() << \"'\" );\n \n- comm_add_close_handler(serverConnection()->fd, fwdServerClosedWrapper, this);\n+ closeHandler = comm_add_close_handler(serverConnection()->fd, fwdServerClosedWrapper, this);\n \n if (serverConnection()->getPeer())\n peerConnectSucceded(serverConnection()->getPeer());\n@@ -988,7 +994,7 @@ FwdState::connectStart()\n request->hier.note(serverConn, pinned_connection->pinning.host);\n if (pinned_connection->pinnedAuth())\n request->flags.auth = 1;\n- comm_add_close_handler(serverConn->fd, fwdServerClosedWrapper, this);\n+ closeHandler = comm_add_close_handler(serverConn->fd, fwdServerClosedWrapper, this);\n // the server may close the pinned connection before this request\n pconnRace = racePossible;\n dispatch();\n@@ -1024,7 +1030,7 @@ FwdState::connectStart()\n debugs(17, 3, HERE << \"reusing pconn \" << serverConnection());\n ++n_tries;\n \n- comm_add_close_handler(serverConnection()->fd, fwdServerClosedWrapper, this);\n+ closeHandler = comm_add_close_handler(serverConnection()->fd, fwdServerClosedWrapper, this);\n \n /* Update server side TOS and Netfilter mark on the connection. */\n if (Ip::Qos::TheConfig.isAclTosActive()) {\nIndex: squid-3.3.13/src/Server.h\n===================================================================\n--- squid-3.3.13.orig/src/Server.h\n+++ squid-3.3.13/src/Server.h\n@@ -125,7 +125,9 @@ protected:\n virtual void sentRequestBody(const CommIoCbParams &io) = 0;\n virtual void doneSendingRequestBody() = 0;\n \n- virtual void closeServer() = 0; /**< end communication with the server */\n+ /// Use this to end communication with the server. The call cancels our\n+ /// closure handler and tells FwdState to forget about the connection.\n+ virtual void closeServer() = 0;\n virtual bool doneWithServer() const = 0; /**< did we end communication? */\n \n /// Entry-dependent callbacks use this check to quit if the entry went bad\nIndex: squid-3.3.13/src/comm.cc\n===================================================================\n--- squid-3.3.13.orig/src/comm.cc\n+++ squid-3.3.13/src/comm.cc\n@@ -1221,7 +1221,7 @@ comm_udp_sendto(int fd,\n return COMM_ERROR;\n }\n \n-void\n+AsyncCall::Pointer\n comm_add_close_handler(int fd, CLCB * handler, void *data)\n {\n debugs(5, 5, \"comm_add_close_handler: FD \" << fd << \", handler=\" <<\n@@ -1230,6 +1230,7 @@ comm_add_close_handler(int fd, CLCB * ha\n AsyncCall::Pointer call=commCbCall(5,4, \"SomeCloseHandler\",\n CommCloseCbPtrFun(handler, data));\n comm_add_close_handler(fd, call);\n+ return call;\n }\n \n void\nIndex: squid-3.3.13/src/comm.h\n===================================================================\n--- squid-3.3.13.orig/src/comm.h\n+++ squid-3.3.13/src/comm.h\n@@ -75,7 +75,7 @@ void commCloseAllSockets(void);\n void checkTimeouts(void);\n \n //typedef void IOACB(int fd, int nfd, Comm::ConnectionPointer details, comm_err_t flag, int xerrno, void *data);\n-void comm_add_close_handler(int fd, CLCB *, void *);\n+AsyncCall::Pointer comm_add_close_handler(int fd, CLCB *, void *);\n void comm_add_close_handler(int fd, AsyncCall::Pointer &);\n void comm_remove_close_handler(int fd, CLCB *, void *);\n void comm_remove_close_handler(int fd, AsyncCall::Pointer &);\nIndex: squid-3.3.13/src/http.cc\n===================================================================\n--- squid-3.3.13.orig/src/http.cc\n+++ squid-3.3.13/src/http.cc\n@@ -199,7 +199,8 @@ HttpStateData::httpTimeout(const CommTim\n fwd->fail(new ErrorState(ERR_READ_TIMEOUT, HTTP_GATEWAY_TIMEOUT, fwd->request));\n }\n \n- serverConnection->close();\n+ closeServer();\n+ mustStop(\"HttpStateData::httpTimeout\");\n }\n \n static void\n@@ -1174,7 +1175,8 @@ HttpStateData::readReply(const CommIoCbP\n err->xerrno = io.xerrno;\n fwd->fail(err);\n flags.do_next_read = false;\n- serverConnection->close();\n+ closeServer();\n+ mustStop(\"HttpStateData::readReply\");\n }\n \n return;\n@@ -1327,7 +1329,8 @@ HttpStateData::continueAfterParsingHeade\n entry->reset();\n fwd->fail(new ErrorState(error, HTTP_BAD_GATEWAY, fwd->request));\n flags.do_next_read = false;\n- serverConnection->close();\n+ closeServer();\n+ mustStop(\"HttpStateData::continueAfterParsingHeader\");\n return false; // quit on error\n }\n \n@@ -1552,7 +1555,8 @@ HttpStateData::wroteLast(const CommIoCbP\n ErrorState *err = new ErrorState(ERR_WRITE_ERROR, HTTP_BAD_GATEWAY, fwd->request);\n err->xerrno = io.xerrno;\n fwd->fail(err);\n- serverConnection->close();\n+ closeServer();\n+ mustStop(\"HttpStateData::wroteLast\");\n return;\n }\n \n@@ -1580,7 +1584,6 @@ HttpStateData::sendComplete()\n requ\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "Index: squid-3.3.13/src/forward.h\n===================================================================\n--- squid-3.3.13.orig/src/forward.h\n+++ squid-3.3.13/src/forward.h\n@@ -86,6 +86,9 @@ private:\n ErrorState *makeConnectingError(const err_type type) const;\n static void RegisterWithCacheManager(void);\n \n+ /// stops monitoring server connection for closure and updates pconn stats\n+ void closeServerConnection(const char *reason);\n+\n public:\n StoreEntry *entry;\n HttpRequest *request;\n@@ -116,6 +119,8 @@ private:\n \n Comm::ConnectionPointer serverConn; ///< a successfully opened connection to a server.\n \n+ AsyncCall::Pointer closeHandler; ///< The serverConn close handler\n+\n /// possible pconn race states\n typedef enum { raceImpossible, racePossible, raceHappened } PconnRace;\n PconnRace pconnRace; ///< current pconn race state\nIndex: squid-3.3.13/src/forward.cc\n===================================================================\n--- squid-3.3.13.orig/src/forward.cc\n+++ squid-3.3.13/src/forward.cc\n@@ -102,10 +102,7 @@ FwdState::abort(void* d)\n Pointer tmp = fwd; // Grab a temporary pointer to keep the object alive during our scope.\n \n if (Comm::IsConnOpen(fwd->serverConnection())) {\n- comm_remove_close_handler(fwd->serverConnection()->fd, fwdServerClosedWrapper, fwd);\n- debugs(17, 3, HERE << \"store entry aborted; closing \" <<\n- fwd->serverConnection());\n- fwd->serverConnection()->close();\n+ fwd->closeServerConnection(\"store entry aborted\");\n } else {\n debugs(17, 7, HERE << \"store entry aborted; no connection to close\");\n }\n@@ -113,6 +110,16 @@ FwdState::abort(void* d)\n fwd->self = NULL;\n }\n \n+void\n+FwdState::closeServerConnection(const char *reason)\n+{\n+ debugs(17, 3, \"because \" << reason << \"; \" << serverConn);\n+ comm_remove_close_handler(serverConn->fd, closeHandler);\n+ closeHandler = NULL;\n+ fwdPconnPool->noteUses(fd_table[serverConn->fd].pconn.uses);\n+ serverConn->close();\n+}\n+\n /**** PUBLIC INTERFACE ********************************************************/\n \n FwdState::FwdState(const Comm::ConnectionPointer &client, StoreEntry * e, HttpRequest * r, const AccessLogEntryPointer &alp):\n@@ -268,9 +275,7 @@ FwdState::~FwdState()\n }\n \n if (Comm::IsConnOpen(serverConn)) {\n- comm_remove_close_handler(serverConnection()->fd, fwdServerClosedWrapper, this);\n- debugs(17, 3, HERE << \"closing FD \" << serverConnection()->fd);\n- serverConn->close();\n+ closeServerConnection(__FUNCTION__);\n }\n \n serverDestinations.clean();\n@@ -426,7 +431,8 @@ FwdState::unregister(Comm::ConnectionPoi\n debugs(17, 3, HERE << entry->url() );\n assert(serverConnection() == conn);\n assert(Comm::IsConnOpen(conn));\n- comm_remove_close_handler(conn->fd, fwdServerClosedWrapper, this);\n+ comm_remove_close_handler(conn->fd, closeHandler);\n+ closeHandler = NULL;\n serverConn = NULL;\n }\n \n@@ -884,7 +890,7 @@ FwdState::connectDone(const Comm::Connec\n \n debugs(17, 3, HERE << serverConnection() << \": '\" << entry->url() << \"'\" );\n \n- comm_add_close_handler(serverConnection()->fd, fwdServerClosedWrapper, this);\n+ closeHandler = comm_add_close_handler(serverConnection()->fd, fwdServerClosedWrapper, this);\n \n if (serverConnection()->getPeer())\n peerConnectSucceded(serverConnection()->getPeer());\n@@ -988,7 +994,7 @@ FwdState::connectStart()\n request->hier.note(serverConn, pinned_connection->pinning.host);\n if (pinned_connection->pinnedAuth())\n request->flags.auth = 1;\n- comm_add_close_handler(serverConn->fd, fwdServerClosedWrapper, this);\n+ closeHandler = comm_add_close_handler(serverConn->fd, fwdServerClosedWrapper, this);\n // the server may close the pinned connection before this request\n pconnRace = racePossible;\n dispatch();\n@@ -1024,7 +1030,7 @@ FwdState::connectStart()\n debugs(17, 3, HERE << \"reusing pconn \" << serverConnection());\n ++n_tries;\n \n- comm_add_close_handler(serverConnection()->fd, fwdServerClosedWrapper, this);\n+ closeHandler = comm_add_close_handler(serverConnection()->fd, fwdServerClosedWrapper, this);\n \n /* Update server side TOS and Netfilter mark on the connection. */\n if (Ip::Qos::TheConfig.isAclTosActive()) {\nIndex: squid-3.3.13/src/Server.h\n===================================================================\n--- squid-3.3.13.orig/src/Server.h\n+++ squid-3.3.13/src/Server.h\n@@ -125,7 +125,9 @@ protected:\n virtual void sentRequestBody(const CommIoCbParams &io) = 0;\n virtual void doneSendingRequestBody() = 0;\n \n- virtual void closeServer() = 0; /**< end communication with the server */\n+ /// Use this to end communication with the server. The call cancels our\n+ /// closure handler and tells FwdState to forget about the connection.\n+ virtual void closeServer() = 0;\n virtual bool doneWithServer() const = 0; /**< did we end communication? */\n \n /// Entry-dependent callbacks use this check to quit if the entry went bad\nIndex: squid-3.3.13/src/comm.cc\n===================================================================\n--- squid-3.3.13.orig/src/comm.cc\n+++ squid-3.3.13/src/comm.cc\n@@ -1221,7 +1221,7 @@ comm_udp_sendto(int fd,\n return COMM_ERROR;\n }\n \n-void\n+AsyncCall::Pointer\n comm_add_close_handler(int fd, CLCB * handler, void *data)\n {\n debugs(5, 5, \"comm_add_close_handler: FD \" << fd << \", handler=\" <<\n@@ -1230,6 +1230,7 @@ comm_add_close_handler(int fd, CLCB * ha\n AsyncCall::Pointer call=commCbCall(5,4, \"SomeCloseHandler\",\n CommCloseCbPtrFun(handler, data));\n comm_add_close_handler(fd, call);\n+ return call;\n }\n \n void\nIndex: squid-3.3.13/src/comm.h\n===================================================================\n--- squid-3.3.13.orig/src/comm.h\n+++ squid-3.3.13/src/comm.h\n@@ -75,7 +75,7 @@ void commCloseAllSockets(void);\n void checkTimeouts(void);\n \n //typedef void IOACB(int fd, int nfd, Comm::ConnectionPointer details, comm_err_t flag, int xerrno, void *data);\n-void comm_add_close_handler(int fd, CLCB *, void *);\n+AsyncCall::Pointer comm_add_close_handler(int fd, CLCB *, void *);\n void comm_add_close_handler(int fd, AsyncCall::Pointer &);\n void comm_remove_close_handler(int fd, CLCB *, void *);\n void comm_remove_close_handler(int fd, AsyncCall::Pointer &);\nIndex: squid-3.3.13/src/http.cc\n===================================================================\n--- squid-3.3.13.orig/src/http.cc\n+++ squid-3.3.13/src/http.cc\n@@ -199,7 +199,8 @@ HttpStateData::httpTimeout(const CommTim\n fwd->fail(new ErrorState(ERR_READ_TIMEOUT, HTTP_GATEWAY_TIMEOUT, fwd->request));\n }\n \n- serverConnection->close();\n+ closeServer();\n+ mustStop(\"HttpStateData::httpTimeout\");\n }\n \n static void\n@@ -1174,7 +1175,8 @@ HttpStateData::readReply(const CommIoCbP\n err->xerrno = io.xerrno;\n fwd->fail(err);\n flags.do_next_read = false;\n- serverConnection->close();\n+ closeServer();\n+ mustStop(\"HttpStateData::readReply\");\n }\n \n return;\n@@ -1327,7 +1329,8 @@ HttpStateData::continueAfterParsingHeade\n entry->reset();\n fwd->fail(new ErrorState(error, HTTP_BAD_GATEWAY, fwd->request));\n flags.do_next_read = false;\n- serverConnection->close();\n+ closeServer();\n+ mustStop(\"HttpStateData::continueAfterParsingHeader\");\n return false; // quit on error\n }\n \n@@ -1552,7 +1555,8 @@ HttpStateData::wroteLast(const CommIoCbP\n ErrorState *err = new ErrorState(ERR_WRITE_ERROR, HTTP_BAD_GATEWAY, fwd->request);\n err->xerrno = io.xerrno;\n fwd->fail(err);\n- serverConnection->close();\n+ closeServer();\n+ mustStop(\"HttpStateData::wroteLast\");\n return;\n }\n \n@@ -1580,7 +1584,6 @@ HttpStateData::sendComplete()\n request->hier.peer_http_request_sent = current_time;\n }\n \n-// Close the HTTP server connection. Used by serverComplete().\n void\n HttpStateData::closeServer()\n {\n@@ -2377,7 +2380,8 @@ HttpStateData::handleMoreRequestBodyAvai\n debugs(11, DBG_IMPORTANT, \"http handleMoreRequestBodyAvailable: Likely proxy abuse detected '\" << request->client_addr << \"' -> '\" << entry->url() << \"'\" );\n \n if (virginReply()->sline.status == HTTP_INVALID_HEADER) {\n- serverConnection->close();\n+ closeServer();\n+ mustStop(\"HttpStateData::handleMoreRequestBodyAvailable\");\n return;\n }\n }"}], "metadata": {"id": "squid-5473-SQUID_2016_2_fix_port.patch", "cve_id": "CVE-2015-3455", "package": "squid", "tier": "adapted", "has_source_context": false, "license": "GPL-2.0-or-later"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1i.orig/crypto/rsa/rsa_ameth.c\n- crypto/rsa/rsa_ameth.c\n- openssl-1.0.1i/crypto/rsa/rsa_ameth.c\n\n## Target Source Code\n\n### crypto/rsa/rsa_ameth.c\n\n#### region() [lines 248-335]\n```c\n\t\t}\n\tret=1;\nerr:\n\tif (m != NULL) OPENSSL_free(m);\n\treturn(ret);\n\t}\n\nstatic int rsa_pub_print(BIO *bp, const EVP_PKEY *pkey, int indent,\n\t\t\t\t\t\t\tASN1_PCTX *ctx)\n\t{\n\treturn do_rsa_print(bp, pkey->pkey.rsa, indent, 0);\n\t}\n\n\nstatic int rsa_priv_print(BIO *bp, const EVP_PKEY *pkey, int indent,\n\t\t\t\t\t\t\tASN1_PCTX *ctx)\n\t{\n\treturn do_rsa_print(bp, pkey->pkey.rsa, indent, 1);\n\t}\n\nstatic RSA_PSS_PARAMS *rsa_pss_decode(const X509_ALGOR *alg,\n\t\t\t\t\tX509_ALGOR **pmaskHash)\n\t{\n\tconst unsigned char *p;\n\tint plen;\n\tRSA_PSS_PARAMS *pss;\n\n\t*pmaskHash = NULL;\n\n\tif (!alg->parameter || alg->parameter->type != V_ASN1_SEQUENCE)\n\t\treturn NULL;\n\tp = alg->parameter->value.sequence->data;\n\tplen = alg->parameter->value.sequence->length;\n\tpss = d2i_RSA_PSS_PARAMS(NULL, &p, plen);\n\n\tif (!pss)\n\t\treturn NULL;\n\t\n\tif (pss->maskGenAlgorithm)\n\t\t{\n\t\tASN1_TYPE *param = pss->maskGenAlgorithm->parameter;\n\t\tif (OBJ_obj2nid(pss->maskGenAlgorithm->algorithm) == NID_mgf1\n\t\t\t&& param->type == V_ASN1_SEQUENCE)\n\t\t\t{\n\t\t\tp = param->value.sequence->data;\n\t\t\tplen = param->value.sequence->length;\n\t\t\t*pmaskHash = d2i_X509_ALGOR(NULL, &p, plen);\n\t\t\t}\n\t\t}\n\n\treturn pss;\n\t}\n\nstatic int rsa_pss_param_print(BIO *bp, RSA_PSS_PARAMS *pss, \n\t\t\t\tX509_ALGOR *maskHash, int indent)\n\t{\n\tint rv = 0;\n\tif (!pss)\n\t\t{\n\t\tif (BIO_puts(bp, \" (INVALID PSS PARAMETERS)\\n\") <= 0)\n\t\t\treturn 0;\n\t\treturn 1;\n\t\t}\n\tif (BIO_puts(bp, \"\\n\") <= 0)\n\t\tgoto err;\n\tif (!BIO_indent(bp, indent, 128))\n\t\tgoto err;\n\tif (BIO_puts(bp, \"Hash Algorithm: \") <= 0)\n\t\tgoto err;\n\n\tif (pss->hashAlgorithm)\n\t\t{\n\t\tif (i2a_ASN1_OBJECT(bp, pss->hashAlgorithm->algorithm) <= 0)\n\t\t\tgoto err;\n\t\t}\n\telse if (BIO_puts(bp, \"sha1 (default)\") <= 0)\n\t\tgoto err;\n\n\tif (BIO_puts(bp, \"\\n\") <= 0)\n\t\tgoto err;\n\n\tif (!BIO_indent(bp, indent, 128))\n\t\tgoto err;\n\n\tif (BIO_puts(bp, \"Mask Algorithm: \") <= 0)\n\t\t\tgoto err;\n\tif (pss->maskGenAlgorithm)\n\t\t{\n```\n\n\n## Upstream Fix\n```diff\nFrom d8541d7e9e63bf5f343af24644046c8d96498c17 Mon Sep 17 00:00:00 2001\nFrom: \"Dr. Stephen Henson\" \nDate: Fri, 2 Oct 2015 13:10:29 +0100\nSubject: [PATCH] Add PSS parameter check.\nMIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\n\nAvoid seg fault by checking mgf1 parameter is not NULL. This can be\ntriggered during certificate verification so could be a DoS attack\nagainst a client or a server enabling client authentication.\n\nThanks to Loïc Jonas Etienne (Qnective AG) for discovering this bug.\n\nCVE-2015-3194\n\nReviewed-by: Matt Caswell \n---\n crypto/rsa/rsa_ameth.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/crypto/rsa/rsa_ameth.c b/crypto/rsa/rsa_ameth.c\nindex 93e071de75e2a..c7f1148a1ded1 100644\n--- a/crypto/rsa/rsa_ameth.c\n+++ b/crypto/rsa/rsa_ameth.c\n@@ -279,7 +279,7 @@ static RSA_PSS_PARAMS *rsa_pss_decode(const X509_ALGOR *alg,\n if (pss->maskGenAlgorithm) {\n ASN1_TYPE *param = pss->maskGenAlgorithm->parameter;\n if (OBJ_obj2nid(pss->maskGenAlgorithm->algorithm) == NID_mgf1\n- && param->type == V_ASN1_SEQUENCE) {\n+ && param && param->type == V_ASN1_SEQUENCE) {\n p = param->value.sequence->data;\n plen = param->value.sequence->length;\n *pmaskHash = d2i_X509_ALGOR(NULL, &p, plen);\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From d8541d7e9e63bf5f343af24644046c8d96498c17 Mon Sep 17 00:00:00 2001\nFrom: \"Dr. Stephen Henson\" \nDate: Fri, 2 Oct 2015 13:10:29 +0100\nSubject: [PATCH] Add PSS parameter check.\nMIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\n\nAvoid seg fault by checking mgf1 parameter is not NULL. This can be\ntriggered during certificate verification so could be a DoS attack\nagainst a client or a server enabling client authentication.\n\nThanks to Loïc Jonas Etienne (Qnective AG) for discovering this bug.\n\nCVE-2015-3194\n\nReviewed-by: Matt Caswell \n---\n crypto/rsa/rsa_ameth.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\nIndex: openssl-1.0.1i/crypto/rsa/rsa_ameth.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/rsa/rsa_ameth.c\t2015-12-03 17:56:38.292632624 +0100\n+++ openssl-1.0.1i/crypto/rsa/rsa_ameth.c\t2015-12-03 17:58:11.106130819 +0100\n@@ -287,7 +287,7 @@ static RSA_PSS_PARAMS *rsa_pss_decode(co\n \t\t{\n \t\tASN1_TYPE *param = pss->maskGenAlgorithm->parameter;\n \t\tif (OBJ_obj2nid(pss->maskGenAlgorithm->algorithm) == NID_mgf1\n-\t\t\t&& param->type == V_ASN1_SEQUENCE)\n+\t\t\t&& param && param->type == V_ASN1_SEQUENCE)\n \t\t\t{\n \t\t\tp = param->value.sequence->data;\n \t\t\tplen = param->value.sequence->length;"}], "metadata": {"id": "openssl-4598-openssl-CVE-2015-3194.patch", "cve_id": "CVE-2015-3197", "package": "openssl", "upstream_enriched": true, "upstream_commit": "d8541d7e9e63bf5f343af24644046c8d96498c17", "upstream_repo": "openssl/openssl", "tier": "adapted", "has_source_context": true, "context_tokens_est": 478, "context_files": 1, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2013-2487\n\nepan/dissectors/packet-reload.c in the REsource LOcation And Discovery (aka RELOAD) dissector in Wireshark 1.8.x before 1.8.6 uses incorrect integer data types, which allows remote attackers to cause a denial of service (infinite loop) via crafted integer values in a packet, related to the (1) dissect_icecandidates, (2) dissect_kinddata, (3) dissect_nodeid_list, (4) dissect_storeans, (5) dissect_storereq, (6) dissect_storeddataspecifier, (7) dissect_fetchreq, (8) dissect_findans, (9) dissect_diagnosticinfo, (10) dissect_diagnosticresponse, (11) dissect_reload_messagecontents, and (12) dissect_reload_message functions, a different vulnerability than CVE-2013-2486.\n\n## Package\nwireshark\n\n## Files to modify\n- ui/gtk/main.c\n\n## Upstream Fix\n```diff\nIndex: ui/gtk/main.c\n===================================================================\n--- ui/gtk/main.c.orig\t2012-08-10 01:35:00.000000000 +0100\n+++ ui/gtk/main.c\t2012-08-15 20:28:59.000000000 +0100\n@@ -1399,11 +1399,13 @@ main_colorize_changed(gboolean packet_li\n \n static GtkWidget *close_dlg = NULL;\n \n+/*\n static void\n priv_warning_dialog_cb(gpointer dialog, gint btn _U_, gpointer data _U_)\n {\n recent.privs_warn_if_elevated = !simple_dialog_check_get(dialog);\n }\n+*/\n \n #ifdef _WIN32\n static void\n@@ -2081,9 +2083,10 @@ check_and_warn_user_startup(gchar *cf_na\n #endif\n {\n gchar *cur_user, *cur_group;\n- gpointer priv_warning_dialog;\n+// gpointer priv_warning_dialog;\n \n /* Tell the user not to run as root. */\n+/*\n if (running_with_special_privs() && recent.privs_warn_if_elevated) {\n cur_user = get_cur_username();\n cur_group = get_cur_groupname();\n@@ -2098,6 +2101,7 @@ check_and_warn_user_startup(gchar *cf_na\n simple_dialog_check_set(priv_warning_dialog, \"Don't show this message again.\");\n simple_dialog_set_cb(priv_warning_dialog, priv_warning_dialog_cb, NULL);\n }\n+*/\n \n #ifdef _WIN32\n /* Warn the user if npf.sys isn't loaded. */\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "Index: ui/gtk/main.c\n===================================================================\n--- ui/gtk/main.c.orig\t2012-08-10 01:35:00.000000000 +0100\n+++ ui/gtk/main.c\t2012-08-15 20:28:59.000000000 +0100\n@@ -1399,11 +1399,13 @@ main_colorize_changed(gboolean packet_li\n \n static GtkWidget *close_dlg = NULL;\n \n+/*\n static void\n priv_warning_dialog_cb(gpointer dialog, gint btn _U_, gpointer data _U_)\n {\n recent.privs_warn_if_elevated = !simple_dialog_check_get(dialog);\n }\n+*/\n \n #ifdef _WIN32\n static void\n@@ -2081,9 +2083,10 @@ check_and_warn_user_startup(gchar *cf_na\n #endif\n {\n gchar *cur_user, *cur_group;\n- gpointer priv_warning_dialog;\n+// gpointer priv_warning_dialog;\n \n /* Tell the user not to run as root. */\n+/*\n if (running_with_special_privs() && recent.privs_warn_if_elevated) {\n cur_user = get_cur_username();\n cur_group = get_cur_groupname();\n@@ -2098,6 +2101,7 @@ check_and_warn_user_startup(gchar *cf_na\n simple_dialog_check_set(priv_warning_dialog, \"Don't show this message again.\");\n simple_dialog_set_cb(priv_warning_dialog, priv_warning_dialog_cb, NULL);\n }\n+*/\n \n #ifdef _WIN32\n /* Warn the user if npf.sys isn't loaded. */"}], "metadata": {"id": "wireshark-1689-wireshark-1.2.0-disable-warnin", "cve_id": "CVE-2013-2487", "package": "wireshark", "tier": "identical", "has_source_context": false, "license": "GPL-2.0-or-later AND GPL-3.0-or-later"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1i.orig/crypto/asn1/a_type.c\n- openssl-1.0.1i/crypto/x509/x509.h\n- openssl-1.0.1i.orig/crypto/x509/x_all.c\n- openssl-1.0.1i/crypto/asn1/asn1_err.c\n- openssl-1.0.1i.orig/crypto/asn1/a_verify.c\n\n## Target Source Code\n\n### crypto/asn1/a_verify.c\n\n#### ASN1_verify() [lines 74-131]\n```c\n\n#ifndef NO_ASN1_OLD\n\nint ASN1_verify(i2d_of_void *i2d, X509_ALGOR *a, ASN1_BIT_STRING *signature,\n\t\tchar *data, EVP_PKEY *pkey)\n\t{\n\tEVP_MD_CTX ctx;\n\tconst EVP_MD *type;\n\tunsigned char *p,*buf_in=NULL;\n\tint ret= -1,i,inl;\n\n\tEVP_MD_CTX_init(&ctx);\n\ti=OBJ_obj2nid(a->algorithm);\n\ttype=EVP_get_digestbyname(OBJ_nid2sn(i));\n\tif (type == NULL)\n\t\t{\n\t\tASN1err(ASN1_F_ASN1_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);\n\t\tgoto err;\n\t\t}\n\t\n\tinl=i2d(data,NULL);\n\tbuf_in=OPENSSL_malloc((unsigned int)inl);\n\tif (buf_in == NULL)\n\t\t{\n\t\tASN1err(ASN1_F_ASN1_VERIFY,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tp=buf_in;\n\n\ti2d(data,&p);\n\tif (!EVP_VerifyInit_ex(&ctx,type, NULL)\n\t\t|| !EVP_VerifyUpdate(&ctx,(unsigned char *)buf_in,inl))\n\t\t{\n\t\tASN1err(ASN1_F_ASN1_VERIFY,ERR_R_EVP_LIB);\n\t\tret=0;\n\t\tgoto err;\n\t\t}\n\n\tOPENSSL_cleanse(buf_in,(unsigned int)inl);\n\tOPENSSL_free(buf_in);\n\n\tif (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data,\n\t\t\t(unsigned int)signature->length,pkey) <= 0)\n\t\t{\n\t\tASN1err(ASN1_F_ASN1_VERIFY,ERR_R_EVP_LIB);\n\t\tret=0;\n\t\tgoto err;\n\t\t}\n\t/* we don't need to zero the 'ctx' because we just checked\n\t * public information */\n\t/* memset(&ctx,0,sizeof(ctx)); */\n\tret=1;\nerr:\n\tEVP_MD_CTX_cleanup(&ctx);\n\treturn(ret);\n\t}\n\n#endif\n```\n\n#### ASN1_item_verify() [lines 131-234]\n```c\n#endif\n\n\nint ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a,\n\t\tASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey)\n\t{\n\tEVP_MD_CTX ctx;\n\tunsigned char *buf_in=NULL;\n\tint ret= -1,inl;\n\n\tint mdnid, pknid;\n\n\tif (!pkey)\n\t\t{\n\t\tASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_PASSE\n/* ... truncated ... */\n```\n\n### crypto/dsa/dsa_asn1.c\n\n#### DSA_verify() [lines 172-189]\n```c\n * 0: incorrect signature\n * -1: error\n */\nint DSA_verify(int type, const unsigned char *dgst, int dgst_len,\n\t const unsigned char *sigbuf, int siglen, DSA *dsa)\n\t{\n\tDSA_SIG *s;\n\tint ret=-1;\n\n\ts = DSA_SIG_new();\n\tif (s == NULL) return(ret);\n\tif (d2i_DSA_SIG(&s,&sigbuf,siglen) == NULL) goto err;\n\tret=DSA_do_verify(dgst,dgst_len,s,dsa);\nerr:\n\tDSA_SIG_free(s);\n\treturn(ret);\n\t}\n\n```\n\n### crypto/ecdsa/ecs_vrf.c\n\n#### region() [lines 18-97]\n```c\n * distribution.\n *\n * 3. All advertising materials mentioning features or use of this\n * software must display the following acknowledgment:\n * \"This product includes software developed by the OpenSSL Project\n * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)\"\n *\n * 4. The names \"OpenSSL Toolkit\" and \"OpenSSL Project\" must not be used to\n * endorse or promote products derived from this software without\n * prior written permission. For written permission, please contact\n * openssl-core@OpenSSL.org.\n *\n * 5. Products derived from this software may not be called \"OpenSSL\"\n * nor may \"OpenSSL\" appear in their names without prior written\n * permission of the OpenSSL Project.\n *\n * 6. Redistributions of any form whatsoever must retain the following\n * acknowledgment:\n * \"This product includes software developed by the OpenSSL Project\n * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)\"\n *\n * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\n * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR\n * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTR\n/* ... truncated ... */\n```\n\n### crypto/x509/x_all.c\n\n#### region() [lines 33-119]\n```c\n * \"This product includes cryptographic software written by\n * Eric Young (eay@cryptsoft.com)\"\n * The word 'cryptographic' can be left out if the rouines from the library\n * being used are not cryptographic related :-).\n * 4. If you include any Windows specific code (or a derivative thereof) from \n * the apps directory (application code) you must include an acknowledgement:\n * \"This product includes software written by Tim Hudson (tjh@cryptsoft.com)\"\n * \n * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\n * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\n * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n * SUCH DAMAGE.\n * \n * The licence and distribution terms for any publically available version or\n * derivative of this code cannot be changed. i.e. this code cannot simply be\n * copied and put under another distribution licence\n * [including the GNU Public Licence.]\n */\n\n#include \n#include \n#include \"cryptl\n/* ... truncated ... */\n```\n\n### crypto/asn1/a_bitstr.c\n\n#### region() [lines 97-188]\n```c\n\t\t\t}\n\t\t}\n\telse\n\t\tbits=0;\n\n\tret=1+len;\n\tif (pp == NULL) return(ret);\n\n\tp= *pp;\n\n\t*(p++)=(unsigned char)bits;\n\td=a->data;\n\tmemcpy(p,d,len);\n\tp+=len;\n\tif (len > 0) p[-1]&=(0xff<flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear */\n\tret->flags|=(ASN1_STRING_FLAG_BITS_LEFT|(i&0x07)); /* set */\n\n\tif (len-- > 1) /* using one because of the bits left byte */\n\t\t{\n\t\ts=(unsigned char *)OPENSSL_malloc((int)len);\n\t\tif (s == NULL)\n\t\t\t{\n\t\t\ti=ERR_R_MALLOC_FAILURE;\n\t\t\tgoto err;\n\t\t\t}\n\t\tmemcpy(s,p,(int)len);\n\t\ts[len-1]&=(0xff<length=(int)len;\n\tif (ret->data != NULL) OPENSSL_free(ret->data);\n\tret->data=s;\n\tret->type=V_ASN1_BIT_STRING;\n\tif (a != NULL) (*a)=ret;\n\t*pp=p;\n\treturn(ret);\nerr:\n\tASN1err(ASN1_F_C2I_ASN1_BIT_STRING,i);\n\tif ((ret != NULL) && ((a == NULL) || (*a != ret)))\n\t\tM_ASN1_BIT_STRING_free(ret);\n\treturn(NULL);\n\t}\n\n/* These next 2 functions from Goetz Babin-Ebell \n */\nint ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a\n/* ... truncated ... */\n```\n\n### crypto/asn1/asn1_err.c\n\n#### region() [lines 207-293]\n```c\n{ERR_REASON(ASN1_R_BMPSTRING_IS_WRONG_LENGTH),\"bmpstring is wrong length\"},\n{ERR_REASON(ASN1_R_BN_LIB) ,\"bn lib\"},\n{ERR_REASON(ASN1_R_BOOLEAN_IS_WRONG_LENGTH),\"boolean is wrong length\"},\n{ERR_REASON(ASN1_R_BUFFER_TOO_SMALL) ,\"buffer too small\"},\n{ERR_REASON(ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER),\"cipher has no object identifier\"},\n{ERR_REASON(ASN1_R_CONTEXT_NOT_INITIALISED),\"context not initialised\"},\n{ERR_REASON(ASN1_R_DATA_IS_WRONG) ,\"data is wrong\"},\n{ERR_REASON(ASN1_R_DECODE_ERROR) ,\"decode error\"},\n{ERR_REASON(ASN1_R_DECODING_ERROR) ,\"decoding error\"},\n{ERR_REASON(ASN1_R_DEPTH_EXCEEDED) ,\"depth exceeded\"},\n{ERR_REASON(ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED),\"digest and key type not supported\"},\n{ERR_REASON(ASN1_R_ENCODE_ERROR) ,\"encode error\"},\n{ERR_REASON(ASN1_R_ERROR_GETTING_TIME) ,\"error getting time\"},\n{ERR_REASON(ASN1_R_ERROR_LOADING_SECTION),\"error loading section\"},\n{ERR_REASON(ASN1_R_ERROR_PARSING_SET_ELEMENT),\"error parsing set element\"},\n{ERR_REASON(ASN1_R_ERROR_SETTING_CIPHER_PARAMS),\"error setting cipher params\"},\n{ERR_REASON(ASN1_R_EXPECTING_AN_INTEGER) ,\"expecting an integer\"},\n{ERR_REASON(ASN1_R_EXPECTING_AN_OBJECT) ,\"expecting an object\"},\n{ERR_REASON(ASN1_R_EXPECTING_A_BOOLEAN) ,\"expecting a boolean\"},\n{ERR_REASON(ASN1_R_EXPECTING_A_TIME) ,\"expecting a time\"},\n{ERR_REASON(ASN1_R_EXPLICIT_LENGTH_MISMATCH),\"explicit length mismatch\"},\n{ERR_REASON(ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED),\"explicit tag not constructed\"},\n{ERR_REASON(ASN1_R_FIELD_MIS\n/* ... truncated ... */\n```\n\n### crypto/asn1/asn1.h\n\n#### DECLARE_ASN1_FUNCTIONS_fname() [lines 737-824]\n```c\n\t\t(ASN1_UNIVERSALSTRING *)d2i_ASN1_type_bytes\\\n\t\t((ASN1_STRING **)a,pp,l,B_ASN1_UNIVERSALSTRING)\n\n#define M_ASN1_BMPSTRING_new()\t(ASN1_BMPSTRING *)\\\n\t\tASN1_STRING_type_new(V_ASN1_BMPSTRING)\n#define M_ASN1_BMPSTRING_free(a)\tASN1_STRING_free((ASN1_STRING *)a)\n#define M_i2d_ASN1_BMPSTRING(a,pp) \\\n\t\ti2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_BMPSTRING,\\\n\t\t\tV_ASN1_UNIVERSAL)\n#define M_d2i_ASN1_BMPSTRING(a,pp,l) \\\n\t\t(ASN1_BMPSTRING *)d2i_ASN1_type_bytes\\\n\t\t((ASN1_STRING **)a,pp,l,B_ASN1_BMPSTRING)\n\n#define M_ASN1_VISIBLESTRING_new()\t(ASN1_VISIBLESTRING *)\\\n\t\tASN1_STRING_type_new(V_ASN1_VISIBLESTRING)\n#define M_ASN1_VISIBLESTRING_free(a)\tASN1_STRING_free((ASN1_STRING *)a)\n#define M_i2d_ASN1_VISIBLESTRING(a,pp) \\\n\t\ti2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_VISIBLESTRING,\\\n\t\t\tV_ASN1_UNIVERSAL)\n#define M_d2i_ASN1_VISIBLESTRING(a,pp,l) \\\n\t\t(ASN1_VISIBLESTRING *)d2i_ASN1_type_bytes\\\n\t\t((ASN1_STRING **)a,pp,l,B_ASN1_VISIBLESTRING)\n\n#define M_ASN1_UTF8STRING_new()\t(ASN1_UTF8STRING *)\\\n\t\tASN1_STRING_type_new(V_ASN1_UTF8STRING)\n#define M_ASN1_UTF8STRING_free(a)\tASN1_STRING_free((ASN1_STRING *)a)\n#define M_i2d_ASN1_UTF8STRING(a,pp) \\\n\t\ti2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UTF8STRING,\\\n\t\t\tV_ASN1_UNIVERSAL)\n#define M_d2i_ASN1_UTF8STRING(a,pp,l) \\\n\t\t(ASN1_UTF8STRING *)d2i_ASN1_type_bytes\\\n\t\t((ASN1_STRING **)a,pp,l,B_ASN1_UTF8STRING)\n\n /* for the is_set parameter to i2d_ASN1_SET */\n#define IS_SEQUENCE\t0\n#define IS_SET\t\t1\n\nDECLARE_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)\n\nint ASN1_TYPE_get(ASN1_TYPE *a);\nvoid\n/* ... truncated ... */\n```\n\n### crypto/asn1/a_type.c\n\n#### IMPLEMENT_STACK_OF() [lines 74-160]\n```c\n\tif (a->value.ptr != NULL)\n\t\t{\n\t\tASN1_TYPE **tmp_a = &a;\n\t\tASN1_primitive_free((ASN1_VALUE **)tmp_a, NULL);\n\t\t}\n\ta->type=type;\n\tif (type == V_ASN1_BOOLEAN)\n\t\ta->value.boolean = value ? 0xff : 0;\n\telse\n\t\ta->value.ptr=value;\n\t}\n\nint ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value)\n\t{\n\tif (!value || (type == V_ASN1_BOOLEAN))\n\t\t{\n\t\tvoid *p = (void *)value;\n\t\tASN1_TYPE_set(a, type, p);\n\t\t}\n\telse if (type == V_ASN1_OBJECT)\n\t\t{\n\t\tASN1_OBJECT *odup;\n\t\todup = OBJ_dup(value);\n\t\tif (!odup)\n\t\t\treturn 0;\n\t\tASN1_TYPE_set(a, type, odup);\n\t\t}\n\telse\n\t\t{\n\t\tASN1_STRING *sdup;\n\t\tsdup = ASN1_STRING_dup(value);\n\t\tif (!sdup)\n\t\t\treturn 0;\n\t\tASN1_TYPE_set(a, type, sdup);\n\t\t}\n\treturn 1;\n\t}\n\nIMPLEMENT_STACK_OF(ASN1_TYPE)\nIMPLEMENT_ASN1_SET_OF(ASN1_TYPE)\n\n/* Returns 0 if they are equal, != 0 otherwise. */\nint ASN1_TYPE_cmp(ASN1_TYPE *a, ASN1_TYPE *b)\n\t{\n\tint result = -1;\n\n\tif (!a || !b || a->type != b->type) return -1;\n\n\tswitch (a->type)\n\t\t{\n\tcase V_ASN1_OBJECT:\n\t\tresult = OBJ_cmp(a->value.object, b->value.object);\n\t\tbreak;\n\tcase V_ASN1_NULL:\n\t\tresult = 0;\t/* They do not have content. */\n\t\tbreak;\n\tcase V_ASN1_INTEGER:\n\tcase V_ASN1_NEG_INTEGER:\n\tcase V_ASN1_ENUMERATED:\n\tcase V_ASN1_NEG_ENUMERATED:\n\tcase V_ASN1_BIT_STRING:\n\tcase V_ASN1_OCTET_STRING:\n\tcase V_ASN1_SEQUENCE:\n\tcase V_ASN1_SET:\n\tcase V_ASN1_NUMERICSTRING:\n\tcase V_ASN1_PRINTABLESTRING:\n\tcase V_ASN1_T61STRING:\n\tcase V_ASN1_VIDEOTEXSTRING:\n\tcase V_ASN1_IA5STRING:\n\tcase V_ASN1_UTCTIME:\n\tcase V_ASN1_GENERALIZEDTIME:\n\tcase V_ASN1_GRAPHICSTRING:\n\tcase V_ASN1_VISIBLESTRING:\n\tcase V\n/* ... truncated ... */\n```\n\n### crypto/asn1/x_algor.c\n\n#### X509_ALGOR_set_md() [lines 130-145]\n```c\n\n/* Set up an X509_ALGOR DigestAlgorithmIdentifier from an EVP_MD */\n\nvoid X509_ALGOR_set_md(X509_ALGOR *alg, const EVP_MD *md)\n\t{\n\tint param_type;\n\n\tif (md->flags & EVP_MD_FLAG_DIGALGID_ABSENT)\n\t\tparam_type = V_ASN1_UNDEF;\n\telse\n\t\tparam_type = V_ASN1_NULL;\n\n\tX509_ALGOR_set0(alg, OBJ_nid2obj(EVP_MD_type(md)), param_type, NULL);\n\n\t}\n\n```\n\n### crypto/x509/x509.h\n\n#### X509_ALGOR_set0() [lines 729-815]\n```c\n#ifndef OPENSSL_NO_RSA\nRSA *d2i_RSAPrivateKey_bio(BIO *bp,RSA **rsa);\nint i2d_RSAPrivateKey_bio(BIO *bp,RSA *rsa);\nRSA *d2i_RSAPublicKey_bio(BIO *bp,RSA **rsa);\nint i2d_RSAPublicKey_bio(BIO *bp,RSA *rsa);\nRSA *d2i_RSA_PUBKEY_bio(BIO *bp,RSA **rsa);\nint i2d_RSA_PUBKEY_bio(BIO *bp,RSA *rsa);\n#endif\n#ifndef OPENSSL_NO_DSA\nDSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa);\nint i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa);\nDSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa);\nint i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa);\n#endif\n#ifndef OPENSSL_NO_EC\nEC_KEY *d2i_EC_PUBKEY_bio(BIO *bp, EC_KEY **eckey);\nint i2d_EC_PUBKEY_bio(BIO *bp, EC_KEY *eckey);\nEC_KEY *d2i_ECPrivateKey_bio(BIO *bp, EC_KEY **eckey);\nint i2d_ECPrivateKey_bio(BIO *bp, EC_KEY *eckey);\n#endif\nX509_SIG *d2i_PKCS8_bio(BIO *bp,X509_SIG **p8);\nint i2d_PKCS8_bio(BIO *bp,X509_SIG *p8);\nPKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,\n\t\t\t\t\t\tPKCS8_PRIV_KEY_INFO **p8inf);\nint i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,PKCS8_PRIV_KEY_INFO *p8inf);\nint i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key);\nint i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey);\nEVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a);\nint i2d_PUBKEY_bio(BIO *bp, EVP_PKEY *pkey);\nEVP_PKEY *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a);\n#endif\n\nX509 *X509_dup(X509 *x509);\nX509_ATTRIBUTE *X509_ATTRIBUTE_dup(X509_ATTRIBUTE *xa);\nX509_EXTENSION *X509_EXTENSION_dup(X509_EXTENSION *ex);\nX509_CRL *X509_CRL_dup(X509_CRL *crl);\nX509_REQ *X509_REQ_dup(X509_REQ *req);\nX509_ALGOR *X509_ALGOR_dup(X509_ALGOR *xn);\nint X509_ALGOR_set0(\n/* ... truncated ... */\n```\n\n\n## Upstream Fix\n```diff\ncommit a8565530e27718760220df469f0a071c85b9e731\nAuthor: Dr. Stephen Henson \nDate: Sat Dec 20 15:09:50 2014 +0000\n\n Fix various certificate fingerprint issues.\n \n By using non-DER or invalid encodings outside the signed portion of a\n certificate the fingerprint can be changed without breaking the signature.\n Although no details of the signed portion of the certificate can be changed\n this can cause problems with some applications: e.g. those using the\n certificate fingerprint for blacklists.\n \n 1. Reject signatures with non zero unused bits.\n \n If the BIT STRING containing the signature has non zero unused bits reject\n the signature. All current signature algorithms require zero unused bits.\n \n 2. Check certificate algorithm consistency.\n \n Check the AlgorithmIdentifier inside TBS matches the one in the\n certificate signature. NB: this will result in signature failure\n errors for some broken certificates.\n \n 3. Check DSA/ECDSA signatures use DER.\n \n Reencode DSA/ECDSA signatures and compare with the original received\n signature. Return an error if there is a mismatch.\n \n This will reject various cases including garbage after signature\n (thanks to Antti Karjalainen and Tuomo Untinen from the Codenomicon CROSS\n program for discovering this case) and use of BER or invalid ASN.1 INTEGERs\n (negative or with leading zeroes).\n \n CVE-2014-8275\n Reviewed-by: Emilia Käsper \n \n (cherry picked from commit 684400ce192dac51df3d3e92b61830a6ef90be3e)\n\ncommit 178c562a4621162dbe19a7c34fa2ad558684f40e\nAuthor: Dr. Stephen Henson \nDate: Tue Jan 6 20:55:38 2015 +0000\n\n use correct function name\n \n Reviewed-by: Rich Salz \n Reviewed-by: Matt Caswell \n (cherry picked from commit cb62ab4b17818fe66d2fed0a7fe71969131c811b)\n\ncommit 5951cc004b96cd681ffdf39d3fc9238a1ff597ae\nAuthor: Dr. Stephen Henson \nDate: Sun Dec 14 23:14:15 2014 +0000\n\n Constify ASN1_TYPE_cmp add X509_ALGOR_cmp.\n \n Reviewed-by: Emilia Käsper \n (cherry picked from commit 4c52816d35681c0533c25fdd3abb4b7c6962302d)\n\ncommit 86edf13b1c97526c0cf63c37342aaa01f5442688\nAuthor: Kurt Roeckx \nDate: Mon Dec 15 17:15:16 2014 +0100\n\n Return error when a bit string indicates an invalid amount of bits left\n \n Reviewed-by: Matt Caswell \n\n\nIndex: openssl-1.0.1i/crypto/asn1/a_verify.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/asn1/a_verify.c\t2015-01-09 16:52:51.651826120 +0100\n+++ openssl-1.0.1i/crypto/asn1/a_verify.c\t2015-01-09 16:53:08.806036820 +0100\n@@ -90,6 +90,12 @@ int ASN1_verify(i2d_of_void *i2d, X509_A\n \t\tASN1err(ASN1_F_ASN1_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);\n \t\tgoto err;\n \t\t}\n+\n+\tif (signature->type == V_ASN1_BIT_STRING && signature->flags & 0x7)\n+\t\t{\n+\t\tASN1err(ASN1_F_ASN1_VERIFY, ASN1_R_INVALID_BIT_STRING_BITS_LEFT);\n+\t\tgoto err;\n+\t\t}\n \t\n \tinl=i2d(data,NULL);\n \tbuf_in=OPENSSL_malloc((unsigned int)inl);\n@@ -146,6 +152,12 @@ int ASN1_item_verify(const ASN1_ITEM *it\n \t\treturn -1;\n \t\t}\n \n+\tif (signature->type == V_ASN1_BIT_STRING && signature->flags & 0x7)\n+\t\t{\n+\t\tASN1err(ASN1_F_ASN1_ITEM_VERIFY, ASN1_R_INVALID_BIT_STRING_BITS_LEFT);\n+\t\treturn -1;\n+\t\t}\n+\n \tEVP_MD_CTX_init(&ctx);\n \n \t/* Convert signature OID into digest and public key OIDs */\nIndex: openssl-1.0.1i/crypto/dsa/dsa_asn1.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/dsa/dsa_asn1.c\t2015-01-09 16:52:51.651826120 +0100\n+++ openssl-1.0.1i/crypto/dsa/dsa_asn1.c\t2015-01-09 16:53:08.806036820 +0100\n@@ -176,13 +176,25 @@ int DSA_verify(int type, const unsigned\n \t const unsigned char *sigbuf, int siglen, DSA *dsa)\n \t{\n \tDSA_SIG *s;\n+\tconst unsigned char *p = sigbuf;\n+\tunsigned char *der = NULL;\n+\tint derlen = -1;\n \tint ret=-1;\n \n \ts = DSA_SIG_new();\n \tif (s == NULL) return(ret);\n-\tif (d2i_DSA_SIG(&s,&sigbuf,siglen) == NULL) goto err;\n+\tif (d2i_DSA_SIG(&s,&p,siglen) == NULL) goto err;\n+\t/* Ensure signature uses DER and doesn't have trailing garbage */\n+\tderlen = i2d_DSA_SIG(s, &der);\n+\tif (derlen != siglen || memcmp(sigbuf, der, derlen))\n+\t\tgoto err;\n \tret=DSA_do_verify(dgst,dgst_len,s,dsa);\n err:\n+\tif (derlen > 0)\n+\t\t{\n+\t\tOPENSSL_cleanse(der, derlen);\n+\t\tOPENSSL_free(der);\n+\t\t}\n \tDSA_SIG_free(s);\n \treturn(ret);\n \t}\nIndex: openssl-1.0.1i/crypto/ecdsa/ecs_vrf.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/ecdsa/ecs_vrf.c\t2015-01-09 16:52:51.651826120 +0100\n+++ openssl-1.0.1i/crypto/ecdsa/ecs_vrf.c\t2015-01-09 16:53:08.806036820 +0100\n@@ -57,6 +57,7 @@\n */\n \n #include \"ecs_locl.h\"\n+#include \"cryptlib.h\"\n #ifndef OPENSSL_NO_ENGINE\n #include \n #endif\n@@ -84,13 +85,25 @@ int ECDSA_verify(int type, const unsigne\n \t\tconst unsigned char *sigbuf, int sig_len, EC_KEY *eckey)\n \t{\n \tECDSA_SIG *s;\n+\tconst unsigned char *p = sigbuf;\n+\tunsigned char *der = NULL;\n+\tint derlen = -1;\n \tint ret=-1;\n \n \ts = ECDSA_SIG_new();\n \tif (s == NULL) return(ret);\n-\tif (d2i_ECDSA_SIG(&s, &sigbuf, sig_len) == NULL) goto err;\n+\tif (d2i_ECDSA_SIG(&s, &p, sig_len) == NULL) goto err;\n+\t/* Ensure signature uses DER and doesn't have trailing garbage */\n+\tderlen = i2d_ECDSA_SIG(s, &der);\n+\tif (derlen != sig_len || memcmp(sigbuf, der, derlen))\n+\t\tgoto err;\n \tret=ECDSA_do_verify(dgst, dgst_len, s, eckey);\n err:\n+\tif (derlen > 0)\n+\t\t{\n+\t\tOPENSSL_cleanse(der, derlen);\n+\t\tOPENSSL_free(der);\n+\t\t}\n \tECDSA_SIG_free(s);\n \treturn(ret);\n \t}\nIndex: openssl-1.0.1i/crypto/x509/x_all.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/x509/x_all.c\t2015-01-09 16:52:51.651826120 +0100\n+++ openssl-1.0.1i/crypto/x509/x_all.c\t2015-01-09 16:53:08.806036820 +0100\n@@ -72,6 +72,8 @@\n \n int X509_verify(X509 *a, EVP_PKEY *r)\n \t{\n+\tif (X509_ALGOR_cmp(a->sig_alg, a->cert_info->signature))\n+\t\treturn 0;\n \treturn(ASN1_item_verify(ASN1_ITEM_rptr(X509_CINF),a->sig_alg,\n \t\ta->signature,a->cert_info,r));\n \t}\nIndex: openssl-1.0.1i/crypto/asn1/a_bitstr.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/asn1/a_bitstr.c\t2015-01-09 16:54:03.083703130 +0100\n+++ openssl-1.0.1i/crypto/asn1/a_bitstr.c\t2015-01-09 16:54:19.571905429 +0100\n@@ -136,11 +136,16 @@ ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN\n \n \tp= *pp;\n \ti= *(p++);\n+\tif (i > 7)\n+\t\t{\n+\t\ti=ASN1_R_INVALID_BIT_STRING_BITS_LEFT;\n+\t\tgoto err;\n+\t\t}\n \t/* We do this to preserve the settings. If we modify\n \t * the settings, via the _set_bit function, we will recalculate\n \t * on output */\n \tret->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear */\n-\tret->flags|=(ASN1_STRING_FLAG_BITS_LEFT|(i&0x07)); /* set */\n+\tret->flags|=(ASN1_STRING_FLAG_BITS_LEFT|i); /* set */\n \n \tif (len-- > 1) /* using one because of the bits left byte */\n \t\t{\nIndex: openssl-1.0.1i/crypto/asn1/asn1_err.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/asn1/asn1_err.c\t2015-01-09 16:54:03.083703130 +0100\n+++ openssl-1.0.1i/crypto/asn1/asn1_err.c\t2015-01-09 16:54:19.571905429 +0100\n@@ -246,6 +246,7 @@ static ERR_STRING_DATA ASN1_str_reasons[\n {ERR_REASON(ASN1_R_ILLEGAL_TIME_VALUE) ,\"illegal time value\"},\n {ERR_REASON(ASN1_R_INTEGER_NOT_ASCII_FORMAT),\"integer not ascii format\"},\n {ERR_REASON(ASN1_R_INTEGER_TOO_LARGE_FOR_LONG),\"integer too large for long\"},\n+{ERR_REASON(ASN1_R_INVALID_BIT_STRING_BITS_LEFT),\"invalid bit string bits left\"},\n {ERR_REASON(ASN1_R_INVALID_BMPSTRING_LENGTH),\"invalid bmpstring length\"},\n {ERR_REASON(ASN1_R_INVALID_DIGIT) ,\"invalid digit\"},\n {ERR_REASON(ASN1_R_INVALID_MIME_TYPE) ,\"invalid mime type\"},\nIndex: openssl-1.0.1i/crypto/asn1/asn1.h\n===================================================================\n--- openssl-1.0.1i.orig/crypto/asn1/a\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "commit a8565530e27718760220df469f0a071c85b9e731\nAuthor: Dr. Stephen Henson \nDate: Sat Dec 20 15:09:50 2014 +0000\n\n Fix various certificate fingerprint issues.\n \n By using non-DER or invalid encodings outside the signed portion of a\n certificate the fingerprint can be changed without breaking the signature.\n Although no details of the signed portion of the certificate can be changed\n this can cause problems with some applications: e.g. those using the\n certificate fingerprint for blacklists.\n \n 1. Reject signatures with non zero unused bits.\n \n If the BIT STRING containing the signature has non zero unused bits reject\n the signature. All current signature algorithms require zero unused bits.\n \n 2. Check certificate algorithm consistency.\n \n Check the AlgorithmIdentifier inside TBS matches the one in the\n certificate signature. NB: this will result in signature failure\n errors for some broken certificates.\n \n 3. Check DSA/ECDSA signatures use DER.\n \n Reencode DSA/ECDSA signatures and compare with the original received\n signature. Return an error if there is a mismatch.\n \n This will reject various cases including garbage after signature\n (thanks to Antti Karjalainen and Tuomo Untinen from the Codenomicon CROSS\n program for discovering this case) and use of BER or invalid ASN.1 INTEGERs\n (negative or with leading zeroes).\n \n CVE-2014-8275\n Reviewed-by: Emilia Käsper \n \n (cherry picked from commit 684400ce192dac51df3d3e92b61830a6ef90be3e)\n\ncommit 178c562a4621162dbe19a7c34fa2ad558684f40e\nAuthor: Dr. Stephen Henson \nDate: Tue Jan 6 20:55:38 2015 +0000\n\n use correct function name\n \n Reviewed-by: Rich Salz \n Reviewed-by: Matt Caswell \n (cherry picked from commit cb62ab4b17818fe66d2fed0a7fe71969131c811b)\n\ncommit 5951cc004b96cd681ffdf39d3fc9238a1ff597ae\nAuthor: Dr. Stephen Henson \nDate: Sun Dec 14 23:14:15 2014 +0000\n\n Constify ASN1_TYPE_cmp add X509_ALGOR_cmp.\n \n Reviewed-by: Emilia Käsper \n (cherry picked from commit 4c52816d35681c0533c25fdd3abb4b7c6962302d)\n\ncommit 86edf13b1c97526c0cf63c37342aaa01f5442688\nAuthor: Kurt Roeckx \nDate: Mon Dec 15 17:15:16 2014 +0100\n\n Return error when a bit string indicates an invalid amount of bits left\n \n Reviewed-by: Matt Caswell \n\n\nIndex: openssl-1.0.1i/crypto/asn1/a_verify.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/asn1/a_verify.c\t2015-01-09 16:52:51.651826120 +0100\n+++ openssl-1.0.1i/crypto/asn1/a_verify.c\t2015-01-09 16:53:08.806036820 +0100\n@@ -90,6 +90,12 @@ int ASN1_verify(i2d_of_void *i2d, X509_A\n \t\tASN1err(ASN1_F_ASN1_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);\n \t\tgoto err;\n \t\t}\n+\n+\tif (signature->type == V_ASN1_BIT_STRING && signature->flags & 0x7)\n+\t\t{\n+\t\tASN1err(ASN1_F_ASN1_VERIFY, ASN1_R_INVALID_BIT_STRING_BITS_LEFT);\n+\t\tgoto err;\n+\t\t}\n \t\n \tinl=i2d(data,NULL);\n \tbuf_in=OPENSSL_malloc((unsigned int)inl);\n@@ -146,6 +152,12 @@ int ASN1_item_verify(const ASN1_ITEM *it\n \t\treturn -1;\n \t\t}\n \n+\tif (signature->type == V_ASN1_BIT_STRING && signature->flags & 0x7)\n+\t\t{\n+\t\tASN1err(ASN1_F_ASN1_ITEM_VERIFY, ASN1_R_INVALID_BIT_STRING_BITS_LEFT);\n+\t\treturn -1;\n+\t\t}\n+\n \tEVP_MD_CTX_init(&ctx);\n \n \t/* Convert signature OID into digest and public key OIDs */\nIndex: openssl-1.0.1i/crypto/dsa/dsa_asn1.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/dsa/dsa_asn1.c\t2015-01-09 16:52:51.651826120 +0100\n+++ openssl-1.0.1i/crypto/dsa/dsa_asn1.c\t2015-01-09 16:53:08.806036820 +0100\n@@ -176,13 +176,25 @@ int DSA_verify(int type, const unsigned\n \t const unsigned char *sigbuf, int siglen, DSA *dsa)\n \t{\n \tDSA_SIG *s;\n+\tconst unsigned char *p = sigbuf;\n+\tunsigned char *der = NULL;\n+\tint derlen = -1;\n \tint ret=-1;\n \n \ts = DSA_SIG_new();\n \tif (s == NULL) return(ret);\n-\tif (d2i_DSA_SIG(&s,&sigbuf,siglen) == NULL) goto err;\n+\tif (d2i_DSA_SIG(&s,&p,siglen) == NULL) goto err;\n+\t/* Ensure signature uses DER and doesn't have trailing garbage */\n+\tderlen = i2d_DSA_SIG(s, &der);\n+\tif (derlen != siglen || memcmp(sigbuf, der, derlen))\n+\t\tgoto err;\n \tret=DSA_do_verify(dgst,dgst_len,s,dsa);\n err:\n+\tif (derlen > 0)\n+\t\t{\n+\t\tOPENSSL_cleanse(der, derlen);\n+\t\tOPENSSL_free(der);\n+\t\t}\n \tDSA_SIG_free(s);\n \treturn(ret);\n \t}\nIndex: openssl-1.0.1i/crypto/ecdsa/ecs_vrf.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/ecdsa/ecs_vrf.c\t2015-01-09 16:52:51.651826120 +0100\n+++ openssl-1.0.1i/crypto/ecdsa/ecs_vrf.c\t2015-01-09 16:53:08.806036820 +0100\n@@ -57,6 +57,7 @@\n */\n \n #include \"ecs_locl.h\"\n+#include \"cryptlib.h\"\n #ifndef OPENSSL_NO_ENGINE\n #include \n #endif\n@@ -84,13 +85,25 @@ int ECDSA_verify(int type, const unsigne\n \t\tconst unsigned char *sigbuf, int sig_len, EC_KEY *eckey)\n \t{\n \tECDSA_SIG *s;\n+\tconst unsigned char *p = sigbuf;\n+\tunsigned char *der = NULL;\n+\tint derlen = -1;\n \tint ret=-1;\n \n \ts = ECDSA_SIG_new();\n \tif (s == NULL) return(ret);\n-\tif (d2i_ECDSA_SIG(&s, &sigbuf, sig_len) == NULL) goto err;\n+\tif (d2i_ECDSA_SIG(&s, &p, sig_len) == NULL) goto err;\n+\t/* Ensure signature uses DER and doesn't have trailing garbage */\n+\tderlen = i2d_ECDSA_SIG(s, &der);\n+\tif (derlen != sig_len || memcmp(sigbuf, der, derlen))\n+\t\tgoto err;\n \tret=ECDSA_do_verify(dgst, dgst_len, s, eckey);\n err:\n+\tif (derlen > 0)\n+\t\t{\n+\t\tOPENSSL_cleanse(der, derlen);\n+\t\tOPENSSL_free(der);\n+\t\t}\n \tECDSA_SIG_free(s);\n \treturn(ret);\n \t}\nIndex: openssl-1.0.1i/crypto/x509/x_all.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/x509/x_all.c\t2015-01-09 16:52:51.651826120 +0100\n+++ openssl-1.0.1i/crypto/x509/x_all.c\t2015-01-09 16:53:08.806036820 +0100\n@@ -72,6 +72,8 @@\n \n int X509_verify(X509 *a, EVP_PKEY *r)\n \t{\n+\tif (X509_ALGOR_cmp(a->sig_alg, a->cert_info->signature))\n+\t\treturn 0;\n \treturn(ASN1_item_verify(ASN1_ITEM_rptr(X509_CINF),a->sig_alg,\n \t\ta->signature,a->cert_info,r));\n \t}\nIndex: openssl-1.0.1i/crypto/asn1/a_bitstr.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/asn1/a_bitstr.c\t2015-01-09 16:54:03.083703130 +0100\n+++ openssl-1.0.1i/crypto/asn1/a_bitstr.c\t2015-01-09 16:54:19.571905429 +0100\n@@ -136,11 +136,16 @@ ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN\n \n \tp= *pp;\n \ti= *(p++);\n+\tif (i > 7)\n+\t\t{\n+\t\ti=ASN1_R_INVALID_BIT_STRING_BITS_LEFT;\n+\t\tgoto err;\n+\t\t}\n \t/* We do this to preserve the settings. If we modify\n \t * the settings, via the _set_bit function, we will recalculate\n \t * on output */\n \tret->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear */\n-\tret->flags|=(ASN1_STRING_FLAG_BITS_LEFT|(i&0x07)); /* set */\n+\tret->flags|=(ASN1_STRING_FLAG_BITS_LEFT|i); /* set */\n \n \tif (len-- > 1) /* using one because of the bits left byte */\n \t\t{\nIndex: openssl-1.0.1i/crypto/asn1/asn1_err.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/asn1/asn1_err.c\t2015-01-09 16:54:03.083703130 +0100\n+++ openssl-1.0.1i/crypto/asn1/asn1_err.c\t2015-01-09 16:54:19.571905429 +0100\n@@ -246,6 +246,7 @@ static ERR_STRING_DATA ASN1_str_reasons[\n {ERR_REASON(ASN1_R_ILLEGAL_TIME_VALUE) ,\"illegal time value\"},\n {ERR_REASON(ASN1_R_INTEGER_NOT_ASCII_FORMAT),\"integer not ascii format\"},\n {ERR_REASON(ASN1_R_INTEGER_TOO_LARGE_FOR_LONG),\"integer too large for long\"},\n+{ERR_REASON(ASN1_R_INVALID_BIT_STRING_BITS_LEFT),\"invalid bit string bits left\"},\n {ERR_REASON(ASN1_R_INVALID_BMPSTRING_LENGTH),\"invalid bmpstring length\"},\n {ERR_REASON(ASN1_R_INVALID_DIGIT) ,\"invalid digit\"},\n {ERR_REASON(ASN1_R_INVALID_MIME_TYPE) ,\"invalid mime type\"},\nIndex: openssl-1.0.1i/crypto/asn1/asn1.h\n===================================================================\n--- openssl-1.0.1i.orig/crypto/asn1/asn1.h\t2015-01-09 16:54:03.083703130 +0100\n+++ openssl-1.0.1i/crypto/asn1/asn1.h\t2015-01-09 16:59:43.213866355 +0100\n@@ -776,7 +776,7 @@ DECLARE_ASN1_FUNCTIONS_fname(ASN1_TYPE,\n int ASN1_TYPE_get(ASN1_TYPE *a);\n void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value);\n int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value);\n-int ASN1_TYPE_cmp(ASN1_TYPE *a, ASN1_TYPE *b);\n+int ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b);\n \n ASN1_OBJECT *\tASN1_OBJECT_new(void );\n void\t\tASN1_OBJECT_free(ASN1_OBJECT *a);\n@@ -1329,6 +1329,7 @@ void ERR_load_ASN1_strings(void);\n #define ASN1_R_ILLEGAL_TIME_VALUE\t\t\t 184\n #define ASN1_R_INTEGER_NOT_ASCII_FORMAT\t\t\t 185\n #define ASN1_R_INTEGER_TOO_LARGE_FOR_LONG\t\t 128\n+#define ASN1_R_INVALID_BIT_STRING_BITS_LEFT\t\t 220\n #define ASN1_R_INVALID_BMPSTRING_LENGTH\t\t\t 129\n #define ASN1_R_INVALID_DIGIT\t\t\t\t 130\n #define ASN1_R_INVALID_MIME_TYPE\t\t\t 205\nIndex: openssl-1.0.1i/crypto/asn1/a_type.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/asn1/a_type.c\t2015-01-09 16:58:54.060265974 +0100\n+++ openssl-1.0.1i/crypto/asn1/a_type.c\t2015-01-09 16:59:43.213866355 +0100\n@@ -113,7 +113,7 @@ IMPLEMENT_STACK_OF(ASN1_TYPE)\n IMPLEMENT_ASN1_SET_OF(ASN1_TYPE)\n \n /* Returns 0 if they are equal, != 0 otherwise. */\n-int ASN1_TYPE_cmp(ASN1_TYPE *a, ASN1_TYPE *b)\n+int ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b)\n \t{\n \tint result = -1;\n \nIndex: openssl-1.0.1i/crypto/asn1/x_algor.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/asn1/x_algor.c\t2015-01-09 16:58:54.061265986 +0100\n+++ openssl-1.0.1i/crypto/asn1/x_algor.c\t2015-01-09 16:59:43.213866355 +0100\n@@ -142,3 +142,14 @@ void X509_ALGOR_set_md(X509_ALGOR *alg,\n \tX509_ALGOR_set0(alg, OBJ_nid2obj(EVP_MD_type(md)), param_type, NULL);\n \n \t}\n+\n+int X509_ALGOR_cmp(const X509_ALGOR *a, const X509_ALGOR *b)\n+\t{\n+\tint rv;\n+\trv = OBJ_cmp(a->algorithm, b->algorithm);\n+\tif (rv)\n+\t\treturn rv;\n+\tif (!a->parameter && !b->parameter)\n+\t\treturn 0;\n+\treturn ASN1_TYPE_cmp(a->parameter, b->parameter);\n+\t}\nIndex: openssl-1.0.1i/crypto/x509/x509.h\n===================================================================\n--- openssl-1.0.1i.orig/crypto/x509/x509.h\t2015-01-09 16:58:54.061265986 +0100\n+++ openssl-1.0.1i/crypto/x509/x509.h\t2015-01-09 16:59:43.214866367 +0100\n@@ -768,6 +768,7 @@ int X509_ALGOR_set0(X509_ALGOR *alg, ASN\n void X509_ALGOR_get0(ASN1_OBJECT **paobj, int *pptype, void **ppval,\n \t\t\t\t\t\tX509_ALGOR *algor);\n void X509_ALGOR_set_md(X509_ALGOR *alg, const EVP_MD *md);\n+int X509_ALGOR_cmp(const X509_ALGOR *a, const X509_ALGOR *b);\n \n X509_NAME *X509_NAME_dup(X509_NAME *xn);\n X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne);"}], "metadata": {"id": "openssl-4769-openssl-CVE-2014-8275.patch", "cve_id": "CVE-2015-3197", "package": "openssl", "tier": "adapted", "has_source_context": true, "context_tokens_est": 3503, "context_files": 10, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1i/crypto/x509/x509_req.c\n- openssl-1.0.1i.orig/crypto/x509/x509_req.c\n\n## Target Source Code\n\n### crypto/x509/x509_req.c\n\n#### region() [lines 53-139]\n```c\n * The licence and distribution terms for any publically available version or\n * derivative of this code cannot be changed. i.e. this code cannot simply be\n * copied and put under another distribution licence\n * [including the GNU Public Licence.]\n */\n\n#include \n#include \"cryptlib.h\"\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nX509_REQ *X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md)\n\t{\n\tX509_REQ *ret;\n\tX509_REQ_INFO *ri;\n\tint i;\n\tEVP_PKEY *pktmp;\n\n\tret=X509_REQ_new();\n\tif (ret == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_TO_X509_REQ,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\n\tri=ret->req_info;\n\n\tri->version->length=1;\n\tri->version->data=(unsigned char *)OPENSSL_malloc(1);\n\tif (ri->version->data == NULL) goto err;\n\tri->version->data[0]=0; /* version == 0 */\n\n\tif (!X509_REQ_set_subject_name(ret,X509_get_subject_name(x)))\n\t\tgoto err;\n\n\tpktmp = X509_get_pubkey(x);\n\ti=X509_REQ_set_pubkey(ret,pktmp);\n\tEVP_PKEY_free(pktmp);\n\tif (!i) goto err;\n\n\tif (pkey != NULL)\n\t\t{\n\t\tif (!X509_REQ_sign(ret,pkey,md))\n\t\t\tgoto err;\n\t\t}\n\treturn(ret);\nerr:\n\tX509_REQ_free(ret);\n\treturn(NULL);\n\t}\n\nEVP_PKEY *X509_REQ_get_pubkey(X509_REQ *req)\n\t{\n\tif ((req == NULL) || (req->req_info == NULL))\n\t\treturn(NULL);\n\treturn(X509_PUBKEY_get(req->req_info->pubkey));\n\t}\n\nint X509_REQ_check_private_key(X509_REQ *x, EVP_PKEY *k)\n\t{\n\tEVP_PKEY *xk=NULL;\n\tint ok=0;\n\n\txk=X509_REQ_get_pubkey(x);\n\tswitch (EVP_PKEY_cmp(xk, k))\n\t\t{\n\tcase 1:\n\t\tok=1;\n\t\tbreak;\n\tcase 0:\n\t\tX509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY,X509_R_KEY_VALUES_MISMATCH);\n\t\tbreak;\n\tcase -1:\n\t\tX509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY,X509_R_KEY_TYPE_MISMATCH);\n\t\tbreak;\n\tcase -2:\n#ifndef OPENSSL_NO_EC\n\t\tif (k->type == EVP_PKEY_EC)\n\t\t\t{\n\t\t\tX509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY, ERR_R_EC_LIB);\n\t\t\tbreak;\n```\n\n\n## Upstream Fix\n```diff\nFrom 28a00bcd8e318da18031b2ac8778c64147cd54f9 Mon Sep 17 00:00:00 2001\nFrom: \"Dr. Stephen Henson\" \nDate: Wed, 18 Feb 2015 00:34:59 +0000\nSubject: [PATCH] Check public key is not NULL.\n\nCVE-2015-0288\nPR#3708\n\nReviewed-by: Matt Caswell \n---\n crypto/x509/x509_req.c | 2 ++\n 1 file changed, 2 insertions(+)\n\ndiff --git a/crypto/x509/x509_req.c b/crypto/x509/x509_req.c\nindex bc6e566c95b42..01795f4b3f370 100644\n--- a/crypto/x509/x509_req.c\n+++ b/crypto/x509/x509_req.c\n@@ -92,6 +92,8 @@ X509_REQ *X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md)\n goto err;\n \n pktmp = X509_get_pubkey(x);\n+ if (pktmp == NULL)\n+ goto err;\n i = X509_REQ_set_pubkey(ret, pktmp);\n EVP_PKEY_free(pktmp);\n if (!i)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "commit 51527f1e3564f210e984fe5b654c45d34e4f03d7\nAuthor: Dr. Stephen Henson \nDate: Wed Feb 18 00:34:59 2015 +0000\n\n Check public key is not NULL.\n \n CVE-2015-0288\n PR#3708\n \n Reviewed-by: Matt Caswell \n (cherry picked from commit 28a00bcd8e318da18031b2ac8778c64147cd54f9)\n\nIndex: openssl-1.0.1i/crypto/x509/x509_req.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/x509/x509_req.c\t2015-03-17 13:22:30.712726374 +0100\n+++ openssl-1.0.1i/crypto/x509/x509_req.c\t2015-03-17 13:23:20.486453016 +0100\n@@ -92,6 +92,8 @@ X509_REQ *X509_to_X509_REQ(X509 *x, EVP_\n \t\tgoto err;\n \n \tpktmp = X509_get_pubkey(x);\n+\tif (pktmp == NULL)\n+\t\tgoto err;\n \ti=X509_REQ_set_pubkey(ret,pktmp);\n \tEVP_PKEY_free(pktmp);\n \tif (!i) goto err;"}], "metadata": {"id": "openssl-4598-openssl-CVE-2015-0288.patch", "cve_id": "CVE-2015-3197", "package": "openssl", "upstream_enriched": true, "upstream_commit": "28a00bcd8e318da18031b2ac8778c64147cd54f9", "upstream_repo": "openssl/openssl", "tier": "adapted", "has_source_context": true, "context_tokens_est": 497, "context_files": 1, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- ssl/s2_srvr.c\n- openssl-1.0.1i/ssl/s2_srvr.c\n- openssl-1.0.1i.orig/ssl/s2_srvr.c\n\n## Target Source Code\n\n### ssl/s2_srvr.c\n\n#### get_client_master_key() [lines 361-521]\n```c\n\treturn(ret);\n\t}\n\nstatic int get_client_master_key(SSL *s)\n\t{\n\tint is_export,i,n,keya,ek;\n\tunsigned long len;\n\tunsigned char *p;\n\tconst SSL_CIPHER *cp;\n\tconst EVP_CIPHER *c;\n\tconst EVP_MD *md;\n\n\tp=(unsigned char *)s->init_buf->data;\n\tif (s->state == SSL2_ST_GET_CLIENT_MASTER_KEY_A)\n\t\t{\n\t\ti=ssl2_read(s,(char *)&(p[s->init_num]),10-s->init_num);\n\n\t\tif (i < (10-s->init_num))\n\t\t\treturn(ssl2_part_read(s,SSL_F_GET_CLIENT_MASTER_KEY,i));\n\t\ts->init_num = 10;\n\n\t\tif (*(p++) != SSL2_MT_CLIENT_MASTER_KEY)\n\t\t\t{\n\t\t\tif (p[-1] != SSL2_MT_ERROR)\n\t\t\t\t{\n\t\t\t\tssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);\n\t\t\t\tSSLerr(SSL_F_GET_CLIENT_MASTER_KEY,SSL_R_READ_WRONG_PACKET_TYPE);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tSSLerr(SSL_F_GET_CLIENT_MASTER_KEY, SSL_R_PEER_ERROR);\n\t\t\treturn(-1);\n\t\t\t}\n\n\t\tcp=ssl2_get_cipher_by_char(p);\n\t\tif (cp == NULL)\n\t\t\t{\n\t\t\tssl2_return_error(s,SSL2_PE_NO_CIPHER);\n\t\t\tSSLerr(SSL_F_GET_CLIENT_MASTER_KEY, SSL_R_NO_CIPHER_MATCH);\n\t\t\treturn(-1);\n\t\t\t}\n\t\ts->session->cipher= cp;\n\n\t\tp+=3;\n\t\tn2s(p,i); s->s2->tmp.clear=i;\n\t\tn2s(p,i); s->s2->tmp.enc=i;\n\t\tn2s(p,i);\n\t\tif(i > SSL_MAX_KEY_ARG_LENGTH)\n\t\t\t{\n\t\t\tssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);\n/* ... 92 lines omitted ... */\n\t\t{\n\t\tssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);\n\t\treturn(-1);\n\t\t}\n#endif\n\n\tif (is_export) i+=s->s2->tmp.clear;\n\n\tif (i > SSL_MAX_MASTER_KEY_LENGTH)\n\t\t{\n\t\tssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);\n\t\tSSLerr(SSL_F_GET_CLIENT_MASTER_KEY, ERR_R_INTERNAL_ERROR);\n\t\treturn -1;\n\t\t}\n\ts->session->master_key_length=i;\n\tmemcpy(s->session->master_key,p,(unsigned int)i);\n\treturn(1);\n\t}\n\nstatic int get_client_hello(SSL *s)\n```\n\n#### get_client_hello() [lines 518-697]\n```c\n\treturn(1);\n\t}\n\nstatic int get_client_hello(SSL *s)\n\t{\n\tint i,n;\n\tunsigned long len;\n\tunsigned char *p;\n\tSTACK_OF(SSL_CIPHER) *cs; /* a stack of SSL_CIPHERS */\n\tSTACK_OF(SSL_CIPHER) *cl; /* the ones we want to use */\n\tSTACK_OF(SSL_CIPHER) *prio, *allow;\n\tint z;\n\n\t/* This is a bit of a hack to check for the correct packet\n\t * type the first time round. */\n\tif (s->state == SSL2_ST_GET_CLIENT_HELLO_A)\n\t\t{\n\t\ts->first_packet=1;\n\t\ts->state=SSL2_ST_GET_CLIENT_HELLO_B;\n\t\t}\n\n\tp=(unsigned char *)s->init_buf->data;\n\tif (s->state == SSL2_ST_GET_CLIENT_HELLO_B)\n\t\t{\n\t\ti=ssl2_read(s,(char *)&(p[s->init_num]),9-s->init_num);\n\t\tif (i < (9-s->init_num)) \n\t\t\treturn(ssl2_part_read(s,SSL_F_GET_CLIENT_HELLO,i));\n\t\ts->init_num = 9;\n\t\n\t\tif (*(p++) != SSL2_MT_CLIENT_HELLO)\n\t\t\t{\n\t\t\tif (p[-1] != SSL2_MT_ERROR)\n\t\t\t\t{\n\t\t\t\tssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);\n\t\t\t\tSSLerr(SSL_F_GET_CLIENT_HELLO,SSL_R_READ_WRONG_PACKET_TYPE);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tSSLerr(SSL_F_GET_CLIENT_HELLO,SSL_R_PEER_ERROR);\n\t\t\treturn(-1);\n\t\t\t}\n/* ... 123 lines omitted ... */\n\tp+=s->s2->tmp.session_id_length;\n\n\t/* challenge */\n\tif (s->s2->challenge_length > sizeof s->s2->challenge)\n\t\t{\n\t\tssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);\n\t\tSSLerr(SSL_F_GET_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);\n\t\treturn -1;\n\t\t}\n\tmemcpy(s->s2->challenge,p,(unsigned int)s->s2->challenge_length);\n\treturn(1);\nmem_err:\n\tSSLerr(SSL_F_GET_CLIENT_HELLO,ERR_R_MALLOC_FAILURE);\n\treturn(0);\n\t}\n\nstatic int server_hello(SSL *s)\n```\n\n\n## Upstream Fix\n```diff\nFrom d81a1600588b726c2bdccda7efad3cc7a87d6245 Mon Sep 17 00:00:00 2001\nFrom: Viktor Dukhovni \nDate: Wed, 30 Dec 2015 22:44:51 -0500\nSubject: [PATCH] Better SSLv2 cipher-suite enforcement\n\nBased on patch by: Nimrod Aviram \n\nCVE-2015-3197\n\nReviewed-by: Tim Hudson \nReviewed-by: Richard Levitte \n---\n ssl/s2_srvr.c | 15 +++++++++++++--\n 1 file changed, 13 insertions(+), 2 deletions(-)\n\ndiff --git a/ssl/s2_srvr.c b/ssl/s2_srvr.c\nindex 5e2e0acc357cf..07e9df82820a9 100644\n--- a/ssl/s2_srvr.c\n+++ b/ssl/s2_srvr.c\n@@ -402,7 +402,7 @@ static int get_client_master_key(SSL *s)\n }\n \n cp = ssl2_get_cipher_by_char(p);\n- if (cp == NULL) {\n+ if (cp == NULL || sk_SSL_CIPHER_find(s->session->ciphers, cp) < 0) {\n ssl2_return_error(s, SSL2_PE_NO_CIPHER);\n SSLerr(SSL_F_GET_CLIENT_MASTER_KEY, SSL_R_NO_CIPHER_MATCH);\n return (-1);\n@@ -692,8 +692,12 @@ static int get_client_hello(SSL *s)\n prio = cs;\n allow = cl;\n }\n+\n+ /* Generate list of SSLv2 ciphers shared between client and server */\n for (z = 0; z < sk_SSL_CIPHER_num(prio); z++) {\n- if (sk_SSL_CIPHER_find(allow, sk_SSL_CIPHER_value(prio, z)) < 0) {\n+ const SSL_CIPHER *cp = sk_SSL_CIPHER_value(prio, z);\n+ if ((cp->algorithm_ssl & SSL_SSLV2) == 0 ||\n+ sk_SSL_CIPHER_find(allow, cp) < 0) {\n (void)sk_SSL_CIPHER_delete(prio, z);\n z--;\n }\n@@ -702,6 +706,13 @@ static int get_client_hello(SSL *s)\n sk_SSL_CIPHER_free(s->session->ciphers);\n s->session->ciphers = prio;\n }\n+\n+ /* Make sure we have at least one cipher in common */\n+ if (sk_SSL_CIPHER_num(s->session->ciphers) == 0) {\n+ ssl2_return_error(s, SSL2_PE_NO_CIPHER);\n+ SSLerr(SSL_F_GET_CLIENT_HELLO, SSL_R_NO_CIPHER_MATCH);\n+ return -1;\n+ }\n /*\n * s->session->ciphers should now have a list of ciphers that are on\n * both the client and server. This list is ordered by the order the\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From d81a1600588b726c2bdccda7efad3cc7a87d6245 Mon Sep 17 00:00:00 2001\nFrom: Viktor Dukhovni \nDate: Wed, 30 Dec 2015 22:44:51 -0500\nSubject: [PATCH] Better SSLv2 cipher-suite enforcement\n\nBased on patch by: Nimrod Aviram \n\nCVE-2015-3197\n\nReviewed-by: Tim Hudson \nReviewed-by: Richard Levitte \n---\n ssl/s2_srvr.c | 15 +++++++++++++--\n 1 file changed, 13 insertions(+), 2 deletions(-)\n\nIndex: openssl-1.0.1i/ssl/s2_srvr.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s2_srvr.c\t2016-02-12 16:01:39.232958201 +0100\n+++ openssl-1.0.1i/ssl/s2_srvr.c\t2016-02-12 16:12:32.198678259 +0100\n@@ -392,7 +392,7 @@ static int get_client_master_key(SSL *s)\n \t\t\t}\n \n \t\tcp=ssl2_get_cipher_by_char(p);\n-\t\tif (cp == NULL)\n+\t if (cp == NULL || sk_SSL_CIPHER_find(s->session->ciphers, cp) < 0)\n \t\t\t{\n \t\t\tssl2_return_error(s,SSL2_PE_NO_CIPHER);\n \t\t\tSSLerr(SSL_F_GET_CLIENT_MASTER_KEY, SSL_R_NO_CIPHER_MATCH);\n@@ -690,10 +690,13 @@ static int get_client_hello(SSL *s)\n \t\t prio = cs;\n \t\t allow = cl;\n \t\t }\n+\n+ /* Generate list of SSLv2 ciphers shared between client and server */\n \t\tfor (z=0; zalgorithm_ssl & SSL_SSLV2) == 0 ||\n+\t\t\t\tsk_SSL_CIPHER_find(allow, cp) < 0) {\n \t\t\t\t(void)sk_SSL_CIPHER_delete(prio,z);\n \t\t\t\tz--;\n \t\t\t\t}\n@@ -703,6 +706,13 @@ static int get_client_hello(SSL *s)\n \t\t sk_SSL_CIPHER_free(s->session->ciphers);\n \t\t s->session->ciphers = prio;\n \t\t }\n+\n+\t\t/* Make sure we have at least one cipher in common */\n+\t\tif (sk_SSL_CIPHER_num(s->session->ciphers) == 0) {\n+\t\t ssl2_return_error(s, SSL2_PE_NO_CIPHER);\n+\t\t SSLerr(SSL_F_GET_CLIENT_HELLO, SSL_R_NO_CIPHER_MATCH);\n+\t\t return -1;\n+\t\t}\n \t\t/* s->session->ciphers should now have a list of\n \t\t * ciphers that are on both the client and server.\n \t\t * This list is ordered by the order the client sent"}], "metadata": {"id": "openssl-4769-openssl-CVE-2015-3197.patch", "cve_id": "CVE-2015-3197", "package": "openssl", "upstream_enriched": true, "upstream_commit": "d81a1600588b726c2bdccda7efad3cc7a87d6245", "upstream_repo": "openssl/openssl", "tier": "adapted", "has_source_context": true, "context_tokens_est": 791, "context_files": 1, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1i/crypto/asn1/tasn_dec.c\n- crypto/asn1/tasn_dec.c\n- openssl-1.0.1i.orig/crypto/asn1/tasn_dec.c\n\n## Target Source Code\n\n### crypto/asn1/tasn_dec.c\n\n#### ASN1_item_ex_d2i() [lines 151-528]\n```c\n * If 'opt' set and tag mismatch return -1 to handle OPTIONAL\n */\n\nint ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,\n\t\t\tconst ASN1_ITEM *it,\n\t\t\tint tag, int aclass, char opt, ASN1_TLC *ctx)\n\t{\n\tconst ASN1_TEMPLATE *tt, *errtt = NULL;\n\tconst ASN1_COMPAT_FUNCS *cf;\n\tconst ASN1_EXTERN_FUNCS *ef;\n\tconst ASN1_AUX *aux = it->funcs;\n\tASN1_aux_cb *asn1_cb;\n\tconst unsigned char *p = NULL, *q;\n\tunsigned char *wp=NULL;\t/* BIG FAT WARNING! BREAKS CONST WHERE USED */\n\tunsigned char imphack = 0, oclass;\n\tchar seq_eoc, seq_nolen, cst, isopt;\n\tlong tmplen;\n\tint i;\n\tint otag;\n\tint ret = 0;\n\tASN1_VALUE **pchptr, *ptmpval;\n\tif (!pval)\n\t\treturn 0;\n\tif (aux && aux->asn1_cb)\n\t\tasn1_cb = aux->asn1_cb;\n\telse asn1_cb = 0;\n\n\tswitch(it->itype)\n\t\t{\n\t\tcase ASN1_ITYPE_PRIMITIVE:\n\t\tif (it->templates)\n\t\t\t{\n\t\t\t/* tagging or OPTIONAL is currently illegal on an item\n\t\t\t * template because the flags can't get passed down.\n\t\t\t * In practice this isn't a problem: we include the\n\t\t\t * relevant flags from the item template in the\n\t\t\t * template itself.\n\t\t\t */\n\t\t\tif ((tag != -1) || opt)\n\t\t\t\t{\n/* ... 323 lines omitted ... */\n\t\tif (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL))\n\t\t\t\tgoto auxerr;\n\t\treturn 1;\n\n\t\tdefault:\n\t\treturn 0;\n\t\t}\n\tauxerr:\n\tASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_AUX_ERROR);\n\terr:\n\tASN1_item_ex_free(pval, it);\n\tif (errtt)\n\t\tERR_add_error_data(4, \"Field=\", errtt->field_name,\n\t\t\t\t\t\", Type=\", it->sname);\n\telse\n\t\tERR_add_error_data(2, \"Type=\", it->sname);\n\treturn 0;\n\t}\n\n/* Templates are handled with two separate functions.\n```\n\n#### asn1_template_noexp_d2i() [lines 615-766]\n```c\n\treturn 0;\n\t}\n\nstatic int asn1_template_noexp_d2i(ASN1_VALUE **val,\n\t\t\t\tconst unsigned char **in, long len,\n\t\t\t\tconst ASN1_TEMPLATE *tt, char opt,\n\t\t\t\tASN1_TLC *ctx)\n\t{\n\tint flags, aclass;\n\tint ret;\n\tconst unsigned char *p, *q;\n\tif (!val)\n\t\treturn 0;\n\tflags = tt->flags;\n\taclass = flags & ASN1_TFLG_TAG_CLASS;\n\n\tp = *in;\n\tq = p;\n\n\tif (flags & ASN1_TFLG_SK_MASK)\n\t\t{\n\t\t/* SET OF, SEQUENCE OF */\n\t\tint sktag, skaclass;\n\t\tchar sk_eoc;\n\t\t/* First work out expected inner tag value */\n\t\tif (flags & ASN1_TFLG_IMPTAG)\n\t\t\t{\n\t\t\tsktag = tt->tag;\n\t\t\tskaclass = aclass;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tskaclass = V_ASN1_UNIVERSAL;\n\t\t\tif (flags & ASN1_TFLG_SET_OF)\n\t\t\t\tsktag = V_ASN1_SET;\n\t\t\telse\n\t\t\t\tsktag = V_ASN1_SEQUENCE;\n\t\t\t}\n\t\t/* Get the tag */\n\t\tret = asn1_check_tlen(&len, NULL, NULL, &sk_eoc, NULL,\n/* ... 98 lines omitted ... */\n\t\t\t}\n\t\telse if (ret == -1)\n\t\t\treturn -1;\n\t\t}\n\n\t*in = p;\n\treturn 1;\n\n\terr:\n\tASN1_template_free(val, tt);\n\treturn 0;\n\t}\n\nstatic int asn1_d2i_ex_primitive(ASN1_VALUE **pval,\n```\n\n\n## Upstream Fix\n```diff\nFrom b29ffa392e839d05171206523e84909146f7a77c Mon Sep 17 00:00:00 2001\nFrom: \"Dr. Stephen Henson\" \nDate: Tue, 10 Nov 2015 19:03:07 +0000\nSubject: [PATCH] Fix leak with ASN.1 combine.\n\nWhen parsing a combined structure pass a flag to the decode routine\nso on error a pointer to the parent structure is not zeroed as\nthis will leak any additional components in the parent.\n\nThis can leak memory in any application parsing PKCS#7 or CMS structures.\n\nCVE-2015-3195.\n\nThanks to Adam Langley (Google/BoringSSL) for discovering this bug using\nlibFuzzer.\n\nPR#4131\n\nReviewed-by: Richard Levitte \n---\n crypto/asn1/tasn_dec.c | 7 +++++--\n 1 file changed, 5 insertions(+), 2 deletions(-)\n\ndiff --git a/crypto/asn1/tasn_dec.c b/crypto/asn1/tasn_dec.c\nindex febf6059cbe5a..9256049d15881 100644\n--- a/crypto/asn1/tasn_dec.c\n+++ b/crypto/asn1/tasn_dec.c\n@@ -180,6 +180,8 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,\n int otag;\n int ret = 0;\n ASN1_VALUE **pchptr, *ptmpval;\n+ int combine = aclass & ASN1_TFLG_COMBINE;\n+ aclass &= ~ASN1_TFLG_COMBINE;\n if (!pval)\n return 0;\n if (aux && aux->asn1_cb)\n@@ -500,7 +502,8 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,\n auxerr:\n ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_AUX_ERROR);\n err:\n- ASN1_item_ex_free(pval, it);\n+ if (combine == 0)\n+ ASN1_item_ex_free(pval, it);\n if (errtt)\n ERR_add_error_data(4, \"Field=\", errtt->field_name,\n \", Type=\", it->sname);\n@@ -689,7 +692,7 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,\n } else {\n /* Nothing special */\n ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item),\n- -1, 0, opt, ctx);\n+ -1, tt->flags & ASN1_TFLG_COMBINE, opt, ctx);\n if (!ret) {\n ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_NESTED_ASN1_ERROR);\n goto err;\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From b29ffa392e839d05171206523e84909146f7a77c Mon Sep 17 00:00:00 2001\nFrom: \"Dr. Stephen Henson\" \nDate: Tue, 10 Nov 2015 19:03:07 +0000\nSubject: [PATCH] Fix leak with ASN.1 combine.\n\nWhen parsing a combined structure pass a flag to the decode routine\nso on error a pointer to the parent structure is not zeroed as\nthis will leak any additional components in the parent.\n\nThis can leak memory in any application parsing PKCS#7 or CMS structures.\n\nCVE-2015-3195.\n\nThanks to Adam Langley (Google/BoringSSL) for discovering this bug using\nlibFuzzer.\n\nPR#4131\n\nReviewed-by: Richard Levitte \n---\n crypto/asn1/tasn_dec.c | 7 +++++--\n 1 file changed, 5 insertions(+), 2 deletions(-)\n\nIndex: openssl-1.0.1i/crypto/asn1/tasn_dec.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/asn1/tasn_dec.c\t2015-12-03 17:59:01.272944957 +0100\n+++ openssl-1.0.1i/crypto/asn1/tasn_dec.c\t2015-12-03 18:02:54.285726394 +0100\n@@ -169,6 +169,8 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval,\n \tint otag;\n \tint ret = 0;\n \tASN1_VALUE **pchptr, *ptmpval;\n+\tint combine = aclass & ASN1_TFLG_COMBINE;\n+\taclass &= ~ASN1_TFLG_COMBINE;\n \tif (!pval)\n \t\treturn 0;\n \tif (aux && aux->asn1_cb)\n@@ -534,7 +536,8 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval,\n \tauxerr:\n \tASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_AUX_ERROR);\n \terr:\n-\tASN1_item_ex_free(pval, it);\n+\tif (combine == 0)\n+\t\tASN1_item_ex_free(pval, it);\n \tif (errtt)\n \t\tERR_add_error_data(4, \"Field=\", errtt->field_name,\n \t\t\t\t\t\", Type=\", it->sname);\n@@ -762,7 +765,7 @@ static int asn1_template_noexp_d2i(ASN1_\n \t\t{\n \t\t/* Nothing special */\n \t\tret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item),\n-\t\t\t\t\t\t\t-1, 0, opt, ctx);\n+\t\t\t\t\t\t\t-1, tt->flags & ASN1_TFLG_COMBINE, opt, ctx);\n \t\tif (!ret)\n \t\t\t{\n \t\t\tASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,"}], "metadata": {"id": "openssl-4769-openssl-CVE-2015-3195.patch", "cve_id": "CVE-2015-3197", "package": "openssl", "upstream_enriched": true, "upstream_commit": "b29ffa392e839d05171206523e84909146f7a77c", "upstream_repo": "openssl/openssl", "tier": "adapted", "has_source_context": true, "context_tokens_est": 669, "context_files": 1, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-4658\n\nxpointer.c in libxml2 before 2.9.5 (as used in Apple iOS before 10, OS X before 10.12, tvOS before 10, and watchOS before 3, and other products) does not forbid namespace nodes in XPointer ranges, which allows remote attackers to execute arbitrary code or cause a denial of service (use-after-free and memory corruption) via a crafted XML document.\n\n## Package\nlibxml2\n\n## Files to modify\n- xpointer.c\n\n## Upstream Fix\n```diff\nFrom c1d1f7121194036608bf555f08d3062a36fd344b Mon Sep 17 00:00:00 2001\nFrom: Nick Wellnhofer \nDate: Tue, 28 Jun 2016 18:34:52 +0200\nSubject: [PATCH] Disallow namespace nodes in XPointer ranges\n\nNamespace nodes must be copied to avoid use-after-free errors.\nBut they don't necessarily have a physical representation in a\ndocument, so simply disallow them in XPointer ranges.\n\nFound with afl-fuzz.\n\nFixes CVE-2016-4658.\n---\n xpointer.c | 149 ++++++++++++++++++++---------------------------------\n 1 file changed, 56 insertions(+), 93 deletions(-)\n\ndiff --git a/xpointer.c b/xpointer.c\nindex a7b03fbdae..694d120e2e 100644\n--- a/xpointer.c\n+++ b/xpointer.c\n@@ -319,6 +319,45 @@ xmlXPtrRangesEqual(xmlXPathObjectPtr range1, xmlXPathObjectPtr range2) {\n return(1);\n }\n \n+/**\n+ * xmlXPtrNewRangeInternal:\n+ * @start: the starting node\n+ * @startindex: the start index\n+ * @end: the ending point\n+ * @endindex: the ending index\n+ *\n+ * Internal function to create a new xmlXPathObjectPtr of type range\n+ *\n+ * Returns the newly created object.\n+ */\n+static xmlXPathObjectPtr\n+xmlXPtrNewRangeInternal(xmlNodePtr start, int startindex,\n+ xmlNodePtr end, int endindex) {\n+ xmlXPathObjectPtr ret;\n+\n+ /*\n+ * Namespace nodes must be copied (see xmlXPathNodeSetDupNs).\n+ * Disallow them for now.\n+ */\n+ if ((start != NULL) && (start->type == XML_NAMESPACE_DECL))\n+\treturn(NULL);\n+ if ((end != NULL) && (end->type == XML_NAMESPACE_DECL))\n+\treturn(NULL);\n+\n+ ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n+ if (ret == NULL) {\n+ xmlXPtrErrMemory(\"allocating range\");\n+\treturn(NULL);\n+ }\n+ memset(ret, 0, sizeof(xmlXPathObject));\n+ ret->type = XPATH_RANGE;\n+ ret->user = start;\n+ ret->index = startindex;\n+ ret->user2 = end;\n+ ret->index2 = endindex;\n+ return(ret);\n+}\n+\n /**\n * xmlXPtrNewRange:\n * @start: the starting node\n@@ -344,17 +383,7 @@ xmlXPtrNewRange(xmlNodePtr start, int startindex,\n if (endindex < 0)\n \treturn(NULL);\n \n- ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n- if (ret == NULL) {\n- xmlXPtrErrMemory(\"allocating range\");\n-\treturn(NULL);\n- }\n- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));\n- ret->type = XPATH_RANGE;\n- ret->user = start;\n- ret->index = startindex;\n- ret->user2 = end;\n- ret->index2 = endindex;\n+ ret = xmlXPtrNewRangeInternal(start, startindex, end, endindex);\n xmlXPtrRangeCheckOrder(ret);\n return(ret);\n }\n@@ -381,17 +410,8 @@ xmlXPtrNewRangePoints(xmlXPathObjectPtr start, xmlXPathObjectPtr end) {\n if (end->type != XPATH_POINT)\n \treturn(NULL);\n \n- ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n- if (ret == NULL) {\n- xmlXPtrErrMemory(\"allocating range\");\n-\treturn(NULL);\n- }\n- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));\n- ret->type = XPATH_RANGE;\n- ret->user = start->user;\n- ret->index = start->index;\n- ret->user2 = end->user;\n- ret->index2 = end->index;\n+ ret = xmlXPtrNewRangeInternal(start->user, start->index, end->user,\n+ end->index);\n xmlXPtrRangeCheckOrder(ret);\n return(ret);\n }\n@@ -416,17 +436,7 @@ xmlXPtrNewRangePointNode(xmlXPathObjectPtr start, xmlNodePtr end) {\n if (start->type != XPATH_POINT)\n \treturn(NULL);\n \n- ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n- if (ret == NULL) {\n- xmlXPtrErrMemory(\"allocating range\");\n-\treturn(NULL);\n- }\n- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));\n- ret->type = XPATH_RANGE;\n- ret->user = start->user;\n- ret->index = start->index;\n- ret->user2 = end;\n- ret->index2 = -1;\n+ ret = xmlXPtrNewRangeInternal(start->user, start->index, end, -1);\n xmlXPtrRangeCheckOrder(ret);\n return(ret);\n }\n@@ -453,17 +463,7 @@ xmlXPtrNewRangeNodePoint(xmlNodePtr start, xmlXPathObjectPtr end) {\n if (end->type != XPATH_POINT)\n \treturn(NULL);\n \n- ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n- if (ret == NULL) {\n- xmlXPtrErrMemory(\"allocating range\");\n-\treturn(NULL);\n- }\n- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));\n- ret->type = XPATH_RANGE;\n- ret->user = start;\n- ret->index = -1;\n- ret->user2 = end->user;\n- ret->index2 = end->index;\n+ ret = xmlXPtrNewRangeInternal(start, -1, end->user, end->index);\n xmlXPtrRangeCheckOrder(ret);\n return(ret);\n }\n@@ -486,17 +486,7 @@ xmlXPtrNewRangeNodes(xmlNodePtr start, xmlNodePtr end) {\n if (end == NULL)\n \treturn(NULL);\n \n- ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n- if (ret == NULL) {\n- xmlXPtrErrMemory(\"allocating range\");\n-\treturn(NULL);\n- }\n- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));\n- ret->type = XPATH_RANGE;\n- ret->user = start;\n- ret->index = -1;\n- ret->user2 = end;\n- ret->index2 = -1;\n+ ret = xmlXPtrNewRangeInternal(start, -1, end, -1);\n xmlXPtrRangeCheckOrder(ret);\n return(ret);\n }\n@@ -516,17 +506,7 @@ xmlXPtrNewCollapsedRange(xmlNodePtr start) {\n if (start == NULL)\n \treturn(NULL);\n \n- ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n- if (ret == NULL) {\n- xmlXPtrErrMemory(\"allocating range\");\n-\treturn(NULL);\n- }\n- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));\n- ret->type = XPATH_RANGE;\n- ret->user = start;\n- ret->index = -1;\n- ret->user2 = NULL;\n- ret->index2 = -1;\n+ ret = xmlXPtrNewRangeInternal(start, -1, NULL, -1);\n return(ret);\n }\n \n@@ -541,6 +521,8 @@ xmlXPtrNewCollapsedRange(xmlNodePtr start) {\n */\n xmlXPathObjectPtr\n xmlXPtrNewRangeNodeObject(xmlNodePtr start, xmlXPathObjectPtr end) {\n+ xmlNodePtr endNode;\n+ int endIndex;\n xmlXPathObjectPtr ret;\n \n if (start == NULL)\n@@ -549,7 +531,12 @@ xmlXPtrNewRangeNodeObject(xmlNodePtr start, xmlXPathObjectPtr end) {\n \treturn(NULL);\n switch (end->type) {\n \tcase XPATH_POINT:\n+\t endNode = end->user;\n+\t endIndex = end->index;\n+\t break;\n \tcase XPATH_RANGE:\n+\t endNode = end->user2;\n+\t endIndex = end->index2;\n \t break;\n \tcase XPATH_NODESET:\n \t /*\n@@ -557,39 +544,15 @@ xmlXPtrNewRangeNodeObject(xmlNodePtr start, xmlXPathObjectPtr end) {\n \t */\n \t if (end->nodesetval->nodeNr <= 0)\n \t\treturn(NULL);\n+\t endNode = end->nodesetval->nodeTab[end->nodesetval->nodeNr - 1];\n+\t endIndex = -1;\n \t break;\n \tdefault:\n \t /* TODO */\n \t return(NULL);\n }\n \n- ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n- if (ret == NULL) {\n- xmlXPtrErrMemory(\"allocating range\");\n-\treturn(NULL);\n- }\n- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));\n- ret->type = XPATH_RANGE;\n- ret->user = start;\n- ret->index = -1;\n- switch (end->type) {\n-\tcase XPATH_POINT:\n-\t ret->user2 = end->user;\n-\t ret->index2 = end->index;\n-\t break;\n-\tcase XPATH_RANGE:\n-\t ret->user2 = end->user2;\n-\t ret->index2 = end->index2;\n-\t break;\n-\tcase XPATH_NODESET: {\n-\t ret->user2 = end->nodesetval->nodeTab[end->nodesetval->nodeNr - 1];\n-\t ret->index2 = -1;\n-\t break;\n-\t}\n-\tdefault:\n-\t STRANGE\n-\t return(NULL);\n- }\n+ ret = xmlXPtrNewRangeInternal(start, -1, endNode, endIndex);\n xmlXPtrRangeCheckOrder(ret);\n return(ret);\n }\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From c1d1f7121194036608bf555f08d3062a36fd344b Mon Sep 17 00:00:00 2001\nFrom: Nick Wellnhofer \nDate: Tue, 28 Jun 2016 18:34:52 +0200\nSubject: [PATCH 1/5] Disallow namespace nodes in XPointer ranges\n\nNamespace nodes must be copied to avoid use-after-free errors.\nBut they don't necessarily have a physical representation in a\ndocument, so simply disallow them in XPointer ranges.\n\nFound with afl-fuzz.\n\nFixes CVE-2016-4658.\n---\n xpointer.c | 149 +++++++++++++++++++++++--------------------------------------\n 1 file changed, 56 insertions(+), 93 deletions(-)\n\ndiff --git a/xpointer.c b/xpointer.c\nindex a7b03fb..694d120 100644\n--- a/xpointer.c\n+++ b/xpointer.c\n@@ -320,6 +320,45 @@ xmlXPtrRangesEqual(xmlXPathObjectPtr range1, xmlXPathObjectPtr range2) {\n }\n \n /**\n+ * xmlXPtrNewRangeInternal:\n+ * @start: the starting node\n+ * @startindex: the start index\n+ * @end: the ending point\n+ * @endindex: the ending index\n+ *\n+ * Internal function to create a new xmlXPathObjectPtr of type range\n+ *\n+ * Returns the newly created object.\n+ */\n+static xmlXPathObjectPtr\n+xmlXPtrNewRangeInternal(xmlNodePtr start, int startindex,\n+ xmlNodePtr end, int endindex) {\n+ xmlXPathObjectPtr ret;\n+\n+ /*\n+ * Namespace nodes must be copied (see xmlXPathNodeSetDupNs).\n+ * Disallow them for now.\n+ */\n+ if ((start != NULL) && (start->type == XML_NAMESPACE_DECL))\n+\treturn(NULL);\n+ if ((end != NULL) && (end->type == XML_NAMESPACE_DECL))\n+\treturn(NULL);\n+\n+ ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n+ if (ret == NULL) {\n+ xmlXPtrErrMemory(\"allocating range\");\n+\treturn(NULL);\n+ }\n+ memset(ret, 0, sizeof(xmlXPathObject));\n+ ret->type = XPATH_RANGE;\n+ ret->user = start;\n+ ret->index = startindex;\n+ ret->user2 = end;\n+ ret->index2 = endindex;\n+ return(ret);\n+}\n+\n+/**\n * xmlXPtrNewRange:\n * @start: the starting node\n * @startindex: the start index\n@@ -344,17 +383,7 @@ xmlXPtrNewRange(xmlNodePtr start, int startindex,\n if (endindex < 0)\n \treturn(NULL);\n \n- ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n- if (ret == NULL) {\n- xmlXPtrErrMemory(\"allocating range\");\n-\treturn(NULL);\n- }\n- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));\n- ret->type = XPATH_RANGE;\n- ret->user = start;\n- ret->index = startindex;\n- ret->user2 = end;\n- ret->index2 = endindex;\n+ ret = xmlXPtrNewRangeInternal(start, startindex, end, endindex);\n xmlXPtrRangeCheckOrder(ret);\n return(ret);\n }\n@@ -381,17 +410,8 @@ xmlXPtrNewRangePoints(xmlXPathObjectPtr start, xmlXPathObjectPtr end) {\n if (end->type != XPATH_POINT)\n \treturn(NULL);\n \n- ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n- if (ret == NULL) {\n- xmlXPtrErrMemory(\"allocating range\");\n-\treturn(NULL);\n- }\n- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));\n- ret->type = XPATH_RANGE;\n- ret->user = start->user;\n- ret->index = start->index;\n- ret->user2 = end->user;\n- ret->index2 = end->index;\n+ ret = xmlXPtrNewRangeInternal(start->user, start->index, end->user,\n+ end->index);\n xmlXPtrRangeCheckOrder(ret);\n return(ret);\n }\n@@ -416,17 +436,7 @@ xmlXPtrNewRangePointNode(xmlXPathObjectPtr start, xmlNodePtr end) {\n if (start->type != XPATH_POINT)\n \treturn(NULL);\n \n- ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n- if (ret == NULL) {\n- xmlXPtrErrMemory(\"allocating range\");\n-\treturn(NULL);\n- }\n- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));\n- ret->type = XPATH_RANGE;\n- ret->user = start->user;\n- ret->index = start->index;\n- ret->user2 = end;\n- ret->index2 = -1;\n+ ret = xmlXPtrNewRangeInternal(start->user, start->index, end, -1);\n xmlXPtrRangeCheckOrder(ret);\n return(ret);\n }\n@@ -453,17 +463,7 @@ xmlXPtrNewRangeNodePoint(xmlNodePtr start, xmlXPathObjectPtr end) {\n if (end->type != XPATH_POINT)\n \treturn(NULL);\n \n- ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n- if (ret == NULL) {\n- xmlXPtrErrMemory(\"allocating range\");\n-\treturn(NULL);\n- }\n- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));\n- ret->type = XPATH_RANGE;\n- ret->user = start;\n- ret->index = -1;\n- ret->user2 = end->user;\n- ret->index2 = end->index;\n+ ret = xmlXPtrNewRangeInternal(start, -1, end->user, end->index);\n xmlXPtrRangeCheckOrder(ret);\n return(ret);\n }\n@@ -486,17 +486,7 @@ xmlXPtrNewRangeNodes(xmlNodePtr start, xmlNodePtr end) {\n if (end == NULL)\n \treturn(NULL);\n \n- ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n- if (ret == NULL) {\n- xmlXPtrErrMemory(\"allocating range\");\n-\treturn(NULL);\n- }\n- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));\n- ret->type = XPATH_RANGE;\n- ret->user = start;\n- ret->index = -1;\n- ret->user2 = end;\n- ret->index2 = -1;\n+ ret = xmlXPtrNewRangeInternal(start, -1, end, -1);\n xmlXPtrRangeCheckOrder(ret);\n return(ret);\n }\n@@ -516,17 +506,7 @@ xmlXPtrNewCollapsedRange(xmlNodePtr start) {\n if (start == NULL)\n \treturn(NULL);\n \n- ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n- if (ret == NULL) {\n- xmlXPtrErrMemory(\"allocating range\");\n-\treturn(NULL);\n- }\n- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));\n- ret->type = XPATH_RANGE;\n- ret->user = start;\n- ret->index = -1;\n- ret->user2 = NULL;\n- ret->index2 = -1;\n+ ret = xmlXPtrNewRangeInternal(start, -1, NULL, -1);\n return(ret);\n }\n \n@@ -541,6 +521,8 @@ xmlXPtrNewCollapsedRange(xmlNodePtr start) {\n */\n xmlXPathObjectPtr\n xmlXPtrNewRangeNodeObject(xmlNodePtr start, xmlXPathObjectPtr end) {\n+ xmlNodePtr endNode;\n+ int endIndex;\n xmlXPathObjectPtr ret;\n \n if (start == NULL)\n@@ -549,7 +531,12 @@ xmlXPtrNewRangeNodeObject(xmlNodePtr start, xmlXPathObjectPtr end) {\n \treturn(NULL);\n switch (end->type) {\n \tcase XPATH_POINT:\n+\t endNode = end->user;\n+\t endIndex = end->index;\n+\t break;\n \tcase XPATH_RANGE:\n+\t endNode = end->user2;\n+\t endIndex = end->index2;\n \t break;\n \tcase XPATH_NODESET:\n \t /*\n@@ -557,39 +544,15 @@ xmlXPtrNewRangeNodeObject(xmlNodePtr start, xmlXPathObjectPtr end) {\n \t */\n \t if (end->nodesetval->nodeNr <= 0)\n \t\treturn(NULL);\n+\t endNode = end->nodesetval->nodeTab[end->nodesetval->nodeNr - 1];\n+\t endIndex = -1;\n \t break;\n \tdefault:\n \t /* TODO */\n \t return(NULL);\n }\n \n- ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));\n- if (ret == NULL) {\n- xmlXPtrErrMemory(\"allocating range\");\n-\treturn(NULL);\n- }\n- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));\n- ret->type = XPATH_RANGE;\n- ret->user = start;\n- ret->index = -1;\n- switch (end->type) {\n-\tcase XPATH_POINT:\n-\t ret->user2 = end->user;\n-\t ret->index2 = end->index;\n-\t break;\n-\tcase XPATH_RANGE:\n-\t ret->user2 = end->user2;\n-\t ret->index2 = end->index2;\n-\t break;\n-\tcase XPATH_NODESET: {\n-\t ret->user2 = end->nodesetval->nodeTab[end->nodesetval->nodeNr - 1];\n-\t ret->index2 = -1;\n-\t break;\n-\t}\n-\tdefault:\n-\t STRANGE\n-\t return(NULL);\n- }\n+ ret = xmlXPtrNewRangeInternal(start, -1, endNode, endIndex);\n xmlXPtrRangeCheckOrder(ret);\n return(ret);\n }\n-- \n2.10.1"}], "metadata": {"id": "libxml2-5770-libxml2-2.9.4-CVE-2016-4658.pa", "cve_id": "CVE-2016-4658", "package": "libxml2", "upstream_enriched": true, "upstream_commit": "c1d1f7121194036608bf555f08d3062a36fd344b", "upstream_repo": "GNOME/libxml2", "tier": "adapted", "has_source_context": false, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3455\n\nSquid 3.2.x before 3.2.14, 3.3.x before 3.3.14, 3.4.x before 3.4.13, and 3.5.x before 3.5.4, when configured with client-first SSL-bump, do not properly validate the domain or hostname fields of X.509 certificates, which allows man-in-the-middle attackers to spoof SSL servers via a valid certificate.\n\n## Package\nsquid\n\n## Upstream Fix\n```diff\n------------------------------------------------------------\nrevno: 12698\nrevision-id: squid3@treenet.co.nz-20160502034346-fhtahpk2lfblo2b1\nparent: squid3@treenet.co.nz-20160420111636-ft1dbd1iuktj8ift\ncommitter: Amos Jeffries \nbranch nick: 3.3\ntimestamp: Mon 2016-05-02 15:43:46 +1200\nmessage:\n Require exact match in Host header name lookup\n------------------------------------------------------------\n# Bazaar merge directive format 2 (Bazaar 0.90)\n# revision_id: squid3@treenet.co.nz-20160502034346-fhtahpk2lfblo2b1\n# target_branch: http://bzr.squid-cache.org/bzr/squid3/3.3\n# testament_sha1: 6e285b375879d79c870bff268c99ef2597f1b725\n# timestamp: 2016-05-02 03:50:49 +0000\n# source_branch: http://bzr.squid-cache.org/bzr/squid3/3.3\n# base_revision_id: squid3@treenet.co.nz-20160420111636-\\\n# ft1dbd1iuktj8ift\n# \n# Begin patch\n=== modified file 'src/mime_header.cc'\n--- src/mime_header.cc\t2012-08-29 12:36:10 +0000\n+++ src/mime_header.cc\t2016-05-02 03:43:46 +0000\n@@ -62,9 +62,6 @@\n if (strcmp(p, \"\\r\\n\\r\\n\") == 0 || strcmp(p, \"\\n\\n\") == 0)\n return NULL;\n \n- while (xisspace(*p))\n- ++p;\n-\n if (strncasecmp(p, name, namelen))\n continue;\n \n\n------------------------------------------------------------\nrevno: 12700\nrevision-id: squid3@treenet.co.nz-20160508124255-w1vb9ifv5affhgai\nparent: squid3@treenet.co.nz-20160506091321-tza59kjh2g6goob0\nfixes bug: http://bugs.squid-cache.org/show_bug.cgi?id=4515\ncommitter: Amos Jeffries \nbranch nick: 3.3\ntimestamp: Mon 2016-05-09 00:42:55 +1200\nmessage:\n Bug 4515: regression after CVE-2016-4554 patch\n------------------------------------------------------------\n# Bazaar merge directive format 2 (Bazaar 0.90)\n# revision_id: squid3@treenet.co.nz-20160508124255-w1vb9ifv5affhgai\n# target_branch: http://bzr.squid-cache.org/bzr/squid3/3.3\n# testament_sha1: 5ff66676035dc7841f6eb610dee8739dc015f29c\n# timestamp: 2016-05-08 12:50:57 +0000\n# source_branch: http://bzr.squid-cache.org/bzr/squid3/3.3\n# base_revision_id: squid3@treenet.co.nz-20160506091321-\\\n# tza59kjh2g6goob0\n# \n# Begin patch\n=== modified file 'src/mime_header.cc'\n--- src/mime_header.cc\t2016-05-02 03:43:46 +0000\n+++ src/mime_header.cc\t2016-05-08 12:42:55 +0000\n@@ -58,10 +58,13 @@\n \n debugs(25, 5, \"mime_get_header: looking for '\" << name << \"'\");\n \n- for (p = mime; *p; p += strcspn(p, \"\\n\\r\")) {\n- if (strcmp(p, \"\\r\\n\\r\\n\") == 0 || strcmp(p, \"\\n\\n\") == 0)\n+ for (p = mime; *p; p += strcspn(p, \"\\n\")) {\n+ if (strcmp(p, \"\\n\\r\\n\") == 0 || strcmp(p, \"\\n\\n\") == 0)\n return NULL;\n \n+ if (*p == '\\n')\n+ ++p;\n+\n if (strncasecmp(p, name, namelen))\n continue;\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "------------------------------------------------------------\nrevno: 12698\nrevision-id: squid3@treenet.co.nz-20160502034346-fhtahpk2lfblo2b1\nparent: squid3@treenet.co.nz-20160420111636-ft1dbd1iuktj8ift\ncommitter: Amos Jeffries \nbranch nick: 3.3\ntimestamp: Mon 2016-05-02 15:43:46 +1200\nmessage:\n Require exact match in Host header name lookup\n------------------------------------------------------------\n# Bazaar merge directive format 2 (Bazaar 0.90)\n# revision_id: squid3@treenet.co.nz-20160502034346-fhtahpk2lfblo2b1\n# target_branch: http://bzr.squid-cache.org/bzr/squid3/3.3\n# testament_sha1: 6e285b375879d79c870bff268c99ef2597f1b725\n# timestamp: 2016-05-02 03:50:49 +0000\n# source_branch: http://bzr.squid-cache.org/bzr/squid3/3.3\n# base_revision_id: squid3@treenet.co.nz-20160420111636-\\\n# ft1dbd1iuktj8ift\n# \n# Begin patch\n=== modified file 'src/mime_header.cc'\n--- src/mime_header.cc\t2012-08-29 12:36:10 +0000\n+++ src/mime_header.cc\t2016-05-02 03:43:46 +0000\n@@ -62,9 +62,6 @@\n if (strcmp(p, \"\\r\\n\\r\\n\") == 0 || strcmp(p, \"\\n\\n\") == 0)\n return NULL;\n \n- while (xisspace(*p))\n- ++p;\n-\n if (strncasecmp(p, name, namelen))\n continue;\n \n\n------------------------------------------------------------\nrevno: 12700\nrevision-id: squid3@treenet.co.nz-20160508124255-w1vb9ifv5affhgai\nparent: squid3@treenet.co.nz-20160506091321-tza59kjh2g6goob0\nfixes bug: http://bugs.squid-cache.org/show_bug.cgi?id=4515\ncommitter: Amos Jeffries \nbranch nick: 3.3\ntimestamp: Mon 2016-05-09 00:42:55 +1200\nmessage:\n Bug 4515: regression after CVE-2016-4554 patch\n------------------------------------------------------------\n# Bazaar merge directive format 2 (Bazaar 0.90)\n# revision_id: squid3@treenet.co.nz-20160508124255-w1vb9ifv5affhgai\n# target_branch: http://bzr.squid-cache.org/bzr/squid3/3.3\n# testament_sha1: 5ff66676035dc7841f6eb610dee8739dc015f29c\n# timestamp: 2016-05-08 12:50:57 +0000\n# source_branch: http://bzr.squid-cache.org/bzr/squid3/3.3\n# base_revision_id: squid3@treenet.co.nz-20160506091321-\\\n# tza59kjh2g6goob0\n# \n# Begin patch\n=== modified file 'src/mime_header.cc'\n--- src/mime_header.cc\t2016-05-02 03:43:46 +0000\n+++ src/mime_header.cc\t2016-05-08 12:42:55 +0000\n@@ -58,10 +58,13 @@\n \n debugs(25, 5, \"mime_get_header: looking for '\" << name << \"'\");\n \n- for (p = mime; *p; p += strcspn(p, \"\\n\\r\")) {\n- if (strcmp(p, \"\\r\\n\\r\\n\") == 0 || strcmp(p, \"\\n\\n\") == 0)\n+ for (p = mime; *p; p += strcspn(p, \"\\n\")) {\n+ if (strcmp(p, \"\\n\\r\\n\") == 0 || strcmp(p, \"\\n\\n\") == 0)\n return NULL;\n \n+ if (*p == '\\n')\n+ ++p;\n+\n if (strncasecmp(p, name, namelen))\n continue;"}], "metadata": {"id": "squid-5473-SQUID-2016_8.patch", "cve_id": "CVE-2015-3455", "package": "squid", "tier": "identical", "has_source_context": false, "license": "GPL-2.0-or-later"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1i/ssl/ssl_err.c\n- openssl-1.0.1i.orig/ssl/s3_clnt.c\n- openssl-1.0.1i/ssl/ssl.h\n- openssl-1.0.1i.orig/ssl/ssl_err.c\n- openssl-1.0.1i/ssl/s3_clnt.c\n\n## Target Source Code\n\n### CHANGES\n\n#### region() [lines 1-49]\n```c\n\n OpenSSL CHANGES\n _______________\n\n Changes between 1.0.1h and 1.0.1i [6 Aug 2014]\n\n *) Fix SRP buffer overrun vulnerability. Invalid parameters passed to the\n SRP code can be overrun an internal buffer. Add sanity check that\n g, A, B < N to SRP code.\n\n Thanks to Sean Devlin and Watson Ladd of Cryptography Services, NCC\n Group for discovering this issue.\n (CVE-2014-3512)\n [Steve Henson]\n\n *) A flaw in the OpenSSL SSL/TLS server code causes the server to negotiate\n TLS 1.0 instead of higher protocol versions when the ClientHello message\n is badly fragmented. This allows a man-in-the-middle attacker to force a\n downgrade to TLS 1.0 even if both the server and the client support a\n higher protocol version, by modifying the client's TLS records.\n\n Thanks to David Benjamin and Adam Langley (Google) for discovering and\n researching this issue.\n (CVE-2014-3511)\n [David Benjamin]\n\n *) OpenSSL DTLS clients enabling anonymous (EC)DH ciphersuites are subject\n to a denial of service attack. A malicious server can crash the client\n with a null pointer dereference (read) by specifying an anonymous (EC)DH\n ciphersuite and sending carefully crafted handshake messages.\n\n Thanks to Felix Gr�bert (Google) for discovering and researching this\n issue.\n (CVE-2014-3510)\n [Emilia K�sper]\n\n *) By sending carefully crafted DTLS packets an attacker could cause openssl\n to leak memory. This can be exploited through a Denial of Service attack.\n Thanks to Adam Langley for discovering and researching this issue.\n (CVE-2014-3507)\n [Adam Langley]\n\n *) An attacker can force openssl to consume large amounts of memory whilst\n processing DTLS handshake messages. This can be exploited through a\n Denial of Service attack.\n Thanks to Adam Langley for discovering and researching this issue.\n (CVE-2014-3506)\n [Adam Langley]\n\n```\n\n### ssl/s3_clnt.c\n\n#### ssl3_check_cert_and_algorithm() [lines 363-372]\n```c\n\n\t\t\t/* at this point we check that we have the\n\t\t\t * required stuff from the server */\n\t\t\tif (!ssl3_check_cert_and_algorithm(s))\n\t\t\t\t{\n\t\t\t\tret= -1;\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tbreak;\n\n```\n\n### ssl/ssl.h\n\n#### ERR_load_SSL_strings() [lines 2330-2416]\n```c\n#define SSL_R_BAD_SRTP_MKI_VALUE\t\t\t 352\n#define SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST\t\t 353\n#define SSL_R_BAD_SSL_FILETYPE\t\t\t\t 124\n#define SSL_R_BAD_SSL_SESSION_ID_LENGTH\t\t\t 125\n#define SSL_R_BAD_STATE\t\t\t\t\t 126\n#define SSL_R_BAD_WRITE_RETRY\t\t\t\t 127\n#define SSL_R_BIO_NOT_SET\t\t\t\t 128\n#define SSL_R_BLOCK_CIPHER_PAD_IS_WRONG\t\t\t 129\n#define SSL_R_BN_LIB\t\t\t\t\t 130\n#define SSL_R_CA_DN_LENGTH_MISMATCH\t\t\t 131\n#define SSL_R_CA_DN_TOO_LONG\t\t\t\t 132\n#define SSL_R_CCS_RECEIVED_EARLY\t\t\t 133\n#define SSL_R_CERTIFICATE_VERIFY_FAILED\t\t\t 134\n#define SSL_R_CERT_LENGTH_MISMATCH\t\t\t 135\n#define SSL_R_CHALLENGE_IS_DIFFERENT\t\t\t 136\n#define SSL_R_CIPHER_CODE_WRONG_LENGTH\t\t\t 137\n#define SSL_R_CIPHER_OR_HASH_UNAVAILABLE\t\t 138\n#define SSL_R_CIPHER_TABLE_SRC_ERROR\t\t\t 139\n#define SSL_R_CLIENTHELLO_TLSEXT\t\t\t 226\n#define SSL_R_COMPRESSED_LENGTH_TOO_LONG\t\t 140\n#define SSL_R_COMPRESSION_DISABLED\t\t\t 343\n#define SSL_R_COMPRESSION_FAILURE\t\t\t 141\n#define SSL_R_COMPRESSION_ID_NOT_WITHIN_PRIVATE_RANGE\t 307\n#define SSL_R_COMPRESSION_LIBRARY_ERROR\t\t\t 142\n#define SSL_R_CONNECTION_ID_IS_DIFFERENT\t\t 143\n#define SSL_R_CONNECTION_TYPE_NOT_SET\t\t\t 144\n#define SSL_R_COOKIE_MISMATCH\t\t\t\t 308\n#define SSL_R_DATA_BETWEEN_CCS_AND_FINISHED\t\t 145\n#define SSL_R_DATA_LENGTH_TOO_LONG\t\t\t 146\n#define SSL_R_DECRYPTION_FAILED\t\t\t\t 147\n#define SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC\t 281\n#define SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG\t\t 148\n#define SSL_R_DIGEST_CHECK_FAILED\t\t\t 149\n#define SSL_R_DTLS_MESSAGE_TOO_BIG\t\t\t 334\n#define SSL_R_DUPLICATE_COMPRESSION_ID\t\t\t 309\n#define SSL_R_ECC_CERT_NOT_FOR_KEY_AGREEMENT\t\t 317\n#define SSL_R_ECC_CERT_NOT_FOR_SIGNING\t\t\t 318\n#define SSL_R_ECC_CERT_SHOULD_HAVE_RSA_SIGNATURE\t 322\n#define SSL_R_ECC_CERT_SHOULD_HAVE_SHA1_SIGNATURE\t 323\n#define SSL_R_ECGROUP_TOO_LARGE_FOR_CIPHER\t\t 310\n#define SSL_R_EMPTY_SRTP_PROTECTION_PROFILE_LIST\t 354\n#define SSL_R_ENCRYPTED_LENGTH_TOO_LONG\t\t\t 150\n#define SSL_R_ERROR_GENERATING_TMP_RSA_KEY\t\t 282\n#define SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST\t\t 151\n#define SSL_R_EXCESSIVE_MESSAGE_SIZE\t\t\t 152\n#define SSL_R_EXTRA_DATA_IN_MESSAGE\t\t\t 153\n#define SSL_R_GOT_A_FIN_BEFORE_A_CCS\t\t\t 154\n#define SSL_R_GOT_NEXT_PROTO_BEFORE_A_CCS\t\t 355\n#define SSL_R_GOT_NEXT_PROTO_WITHOUT_EXTENSION\t\t 356\n#define SSL_R_HTTPS_PROXY_REQUEST\t\t\t 155\n#define SSL_R_HTTP_REQUEST\t\t\t\t 156\n#define SSL_R_ILLEGAL_PADDING\t\t\t\t 283\n#define SSL_R_INCONSISTENT_COMPRESSION\t\t\t 340\n#define SSL_R_INVALID_CHALLENGE_LENGTH\t\t\t 158\n#define SSL_R_INVALID_COMMAND\t\t\t\t 280\n#define SSL_R_INVALID_COMPRESSION_ALGORITHM\t\t 341\n#define SSL_R_INVALID_PURPOSE\t\t\t\t 278\n#define SSL_R_INVALID_SRP_USERNAME\t\t\t 357\n#define SSL_R_INVALID_STATUS_RESPONSE\t\t\t 328\n#define SSL_R_INVALID_TICKET_KEYS_LENGTH\t\t 325\n#define SSL_R_INVALID_TRUST\t\t\t\t 279\n#define SSL_R_KEY_ARG_TOO_LONG\t\t\t\t 284\n#define SSL_R_KRB5\t\t\t\t\t 285\n#define SSL_R_KRB5_C_CC_PRINC\t\t\t\t 286\n#define SSL_R_KRB5_C_GET_CRED\t\t\t\t 287\n#define SSL_R_KRB5_C_INIT\t\t\t\t 288\n#define SSL_R_KRB5_C_MK_REQ\t\t\t\t 289\n#define SSL_R_KRB5_S_BAD_TICKET\t\t\t\t 290\n#define SSL_R_KRB5_S_INIT\t\t\t\t 291\n#define SSL_R_KRB5_S_RD_REQ\t\t\t\t 292\n#define SSL_R_KRB5_S_TKT_EXPIRED\t\t\t 293\n#define SSL_R_KRB5_S_TKT_NYV\t\t\t\t 294\n#define SSL_R_KRB5_S_TKT_SKEW\t\t\t\t 295\n#define SSL_R_LENGTH_MISMATCH\t\t\t\t 159\n#define SSL_R_LENGTH_TOO_SHORT\t\t\t\t 160\n#define SSL_R_LIBRARY_BUG\t\t\t\t 274\n#define SSL_R_LIBRARY_HAS_NO_CIPHERS\t\t\t 161\n#define SSL_R_MESSAGE_TOO_LONG\t\t\t\t 296\n#define SSL_R_MISSING_DH_DSA_CERT\t\t\t 162\n#define SSL_R_MISSING_DH_KEY\t\t\t\t 163\n#define SSL_R_MISSING_DH_RSA_CERT\t\t\t 164\n#define SSL_R_MISSING_DSA_SIGNING_CERT\t\t\t 165\n#define SSL_R_MISSING_EXPORT_TMP_DH_KEY\t\t\t 166\n#define SSL_R_MISSING_EXPORT_TMP_RSA_KEY\t\t 167\n#define SSL_R_MISSING_RSA_CERTIFICATE\t\t\t 168\n#define SSL_R_MISSING_RSA_ENCRYPTING_CERT\t\t 169\n#define SSL_R_MISSING_RSA_SIGNING_CERT\t\t\t 170\n```\n\n### ssl/ssl_err.c\n\n#### region() [lines 324-410]\n```c\n{ERR_REASON(SSL_R_BAD_RSA_E_LENGTH) ,\"bad rsa e length\"},\n{ERR_REASON(SSL_R_BAD_RSA_MODULUS_LENGTH),\"bad rsa modulus length\"},\n{ERR_REASON(SSL_R_BAD_RSA_SIGNATURE) ,\"bad rsa signature\"},\n{ERR_REASON(SSL_R_BAD_SIGNATURE) ,\"bad signature\"},\n{ERR_REASON(SSL_R_BAD_SRP_A_LENGTH) ,\"bad srp a length\"},\n{ERR_REASON(SSL_R_BAD_SRP_B_LENGTH) ,\"bad srp b length\"},\n{ERR_REASON(SSL_R_BAD_SRP_G_LENGTH) ,\"bad srp g length\"},\n{ERR_REASON(SSL_R_BAD_SRP_N_LENGTH) ,\"bad srp n length\"},\n{ERR_REASON(SSL_R_BAD_SRP_PARAMETERS) ,\"bad srp parameters\"},\n{ERR_REASON(SSL_R_BAD_SRP_S_LENGTH) ,\"bad srp s length\"},\n{ERR_REASON(SSL_R_BAD_SRTP_MKI_VALUE) ,\"bad srtp mki value\"},\n{ERR_REASON(SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST),\"bad srtp protection profile list\"},\n{ERR_REASON(SSL_R_BAD_SSL_FILETYPE) ,\"bad ssl filetype\"},\n{ERR_REASON(SSL_R_BAD_SSL_SESSION_ID_LENGTH),\"bad ssl session id length\"},\n{ERR_REASON(SSL_R_BAD_STATE) ,\"bad state\"},\n{ERR_REASON(SSL_R_BAD_WRITE_RETRY) ,\"bad write retry\"},\n{ERR_REASON(SSL_R_BIO_NOT_SET) ,\"bio not set\"},\n{ERR_REASON(SSL_R_BLOCK_CIPHER_PAD_IS_WRONG),\"block cipher pad is wrong\"},\n{ERR_REASON(SSL_R_BN_LIB) ,\"bn lib\"},\n{ERR_REASON(SSL_R_CA_DN_LENGTH_MISMATCH) ,\"ca dn length mismatch\"},\n{ERR_REASON(SSL_R_CA_DN_TOO_LONG) ,\"ca dn too long\"},\n{ERR_REASON(SSL_R_CCS_RECEIVED_EARLY) ,\"ccs received early\"},\n{ERR_REASON(SSL_R_CERTIFICATE_VERIFY_FAILED),\"certificate verify failed\"},\n{ERR_REASON(SSL_R_CERT_LENGTH_MISMATCH) ,\"cert length mismatch\"},\n{ERR_REASON(SSL_R_CHALLENGE_IS_DIFFERENT),\"challenge is different\"},\n{ERR_REASON(SSL_R_CIPHER_CODE_WRONG_LENGTH),\"cipher code wrong length\"},\n{ERR_REASON(SSL_R_CIPHER_OR_HASH_UNAVAILABLE),\"cipher or hash unavailable\"},\n{ERR_REASON(SSL_R_CIPHER_TABLE_SRC_ERROR),\"cipher table src error\"},\n{ERR_REASON(SSL_R_CLIENTHELLO_TLSEXT) ,\"clienthello tlsext\"},\n{ERR_REASON(SSL_R_COMPRESSED_LENGTH_TOO_LONG),\"compressed length too long\"},\n{ERR_REASON(SSL_R_COMPRESSION_DISABLED) ,\"compression disabled\"},\n{ERR_REASON(SSL_R_COMPRESSION_FAILURE) ,\"compression failure\"},\n{ERR_REASON(SSL_R_COMPRESSION_ID_NOT_WITHIN_PRIVATE_RANGE),\"compression id not within private range\"},\n{ERR_REASON(SSL_R_COMPRESSION_LIBRARY_ERROR),\"compression library error\"},\n{ERR_REASON(SSL_R_CONNECTION_ID_IS_DIFFERENT),\"connection id is different\"},\n{ERR_REASON(SSL_R_CONNECTION_TYPE_NOT_SET),\"connection type not set\"},\n{ERR_REASON(SSL_R_COOKIE_MISMATCH) ,\"cookie mismatch\"},\n{ERR_REASON(SSL_R_DATA_BETWEEN_CCS_AND_FINISHED),\"data between ccs and finished\"},\n{ERR_REASON(SSL_R_DATA_LENGTH_TOO_LONG) ,\"data length too long\"},\n{ERR_REASON(SSL_R_DECRYPTION_FAILED) ,\"decryption failed\"},\n{ERR_REASON(SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC),\"decryption failed or bad record mac\"},\n{ERR_REASON(SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG),\"dh public value length is wrong\"},\n{ERR_REASON(SSL_R_DIGEST_CHECK_FAILED) ,\"digest check failed\"},\n{ERR_REASON(SSL_R_DTLS_MESSAGE_TOO_BIG) ,\"dtls message too big\"},\n{ERR_REASON(SSL_R_DUPLICATE_COMPRESSION_ID),\"duplicate compression id\"},\n{ERR_REASON(SSL_R_ECC_CERT_NOT_FOR_KEY_AGREEMENT),\"ecc cert not for key agreement\"},\n{ERR_REASON(SSL_R_ECC_CERT_NOT_FOR_SIGNING),\"ecc cert not for signing\"},\n{ERR_REASON(SSL_R_ECC_CERT_SHOULD_HAVE_RSA_SIGNATURE),\"ecc cert should have rsa signature\"},\n{ERR_REASON(SSL_R_ECC_CERT_SHOULD_HAVE_SHA1_SIGNATURE),\"ecc cert should have sha1 signature\"},\n{ERR_REASON(SSL_R_ECGROUP_TOO_LARGE_FOR_CIPHER),\"ecgroup too large for cipher\"},\n{ERR_REASON(SSL_R_EMPTY_SRTP_PROTECTION_PROFILE_LIST),\"empty srtp protection profile list\"},\n{ERR_REASON(SSL_R_ENCRYPTED_LENGTH_TOO_LONG),\"encrypted length too long\"},\n{ERR_REASON(SSL_R_ERROR_GENERATING_TMP_RSA_KEY),\"error generating tmp rsa key\"},\n{ERR_REASON(SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST),\"error in received cipher list\"},\n{ERR_REASON(SSL_R_EXCESSIVE_MESSAGE_SIZE),\"excessive message size\"},\n{E\n/* ... truncated ... */\n```\n\n\n## Upstream Fix\n```diff\nFrom 63830384e90d9b36d2793d4891501ec024827433 Mon Sep 17 00:00:00 2001\nFrom: Emilia Kasper \nDate: Tue, 19 May 2015 12:05:22 +0200\nSubject: [PATCH] client: reject handshakes with DH parameters < 768 bits.\n\nSince the client has no way of communicating her supported parameter\nrange to the server, connections to servers that choose weak DH will\nsimply fail.\n\nReviewed-by: Kurt Roeckx \n---\n CHANGES | 3 ++-\n ssl/s3_clnt.c | 22 ++++++++++++++++------\n ssl/ssl.h | 1 +\n ssl/ssl_err.c | 1 +\n 4 files changed, 20 insertions(+), 7 deletions(-)\n\ndiff --git a/CHANGES b/CHANGES\nindex 11bdbbd6926de..9d2f9f9fa8bd2 100644\n--- a/CHANGES\n+++ b/CHANGES\n@@ -4,7 +4,8 @@\n \n Changes between 1.0.1m and 1.0.1n [xx XXX xxxx]\n \n- *)\n+ *) Reject DH handshakes with parameters shorter than 768 bits.\n+ [Kurt Roeckx and Emilia Kasper]\n \n Changes between 1.0.1l and 1.0.1m [19 Mar 2015]\n \ndiff --git a/ssl/s3_clnt.c b/ssl/s3_clnt.c\nindex a521d56fe4fdf..780a03f1e6e85 100644\n--- a/ssl/s3_clnt.c\n+++ b/ssl/s3_clnt.c\n@@ -3295,23 +3295,33 @@ int ssl3_check_cert_and_algorithm(SSL *s)\n }\n #endif\n #ifndef OPENSSL_NO_DH\n- if ((alg_k & SSL_kEDH) &&\n- !(has_bits(i, EVP_PK_DH | EVP_PKT_EXCH) || (dh != NULL))) {\n- SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM, SSL_R_MISSING_DH_KEY);\n+ if ((alg_k & SSL_kEDH) && dh == NULL) {\n+ SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM, ERR_R_INTERNAL_ERROR);\n goto f_err;\n- } else if ((alg_k & SSL_kDHr) && !has_bits(i, EVP_PK_DH | EVP_PKS_RSA)) {\n+ }\n+ if ((alg_k & SSL_kDHr) && !has_bits(i, EVP_PK_DH | EVP_PKS_RSA)) {\n SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,\n SSL_R_MISSING_DH_RSA_CERT);\n goto f_err;\n }\n # ifndef OPENSSL_NO_DSA\n- else if ((alg_k & SSL_kDHd) && !has_bits(i, EVP_PK_DH | EVP_PKS_DSA)) {\n+ if ((alg_k & SSL_kDHd) && !has_bits(i, EVP_PK_DH | EVP_PKS_DSA)) {\n SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,\n SSL_R_MISSING_DH_DSA_CERT);\n goto f_err;\n }\n # endif\n-#endif\n+\n+ /* Check DHE only: static DH not implemented. */\n+ if (alg_k & SSL_kEDH) {\n+ int dh_size = BN_num_bits(dh->p);\n+ if ((!SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) && dh_size < 768)\n+ || (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) && dh_size < 512)) {\n+ SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM, SSL_R_DH_KEY_TOO_SMALL);\n+ goto f_err;\n+ }\n+ }\n+#endif /* !OPENSSL_NO_DH */\n \n if (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) && !has_bits(i, EVP_PKT_EXP)) {\n #ifndef OPENSSL_NO_RSA\ndiff --git a/ssl/ssl.h b/ssl/ssl.h\nindex 62472a1e3c016..32e27c6fbf91b 100644\n--- a/ssl/ssl.h\n+++ b/ssl/ssl.h\n@@ -2524,6 +2524,7 @@ void ERR_load_SSL_strings(void);\n # define SSL_R_DATA_LENGTH_TOO_LONG 146\n # define SSL_R_DECRYPTION_FAILED 147\n # define SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC 281\n+# define SSL_R_DH_KEY_TOO_SMALL 372\n # define SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG 148\n # define SSL_R_DIGEST_CHECK_FAILED 149\n # define SSL_R_DTLS_MESSAGE_TOO_BIG 334\ndiff --git a/ssl/ssl_err.c b/ssl/ssl_err.c\nindex 835b43ce67cbd..fef324d46295b 100644\n--- a/ssl/ssl_err.c\n+++ b/ssl/ssl_err.c\n@@ -441,6 +441,7 @@ static ERR_STRING_DATA SSL_str_reasons[] = {\n {ERR_REASON(SSL_R_DECRYPTION_FAILED), \"decryption failed\"},\n {ERR_REASON(SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC),\n \"decryption failed or bad record mac\"},\n+ {ERR_REASON(SSL_R_DH_KEY_TOO_SMALL), \"dh key too small\"},\n {ERR_REASON(SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG),\n \"dh public value length is wrong\"},\n {ERR_REASON(SSL_R_DIGEST_CHECK_FAILED), \"digest check failed\"},\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From 63830384e90d9b36d2793d4891501ec024827433 Mon Sep 17 00:00:00 2001\nFrom: Emilia Kasper \nDate: Tue, 19 May 2015 12:05:22 +0200\nSubject: [PATCH 5/5] client: reject handshakes with DH parameters < 1024 bits.\n\nSince the client has no way of communicating her supported parameter\nrange to the server, connections to servers that choose weak DH will\nsimply fail.\n\nReviewed-by: Kurt Roeckx \n---\n CHANGES | 3 ++-\n ssl/s3_clnt.c | 22 ++++++++++++++++------\n ssl/ssl.h | 1 +\n ssl/ssl_err.c | 1 +\n 4 files changed, 20 insertions(+), 7 deletions(-)\n\nIndex: openssl-1.0.1i/CHANGES\n===================================================================\n--- openssl-1.0.1i.orig/CHANGES\t2015-06-12 13:25:24.308393444 +0200\n+++ openssl-1.0.1i/CHANGES\t2015-06-12 13:25:50.681740239 +0200\n@@ -2,6 +2,9 @@\n OpenSSL CHANGES\n _______________\n \n+ *) Reject DH handshakes with parameters shorter than 1024 bits.\n+ [Kurt Roeckx and Emilia Kasper]\n+\n Changes between 1.0.1h and 1.0.1i [6 Aug 2014]\n *) Add support for TLS_FALLBACK_SCSV.\n Client applications doing fallback retries should call\nIndex: openssl-1.0.1i/ssl/s3_clnt.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s3_clnt.c\t2015-06-12 13:25:24.309393457 +0200\n+++ openssl-1.0.1i/ssl/s3_clnt.c\t2015-06-12 13:29:40.896761553 +0200\n@@ -3322,26 +3322,34 @@ int ssl3_check_cert_and_algorithm(SSL *s\n \t\t}\n #endif\n #ifndef OPENSSL_NO_DH\n-\tif ((alg_k & SSL_kEDH) &&\n-\t\t!(has_bits(i,EVP_PK_DH|EVP_PKT_EXCH) || (dh != NULL)))\n-\t\t{\n-\t\tSSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_KEY);\n+ if ((alg_k & SSL_kEDH) && dh == NULL) {\n+ SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM, ERR_R_INTERNAL_ERROR);\n \t\tgoto f_err;\n-\t\t}\n-\telse if ((alg_k & SSL_kDHr) && !has_bits(i,EVP_PK_DH|EVP_PKS_RSA))\n+ }\n+ if ((alg_k & SSL_kDHr) && !has_bits(i, EVP_PK_DH | EVP_PKS_RSA))\n \t\t{\n \t\tSSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_RSA_CERT);\n \t\tgoto f_err;\n \t\t}\n #ifndef OPENSSL_NO_DSA\n-\telse if ((alg_k & SSL_kDHd) && !has_bits(i,EVP_PK_DH|EVP_PKS_DSA))\n+ if ((alg_k & SSL_kDHd) && !has_bits(i, EVP_PK_DH | EVP_PKS_DSA))\n \t\t{\n \t\tSSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_DSA_CERT);\n \t\tgoto f_err;\n \t\t}\n #endif\n-#endif\n \n+ /* Check DHE only: static DH not implemented. */\n+ if (alg_k & SSL_kEDH) {\n+ int dh_size = BN_num_bits(dh->p);\n+ if ((!SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) && dh_size < 1024)\n+ || (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) && dh_size < 512)) {\n+ SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM, SSL_R_DH_KEY_TOO_SMALL);\n+ goto f_err;\n+ }\n+ }\n+#endif /* !OPENSSL_NO_DH */\n+ \n \tif (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) && !has_bits(i,EVP_PKT_EXP))\n \t\t{\n #ifndef OPENSSL_NO_RSA\nIndex: openssl-1.0.1i/ssl/ssl.h\n===================================================================\n--- openssl-1.0.1i.orig/ssl/ssl.h\t2015-06-12 13:25:24.310393470 +0200\n+++ openssl-1.0.1i/ssl/ssl.h\t2015-06-12 13:30:24.446331928 +0200\n@@ -2369,6 +2369,7 @@ void ERR_load_SSL_strings(void);\n #define SSL_R_DATA_LENGTH_TOO_LONG\t\t\t 146\n #define SSL_R_DECRYPTION_FAILED\t\t\t\t 147\n #define SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC\t 281\n+#define SSL_R_DH_KEY_TOO_SMALL 372\n #define SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG\t\t 148\n #define SSL_R_DIGEST_CHECK_FAILED\t\t\t 149\n #define SSL_R_DTLS_MESSAGE_TOO_BIG\t\t\t 334\nIndex: openssl-1.0.1i/ssl/ssl_err.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/ssl_err.c\t2015-06-12 13:25:24.311393483 +0200\n+++ openssl-1.0.1i/ssl/ssl_err.c\t2015-06-12 13:30:48.525647135 +0200\n@@ -363,6 +363,7 @@ static ERR_STRING_DATA SSL_str_reasons[]\n {ERR_REASON(SSL_R_DATA_LENGTH_TOO_LONG) ,\"data length too long\"},\n {ERR_REASON(SSL_R_DECRYPTION_FAILED) ,\"decryption failed\"},\n {ERR_REASON(SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC),\"decryption failed or bad record mac\"},\n+{ERR_REASON(SSL_R_DH_KEY_TOO_SMALL), \"dh key too small\"},\n {ERR_REASON(SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG),\"dh public value length is wrong\"},\n {ERR_REASON(SSL_R_DIGEST_CHECK_FAILED) ,\"digest check failed\"},\n {ERR_REASON(SSL_R_DTLS_MESSAGE_TOO_BIG) ,\"dtls message too big\"},"}], "metadata": {"id": "openssl-4769-0005-client-reject-handshakes-", "cve_id": "CVE-2015-3197", "package": "openssl", "upstream_enriched": true, "upstream_commit": "63830384e90d9b36d2793d4891501ec024827433", "upstream_repo": "openssl/openssl", "tier": "adapted", "has_source_context": true, "context_tokens_est": 2525, "context_files": 4, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2013-4560\n\nUse-after-free vulnerability in lighttpd before 1.4.33 allows remote attackers to cause a denial of service (segmentation fault and crash) via unspecified vectors that trigger FAMMonitorDirectory failures.\n\n## Package\nlighttpd\n\n## Files to modify\n- src/mod_geoip.c\n\n## Upstream Fix\n```diff\nIndex: src/Makefile.am\n===================================================================\n--- src/Makefile.am.orig\n+++ src/Makefile.am\n@@ -234,6 +234,10 @@ mod_accesslog_la_SOURCES = mod_accesslog\n mod_accesslog_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined\n mod_accesslog_la_LIBADD = $(common_libadd)\n \n+lib_LTLIBRARIES += mod_geoip.la\n+mod_geoip_la_SOURCES = mod_geoip.c\n+mod_geoip_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined\n+mod_geoip_la_LIBADD = $(common_libadd) -lGeoIP\n \n hdr = server.h buffer.h network.h log.h keyvalue.h \\\n response.h request.h fastcgi.h chunk.h \\\nIndex: src/mod_geoip.c\n===================================================================\n--- /dev/null\n+++ src/mod_geoip.c\n@@ -0,0 +1,417 @@\n+#include \n+#include \n+\n+#include \n+#include \n+#include \n+\n+#include \"base.h\"\n+#include \"log.h\"\n+#include \"buffer.h\"\n+\n+#include \"plugin.h\"\n+#include \"inet_ntop_cache.h\"\n+\n+#ifdef HAVE_CONFIG_H\n+#include \"config.h\"\n+#endif\n+\n+/**\n+ *\n+ * $mod_geoip.c (v2.0) (13.09.2006 00:29:11)\n+ *\n+ * Name:\n+ * \tmod_geoip.c\n+ *\n+ * Description:\n+ * \tGeoIP module (plugin) for lighttpd.\n+ *\tthe module loads a geoip database of type \"country\" or \"city\" and\n+ *\tsets new ENV vars based on ip record lookups.\n+ *\n+ *\tcountry db env's:\n+ *\t\tGEOIP_COUNTRY_CODE\n+ *\t\tGEOIP_COUNTRY_CODE3\n+ *\t\tGEOIP_COUNTRY_NAME\n+ *\n+ *\tcity db env's:\n+ *\t\tGEOIP_COUNTRY_CODE\n+ *\t\tGEOIP_COUNTRY_CODE3\n+ *\t\tGEOIP_COUNTRY_NAME\n+ *\t\tGEOIP_CITY_NAME\n+ *\t\tGEOIP_CITY_POSTAL_CODE\n+ *\t\tGEOIP_CITY_LATITUDE\n+ *\t\tGEOIP_CITY_LONG_LATITUDE\n+ *\t\tGEOIP_CITY_DMA_CODE\n+ *\t\tGEOIP_CITY_AREA_CODE\n+ *\n+ * Usage (configuration options):\n+ *\tgeoip.db-filename = \n+ *\tgeoip.memory-cache = : default disabled\n+ *\t\tif enabled, mod_geoip will load the database binary file to\n+ *\t\tmemory for very fast lookups. the only penalty is memory usage.\n+ *\n+ * Author:\n+ * \tAmi E. Bizamcher (amix)\n+ *\tduke.amix@gmail.com\n+ *\n+ * Note:\n+ * \tGeoIP Library and API must be installed!\n+ */\n+\n+\n+/* plugin config for all request/connections */\n+\n+typedef struct {\n+\tunsigned short mem_cache;\n+\tbuffer\t*db_name;\n+\tGeoIP *gi;\n+} plugin_config;\n+\n+typedef struct {\n+\tPLUGIN_DATA;\n+\n+\tplugin_config **config_storage;\n+\n+\tplugin_config conf;\n+} plugin_data;\n+\n+/* init the plugin data */\n+INIT_FUNC(mod_geoip_init) {\n+\tplugin_data *p;\n+\n+\tp = calloc(1, sizeof(*p));\n+\n+\treturn p;\n+}\n+\n+/* detroy the plugin data */\n+FREE_FUNC(mod_geoip_free) {\n+\tplugin_data *p = p_d;\n+\n+\tUNUSED(srv);\n+\n+\tif (!p) return HANDLER_GO_ON;\n+\n+\tif (p->config_storage) {\n+\t\tsize_t i;\n+\n+\t\tfor (i = 0; i < srv->config_context->used; i++) {\n+\t\t\tplugin_config *s = p->config_storage[i];\n+\n+\t\t\tif (!s) continue;\n+\n+\t\t\tbuffer_free(s->db_name);\n+\n+\t\t\t/* clean up */\n+\t\t\tGeoIP_delete(s->gi);\n+\n+\t\t\tfree(s);\n+\t\t}\n+\t\tfree(p->config_storage);\n+\t}\n+\n+\tfree(p);\n+\n+\treturn HANDLER_GO_ON;\n+}\n+\n+/* handle plugin config and check values */\n+\n+SETDEFAULTS_FUNC(mod_geoip_set_defaults) {\n+\tplugin_data *p = p_d;\n+\tsize_t i = 0;\n+\n+\tconfig_values_t cv[] = {\n+\t\t{ \"geoip.db-filename\",\tNULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },\t/* 0 */\n+\t\t{ \"geoip.memory-cache\",\tNULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 1 */\n+\t\t{ NULL,\t\t\tNULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }\n+\t};\n+\n+\tif (!p) return HANDLER_ERROR;\n+\n+\tp->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *));\n+\n+\tfor (i = 0; i < srv->config_context->used; i++) {\n+\t\tplugin_config *s;\n+\t\tint mode;\n+\n+\t\ts = calloc(1, sizeof(plugin_config));\n+\n+\t\ts->db_name = buffer_init();\n+\t\ts->mem_cache = 0; /* default: do not load db to cache */\n+\t\ts->gi = NULL;\n+\n+\t\tcv[0].destination = s->db_name;\n+\t\tcv[1].destination = &(s->mem_cache);\n+\n+\t\tp->config_storage[i] = s;\n+\n+\t\tif (0 != config_insert_values_global(srv, ((data_config *)srv->config_context->data[i])->value, cv)) {\n+\t\t\treturn HANDLER_ERROR;\n+\t\t}\n+\n+\t\tmode = GEOIP_STANDARD | GEOIP_CHECK_CACHE;\n+\n+\t\t/* country db filename is requeried! */\n+\t\tif (!buffer_is_empty(s->db_name)) {\n+\n+\t\t\t/* let's start cooking */\n+\t\t\tif (s->mem_cache != 0)\n+\t\t\t\tmode = GEOIP_MEMORY_CACHE | GEOIP_CHECK_CACHE;\n+\n+\t\t\tif (NULL == (s->gi = GeoIP_open(s->db_name->ptr, mode))) {\n+\t\t\t\tlog_error_write(srv, __FILE__, __LINE__, \"s\",\n+\t\t\t\t\t\"failed to open GeoIP database!!!\");\n+\n+\t\t\t\treturn HANDLER_ERROR;\n+\t\t\t}\n+\n+\t\t\t/* is the db supported ? */\n+\t\t\tif (s->gi->databaseType != GEOIP_COUNTRY_EDITION &&\n+\t\t\t\ts->gi->databaseType != GEOIP_CITY_EDITION_REV0 &&\n+\t\t\t\ts->gi->databaseType != GEOIP_CITY_EDITION_REV1) {\n+\t\t\t\tlog_error_write(srv, __FILE__, __LINE__, \"s\",\n+\t\t\t\t\t\"GeoIP database is of unsupported type!!!\");\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\treturn HANDLER_GO_ON;\n+}\n+\n+#define PATCH(x) \\\n+\tp->conf.x = s->x;\n+static int mod_geoip_patch_connection(server *srv, connection *con, plugin_data *p) {\n+\tsize_t i, j;\n+\tplugin_config *s = p->config_storage[0];\n+\n+\tPATCH(db_name);\n+\tPATCH(mem_cache);\n+ PATCH(gi);\n+\n+\t/* skip the first, the global context */\n+\tfor (i = 1; i < srv->config_context->used; i++) {\n+\t\tdata_config *dc = (data_config *)srv->config_context->data[i];\n+\t\ts = p->config_storage[i];\n+\n+\t\t/* condition didn't match */\n+\t\tif (!config_check_cond(srv, con, dc)) continue;\n+\n+\t\t/* merge config */\n+\t\tfor (j = 0; j < dc->value->used; j++) {\n+\t\t\tdata_unset *du = dc->value->data[j];\n+\n+\t\t\tif (buffer_is_equal_string(du->key, CONST_STR_LEN(\"geoip.db-filename\"))) {\n+\t\t\t\tPATCH(db_name);\n+\t\t\t}\n+\n+\t\t\tif (buffer_is_equal_string(du->key, CONST_STR_LEN(\"geoip.memory-cache\"))) {\n+ PATCH(mem_cache);\n+ }\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+}\n+#undef PATCH\n+\n+URIHANDLER_FUNC(mod_geoip_subrequest) {\n+ plugin_data *p = p_d;\n+\n+ mod_geoip_patch_connection(srv, con, p);\n+\n+ if (!buffer_is_empty(p->conf.db_name)) {\n+\t\tconst char *remote_ip;\n+\t\tGeoIP *gi;\n+\t\tdata_string *ds;\n+\t\tconst char *returnedCountry;\n+\n+\t\tremote_ip = inet_ntop_cache_get_ip(srv, &(con->dst_addr));\n+\n+\t\tif (p->conf.gi->databaseType == GEOIP_COUNTRY_EDITION) {\n+\t\t\t/* get the country code 2 chars */\n+\t\t\tif (NULL == (ds = (data_string *)array_get_element(con->environment, \"GEOIP_COUNTRY_CODE\"))) {\n+\t\t\t\tif (NULL != (returnedCountry = GeoIP_country_code_by_addr(p->conf.gi, remote_ip))) {\n+\t \t \tif (NULL == (ds = (data_string *)array_get_unused_element(con->environment, TYPE_STRING))) {\n+ \t \t \tds = data_string_init();\n+\t \t \t}\n+\n+\t\t\t\t\tbuffer_copy_string(ds->key, \"GEOIP_COUNTRY_CODE\");\n+\t\t\t\t\tbuffer_copy_string(ds->value, returnedCountry);\n+\t\t\t\t\tarray_insert_unique(con->environment, (data_unset *)ds);\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\t/* get the country code 3 chars */\n+\t\t\tif (NULL == (ds = (data_string *)array_get_element(con->environment, \"GEOIP_COUNTRY_CODE3\"))) {\n+\t\t\t\tif (NULL != (returnedCountry = GeoIP_country_code3_by_addr(p->conf.gi, remote_ip))) {\n+\t\t\t\t\tif (NULL == (ds = (data_string *)array_get_unused_element(con->environment, TYPE_STRING))) {\n+\t\t\t\t\t\tds = data_string_init();\n+\t\t\t\t\t}\n+\n+\t\t\t\t\tbuffer_copy_string(ds->key, \"GEOIP_COUNTRY_CODE3\");\n+\t\t\t\t\tbuffer_copy_string(ds->value, returnedCountry);\n+\t\t\t\t\tarray_insert_unique(con->environment, (data_unset *)ds);\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\t/* get the country name */\n+\t\t\tif (NULL == (ds = (data_string *)array_get_element(con->environment, \"GEOIP_COUNTRY_NAME\"))) {\n+\t\t\t\tif (NULL != (returnedCountry = GeoIP_country_name_by_addr(p->conf.gi, remote_ip))) {\n+\t\t\t\t\tif (NULL == (ds = (data_string *)array_get_unused_element(con->environment, TYPE_STRING))) {\n+\t\t\t\t\t\tds = data_string_init();\n+\t\t\t\t\t}\n+\n+\t\t\t\t\tbuffer_copy_string(ds->key, \"GEOIP_COUNTRY_NAME\");\n+\t\t\t\t\tbuffer_copy_string(ds->value, returnedCountry);\n+\t\t\t\t\tarray_insert_unique(con->environment, (data_unset *)ds);\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\t/* go on... */\n+\t\t\treturn HANDLER_GO_ON;\n+\t\t}\n+\n+\t\t/* if we are here, geo city is in use */\n+\t\tGeoIPRecord * gir;\n+\n+\t\tif (NULL != (gir = GeoIP_record_by_addr(p->conf.gi, remote_ip))) {\n+\t\t\t/\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "Index: src/Makefile.am\n===================================================================\n--- src/Makefile.am.orig\n+++ src/Makefile.am\n@@ -234,6 +234,10 @@ mod_accesslog_la_SOURCES = mod_accesslog\n mod_accesslog_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined\n mod_accesslog_la_LIBADD = $(common_libadd)\n \n+lib_LTLIBRARIES += mod_geoip.la\n+mod_geoip_la_SOURCES = mod_geoip.c\n+mod_geoip_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined\n+mod_geoip_la_LIBADD = $(common_libadd) -lGeoIP\n \n hdr = server.h buffer.h network.h log.h keyvalue.h \\\n response.h request.h fastcgi.h chunk.h \\\nIndex: src/mod_geoip.c\n===================================================================\n--- /dev/null\n+++ src/mod_geoip.c\n@@ -0,0 +1,417 @@\n+#include \n+#include \n+\n+#include \n+#include \n+#include \n+\n+#include \"base.h\"\n+#include \"log.h\"\n+#include \"buffer.h\"\n+\n+#include \"plugin.h\"\n+#include \"inet_ntop_cache.h\"\n+\n+#ifdef HAVE_CONFIG_H\n+#include \"config.h\"\n+#endif\n+\n+/**\n+ *\n+ * $mod_geoip.c (v2.0) (13.09.2006 00:29:11)\n+ *\n+ * Name:\n+ * \tmod_geoip.c\n+ *\n+ * Description:\n+ * \tGeoIP module (plugin) for lighttpd.\n+ *\tthe module loads a geoip database of type \"country\" or \"city\" and\n+ *\tsets new ENV vars based on ip record lookups.\n+ *\n+ *\tcountry db env's:\n+ *\t\tGEOIP_COUNTRY_CODE\n+ *\t\tGEOIP_COUNTRY_CODE3\n+ *\t\tGEOIP_COUNTRY_NAME\n+ *\n+ *\tcity db env's:\n+ *\t\tGEOIP_COUNTRY_CODE\n+ *\t\tGEOIP_COUNTRY_CODE3\n+ *\t\tGEOIP_COUNTRY_NAME\n+ *\t\tGEOIP_CITY_NAME\n+ *\t\tGEOIP_CITY_POSTAL_CODE\n+ *\t\tGEOIP_CITY_LATITUDE\n+ *\t\tGEOIP_CITY_LONG_LATITUDE\n+ *\t\tGEOIP_CITY_DMA_CODE\n+ *\t\tGEOIP_CITY_AREA_CODE\n+ *\n+ * Usage (configuration options):\n+ *\tgeoip.db-filename = \n+ *\tgeoip.memory-cache = : default disabled\n+ *\t\tif enabled, mod_geoip will load the database binary file to\n+ *\t\tmemory for very fast lookups. the only penalty is memory usage.\n+ *\n+ * Author:\n+ * \tAmi E. Bizamcher (amix)\n+ *\tduke.amix@gmail.com\n+ *\n+ * Note:\n+ * \tGeoIP Library and API must be installed!\n+ */\n+\n+\n+/* plugin config for all request/connections */\n+\n+typedef struct {\n+\tunsigned short mem_cache;\n+\tbuffer\t*db_name;\n+\tGeoIP *gi;\n+} plugin_config;\n+\n+typedef struct {\n+\tPLUGIN_DATA;\n+\n+\tplugin_config **config_storage;\n+\n+\tplugin_config conf;\n+} plugin_data;\n+\n+/* init the plugin data */\n+INIT_FUNC(mod_geoip_init) {\n+\tplugin_data *p;\n+\n+\tp = calloc(1, sizeof(*p));\n+\n+\treturn p;\n+}\n+\n+/* detroy the plugin data */\n+FREE_FUNC(mod_geoip_free) {\n+\tplugin_data *p = p_d;\n+\n+\tUNUSED(srv);\n+\n+\tif (!p) return HANDLER_GO_ON;\n+\n+\tif (p->config_storage) {\n+\t\tsize_t i;\n+\n+\t\tfor (i = 0; i < srv->config_context->used; i++) {\n+\t\t\tplugin_config *s = p->config_storage[i];\n+\n+\t\t\tif (!s) continue;\n+\n+\t\t\tbuffer_free(s->db_name);\n+\n+\t\t\t/* clean up */\n+\t\t\tGeoIP_delete(s->gi);\n+\n+\t\t\tfree(s);\n+\t\t}\n+\t\tfree(p->config_storage);\n+\t}\n+\n+\tfree(p);\n+\n+\treturn HANDLER_GO_ON;\n+}\n+\n+/* handle plugin config and check values */\n+\n+SETDEFAULTS_FUNC(mod_geoip_set_defaults) {\n+\tplugin_data *p = p_d;\n+\tsize_t i = 0;\n+\n+\tconfig_values_t cv[] = {\n+\t\t{ \"geoip.db-filename\",\tNULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },\t/* 0 */\n+\t\t{ \"geoip.memory-cache\",\tNULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 1 */\n+\t\t{ NULL,\t\t\tNULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }\n+\t};\n+\n+\tif (!p) return HANDLER_ERROR;\n+\n+\tp->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *));\n+\n+\tfor (i = 0; i < srv->config_context->used; i++) {\n+\t\tplugin_config *s;\n+\t\tint mode;\n+\n+\t\ts = calloc(1, sizeof(plugin_config));\n+\n+\t\ts->db_name = buffer_init();\n+\t\ts->mem_cache = 0; /* default: do not load db to cache */\n+\t\ts->gi = NULL;\n+\n+\t\tcv[0].destination = s->db_name;\n+\t\tcv[1].destination = &(s->mem_cache);\n+\n+\t\tp->config_storage[i] = s;\n+\n+\t\tif (0 != config_insert_values_global(srv, ((data_config *)srv->config_context->data[i])->value, cv)) {\n+\t\t\treturn HANDLER_ERROR;\n+\t\t}\n+\n+\t\tmode = GEOIP_STANDARD | GEOIP_CHECK_CACHE;\n+\n+\t\t/* country db filename is requeried! */\n+\t\tif (!buffer_is_empty(s->db_name)) {\n+\n+\t\t\t/* let's start cooking */\n+\t\t\tif (s->mem_cache != 0)\n+\t\t\t\tmode = GEOIP_MEMORY_CACHE | GEOIP_CHECK_CACHE;\n+\n+\t\t\tif (NULL == (s->gi = GeoIP_open(s->db_name->ptr, mode))) {\n+\t\t\t\tlog_error_write(srv, __FILE__, __LINE__, \"s\",\n+\t\t\t\t\t\"failed to open GeoIP database!!!\");\n+\n+\t\t\t\treturn HANDLER_ERROR;\n+\t\t\t}\n+\n+\t\t\t/* is the db supported ? */\n+\t\t\tif (s->gi->databaseType != GEOIP_COUNTRY_EDITION &&\n+\t\t\t\ts->gi->databaseType != GEOIP_CITY_EDITION_REV0 &&\n+\t\t\t\ts->gi->databaseType != GEOIP_CITY_EDITION_REV1) {\n+\t\t\t\tlog_error_write(srv, __FILE__, __LINE__, \"s\",\n+\t\t\t\t\t\"GeoIP database is of unsupported type!!!\");\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\treturn HANDLER_GO_ON;\n+}\n+\n+#define PATCH(x) \\\n+\tp->conf.x = s->x;\n+static int mod_geoip_patch_connection(server *srv, connection *con, plugin_data *p) {\n+\tsize_t i, j;\n+\tplugin_config *s = p->config_storage[0];\n+\n+\tPATCH(db_name);\n+\tPATCH(mem_cache);\n+ PATCH(gi);\n+\n+\t/* skip the first, the global context */\n+\tfor (i = 1; i < srv->config_context->used; i++) {\n+\t\tdata_config *dc = (data_config *)srv->config_context->data[i];\n+\t\ts = p->config_storage[i];\n+\n+\t\t/* condition didn't match */\n+\t\tif (!config_check_cond(srv, con, dc)) continue;\n+\n+\t\t/* merge config */\n+\t\tfor (j = 0; j < dc->value->used; j++) {\n+\t\t\tdata_unset *du = dc->value->data[j];\n+\n+\t\t\tif (buffer_is_equal_string(du->key, CONST_STR_LEN(\"geoip.db-filename\"))) {\n+\t\t\t\tPATCH(db_name);\n+\t\t\t}\n+\n+\t\t\tif (buffer_is_equal_string(du->key, CONST_STR_LEN(\"geoip.memory-cache\"))) {\n+ PATCH(mem_cache);\n+ }\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+}\n+#undef PATCH\n+\n+URIHANDLER_FUNC(mod_geoip_subrequest) {\n+ plugin_data *p = p_d;\n+\n+ mod_geoip_patch_connection(srv, con, p);\n+\n+ if (!buffer_is_empty(p->conf.db_name)) {\n+\t\tconst char *remote_ip;\n+\t\tGeoIP *gi;\n+\t\tdata_string *ds;\n+\t\tconst char *returnedCountry;\n+\n+\t\tremote_ip = inet_ntop_cache_get_ip(srv, &(con->dst_addr));\n+\n+\t\tif (p->conf.gi->databaseType == GEOIP_COUNTRY_EDITION) {\n+\t\t\t/* get the country code 2 chars */\n+\t\t\tif (NULL == (ds = (data_string *)array_get_element(con->environment, \"GEOIP_COUNTRY_CODE\"))) {\n+\t\t\t\tif (NULL != (returnedCountry = GeoIP_country_code_by_addr(p->conf.gi, remote_ip))) {\n+\t \t \tif (NULL == (ds = (data_string *)array_get_unused_element(con->environment, TYPE_STRING))) {\n+ \t \t \tds = data_string_init();\n+\t \t \t}\n+\n+\t\t\t\t\tbuffer_copy_string(ds->key, \"GEOIP_COUNTRY_CODE\");\n+\t\t\t\t\tbuffer_copy_string(ds->value, returnedCountry);\n+\t\t\t\t\tarray_insert_unique(con->environment, (data_unset *)ds);\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\t/* get the country code 3 chars */\n+\t\t\tif (NULL == (ds = (data_string *)array_get_element(con->environment, \"GEOIP_COUNTRY_CODE3\"))) {\n+\t\t\t\tif (NULL != (returnedCountry = GeoIP_country_code3_by_addr(p->conf.gi, remote_ip))) {\n+\t\t\t\t\tif (NULL == (ds = (data_string *)array_get_unused_element(con->environment, TYPE_STRING))) {\n+\t\t\t\t\t\tds = data_string_init();\n+\t\t\t\t\t}\n+\n+\t\t\t\t\tbuffer_copy_string(ds->key, \"GEOIP_COUNTRY_CODE3\");\n+\t\t\t\t\tbuffer_copy_string(ds->value, returnedCountry);\n+\t\t\t\t\tarray_insert_unique(con->environment, (data_unset *)ds);\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\t/* get the country name */\n+\t\t\tif (NULL == (ds = (data_string *)array_get_element(con->environment, \"GEOIP_COUNTRY_NAME\"))) {\n+\t\t\t\tif (NULL != (returnedCountry = GeoIP_country_name_by_addr(p->conf.gi, remote_ip))) {\n+\t\t\t\t\tif (NULL == (ds = (data_string *)array_get_unused_element(con->environment, TYPE_STRING))) {\n+\t\t\t\t\t\tds = data_string_init();\n+\t\t\t\t\t}\n+\n+\t\t\t\t\tbuffer_copy_string(ds->key, \"GEOIP_COUNTRY_NAME\");\n+\t\t\t\t\tbuffer_copy_string(ds->value, returnedCountry);\n+\t\t\t\t\tarray_insert_unique(con->environment, (data_unset *)ds);\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\t/* go on... */\n+\t\t\treturn HANDLER_GO_ON;\n+\t\t}\n+\n+\t\t/* if we are here, geo city is in use */\n+\t\tGeoIPRecord * gir;\n+\n+\t\tif (NULL != (gir = GeoIP_record_by_addr(p->conf.gi, remote_ip))) {\n+\t\t\t/* get the country code 2 chars */\n+ if (NULL == (ds = (data_string *)array_get_element(con->environment, \"GEOIP_COUNTRY_CODE\"))) {\n+ if (NULL == (ds = (data_string *)array_get_unused_element(con->environment, TYPE_STRING))) {\n+ ds = data_string_init();\n+ }\n+\n+ buffer_copy_string(ds->key, \"GEOIP_COUNTRY_CODE\");\n+ buffer_copy_string(ds->value, gir->country_code);\n+ array_insert_unique(con->environment, (data_unset *)ds);\n+ }\n+\n+\t\t\t/* get the country code 3 chars */\n+\t\t\tif (NULL == (ds = (data_string *)array_get_element(con->environment, \"GEOIP_COUNTRY_CODE3\"))) {\n+\t\t\t\tif (NULL == (ds = (data_string *)array_get_unused_element(con->environment, TYPE_STRING))) {\n+\t\t\t\t\tds = data_string_init();\n+\t\t\t\t}\n+\n+\t\t\t\tbuffer_copy_string(ds->key, \"GEOIP_COUNTRY_CODE3\");\n+\t\t\t\tbuffer_copy_string(ds->value, gir->country_code3);\n+\t\t\t\tarray_insert_unique(con->environment, (data_unset *)ds);\n+\t\t\t}\n+\n+\t\t\t/* get the country name */\n+\t\t\tif (NULL == (ds = (data_string *)array_get_element(con->environment, \"GEOIP_COUNTRY_NAME\"))) {\n+\t\t\t\tif (NULL == (ds = (data_string *)array_get_unused_element(con->environment, TYPE_STRING))) {\n+\t\t\t\t\tds = data_string_init();\n+\t\t\t\t}\n+\n+\t\t\t\tbuffer_copy_string(ds->key, \"GEOIP_COUNTRY_NAME\");\n+\t\t\t\tbuffer_copy_string(ds->value, gir->country_name);\n+\t\t\t\tarray_insert_unique(con->environment, (data_unset *)ds);\n+\t\t\t}\n+\n+\t\t\t/* get the city region */\n+ if (NULL == (ds = (data_string *)array_get_element(con->environment, \"GEOIP_CITY_REGION\"))) {\n+ if (NULL == (ds = (data_string *)array_get_unused_element(con->environment, TYPE_STRING))) {\n+ ds = data_string_init();\n+ }\n+\n+ buffer_copy_string(ds->key, \"GEOIP_CITY_REGION\");\n+ buffer_copy_string(ds->value, gir->region);\n+ array_insert_unique(con->environment, (data_unset *)ds);\n+ }\n+\n+ /* get the city */\n+ if (NULL == (ds = (data_string *)array_get_element(con->environment, \"GEOIP_CITY_NAME\"))) {\n+ if (NULL == (ds = (data_string *)array_get_unused_element(con->environment, TYPE_STRING))) {\n+ ds = data_string_init();\n+ }\n+\n+ buffer_copy_string(ds->key, \"GEOIP_CITY_NAME\");\n+ buffer_copy_string(ds->value, gir->city);\n+ array_insert_unique(con->environment, (data_unset *)ds);\n+ }\n+\n+ /* get the postal code */\n+ if (NULL == (ds = (data_string *)array_get_element(con->environment, \"GEOIP_CITY_POSTAL_CODE\"))) {\n+ if (NULL == (ds = (data_string *)array_get_unused_element(con->environment, TYPE_STRING))) {\n+ ds = data_string_init();\n+ }\n+\n+ buffer_copy_string(ds->key, \"GEOIP_CITY_POSTAL_CODE\");\n+ buffer_copy_string(ds->value, gir->postal_code);\n+ array_insert_unique(con->environment, (data_unset *)ds);\n+ }\n+\n+\t\t\t/* get the latitude */\n+\t\t\tif (NULL == (ds = (data_string *)array_get_element(con->environment, \"GEOIP_CITY_LATITUDE\"))) {\n+\t\t\t\tif (NULL == (ds = (data_string *)array_get_unused_element(con->environment, TYPE_STRING))) {\n+\t\t\t\t\tds = data_string_init();\n+\t\t\t\t}\n+\n+\t\t\t\tchar latitude[32];\n+\t\t\t\tsprintf(&latitude, \"%f\", gir->latitude);\n+\t\t\t\tbuffer_copy_string(ds->key, \"GEOIP_CITY_LATITUDE\");\n+\t\t\t\tbuffer_copy_string(ds->value, latitude);\n+\t\t\t\tarray_insert_unique(con->environment, (data_unset *)ds);\n+\t\t\t}\n+\n+\t\t\t/* get the long latitude */\n+\t\t\tif (NULL == (ds = (data_string *)array_get_element(con->environment, \"GEOIP_CITY_LONG_LATITUDE\"))) {\n+ if (NULL == (ds = (data_string *)array_get_unused_element(con->environment, TYPE_STRING))) {\n+ ds = data_string_init();\n+ }\n+\n+ char long_latitude[32];\n+ sprintf(&long_latitude, \"%f\", gir->longitude);\n+ buffer_copy_string(ds->key, \"GEOIP_CITY_LONG_LATITUDE\");\n+ buffer_copy_string(ds->value, long_latitude);\n+ array_insert_unique(con->environment, (data_unset *)ds);\n+ }\n+\n+\t\t\t/* get the dma code */\n+ if (NULL == (ds = (data_string *)array_get_element(con->environment, \"GEOIP_CITY_DMA_CODE\"))) {\n+ if (NULL == (ds = (data_string *)array_get_unused_element(con->environment, TYPE_STRING))) {\n+ ds = data_string_init();\n+ }\n+\n+ char dc[5];\n+ sprintf(&dc, \"%i\", gir->dma_code);\n+ buffer_copy_string(ds->key, \"GEOIP_CITY_DMA_CODE\");\n+ buffer_copy_string(ds->value, dc);\n+ array_insert_unique(con->environment, (data_unset *)ds);\n+ }\n+\n+\t\t\t/* get the area code */\n+ if (NULL == (ds = (data_string *)array_get_element(con->environment, \"GEOIP_CITY_AREA_CODE\"))) {\n+ if (NULL == (ds = (data_string *)array_get_unused_element(con->environment, TYPE_STRING))) {\n+ ds = data_string_init();\n+ }\n+\n+ char ac[5];\n+ sprintf(&ac, \"%i\", gir->area_code);\n+ buffer_copy_string(ds->key, \"GEOIP_CITY_AREA_CODE\");\n+ buffer_copy_string(ds->value, ac);\n+ array_insert_unique(con->environment, (data_unset *)ds);\n+ }\n+\t\t}\n+\t}\n+\n+ /* keep walking... (johnnie walker style ;) */\n+ return HANDLER_GO_ON;\n+}\n+\n+/* this function is called at dlopen() time and inits the callbacks */\n+\n+int mod_geoip_plugin_init(plugin *p) {\n+\tp->version = LIGHTTPD_VERSION_ID;\n+\tp->name = buffer_init_string(\"geoip\");\n+\n+\tp->init = mod_geoip_init;\n+\tp->handle_subrequest_start = mod_geoip_subrequest;\n+\tp->set_defaults = mod_geoip_set_defaults;\n+\tp->cleanup = mod_geoip_free;\n+\n+\tp->data = NULL;\n+\n+\treturn 0;\n+}\nIndex: doc/geoip.txt\n===================================================================\n--- /dev/null\n+++ doc/geoip.txt\n@@ -0,0 +1,148 @@\n+{{{\n+#!rst\n+==============================\n+ip based geographic lookups...\n+==============================\n+\n+-----------------\n+Module: mod_geoip\n+-----------------\n+\n+\n+\n+.. contents:: Table of Contents\n+\n+Requirements\n+============\n+\n+:Packages: GeoIP C API & Library (http://www.maxmind.com/download/geoip/api/c/)\n+\n+Overview\n+========\n+\n+mod_geoip is a module for fast ip/location lookups. It uses MaxMind GeoIP /\n+GeoCity databases.\n+If the ip was found in the database the module sets the appropriate\n+environments variables to the request, thus making other modules/fcgi be\n+informed.\n+\n+.. note::\n+\n+ Currently only country/city databases are supported because they have a free\n+ version that i can test.\n+\n+Configuration Options\n+========================\n+\n+mod_geoip uses two configuration options.\n+\n+1) geoip.db-filename = \n+2) geoip.memory-cache = : default disabled\n+\n+if enabled, mod_geoip will load the database binary file to\n+memory for very fast lookups. the only penalty is memory usage.\n+\n+.. note::\n+\n+ mod_geoip will determine the database type automatically so if you enter\n+ GeoCity databse path it will load GeoCity Env.\n+\n+Environment\n+===========\n+\n+Every database sets it's own ENV:\n+\n+GeoIP (Country):\n+----------------\n+\n+::\n+\n+ GEOIP_COUNTRY_CODE\n+ GEOIP_COUNTRY_CODE3\n+ GEOIP_COUNTRY_NAME\n+\n+GeoCity:\n+--------\n+\n+::\n+\n+ GEOIP_COUNTRY_CODE\n+ GEOIP_COUNTRY_CODE3\n+ GEOIP_COUNTRY_NAME\n+ GEOIP_CITY_NAME\n+ GEOIP_CITY_POSTAL_CODE\n+ GEOIP_CITY_LATITUDE\n+ GEOIP_CITY_LONG_LATITUDE\n+ GEOIP_CITY_DMA_CODE\n+ GEOIP_CITY_AREA_CODE\n+\n+Examples\n+========\n+\n+mod_geoip + php\n+---------------\n+\n+when using fastcgi (not only php) you can access mod_geoip env and do as you\n+please. this example just prints all mod_geoip envs to the client, html.\n+\n+Config-file ::\n+\n+ geoip.db-filename = \"/your-geoip-db-path/GeoCityLite.dat\"\n+ geoip.memory-cache = \"enable\"\n+\n+index.php ::\n+\n+ \\n\\n\\t
\\n\";\n+ echo 'Country Code: ' . $country_code . '
';\n+ echo 'Country Code 3: ' . $country_code3 . '
';\n+ echo 'Country Name: ' . $country_name . '
';\n+ echo '
';\n+ echo 'City Region: ' . $city_region . '
';\n+ echo 'City Name: ' . $city_name . '
';\n+ echo 'City Postal Code: ' . $city_postal_code . '
';\n+ echo 'City Latitude: ' . $city_latitude . '
';\n+ echo 'City Long Latitude: ' . $city_long_latitude . '
';\n+ echo 'City DMA Code: ' . $city_dma_code . '
';\n+ echo 'City Area Code: ' . $city_area_code . '
';\n+ echo \"\\n\";\n+ ?>\n+\n+country based redirect\n+----------------------\n+\n+Config-file ::\n+\n+ $HTTP[\"host\"] =~ \"www.domain.com\" {\n+ url.rewrite = ( \"\" => \"/redirect.php\")\n+ }\n+\n+redirect.php ::\n+\n+ \n+\n+.. note::\n+\n+ Currently it is not possible to redirect based on mod_geoip directly in\n+lighttpd config file. But i believe with the relase of lighttpd mod_magnet\n+it would be. (mod_magnet will be available in lighttpd 1.4.12+)\n+\n+Downloads\n+=========\n+mod_geoip.c (http://trac.lighttpd.net/trac/attachment/wiki/Docs/ModGeoip/mod_geoip.c)\n+}}}"}], "metadata": {"id": "lighttpd-2374-lighttpd-1.4.13_geoip.patch", "cve_id": "CVE-2013-4560", "package": "lighttpd", "tier": "adapted", "has_source_context": false, "license": "BSD-3-Clause"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- ssl/s3_clnt.c\n- openssl-1.0.1k.orig/ssl/s3_srvr.c\n- openssl-1.0.1k/ssl/s3_srvr.c\n- openssl-1.0.1k.orig/ssl/s3_clnt.c\n- openssl-1.0.1k/ssl/s3_clnt.c\n\n## Target Source Code\n\n### ssl/s3_clnt.c\n\n#### ssl3_get_key_exchange() [lines 1252-1993]\n```c\n\treturn(ret);\n\t}\n\nint ssl3_get_key_exchange(SSL *s)\n\t{\n#ifndef OPENSSL_NO_RSA\n\tunsigned char *q,md_buf[EVP_MAX_MD_SIZE*2];\n#endif\n\tEVP_MD_CTX md_ctx;\n\tunsigned char *param,*p;\n\tint al,j,ok;\n\tlong i,param_len,n,alg_k,alg_a;\n\tEVP_PKEY *pkey=NULL;\n\tconst EVP_MD *md = NULL;\n#ifndef OPENSSL_NO_RSA\n\tRSA *rsa=NULL;\n#endif\n#ifndef OPENSSL_NO_DH\n\tDH *dh=NULL;\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tEC_KEY *ecdh = NULL;\n\tBN_CTX *bn_ctx = NULL;\n\tEC_POINT *srvr_ecpoint = NULL;\n\tint curve_nid = 0;\n\tint encoded_pt_len = 0;\n#endif\n\n\tEVP_MD_CTX_init(&md_ctx);\n\n\t/* use same message size as in ssl3_get_certificate_request()\n\t * as ServerKeyExchange message may be skipped */\n\tn=s->method->ssl_get_message(s,\n\t\tSSL3_ST_CR_KEY_EXCH_A,\n\t\tSSL3_ST_CR_KEY_EXCH_B,\n\t\t-1,\n\t\ts->max_cert_list,\n\t\t&ok);\n\tif (!ok) return((int)n);\n\n/* ... 59 lines omitted ... */\n\t\t}\n\n\t/* Total length of the parameters including the length prefix */\n\tparam_len=0;\n\n\talg_a=s->s3->tmp.new_cipher->algorithm_auth;\n\n\tal=SSL_AD_DECODE_ERROR;\n\n#ifndef OPENSSL_NO_PSK\n\tif (alg_k & SSL_kPSK)\n\t\t{\n\t\tchar tmp_id_hint[PSK_MAX_IDENTITY_LEN+1];\n\n\t\tparam_len = 2;\n\t\tif (param_len > n)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,\n\t\t\t\tSSL_R_LENGTH_TOO_SHORT);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tn2s(p,i);\n\n\t\t/* Store PSK identity hint for later use, hint is used\n\t\t * in ssl3_send_client_key_exchange. Assume that the\n\t\t * maximum length of a PSK identity hint can be as\n\t\t * long as the maximum length of a PSK identity. */\n\t\tif (i > PSK_MAX_IDENTITY_LEN)\n/* ... 595 lines omitted ... */\n\tEVP_PKEY_free(pkey);\n#ifndef OPENSSL_NO_RSA\n\tif (rsa != NULL)\n\t\tRSA_free(rsa);\n#endif\n#ifndef OPENSSL_NO_DH\n\tif (dh != NULL)\n\t\tDH_free(dh);\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tBN_CTX_free(bn_ctx);\n\tEC_POINT_free(srvr_ecpoint);\n\tif (ecdh != NULL)\n\t\tEC_KEY_free(ecdh);\n#endif\n\tEVP_MD_CTX_cleanup(&md_ctx);\n\treturn(-1);\n\t}\n\nint ssl3_get_certificate_request(SSL *s)\n```\n\n#### ssl3_send_client_key_exchange() [lines 2337-3075]\n```c\n\t}\n\n\nint ssl3_send_client_key_exchange(SSL *s)\n\t{\n\tunsigned char *p,*d;\n\tint n;\n\tunsigned long alg_k;\n#ifndef OPENSSL_NO_RSA\n\tunsigned char *q;\n\tEVP_PKEY *pkey=NULL;\n#endif\n#ifndef OPENSSL_NO_KRB5\n\tKSSL_ERR kssl_err;\n#endif /* OPENSSL_NO_KRB5 */\n#ifndef OPENSSL_NO_ECDH\n\tEC_KEY *clnt_ecdh = NULL;\n\tconst EC_POINT *srvr_ecpoint = NULL;\n\tEVP_PKEY *srvr_pub_pkey = NULL;\n\tunsigned char *encodedPoint = NULL;\n\tint encoded_pt_len = 0;\n\tBN_CTX * bn_ctx = NULL;\n#endif\n\n\tif (s->state == SSL3_ST_CW_KEY_EXCH_A)\n\t\t{\n\t\td=(unsigned char *)s->init_buf->data;\n\t\tp= &(d[4]);\n\n\t\talg_k=s->s3->tmp.new_cipher->algorithm_mkey;\n\n\t\t/* Fool emacs indentation */\n\t\tif (0) {}\n#ifndef OPENSSL_NO_RSA\n\t\telse if (alg_k & SSL_kRSA)\n\t\t\t{\n\t\t\tRSA *rsa;\n\t\t\tunsigned char tmp_buf[SSL_MAX_MASTER_KEY_LENGTH];\n\n\t\t\tif (s->session->sess_cert == NULL)\n/* ... 616 lines omitted ... */\n\t\t\t\t\tERR_R_INTERNAL_ERROR);\n\t\t\t\tgoto psk_err;\n\t\t\t\t}\n\t\t\t/* create PSK pre_master_secret */\n\t\t\tpre_ms_len = 2+psk_len+2+psk_len;\n\t\t\tt = psk_or_pre_ms;\n\t\t\tmemmove(psk_or_pre_ms+psk_len+4, psk_or_pre_ms, psk_len);\n\t\t\ts2n(psk_len, t);\n\t\t\tmemset(t, 0, psk_len);\n\t\t\tt+=psk_len;\n\t\t\ts2n(psk_len, t);\n\n\t\t\tif (s->session->psk_identity_hint != NULL)\n\t\t\t\tOPENSSL_free(s->session->psk_identity_hint);\n\t\t\ts->session->psk_identity_hint = BUF_strdup(s->ctx->psk_identity_hint);\n\t\t\tif (s->ctx->psk_identity_hint != NULL &&\n\t\t\t\ts->session->psk_identity_hint == NULL)\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,\n\t\t\t\t\tERR_R_MALLOC_FAILURE);\n\t\t\t\tgoto psk_err;\n\t\t\t\t}\n\n\t\t\tif (s->session->psk_identity != NULL)\n\t\t\t\tOPENSSL_free(s->session->psk_identity);\n\t\t\ts->session->psk_identity = BUF_strdup(identity);\n\t\t\tif (s->session->psk_identity == NULL)\n/* ... 36 lines omitted ... */\n\t\ts->state=SSL3_ST_CW_KEY_EXCH_B;\n\t\t/* number of bytes to write */\n\t\ts->init_num=n+4;\n\t\ts->init_off=0;\n\t\t}\n\n\t/* SSL3_ST_CW_KEY_EXCH_B */\n\treturn(ssl3_do_write(s,SSL3_RT_HANDSHAKE));\nerr:\n#ifndef OPENSSL_NO_ECDH\n\tBN_CTX_free(bn_ctx);\n\tif (encodedPoint != NULL) OPENSSL_free(encodedPoint);\n\tif (clnt_ecdh != NULL) \n\t\tEC_KEY_free(clnt_ecdh);\n\tEVP_PKEY_free(srvr_pub_pkey);\n#endif\n\treturn(-1);\n\t}\n\nint ssl3_send_client_verify(SSL *s)\n```\n\n### ssl/s3_srvr.c\n\n#### ssl3_get_client_key_exchange() [lines 2164-2981]\n```c\n\treturn(-1);\n\t}\n\nint ssl3_get_client_key_exchange(SSL *s)\n\t{\n\tint i,al,ok;\n\tlong n;\n\tunsigned long alg_k;\n\tunsigned char *p;\n#ifndef OPENSSL_NO_RSA\n\tRSA *rsa=NULL;\n\tEVP_PKEY *pkey=NULL;\n#endif\n#ifndef OPENSSL_NO_DH\n\tBIGNUM *pub=NULL;\n\tDH *dh_srvr;\n#endif\n#ifndef OPENSSL_NO_KRB5\n\tKSSL_ERR kssl_err;\n#endif /* OPENSSL_NO_KRB5 */\n\n#ifndef OPENSSL_NO_ECDH\n\tEC_KEY *srvr_ecdh = NULL;\n\tEVP_PKEY *clnt_pub_pkey = NULL;\n\tEC_POINT *clnt_ecpoint = NULL;\n\tBN_CTX *bn_ctx = NULL; \n#endif\n\n\tn=s->method->ssl_get_message(s,\n\t\tSSL3_ST_SR_KEY_EXCH_A,\n\t\tSSL3_ST_SR_KEY_EXCH_B,\n\t\tSSL3_MT_CLIENT_KEY_EXCHANGE,\n\t\t2048, /* ??? */\n\t\t&ok);\n\n\tif (!ok) return((int)n);\n\tp=(unsigned char *)s->init_msg;\n\n\talg_k=s->s3->tmp.new_cipher->algorithm_mkey;\n\n/* ... 603 lines omitted ... */\n\n\t\t\t/* create PSK pre_master_secret */\n\t\t\tpre_ms_len=2+psk_len+2+psk_len;\n\t\t\tt = psk_or_pre_ms;\n\t\t\tmemmove(psk_or_pre_ms+psk_len+4, psk_or_pre_ms, psk_len);\n\t\t\ts2n(psk_len, t);\n\t\t\tmemset(t, 0, psk_len);\n\t\t\tt+=psk_len;\n\t\t\ts2n(psk_len, t);\n\n\t\t\tif (s->session->psk_identity != NULL)\n\t\t\t\tOPENSSL_free(s->session->psk_identity);\n\t\t\ts->session->psk_identity = BUF_strdup((char *)p);\n\t\t\tif (s->session->psk_identity == NULL)\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,\n\t\t\t\t\tERR_R_MALLOC_FAILURE);\n\t\t\t\tgoto psk_err;\n\t\t\t\t}\n\n\t\t\tif (s->session->psk_identity_hint != NULL)\n\t\t\t\tOPENSSL_free(s->session->psk_identity_hint);\n\t\t\ts->session->psk_identity_hint = BUF_strdup(s->ctx->psk_identity_hint);\n\t\t\tif (s->ctx->psk_identity_hint != NULL &&\n\t\t\t\ts->session->psk_identity_hint == NULL)\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,\n/* ... 128 lines omitted ... */\n\t\tgoto f_err;\n\t\t}\n\n\treturn(1);\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,al);\n#if !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_ECDH) || defined(OPENSSL_NO_SRP)\nerr:\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tEVP_PKEY_free(clnt_pub_pkey);\n\tEC_POINT_free(clnt_ecpoint);\n\tif (srvr_ecdh != NULL) \n\t\tEC_KEY_free(srvr_ecdh);\n\tBN_CTX_free(bn_ctx);\n#endif\n\treturn(-1);\n\t}\n\nint ssl3_get_cert_verify(SSL *s)\n```\n\n\n## Upstream Fix\n```diff\nFrom 3c66a669dfc7b3792f7af0758ea26fe8502ce70c Mon Sep 17 00:00:00 2001\nFrom: \"Dr. Stephen Henson\" \nDate: Wed, 1 Jul 2015 23:40:03 +0100\nSubject: [PATCH] Fix PSK handling.\n\nThe PSK identity hint should be stored in the SSL_SESSION structure\nand not in the parent context (which will overwrite values used\nby other SSL structures with the same SSL_CTX).\n\nUse BUF_strndup when copying identity as it may not be null terminated.\n\nReviewed-by: Tim Hudson \n---\n ssl/s3_clnt.c | 17 +++--------------\n ssl/s3_srvr.c | 2 +-\n 2 files changed, 4 insertions(+), 15 deletions(-)\n\ndiff --git a/ssl/s3_clnt.c b/ssl/s3_clnt.c\nindex 2346ce50c0701..6af145a8b744d 100644\n--- a/ssl/s3_clnt.c\n+++ b/ssl/s3_clnt.c\n@@ -1456,8 +1456,6 @@ int ssl3_get_key_exchange(SSL *s)\n \n #ifndef OPENSSL_NO_PSK\n if (alg_k & SSL_kPSK) {\n- char tmp_id_hint[PSK_MAX_IDENTITY_LEN + 1];\n-\n param_len = 2;\n if (param_len > n) {\n SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE, SSL_R_LENGTH_TOO_SHORT);\n@@ -1483,17 +1481,8 @@ int ssl3_get_key_exchange(SSL *s)\n }\n param_len += i;\n \n- /*\n- * If received PSK identity hint contains NULL characters, the hint\n- * is truncated from the first NULL. p may not be ending with NULL,\n- * so create a NULL-terminated string.\n- */\n- memcpy(tmp_id_hint, p, i);\n- memset(tmp_id_hint + i, 0, PSK_MAX_IDENTITY_LEN + 1 - i);\n- if (s->ctx->psk_identity_hint != NULL)\n- OPENSSL_free(s->ctx->psk_identity_hint);\n- s->ctx->psk_identity_hint = BUF_strdup(tmp_id_hint);\n- if (s->ctx->psk_identity_hint == NULL) {\n+ s->session->psk_identity_hint = BUF_strndup((char *)p, i);\n+ if (s->session->psk_identity_hint == NULL) {\n al = SSL_AD_HANDSHAKE_FAILURE;\n SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE, ERR_R_MALLOC_FAILURE);\n goto f_err;\n@@ -3077,7 +3066,7 @@ int ssl3_send_client_key_exchange(SSL *s)\n }\n \n memset(identity, 0, sizeof(identity));\n- psk_len = s->psk_client_callback(s, s->ctx->psk_identity_hint,\n+ psk_len = s->psk_client_callback(s, s->session->psk_identity_hint,\n identity, sizeof(identity) - 1,\n psk_or_pre_ms,\n sizeof(psk_or_pre_ms));\ndiff --git a/ssl/s3_srvr.c b/ssl/s3_srvr.c\nindex 8885694c02b34..acd3b9e964a23 100644\n--- a/ssl/s3_srvr.c\n+++ b/ssl/s3_srvr.c\n@@ -2780,7 +2780,7 @@ int ssl3_get_client_key_exchange(SSL *s)\n \n if (s->session->psk_identity != NULL)\n OPENSSL_free(s->session->psk_identity);\n- s->session->psk_identity = BUF_strdup((char *)p);\n+ s->session->psk_identity = BUF_strndup((char *)p, i);\n if (s->session->psk_identity == NULL) {\n SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, ERR_R_MALLOC_FAILURE);\n goto psk_err;\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From d6be3124f22870f1888c532523b74ea5d89795eb Mon Sep 17 00:00:00 2001\nFrom: \"Dr. Stephen Henson\" \nDate: Wed, 1 Jul 2015 23:40:03 +0100\nSubject: [PATCH] Fix PSK handling.\n\nThe PSK identity hint should be stored in the SSL_SESSION structure\nand not in the parent context (which will overwrite values used\nby other SSL structures with the same SSL_CTX).\n\nUse BUF_strndup when copying identity as it may not be null terminated.\n\nReviewed-by: Tim Hudson \n(cherry picked from commit 3c66a669dfc7b3792f7af0758ea26fe8502ce70c)\n---\n ssl/s3_clnt.c | 17 +++--------------\n ssl/s3_srvr.c | 2 +-\n 2 files changed, 4 insertions(+), 15 deletions(-)\n\nIndex: openssl-1.0.1k/ssl/s3_clnt.c\n===================================================================\n--- openssl-1.0.1k.orig/ssl/s3_clnt.c\t2015-12-04 17:07:16.576888840 +0100\n+++ openssl-1.0.1k/ssl/s3_clnt.c\t2015-12-04 17:23:09.487644962 +0100\n@@ -1360,8 +1360,6 @@ int ssl3_get_key_exchange(SSL *s)\n #ifndef OPENSSL_NO_PSK\n \tif (alg_k & SSL_kPSK)\n \t\t{\n-\t\tchar tmp_id_hint[PSK_MAX_IDENTITY_LEN+1];\n-\n \t\tparam_len = 2;\n \t\tif (param_len > n)\n \t\t\t{\n@@ -1390,17 +1388,8 @@ int ssl3_get_key_exchange(SSL *s)\n \t\t\t}\n \t\tparam_len += i;\n \n-\t\t/* If received PSK identity hint contains NULL\n-\t\t * characters, the hint is truncated from the first\n-\t\t * NULL. p may not be ending with NULL, so create a\n-\t\t * NULL-terminated string. */\n-\t\tmemcpy(tmp_id_hint, p, i);\n-\t\tmemset(tmp_id_hint+i, 0, PSK_MAX_IDENTITY_LEN+1-i);\n-\t\tif (s->ctx->psk_identity_hint != NULL)\n-\t\t\tOPENSSL_free(s->ctx->psk_identity_hint);\n-\t\ts->ctx->psk_identity_hint = BUF_strdup(tmp_id_hint);\n-\t\tif (s->ctx->psk_identity_hint == NULL)\n-\t\t\t{\n+\t s->session->psk_identity_hint = BUF_strndup((char *)p, i);\n+ \tif (s->session->psk_identity_hint == NULL) {\n \t\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n \t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE, ERR_R_MALLOC_FAILURE);\n \t\t\tgoto f_err;\n@@ -3002,7 +2991,7 @@ int ssl3_send_client_key_exchange(SSL *s\n \t\t\t\t}\n \n \t\t\tmemset(identity, 0, sizeof(identity));\n-\t\t\tpsk_len = s->psk_client_callback(s, s->ctx->psk_identity_hint,\n+\t\t\tpsk_len = s->psk_client_callback(s, s->session->psk_identity_hint,\n \t\t\t\tidentity, sizeof(identity) - 1,\n \t\t\t\tpsk_or_pre_ms, sizeof(psk_or_pre_ms));\n \t\t\tif (psk_len > PSK_MAX_PSK_LEN)\nIndex: openssl-1.0.1k/ssl/s3_srvr.c\n===================================================================\n--- openssl-1.0.1k.orig/ssl/s3_srvr.c\t2015-12-04 17:07:14.127850873 +0100\n+++ openssl-1.0.1k/ssl/s3_srvr.c\t2015-12-04 17:07:16.577888855 +0100\n@@ -2816,7 +2816,7 @@ int ssl3_get_client_key_exchange(SSL *s)\n \n \t\t\tif (s->session->psk_identity != NULL)\n \t\t\t\tOPENSSL_free(s->session->psk_identity);\n-\t\t\ts->session->psk_identity = BUF_strdup((char *)p);\n+\t\t\ts->session->psk_identity = BUF_strndup((char *)p, i);\n \t\t\tif (s->session->psk_identity == NULL)\n \t\t\t\t{\n \t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,"}], "metadata": {"id": "openssl-4598-openssl-CVE-2015-3196.patch", "cve_id": "CVE-2015-3197", "package": "openssl", "upstream_enriched": true, "upstream_commit": "3c66a669dfc7b3792f7af0758ea26fe8502ce70c", "upstream_repo": "openssl/openssl", "tier": "adapted", "has_source_context": true, "context_tokens_est": 1568, "context_files": 2, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1i.orig/apps/gendh.c\n- openssl-1.0.1i/apps/gendh.c\n- openssl-1.0.1i/apps/dhparam.c\n- openssl-1.0.1i.orig/apps/dhparam.c\n- apps/dhparam.c\n\n## Target Source Code\n\n### apps/dhparam.c\n\n#### region() [lines 91-178]\n```c\n *\n * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\n * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR\n * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\n * OF THE POSSIBILITY OF SUCH DAMAGE.\n * ====================================================================\n *\n * This product includes cryptographic software written by Eric Young\n * (eay@cryptsoft.com). This product includes software written by Tim\n * Hudson (tjh@cryptsoft.com).\n *\n */\n\n#include \t/* for OPENSSL_NO_DH */\n#ifndef OPENSSL_NO_DH\n#include \n#include \n#include \n#include \n#include \"apps.h\"\n#include \n#include \n#include \n#include \n#include \n#include \n\n#ifndef OPENSSL_NO_DSA\n#include \n#endif\n\n#undef PROG\n#define PROG\tdhparam_main\n\n#define DEFBITS\t512\n\n/* -inform arg\t- input format - default PEM (DER or PEM)\n * -outform arg - output format - default PEM\n * -in arg\t- input file - default stdin\n * -out arg\t- output file - default stdout\n * -dsaparam - read or generate DSA parameters, convert to DH\n * -check\t- check the parameters are ok\n * -noout\n * -text\n * -C\n */\n\nstatic int MS_CALLBACK dh_cb(int p, int n, BN_GENCB *cb);\n\nint MAIN(int, char **);\n\nint MAIN(int argc, char **argv)\n\t{\n\tDH *dh=NULL;\n\tint i,badops=0,text=0;\n#ifndef OPENSSL_NO_DSA\n\tint dsaparam=0;\n#endif\n\tBIO *in=NULL,*out=NULL;\n\tint informat,outformat,check=0,noout=0,C=0,ret=1;\n\tchar *infile,*outfile,*prog;\n\tchar *inrand=NULL;\n#ifndef OPENSSL_NO_ENGINE\n\tchar *engine=NULL;\n#endif\n\tint num = 0, g = 0;\n\n\tapps_startup();\n\n\tif (bio_err == NULL)\n\t\tif ((bio_err=BIO_new(BIO_s_file())) != NULL)\n\t\t\tBIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);\n\n\tif (!load_config(bio_err, NULL))\n\t\tgoto end;\n\n\tinfile=NULL;\n\toutfile=NULL;\n\tinformat=FORMAT_PEM;\n\toutformat=FORMAT_PEM;\n```\n\n#### region() [lines 147-536]\n```c\n\nint MAIN(int, char **);\n\nint MAIN(int argc, char **argv)\n\t{\n\tDH *dh=NULL;\n\tint i,badops=0,text=0;\n#ifndef OPENSSL_NO_DSA\n\tint dsaparam=0;\n#endif\n\tBIO *in=NULL,*out=NULL;\n\tint informat,outformat,check=0,noout=0,C=0,ret=1;\n\tchar *infile,*outfile,*prog;\n\tchar *inrand=NULL;\n#ifndef OPENSSL_NO_ENGINE\n\tchar *engine=NULL;\n#endif\n\tint num = 0, g = 0;\n\n\tapps_startup();\n\n\tif (bio_err == NULL)\n\t\tif ((bio_err=BIO_new(BIO_s_file())) != NULL)\n\t\t\tBIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);\n\n\tif (!load_config(bio_err, NULL))\n\t\tgoto end;\n\n\tinfile=NULL;\n\toutfile=NULL;\n\tinformat=FORMAT_PEM;\n\toutformat=FORMAT_PEM;\n\n\tprog=argv[0];\n\targc--;\n\targv++;\n\twhile (argc >= 1)\n\t\t{\n\t\tif \t(strcmp(*argv,\"-inform\") == 0)\n\t\t\t{\n/* ... 57 lines omitted ... */\n\t\tBIO_printf(bio_err,\" -inform arg input format - one of DER PEM\\n\");\n\t\tBIO_printf(bio_err,\" -outform arg output format - one of DER PEM\\n\");\n\t\tBIO_printf(bio_err,\" -in arg input file\\n\");\n\t\tBIO_printf(bio_err,\" -out arg output file\\n\");\n#ifndef OPENSSL_NO_DSA\n\t\tBIO_printf(bio_err,\" -dsaparam read or generate DSA parameters, convert to DH\\n\");\n#endif\n\t\tBIO_printf(bio_err,\" -check check the DH parameters\\n\");\n\t\tBIO_printf(bio_err,\" -text print a text form of the DH parameters\\n\");\n\t\tBIO_printf(bio_err,\" -C Output C code\\n\");\n\t\tBIO_printf(bio_err,\" -2 generate parameters using 2 as the generator value\\n\");\n\t\tBIO_printf(bio_err,\" -5 generate parameters using 5 as the generator value\\n\");\n\t\tBIO_printf(bio_err,\" numbits number of bits in to generate (default 512)\\n\");\n#ifndef OPENSSL_NO_ENGINE\n\t\tBIO_printf(bio_err,\" -engine e use engine e, possibly a hardware device.\\n\");\n#endif\n\t\tBIO_printf(bio_err,\" -rand file%cfile%c...\\n\", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR);\n\t\tBIO_printf(bio_err,\" - load the file (or the files in the directory) into\\n\");\n\t\tBIO_printf(bio_err,\" the random number generator\\n\");\n\t\tBIO_printf(bio_err,\" -noout no output\\n\");\n\t\tgoto end;\n\t\t}\n\n\tERR_load_crypto_strings();\n\n#ifndef OPENSSL_NO_ENGINE\n setup_engine(bio_err, engine, 0);\n/* ... 246 lines omitted ... */\n\t\t\tBIO_printf(bio_err,\"bad output format specified for outfile\\n\");\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (!i)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,\"unable to write DH parameters\\n\");\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tret=0;\nend:\n\tif (in != NULL) BIO_free(in);\n\tif (out != NULL) BIO_free_all(out);\n\tif (dh != NULL) DH_free(dh);\n\tapps_shutdown();\n\tOPENSSL_EXIT(ret);\n\t}\n\n/* dh_cb is identical to dsa_cb in apps/dsaparam.c */\n```\n\n### apps/gendh.c\n\n#### region() [lines 39-126]\n```c\n * the apps directory (application code) you must include an acknowledgement:\n * \"This product includes software written by Tim Hudson (tjh@cryptsoft.com)\"\n * \n * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\n * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\n * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n * SUCH DAMAGE.\n * \n * The licence and distribution terms for any publically available version or\n * derivative of this code cannot be changed. i.e. this code cannot simply be\n * copied and put under another distribution licence\n * [including the GNU Public Licence.]\n */\n\n#include \n/* Until the key-gen callbacks are modified to use newer prototypes, we allow\n * deprecated functions for openssl-internal code */\n#ifdef OPENSSL_NO_DEPRECATED\n#undef OPENSSL_NO_DEPRECATED\n#endif\n\n#ifndef OPENSSL_NO_DH\n#include \n#include \n#include \n#include \n#include \"apps.h\"\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n#define DEFBITS\t512\n#undef PROG\n#define PROG gendh_main\n\nstatic int MS_CALLBACK dh_cb(int p, int n, BN_GENCB *cb);\n\nint MAIN(int, char **);\n\nint MAIN(int argc, char **argv)\n\t{\n\tBN_GENCB cb;\n\tDH *dh=NULL;\n\tint ret=1,num=DEFBITS;\n\tint g=2;\n\tchar *outfile=NULL;\n\tchar *inrand=NULL;\n#ifndef OPENSSL_NO_ENGINE\n\tchar *engine=NULL;\n#endif\n\tBIO *out=NULL;\n\n\tapps_startup();\n\n\tBN_GENCB_set(&cb, dh_cb, bio_err);\n\tif (bio_err == NULL)\n\t\tif ((bio_err=BIO_new(BIO_s_file())) != NULL)\n\t\t\tBIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);\n\n\tif (!load_config(bio_err, NULL))\n\t\tgoto end;\n\n\targv++;\n\targc--;\n\tfor (;;)\n\t\t{\n\t\tif (argc <= 0) break;\n\t\tif (strcmp(*argv,\"-out\") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\toutfile= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,\"-2\") == 0)\n\t\t\tg=2;\n\t/*\telse if (strcmp(*argv,\"-3\") == 0)\n\t\t\tg=3; */\n\t\telse if (strcmp(*argv,\"-5\") == 0)\n```\n\n\n## Upstream Fix\n```diff\nFrom 8568170d774f02880eec6cad5512f555d0c83f65 Mon Sep 17 00:00:00 2001\nFrom: Emilia Kasper \nDate: Wed, 13 May 2015 11:57:55 +0200\nSubject: [PATCH] dhparam: set the default to 2048 bits\n\nReviewed-by: Matt Caswell \nReviewed-by: Kurt Roeckx \n---\n apps/dhparam.c | 4 ++--\n apps/gendh.c | 2 +-\n 2 files changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/apps/dhparam.c b/apps/dhparam.c\nindex f86311c28fd36..d3b6d58ad2e5a 100644\n--- a/apps/dhparam.c\n+++ b/apps/dhparam.c\n@@ -130,7 +130,7 @@\n # undef PROG\n # define PROG dhparam_main\n \n-# define DEFBITS 512\n+# define DEFBITS 2048\n \n /*-\n * -inform arg - input format - default PEM (DER or PEM)\n@@ -254,7 +254,7 @@ int MAIN(int argc, char **argv)\n BIO_printf(bio_err,\n \" -5 generate parameters using 5 as the generator value\\n\");\n BIO_printf(bio_err,\n- \" numbits number of bits in to generate (default 512)\\n\");\n+ \" numbits number of bits in to generate (default 2048)\\n\");\n # ifndef OPENSSL_NO_ENGINE\n BIO_printf(bio_err,\n \" -engine e use engine e, possibly a hardware device.\\n\");\ndiff --git a/apps/gendh.c b/apps/gendh.c\nindex adaa101783dfd..fef6f1b1774d1 100644\n--- a/apps/gendh.c\n+++ b/apps/gendh.c\n@@ -80,7 +80,7 @@\n # include \n # include \n \n-# define DEFBITS 512\n+# define DEFBITS 2048\n # undef PROG\n # define PROG gendh_main\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From 8568170d774f02880eec6cad5512f555d0c83f65 Mon Sep 17 00:00:00 2001\nFrom: Emilia Kasper \nDate: Wed, 13 May 2015 11:57:55 +0200\nSubject: [PATCH 2/5] dhparam: set the default to 2048 bits\n\nReviewed-by: Matt Caswell \nReviewed-by: Kurt Roeckx \n---\n apps/dhparam.c | 4 ++--\n apps/gendh.c | 2 +-\n 2 files changed, 3 insertions(+), 3 deletions(-)\n\nIndex: openssl-1.0.1i/apps/dhparam.c\n===================================================================\n--- openssl-1.0.1i.orig/apps/dhparam.c\t2015-06-12 13:16:47.628625800 +0200\n+++ openssl-1.0.1i/apps/dhparam.c\t2015-06-12 13:17:23.851068922 +0200\n@@ -130,7 +130,7 @@\n #undef PROG\n #define PROG\tdhparam_main\n \n-#define DEFBITS\t512\n+#define DEFBITS\t2048\n \n /* -inform arg\t- input format - default PEM (DER or PEM)\n * -outform arg - output format - default PEM\n@@ -253,7 +253,7 @@ bad:\n \t\tBIO_printf(bio_err,\" -C Output C code\\n\");\n \t\tBIO_printf(bio_err,\" -2 generate parameters using 2 as the generator value\\n\");\n \t\tBIO_printf(bio_err,\" -5 generate parameters using 5 as the generator value\\n\");\n-\t\tBIO_printf(bio_err,\" numbits number of bits in to generate (default 512)\\n\");\n+\t\tBIO_printf(bio_err,\" numbits number of bits in to generate (default 2048)\\n\");\n #ifndef OPENSSL_NO_ENGINE\n \t\tBIO_printf(bio_err,\" -engine e use engine e, possibly a hardware device.\\n\");\n #endif\nIndex: openssl-1.0.1i/apps/gendh.c\n===================================================================\n--- openssl-1.0.1i.orig/apps/gendh.c\t2015-06-12 13:16:47.629625812 +0200\n+++ openssl-1.0.1i/apps/gendh.c\t2015-06-12 13:17:54.615474034 +0200\n@@ -78,7 +78,7 @@\n #include \n #include \n \n-#define DEFBITS\t512\n+#define DEFBITS\t2048\n #undef PROG\n #define PROG gendh_main"}], "metadata": {"id": "openssl-4769-0002-dhparam-set-the-default-t", "cve_id": "CVE-2015-3197", "package": "openssl", "upstream_enriched": true, "upstream_commit": "8568170d774f02880eec6cad5512f555d0c83f65", "upstream_repo": "openssl/openssl", "tier": "adapted", "has_source_context": true, "context_tokens_est": 1941, "context_files": 2, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2014-3609\n\nHttpHdrRange.cc in Squid 3.x before 3.3.12 and 3.4.x before 3.4.6 allows remote attackers to cause a denial of service (crash) via a request with crafted \"Range headers with unidentifiable byte-range values.\"\n\n## Package\nsquid\n\n## Files to modify\n- ../squid-3.2.11-o/src/HttpRequest.h\n\n## Upstream Fix\n```diff\ndiff -rNU 20 ../squid-3.2.11-o/src/client_side.cc ./src/client_side.cc\n--- ../squid-3.2.11-o/src/client_side.cc\t2013-04-30 06:47:06.000000000 +0200\n+++ ./src/client_side.cc\t2014-04-09 15:14:50.000000000 +0200\n@@ -1249,43 +1249,41 @@\n \n /* hits only - upstream peer determines correct behaviour on misses, and client_side_reply determines\n * hits candidates\n */\n else if (logTypeIsATcpHit(http->logType) && http->request->header.has(HDR_IF_RANGE) && !clientIfRangeMatch(http, rep))\n range_err = \"If-Range match failed\";\n else if (!http->request->range->canonize(rep))\n range_err = \"canonization failed\";\n else if (http->request->range->isComplex())\n range_err = \"too complex range header\";\n else if (!logTypeIsATcpHit(http->logType) && http->request->range->offsetLimitExceeded(roffLimit))\n range_err = \"range outside range_offset_limit\";\n \n /* get rid of our range specs on error */\n if (range_err) {\n /* XXX We do this here because we need canonisation etc. However, this current\n * code will lead to incorrect store offset requests - the store will have the\n * offset data, but we won't be requesting it.\n * So, we can either re-request, or generate an error\n */\n- debugs(33, 3, \"clientBuildRangeHeader: will not do ranges: \" << range_err << \".\");\n- delete http->request->range;\n- http->request->range = NULL;\n+\thttp->request->ignoreRange(range_err);\n } else {\n /* XXX: TODO: Review, this unconditional set may be wrong. - TODO: review. */\n httpStatusLineSet(&rep->sline, rep->sline.version,\n HTTP_PARTIAL_CONTENT, NULL);\n // web server responded with a valid, but unexpected range.\n // will (try-to) forward as-is.\n //TODO: we should cope with multirange request/responses\n bool replyMatchRequest = rep->content_range != NULL ?\n request->range->contains(rep->content_range->spec) :\n true;\n const int spec_count = http->request->range->specs.count;\n int64_t actual_clen = -1;\n \n debugs(33, 3, \"clientBuildRangeHeader: range spec count: \" <<\n spec_count << \" virgin clen: \" << rep->content_length);\n assert(spec_count > 0);\n /* append appropriate header(s) */\n \n if (spec_count == 1) {\n if (!replyMatchRequest) {\ndiff -rNU 20 ../squid-3.2.11-o/src/client_side_reply.cc ./src/client_side_reply.cc\n--- ../squid-3.2.11-o/src/client_side_reply.cc\t2013-04-30 06:47:06.000000000 +0200\n+++ ./src/client_side_reply.cc\t2014-04-09 15:21:57.000000000 +0200\n@@ -102,40 +102,43 @@\n err_type err, http_status status, const HttpRequestMethod& method, char const *uri,\n Ip::Address &addr, HttpRequest * failedrequest, const char *unparsedrequest,\n #if USE_AUTH\n Auth::UserRequest::Pointer auth_user_request\n #else\n void*\n #endif\n )\n {\n ErrorState *errstate = clientBuildError(err, status, uri, addr, failedrequest);\n \n if (unparsedrequest)\n errstate->request_hdrs = xstrdup(unparsedrequest);\n \n if (status == HTTP_NOT_IMPLEMENTED && http->request)\n /* prevent confusion over whether we default to persistent or not */\n http->request->flags.proxy_keepalive = 0;\n \n http->al->http.code = errstate->httpStatus;\n \n+ if (http->request)\n+\thttp->request->ignoreRange(\"responding with a Squid-generated error\");\n+\n createStoreEntry(method, request_flags());\n #if USE_AUTH\n errstate->auth_user_request = auth_user_request;\n #endif\n assert(errstate->callback_data == NULL);\n errorAppendEntry(http->storeEntry(), errstate);\n /* Now the caller reads to get this */\n }\n \n void\n clientReplyContext::removeStoreReference(store_client ** scp,\n StoreEntry ** ep)\n {\n StoreEntry *e;\n store_client *sc_tmp = *scp;\n \n if ((e = *ep) != NULL) {\n *ep = NULL;\n storeUnregister(sc_tmp, e, this);\n *scp = NULL;\ndiff -rNU 20 ../squid-3.2.11-o/src/client_side_request.cc ./src/client_side_request.cc\n--- ../squid-3.2.11-o/src/client_side_request.cc\t2014-04-09 14:58:52.000000000 +0200\n+++ ./src/client_side_request.cc\t2014-04-09 15:22:41.000000000 +0200\n@@ -1097,42 +1097,41 @@\n clientStreamNode *node = (clientStreamNode *)http->client_stream.tail->data;\n /* XXX: This is suboptimal. We should give the stream the range set,\n * and thereby let the top of the stream set the offset when the\n * size becomes known. As it is, we will end up requesting from 0\n * for evey -X range specification.\n * RBC - this may be somewhat wrong. We should probably set the range\n * iter up at this point.\n */\n node->readBuffer.offset = request->range->lowestOffset(0);\n http->range_iter.pos = request->range->begin();\n http->range_iter.valid = true;\n }\n }\n \n /* Only HEAD and GET requests permit a Range or Request-Range header.\n * If these headers appear on any other type of request, delete them now.\n */\n else {\n req_hdr->delById(HDR_RANGE);\n req_hdr->delById(HDR_REQUEST_RANGE);\n- delete request->range;\n- request->range = NULL;\n+\trequest->ignoreRange(\"neither HEAD nor GET\");\n }\n \n if (req_hdr->has(HDR_AUTHORIZATION))\n request->flags.auth = 1;\n \n clientCheckPinning(http);\n \n if (request->login[0] != '\\0')\n request->flags.auth = 1;\n \n if (req_hdr->has(HDR_VIA)) {\n String s = req_hdr->getList(HDR_VIA);\n /*\n * ThisCache cannot be a member of Via header, \"1.1 ThisCache\" can.\n * Note ThisCache2 has a space prepended to the hostname so we don't\n * accidentally match super-domains.\n */\n \n if (strListIsSubstr(&s, ThisCache2, ',')) {\n debugObj(33, 1, \"WARNING: Forwarding loop detected for:\\n\",\ndiff -rNU 20 ../squid-3.2.11-o/src/http.cc ./src/http.cc\n--- ../squid-3.2.11-o/src/http.cc\t2013-04-30 06:47:06.000000000 +0200\n+++ ./src/http.cc\t2014-04-09 15:23:31.000000000 +0200\n@@ -1710,42 +1710,41 @@\n assert (hdr_out->owner == hoRequest);\n \n /* append our IMS header */\n if (request->lastmod > -1)\n hdr_out->putTime(HDR_IF_MODIFIED_SINCE, request->lastmod);\n \n bool we_do_ranges = decideIfWeDoRanges (request);\n \n String strConnection (hdr_in->getList(HDR_CONNECTION));\n \n while ((e = hdr_in->getEntry(&pos)))\n copyOneHeaderFromClientsideRequestToUpstreamRequest(e, strConnection, request, hdr_out, we_do_ranges, flags);\n \n /* Abstraction break: We should interpret multipart/byterange responses\n * into offset-length data, and this works around our inability to do so.\n */\n if (!we_do_ranges && request->multipartRangeRequest()) {\n /* don't cache the result */\n request->flags.cachable = 0;\n /* pretend it's not a range request */\n- delete request->range;\n- request->range = NULL;\n+\trequest->ignoreRange(\"want to request the whole object\");\n request->flags.range = 0;\n }\n \n /* append Via */\n if (Config.onoff.via) {\n String strVia;\n strVia = hdr_in->getList(HDR_VIA);\n snprintf(bbuf, BBUF_SZ, \"%d.%d %s\",\n request->http_ver.major,\n request->http_ver.minor, ThisCache);\n strListAdd(&strVia, bbuf, ',');\n hdr_out->putStr(HDR_VIA, strVia.termedBuf());\n strVia.clean();\n }\n \n if (request->flags.accelerated) {\n /* Append Surrogate-Capabilities */\n String strSurrogate(hdr_in->getList(HDR_SURROGATE_CAPABILITY));\n #if USE_SQUID_ESI\n snprintf(bbuf, BBUF_SZ, \"%s=\\\"Surrogate/1.0 ESI/1.0\\\"\", Config.Accel.surrogate_id);\ndiff -rNU 20 ../squid-3.2.11-o/src/HttpRequest.cc ./src/HttpRequest.cc\n--- ../squid-3.2.11-o/src/HttpRequest.cc\t2013-04-30 06:47\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "diff -rNU 20 ../squid-3.2.11-o/src/client_side.cc ./src/client_side.cc\n--- ../squid-3.2.11-o/src/client_side.cc\t2013-04-30 06:47:06.000000000 +0200\n+++ ./src/client_side.cc\t2014-04-09 15:14:50.000000000 +0200\n@@ -1249,43 +1249,41 @@\n \n /* hits only - upstream peer determines correct behaviour on misses, and client_side_reply determines\n * hits candidates\n */\n else if (logTypeIsATcpHit(http->logType) && http->request->header.has(HDR_IF_RANGE) && !clientIfRangeMatch(http, rep))\n range_err = \"If-Range match failed\";\n else if (!http->request->range->canonize(rep))\n range_err = \"canonization failed\";\n else if (http->request->range->isComplex())\n range_err = \"too complex range header\";\n else if (!logTypeIsATcpHit(http->logType) && http->request->range->offsetLimitExceeded(roffLimit))\n range_err = \"range outside range_offset_limit\";\n \n /* get rid of our range specs on error */\n if (range_err) {\n /* XXX We do this here because we need canonisation etc. However, this current\n * code will lead to incorrect store offset requests - the store will have the\n * offset data, but we won't be requesting it.\n * So, we can either re-request, or generate an error\n */\n- debugs(33, 3, \"clientBuildRangeHeader: will not do ranges: \" << range_err << \".\");\n- delete http->request->range;\n- http->request->range = NULL;\n+\thttp->request->ignoreRange(range_err);\n } else {\n /* XXX: TODO: Review, this unconditional set may be wrong. - TODO: review. */\n httpStatusLineSet(&rep->sline, rep->sline.version,\n HTTP_PARTIAL_CONTENT, NULL);\n // web server responded with a valid, but unexpected range.\n // will (try-to) forward as-is.\n //TODO: we should cope with multirange request/responses\n bool replyMatchRequest = rep->content_range != NULL ?\n request->range->contains(rep->content_range->spec) :\n true;\n const int spec_count = http->request->range->specs.count;\n int64_t actual_clen = -1;\n \n debugs(33, 3, \"clientBuildRangeHeader: range spec count: \" <<\n spec_count << \" virgin clen: \" << rep->content_length);\n assert(spec_count > 0);\n /* append appropriate header(s) */\n \n if (spec_count == 1) {\n if (!replyMatchRequest) {\ndiff -rNU 20 ../squid-3.2.11-o/src/client_side_reply.cc ./src/client_side_reply.cc\n--- ../squid-3.2.11-o/src/client_side_reply.cc\t2013-04-30 06:47:06.000000000 +0200\n+++ ./src/client_side_reply.cc\t2014-04-09 15:21:57.000000000 +0200\n@@ -102,40 +102,43 @@\n err_type err, http_status status, const HttpRequestMethod& method, char const *uri,\n Ip::Address &addr, HttpRequest * failedrequest, const char *unparsedrequest,\n #if USE_AUTH\n Auth::UserRequest::Pointer auth_user_request\n #else\n void*\n #endif\n )\n {\n ErrorState *errstate = clientBuildError(err, status, uri, addr, failedrequest);\n \n if (unparsedrequest)\n errstate->request_hdrs = xstrdup(unparsedrequest);\n \n if (status == HTTP_NOT_IMPLEMENTED && http->request)\n /* prevent confusion over whether we default to persistent or not */\n http->request->flags.proxy_keepalive = 0;\n \n http->al->http.code = errstate->httpStatus;\n \n+ if (http->request)\n+\thttp->request->ignoreRange(\"responding with a Squid-generated error\");\n+\n createStoreEntry(method, request_flags());\n #if USE_AUTH\n errstate->auth_user_request = auth_user_request;\n #endif\n assert(errstate->callback_data == NULL);\n errorAppendEntry(http->storeEntry(), errstate);\n /* Now the caller reads to get this */\n }\n \n void\n clientReplyContext::removeStoreReference(store_client ** scp,\n StoreEntry ** ep)\n {\n StoreEntry *e;\n store_client *sc_tmp = *scp;\n \n if ((e = *ep) != NULL) {\n *ep = NULL;\n storeUnregister(sc_tmp, e, this);\n *scp = NULL;\ndiff -rNU 20 ../squid-3.2.11-o/src/client_side_request.cc ./src/client_side_request.cc\n--- ../squid-3.2.11-o/src/client_side_request.cc\t2014-04-09 14:58:52.000000000 +0200\n+++ ./src/client_side_request.cc\t2014-04-09 15:22:41.000000000 +0200\n@@ -1097,42 +1097,41 @@\n clientStreamNode *node = (clientStreamNode *)http->client_stream.tail->data;\n /* XXX: This is suboptimal. We should give the stream the range set,\n * and thereby let the top of the stream set the offset when the\n * size becomes known. As it is, we will end up requesting from 0\n * for evey -X range specification.\n * RBC - this may be somewhat wrong. We should probably set the range\n * iter up at this point.\n */\n node->readBuffer.offset = request->range->lowestOffset(0);\n http->range_iter.pos = request->range->begin();\n http->range_iter.valid = true;\n }\n }\n \n /* Only HEAD and GET requests permit a Range or Request-Range header.\n * If these headers appear on any other type of request, delete them now.\n */\n else {\n req_hdr->delById(HDR_RANGE);\n req_hdr->delById(HDR_REQUEST_RANGE);\n- delete request->range;\n- request->range = NULL;\n+\trequest->ignoreRange(\"neither HEAD nor GET\");\n }\n \n if (req_hdr->has(HDR_AUTHORIZATION))\n request->flags.auth = 1;\n \n clientCheckPinning(http);\n \n if (request->login[0] != '\\0')\n request->flags.auth = 1;\n \n if (req_hdr->has(HDR_VIA)) {\n String s = req_hdr->getList(HDR_VIA);\n /*\n * ThisCache cannot be a member of Via header, \"1.1 ThisCache\" can.\n * Note ThisCache2 has a space prepended to the hostname so we don't\n * accidentally match super-domains.\n */\n \n if (strListIsSubstr(&s, ThisCache2, ',')) {\n debugObj(33, 1, \"WARNING: Forwarding loop detected for:\\n\",\ndiff -rNU 20 ../squid-3.2.11-o/src/http.cc ./src/http.cc\n--- ../squid-3.2.11-o/src/http.cc\t2013-04-30 06:47:06.000000000 +0200\n+++ ./src/http.cc\t2014-04-09 15:23:31.000000000 +0200\n@@ -1710,42 +1710,41 @@\n assert (hdr_out->owner == hoRequest);\n \n /* append our IMS header */\n if (request->lastmod > -1)\n hdr_out->putTime(HDR_IF_MODIFIED_SINCE, request->lastmod);\n \n bool we_do_ranges = decideIfWeDoRanges (request);\n \n String strConnection (hdr_in->getList(HDR_CONNECTION));\n \n while ((e = hdr_in->getEntry(&pos)))\n copyOneHeaderFromClientsideRequestToUpstreamRequest(e, strConnection, request, hdr_out, we_do_ranges, flags);\n \n /* Abstraction break: We should interpret multipart/byterange responses\n * into offset-length data, and this works around our inability to do so.\n */\n if (!we_do_ranges && request->multipartRangeRequest()) {\n /* don't cache the result */\n request->flags.cachable = 0;\n /* pretend it's not a range request */\n- delete request->range;\n- request->range = NULL;\n+\trequest->ignoreRange(\"want to request the whole object\");\n request->flags.range = 0;\n }\n \n /* append Via */\n if (Config.onoff.via) {\n String strVia;\n strVia = hdr_in->getList(HDR_VIA);\n snprintf(bbuf, BBUF_SZ, \"%d.%d %s\",\n request->http_ver.major,\n request->http_ver.minor, ThisCache);\n strListAdd(&strVia, bbuf, ',');\n hdr_out->putStr(HDR_VIA, strVia.termedBuf());\n strVia.clean();\n }\n \n if (request->flags.accelerated) {\n /* Append Surrogate-Capabilities */\n String strSurrogate(hdr_in->getList(HDR_SURROGATE_CAPABILITY));\n #if USE_SQUID_ESI\n snprintf(bbuf, BBUF_SZ, \"%s=\\\"Surrogate/1.0 ESI/1.0\\\"\", Config.Accel.surrogate_id);\ndiff -rNU 20 ../squid-3.2.11-o/src/HttpRequest.cc ./src/HttpRequest.cc\n--- ../squid-3.2.11-o/src/HttpRequest.cc\t2013-04-30 06:47:06.000000000 +0200\n+++ ./src/HttpRequest.cc\t2014-04-09 15:04:05.000000000 +0200\n@@ -674,31 +674,46 @@\n return rangeOffsetLimit;\n \n rangeOffsetLimit = 0; // default value for rangeOffsetLimit\n \n ACLFilledChecklist ch(NULL, this, NULL);\n ch.src_addr = client_addr;\n ch.my_addr = my_addr;\n \n for (acl_size_t *l = Config.rangeOffsetLimit; l; l = l -> next) {\n /* if there is no ACL list or if the ACLs listed match use this limit value */\n if (!l->aclList || ch.fastCheck(l->aclList) == ACCESS_ALLOWED) {\n debugs(58, 4, HERE << \"rangeOffsetLimit=\" << rangeOffsetLimit);\n rangeOffsetLimit = l->size; // may be -1\n break;\n }\n }\n \n return rangeOffsetLimit;\n }\n \n+void\n+HttpRequest::ignoreRange(const char *reason)\n+{\n+ if (range) {\n+ debugs(73, 3, static_cast(range) << \" for \" << reason);\n+ delete range;\n+ range = NULL;\n+ }\n+ // Some callers also reset isRanged but it may not be safe for all callers:\n+ // isRanged is used to determine whether a weak ETag comparison is allowed,\n+ // and that check should not ignore the Range header if it was present.\n+ // TODO: Some callers also delete HDR_RANGE, HDR_REQUEST_RANGE. Should we?\n+}\n+\n+\n bool\n HttpRequest::canHandle1xx() const\n {\n // old clients do not support 1xx unless they sent Expect: 100-continue\n // (we reject all other HDR_EXPECT values so just check for HDR_EXPECT)\n if (http_ver <= HttpVersion(1,0) && !header.has(HDR_EXPECT))\n return false;\n \n // others must support 1xx control messages\n return true;\n }\ndiff -rNU 20 ../squid-3.2.11-o/src/HttpRequest.h ./src/HttpRequest.h\n--- ../squid-3.2.11-o/src/HttpRequest.h\t2013-04-30 06:47:06.000000000 +0200\n+++ ./src/HttpRequest.h\t2014-04-09 15:04:42.000000000 +0200\n@@ -223,40 +223,43 @@\n void pack(Packer * p);\n \n static void httpRequestPack(void *obj, Packer *p);\n \n static HttpRequest * CreateFromUrlAndMethod(char * url, const HttpRequestMethod& method);\n \n static HttpRequest * CreateFromUrl(char * url);\n \n ConnStateData *pinnedConnection() {\n if (clientConnectionManager.valid() && clientConnectionManager->pinning.pinned)\n return clientConnectionManager.get();\n return NULL;\n }\n \n /**\n * The client connection manager, if known;\n * Used for any response actions needed directly to the client.\n * ie 1xx forwarding or connection pinning state changes\n */\n CbcPointer clientConnectionManager;\n+ /// forgets about the cached Range header (for a reason)\n+ void ignoreRange(const char *reason);\n+\n \n int64_t getRangeOffsetLimit(); /* the result of this function gets cached in rangeOffsetLimit */\n \n private:\n const char *packableURI(bool full_uri) const;\n \n mutable int64_t rangeOffsetLimit; /* caches the result of getRangeOffsetLimit */\n \n protected:\n virtual void packFirstLineInto(Packer * p, bool full_uri) const;\n \n virtual bool sanityCheckStartLine(MemBuf *buf, const size_t hdr_len, http_status *error);\n \n virtual void hdrCacheInit();\n \n virtual bool inheritProperties(const HttpMsg *aMsg);\n };\n \n MEMPROXY_CLASS_INLINE(HttpRequest);"}], "metadata": {"id": "squid-2990-squid-3.2.11-bnc867533-CVE-201", "cve_id": "CVE-2014-3609", "package": "squid", "tier": "adapted", "has_source_context": false, "license": "GPL-2.0-or-later"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1i/crypto/cms/cms_smime.c\n- openssl-1.0.1i.orig/crypto/cms/cms_smime.c\n\n## Target Source Code\n\n### crypto/cms/cms_smime.c\n\n#### do_free_upto() [lines 130-150]\n```c\n\treturn 1;\n\t}\n\nstatic void do_free_upto(BIO *f, BIO *upto)\n\t{\n\tif (upto)\n\t\t{\n\t\tBIO *tbio;\n\t\tdo \n\t\t\t{\n\t\t\ttbio = BIO_pop(f);\n\t\t\tBIO_free(f);\n\t\t\tf = tbio;\n\t\t\t}\n\t\twhile (f != upto);\n\t\t}\n\telse\n\t\tBIO_free_all(f);\n\t}\n\nint CMS_data(CMS_ContentInfo *cms, BIO *out, unsigned int flags)\n```\n\n\n## Upstream Fix\n```diff\ncommit 92f9a8bf3844359bb50d86dab92bc24b074d350d\nAuthor: Dr. Stephen Henson \nDate: Fri Jun 5 12:11:25 2015 +0100\n\n Fix infinite loop in CMS\n \n Fix loop in do_free_upto if cmsbio is NULL: this will happen when attempting\n to verify and a digest is not recognised. Reported by Johannes Bauer.\n \n CVE-2015-1792\n \n Reviewed-by: Matt Caswell \n\nIndex: openssl-1.0.1i/crypto/cms/cms_smime.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/cms/cms_smime.c\t2015-06-12 11:37:27.983984849 +0200\n+++ openssl-1.0.1i/crypto/cms/cms_smime.c\t2015-06-12 11:38:03.058396809 +0200\n@@ -141,7 +141,7 @@ static void do_free_upto(BIO *f, BIO *up\n \t\t\tBIO_free(f);\n \t\t\tf = tbio;\n \t\t\t}\n-\t\twhile (f != upto);\n+\t while (f && f != upto);\n \t\t}\n \telse\n \t\tBIO_free_all(f);\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "commit 92f9a8bf3844359bb50d86dab92bc24b074d350d\nAuthor: Dr. Stephen Henson \nDate: Fri Jun 5 12:11:25 2015 +0100\n\n Fix infinite loop in CMS\n \n Fix loop in do_free_upto if cmsbio is NULL: this will happen when attempting\n to verify and a digest is not recognised. Reported by Johannes Bauer.\n \n CVE-2015-1792\n \n Reviewed-by: Matt Caswell \n\nIndex: openssl-1.0.1i/crypto/cms/cms_smime.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/cms/cms_smime.c\t2015-06-12 11:37:27.983984849 +0200\n+++ openssl-1.0.1i/crypto/cms/cms_smime.c\t2015-06-12 11:38:03.058396809 +0200\n@@ -141,7 +141,7 @@ static void do_free_upto(BIO *f, BIO *up\n \t\t\tBIO_free(f);\n \t\t\tf = tbio;\n \t\t\t}\n-\t\twhile (f != upto);\n+\t while (f && f != upto);\n \t\t}\n \telse\n \t\tBIO_free_all(f);"}], "metadata": {"id": "openssl-4598-openssl-CVE-2015-1792.patch", "cve_id": "CVE-2015-3197", "package": "openssl", "tier": "identical", "has_source_context": true, "context_tokens_est": 87, "context_files": 1, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-9556\n\nThe IsPixelGray function in MagickCore/pixel-accessor.h in ImageMagick 7.0.3-8 allows remote attackers to cause a denial of service (out-of-bounds heap read) via a crafted image file.\n\n## Package\nGraphicsMagick\n\n## Files to modify\n- coders/svg.c\n- GraphicsMagick-1.3.20.orig/coders/svg.c\n- magick/render.c\n- GraphicsMagick-1.3.20.orig/magick/render.c\n\n## Upstream Fix\n```diff\nIndex: GraphicsMagick-1.3.20/coders/svg.c\n===================================================================\n--- GraphicsMagick-1.3.20.orig/coders/svg.c\t2013-03-10 00:19:31.000000000 +0100\n+++ GraphicsMagick-1.3.20/coders/svg.c\t2016-06-23 10:05:21.805840780 +0200\n@@ -316,25 +316,22 @@ static char **GetTransformTokens(void *c\n *p,\n *q;\n \n- register long\n+ register size_t\n i;\n \n SVGInfo\n *svg_info;\n \n+ size_t\n+ alloc_tokens;\n+\n svg_info=(SVGInfo *) context;\n *number_tokens=0;\n if (text == (const char *) NULL)\n return((char **) NULL);\n- /*\n- Determine the number of arguments.\n- */\n- for (p=text; *p != '\\0'; p++)\n- {\n- if (*p == '(')\n- (*number_tokens)+=2;\n- }\n- tokens=MagickAllocateMemory(char **,(*number_tokens+2)*sizeof(*tokens));\n+\n+ alloc_tokens=8;\n+ tokens=MagickAllocateMemory(char **,(alloc_tokens+2)*sizeof(*tokens));\n if (tokens == (char **) NULL)\n {\n ThrowException3(svg_info->exception,ResourceLimitError,\n@@ -350,15 +347,28 @@ static char **GetTransformTokens(void *c\n {\n if ((*q != '(') && (*q != ')') && (*q != '\\0'))\n continue;\n+ if (i == alloc_tokens)\n+ {\n+ alloc_tokens <<= 1;\n+ MagickReallocMemory(char **,tokens,(alloc_tokens+2)*sizeof(*tokens));\n+ if (tokens == (char **) NULL)\n+ {\n+ ThrowException3(svg_info->exception,ResourceLimitError,\n+ MemoryAllocationFailed,UnableToConvertStringToTokens);\n+ return((char **) NULL);\n+ }\n+ }\n tokens[i]=AllocateString(p);\n (void) strlcpy(tokens[i],p,q-p+1);\n- Strip(tokens[i++]);\n+ Strip(tokens[i]);\n+ i++;\n p=q+1;\n }\n tokens[i]=AllocateString(p);\n (void) strlcpy(tokens[i],p,q-p+1);\n Strip(tokens[i++]);\n tokens[i]=(char *) NULL;\n+ *number_tokens=i;\n return(tokens);\n }\n \n@@ -1177,18 +1187,20 @@ static void SVGStartElement(void *contex\n IdentityAffine(&transform);\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\" \");\n tokens=GetTransformTokens(context,value,&number_tokens);\n- for (j=0; j < (number_tokens-1); j+=2)\n+ if ((tokens != (char **) NULL) && (number_tokens > 0))\n {\n- keyword=(char *) tokens[j];\n- if (keyword == (char *) NULL)\n- continue;\n- value=(char *) tokens[j+1];\n- (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n- \" %.1024s: %.1024s\",keyword,value);\n- current=transform;\n- IdentityAffine(&affine);\n- switch (*keyword)\n+ for (j=0; j < (number_tokens-1); j+=2)\n {\n+ keyword=(char *) tokens[j];\n+ if (keyword == (char *) NULL)\n+ continue;\n+ value=(char *) tokens[j+1];\n+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n+ \" %.1024s: %.1024s\",keyword,value);\n+ current=transform;\n+ IdentityAffine(&affine);\n+ switch (*keyword)\n+ {\n case 'M':\n case 'm':\n {\n@@ -1293,22 +1305,23 @@ static void SVGStartElement(void *contex\n }\n default:\n break;\n- }\n- transform.sx=current.sx*affine.sx+current.ry*affine.rx;\n- transform.rx=current.rx*affine.sx+current.sy*affine.rx;\n- transform.ry=current.sx*affine.ry+current.ry*affine.sy;\n- transform.sy=current.rx*affine.ry+current.sy*affine.sy;\n- transform.tx=current.sx*affine.tx+current.ry*affine.ty+\n- current.tx;\n- transform.ty=current.rx*affine.tx+current.sy*affine.ty+\n- current.ty;\n- }\n- MVGPrintf(svg_info->file,\"affine %g %g %g %g %g %g\\n\",\n- transform.sx,transform.rx,transform.ry,transform.sy,\n- transform.tx,transform.ty);\n- for (j=0; tokens[j] != (char *) NULL; j++)\n- MagickFreeMemory(tokens[j]);\n- MagickFreeMemory(tokens);\n+ } /* end switch */\n+ transform.sx=current.sx*affine.sx+current.ry*affine.rx;\n+ transform.rx=current.rx*affine.sx+current.sy*affine.rx;\n+ transform.ry=current.sx*affine.ry+current.ry*affine.sy;\n+ transform.sy=current.rx*affine.ry+current.sy*affine.sy;\n+ transform.tx=current.sx*affine.tx+current.ry*affine.ty+\n+ current.tx;\n+ transform.ty=current.rx*affine.tx+current.sy*affine.ty+\n+ current.ty;\n+ } /* end for */\n+ MVGPrintf(svg_info->file,\"affine %g %g %g %g %g %g\\n\",\n+ transform.sx,transform.rx,transform.ry,transform.sy,\n+ transform.tx,transform.ty);\n+ for (j=0; tokens[j] != (char *) NULL; j++)\n+ MagickFreeMemory(tokens[j]);\n+ MagickFreeMemory(tokens);\n+ } /* end if */\n break;\n }\n if (LocaleCompare(keyword,\"gradientUnits\") == 0)\n@@ -1746,6 +1759,8 @@ static void SVGStartElement(void *contex\n IdentityAffine(&transform);\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\" \");\n tokens=GetTransformTokens(context,value,&number_tokens);\n+ if ((tokens != (char **) NULL) && (number_tokens > 0))\n+ {\n for (j=0; j < (number_tokens-1); j+=2)\n {\n keyword=(char *) tokens[j];\n@@ -1873,8 +1888,10 @@ static void SVGStartElement(void *contex\n MVGPrintf(svg_info->file,\"affine %g %g %g %g %g %g\\n\",\n transform.sx,transform.rx,transform.ry,transform.sy,\n transform.tx,transform.ty);\n- for (j=0; tokens[j] != (char *) NULL; j++)\n- MagickFreeMemory(tokens[j]);\n+ }\n+ if (number_tokens > 0)\n+ for (j=0; tokens[j] != (char *) NULL; j++)\n+ MagickFreeMemory(tokens[j]);\n MagickFreeMemory(tokens);\n break;\n }\nIndex: GraphicsMagick-1.3.20/magick/render.c\n===================================================================\n--- GraphicsMagick-1.3.20.orig/magick/render.c\t2016-06-23 10:05:21.649838266 +0200\n+++ GraphicsMagick-1.3.20/magick/render.c\t2016-06-23 10:05:21.805840780 +0200\n@@ -432,7 +432,7 @@ ConvertPathToPolygon(const PathInfo *pat\n {\n number_edges<<=1;\n MagickReallocMemory(EdgeInfo *,polygon_info->edges,\n- number_edges*sizeof(EdgeInfo));\n+ MagickArraySize(number_edges,sizeof(EdgeInfo)));\n if (polygon_info->edges == (EdgeInfo *) NULL)\n return((PolygonInfo *) NULL);\n }\n@@ -484,7 +484,7 @@ ConvertPathToPolygon(const PathInfo *pat\n {\n number_edges<<=1;\n MagickReallocMemory(EdgeInfo *,polygon_info->edges,\n- number_edges*sizeof(EdgeInfo));\n+ MagickArraySize(number_edges,sizeof(EdgeInfo)));\n if (polygon_info->edges == (EdgeInfo *) NULL)\n return((PolygonInfo *) NULL);\n }\n@@ -517,7 +517,7 @@ ConvertPathToPolygon(const PathInfo *pat\n if (n == number_points)\n {\n number_points<<=1;\n- MagickReallocMemory(PointInfo *,points,number_points*sizeof(PointInfo));\n+ MagickReallocMemory(PointInfo *,points,MagickArraySize(number_points,sizeof(PointInfo)));\n if (points == (PointInfo *) NULL)\n return((PolygonInfo *) NULL);\n }\n@@ -541,7 +541,7 @@ ConvertPathToPolygon(const PathInfo *p\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "Index: GraphicsMagick-1.3.20/coders/svg.c\n===================================================================\n--- GraphicsMagick-1.3.20.orig/coders/svg.c\t2013-03-10 00:19:31.000000000 +0100\n+++ GraphicsMagick-1.3.20/coders/svg.c\t2016-06-23 10:05:21.805840780 +0200\n@@ -316,25 +316,22 @@ static char **GetTransformTokens(void *c\n *p,\n *q;\n \n- register long\n+ register size_t\n i;\n \n SVGInfo\n *svg_info;\n \n+ size_t\n+ alloc_tokens;\n+\n svg_info=(SVGInfo *) context;\n *number_tokens=0;\n if (text == (const char *) NULL)\n return((char **) NULL);\n- /*\n- Determine the number of arguments.\n- */\n- for (p=text; *p != '\\0'; p++)\n- {\n- if (*p == '(')\n- (*number_tokens)+=2;\n- }\n- tokens=MagickAllocateMemory(char **,(*number_tokens+2)*sizeof(*tokens));\n+\n+ alloc_tokens=8;\n+ tokens=MagickAllocateMemory(char **,(alloc_tokens+2)*sizeof(*tokens));\n if (tokens == (char **) NULL)\n {\n ThrowException3(svg_info->exception,ResourceLimitError,\n@@ -350,15 +347,28 @@ static char **GetTransformTokens(void *c\n {\n if ((*q != '(') && (*q != ')') && (*q != '\\0'))\n continue;\n+ if (i == alloc_tokens)\n+ {\n+ alloc_tokens <<= 1;\n+ MagickReallocMemory(char **,tokens,(alloc_tokens+2)*sizeof(*tokens));\n+ if (tokens == (char **) NULL)\n+ {\n+ ThrowException3(svg_info->exception,ResourceLimitError,\n+ MemoryAllocationFailed,UnableToConvertStringToTokens);\n+ return((char **) NULL);\n+ }\n+ }\n tokens[i]=AllocateString(p);\n (void) strlcpy(tokens[i],p,q-p+1);\n- Strip(tokens[i++]);\n+ Strip(tokens[i]);\n+ i++;\n p=q+1;\n }\n tokens[i]=AllocateString(p);\n (void) strlcpy(tokens[i],p,q-p+1);\n Strip(tokens[i++]);\n tokens[i]=(char *) NULL;\n+ *number_tokens=i;\n return(tokens);\n }\n \n@@ -1177,18 +1187,20 @@ static void SVGStartElement(void *contex\n IdentityAffine(&transform);\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\" \");\n tokens=GetTransformTokens(context,value,&number_tokens);\n- for (j=0; j < (number_tokens-1); j+=2)\n+ if ((tokens != (char **) NULL) && (number_tokens > 0))\n {\n- keyword=(char *) tokens[j];\n- if (keyword == (char *) NULL)\n- continue;\n- value=(char *) tokens[j+1];\n- (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n- \" %.1024s: %.1024s\",keyword,value);\n- current=transform;\n- IdentityAffine(&affine);\n- switch (*keyword)\n+ for (j=0; j < (number_tokens-1); j+=2)\n {\n+ keyword=(char *) tokens[j];\n+ if (keyword == (char *) NULL)\n+ continue;\n+ value=(char *) tokens[j+1];\n+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n+ \" %.1024s: %.1024s\",keyword,value);\n+ current=transform;\n+ IdentityAffine(&affine);\n+ switch (*keyword)\n+ {\n case 'M':\n case 'm':\n {\n@@ -1293,22 +1305,23 @@ static void SVGStartElement(void *contex\n }\n default:\n break;\n- }\n- transform.sx=current.sx*affine.sx+current.ry*affine.rx;\n- transform.rx=current.rx*affine.sx+current.sy*affine.rx;\n- transform.ry=current.sx*affine.ry+current.ry*affine.sy;\n- transform.sy=current.rx*affine.ry+current.sy*affine.sy;\n- transform.tx=current.sx*affine.tx+current.ry*affine.ty+\n- current.tx;\n- transform.ty=current.rx*affine.tx+current.sy*affine.ty+\n- current.ty;\n- }\n- MVGPrintf(svg_info->file,\"affine %g %g %g %g %g %g\\n\",\n- transform.sx,transform.rx,transform.ry,transform.sy,\n- transform.tx,transform.ty);\n- for (j=0; tokens[j] != (char *) NULL; j++)\n- MagickFreeMemory(tokens[j]);\n- MagickFreeMemory(tokens);\n+ } /* end switch */\n+ transform.sx=current.sx*affine.sx+current.ry*affine.rx;\n+ transform.rx=current.rx*affine.sx+current.sy*affine.rx;\n+ transform.ry=current.sx*affine.ry+current.ry*affine.sy;\n+ transform.sy=current.rx*affine.ry+current.sy*affine.sy;\n+ transform.tx=current.sx*affine.tx+current.ry*affine.ty+\n+ current.tx;\n+ transform.ty=current.rx*affine.tx+current.sy*affine.ty+\n+ current.ty;\n+ } /* end for */\n+ MVGPrintf(svg_info->file,\"affine %g %g %g %g %g %g\\n\",\n+ transform.sx,transform.rx,transform.ry,transform.sy,\n+ transform.tx,transform.ty);\n+ for (j=0; tokens[j] != (char *) NULL; j++)\n+ MagickFreeMemory(tokens[j]);\n+ MagickFreeMemory(tokens);\n+ } /* end if */\n break;\n }\n if (LocaleCompare(keyword,\"gradientUnits\") == 0)\n@@ -1746,6 +1759,8 @@ static void SVGStartElement(void *contex\n IdentityAffine(&transform);\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\" \");\n tokens=GetTransformTokens(context,value,&number_tokens);\n+ if ((tokens != (char **) NULL) && (number_tokens > 0))\n+ {\n for (j=0; j < (number_tokens-1); j+=2)\n {\n keyword=(char *) tokens[j];\n@@ -1873,8 +1888,10 @@ static void SVGStartElement(void *contex\n MVGPrintf(svg_info->file,\"affine %g %g %g %g %g %g\\n\",\n transform.sx,transform.rx,transform.ry,transform.sy,\n transform.tx,transform.ty);\n- for (j=0; tokens[j] != (char *) NULL; j++)\n- MagickFreeMemory(tokens[j]);\n+ }\n+ if (number_tokens > 0)\n+ for (j=0; tokens[j] != (char *) NULL; j++)\n+ MagickFreeMemory(tokens[j]);\n MagickFreeMemory(tokens);\n break;\n }\nIndex: GraphicsMagick-1.3.20/magick/render.c\n===================================================================\n--- GraphicsMagick-1.3.20.orig/magick/render.c\t2016-06-23 10:05:21.649838266 +0200\n+++ GraphicsMagick-1.3.20/magick/render.c\t2016-06-23 10:05:21.805840780 +0200\n@@ -432,7 +432,7 @@ ConvertPathToPolygon(const PathInfo *pat\n {\n number_edges<<=1;\n MagickReallocMemory(EdgeInfo *,polygon_info->edges,\n- number_edges*sizeof(EdgeInfo));\n+ MagickArraySize(number_edges,sizeof(EdgeInfo)));\n if (polygon_info->edges == (EdgeInfo *) NULL)\n return((PolygonInfo *) NULL);\n }\n@@ -484,7 +484,7 @@ ConvertPathToPolygon(const PathInfo *pat\n {\n number_edges<<=1;\n MagickReallocMemory(EdgeInfo *,polygon_info->edges,\n- number_edges*sizeof(EdgeInfo));\n+ MagickArraySize(number_edges,sizeof(EdgeInfo)));\n if (polygon_info->edges == (EdgeInfo *) NULL)\n return((PolygonInfo *) NULL);\n }\n@@ -517,7 +517,7 @@ ConvertPathToPolygon(const PathInfo *pat\n if (n == number_points)\n {\n number_points<<=1;\n- MagickReallocMemory(PointInfo *,points,number_points*sizeof(PointInfo));\n+ MagickReallocMemory(PointInfo *,points,MagickArraySize(number_points,sizeof(PointInfo)));\n if (points == (PointInfo *) NULL)\n return((PolygonInfo *) NULL);\n }\n@@ -541,7 +541,7 @@ ConvertPathToPolygon(const PathInfo *pat\n {\n number_edges<<=1;\n MagickReallocMemory(EdgeInfo *,polygon_info->edges,\n- number_edges*sizeof(EdgeInfo));\n+ MagickArraySize(number_edges,sizeof(EdgeInfo)));\n if (polygon_info->edges == (EdgeInfo *) NULL)\n return((PolygonInfo *) NULL);\n }\n@@ -2309,7 +2309,7 @@ DrawImage(Image *image,const DrawInfo *d\n {\n n++;\n MagickReallocMemory(DrawInfo **,graphic_context,\n- (n+1)*sizeof(DrawInfo *));\n+ MagickArraySize((n+1),sizeof(DrawInfo *)));\n if (graphic_context == (DrawInfo **) NULL)\n {\n ThrowException3(&image->exception,ResourceLimitError,\n@@ -2671,7 +2671,7 @@ DrawImage(Image *image,const DrawInfo *d\n continue;\n number_points<<=1;\n MagickReallocMemory(PrimitiveInfo *,primitive_info,\n- number_points*sizeof(PrimitiveInfo));\n+ MagickArraySize(number_points,sizeof(PrimitiveInfo)));\n if (primitive_info == (PrimitiveInfo *) NULL)\n {\n ThrowException3(&image->exception,ResourceLimitError,\n@@ -2777,7 +2777,7 @@ DrawImage(Image *image,const DrawInfo *d\n {\n number_points+=length+1;\n MagickReallocMemory(PrimitiveInfo *,primitive_info,\n- number_points*sizeof(PrimitiveInfo));\n+ MagickArraySize(number_points,sizeof(PrimitiveInfo)));\n if (primitive_info == (PrimitiveInfo *) NULL)\n {\n ThrowException3(&image->exception,ResourceLimitError,\n@@ -5468,8 +5468,8 @@ TraceStrokePolygon(const DrawInfo *draw_\n if (q >= (max_strokes-6*BezierQuantum-360))\n {\n max_strokes+=6*BezierQuantum+360;\n- MagickReallocMemory(PointInfo *,path_p,max_strokes*sizeof(PointInfo));\n- MagickReallocMemory(PointInfo *,path_q,max_strokes*sizeof(PointInfo));\n+ MagickReallocMemory(PointInfo *,path_p,MagickArraySize(max_strokes,sizeof(PointInfo)));\n+ MagickReallocMemory(PointInfo *,path_q,MagickArraySize(max_strokes,sizeof(PointInfo)));\n if ((path_p == (PointInfo *) NULL) || (path_q == (PointInfo *) NULL))\n {\n MagickFreeMemory(polygon_primitive);"}], "metadata": {"id": "GraphicsMagick-5955-GraphicsMagick-CVE-2016-2317.p", "cve_id": "CVE-2016-9556", "package": "GraphicsMagick", "tier": "adapted", "has_source_context": false, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1h/apps/s_client.c\n- openssl-1.0.1h/apps/s_socket.c\n- openssl-1.0.1h.orig/apps/s_client.c\n- openssl-1.0.1h/apps/s_server.c\n- openssl-1.0.1h.orig/apps/s_server.c\n\n## Target Source Code\n\n### apps/s_apps.h\n\n#### region() [lines 109-177]\n```c\n *\n */\n#if !defined(OPENSSL_SYS_NETWARE) /* conflicts with winsock2 stuff on netware */\n#include \n#endif\n#include \n\n#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS)\n#include \n#endif\n\n#if defined(OPENSSL_SYS_MSDOS) && !defined(_WIN32)\n#define _kbhit kbhit\n#endif\n\n#if defined(OPENSSL_SYS_VMS) && !defined(FD_SET)\n/* VAX C does not defined fd_set and friends, but it's actually quite simple */\n/* These definitions are borrowed from SOCKETSHR.\t/Richard Levitte */\n#define MAX_NOFILE\t32\n#define\tNBBY\t\t 8\t\t/* number of bits in a byte\t*/\n\n#ifndef\tFD_SETSIZE\n#define\tFD_SETSIZE\tMAX_NOFILE\n#endif\t/* FD_SETSIZE */\n\n/* How many things we'll allow select to use. 0 if unlimited */\n#define MAXSELFD\tMAX_NOFILE\ntypedef int\tfd_mask;\t/* int here! VMS prototypes int, not long */\n#define NFDBITS\t(sizeof(fd_mask) * NBBY)\t/* bits per mask (power of 2!)*/\n#define NFDSHIFT 5\t\t\t\t/* Shift based on above */\n\ntypedef fd_mask fd_set;\n#define\tFD_SET(n, p)\t(*(p) |= (1 << ((n) % NFDBITS)))\n#define\tFD_CLR(n, p)\t(*(p) &= ~(1 << ((n) % NFDBITS)))\n#define\tFD_ISSET(n, p)\t(*(p) & (1 << ((n) % NFDBITS)))\n#define FD_ZERO(p)\tmemset((char *)(p), 0, sizeof(*(p)))\n#endif\n\n#define PORT 4433\n#define PORT_STR \"4433\"\n#define PROTOCOL \"tcp\"\n\nint do_server(int port, int type, int *ret, int (*cb) (char *hostname, int s, unsigned char *context), unsigned char *context);\n#ifdef HEADER_X509_H\nint MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx);\n#endif\n#ifdef HEADER_SSL_H\nint set_cert_stuff(SSL_CTX *ctx, char *cert_file, char *key_file);\nint set_cert_key_stuff(SSL_CTX *ctx, X509 *cert, EVP_PKEY *key);\n#endif\nint init_client(int *sock, char *server, int port, int type);\nint should_retry(int i);\nint extract_port(char *str, short *port_ptr);\nint extract_host_port(char *str,char **host_ptr,unsigned char *ip,short *p);\n\nlong MS_CALLBACK bio_dump_callback(BIO *bio, int cmd, const char *argp,\n\t\t\t\t int argi, long argl, long ret);\n\n#ifdef HEADER_SSL_H\nvoid MS_CALLBACK apps_ssl_info_callback(const SSL *s, int where, int ret);\nvoid MS_CALLBACK msg_cb(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg);\nvoid MS_CALLBACK tlsext_cb(SSL *s, int client_server, int type,\n\t\t\t\t\tunsigned char *data, int len,\n\t\t\t\t\tvoid *arg);\n#endif\n\nint MS_CALLBACK generate_cookie_callback(SSL *ssl, unsigned char *cookie, unsigned int *cookie_len);\nint MS_CALLBACK verify_cookie_callback(SSL *ssl, unsigned char *cookie, unsigned int cookie_len);\n\n```\n\n### apps/s_client.c\n\n#### MAIN() [lines 555-1926]\n```c\n\nint MAIN(int, char **);\n\nint MAIN(int argc, char **argv)\n\t{\n\tunsigned int off=0, clr=0;\n\tSSL *con=NULL;\n#ifndef OPENSSL_NO_KRB5\n\tKSSL_CTX *kctx;\n#endif\n\tint s,k,width,state=0;\n\tchar *cbuf=NULL,*sbuf=NULL,*mbuf=NULL;\n\tint cbuf_len,cbuf_off;\n\tint sbuf_len,sbuf_off;\n\tfd_set readfds,writefds;\n\tshort port=PORT;\n\tint full_log=1;\n\tchar *host=SSL_HOST_NAME;\n\tchar *cert_file=NULL,*key_file=NULL;\n\tint cert_format = FORMAT_PEM, key_format = FORMAT_PEM;\n\tchar *passarg = NULL, *pass = NULL;\n\tX509 *cert = NULL;\n\tEVP_PKEY *key = NULL;\n\tchar *CApath=NULL,*CAfile=NULL,*cipher=NULL;\n\tint reconnect=0,badop=0,verify=SSL_VERIFY_NONE,bugs=0;\n\tint crlf=0;\n\tint write_tty,read_tty,write_ssl,read_ssl,tty_on,ssl_pending;\n\tSSL_CTX *ctx=NULL;\n\tint ret=1,in_init=1,i,nbio_test=0;\n\tint starttls_proto = PROTO_OFF;\n\tint prexit = 0;\n\tX509_VERIFY_PARAM *vpm = NULL;\n\tint badarg = 0;\n\tconst SSL_METHOD *meth=NULL;\n\tint socket_type=SOCK_STREAM;\n\tBIO *sbio;\n\tchar *inrand=NULL;\n\tint mbuf_len=0;\n\tstruct timeval timeout, *timeoutp;\n#ifndef OPENSSL_NO_ENGINE\n/* ... 1322 lines omitted ... */\n\t\tX509_free(cert);\n\tif (key)\n\t\tEVP_PKEY_free(key);\n\tif (pass)\n\t\tOPENSSL_free(pass);\n\tif (vpm)\n\t\tX509_VERIFY_PARAM_free(vpm);\n\tif (cbuf != NULL) { OPENSSL_cleanse(cbuf,BUFSIZZ); OPENSSL_free(cbuf); }\n\tif (sbuf != NULL) { OPENSSL_cleanse(sbuf,BUFSIZZ); OPENSSL_free(sbuf); }\n\tif (mbuf != NULL) { OPENSSL_cleanse(mbuf,BUFSIZZ); OPENSSL_free(mbuf); }\n\tif (bio_c_out != NULL)\n\t\t{\n\t\tBIO_free(bio_c_out);\n\t\tbio_c_out=NULL;\n\t\t}\n\tapps_shutdown();\n\tOPENSSL_EXIT(ret);\n\t}\n\n\n```\n\n#### region() [lines 1228-1315]\n```c\n\t\t\tBIO_printf(bio_err, \"Can't open session file %s\\n\",\n\t\t\t\t\t\tsess_in);\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\tSSL_set_session(con, sess);\n\t\tSSL_SESSION_free(sess);\n\t\t}\n#ifndef OPENSSL_NO_TLSEXT\n\tif (servername != NULL)\n\t\t{\n\t\tif (!SSL_set_tlsext_host_name(con,servername))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,\"Unable to set TLS servername extension.\\n\");\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_KRB5\n\tif (con && (kctx = kssl_ctx_new()) != NULL)\n {\n\t\tSSL_set0_kssl_ctx(con, kctx);\n kssl_ctx_setstring(kctx, KSSL_SERVER, host);\n\t\t}\n#endif\t/* OPENSSL_NO_KRB5 */\n/*\tSSL_set_cipher_list(con,\"RC4-MD5\"); */\n#if 0\n#ifdef TLSEXT_TYPE_opaque_prf_input\n\tSSL_set_tlsext_opaque_prf_input(con, \"Test client\", 11);\n#endif\n#endif\n\nre_start:\n\n\tif (init_client(&s,host,port,socket_type) == 0)\n\t\t{\n\t\tBIO_printf(bio_err,\"connect:errno=%d\\n\",get_last_socket_error());\n\t\tSHUTDOWN(s);\n\t\tgoto end;\n\t\t}\n\tBIO_printf(bio_c_out,\"CONNECTED(%08X)\\n\",s);\n\n#ifdef FIONBIO\n\tif (c_nbio)\n\t\t{\n\t\tunsigned long l=1;\n\t\tBIO_printf(bio_c_out,\"turning on non blocking io\\n\");\n\t\tif (BIO_socket_ioctl(s,FIONBIO,&l) < 0)\n\t\t\t{\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n#endif \n\tif (c_Pause & 0x01) SSL_set_debug(con, 1);\n\n\tif ( SSL_version(con) == DTLS1_VERSION)\n\t\t{\n\n\t\tsbio=BIO_new_dgram(s,BIO_NOCLOSE);\n\t\tif (getsockname(s, &peer, (void *)&peerlen) < 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, \"getsockname:errno=%d\\n\",\n\t\t\t\tget_last_socket_error());\n\t\t\tSHUTDOWN(s);\n\t\t\tgoto end;\n\t\t\t}\n\n\t\t(void)BIO_ctrl_set_connec\n/* ... truncated ... */\n```\n\n### apps/s_server.c\n\n#### MAIN() [lines 929-1927]\n```c\nstatic char *srtp_profiles = NULL;\n#endif\n\nint MAIN(int argc, char *argv[])\n\t{\n\tX509_VERIFY_PARAM *vpm = NULL;\n\tint badarg = 0;\n\tshort port=PORT;\n\tchar *CApath=NULL,*CAfile=NULL;\n\tunsigned char *context = NULL;\n\tchar *dhfile = NULL;\n#ifndef OPENSSL_NO_ECDH\n\tchar *named_curve = NULL;\n#endif\n\tint badop=0,bugs=0;\n\tint ret=1;\n\tint off=0;\n\tint no_tmp_rsa=0,no_dhe=0,no_ecdhe=0,nocert=0;\n\tint state=0;\n\tconst SSL_METHOD *meth=NULL;\n\tint socket_type=SOCK_STREAM;\n\tENGINE *e=NULL;\n\tchar *inrand=NULL;\n\tint s_cert_format = FORMAT_PEM, s_key_format = FORMAT_PEM;\n\tchar *passarg = NULL, *pass = NULL;\n\tchar *dpassarg = NULL, *dpass = NULL;\n\tint s_dcert_format = FORMAT_PEM, s_dkey_format = FORMAT_PEM;\n\tX509 *s_cert = NULL, *s_dcert = NULL;\n\tEVP_PKEY *s_key = NULL, *s_dkey = NULL;\n\tint no_cache = 0;\n#ifndef OPENSSL_NO_TLSEXT\n\tEVP_PKEY *s_key2 = NULL;\n\tX509 *s_cert2 = NULL;\n tlsextctx tlsextcbp = {NULL, NULL, SSL_TLSEXT_ERR_ALERT_WARNING};\n# ifndef OPENSSL_NO_NEXTPROTONEG\n\tconst char *next_proto_neg_in = NULL;\n\ttlsextnextprotoctx next_proto;\n# endif\n#endif\n#ifndef OPENSSL_NO_PSK\n/* ... 952 lines omitted ... */\n\tif (tlscstatp.port)\n\t\tOPENSSL_free(tlscstatp.port);\n\tif (tlscstatp.path)\n\t\tOPENSSL_free(tlscstatp.path);\n\tif (ctx2 != NULL) SSL_CTX_free(ctx2);\n\tif (s_cert2)\n\t\tX509_free(s_cert2);\n\tif (s_key2)\n\t\tEVP_PKEY_free(s_key2);\n#endif\n\tif (bio_s_out != NULL)\n\t\t{\n BIO_free(bio_s_out);\n\t\tbio_s_out=NULL;\n\t\t}\n\tapps_shutdown();\n\tOPENSSL_EXIT(ret);\n\t}\n\nstatic void print_stats(BIO *bio, SSL_CTX *ssl_ctx)\n```\n\n#### region() [lines 1853-1942]\n```c\n#ifndef OPENSSL_NO_SRP\n\tif (srp_verifier_file != NULL)\n\t\t{\n\t\tsrp_callback_parm.vb = SRP_VBASE_new(srpuserseed);\n\t\tsrp_callback_parm.user = NULL;\n\t\tsrp_callback_parm.login = NULL;\n\t\tif ((ret = SRP_VBASE_init(srp_callback_parm.vb, srp_verifier_file)) != SRP_NO_ERROR)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,\n\t\t\t\t \"Cannot initialize SRP verifier file \\\"%s\\\":ret=%d\\n\",\n\t\t\t\t srp_verifier_file, ret);\n\t\t\t\tgoto end;\n\t\t\t}\n\t\tSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE,verify_callback);\n\t\tSSL_CTX_set_srp_cb_arg(ctx, &srp_callback_parm); \t\t\t\n\t\tSSL_CTX_set_srp_username_callback(ctx, ssl_srp_server_param_cb);\n\t\t}\n\telse\n#endif\n\tif (CAfile != NULL)\n\t\t{\n\t\tSSL_CTX_set_client_CA_list(ctx,SSL_load_client_CA_file(CAfile));\n#ifndef OPENSSL_NO_TLSEXT\n\t\tif (ctx2) \n\t\t\tSSL_CTX_set_client_CA_list(ctx2,SSL_load_client_CA_file(CAfile));\n#endif\n\t\t}\n\n\tBIO_printf(bio_s_out,\"ACCEPT\\n\");\n\t(void)BIO_flush(bio_s_out);\n\tif (www)\n\t\tdo_server(port,socket_type,&accept_socket,www_body, context);\n\telse\n\t\tdo_server(port,socket_type,&accept_socket,sv_body, context);\n\tprint_stats(bio_s_out,ctx);\n\tret=0;\nend:\n\tif (ctx != NULL) SSL_CTX_free(ctx);\n\tif (s_cert)\n\t\tX509_free(s_cert);\n\tif (s_dcert)\n\t\tX509_free(s_dcert);\n\tif (s_key)\n\t\tEVP_PKEY_free(s_key);\n\tif (s_dkey)\n\t\tEVP_PKEY_free(s_dkey);\n\tif (pass)\n\t\tOPENSSL_free(pass);\n\tif (dpass)\n\t\tOPENSSL_free(dpass);\n\tif (vpm)\n\t\tX509_VERIFY_PARAM_free(vpm);\n#ifndef OPENSSL_NO_TLSEXT\n\tif (tlscstatp.host)\n\t\tOPENSSL_free(tlscstatp.host);\n\tif (tlscstatp.port)\n\t\tOPENSSL_free(tlscstatp.port);\n\tif (tlscstatp.path)\n\t\tOPENSSL_free(tlscstatp.path);\n\tif (ctx2 != NULL) SSL_CTX_free(ctx2);\n\tif (s_cert2)\n\t\n/* ... truncated ... */\n```\n\n### apps/s_socket.c\n\n#### region() [lines 63-152]\n```c\n#include \n\n#ifdef FLAT_INC\n#include \"e_os2.h\"\n#else\n#include \"../e_os2.h\"\n#endif\n\n/* With IPv6, it looks like Digital has mixed up the proper order of\n recursive header file inclusion, resulting in the compiler complaining\n that u_int isn't defined, but only if _POSIX_C_SOURCE is defined, which\n is needed to have fileno() declared correctly... So let's define u_int */\n#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__U_INT)\n#define __U_INT\ntypedef unsigned int u_int;\n#endif\n\n#define USE_SOCKETS\n#define NON_MAIN\n#include \"apps.h\"\n#undef USE_SOCKETS\n#undef NON_MAIN\n#include \"s_apps.h\"\n#include \n\n#ifdef FLAT_INC\n#include \"e_os.h\"\n#else\n#include \"../e_os.h\"\n#endif\n\n#ifndef OPENSSL_NO_SOCK\n\n#if defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_BSDSOCK)\n#include \"netdb.h\"\n#endif\n\nstatic struct hostent *GetHostByName(char *name);\n#if defined(OPENSSL_SYS_WINDOWS) || (defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK))\nstatic void ssl_sock_cleanup(void);\n#endif\nstatic int ssl_sock_init(void);\nstatic int init_client_ip(int *sock,unsigned char ip[4], int port, int type);\nstatic int init_server(int *sock, int port, int type);\nstatic int init_server_long(int *sock, int port,char *ip, int type);\nstatic int do_accept(int acc_sock, int *sock, char **host);\nstatic int host_ip(char *str, unsigned char ip[4]);\n\n#ifdef OPENSSL_SYS_WIN16\n#define SOCKET_PROTOCOL\t0 /* more microsoft stupidity */\n#else\n#define SOCKET_PROTOCOL\tIPPROTO_TCP\n#endif\n\n#if defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK)\nstatic int wsa_init_done=0;\n#endif\n\n#ifdef OPENSSL_SYS_WINDOWS\nstatic struct WSAData wsa_state;\nstatic int wsa_init_done=0;\n\n#ifdef OPENSSL_SYS_WIN16\nstatic HWND topWnd=0;\nstatic FARPROC lpTopWndProc=NULL;\nstatic FARPROC lpTopHookProc=NULL;\nextern HINSTANCE _hInstance; /* nice global CRT provides */\n\nstatic LONG FAR PASCAL topHookProc(HWND hwnd, UINT message, WPARAM wParam,\n\t LPARAM lParam)\n\t{\n\tif (hwnd == topWnd)\n\t\t{\n\t\tswitch(message)\n\t\t\t{\n\t\tcase WM_DESTROY:\n\t\tcase WM_CLOSE:\n\t\t\tSetWindowLong(topWnd,GWL_WNDPROC,(LONG)lpTopWndProc);\n\t\t\tssl_sock_cleanup();\n\t\t\tbreak;\n\t\t\t}\n\t\t}\n\treturn CallWindowProc(lpTopWndProc,hwnd,message,wParam,lParam);\n\t}\n\nstatic BOOL CALLBACK enumproc(HWND hwnd,LPARAM lParam)\n\t{\n\ttopWnd=hwnd;\n\treturn(FALSE);\n\t}\n```\n\n#### ssl_sock_init() [lines 177-237]\n```c\n\t}\n#endif\n\nstatic int ssl_sock_init(void)\n\t{\n#ifdef WATT32\n\textern int _watt_do_exit;\n\t_watt_do_exit = 0;\n\tif (sock_init())\n\t\treturn (0);\n#elif defined(OPENSSL_SYS_WINDOWS)\n\tif (!wsa_init_done)\n\t\t{\n\t\tint err;\n\t \n#ifdef SIGINT\n\t\tsignal(SIGINT,(void (*)(int))ssl_sock_cleanup);\n#endif\n\t\twsa_init_done=1;\n\t\tmemset(&wsa_state,0,sizeof(wsa_state));\n\t\tif (WSAStartup(0x0101,&wsa_state)!=0)\n\t\t\t{\n\t\t\terr=WSAGetLastError();\n\t\t\tBIO_printf(bio_err,\"unable to start WINSOCK, error code=%d\\n\",err);\n\t\t\treturn(0);\n\t\t\t}\n\n#ifdef OPENSSL_SYS_WIN16\n\t\tEnumTaskWindows(GetCurrentTask(),enumproc,0L);\n\t\tlpTopWndProc=(FARPROC)GetWindowLong(topWnd,GWL_WNDPROC);\n\t\tlpTopHookProc=MakeProcInstance((FARPROC)topHookProc,_hInstance);\n\n\t\tSetWindowLong(topWnd,GWL_WNDPROC,(LONG)lpTopHookProc);\n#endif /* OPENSSL_SYS_WIN16 */\n\t\t}\n#elif defined(OPEN\n/* ... truncated ... */\n```\n\n\n## Upstream Fix\n```diff\nIndex: openssl-1.0.1h/apps/s_apps.h\n===================================================================\n--- openssl-1.0.1h.orig/apps/s_apps.h\n+++ openssl-1.0.1h/apps/s_apps.h\n@@ -148,7 +148,7 @@ typedef fd_mask fd_set;\n #define PORT_STR \"4433\"\n #define PROTOCOL \"tcp\"\n \n-int do_server(int port, int type, int *ret, int (*cb) (char *hostname, int s, unsigned char *context), unsigned char *context);\n+int do_server(char *port, int type, int *ret, int (*cb) (char *hostname, int s, unsigned char *context), unsigned char *context);\n #ifdef HEADER_X509_H\n int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx);\n #endif\n@@ -156,10 +156,9 @@ int MS_CALLBACK verify_callback(int ok,\n int set_cert_stuff(SSL_CTX *ctx, char *cert_file, char *key_file);\n int set_cert_key_stuff(SSL_CTX *ctx, X509 *cert, EVP_PKEY *key);\n #endif\n-int init_client(int *sock, char *server, int port, int type);\n+int init_client(int *sock, char *server, char *port, int type);\n int should_retry(int i);\n-int extract_port(char *str, short *port_ptr);\n-int extract_host_port(char *str,char **host_ptr,unsigned char *ip,short *p);\n+int extract_host_port(char *str,char **host_ptr,char **port_ptr);\n \n long MS_CALLBACK bio_dump_callback(BIO *bio, int cmd, const char *argp,\n \t\t\t\t int argi, long argl, long ret);\nIndex: openssl-1.0.1h/apps/s_client.c\n===================================================================\n--- openssl-1.0.1h.orig/apps/s_client.c\n+++ openssl-1.0.1h/apps/s_client.c\n@@ -567,7 +567,7 @@ int MAIN(int argc, char **argv)\n \tint cbuf_len,cbuf_off;\n \tint sbuf_len,sbuf_off;\n \tfd_set readfds,writefds;\n-\tshort port=PORT;\n+\tchar *port_str = PORT_STR;\n \tint full_log=1;\n \tchar *host=SSL_HOST_NAME;\n \tchar *cert_file=NULL,*key_file=NULL;\n@@ -668,13 +668,12 @@ int MAIN(int argc, char **argv)\n \t\telse if\t(strcmp(*argv,\"-port\") == 0)\n \t\t\t{\n \t\t\tif (--argc < 1) goto bad;\n-\t\t\tport=atoi(*(++argv));\n-\t\t\tif (port == 0) goto bad;\n+\t\t\tport_str= *(++argv);\n \t\t\t}\n \t\telse if (strcmp(*argv,\"-connect\") == 0)\n \t\t\t{\n \t\t\tif (--argc < 1) goto bad;\n-\t\t\tif (!extract_host_port(*(++argv),&host,NULL,&port))\n+\t\t\tif (!extract_host_port(*(++argv),&host,&port_str))\n \t\t\t\tgoto bad;\n \t\t\t}\n \t\telse if\t(strcmp(*argv,\"-verify\") == 0)\n@@ -1267,7 +1266,7 @@ bad:\n \n re_start:\n \n-\tif (init_client(&s,host,port,socket_type) == 0)\n+\tif (init_client(&s,host,port_str,socket_type) == 0)\n \t\t{\n \t\tBIO_printf(bio_err,\"connect:errno=%d\\n\",get_last_socket_error());\n \t\tSHUTDOWN(s);\nIndex: openssl-1.0.1h/apps/s_server.c\n===================================================================\n--- openssl-1.0.1h.orig/apps/s_server.c\n+++ openssl-1.0.1h/apps/s_server.c\n@@ -933,7 +933,7 @@ int MAIN(int argc, char *argv[])\n \t{\n \tX509_VERIFY_PARAM *vpm = NULL;\n \tint badarg = 0;\n-\tshort port=PORT;\n+\tchar *port_str = PORT_STR;\n \tchar *CApath=NULL,*CAfile=NULL;\n \tunsigned char *context = NULL;\n \tchar *dhfile = NULL;\n@@ -1004,8 +1004,7 @@ int MAIN(int argc, char *argv[])\n \t\t\t (strcmp(*argv,\"-accept\") == 0))\n \t\t\t{\n \t\t\tif (--argc < 1) goto bad;\n-\t\t\tif (!extract_port(*(++argv),&port))\n-\t\t\t\tgoto bad;\n+\t\t\tport_str= *(++argv);\n \t\t\t}\n \t\telse if\t(strcmp(*argv,\"-verify\") == 0)\n \t\t\t{\n@@ -1892,9 +1891,9 @@ bad:\n \tBIO_printf(bio_s_out,\"ACCEPT\\n\");\n \t(void)BIO_flush(bio_s_out);\n \tif (www)\n-\t\tdo_server(port,socket_type,&accept_socket,www_body, context);\n+\t\tdo_server(port_str,socket_type,&accept_socket,www_body, context);\n \telse\n-\t\tdo_server(port,socket_type,&accept_socket,sv_body, context);\n+\t\tdo_server(port_str,socket_type,&accept_socket,sv_body, context);\n \tprint_stats(bio_s_out,ctx);\n \tret=0;\n end:\nIndex: openssl-1.0.1h/apps/s_socket.c\n===================================================================\n--- openssl-1.0.1h.orig/apps/s_socket.c\n+++ openssl-1.0.1h/apps/s_socket.c\n@@ -102,9 +102,7 @@ static struct hostent *GetHostByName(cha\n static void ssl_sock_cleanup(void);\n #endif\n static int ssl_sock_init(void);\n-static int init_client_ip(int *sock,unsigned char ip[4], int port, int type);\n-static int init_server(int *sock, int port, int type);\n-static int init_server_long(int *sock, int port,char *ip, int type);\n+static int init_server(int *sock, char *port, int type);\n static int do_accept(int acc_sock, int *sock, char **host);\n static int host_ip(char *str, unsigned char ip[4]);\n \n@@ -234,57 +232,70 @@ static int ssl_sock_init(void)\n \treturn(1);\n \t}\n \n-int init_client(int *sock, char *host, int port, int type)\n+int init_client(int *sock, char *host, char *port, int type)\n \t{\n-\tunsigned char ip[4];\n-\n-\tmemset(ip, '\\0', sizeof ip);\n-\tif (!host_ip(host,&(ip[0])))\n-\t\treturn 0;\n-\treturn init_client_ip(sock,ip,port,type);\n-\t}\n-\n-static int init_client_ip(int *sock, unsigned char ip[4], int port, int type)\n-\t{\n-\tunsigned long addr;\n-\tstruct sockaddr_in them;\n-\tint s,i;\n+\tstruct addrinfo *res, *res0, hints;\n+\tchar * failed_call = NULL;\n+\tint s;\n+\tint e;\n \n \tif (!ssl_sock_init()) return(0);\n \n-\tmemset((char *)&them,0,sizeof(them));\n-\tthem.sin_family=AF_INET;\n-\tthem.sin_port=htons((unsigned short)port);\n-\taddr=(unsigned long)\n-\t\t((unsigned long)ip[0]<<24L)|\n-\t\t((unsigned long)ip[1]<<16L)|\n-\t\t((unsigned long)ip[2]<< 8L)|\n-\t\t((unsigned long)ip[3]);\n-\tthem.sin_addr.s_addr=htonl(addr);\n-\n-\tif (type == SOCK_STREAM)\n-\t\ts=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);\n-\telse /* ( type == SOCK_DGRAM) */\n-\t\ts=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);\n-\t\t\t\n-\tif (s == INVALID_SOCKET) { perror(\"socket\"); return(0); }\n+\tmemset(&hints, '\\0', sizeof(hints));\n+\thints.ai_socktype = type;\n+\thints.ai_flags = AI_ADDRCONFIG;\n+\n+\te = getaddrinfo(host, port, &hints, &res);\n+\tif (e)\n+\t{\n+\t\tfprintf(stderr, \"getaddrinfo: %s\\n\", gai_strerror(e));\n+\t\tif (e == EAI_SYSTEM)\n+\t\t\tperror(\"getaddrinfo\");\n+\t\treturn (0);\n+\t\t}\n \n+\tres0 = res;\n+\twhile (res)\n+\t\t{\n+\t\ts = socket(res->ai_family, res->ai_socktype, res->ai_protocol);\n+\t\tif (s == INVALID_SOCKET)\n+\t\t\t{\n+\t\t\tfailed_call = \"socket\";\n+\t\t\tgoto nextres;\n+\t\t\t}\n #if defined(SO_KEEPALIVE) && !defined(OPENSSL_SYS_MPE)\n \tif (type == SOCK_STREAM)\n \t\t{\n-\t\ti=0;\n-\t\ti=setsockopt(s,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i));\n-\t\tif (i < 0) { closesocket(s); perror(\"keepalive\"); return(0); }\n+\t\t\tint i=0;\n+\t\t\ti=setsockopt(s,SOL_SOCKET,SO_KEEPALIVE,\n+\t\t\t\t(char *)&i,sizeof(i));\n+\t\t\tif (i < 0) {\n+\t\t\t\tfailed_call = \"keepalive\";\n+\t\t\t\tgoto nextres;\n+\t\t\t\t}\n \t\t}\n #endif\n-\n-\tif (connect(s,(struct sockaddr *)&them,sizeof(them)) == -1)\n-\t\t{ closesocket(s); perror(\"connect\"); return(0); }\n+\t\tif (connect(s,(struct sockaddr *)res->ai_addr,\n+\t\t\tres->ai_addrlen) == 0)\n+\t\t\t{\n+\t\t\tfreeaddrinfo(res0);\n \t*sock=s;\n \treturn(1);\n \t}\n \n-int do_server(int port, int type, int *ret, int (*cb)(char *hostname, int s, unsigned char *context), unsigned char *context)\n+\t\tfailed_call = \"socket\";\n+nextres:\n+\t\tif (s != INVALID_SOCKET)\n+\t\t\tclose(s);\n+\t\tres = res->ai_next;\n+\t\t}\n+\tfreeaddrinfo(res0);\n+\n+\tperror(failed_call);\n+\treturn(0);\n+\t}\n+\n+int do_server(char *port, int type, int *ret, int (*cb)(char *hostname, int s, unsigned char *context), unsigned char *context)\n \t{\n \tint sock;\n \tchar *name = NULL;\n@@ -322,33 +333,50 @@ int do_server(int port, int type, int *r\n \t\t}\n \t}\n \n-static int init_server_long(int *sock, int port, char *ip, int type)\n+static int init_server(int *sock, char *port, int type)\n \t{\n-\tint ret=0;\n-\tstruct sockaddr_in server;\n-\tint s= -1;\n+\tstruct addrinfo *res, *res0 = NULL, hints;\n+\tchar * failed_call = NULL;\n+\tint s = INVALID_SOCKET;\n+\tint e;\n \n \tif (!ssl_sock_init()) return(0);\n \n-\tmemset((char *)&server,0,sizeof(server));\n-\tserver.sin_family=AF_INET;\n-\tserver.sin_port=htons((unsigned short)port);\n-\tif (ip == NULL)\n-\t\tserver.sin_addr.s_addr=INADDR_ANY;\n-\telse\n-/* Added for T3E, address-of fails on bit field (beckman@acl.lanl.gov) */\n-#ifndef BIT_FIELD_LIMITS\n-\t\tmemcpy(&server.sin_addr.s_addr,ip,4);\n-#else\n-\t\tmemcpy(&server.sin_addr,ip,4);\n-#endif\n+\tmemset(&hints, '\\0', sizeof(hints));\n+\thints.ai_family = AF_INET6;\n+tryipv4:\n+\thints.ai_socktype = type;\n+\thints.ai_flags = AI_PASSIVE;\n \t\n-\t\tif (type == SOCK_STREAM)\n-\t\t\ts=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);\n-\t\telse \n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "Index: openssl-1.0.1h/apps/s_apps.h\n===================================================================\n--- openssl-1.0.1h.orig/apps/s_apps.h\n+++ openssl-1.0.1h/apps/s_apps.h\n@@ -148,7 +148,7 @@ typedef fd_mask fd_set;\n #define PORT_STR \"4433\"\n #define PROTOCOL \"tcp\"\n \n-int do_server(int port, int type, int *ret, int (*cb) (char *hostname, int s, unsigned char *context), unsigned char *context);\n+int do_server(char *port, int type, int *ret, int (*cb) (char *hostname, int s, unsigned char *context), unsigned char *context);\n #ifdef HEADER_X509_H\n int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx);\n #endif\n@@ -156,10 +156,9 @@ int MS_CALLBACK verify_callback(int ok,\n int set_cert_stuff(SSL_CTX *ctx, char *cert_file, char *key_file);\n int set_cert_key_stuff(SSL_CTX *ctx, X509 *cert, EVP_PKEY *key);\n #endif\n-int init_client(int *sock, char *server, int port, int type);\n+int init_client(int *sock, char *server, char *port, int type);\n int should_retry(int i);\n-int extract_port(char *str, short *port_ptr);\n-int extract_host_port(char *str,char **host_ptr,unsigned char *ip,short *p);\n+int extract_host_port(char *str,char **host_ptr,char **port_ptr);\n \n long MS_CALLBACK bio_dump_callback(BIO *bio, int cmd, const char *argp,\n \t\t\t\t int argi, long argl, long ret);\nIndex: openssl-1.0.1h/apps/s_client.c\n===================================================================\n--- openssl-1.0.1h.orig/apps/s_client.c\n+++ openssl-1.0.1h/apps/s_client.c\n@@ -567,7 +567,7 @@ int MAIN(int argc, char **argv)\n \tint cbuf_len,cbuf_off;\n \tint sbuf_len,sbuf_off;\n \tfd_set readfds,writefds;\n-\tshort port=PORT;\n+\tchar *port_str = PORT_STR;\n \tint full_log=1;\n \tchar *host=SSL_HOST_NAME;\n \tchar *cert_file=NULL,*key_file=NULL;\n@@ -668,13 +668,12 @@ int MAIN(int argc, char **argv)\n \t\telse if\t(strcmp(*argv,\"-port\") == 0)\n \t\t\t{\n \t\t\tif (--argc < 1) goto bad;\n-\t\t\tport=atoi(*(++argv));\n-\t\t\tif (port == 0) goto bad;\n+\t\t\tport_str= *(++argv);\n \t\t\t}\n \t\telse if (strcmp(*argv,\"-connect\") == 0)\n \t\t\t{\n \t\t\tif (--argc < 1) goto bad;\n-\t\t\tif (!extract_host_port(*(++argv),&host,NULL,&port))\n+\t\t\tif (!extract_host_port(*(++argv),&host,&port_str))\n \t\t\t\tgoto bad;\n \t\t\t}\n \t\telse if\t(strcmp(*argv,\"-verify\") == 0)\n@@ -1267,7 +1266,7 @@ bad:\n \n re_start:\n \n-\tif (init_client(&s,host,port,socket_type) == 0)\n+\tif (init_client(&s,host,port_str,socket_type) == 0)\n \t\t{\n \t\tBIO_printf(bio_err,\"connect:errno=%d\\n\",get_last_socket_error());\n \t\tSHUTDOWN(s);\nIndex: openssl-1.0.1h/apps/s_server.c\n===================================================================\n--- openssl-1.0.1h.orig/apps/s_server.c\n+++ openssl-1.0.1h/apps/s_server.c\n@@ -933,7 +933,7 @@ int MAIN(int argc, char *argv[])\n \t{\n \tX509_VERIFY_PARAM *vpm = NULL;\n \tint badarg = 0;\n-\tshort port=PORT;\n+\tchar *port_str = PORT_STR;\n \tchar *CApath=NULL,*CAfile=NULL;\n \tunsigned char *context = NULL;\n \tchar *dhfile = NULL;\n@@ -1004,8 +1004,7 @@ int MAIN(int argc, char *argv[])\n \t\t\t (strcmp(*argv,\"-accept\") == 0))\n \t\t\t{\n \t\t\tif (--argc < 1) goto bad;\n-\t\t\tif (!extract_port(*(++argv),&port))\n-\t\t\t\tgoto bad;\n+\t\t\tport_str= *(++argv);\n \t\t\t}\n \t\telse if\t(strcmp(*argv,\"-verify\") == 0)\n \t\t\t{\n@@ -1892,9 +1891,9 @@ bad:\n \tBIO_printf(bio_s_out,\"ACCEPT\\n\");\n \t(void)BIO_flush(bio_s_out);\n \tif (www)\n-\t\tdo_server(port,socket_type,&accept_socket,www_body, context);\n+\t\tdo_server(port_str,socket_type,&accept_socket,www_body, context);\n \telse\n-\t\tdo_server(port,socket_type,&accept_socket,sv_body, context);\n+\t\tdo_server(port_str,socket_type,&accept_socket,sv_body, context);\n \tprint_stats(bio_s_out,ctx);\n \tret=0;\n end:\nIndex: openssl-1.0.1h/apps/s_socket.c\n===================================================================\n--- openssl-1.0.1h.orig/apps/s_socket.c\n+++ openssl-1.0.1h/apps/s_socket.c\n@@ -102,9 +102,7 @@ static struct hostent *GetHostByName(cha\n static void ssl_sock_cleanup(void);\n #endif\n static int ssl_sock_init(void);\n-static int init_client_ip(int *sock,unsigned char ip[4], int port, int type);\n-static int init_server(int *sock, int port, int type);\n-static int init_server_long(int *sock, int port,char *ip, int type);\n+static int init_server(int *sock, char *port, int type);\n static int do_accept(int acc_sock, int *sock, char **host);\n static int host_ip(char *str, unsigned char ip[4]);\n \n@@ -234,57 +232,70 @@ static int ssl_sock_init(void)\n \treturn(1);\n \t}\n \n-int init_client(int *sock, char *host, int port, int type)\n+int init_client(int *sock, char *host, char *port, int type)\n \t{\n-\tunsigned char ip[4];\n-\n-\tmemset(ip, '\\0', sizeof ip);\n-\tif (!host_ip(host,&(ip[0])))\n-\t\treturn 0;\n-\treturn init_client_ip(sock,ip,port,type);\n-\t}\n-\n-static int init_client_ip(int *sock, unsigned char ip[4], int port, int type)\n-\t{\n-\tunsigned long addr;\n-\tstruct sockaddr_in them;\n-\tint s,i;\n+\tstruct addrinfo *res, *res0, hints;\n+\tchar * failed_call = NULL;\n+\tint s;\n+\tint e;\n \n \tif (!ssl_sock_init()) return(0);\n \n-\tmemset((char *)&them,0,sizeof(them));\n-\tthem.sin_family=AF_INET;\n-\tthem.sin_port=htons((unsigned short)port);\n-\taddr=(unsigned long)\n-\t\t((unsigned long)ip[0]<<24L)|\n-\t\t((unsigned long)ip[1]<<16L)|\n-\t\t((unsigned long)ip[2]<< 8L)|\n-\t\t((unsigned long)ip[3]);\n-\tthem.sin_addr.s_addr=htonl(addr);\n-\n-\tif (type == SOCK_STREAM)\n-\t\ts=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);\n-\telse /* ( type == SOCK_DGRAM) */\n-\t\ts=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);\n-\t\t\t\n-\tif (s == INVALID_SOCKET) { perror(\"socket\"); return(0); }\n+\tmemset(&hints, '\\0', sizeof(hints));\n+\thints.ai_socktype = type;\n+\thints.ai_flags = AI_ADDRCONFIG;\n+\n+\te = getaddrinfo(host, port, &hints, &res);\n+\tif (e)\n+\t{\n+\t\tfprintf(stderr, \"getaddrinfo: %s\\n\", gai_strerror(e));\n+\t\tif (e == EAI_SYSTEM)\n+\t\t\tperror(\"getaddrinfo\");\n+\t\treturn (0);\n+\t\t}\n \n+\tres0 = res;\n+\twhile (res)\n+\t\t{\n+\t\ts = socket(res->ai_family, res->ai_socktype, res->ai_protocol);\n+\t\tif (s == INVALID_SOCKET)\n+\t\t\t{\n+\t\t\tfailed_call = \"socket\";\n+\t\t\tgoto nextres;\n+\t\t\t}\n #if defined(SO_KEEPALIVE) && !defined(OPENSSL_SYS_MPE)\n \tif (type == SOCK_STREAM)\n \t\t{\n-\t\ti=0;\n-\t\ti=setsockopt(s,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i));\n-\t\tif (i < 0) { closesocket(s); perror(\"keepalive\"); return(0); }\n+\t\t\tint i=0;\n+\t\t\ti=setsockopt(s,SOL_SOCKET,SO_KEEPALIVE,\n+\t\t\t\t(char *)&i,sizeof(i));\n+\t\t\tif (i < 0) {\n+\t\t\t\tfailed_call = \"keepalive\";\n+\t\t\t\tgoto nextres;\n+\t\t\t\t}\n \t\t}\n #endif\n-\n-\tif (connect(s,(struct sockaddr *)&them,sizeof(them)) == -1)\n-\t\t{ closesocket(s); perror(\"connect\"); return(0); }\n+\t\tif (connect(s,(struct sockaddr *)res->ai_addr,\n+\t\t\tres->ai_addrlen) == 0)\n+\t\t\t{\n+\t\t\tfreeaddrinfo(res0);\n \t*sock=s;\n \treturn(1);\n \t}\n \n-int do_server(int port, int type, int *ret, int (*cb)(char *hostname, int s, unsigned char *context), unsigned char *context)\n+\t\tfailed_call = \"socket\";\n+nextres:\n+\t\tif (s != INVALID_SOCKET)\n+\t\t\tclose(s);\n+\t\tres = res->ai_next;\n+\t\t}\n+\tfreeaddrinfo(res0);\n+\n+\tperror(failed_call);\n+\treturn(0);\n+\t}\n+\n+int do_server(char *port, int type, int *ret, int (*cb)(char *hostname, int s, unsigned char *context), unsigned char *context)\n \t{\n \tint sock;\n \tchar *name = NULL;\n@@ -322,33 +333,50 @@ int do_server(int port, int type, int *r\n \t\t}\n \t}\n \n-static int init_server_long(int *sock, int port, char *ip, int type)\n+static int init_server(int *sock, char *port, int type)\n \t{\n-\tint ret=0;\n-\tstruct sockaddr_in server;\n-\tint s= -1;\n+\tstruct addrinfo *res, *res0 = NULL, hints;\n+\tchar * failed_call = NULL;\n+\tint s = INVALID_SOCKET;\n+\tint e;\n \n \tif (!ssl_sock_init()) return(0);\n \n-\tmemset((char *)&server,0,sizeof(server));\n-\tserver.sin_family=AF_INET;\n-\tserver.sin_port=htons((unsigned short)port);\n-\tif (ip == NULL)\n-\t\tserver.sin_addr.s_addr=INADDR_ANY;\n-\telse\n-/* Added for T3E, address-of fails on bit field (beckman@acl.lanl.gov) */\n-#ifndef BIT_FIELD_LIMITS\n-\t\tmemcpy(&server.sin_addr.s_addr,ip,4);\n-#else\n-\t\tmemcpy(&server.sin_addr,ip,4);\n-#endif\n+\tmemset(&hints, '\\0', sizeof(hints));\n+\thints.ai_family = AF_INET6;\n+tryipv4:\n+\thints.ai_socktype = type;\n+\thints.ai_flags = AI_PASSIVE;\n \t\n-\t\tif (type == SOCK_STREAM)\n-\t\t\ts=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);\n-\t\telse /* type == SOCK_DGRAM */\n-\t\t\ts=socket(AF_INET, SOCK_DGRAM,IPPROTO_UDP);\n+\te = getaddrinfo(NULL, port, &hints, &res);\n+\tif (e)\n+\t\t{\n+\t\tif (hints.ai_family == AF_INET)\n+\t\t\t{\n+\t\t\tfprintf(stderr, \"getaddrinfo: %s\\n\", gai_strerror(e));\n+\t\t\tif (e == EAI_SYSTEM)\n+\t\t\t\tperror(\"getaddrinfo\");\n+\t\t\treturn (0);\n+\t\t\t}\n+\t\t\telse\n+\t\t\t\tres = NULL;\n+\t\t}\n \n-\tif (s == INVALID_SOCKET) goto err;\n+\tres0 = res;\n+\twhile (res)\n+\t\t{\n+\t\ts = socket(res->ai_family, res->ai_socktype, res->ai_protocol);\n+\t\tif (s == INVALID_SOCKET)\n+\t\t\t{\n+\t\t\tfailed_call = \"socket\";\n+\t\t\tgoto nextres;\n+\t\t\t}\n+\t\tif (hints.ai_family == AF_INET6)\n+\t\t\t{\n+\t\t\tint j = 0;\n+\t\t\tsetsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY,\n+\t\t\t\t (void *) &j, sizeof j);\n+\t\t\t}\n #if defined SOL_SOCKET && defined SO_REUSEADDR\n \t\t{\n \t\tint j = 1;\n@@ -356,35 +384,49 @@ static int init_server_long(int *sock, i\n \t\t\t (void *) &j, sizeof j);\n \t\t}\n #endif\n-\tif (bind(s,(struct sockaddr *)&server,sizeof(server)) == -1)\n+\n+\t\tif (bind(s,(struct sockaddr *)res->ai_addr, res->ai_addrlen) == -1)\n \t\t{\n-#ifndef OPENSSL_SYS_WINDOWS\n-\t\tperror(\"bind\");\n-#endif\n-\t\tgoto err;\n+\t\t\tfailed_call = \"bind\";\n+\t\t\tgoto nextres;\n \t\t}\n-\t/* Make it 128 for linux */\n-\tif (type==SOCK_STREAM && listen(s,128) == -1) goto err;\n-\t*sock=s;\n-\tret=1;\n-err:\n-\tif ((ret == 0) && (s != -1))\n+\t\tif (type==SOCK_STREAM && listen(s,128) == -1)\n \t\t{\n-\t\tSHUTDOWN(s);\n+\t\t\tfailed_call = \"listen\";\n+\t\t\tgoto nextres;\n \t\t}\n-\treturn(ret);\n+\n+\t\t*sock=s;\n+\t\treturn(1);\n+\n+nextres:\n+\t\tif (s != INVALID_SOCKET)\n+\t\t\tclose(s);\n+\t\tres = res->ai_next;\n \t}\n+\tif (res0)\n+\t\tfreeaddrinfo(res0);\n \n-static int init_server(int *sock, int port, int type)\n+\tif (s == INVALID_SOCKET)\n \t{\n-\treturn(init_server_long(sock, port, NULL, type));\n+\t\tif (hints.ai_family == AF_INET6)\n+\t\t{\n+\t\t\thints.ai_family = AF_INET;\n+\t\t\tgoto tryipv4;\n+\t\t}\n+\t\tperror(\"socket\");\n+\t\treturn(0);\n+\t}\n+\n+\tperror(failed_call);\n+\treturn(0);\n \t}\n \n static int do_accept(int acc_sock, int *sock, char **host)\n \t{\n+\tstatic struct sockaddr_storage from;\n+\tchar buffer[NI_MAXHOST];\n \tint ret;\n-\tstruct hostent *h1,*h2;\n-\tstatic struct sockaddr_in from;\n \tint len;\n /*\tstruct linger ling; */\n \n@@ -431,138 +473,59 @@ redoit:\n */\n \n \tif (host == NULL) goto end;\n-#ifndef BIT_FIELD_LIMITS\n-\t/* I should use WSAAsyncGetHostByName() under windows */\n-\th1=gethostbyaddr((char *)&from.sin_addr.s_addr,\n-\t\tsizeof(from.sin_addr.s_addr),AF_INET);\n-#else\n-\th1=gethostbyaddr((char *)&from.sin_addr,\n-\t\tsizeof(struct in_addr),AF_INET);\n-#endif\n-\tif (h1 == NULL)\n+\n+\tif (getnameinfo((struct sockaddr *)&from, sizeof(from),\n+\t\tbuffer, sizeof(buffer),\n+\t\tNULL, 0, 0))\n \t\t{\n-\t\tBIO_printf(bio_err,\"bad gethostbyaddr\\n\");\n+\t\tBIO_printf(bio_err,\"getnameinfo failed\\n\");\n \t\t*host=NULL;\n \t\t/* return(0); */\n \t\t}\n \telse\n \t\t{\n-\t\tif ((*host=(char *)OPENSSL_malloc(strlen(h1->h_name)+1)) == NULL)\n+\t\tif ((*host=(char *)OPENSSL_malloc(strlen(buffer)+1)) == NULL)\n \t\t\t{\n \t\t\tperror(\"OPENSSL_malloc\");\n \t\t\tclosesocket(ret);\n \t\t\treturn(0);\n \t\t\t}\n-\t\tBUF_strlcpy(*host,h1->h_name,strlen(h1->h_name)+1);\n-\n-\t\th2=GetHostByName(*host);\n-\t\tif (h2 == NULL)\n-\t\t\t{\n-\t\t\tBIO_printf(bio_err,\"gethostbyname failure\\n\");\n-\t\t\tclosesocket(ret);\n-\t\t\treturn(0);\n-\t\t\t}\n-\t\tif (h2->h_addrtype != AF_INET)\n-\t\t\t{\n-\t\t\tBIO_printf(bio_err,\"gethostbyname addr is not AF_INET\\n\");\n-\t\t\tclosesocket(ret);\n-\t\t\treturn(0);\n-\t\t\t}\n+\t\tstrcpy(*host, buffer);\n \t\t}\n end:\n \t*sock=ret;\n \treturn(1);\n \t}\n \n-int extract_host_port(char *str, char **host_ptr, unsigned char *ip,\n-\t short *port_ptr)\n+int extract_host_port(char *str, char **host_ptr, \n+\t char **port_ptr)\n \t{\n-\tchar *h,*p;\n+\tchar *h,*p,*x;\n \n-\th=str;\n-\tp=strchr(str,':');\n+\tx=h=str;\n+\tif (*h == '[')\n+\t\t{\n+\t\th++;\n+\t\tp=strchr(h,']');\n \tif (p == NULL)\n \t\t{\n-\t\tBIO_printf(bio_err,\"no port defined\\n\");\n+\t\t\tBIO_printf(bio_err,\"no ending bracket for IPv6 address\\n\");\n \t\treturn(0);\n \t\t}\n \t*(p++)='\\0';\n-\n-\tif ((ip != NULL) && !host_ip(str,ip))\n-\t\tgoto err;\n-\tif (host_ptr != NULL) *host_ptr=h;\n-\n-\tif (!extract_port(p,port_ptr))\n-\t\tgoto err;\n-\treturn(1);\n-err:\n-\treturn(0);\n+\t\tx = p;\n \t}\n-\n-static int host_ip(char *str, unsigned char ip[4])\n-\t{\n-\tunsigned int in[4]; \n-\tint i;\n-\n-\tif (sscanf(str,\"%u.%u.%u.%u\",&(in[0]),&(in[1]),&(in[2]),&(in[3])) == 4)\n-\t\t{\n-\t\tfor (i=0; i<4; i++)\n-\t\t\tif (in[i] > 255)\n-\t\t\t\t{\n-\t\t\t\tBIO_printf(bio_err,\"invalid IP address\\n\");\n-\t\t\t\tgoto err;\n-\t\t\t\t}\n-\t\tip[0]=in[0];\n-\t\tip[1]=in[1];\n-\t\tip[2]=in[2];\n-\t\tip[3]=in[3];\n-\t\t}\n-\telse\n-\t\t{ /* do a gethostbyname */\n-\t\tstruct hostent *he;\n-\n-\t\tif (!ssl_sock_init()) return(0);\n-\n-\t\the=GetHostByName(str);\n-\t\tif (he == NULL)\n-\t\t\t{\n-\t\t\tBIO_printf(bio_err,\"gethostbyname failure\\n\");\n-\t\t\tgoto err;\n-\t\t\t}\n-\t\t/* cast to short because of win16 winsock definition */\n-\t\tif ((short)he->h_addrtype != AF_INET)\n+\tp=strchr(x,':');\n+\tif (p == NULL)\n \t\t\t{\n-\t\t\tBIO_printf(bio_err,\"gethostbyname addr is not AF_INET\\n\");\n-\t\t\treturn(0);\n-\t\t\t}\n-\t\tip[0]=he->h_addr_list[0][0];\n-\t\tip[1]=he->h_addr_list[0][1];\n-\t\tip[2]=he->h_addr_list[0][2];\n-\t\tip[3]=he->h_addr_list[0][3];\n-\t\t}\n-\treturn(1);\n-err:\n+\t\tBIO_printf(bio_err,\"no port defined\\n\");\n \treturn(0);\n \t}\n+\t*(p++)='\\0';\n \n-int extract_port(char *str, short *port_ptr)\n-\t{\n-\tint i;\n-\tstruct servent *s;\n+\tif (host_ptr != NULL) *host_ptr=h;\n+\tif (port_ptr != NULL) *port_ptr=p;\n \n-\ti=atoi(str);\n-\tif (i != 0)\n-\t\t*port_ptr=(unsigned short)i;\n-\telse\n-\t\t{\n-\t\ts=getservbyname(str,\"tcp\");\n-\t\tif (s == NULL)\n-\t\t\t{\n-\t\t\tBIO_printf(bio_err,\"getservbyname failure for %s\\n\",str);\n-\t\t\treturn(0);\n-\t\t\t}\n-\t\t*port_ptr=ntohs((unsigned short)s->s_port);\n-\t\t}\n \treturn(1);\n \t}"}], "metadata": {"id": "openssl-4598-openssl-1.0.1c-ipv6-apps.patch", "cve_id": "CVE-2015-3197", "package": "openssl", "tier": "adapted", "has_source_context": true, "context_tokens_est": 3075, "context_files": 4, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-4658\n\nxpointer.c in libxml2 before 2.9.5 (as used in Apple iOS before 10, OS X before 10.12, tvOS before 10, and watchOS before 3, and other products) does not forbid namespace nodes in XPointer ranges, which allows remote attackers to execute arbitrary code or cause a denial of service (use-after-free and memory corruption) via a crafted XML document.\n\n## Package\nlibxml2\n\n## Files to modify\n- parser.c\n- libxml2-2.9.1.orig/parser.c\n\n## Target Source Code\n\n### parser.c\n\n#### xmlParseStartTag2() [lines 9251-7078]\n```c\n\n```\n\n#### region() [lines 9270-7078]\n```c\n\n```\n\n#### region() [lines 9295-7078]\n```c\n\n```\n\n#### region() [lines 9306-7078]\n```c\n\n```\n\n#### region() [lines 9435-7078]\n```c\n\n```\n\n#### region() [lines 9472-7078]\n```c\n\n```\n\n#### region() [lines 9488-7078]\n```c\n\n```\n\n#### region() [lines 9655-7078]\n```c\n\n```\n\n\n## Upstream Fix\n```diff\nFrom f1063fdbe7fa66332bbb76874101c2a7b51b519f Mon Sep 17 00:00:00 2001\nFrom: Daniel Veillard \nDate: Fri, 20 Nov 2015 16:06:59 +0800\nSubject: [PATCH] CVE-2015-7500 Fix memory access error due to incorrect\n entities boundaries\n\nFor https://bugzilla.gnome.org/show_bug.cgi?id=756525\nhandle properly the case where we popped out of the current entity\nwhile processing a start tag\nReported by Kostya Serebryany @ Google\n\nThis slightly modifies the output of 754946 in regression tests\n---\n parser.c | 28 ++++++++++++++++++++++------\n result/errors/754946.xml.err | 7 +++++--\n 2 files changed, 27 insertions(+), 8 deletions(-)\n\ndiff --git a/parser.c b/parser.c\nindex c7e4574b48..c5741e3b8c 100644\n--- a/parser.c\n+++ b/parser.c\n@@ -9348,7 +9348,7 @@ xmlParseStartTag2(xmlParserCtxtPtr ctxt, const xmlChar **pref,\n const xmlChar **atts = ctxt->atts;\n int maxatts = ctxt->maxatts;\n int nratts, nbatts, nbdef;\n- int i, j, nbNs, attval, oldline, oldcol;\n+ int i, j, nbNs, attval, oldline, oldcol, inputNr;\n const xmlChar *base;\n unsigned long cur;\n int nsNr = ctxt->nsNr;\n@@ -9367,6 +9367,7 @@ xmlParseStartTag2(xmlParserCtxtPtr ctxt, const xmlChar **pref,\n SHRINK;\n base = ctxt->input->base;\n cur = ctxt->input->cur - ctxt->input->base;\n+ inputNr = ctxt->inputNr;\n oldline = ctxt->input->line;\n oldcol = ctxt->input->col;\n nbatts = 0;\n@@ -9392,7 +9393,8 @@ xmlParseStartTag2(xmlParserCtxtPtr ctxt, const xmlChar **pref,\n */\n SKIP_BLANKS;\n GROW;\n- if (ctxt->input->base != base) goto base_changed;\n+ if ((ctxt->input->base != base) || (inputNr != ctxt->inputNr))\n+ goto base_changed;\n \n while (((RAW != '>') &&\n \t ((RAW != '/') || (NXT(1) != '>')) &&\n@@ -9403,7 +9405,7 @@ xmlParseStartTag2(xmlParserCtxtPtr ctxt, const xmlChar **pref,\n \n \tattname = xmlParseAttribute2(ctxt, prefix, localname,\n \t &aprefix, &attvalue, &len, &alloc);\n-\tif (ctxt->input->base != base) {\n+\tif ((ctxt->input->base != base) || (inputNr != ctxt->inputNr)) {\n \t if ((attvalue != NULL) && (alloc != 0))\n \t xmlFree(attvalue);\n \t attvalue = NULL;\n@@ -9552,7 +9554,8 @@ xmlParseStartTag2(xmlParserCtxtPtr ctxt, const xmlChar **pref,\n \t\t break;\n \t\t}\n \t\tSKIP_BLANKS;\n-\t\tif (ctxt->input->base != base) goto base_changed;\n+\t\tif ((ctxt->input->base != base) || (inputNr != ctxt->inputNr))\n+\t\t goto base_changed;\n \t\tcontinue;\n \t }\n \n@@ -9589,7 +9592,8 @@ xmlParseStartTag2(xmlParserCtxtPtr ctxt, const xmlChar **pref,\n \tGROW\n if (ctxt->instate == XML_PARSER_EOF)\n break;\n-\tif (ctxt->input->base != base) goto base_changed;\n+\tif ((ctxt->input->base != base) || (inputNr != ctxt->inputNr))\n+\t goto base_changed;\n \tif ((RAW == '>') || (((RAW == '/') && (NXT(1) == '>'))))\n \t break;\n \tif (!IS_BLANK_CH(RAW)) {\n@@ -9605,7 +9609,8 @@ xmlParseStartTag2(xmlParserCtxtPtr ctxt, const xmlChar **pref,\n \t break;\n \t}\n GROW;\n-\tif (ctxt->input->base != base) goto base_changed;\n+\tif ((ctxt->input->base != base) || (inputNr != ctxt->inputNr))\n+\t goto base_changed;\n }\n \n /*\n@@ -9772,6 +9777,17 @@ xmlParseStartTag2(xmlParserCtxtPtr ctxt, const xmlChar **pref,\n \t if ((ctxt->attallocs[j] != 0) && (atts[i] != NULL))\n \t xmlFree((xmlChar *) atts[i]);\n }\n+\n+ /*\n+ * We can't switch from one entity to another in the middle\n+ * of a start tag\n+ */\n+ if (inputNr != ctxt->inputNr) {\n+ xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,\n+\t\t \"Start tag doesn't start and stop in the same entity\\n\");\n+\treturn(NULL);\n+ }\n+\n ctxt->input->cur = ctxt->input->base + cur;\n ctxt->input->line = oldline;\n ctxt->input->col = oldcol;\ndiff --git a/result/errors/754946.xml.err b/result/errors/754946.xml.err\nindex 423dff5665..a75088b982 100644\n--- a/result/errors/754946.xml.err\n+++ b/result/errors/754946.xml.err\n@@ -11,6 +11,9 @@ Entity: line 1: parser error : DOCTYPE improperly terminated\n Entity: line 1: \n A%SYSTEM;%SYSTEM;\nDate: Fri, 20 Nov 2015 16:06:59 +0800\nSubject: CVE-2015-7500 Fix memory access error due to incorrect entities\n boundaries\n\nFor https://bugzilla.gnome.org/show_bug.cgi?id=756525\nhandle properly the case where we popped out of the current entity\nwhile processing a start tag\nReported by Kostya Serebryany @ Google\n\nThis slightly modifies the output of 754946 in regression tests\n---\n parser.c | 28 ++++++++++++++++++++++------\n result/errors/754946.xml.err | 7 +++++--\n 2 files changed, 27 insertions(+), 8 deletions(-)\n\nIndex: libxml2-2.9.1/parser.c\n===================================================================\n--- libxml2-2.9.1.orig/parser.c\n+++ libxml2-2.9.1/parser.c\n@@ -9290,7 +9290,7 @@ xmlParseStartTag2(xmlParserCtxtPtr ctxt,\n const xmlChar **atts = ctxt->atts;\n int maxatts = ctxt->maxatts;\n int nratts, nbatts, nbdef;\n- int i, j, nbNs, attval, oldline, oldcol;\n+ int i, j, nbNs, attval, oldline, oldcol, inputNr;\n const xmlChar *base;\n unsigned long cur;\n int nsNr = ctxt->nsNr;\n@@ -9309,6 +9309,7 @@ reparse:\n SHRINK;\n base = ctxt->input->base;\n cur = ctxt->input->cur - ctxt->input->base;\n+ inputNr = ctxt->inputNr;\n oldline = ctxt->input->line;\n oldcol = ctxt->input->col;\n nbatts = 0;\n@@ -9334,7 +9335,8 @@ reparse:\n */\n SKIP_BLANKS;\n GROW;\n- if (ctxt->input->base != base) goto base_changed;\n+ if ((ctxt->input->base != base) || (inputNr != ctxt->inputNr))\n+ goto base_changed;\n \n while (((RAW != '>') &&\n \t ((RAW != '/') || (NXT(1) != '>')) &&\n@@ -9345,7 +9347,7 @@ reparse:\n \n \tattname = xmlParseAttribute2(ctxt, prefix, localname,\n \t &aprefix, &attvalue, &len, &alloc);\n-\tif (ctxt->input->base != base) {\n+\tif ((ctxt->input->base != base) || (inputNr != ctxt->inputNr)) {\n \t if ((attvalue != NULL) && (alloc != 0))\n \t xmlFree(attvalue);\n \t attvalue = NULL;\n@@ -9474,7 +9476,8 @@ skip_default_ns:\n skip_ns:\n \t\tif (alloc != 0) xmlFree(attvalue);\n \t\tSKIP_BLANKS;\n-\t\tif (ctxt->input->base != base) goto base_changed;\n+\t\tif ((ctxt->input->base != base) || (inputNr != ctxt->inputNr))\n+\t\t goto base_changed;\n \t\tcontinue;\n \t }\n \n@@ -9511,7 +9514,8 @@ failed:\n \tGROW\n if (ctxt->instate == XML_PARSER_EOF)\n break;\n-\tif (ctxt->input->base != base) goto base_changed;\n+\tif ((ctxt->input->base != base) || (inputNr != ctxt->inputNr))\n+\t goto base_changed;\n \tif ((RAW == '>') || (((RAW == '/') && (NXT(1) == '>'))))\n \t break;\n \tif (!IS_BLANK_CH(RAW)) {\n@@ -9527,7 +9531,8 @@ failed:\n \t break;\n \t}\n GROW;\n-\tif (ctxt->input->base != base) goto base_changed;\n+\tif ((ctxt->input->base != base) || (inputNr != ctxt->inputNr))\n+\t goto base_changed;\n }\n \n /*\n@@ -9694,6 +9699,17 @@ base_changed:\n \t if ((ctxt->attallocs[j] != 0) && (atts[i] != NULL))\n \t xmlFree((xmlChar *) atts[i]);\n }\n+\n+ /*\n+ * We can't switch from one entity to another in the middle\n+ * of a start tag\n+ */\n+ if (inputNr != ctxt->inputNr) {\n+ xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,\n+\t\t \"Start tag doesn't start and stop in the same entity\\n\");\n+\treturn(NULL);\n+ }\n+\n ctxt->input->cur = ctxt->input->base + cur;\n ctxt->input->line = oldline;\n ctxt->input->col = oldcol;"}], "metadata": {"id": "libxml2-5762-libxml2-2.9.1-CVE-2015-7500.pa", "cve_id": "CVE-2016-4658", "package": "libxml2", "upstream_enriched": true, "upstream_commit": "f1063fdbe7fa66332bbb76874101c2a7b51b519f", "upstream_repo": "GNOME/libxml2", "tier": "adapted", "has_source_context": true, "context_tokens_est": 92, "context_files": 1, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-6250\n\nInteger overflow in the ISO9660 writer in libarchive before 3.2.1 allows remote attackers to cause a denial of service (application crash) or execute arbitrary code via vectors related to verifying filename lengths when writing an ISO9660 archive, which trigger a buffer overflow.\n\n## Package\nlibarchive\n\n## Files to modify\n- libarchive-3.1.2.orig/libarchive/archive_read_support_format_7zip.c\n- libarchive/archive_read_support_format_7zip.c\n\n## Target Source Code\n\n### libarchive/archive_read_support_format_7zip.c\n\n#### read_Header() [lines 2231-2546]\n```c\n}\n\nstatic int\nread_Header(struct archive_read *a, struct _7z_header_info *h,\n int check_header_id)\n{\n\tstruct _7zip *zip = (struct _7zip *)a->format->data;\n\tconst unsigned char *p;\n\tstruct _7z_folder *folders;\n\tstruct _7z_stream_info *si = &(zip->si);\n\tstruct _7zip_entry *entries;\n\tuint32_t folderIndex, indexInFolder;\n\tunsigned i;\n\tint eindex, empty_streams, sindex;\n\n\tif (check_header_id) {\n\t\t/*\n\t\t * Read Header.\n\t\t */\n\t\tif ((p = header_bytes(a, 1)) == NULL)\n\t\t\treturn (-1);\n\t\tif (*p != kHeader)\n\t\t\treturn (-1);\n\t}\n\n\t/*\n\t * Read ArchiveProperties.\n\t */\n\tif ((p = header_bytes(a, 1)) == NULL)\n\t\treturn (-1);\n\tif (*p == kArchiveProperties) {\n\t\tfor (;;) {\n\t\t\tuint64_t size;\n\t\t\tif ((p = header_bytes(a, 1)) == NULL)\n\t\t\t\treturn (-1);\n\t\t\tif (*p == 0)\n\t\t\t\tbreak;\n\t\t\tif (parse_7zip_uint64(a, &size) < 0)\n\t\t\t\treturn (-1);\n\t\t}\n/* ... 57 lines omitted ... */\n\t\t\t a, h->emptyStreamBools, (size_t)zip->numFiles) < 0)\n\t\t\t\treturn (-1);\n\t\t\tempty_streams = 0;\n\t\t\tfor (i = 0; i < zip->numFiles; i++) {\n\t\t\t\tif (h->emptyStreamBools[i])\n\t\t\t\t\tempty_streams++;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase kEmptyFile:\n\t\t\tif (empty_streams <= 0) {\n\t\t\t\t/* Unexcepted sequence. Skip this. */\n\t\t\t\tif (header_bytes(a, ll) == NULL)\n\t\t\t\t\treturn (-1);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\th->emptyFileBools = calloc(empty_streams,\n\t\t\t sizeof(*h->emptyFileBools));\n\t\t\tif (h->emptyFileBools == NULL)\n\t\t\t\treturn (-1);\n\t\t\tif (read_Bools(a, h->emptyFileBools, empty_streams) < 0)\n\t\t\t\treturn (-1);\n\t\t\tbreak;\n\t\tcase kAnti:\n\t\t\tif (empty_streams <= 0) {\n\t\t\t\t/* Unexcepted sequence. Skip this. */\n\t\t\t\tif (header_bytes(a, ll) == NULL)\n/* ... 173 lines omitted ... */\n\t\t\t\t\treturn (-1);\n\t\t\t\tif (folders[folderIndex].numUnpackStreams)\n\t\t\t\t\tbreak;\n\t\t\t\tfolderIndex++;\n\t\t\t}\n\t\t}\n\t\tentries[i].folderIndex = folderIndex;\n\t\tif ((entries[i].flg & HAS_STREAM) == 0)\n\t\t\tcontinue;\n\t\tindexInFolder++;\n\t\tif (indexInFolder >= folders[folderIndex].numUnpackStreams) {\n\t\t\tfolderIndex++;\n\t\t\tindexInFolder = 0;\n\t\t}\n\t}\n\n\treturn (0);\n}\n\n#define EPOC_TIME ARCHIVE_LITERAL_ULL(116444736000000000)\n```\n\n\n## Upstream Fix\n```diff\ncommit 7f17c791dcfd8c0416e2cd2485b19410e47ef126\nAuthor: Tim Kientzle \nDate: Sun Sep 18 18:14:58 2016 -0700\n\n Issue 761: Heap overflow reading corrupted 7Zip files\n \n The sample file that demonstrated this had multiple 'EmptyStream'\n attributes. The first one ended up being used to calculate\n certain statistics, then was overwritten by the second which\n was incompatible with those statistics.\n \n The fix here is to reject any header with multiple EmptyStream\n attributes. While here, also reject headers with multiple\n EmptyFile, AntiFile, Name, or Attributes markers.\n\nIndex: libarchive-3.1.2/libarchive/archive_read_support_format_7zip.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_read_support_format_7zip.c\n+++ libarchive-3.1.2/libarchive/archive_read_support_format_7zip.c\n@@ -2337,6 +2337,8 @@ read_Header(struct archive_read *a, stru\n \n \t\tswitch (type) {\n \t\tcase kEmptyStream:\n+\t\t\tif (h->emptyStreamBools != NULL)\n+\t\t\t\treturn (-1);\n \t\t\th->emptyStreamBools = calloc((size_t)zip->numFiles,\n \t\t\t sizeof(*h->emptyStreamBools));\n \t\t\tif (h->emptyStreamBools == NULL)\n@@ -2357,6 +2359,8 @@ read_Header(struct archive_read *a, stru\n \t\t\t\t\treturn (-1);\n \t\t\t\tbreak;\n \t\t\t}\n+\t\t\tif (h->emptyFileBools != NULL)\n+\t\t\t\treturn (-1);\n \t\t\th->emptyFileBools = calloc(empty_streams,\n \t\t\t sizeof(*h->emptyFileBools));\n \t\t\tif (h->emptyFileBools == NULL)\n@@ -2371,6 +2375,8 @@ read_Header(struct archive_read *a, stru\n \t\t\t\t\treturn (-1);\n \t\t\t\tbreak;\n \t\t\t}\n+\t\t\tif (h->antiBools != NULL)\n+\t\t\t\treturn (-1);\n \t\t\th->antiBools = calloc(empty_streams,\n \t\t\t sizeof(*h->antiBools));\n \t\t\tif (h->antiBools == NULL)\n@@ -2397,6 +2403,8 @@ read_Header(struct archive_read *a, stru\n \t\t\tif ((ll & 1) || ll < zip->numFiles * 4)\n \t\t\t\treturn (-1);\n \n+\t\t\tif (zip->entry_names != NULL)\n+\t\t\t\treturn (-1);\n \t\t\tzip->entry_names = malloc(ll);\n \t\t\tif (zip->entry_names == NULL)\n \t\t\t\treturn (-1);\n@@ -2449,6 +2457,8 @@ read_Header(struct archive_read *a, stru\n \t\t\tif ((p = header_bytes(a, 2)) == NULL)\n \t\t\t\treturn (-1);\n \t\t\tallAreDefined = *p;\n+\t\t\tif (h->attrBools != NULL)\n+\t\t\t\treturn (-1);\n \t\t\th->attrBools = calloc((size_t)zip->numFiles,\n \t\t\t sizeof(*h->attrBools));\n \t\t\tif (h->attrBools == NULL)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "commit 7f17c791dcfd8c0416e2cd2485b19410e47ef126\nAuthor: Tim Kientzle \nDate: Sun Sep 18 18:14:58 2016 -0700\n\n Issue 761: Heap overflow reading corrupted 7Zip files\n \n The sample file that demonstrated this had multiple 'EmptyStream'\n attributes. The first one ended up being used to calculate\n certain statistics, then was overwritten by the second which\n was incompatible with those statistics.\n \n The fix here is to reject any header with multiple EmptyStream\n attributes. While here, also reject headers with multiple\n EmptyFile, AntiFile, Name, or Attributes markers.\n\nIndex: libarchive-3.1.2/libarchive/archive_read_support_format_7zip.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_read_support_format_7zip.c\n+++ libarchive-3.1.2/libarchive/archive_read_support_format_7zip.c\n@@ -2337,6 +2337,8 @@ read_Header(struct archive_read *a, stru\n \n \t\tswitch (type) {\n \t\tcase kEmptyStream:\n+\t\t\tif (h->emptyStreamBools != NULL)\n+\t\t\t\treturn (-1);\n \t\t\th->emptyStreamBools = calloc((size_t)zip->numFiles,\n \t\t\t sizeof(*h->emptyStreamBools));\n \t\t\tif (h->emptyStreamBools == NULL)\n@@ -2357,6 +2359,8 @@ read_Header(struct archive_read *a, stru\n \t\t\t\t\treturn (-1);\n \t\t\t\tbreak;\n \t\t\t}\n+\t\t\tif (h->emptyFileBools != NULL)\n+\t\t\t\treturn (-1);\n \t\t\th->emptyFileBools = calloc(empty_streams,\n \t\t\t sizeof(*h->emptyFileBools));\n \t\t\tif (h->emptyFileBools == NULL)\n@@ -2371,6 +2375,8 @@ read_Header(struct archive_read *a, stru\n \t\t\t\t\treturn (-1);\n \t\t\t\tbreak;\n \t\t\t}\n+\t\t\tif (h->antiBools != NULL)\n+\t\t\t\treturn (-1);\n \t\t\th->antiBools = calloc(empty_streams,\n \t\t\t sizeof(*h->antiBools));\n \t\t\tif (h->antiBools == NULL)\n@@ -2397,6 +2403,8 @@ read_Header(struct archive_read *a, stru\n \t\t\tif ((ll & 1) || ll < zip->numFiles * 4)\n \t\t\t\treturn (-1);\n \n+\t\t\tif (zip->entry_names != NULL)\n+\t\t\t\treturn (-1);\n \t\t\tzip->entry_names = malloc(ll);\n \t\t\tif (zip->entry_names == NULL)\n \t\t\t\treturn (-1);\n@@ -2449,6 +2457,8 @@ read_Header(struct archive_read *a, stru\n \t\t\tif ((p = header_bytes(a, 2)) == NULL)\n \t\t\t\treturn (-1);\n \t\t\tallAreDefined = *p;\n+\t\t\tif (h->attrBools != NULL)\n+\t\t\t\treturn (-1);\n \t\t\th->attrBools = calloc((size_t)zip->numFiles,\n \t\t\t sizeof(*h->attrBools));\n \t\t\tif (h->attrBools == NULL)"}], "metadata": {"id": "libarchive-5940-CVE-2016-8689.patch", "cve_id": "CVE-2016-6250", "package": "libarchive", "tier": "identical", "has_source_context": true, "context_tokens_est": 524, "context_files": 1, "license": "BSD-2-Clause"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2012-2142\n\nThe error function in Error.cc in poppler before 0.21.4 allows remote attackers to execute arbitrary commands via a PDF containing an escape sequence for a terminal emulator.\n\n## Package\npoppler\n\n## Upstream Fix\n```diff\nFrom dcbc923bd3592a81876f84005fbaddcea18641cc Mon Sep 17 00:00:00 2001\nFrom: Thomas Freitag \nDate: Sun, 22 Jul 2012 16:40:46 +0000\nSubject: Make sure xScale and yScale are always initialized\n\nBug #52215\n---\n(limited to 'poppler/PSOutputDev.cc')\n\ndiff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc\nindex a01a4b3..e15c2e9 100644\n--- a/poppler/PSOutputDev.cc\n+++ b/poppler/PSOutputDev.cc\n@@ -3521,6 +3521,7 @@ void PSOutputDev::startPage(int pageNum, GfxState *state) {\n saveState(NULL);\n }\n \n+ xScale = yScale = 1;\n switch (mode) {\n \n case psModePSOrigPageSizes:\n@@ -3631,8 +3632,6 @@ void PSOutputDev::startPage(int pageNum, GfxState *state) {\n } else {\n \tyScale = xScale;\n }\n- } else {\n- xScale = yScale = 1;\n }\n // deal with odd bounding boxes or clipping\n if (clipLLX0 < clipURX0 && clipLLY0 < clipURY0) {\n@@ -3694,7 +3693,6 @@ void PSOutputDev::startPage(int pageNum, GfxState *state) {\n if (tx != 0 || ty != 0) {\n writePSFmt(\"{0:.6g} {1:.6g} translate\\n\", tx, ty);\n }\n- xScale = yScale = 1;\n break;\n \n case psModeForm:\n@@ -3702,7 +3700,6 @@ void PSOutputDev::startPage(int pageNum, GfxState *state) {\n writePS(\"begin xpdf begin\\n\");\n writePS(\"pdfStartPage\\n\");\n tx = ty = 0;\n- xScale = yScale = 1;\n rotate = 0;\n break;\n }\n--\ncgit v0.9.0.2-2-gbebe\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From dcbc923bd3592a81876f84005fbaddcea18641cc Mon Sep 17 00:00:00 2001\nFrom: Thomas Freitag \nDate: Sun, 22 Jul 2012 16:40:46 +0000\nSubject: Make sure xScale and yScale are always initialized\n\nBug #52215\n---\n(limited to 'poppler/PSOutputDev.cc')\n\ndiff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc\nindex a01a4b3..e15c2e9 100644\n--- a/poppler/PSOutputDev.cc\n+++ b/poppler/PSOutputDev.cc\n@@ -3521,6 +3521,7 @@ void PSOutputDev::startPage(int pageNum, GfxState *state) {\n saveState(NULL);\n }\n \n+ xScale = yScale = 1;\n switch (mode) {\n \n case psModePSOrigPageSizes:\n@@ -3631,8 +3632,6 @@ void PSOutputDev::startPage(int pageNum, GfxState *state) {\n } else {\n \tyScale = xScale;\n }\n- } else {\n- xScale = yScale = 1;\n }\n // deal with odd bounding boxes or clipping\n if (clipLLX0 < clipURX0 && clipLLY0 < clipURY0) {\n@@ -3694,7 +3693,6 @@ void PSOutputDev::startPage(int pageNum, GfxState *state) {\n if (tx != 0 || ty != 0) {\n writePSFmt(\"{0:.6g} {1:.6g} translate\\n\", tx, ty);\n }\n- xScale = yScale = 1;\n break;\n \n case psModeForm:\n@@ -3702,7 +3700,6 @@ void PSOutputDev::startPage(int pageNum, GfxState *state) {\n writePS(\"begin xpdf begin\\n\");\n writePS(\"pdfStartPage\\n\");\n tx = ty = 0;\n- xScale = yScale = 1;\n rotate = 0;\n break;\n }\n--\ncgit v0.9.0.2-2-gbebe"}], "metadata": {"id": "poppler-1943-dcbc923bd3592a81876f84005fbadd", "cve_id": "CVE-2012-2142", "package": "poppler", "tier": "identical", "has_source_context": false, "license": "GPL-2.0-only OR GPL-3.0-only"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1i/ssl/s3_clnt.c\n- openssl-1.0.1i.orig/ssl/s3_clnt.c\n\n## Target Source Code\n\n### ssl/s3_clnt.c\n\n#### ssl3_get_key_exchange() [lines 1270-1877]\n```c\n\treturn(ret);\n\t}\n\nint ssl3_get_key_exchange(SSL *s)\n\t{\n#ifndef OPENSSL_NO_RSA\n\tunsigned char *q,md_buf[EVP_MAX_MD_SIZE*2];\n#endif\n\tEVP_MD_CTX md_ctx;\n\tunsigned char *param,*p;\n\tint al,i,j,param_len,ok;\n\tlong n,alg_k,alg_a;\n\tEVP_PKEY *pkey=NULL;\n\tconst EVP_MD *md = NULL;\n#ifndef OPENSSL_NO_RSA\n\tRSA *rsa=NULL;\n#endif\n#ifndef OPENSSL_NO_DH\n\tDH *dh=NULL;\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tEC_KEY *ecdh = NULL;\n\tBN_CTX *bn_ctx = NULL;\n\tEC_POINT *srvr_ecpoint = NULL;\n\tint curve_nid = 0;\n\tint encoded_pt_len = 0;\n#endif\n\n\t/* use same message size as in ssl3_get_certificate_request()\n\t * as ServerKeyExchange message may be skipped */\n\tn=s->method->ssl_get_message(s,\n\t\tSSL3_ST_CR_KEY_EXCH_A,\n\t\tSSL3_ST_CR_KEY_EXCH_B,\n\t\t-1,\n\t\ts->max_cert_list,\n\t\t&ok);\n\tif (!ok) return((int)n);\n\n\tif (s->s3->tmp.message_type != SSL3_MT_SERVER_KEY_EXCHANGE)\n\t\t{\n#ifndef OPENSSL_NO_PSK\n\t\t/* In plain PSK ciphersuite, ServerKeyExchange can be\n/* ... 546 lines omitted ... */\n\tEVP_PKEY_free(pkey);\n#ifndef OPENSSL_NO_RSA\n\tif (rsa != NULL)\n\t\tRSA_free(rsa);\n#endif\n#ifndef OPENSSL_NO_DH\n\tif (dh != NULL)\n\t\tDH_free(dh);\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tBN_CTX_free(bn_ctx);\n\tEC_POINT_free(srvr_ecpoint);\n\tif (ecdh != NULL)\n\t\tEC_KEY_free(ecdh);\n#endif\n\tEVP_MD_CTX_cleanup(&md_ctx);\n\treturn(-1);\n\t}\n\nint ssl3_get_certificate_request(SSL *s)\n```\n\n\n## Upstream Fix\n```diff\nFrom b15f8769644b00ef7283521593360b7b2135cb63 Mon Sep 17 00:00:00 2001\nFrom: \"Dr. Stephen Henson\" \nDate: Fri, 24 Oct 2014 12:30:33 +0100\nSubject: [PATCH] ECDH downgrade bug fix.\n\nFix bug where an OpenSSL client would accept a handshake using an\nephemeral ECDH ciphersuites with the server key exchange message omitted.\n\nThanks to Karthikeyan Bhargavan for reporting this issue.\n\nCVE-2014-3572\nReviewed-by: Matt Caswell \n---\n CHANGES | 7 +++++++\n ssl/s3_clnt.c | 18 +++++++++++++++---\n 2 files changed, 22 insertions(+), 3 deletions(-)\n\ndiff --git a/CHANGES b/CHANGES\nindex c444b24a2c1e6..0252eb570671c 100644\n--- a/CHANGES\n+++ b/CHANGES\n@@ -659,6 +659,13 @@\n \n Changes between 1.0.1j and 1.0.1k [xx XXX xxxx]\n \n+ *) Abort handshake if server key exchange message is omitted for ephemeral\n+ ECDH ciphersuites.\n+\n+ Thanks to Karthikeyan Bhargavan for reporting this issue.\n+ (CVE-2014-3572)\n+ [Steve Henson]\n+\n *) Ensure that the session ID context of an SSL is updated when its\n SSL_CTX is updated via SSL_set_SSL_CTX.\n \ndiff --git a/ssl/s3_clnt.c b/ssl/s3_clnt.c\nindex 4ca2774f23340..2313fbc1e749c 100644\n--- a/ssl/s3_clnt.c\n+++ b/ssl/s3_clnt.c\n@@ -1376,6 +1376,8 @@ int ssl3_get_key_exchange(SSL *s)\n \tint encoded_pt_len = 0;\n #endif\n \n+\tEVP_MD_CTX_init(&md_ctx);\n+\n \t/* use same message size as in ssl3_get_certificate_request()\n \t * as ServerKeyExchange message may be skipped */\n \tn=s->method->ssl_get_message(s,\n@@ -1386,14 +1388,26 @@ int ssl3_get_key_exchange(SSL *s)\n \t\t&ok);\n \tif (!ok) return((int)n);\n \n+\talg_k=s->s3->tmp.new_cipher->algorithm_mkey;\n+\n \tif (s->s3->tmp.message_type != SSL3_MT_SERVER_KEY_EXCHANGE)\n \t\t{\n+\t\t/*\n+\t\t * Can't skip server key exchange if this is an ephemeral\n+\t\t * ciphersuite.\n+\t\t */\n+\t\tif (alg_k & (SSL_kDHE|SSL_kECDHE))\n+\t\t\t{\n+\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE, SSL_R_UNEXPECTED_MESSAGE);\n+\t\t\tal = SSL_AD_UNEXPECTED_MESSAGE;\n+\t\t\tgoto f_err;\n+\t\t\t}\n #ifndef OPENSSL_NO_PSK\n \t\t/* In plain PSK ciphersuite, ServerKeyExchange can be\n \t\t omitted if no identity hint is sent. Set\n \t\t session->sess_cert anyway to avoid problems\n \t\t later.*/\n-\t\tif (s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK)\n+\t\tif (alg_k & SSL_kPSK)\n \t\t\t{\n \t\t\ts->session->sess_cert=ssl_sess_cert_new();\n \t\t\tif (s->ctx->psk_identity_hint)\n@@ -1438,9 +1452,7 @@ int ssl3_get_key_exchange(SSL *s)\n \t/* Total length of the parameters including the length prefix */\n \tparam_len=0;\n \n-\talg_k=s->s3->tmp.new_cipher->algorithm_mkey;\n \talg_a=s->s3->tmp.new_cipher->algorithm_auth;\n-\tEVP_MD_CTX_init(&md_ctx);\n \n \tal=SSL_AD_DECODE_ERROR;\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "commit ef28c6d6767a6a30df5add36171894c96628fe98\nAuthor: Dr. Stephen Henson \nDate: Fri Oct 24 12:30:33 2014 +0100\n\n ECDH downgrade bug fix.\n \n Fix bug where an OpenSSL client would accept a handshake using an\n ephemeral ECDH ciphersuites with the server key exchange message omitted.\n \n Thanks to Karthikeyan Bhargavan for reporting this issue.\n \n CVE-2014-3572\n Reviewed-by: Matt Caswell \n \n (cherry picked from commit b15f8769644b00ef7283521593360b7b2135cb63)\n\nIndex: openssl-1.0.1i/ssl/s3_clnt.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s3_clnt.c\t2015-01-08 13:13:24.167899760 +0100\n+++ openssl-1.0.1i/ssl/s3_clnt.c\t2015-01-08 13:37:47.300042642 +0100\n@@ -1295,6 +1295,8 @@ int ssl3_get_key_exchange(SSL *s)\n \tint encoded_pt_len = 0;\n #endif\n \n+\tEVP_MD_CTX_init(&md_ctx);\n+\n \t/* use same message size as in ssl3_get_certificate_request()\n \t * as ServerKeyExchange message may be skipped */\n \tn=s->method->ssl_get_message(s,\n@@ -1305,14 +1307,26 @@ int ssl3_get_key_exchange(SSL *s)\n \t\t&ok);\n \tif (!ok) return((int)n);\n \n+\talg_k=s->s3->tmp.new_cipher->algorithm_mkey;\n+\n \tif (s->s3->tmp.message_type != SSL3_MT_SERVER_KEY_EXCHANGE)\n \t\t{\n+\t\t/*\n+\t\t * Can't skip server key exchange if this is an ephemeral\n+\t\t * ciphersuite.\n+\t\t */\n+\t\tif (alg_k & (SSL_kEDH|SSL_kEECDH))\n+\t\t\t{\n+\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE, SSL_R_UNEXPECTED_MESSAGE);\n+\t\t\tal = SSL_AD_UNEXPECTED_MESSAGE;\n+\t\t\tgoto f_err;\n+\t\t\t}\n #ifndef OPENSSL_NO_PSK\n \t\t/* In plain PSK ciphersuite, ServerKeyExchange can be\n \t\t omitted if no identity hint is sent. Set\n \t\t session->sess_cert anyway to avoid problems\n \t\t later.*/\n-\t\tif (s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK)\n+\t\tif (alg_k & SSL_kPSK)\n \t\t\t{\n \t\t\ts->session->sess_cert=ssl_sess_cert_new();\n \t\t\tif (s->ctx->psk_identity_hint)\n@@ -1355,9 +1369,7 @@ int ssl3_get_key_exchange(SSL *s)\n \t\t}\n \n \tparam_len=0;\n-\talg_k=s->s3->tmp.new_cipher->algorithm_mkey;\n \talg_a=s->s3->tmp.new_cipher->algorithm_auth;\n-\tEVP_MD_CTX_init(&md_ctx);\n \n #ifndef OPENSSL_NO_PSK\n \tif (alg_k & SSL_kPSK)"}], "metadata": {"id": "openssl-4769-openssl-CVE-2014-3572.patch", "cve_id": "CVE-2015-3197", "package": "openssl", "upstream_enriched": true, "upstream_commit": "b15f8769644b00ef7283521593360b7b2135cb63", "upstream_repo": "openssl/openssl", "tier": "adapted", "has_source_context": true, "context_tokens_est": 345, "context_files": 1, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2014-3609\n\nHttpHdrRange.cc in Squid 3.x before 3.3.12 and 3.4.x before 3.4.6 allows remote attackers to cause a denial of service (crash) via a request with crafted \"Range headers with unidentifiable byte-range values.\"\n\n## Package\nsquid\n\n## Upstream Fix\n```diff\nIndex: helpers/basic_auth/fake/fake.cc\n===================================================================\n--- helpers/basic_auth/fake/fake.cc.orig\n+++ helpers/basic_auth/fake/fake.cc\n@@ -74,7 +74,7 @@ main(int argc, char *argv[])\n \n process_options(argc, argv);\n \n- debug(\"%s build \" __DATE__ \", \" __TIME__ \" starting up...\\n\", program_name);\n+ debug(\"%s starting up...\\n\", program_name);\n \n while (fgets(buf, HELPER_INPUT_BUFFER, stdin) != NULL) {\n char *p;\n@@ -90,6 +90,6 @@ main(int argc, char *argv[])\n /* send 'OK' result back to Squid */\n SEND_OK(\"\");\n }\n- debug(\"%s build \" __DATE__ \", \" __TIME__ \" shutting down...\\n\", program_name);\n+ debug(\"%s shutting down...\\n\", program_name);\n exit(0);\n }\nIndex: helpers/external_acl/AD_group/ext_ad_group_acl.cc\n===================================================================\n--- helpers/external_acl/AD_group/ext_ad_group_acl.cc.orig\n+++ helpers/external_acl/AD_group/ext_ad_group_acl.cc\n@@ -815,8 +815,7 @@ main(int argc, char *argv[])\n if (!DefaultDomain)\n DefaultDomain = xstrdup(machinedomain);\n }\n- debug(\"External ACL win32 group helper build \" __DATE__ \", \" __TIME__\n- \" starting up...\\n\");\n+ debug(\"External ACL win32 group helper build starting up...\\n\");\n if (use_global)\n debug(\"Domain Global group mode enabled using '%s' as default domain.\\n\", DefaultDomain);\n if (use_case_insensitive_compare)\nIndex: helpers/external_acl/LM_group/ext_lm_group_acl.cc\n===================================================================\n--- helpers/external_acl/LM_group/ext_lm_group_acl.cc.orig\n+++ helpers/external_acl/LM_group/ext_lm_group_acl.cc\n@@ -546,8 +546,7 @@ main(int argc, char *argv[])\n if (!DefaultDomain)\n DefaultDomain = xstrdup(machinedomain);\n }\n- debug(\"External ACL win32 group helper build \" __DATE__ \", \" __TIME__\n- \" starting up...\\n\");\n+ debug(\"External ACL win32 group helper build starting up...\\n\");\n if (use_global)\n debug(\"Domain Global group mode enabled using '%s' as default domain.\\n\", DefaultDomain);\n if (use_case_insensitive_compare)\nIndex: helpers/negotiate_auth/SSPI/negotiate_sspi_auth.cc\n===================================================================\n--- helpers/negotiate_auth/SSPI/negotiate_sspi_auth.cc.orig\n+++ helpers/negotiate_auth/SSPI/negotiate_sspi_auth.cc\n@@ -272,7 +272,7 @@ main(int argc, char *argv[])\n \n process_options(argc, argv);\n \n- debug(\"%s build \" __DATE__ \", \" __TIME__ \" starting up...\\n\", my_program_name);\n+ debug(\"%s starting up...\\n\", my_program_name);\n \n if (LoadSecurityDll(SSP_NTLM, NEGOTIATE_PACKAGE_NAME) == NULL) {\n fprintf(stderr, \"FATAL: %s: can't initialize SSPI, exiting.\\n\", argv[0]);\nIndex: helpers/ntlm_auth/SSPI/ntlm_sspi_auth.cc\n===================================================================\n--- helpers/ntlm_auth/SSPI/ntlm_sspi_auth.cc.orig\n+++ helpers/ntlm_auth/SSPI/ntlm_sspi_auth.cc\n@@ -612,7 +612,7 @@ main(int argc, char *argv[])\n \n process_options(argc, argv);\n \n- debug(\"%s build \" __DATE__ \", \" __TIME__ \" starting up...\\n\", my_program_name);\n+ debug(\"%s starting up...\\n\", my_program_name);\n \n if (LoadSecurityDll(SSP_NTLM, NTLM_PACKAGE_NAME) == NULL) {\n fprintf(stderr, \"FATAL, can't initialize SSPI, exiting.\\n\");\nIndex: helpers/ntlm_auth/fake/ntlm_fake_auth.cc\n===================================================================\n--- helpers/ntlm_auth/fake/ntlm_fake_auth.cc.orig\n+++ helpers/ntlm_auth/fake/ntlm_fake_auth.cc\n@@ -175,7 +175,7 @@ main(int argc, char *argv[])\n \n process_options(argc, argv);\n \n- debug(\"%s build \" __DATE__ \", \" __TIME__ \" starting up...\\n\", my_program_name);\n+ debug(\"%s starting up...\\n\", my_program_name);\n \n while (fgets(buf, HELPER_INPUT_BUFFER, stdin) != NULL) {\n user[0] = '\\0';\t\t/*no user code */\nIndex: helpers/ntlm_auth/smb_lm/ntlm_smb_lm_auth.cc\n===================================================================\n--- helpers/ntlm_auth/smb_lm/ntlm_smb_lm_auth.cc.orig\n+++ helpers/ntlm_auth/smb_lm/ntlm_smb_lm_auth.cc\n@@ -683,7 +683,7 @@ manage_request()\n int\n main(int argc, char *argv[])\n {\n- debug(\"ntlm_auth build \" __DATE__ \", \" __TIME__ \" starting up...\\n\");\n+ debug(\"ntlm_auth build starting up...\\n\");\n \n my_program_name = argv[0];\n process_options(argc, argv);\nIndex: helpers/url_rewrite/fake/fake.cc\n===================================================================\n--- helpers/url_rewrite/fake/fake.cc.orig\n+++ helpers/url_rewrite/fake/fake.cc\n@@ -79,7 +79,7 @@ main(int argc, char *argv[])\n \n process_options(argc, argv);\n \n- debug(\"%s build \" __DATE__ \", \" __TIME__ \" starting up...\\n\", my_program_name);\n+ debug(\"%s starting up...\\n\", my_program_name);\n \n while (fgets(buf, HELPER_INPUT_BUFFER, stdin) != NULL) {\n char *p;\n@@ -95,6 +95,6 @@ main(int argc, char *argv[])\n /* send 'no-change' result back to Squid */\n fprintf(stdout,\"\\n\");\n }\n- debug(\"%s build \" __DATE__ \", \" __TIME__ \" shutting down...\\n\", my_program_name);\n+ debug(\"%s shutting down...\\n\", my_program_name);\n exit(0);\n }\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "Index: helpers/basic_auth/fake/fake.cc\n===================================================================\n--- helpers/basic_auth/fake/fake.cc.orig\n+++ helpers/basic_auth/fake/fake.cc\n@@ -74,7 +74,7 @@ main(int argc, char *argv[])\n \n process_options(argc, argv);\n \n- debug(\"%s build \" __DATE__ \", \" __TIME__ \" starting up...\\n\", program_name);\n+ debug(\"%s starting up...\\n\", program_name);\n \n while (fgets(buf, HELPER_INPUT_BUFFER, stdin) != NULL) {\n char *p;\n@@ -90,6 +90,6 @@ main(int argc, char *argv[])\n /* send 'OK' result back to Squid */\n SEND_OK(\"\");\n }\n- debug(\"%s build \" __DATE__ \", \" __TIME__ \" shutting down...\\n\", program_name);\n+ debug(\"%s shutting down...\\n\", program_name);\n exit(0);\n }\nIndex: helpers/external_acl/AD_group/ext_ad_group_acl.cc\n===================================================================\n--- helpers/external_acl/AD_group/ext_ad_group_acl.cc.orig\n+++ helpers/external_acl/AD_group/ext_ad_group_acl.cc\n@@ -815,8 +815,7 @@ main(int argc, char *argv[])\n if (!DefaultDomain)\n DefaultDomain = xstrdup(machinedomain);\n }\n- debug(\"External ACL win32 group helper build \" __DATE__ \", \" __TIME__\n- \" starting up...\\n\");\n+ debug(\"External ACL win32 group helper build starting up...\\n\");\n if (use_global)\n debug(\"Domain Global group mode enabled using '%s' as default domain.\\n\", DefaultDomain);\n if (use_case_insensitive_compare)\nIndex: helpers/external_acl/LM_group/ext_lm_group_acl.cc\n===================================================================\n--- helpers/external_acl/LM_group/ext_lm_group_acl.cc.orig\n+++ helpers/external_acl/LM_group/ext_lm_group_acl.cc\n@@ -546,8 +546,7 @@ main(int argc, char *argv[])\n if (!DefaultDomain)\n DefaultDomain = xstrdup(machinedomain);\n }\n- debug(\"External ACL win32 group helper build \" __DATE__ \", \" __TIME__\n- \" starting up...\\n\");\n+ debug(\"External ACL win32 group helper build starting up...\\n\");\n if (use_global)\n debug(\"Domain Global group mode enabled using '%s' as default domain.\\n\", DefaultDomain);\n if (use_case_insensitive_compare)\nIndex: helpers/negotiate_auth/SSPI/negotiate_sspi_auth.cc\n===================================================================\n--- helpers/negotiate_auth/SSPI/negotiate_sspi_auth.cc.orig\n+++ helpers/negotiate_auth/SSPI/negotiate_sspi_auth.cc\n@@ -272,7 +272,7 @@ main(int argc, char *argv[])\n \n process_options(argc, argv);\n \n- debug(\"%s build \" __DATE__ \", \" __TIME__ \" starting up...\\n\", my_program_name);\n+ debug(\"%s starting up...\\n\", my_program_name);\n \n if (LoadSecurityDll(SSP_NTLM, NEGOTIATE_PACKAGE_NAME) == NULL) {\n fprintf(stderr, \"FATAL: %s: can't initialize SSPI, exiting.\\n\", argv[0]);\nIndex: helpers/ntlm_auth/SSPI/ntlm_sspi_auth.cc\n===================================================================\n--- helpers/ntlm_auth/SSPI/ntlm_sspi_auth.cc.orig\n+++ helpers/ntlm_auth/SSPI/ntlm_sspi_auth.cc\n@@ -612,7 +612,7 @@ main(int argc, char *argv[])\n \n process_options(argc, argv);\n \n- debug(\"%s build \" __DATE__ \", \" __TIME__ \" starting up...\\n\", my_program_name);\n+ debug(\"%s starting up...\\n\", my_program_name);\n \n if (LoadSecurityDll(SSP_NTLM, NTLM_PACKAGE_NAME) == NULL) {\n fprintf(stderr, \"FATAL, can't initialize SSPI, exiting.\\n\");\nIndex: helpers/ntlm_auth/fake/ntlm_fake_auth.cc\n===================================================================\n--- helpers/ntlm_auth/fake/ntlm_fake_auth.cc.orig\n+++ helpers/ntlm_auth/fake/ntlm_fake_auth.cc\n@@ -175,7 +175,7 @@ main(int argc, char *argv[])\n \n process_options(argc, argv);\n \n- debug(\"%s build \" __DATE__ \", \" __TIME__ \" starting up...\\n\", my_program_name);\n+ debug(\"%s starting up...\\n\", my_program_name);\n \n while (fgets(buf, HELPER_INPUT_BUFFER, stdin) != NULL) {\n user[0] = '\\0';\t\t/*no user code */\nIndex: helpers/ntlm_auth/smb_lm/ntlm_smb_lm_auth.cc\n===================================================================\n--- helpers/ntlm_auth/smb_lm/ntlm_smb_lm_auth.cc.orig\n+++ helpers/ntlm_auth/smb_lm/ntlm_smb_lm_auth.cc\n@@ -683,7 +683,7 @@ manage_request()\n int\n main(int argc, char *argv[])\n {\n- debug(\"ntlm_auth build \" __DATE__ \", \" __TIME__ \" starting up...\\n\");\n+ debug(\"ntlm_auth build starting up...\\n\");\n \n my_program_name = argv[0];\n process_options(argc, argv);\nIndex: helpers/url_rewrite/fake/fake.cc\n===================================================================\n--- helpers/url_rewrite/fake/fake.cc.orig\n+++ helpers/url_rewrite/fake/fake.cc\n@@ -79,7 +79,7 @@ main(int argc, char *argv[])\n \n process_options(argc, argv);\n \n- debug(\"%s build \" __DATE__ \", \" __TIME__ \" starting up...\\n\", my_program_name);\n+ debug(\"%s starting up...\\n\", my_program_name);\n \n while (fgets(buf, HELPER_INPUT_BUFFER, stdin) != NULL) {\n char *p;\n@@ -95,6 +95,6 @@ main(int argc, char *argv[])\n /* send 'no-change' result back to Squid */\n fprintf(stdout,\"\\n\");\n }\n- debug(\"%s build \" __DATE__ \", \" __TIME__ \" shutting down...\\n\", my_program_name);\n+ debug(\"%s shutting down...\\n\", my_program_name);\n exit(0);\n }"}], "metadata": {"id": "squid-2990-squid-nobuilddates.patch", "cve_id": "CVE-2014-3609", "package": "squid", "tier": "identical", "has_source_context": false, "license": "GPL-2.0-or-later"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-7555\n\nHeap-based buffer overflow in giffix.c in giffix in giflib 5.1.1 allows attackers to cause a denial of service (program crash) via crafted image and logical screen width fields in a GIF file.\n\n## Package\ngiflib\n\n## Files to modify\n- giflib-5.0.4.orig/lib/gif_lib_private.h\n- lib/gif_hash.h\n- giflib-5.0.4.orig/lib/gif_hash.h\n- lib/gif_lib_private.h\n\n## Upstream Fix\n```diff\n---\n configure.ac | 7 +++++--\n lib/gif_hash.h | 4 ++++\n lib/gif_lib_private.h | 3 +++\n 3 files changed, 12 insertions(+), 2 deletions(-)\n\nIndex: giflib-5.0.4/configure.ac\n===================================================================\n--- giflib-5.0.4.orig/configure.ac\n+++ giflib-5.0.4/configure.ac\n@@ -8,11 +8,14 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_R\n dnl Note: config.h is not used in the current build\n dnl We leave this in place only to suppress an error message at autogen time\n AM_CONFIG_HEADER(config.h)\n+AC_CONFIG_MACRO_DIR([m4])\n \n dnl Checks for programs.\n-AC_PROG_LIBTOOL\n-AC_PROG_CC\n+AC_PROG_CC_STDC\n+AC_USE_SYSTEM_EXTENSIONS\n+AC_SYS_LARGEFILE\n AC_PROG_CPP\n+LT_INIT([pic-only disable-static])\n AC_PROG_INSTALL\n AC_PROG_LN_S\n AC_PROG_MAKE_SET\nIndex: giflib-5.0.4/lib/gif_hash.h\n===================================================================\n--- giflib-5.0.4.orig/lib/gif_hash.h\n+++ giflib-5.0.4/lib/gif_hash.h\n@@ -25,6 +25,8 @@ gif_hash.h - magfic constants and declar\n #define HT_PUT_KEY(l)\t(l << 12)\n #define HT_PUT_CODE(l)\t(l & 0x0FFF)\n \n+#pragma GCC visibility push(hidden)\n+\n typedef struct GifHashTableType {\n uint32_t HTable[HT_SIZE];\n } GifHashTableType;\n@@ -34,6 +36,8 @@ void _ClearHashTable(GifHashTableType *H\n void _InsertHashTable(GifHashTableType *HashTable, uint32_t Key, int Code);\n int _ExistsHashTable(GifHashTableType *HashTable, uint32_t Key);\n \n+#pragma GCC visibility pop\n+\n #endif /* _GIF_HASH_H_ */\n \n /* end */\nIndex: giflib-5.0.4/lib/gif_lib_private.h\n===================================================================\n--- giflib-5.0.4.orig/lib/gif_lib_private.h\n+++ giflib-5.0.4/lib/gif_lib_private.h\n@@ -29,6 +29,8 @@ gif_lib_private.h - internal giflib rout\n #define IS_READABLE(Private) (Private->FileState & FILE_STATE_READ)\n #define IS_WRITEABLE(Private) (Private->FileState & FILE_STATE_WRITE)\n \n+#pragma GCC visibility push(hidden)\n+\n typedef struct GifFilePrivateType {\n GifWord FileState, FileHandle, /* Where all this data goes to! */\n BitsPerPixel, /* Bits per pixel (Codes uses at least this + 1). */\n@@ -54,6 +56,7 @@ typedef struct GifFilePrivateType {\n bool gif89;\n } GifFilePrivateType;\n \n+#pragma GCC visibility pop\n #endif /* _GIF_LIB_PRIVATE_H */\n \n /* end */\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "---\n configure.ac | 7 +++++--\n lib/gif_hash.h | 4 ++++\n lib/gif_lib_private.h | 3 +++\n 3 files changed, 12 insertions(+), 2 deletions(-)\n\nIndex: giflib-5.0.4/configure.ac\n===================================================================\n--- giflib-5.0.4.orig/configure.ac\n+++ giflib-5.0.4/configure.ac\n@@ -8,11 +8,14 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_R\n dnl Note: config.h is not used in the current build\n dnl We leave this in place only to suppress an error message at autogen time\n AM_CONFIG_HEADER(config.h)\n+AC_CONFIG_MACRO_DIR([m4])\n \n dnl Checks for programs.\n-AC_PROG_LIBTOOL\n-AC_PROG_CC\n+AC_PROG_CC_STDC\n+AC_USE_SYSTEM_EXTENSIONS\n+AC_SYS_LARGEFILE\n AC_PROG_CPP\n+LT_INIT([pic-only disable-static])\n AC_PROG_INSTALL\n AC_PROG_LN_S\n AC_PROG_MAKE_SET\nIndex: giflib-5.0.4/lib/gif_hash.h\n===================================================================\n--- giflib-5.0.4.orig/lib/gif_hash.h\n+++ giflib-5.0.4/lib/gif_hash.h\n@@ -25,6 +25,8 @@ gif_hash.h - magfic constants and declar\n #define HT_PUT_KEY(l)\t(l << 12)\n #define HT_PUT_CODE(l)\t(l & 0x0FFF)\n \n+#pragma GCC visibility push(hidden)\n+\n typedef struct GifHashTableType {\n uint32_t HTable[HT_SIZE];\n } GifHashTableType;\n@@ -34,6 +36,8 @@ void _ClearHashTable(GifHashTableType *H\n void _InsertHashTable(GifHashTableType *HashTable, uint32_t Key, int Code);\n int _ExistsHashTable(GifHashTableType *HashTable, uint32_t Key);\n \n+#pragma GCC visibility pop\n+\n #endif /* _GIF_HASH_H_ */\n \n /* end */\nIndex: giflib-5.0.4/lib/gif_lib_private.h\n===================================================================\n--- giflib-5.0.4.orig/lib/gif_lib_private.h\n+++ giflib-5.0.4/lib/gif_lib_private.h\n@@ -29,6 +29,8 @@ gif_lib_private.h - internal giflib rout\n #define IS_READABLE(Private) (Private->FileState & FILE_STATE_READ)\n #define IS_WRITEABLE(Private) (Private->FileState & FILE_STATE_WRITE)\n \n+#pragma GCC visibility push(hidden)\n+\n typedef struct GifFilePrivateType {\n GifWord FileState, FileHandle, /* Where all this data goes to! */\n BitsPerPixel, /* Bits per pixel (Codes uses at least this + 1). */\n@@ -54,6 +56,7 @@ typedef struct GifFilePrivateType {\n bool gif89;\n } GifFilePrivateType;\n \n+#pragma GCC visibility pop\n #endif /* _GIF_LIB_PRIVATE_H */\n \n /* end */"}], "metadata": {"id": "giflib-4546-giflib-visibility.patch", "cve_id": "CVE-2015-7555", "package": "giflib", "tier": "identical", "has_source_context": false, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2013-5705\n\napache2/modsecurity.c in ModSecurity before 2.7.6 allows remote attackers to bypass rules by using chunked transfer coding with a capitalized Chunked value in the Transfer-Encoding HTTP header.\n\n## Package\napache2-mod_security2\n\n## Files to modify\n- ../modsecurity-apache_2.7.5-o/apache2/modsecurity.c\n\n## Upstream Fix\n```diff\ndiff -rNU 30 ../modsecurity-apache_2.7.5-o/apache2/modsecurity.c ./apache2/modsecurity.c\n--- ../modsecurity-apache_2.7.5-o/apache2/modsecurity.c\t2013-07-28 05:58:49.000000000 +0200\n+++ ./apache2/modsecurity.c\t2014-07-31 15:32:26.000000000 +0200\n@@ -270,61 +270,61 @@\n return APR_SUCCESS;\n }\n \n /**\n *\n */\n apr_status_t modsecurity_tx_init(modsec_rec *msr) {\n const char *s = NULL;\n const apr_array_header_t *arr;\n char *semicolon = NULL;\n char *comma = NULL;\n apr_table_entry_t *te;\n int i;\n \n /* Register TX cleanup */\n apr_pool_cleanup_register(msr->mp, msr, modsecurity_tx_cleanup, apr_pool_cleanup_null);\n \n /* Initialise C-L */\n msr->request_content_length = -1;\n s = apr_table_get(msr->request_headers, \"Content-Length\");\n if (s != NULL) {\n msr->request_content_length = strtol(s, NULL, 10);\n }\n \n /* Figure out whether this request has a body */\n msr->reqbody_chunked = 0;\n msr->reqbody_should_exist = 0;\n if (msr->request_content_length == -1) {\n /* There's no C-L, but is chunked encoding used? */\n char *transfer_encoding = (char *)apr_table_get(msr->request_headers, \"Transfer-Encoding\");\n- if ((transfer_encoding != NULL)&&(strstr(transfer_encoding, \"chunked\") != NULL)) {\n+ if ((transfer_encoding != NULL)&&(m_strcasestr(transfer_encoding, \"chunked\") != NULL)) {\n msr->reqbody_should_exist = 1;\n msr->reqbody_chunked = 1;\n }\n } else {\n /* C-L found */\n msr->reqbody_should_exist = 1;\n }\n \n /* Initialise C-T */\n msr->request_content_type = NULL;\n s = apr_table_get(msr->request_headers, \"Content-Type\");\n if (s != NULL) msr->request_content_type = s;\n \n /* Decide what to do with the request body. */\n if ((msr->request_content_type != NULL)\n && (strncasecmp(msr->request_content_type, \"application/x-www-form-urlencoded\", 33) == 0))\n {\n /* Always place POST requests with\n * \"application/x-www-form-urlencoded\" payloads in memory.\n */\n msr->msc_reqbody_storage = MSC_REQBODY_MEMORY;\n msr->msc_reqbody_spilltodisk = 0;\n msr->msc_reqbody_processor = \"URLENCODED\";\n } else {\n /* If the C-L is known and there's more data than\n * our limit go to disk straight away.\n */\n if ((msr->request_content_length != -1)\n && (msr->request_content_length > msr->txcfg->reqbody_inmemory_limit))\n {\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "diff -rNU 30 ../modsecurity-apache_2.7.5-o/apache2/modsecurity.c ./apache2/modsecurity.c\n--- ../modsecurity-apache_2.7.5-o/apache2/modsecurity.c\t2013-07-28 05:58:49.000000000 +0200\n+++ ./apache2/modsecurity.c\t2014-07-31 15:32:26.000000000 +0200\n@@ -270,61 +270,61 @@\n return APR_SUCCESS;\n }\n \n /**\n *\n */\n apr_status_t modsecurity_tx_init(modsec_rec *msr) {\n const char *s = NULL;\n const apr_array_header_t *arr;\n char *semicolon = NULL;\n char *comma = NULL;\n apr_table_entry_t *te;\n int i;\n \n /* Register TX cleanup */\n apr_pool_cleanup_register(msr->mp, msr, modsecurity_tx_cleanup, apr_pool_cleanup_null);\n \n /* Initialise C-L */\n msr->request_content_length = -1;\n s = apr_table_get(msr->request_headers, \"Content-Length\");\n if (s != NULL) {\n msr->request_content_length = strtol(s, NULL, 10);\n }\n \n /* Figure out whether this request has a body */\n msr->reqbody_chunked = 0;\n msr->reqbody_should_exist = 0;\n if (msr->request_content_length == -1) {\n /* There's no C-L, but is chunked encoding used? */\n char *transfer_encoding = (char *)apr_table_get(msr->request_headers, \"Transfer-Encoding\");\n- if ((transfer_encoding != NULL)&&(strstr(transfer_encoding, \"chunked\") != NULL)) {\n+ if ((transfer_encoding != NULL)&&(m_strcasestr(transfer_encoding, \"chunked\") != NULL)) {\n msr->reqbody_should_exist = 1;\n msr->reqbody_chunked = 1;\n }\n } else {\n /* C-L found */\n msr->reqbody_should_exist = 1;\n }\n \n /* Initialise C-T */\n msr->request_content_type = NULL;\n s = apr_table_get(msr->request_headers, \"Content-Type\");\n if (s != NULL) msr->request_content_type = s;\n \n /* Decide what to do with the request body. */\n if ((msr->request_content_type != NULL)\n && (strncasecmp(msr->request_content_type, \"application/x-www-form-urlencoded\", 33) == 0))\n {\n /* Always place POST requests with\n * \"application/x-www-form-urlencoded\" payloads in memory.\n */\n msr->msc_reqbody_storage = MSC_REQBODY_MEMORY;\n msr->msc_reqbody_spilltodisk = 0;\n msr->msc_reqbody_processor = \"URLENCODED\";\n } else {\n /* If the C-L is known and there's more data than\n * our limit go to disk straight away.\n */\n if ((msr->request_content_length != -1)\n && (msr->request_content_length > msr->txcfg->reqbody_inmemory_limit))\n {"}], "metadata": {"id": "apache2-mod_security2-2940-apache2-mod_security2-2.7.x-bn", "cve_id": "CVE-2013-5705", "package": "apache2-mod_security2", "tier": "identical", "has_source_context": false, "license": "Apache-2.0"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- ssl/t1_lib.c\n\n## Target Source Code\n\n### ssl/t1_lib.c\n\n#### region() [lines 165-273]\n```c\n\tssl3_free(s);\n\t}\n\nvoid tls1_clear(SSL *s)\n\t{\n\tssl3_clear(s);\n\ts->version = s->method->version;\n\t}\n\n#ifndef OPENSSL_NO_EC\n\nstatic int nid_list[] =\n\t{\n\t\tNID_sect163k1, /* sect163k1 (1) */\n\t\tNID_sect163r1, /* sect163r1 (2) */\n\t\tNID_sect163r2, /* sect163r2 (3) */\n\t\tNID_sect193r1, /* sect193r1 (4) */ \n\t\tNID_sect193r2, /* sect193r2 (5) */ \n\t\tNID_sect233k1, /* sect233k1 (6) */\n\t\tNID_sect233r1, /* sect233r1 (7) */ \n\t\tNID_sect239k1, /* sect239k1 (8) */ \n\t\tNID_sect283k1, /* sect283k1 (9) */\n\t\tNID_sect283r1, /* sect283r1 (10) */ \n\t\tNID_sect409k1, /* sect409k1 (11) */ \n\t\tNID_sect409r1, /* sect409r1 (12) */\n\t\tNID_sect571k1, /* sect571k1 (13) */ \n\t\tNID_sect571r1, /* sect571r1 (14) */ \n\t\tNID_secp160k1, /* secp160k1 (15) */\n\t\tNID_secp160r1, /* secp160r1 (16) */ \n\t\tNID_secp160r2, /* secp160r2 (17) */ \n\t\tNID_secp192k1, /* secp192k1 (18) */\n\t\tNID_X9_62_prime192v1, /* secp192r1 (19) */ \n\t\tNID_secp224k1, /* secp224k1 (20) */ \n\t\tNID_secp224r1, /* secp224r1 (21) */\n\t\tNID_secp256k1, /* secp256k1 (22) */ \n\t\tNID_X9_62_prime256v1, /* secp256r1 (23) */ \n\t\tNID_secp384r1, /* secp384r1 (24) */\n\t\tNID_secp521r1 /* secp521r1 (25) */\t\n\t};\n\nstatic int pref_list[] =\n\t{\n\t\tNID_sect571r1, /* sect571r1 (14) */ \n\t\tNID_sect571k1, /* sect571k1 (13) */ \n\t\tNID_secp521r1, /* secp521r1 (25) */\t\n\t\tNID_sect409k1, /* sect409k1 (11) */ \n\t\tNID_sect409r1, /* sect409r1 (12) */\n\t\tNID_secp384r1, /* secp384r1 (24) */\n\t\tNID_sect283k1, /* sect283k1 (9) */\n\t\tNID_sect283r1, /* sect283r1 (10) */ \n\t\tNID_secp256k1, /* secp256k1 (22) */ \n\t\tNID_X9_62_prime256v1, /* secp256r1 (23) */ \n\t\tNID_sect239k1, /* sect239k1 (8) */ \n\t\tNID_sect233k1, /* sect233k1 (6) */\n\t\tNID_sect233r1, /* sect233r1 (7) */ \n\t\tNID_secp224k1, /* secp224k1 (20) */ \n\t\tNID_secp224r1, /* secp224r1 (21) */\n\t\tNID_sect193r1, /* sect193r1 (4) */ \n\t\tNID_sect193r2, /* sect193r2 (5) */ \n\t\tNID_secp192k1, /* secp192k1 (18) */\n\t\tNID_X9_62_prime192v1, /* secp192r1 (19) */ \n\t\tNID_sect163k1, /* sect163k1 (1) */\n\t\tNID_sect163r1, /* sect163r1 (2) */\n\t\tNID_sect163r2, /* sect163r2 (3) */\n\t\tNID_secp160k1, /* secp160k1 (15) */\n\t\tNID_secp160r1, /* secp160r1 (16) */ \n\t\tNID_secp160r2, /* secp160r2 (17) */ \n\t};\n\nint tls1_ec_curve_id2nid(int curve_id)\n\t{\n\t/* ECC curves from draft-ietf-tls-ecc-12.txt (Oct. 17, 2005) */\n\tif ((curve_id < 1) || ((unsigned int)curve_id >\n\t\t\t\tsizeof(nid_list)/sizeof(nid_list[0])))\n\t\treturn 0;\n\treturn nid_list[curve_id-1];\n\t}\n\nint tls1_ec_nid2curve_id(int nid)\n\t{\n\t/* ECC curves from draft-ietf-tls-ecc-12.txt (Oct. 17, 2005) */\n\tswitch (nid)\n\t\t{\n\tcase NID_sect163k1: /* sect163k1 (1) */\n\t\treturn 1;\n\tcase NID_sect163r1: /* sect163r1 (2) */\n\t\treturn 2;\n\tcase NID_sect163r2: /* sect163r2 (3) */\n\t\treturn 3;\n\tcase NID_sect193r1: /* sect193r1 (4) */ \n\t\treturn 4;\n\tcase NID_sect193r2: /* sect193r2 (5) */ \n\t\treturn 5;\n\tcase NID_sect233k1: /* sect233k1 (6) */\n\t\treturn 6;\n\tcase NID_sect233r1: /* sect233r1 (7) */ \n\t\treturn 7;\n\tcase NID_sect239k1: /* sect239k1 (8) */ \n\t\treturn 8;\n\tcase NID_sect283k1: /* sect283k1 (9) */\n\t\treturn 9;\n\tcase NID_sect283r1: /* sect283r1 (10) */ \n\t\treturn 10;\n\tcase NID_sect409k1: /* sect409k1 (11) */ \n\t\treturn 11;\n\tcase NID_sect409r1: /* sect409r1 (12) */\n\t\treturn 12;\n\tcase NID_sect571k1: /* sect571k1 (13) */ \n\t\treturn 13;\n```\n\n#### region() [lines 194-281]\n```c\n\t\tNID_secp160r2, /* secp160r2 (17) */ \n\t\tNID_secp192k1, /* secp192k1 (18) */\n\t\tNID_X9_62_prime192v1, /* secp192r1 (19) */ \n\t\tNID_secp224k1, /* secp224k1 (20) */ \n\t\tNID_secp224r1, /* secp224r1 (21) */\n\t\tNID_secp256k1, /* secp256k1 (22) */ \n\t\tNID_X9_62_prime256v1, /* secp256r1 (23) */ \n\t\tNID_secp384r1, /* secp384r1 (24) */\n\t\tNID_secp521r1 /* secp521r1 (25) */\t\n\t};\n\nstatic int pref_list[] =\n\t{\n\t\tNID_sect571r1, /* sect571r1 (14) */ \n\t\tNID_sect571k1, /* sect571k1 (13) */ \n\t\tNID_secp521r1, /* secp521r1 (25) */\t\n\t\tNID_sect409k1, /* sect409k1 (11) */ \n\t\tNID_sect409r1, /* sect409r1 (12) */\n\t\tNID_secp384r1, /* secp384r1 (24) */\n\t\tNID_sect283k1, /* sect283k1 (9) */\n\t\tNID_sect283r1, /* sect283r1 (10) */ \n\t\tNID_secp256k1, /* secp256k1 (22) */ \n\t\tNID_X9_62_prime256v1, /* secp256r1 (23) */ \n\t\tNID_sect239k1, /* sect239k1 (8) */ \n\t\tNID_sect233k1, /* sect233k1 (6) */\n\t\tNID_sect233r1, /* sect233r1 (7) */ \n\t\tNID_secp224k1, /* secp224k1 (20) */ \n\t\tNID_secp224r1, /* secp224r1 (21) */\n\t\tNID_sect193r1, /* sect193r1 (4) */ \n\t\tNID_sect193r2, /* sect193r2 (5) */ \n\t\tNID_secp192k1, /* secp192k1 (18) */\n\t\tNID_X9_62_prime192v1, /* secp192r1 (19) */ \n\t\tNID_sect163k1, /* sect163k1 (1) */\n\t\tNID_sect163r1, /* sect163r1 (2) */\n\t\tNID_sect163r2, /* sect163r2 (3) */\n\t\tNID_secp160k1, /* secp160k1 (15) */\n\t\tNID_secp160r1, /* secp160r1 (16) */ \n\t\tNID_secp160r2, /* secp160r2 (17) */ \n\t};\n\nint tls1_ec_curve_id2nid(int curve_id)\n\t{\n\t/* ECC curves from draft-ietf-tls-ecc-12.txt (Oct. 17, 2005) */\n\tif ((curve_id < 1) || ((unsigned int)curve_id >\n\t\t\t\tsizeof(nid_list)/sizeof(nid_list[0])))\n\t\treturn 0;\n\treturn nid_list[curve_id-1];\n\t}\n\nint tls1_ec_nid2curve_id(int nid)\n\t{\n\t/* ECC curves from draft-ietf-tls-ecc-12.txt (Oct. 17, 2005) */\n\tswitch (nid)\n\t\t{\n\tcase NID_sect163k1: /* sect163k1 (1) */\n\t\treturn 1;\n\tcase NID_sect163r1: /* sect163r1 (2) */\n\t\treturn 2;\n\tcase NID_sect163r2: /* sect163r2 (3) */\n\t\treturn 3;\n\tcase NID_sect193r1: /* sect193r1 (4) */ \n\t\treturn 4;\n\tcase NID_sect193r2: /* sect193r2 (5) */ \n\t\treturn 5;\n\tcase NID_sect233k1: /* sect233k1 (6) */\n\t\treturn 6;\n\tcase NID_sect233r1: /* sect233r1 (7) */ \n\t\treturn 7;\n\tcase NID_sect239k1: /* sect239k1 (8) */ \n\t\treturn 8;\n\tcase NID_sect283k1: /* sect283k1 (9) */\n\t\treturn 9;\n\tcase NID_sect283r1: /* sect283r1 (10) */ \n\t\treturn 10;\n\tcase NID_sect409k1: /* sect409k1 (11) */ \n\t\treturn 11;\n\tcase NID_sect409r1: /* sect409r1 (12) */\n\t\treturn 12;\n\tcase NID_sect571k1: /* sect571k1 (13) */ \n\t\treturn 13;\n\tcase NID_sect571r1: /* sect571r1 (14) */ \n\t\treturn 14;\n\tcase NID_secp160k1: /* secp160k1 (15) */\n\t\treturn 15;\n\tcase NID_secp160r1: /* secp160r1 (16) */ \n\t\treturn 16;\n\tcase NID_secp160r2: /* secp160r2 (17) */ \n\t\treturn 17;\n```\n\n#### tls1_ec_curve_id2nid() [lines 231-243]\n```c\n\t\tNID_secp160r2, /* secp160r2 (17) */ \n\t};\n\nint tls1_ec_curve_id2nid(int curve_id)\n\t{\n\t/* ECC curves from draft-ietf-tls-ecc-12.txt (Oct. 17, 2005) */\n\tif ((curve_id < 1) || ((unsigned int)curve_id >\n\t\t\t\tsizeof(nid_list)/sizeof(nid_list[0])))\n\t\treturn 0;\n\treturn nid_list[curve_id-1];\n\t}\n\nint tls1_ec_nid2curve_id(int nid)\n```\n\n#### region() [lines 449-540]\n```c\n\t\t(*ret++) = (unsigned char) login_len;\n\t\tmemcpy(ret, s->srp_ctx.login, login_len);\n\t\tret+=login_len;\n\t\t}\n#endif\n\n#ifndef OPENSSL_NO_EC\n\tif (s->tlsext_ecpointformatlist != NULL)\n\t\t{\n\t\t/* Add TLS extension ECPointFormats to the ClientHello message */\n\t\tlong lenmax; \n\n\t\tif ((lenmax = limit - ret - 5) < 0) return NULL; \n\t\tif (s->tlsext_ecpointformatlist_length > (unsigned long)lenmax) return NULL;\n\t\tif (s->tlsext_ecpointformatlist_length > 255)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n\t\t\treturn NULL;\n\t\t\t}\n\t\t\n\t\ts2n(TLSEXT_TYPE_ec_point_formats,ret);\n\t\ts2n(s->tlsext_ecpointformatlist_length + 1,ret);\n\t\t*(ret++) = (unsigned char) s->tlsext_ecpointformatlist_length;\n\t\tmemcpy(ret, s->tlsext_ecpointformatlist, s->tlsext_ecpointformatlist_length);\n\t\tret+=s->tlsext_ecpointformatlist_length;\n\t\t}\n\tif (s->tlsext_ellipticcurvelist != NULL)\n\t\t{\n\t\t/* Add TLS extension EllipticCurves to the ClientHello message */\n\t\tlong lenmax; \n\n\t\tif ((lenmax = limit - ret - 6) < 0) return NULL; \n\t\tif (s->tlsext_ellipticcurvelist_length > (unsigned long)lenmax) return NULL;\n\t\tif (s->tlsext_ellipticcurvelist_length > 65532)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n\t\t\treturn NULL;\n\t\t\t}\n\t\t\n\t\ts2n(TLSEXT_TYPE_elliptic_curves,ret);\n\t\ts2n(s->tlsext_ellipticcurvelist_length + 2, ret);\n\n\t\t/* NB: draft-ietf-tls-ecc-12.txt uses a one-byte prefix for\n\t\t * elliptic_curve_list, but the examples use two bytes.\n\t\t * http://www1.ietf.org/mail-archive/web/tls/current/msg00538.html\n\t\t * resolves this to two bytes.\n\t\t */\n\t\ts2n(s->tlsext_ellipticcurvelist_length, ret);\n\t\tmemcpy(ret, s->tlsext_ellipticcurvelist, s->tlsext_ellipticcurvelist_length);\n\t\tret+=s->tlsext_ellipticcurvelist_length;\n\t\t}\n#endif /* OPENSSL_NO_EC */\n\n\tif (!(SSL_get_options(s) & SSL_OP_NO_TICKET))\n\t\t{\n\t\tint ticklen;\n\t\tif (!s->new_session && s->session && s->session->tlsext_tick)\n\t\t\tticklen = s->session->tlsext_ticklen;\n\t\telse if (s->session && s->tlsext_session_ticket &&\n\t\t\t s->tlsext_session_ticket->data)\n\t\t\t{\n\t\t\tticklen = s->tlsext_session_ticket->length;\n\t\t\ts->session->tlsext_tick = OPENSSL_malloc(ticklen);\n\t\t\tif (!s->session->tlsext_tick)\n\t\t\t\treturn NULL;\n\t\t\tmemcpy(s->session->tlsext_tick,\n\t\t\t s->tlsext_session_ticket->data,\n\t\t\t ticklen);\n\t\t\ts->session->tlsext_ticklen = ticklen;\n\t\t\t}\n\t\telse\n\t\t\tticklen = 0;\n\t\tif (ticklen == 0 && s->tlsext_session_ticket &&\n\t\t s->tlsext_session_ticket->data == NULL)\n\t\t\tgoto skip_ext;\n\t\t/* Check for enough room 2 for extension type, 2 for len\n \t\t * rest for ticket\n \t\t */\n\t\tif ((long)(limit - ret - 4 - ticklen) < 0) return NULL;\n\t\ts2n(TLSEXT_TYPE_session_ticket,ret); \n\t\ts2n(ticklen,ret);\n\t\tif (ticklen)\n\t\t\t{\n\t\t\tmemcpy(ret, s->session->tlsext_tick, ticklen);\n\t\t\tret += ticklen;\n\t\t\t}\n\t\t}\n\t\tskip_ext:\n\n\tif (TLS1_get_client_version(s) >= TLS1_2_VERSION)\n\t\t{\n\t\tif ((size_t)(limit - ret) < sizeof(tls12_sigalgs) + 6)\n```\n\n#### ssl_prepare_clienthello_tlsext() [lines 1761-1857]\n```c\n\t}\n\n\nint ssl_prepare_clienthello_tlsext(SSL *s)\n\t{\n#ifndef OPENSSL_NO_EC\n\t/* If we are client and using an elliptic curve cryptography cipher suite, send the point formats \n\t * and elliptic curves we support.\n\t */\n\tint using_ecc = 0;\n\tint i;\n\tunsigned char *j;\n\tunsigned long alg_k, alg_a;\n\tSTACK_OF(SSL_CIPHER) *cipher_stack = SSL_get_ciphers(s);\n\n\tfor (i = 0; i < sk_SSL_CIPHER_num(cipher_stack); i++)\n\t\t{\n\t\tSSL_CIPHER *c = sk_SSL_CIPHER_value(cipher_stack, i);\n\n\t\talg_k = c->algorithm_mkey;\n\t\talg_a = c->algorithm_auth;\n\t\tif ((alg_k & (SSL_kEECDH|SSL_kECDHr|SSL_kECDHe) || (alg_a & SSL_aECDSA)))\n\t\t\t{\n\t\t\tusing_ecc = 1;\n\t\t\tbreak;\n\t\t\t}\n\t\t}\n\tusing_ecc = using_ecc && (s->version >= TLS1_VERSION);\n\tif (using_ecc)\n\t\t{\n\t\tif (s->tlsext_ecpointformatlist != NULL) OPENSSL_free(s->tlsext_ecpointformatlist);\n\t\tif ((s->tlsext_ecpointformatlist = OPENSSL_malloc(3)) == NULL)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL_PREPARE_CLIENTHELLO_TLSEXT,ERR_R_MALLOC_FAILURE);\n\t\t\treturn -1;\n\t\t\t}\n\t\ts->tlsext_ecpointformatlist_length = 3;\n\t\ts->tlsext_ecpointformatlist[0] = TLSEXT_ECPOINTFORMAT_uncompressed;\n\t\ts->tlsext_ecpointformatlist[1] = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime;\n\t\ts->tlsext_ecpointformatlist[2] = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2;\n\n\t\t/* we support all named elliptic curves in draft-ietf-tls-ecc-12 */\n\t\tif (s->tlsext_ellipticcurvelist != NULL) OPENSSL_free(s->tlsext_ellipticcurvelist);\n\t\ts->tlsext_ellipticcurvelist_length = sizeof(pref_list)/sizeof(pref_list[0]) * 2;\n\t\tif ((s->tlsext_ellipticcurvelist = OPENSSL_malloc(s->tlsext_ellipticcurvelist_length)) == NULL)\n\t\t\t{\n\t\t\ts->tlsext_ellipticcurvelist_length = 0;\n\t\t\tSSLerr(SSL_F_SSL_PREPARE_CLIENTHELLO_TLSEXT,ERR_R_MALLOC_FAILURE);\n\t\t\treturn -1;\n\t\t\t}\n\t\tfor (i = 0, j = s->tlsext_ellipticcurvelist; (unsigned int)i <\n\t\t\t\tsizeof(pref_list)/sizeof(pref_list[0]); i++)\n\t\t\t{\n\t\t\tint id = tls1_ec_nid2curve_id(pref_list[i]);\n\t\t\ts2n(id,j);\n\t\t\t}\n\t\t}\n#endif /* OPENSSL_NO_EC */\n\n#ifdef TLSEXT_TYPE_opaque_prf_input\n \t{\n\t\tint r = 1;\n\t\n\t\tif (s->ctx->tlsext_opaque_prf_input_callback != 0)\n\t\t\t{\n\t\t\tr = s->ctx->tlsext_opaque_prf_input_callback(s, NULL, 0, s->ctx->tlsext_opaque_prf_input_callback_arg);\n\t\t\tif (!r)\n\t\t\t\treturn -1;\n\t\t\t}\n\n\t\tif (s->tlsext_opaque_prf_input != NULL)\n\t\t\t{\n\t\t\tif (s->s3->client_opaque_prf_input != NULL) /* shouldn't really happen */\n\t\t\t\tOPENSSL_free(s->s3->client_opaque_prf_input);\n\n\t\t\tif (s->tlsext_opaque_prf_input_len == 0)\n\t\t\t\ts->s3->client_opaque_prf_input = OPENSSL_malloc(1); /* dummy byte just to get non-NULL */\n\t\t\telse\n\t\t\t\ts->s3->client_opaque_prf_input = BUF_memdup(s->tlsext_opaque_prf_input, s->tlsext_opaque_prf_input_len);\n\t\t\tif (s->s3->client_opaque_prf_input == NULL)\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL_PREPARE_CLIENTHELLO_TLSEXT,ERR_R_MALLOC_FAILURE);\n\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\ts->s3->client_opaque_prf_input_len = s->tlsext_opaque_prf_input_len;\n\t\t\t}\n\n\t\tif (r == 2)\n\t\t\t/* at callback's request, insist on receiving an appropriate server opaque PRF input */\n\t\t\ts->s3->server_opaque_prf_input_len = s->tlsext_opaque_prf_input_len;\n\t}\n#endif\n\n\treturn 1;\n\t}\n\nint ssl_prepare_serverhello_tlsext(SSL *s)\n```\n\n\n## Upstream Fix\n```diff\nFrom 8b6205c48496f519774954db97836343820bff27 Mon Sep 17 00:00:00 2001\nFrom: Matt Caswell \nDate: Mon, 10 Nov 2014 23:42:50 +0000\nSubject: [PATCH] Added OPENSSL_NO_EC2M guards around the preferred EC curve\n list\n\nReviewed-by: Dr. Stephen Henson \n---\n ssl/t1_lib.c | 23 +++++++++++++++--------\n 1 file changed, 15 insertions(+), 8 deletions(-)\n\ndiff --git a/ssl/t1_lib.c b/ssl/t1_lib.c\nindex d6aff4b682f23..f5728c28d97dd 100644\n--- a/ssl/t1_lib.c\n+++ b/ssl/t1_lib.c\n@@ -204,28 +204,40 @@ static int nid_list[] =\n \n static int pref_list[] =\n \t{\n+#ifndef OPENSSL_NO_EC2M\n \t\tNID_sect571r1, /* sect571r1 (14) */ \n \t\tNID_sect571k1, /* sect571k1 (13) */ \n+#endif\n \t\tNID_secp521r1, /* secp521r1 (25) */\t\n+#ifndef OPENSSL_NO_EC2M\n \t\tNID_sect409k1, /* sect409k1 (11) */ \n \t\tNID_sect409r1, /* sect409r1 (12) */\n+#endif\n \t\tNID_secp384r1, /* secp384r1 (24) */\n+#ifndef OPENSSL_NO_EC2M\n \t\tNID_sect283k1, /* sect283k1 (9) */\n \t\tNID_sect283r1, /* sect283r1 (10) */ \n+#endif\n \t\tNID_secp256k1, /* secp256k1 (22) */ \n \t\tNID_X9_62_prime256v1, /* secp256r1 (23) */ \n+#ifndef OPENSSL_NO_EC2M\n \t\tNID_sect239k1, /* sect239k1 (8) */ \n \t\tNID_sect233k1, /* sect233k1 (6) */\n \t\tNID_sect233r1, /* sect233r1 (7) */ \n+#endif\n \t\tNID_secp224k1, /* secp224k1 (20) */ \n \t\tNID_secp224r1, /* secp224r1 (21) */\n+#ifndef OPENSSL_NO_EC2M\n \t\tNID_sect193r1, /* sect193r1 (4) */ \n \t\tNID_sect193r2, /* sect193r2 (5) */ \n+#endif\n \t\tNID_secp192k1, /* secp192k1 (18) */\n \t\tNID_X9_62_prime192v1, /* secp192r1 (19) */ \n+#ifndef OPENSSL_NO_EC2M\n \t\tNID_sect163k1, /* sect163k1 (1) */\n \t\tNID_sect163r1, /* sect163r1 (2) */\n \t\tNID_sect163r2, /* sect163r2 (3) */\n+#endif\n \t\tNID_secp160k1, /* secp160k1 (15) */\n \t\tNID_secp160r1, /* secp160r1 (16) */ \n \t\tNID_secp160r2, /* secp160r2 (17) */ \n@@ -233,7 +245,7 @@ static int pref_list[] =\n \n int tls1_ec_curve_id2nid(int curve_id)\n \t{\n-\t/* ECC curves from draft-ietf-tls-ecc-12.txt (Oct. 17, 2005) */\n+\t/* ECC curves from RFC 4492 */\n \tif ((curve_id < 1) || ((unsigned int)curve_id >\n \t\t\t\tsizeof(nid_list)/sizeof(nid_list[0])))\n \t\treturn 0;\n@@ -242,7 +254,7 @@ int tls1_ec_curve_id2nid(int curve_id)\n \n int tls1_ec_nid2curve_id(int nid)\n \t{\n-\t/* ECC curves from draft-ietf-tls-ecc-12.txt (Oct. 17, 2005) */\n+\t/* ECC curves from RFC 4492 */\n \tswitch (nid)\n \t\t{\n \tcase NID_sect163k1: /* sect163k1 (1) */\n@@ -488,11 +500,6 @@ unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *buf, unsigned c\n \t\ts2n(TLSEXT_TYPE_elliptic_curves,ret);\n \t\ts2n(s->tlsext_ellipticcurvelist_length + 2, ret);\n \n-\t\t/* NB: draft-ietf-tls-ecc-12.txt uses a one-byte prefix for\n-\t\t * elliptic_curve_list, but the examples use two bytes.\n-\t\t * http://www1.ietf.org/mail-archive/web/tls/current/msg00538.html\n-\t\t * resolves this to two bytes.\n-\t\t */\n \t\ts2n(s->tlsext_ellipticcurvelist_length, ret);\n \t\tmemcpy(ret, s->tlsext_ellipticcurvelist, s->tlsext_ellipticcurvelist_length);\n \t\tret+=s->tlsext_ellipticcurvelist_length;\n@@ -1800,7 +1807,7 @@ int ssl_prepare_clienthello_tlsext(SSL *s)\n \t\ts->tlsext_ecpointformatlist[1] = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime;\n \t\ts->tlsext_ecpointformatlist[2] = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2;\n \n-\t\t/* we support all named elliptic curves in draft-ietf-tls-ecc-12 */\n+\t\t/* we support all named elliptic curves in RFC 4492 */\n \t\tif (s->tlsext_ellipticcurvelist != NULL) OPENSSL_free(s->tlsext_ellipticcurvelist);\n \t\ts->tlsext_ellipticcurvelist_length = sizeof(pref_list)/sizeof(pref_list[0]) * 2;\n \t\tif ((s->tlsext_ellipticcurvelist = OPENSSL_malloc(s->tlsext_ellipticcurvelist_length)) == NULL)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From 8b6205c48496f519774954db97836343820bff27 Mon Sep 17 00:00:00 2001\nFrom: Matt Caswell \nDate: Mon, 10 Nov 2014 23:42:50 +0000\nSubject: [PATCH] Added OPENSSL_NO_EC2M guards around the preferred EC curve\n list\n\nReviewed-by: Dr. Stephen Henson \n---\n ssl/t1_lib.c | 23 +++++++++++++++--------\n 1 file changed, 15 insertions(+), 8 deletions(-)\n\ndiff --git a/ssl/t1_lib.c b/ssl/t1_lib.c\nindex d6aff4b..f5728c2 100644\n--- a/ssl/t1_lib.c\n+++ b/ssl/t1_lib.c\n@@ -204,28 +204,40 @@ static int nid_list[] =\n \n static int pref_list[] =\n \t{\n+#ifndef OPENSSL_NO_EC2M\n \t\tNID_sect571r1, /* sect571r1 (14) */ \n \t\tNID_sect571k1, /* sect571k1 (13) */ \n+#endif\n \t\tNID_secp521r1, /* secp521r1 (25) */\t\n+#ifndef OPENSSL_NO_EC2M\n \t\tNID_sect409k1, /* sect409k1 (11) */ \n \t\tNID_sect409r1, /* sect409r1 (12) */\n+#endif\n \t\tNID_secp384r1, /* secp384r1 (24) */\n+#ifndef OPENSSL_NO_EC2M\n \t\tNID_sect283k1, /* sect283k1 (9) */\n \t\tNID_sect283r1, /* sect283r1 (10) */ \n+#endif\n \t\tNID_secp256k1, /* secp256k1 (22) */ \n \t\tNID_X9_62_prime256v1, /* secp256r1 (23) */ \n+#ifndef OPENSSL_NO_EC2M\n \t\tNID_sect239k1, /* sect239k1 (8) */ \n \t\tNID_sect233k1, /* sect233k1 (6) */\n \t\tNID_sect233r1, /* sect233r1 (7) */ \n+#endif\n \t\tNID_secp224k1, /* secp224k1 (20) */ \n \t\tNID_secp224r1, /* secp224r1 (21) */\n+#ifndef OPENSSL_NO_EC2M\n \t\tNID_sect193r1, /* sect193r1 (4) */ \n \t\tNID_sect193r2, /* sect193r2 (5) */ \n+#endif\n \t\tNID_secp192k1, /* secp192k1 (18) */\n \t\tNID_X9_62_prime192v1, /* secp192r1 (19) */ \n+#ifndef OPENSSL_NO_EC2M\n \t\tNID_sect163k1, /* sect163k1 (1) */\n \t\tNID_sect163r1, /* sect163r1 (2) */\n \t\tNID_sect163r2, /* sect163r2 (3) */\n+#endif\n \t\tNID_secp160k1, /* secp160k1 (15) */\n \t\tNID_secp160r1, /* secp160r1 (16) */ \n \t\tNID_secp160r2, /* secp160r2 (17) */ \n@@ -233,7 +245,7 @@ static int pref_list[] =\n \n int tls1_ec_curve_id2nid(int curve_id)\n \t{\n-\t/* ECC curves from draft-ietf-tls-ecc-12.txt (Oct. 17, 2005) */\n+\t/* ECC curves from RFC 4492 */\n \tif ((curve_id < 1) || ((unsigned int)curve_id >\n \t\t\t\tsizeof(nid_list)/sizeof(nid_list[0])))\n \t\treturn 0;\n@@ -242,7 +254,7 @@ int tls1_ec_curve_id2nid(int curve_id)\n \n int tls1_ec_nid2curve_id(int nid)\n \t{\n-\t/* ECC curves from draft-ietf-tls-ecc-12.txt (Oct. 17, 2005) */\n+\t/* ECC curves from RFC 4492 */\n \tswitch (nid)\n \t\t{\n \tcase NID_sect163k1: /* sect163k1 (1) */\n@@ -488,11 +500,6 @@ unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *buf, unsigned c\n \t\ts2n(TLSEXT_TYPE_elliptic_curves,ret);\n \t\ts2n(s->tlsext_ellipticcurvelist_length + 2, ret);\n \n-\t\t/* NB: draft-ietf-tls-ecc-12.txt uses a one-byte prefix for\n-\t\t * elliptic_curve_list, but the examples use two bytes.\n-\t\t * http://www1.ietf.org/mail-archive/web/tls/current/msg00538.html\n-\t\t * resolves this to two bytes.\n-\t\t */\n \t\ts2n(s->tlsext_ellipticcurvelist_length, ret);\n \t\tmemcpy(ret, s->tlsext_ellipticcurvelist, s->tlsext_ellipticcurvelist_length);\n \t\tret+=s->tlsext_ellipticcurvelist_length;\n@@ -1800,7 +1807,7 @@ int ssl_prepare_clienthello_tlsext(SSL *s)\n \t\ts->tlsext_ecpointformatlist[1] = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime;\n \t\ts->tlsext_ecpointformatlist[2] = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2;\n \n-\t\t/* we support all named elliptic curves in draft-ietf-tls-ecc-12 */\n+\t\t/* we support all named elliptic curves in RFC 4492 */\n \t\tif (s->tlsext_ellipticcurvelist != NULL) OPENSSL_free(s->tlsext_ellipticcurvelist);\n \t\ts->tlsext_ellipticcurvelist_length = sizeof(pref_list)/sizeof(pref_list[0]) * 2;\n \t\tif ((s->tlsext_ellipticcurvelist = OPENSSL_malloc(s->tlsext_ellipticcurvelist_length)) == NULL)\n-- \n2.1.2"}], "metadata": {"id": "openssl-4769-openssl-Added-OPENSSL_NO_EC2M-", "cve_id": "CVE-2015-3197", "package": "openssl", "upstream_enriched": true, "upstream_commit": "8b6205c48496f519774954db97836343820bff27", "upstream_repo": "openssl/openssl", "tier": "adapted", "has_source_context": true, "context_tokens_est": 3101, "context_files": 1, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-4658\n\nxpointer.c in libxml2 before 2.9.5 (as used in Apple iOS before 10, OS X before 10.12, tvOS before 10, and watchOS before 3, and other products) does not forbid namespace nodes in XPointer ranges, which allows remote attackers to execute arbitrary code or cause a denial of service (use-after-free and memory corruption) via a crafted XML document.\n\n## Package\nlibxml2\n\n## Files to modify\n- SAX2.c\n\n## Upstream Fix\n```diff\ncommit 77b77b1301e052d90e6a0967534a698506afcd86\nAuthor: Daniel Veillard \nDate: Thu Jan 26 19:11:02 2012 +0800\n\n Fix SAX2 builder in case of undefined element namespaces\n \n Work as in XML-1.0 before namespaces, and use prefix:localname\n as the new element name (and no namespace of course)\n Also fix 3 cases in the regression tests where the prefix: was\n erroneously dropped in such case\n\nIndex: SAX2.c\n===================================================================\n--- SAX2.c.orig\t2012-09-11 08:01:01.000000000 +0200\n+++ SAX2.c\t2012-12-15 16:32:27.353560391 +0100\n@@ -2188,7 +2188,6 @@\n xmlNodePtr parent;\n xmlNsPtr last = NULL, ns;\n const xmlChar *uri, *pref;\n- xmlChar *lname = NULL;\n int i, j;\n \n if (ctx == NULL) return;\n@@ -2208,20 +2207,6 @@\n }\n \n /*\n- * Take care of the rare case of an undefined namespace prefix\n- */\n- if ((prefix != NULL) && (URI == NULL)) {\n- if (ctxt->dictNames) {\n-\t const xmlChar *fullname;\n-\n-\t fullname = xmlDictQLookup(ctxt->dict, prefix, localname);\n-\t if (fullname != NULL)\n-\t localname = fullname;\n-\t} else {\n-\t lname = xmlBuildQName(localname, prefix, NULL, 0);\n-\t}\n- }\n- /*\n * allocate the node\n */\n if (ctxt->freeElems != NULL) {\n@@ -2234,10 +2219,7 @@\n \tif (ctxt->dictNames)\n \t ret->name = localname;\n \telse {\n-\t if (lname == NULL)\n-\t\tret->name = xmlStrdup(localname);\n-\t else\n-\t ret->name = lname;\n+\t ret->name = xmlStrdup(localname);\n \t if (ret->name == NULL) {\n \t xmlSAX2ErrMemory(ctxt, \"xmlSAX2StartElementNs\");\n \t\treturn;\n@@ -2249,11 +2231,8 @@\n \tif (ctxt->dictNames)\n \t ret = xmlNewDocNodeEatName(ctxt->myDoc, NULL,\n \t (xmlChar *) localname, NULL);\n-\telse if (lname == NULL)\n-\t ret = xmlNewDocNode(ctxt->myDoc, NULL, localname, NULL);\n \telse\n-\t ret = xmlNewDocNodeEatName(ctxt->myDoc, NULL,\n-\t (xmlChar *) lname, NULL);\n+\t ret = xmlNewDocNode(ctxt->myDoc, NULL, localname, NULL);\n \tif (ret == NULL) {\n \t xmlSAX2ErrMemory(ctxt, \"xmlSAX2StartElementNs\");\n \t return;\n@@ -2360,31 +2339,6 @@\n */\n if (nb_attributes > 0) {\n for (j = 0,i = 0;i < nb_attributes;i++,j+=5) {\n-\t /*\n-\t * Handle the rare case of an undefined atribute prefix\n-\t */\n-\t if ((attributes[j+1] != NULL) && (attributes[j+2] == NULL)) {\n-\t\tif (ctxt->dictNames) {\n-\t\t const xmlChar *fullname;\n-\n-\t\t fullname = xmlDictQLookup(ctxt->dict, attributes[j+1],\n-\t\t attributes[j]);\n-\t\t if (fullname != NULL) {\n-\t\t\txmlSAX2AttributeNs(ctxt, fullname, NULL,\n-\t\t\t attributes[j+3], attributes[j+4]);\n-\t\t continue;\n-\t\t }\n-\t\t} else {\n-\t\t lname = xmlBuildQName(attributes[j], attributes[j+1],\n-\t\t NULL, 0);\n-\t\t if (lname != NULL) {\n-\t\t\txmlSAX2AttributeNs(ctxt, lname, NULL,\n-\t\t\t attributes[j+3], attributes[j+4]);\n-\t\t\txmlFree(lname);\n-\t\t continue;\n-\t\t }\n-\t\t}\n-\t }\n \t xmlSAX2AttributeNs(ctxt, attributes[j], attributes[j+1],\n \t\t\t attributes[j+3], attributes[j+4]);\n \t}\n\nIndex: result/namespaces/err_7.xml\n===================================================================\n--- result/namespaces/err_7.xml.orig\n+++ result/namespaces/err_7.xml\n@@ -1,2 +1,2 @@\n \n-\n+\nIndex: result/xmlid/id_tst2.xml\n===================================================================\n--- result/xmlid/id_tst2.xml.orig\n+++ result/xmlid/id_tst2.xml\n@@ -1,6 +1,6 @@\n Object is a Node Set :\n Set contains 1 nodes:\n-1 ELEMENT n:foo\n+1 ELEMENT foo\n ATTRIBUTE id\n TEXT\n content=bar\nIndex: result/xmlid/id_tst3.xml\n===================================================================\n--- result/xmlid/id_tst3.xml.orig\n+++ result/xmlid/id_tst3.xml\n@@ -1,6 +1,6 @@\n Object is a Node Set :\n Set contains 1 nodes:\n-1 ELEMENT f:o:o\n+1 ELEMENT o:o\n ATTRIBUTE id\n TEXT\n content=bar\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "commit 77b77b1301e052d90e6a0967534a698506afcd86\nAuthor: Daniel Veillard \nDate: Thu Jan 26 19:11:02 2012 +0800\n\n Fix SAX2 builder in case of undefined element namespaces\n \n Work as in XML-1.0 before namespaces, and use prefix:localname\n as the new element name (and no namespace of course)\n Also fix 3 cases in the regression tests where the prefix: was\n erroneously dropped in such case\n\nIndex: SAX2.c\n===================================================================\n--- SAX2.c.orig\t2012-09-11 08:01:01.000000000 +0200\n+++ SAX2.c\t2012-12-15 16:32:27.353560391 +0100\n@@ -2188,7 +2188,6 @@\n xmlNodePtr parent;\n xmlNsPtr last = NULL, ns;\n const xmlChar *uri, *pref;\n- xmlChar *lname = NULL;\n int i, j;\n \n if (ctx == NULL) return;\n@@ -2208,20 +2207,6 @@\n }\n \n /*\n- * Take care of the rare case of an undefined namespace prefix\n- */\n- if ((prefix != NULL) && (URI == NULL)) {\n- if (ctxt->dictNames) {\n-\t const xmlChar *fullname;\n-\n-\t fullname = xmlDictQLookup(ctxt->dict, prefix, localname);\n-\t if (fullname != NULL)\n-\t localname = fullname;\n-\t} else {\n-\t lname = xmlBuildQName(localname, prefix, NULL, 0);\n-\t}\n- }\n- /*\n * allocate the node\n */\n if (ctxt->freeElems != NULL) {\n@@ -2234,10 +2219,7 @@\n \tif (ctxt->dictNames)\n \t ret->name = localname;\n \telse {\n-\t if (lname == NULL)\n-\t\tret->name = xmlStrdup(localname);\n-\t else\n-\t ret->name = lname;\n+\t ret->name = xmlStrdup(localname);\n \t if (ret->name == NULL) {\n \t xmlSAX2ErrMemory(ctxt, \"xmlSAX2StartElementNs\");\n \t\treturn;\n@@ -2249,11 +2231,8 @@\n \tif (ctxt->dictNames)\n \t ret = xmlNewDocNodeEatName(ctxt->myDoc, NULL,\n \t (xmlChar *) localname, NULL);\n-\telse if (lname == NULL)\n-\t ret = xmlNewDocNode(ctxt->myDoc, NULL, localname, NULL);\n \telse\n-\t ret = xmlNewDocNodeEatName(ctxt->myDoc, NULL,\n-\t (xmlChar *) lname, NULL);\n+\t ret = xmlNewDocNode(ctxt->myDoc, NULL, localname, NULL);\n \tif (ret == NULL) {\n \t xmlSAX2ErrMemory(ctxt, \"xmlSAX2StartElementNs\");\n \t return;\n@@ -2360,31 +2339,6 @@\n */\n if (nb_attributes > 0) {\n for (j = 0,i = 0;i < nb_attributes;i++,j+=5) {\n-\t /*\n-\t * Handle the rare case of an undefined atribute prefix\n-\t */\n-\t if ((attributes[j+1] != NULL) && (attributes[j+2] == NULL)) {\n-\t\tif (ctxt->dictNames) {\n-\t\t const xmlChar *fullname;\n-\n-\t\t fullname = xmlDictQLookup(ctxt->dict, attributes[j+1],\n-\t\t attributes[j]);\n-\t\t if (fullname != NULL) {\n-\t\t\txmlSAX2AttributeNs(ctxt, fullname, NULL,\n-\t\t\t attributes[j+3], attributes[j+4]);\n-\t\t continue;\n-\t\t }\n-\t\t} else {\n-\t\t lname = xmlBuildQName(attributes[j], attributes[j+1],\n-\t\t NULL, 0);\n-\t\t if (lname != NULL) {\n-\t\t\txmlSAX2AttributeNs(ctxt, lname, NULL,\n-\t\t\t attributes[j+3], attributes[j+4]);\n-\t\t\txmlFree(lname);\n-\t\t continue;\n-\t\t }\n-\t\t}\n-\t }\n \t xmlSAX2AttributeNs(ctxt, attributes[j], attributes[j+1],\n \t\t\t attributes[j+3], attributes[j+4]);\n \t}\n\nIndex: result/namespaces/err_7.xml\n===================================================================\n--- result/namespaces/err_7.xml.orig\n+++ result/namespaces/err_7.xml\n@@ -1,2 +1,2 @@\n \n-\n+\nIndex: result/xmlid/id_tst2.xml\n===================================================================\n--- result/xmlid/id_tst2.xml.orig\n+++ result/xmlid/id_tst2.xml\n@@ -1,6 +1,6 @@\n Object is a Node Set :\n Set contains 1 nodes:\n-1 ELEMENT n:foo\n+1 ELEMENT foo\n ATTRIBUTE id\n TEXT\n content=bar\nIndex: result/xmlid/id_tst3.xml\n===================================================================\n--- result/xmlid/id_tst3.xml.orig\n+++ result/xmlid/id_tst3.xml\n@@ -1,6 +1,6 @@\n Object is a Node Set :\n Set contains 1 nodes:\n-1 ELEMENT f:o:o\n+1 ELEMENT o:o\n ATTRIBUTE id\n TEXT\n content=bar"}], "metadata": {"id": "libxml2-5762-fix-perl.diff", "cve_id": "CVE-2016-4658", "package": "libxml2", "tier": "identical", "has_source_context": false, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-6250\n\nInteger overflow in the ISO9660 writer in libarchive before 3.2.1 allows remote attackers to cause a denial of service (application crash) or execute arbitrary code via vectors related to verifying filename lengths when writing an ISO9660 archive, which trigger a buffer overflow.\n\n## Package\nlibarchive\n\n## Files to modify\n- libarchive/archive_read_support_format_iso9660.c\n\n## Upstream Fix\n```diff\ncommit 3ad08e01b4d253c66ae56414886089684155af22\nAuthor: Tim Kientzle \nDate: Sun Jun 19 14:34:37 2016 -0700\n\n Issue 717: Fix integer overflow when computing location of volume descriptor\n \n The multiplication here defaulted to 'int' but calculations\n of file positions should always use int64_t. A simple cast\n suffices to fix this since the base location is always 32 bits\n for ISO, so multiplying by the sector size will never overflow\n a 64-bit integer.\n\ndiff --git a/libarchive/archive_read_support_format_iso9660.c b/libarchive/archive_read_support_format_iso9660.c\nindex 6934cee..f41ba38 100644\n--- a/libarchive/archive_read_support_format_iso9660.c\n+++ b/libarchive/archive_read_support_format_iso9660.c\n@@ -1091,7 +1091,7 @@ choose_volume(struct archive_read *a, struct iso9660 *iso9660)\n \t\t/* This condition is unlikely; by way of caution. */\n \t\tvd = &(iso9660->joliet);\n \n-\tskipsize = LOGICAL_BLOCK_SIZE * vd->location;\n+\tskipsize = LOGICAL_BLOCK_SIZE * (int64_t)vd->location;\n \tskipsize = __archive_read_consume(a, skipsize);\n \tif (skipsize < 0)\n \t\treturn ((int)skipsize);\n@@ -1129,7 +1129,7 @@ choose_volume(struct archive_read *a, struct iso9660 *iso9660)\n \t && iso9660->seenJoliet) {\n \t\t/* Switch reading data from primary to joliet. */\n \t\tvd = &(iso9660->joliet);\n-\t\tskipsize = LOGICAL_BLOCK_SIZE * vd->location;\n+\t\tskipsize = LOGICAL_BLOCK_SIZE * (int64_t)vd->location;\n \t\tskipsize -= iso9660->current_position;\n \t\tskipsize = __archive_read_consume(a, skipsize);\n \t\tif (skipsize < 0)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "commit 3ad08e01b4d253c66ae56414886089684155af22\nAuthor: Tim Kientzle \nDate: Sun Jun 19 14:34:37 2016 -0700\n\n Issue 717: Fix integer overflow when computing location of volume descriptor\n \n The multiplication here defaulted to 'int' but calculations\n of file positions should always use int64_t. A simple cast\n suffices to fix this since the base location is always 32 bits\n for ISO, so multiplying by the sector size will never overflow\n a 64-bit integer.\n\ndiff --git a/libarchive/archive_read_support_format_iso9660.c b/libarchive/archive_read_support_format_iso9660.c\nindex 6934cee..f41ba38 100644\n--- a/libarchive/archive_read_support_format_iso9660.c\n+++ b/libarchive/archive_read_support_format_iso9660.c\n@@ -1091,7 +1091,7 @@ choose_volume(struct archive_read *a, struct iso9660 *iso9660)\n \t\t/* This condition is unlikely; by way of caution. */\n \t\tvd = &(iso9660->joliet);\n \n-\tskipsize = LOGICAL_BLOCK_SIZE * vd->location;\n+\tskipsize = LOGICAL_BLOCK_SIZE * (int64_t)vd->location;\n \tskipsize = __archive_read_consume(a, skipsize);\n \tif (skipsize < 0)\n \t\treturn ((int)skipsize);\n@@ -1129,7 +1129,7 @@ choose_volume(struct archive_read *a, struct iso9660 *iso9660)\n \t && iso9660->seenJoliet) {\n \t\t/* Switch reading data from primary to joliet. */\n \t\tvd = &(iso9660->joliet);\n-\t\tskipsize = LOGICAL_BLOCK_SIZE * vd->location;\n+\t\tskipsize = LOGICAL_BLOCK_SIZE * (int64_t)vd->location;\n \t\tskipsize -= iso9660->current_position;\n \t\tskipsize = __archive_read_consume(a, skipsize);\n \t\tif (skipsize < 0)"}], "metadata": {"id": "libarchive-5940-CVE-2016-5844.patch", "cve_id": "CVE-2016-6250", "package": "libarchive", "tier": "identical", "has_source_context": false, "license": "BSD-2-Clause"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-6250\n\nInteger overflow in the ISO9660 writer in libarchive before 3.2.1 allows remote attackers to cause a denial of service (application crash) or execute arbitrary code via vectors related to verifying filename lengths when writing an ISO9660 archive, which trigger a buffer overflow.\n\n## Package\nlibarchive\n\n## Files to modify\n- libarchive-3.1.2.orig/libarchive/archive_read_support_format_7zip.c\n- libarchive/test/test_read_format_7zip_malformed.c\n- libarchive/archive_read_support_format_7zip.c\n\n## Target Source Code\n\n### Makefile.am\n\n#### region() [lines 334-420]\n```c\n\tlibarchive/test/test_compat_cpio.c\t\t\t\\\n\tlibarchive/test/test_compat_gtar.c\t\t\t\\\n\tlibarchive/test/test_compat_gzip.c\t\t\t\\\n\tlibarchive/test/test_compat_lzip.c\t\t\t\\\n\tlibarchive/test/test_compat_lzma.c\t\t\t\\\n\tlibarchive/test/test_compat_lzop.c\t\t\t\\\n\tlibarchive/test/test_compat_mac.c\t\t\t\\\n\tlibarchive/test/test_compat_pax_libarchive_2x.c\t\t\\\n\tlibarchive/test/test_compat_solaris_tar_acl.c\t\t\\\n\tlibarchive/test/test_compat_solaris_pax_sparse.c\t\\\n\tlibarchive/test/test_compat_tar_hardlink.c\t\t\\\n\tlibarchive/test/test_compat_uudecode.c\t\t\t\\\n\tlibarchive/test/test_compat_xz.c\t\t\t\\\n\tlibarchive/test/test_compat_zip.c\t\t\t\\\n\tlibarchive/test/test_empty_write.c\t\t\t\\\n\tlibarchive/test/test_entry.c\t\t\t\t\\\n\tlibarchive/test/test_entry_strmode.c\t\t\t\\\n\tlibarchive/test/test_extattr_freebsd.c\t\t\t\\\n\tlibarchive/test/test_filter_count.c\t\t\t\\\n\tlibarchive/test/test_fuzz.c\t\t\t\t\\\n\tlibarchive/test/test_gnutar_filename_encoding.c\t\t\\\n\tlibarchive/test/test_link_resolver.c\t\t\t\\\n\tlibarchive/test/test_open_failure.c\t\t\t\\\n\tlibarchive/test/test_open_fd.c\t\t\t\t\\\n\tlibarchive/test/test_open_file.c\t\t\t\\\n\tlibarchive/test/test_open_filename.c\t\t\t\\\n\tlibarchive/test/test_pax_filename_encoding.c\t\t\\\n\tlibarchive/test/test_read_data_large.c\t\t\t\\\n\tlibarchive/test/test_read_disk.c\t\t\t\\\n\tlibarchive/test/test_read_disk_directory_traversals.c\t\\\n\tlibarchive/test/test_read_disk_entry_from_file.c\t\\\n\tlibarchive/test/test_read_extract.c\t\t\t\\\n\tlibarchive/test/test_read_file_nonexistent.c\t\t\\\n\tlibarchive/test/test_read_filter_grzip.c\t\t\\\n\tlibarchive/test/test_read_filter_lrzip.c\t\t\\\n\tlibarchive/test/test_read_filter_lzop.c\t\t\t\\\n\tlibarchive/test/test_read_filter_lzop_multiple_parts.c\t\\\n\tlibarchive/test/test_read_filter_program.c\t\t\\\n\tlibarchive/test/test_read_filter_program_signature.c\t\\\n\tlibarchive/test/test_read_filter_uudecode.c\t\t\\\n\tlibarchive/test/test_read_format_7zip.c\t\t\t\\\n\tlibarchive/test/test_read_format_ar.c\t\t\t\\\n\tlibarchive/test/test_read_format_cab.c\t\t\t\\\n\tlibarchive/test/test_read_format_cab_filename.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_afio.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin_Z.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin_be.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin_bz2.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin_gz.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_bin_lzip.c\t\\\n\tlibarchive/test/test_read_format_cpio_bin_lzma.c\t\\\n\tlibarchive/test/test_read_format_cpio_bin_xz.c\t\t\\\n\tlibarchive/test/test_read_format_cpio_filename.c\t\\\n\tlibarchive/test/test_read_format_cpio_odc.c\t\t\\\n\tlibarch\n/* ... truncated ... */\n```\n\n### libarchive/archive_read_support_format_7zip.c\n\n#### read_CodersInfo() [lines 1897-1995]\n```c\n}\n\nstatic int\nread_CodersInfo(struct archive_read *a, struct _7z_coders_info *ci)\n{\n\tconst unsigned char *p;\n\tstruct _7z_digests digest;\n\tunsigned i;\n\n\tmemset(ci, 0, sizeof(*ci));\n\tmemset(&digest, 0, sizeof(digest));\n\n\tif ((p = header_bytes(a, 1)) == NULL)\n\t\tgoto failed;\n\tif (*p != kFolder)\n\t\tgoto failed;\n\n\t/*\n\t * Read NumFolders.\n\t */\n\tif (parse_7zip_uint64(a, &(ci->numFolders)) < 0)\n\t\tgoto failed;\n\tif (1000000 < ci->numFolders)\n\t\t\treturn (-1);\n\n\t/*\n\t * Read External.\n\t */\n\tif ((p = header_bytes(a, 1)) == NULL)\n\t\tgoto failed;\n\tswitch (*p) {\n\tcase 0:\n\t\tci->folders =\n\t\t\tcalloc((size_t)ci->numFolders, sizeof(*ci->folders));\n\t\tif (ci->folders == NULL)\n\t\t\treturn (-1);\n\t\tfor (i = 0; i < ci->numFolders; i++) {\n\t\t\tif (read_Folder(a, &(ci->folders[i])) < 0)\n\t\t\t\tgoto failed;\n\t\t}\n\t\tbreak;\n\tcase 1:\n\t\tif (parse_7zip_uint64(a, &(ci->dataStreamIndex)) < 0)\n\t\t\treturn (-1);\n\t\tif (1000000 < ci->dataStreamIndex)\n\t\t\treturn (-1);\n\t\tbreak;\n\t}\n\n\tif ((p = header_bytes(a, 1)) == NULL)\n\t\tgoto failed;\n\tif (*p != kCodersUnPackSize)\n\t\tgoto failed;\n\n\tfor (i = 0; i < ci->numFolders; i++) {\n\t\tstruct _7z_folder *folder = &(ci->folders[i]);\n\t\tunsigned j;\n\n\t\tfolder->unPackSize =\n\t\t calloc((size_t)folder->numOutStreams, sizeof(*folder->unPackSize));\n\t\tif (folder->unPackSize == NULL)\n\t\t\tgoto failed;\n\t\tfor (j = 0; j < folder->numOutStreams; j++) {\n\t\t\tif (parse_7zip_uint64(a, &(folder->unPackSize[j])) < 0)\n\t\t\t\tgoto failed;\n\t\t}\n\t}\n\n\t/*\n\t * Read CRCs.\n\t */\n\tif ((p = header_bytes(a, 1)) == NULL)\n\t\tgoto failed;\n\tif (*p == kEnd)\n\t\treturn (0);\n\tif (*p != kCRC)\n\t\tgoto failed;\n\tif (read_Digests(a, &digest, (size_t)ci->numFolders) < 0)\n\t\tgoto failed;\n\tfor (i = 0; i < ci->numFolders; i++) {\n\t\tci->folders[i].digest_defined = digest.defineds[i];\n\t\tci->folders[i].digest = digest.digests[i];\n\t}\n\n\t/*\n\t * Must be kEnd.\n\t */\n\tif ((p = header_bytes(a, 1)) == NULL)\n\t\tgoto failed;\n\tif (*p != kEnd)\n\t\tgoto failed;\n\tfree_Digest(&digest);\n\treturn (0);\nfailed:\n\tfree_Digest(&digest);\n\treturn (-1);\n}\n\nstatic uint64_t\n```\n\n\n### Type definitions\n\n```c\n/* from archive_private.h */\nstruct archive {\n\t/*\n\t * The magic/state values are used to sanity-check the\n\t * client's usage. If an API function is called at a\n\t * ridiculous time, or the client passes us an invalid\n\t * pointer, these values allow me to catch that.\n\t */\n\tunsigned int\tmagic;\n\tunsigned int\tstate;\n\n\t/*\n\t * Some public API functions depend on the \"real\" type of the\n\t * archive object.\n\t */\n\tstruct archive_vtable *vtable;\n\n\tint\t\t archive_format;\n\tconst char\t *archive_format_name;\n\n\tint\t compression_code;\t/* Currently active compression. */\n\tconst char *compression_name;\n\n\t/* Number of file entries processed. */\n\tint\t\t file_count;\n\n\tint\t\t archive_error_number;\n\tconst char\t *error;\n\tstruct archive_string\terror_string;\n\n\tchar *current_code;\n\tunsigned current_codepage; /* Current ACP(ANSI CodePage). */\n\tunsigned current_oemcp; /* Current OEMCP(OEM CodePage). */\n\tstruct archive_string_conv *sconv;\n};\n```\n\n\n## Upstream Fix\n```diff\ncommit d094dc02905605ca514baf87855f026b9bf52f1f\nAuthor: Tim Kientzle \nDate: Sun Feb 8 13:29:51 2015 -0800\n\n Issue 405: segfault on malformed 7z archive\n \n Reject a couple of nonsensical cases.\n\nIndex: libarchive-3.1.2/Makefile.am\n===================================================================\n--- libarchive-3.1.2.orig/Makefile.am\n+++ libarchive-3.1.2/Makefile.am\n@@ -373,6 +373,7 @@ libarchive_test_SOURCES=\t\t\t\t\t\\\n \tlibarchive/test/test_read_filter_program_signature.c\t\\\n \tlibarchive/test/test_read_filter_uudecode.c\t\t\\\n \tlibarchive/test/test_read_format_7zip.c\t\t\t\\\n+ libarchive/test/test_read_format_7zip_malformed.c \\\n \tlibarchive/test/test_read_format_ar.c\t\t\t\\\n \tlibarchive/test/test_read_format_cab.c\t\t\t\\\n \tlibarchive/test/test_read_format_cab_filename.c\t\t\\\n@@ -601,6 +602,8 @@ libarchive_test_EXTRA_DIST=\\\n \tlibarchive/test/test_read_format_7zip_lzma1_2.7z.uu\t\t\\\n \tlibarchive/test/test_read_format_7zip_lzma1_lzma2.7z.uu\t\t\\\n \tlibarchive/test/test_read_format_7zip_lzma2.7z.uu\t\t\\\n+\tlibarchive/test/test_read_format_7zip_malformed.7z.uu \t\t\\\n+\tlibarchive/test/test_read_format_7zip_malformed2.7z.uu \t\t\\\n \tlibarchive/test/test_read_format_7zip_ppmd.7z.uu\t\t\\\n \tlibarchive/test/test_read_format_7zip_symbolic_name.7z.uu\t\\\n \tlibarchive/test/test_read_format_ar.ar.uu\t\t\t\\\nIndex: libarchive-3.1.2/libarchive/archive_read_support_format_7zip.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_read_support_format_7zip.c\n+++ libarchive-3.1.2/libarchive/archive_read_support_format_7zip.c\n@@ -1940,7 +1940,16 @@ read_CodersInfo(struct archive_read *a,\n \t\t\treturn (-1);\n \t\tif (1000000 < ci->dataStreamIndex)\n \t\t\treturn (-1);\n+\t\tif (ci->numFolders > 0) {\n+\t\t\tarchive_set_error(&a->archive, -1,\n+\t\t\t \"Malformed 7-Zip archive\");\n+\t\t\tgoto failed;\n+\t\t}\n \t\tbreak;\n+\tdefault:\n+\t\tarchive_set_error(&a->archive, -1,\n+\t\t \"Malformed 7-Zip archive\");\n+\t\tgoto failed;\n \t}\n \n \tif ((p = header_bytes(a, 1)) == NULL)\nIndex: libarchive-3.1.2/libarchive/test/test_read_format_7zip_malformed.7z.uu\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_format_7zip_malformed.7z.uu\n@@ -0,0 +1,5 @@\n+begin 644 test_read_format_7zip_malformed.7z\n+M-WJ\\KR<<,#\"@P/<&!P\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "commit d094dc02905605ca514baf87855f026b9bf52f1f\nAuthor: Tim Kientzle \nDate: Sun Feb 8 13:29:51 2015 -0800\n\n Issue 405: segfault on malformed 7z archive\n \n Reject a couple of nonsensical cases.\n\nIndex: libarchive-3.1.2/Makefile.am\n===================================================================\n--- libarchive-3.1.2.orig/Makefile.am\n+++ libarchive-3.1.2/Makefile.am\n@@ -373,6 +373,7 @@ libarchive_test_SOURCES=\t\t\t\t\t\\\n \tlibarchive/test/test_read_filter_program_signature.c\t\\\n \tlibarchive/test/test_read_filter_uudecode.c\t\t\\\n \tlibarchive/test/test_read_format_7zip.c\t\t\t\\\n+ libarchive/test/test_read_format_7zip_malformed.c \\\n \tlibarchive/test/test_read_format_ar.c\t\t\t\\\n \tlibarchive/test/test_read_format_cab.c\t\t\t\\\n \tlibarchive/test/test_read_format_cab_filename.c\t\t\\\n@@ -601,6 +602,8 @@ libarchive_test_EXTRA_DIST=\\\n \tlibarchive/test/test_read_format_7zip_lzma1_2.7z.uu\t\t\\\n \tlibarchive/test/test_read_format_7zip_lzma1_lzma2.7z.uu\t\t\\\n \tlibarchive/test/test_read_format_7zip_lzma2.7z.uu\t\t\\\n+\tlibarchive/test/test_read_format_7zip_malformed.7z.uu \t\t\\\n+\tlibarchive/test/test_read_format_7zip_malformed2.7z.uu \t\t\\\n \tlibarchive/test/test_read_format_7zip_ppmd.7z.uu\t\t\\\n \tlibarchive/test/test_read_format_7zip_symbolic_name.7z.uu\t\\\n \tlibarchive/test/test_read_format_ar.ar.uu\t\t\t\\\nIndex: libarchive-3.1.2/libarchive/archive_read_support_format_7zip.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_read_support_format_7zip.c\n+++ libarchive-3.1.2/libarchive/archive_read_support_format_7zip.c\n@@ -1940,7 +1940,16 @@ read_CodersInfo(struct archive_read *a,\n \t\t\treturn (-1);\n \t\tif (1000000 < ci->dataStreamIndex)\n \t\t\treturn (-1);\n+\t\tif (ci->numFolders > 0) {\n+\t\t\tarchive_set_error(&a->archive, -1,\n+\t\t\t \"Malformed 7-Zip archive\");\n+\t\t\tgoto failed;\n+\t\t}\n \t\tbreak;\n+\tdefault:\n+\t\tarchive_set_error(&a->archive, -1,\n+\t\t \"Malformed 7-Zip archive\");\n+\t\tgoto failed;\n \t}\n \n \tif ((p = header_bytes(a, 1)) == NULL)\nIndex: libarchive-3.1.2/libarchive/test/test_read_format_7zip_malformed.7z.uu\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_format_7zip_malformed.7z.uu\n@@ -0,0 +1,5 @@\n+begin 644 test_read_format_7zip_malformed.7z\n+M-WJ\\KR<<,#\"@P/<&!P````````!(`````````&:^$Y\n#include \n#include \"cryptlib.h\"\n#include \n#include \"bn_lcl.h\"\n\nstatic const char Hex[]=\"0123456789ABCDEF\";\n\n/* Must 'OPENSSL_free' the returned data */\nchar *BN_bn2hex(const BIGNUM *a)\n\t{\n\tint i,j,v,z=0;\n\tchar *buf;\n\tchar *p;\n\n\tbuf=(char *)OPENSSL_malloc(a->top*BN_BYTES*2+2);\n\tif (buf == NULL)\n\t\t{\n\t\tBNerr(BN_F_BN_BN2HEX,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tp=buf;\n\tif (a->neg) *(p++)='-';\n\tif (BN_is_zero(a)) *(p++)='0';\n\tfor (i=a->top-1; i >=0; i--)\n\t\t{\n\t\tfor (j=BN_BITS2-8; j >= 0; j-=8)\n\t\t\t{\n\t\t\t/* strip leading zeros */\n\t\t\tv=((int)(a->d[i]>>(long)j))&0xff;\n\t\t\tif (z || (v != 0))\n\t\t\t\t{\n\t\t\t\t*(p++)=Hex[v>>4];\n\t\t\t\t*(p++)=Hex[v&0x0f];\n\t\t\t\tz=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t*p='\\0';\nerr:\n\treturn(buf);\n\t}\n\n/* Must 'OPENSSL_free' the returned data */\nchar *BN_bn2dec(const BIGNUM *a)\n\t{\n\tint i=0,num, ok = 0;\n```\n\n#### region() [lines 169-239]\n```c\n\treturn(buf);\n\t}\n\nint BN_hex2bn(BIGNUM **bn, const char *a)\n\t{\n\tBIGNUM *ret=NULL;\n\tBN_ULONG l=0;\n\tint neg=0,h,m,i,j,k,c;\n\tint num;\n\n\tif ((a == NULL) || (*a == '\\0')) return(0);\n\n\tif (*a == '-') { neg=1; a++; }\n\n\tfor (i=0; isxdigit((unsigned char) a[i]); i++)\n\t\t;\n\n\tnum=i+neg;\n\tif (bn == NULL) return(num);\n\n\t/* a is the start of the hex digits, and it is 'i' long */\n\tif (*bn == NULL)\n\t\t{\n\t\tif ((ret=BN_new()) == NULL) return(0);\n\t\t}\n\telse\n\t\t{\n\t\tret= *bn;\n\t\tBN_zero(ret);\n\t\t}\n\n\t/* i is the number of hex digests; */\n\tif (bn_expand(ret,i*4) == NULL) goto err;\n\n\tj=i; /* least significant 'hex' */\n\tm=0;\n\th=0;\n\twhile (j > 0)\n\t\t{\n\t\tm=((BN_BYTES*2) <= j)?(BN_BYTES*2):j;\n\t\tl=0;\n\t\tfor (;;)\n\t\t\t{\n\t\t\tc=a[j-m];\n\t\t\tif ((c >= '0') && (c <= '9')) k=c-'0';\n\t\t\telse if ((c >= 'a') && (c <= 'f')) k=c-'a'+10;\n\t\t\telse if ((c >= 'A') && (c <= 'F')) k=c-'A'+10;\n\t\t\telse k=0; /* paranoia */\n\t\t\tl=(l<<4)|k;\n\n\t\t\tif (--m <= 0)\n\t\t\t\t{\n\t\t\t\tret->d[h++]=l;\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\tj-=(BN_BYTES*2);\n\t\t}\n\tret->top=h;\n\tbn_correct_top(ret);\n\tret->neg=neg;\n\n\t*bn=ret;\n\tbn_check_top(ret);\n\treturn(num);\nerr:\n\tif (*bn == NULL) BN_free(ret);\n\treturn(0);\n\t}\n\nint BN_dec2bn(BIGNUM **bn, const char *a)\n```\n\n#### region() [lines 236-297]\n```c\n\treturn(0);\n\t}\n\nint BN_dec2bn(BIGNUM **bn, const char *a)\n\t{\n\tBIGNUM *ret=NULL;\n\tBN_ULONG l=0;\n\tint neg=0,i,j;\n\tint num;\n\n\tif ((a == NULL) || (*a == '\\0')) return(0);\n\tif (*a == '-') { neg=1; a++; }\n\n\tfor (i=0; isdigit((unsigned char) a[i]); i++)\n\t\t;\n\n\tnum=i+neg;\n\tif (bn == NULL) return(num);\n\n\t/* a is the start of the digits, and it is 'i' long.\n\t * We chop it into BN_DEC_NUM digits at a time */\n\tif (*bn == NULL)\n\t\t{\n\t\tif ((ret=BN_new()) == NULL) return(0);\n\t\t}\n\telse\n\t\t{\n\t\tret= *bn;\n\t\tBN_zero(ret);\n\t\t}\n\n\t/* i is the number of digests, a bit of an over expand; */\n\tif (bn_expand(ret,i*4) == NULL) goto err;\n\n\tj=BN_DEC_NUM-(i%BN_DEC_NUM);\n\tif (j == BN_DEC_NUM) j=0;\n\tl=0;\n\twhile (*a)\n\t\t{\n\t\tl*=10;\n\t\tl+= *a-'0';\n\t\ta++;\n\t\tif (++j == BN_DEC_NUM)\n\t\t\t{\n\t\t\tBN_mul_word(ret,BN_DEC_CONV);\n\t\t\tBN_add_word(ret,l);\n\t\t\tl=0;\n\t\t\tj=0;\n\t\t\t}\n\t\t}\n\tret->neg=neg;\n\n\tbn_correct_top(ret);\n\t*bn=ret;\n\tbn_check_top(ret);\n\treturn(num);\nerr:\n\tif (*bn == NULL) BN_free(ret);\n\treturn(0);\n\t}\n\nint BN_asc2bn(BIGNUM **bn, const char *a)\n```\n\n### crypto/bn/bn.h\n\n#### region() [lines 92-178]\n```c\n * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\n * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR\n * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\n * OF THE POSSIBILITY OF SUCH DAMAGE.\n * ====================================================================\n *\n * This product includes cryptographic software written by Eric Young\n * (eay@cryptsoft.com). This product includes software written by Tim\n * Hudson (tjh@cryptsoft.com).\n *\n */\n/* ====================================================================\n * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.\n *\n * Portions of the attached software (\"Contribution\") are developed by \n * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.\n *\n * The Contribution is licensed pursuant to the Eric Young open source\n * license provided above.\n *\n * The binary polynomial arithmetic software is originally written by \n * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.\n *\n */\n\n#ifndef HEADER_BN_H\n#define HEADER_BN_H\n\n#include \n#ifndef OPENSSL_NO_FP_API\n#include /* FILE */\n#endif\n#include \n#include \n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n/* These preprocessor symbols control various aspects of the bignum headers and\n * library code. They're not defined by any \"normal\" configuration, as they are\n * intended for development and testing purposes. NB: defining all three can be\n * useful for debugging application code as well as openssl itself.\n *\n * BN_DEBUG - turn on various debugging alterations to the bignum code\n * BN_DEBUG_RAND - uses random poisoning of unused words to trip up\n * mismanagement of bignum internals. You must also define BN_DEBUG.\n */\n/* #define BN_DEBUG */\n/* #define BN_DEBUG_RAND */\n\n#ifndef OPENSSL_SMALL_FOOTPRINT\n#define BN_MUL_COMBA\n#define BN_SQR_COMBA\n#define BN_RECURSION\n#endif\n\n/* This next option uses the C libraries (2 word)/(1 word) function.\n * If it is not defined, I use my C version (which is slower).\n * The reason for this flag is that when the particular C compiler\n * library routine is used, and the library is linked with a different\n * compiler, the library is missing. This mostly happens when the\n * library is built with gcc and then linked using normal cc. This would\n * be a common occurrence because gcc normally produces code that is\n * 2 times faster than system compilers for the big number stuff.\n * For machines with only one compiler (or shared libraries), this should\n * be on. Again this in only really a problem on machines\n * using \"long long's\", are 32bit, and are not using my assembler code. */\n#if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WINDOWS) || \\\n defined(OPENSSL_SYS_WIN32) || defined(linux)\n# ifndef BN_DIV2W\n# define BN_DIV2W\n# endif\n#endif\n\n/* assuming long is 64bit - this is the DEC Alpha\n * unsigned long long is only 64 bits :-(, don't define\n * BN_LLONG for the DEC Alpha */\n#ifdef SIXTY_FOUR_BIT_LONG\n```\n\n#### region() [lines 657-745]\n```c\n/* Some functions allow for representation of the irreducible polynomials\n * as an unsigned int[], say p. The irreducible f(t) is then of the form:\n * t^p[0] + t^p[1] + ... + t^p[k]\n * where m = p[0] > p[1] > ... > p[k] = 0.\n */\nint\tBN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const int p[]);\n\t/* r = a mod p */\nint\tBN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n\tconst int p[], BN_CTX *ctx); /* r = (a * b) mod p */\nint\tBN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const int p[],\n\tBN_CTX *ctx); /* r = (a * a) mod p */\nint\tBN_GF2m_mod_inv_arr(BIGNUM *r, const BIGNUM *b, const int p[],\n\tBN_CTX *ctx); /* r = (1 / b) mod p */\nint\tBN_GF2m_mod_div_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n\tconst int p[], BN_CTX *ctx); /* r = (a / b) mod p */\nint\tBN_GF2m_mod_exp_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n\tconst int p[], BN_CTX *ctx); /* r = (a ^ b) mod p */\nint\tBN_GF2m_mod_sqrt_arr(BIGNUM *r, const BIGNUM *a,\n\tconst int p[], BN_CTX *ctx); /* r = sqrt(a) mod p */\nint\tBN_GF2m_mod_solve_quad_arr(BIGNUM *r, const BIGNUM *a,\n\tconst int p[], BN_CTX *ctx); /* r^2 + r = a mod p */\nint\tBN_GF2m_poly2arr(const BIGNUM *a, int p[], int max);\nint\tBN_GF2m_arr2poly(const int p[], BIGNUM *a);\n\n#endif\n\n/* faster mod functions for the 'NIST primes' \n * 0 <= a < p^2 */\nint BN_nist_mod_192(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);\nint BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);\nint BN_nist_mod_256(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);\nint BN_nist_mod_384(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);\nint BN_nist_mod_521(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);\n\nconst BIGNUM *BN_get0_nist_prime_192(void);\nconst BIGNUM *BN_get0_nist_prime_224(void);\nconst BIGNUM *BN_get0_nist_prime_256(void);\nconst BIGNUM *BN_get0_nist_prime_384(void);\nconst BIGNUM *BN_get0_nist_prime_521(void);\n\n/* library internal functions */\n\n#define bn_expand(a,bits) ((((((bits+BN_BITS2-1))/BN_BITS2)) <= (a)->dmax)?\\\n\t(a):bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2))\n#define bn_wexpand(a,words) (((words) <= (a)->dmax)?(a):bn_expand2((a),(words)))\nBIGNUM *bn_expand2(BIGNUM *a, int words);\n#ifndef OPENSSL_NO_DEPRECATED\nBIGNUM *bn_dup_expand(const BIGNUM *a, int words); /* unused */\n#endif\n\n/* Bignum consistency macros\n * There is one \"API\" macro, bn_fix_top(), for stripping leading zeroes from\n * bignum data after direct manipulations on the data. There is also an\n * \"internal\" macro, bn_check_top(), for verifying that there are no leading\n * zeroes. Unfortunately, some auditing is required due to the fact that\n * bn_fix_top() has become an overabused duct-tape because bignum data is\n * occasionally passed around in an inconsistent state. So the following\n * changes have been made to sort this out;\n * - bn_fix_top()s implementation has been moved to bn_correct_top()\n * - if BN_DEBUG isn't defined, bn_fix_top() maps to bn_correct_top(), and\n * bn_check_top() is as before.\n * - if BN_DEBUG *is* defined;\n * - bn_check_top() tries to pollute unused words even if the bignum 'top' is\n * consistent. (ed: only if BN_DEBUG_RAND is defined)\n * - bn_fix_top() maps to bn_check_top() rather than \"fixing\" anything.\n * The idea is to have debug builds flag up inconsistent bignums when they\n * occur. If that occurs in a bn_fix_top(), we examine the code in question; if\n * the use of bn_fix_top() was appropriate (ie. it follows directly after code\n * that manipulates the bignum) it is converted to bn_correct_top(), and if it\n * was not appropriate, we convert it permanently to bn_check_top() and track\n * down the cause of the bug. Eventually, no internal code should be using the\n * bn_fix_top() macro. External applications and libraries should try this with\n * their own code too, both in terms of building against the openssl headers\n * with BN_DEBUG defined *and* linking with a version of OpenSSL built with it\n * defined. This not only improves external code, it provides more test\n * coverage for openssl's own code.\n */\n\n#ifdef BN_DEBUG\n\n/* We only need assert() when debugging */\n#include \n\n#ifdef BN_DEBUG_RAND\n/* To avoid \"make update\" cvs wars due to BN_DEBUG, use some tricks */\n#ifndef RAND_pseudo_bytes\nint RAND_pseudo_bytes(unsigned char *buf,int num);\n#define BN_DEBUG_TRIX\n#endif\n```\n\n\n## Upstream Fix\n```diff\nIndex: openssl-1.0.1i/crypto/bn/bn_print.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/bn/bn_print.c\t2014-07-22 21:41:23.000000000 +0200\n+++ openssl-1.0.1i/crypto/bn/bn_print.c\t2016-02-24 22:09:06.146184510 +0100\n@@ -58,6 +58,7 @@\n \n #include \n #include \n+#include \n #include \"cryptlib.h\"\n #include \n #include \"bn_lcl.h\"\n@@ -180,10 +181,12 @@\n \n \tif (*a == '-') { neg=1; a++; }\n \n-\tfor (i=0; isxdigit((unsigned char) a[i]); i++)\n-\t\t;\n+ for (i = 0; i <= (INT_MAX/4) && isxdigit((unsigned char)a[i]); i++);\n+ if (i > INT_MAX/4)\n+ goto err;\n+\n+ num = i + neg;\n \n-\tnum=i+neg;\n \tif (bn == NULL) return(num);\n \n \t/* a is the start of the hex digits, and it is 'i' long */\n@@ -197,7 +200,7 @@\n \t\tBN_zero(ret);\n \t\t}\n \n-\t/* i is the number of hex digests; */\n+\t/* i is the number of hex digits */\n \tif (bn_expand(ret,i*4) == NULL) goto err;\n \n \tj=i; /* least significant 'hex' */\n@@ -244,12 +247,15 @@\n \tint num;\n \n \tif ((a == NULL) || (*a == '\\0')) return(0);\n+\n \tif (*a == '-') { neg=1; a++; }\n \n-\tfor (i=0; isdigit((unsigned char) a[i]); i++)\n-\t\t;\n+ for (i = 0; i <= (INT_MAX/4) && isdigit((unsigned char)a[i]); i++);\n+ if (i > INT_MAX/4)\n+ goto err;\n+\n+ num = i + neg;\n \n-\tnum=i+neg;\n \tif (bn == NULL) return(num);\n \n \t/* a is the start of the digits, and it is 'i' long.\n@@ -264,7 +270,7 @@\n \t\tBN_zero(ret);\n \t\t}\n \n-\t/* i is the number of digests, a bit of an over expand; */\n+\t/* i is the number of digits, a bit of an over expand */\n \tif (bn_expand(ret,i*4) == NULL) goto err;\n \n \tj=BN_DEC_NUM-(i%BN_DEC_NUM);\nIndex: openssl-1.0.1i/crypto/bn/bn.h\n===================================================================\n--- openssl-1.0.1i.orig/crypto/bn/bn.h\t2014-08-06 23:10:56.000000000 +0200\n+++ openssl-1.0.1i/crypto/bn/bn.h\t2016-02-24 22:10:22.862770519 +0100\n@@ -131,6 +131,7 @@\n #endif\n #include \n #include \n+#include \n \n #ifdef __cplusplus\n extern \"C\" {\n@@ -696,8 +697,16 @@\n \n /* library internal functions */\n \n-#define bn_expand(a,bits) ((((((bits+BN_BITS2-1))/BN_BITS2)) <= (a)->dmax)?\\\n-\t(a):bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2))\n+#define bn_expand(a,bits) \\\n+ ( \\\n+ bits > (INT_MAX - BN_BITS2 + 1) ? \\\n+ NULL \\\n+ : \\\n+ (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax) ? \\\n+ (a) \\\n+ : \\\n+ bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2) \\\n+ )\n #define bn_wexpand(a,words) (((words) <= (a)->dmax)?(a):bn_expand2((a),(words)))\n BIGNUM *bn_expand2(BIGNUM *a, int words);\n #ifndef OPENSSL_NO_DEPRECATED\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "Index: openssl-1.0.1i/crypto/bn/bn_print.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/bn/bn_print.c\t2014-07-22 21:41:23.000000000 +0200\n+++ openssl-1.0.1i/crypto/bn/bn_print.c\t2016-02-24 22:09:06.146184510 +0100\n@@ -58,6 +58,7 @@\n \n #include \n #include \n+#include \n #include \"cryptlib.h\"\n #include \n #include \"bn_lcl.h\"\n@@ -180,10 +181,12 @@\n \n \tif (*a == '-') { neg=1; a++; }\n \n-\tfor (i=0; isxdigit((unsigned char) a[i]); i++)\n-\t\t;\n+ for (i = 0; i <= (INT_MAX/4) && isxdigit((unsigned char)a[i]); i++);\n+ if (i > INT_MAX/4)\n+ goto err;\n+\n+ num = i + neg;\n \n-\tnum=i+neg;\n \tif (bn == NULL) return(num);\n \n \t/* a is the start of the hex digits, and it is 'i' long */\n@@ -197,7 +200,7 @@\n \t\tBN_zero(ret);\n \t\t}\n \n-\t/* i is the number of hex digests; */\n+\t/* i is the number of hex digits */\n \tif (bn_expand(ret,i*4) == NULL) goto err;\n \n \tj=i; /* least significant 'hex' */\n@@ -244,12 +247,15 @@\n \tint num;\n \n \tif ((a == NULL) || (*a == '\\0')) return(0);\n+\n \tif (*a == '-') { neg=1; a++; }\n \n-\tfor (i=0; isdigit((unsigned char) a[i]); i++)\n-\t\t;\n+ for (i = 0; i <= (INT_MAX/4) && isdigit((unsigned char)a[i]); i++);\n+ if (i > INT_MAX/4)\n+ goto err;\n+\n+ num = i + neg;\n \n-\tnum=i+neg;\n \tif (bn == NULL) return(num);\n \n \t/* a is the start of the digits, and it is 'i' long.\n@@ -264,7 +270,7 @@\n \t\tBN_zero(ret);\n \t\t}\n \n-\t/* i is the number of digests, a bit of an over expand; */\n+\t/* i is the number of digits, a bit of an over expand */\n \tif (bn_expand(ret,i*4) == NULL) goto err;\n \n \tj=BN_DEC_NUM-(i%BN_DEC_NUM);\nIndex: openssl-1.0.1i/crypto/bn/bn.h\n===================================================================\n--- openssl-1.0.1i.orig/crypto/bn/bn.h\t2014-08-06 23:10:56.000000000 +0200\n+++ openssl-1.0.1i/crypto/bn/bn.h\t2016-02-24 22:10:22.862770519 +0100\n@@ -131,6 +131,7 @@\n #endif\n #include \n #include \n+#include \n \n #ifdef __cplusplus\n extern \"C\" {\n@@ -696,8 +697,16 @@\n \n /* library internal functions */\n \n-#define bn_expand(a,bits) ((((((bits+BN_BITS2-1))/BN_BITS2)) <= (a)->dmax)?\\\n-\t(a):bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2))\n+#define bn_expand(a,bits) \\\n+ ( \\\n+ bits > (INT_MAX - BN_BITS2 + 1) ? \\\n+ NULL \\\n+ : \\\n+ (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax) ? \\\n+ (a) \\\n+ : \\\n+ bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2) \\\n+ )\n #define bn_wexpand(a,words) (((words) <= (a)->dmax)?(a):bn_expand2((a),(words)))\n BIGNUM *bn_expand2(BIGNUM *a, int words);\n #ifndef OPENSSL_NO_DEPRECATED"}], "metadata": {"id": "openssl-4769-openssl-CVE-2016-0797.patch", "cve_id": "CVE-2015-3197", "package": "openssl", "tier": "identical", "has_source_context": true, "context_tokens_est": 3373, "context_files": 2, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1i/ssl/s23_clnt.c\n- openssl-1.0.1i.orig/ssl/s23_srvr.c\n- openssl-1.0.1i/ssl/s23_srvr.c\n- openssl-1.0.1i.orig/ssl/s23_clnt.c\n\n## Target Source Code\n\n### ssl/s23_clnt.c\n\n#### region() [lines 86-175]\n```c\n *\n * 6. Redistributions of any form whatsoever must retain the following\n * acknowledgment:\n * \"This product includes software developed by the OpenSSL Project\n * for use in the OpenSSL Toolkit (http://www.openssl.org/)\"\n *\n * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\n * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR\n * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\n * OF THE POSSIBILITY OF SUCH DAMAGE.\n * ====================================================================\n *\n * This product includes cryptographic software written by Eric Young\n * (eay@cryptsoft.com). This product includes software written by Tim\n * Hudson (tjh@cryptsoft.com).\n *\n */\n\n#include \n#include \"ssl_locl.h\"\n#include \n#include \n#include \n#include \n\nstatic const SSL_METHOD *ssl23_get_client_method(int ver);\nstatic int ssl23_client_hello(SSL *s);\nstatic int ssl23_get_server_hello(SSL *s);\nstatic const SSL_METHOD *ssl23_get_client_method(int ver)\n\t{\n#ifndef OPENSSL_NO_SSL2\n\tif (ver == SSL2_VERSION)\n\t\treturn(SSLv2_client_method());\n#endif\n\tif (ver == SSL3_VERSION)\n\t\treturn(SSLv3_client_method());\n\telse if (ver == TLS1_VERSION)\n\t\treturn(TLSv1_client_method());\n\telse if (ver == TLS1_1_VERSION)\n\t\treturn(TLSv1_1_client_method());\n\telse if (ver == TLS1_2_VERSION)\n\t\treturn(TLSv1_2_client_method());\n\telse\n\t\treturn(NULL);\n\t}\n\nIMPLEMENT_ssl23_meth_func(SSLv23_client_method,\n\t\t\tssl_undefined_function,\n\t\t\tssl23_connect,\n\t\t\tssl23_get_client_method)\n\nint ssl23_connect(SSL *s)\n\t{\n\tBUF_MEM *buf=NULL;\n\tunsigned long Time=(unsigned long)time(NULL);\n\tvoid (*cb)(const SSL *ssl,int type,int val)=NULL;\n\tint ret= -1;\n\tint new_state,state;\n\n\tRAND_add(&Time,sizeof(Time),0);\n\tERR_clear_error();\n\tclear_sys_error();\n\n\tif (s->info_callback != NULL)\n\t\tcb=s->info_callback;\n\telse if (s->ctx->info_callback != NULL)\n\t\tcb=s->ctx->info_callback;\n\t\n\ts->in_handshake++;\n\tif (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s); \n\n\tfor (;;)\n\t\t{\n\t\tstate=s->state;\n\n\t\tswitch(s->state)\n\t\t\t{\n\t\tcase SSL_ST_BEFORE:\n\t\tcase SSL_ST_CONNECT:\n\t\tcase SSL_ST_BEFORE|SSL_ST_CONNECT:\n\t\tcase SSL_ST_OK|SSL_ST_CONNECT:\n\n```\n\n#### ssl23_get_server_hello() [lines 606-801]\n```c\n\treturn ret;\n\t}\n\nstatic int ssl23_get_server_hello(SSL *s)\n\t{\n\tchar buf[8];\n\tunsigned char *p;\n\tint i;\n\tint n;\n\n\tn=ssl23_read_bytes(s,7);\n\n\tif (n != 7) return(n);\n\tp=s->packet;\n\n\tmemcpy(buf,p,n);\n\n\tif ((p[0] & 0x80) && (p[2] == SSL2_MT_SERVER_HELLO) &&\n\t\t(p[5] == 0x00) && (p[6] == 0x02))\n\t\t{\n#ifdef OPENSSL_NO_SSL2\n\t\tSSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_PROTOCOL);\n\t\tgoto err;\n#else\n\t\t/* we are talking sslv2 */\n\t\t/* we need to clean up the SSLv3 setup and put in the\n\t\t * sslv2 stuff. */\n\t\tint ch_len;\n\n\t\tif (s->options & SSL_OP_NO_SSLv2)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_PROTOCOL);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (s->s2 == NULL)\n\t\t\t{\n\t\t\tif (!ssl2_new(s))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\telse\n/* ... 43 lines omitted ... */\n\n\t\ts->method=SSLv2_client_method();\n\t\ts->handshake_func=s->method->ssl_connect;\n#endif\n\t\t}\n\telse if (p[1] == SSL3_VERSION_MAJOR &&\n\t p[2] <= TLS1_2_VERSION_MINOR &&\n\t ((p[0] == SSL3_RT_HANDSHAKE && p[5] == SSL3_MT_SERVER_HELLO) ||\n\t (p[0] == SSL3_RT_ALERT && p[3] == 0 && p[4] == 2)))\n\t\t{\n\t\t/* we have sslv3 or tls1 (server hello or alert) */\n\n\t\tif ((p[2] == SSL3_VERSION_MINOR) &&\n\t\t\t!(s->options & SSL_OP_NO_SSLv3))\n\t\t\t{\n#ifdef OPENSSL_FIPS\n\t\t\tif(FIPS_mode())\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL23_GET_SERVER_HELLO,\n\t\t\t\t\tSSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE);\n\t\t\t\tgoto err;\n\t\t\t\t}\n#endif\n\t\t\ts->version=SSL3_VERSION;\n\t\t\ts->method=SSLv3_client_method();\n\t\t\t}\n/* ... 67 lines omitted ... */\n\n\t\ts->handshake_func=s->method->ssl_connect;\n\t\t}\n\telse\n\t\t{\n\t\tSSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNKNOWN_PROTOCOL);\n\t\tgoto err;\n\t\t}\n\ts->init_num=0;\n\n\t/* Since, if we are sending a ssl23 client hello, we are not\n\t * reusing a session-id */\n\tif (!ssl_get_new_session(s,0))\n\t\tgoto err;\n\n\treturn(SSL_connect(s));\nerr:\n\treturn(-1);\n\t}\n\n```\n\n### ssl/s23_srvr.c\n\n#### region() [lines 88-177]\n```c\n * acknowledgment:\n * \"This product includes software developed by the OpenSSL Project\n * for use in the OpenSSL Toolkit (http://www.openssl.org/)\"\n *\n * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\n * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR\n * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\n * OF THE POSSIBILITY OF SUCH DAMAGE.\n * ====================================================================\n *\n * This product includes cryptographic software written by Eric Young\n * (eay@cryptsoft.com). This product includes software written by Tim\n * Hudson (tjh@cryptsoft.com).\n *\n */\n\n#include \n#include \"ssl_locl.h\"\n#include \n#include \n#include \n#include \n#ifdef OPENSSL_FIPS\n#include \n#endif\n\nstatic const SSL_METHOD *ssl23_get_server_method(int ver);\nint ssl23_get_client_hello(SSL *s);\nstatic const SSL_METHOD *ssl23_get_server_method(int ver)\n\t{\n#ifndef OPENSSL_NO_SSL2\n\tif (ver == SSL2_VERSION)\n\t\treturn(SSLv2_server_method());\n#endif\n\tif (ver == SSL3_VERSION)\n\t\treturn(SSLv3_server_method());\n\telse if (ver == TLS1_VERSION)\n\t\treturn(TLSv1_server_method());\n\telse if (ver == TLS1_1_VERSION)\n\t\treturn(TLSv1_1_server_method());\n\telse if (ver == TLS1_2_VERSION)\n\t\treturn(TLSv1_2_server_method());\n\telse\n\t\treturn(NULL);\n\t}\n\nIMPLEMENT_ssl23_meth_func(SSLv23_server_method,\n\t\t\tssl23_accept,\n\t\t\tssl_undefined_function,\n\t\t\tssl23_get_server_method)\n\nint ssl23_accept(SSL *s)\n\t{\n\tBUF_MEM *buf;\n\tunsigned long Time=(unsigned long)time(NULL);\n\tvoid (*cb)(const SSL *ssl,int type,int val)=NULL;\n\tint ret= -1;\n\tint new_state,state;\n\n\tRAND_add(&Time,sizeof(Time),0);\n\tERR_clear_error();\n\tclear_sys_error();\n\n\tif (s->info_callback != NULL)\n\t\tcb=s->info_callback;\n\telse if (s->ctx->info_callback != NULL)\n\t\tcb=s->ctx->info_callback;\n\t\n\ts->in_handshake++;\n\tif (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s); \n\n\tfor (;;)\n\t\t{\n\t\tstate=s->state;\n\n\t\tswitch(s->state)\n\t\t\t{\n\t\tcase SSL_ST_BEFORE:\n\t\tcase SSL_ST_ACCEPT:\n\t\tcase SSL_ST_BEFORE|SSL_ST_ACCEPT:\n\t\tcase SSL_ST_OK|SSL_ST_ACCEPT:\n\n```\n\n#### ssl23_get_client_hello() [lines 235-655]\n```c\n\t}\n\n\nint ssl23_get_client_hello(SSL *s)\n\t{\n\tchar buf_space[11]; /* Request this many bytes in initial read.\n\t * We can detect SSL 3.0/TLS 1.0 Client Hellos\n\t * ('type == 3') correctly only when the following\n\t * is in a single record, which is not guaranteed by\n\t * the protocol specification:\n\t * Byte Content\n\t * 0 type \\\n\t * 1/2 version > record header\n\t * 3/4 length /\n\t * 5 msg_type \\\n\t * 6-8 length > Client Hello message\n\t * 9/10 client_version /\n\t */\n\tchar *buf= &(buf_space[0]);\n\tunsigned char *p,*d,*d_len,*dd;\n\tunsigned int i;\n\tunsigned int csl,sil,cl;\n\tint n=0,j;\n\tint type=0;\n\tint v[2];\n\n\tif (s->state ==\tSSL23_ST_SR_CLNT_HELLO_A)\n\t\t{\n\t\t/* read the initial header */\n\t\tv[0]=v[1]=0;\n\n\t\tif (!ssl3_setup_buffers(s)) goto err;\n\n\t\tn=ssl23_read_bytes(s, sizeof buf_space);\n\t\tif (n != sizeof buf_space) return(n); /* n == -1 || n == 0 */\n\n\t\tp=s->packet;\n\n\t\tmemcpy(buf,p,n);\n\n/* ... 316 lines omitted ... */\n\n\t\ts->method=SSLv2_server_method();\n\t\ts->handshake_func=s->method->ssl_accept;\n#endif\n\t\t}\n\n\tif ((type == 2) || (type == 3))\n\t\t{\n\t\t/* we have SSLv3/TLSv1 (type 2: SSL2 style, type 3: SSL3/TLS style) */\n\n\t\tif (!ssl_init_wbio_buffer(s,1)) goto err;\n\n\t\t/* we are in this state */\n\t\ts->state=SSL3_ST_SR_CLNT_HELLO_A;\n\n\t\tif (type == 3)\n\t\t\t{\n\t\t\t/* put the 'n' bytes we have read into the input buffer\n\t\t\t * for SSLv3 */\n\t\t\ts->rstate=SSL_ST_READ_HEADER;\n\t\t\ts->packet_length=n;\n\t\t\tif (s->s3->rbuf.buf == NULL)\n\t\t\t\tif (!ssl3_setup_read_buffer(s))\n\t\t\t\t\tgoto err;\n\n\t\t\ts->packet= &(s->s3->rbuf.buf[0]);\n/* ... 19 lines omitted ... */\n\t\ts->client_version=(v[0]<<8)|v[1];\n#endif\n\t\ts->handshake_func=s->method->ssl_accept;\n\t\t}\n\t\n\tif ((type < 1) || (type > 3))\n\t\t{\n\t\t/* bad, very bad */\n\t\tSSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_UNKNOWN_PROTOCOL);\n\t\tgoto err;\n\t\t}\n\ts->init_num=0;\n\n\tif (buf != buf_space) OPENSSL_free(buf);\n\treturn(SSL_accept(s));\nerr:\n\tif (buf != buf_space) OPENSSL_free(buf);\n\treturn(-1);\n\t}\n\n```\n\n\n## Upstream Fix\n```diff\ncommit 26a59d9b46574e457870197dffa802871b4c8fc7\nAuthor: Geoff Thorpe \nDate: Wed Oct 15 03:25:50 2014 -0400\n\n Fix no-ssl3 configuration option\n \n CVE-2014-3568\n \n Reviewed-by: Emilia Kasper \n Reviewed-by: Rich Salz \n\nIndex: openssl-1.0.1i/ssl/s23_clnt.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s23_clnt.c\t2014-10-30 17:13:45.901895834 +0100\n+++ openssl-1.0.1i/ssl/s23_clnt.c\t2014-10-30 17:15:17.029990562 +0100\n@@ -125,9 +125,11 @@ static const SSL_METHOD *ssl23_get_clien\n \tif (ver == SSL2_VERSION)\n \t\treturn(SSLv2_client_method());\n #endif\n+#ifndef OPENSSL_NO_SSL3\n \tif (ver == SSL3_VERSION)\n \t\treturn(SSLv3_client_method());\n-\telse if (ver == TLS1_VERSION)\n+#endif\n+\tif (ver == TLS1_VERSION)\n \t\treturn(TLSv1_client_method());\n \telse if (ver == TLS1_1_VERSION)\n \t\treturn(TLSv1_1_client_method());\n@@ -698,6 +700,7 @@ static int ssl23_get_server_hello(SSL *s\n \t\t{\n \t\t/* we have sslv3 or tls1 (server hello or alert) */\n \n+#ifndef OPENSSL_NO_SSL3\n \t\tif ((p[2] == SSL3_VERSION_MINOR) &&\n \t\t\t!(s->options & SSL_OP_NO_SSLv3))\n \t\t\t{\n@@ -712,7 +715,9 @@ static int ssl23_get_server_hello(SSL *s\n \t\t\ts->version=SSL3_VERSION;\n \t\t\ts->method=SSLv3_client_method();\n \t\t\t}\n-\t\telse if ((p[2] == TLS1_VERSION_MINOR) &&\n+\t\telse\n+#endif\n+\t\tif ((p[2] == TLS1_VERSION_MINOR) &&\n \t\t\t!(s->options & SSL_OP_NO_TLSv1))\n \t\t\t{\n \t\t\ts->version=TLS1_VERSION;\nIndex: openssl-1.0.1i/ssl/s23_srvr.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s23_srvr.c\t2014-10-30 17:13:45.901895834 +0100\n+++ openssl-1.0.1i/ssl/s23_srvr.c\t2014-10-30 17:15:17.029990562 +0100\n@@ -127,9 +127,11 @@ static const SSL_METHOD *ssl23_get_serve\n \tif (ver == SSL2_VERSION)\n \t\treturn(SSLv2_server_method());\n #endif\n+#ifndef OPENSSL_NO_SSL3\n \tif (ver == SSL3_VERSION)\n \t\treturn(SSLv3_server_method());\n-\telse if (ver == TLS1_VERSION)\n+#endif\n+\tif (ver == TLS1_VERSION)\n \t\treturn(TLSv1_server_method());\n \telse if (ver == TLS1_1_VERSION)\n \t\treturn(TLSv1_1_server_method());\n@@ -600,6 +602,12 @@ static int ssl23_get_client_hello(SSL *s\n \tif ((type == 2) || (type == 3))\n \t\t{\n \t\t/* we have SSLv3/TLSv1 (type 2: SSL2 style, type 3: SSL3/TLS style) */\n+ s->method = ssl23_get_server_method(s->version);\n+\t\tif (s->method == NULL)\n+\t\t\t{\n+\t\t\tSSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_UNSUPPORTED_PROTOCOL);\n+\t\t\tgoto err;\n+\t\t\t}\n \n \t\tif (!ssl_init_wbio_buffer(s,1)) goto err;\n \n@@ -627,14 +635,6 @@ static int ssl23_get_client_hello(SSL *s\n \t\t\ts->s3->rbuf.left=0;\n \t\t\ts->s3->rbuf.offset=0;\n \t\t\t}\n-\t\tif (s->version == TLS1_2_VERSION)\n-\t\t\ts->method = TLSv1_2_server_method();\n-\t\telse if (s->version == TLS1_1_VERSION)\n-\t\t\ts->method = TLSv1_1_server_method();\n-\t\telse if (s->version == TLS1_VERSION)\n-\t\t\ts->method = TLSv1_server_method();\n-\t\telse\n-\t\t\ts->method = SSLv3_server_method();\n #if 0 /* ssl3_get_client_hello does this */\n \t\ts->client_version=(v[0]<<8)|v[1];\n #endif\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "commit 26a59d9b46574e457870197dffa802871b4c8fc7\nAuthor: Geoff Thorpe \nDate: Wed Oct 15 03:25:50 2014 -0400\n\n Fix no-ssl3 configuration option\n \n CVE-2014-3568\n \n Reviewed-by: Emilia Kasper \n Reviewed-by: Rich Salz \n\nIndex: openssl-1.0.1i/ssl/s23_clnt.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s23_clnt.c\t2014-10-30 17:13:45.901895834 +0100\n+++ openssl-1.0.1i/ssl/s23_clnt.c\t2014-10-30 17:15:17.029990562 +0100\n@@ -125,9 +125,11 @@ static const SSL_METHOD *ssl23_get_clien\n \tif (ver == SSL2_VERSION)\n \t\treturn(SSLv2_client_method());\n #endif\n+#ifndef OPENSSL_NO_SSL3\n \tif (ver == SSL3_VERSION)\n \t\treturn(SSLv3_client_method());\n-\telse if (ver == TLS1_VERSION)\n+#endif\n+\tif (ver == TLS1_VERSION)\n \t\treturn(TLSv1_client_method());\n \telse if (ver == TLS1_1_VERSION)\n \t\treturn(TLSv1_1_client_method());\n@@ -698,6 +700,7 @@ static int ssl23_get_server_hello(SSL *s\n \t\t{\n \t\t/* we have sslv3 or tls1 (server hello or alert) */\n \n+#ifndef OPENSSL_NO_SSL3\n \t\tif ((p[2] == SSL3_VERSION_MINOR) &&\n \t\t\t!(s->options & SSL_OP_NO_SSLv3))\n \t\t\t{\n@@ -712,7 +715,9 @@ static int ssl23_get_server_hello(SSL *s\n \t\t\ts->version=SSL3_VERSION;\n \t\t\ts->method=SSLv3_client_method();\n \t\t\t}\n-\t\telse if ((p[2] == TLS1_VERSION_MINOR) &&\n+\t\telse\n+#endif\n+\t\tif ((p[2] == TLS1_VERSION_MINOR) &&\n \t\t\t!(s->options & SSL_OP_NO_TLSv1))\n \t\t\t{\n \t\t\ts->version=TLS1_VERSION;\nIndex: openssl-1.0.1i/ssl/s23_srvr.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s23_srvr.c\t2014-10-30 17:13:45.901895834 +0100\n+++ openssl-1.0.1i/ssl/s23_srvr.c\t2014-10-30 17:15:17.029990562 +0100\n@@ -127,9 +127,11 @@ static const SSL_METHOD *ssl23_get_serve\n \tif (ver == SSL2_VERSION)\n \t\treturn(SSLv2_server_method());\n #endif\n+#ifndef OPENSSL_NO_SSL3\n \tif (ver == SSL3_VERSION)\n \t\treturn(SSLv3_server_method());\n-\telse if (ver == TLS1_VERSION)\n+#endif\n+\tif (ver == TLS1_VERSION)\n \t\treturn(TLSv1_server_method());\n \telse if (ver == TLS1_1_VERSION)\n \t\treturn(TLSv1_1_server_method());\n@@ -600,6 +602,12 @@ static int ssl23_get_client_hello(SSL *s\n \tif ((type == 2) || (type == 3))\n \t\t{\n \t\t/* we have SSLv3/TLSv1 (type 2: SSL2 style, type 3: SSL3/TLS style) */\n+ s->method = ssl23_get_server_method(s->version);\n+\t\tif (s->method == NULL)\n+\t\t\t{\n+\t\t\tSSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_UNSUPPORTED_PROTOCOL);\n+\t\t\tgoto err;\n+\t\t\t}\n \n \t\tif (!ssl_init_wbio_buffer(s,1)) goto err;\n \n@@ -627,14 +635,6 @@ static int ssl23_get_client_hello(SSL *s\n \t\t\ts->s3->rbuf.left=0;\n \t\t\ts->s3->rbuf.offset=0;\n \t\t\t}\n-\t\tif (s->version == TLS1_2_VERSION)\n-\t\t\ts->method = TLSv1_2_server_method();\n-\t\telse if (s->version == TLS1_1_VERSION)\n-\t\t\ts->method = TLSv1_1_server_method();\n-\t\telse if (s->version == TLS1_VERSION)\n-\t\t\ts->method = TLSv1_server_method();\n-\t\telse\n-\t\t\ts->method = SSLv3_server_method();\n #if 0 /* ssl3_get_client_hello does this */\n \t\ts->client_version=(v[0]<<8)|v[1];\n #endif"}], "metadata": {"id": "openssl-4769-openssl-CVE-2014-3568.patch", "cve_id": "CVE-2015-3197", "package": "openssl", "tier": "identical", "has_source_context": true, "context_tokens_est": 2417, "context_files": 2, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2013-4560\n\nUse-after-free vulnerability in lighttpd before 1.4.33 allows remote attackers to cause a denial of service (segmentation fault and crash) via unspecified vectors that trigger FAMMonitorDirectory failures.\n\n## Package\nlighttpd\n\n## Files to modify\n- src/stat_cache.c\n\n## Upstream Fix\n```diff\norigin: http://download.lighttpd.net/lighttpd/security/lighttpd_sa_2013_03.txt\n\ncommit bbbe8878144ab178c6ec37e9aeb99640cc8b6672\nAuthor: Stefan Bühler \nDate: Tue Nov 12 12:37:03 2013 +0100\n\n [stat-cache] FAM: fix use after free\n\ndiff --git a/src/stat_cache.c b/src/stat_cache.c\nindex e995f3b..924f4dc 100644\n--- a/src/stat_cache.c\n+++ b/src/stat_cache.c\n@@ -648,6 +648,7 @@ handler_t stat_cache_get_entry(server *srv, connection *con, buffer *name, stat_\n \t\t\t\t\t\tFamErrlist[FAMErrno]);\n \n \t\t\t\tfam_dir_entry_free(fam_dir);\n+\t\t\t\tfam_dir = NULL;\n \t\t\t} else {\n \t\t\t\tint osize = 0;\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "origin: http://download.lighttpd.net/lighttpd/security/lighttpd_sa_2013_03.txt\n\ncommit bbbe8878144ab178c6ec37e9aeb99640cc8b6672\nAuthor: Stefan Bühler \nDate: Tue Nov 12 12:37:03 2013 +0100\n\n [stat-cache] FAM: fix use after free\n\ndiff --git a/src/stat_cache.c b/src/stat_cache.c\nindex e995f3b..924f4dc 100644\n--- a/src/stat_cache.c\n+++ b/src/stat_cache.c\n@@ -648,6 +648,7 @@ handler_t stat_cache_get_entry(server *srv, connection *con, buffer *name, stat_\n \t\t\t\t\t\tFamErrlist[FAMErrno]);\n \n \t\t\t\tfam_dir_entry_free(fam_dir);\n+\t\t\t\tfam_dir = NULL;\n \t\t\t} else {\n \t\t\t\tint osize = 0;"}], "metadata": {"id": "lighttpd-2374-cve-2013-4560.patch", "cve_id": "CVE-2013-4560", "package": "lighttpd", "tier": "identical", "has_source_context": false, "license": "BSD-3-Clause"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1g.orig/crypto/rand/rand_egd.c\n\n## Target Source Code\n\n### crypto/rand/rand_egd.c\n\n#### region() [lines 56-143]\n```c\n\n#include \n#include \n#include \n\n/*\n * Query the EGD .\n *\n * This module supplies three routines:\n *\n * RAND_query_egd_bytes(path, buf, bytes)\n * will actually query \"bytes\" bytes of entropy form the egd-socket located\n * at path and will write them to buf (if supplied) or will directly feed\n * it to RAND_seed() if buf==NULL.\n * The number of bytes is not limited by the maximum chunk size of EGD,\n * which is 255 bytes. If more than 255 bytes are wanted, several chunks\n * of entropy bytes are requested. The connection is left open until the\n * query is competed.\n * RAND_query_egd_bytes() returns with\n * -1 if an error occured during connection or communication.\n * num the number of bytes read from the EGD socket. This number is either\n * the number of bytes requested or smaller, if the EGD pool is\n * drained and the daemon signals that the pool is empty.\n * This routine does not touch any RAND_status(). This is necessary, since\n * PRNG functions may call it during initialization.\n *\n * RAND_egd_bytes(path, bytes) will query \"bytes\" bytes and have them\n * used to seed the PRNG.\n * RAND_egd_bytes() is a wrapper for RAND_query_egd_bytes() with buf=NULL.\n * Unlike RAND_query_egd_bytes(), RAND_status() is used to test the\n * seed status so that the return value can reflect the seed state:\n * -1 if an error occured during connection or communication _or_\n * if the PRNG has still not received the required seeding.\n * num the number of bytes read from the EGD socket. This number is either\n * the number of bytes requested or smaller, if the EGD pool is\n * drained and the daemon signals that the pool is empty.\n *\n * RAND_egd(path) will query 255 bytes and use the bytes retreived to seed\n * the PRNG.\n * RAND_egd() is a wrapper for RAND_egd_bytes() with numbytes=255.\n */\n\n#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_NETWARE) || defined(OPENSSL_SYS_VOS) || defined(OPENSSL_SYS_BEOS)\nint RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes)\n\t{\n\treturn(-1);\n\t}\nint RAND_egd(const char *path)\n\t{\n\treturn(-1);\n\t}\n\nint RAND_egd_bytes(const char *path,int bytes)\n\t{\n\treturn(-1);\n\t}\n#else\n#include \n#include OPENSSL_UNISTD\n#include \n#include \n#ifndef NO_SYS_UN_H\n# ifdef OPENSSL_SYS_VXWORKS\n# include \n# else\n# include \n# endif\n#else\nstruct\tsockaddr_un {\n\tshort\tsun_family;\t\t/* AF_UNIX */\n\tchar\tsun_path[108];\t\t/* path name (gag) */\n};\n#endif /* NO_SYS_UN_H */\n#include \n#include \n\n#ifndef offsetof\n# define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)\n#endif\n\nint RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes)\n\t{\n\tint ret = 0;\n\tstruct sockaddr_un addr;\n\tint len, num, numbytes;\n\tint fd = -1;\n\tint success;\n\tunsigned char egdbuf[2], tempbuf[255], *retrievebuf;\n```\n\n\n## Upstream Fix\n```diff\n--- openssl-1.0.1g.orig/crypto/rand/rand_egd.c\n+++ openssl-1.0.1g/crypto/rand/rand_egd.c\n@@ -95,7 +95,7 @@\n * RAND_egd() is a wrapper for RAND_egd_bytes() with numbytes=255.\n */\n \n-#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_NETWARE) || defined(OPENSSL_SYS_VOS) || defined(OPENSSL_SYS_BEOS)\n+#if defined(__linux__) || defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_NETWARE) || defined(OPENSSL_SYS_VOS) || defined(OPENSSL_SYS_BEOS)\n int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes)\n \t{\n \treturn(-1);\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "--- openssl-1.0.1g.orig/crypto/rand/rand_egd.c\n+++ openssl-1.0.1g/crypto/rand/rand_egd.c\n@@ -95,7 +95,7 @@\n * RAND_egd() is a wrapper for RAND_egd_bytes() with numbytes=255.\n */\n \n-#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_NETWARE) || defined(OPENSSL_SYS_VOS) || defined(OPENSSL_SYS_BEOS)\n+#if defined(__linux__) || defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_NETWARE) || defined(OPENSSL_SYS_VOS) || defined(OPENSSL_SYS_BEOS)\n int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes)\n \t{\n \treturn(-1);"}], "metadata": {"id": "openssl-4598-openssl-no-egd.patch", "cve_id": "CVE-2015-3197", "package": "openssl", "tier": "identical", "has_source_context": true, "context_tokens_est": 791, "context_files": 1, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-6250\n\nInteger overflow in the ISO9660 writer in libarchive before 3.2.1 allows remote attackers to cause a denial of service (application crash) or execute arbitrary code via vectors related to verifying filename lengths when writing an ISO9660 archive, which trigger a buffer overflow.\n\n## Package\nlibarchive\n\n## Files to modify\n- libarchive-3.1.2.orig/libarchive/archive_read_support_format_tar.c\n- libarchive/archive_read_support_format_tar.c\n\n## Target Source Code\n\n### libarchive/archive_read_support_format_tar.c\n\n#### archive_read_format_tar_read_header() [lines 421-521]\n```c\n * tar_read_header() function below.\n */\nstatic int\narchive_read_format_tar_read_header(struct archive_read *a,\n struct archive_entry *entry)\n{\n\t/*\n\t * When converting tar archives to cpio archives, it is\n\t * essential that each distinct file have a distinct inode\n\t * number. To simplify this, we keep a static count here to\n\t * assign fake dev/inode numbers to each tar entry. Note that\n\t * pax format archives may overwrite this with something more\n\t * useful.\n\t *\n\t * Ideally, we would track every file read from the archive so\n\t * that we could assign the same dev/ino pair to hardlinks,\n\t * but the memory required to store a complete lookup table is\n\t * probably not worthwhile just to support the relatively\n\t * obscure tar->cpio conversion case.\n\t */\n\tstatic int default_inode;\n\tstatic int default_dev;\n\tstruct tar *tar;\n\tconst char *p;\n\tint r;\n\tsize_t l, unconsumed = 0;\n\n\t/* Assign default device/inode values. */\n\tarchive_entry_set_dev(entry, 1 + default_dev); /* Don't use zero. */\n\tarchive_entry_set_ino(entry, ++default_inode); /* Don't use zero. */\n\t/* Limit generated st_ino number to 16 bits. */\n\tif (default_inode >= 0xffff) {\n\t\t++default_dev;\n\t\tdefault_inode = 0;\n\t}\n\n\ttar = (struct tar *)(a->format->data);\n\ttar->entry_offset = 0;\n\tgnu_clear_sparse_list(tar);\n\ttar->realsize = -1; /* Mark this as \"unset\" */\n\n\t/* Setup default string conversion. */\n\ttar->sconv = tar->opt_sconv;\n\tif (tar->sconv == NULL) {\n\t\tif (!tar->init_default_conversion) {\n\t\t\ttar->sconv_default =\n\t\t\t archive_string_default_conversion_for_read(&(a->archive));\n\t\t\ttar->init_default_conversion = 1;\n\t\t}\n\t\ttar->sconv = tar->sconv_default;\n\t}\n\n\tr = tar_read_header(a, tar, entry, &unconsumed);\n\n\ttar_flush_unconsumed(a, &unconsumed);\n\n\t/*\n\t * \"non-sparse\" files are really just sparse files with\n\t * a single block.\n\t */\n\tif (tar->sparse_list == NULL) {\n\t\tif (gnu_add_sparse_entry(a, tar, 0, tar->entry_bytes_remaining)\n\t\t != ARCHIVE_OK)\n\t\t\treturn (ARCHIVE_FATAL);\n\t} else {\n\t\tstruct sparse_block *sb;\n\n\t\tfor (sb = tar->sparse_list; sb != NULL; sb = sb->next) {\n\t\t\tif (!sb->hole)\n\t\t\t\tarchive_entry_sparse_add_entry(entry,\n\t\t\t\t sb->offset, sb->remaining);\n\t\t}\n\t}\n\n\tif (r == ARCHIVE_OK) {\n\t\t/*\n\t\t * \"Regular\" entry with trailing '/' is really\n\t\t * directory: This is needed for certain old tar\n\t\t * variants and even for some broken newer ones.\n\t\t */\n\t\tconst wchar_t *wp;\n\t\twp = archive_entry_pathname_w(entry);\n\t\tif (wp != NULL) {\n\t\t\tl = wcslen(wp);\n\t\t\tif (archive_entry_filetype(entry) == AE_IFREG\n\t\t\t && wp[l-1] == L'/')\n\t\t\t\tarchive_entry_set_filetype(entry, AE_IFDIR);\n\t\t} else {\n\t\t\tp = archive_entry_pathname(entry);\n\t\t\tif (p == NULL)\n\t\t\t\treturn (ARCHIVE_FAILED);\n\t\t\tl = strlen(p);\n\t\t\tif (archive_entry_filetype(entry) == AE_IFREG\n\t\t\t && p[l-1] == '/')\n\t\t\t\tarchive_entry_set_filetype(entry, AE_IFDIR);\n\t\t}\n\t}\n\treturn (r);\n}\n\nstatic int\n```\n\n\n## Upstream Fix\n```diff\ncommit bb9b157146a62e655fb369b32684398c949fa1b1\nAuthor: Tim Kientzle \nDate: Sat Feb 21 09:36:23 2015 -0800\n\n Issue 407: Tar reader tries to examine last character of an empty filename\n \n Of interest: While working on this, I noted that we have\n an existing test for tar files with empty filenames.\n That test asserts that the correct behavior here is for the\n format handler to return the entry with the empty filename\n and a status of ARCHIVE_OK. Clients need to be robust against\n empty filenames.\n\nIndex: libarchive-3.1.2/libarchive/archive_read_support_format_tar.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_read_support_format_tar.c\n+++ libarchive-3.1.2/libarchive/archive_read_support_format_tar.c\n@@ -442,6 +442,7 @@ archive_read_format_tar_read_header(stru\n \tstatic int default_dev;\n \tstruct tar *tar;\n \tconst char *p;\n+\tconst wchar_t *wp;\n \tint r;\n \tsize_t l, unconsumed = 0;\n \n@@ -492,27 +493,22 @@ archive_read_format_tar_read_header(stru\n \t\t}\n \t}\n \n-\tif (r == ARCHIVE_OK) {\n+\tif (r == ARCHIVE_OK && archive_entry_filetype(entry) == AE_IFREG) {\n \t\t/*\n \t\t * \"Regular\" entry with trailing '/' is really\n \t\t * directory: This is needed for certain old tar\n \t\t * variants and even for some broken newer ones.\n \t\t */\n-\t\tconst wchar_t *wp;\n-\t\twp = archive_entry_pathname_w(entry);\n-\t\tif (wp != NULL) {\n+\t\tif ((wp = archive_entry_pathname_w(entry)) != NULL) {\n \t\t\tl = wcslen(wp);\n-\t\t\tif (archive_entry_filetype(entry) == AE_IFREG\n-\t\t\t && wp[l-1] == L'/')\n+\t\t\tif (l > 0 && wp[l - 1] == L'/') {\n \t\t\t\tarchive_entry_set_filetype(entry, AE_IFDIR);\n-\t\t} else {\n-\t\t\tp = archive_entry_pathname(entry);\n-\t\t\tif (p == NULL)\n-\t\t\t\treturn (ARCHIVE_FAILED);\n+\t\t\t}\n+\t\t} else if ((p = archive_entry_pathname(entry)) != NULL) {\n \t\t\tl = strlen(p);\n-\t\t\tif (archive_entry_filetype(entry) == AE_IFREG\n-\t\t\t && p[l-1] == '/')\n+\t\t\tif (l > 0 && p[l - 1] == '/') {\n \t\t\t\tarchive_entry_set_filetype(entry, AE_IFDIR);\n+\t\t\t}\n \t\t}\n \t}\n \treturn (r);\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "commit bb9b157146a62e655fb369b32684398c949fa1b1\nAuthor: Tim Kientzle \nDate: Sat Feb 21 09:36:23 2015 -0800\n\n Issue 407: Tar reader tries to examine last character of an empty filename\n \n Of interest: While working on this, I noted that we have\n an existing test for tar files with empty filenames.\n That test asserts that the correct behavior here is for the\n format handler to return the entry with the empty filename\n and a status of ARCHIVE_OK. Clients need to be robust against\n empty filenames.\n\nIndex: libarchive-3.1.2/libarchive/archive_read_support_format_tar.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_read_support_format_tar.c\n+++ libarchive-3.1.2/libarchive/archive_read_support_format_tar.c\n@@ -442,6 +442,7 @@ archive_read_format_tar_read_header(stru\n \tstatic int default_dev;\n \tstruct tar *tar;\n \tconst char *p;\n+\tconst wchar_t *wp;\n \tint r;\n \tsize_t l, unconsumed = 0;\n \n@@ -492,27 +493,22 @@ archive_read_format_tar_read_header(stru\n \t\t}\n \t}\n \n-\tif (r == ARCHIVE_OK) {\n+\tif (r == ARCHIVE_OK && archive_entry_filetype(entry) == AE_IFREG) {\n \t\t/*\n \t\t * \"Regular\" entry with trailing '/' is really\n \t\t * directory: This is needed for certain old tar\n \t\t * variants and even for some broken newer ones.\n \t\t */\n-\t\tconst wchar_t *wp;\n-\t\twp = archive_entry_pathname_w(entry);\n-\t\tif (wp != NULL) {\n+\t\tif ((wp = archive_entry_pathname_w(entry)) != NULL) {\n \t\t\tl = wcslen(wp);\n-\t\t\tif (archive_entry_filetype(entry) == AE_IFREG\n-\t\t\t && wp[l-1] == L'/')\n+\t\t\tif (l > 0 && wp[l - 1] == L'/') {\n \t\t\t\tarchive_entry_set_filetype(entry, AE_IFDIR);\n-\t\t} else {\n-\t\t\tp = archive_entry_pathname(entry);\n-\t\t\tif (p == NULL)\n-\t\t\t\treturn (ARCHIVE_FAILED);\n+\t\t\t}\n+\t\t} else if ((p = archive_entry_pathname(entry)) != NULL) {\n \t\t\tl = strlen(p);\n-\t\t\tif (archive_entry_filetype(entry) == AE_IFREG\n-\t\t\t && p[l-1] == '/')\n+\t\t\tif (l > 0 && p[l - 1] == '/') {\n \t\t\t\tarchive_entry_set_filetype(entry, AE_IFDIR);\n+\t\t\t}\n \t\t}\n \t}\n \treturn (r);"}], "metadata": {"id": "libarchive-5942-CVE-2015-8924.patch", "cve_id": "CVE-2016-6250", "package": "libarchive", "tier": "identical", "has_source_context": true, "context_tokens_est": 741, "context_files": 1, "license": "BSD-2-Clause"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-4658\n\nxpointer.c in libxml2 before 2.9.5 (as used in Apple iOS before 10, OS X before 10.12, tvOS before 10, and watchOS before 3, and other products) does not forbid namespace nodes in XPointer ranges, which allows remote attackers to execute arbitrary code or cause a denial of service (use-after-free and memory corruption) via a crafted XML document.\n\n## Package\nlibxml2\n\n## Files to modify\n- buf.c\n- include/libxml/tree.h\n- xmlreader.c\n\n## Target Source Code\n\n### include/libxml/tree.h\n\n#### region() [lines 37-124]\n```c\n\ntypedef struct _xmlParserCtxt xmlParserCtxt;\ntypedef xmlParserCtxt *xmlParserCtxtPtr;\n\ntypedef struct _xmlSAXLocator xmlSAXLocator;\ntypedef xmlSAXLocator *xmlSAXLocatorPtr;\n\ntypedef struct _xmlSAXHandler xmlSAXHandler;\ntypedef xmlSAXHandler *xmlSAXHandlerPtr;\n\n/* entities.h */\ntypedef struct _xmlEntity xmlEntity;\ntypedef xmlEntity *xmlEntityPtr;\n\n/**\n * BASE_BUFFER_SIZE:\n *\n * default buffer size 4000.\n */\n#define BASE_BUFFER_SIZE 4096\n\n/**\n * LIBXML_NAMESPACE_DICT:\n *\n * Defines experimental behaviour:\n * 1) xmlNs gets an additional field @context (a xmlDoc)\n * 2) when creating a tree, xmlNs->href is stored in the dict of xmlDoc.\n */\n/* #define LIBXML_NAMESPACE_DICT */\n\n/**\n * xmlBufferAllocationScheme:\n *\n * A buffer allocation scheme can be defined to either match exactly the\n * need or double it's allocated size each time it is found too small.\n */\n\ntypedef enum {\n XML_BUFFER_ALLOC_DOUBLEIT,\t/* double each time one need to grow */\n XML_BUFFER_ALLOC_EXACT,\t/* grow only to the minimal size */\n XML_BUFFER_ALLOC_IMMUTABLE, /* immutable buffer */\n XML_BUFFER_ALLOC_IO,\t/* special allocation scheme used for I/O */\n XML_BUFFER_ALLOC_HYBRID\t/* exact up to a threshold, and doubleit thereafter */\n} xmlBufferAllocationScheme;\n\n/**\n * xmlBuffer:\n *\n * A buffer structure, this old construct is limited to 2GB and\n * is being deprecated, use API with xmlBuf instead\n */\ntypedef struct _xmlBuffer xmlBuffer;\ntypedef xmlBuffer *xmlBufferPtr;\nstruct _xmlBuffer {\n xmlChar *content;\t\t/* The buffer content UTF8 */\n unsigned int use;\t\t/* The buffer size used */\n unsigned int size;\t\t/* The buffer size */\n xmlBufferAllocationScheme alloc; /* The realloc method */\n xmlChar *contentIO;\t\t/* in IO mode we may have a different base */\n};\n\n/**\n * xmlBuf:\n *\n * A buffer structure, new one, the actual structure internals are not public\n */\n\ntypedef struct _xmlBuf xmlBuf;\n\n/**\n * xmlBufPtr:\n *\n * A pointer to a buffer structure, the actual structure internals are not\n * public\n */\n\ntypedef xmlBuf *xmlBufPtr;\n\n/*\n * A few public routines for xmlBuf. As those are expected to be used\n * mostly internally the bulk of the routines are internal in buf.h\n */\nXMLPUBFUN xmlChar* XMLCALL xmlBufContent\t(const xmlBufPtr buf);\nXMLPUBFUN xmlChar* XMLCALL xmlBufEnd (const xmlBufPtr buf);\nXMLPUBFUN size_t XMLCALL xmlBufUse (const xmlBufPtr buf);\nXMLPUBFUN size_t XMLCALL xmlBufShrink\t(xmlBufPtr buf, size_t len);\n\n/*\n```\n\n\n## Upstream Fix\n```diff\nFrom 213f1fe0d76d30eaed6e5853057defc43e6df2c9 Mon Sep 17 00:00:00 2001\nFrom: Daniel Veillard \nDate: Tue, 14 Apr 2015 17:41:48 +0800\nSubject: [PATCH] CVE-2015-1819 Enforce the reader to run in constant memory\n\nOne of the operation on the reader could resolve entities\nleading to the classic expansion issue. Make sure the\nbuffer used for xmlreader operation is bounded.\nIntroduce a new allocation type for the buffers for this effect.\n---\n buf.c | 43 ++++++++++++++++++++++++++++++++++++++++++-\n include/libxml/tree.h | 3 ++-\n xmlreader.c | 20 +++++++++++++++++++-\n 3 files changed, 63 insertions(+), 3 deletions(-)\n\ndiff --git a/buf.c b/buf.c\nindex 6efc7b677c..07922ff693 100644\n--- a/buf.c\n+++ b/buf.c\n@@ -27,6 +27,7 @@\n #include \n #include \n #include \n+#include /* for XML_MAX_TEXT_LENGTH */\n #include \"buf.h\"\n \n #define WITH_BUFFER_COMPAT\n@@ -299,7 +300,8 @@ xmlBufSetAllocationScheme(xmlBufPtr buf,\n if ((scheme == XML_BUFFER_ALLOC_DOUBLEIT) ||\n (scheme == XML_BUFFER_ALLOC_EXACT) ||\n (scheme == XML_BUFFER_ALLOC_HYBRID) ||\n- (scheme == XML_BUFFER_ALLOC_IMMUTABLE)) {\n+ (scheme == XML_BUFFER_ALLOC_IMMUTABLE) ||\n+\t(scheme == XML_BUFFER_ALLOC_BOUNDED)) {\n \tbuf->alloc = scheme;\n if (buf->buffer)\n buf->buffer->alloc = scheme;\n@@ -458,6 +460,18 @@ xmlBufGrowInternal(xmlBufPtr buf, size_t len) {\n size = buf->use + len + 100;\n #endif\n \n+ if (buf->alloc == XML_BUFFER_ALLOC_BOUNDED) {\n+ /*\n+\t * Used to provide parsing limits\n+\t */\n+ if ((buf->use + len >= XML_MAX_TEXT_LENGTH) ||\n+\t (buf->size >= XML_MAX_TEXT_LENGTH)) {\n+\t xmlBufMemoryError(buf, \"buffer error: text too long\\n\");\n+\t return(0);\n+\t}\n+\tif (size >= XML_MAX_TEXT_LENGTH)\n+\t size = XML_MAX_TEXT_LENGTH;\n+ }\n if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) {\n size_t start_buf = buf->content - buf->contentIO;\n \n@@ -739,6 +753,15 @@ xmlBufResize(xmlBufPtr buf, size_t size)\n CHECK_COMPAT(buf)\n \n if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return(0);\n+ if (buf->alloc == XML_BUFFER_ALLOC_BOUNDED) {\n+ /*\n+\t * Used to provide parsing limits\n+\t */\n+ if (size >= XML_MAX_TEXT_LENGTH) {\n+\t xmlBufMemoryError(buf, \"buffer error: text too long\\n\");\n+\t return(0);\n+\t}\n+ }\n \n /* Don't resize if we don't have to */\n if (size < buf->size)\n@@ -867,6 +890,15 @@ xmlBufAdd(xmlBufPtr buf, const xmlChar *str, int len) {\n \n needSize = buf->use + len + 2;\n if (needSize > buf->size){\n+\tif (buf->alloc == XML_BUFFER_ALLOC_BOUNDED) {\n+\t /*\n+\t * Used to provide parsing limits\n+\t */\n+\t if (needSize >= XML_MAX_TEXT_LENGTH) {\n+\t\txmlBufMemoryError(buf, \"buffer error: text too long\\n\");\n+\t\treturn(-1);\n+\t }\n+\t}\n if (!xmlBufResize(buf, needSize)){\n \t xmlBufMemoryError(buf, \"growing buffer\");\n return XML_ERR_NO_MEMORY;\n@@ -938,6 +970,15 @@ xmlBufAddHead(xmlBufPtr buf, const xmlChar *str, int len) {\n }\n needSize = buf->use + len + 2;\n if (needSize > buf->size){\n+\tif (buf->alloc == XML_BUFFER_ALLOC_BOUNDED) {\n+\t /*\n+\t * Used to provide parsing limits\n+\t */\n+\t if (needSize >= XML_MAX_TEXT_LENGTH) {\n+\t\txmlBufMemoryError(buf, \"buffer error: text too long\\n\");\n+\t\treturn(-1);\n+\t }\n+\t}\n if (!xmlBufResize(buf, needSize)){\n \t xmlBufMemoryError(buf, \"growing buffer\");\n return XML_ERR_NO_MEMORY;\ndiff --git a/include/libxml/tree.h b/include/libxml/tree.h\nindex 2f90717c1b..4a9b3bc634 100644\n--- a/include/libxml/tree.h\n+++ b/include/libxml/tree.h\n@@ -76,7 +76,8 @@ typedef enum {\n XML_BUFFER_ALLOC_EXACT,\t/* grow only to the minimal size */\n XML_BUFFER_ALLOC_IMMUTABLE, /* immutable buffer */\n XML_BUFFER_ALLOC_IO,\t/* special allocation scheme used for I/O */\n- XML_BUFFER_ALLOC_HYBRID\t/* exact up to a threshold, and doubleit thereafter */\n+ XML_BUFFER_ALLOC_HYBRID,\t/* exact up to a threshold, and doubleit thereafter */\n+ XML_BUFFER_ALLOC_BOUNDED\t/* limit the upper size of the buffer */\n } xmlBufferAllocationScheme;\n \n /**\ndiff --git a/xmlreader.c b/xmlreader.c\nindex f19e123382..471e7e2a64 100644\n--- a/xmlreader.c\n+++ b/xmlreader.c\n@@ -2091,6 +2091,9 @@ xmlNewTextReader(xmlParserInputBufferPtr input, const char *URI) {\n \t\t\"xmlNewTextReader : malloc failed\\n\");\n \treturn(NULL);\n }\n+ /* no operation on a reader should require a huge buffer */\n+ xmlBufSetAllocationScheme(ret->buffer,\n+\t\t\t XML_BUFFER_ALLOC_BOUNDED);\n ret->sax = (xmlSAXHandler *) xmlMalloc(sizeof(xmlSAXHandler));\n if (ret->sax == NULL) {\n \txmlBufFree(ret->buffer);\n@@ -3616,6 +3619,7 @@ xmlTextReaderConstValue(xmlTextReaderPtr reader) {\n \t return(((xmlNsPtr) node)->href);\n case XML_ATTRIBUTE_NODE:{\n \t xmlAttrPtr attr = (xmlAttrPtr) node;\n+\t const xmlChar *ret;\n \n \t if ((attr->children != NULL) &&\n \t (attr->children->type == XML_TEXT_NODE) &&\n@@ -3629,10 +3633,21 @@ xmlTextReaderConstValue(xmlTextReaderPtr reader) {\n \"xmlTextReaderSetup : malloc failed\\n\");\n return (NULL);\n }\n+\t\t xmlBufSetAllocationScheme(reader->buffer,\n+\t\t XML_BUFFER_ALLOC_BOUNDED);\n } else\n xmlBufEmpty(reader->buffer);\n \t xmlBufGetNodeContent(reader->buffer, node);\n-\t\treturn(xmlBufContent(reader->buffer));\n+\t\tret = xmlBufContent(reader->buffer);\n+\t\tif (ret == NULL) {\n+\t\t /* error on the buffer best to reallocate */\n+\t\t xmlBufFree(reader->buffer);\n+\t\t reader->buffer = xmlBufCreateSize(100);\n+\t\t xmlBufSetAllocationScheme(reader->buffer,\n+\t\t XML_BUFFER_ALLOC_BOUNDED);\n+\t\t ret = BAD_CAST \"\";\n+\t\t}\n+\t\treturn(ret);\n \t }\n \t break;\n \t}\n@@ -5131,6 +5146,9 @@ xmlTextReaderSetup(xmlTextReaderPtr reader,\n \"xmlTextReaderSetup : malloc failed\\n\");\n return (-1);\n }\n+ /* no operation on a reader should require a huge buffer */\n+ xmlBufSetAllocationScheme(reader->buffer,\n+\t\t\t XML_BUFFER_ALLOC_BOUNDED);\n if (reader->sax == NULL)\n \treader->sax = (xmlSAXHandler *) xmlMalloc(sizeof(xmlSAXHandler));\n if (reader->sax == NULL) {\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From 213f1fe0d76d30eaed6e5853057defc43e6df2c9 Mon Sep 17 00:00:00 2001\nFrom: Daniel Veillard \nDate: Tue, 14 Apr 2015 17:41:48 +0800\nSubject: [PATCH] CVE-2015-1819 Enforce the reader to run in constant memory\n\nOne of the operation on the reader could resolve entities\nleading to the classic expansion issue. Make sure the\nbuffer used for xmlreader operation is bounded.\nIntroduce a new allocation type for the buffers for this effect.\n---\n buf.c | 43 ++++++++++++++++++++++++++++++++++++++++++-\n include/libxml/tree.h | 3 ++-\n xmlreader.c | 20 +++++++++++++++++++-\n 3 files changed, 63 insertions(+), 3 deletions(-)\n\ndiff --git a/buf.c b/buf.c\nindex 6efc7b6..07922ff 100644\n--- a/buf.c\n+++ b/buf.c\n@@ -27,6 +27,7 @@\n #include \n #include \n #include \n+#include /* for XML_MAX_TEXT_LENGTH */\n #include \"buf.h\"\n \n #define WITH_BUFFER_COMPAT\n@@ -299,7 +300,8 @@ xmlBufSetAllocationScheme(xmlBufPtr buf,\n if ((scheme == XML_BUFFER_ALLOC_DOUBLEIT) ||\n (scheme == XML_BUFFER_ALLOC_EXACT) ||\n (scheme == XML_BUFFER_ALLOC_HYBRID) ||\n- (scheme == XML_BUFFER_ALLOC_IMMUTABLE)) {\n+ (scheme == XML_BUFFER_ALLOC_IMMUTABLE) ||\n+\t(scheme == XML_BUFFER_ALLOC_BOUNDED)) {\n \tbuf->alloc = scheme;\n if (buf->buffer)\n buf->buffer->alloc = scheme;\n@@ -458,6 +460,18 @@ xmlBufGrowInternal(xmlBufPtr buf, size_t len) {\n size = buf->use + len + 100;\n #endif\n \n+ if (buf->alloc == XML_BUFFER_ALLOC_BOUNDED) {\n+ /*\n+\t * Used to provide parsing limits\n+\t */\n+ if ((buf->use + len >= XML_MAX_TEXT_LENGTH) ||\n+\t (buf->size >= XML_MAX_TEXT_LENGTH)) {\n+\t xmlBufMemoryError(buf, \"buffer error: text too long\\n\");\n+\t return(0);\n+\t}\n+\tif (size >= XML_MAX_TEXT_LENGTH)\n+\t size = XML_MAX_TEXT_LENGTH;\n+ }\n if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) {\n size_t start_buf = buf->content - buf->contentIO;\n \n@@ -739,6 +753,15 @@ xmlBufResize(xmlBufPtr buf, size_t size)\n CHECK_COMPAT(buf)\n \n if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return(0);\n+ if (buf->alloc == XML_BUFFER_ALLOC_BOUNDED) {\n+ /*\n+\t * Used to provide parsing limits\n+\t */\n+ if (size >= XML_MAX_TEXT_LENGTH) {\n+\t xmlBufMemoryError(buf, \"buffer error: text too long\\n\");\n+\t return(0);\n+\t}\n+ }\n \n /* Don't resize if we don't have to */\n if (size < buf->size)\n@@ -867,6 +890,15 @@ xmlBufAdd(xmlBufPtr buf, const xmlChar *str, int len) {\n \n needSize = buf->use + len + 2;\n if (needSize > buf->size){\n+\tif (buf->alloc == XML_BUFFER_ALLOC_BOUNDED) {\n+\t /*\n+\t * Used to provide parsing limits\n+\t */\n+\t if (needSize >= XML_MAX_TEXT_LENGTH) {\n+\t\txmlBufMemoryError(buf, \"buffer error: text too long\\n\");\n+\t\treturn(-1);\n+\t }\n+\t}\n if (!xmlBufResize(buf, needSize)){\n \t xmlBufMemoryError(buf, \"growing buffer\");\n return XML_ERR_NO_MEMORY;\n@@ -938,6 +970,15 @@ xmlBufAddHead(xmlBufPtr buf, const xmlChar *str, int len) {\n }\n needSize = buf->use + len + 2;\n if (needSize > buf->size){\n+\tif (buf->alloc == XML_BUFFER_ALLOC_BOUNDED) {\n+\t /*\n+\t * Used to provide parsing limits\n+\t */\n+\t if (needSize >= XML_MAX_TEXT_LENGTH) {\n+\t\txmlBufMemoryError(buf, \"buffer error: text too long\\n\");\n+\t\treturn(-1);\n+\t }\n+\t}\n if (!xmlBufResize(buf, needSize)){\n \t xmlBufMemoryError(buf, \"growing buffer\");\n return XML_ERR_NO_MEMORY;\ndiff --git a/include/libxml/tree.h b/include/libxml/tree.h\nindex 2f90717..4a9b3bc 100644\n--- a/include/libxml/tree.h\n+++ b/include/libxml/tree.h\n@@ -76,7 +76,8 @@ typedef enum {\n XML_BUFFER_ALLOC_EXACT,\t/* grow only to the minimal size */\n XML_BUFFER_ALLOC_IMMUTABLE, /* immutable buffer */\n XML_BUFFER_ALLOC_IO,\t/* special allocation scheme used for I/O */\n- XML_BUFFER_ALLOC_HYBRID\t/* exact up to a threshold, and doubleit thereafter */\n+ XML_BUFFER_ALLOC_HYBRID,\t/* exact up to a threshold, and doubleit thereafter */\n+ XML_BUFFER_ALLOC_BOUNDED\t/* limit the upper size of the buffer */\n } xmlBufferAllocationScheme;\n \n /**\ndiff --git a/xmlreader.c b/xmlreader.c\nindex f19e123..471e7e2 100644\n--- a/xmlreader.c\n+++ b/xmlreader.c\n@@ -2091,6 +2091,9 @@ xmlNewTextReader(xmlParserInputBufferPtr input, const char *URI) {\n \t\t\"xmlNewTextReader : malloc failed\\n\");\n \treturn(NULL);\n }\n+ /* no operation on a reader should require a huge buffer */\n+ xmlBufSetAllocationScheme(ret->buffer,\n+\t\t\t XML_BUFFER_ALLOC_BOUNDED);\n ret->sax = (xmlSAXHandler *) xmlMalloc(sizeof(xmlSAXHandler));\n if (ret->sax == NULL) {\n \txmlBufFree(ret->buffer);\n@@ -3616,6 +3619,7 @@ xmlTextReaderConstValue(xmlTextReaderPtr reader) {\n \t return(((xmlNsPtr) node)->href);\n case XML_ATTRIBUTE_NODE:{\n \t xmlAttrPtr attr = (xmlAttrPtr) node;\n+\t const xmlChar *ret;\n \n \t if ((attr->children != NULL) &&\n \t (attr->children->type == XML_TEXT_NODE) &&\n@@ -3629,10 +3633,21 @@ xmlTextReaderConstValue(xmlTextReaderPtr reader) {\n \"xmlTextReaderSetup : malloc failed\\n\");\n return (NULL);\n }\n+\t\t xmlBufSetAllocationScheme(reader->buffer,\n+\t\t XML_BUFFER_ALLOC_BOUNDED);\n } else\n xmlBufEmpty(reader->buffer);\n \t xmlBufGetNodeContent(reader->buffer, node);\n-\t\treturn(xmlBufContent(reader->buffer));\n+\t\tret = xmlBufContent(reader->buffer);\n+\t\tif (ret == NULL) {\n+\t\t /* error on the buffer best to reallocate */\n+\t\t xmlBufFree(reader->buffer);\n+\t\t reader->buffer = xmlBufCreateSize(100);\n+\t\t xmlBufSetAllocationScheme(reader->buffer,\n+\t\t XML_BUFFER_ALLOC_BOUNDED);\n+\t\t ret = BAD_CAST \"\";\n+\t\t}\n+\t\treturn(ret);\n \t }\n \t break;\n \t}\n@@ -5131,6 +5146,9 @@ xmlTextReaderSetup(xmlTextReaderPtr reader,\n \"xmlTextReaderSetup : malloc failed\\n\");\n return (-1);\n }\n+ /* no operation on a reader should require a huge buffer */\n+ xmlBufSetAllocationScheme(reader->buffer,\n+\t\t\t XML_BUFFER_ALLOC_BOUNDED);\n if (reader->sax == NULL)\n \treader->sax = (xmlSAXHandler *) xmlMalloc(sizeof(xmlSAXHandler));\n if (reader->sax == NULL) {\n-- \n2.3.5"}], "metadata": {"id": "libxml2-5762-libxml2-2.9.1-CVE-2015-1819.pa", "cve_id": "CVE-2016-4658", "package": "libxml2", "upstream_enriched": true, "upstream_commit": "213f1fe0d76d30eaed6e5853057defc43e6df2c9", "upstream_repo": "GNOME/libxml2", "tier": "adapted", "has_source_context": true, "context_tokens_est": 636, "context_files": 1, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1i/ssl/ssl_err.c\n- openssl-1.0.1i.orig/ssl/ssl_locl.h\n- openssl-1.0.1i.orig/ssl/ssl_sess.c\n- openssl-1.0.1i.orig/ssl/s3_clnt.c\n- openssl-1.0.1i/ssl/ssl_locl.h\n\n## Target Source Code\n\n### ssl/ssl.h\n\n#### ERR_load_SSL_strings() [lines 2215-2301]\n```c\n#define SSL_F_SSL_CTX_USE_CERTIFICATE\t\t\t 171\n#define SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1\t\t 172\n#define SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE\t 220\n#define SSL_F_SSL_CTX_USE_CERTIFICATE_FILE\t\t 173\n#define SSL_F_SSL_CTX_USE_PRIVATEKEY\t\t\t 174\n#define SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1\t\t 175\n#define SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE\t\t 176\n#define SSL_F_SSL_CTX_USE_PSK_IDENTITY_HINT\t\t 272\n#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY\t\t\t 177\n#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1\t\t 178\n#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE\t\t 179\n#define SSL_F_SSL_DO_HANDSHAKE\t\t\t\t 180\n#define SSL_F_SSL_GET_NEW_SESSION\t\t\t 181\n#define SSL_F_SSL_GET_PREV_SESSION\t\t\t 217\n#define SSL_F_SSL_GET_SERVER_SEND_CERT\t\t\t 182\n#define SSL_F_SSL_GET_SERVER_SEND_PKEY\t\t\t 317\n#define SSL_F_SSL_GET_SIGN_PKEY\t\t\t\t 183\n#define SSL_F_SSL_INIT_WBIO_BUFFER\t\t\t 184\n#define SSL_F_SSL_LOAD_CLIENT_CA_FILE\t\t\t 185\n#define SSL_F_SSL_NEW\t\t\t\t\t 186\n#define SSL_F_SSL_PARSE_CLIENTHELLO_RENEGOTIATE_EXT\t 300\n#define SSL_F_SSL_PARSE_CLIENTHELLO_TLSEXT\t\t 302\n#define SSL_F_SSL_PARSE_CLIENTHELLO_USE_SRTP_EXT\t 310\n#define SSL_F_SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT\t 301\n#define SSL_F_SSL_PARSE_SERVERHELLO_TLSEXT\t\t 303\n#define SSL_F_SSL_PARSE_SERVERHELLO_USE_SRTP_EXT\t 311\n#define SSL_F_SSL_PEEK\t\t\t\t\t 270\n#define SSL_F_SSL_PREPARE_CLIENTHELLO_TLSEXT\t\t 281\n#define SSL_F_SSL_PREPARE_SERVERHELLO_TLSEXT\t\t 282\n#define SSL_F_SSL_READ\t\t\t\t\t 223\n#define SSL_F_SSL_RSA_PRIVATE_DECRYPT\t\t\t 187\n#define SSL_F_SSL_RSA_PUBLIC_ENCRYPT\t\t\t 188\n#define SSL_F_SSL_SESSION_NEW\t\t\t\t 189\n#define SSL_F_SSL_SESSION_PRINT_FP\t\t\t 190\n#define SSL_F_SSL_SESSION_SET1_ID_CONTEXT\t\t 312\n#define SSL_F_SSL_SESS_CERT_NEW\t\t\t\t 225\n#define SSL_F_SSL_SET_CERT\t\t\t\t 191\n#define SSL_F_SSL_SET_CIPHER_LIST\t\t\t 271\n#define SSL_F_SSL_SET_FD\t\t\t\t 192\n#define SSL_F_SSL_SET_PKEY\t\t\t\t 193\n#define SSL_F_SSL_SET_PURPOSE\t\t\t\t 227\n#define SSL_F_SSL_SET_RFD\t\t\t\t 194\n#define SSL_F_SSL_SET_SESSION\t\t\t\t 195\n#define SSL_F_SSL_SET_SESSION_ID_CONTEXT\t\t 218\n#define SSL_F_SSL_SET_SESSION_TICKET_EXT\t\t 294\n#define SSL_F_SSL_SET_TRUST\t\t\t\t 228\n#define SSL_F_SSL_SET_WFD\t\t\t\t 196\n#define SSL_F_SSL_SHUTDOWN\t\t\t\t 224\n#define SSL_F_SSL_SRP_CTX_INIT\t\t\t\t 313\n#define SSL_F_SSL_UNDEFINED_CONST_FUNCTION\t\t 243\n#define SSL_F_SSL_UNDEFINED_FUNCTION\t\t\t 197\n#define SSL_F_SSL_UNDEFINED_VOID_FUNCTION\t\t 244\n#define SSL_F_SSL_USE_CERTIFICATE\t\t\t 198\n#define SSL_F_SSL_USE_CERTIFICATE_ASN1\t\t\t 199\n#define SSL_F_SSL_USE_CERTIFICATE_FILE\t\t\t 200\n#define SSL_F_SSL_USE_PRIVATEKEY\t\t\t 201\n#define SSL_F_SSL_USE_PRIVATEKEY_ASN1\t\t\t 202\n#define SSL_F_SSL_USE_PRIVATEKEY_FILE\t\t\t 203\n#define SSL_F_SSL_USE_PSK_IDENTITY_HINT\t\t\t 273\n#define SSL_F_SSL_USE_RSAPRIVATEKEY\t\t\t 204\n#define SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1\t\t 205\n#define SSL_F_SSL_USE_RSAPRIVATEKEY_FILE\t\t 206\n#define SSL_F_SSL_VERIFY_CERT_CHAIN\t\t\t 207\n#define SSL_F_SSL_WRITE\t\t\t\t\t 208\n#define SSL_F_TLS1_CERT_VERIFY_MAC\t\t\t 286\n#define SSL_F_TLS1_CHANGE_CIPHER_STATE\t\t\t 209\n#define SSL_F_TLS1_CHECK_SERVERHELLO_TLSEXT\t\t 274\n#define SSL_F_TLS1_ENC\t\t\t\t\t 210\n#define SSL_F_TLS1_EXPORT_KEYING_MATERIAL\t\t 314\n#define SSL_F_TLS1_HEARTBEAT\t\t\t\t 315\n#define SSL_F_TLS1_PREPARE_CLIENTHELLO_TLSEXT\t\t 275\n#define SSL_F_TLS1_PR\n/* ... truncated ... */\n```\n\n### ssl/s3_clnt.c\n\n#### ssl3_get_new_session_ticket() [lines 2049-2141]\n```c\n\treturn(X509_NAME_cmp(*a,*b));\n\t}\n#ifndef OPENSSL_NO_TLSEXT\nint ssl3_get_new_session_ticket(SSL *s)\n\t{\n\tint ok,al,ret=0, ticklen;\n\tlong n;\n\tconst unsigned char *p;\n\tunsigned char *d;\n\n\tn=s->method->ssl_get_message(s,\n\t\tSSL3_ST_CR_SESSION_TICKET_A,\n\t\tSSL3_ST_CR_SESSION_TICKET_B,\n\t\t-1,\n\t\t16384,\n\t\t&ok);\n\n\tif (!ok)\n\t\treturn((int)n);\n\n\tif (s->s3->tmp.message_type == SSL3_MT_FINISHED)\n\t\t{\n\t\ts->s3->tmp.reuse_message=1;\n\t\treturn(1);\n\t\t}\n\tif (s->s3->tmp.message_type != SSL3_MT_NEWSESSION_TICKET)\n\t\t{\n\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\tSSLerr(SSL_F_SSL3_GET_NEW_SESSION_TICKET,SSL_R_BAD_MESSAGE_TYPE);\n\t\tgoto f_err;\n\t\t}\n\tif (n < 6)\n\t\t{\n\t\t/* need at least ticket_lifetime_hint + ticket length */\n\t\tal = SSL_AD_DECODE_ERROR;\n\t\tSSLerr(SSL_F_SSL3_GET_NEW_SESSION_TICKET,SSL_R_LENGTH_MISMATCH);\n\t\tgoto f_err;\n\t\t}\n\n\tp=d=(unsigned char *)s->init_msg;\n\tn2l(p, s->session->tlsext_tick_lifetime_hint);\n\tn2s(p, ticklen);\n\t/* ticket_lifetime_hint + ticket_length + ticket */\n\tif (ticklen + 6 != n)\n\t\t{\n\t\tal = SSL_AD_DECODE_ERROR;\n\t\tSSLerr(SSL_F_SSL3_GET_NEW_SESSION_TICKET,SSL_R_LENGTH_MISMATCH);\n\t\tgoto f_err;\n\t\t}\n\tif (s->session->tlsext_tick)\n\t\t{\n\t\tOPENSSL_free(s->session->tlsext_tick);\n\t\ts->session->tlsext_ticklen = 0;\n\t\t}\n\ts->session->tlsext_tick = OPENSSL_malloc(ticklen);\n\tif (!s->session->tlsext_tick)\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_GET_NEW_SESSION_TICKET,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tmemcpy(s->session->tlsext_tick, p, ticklen);\n\ts->session->tlsext_ticklen = ticklen;\n\t/* There are two ways to detect a resumed ticket sesion.\n\t * One is to set an appropriate session ID and then the server\n\t * must return a match in ServerHello. This allows the normal\n\t * client session ID matching to work and we know much \n\t * earlier that the ticket has been accepted.\n\t * \n\t * The other way is to set zero length session ID when the\n\t * ticket is presented and rely on the handshake to determine\n\t * session resumption.\n\t *\n\t * We choose the former approach because this fits in with\n\t * assumptions elsewhere in OpenSSL. The session ID is set\n\t * to the SHA256 (or SHA1 is SHA256 is disabled) hash of the\n\t * ticket.\n\t */ \n\tEVP_Digest(p, ticklen,\n\t\t\ts->session->session_id, &s->session->session_id_length,\n#ifndef OPENSSL_NO_SHA256\n\t\t\t\t\t\t\tEVP_sha256(), NULL);\n#else\n\t\t\t\t\t\t\tEVP_sha1(), NULL);\n#endif\n\tret=1;\n\treturn(ret);\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,al);\nerr:\n\treturn(-1);\n\t}\n\nint ssl3_get_cert_status(SSL *s)\n```\n\n### ssl/ssl_err.c\n\n#### region() [lines 206-292]\n```c\n{ERR_FUNC(SSL_F_SSL_CTRL),\t\"SSL_ctrl\"},\n{ERR_FUNC(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY),\t\"SSL_CTX_check_private_key\"},\n{ERR_FUNC(SSL_F_SSL_CTX_MAKE_PROFILES),\t\"SSL_CTX_MAKE_PROFILES\"},\n{ERR_FUNC(SSL_F_SSL_CTX_NEW),\t\"SSL_CTX_new\"},\n{ERR_FUNC(SSL_F_SSL_CTX_SET_CIPHER_LIST),\t\"SSL_CTX_set_cipher_list\"},\n{ERR_FUNC(SSL_F_SSL_CTX_SET_CLIENT_CERT_ENGINE),\t\"SSL_CTX_set_client_cert_engine\"},\n{ERR_FUNC(SSL_F_SSL_CTX_SET_PURPOSE),\t\"SSL_CTX_set_purpose\"},\n{ERR_FUNC(SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT),\t\"SSL_CTX_set_session_id_context\"},\n{ERR_FUNC(SSL_F_SSL_CTX_SET_SSL_VERSION),\t\"SSL_CTX_set_ssl_version\"},\n{ERR_FUNC(SSL_F_SSL_CTX_SET_TRUST),\t\"SSL_CTX_set_trust\"},\n{ERR_FUNC(SSL_F_SSL_CTX_USE_CERTIFICATE),\t\"SSL_CTX_use_certificate\"},\n{ERR_FUNC(SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1),\t\"SSL_CTX_use_certificate_ASN1\"},\n{ERR_FUNC(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE),\t\"SSL_CTX_use_certificate_chain_file\"},\n{ERR_FUNC(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE),\t\"SSL_CTX_use_certificate_file\"},\n{ERR_FUNC(SSL_F_SSL_CTX_USE_PRIVATEKEY),\t\"SSL_CTX_use_PrivateKey\"},\n{ERR_FUNC(SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1),\t\"SSL_CTX_use_PrivateKey_ASN1\"},\n{ERR_FUNC(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE),\t\"SSL_CTX_use_PrivateKey_file\"},\n{ERR_FUNC(SSL_F_SSL_CTX_USE_PSK_IDENTITY_HINT),\t\"SSL_CTX_use_psk_identity_hint\"},\n{ERR_FUNC(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY),\t\"SSL_CTX_use_RSAPrivateKey\"},\n{ERR_FUNC(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1),\t\"SSL_CTX_use_RSAPrivateKey_ASN1\"},\n{ERR_FUNC(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE),\t\"SSL_CTX_use_RSAPrivateKey_file\"},\n{ERR_FUNC(SSL_F_SSL_DO_HANDSHAKE),\t\"SSL_do_handshake\"},\n{ERR_FUNC(SSL_F_SSL_GET_NEW_SESSION),\t\"SSL_GET_NEW_SESSION\"},\n{ERR_FUNC(SSL_F_SSL_GET_PREV_SESSION),\t\"SSL_GET_PREV_SESSION\"},\n{ERR_FUNC(SSL_F_SSL_GET_SERVER_SEND_CERT),\t\"SSL_GET_SERVER_SEND_CERT\"},\n{ERR_FUNC(SSL_F_SSL_GET_SERVER_SEND_PKEY),\t\"SSL_GET_SERVER_SEND_PKEY\"},\n{ERR_FUNC(SSL_F_SSL_GET_SIGN_PKEY),\t\"SSL_GET_SIGN_PKEY\"},\n{ERR_FUNC(SSL_F_SSL_INIT_WBIO_BUFFER),\t\"SSL_INIT_WBIO_BUFFER\"},\n{ERR_FUNC(SSL_F_SSL_LOAD_CLIENT_CA_FILE),\t\"SSL_load_client_CA_file\"},\n{ERR_FUNC(SSL_F_SSL_NEW),\t\"SSL_new\"},\n{ERR_FUNC(SSL_F_SSL_PARSE_CLIENTHELLO_RENEGOTIATE_EXT),\t\"SSL_PARSE_CLIENTHELLO_RENEGOTIATE_EXT\"},\n{ERR_FUNC(SSL_F_SSL_PARSE_CLIENTHELLO_TLSEXT),\t\"SSL_PARSE_CLIENTHELLO_TLSEXT\"},\n{ERR_FUNC(SSL_F_SSL_PARSE_CLIENTHELLO_USE_SRTP_EXT),\t\"SSL_PARSE_CLIENTHELLO_USE_SRTP_EXT\"},\n{ERR_FUNC(SSL_F_SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT),\t\"SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT\"},\n{ERR_FUNC(SSL_F_SSL_PARSE_SERVERHELLO_TLSEXT),\t\"SSL_PARSE_SERVERHELLO_TLSEXT\"},\n{ERR_FUNC(SSL_F_SSL_PARSE_SERVERHELLO_USE_SRTP_EXT),\t\"SSL_PARSE_SERVERHELLO_USE_SRTP_EXT\"},\n{ERR_FUNC(SSL_F_SSL_PEEK),\t\"SSL_peek\"},\n{ERR_FUNC(SSL_F_SSL_PREPARE_CLIENTHELLO_TLSEXT),\t\"SSL_PREPARE_CLIENTHELLO_TLSEXT\"},\n{ERR_FUNC(SSL_F_SSL_PREPARE_SERVERHELLO_TLSEXT),\t\"SSL_PREPARE_SERVERHELLO_TLSEXT\"},\n{ERR_FUNC(SSL_F_SSL_READ),\t\"SSL_read\"},\n{ERR_FUNC(SSL_F_SSL_RSA_PRIVATE_DECRYPT),\t\"SSL_RSA_PRIVATE_DECRYPT\"},\n{ERR_FUNC(SSL_F_SSL_RSA_PUBLIC_ENCRYPT),\t\"SSL_RSA_PUBLIC_ENCRYPT\"},\n{ERR_FUNC(SSL_F_SSL_SESSION_NEW),\t\"SSL_SESSION_new\"},\n{ERR_FUNC(SSL_F_SSL_SESSION_PRINT_FP),\t\"SSL_SESSION_print_fp\"},\n{ERR_FUNC(SSL_F_SSL_SESSION\n/* ... truncated ... */\n```\n\n### ssl/ssl_locl.h\n\n#### ssl_sess_cert_free() [lines 796-882]\n```c\n\t\tdtls1_ctrl, \\\n\t\tssl3_ctx_ctrl, \\\n\t\tssl3_get_cipher_by_char, \\\n\t\tssl3_put_cipher_by_char, \\\n\t\tssl3_pending, \\\n\t\tssl3_num_ciphers, \\\n\t\tdtls1_get_cipher, \\\n\t\ts_get_meth, \\\n\t\tdtls1_default_timeout, \\\n\t\t&DTLSv1_enc_data, \\\n\t\tssl_undefined_void_function, \\\n\t\tssl3_callback_ctrl, \\\n\t\tssl3_ctx_callback_ctrl, \\\n\t}; \\\n\treturn &func_name##_data; \\\n\t}\n\nstruct openssl_ssl_test_functions\n\t{\n\tint (*p_ssl_init_wbio_buffer)(SSL *s, int push);\n\tint (*p_ssl3_setup_buffers)(SSL *s);\n\tint (*p_tls1_process_heartbeat)(SSL *s);\n\tint (*p_dtls1_process_heartbeat)(SSL *s);\n\t};\n\n#ifndef OPENSSL_UNIT_TEST\n\nvoid ssl_clear_cipher_ctx(SSL *s);\nint ssl_clear_bad_session(SSL *s);\nCERT *ssl_cert_new(void);\nCERT *ssl_cert_dup(CERT *cert);\nint ssl_cert_inst(CERT **o);\nvoid ssl_cert_free(CERT *c);\nSESS_CERT *ssl_sess_cert_new(void);\nvoid ssl_sess_cert_free(SESS_CERT *sc);\nint ssl_set_peer_cert_type(SESS_CERT *c, int type);\nint ssl_get_new_session(SSL *s, int session);\nint ssl_get_prev_session(SSL *s, unsigned char *session,int len, const unsigned char *limit);\nint ssl_cipher_id_cmp(const SSL_CIPHER *a,const SSL_CIPHER *b);\nDECLARE_OBJ_BSEARCH_GLOBAL_CMP_FN(SSL_CIPHER, SSL_CIPHER,\n\t\t\t\t ssl_cipher_id);\nint ssl_cipher_ptr_id_cmp(const SSL_CIPHER * const *ap,\n\t\t\tconst SSL_CIPHER * const *bp);\nSTACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num,\n\t\t\t\t\t STACK_OF(SSL_CIPHER) **skp);\nint ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p,\n int (*put_cb)(const SSL_CIPHER *, unsigned char *));\nSTACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *meth,\n\t\t\t\t\t STACK_OF(SSL_CIPHER) **pref,\n\t\t\t\t\t STACK_OF(SSL_CIPHER) **sorted,\n\t\t\t\t\t const char *rule_str);\nvoid ssl_update_cache(SSL *s, int mode);\nint ssl_cipher_get_evp(const SSL_SESSION *s,const EVP_CIPHER **enc,\n\t\t const EVP_MD **md,int *mac_pkey_type,int *mac_secret_size, SSL_COMP **comp);\nint ssl_get_handshake_digest(int i,long *mask,const EVP_MD **md);\t\t\t \nint ssl_verify_cert_chain(SSL *s,STACK_OF(X509) *sk);\nint ssl_undefined_function(SSL *s);\nint ssl_undefined_void_function(void);\nint ssl_undefined_const_function(const SSL *s);\nCERT_PKEY *ssl_get_server_send_pkey(const SSL *s);\nX509 *ssl_get_server_send_cert(const SSL *);\nEVP_PKEY *ssl_get_sign_pkey(SSL *s,const SSL_CIPHER *c, const EVP_MD **pmd);\nint ssl_cert_type(X509 *x,EVP_PKEY *pkey);\nvoid ssl_set_cert_masks(CERT *c, const SSL_CIPHER *cipher);\nSTACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s);\nint ssl_verify_alarm_type(long type);\nvoid ssl_load_ciphers(void);\nint ssl_fill_hello_random(SSL *s, int server, unsigned char *field, int len);\n\nint ssl2_enc_init(SSL *s, int client);\nint ssl2_generate_key_material(SSL *s);\nvoid ssl2_enc(SSL *s,int send_data);\nvoid ssl2_mac(SSL *s,unsigned char *mac,int send_data);\nconst SSL_CIPHER *ssl2_get_cipher_by_char(const unsigned char *p);\nint ssl2_put_cipher_by_char(const SSL_CIPHER *c,unsigned char *p);\nint ssl2_part_read(SSL *s, unsigned long f, int i);\nint ssl2_do_write(SSL *s);\nint ssl2_set_certificate(SSL *s, int type, int len, const unsigned char *data);\nvoid ssl2_return_\n/* ... truncated ... */\n```\n\n### ssl/ssl_sess.c\n\n#### region() [lines 185-271]\n```c\n\treturn(CRYPTO_get_ex_data(&s->ex_data,idx));\n\t}\n\nSSL_SESSION *SSL_SESSION_new(void)\n\t{\n\tSSL_SESSION *ss;\n\n\tss=(SSL_SESSION *)OPENSSL_malloc(sizeof(SSL_SESSION));\n\tif (ss == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_SESSION_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(0);\n\t\t}\n\tmemset(ss,0,sizeof(SSL_SESSION));\n\n\tss->verify_result = 1; /* avoid 0 (= X509_V_OK) just in case */\n\tss->references=1;\n\tss->timeout=60*5+4; /* 5 minute timeout by default */\n\tss->time=(unsigned long)time(NULL);\n\tss->prev=NULL;\n\tss->next=NULL;\n\tss->compress_meth=0;\n#ifndef OPENSSL_NO_TLSEXT\n\tss->tlsext_hostname = NULL; \n#ifndef OPENSSL_NO_EC\n\tss->tlsext_ecpointformatlist_length = 0;\n\tss->tlsext_ecpointformatlist = NULL;\n\tss->tlsext_ellipticcurvelist_length = 0;\n\tss->tlsext_ellipticcurvelist = NULL;\n#endif\n#endif\n\tCRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data);\n#ifndef OPENSSL_NO_PSK\n\tss->psk_identity_hint=NULL;\n\tss->psk_identity=NULL;\n#endif\n#ifndef OPENSSL_NO_SRP\n\tss->srp_username=NULL;\n#endif\n\treturn(ss);\n\t}\n\nconst unsigned char *SSL_SESSION_get_id(const SSL_SESSION *s, unsigned int *len)\n\t{\n\tif(len)\n\t\t*len = s->session_id_length;\n\treturn s->session_id;\n\t}\n\nunsigned int SSL_SESSION_get_compress_id(const SSL_SESSION *s)\n\t{\n\treturn s->compress_meth;\n\t}\n\n/* Even with SSLv2, we have 16 bytes (128 bits) of session ID space. SSLv3/TLSv1\n * has 32 bytes (256 bits). As such, filling the ID with random gunk repeatedly\n * until we have no conflict is going to complete in one iteration pretty much\n * \"most\" of the time (btw: understatement). So, if it takes us 10 iterations\n * and we still can't avoid a conflict - well that's a reasonable point to call\n * it quits. Either the RAND code is broken or someone is trying to open roughly\n * very close to 2^128 (or 2^256) SSL sessions to our server. How you might\n * store that many sessions is perhaps a more interesting question ... */\n\n#define MAX_SESS_ID_ATTEMPTS 10\nstatic int def_generate_session_id(const SSL *ssl, unsigned char *id,\n\t\t\t\tunsigned int *id_len)\n{\n\tunsigned int retry = 0;\n\tdo\n\t\tif (RAND_pseudo_bytes(id, *id_len) <= 0)\n\t\t\treturn 0;\n\twhile(SSL_has_matching_session_id(ssl, id, *id_len) &&\n\t\t(++retry < MAX_SESS_ID_ATTEMPTS));\n\tif(retry < MAX_SESS_ID_ATTEMPTS)\n\t\treturn 1;\n\t/* else - woops a session_id match */\n\t/* XXX We should also check the external cache --\n\t * but the probability of a collision is negligible, and\n\t * we could not prevent the concurrent creation of sessions\n\t * with identical IDs since we currently don't have means\n\t * to atomically check whether a session ID already exists\n\t * and make a reservation for it if it does not\n\t * (this problem applies to the internal cache as well).\n\t */\n\treturn 0;\n}\n\n```\n\n\n## Upstream Fix\n```diff\ncommit 98ece4eebfb6cd45cc8d550c6ac0022965071afc\nAuthor: Matt Caswell \nDate: Mon May 18 16:27:48 2015 +0100\n\n Fix race condition in NewSessionTicket\n \n If a NewSessionTicket is received by a multi-threaded client when\n attempting to reuse a previous ticket then a race condition can occur\n potentially leading to a double free of the ticket data.\n \n CVE-2015-1791\n \n This also fixes RT#3808 where a session ID is changed for a session already\n in the client session cache. Since the session ID is the key to the cache\n this breaks the cache access.\n \n Parts of this patch were inspired by this Akamai change:\n https://github.com/akamai/openssl/commit/c0bf69a791239ceec64509f9f19fcafb2461b0d3\n \n Reviewed-by: Rich Salz \n\ncommit 907f04a30354615e54beaa2bc0b986083f7793ee\nAuthor: Matt Caswell \nDate: Thu Jun 11 01:30:06 2015 +0100\n\n More ssl_session_dup fixes\n \n Fix error handling in ssl_session_dup, as well as incorrect setting up of\n the session ticket. Follow on from CVE-2015-1791.\n \n Thanks to LibreSSL project for reporting these issues.\n \n Conflicts:\n \tssl/ssl_sess.c\n \n Reviewed-by: Tim Hudson \n\nIndex: openssl-1.0.1i/ssl/ssl.h\n===================================================================\n--- openssl-1.0.1i.orig/ssl/ssl.h\t2015-06-12 19:15:11.549954732 +0200\n+++ openssl-1.0.1i/ssl/ssl.h\t2015-06-12 19:15:13.279975926 +0200\n@@ -2254,6 +2254,7 @@ void ERR_load_SSL_strings(void);\n #define SSL_F_SSL_READ\t\t\t\t\t 223\n #define SSL_F_SSL_RSA_PRIVATE_DECRYPT\t\t\t 187\n #define SSL_F_SSL_RSA_PUBLIC_ENCRYPT\t\t\t 188\n+#define SSL_F_SSL_SESSION_DUP\t\t\t\t 348\n #define SSL_F_SSL_SESSION_NEW\t\t\t\t 189\n #define SSL_F_SSL_SESSION_PRINT_FP\t\t\t 190\n #define SSL_F_SSL_SESSION_SET1_ID_CONTEXT\t\t 312\nIndex: openssl-1.0.1i/ssl/s3_clnt.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s3_clnt.c\t2015-06-12 19:15:11.549954732 +0200\n+++ openssl-1.0.1i/ssl/s3_clnt.c\t2015-06-12 19:15:13.279975926 +0200\n@@ -2105,6 +2105,38 @@ int ssl3_get_new_session_ticket(SSL *s)\n \t\t}\n \n \tp=d=(unsigned char *)s->init_msg;\n+\n+ if (s->session->session_id_length > 0) {\n+ int i = s->session_ctx->session_cache_mode;\n+ SSL_SESSION *new_sess;\n+ /*\n+ * We reused an existing session, so we need to replace it with a new\n+ * one\n+ */\n+ if (i & SSL_SESS_CACHE_CLIENT) {\n+ /*\n+ * Remove the old session from the cache\n+ */\n+ if (i & SSL_SESS_CACHE_NO_INTERNAL_STORE) {\n+ if (s->session_ctx->remove_session_cb != NULL)\n+ s->session_ctx->remove_session_cb(s->session_ctx,\n+ s->session);\n+ } else {\n+ /* We carry on if this fails */\n+ SSL_CTX_remove_session(s->session_ctx, s->session);\n+ }\n+ }\n+\n+ if ((new_sess = ssl_session_dup(s->session, 0)) == 0) {\n+ al = SSL_AD_INTERNAL_ERROR;\n+ SSLerr(SSL_F_SSL3_GET_NEW_SESSION_TICKET, ERR_R_MALLOC_FAILURE);\n+ goto f_err;\n+ }\n+\n+ SSL_SESSION_free(s->session);\n+ s->session = new_sess;\n+ }\n+\n \tn2l(p, s->session->tlsext_tick_lifetime_hint);\n \tn2s(p, ticklen);\n \t/* ticket_lifetime_hint + ticket_length + ticket */\nIndex: openssl-1.0.1i/ssl/ssl_err.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/ssl_err.c\t2015-06-12 19:15:11.549954732 +0200\n+++ openssl-1.0.1i/ssl/ssl_err.c\t2015-06-12 19:15:13.280975939 +0200\n@@ -245,6 +245,7 @@ static ERR_STRING_DATA SSL_str_functs[]=\n {ERR_FUNC(SSL_F_SSL_READ),\t\"SSL_read\"},\n {ERR_FUNC(SSL_F_SSL_RSA_PRIVATE_DECRYPT),\t\"SSL_RSA_PRIVATE_DECRYPT\"},\n {ERR_FUNC(SSL_F_SSL_RSA_PUBLIC_ENCRYPT),\t\"SSL_RSA_PUBLIC_ENCRYPT\"},\n+{ERR_FUNC(SSL_F_SSL_SESSION_DUP), \"ssl_session_dup\"},\n {ERR_FUNC(SSL_F_SSL_SESSION_NEW),\t\"SSL_SESSION_new\"},\n {ERR_FUNC(SSL_F_SSL_SESSION_PRINT_FP),\t\"SSL_SESSION_print_fp\"},\n {ERR_FUNC(SSL_F_SSL_SESSION_SET1_ID_CONTEXT),\t\"SSL_SESSION_set1_id_context\"},\nIndex: openssl-1.0.1i/ssl/ssl_locl.h\n===================================================================\n--- openssl-1.0.1i.orig/ssl/ssl_locl.h\t2015-06-12 19:15:11.549954732 +0200\n+++ openssl-1.0.1i/ssl/ssl_locl.h\t2015-06-12 19:15:13.280975939 +0200\n@@ -835,6 +835,7 @@ void ssl_sess_cert_free(SESS_CERT *sc);\n int ssl_set_peer_cert_type(SESS_CERT *c, int type);\n int ssl_get_new_session(SSL *s, int session);\n int ssl_get_prev_session(SSL *s, unsigned char *session,int len, const unsigned char *limit);\n+SSL_SESSION *ssl_session_dup(SSL_SESSION *src, int ticket);\n int ssl_cipher_id_cmp(const SSL_CIPHER *a,const SSL_CIPHER *b);\n DECLARE_OBJ_BSEARCH_GLOBAL_CMP_FN(SSL_CIPHER, SSL_CIPHER,\n \t\t\t\t ssl_cipher_id);\nIndex: openssl-1.0.1i/ssl/ssl_sess.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/ssl_sess.c\t2015-06-12 19:15:11.549954732 +0200\n+++ openssl-1.0.1i/ssl/ssl_sess.c\t2015-06-12 19:26:20.502163556 +0200\n@@ -224,6 +224,129 @@ SSL_SESSION *SSL_SESSION_new(void)\n \treturn(ss);\n \t}\n \n+/*\n+ * Create a new SSL_SESSION and duplicate the contents of |src| into it. If\n+ * ticket == 0 then no ticket information is duplicated, otherwise it is.\n+ */\n+SSL_SESSION *ssl_session_dup(SSL_SESSION *src, int ticket)\n+{\n+ SSL_SESSION *dest;\n+\n+ dest = OPENSSL_malloc(sizeof(*src));\n+ if (dest == NULL) {\n+ goto err;\n+ }\n+ memcpy(dest, src, sizeof(*dest));\n+\n+ /* Set the various pointers to NULL so that we can call SSL_SESSION_free in\n+ * the case of an error whilst halfway through constructing dest\n+ */\n+#ifndef OPENSSL_NO_PSK\n+ dest->psk_identity_hint = NULL;\n+ dest->psk_identity = NULL;\n+#endif\n+ dest->ciphers = NULL;\n+#ifndef OPENSSL_NO_TLSEXT\n+ dest->tlsext_hostname = NULL;\n+# ifndef OPENSSL_NO_EC\n+ dest->tlsext_ecpointformatlist = NULL;\n+ dest->tlsext_ellipticcurvelist = NULL;\n+# endif\n+#endif\n+ dest->tlsext_tick = NULL;\n+#ifndef OPENSSL_NO_SRP\n+ dest->srp_username = NULL;\n+#endif\n+ memset(&dest->ex_data, 0, sizeof(dest->ex_data));\n+\n+ /* We deliberately don't copy the prev and next pointers */\n+ dest->prev = NULL;\n+ dest->next = NULL;\n+\n+ dest->references = 1;\n+\n+ if (src->sess_cert != NULL)\n+ CRYPTO_add(&src->sess_cert->references, 1, CRYPTO_LOCK_SSL_SESS_CERT);\n+\n+ if (src->peer != NULL)\n+ CRYPTO_add(&src->peer->references, 1, CRYPTO_LOCK_X509);\n+#ifndef OPENSSL_NO_PSK\n+ if (src->psk_identity_hint) {\n+ dest->psk_identity_hint = BUF_strdup(src->psk_identity_hint);\n+ if (dest->psk_identity_hint == NULL) {\n+ goto err;\n+ }\n+ }\n+ if (src->psk_identity) {\n+ dest->psk_identity = BUF_strdup(src->psk_identity);\n+ if (dest->psk_identity == NULL) {\n+ goto err;\n+ }\n+ }\n+#endif\n+\n+ if(src->ciphers != NULL) {\n+ dest->ciphers = sk_SSL_CIPHER_dup(src->ciphers);\n+ if (dest->ciphers == NULL)\n+ goto err;\n+ }\n+\n+ if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_SSL_SESSION,\n+ &dest->ex_data, &src->ex_data)) {\n+ goto err;\n+ }\n+\n+#ifndef OPENSSL_NO_TLSEXT\n+ if (src->tlsext_hostname) {\n+ dest->tlsext_hostname = BUF_strdup(src->tlsext_hostname);\n+ if (dest->tlsext_hostname == NULL) {\n+ goto err;\n+ }\n+ }\n+# ifndef OPENSSL_NO_EC\n+ if (src->tlsext_ecpointformatlist) {\n+ dest->tlsext_ecpointformatlist =\n+ BUF_memdup(src->tlsext_ecpointformatlist,\n+ src->tlsext_ecpointformatlist_length);\n+ if (dest->tlsext_ecpointformatlist == NULL)\n+ goto err;\n+ }\n+ if (src->tlsext_ellipticcurvelist) {\n+ dest->tlsext_ellipticcurvelist =\n+ BUF_memdup(src->tlsext_ellipticcurvelist,\n+ src->t\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "commit 98ece4eebfb6cd45cc8d550c6ac0022965071afc\nAuthor: Matt Caswell \nDate: Mon May 18 16:27:48 2015 +0100\n\n Fix race condition in NewSessionTicket\n \n If a NewSessionTicket is received by a multi-threaded client when\n attempting to reuse a previous ticket then a race condition can occur\n potentially leading to a double free of the ticket data.\n \n CVE-2015-1791\n \n This also fixes RT#3808 where a session ID is changed for a session already\n in the client session cache. Since the session ID is the key to the cache\n this breaks the cache access.\n \n Parts of this patch were inspired by this Akamai change:\n https://github.com/akamai/openssl/commit/c0bf69a791239ceec64509f9f19fcafb2461b0d3\n \n Reviewed-by: Rich Salz \n\ncommit 907f04a30354615e54beaa2bc0b986083f7793ee\nAuthor: Matt Caswell \nDate: Thu Jun 11 01:30:06 2015 +0100\n\n More ssl_session_dup fixes\n \n Fix error handling in ssl_session_dup, as well as incorrect setting up of\n the session ticket. Follow on from CVE-2015-1791.\n \n Thanks to LibreSSL project for reporting these issues.\n \n Conflicts:\n \tssl/ssl_sess.c\n \n Reviewed-by: Tim Hudson \n\nIndex: openssl-1.0.1i/ssl/ssl.h\n===================================================================\n--- openssl-1.0.1i.orig/ssl/ssl.h\t2015-06-12 19:15:11.549954732 +0200\n+++ openssl-1.0.1i/ssl/ssl.h\t2015-06-12 19:15:13.279975926 +0200\n@@ -2254,6 +2254,7 @@ void ERR_load_SSL_strings(void);\n #define SSL_F_SSL_READ\t\t\t\t\t 223\n #define SSL_F_SSL_RSA_PRIVATE_DECRYPT\t\t\t 187\n #define SSL_F_SSL_RSA_PUBLIC_ENCRYPT\t\t\t 188\n+#define SSL_F_SSL_SESSION_DUP\t\t\t\t 348\n #define SSL_F_SSL_SESSION_NEW\t\t\t\t 189\n #define SSL_F_SSL_SESSION_PRINT_FP\t\t\t 190\n #define SSL_F_SSL_SESSION_SET1_ID_CONTEXT\t\t 312\nIndex: openssl-1.0.1i/ssl/s3_clnt.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s3_clnt.c\t2015-06-12 19:15:11.549954732 +0200\n+++ openssl-1.0.1i/ssl/s3_clnt.c\t2015-06-12 19:15:13.279975926 +0200\n@@ -2105,6 +2105,38 @@ int ssl3_get_new_session_ticket(SSL *s)\n \t\t}\n \n \tp=d=(unsigned char *)s->init_msg;\n+\n+ if (s->session->session_id_length > 0) {\n+ int i = s->session_ctx->session_cache_mode;\n+ SSL_SESSION *new_sess;\n+ /*\n+ * We reused an existing session, so we need to replace it with a new\n+ * one\n+ */\n+ if (i & SSL_SESS_CACHE_CLIENT) {\n+ /*\n+ * Remove the old session from the cache\n+ */\n+ if (i & SSL_SESS_CACHE_NO_INTERNAL_STORE) {\n+ if (s->session_ctx->remove_session_cb != NULL)\n+ s->session_ctx->remove_session_cb(s->session_ctx,\n+ s->session);\n+ } else {\n+ /* We carry on if this fails */\n+ SSL_CTX_remove_session(s->session_ctx, s->session);\n+ }\n+ }\n+\n+ if ((new_sess = ssl_session_dup(s->session, 0)) == 0) {\n+ al = SSL_AD_INTERNAL_ERROR;\n+ SSLerr(SSL_F_SSL3_GET_NEW_SESSION_TICKET, ERR_R_MALLOC_FAILURE);\n+ goto f_err;\n+ }\n+\n+ SSL_SESSION_free(s->session);\n+ s->session = new_sess;\n+ }\n+\n \tn2l(p, s->session->tlsext_tick_lifetime_hint);\n \tn2s(p, ticklen);\n \t/* ticket_lifetime_hint + ticket_length + ticket */\nIndex: openssl-1.0.1i/ssl/ssl_err.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/ssl_err.c\t2015-06-12 19:15:11.549954732 +0200\n+++ openssl-1.0.1i/ssl/ssl_err.c\t2015-06-12 19:15:13.280975939 +0200\n@@ -245,6 +245,7 @@ static ERR_STRING_DATA SSL_str_functs[]=\n {ERR_FUNC(SSL_F_SSL_READ),\t\"SSL_read\"},\n {ERR_FUNC(SSL_F_SSL_RSA_PRIVATE_DECRYPT),\t\"SSL_RSA_PRIVATE_DECRYPT\"},\n {ERR_FUNC(SSL_F_SSL_RSA_PUBLIC_ENCRYPT),\t\"SSL_RSA_PUBLIC_ENCRYPT\"},\n+{ERR_FUNC(SSL_F_SSL_SESSION_DUP), \"ssl_session_dup\"},\n {ERR_FUNC(SSL_F_SSL_SESSION_NEW),\t\"SSL_SESSION_new\"},\n {ERR_FUNC(SSL_F_SSL_SESSION_PRINT_FP),\t\"SSL_SESSION_print_fp\"},\n {ERR_FUNC(SSL_F_SSL_SESSION_SET1_ID_CONTEXT),\t\"SSL_SESSION_set1_id_context\"},\nIndex: openssl-1.0.1i/ssl/ssl_locl.h\n===================================================================\n--- openssl-1.0.1i.orig/ssl/ssl_locl.h\t2015-06-12 19:15:11.549954732 +0200\n+++ openssl-1.0.1i/ssl/ssl_locl.h\t2015-06-12 19:15:13.280975939 +0200\n@@ -835,6 +835,7 @@ void ssl_sess_cert_free(SESS_CERT *sc);\n int ssl_set_peer_cert_type(SESS_CERT *c, int type);\n int ssl_get_new_session(SSL *s, int session);\n int ssl_get_prev_session(SSL *s, unsigned char *session,int len, const unsigned char *limit);\n+SSL_SESSION *ssl_session_dup(SSL_SESSION *src, int ticket);\n int ssl_cipher_id_cmp(const SSL_CIPHER *a,const SSL_CIPHER *b);\n DECLARE_OBJ_BSEARCH_GLOBAL_CMP_FN(SSL_CIPHER, SSL_CIPHER,\n \t\t\t\t ssl_cipher_id);\nIndex: openssl-1.0.1i/ssl/ssl_sess.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/ssl_sess.c\t2015-06-12 19:15:11.549954732 +0200\n+++ openssl-1.0.1i/ssl/ssl_sess.c\t2015-06-12 19:26:20.502163556 +0200\n@@ -224,6 +224,129 @@ SSL_SESSION *SSL_SESSION_new(void)\n \treturn(ss);\n \t}\n \n+/*\n+ * Create a new SSL_SESSION and duplicate the contents of |src| into it. If\n+ * ticket == 0 then no ticket information is duplicated, otherwise it is.\n+ */\n+SSL_SESSION *ssl_session_dup(SSL_SESSION *src, int ticket)\n+{\n+ SSL_SESSION *dest;\n+\n+ dest = OPENSSL_malloc(sizeof(*src));\n+ if (dest == NULL) {\n+ goto err;\n+ }\n+ memcpy(dest, src, sizeof(*dest));\n+\n+ /* Set the various pointers to NULL so that we can call SSL_SESSION_free in\n+ * the case of an error whilst halfway through constructing dest\n+ */\n+#ifndef OPENSSL_NO_PSK\n+ dest->psk_identity_hint = NULL;\n+ dest->psk_identity = NULL;\n+#endif\n+ dest->ciphers = NULL;\n+#ifndef OPENSSL_NO_TLSEXT\n+ dest->tlsext_hostname = NULL;\n+# ifndef OPENSSL_NO_EC\n+ dest->tlsext_ecpointformatlist = NULL;\n+ dest->tlsext_ellipticcurvelist = NULL;\n+# endif\n+#endif\n+ dest->tlsext_tick = NULL;\n+#ifndef OPENSSL_NO_SRP\n+ dest->srp_username = NULL;\n+#endif\n+ memset(&dest->ex_data, 0, sizeof(dest->ex_data));\n+\n+ /* We deliberately don't copy the prev and next pointers */\n+ dest->prev = NULL;\n+ dest->next = NULL;\n+\n+ dest->references = 1;\n+\n+ if (src->sess_cert != NULL)\n+ CRYPTO_add(&src->sess_cert->references, 1, CRYPTO_LOCK_SSL_SESS_CERT);\n+\n+ if (src->peer != NULL)\n+ CRYPTO_add(&src->peer->references, 1, CRYPTO_LOCK_X509);\n+#ifndef OPENSSL_NO_PSK\n+ if (src->psk_identity_hint) {\n+ dest->psk_identity_hint = BUF_strdup(src->psk_identity_hint);\n+ if (dest->psk_identity_hint == NULL) {\n+ goto err;\n+ }\n+ }\n+ if (src->psk_identity) {\n+ dest->psk_identity = BUF_strdup(src->psk_identity);\n+ if (dest->psk_identity == NULL) {\n+ goto err;\n+ }\n+ }\n+#endif\n+\n+ if(src->ciphers != NULL) {\n+ dest->ciphers = sk_SSL_CIPHER_dup(src->ciphers);\n+ if (dest->ciphers == NULL)\n+ goto err;\n+ }\n+\n+ if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_SSL_SESSION,\n+ &dest->ex_data, &src->ex_data)) {\n+ goto err;\n+ }\n+\n+#ifndef OPENSSL_NO_TLSEXT\n+ if (src->tlsext_hostname) {\n+ dest->tlsext_hostname = BUF_strdup(src->tlsext_hostname);\n+ if (dest->tlsext_hostname == NULL) {\n+ goto err;\n+ }\n+ }\n+# ifndef OPENSSL_NO_EC\n+ if (src->tlsext_ecpointformatlist) {\n+ dest->tlsext_ecpointformatlist =\n+ BUF_memdup(src->tlsext_ecpointformatlist,\n+ src->tlsext_ecpointformatlist_length);\n+ if (dest->tlsext_ecpointformatlist == NULL)\n+ goto err;\n+ }\n+ if (src->tlsext_ellipticcurvelist) {\n+ dest->tlsext_ellipticcurvelist =\n+ BUF_memdup(src->tlsext_ellipticcurvelist,\n+ src->tlsext_ellipticcurvelist_length);\n+ if (dest->tlsext_ellipticcurvelist == NULL)\n+ goto err;\n+ }\n+# endif\n+#endif\n+\n+ if (ticket != 0) {\n+ dest->tlsext_tick = BUF_memdup(src->tlsext_tick, src->tlsext_ticklen);\n+ if(dest->tlsext_tick == NULL)\n+ goto err;\n+ } else {\n+ dest->tlsext_tick_lifetime_hint = 0;\n+ dest->tlsext_ticklen = 0;\n+ }\n+\n+#ifndef OPENSSL_NO_SRP\n+ if (src->srp_username) {\n+ dest->srp_username = BUF_strdup(src->srp_username);\n+ if (dest->srp_username == NULL) {\n+ goto err;\n+ }\n+ }\n+#endif\n+\n+ return dest;\n+err:\n+ SSLerr(SSL_F_SSL_SESSION_DUP, ERR_R_MALLOC_FAILURE);\n+ SSL_SESSION_free(dest);\n+ return NULL;\n+}\n+\n+\n const unsigned char *SSL_SESSION_get_id(const SSL_SESSION *s, unsigned int *len)\n \t{\n \tif(len)"}], "metadata": {"id": "openssl-4598-openssl-CVE-2015-1791.patch", "cve_id": "CVE-2015-3197", "package": "openssl", "tier": "adapted", "has_source_context": true, "context_tokens_est": 3732, "context_files": 5, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-6250\n\nInteger overflow in the ISO9660 writer in libarchive before 3.2.1 allows remote attackers to cause a denial of service (application crash) or execute arbitrary code via vectors related to verifying filename lengths when writing an ISO9660 archive, which trigger a buffer overflow.\n\n## Package\nlibarchive\n\n## Files to modify\n- libarchive-3.1.2.orig/libarchive/archive_read.c\n- libarchive/archive_read.c\n- libarchive/test/test_read_too_many_filters.c\n\n## Target Source Code\n\n### Makefile.am\n\n#### region() [lines 400-486]\n```c\n\tlibarchive/test/test_read_format_iso_xorriso.c\t\t\\\n\tlibarchive/test/test_read_format_isojoliet_bz2.c\t\\\n\tlibarchive/test/test_read_format_isojoliet_long.c\t\\\n\tlibarchive/test/test_read_format_isojoliet_rr.c\t\t\\\n\tlibarchive/test/test_read_format_isojoliet_versioned.c\t\\\n\tlibarchive/test/test_read_format_isorr_bz2.c\t\t\\\n\tlibarchive/test/test_read_format_isorr_ce.c\t\t\\\n\tlibarchive/test/test_read_format_isorr_new_bz2.c\t\\\n\tlibarchive/test/test_read_format_isorr_rr_moved.c\t\\\n\tlibarchive/test/test_read_format_isozisofs_bz2.c\t\\\n\tlibarchive/test/test_read_format_lha.c\t\t\t\\\n\tlibarchive/test/test_read_format_lha_filename.c\t\t\\\n\tlibarchive/test/test_read_format_mtree.c\t\t\\\n\tlibarchive/test/test_read_format_pax_bz2.c\t\t\\\n\tlibarchive/test/test_read_format_rar.c\t\t\t\\\n\tlibarchive/test/test_read_format_raw.c\t\t\t\\\n\tlibarchive/test/test_read_format_tar.c\t\t\t\\\n\tlibarchive/test/test_read_format_tar_empty_filename.c\t\\\n\tlibarchive/test/test_read_format_tar_filename.c\t\t\\\n\tlibarchive/test/test_read_format_tbz.c\t\t\t\\\n\tlibarchive/test/test_read_format_tgz.c\t\t\t\\\n\tlibarchive/test/test_read_format_tlz.c\t\t\t\\\n\tlibarchive/test/test_read_format_txz.c\t\t\t\\\n\tlibarchive/test/test_read_format_tz.c\t\t\t\\\n\tlibarchive/test/test_read_format_ustar_filename.c\t\\\n\tlibarchive/test/test_read_format_xar.c\t\t\t\\\n\tlibarchive/test/test_read_format_zip.c\t\t\t\\\n\tlibarchive/test/test_read_format_zip_comment_stored.c\t\\\n\tlibarchive/test/test_read_format_zip_filename.c\t\t\\\n\tlibarchive/test/test_read_format_zip_mac_metadata.c\t\\\n\tlibarchive/test/test_read_format_zip_sfx.c\t\t\\\n\tlibarchive/test/test_read_large.c\t\t\t\\\n\tlibarchive/test/test_read_pax_truncated.c\t\t\\\n\tlibarchive/test/test_read_position.c\t\t\t\\\n\tlibarchive/test/test_read_set_format.c\t\t\t\\\n\tlibarchive/test/test_read_truncated.c\t\t\t\\\n\tlibarchive/test/test_read_truncated_filter.c\t\t\\\n\tlibarchive/test/test_sparse_basic.c\t\t\t\\\n\tlibarchive/test/test_tar_filenames.c\t\t\t\\\n\tlibarchive/test/test_tar_large.c\t\t\t\\\n\tlibarchive/test/test_ustar_filenames.c\t\t\t\\\n\tlibarchive/test/test_ustar_filename_encoding.c\t\t\\\n\tlibarchive/test/test_write_disk.c\t\t\t\\\n\tlibarchive/test/test_write_disk_appledouble.c\t\t\\\n\tlibarchive/test/test_write_disk_failures.c\t\t\\\n\tlibarchive/test/test_write_disk_hardlink.c\t\t\\\n\tlibarchive/test/test_write_disk_hfs_compression.c\t\\\n\tlibarchive/test/test_write_disk_lookup.c\t\t\\\n\tlibarchive/test/test_write_disk_mac_metadata.c\t\t\\\n\tlibarchive/test/test_write_disk_no_hfs_compression.c\t\\\n\tlibarchive/test/test_write_disk_perms.c\t\t\t\\\n\tlibarchive/test/test_write_disk_secure.c\t\t\\\n\tlibarchive/test/test_write_disk_s\n/* ... truncated ... */\n```\n\n### libarchive/archive_read.c\n\n#### archive_read_open1() [lines 450-539]\n```c\n}\n\nint\narchive_read_open1(struct archive *_a)\n{\n\tstruct archive_read *a = (struct archive_read *)_a;\n\tstruct archive_read_filter *filter, *tmp;\n\tint slot, e;\n\tunsigned int i;\n\n\tarchive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW,\n\t \"archive_read_open\");\n\tarchive_clear_error(&a->archive);\n\n\tif (a->client.reader == NULL) {\n\t\tarchive_set_error(&a->archive, EINVAL,\n\t\t \"No reader function provided to archive_read_open\");\n\t\ta->archive.state = ARCHIVE_STATE_FATAL;\n\t\treturn (ARCHIVE_FATAL);\n\t}\n\n\t/* Open data source. */\n\tif (a->client.opener != NULL) {\n\t\te = (a->client.opener)(&a->archive, a->client.dataset[0].data);\n\t\tif (e != 0) {\n\t\t\t/* If the open failed, call the closer to clean up. */\n\t\t\tif (a->client.closer) {\n\t\t\t\tfor (i = 0; i < a->client.nodes; i++)\n\t\t\t\t\t(a->client.closer)(&a->archive,\n\t\t\t\t\t a->client.dataset[i].data);\n\t\t\t}\n\t\t\treturn (e);\n\t\t}\n\t}\n\n\tfilter = calloc(1, sizeof(*filter));\n\tif (filter == NULL)\n\t\treturn (ARCHIVE_FATAL);\n\tfilter->bidder = NULL;\n\tfilter->upstream = NULL;\n\tfilter->archive = a;\n\tfilter->data = a->client.dataset[0].data;\n\tfilter->open = client_open_proxy;\n\tfilter->read = client_read_proxy;\n\tfilter->skip = client_skip_proxy;\n\tfilter->seek = client_seek_proxy;\n\tfilter->close = client_close_proxy;\n\tfilter->sswitch = client_switch_proxy;\n\tfilter->name = \"none\";\n\tfilter->code = ARCHIVE_FILTER_NONE;\n\n\ta->client.dataset[0].begin_position = 0;\n\tif (!a->filter || !a->bypass_filter_bidding)\n\t{\n\t\ta->filter = filter;\n\t\t/* Build out the input pipeline. */\n\t\te = choose_filters(a);\n\t\tif (e < ARCHIVE_WARN) {\n\t\t\ta->archive.state = ARCHIVE_STATE_FATAL;\n\t\t\treturn (ARCHIVE_FATAL);\n\t\t}\n\t}\n\telse\n\t{\n\t\t/* Need to add \"NONE\" type filter at the end of the filter chain */\n\t\ttmp = a->filter;\n\t\twhile (tmp->upstream)\n\t\t\ttmp = tmp->upstream;\n\t\ttmp->upstream = filter;\n\t}\n\n\tif (!a->format)\n\t{\n\t\tslot = choose_format(a);\n\t\tif (slot < 0) {\n\t\t\t__archive_read_close_filters(a);\n\t\t\ta->archive.state = ARCHIVE_STATE_FATAL;\n\t\t\treturn (ARCHIVE_FATAL);\n\t\t}\n\t\ta->format = &(a->formats[slot]);\n\t}\n\n\ta->archive.state = ARCHIVE_STATE_HEADER;\n\n\t/* Ensure libarchive starts from the first node in a multivolume set */\n\tclient_switch_proxy(a->filter, 0);\n\treturn (e);\n}\n\n/*\n```\n\n#### choose_filters() [lines 542-601]\n```c\n * building the pipeline.\n */\nstatic int\nchoose_filters(struct archive_read *a)\n{\n\tint number_bidders, i, bid, best_bid;\n\tstruct archive_read_filter_bidder *bidder, *best_bidder;\n\tstruct archive_read_filter *filter;\n\tssize_t avail;\n\tint r;\n\n\tfor (;;) {\n\t\tn\n/* ... truncated ... */\n```\n\n### libarchive/test/CMakeLists.txt\n\n#### IF() [lines 111-197]\n```c\n test_read_format_gtar_lzma.c\n test_read_format_gtar_sparse.c\n test_read_format_iso_Z.c\n test_read_format_iso_multi_extent.c\n test_read_format_iso_xorriso.c\n test_read_format_isojoliet_bz2.c\n test_read_format_isojoliet_long.c\n test_read_format_isojoliet_rr.c\n test_read_format_isojoliet_versioned.c\n test_read_format_isorr_bz2.c\n test_read_format_isorr_ce.c\n test_read_format_isorr_new_bz2.c\n test_read_format_isorr_rr_moved.c\n test_read_format_isozisofs_bz2.c\n test_read_format_lha.c\n test_read_format_lha_filename.c\n test_read_format_mtree.c\n test_read_format_pax_bz2.c\n test_read_format_rar.c\n test_read_format_raw.c\n test_read_format_tar.c\n test_read_format_tar_empty_filename.c\n test_read_format_tar_filename.c\n test_read_format_tbz.c\n test_read_format_tgz.c\n test_read_format_tlz.c\n test_read_format_txz.c\n test_read_format_tz.c\n test_read_format_ustar_filename.c\n test_read_format_xar.c\n test_read_format_zip.c\n test_read_format_zip_comment_stored.c\n test_read_format_zip_filename.c\n test_read_format_zip_mac_metadata.c\n test_read_format_zip_sfx.c\n test_read_large.c\n test_read_pax_truncated.c\n test_read_position.c\n test_read_set_format.c\n test_read_truncated.c\n test_read_truncated_filter.c\n test_sparse_basic.c\n test_tar_filenames.c\n test_tar_large.c\n test_ustar_filenames.c\n test_ustar_filename_encoding.c\n test_write_disk.c\n test_write_disk_appledouble.c\n test_write_disk_failures.c\n test_write_disk_hardlink.c\n test_write_disk_hfs_compression.c\n test_write_disk_lookup.c\n test_write_disk_mac_metadata.c\n test_write_disk_no_hfs_compression.c\n test_write_disk_perms.c\n test_write_disk_secure.c\n test_write_disk_sparse.c\n test_write_disk_symlink.c\n test_write_disk_times.c\n test_write_filter_b64encode.c\n test_write_filter_bzip2.c\n test_write_filter_compress.c\n test_write_filter_gzip.c\n test_write_filter_gzip_timestamp.c\n test_write_filter_lrzip.c\n test_write_filter_lzip.c\n test_write_filter_lzma.c\n test_write_filter_lzop.c\n test_write_filter_program.c\n test_write_filter_uuencode.c\n test_write_filter_xz.c\n test_write_format_7zip.c\n test_write_format_7zip_empty.c\n test_write_format_7zip_large.c\n test_write_format_ar.c\n test_write_format_cpio.c\n test_write_format_cpio_empty.c\n test_write_format_cpio_newc.c\n test_write_format_cpio_odc.c\n test_write_format_gn\n/* ... truncated ... */\n```\n\n\n### Type definitions\n\n```c\n/* from archive_private.h */\nstruct archive {\n\t/*\n\t * The magic/state values are used to sanity-check the\n\t * client's usage. If an API function is called at a\n\t * ridiculous time, or the client passes us an invalid\n\t * pointer, these values allow me to catch that.\n\t */\n\tunsigned int\tmagic;\n\tunsigned int\tstate;\n\n\t/*\n\t * Some public API functions depend on the \"real\" type of the\n\t * archive object.\n\t */\n\tstruct archive_vtable *vtable;\n\n\tint\t\t archive_format;\n\tconst char\t *archive_format_name;\n\n\tint\t compression_code;\t/* Currently active compression. */\n\tconst char *compression_name;\n\n\t/* Number of file entries processed. */\n\tint\t\t file_count;\n\n\tint\t\t archive_error_number;\n\tconst char\t *error;\n\tstruct archive_string\terror_string;\n\n\tchar *current_code;\n\tunsigned current_codepage; /* Current ACP(ANSI CodePage). */\n\tunsigned current_oemcp; /* Current OEMCP(OEM CodePage). */\n\tstruct archive_string_conv *sconv;\n};\n\n/* from archive_read_private.h */\nstruct archive_read_filter_bidder {\n\t/* Configuration data for the bidder. */\n\tvoid *data;\n\t/* Name of the filter */\n\tconst char *name;\n\t/* Taste the upstream filter to see if we handle this. */\n\tint (*bid)(struct archive_read_filter_bidder *,\n\t struct archive_read_filter *);\n\t/* Initialize a newly-created filter. */\n\tint (*init)(struct archive_read_filter *);\n\t/* Set an option for the filter bidder. */\n\tint (*options)(struct archive_read_filter_bidder *,\n\t const char *key, const char *value);\n\t/* Release the bidder's configuration data. */\n\tint (*free)(struct archive_read_filter_bidder *);\n};\n\n/* from archive_read_private.h */\nstruct archive_read_filter {\n\tint64_t position;\n\t/* Essentially all filters will need these values, so\n\t * just declare them here. */\n\tstruct archive_read_filter_bidder *bidder; /* My bidder. */\n\tstruct archive_read_filter *upstream; /* Who I read from. */\n\tstruct archive_read *archive; /* Associated archive. */\n\t/* Open a block for reading */\n\tint (*open)(struct archive_read_filter *self);\n\t/* Return next block. */\n\tssize_t (*read)(struct archive_read_filter *, const void **);\n\t/* Skip forward this many bytes. */\n\tint64_t (*skip)(struct archive_read_filter *self, int64_t request);\n\t/* Seek to an absolute location. */\n\tint64_t (*seek)(struct archive_read_filter *self, int64_t offset, int whence);\n\t/* Close (just this filter) and free(self). */\n\tint (*close)(struct archive_read_filter *self);\n\t/* Function that handles switching from reading one block to the next/prev */\n\tint (*sswitch)(struct archive_read_filter *self, unsigned int iindex);\n\t/* My private data. */\n\tvoid *data;\n\n\tconst char\t*name;\n\tint\t\t code;\n\n\t/* Used by reblocking logic. */\n\tchar\t\t*buffer;\n\tsize_t\t\t buffer_size;\n\tchar\t\t*next;\t\t/* Current read location. */\n\tsize_t\t\t avail;\t\t/* Bytes in my buffer. */\n\tconst void\t*client_buff;\t/* Client buffer information. */\n\tsize_t\t\t client_total;\n\tconst char\t*client_next;\n\tsize_t\t\t client_avail;\n\tchar\t\t end_of_file;\n\tchar\t\t closed;\n\tchar\t\t fatal;\n};\n```\n\n\n## Upstream Fix\n```diff\ncommit 6e06b1c89dd0d16f74894eac4cfc1327a06ee4a0\nAuthor: Tim Kientzle \nDate: Sat Jan 10 12:24:58 2015 -0800\n\n Fix a potential crash issue discovered by Alexander Cherepanov:\n \n It seems bsdtar automatically handles stacked compression. This is a\n nice feature but it could be problematic when it's completely\n unlimited. Most clearly it's illustrated with quines:\n \n $ curl -sRO http://www.maximumcompression.com/selfgz.gz\n $ (ulimit -v 10000000 && bsdtar -tvf selfgz.gz)\n bsdtar: Error opening archive: Can't allocate data for gzip decompression\n \n Without ulimit, bsdtar will eat all available memory. This could also\n be a problem for other applications using libarchive.\n\nIndex: libarchive-3.1.2/Makefile.am\n===================================================================\n--- libarchive-3.1.2.orig/Makefile.am\n+++ libarchive-3.1.2/Makefile.am\n@@ -439,6 +439,7 @@ libarchive_test_SOURCES=\t\t\t\t\t\\\n \tlibarchive/test/test_read_pax_truncated.c\t\t\\\n \tlibarchive/test/test_read_position.c\t\t\t\\\n \tlibarchive/test/test_read_set_format.c\t\t\t\\\n+\tlibarchive/test/test_read_too_many_filters.c\t\t\\\n \tlibarchive/test/test_read_truncated.c\t\t\t\\\n \tlibarchive/test/test_read_truncated_filter.c\t\t\\\n \tlibarchive/test/test_sparse_basic.c\t\t\t\\\n@@ -703,6 +704,7 @@ libarchive_test_EXTRA_DIST=\\\n \tlibarchive/test/test_read_splitted_rar_ab.uu\t\t\t\\\n \tlibarchive/test/test_read_splitted_rar_ac.uu\t\t\t\\\n \tlibarchive/test/test_read_splitted_rar_ad.uu\t\t\t\\\n+\tlibarchive/test/test_read_too_many_filters.gz.uu \\\n \tlibarchive/test/test_splitted_rar_seek_support_aa.uu\t\t\\\n \tlibarchive/test/test_splitted_rar_seek_support_ab.uu\t\t\\\n \tlibarchive/test/test_splitted_rar_seek_support_ac.uu\t\t\\\nIndex: libarchive-3.1.2/libarchive/archive_read.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_read.c\n+++ libarchive-3.1.2/libarchive/archive_read.c\n@@ -544,13 +544,13 @@ archive_read_open1(struct archive *_a)\n static int\n choose_filters(struct archive_read *a)\n {\n-\tint number_bidders, i, bid, best_bid;\n+\tint number_bidders, i, bid, best_bid, n;\n \tstruct archive_read_filter_bidder *bidder, *best_bidder;\n \tstruct archive_read_filter *filter;\n \tssize_t avail;\n \tint r;\n \n-\tfor (;;) {\n+\tfor (n = 0; n < 25; ++n) {\n \t\tnumber_bidders = sizeof(a->bidders) / sizeof(a->bidders[0]);\n \n \t\tbest_bid = 0;\n@@ -596,6 +596,9 @@ choose_filters(struct archive_read *a)\n \t\t\treturn (ARCHIVE_FATAL);\n \t\t}\n \t}\n+\tarchive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,\n+\t \"Input requires too many filters for decoding\");\n+\treturn (ARCHIVE_FATAL);\n }\n \n /*\nIndex: libarchive-3.1.2/libarchive/test/CMakeLists.txt\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/test/CMakeLists.txt\n+++ libarchive-3.1.2/libarchive/test/CMakeLists.txt\n@@ -150,6 +150,7 @@ IF(ENABLE_TEST)\n test_read_pax_truncated.c\n test_read_position.c\n test_read_set_format.c\n+ test_read_too_many_filters.c\n test_read_truncated.c\n test_read_truncated_filter.c\n test_sparse_basic.c\nIndex: libarchive-3.1.2/libarchive/test/test_read_too_many_filters.c\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_too_many_filters.c\n@@ -0,0 +1,45 @@\n+/*-\n+ * Copyright (c) 2003-2008,2015 Tim Kientzle\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ * 1. Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in the\n+ * documentation and/or other materials provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR\n+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,\n+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+#include \"test.h\"\n+\n+DEFINE_TEST(test_read_too_many_filters)\n+{\n+\tconst char *name = \"test_read_too_many_filters.gz\";\n+\tstruct archive *a;\n+\tint r;\n+\n+\tassert((a = archive_read_new()) != NULL);\n+\tr = archive_read_support_filter_gzip(a);\n+\tif (r == ARCHIVE_WARN) {\n+\t\tskipping(\"gzip reading not fully supported on this platform\");\n+\t}\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));\n+\textract_reference_file(name);\n+\tassertEqualIntA(a, ARCHIVE_FATAL,\n+\t archive_read_open_filename(a, name, 200));\n+\n+\tassertEqualInt(ARCHIVE_OK, archive_read_close(a));\n+\tassertEqualInt(ARCHIVE_OK, archive_read_free(a));\n+}\nIndex: libarchive-3.1.2/libarchive/test/test_read_too_many_filters.gz.uu\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_too_many_filters.gz.uu\n@@ -0,0 +1,15 @@\n+This is a valid gzip file that decompresses to itself, from\n+ http://www.maximumcompression.com/selfgz.gz\n+\n+This is used in test_read_too_many_filters to try to\n+crash libarchive by forcing it to spawn an unending\n+list of gunzip filters.\n+\n+begin 644 test_read_too_many_filters.gz\n+M'XL(\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "commit 6e06b1c89dd0d16f74894eac4cfc1327a06ee4a0\nAuthor: Tim Kientzle \nDate: Sat Jan 10 12:24:58 2015 -0800\n\n Fix a potential crash issue discovered by Alexander Cherepanov:\n \n It seems bsdtar automatically handles stacked compression. This is a\n nice feature but it could be problematic when it's completely\n unlimited. Most clearly it's illustrated with quines:\n \n $ curl -sRO http://www.maximumcompression.com/selfgz.gz\n $ (ulimit -v 10000000 && bsdtar -tvf selfgz.gz)\n bsdtar: Error opening archive: Can't allocate data for gzip decompression\n \n Without ulimit, bsdtar will eat all available memory. This could also\n be a problem for other applications using libarchive.\n\nIndex: libarchive-3.1.2/Makefile.am\n===================================================================\n--- libarchive-3.1.2.orig/Makefile.am\n+++ libarchive-3.1.2/Makefile.am\n@@ -439,6 +439,7 @@ libarchive_test_SOURCES=\t\t\t\t\t\\\n \tlibarchive/test/test_read_pax_truncated.c\t\t\\\n \tlibarchive/test/test_read_position.c\t\t\t\\\n \tlibarchive/test/test_read_set_format.c\t\t\t\\\n+\tlibarchive/test/test_read_too_many_filters.c\t\t\\\n \tlibarchive/test/test_read_truncated.c\t\t\t\\\n \tlibarchive/test/test_read_truncated_filter.c\t\t\\\n \tlibarchive/test/test_sparse_basic.c\t\t\t\\\n@@ -703,6 +704,7 @@ libarchive_test_EXTRA_DIST=\\\n \tlibarchive/test/test_read_splitted_rar_ab.uu\t\t\t\\\n \tlibarchive/test/test_read_splitted_rar_ac.uu\t\t\t\\\n \tlibarchive/test/test_read_splitted_rar_ad.uu\t\t\t\\\n+\tlibarchive/test/test_read_too_many_filters.gz.uu \\\n \tlibarchive/test/test_splitted_rar_seek_support_aa.uu\t\t\\\n \tlibarchive/test/test_splitted_rar_seek_support_ab.uu\t\t\\\n \tlibarchive/test/test_splitted_rar_seek_support_ac.uu\t\t\\\nIndex: libarchive-3.1.2/libarchive/archive_read.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_read.c\n+++ libarchive-3.1.2/libarchive/archive_read.c\n@@ -544,13 +544,13 @@ archive_read_open1(struct archive *_a)\n static int\n choose_filters(struct archive_read *a)\n {\n-\tint number_bidders, i, bid, best_bid;\n+\tint number_bidders, i, bid, best_bid, n;\n \tstruct archive_read_filter_bidder *bidder, *best_bidder;\n \tstruct archive_read_filter *filter;\n \tssize_t avail;\n \tint r;\n \n-\tfor (;;) {\n+\tfor (n = 0; n < 25; ++n) {\n \t\tnumber_bidders = sizeof(a->bidders) / sizeof(a->bidders[0]);\n \n \t\tbest_bid = 0;\n@@ -596,6 +596,9 @@ choose_filters(struct archive_read *a)\n \t\t\treturn (ARCHIVE_FATAL);\n \t\t}\n \t}\n+\tarchive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,\n+\t \"Input requires too many filters for decoding\");\n+\treturn (ARCHIVE_FATAL);\n }\n \n /*\nIndex: libarchive-3.1.2/libarchive/test/CMakeLists.txt\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/test/CMakeLists.txt\n+++ libarchive-3.1.2/libarchive/test/CMakeLists.txt\n@@ -150,6 +150,7 @@ IF(ENABLE_TEST)\n test_read_pax_truncated.c\n test_read_position.c\n test_read_set_format.c\n+ test_read_too_many_filters.c\n test_read_truncated.c\n test_read_truncated_filter.c\n test_sparse_basic.c\nIndex: libarchive-3.1.2/libarchive/test/test_read_too_many_filters.c\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_too_many_filters.c\n@@ -0,0 +1,45 @@\n+/*-\n+ * Copyright (c) 2003-2008,2015 Tim Kientzle\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ * 1. Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in the\n+ * documentation and/or other materials provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR\n+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,\n+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+#include \"test.h\"\n+\n+DEFINE_TEST(test_read_too_many_filters)\n+{\n+\tconst char *name = \"test_read_too_many_filters.gz\";\n+\tstruct archive *a;\n+\tint r;\n+\n+\tassert((a = archive_read_new()) != NULL);\n+\tr = archive_read_support_filter_gzip(a);\n+\tif (r == ARCHIVE_WARN) {\n+\t\tskipping(\"gzip reading not fully supported on this platform\");\n+\t}\n+\tassertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));\n+\textract_reference_file(name);\n+\tassertEqualIntA(a, ARCHIVE_FATAL,\n+\t archive_read_open_filename(a, name, 200));\n+\n+\tassertEqualInt(ARCHIVE_OK, archive_read_close(a));\n+\tassertEqualInt(ARCHIVE_OK, archive_read_free(a));\n+}\nIndex: libarchive-3.1.2/libarchive/test/test_read_too_many_filters.gz.uu\n===================================================================\n--- /dev/null\n+++ libarchive-3.1.2/libarchive/test/test_read_too_many_filters.gz.uu\n@@ -0,0 +1,15 @@\n+This is a valid gzip file that decompresses to itself, from\n+ http://www.maximumcompression.com/selfgz.gz\n+\n+This is used in test_read_too_many_filters to try to\n+crash libarchive by forcing it to spawn an unending\n+list of gunzip filters.\n+\n+begin 644 test_read_too_many_filters.gz\n+M'XL(`````````P`/`/#_'XL(`````````P`/`/#_````__\\```#__X)QH5P`\n+M`!X`X?\\```#__P```/__@G&A7```'@#A_P```/__````__\\```#__P```/__\n+M````__\\```#__\\(FAF`!`!0`Z_\\```#__P```/__PB:&8`$`%`#K_\\(FAF`!\n+M`!0`Z_^9(#6-B\"@Q,C,T`K/`+```%`#K_P*SP\"P``!0`Z_]\"B\"'$`````/__\n+>`P!#2DTAT@```$*((<0`````__\\#`$-*32'2````\n+`\n+end"}], "metadata": {"id": "libarchive-5940-CVE-2016-7166.patch", "cve_id": "CVE-2016-6250", "package": "libarchive", "tier": "adapted", "has_source_context": true, "context_tokens_est": 2705, "context_files": 3, "license": "BSD-2-Clause"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2013-4560\n\nUse-after-free vulnerability in lighttpd before 1.4.33 allows remote attackers to cause a denial of service (segmentation fault and crash) via unspecified vectors that trigger FAMMonitorDirectory failures.\n\n## Package\nlighttpd\n\n## Files to modify\n- src/server.c\n- lighttpd-1.4.31.orig/src/base.h\n- src/network.c\n- lighttpd-1.4.31.orig/src/network.c\n- src/base.h\n\n## Target Source Code\n\n### src/base.h\n\n#### region() [lines 280-367]\n```c\n\tunsigned short ssl_honor_cipher_order; /* determine SSL cipher in server-preferred order, not client-order */\n\tunsigned short ssl_use_sslv2;\n\tunsigned short ssl_use_sslv3;\n\tunsigned short ssl_verifyclient;\n\tunsigned short ssl_verifyclient_enforce;\n\tunsigned short ssl_verifyclient_depth;\n\tbuffer *ssl_verifyclient_username;\n\tunsigned short ssl_verifyclient_export_cert;\n\tunsigned short ssl_disable_client_renegotiation;\n\n\tunsigned short use_ipv6, set_v6only; /* set_v6only is only a temporary option */\n\tunsigned short defer_accept;\n\tunsigned short is_ssl;\n\tunsigned short allow_http11;\n\tunsigned short etag_use_inode;\n\tunsigned short etag_use_mtime;\n\tunsigned short etag_use_size;\n\tunsigned short force_lowercase_filenames; /* if the FS is case-insensitive, force all files to lower-case */\n\tunsigned int max_request_size;\n\n\tunsigned short kbytes_per_second; /* connection kb/s limit */\n\n\t/* configside */\n\tunsigned short global_kbytes_per_second; /* */\n\n\toff_t global_bytes_per_second_cnt;\n\t/* server-wide traffic-shaper\n\t *\n\t * each context has the counter which is inited once\n\t * a second by the global_kbytes_per_second config-var\n\t *\n\t * as soon as global_kbytes_per_second gets below 0\n\t * the connected conns are \"offline\" a little bit\n\t *\n\t * the problem:\n\t * we somehow have to loose our \"we are writable\" signal\n\t * on the way.\n\t *\n\t */\n\toff_t *global_bytes_per_second_cnt_ptr; /* */\n\n#ifdef USE_OPENSSL\n\tSSL_CTX *ssl_ctx;\n#endif\n} specific_config;\n\n/* the order of the items should be the same as they are processed\n * read before write as we use this later */\ntypedef enum {\n\tCON_STATE_CONNECT,\n\tCON_STATE_REQUEST_START,\n\tCON_STATE_READ,\n\tCON_STATE_REQUEST_END,\n\tCON_STATE_READ_POST,\n\tCON_STATE_HANDLE_REQUEST,\n\tCON_STATE_RESPONSE_START,\n\tCON_STATE_WRITE,\n\tCON_STATE_RESPONSE_END,\n\tCON_STATE_ERROR,\n\tCON_STATE_CLOSE\n} connection_state_t;\n\ntypedef enum { COND_RESULT_UNSET, COND_RESULT_FALSE, COND_RESULT_TRUE } cond_result_t;\ntypedef struct {\n\tcond_result_t result;\n\tint patterncount;\n\tint matches[3 * 10];\n\tbuffer *comp_value; /* just a pointer */\n\t\n\tcomp_key_t comp_type;\n} cond_cache_t;\n\ntypedef struct {\n\tconnection_state_t state;\n\n\t/* timestamps */\n\ttime_t read_idle_ts;\n\ttime_t close_timeout_ts;\n\ttime_t write_request_ts;\n\n\ttime_t connection_start;\n\ttime_t request_start;\n\n\tstruct timeval start_tv;\n\n\tsize_t request_count; /* number of requests handled in this connection */\n\tsize_t loops_per_request; /* to catch endless loops in a single request\n\t\t\t\t *\n```\n\n### src/configfile.c\n\n#### region() [lines 298-362]\n```c\n\n\n#define PATCH(x) con->conf.x = s->x\nint config_setup_connection(server *srv, connection *con) {\n\tspecific_config *s = srv->config_storage[0];\n\n\tPATCH(allow_http11);\n\tPATCH(mimetypes);\n\tPATCH(document_root);\n\tPATCH(max_keep_alive_requests);\n\tPATCH(max_keep_alive_idle);\n\tPATCH(max_read_idle);\n\tPATCH(max_write_idle);\n\tPATCH(use_xattr);\n\tPATCH(error_handler);\n\tPATCH(errorfile_prefix);\n#ifdef HAVE_LSTAT\n\tPATCH(follow_symlink);\n#endif\n\tPATCH(server_tag);\n\tPATCH(kbytes_per_second);\n\tPATCH(global_kbytes_per_second);\n\tPATCH(global_bytes_per_second_cnt);\n\n\tcon->conf.global_bytes_per_second_cnt_ptr = &s->global_bytes_per_second_cnt;\n\tbuffer_copy_string_buffer(con->server_name, s->server_name);\n\n\tPATCH(log_request_header);\n\tPATCH(log_response_header);\n\tPATCH(log_request_handling);\n\tPATCH(log_condition_handling);\n\tPATCH(log_file_not_found);\n\tPATCH(log_ssl_noise);\n\tPATCH(log_timeouts);\n\n\tPATCH(range_requests);\n\tPATCH(force_lowercase_filenames);\n\tPATCH(is_ssl);\n\n\tPATCH(ssl_pemfile);\n#ifdef USE_OPENSSL\n\tPATCH(ssl_ctx);\n#endif\n\tPATCH(ssl_ca_file);\n\tPATCH(ssl_cipher_list);\n\tPATCH(ssl_dh_file);\n\tPATCH(ssl_ec_curve);\n\tPATCH(ssl_honor_cipher_order);\n\tPATCH(ssl_use_sslv2);\n\tPATCH(ssl_use_sslv3);\n\tPATCH(etag_use_inode);\n\tPATCH(etag_use_mtime);\n\tPATCH(etag_use_size);\n\n\tPATCH(ssl_verifyclient);\n\tPATCH(ssl_verifyclient_enforce);\n\tPATCH(ssl_verifyclient_depth);\n\tPATCH(ssl_verifyclient_username);\n\tPATCH(ssl_verifyclient_export_cert);\n\tPATCH(ssl_disable_client_renegotiation);\n\n\treturn 0;\n}\n\nint config_patch_connection(server *srv, connection *con, comp_key_t comp) {\n```\n\n#### region() [lines 376-472]\n```c\n\t\tfor (j = 0; j < dc->value->used; j++) {\n\t\t\tdata_unset *du = dc->value->data[j];\n\n\t\t\tif (buffer_is_equal_string(du->key, CONST_STR_LEN(\"server.document-root\"))) {\n\t\t\t\tPATCH(document_root);\n\t\t\t} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(\"server.range-requests\"))) {\n\t\t\t\tPATCH(range_requests);\n\t\t\t} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(\"server.error-handler-404\"))) {\n\t\t\t\tPATCH(error_handler);\n\t\t\t} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(\"server.errorfile-prefix\"))) {\n\t\t\t\tPATCH(errorfile_prefix);\n\t\t\t} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(\"mimetype.assign\"))) {\n\t\t\t\tPATCH(mimetypes);\n\t\t\t} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(\"server.max-keep-alive-requests\"))) {\n\t\t\t\tPATCH(max_keep_alive_requests);\n\t\t\t} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(\"server.max-keep-alive-idle\"))) {\n\t\t\t\tPATCH(max_keep_alive_idle);\n\t\t\t} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(\"server.max-write-idle\"))) {\n\t\t\t\tPATCH(max_write_idle);\n\t\t\t} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(\"server.max-read-idle\"))) {\n\t\t\t\tPATCH(max_read_idle);\n\t\t\t} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(\"mimetype.use-xattr\"))) {\n\t\t\t\tPATCH(use_xattr);\n\t\t\t} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(\"etag.use-inode\"))) {\n\t\t\t\tPATCH(etag_use_inode);\n\t\t\t} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(\"etag.use-mtime\"))) {\n\t\t\t\tPATCH(etag_use_mtime);\n\t\t\t} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(\"etag.use-size\"))) {\n\t\t\t\tPATCH(etag_use_size);\n\t\t\t} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(\"ssl.pemfile\"))) {\n\t\t\t\tPATCH(ssl_pemfile);\n#ifdef USE_OPENSSL\n\t\t\t\tPATCH(ssl_ctx);\n#endif\n\t\t\t} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(\"ssl.ca-file\"))) {\n\t\t\t\tPATCH(ssl_ca_file);\n\t\t\t} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(\"ssl.honor-cipher-order\"))) {\n\t\t\t\tPATCH(ssl_honor_cipher_order);\n\t\t\t} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(\"ssl.use-sslv2\"))) {\n\t\t\t\tPATCH(ssl_use_sslv2);\n\t\t\t} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(\"ssl.use-sslv3\"))) {\n\t\t\t\tPATCH(ssl_use_sslv3);\n\t\t\t} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(\"ssl.cipher-list\"))) {\n\t\t\t\tPATCH(ssl_cipher_list);\n\t\t\t} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(\"ssl.engine\"\n/* ... truncated ... */\n```\n\n### src/network.c\n\n#### region() [lines 84-132]\n```c\n}\n\n#if defined USE_OPENSSL && ! defined OPENSSL_NO_TLSEXT\nstatic int network_ssl_servername_callback(SSL *ssl, int *al, server *srv) {\n\tconst char *servername;\n\tconnection *con = (connection *) SSL_get_app_data(ssl);\n\tUNUSED(al);\n\n\tbuffer_copy_string(con->uri.scheme, \"https\");\n\n\tif (NULL == (servername = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name))) {\n#if 0\n\t\t/* this \"error\" just means the client didn't support it */\n\t\tlog_error_write(srv, __FILE__, __LINE__, \"ss\", \"SSL:\",\n\t\t\t\t\"failed to get TLS server name\");\n#endif\n\t\treturn SSL_TLSEXT_ERR_NOACK;\n\t}\n\tbuffer_copy_string(con->tlsext_server_name, servername);\n\tbuffer_to_lower(con->tlsext_server_name);\n\n\t/* Sometimes this is still set, confusing COMP_HTTP_HOST */\n\tbuffer_reset(con->uri.authority);\n\n\tconfig_cond_cache_reset(srv, con);\n\tconfig_setup_connection(srv, con);\n\n\tconfig_patch_connection(srv, con, COMP_SERVER_SOCKET);\n\tconfig_patch_connection(srv, con, COMP_HTTP_SCHEME);\n\tconfig_patch_connection(srv, con, COMP_HTTP_HOST);\n\n\tif (NULL == con->conf.ssl_ctx) {\n\t\t/* ssl_ctx <=> pemfile was set <=> ssl_ctx got patched: so this should never happen */\n\t\tlog_error_write(srv, __FILE__, __LINE__, \"ssb\", \"SSL:\",\n\t\t\t\"null SSL_CTX for TLS server name\", con->tlsext_server_name);\n\t\treturn SSL_TLSEXT_ERR_ALERT_FATAL;\n\t}\n\n\t/* switch to new SSL_CTX in reaction to a client's server_name extension */\n\tif (con->conf.ssl_ctx != SSL_set_SSL_CTX(ssl, con->conf.ssl_ctx)) {\n\t\tlog_error_write(srv, __FILE__, __LINE__, \"ssb\", \"SSL:\",\n\t\t\t\"failed to set SSL_CTX for TLS server name\", con->tlsext_server_name);\n\t\treturn SSL_TLSEXT_ERR_ALERT_FATAL;\n\t}\n\n\treturn SSL_TLSEXT_ERR_OK;\n}\n#endif\n\n```\n\n#### region() [lines 456-545]\n```c\n\t\tclose(srv_socket->fd);\n\t}\n\tbuffer_free(srv_socket->srv_token);\n\tfree(srv_socket);\n\n\treturn -1;\n}\n\nint network_close(server *srv) {\n\tsize_t i;\n\tfor (i = 0; i < srv->srv_sockets.used; i++) {\n\t\tserver_socket *srv_socket = srv->srv_sockets.ptr[i];\n\n\t\tif (srv_socket->fd != -1) {\n\t\t\t/* check if server fd are already registered */\n\t\t\tif (srv_socket->fde_ndx != -1) {\n\t\t\t\tfdevent_event_del(srv->ev, &(srv_socket->fde_ndx), srv_socket->fd);\n\t\t\t\tfdevent_unregister(srv->ev, srv_socket->fd);\n\t\t\t}\n\n\t\t\tclose(srv_socket->fd);\n\t\t}\n\n\t\tbuffer_free(srv_socket->srv_token);\n\n\t\tfree(srv_socket);\n\t}\n\n\tfree(srv->srv_sockets.ptr);\n\n\treturn 0;\n}\n\ntypedef enum {\n\tNETWORK_BACKEND_UNSET,\n\tNETWORK_BACKEND_WRITE,\n\tNETWORK_BACKEND_WRITEV,\n\tNETWORK_BACKEND_LINUX_SENDFILE,\n\tNETWORK_BACKEND_FREEBSD_SENDFILE,\n\tNETWORK_BACKEND_SOLARIS_SENDFILEV\n} network_backend_t;\n\nint network_init(server *srv) {\n\tbuffer *b;\n\tsize_t i;\n\tnetwork_backend_t backend;\n\n#if OPENSSL_VERSION_NUMBER >= 0x0090800fL\n#ifndef OPENSSL_NO_ECDH\n\tEC_KEY *ecdh;\n\tint nid;\n#endif\n#endif\n\n#ifdef USE_OPENSSL\n\tDH *dh;\n\tBIO *bio;\n\n /* 1024-bit MODP Group with 160-bit prime order subgroup (RFC5114)\n\t* -----BEGIN DH PARAMETERS-----\n\t* MIIBDAKBgQCxC4+WoIDgHd6S3l6uXVTsUsmfvPsGo8aaap3KUtI7YWBz4oZ1oj0Y\n\t* mDjvHi7mUsAT7LSuqQYRIySXXDzUm4O/rMvdfZDEvXCYSI6cIZpzck7/1vrlZEc4\n\t* +qMaT/VbzMChUa9fDci0vUW/N982XBpl5oz9p21NpwjfH7K8LkpDcQKBgQCk0cvV\n\t* w/00EmdlpELvuZkF+BBN0lisUH/WQGz/FCZtMSZv6h5cQVZLd35pD1UE8hMWAhe0\n\t* sBuIal6RVH+eJ0n01/vX07mpLuGQnQ0iY/gKdqaiTAh6CR9THb8KAWm2oorWYqTR\n\t* jnOvoy13nVkY0IvIhY9Nzvl8KiSFXm7rIrOy5QICAKA=\n\t* -----END DH PARAMETERS-----\n\t*/\n\n\tstatic const unsigned char dh1024_p[]={\n\t\t0xB1,0x0B,0x8F,0x96,0xA0,0x80,0xE0,0x1D,0xDE,0x92,0xDE,0x5E,\n\t\t0xAE,0x5D,0x54,0xEC,0x52,0xC9,0x9F,0xBC,0xFB,0x06,0xA3,0xC6,\n\t\t0x9A,0x6A,0x9D,0xCA,0x52,0xD2,0x3B,0x61,0x60,0x73,0xE2,0x86,\n\t\t0x75,0xA2,0x3D,0x18,0x98,0x38,0xEF,0x1E,0x2E,0xE6,0x52,0xC0,\n\t\t0x13,0xEC,0xB4,0xAE,0xA9,0x06,0x11,0x23,0x24,0x97,0x5C,0x3C,\n\t\t0xD4,0x9B,0x83,0xBF,0xAC,0xCB,0xDD,0x7D,0x90,0xC4,0xBD,0x70,\n\t\t0x98,0x48,0x8E,0x9C,0x21,0x9A,0x73,0x72,0x4E,0xFF,0xD6,0xFA,\n\t\t0xE5,0x64,0x47,0x38,0xFA,0xA3,0x1A,0x4F,0xF5,0x5B,0xCC,0xC0,\n\t\t0xA1,0x51,0xAF,0x5F,0x0D,0xC8,0xB4,0xBD,0x45,0xBF,0x37,0xDF,\n\t\t0x36,0x5C,0x1A,0x65,0xE6,0x8C,0xFD,0xA7,0x6D,0x4D,0xA7,0x0\n/* ... truncated ... */\n```\n\n### src/server.c\n\n#### region() [lines 253-355]\n```c\n\treturn srv;\n}\n\nstatic void server_free(server *srv) {\n\tsize_t i;\n\n\tfor (i = 0; i < FILE_CACHE_MAX; i++) {\n\t\tbuffer_free(srv->mtime_cache[i].str);\n\t}\n\n#define CLEAN(x) \\\n\tbuffer_free(srv->x);\n\n\tCLEAN(response_header);\n\tCLEAN(parse_full_path);\n\tCLEAN(ts_debug_str);\n\tCLEAN(ts_date_str);\n\tCLEAN(errorlog_buf);\n\tCLEAN(response_range);\n\tCLEAN(tmp_buf);\n\tCLEAN(empty_string);\n\tCLEAN(cond_check_buf);\n\n\tCLEAN(srvconf.errorlog_file);\n\tCLEAN(srvconf.breakagelog_file);\n\tCLEAN(srvconf.groupname);\n\tCLEAN(srvconf.username);\n\tCLEAN(srvconf.changeroot);\n\tCLEAN(srvconf.bindhost);\n\tCLEAN(srvconf.event_handler);\n\tCLEAN(srvconf.pid_file);\n\tCLEAN(srvconf.modules_dir);\n\tCLEAN(srvconf.network_backend);\n\n\tCLEAN(tmp_chunk_len);\n#undef CLEAN\n\n#if 0\n\tfdevent_unregister(srv->ev, srv->fd);\n#endif\n\tfdevent_free(srv->ev);\n\n\tfree(srv->conns);\n\n\tif (srv->config_storage) {\n\t\tfor (i = 0; i < srv->config_context->used; i++) {\n\t\t\tspecific_config *s = srv->config_storage[i];\n\n\t\t\tif (!s) continue;\n\n\t\t\tbuffer_free(s->document_root);\n\t\t\tbuffer_free(s->server_name);\n\t\t\tbuffer_free(s->server_tag);\n\t\t\tbuffer_free(s->ssl_pemfile);\n\t\t\tbuffer_free(s->ssl_ca_file);\n\t\t\tbuffer_free(s->ssl_cipher_list);\n\t\t\tbuffer_free(s->ssl_dh_file);\n\t\t\tbuffer_free(s->ssl_ec_curve);\n\t\t\tbuffer_free(s->error_handler);\n\t\t\tbuffer_free(s->errorfile_prefix);\n\t\t\tarray_free(s->mimetypes);\n\t\t\tbuffer_free(s->ssl_verifyclient_username);\n#ifdef USE_OPENSSL\n\t\t\tSSL_CTX_free(s->ssl_ctx);\n#endif\n\t\t\tfree(s);\n\t\t}\n\t\tfree(srv->config_storage);\n\t\tsrv->config_storage = NULL;\n\t}\n\n#define CLEAN(x) \\\n\tarray_free(srv->x);\n\n\tCLEAN(config_context);\n\tCLEAN(config_touched);\n\tCLEAN(status);\n\tCLEAN(srvconf.upload_tempdirs);\n#undef CLEAN\n\n\tjoblist_free(srv, srv->joblist);\n\tfdwaitqueue_free(srv, srv->fdwaitqueue);\n\n\tif (srv->stat_cache) {\n\t\tstat_cache_free(srv->stat_cache);\n\t}\n\n\tarray_free(srv->srvconf.modules);\n\tarray_free(srv->split_vals);\n\n#ifdef USE_OPENSSL\n\tif (srv->ssl_is_init) {\n\t\tCRYPTO_cleanup_all_ex_data();\n\t\tERR_free_strings();\n\t\tERR_remove_state(0);\n\t\tEVP_cleanup();\n\t}\n#endif\n\n\tfree(srv);\n}\n\nstatic void show_version (void) {\n```\n\n\n## Upstream Fix\n```diff\norigin: http://download.lighttpd.net/lighttpd/security/lighttpd_sa_2013_01.txt\ncommit 1af871fcef97574c71870309d572d6b1026ee605\nAuthor: Stefan Bühler \nDate: Tue Nov 5 15:29:07 2013 +0000\n\n [ssl] fix SNI handling; only use key+cert+verify-client from SNI specific config (fixes #2525, CVE-2013-4508)\n \n pull all ssl.ca-file values into all SSL_CTXs, but use only the local\n ssl.ca-file for verify-client; correct SNI name is no requirement,\n so enforcing verification for a subset of SNI names doesn't actually\n protect those.\n \n From: Stefan Bühler \n \n git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2913 152afb58-edef-0310-8abb-c4023f1b3aa9\n\nIndex: lighttpd-1.4.31/src/base.h\n===================================================================\n--- lighttpd-1.4.31.orig/src/base.h\t2011-11-30 19:43:35.000000000 +0000\n+++ lighttpd-1.4.31/src/base.h\t2013-11-13 02:43:16.910532167 +0000\n@@ -319,7 +319,11 @@\n \toff_t *global_bytes_per_second_cnt_ptr; /* */\n \n #ifdef USE_OPENSSL\n-\tSSL_CTX *ssl_ctx;\n+\tSSL_CTX *ssl_ctx; /* not patched */\n+\t/* SNI per host: with COMP_SERVER_SOCKET, COMP_HTTP_SCHEME, COMP_HTTP_HOST */\n+\tEVP_PKEY *ssl_pemfile_pkey;\n+\tX509 *ssl_pemfile_x509;\n+\tSTACK_OF(X509_NAME) *ssl_ca_file_cert_names;\n #endif\n } specific_config;\n \nIndex: lighttpd-1.4.31/src/configfile.c\n===================================================================\n--- lighttpd-1.4.31.orig/src/configfile.c\t2011-12-06 20:01:49.000000000 +0000\n+++ lighttpd-1.4.31/src/configfile.c\t2013-11-13 02:43:16.910532167 +0000\n@@ -336,9 +336,13 @@\n \n \tPATCH(ssl_pemfile);\n #ifdef USE_OPENSSL\n-\tPATCH(ssl_ctx);\n+\tPATCH(ssl_pemfile_x509);\n+\tPATCH(ssl_pemfile_pkey);\n #endif\n \tPATCH(ssl_ca_file);\n+#ifdef USE_OPENSSL\n+\tPATCH(ssl_ca_file_cert_names);\n+#endif\n \tPATCH(ssl_cipher_list);\n \tPATCH(ssl_dh_file);\n \tPATCH(ssl_ec_curve);\n@@ -405,10 +409,14 @@\n \t\t\t} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(\"ssl.pemfile\"))) {\n \t\t\t\tPATCH(ssl_pemfile);\n #ifdef USE_OPENSSL\n-\t\t\t\tPATCH(ssl_ctx);\n+\t\t\t\tPATCH(ssl_pemfile_x509);\n+\t\t\t\tPATCH(ssl_pemfile_pkey);\n #endif\n \t\t\t} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(\"ssl.ca-file\"))) {\n \t\t\t\tPATCH(ssl_ca_file);\n+#ifdef USE_OPENSSL\n+\t\t\t\tPATCH(ssl_ca_file_cert_names);\n+#endif\n \t\t\t} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(\"ssl.honor-cipher-order\"))) {\n \t\t\t\tPATCH(ssl_honor_cipher_order);\n \t\t\t} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(\"ssl.use-sslv2\"))) {\nIndex: lighttpd-1.4.31/src/network.c\n===================================================================\n--- lighttpd-1.4.31.orig/src/network.c\t2011-12-27 13:45:02.000000000 +0000\n+++ lighttpd-1.4.31/src/network.c\t2013-11-13 02:43:16.910532167 +0000\n@@ -112,20 +112,46 @@\n \tconfig_patch_connection(srv, con, COMP_HTTP_SCHEME);\n \tconfig_patch_connection(srv, con, COMP_HTTP_HOST);\n \n-\tif (NULL == con->conf.ssl_ctx) {\n-\t\t/* ssl_ctx <=> pemfile was set <=> ssl_ctx got patched: so this should never happen */\n+\tif (NULL == con->conf.ssl_pemfile_x509 || NULL == con->conf.ssl_pemfile_pkey) {\n+\t\t/* x509/pkey available <=> pemfile was set <=> pemfile got patched: so this should never happen, unless you nest $SERVER[\"socket\"] */\n \t\tlog_error_write(srv, __FILE__, __LINE__, \"ssb\", \"SSL:\",\n-\t\t\t\"null SSL_CTX for TLS server name\", con->tlsext_server_name);\n+\t\t\t\"no certificate/private key for TLS server name\", con->tlsext_server_name);\n \t\treturn SSL_TLSEXT_ERR_ALERT_FATAL;\n \t}\n \n-\t/* switch to new SSL_CTX in reaction to a client's server_name extension */\n-\tif (con->conf.ssl_ctx != SSL_set_SSL_CTX(ssl, con->conf.ssl_ctx)) {\n-\t\tlog_error_write(srv, __FILE__, __LINE__, \"ssb\", \"SSL:\",\n-\t\t\t\"failed to set SSL_CTX for TLS server name\", con->tlsext_server_name);\n+\t/* first set certificate! setting private key checks whether certificate matches it */\n+\tif (!SSL_use_certificate(ssl, con->conf.ssl_pemfile_x509)) {\n+\t\tlog_error_write(srv, __FILE__, __LINE__, \"ssb:s\", \"SSL:\",\n+\t\t\t\"failed to set certificate for TLS server name\", con->tlsext_server_name,\n+\t\t\tERR_error_string(ERR_get_error(), NULL));\n+\t\treturn SSL_TLSEXT_ERR_ALERT_FATAL;\n+\t}\n+\n+\tif (!SSL_use_PrivateKey(ssl, con->conf.ssl_pemfile_pkey)) {\n+\t\tlog_error_write(srv, __FILE__, __LINE__, \"ssb:s\", \"SSL:\",\n+\t\t\t\"failed to set private key for TLS server name\", con->tlsext_server_name,\n+\t\t\tERR_error_string(ERR_get_error(), NULL));\n \t\treturn SSL_TLSEXT_ERR_ALERT_FATAL;\n \t}\n \n+\tif (con->conf.ssl_verifyclient) {\n+\t\tif (NULL == con->conf.ssl_ca_file_cert_names) {\n+\t\t\tlog_error_write(srv, __FILE__, __LINE__, \"ssb:s\", \"SSL:\",\n+\t\t\t\t\"can't verify client without ssl.ca-file for TLS server name\", con->tlsext_server_name,\n+\t\t\t\tERR_error_string(ERR_get_error(), NULL));\n+\t\t\treturn SSL_TLSEXT_ERR_ALERT_FATAL;\n+\t\t}\n+\n+\t\tSSL_set_client_CA_list(ssl, SSL_dup_CA_list(con->conf.ssl_ca_file_cert_names));\n+\t\t/* forcing verification here is really not that useful - a client could just connect without SNI */\n+\t\tSSL_set_verify(\n+\t\t\tssl,\n+\t\t\tSSL_VERIFY_PEER | (con->conf.ssl_verifyclient_enforce ? SSL_VERIFY_FAIL_IF_NO_PEER_CERT : 0),\n+\t\t\tNULL\n+\t\t);\n+\t\tSSL_set_verify_depth(ssl, con->conf.ssl_verifyclient_depth);\n+\t}\n+\n \treturn SSL_TLSEXT_ERR_OK;\n }\n #endif\n@@ -495,9 +521,100 @@\n \tNETWORK_BACKEND_SOLARIS_SENDFILEV\n } network_backend_t;\n \n+#ifdef USE_OPENSSL\n+static X509* x509_load_pem_file(server *srv, const char *file) {\n+\tBIO *in;\n+\tX509 *x = NULL;\n+\n+\tin = BIO_new(BIO_s_file());\n+\tif (NULL == in) {\n+\t\tlog_error_write(srv, __FILE__, __LINE__, \"S\", \"SSL: BIO_new(BIO_s_file()) failed\");\n+\t\tgoto error;\n+\t}\n+\n+\tif (BIO_read_filename(in,file) <= 0) {\n+\t\tlog_error_write(srv, __FILE__, __LINE__, \"SSS\", \"SSL: BIO_read_filename('\", file,\"') failed\");\n+\t\tgoto error;\n+\t}\n+\tx = PEM_read_bio_X509(in, NULL, NULL, NULL);\n+\n+\tif (NULL == x) {\n+\t\tlog_error_write(srv, __FILE__, __LINE__, \"SSS\", \"SSL: couldn't read X509 certificate from '\", file,\"'\");\n+\t\tgoto error;\n+\t}\n+\n+\tBIO_free(in);\n+\treturn x;\n+\n+error:\n+\tif (NULL != x) X509_free(x);\n+\tif (NULL != in) BIO_free(in);\n+\treturn NULL;\n+}\n+\n+static EVP_PKEY* evp_pkey_load_pem_file(server *srv, const char *file) {\n+\tBIO *in;\n+\tEVP_PKEY *x = NULL;\n+\n+\tin=BIO_new(BIO_s_file());\n+\tif (NULL == in) {\n+\t\tlog_error_write(srv, __FILE__, __LINE__, \"s\", \"SSL: BIO_new(BIO_s_file()) failed\");\n+\t\tgoto error;\n+\t}\n+\n+\tif (BIO_read_filename(in,file) <= 0) {\n+\t\tlog_error_write(srv, __FILE__, __LINE__, \"SSS\", \"SSL: BIO_read_filename('\", file,\"') failed\");\n+\t\tgoto error;\n+\t}\n+\tx = PEM_read_bio_PrivateKey(in, NULL, NULL, NULL);\n+\n+\tif (NULL == x) {\n+\t\tlog_error_write(srv, __FILE__, __LINE__, \"SSS\", \"SSL: couldn't read private key from '\", file,\"'\");\n+\t\tgoto error;\n+\t}\n+\n+\tBIO_free(in);\n+\treturn x;\n+\n+error:\n+\tif (NULL != x) EVP_PKEY_free(x);\n+\tif (NULL != in) BIO_free(in);\n+\treturn NULL;\n+}\n+\n+static int network_openssl_load_pemfile(server *srv, size_t ndx) {\n+\tspecific_config *s = srv->config_storage[ndx];\n+\n+#ifdef OPENSSL_NO_TLSEXT\n+\t{\n+\t\tdata_config *dc = (data_config *)srv->config_context->data[i];\n+\t\tif ((ndx > 0 && (COMP_SERVER_SOCKET != dc->comp || dc->cond != CONFIG_COND_EQ))\n+\t\t\t|| !s->is_ssl) {\n+\t\t\tlog_error_write(srv, __FILE__, __LINE__, \"ss\", \"SSL:\",\n+\t\t\t\t\t\"ssl.pemfile only works in SSL socket binding context as openssl version does not support TLS extensions\");\n+\t\t\treturn -1;\n+\t\t}\n+\t}\n+#endif\n+\n+\tif (NULL == (s->ssl_pemfile_x509 = x509_load_pem_file(srv, s->ssl_pemfile->ptr))) return -1;\n+\tif (NULL == (s->ssl_pemfile_pkey = evp_pkey_load_pem_file(srv, s->ssl_pemfile->ptr))) return -1;\n+\n+\tif (!X509_check_private_key(s->ssl_pemfile_x509, s->ssl_pemfile_pkey)) {\n+\t\tlog_error_write(srv, __FILE__, __LINE__, \"sssb\", \"SSL:\",\n+\t\t\t\t\"Private key does not match the certificate public key, reason:\",\n+\t\t\t\tERR_error_string(ERR_get_error(), NULL),\n+\t\t\t\ts->ssl_pemfile);\n+\t\treturn -1;\n+\t}\n+\n+\treturn 0;\n+}\n+#endif\n+\n int network_init(server *srv) {\n \tbuffer *b;\n-\tsize_t i;\n+\tsize_t i, j;\n \tnetwork_backend_t backend;\n \n #if OPENSSL_VERSION_NUMBER >= 0x0090800fL\n@@ -582,18 +699,7 @@\n \t\tlo\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "origin: http://download.lighttpd.net/lighttpd/security/lighttpd_sa_2013_01.txt\ncommit 1af871fcef97574c71870309d572d6b1026ee605\nAuthor: Stefan Bühler \nDate: Tue Nov 5 15:29:07 2013 +0000\n\n [ssl] fix SNI handling; only use key+cert+verify-client from SNI specific config (fixes #2525, CVE-2013-4508)\n \n pull all ssl.ca-file values into all SSL_CTXs, but use only the local\n ssl.ca-file for verify-client; correct SNI name is no requirement,\n so enforcing verification for a subset of SNI names doesn't actually\n protect those.\n \n From: Stefan Bühler \n \n git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2913 152afb58-edef-0310-8abb-c4023f1b3aa9\n\nIndex: lighttpd-1.4.31/src/base.h\n===================================================================\n--- lighttpd-1.4.31.orig/src/base.h\t2011-11-30 19:43:35.000000000 +0000\n+++ lighttpd-1.4.31/src/base.h\t2013-11-13 02:43:16.910532167 +0000\n@@ -319,7 +319,11 @@\n \toff_t *global_bytes_per_second_cnt_ptr; /* */\n \n #ifdef USE_OPENSSL\n-\tSSL_CTX *ssl_ctx;\n+\tSSL_CTX *ssl_ctx; /* not patched */\n+\t/* SNI per host: with COMP_SERVER_SOCKET, COMP_HTTP_SCHEME, COMP_HTTP_HOST */\n+\tEVP_PKEY *ssl_pemfile_pkey;\n+\tX509 *ssl_pemfile_x509;\n+\tSTACK_OF(X509_NAME) *ssl_ca_file_cert_names;\n #endif\n } specific_config;\n \nIndex: lighttpd-1.4.31/src/configfile.c\n===================================================================\n--- lighttpd-1.4.31.orig/src/configfile.c\t2011-12-06 20:01:49.000000000 +0000\n+++ lighttpd-1.4.31/src/configfile.c\t2013-11-13 02:43:16.910532167 +0000\n@@ -336,9 +336,13 @@\n \n \tPATCH(ssl_pemfile);\n #ifdef USE_OPENSSL\n-\tPATCH(ssl_ctx);\n+\tPATCH(ssl_pemfile_x509);\n+\tPATCH(ssl_pemfile_pkey);\n #endif\n \tPATCH(ssl_ca_file);\n+#ifdef USE_OPENSSL\n+\tPATCH(ssl_ca_file_cert_names);\n+#endif\n \tPATCH(ssl_cipher_list);\n \tPATCH(ssl_dh_file);\n \tPATCH(ssl_ec_curve);\n@@ -405,10 +409,14 @@\n \t\t\t} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(\"ssl.pemfile\"))) {\n \t\t\t\tPATCH(ssl_pemfile);\n #ifdef USE_OPENSSL\n-\t\t\t\tPATCH(ssl_ctx);\n+\t\t\t\tPATCH(ssl_pemfile_x509);\n+\t\t\t\tPATCH(ssl_pemfile_pkey);\n #endif\n \t\t\t} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(\"ssl.ca-file\"))) {\n \t\t\t\tPATCH(ssl_ca_file);\n+#ifdef USE_OPENSSL\n+\t\t\t\tPATCH(ssl_ca_file_cert_names);\n+#endif\n \t\t\t} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(\"ssl.honor-cipher-order\"))) {\n \t\t\t\tPATCH(ssl_honor_cipher_order);\n \t\t\t} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(\"ssl.use-sslv2\"))) {\nIndex: lighttpd-1.4.31/src/network.c\n===================================================================\n--- lighttpd-1.4.31.orig/src/network.c\t2011-12-27 13:45:02.000000000 +0000\n+++ lighttpd-1.4.31/src/network.c\t2013-11-13 02:43:16.910532167 +0000\n@@ -112,20 +112,46 @@\n \tconfig_patch_connection(srv, con, COMP_HTTP_SCHEME);\n \tconfig_patch_connection(srv, con, COMP_HTTP_HOST);\n \n-\tif (NULL == con->conf.ssl_ctx) {\n-\t\t/* ssl_ctx <=> pemfile was set <=> ssl_ctx got patched: so this should never happen */\n+\tif (NULL == con->conf.ssl_pemfile_x509 || NULL == con->conf.ssl_pemfile_pkey) {\n+\t\t/* x509/pkey available <=> pemfile was set <=> pemfile got patched: so this should never happen, unless you nest $SERVER[\"socket\"] */\n \t\tlog_error_write(srv, __FILE__, __LINE__, \"ssb\", \"SSL:\",\n-\t\t\t\"null SSL_CTX for TLS server name\", con->tlsext_server_name);\n+\t\t\t\"no certificate/private key for TLS server name\", con->tlsext_server_name);\n \t\treturn SSL_TLSEXT_ERR_ALERT_FATAL;\n \t}\n \n-\t/* switch to new SSL_CTX in reaction to a client's server_name extension */\n-\tif (con->conf.ssl_ctx != SSL_set_SSL_CTX(ssl, con->conf.ssl_ctx)) {\n-\t\tlog_error_write(srv, __FILE__, __LINE__, \"ssb\", \"SSL:\",\n-\t\t\t\"failed to set SSL_CTX for TLS server name\", con->tlsext_server_name);\n+\t/* first set certificate! setting private key checks whether certificate matches it */\n+\tif (!SSL_use_certificate(ssl, con->conf.ssl_pemfile_x509)) {\n+\t\tlog_error_write(srv, __FILE__, __LINE__, \"ssb:s\", \"SSL:\",\n+\t\t\t\"failed to set certificate for TLS server name\", con->tlsext_server_name,\n+\t\t\tERR_error_string(ERR_get_error(), NULL));\n+\t\treturn SSL_TLSEXT_ERR_ALERT_FATAL;\n+\t}\n+\n+\tif (!SSL_use_PrivateKey(ssl, con->conf.ssl_pemfile_pkey)) {\n+\t\tlog_error_write(srv, __FILE__, __LINE__, \"ssb:s\", \"SSL:\",\n+\t\t\t\"failed to set private key for TLS server name\", con->tlsext_server_name,\n+\t\t\tERR_error_string(ERR_get_error(), NULL));\n \t\treturn SSL_TLSEXT_ERR_ALERT_FATAL;\n \t}\n \n+\tif (con->conf.ssl_verifyclient) {\n+\t\tif (NULL == con->conf.ssl_ca_file_cert_names) {\n+\t\t\tlog_error_write(srv, __FILE__, __LINE__, \"ssb:s\", \"SSL:\",\n+\t\t\t\t\"can't verify client without ssl.ca-file for TLS server name\", con->tlsext_server_name,\n+\t\t\t\tERR_error_string(ERR_get_error(), NULL));\n+\t\t\treturn SSL_TLSEXT_ERR_ALERT_FATAL;\n+\t\t}\n+\n+\t\tSSL_set_client_CA_list(ssl, SSL_dup_CA_list(con->conf.ssl_ca_file_cert_names));\n+\t\t/* forcing verification here is really not that useful - a client could just connect without SNI */\n+\t\tSSL_set_verify(\n+\t\t\tssl,\n+\t\t\tSSL_VERIFY_PEER | (con->conf.ssl_verifyclient_enforce ? SSL_VERIFY_FAIL_IF_NO_PEER_CERT : 0),\n+\t\t\tNULL\n+\t\t);\n+\t\tSSL_set_verify_depth(ssl, con->conf.ssl_verifyclient_depth);\n+\t}\n+\n \treturn SSL_TLSEXT_ERR_OK;\n }\n #endif\n@@ -495,9 +521,100 @@\n \tNETWORK_BACKEND_SOLARIS_SENDFILEV\n } network_backend_t;\n \n+#ifdef USE_OPENSSL\n+static X509* x509_load_pem_file(server *srv, const char *file) {\n+\tBIO *in;\n+\tX509 *x = NULL;\n+\n+\tin = BIO_new(BIO_s_file());\n+\tif (NULL == in) {\n+\t\tlog_error_write(srv, __FILE__, __LINE__, \"S\", \"SSL: BIO_new(BIO_s_file()) failed\");\n+\t\tgoto error;\n+\t}\n+\n+\tif (BIO_read_filename(in,file) <= 0) {\n+\t\tlog_error_write(srv, __FILE__, __LINE__, \"SSS\", \"SSL: BIO_read_filename('\", file,\"') failed\");\n+\t\tgoto error;\n+\t}\n+\tx = PEM_read_bio_X509(in, NULL, NULL, NULL);\n+\n+\tif (NULL == x) {\n+\t\tlog_error_write(srv, __FILE__, __LINE__, \"SSS\", \"SSL: couldn't read X509 certificate from '\", file,\"'\");\n+\t\tgoto error;\n+\t}\n+\n+\tBIO_free(in);\n+\treturn x;\n+\n+error:\n+\tif (NULL != x) X509_free(x);\n+\tif (NULL != in) BIO_free(in);\n+\treturn NULL;\n+}\n+\n+static EVP_PKEY* evp_pkey_load_pem_file(server *srv, const char *file) {\n+\tBIO *in;\n+\tEVP_PKEY *x = NULL;\n+\n+\tin=BIO_new(BIO_s_file());\n+\tif (NULL == in) {\n+\t\tlog_error_write(srv, __FILE__, __LINE__, \"s\", \"SSL: BIO_new(BIO_s_file()) failed\");\n+\t\tgoto error;\n+\t}\n+\n+\tif (BIO_read_filename(in,file) <= 0) {\n+\t\tlog_error_write(srv, __FILE__, __LINE__, \"SSS\", \"SSL: BIO_read_filename('\", file,\"') failed\");\n+\t\tgoto error;\n+\t}\n+\tx = PEM_read_bio_PrivateKey(in, NULL, NULL, NULL);\n+\n+\tif (NULL == x) {\n+\t\tlog_error_write(srv, __FILE__, __LINE__, \"SSS\", \"SSL: couldn't read private key from '\", file,\"'\");\n+\t\tgoto error;\n+\t}\n+\n+\tBIO_free(in);\n+\treturn x;\n+\n+error:\n+\tif (NULL != x) EVP_PKEY_free(x);\n+\tif (NULL != in) BIO_free(in);\n+\treturn NULL;\n+}\n+\n+static int network_openssl_load_pemfile(server *srv, size_t ndx) {\n+\tspecific_config *s = srv->config_storage[ndx];\n+\n+#ifdef OPENSSL_NO_TLSEXT\n+\t{\n+\t\tdata_config *dc = (data_config *)srv->config_context->data[i];\n+\t\tif ((ndx > 0 && (COMP_SERVER_SOCKET != dc->comp || dc->cond != CONFIG_COND_EQ))\n+\t\t\t|| !s->is_ssl) {\n+\t\t\tlog_error_write(srv, __FILE__, __LINE__, \"ss\", \"SSL:\",\n+\t\t\t\t\t\"ssl.pemfile only works in SSL socket binding context as openssl version does not support TLS extensions\");\n+\t\t\treturn -1;\n+\t\t}\n+\t}\n+#endif\n+\n+\tif (NULL == (s->ssl_pemfile_x509 = x509_load_pem_file(srv, s->ssl_pemfile->ptr))) return -1;\n+\tif (NULL == (s->ssl_pemfile_pkey = evp_pkey_load_pem_file(srv, s->ssl_pemfile->ptr))) return -1;\n+\n+\tif (!X509_check_private_key(s->ssl_pemfile_x509, s->ssl_pemfile_pkey)) {\n+\t\tlog_error_write(srv, __FILE__, __LINE__, \"sssb\", \"SSL:\",\n+\t\t\t\t\"Private key does not match the certificate public key, reason:\",\n+\t\t\t\tERR_error_string(ERR_get_error(), NULL),\n+\t\t\t\ts->ssl_pemfile);\n+\t\treturn -1;\n+\t}\n+\n+\treturn 0;\n+}\n+#endif\n+\n int network_init(server *srv) {\n \tbuffer *b;\n-\tsize_t i;\n+\tsize_t i, j;\n \tnetwork_backend_t backend;\n \n #if OPENSSL_VERSION_NUMBER >= 0x0090800fL\n@@ -582,18 +699,7 @@\n \t\tlong ssloptions =\n \t\t\tSSL_OP_ALL | SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION | SSL_OP_NO_COMPRESSION;\n \n-\t\tif (buffer_is_empty(s->ssl_pemfile)) continue;\n-\n-#ifdef OPENSSL_NO_TLSEXT\n-\t\t{\n-\t\t\tdata_config *dc = (data_config *)srv->config_context->data[i];\n-\t\t\tif (COMP_HTTP_HOST == dc->comp) {\n-\t\t\t log_error_write(srv, __FILE__, __LINE__, \"ss\", \"SSL:\",\n-\t\t\t\t\t \"can't use ssl.pemfile with $HTTP[\\\"host\\\"], openssl version does not support TLS extensions\");\n-\t\t\t return -1;\n-\t\t\t}\n-\t\t}\n-#endif\n+\t\tif (buffer_is_empty(s->ssl_pemfile) && buffer_is_empty(s->ssl_ca_file)) continue;\n \n \t\tif (srv->ssl_is_init == 0) {\n \t\t\tSSL_load_error_strings();\n@@ -608,6 +714,29 @@\n \t\t\t}\n \t\t}\n \n+\t\tif (!buffer_is_empty(s->ssl_pemfile)) {\n+#ifdef OPENSSL_NO_TLSEXT\n+\t\t\tdata_config *dc = (data_config *)srv->config_context->data[i];\n+\t\t\tif (COMP_HTTP_HOST == dc->comp) {\n+\t\t\t\tlog_error_write(srv, __FILE__, __LINE__, \"ss\", \"SSL:\",\n+\t\t\t\t\t\t\"can't use ssl.pemfile with $HTTP[\\\"host\\\"], openssl version does not support TLS extensions\");\n+\t\t\t\treturn -1;\n+\t\t\t}\n+#endif\n+\t\t\tif (network_openssl_load_pemfile(srv, i)) return -1;\n+\t\t}\n+\n+\n+\t\tif (!buffer_is_empty(s->ssl_ca_file)) {\n+\t\t\ts->ssl_ca_file_cert_names = SSL_load_client_CA_file(s->ssl_ca_file->ptr);\n+\t\t\tif (NULL == s->ssl_ca_file_cert_names) {\n+\t\t\t\tlog_error_write(srv, __FILE__, __LINE__, \"ssb\", \"SSL:\",\n+\t\t\t\t\t\tERR_error_string(ERR_get_error(), NULL), s->ssl_ca_file);\n+\t\t\t}\n+\t\t}\n+\n+\t\tif (buffer_is_empty(s->ssl_pemfile) || !s->is_ssl) continue;\n+\n \t\tif (NULL == (s->ssl_ctx = SSL_CTX_new(SSLv23_server_method()))) {\n \t\t\tlog_error_write(srv, __FILE__, __LINE__, \"ss\", \"SSL:\",\n \t\t\t\t\tERR_error_string(ERR_get_error(), NULL));\n@@ -707,45 +836,42 @@\n #endif\n #endif\n \n-\t\tif (!buffer_is_empty(s->ssl_ca_file)) {\n-\t\t\tif (1 != SSL_CTX_load_verify_locations(s->ssl_ctx, s->ssl_ca_file->ptr, NULL)) {\n-\t\t\t\tlog_error_write(srv, __FILE__, __LINE__, \"ssb\", \"SSL:\",\n-\t\t\t\t\t\tERR_error_string(ERR_get_error(), NULL), s->ssl_ca_file);\n-\t\t\t\treturn -1;\n-\t\t\t}\n-\t\t\tif (s->ssl_verifyclient) {\n-\t\t\t\tSTACK_OF(X509_NAME) *certs = SSL_load_client_CA_file(s->ssl_ca_file->ptr);\n-\t\t\t\tif (!certs) {\n+\t\t/* load all ssl.ca-files specified in the config into each SSL_CTX to be prepared for SNI */\n+\t\tfor (j = 0; j < srv->config_context->used; j++) {\n+\t\t\tspecific_config *s1 = srv->config_storage[j];\n+\n+\t\t\tif (!buffer_is_empty(s1->ssl_ca_file)) {\n+\t\t\t\tif (1 != SSL_CTX_load_verify_locations(s->ssl_ctx, s1->ssl_ca_file->ptr, NULL)) {\n \t\t\t\t\tlog_error_write(srv, __FILE__, __LINE__, \"ssb\", \"SSL:\",\n-\t\t\t\t\t\t\tERR_error_string(ERR_get_error(), NULL), s->ssl_ca_file);\n-\t\t\t\t}\n-\t\t\t\tif (SSL_CTX_set_session_id_context(s->ssl_ctx, (void*) &srv, sizeof(srv)) != 1) {\n-\t\t\t\t\tlog_error_write(srv, __FILE__, __LINE__, \"ss\", \"SSL:\",\n-\t\t\t\t\t\tERR_error_string(ERR_get_error(), NULL));\n+\t\t\t\t\t\t\tERR_error_string(ERR_get_error(), NULL), s1->ssl_ca_file);\n \t\t\t\t\treturn -1;\n \t\t\t\t}\n-\t\t\t\tSSL_CTX_set_client_CA_list(s->ssl_ctx, certs);\n-\t\t\t\tSSL_CTX_set_verify(\n-\t\t\t\t\ts->ssl_ctx,\n-\t\t\t\t\tSSL_VERIFY_PEER | (s->ssl_verifyclient_enforce ? SSL_VERIFY_FAIL_IF_NO_PEER_CERT : 0),\n-\t\t\t\t\tNULL\n+\t\t\t}\n+\t\t}\n+\n+\t\tif (s->ssl_verifyclient) {\n+\t\t\tif (NULL == s->ssl_ca_file_cert_names) {\n+\t\t\t\tlog_error_write(srv, __FILE__, __LINE__, \"s\",\n+\t\t\t\t\t\"SSL: You specified ssl.verifyclient.activate but no ca_file\"\n \t\t\t\t);\n-\t\t\t\tSSL_CTX_set_verify_depth(s->ssl_ctx, s->ssl_verifyclient_depth);\n+\t\t\t\treturn -1;\n \t\t\t}\n-\t\t} else if (s->ssl_verifyclient) {\n-\t\t\tlog_error_write(\n-\t\t\t\tsrv, __FILE__, __LINE__, \"s\",\n-\t\t\t\t\"SSL: You specified ssl.verifyclient.activate but no ca_file\"\n+\t\t\tSSL_CTX_set_client_CA_list(s->ssl_ctx, SSL_dup_CA_list(s->ssl_ca_file_cert_names));\n+\t\t\tSSL_CTX_set_verify(\n+\t\t\t\ts->ssl_ctx,\n+\t\t\t\tSSL_VERIFY_PEER | (s->ssl_verifyclient_enforce ? SSL_VERIFY_FAIL_IF_NO_PEER_CERT : 0),\n+\t\t\t\tNULL\n \t\t\t);\n+\t\t\tSSL_CTX_set_verify_depth(s->ssl_ctx, s->ssl_verifyclient_depth);\n \t\t}\n \n-\t\tif (SSL_CTX_use_certificate_file(s->ssl_ctx, s->ssl_pemfile->ptr, SSL_FILETYPE_PEM) < 0) {\n+\t\tif (SSL_CTX_use_certificate(s->ssl_ctx, s->ssl_pemfile_x509) < 0) {\n \t\t\tlog_error_write(srv, __FILE__, __LINE__, \"ssb\", \"SSL:\",\n \t\t\t\t\tERR_error_string(ERR_get_error(), NULL), s->ssl_pemfile);\n \t\t\treturn -1;\n \t\t}\n \n-\t\tif (SSL_CTX_use_PrivateKey_file (s->ssl_ctx, s->ssl_pemfile->ptr, SSL_FILETYPE_PEM) < 0) {\n+\t\tif (SSL_CTX_use_PrivateKey(s->ssl_ctx, s->ssl_pemfile_pkey) < 0) {\n \t\t\tlog_error_write(srv, __FILE__, __LINE__, \"ssb\", \"SSL:\",\n \t\t\t\t\tERR_error_string(ERR_get_error(), NULL), s->ssl_pemfile);\n \t\t\treturn -1;\n@@ -842,7 +968,6 @@\n \tfor (i = 1; i < srv->config_context->used; i++) {\n \t\tdata_config *dc = (data_config *)srv->config_context->data[i];\n \t\tspecific_config *s = srv->config_storage[i];\n-\t\tsize_t j;\n \n \t\t/* not our stage */\n \t\tif (COMP_SERVER_SOCKET != dc->comp) continue;\nIndex: lighttpd-1.4.31/src/server.c\n===================================================================\n--- lighttpd-1.4.31.orig/src/server.c\t2012-04-28 15:39:38.000000000 +0000\n+++ lighttpd-1.4.31/src/server.c\t2013-11-13 02:43:16.910532167 +0000\n@@ -314,6 +314,9 @@\n \t\t\tbuffer_free(s->ssl_verifyclient_username);\n #ifdef USE_OPENSSL\n \t\t\tSSL_CTX_free(s->ssl_ctx);\n+\t\t\tEVP_PKEY_free(s->ssl_pemfile_pkey);\n+\t\t\tX509_free(s->ssl_pemfile_x509);\n+\t\t\tif (NULL != s->ssl_ca_file_cert_names) sk_X509_NAME_pop_free(s->ssl_ca_file_cert_names, X509_NAME_free);\n #endif\n \t\t\tfree(s);\n \t\t}"}], "metadata": {"id": "lighttpd-2374-cve-2013-4508.patch", "cve_id": "CVE-2013-4560", "package": "lighttpd", "tier": "adapted", "has_source_context": true, "context_tokens_est": 3188, "context_files": 4, "license": "BSD-3-Clause"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2012-0113\n\nUnspecified vulnerability in the MySQL Server component in Oracle MySQL 5.1.x and 5.5.x allows remote authenticated users to affect confidentiality and availability via unknown vectors, a different vulnerability than CVE-2012-0118.\n\n## Package\nmariadb\n\n## Upstream Fix\n```diff\nPATCH-P0-FIX-SUSE: Tweak default configuration\n\nThis patch adds log file locations and socket location as they should be in\nSuSE to the default configuration files.\n\nMaintainer: Michal Hrusecky \n\nIndex: support-files/my-huge.cnf.sh\n===================================================================\n--- support-files/my-huge.cnf.sh.orig\n+++ support-files/my-huge.cnf.sh\n@@ -132,7 +132,15 @@ o#innodb_log_group_home_dir = @localstat\n #innodb_flush_log_at_trx_commit = 1\n #innodb_lock_wait_timeout = 50\n \n+# The safe_mysqld script\n+[safe_mysqld]\n+log-error=/var/log/mysql/mysqld.log\n+socket\t\t= @MYSQL_UNIX_ADDR@\n+\n+# !includedir /etc/mysql\n+\n [mysqldump]\n+socket\t\t= @MYSQL_UNIX_ADDR@\n quick\n max_allowed_packet = 16M\n \nIndex: support-files/my-large.cnf.sh\n===================================================================\n--- support-files/my-large.cnf.sh.orig\n+++ support-files/my-large.cnf.sh\n@@ -132,7 +132,15 @@ server-id\t= 1\n #innodb_flush_log_at_trx_commit = 1\n #innodb_lock_wait_timeout = 50\n \n+# The safe_mysqld script\n+[safe_mysqld]\n+log-error=/var/log/mysql/mysqld.log\n+socket\t\t= @MYSQL_UNIX_ADDR@\n+\n+# !includedir /etc/mysql\n+\n [mysqldump]\n+socket\t\t= @MYSQL_UNIX_ADDR@\n quick\n max_allowed_packet = 16M\n \nIndex: support-files/my-medium.cnf.sh\n===================================================================\n--- support-files/my-medium.cnf.sh.orig\n+++ support-files/my-medium.cnf.sh\n@@ -28,6 +28,8 @@ socket\t\t= @MYSQL_UNIX_ADDR@\n [mysqld]\n port\t\t= @MYSQL_TCP_PORT@\n socket\t\t= @MYSQL_UNIX_ADDR@\n+# Change following line if you want to store your database elsewhere\n+datadir\t= /var/lib/mysql\n skip-external-locking\n key_buffer_size = 16M\n max_allowed_packet = 1M\n@@ -130,7 +132,15 @@ server-id\t= 1\n #innodb_flush_log_at_trx_commit = 1\n #innodb_lock_wait_timeout = 50\n \n+# The safe_mysqld script\n+[safe_mysqld]\n+log-error\t= /var/log/mysql/mysqld.log\n+socket\t\t= @MYSQL_UNIX_ADDR@\n+\n+# !includedir /etc/mysql\n+\n [mysqldump]\n+socket\t\t= @MYSQL_UNIX_ADDR@\n quick\n max_allowed_packet = 16M\n \nIndex: support-files/my-small.cnf.sh\n===================================================================\n--- support-files/my-small.cnf.sh.orig\n+++ support-files/my-small.cnf.sh\n@@ -65,7 +65,15 @@ server-id\t= 1\n #innodb_flush_log_at_trx_commit = 1\n #innodb_lock_wait_timeout = 50\n \n+# The safe_mysqld script\n+[safe_mysqld]\n+log-error\t= /var/log/mysql/mysqld.log\n+socket\t\t= @MYSQL_UNIX_ADDR@\n+\n+# !includedir /etc/mysql\n+\n [mysqldump]\n+socket\t\t= @MYSQL_UNIX_ADDR@\n quick\n max_allowed_packet = 16M\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "PATCH-P0-FIX-SUSE: Tweak default configuration\n\nThis patch adds log file locations and socket location as they should be in\nSuSE to the default configuration files.\n\nMaintainer: Michal Hrusecky \n\nIndex: support-files/my-huge.cnf.sh\n===================================================================\n--- support-files/my-huge.cnf.sh.orig\n+++ support-files/my-huge.cnf.sh\n@@ -132,7 +132,15 @@ o#innodb_log_group_home_dir = @localstat\n #innodb_flush_log_at_trx_commit = 1\n #innodb_lock_wait_timeout = 50\n \n+# The safe_mysqld script\n+[safe_mysqld]\n+log-error=/var/log/mysql/mysqld.log\n+socket\t\t= @MYSQL_UNIX_ADDR@\n+\n+# !includedir /etc/mysql\n+\n [mysqldump]\n+socket\t\t= @MYSQL_UNIX_ADDR@\n quick\n max_allowed_packet = 16M\n \nIndex: support-files/my-large.cnf.sh\n===================================================================\n--- support-files/my-large.cnf.sh.orig\n+++ support-files/my-large.cnf.sh\n@@ -132,7 +132,15 @@ server-id\t= 1\n #innodb_flush_log_at_trx_commit = 1\n #innodb_lock_wait_timeout = 50\n \n+# The safe_mysqld script\n+[safe_mysqld]\n+log-error=/var/log/mysql/mysqld.log\n+socket\t\t= @MYSQL_UNIX_ADDR@\n+\n+# !includedir /etc/mysql\n+\n [mysqldump]\n+socket\t\t= @MYSQL_UNIX_ADDR@\n quick\n max_allowed_packet = 16M\n \nIndex: support-files/my-medium.cnf.sh\n===================================================================\n--- support-files/my-medium.cnf.sh.orig\n+++ support-files/my-medium.cnf.sh\n@@ -28,6 +28,8 @@ socket\t\t= @MYSQL_UNIX_ADDR@\n [mysqld]\n port\t\t= @MYSQL_TCP_PORT@\n socket\t\t= @MYSQL_UNIX_ADDR@\n+# Change following line if you want to store your database elsewhere\n+datadir\t= /var/lib/mysql\n skip-external-locking\n key_buffer_size = 16M\n max_allowed_packet = 1M\n@@ -130,7 +132,15 @@ server-id\t= 1\n #innodb_flush_log_at_trx_commit = 1\n #innodb_lock_wait_timeout = 50\n \n+# The safe_mysqld script\n+[safe_mysqld]\n+log-error\t= /var/log/mysql/mysqld.log\n+socket\t\t= @MYSQL_UNIX_ADDR@\n+\n+# !includedir /etc/mysql\n+\n [mysqldump]\n+socket\t\t= @MYSQL_UNIX_ADDR@\n quick\n max_allowed_packet = 16M\n \nIndex: support-files/my-small.cnf.sh\n===================================================================\n--- support-files/my-small.cnf.sh.orig\n+++ support-files/my-small.cnf.sh\n@@ -65,7 +65,15 @@ server-id\t= 1\n #innodb_flush_log_at_trx_commit = 1\n #innodb_lock_wait_timeout = 50\n \n+# The safe_mysqld script\n+[safe_mysqld]\n+log-error\t= /var/log/mysql/mysqld.log\n+socket\t\t= @MYSQL_UNIX_ADDR@\n+\n+# !includedir /etc/mysql\n+\n [mysqldump]\n+socket\t\t= @MYSQL_UNIX_ADDR@\n quick\n max_allowed_packet = 16M"}], "metadata": {"id": "mariadb-499-mariadb-5.1.55-cnf.patch", "cve_id": "CVE-2012-0113", "package": "mariadb", "tier": "identical", "has_source_context": false, "license": "GPL-2.0-only"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- crypto/evp/e_aes.c\n\n## Upstream Fix\n```diff\nFrom 800e34eef64fc2d1ef301cc9195d1059f49884d7 Mon Sep 17 00:00:00 2001\nFrom: \"Leonidas S. Barbosa\" \nDate: Tue, 1 Sep 2015 17:28:38 -0400\nSubject: [PATCH 1/4] Taking only the struct-change of 'ks' to 'ks->ks'\n\nFrom c5f6da54fc64fb544028a547c9f6835f3f392428\n---\n crypto/evp/e_aes.c | 52 ++++++++++++++++++++++++++--------------------------\n 1 file changed, 26 insertions(+), 26 deletions(-)\n\ndiff --git a/crypto/evp/e_aes.c b/crypto/evp/e_aes.c\nindex a4b00c9..f3ac729 100644\n--- a/crypto/evp/e_aes.c\n+++ b/crypto/evp/e_aes.c\n@@ -62,7 +62,7 @@\n \n typedef struct\n \t{\n-\tAES_KEY ks;\n+\tunion { double align; AES_KEY ks; } ks;\n \tblock128_f block;\n \tunion {\n \t\tcbc128_f cbc;\n@@ -72,7 +72,7 @@ typedef struct\n \n typedef struct\n \t{\n-\tAES_KEY ks;\t\t/* AES key schedule to use */\n+\tunion { double align; AES_KEY ks; } ks;\t/* AES key schedule to use */\n \tint key_set;\t\t/* Set if key initialised */\n \tint iv_set;\t\t/* Set if an iv is set */\n \tGCM128_CONTEXT gcm;\n@@ -86,7 +86,7 @@ typedef struct\n \n typedef struct\n \t{\n-\tAES_KEY ks1, ks2;\t/* AES key schedules to use */\n+\tunion { double align; AES_KEY ks; } ks1, ks2;\t/* AES key schedules to use */\n \tXTS128_CONTEXT xts;\n \tvoid (*stream)(const unsigned char *in,\n \t\t\tunsigned char *out, size_t length,\n@@ -96,7 +96,7 @@ typedef struct\n \n typedef struct\n \t{\n-\tAES_KEY ks;\t\t/* AES key schedule to use */\n+\tunion { double align; AES_KEY ks; } ks;\t/* AES key schedule to use */\n \tint key_set;\t\t/* Set if key initialised */\n \tint iv_set;\t\t/* Set if an iv is set */\n \tint tag_set;\t\t/* Set if tag is valid */\n@@ -324,7 +324,7 @@ static int aesni_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \t\treturn 1;\n \tif (key)\n \t\t{\n-\t\taesni_set_encrypt_key(key, ctx->key_len * 8, &gctx->ks);\n+\t\taesni_set_encrypt_key(key, ctx->key_len * 8, &gctx->ks.ks);\n \t\tCRYPTO_gcm128_init(&gctx->gcm, &gctx->ks,\n \t\t\t\t(block128_f)aesni_encrypt);\n \t\tgctx->ctr = (ctr128_f)aesni_ctr32_encrypt_blocks;\n@@ -369,19 +369,19 @@ static int aesni_xts_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \t\t/* key_len is two AES keys */\n \t\tif (enc)\n \t\t\t{\n-\t\t\taesni_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1);\n+\t\t\taesni_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1.ks);\n \t\t\txctx->xts.block1 = (block128_f)aesni_encrypt;\n \t\t\txctx->stream = aesni_xts_encrypt;\n \t\t\t}\n \t\telse\n \t\t\t{\n-\t\t\taesni_set_decrypt_key(key, ctx->key_len * 4, &xctx->ks1);\n+\t\t\taesni_set_decrypt_key(key, ctx->key_len * 4, &xctx->ks1.ks);\n \t\t\txctx->xts.block1 = (block128_f)aesni_decrypt;\n \t\t\txctx->stream = aesni_xts_decrypt;\n \t\t\t}\n \n \t\taesni_set_encrypt_key(key + ctx->key_len/2,\n-\t\t\t\t\t\tctx->key_len * 4, &xctx->ks2);\n+\t\t\t\t\t\tctx->key_len * 4, &xctx->ks2.ks);\n \t\txctx->xts.block2 = (block128_f)aesni_encrypt;\n \n \t\txctx->xts.key1 = &xctx->ks1;\n@@ -408,7 +408,7 @@ static int aesni_ccm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \t\treturn 1;\n \tif (key)\n \t\t{\n-\t\taesni_set_encrypt_key(key, ctx->key_len * 8, &cctx->ks);\n+\t\taesni_set_encrypt_key(key, ctx->key_len * 8, &cctx->ks.ks);\n \t\tCRYPTO_ccm128_init(&cctx->ccm, cctx->M, cctx->L,\n \t\t\t\t\t&cctx->ks, (block128_f)aesni_encrypt);\n \t\tcctx->str = enc?(ccm128_f)aesni_ccm64_encrypt_blocks :\n@@ -519,7 +519,7 @@ static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #ifdef BSAES_CAPABLE\n \t if (BSAES_CAPABLE && mode==EVP_CIPH_CBC_MODE)\n \t\t{\n-\t\tret = AES_set_decrypt_key(key,ctx->key_len*8,&dat->ks);\n+\t\tret = AES_set_decrypt_key(key,ctx->key_len*8,&dat->ks.ks);\n \t\tdat->block\t= (block128_f)AES_decrypt;\n \t\tdat->stream.cbc\t= (cbc128_f)bsaes_cbc_encrypt;\n \t\t}\n@@ -528,7 +528,7 @@ static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #ifdef VPAES_CAPABLE\n \t if (VPAES_CAPABLE)\n \t\t{\n-\t\tret = vpaes_set_decrypt_key(key,ctx->key_len*8,&dat->ks);\n+\t\tret = vpaes_set_decrypt_key(key,ctx->key_len*8,&dat->ks.ks);\n \t\tdat->block\t= (block128_f)vpaes_decrypt;\n \t\tdat->stream.cbc\t= mode==EVP_CIPH_CBC_MODE ?\n \t\t\t\t\t(cbc128_f)vpaes_cbc_encrypt :\n@@ -537,7 +537,7 @@ static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \t else\n #endif\n \t\t{\n-\t\tret = AES_set_decrypt_key(key,ctx->key_len*8,&dat->ks);\n+\t\tret = AES_set_decrypt_key(key,ctx->key_len*8,&dat->ks.ks);\n \t\tdat->block\t= (block128_f)AES_decrypt;\n \t\tdat->stream.cbc\t= mode==EVP_CIPH_CBC_MODE ?\n \t\t\t\t\t(cbc128_f)AES_cbc_encrypt :\n@@ -547,7 +547,7 @@ static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #ifdef BSAES_CAPABLE\n \t if (BSAES_CAPABLE && mode==EVP_CIPH_CTR_MODE)\n \t\t{\n-\t\tret = AES_set_encrypt_key(key,ctx->key_len*8,&dat->ks);\n+\t\tret = AES_set_encrypt_key(key,ctx->key_len*8,&dat->ks.ks);\n \t\tdat->block\t= (block128_f)AES_encrypt;\n \t\tdat->stream.ctr\t= (ctr128_f)bsaes_ctr32_encrypt_blocks;\n \t\t}\n@@ -556,7 +556,7 @@ static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #ifdef VPAES_CAPABLE\n \t if (VPAES_CAPABLE)\n \t\t{\n-\t\tret = vpaes_set_encrypt_key(key,ctx->key_len*8,&dat->ks);\n+\t\tret = vpaes_set_encrypt_key(key,ctx->key_len*8,&dat->ks.ks);\n \t\tdat->block\t= (block128_f)vpaes_encrypt;\n \t\tdat->stream.cbc\t= mode==EVP_CIPH_CBC_MODE ?\n \t\t\t\t\t(cbc128_f)vpaes_cbc_encrypt :\n@@ -565,7 +565,7 @@ static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \t else\n #endif\n \t\t{\n-\t\tret = AES_set_encrypt_key(key,ctx->key_len*8,&dat->ks);\n+\t\tret = AES_set_encrypt_key(key,ctx->key_len*8,&dat->ks.ks);\n \t\tdat->block\t= (block128_f)AES_encrypt;\n \t\tdat->stream.cbc\t= mode==EVP_CIPH_CBC_MODE ?\n \t\t\t\t\t(cbc128_f)AES_cbc_encrypt :\n@@ -861,7 +861,7 @@ static int aes_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #ifdef BSAES_CAPABLE\n \t\tif (BSAES_CAPABLE)\n \t\t\t{\n-\t\t\tAES_set_encrypt_key(key,ctx->key_len*8,&gctx->ks);\n+\t\t\tAES_set_encrypt_key(key,ctx->key_len*8,&gctx->ks.ks);\n \t\t\tCRYPTO_gcm128_init(&gctx->gcm,&gctx->ks,\n \t\t\t\t\t(block128_f)AES_encrypt);\n \t\t\tgctx->ctr = (ctr128_f)bsaes_ctr32_encrypt_blocks;\n@@ -872,7 +872,7 @@ static int aes_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #ifdef VPAES_CAPABLE\n \t\tif (VPAES_CAPABLE)\n \t\t\t{\n-\t\t\tvpaes_set_encrypt_key(key,ctx->key_len*8,&gctx->ks);\n+\t\t\tvpaes_set_encrypt_key(key,ctx->key_len*8,&gctx->ks.ks);\n \t\t\tCRYPTO_gcm128_init(&gctx->gcm,&gctx->ks,\n \t\t\t\t\t(block128_f)vpaes_encrypt);\n \t\t\tgctx->ctr = NULL;\n@@ -882,7 +882,7 @@ static int aes_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #endif\n \t\t(void)0;\t/* terminate potentially open 'else' */\n \n-\t\tAES_set_encrypt_key(key, ctx->key_len * 8, &gctx->ks);\n+\t\tAES_set_encrypt_key(key, ctx->key_len * 8, &gctx->ks.ks);\n \t\tCRYPTO_gcm128_init(&gctx->gcm, &gctx->ks, (block128_f)AES_encrypt);\n #ifdef AES_CTR_ASM\n \t\tgctx->ctr = (ctr128_f)AES_ctr32_encrypt;\n@@ -1132,17 +1132,17 @@ static int aes_xts_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \t\t {\n \t\t if (enc)\n \t\t\t{\n-\t\t\tvpaes_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1);\n+\t\t\tvpaes_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1.ks);\n \t\t\txctx->xts.block1 = (block128_f)vpaes_encrypt;\n \t\t\t}\n \t\t else\n \t\t\t{\n-\t\t\tvpaes_set_decrypt_key(key, ctx->key_len * 4, &xctx->ks1);\n+\t\t\tvpaes_set_decrypt_key(key, ctx->key_len * 4, &xctx->ks1.ks);\n \t\t\txctx->xts.block1 = (block128_f)vpaes_decrypt;\n \t\t\t}\n \n \t\t vpaes_set_encrypt_key(key + ctx->key_len/2,\n-\t\t\t\t\t\tctx->key_len * 4, &xctx->ks2);\n+\t\t\t\t\t\tctx->key_len * 4, &xctx->ks2.ks);\n \t\t xctx->xts.block2 = (block128_f)vpaes_encrypt;\n \n \t\t xctx->xts.key1 = &xctx->ks1;\n@@ -1154,17 +1154,17 @@ static int aes_xts_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \n \t\tif (enc)\n \t\t\t{\n-\t\t\tAES_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1);\n+\t\t\tAES_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1.ks);\n \t\t\txctx->xts.block1 = (block128_f)AES_encrypt;\n \t\t\t}\n \t\telse\n \t\t\t{\n-\t\t\tAES_set_decrypt_key(key, ctx->key_len * 4, &xctx->ks1);\n+\t\t\tAES_set_decrypt_key(key, ctx->key_len * 4, &xctx->ks1.ks);\n \t\t\txctx->xts.block1 = (block128_f)AES_decrypt;\n \t\t\t}\n \n \t\tAES_set_encrypt_key(key + ctx->key_len/2,\n-\t\t\t\t\t\tctx->key_len * 4, &xctx->ks2);\n+\t\t\t\t\t\tctx->key_len * 4, &xctx->ks2.ks);\n \t\txctx->xts.block2 = (block128_f\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From 800e34eef64fc2d1ef301cc9195d1059f49884d7 Mon Sep 17 00:00:00 2001\nFrom: \"Leonidas S. Barbosa\" \nDate: Tue, 1 Sep 2015 17:28:38 -0400\nSubject: [PATCH 1/4] Taking only the struct-change of 'ks' to 'ks->ks'\n\nFrom c5f6da54fc64fb544028a547c9f6835f3f392428\n---\n crypto/evp/e_aes.c | 52 ++++++++++++++++++++++++++--------------------------\n 1 file changed, 26 insertions(+), 26 deletions(-)\n\ndiff --git a/crypto/evp/e_aes.c b/crypto/evp/e_aes.c\nindex a4b00c9..f3ac729 100644\n--- a/crypto/evp/e_aes.c\n+++ b/crypto/evp/e_aes.c\n@@ -62,7 +62,7 @@\n \n typedef struct\n \t{\n-\tAES_KEY ks;\n+\tunion { double align; AES_KEY ks; } ks;\n \tblock128_f block;\n \tunion {\n \t\tcbc128_f cbc;\n@@ -72,7 +72,7 @@ typedef struct\n \n typedef struct\n \t{\n-\tAES_KEY ks;\t\t/* AES key schedule to use */\n+\tunion { double align; AES_KEY ks; } ks;\t/* AES key schedule to use */\n \tint key_set;\t\t/* Set if key initialised */\n \tint iv_set;\t\t/* Set if an iv is set */\n \tGCM128_CONTEXT gcm;\n@@ -86,7 +86,7 @@ typedef struct\n \n typedef struct\n \t{\n-\tAES_KEY ks1, ks2;\t/* AES key schedules to use */\n+\tunion { double align; AES_KEY ks; } ks1, ks2;\t/* AES key schedules to use */\n \tXTS128_CONTEXT xts;\n \tvoid (*stream)(const unsigned char *in,\n \t\t\tunsigned char *out, size_t length,\n@@ -96,7 +96,7 @@ typedef struct\n \n typedef struct\n \t{\n-\tAES_KEY ks;\t\t/* AES key schedule to use */\n+\tunion { double align; AES_KEY ks; } ks;\t/* AES key schedule to use */\n \tint key_set;\t\t/* Set if key initialised */\n \tint iv_set;\t\t/* Set if an iv is set */\n \tint tag_set;\t\t/* Set if tag is valid */\n@@ -324,7 +324,7 @@ static int aesni_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \t\treturn 1;\n \tif (key)\n \t\t{\n-\t\taesni_set_encrypt_key(key, ctx->key_len * 8, &gctx->ks);\n+\t\taesni_set_encrypt_key(key, ctx->key_len * 8, &gctx->ks.ks);\n \t\tCRYPTO_gcm128_init(&gctx->gcm, &gctx->ks,\n \t\t\t\t(block128_f)aesni_encrypt);\n \t\tgctx->ctr = (ctr128_f)aesni_ctr32_encrypt_blocks;\n@@ -369,19 +369,19 @@ static int aesni_xts_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \t\t/* key_len is two AES keys */\n \t\tif (enc)\n \t\t\t{\n-\t\t\taesni_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1);\n+\t\t\taesni_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1.ks);\n \t\t\txctx->xts.block1 = (block128_f)aesni_encrypt;\n \t\t\txctx->stream = aesni_xts_encrypt;\n \t\t\t}\n \t\telse\n \t\t\t{\n-\t\t\taesni_set_decrypt_key(key, ctx->key_len * 4, &xctx->ks1);\n+\t\t\taesni_set_decrypt_key(key, ctx->key_len * 4, &xctx->ks1.ks);\n \t\t\txctx->xts.block1 = (block128_f)aesni_decrypt;\n \t\t\txctx->stream = aesni_xts_decrypt;\n \t\t\t}\n \n \t\taesni_set_encrypt_key(key + ctx->key_len/2,\n-\t\t\t\t\t\tctx->key_len * 4, &xctx->ks2);\n+\t\t\t\t\t\tctx->key_len * 4, &xctx->ks2.ks);\n \t\txctx->xts.block2 = (block128_f)aesni_encrypt;\n \n \t\txctx->xts.key1 = &xctx->ks1;\n@@ -408,7 +408,7 @@ static int aesni_ccm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \t\treturn 1;\n \tif (key)\n \t\t{\n-\t\taesni_set_encrypt_key(key, ctx->key_len * 8, &cctx->ks);\n+\t\taesni_set_encrypt_key(key, ctx->key_len * 8, &cctx->ks.ks);\n \t\tCRYPTO_ccm128_init(&cctx->ccm, cctx->M, cctx->L,\n \t\t\t\t\t&cctx->ks, (block128_f)aesni_encrypt);\n \t\tcctx->str = enc?(ccm128_f)aesni_ccm64_encrypt_blocks :\n@@ -519,7 +519,7 @@ static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #ifdef BSAES_CAPABLE\n \t if (BSAES_CAPABLE && mode==EVP_CIPH_CBC_MODE)\n \t\t{\n-\t\tret = AES_set_decrypt_key(key,ctx->key_len*8,&dat->ks);\n+\t\tret = AES_set_decrypt_key(key,ctx->key_len*8,&dat->ks.ks);\n \t\tdat->block\t= (block128_f)AES_decrypt;\n \t\tdat->stream.cbc\t= (cbc128_f)bsaes_cbc_encrypt;\n \t\t}\n@@ -528,7 +528,7 @@ static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #ifdef VPAES_CAPABLE\n \t if (VPAES_CAPABLE)\n \t\t{\n-\t\tret = vpaes_set_decrypt_key(key,ctx->key_len*8,&dat->ks);\n+\t\tret = vpaes_set_decrypt_key(key,ctx->key_len*8,&dat->ks.ks);\n \t\tdat->block\t= (block128_f)vpaes_decrypt;\n \t\tdat->stream.cbc\t= mode==EVP_CIPH_CBC_MODE ?\n \t\t\t\t\t(cbc128_f)vpaes_cbc_encrypt :\n@@ -537,7 +537,7 @@ static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \t else\n #endif\n \t\t{\n-\t\tret = AES_set_decrypt_key(key,ctx->key_len*8,&dat->ks);\n+\t\tret = AES_set_decrypt_key(key,ctx->key_len*8,&dat->ks.ks);\n \t\tdat->block\t= (block128_f)AES_decrypt;\n \t\tdat->stream.cbc\t= mode==EVP_CIPH_CBC_MODE ?\n \t\t\t\t\t(cbc128_f)AES_cbc_encrypt :\n@@ -547,7 +547,7 @@ static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #ifdef BSAES_CAPABLE\n \t if (BSAES_CAPABLE && mode==EVP_CIPH_CTR_MODE)\n \t\t{\n-\t\tret = AES_set_encrypt_key(key,ctx->key_len*8,&dat->ks);\n+\t\tret = AES_set_encrypt_key(key,ctx->key_len*8,&dat->ks.ks);\n \t\tdat->block\t= (block128_f)AES_encrypt;\n \t\tdat->stream.ctr\t= (ctr128_f)bsaes_ctr32_encrypt_blocks;\n \t\t}\n@@ -556,7 +556,7 @@ static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #ifdef VPAES_CAPABLE\n \t if (VPAES_CAPABLE)\n \t\t{\n-\t\tret = vpaes_set_encrypt_key(key,ctx->key_len*8,&dat->ks);\n+\t\tret = vpaes_set_encrypt_key(key,ctx->key_len*8,&dat->ks.ks);\n \t\tdat->block\t= (block128_f)vpaes_encrypt;\n \t\tdat->stream.cbc\t= mode==EVP_CIPH_CBC_MODE ?\n \t\t\t\t\t(cbc128_f)vpaes_cbc_encrypt :\n@@ -565,7 +565,7 @@ static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \t else\n #endif\n \t\t{\n-\t\tret = AES_set_encrypt_key(key,ctx->key_len*8,&dat->ks);\n+\t\tret = AES_set_encrypt_key(key,ctx->key_len*8,&dat->ks.ks);\n \t\tdat->block\t= (block128_f)AES_encrypt;\n \t\tdat->stream.cbc\t= mode==EVP_CIPH_CBC_MODE ?\n \t\t\t\t\t(cbc128_f)AES_cbc_encrypt :\n@@ -861,7 +861,7 @@ static int aes_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #ifdef BSAES_CAPABLE\n \t\tif (BSAES_CAPABLE)\n \t\t\t{\n-\t\t\tAES_set_encrypt_key(key,ctx->key_len*8,&gctx->ks);\n+\t\t\tAES_set_encrypt_key(key,ctx->key_len*8,&gctx->ks.ks);\n \t\t\tCRYPTO_gcm128_init(&gctx->gcm,&gctx->ks,\n \t\t\t\t\t(block128_f)AES_encrypt);\n \t\t\tgctx->ctr = (ctr128_f)bsaes_ctr32_encrypt_blocks;\n@@ -872,7 +872,7 @@ static int aes_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #ifdef VPAES_CAPABLE\n \t\tif (VPAES_CAPABLE)\n \t\t\t{\n-\t\t\tvpaes_set_encrypt_key(key,ctx->key_len*8,&gctx->ks);\n+\t\t\tvpaes_set_encrypt_key(key,ctx->key_len*8,&gctx->ks.ks);\n \t\t\tCRYPTO_gcm128_init(&gctx->gcm,&gctx->ks,\n \t\t\t\t\t(block128_f)vpaes_encrypt);\n \t\t\tgctx->ctr = NULL;\n@@ -882,7 +882,7 @@ static int aes_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #endif\n \t\t(void)0;\t/* terminate potentially open 'else' */\n \n-\t\tAES_set_encrypt_key(key, ctx->key_len * 8, &gctx->ks);\n+\t\tAES_set_encrypt_key(key, ctx->key_len * 8, &gctx->ks.ks);\n \t\tCRYPTO_gcm128_init(&gctx->gcm, &gctx->ks, (block128_f)AES_encrypt);\n #ifdef AES_CTR_ASM\n \t\tgctx->ctr = (ctr128_f)AES_ctr32_encrypt;\n@@ -1132,17 +1132,17 @@ static int aes_xts_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \t\t {\n \t\t if (enc)\n \t\t\t{\n-\t\t\tvpaes_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1);\n+\t\t\tvpaes_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1.ks);\n \t\t\txctx->xts.block1 = (block128_f)vpaes_encrypt;\n \t\t\t}\n \t\t else\n \t\t\t{\n-\t\t\tvpaes_set_decrypt_key(key, ctx->key_len * 4, &xctx->ks1);\n+\t\t\tvpaes_set_decrypt_key(key, ctx->key_len * 4, &xctx->ks1.ks);\n \t\t\txctx->xts.block1 = (block128_f)vpaes_decrypt;\n \t\t\t}\n \n \t\t vpaes_set_encrypt_key(key + ctx->key_len/2,\n-\t\t\t\t\t\tctx->key_len * 4, &xctx->ks2);\n+\t\t\t\t\t\tctx->key_len * 4, &xctx->ks2.ks);\n \t\t xctx->xts.block2 = (block128_f)vpaes_encrypt;\n \n \t\t xctx->xts.key1 = &xctx->ks1;\n@@ -1154,17 +1154,17 @@ static int aes_xts_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \n \t\tif (enc)\n \t\t\t{\n-\t\t\tAES_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1);\n+\t\t\tAES_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1.ks);\n \t\t\txctx->xts.block1 = (block128_f)AES_encrypt;\n \t\t\t}\n \t\telse\n \t\t\t{\n-\t\t\tAES_set_decrypt_key(key, ctx->key_len * 4, &xctx->ks1);\n+\t\t\tAES_set_decrypt_key(key, ctx->key_len * 4, &xctx->ks1.ks);\n \t\t\txctx->xts.block1 = (block128_f)AES_decrypt;\n \t\t\t}\n \n \t\tAES_set_encrypt_key(key + ctx->key_len/2,\n-\t\t\t\t\t\tctx->key_len * 4, &xctx->ks2);\n+\t\t\t\t\t\tctx->key_len * 4, &xctx->ks2.ks);\n \t\txctx->xts.block2 = (block128_f)AES_encrypt;\n \n \t\txctx->xts.key1 = &xctx->ks1;\n@@ -1289,7 +1289,7 @@ static int aes_ccm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #ifdef VPAES_CAPABLE\n \t\tif (VPAES_CAPABLE)\n \t\t\t{\n-\t\t\tvpaes_set_encrypt_key(key, ctx->key_len*8, &cctx->ks);\n+\t\t\tvpaes_set_encrypt_key(key, ctx->key_len*8, &cctx->ks.ks);\n \t\t\tCRYPTO_ccm128_init(&cctx->ccm, cctx->M, cctx->L,\n \t\t\t\t\t&cctx->ks, (block128_f)vpaes_encrypt);\n \t\t\tcctx->str = NULL;\n@@ -1297,7 +1297,7 @@ static int aes_ccm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \t\t\tbreak;\n \t\t\t}\n #endif\n-\t\tAES_set_encrypt_key(key, ctx->key_len * 8, &cctx->ks);\n+\t\tAES_set_encrypt_key(key, ctx->key_len * 8, &cctx->ks.ks);\n \t\tCRYPTO_ccm128_init(&cctx->ccm, cctx->M, cctx->L,\n \t\t\t\t\t&cctx->ks, (block128_f)AES_encrypt);\n \t\tcctx->str = NULL;\n-- \n1.8.5.6"}], "metadata": {"id": "openssl-4769-0001-Taking-only-the-struct-ch", "cve_id": "CVE-2015-3197", "package": "openssl", "tier": "adapted", "has_source_context": false, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2012-2142\n\nThe error function in Error.cc in poppler before 0.21.4 allows remote attackers to execute arbitrary commands via a PDF containing an escape sequence for a terminal emulator.\n\n## Package\npoppler\n\n## Upstream Fix\n```diff\nFrom 92ef16e3699da949c80716c3fd4b438fe79c134d Mon Sep 17 00:00:00 2001\nFrom: Thomas Freitag \nDate: Sun, 10 Jun 2012 14:58:54 +0000\nSubject: use setoverprintmode only if rip knows it\n\n---\n(limited to 'poppler/PSOutputDev.cc')\n\ndiff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc\nindex dac10d0..c655652 100644\n--- a/poppler/PSOutputDev.cc\n+++ b/poppler/PSOutputDev.cc\n@@ -258,7 +258,7 @@ static const char *prolog[] = {\n \"} def\",\n \"~3n\",\n \"/opm { dup /pdfOPM exch def\",\n- \" setoverprintmode } def\",\n+ \" /setoverprintmode where{pop setoverprintmode}{pop}ifelse } def\",\n \"~23n\",\n \"/cs { /pdfFillXform exch def dup /pdfFillCS exch def\",\n \" setcolorspace } def\",\n@@ -292,7 +292,7 @@ static const char *prolog[] = {\n \"} def\",\n \"~3s\",\n \"/opm { dup /pdfOPM exch def\",\n- \" setoverprintmode } def\",\n+ \" /setoverprintmode where{pop setoverprintmode}{pop}ifelse } def\",\n \"~23s\",\n \"/k { 4 copy 4 array astore /pdfFill exch def setcmykcolor\",\n \" /pdfLastFill true def /pdfLastStroke false def } def\",\n@@ -390,7 +390,7 @@ static const char *prolog[] = {\n \"~3sn\",\n \" /pdfOPM where {\",\n \" pop\",\n- \" pdfOPM setoverprintmode\",\n+ \" pdfOPM /setoverprintmode where{pop setoverprintmode}{pop}ifelse \",\n \" } if\",\n \"~23sn\",\n \"} def\",\n--\ncgit v0.9.0.2-2-gbebe\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From 92ef16e3699da949c80716c3fd4b438fe79c134d Mon Sep 17 00:00:00 2001\nFrom: Thomas Freitag \nDate: Sun, 10 Jun 2012 14:58:54 +0000\nSubject: use setoverprintmode only if rip knows it\n\n---\n(limited to 'poppler/PSOutputDev.cc')\n\ndiff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc\nindex dac10d0..c655652 100644\n--- a/poppler/PSOutputDev.cc\n+++ b/poppler/PSOutputDev.cc\n@@ -258,7 +258,7 @@ static const char *prolog[] = {\n \"} def\",\n \"~3n\",\n \"/opm { dup /pdfOPM exch def\",\n- \" setoverprintmode } def\",\n+ \" /setoverprintmode where{pop setoverprintmode}{pop}ifelse } def\",\n \"~23n\",\n \"/cs { /pdfFillXform exch def dup /pdfFillCS exch def\",\n \" setcolorspace } def\",\n@@ -292,7 +292,7 @@ static const char *prolog[] = {\n \"} def\",\n \"~3s\",\n \"/opm { dup /pdfOPM exch def\",\n- \" setoverprintmode } def\",\n+ \" /setoverprintmode where{pop setoverprintmode}{pop}ifelse } def\",\n \"~23s\",\n \"/k { 4 copy 4 array astore /pdfFill exch def setcmykcolor\",\n \" /pdfLastFill true def /pdfLastStroke false def } def\",\n@@ -390,7 +390,7 @@ static const char *prolog[] = {\n \"~3sn\",\n \" /pdfOPM where {\",\n \" pop\",\n- \" pdfOPM setoverprintmode\",\n+ \" pdfOPM /setoverprintmode where{pop setoverprintmode}{pop}ifelse \",\n \" } if\",\n \"~23sn\",\n \"} def\",\n--\ncgit v0.9.0.2-2-gbebe"}], "metadata": {"id": "poppler-1943-poppler-fix-postscript-error-s", "cve_id": "CVE-2012-2142", "package": "poppler", "tier": "identical", "has_source_context": false, "license": "GPL-2.0-only OR GPL-3.0-only"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-6250\n\nInteger overflow in the ISO9660 writer in libarchive before 3.2.1 allows remote attackers to cause a denial of service (application crash) or execute arbitrary code via vectors related to verifying filename lengths when writing an ISO9660 archive, which trigger a buffer overflow.\n\n## Package\nlibarchive\n\n## Files to modify\n- libarchive/archive_write_disk_posix.c\n- libarchive-3.1.2.orig/libarchive/archive_write_disk_posix.c\n\n## Target Source Code\n\n### libarchive/archive_write_disk_posix.c\n\n#### region() [lines 287-379]\n```c\n * Note that POSIX specifies 0777 for implicitly-created dirs, \"modified\n * by the process' file creation mask.\"\n */\n#define\tDEFAULT_DIR_MODE 0777\n/*\n * Dir modes are restored in two steps: During the extraction, the permissions\n * in the archive are modified to match the following limits. During\n * the post-extract fixup pass, the permissions from the archive are\n * applied.\n */\n#define\tMINIMUM_DIR_MODE 0700\n#define\tMAXIMUM_DIR_MODE 0775\n\n/*\n * Maxinum uncompressed size of a decmpfs block.\n */\n#define MAX_DECMPFS_BLOCK_SIZE\t(64 * 1024)\n/*\n * HFS+ compression type.\n */\n#define CMP_XATTR\t\t3/* Compressed data in xattr. */\n#define CMP_RESOURCE_FORK\t4/* Compressed data in resource fork. */\n/*\n * HFS+ compression resource fork.\n */\n#define RSRC_H_SIZE\t260\t/* Base size of Resource fork header. */\n#define RSRC_F_SIZE\t50\t/* Size of Resource fork footer. */\n/* Size to write compressed data to resource fork. */\n#define COMPRESSED_W_SIZE\t(64 * 1024)\n/* decmpfs difinitions. */\n#define MAX_DECMPFS_XATTR_SIZE\t\t3802\n#ifndef DECMPFS_XATTR_NAME\n#define DECMPFS_XATTR_NAME\t\t\"com.apple.decmpfs\"\n#endif\n#define DECMPFS_MAGIC\t\t\t0x636d7066\n#define DECMPFS_COMPRESSION_MAGIC\t0\n#define DECMPFS_COMPRESSION_TYPE\t4\n#define DECMPFS_UNCOMPRESSED_SIZE\t8\n#define DECMPFS_HEADER_SIZE\t\t16\n\n#define HFS_BLOCKS(s)\t((s) >> 12)\n\nstatic int\tcheck_symlinks(struct archive_write_disk *);\nstatic int\tcreate_filesystem_object(struct archive_write_disk *);\nstatic struct fixup_entry *current_fixup(struct archive_write_disk *, const char *pathname);\n#if defined(HAVE_FCHDIR) && defined(PATH_MAX)\nstatic void\tedit_deep_directories(struct archive_write_disk *ad);\n#endif\nstatic int\tcleanup_pathname(struct archive_write_disk *);\nstatic int\tcreate_dir(struct archive_write_disk *, char *);\nstatic int\tcreate_parent_dir(struct archive_write_disk *, char *);\nstatic ssize_t\thfs_write_data_block(struct archive_write_disk *,\n\t\t const char *, size_t);\nstatic int\tfixup_appledouble(struct archive_write_disk *, const char *);\nstatic int\tolder(struct stat *, struct archive_entry *);\nstatic int\trestore_entry(struct archive_write_disk *);\nstatic int\tset_mac_metadata(struct archive_write_disk *, const char *,\n\t\t\t\t const void *, size_t);\nstatic int\tset_xattrs(struct archive_write_disk *);\nstatic int\tset_fflags(struct archive_write_disk *);\nstatic int\tset_fflags_platform(struct archive_write_disk *, int fd,\n\t\t const char *name, mode_t mode,\n\t\t unsigned long fflags_set, unsigned long fflags_clear);\nstatic int\tset_ownership(struct archive_write_disk *);\nstatic int\tset_mode(struct archive_write_disk *, int mode);\nstatic int\tset_time(int, int, const char *, time_t, long, time_t, long);\nstatic int\tset_times(struct archive_write_disk *, int, int, const char *,\n\t\t time_t, long, time_t, long, time_t, long, time_t, long);\nstatic int\tset_times_from_entry(struct archive_write_disk *);\nstatic struct fixup_entry *sort_dir_list(struct fixup_entry *p);\nstatic ssize_t\twrite_data_block(struct archive_write_disk *,\n\t\t const char *, size_t);\n\nstatic struct archive_vtable *archive_write_disk_vtable(void);\n\nstatic int\t_archive_write_disk_close(struct archive *);\nstatic int\t_archive_write_disk_free(struct archive *);\nstatic int\t_archive_write_disk_header(struct archive *, struct archive_entry *);\nstatic int64_t\t_archive_write_disk_filter_bytes(struct archive *, int);\nstatic int\t_archive_write_disk_finish_entry(struct archive *);\nstatic ssize_t\t_archive_write_disk_data(struct archive *, const void *, size_t);\nstatic ssize_t\t_archive_write_disk_data_block(struct archive *, const void *, size_t, int64_t);\n\nstatic int\nlazy_stat(struct archive_write_disk *a)\n{\n\tif (a->pst != NULL) {\n\t\t/* Already have stat() data available. */\n\t\treturn (ARCHIVE_OK);\n\t}\n#ifdef HAVE_FSTAT\n\tif (a->fd >= 0 && fstat(a->fd, &a->st) == 0) {\n\t\ta->pst = &a->st;\n```\n\n#### edit_deep_directories() [lines 1785-1827]\n```c\n */\n#if defined(HAVE_FCHDIR) && defined(PATH_MAX)\nstatic void\nedit_deep_directories(struct archive_write_disk *a)\n{\n\tint ret;\n\tchar *tail = a->name;\n\n\t/* If path is short, avoid the open() below. */\n\tif (strlen(tail) <= PATH_MAX)\n\t\treturn;\n\n\t/* Try to record our starting dir. */\n\ta->restore_pwd = open(\".\", O_RDONLY | O_BINARY | O_CLOEXEC);\n\t__archive_ensure_cloexec_flag(a->restore_pwd);\n\tif (a->restore_pwd < 0)\n\t\treturn;\n\n\t/* As long as the path is too long... */\n\twhile (strlen(tail) > PATH_MAX) {\n\t\t/* Locate a dir prefix shorter than PATH_MAX. */\n\t\ttail += PATH_MAX - 8;\n\t\twhile (tail > a->name && *tail != '/')\n\t\t\ttail--;\n\t\t/* Exit if we find a too-long path component. */\n\t\tif (tail <= a->name)\n\t\t\treturn;\n\t\t/* Create the intermediate dir and chdir to it. */\n\t\t*tail = '\\0'; /* Terminate dir portion */\n\t\tret = create_dir(a, a->name);\n\t\tif (ret == ARCHIVE_OK && chdir(a->name) != 0)\n\t\t\tret = ARCHIVE_FAILED;\n\t\t*tail = '/'; /* Restore the / we removed. */\n\t\tif (ret != ARCHIVE_OK)\n\t\t\treturn;\n\t\ttail++;\n\t\t/* The chdir() succeeded; we've now shortened the path. */\n\t\ta->name = tail;\n\t}\n\treturn;\n}\n#endif\n\n```\n\n#### create_filesystem_object() [lines 1990-2126]\n```c\n * a single system call.\n */\nstatic int\ncreate_filesystem_object(struct archive_write_disk *a)\n{\n\t/* Create the entry. */\n\tconst char *linkname;\n\tmode_t final_mode, mode;\n\tint r;\n\n\t/* We identify hard/symlinks according to the link names. */\n\t/* Since link(2) and symlink(2) don't handle modes, we're done here. */\n\tlinkname = archive_entry_hardlink(a->entry);\n\tif (linkname != NULL) {\n#if !HAVE_LINK\n\t\treturn (EPERM);\n#else\n\t\tr = link(linkname, a->name) ? errno : 0;\n\t\t/*\n\t\t * New cpio and pax formats allow hardlink entries\n\t\t * to carry data, so we may have to open the file\n\t\t * for hardlink entries.\n\t\t *\n\t\t * If the hardlink was successfully created and\n\t\t * the archive doesn't have carry data for it,\n\t\t * consider it to be non-authoritative for meta data.\n\t\t * This is consistent with GNU tar and BSD pax.\n\t\t * If the hardlink does carry data, let the last\n\t\t * archive entry decide ownership.\n\t\t */\n\t\tif (r == 0 && a->filesize <= 0) {\n\t\t\ta->todo = 0;\n\t\t\ta->deferred = 0;\n\t\t} else if (r == 0 && a->filesize > 0) {\n\t\t\ta->fd = open(a->name,\n\t\t\t\t O_WRONLY | O_TRUNC | O_BINARY | O_CLOEXEC);\n\t\t\t__archive_ensure_cloexec_flag(a->fd);\n\t\t\tif (a->fd < 0)\n\t\t\t\tr = errno;\n\t\t}\n/* ... 91 lines omitted ... */\n\t\tr = mkfifo(a->name, mode);\n\t\tbreak;\n#else\n\t\t/* TODO: Find a better way to warn about our inability\n\t\t * to restore a fifo. */\n\t\treturn (EINVAL);\n#endif /* HAVE_MKFIFO */\n\t}\n\n\t/* All the system calls above set errno on failure. */\n\tif (r)\n\t\treturn (errno);\n\n\t/* If we managed to set the final mode, we've avoided a chmod(). */\n\tif (mode == final_mode)\n\t\ta->todo &= ~TODO_MODE;\n\treturn (0);\n}\n\n/*\n```\n\n#### current_fixup() [lines 2325-2335]\n```c\n * Returns a fixup structure for the current entry.\n */\nstatic struct fixup_entry *\ncurrent_fixup(struct archive_write_disk *a, const char *pathname)\n{\n\tif (a->current_fixup == NULL)\n\t\ta->current_fixup = new_fixup(a, pathname);\n\treturn (a->current_fixup);\n}\n\n/* TODO: Make this work. */\n```\n\n#### cleanup_pathname_win() [lines 2446-2503]\n```c\n * See also : http://msdn.microsoft.com/en-us/library/aa365247.aspx\n */\nstatic void\ncleanup_pathname_win(struct archive_write_disk *a)\n{\n\twchar_t wc;\n\tchar *p;\n\tsize_t alen, l;\n\tint mb, complete, utf8;\n\n\talen = 0;\n\tmb = 0;\n\tcomplete = 1;\n\tutf8 = (strcmp(nl_langinfo(CODESET), \"UTF-8\") == 0)? 1: 0;\n\tfor (p = a->name; *p != '\\0'; p++) {\n\t\t++alen;\n\t\tif (*p == '\\\\') {\n\t\t\t/* If previous byte is smaller than 128,\n\t\t\t * this is not second byte of multibyte characters,\n\t\t\t * so we can replace '\\' with '/'. */\n\t\t\tif (utf8 || !mb)\n\t\t\t\t*p = '/';\n\t\t\telse\n\t\t\t\tcomplete = 0;/* uncompleted. */\n\t\t} else if (*(unsigned char *)p > 127)\n\t\t\tmb = 1;\n\t\telse\n\t\t\tmb = 0;\n\t\t/* Rewrite the path name if its next character is unusable. */\n\t\tif (*p == ':' || *p == '*' || *p == '?' || *p == '\"' ||\n\t\t *p == '<' || *p == '>' || *p == '|')\n\t\t\t*p = '_';\n\t}\n\tif (complete)\n\t\treturn;\n\n\t/*\n\t * Convert path separator in wide-character.\n\t */\n\tp = a->name;\n\twhile (*p != '\\0' && alen) {\n\t\tl = mbtowc(&wc, p, alen);\n\t\tif (l == (size_t)-1) {\n\t\t\twhile (*p != '\\0') {\n\t\t\t\tif (*p == '\\\\')\n\t\t\t\t\t*p = '/';\n\t\t\t\t++p;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tif (l == 1 && wc == L'\\\\')\n\t\t\t*p = '/';\n\t\tp += l;\n\t\talen -= l;\n\t}\n}\n#endif\n\n```\n\n#### cleanup_pathname() [lines 2508-2599]\n```c\n * set) any '..' in the path.\n */\nstatic int\ncleanup_pathname(struct archive_write_disk *a)\n{\n\tchar *dest, *src;\n\tchar separator = '\\0';\n\n\tdest = src = a->name;\n\tif (*src == '\\0') {\n\t\tarchive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,\n\t\t \"Invalid empty pathname\");\n\t\treturn (ARCHIVE_FAILED);\n\t}\n\n#if defined(__CYGWIN__)\n\tcleanup_pathname_win(a);\n#endif\n\t/* Skip leading '/'. */\n\tif (*src == '/')\n\t\tseparator = *src++;\n\n\t/* Scan the pathname one element at a time. */\n\tfor (;;) {\n\t\t/* src points to first char after '/' */\n\t\tif (src[0] == '\\0') {\n\t\t\tbreak;\n\t\t} else if (src[0] == '/') {\n\t\t\t/* Found '//', ignore second one. */\n\t\t\tsrc++;\n\t\t\tcontinue;\n\t\t} else if (src[0] == '.') {\n\t\t\tif (src[1] == '\\0') {\n\t\t\t\t/* Ignore trailing '.' */\n\t\t\t\tbreak;\n\t\t\t} else if (src[1] == '/') {\n\t\t\t\t/* Skip './'. */\n\t\t\t\tsrc += 2;\n\t\t\t\tcontinue;\n\t\t\t} else if (src[1] == '.') {\n\t\t\t\tif (src[2] == '/' || src[2] == '\\0') {\n\t\t\t\t\t/* Conditionally warn about '..' */\n\t\t\t\t\tif (a->flags & ARCHIVE_EXTRACT_SECURE_NODOTDOT) {\n\t\t\t\t\t\tarchive_set_error(&a->archive,\n\t\t\t\t\t\t ARCHIVE_ERRNO_MISC,\n\t\t\t\t\t\t \"Path contains '..'\");\n\t\t\t\t\t\treturn (ARCHIVE_FAILED);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t/*\n\t\t\t\t * Note: Under no circumstances do we\n\t\t\t\t * remove '..' elements. In\n\t\t\t\t * particular, restoring\n\t\t\t\t * '/foo/../bar/' should create the\n\t\t\t\t * 'foo' dir as a side-effect.\n\t\t\t\t */\n\t\t\t}\n\t\t}\n\n\t\t/* Copy current element, including leading '/'. */\n\t\tif (separator)\n\t\t\t*dest++ = '/';\n\t\twhile (*src != '\\0' && *src != '/') {\n\t\t\t*dest++ = *src++;\n\t\t}\n\n\t\tif (*src == '\\0')\n\t\t\tbreak;\n\n\t\t/* Skip '/' separator. */\n\t\tseparator = *src++;\n\t}\n\t/*\n\t * We've just copied zero or more path elements, not including the\n\t * final '/'.\n\t */\n\tif (dest == a->name) {\n\t\t/*\n\t\t * Nothing got copied. The path must have been something\n\t\t * like '.' or '/' or './' or '/././././/./'.\n\t\t */\n\t\tif (separator)\n\t\t\t*dest++ = '/';\n\t\telse\n\t\t\t*dest++ = '.';\n\t}\n\t/* Terminate the result. */\n\t*dest = '\\0';\n\treturn (ARCHIVE_OK);\n}\n\n/*\n```\n\n\n### Type definitions\n\n```c\n/* from archive_string.h */\nstruct archive_string {\n\tchar\t*s; /* Pointer to the storage */\n\tsize_t\t length; /* Length of 's' in characters */\n\tsize_t\t buffer_length; /* Length of malloc-ed storage in bytes. */\n};\n```\n\n\n## Upstream Fix\n```diff\nIndex: libarchive-3.1.2/libarchive/archive_write_disk_posix.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_write_disk_posix.c\n+++ libarchive-3.1.2/libarchive/archive_write_disk_posix.c\n@@ -326,12 +326,14 @@ struct archive_write_disk {\n \n #define HFS_BLOCKS(s)\t((s) >> 12)\n \n+static int\tcheck_symlinks_fsobj(char *path, int *error_number, struct archive_string *error_string, int flags);\n static int\tcheck_symlinks(struct archive_write_disk *);\n static int\tcreate_filesystem_object(struct archive_write_disk *);\n static struct fixup_entry *current_fixup(struct archive_write_disk *, const char *pathname);\n #if defined(HAVE_FCHDIR) && defined(PATH_MAX)\n static void\tedit_deep_directories(struct archive_write_disk *ad);\n #endif\n+static int\tcleanup_pathname_fsobj(char *path, int *error_number, struct archive_string *error_string, int flags);\n static int\tcleanup_pathname(struct archive_write_disk *);\n static int\tcreate_dir(struct archive_write_disk *, char *);\n static int\tcreate_parent_dir(struct archive_write_disk *, char *);\n@@ -1791,7 +1793,7 @@ edit_deep_directories(struct archive_wri\n \tchar *tail = a->name;\n \n \t/* If path is short, avoid the open() below. */\n-\tif (strlen(tail) <= PATH_MAX)\n+\tif (strlen(tail) < PATH_MAX)\n \t\treturn;\n \n \t/* Try to record our starting dir. */\n@@ -1801,7 +1803,7 @@ edit_deep_directories(struct archive_wri\n \t\treturn;\n \n \t/* As long as the path is too long... */\n-\twhile (strlen(tail) > PATH_MAX) {\n+\twhile (strlen(tail) >= PATH_MAX) {\n \t\t/* Locate a dir prefix shorter than PATH_MAX. */\n \t\ttail += PATH_MAX - 8;\n \t\twhile (tail > a->name && *tail != '/')\n@@ -1996,6 +1998,10 @@ create_filesystem_object(struct archive_\n \tconst char *linkname;\n \tmode_t final_mode, mode;\n \tint r;\n+\t/* these for check_symlinks_fsobj */\n+\tchar *linkname_copy;\t/* non-const copy of linkname */\n+\tstruct archive_string error_string;\n+\tint error_number;\n \n \t/* We identify hard/symlinks according to the link names. */\n \t/* Since link(2) and symlink(2) don't handle modes, we're done here. */\n@@ -2004,6 +2010,27 @@ create_filesystem_object(struct archive_\n #if !HAVE_LINK\n \t\treturn (EPERM);\n #else\n+\t\tarchive_string_init(&error_string);\n+\t\tlinkname_copy = strdup(linkname);\n+\t\tif (linkname_copy == NULL) {\n+\t\t return (EPERM);\n+\t\t}\n+\t\t/* TODO: consider using the cleaned-up path as the link target? */\n+\t\tr = cleanup_pathname_fsobj(linkname_copy, &error_number, &error_string, a->flags);\n+\t\tif (r != ARCHIVE_OK) {\n+\t\t\tarchive_set_error(&a->archive, error_number, \"%s\", error_string.s);\n+\t\t\tfree(linkname_copy);\n+\t\t\t/* EPERM is more appropriate than error_number for our callers */\n+\t\t\treturn (EPERM);\n+\t\t}\n+\t\tr = check_symlinks_fsobj(linkname_copy, &error_number, &error_string, a->flags);\n+\t\tif (r != ARCHIVE_OK) {\n+\t\t\tarchive_set_error(&a->archive, error_number, \"%s\", error_string.s);\n+\t\t\tfree(linkname_copy);\n+\t\t\t/* EPERM is more appropriate than error_number for our callers */\n+\t\t\treturn (EPERM);\n+\t\t}\n+\t\tfree(linkname_copy);\n \t\tr = link(linkname, a->name) ? errno : 0;\n \t\t/*\n \t\t * New cpio and pax formats allow hardlink entries\n@@ -2343,99 +2370,215 @@ current_fixup(struct archive_write_disk\n * recent paths.\n */\n /* TODO: Extend this to support symlinks on Windows Vista and later. */\n+\n+/*\n+ * Checks the given path to see if any elements along it are symlinks. Returns\n+ * ARCHIVE_OK if there are none, otherwise puts an error in errmsg.\n+ */\n static int\n-check_symlinks(struct archive_write_disk *a)\n+check_symlinks_fsobj(char *path, int *error_number, struct archive_string *error_string, int flags)\n {\n #if !defined(HAVE_LSTAT)\n \t/* Platform doesn't have lstat, so we can't look for symlinks. */\n-\t(void)a; /* UNUSED */\n+\t(void)path; /* UNUSED */\n+\t(void)error_number; /* UNUSED */\n+\t(void)error_string; /* UNUSED */\n+\t(void)flags; /* UNUSED */\n \treturn (ARCHIVE_OK);\n #else\n-\tchar *pn;\n+\tint res = ARCHIVE_OK;\n+\tchar *tail;\n+\tchar *head;\n+\tint last;\n \tchar c;\n \tint r;\n \tstruct stat st;\n+\tint restore_pwd;\n+\n+\t/* Nothing to do here if name is empty */\n+\tif(path[0] == '\\0')\n+\t return (ARCHIVE_OK);\n \n \t/*\n \t * Guard against symlink tricks. Reject any archive entry whose\n \t * destination would be altered by a symlink.\n-\t */\n-\t/* Whatever we checked last time doesn't need to be re-checked. */\n-\tpn = a->name;\n-\tif (archive_strlen(&(a->path_safe)) > 0) {\n-\t\tchar *p = a->path_safe.s;\n-\t\twhile ((*pn != '\\0') && (*p == *pn))\n-\t\t\t++p, ++pn;\n-\t}\n-\tc = pn[0];\n-\t/* Keep going until we've checked the entire name. */\n-\twhile (pn[0] != '\\0' && (pn[0] != '/' || pn[1] != '\\0')) {\n+\t *\n+\t * Walk the filename in chunks separated by '/'. For each segment:\n+\t * - if it doesn't exist, continue\n+\t * - if it's symlink, abort or remove it\n+\t * - if it's a directory and it's not the last chunk, cd into it\n+\t * As we go:\n+\t * head points to the current (relative) path\n+\t * tail points to the temporary \\0 terminating the segment we're currently examining\n+\t * c holds what used to be in *tail\n+\t * last is 1 if this is the last tail\n+\t */\n+\trestore_pwd = open(\".\", O_RDONLY | O_BINARY | O_CLOEXEC);\n+\t__archive_ensure_cloexec_flag(restore_pwd);\n+\tif (restore_pwd < 0)\n+\t\treturn (ARCHIVE_FATAL);\n+\thead = path;\n+\ttail = path;\n+\tlast = 0;\n+\n+\t/* TODO: reintroduce a safe cache here? */\n+\n+\t/* Keep going until we've checked the entire name.\n+\t * head, tail, path all alias the same string, which is\n+\t * temporarily zeroed at tail, so be careful restoring the\n+\t * stashed (c=tail[0]) for error messages.\n+\t * Exiting the loop with break is okay; continue is not.\n+\t */\n+\twhile (!last) {\n+\t\t/* Skip the separator we just consumed, plus any adjacent ones */\n+\t\twhile (*tail == '/')\n+\t\t ++tail;\n \t\t/* Skip the next path element. */\n-\t\twhile (*pn != '\\0' && *pn != '/')\n-\t\t\t++pn;\n-\t\tc = pn[0];\n-\t\tpn[0] = '\\0';\n+\t\twhile (*tail != '\\0' && *tail != '/')\n+\t\t\t++tail;\n+\t\t/* is this the last path component? */\n+\t\tlast = (tail[0] == '\\0') || (tail[0] == '/' && tail[1] == '\\0');\n+\t\t/* temporarily truncate the string here */\n+\t\tc = tail[0];\n+\t\ttail[0] = '\\0';\n \t\t/* Check that we haven't hit a symlink. */\n-\t\tr = lstat(a->name, &st);\n+\t\tr = lstat(head, &st);\n \t\tif (r != 0) {\n+\t\t\ttail[0] = c;\n \t\t\t/* We've hit a dir that doesn't exist; stop now. */\n \t\t\tif (errno == ENOENT)\n \t\t\t\tbreak;\n+\t\t\t/* Treat any other error as fatal - best to be paranoid here */\n+\t\t\tif(error_number) *error_number = errno;\n+\t\t\tif(error_string)\n+\t\t\t\tarchive_string_sprintf(error_string,\n+\t\t\t\t\t\"Could not stat %s\",\n+\t\t\t\t\tpath);\n+\t\t\tres = (ARCHIVE_FATAL);\n+\t\t\tbreak;\n+\t\t} else if (S_ISDIR(st.st_mode)) {\n+\t\t\tif (!last) {\n+\t\t\t\tif (chdir(head) != 0) {\n+\t\t\t\t\ttail[0] = c;\n+\t\t\t\t\tif(error_number) *error_number = errno;\n+\t\t\t\t\tif(error_string)\n+\t\t\t\t\t\tarchive_string_sprintf(error_string,\n+\t\t\t\t\t\t\t\"Could not chdir %s\",\n+\t\t\t\t\t\t\tpath);\n+\t\t\t\t\tres = (ARCHIVE_FATAL);\n+\t\t\t\t\tbreak;\n+\t\t\t\t}\n+\t\t\t\t/* Our view is now from inside this dir: */\n+\t\t\t\thead = tail + 1;\n+\t\t\t}\n \t\t} else if (S_ISLNK(st.st_mode)) {\n-\t\t\tif (c == '\\0') {\n+\t\t\tif (last) {\n \t\t\t\t/*\n \t\t\t\t * Last element is symlink; remove it\n \t\t\t\t * so we can overwrite it with the\n \t\t\t\t * item being extracted.\n \t\t\t\t */\n-\t\t\t\tif (unlink(a->name)) {\n-\t\t\t\t\tarchive_set_error(&a->archive, errno,\n-\t\t\t\t\t \"Could not remove symlink %s\",\n-\t\t\t\t\t a->name);\n-\t\t\t\t\tpn[0] = c;\n-\t\t\t\t\treturn (ARCHIVE_FAILED);\n+\t\t\t\tif (unlink(head)) {\n+\t\t\t\t\ttail[0] = c;\n+\t\t\t\t\tif(error_number) *error_number = errno;\n+\t\t\t\t\tif(error_string)\n+\t\t\t\t\t\tarchive_string_sprintf(error_string,\n+\t\t\t\t\t\t\t\"Could not remove symlink %s\",\n+\t\t\t\t\t\t\tpath);\n+\t\t\t\t\tres = (ARCHIVE_FAILED);\n+\t\t\t\t\tbreak;\n \t\t\t\t}\n-\t\t\t\ta->pst = NULL;\n \t\t\t\t/*\n \t\t\t\t * Even if we did remove it, a warning\n \t\t\t\t * is in order. The warning is silly,\n \t\t\t\t * though, if we're just replacing one\n \t\t\t\t * symlink with another symlink.\n \t\t\t\t */\n+\t\t\t\ttail[0] = c;\n+\t\t\t\t/* FIXME: not sure how important this is to restore\n \t\t\t\tif (!S_ISLNK(a->mode)) {\n-\t\t\t\t\tarchive_set_error(&a->archive, 0,\n-\t\t\t\t\t \"Removing symlink %s\",\n-\t\t\t\t\t a->name);\n+\t\t\t\t\tif(error_numbe\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "Index: libarchive-3.1.2/libarchive/archive_write_disk_posix.c\n===================================================================\n--- libarchive-3.1.2.orig/libarchive/archive_write_disk_posix.c\n+++ libarchive-3.1.2/libarchive/archive_write_disk_posix.c\n@@ -326,12 +326,14 @@ struct archive_write_disk {\n \n #define HFS_BLOCKS(s)\t((s) >> 12)\n \n+static int\tcheck_symlinks_fsobj(char *path, int *error_number, struct archive_string *error_string, int flags);\n static int\tcheck_symlinks(struct archive_write_disk *);\n static int\tcreate_filesystem_object(struct archive_write_disk *);\n static struct fixup_entry *current_fixup(struct archive_write_disk *, const char *pathname);\n #if defined(HAVE_FCHDIR) && defined(PATH_MAX)\n static void\tedit_deep_directories(struct archive_write_disk *ad);\n #endif\n+static int\tcleanup_pathname_fsobj(char *path, int *error_number, struct archive_string *error_string, int flags);\n static int\tcleanup_pathname(struct archive_write_disk *);\n static int\tcreate_dir(struct archive_write_disk *, char *);\n static int\tcreate_parent_dir(struct archive_write_disk *, char *);\n@@ -1791,7 +1793,7 @@ edit_deep_directories(struct archive_wri\n \tchar *tail = a->name;\n \n \t/* If path is short, avoid the open() below. */\n-\tif (strlen(tail) <= PATH_MAX)\n+\tif (strlen(tail) < PATH_MAX)\n \t\treturn;\n \n \t/* Try to record our starting dir. */\n@@ -1801,7 +1803,7 @@ edit_deep_directories(struct archive_wri\n \t\treturn;\n \n \t/* As long as the path is too long... */\n-\twhile (strlen(tail) > PATH_MAX) {\n+\twhile (strlen(tail) >= PATH_MAX) {\n \t\t/* Locate a dir prefix shorter than PATH_MAX. */\n \t\ttail += PATH_MAX - 8;\n \t\twhile (tail > a->name && *tail != '/')\n@@ -1996,6 +1998,10 @@ create_filesystem_object(struct archive_\n \tconst char *linkname;\n \tmode_t final_mode, mode;\n \tint r;\n+\t/* these for check_symlinks_fsobj */\n+\tchar *linkname_copy;\t/* non-const copy of linkname */\n+\tstruct archive_string error_string;\n+\tint error_number;\n \n \t/* We identify hard/symlinks according to the link names. */\n \t/* Since link(2) and symlink(2) don't handle modes, we're done here. */\n@@ -2004,6 +2010,27 @@ create_filesystem_object(struct archive_\n #if !HAVE_LINK\n \t\treturn (EPERM);\n #else\n+\t\tarchive_string_init(&error_string);\n+\t\tlinkname_copy = strdup(linkname);\n+\t\tif (linkname_copy == NULL) {\n+\t\t return (EPERM);\n+\t\t}\n+\t\t/* TODO: consider using the cleaned-up path as the link target? */\n+\t\tr = cleanup_pathname_fsobj(linkname_copy, &error_number, &error_string, a->flags);\n+\t\tif (r != ARCHIVE_OK) {\n+\t\t\tarchive_set_error(&a->archive, error_number, \"%s\", error_string.s);\n+\t\t\tfree(linkname_copy);\n+\t\t\t/* EPERM is more appropriate than error_number for our callers */\n+\t\t\treturn (EPERM);\n+\t\t}\n+\t\tr = check_symlinks_fsobj(linkname_copy, &error_number, &error_string, a->flags);\n+\t\tif (r != ARCHIVE_OK) {\n+\t\t\tarchive_set_error(&a->archive, error_number, \"%s\", error_string.s);\n+\t\t\tfree(linkname_copy);\n+\t\t\t/* EPERM is more appropriate than error_number for our callers */\n+\t\t\treturn (EPERM);\n+\t\t}\n+\t\tfree(linkname_copy);\n \t\tr = link(linkname, a->name) ? errno : 0;\n \t\t/*\n \t\t * New cpio and pax formats allow hardlink entries\n@@ -2343,99 +2370,215 @@ current_fixup(struct archive_write_disk\n * recent paths.\n */\n /* TODO: Extend this to support symlinks on Windows Vista and later. */\n+\n+/*\n+ * Checks the given path to see if any elements along it are symlinks. Returns\n+ * ARCHIVE_OK if there are none, otherwise puts an error in errmsg.\n+ */\n static int\n-check_symlinks(struct archive_write_disk *a)\n+check_symlinks_fsobj(char *path, int *error_number, struct archive_string *error_string, int flags)\n {\n #if !defined(HAVE_LSTAT)\n \t/* Platform doesn't have lstat, so we can't look for symlinks. */\n-\t(void)a; /* UNUSED */\n+\t(void)path; /* UNUSED */\n+\t(void)error_number; /* UNUSED */\n+\t(void)error_string; /* UNUSED */\n+\t(void)flags; /* UNUSED */\n \treturn (ARCHIVE_OK);\n #else\n-\tchar *pn;\n+\tint res = ARCHIVE_OK;\n+\tchar *tail;\n+\tchar *head;\n+\tint last;\n \tchar c;\n \tint r;\n \tstruct stat st;\n+\tint restore_pwd;\n+\n+\t/* Nothing to do here if name is empty */\n+\tif(path[0] == '\\0')\n+\t return (ARCHIVE_OK);\n \n \t/*\n \t * Guard against symlink tricks. Reject any archive entry whose\n \t * destination would be altered by a symlink.\n-\t */\n-\t/* Whatever we checked last time doesn't need to be re-checked. */\n-\tpn = a->name;\n-\tif (archive_strlen(&(a->path_safe)) > 0) {\n-\t\tchar *p = a->path_safe.s;\n-\t\twhile ((*pn != '\\0') && (*p == *pn))\n-\t\t\t++p, ++pn;\n-\t}\n-\tc = pn[0];\n-\t/* Keep going until we've checked the entire name. */\n-\twhile (pn[0] != '\\0' && (pn[0] != '/' || pn[1] != '\\0')) {\n+\t *\n+\t * Walk the filename in chunks separated by '/'. For each segment:\n+\t * - if it doesn't exist, continue\n+\t * - if it's symlink, abort or remove it\n+\t * - if it's a directory and it's not the last chunk, cd into it\n+\t * As we go:\n+\t * head points to the current (relative) path\n+\t * tail points to the temporary \\0 terminating the segment we're currently examining\n+\t * c holds what used to be in *tail\n+\t * last is 1 if this is the last tail\n+\t */\n+\trestore_pwd = open(\".\", O_RDONLY | O_BINARY | O_CLOEXEC);\n+\t__archive_ensure_cloexec_flag(restore_pwd);\n+\tif (restore_pwd < 0)\n+\t\treturn (ARCHIVE_FATAL);\n+\thead = path;\n+\ttail = path;\n+\tlast = 0;\n+\n+\t/* TODO: reintroduce a safe cache here? */\n+\n+\t/* Keep going until we've checked the entire name.\n+\t * head, tail, path all alias the same string, which is\n+\t * temporarily zeroed at tail, so be careful restoring the\n+\t * stashed (c=tail[0]) for error messages.\n+\t * Exiting the loop with break is okay; continue is not.\n+\t */\n+\twhile (!last) {\n+\t\t/* Skip the separator we just consumed, plus any adjacent ones */\n+\t\twhile (*tail == '/')\n+\t\t ++tail;\n \t\t/* Skip the next path element. */\n-\t\twhile (*pn != '\\0' && *pn != '/')\n-\t\t\t++pn;\n-\t\tc = pn[0];\n-\t\tpn[0] = '\\0';\n+\t\twhile (*tail != '\\0' && *tail != '/')\n+\t\t\t++tail;\n+\t\t/* is this the last path component? */\n+\t\tlast = (tail[0] == '\\0') || (tail[0] == '/' && tail[1] == '\\0');\n+\t\t/* temporarily truncate the string here */\n+\t\tc = tail[0];\n+\t\ttail[0] = '\\0';\n \t\t/* Check that we haven't hit a symlink. */\n-\t\tr = lstat(a->name, &st);\n+\t\tr = lstat(head, &st);\n \t\tif (r != 0) {\n+\t\t\ttail[0] = c;\n \t\t\t/* We've hit a dir that doesn't exist; stop now. */\n \t\t\tif (errno == ENOENT)\n \t\t\t\tbreak;\n+\t\t\t/* Treat any other error as fatal - best to be paranoid here */\n+\t\t\tif(error_number) *error_number = errno;\n+\t\t\tif(error_string)\n+\t\t\t\tarchive_string_sprintf(error_string,\n+\t\t\t\t\t\"Could not stat %s\",\n+\t\t\t\t\tpath);\n+\t\t\tres = (ARCHIVE_FATAL);\n+\t\t\tbreak;\n+\t\t} else if (S_ISDIR(st.st_mode)) {\n+\t\t\tif (!last) {\n+\t\t\t\tif (chdir(head) != 0) {\n+\t\t\t\t\ttail[0] = c;\n+\t\t\t\t\tif(error_number) *error_number = errno;\n+\t\t\t\t\tif(error_string)\n+\t\t\t\t\t\tarchive_string_sprintf(error_string,\n+\t\t\t\t\t\t\t\"Could not chdir %s\",\n+\t\t\t\t\t\t\tpath);\n+\t\t\t\t\tres = (ARCHIVE_FATAL);\n+\t\t\t\t\tbreak;\n+\t\t\t\t}\n+\t\t\t\t/* Our view is now from inside this dir: */\n+\t\t\t\thead = tail + 1;\n+\t\t\t}\n \t\t} else if (S_ISLNK(st.st_mode)) {\n-\t\t\tif (c == '\\0') {\n+\t\t\tif (last) {\n \t\t\t\t/*\n \t\t\t\t * Last element is symlink; remove it\n \t\t\t\t * so we can overwrite it with the\n \t\t\t\t * item being extracted.\n \t\t\t\t */\n-\t\t\t\tif (unlink(a->name)) {\n-\t\t\t\t\tarchive_set_error(&a->archive, errno,\n-\t\t\t\t\t \"Could not remove symlink %s\",\n-\t\t\t\t\t a->name);\n-\t\t\t\t\tpn[0] = c;\n-\t\t\t\t\treturn (ARCHIVE_FAILED);\n+\t\t\t\tif (unlink(head)) {\n+\t\t\t\t\ttail[0] = c;\n+\t\t\t\t\tif(error_number) *error_number = errno;\n+\t\t\t\t\tif(error_string)\n+\t\t\t\t\t\tarchive_string_sprintf(error_string,\n+\t\t\t\t\t\t\t\"Could not remove symlink %s\",\n+\t\t\t\t\t\t\tpath);\n+\t\t\t\t\tres = (ARCHIVE_FAILED);\n+\t\t\t\t\tbreak;\n \t\t\t\t}\n-\t\t\t\ta->pst = NULL;\n \t\t\t\t/*\n \t\t\t\t * Even if we did remove it, a warning\n \t\t\t\t * is in order. The warning is silly,\n \t\t\t\t * though, if we're just replacing one\n \t\t\t\t * symlink with another symlink.\n \t\t\t\t */\n+\t\t\t\ttail[0] = c;\n+\t\t\t\t/* FIXME: not sure how important this is to restore\n \t\t\t\tif (!S_ISLNK(a->mode)) {\n-\t\t\t\t\tarchive_set_error(&a->archive, 0,\n-\t\t\t\t\t \"Removing symlink %s\",\n-\t\t\t\t\t a->name);\n+\t\t\t\t\tif(error_number) *error_number = 0;\n+\t\t\t\t\tif(error_string)\n+\t\t\t\t\t\tarchive_string_sprintf(error_string,\n+\t\t\t\t\t\t\t\"Removing symlink %s\",\n+\t\t\t\t\t\t\tpath);\n \t\t\t\t}\n+\t\t\t\t*/\n \t\t\t\t/* Symlink gone. No more problem! */\n-\t\t\t\tpn[0] = c;\n-\t\t\t\treturn (0);\n-\t\t\t} else if (a->flags & ARCHIVE_EXTRACT_UNLINK) {\n+\t\t\t\tres = (ARCHIVE_OK);\n+\t\t\t\tbreak;\n+\t\t\t} else if (flags & ARCHIVE_EXTRACT_UNLINK) {\n \t\t\t\t/* User asked us to remove problems. */\n-\t\t\t\tif (unlink(a->name) != 0) {\n-\t\t\t\t\tarchive_set_error(&a->archive, 0,\n-\t\t\t\t\t \"Cannot remove intervening symlink %s\",\n-\t\t\t\t\t a->name);\n-\t\t\t\t\tpn[0] = c;\n-\t\t\t\t\treturn (ARCHIVE_FAILED);\n+\t\t\t\tif (unlink(head) != 0) {\n+\t\t\t\t\ttail[0] = c;\n+\t\t\t\t\tif(error_number) *error_number = 0;\n+\t\t\t\t\tif(error_string)\n+\t\t\t\t\t\tarchive_string_sprintf(error_string,\n+\t\t\t\t\t\t\t\"Cannot remove intervening symlink %s\",\n+\t\t\t\t\t\t\tpath);\n+\t\t\t\t\tres = (ARCHIVE_FAILED);\n+\t\t\t\t\tbreak;\n \t\t\t\t}\n-\t\t\t\ta->pst = NULL;\n \t\t\t} else {\n-\t\t\t\tarchive_set_error(&a->archive, 0,\n-\t\t\t\t \"Cannot extract through symlink %s\",\n-\t\t\t\t a->name);\n-\t\t\t\tpn[0] = c;\n-\t\t\t\treturn (ARCHIVE_FAILED);\n+\t\t\t\ttail[0] = c;\n+\t\t\t\tif(error_number) *error_number = 0;\n+\t\t\t\tif(error_string)\n+\t\t\t\t\tarchive_string_sprintf(error_string,\n+\t\t\t\t\t\t\"Cannot extract through symlink %s\",\n+\t\t\t\t\t\tpath);\n+\t\t\t\tres = (ARCHIVE_FAILED);\n+\t\t\t\tbreak;\n \t\t\t}\n \t\t}\n+\t\t/* be sure to always maintain this */\n+\t\ttail[0] = c;\n \t}\n-\tpn[0] = c;\n-\t/* We've checked and/or cleaned the whole path, so remember it. */\n-\tarchive_strcpy(&a->path_safe, a->name);\n-\treturn (ARCHIVE_OK);\n+\t/* Catches loop exits via break */\n+\ttail[0] = c;\n+#ifdef HAVE_FCHDIR\n+\t/* If we changed directory above, restore it here. */\n+\tif (restore_pwd >= 0) {\n+\t\tr = fchdir(restore_pwd);\n+\t\tif (r != 0) {\n+\t\t\tif(error_number) *error_number = 0;\n+\t\t\tif(error_string)\n+\t\t\t\tarchive_string_sprintf(error_string,\n+\t\t\t\t\t\"Cannot extract through symlink %s\",\n+\t\t\t\t\tpath);\n+\t\t}\n+\t\tclose(restore_pwd);\n+\t\trestore_pwd = -1;\n+\t\tif (r != 0) {\n+\t\t\tres = (ARCHIVE_FATAL);\n+\t\t}\n+\t}\n+#endif\n+\t/* TODO: reintroduce a safe cache here? */\n+\treturn res;\n #endif\n }\n \n+/*\n+ * Check a->name for symlinks, returning ARCHIVE_OK if its clean, otherwise\n+ * calls archive_set_error and returns ARCHIVE_{FATAL,FAILED}\n+ */\n+static int\n+check_symlinks(struct archive_write_disk *a)\n+{\n+\tstruct archive_string error_string;\n+\tint error_number;\n+\tint rc;\n+\tarchive_string_init(&error_string);\n+\trc = check_symlinks_fsobj(a->name, &error_number, &error_string, a->flags);\n+\tif (rc != ARCHIVE_OK) {\n+\t\tarchive_set_error(&a->archive, error_number, \"%s\", error_string.s);\n+\t}\n+\tarchive_string_free(&error_string);\n+\ta->pst = NULL;\t/* to be safe */\n+\treturn rc;\n+}\n+\n+\n #if defined(__CYGWIN__)\n /*\n * 1. Convert a path separator from '\\' to '/' .\n@@ -2509,15 +2652,17 @@ cleanup_pathname_win(struct archive_writ\n * is set) if the path is absolute.\n */\n static int\n-cleanup_pathname(struct archive_write_disk *a)\n+cleanup_pathname_fsobj(char *path, int *error_number, struct archive_string *error_string, int flags)\n {\n \tchar *dest, *src;\n \tchar separator = '\\0';\n \n-\tdest = src = a->name;\n+\tdest = src = path;\n \tif (*src == '\\0') {\n-\t\tarchive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,\n-\t\t \"Invalid empty pathname\");\n+\t\tif (error_number) *error_number = ARCHIVE_ERRNO_MISC;\n+\t\tif (error_string)\n+\t\t\tarchive_string_sprintf(error_string,\n+\t\t\t\t\"Invalid empty pathname\");\n \t\treturn (ARCHIVE_FAILED);\n \t}\n \n@@ -2555,10 +2700,11 @@ cleanup_pathname(struct archive_write_di\n \t\t\t} else if (src[1] == '.') {\n \t\t\t\tif (src[2] == '/' || src[2] == '\\0') {\n \t\t\t\t\t/* Conditionally warn about '..' */\n-\t\t\t\t\tif (a->flags & ARCHIVE_EXTRACT_SECURE_NODOTDOT) {\n-\t\t\t\t\t\tarchive_set_error(&a->archive,\n-\t\t\t\t\t\t ARCHIVE_ERRNO_MISC,\n-\t\t\t\t\t\t \"Path contains '..'\");\n+\t\t\t\t\tif (flags & ARCHIVE_EXTRACT_SECURE_NODOTDOT) {\n+\t\t\t\t\t\tif (error_number) *error_number = ARCHIVE_ERRNO_MISC;\n+\t\t\t\t\t\tif (error_string)\n+\t\t\t\t\t\t\tarchive_string_sprintf(error_string,\n+\t\t\t\t\t\t\t\t\"Path contains '..'\");\n \t\t\t\t\t\treturn (ARCHIVE_FAILED);\n \t\t\t\t\t}\n \t\t\t\t}\n@@ -2589,7 +2735,7 @@ cleanup_pathname(struct archive_write_di\n \t * We've just copied zero or more path elements, not including the\n \t * final '/'.\n \t */\n-\tif (dest == a->name) {\n+\tif (dest == path) {\n \t\t/*\n \t\t * Nothing got copied. The path must have been something\n \t\t * like '.' or '/' or './' or '/././././/./'.\n@@ -2604,6 +2750,21 @@ cleanup_pathname(struct archive_write_di\n \treturn (ARCHIVE_OK);\n }\n \n+static int\n+cleanup_pathname(struct archive_write_disk *a)\n+{\n+\tstruct archive_string error_string;\n+\tint error_number;\n+\tint rc;\n+\tarchive_string_init(&error_string);\n+\trc = cleanup_pathname_fsobj(a->name, &error_number, &error_string, a->flags);\n+\tif (rc != ARCHIVE_OK) {\n+\t\tarchive_set_error(&a->archive, error_number, \"%s\", error_string.s);\n+\t}\n+\tarchive_string_free(&error_string);\n+\treturn rc;\n+}\n+\n /*\n * Create the parent directory of the specified path, assuming path\n * is already in mutable storage."}], "metadata": {"id": "libarchive-5942-CVE-2016-5418.patch", "cve_id": "CVE-2016-6250", "package": "libarchive", "tier": "adapted", "has_source_context": true, "context_tokens_est": 2640, "context_files": 1, "license": "BSD-2-Clause"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-9556\n\nThe IsPixelGray function in MagickCore/pixel-accessor.h in ImageMagick 7.0.3-8 allows remote attackers to cause a denial of service (out-of-bounds heap read) via a crafted image file.\n\n## Package\nGraphicsMagick\n\n## Files to modify\n- GraphicsMagick-1.3.18.orig/magick/utility.c\n- magick/tempfile.h\n- GraphicsMagick-1.3.18.orig/magick/tempfile.c\n- GraphicsMagick-1.3.18.orig/magick/symbols.h\n- magick/utility.h\n\n## Upstream Fix\n```diff\nIndex: GraphicsMagick-1.3.18/magick/delegate.c\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/delegate.c\n+++ GraphicsMagick-1.3.18/magick/delegate.c\n@@ -539,7 +539,10 @@ MagickExport unsigned int InvokeDelegate\n char\n *command,\n **commands,\n- filename[MaxTextExtent];\n+ linkedname[MaxTextExtent],\n+ linkedinfoname[MaxTextExtent],\n+ filename[MaxTextExtent],\n+ safechars[]=\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,-_+ /\";\n \n const DelegateInfo\n *delegate_info;\n@@ -559,6 +562,10 @@ MagickExport unsigned int InvokeDelegate\n assert(image != (Image *) NULL);\n assert(image->signature == MagickSignature);\n temporary_image_filename=(*image->filename == '\\0');\n+ linkedname[0]='\\0';\n+ linkedname[MaxTextExtent-1]='\\0';\n+ linkedinfoname[0]='\\0';\n+ linkedinfoname[MaxTextExtent-1]='\\0';\n if (temporary_image_filename)\n {\n /* Allocate a temporary filename if image is unnamed. */\n@@ -568,12 +575,24 @@ MagickExport unsigned int InvokeDelegate\n return(False);\n }\n }\n+ else if (strspn(image->filename, safechars) != strlen(image->filename))\n+ {\n+ strncpy(linkedname,image->filename,MaxTextExtent-1);\n+ if (!AcquireTemporarySymlink(image->filename,linkedname))\n+\t{\n+ (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image->filename);\n+\t return (False);\n+\t}\n+ }\n+\n (void) strlcpy(filename,image->filename,MaxTextExtent);\n delegate_info=GetDelegateInfo(decode,encode,exception);\n if (delegate_info == (DelegateInfo *) NULL)\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+ if (*linkedname)\n+\tstrncpy(image->filename,linkedname,MaxTextExtent-1);\n (void) ThrowException(exception,DelegateError,NoTagFound,\n decode ? decode : encode);\n return(False);\n@@ -594,6 +613,18 @@ MagickExport unsigned int InvokeDelegate\n }\n image_info->temporary=True;\n }\n+ else if (strspn(image_info->filename, safechars) != strlen(image_info->filename))\n+ {\n+ strncpy(linkedinfoname,image_info->filename,MaxTextExtent-1);\n+ if (!AcquireTemporarySymlink(image_info->filename,linkedinfoname))\n+\t{\n+ if (temporary_image_filename)\n+ LiberateTemporaryFile(image->filename);\n+ (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->filename);\n+ return(False);\n+ }\n+ temporary_image_filename=True;\n+ }\n \n if (delegate_info->mode != 0)\n if ((decode && (delegate_info->encode != (char *) NULL)) ||\n@@ -617,6 +648,13 @@ MagickExport unsigned int InvokeDelegate\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->unique);\n return(False);\n }\n@@ -625,6 +663,13 @@ MagickExport unsigned int InvokeDelegate\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n (void) LiberateTemporaryFile(image_info->unique);\n (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->zero);\n return(False);\n@@ -638,6 +683,13 @@ MagickExport unsigned int InvokeDelegate\n (void) LiberateTemporaryFile(image_info->zero);\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n (void) ThrowException(exception,DelegateError,DelegateFailed,\n decode ? decode : encode);\n return(False);\n@@ -663,6 +715,13 @@ MagickExport unsigned int InvokeDelegate\n (void) LiberateTemporaryFile(image_info->zero);\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n DestroyImageInfo(clone_info);\n (void) ThrowException(exception,DelegateError,DelegateFailed,\n decode ? decode : encode);\n@@ -684,6 +743,13 @@ MagickExport unsigned int InvokeDelegate\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+ if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+ if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+ }\n (void) ThrowException(exception,ResourceLimitError,MemoryAllocationFailed,decode ? decode : encode);\n return(False);\n }\n@@ -810,6 +876,13 @@ MagickExport unsigned int InvokeDelegate\n error_exit:\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+ if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+ if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+ }\n for ( ; commands[i] != (char *) NULL; i++)\n MagickFreeMemory(commands[i]);\n MagickFreeMemory(commands);\nIndex: GraphicsMagick-1.3.18/magick/symbols.h\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/symbols.h\n+++ GraphicsMagick-1.3.18/magick/symbols.h\n@@ -43,6 +43,7 @@\n #define AcquireTemporaryFileDescriptor GmAcquireTemporaryFileDescriptor\n #define AcquireTemporaryFileName GmAcquireTemporaryFileName\n #define AcquireTemporaryFileStream GmAcquireTemporaryFileStream\n+#define AcquireTemporarySymlink GmAcquireTemporarySymlink\n #define AdaptiveThresholdImage GmAdaptiveThresholdImage\n #define AddDefinition GmAddDefinition\n #define AddDefinitions GmAddDefinitions\nIndex: GraphicsMagick-1.3.18/magick/tempfile.c\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/tempfile.c\n+++ GraphicsMagick-1.3.18/magick/tempfile.c\n@@ -192,6 +192,93 @@ MagickExport MagickPassFail AcquireTempo\n % %\n % %\n % %\n++ A c q u i r e T e m p o r a r y S y m l i n k %\n+% %\n+% %\n+% %\n+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n+%\n+% AcquireTemporarySymlink replaces the contents of the string buffer pointed\n+% to by filename with the unique name of a symbolic link. True is returned\n+% if a symlink\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "Index: GraphicsMagick-1.3.18/magick/delegate.c\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/delegate.c\n+++ GraphicsMagick-1.3.18/magick/delegate.c\n@@ -539,7 +539,10 @@ MagickExport unsigned int InvokeDelegate\n char\n *command,\n **commands,\n- filename[MaxTextExtent];\n+ linkedname[MaxTextExtent],\n+ linkedinfoname[MaxTextExtent],\n+ filename[MaxTextExtent],\n+ safechars[]=\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,-_+ /\";\n \n const DelegateInfo\n *delegate_info;\n@@ -559,6 +562,10 @@ MagickExport unsigned int InvokeDelegate\n assert(image != (Image *) NULL);\n assert(image->signature == MagickSignature);\n temporary_image_filename=(*image->filename == '\\0');\n+ linkedname[0]='\\0';\n+ linkedname[MaxTextExtent-1]='\\0';\n+ linkedinfoname[0]='\\0';\n+ linkedinfoname[MaxTextExtent-1]='\\0';\n if (temporary_image_filename)\n {\n /* Allocate a temporary filename if image is unnamed. */\n@@ -568,12 +575,24 @@ MagickExport unsigned int InvokeDelegate\n return(False);\n }\n }\n+ else if (strspn(image->filename, safechars) != strlen(image->filename))\n+ {\n+ strncpy(linkedname,image->filename,MaxTextExtent-1);\n+ if (!AcquireTemporarySymlink(image->filename,linkedname))\n+\t{\n+ (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image->filename);\n+\t return (False);\n+\t}\n+ }\n+\n (void) strlcpy(filename,image->filename,MaxTextExtent);\n delegate_info=GetDelegateInfo(decode,encode,exception);\n if (delegate_info == (DelegateInfo *) NULL)\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+ if (*linkedname)\n+\tstrncpy(image->filename,linkedname,MaxTextExtent-1);\n (void) ThrowException(exception,DelegateError,NoTagFound,\n decode ? decode : encode);\n return(False);\n@@ -594,6 +613,18 @@ MagickExport unsigned int InvokeDelegate\n }\n image_info->temporary=True;\n }\n+ else if (strspn(image_info->filename, safechars) != strlen(image_info->filename))\n+ {\n+ strncpy(linkedinfoname,image_info->filename,MaxTextExtent-1);\n+ if (!AcquireTemporarySymlink(image_info->filename,linkedinfoname))\n+\t{\n+ if (temporary_image_filename)\n+ LiberateTemporaryFile(image->filename);\n+ (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->filename);\n+ return(False);\n+ }\n+ temporary_image_filename=True;\n+ }\n \n if (delegate_info->mode != 0)\n if ((decode && (delegate_info->encode != (char *) NULL)) ||\n@@ -617,6 +648,13 @@ MagickExport unsigned int InvokeDelegate\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->unique);\n return(False);\n }\n@@ -625,6 +663,13 @@ MagickExport unsigned int InvokeDelegate\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n (void) LiberateTemporaryFile(image_info->unique);\n (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->zero);\n return(False);\n@@ -638,6 +683,13 @@ MagickExport unsigned int InvokeDelegate\n (void) LiberateTemporaryFile(image_info->zero);\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n (void) ThrowException(exception,DelegateError,DelegateFailed,\n decode ? decode : encode);\n return(False);\n@@ -663,6 +715,13 @@ MagickExport unsigned int InvokeDelegate\n (void) LiberateTemporaryFile(image_info->zero);\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+\t if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+\t if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+\t }\n DestroyImageInfo(clone_info);\n (void) ThrowException(exception,DelegateError,DelegateFailed,\n decode ? decode : encode);\n@@ -684,6 +743,13 @@ MagickExport unsigned int InvokeDelegate\n {\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+ if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+ if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+ }\n (void) ThrowException(exception,ResourceLimitError,MemoryAllocationFailed,decode ? decode : encode);\n return(False);\n }\n@@ -810,6 +876,13 @@ MagickExport unsigned int InvokeDelegate\n error_exit:\n if (temporary_image_filename)\n (void) LiberateTemporaryFile(image->filename);\n+ if (*linkedname)\n+ strncpy(image->filename,linkedname,MaxTextExtent-1);\n+ if (*linkedinfoname)\n+ {\n+ LiberateTemporaryFile(linkedinfoname);\n+ strncpy(image_info->filename,linkedinfoname,MaxTextExtent-1);\n+ }\n for ( ; commands[i] != (char *) NULL; i++)\n MagickFreeMemory(commands[i]);\n MagickFreeMemory(commands);\nIndex: GraphicsMagick-1.3.18/magick/symbols.h\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/symbols.h\n+++ GraphicsMagick-1.3.18/magick/symbols.h\n@@ -43,6 +43,7 @@\n #define AcquireTemporaryFileDescriptor GmAcquireTemporaryFileDescriptor\n #define AcquireTemporaryFileName GmAcquireTemporaryFileName\n #define AcquireTemporaryFileStream GmAcquireTemporaryFileStream\n+#define AcquireTemporarySymlink GmAcquireTemporarySymlink\n #define AdaptiveThresholdImage GmAdaptiveThresholdImage\n #define AddDefinition GmAddDefinition\n #define AddDefinitions GmAddDefinitions\nIndex: GraphicsMagick-1.3.18/magick/tempfile.c\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/tempfile.c\n+++ GraphicsMagick-1.3.18/magick/tempfile.c\n@@ -192,6 +192,93 @@ MagickExport MagickPassFail AcquireTempo\n % %\n % %\n % %\n++ A c q u i r e T e m p o r a r y S y m l i n k %\n+% %\n+% %\n+% %\n+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n+%\n+% AcquireTemporarySymlink replaces the contents of the string buffer pointed\n+% to by filename with the unique name of a symbolic link. True is returned\n+% if a symlink waas created, or False is returned if there is a failure.\n+% The allocated symlink should be recovered via the LiberateTemporaryFile()\n+% function once it is no longer required.\n+%\n+% The format of the AcquireTemporarySymlink method is:\n+%\n+% unsigned int AcquireTemporarySymlink(char *linkname, const char *name,\n+% ExceptionInfo *exception)\n+%\n+% A description of each parameter follows.\n+%\n+% o linkname: Specifies a pointer to an array of characters that must be\n+% MaxTextExtent characters of size. The unique\n+% name of the symlink is returned in this array.\n+% o name: Specifies a file name the symlink should point to.\n+*/\n+MagickExport unsigned int AcquireTemporarySymlink(char *linkname, const char *name)\n+{\n+ char\n+ *tempdir,\n+ tempname[MaxTextExtent];\n+\n+ int\n+ fd,\n+ tries;\n+ \n+ assert(linkname != (char *)NULL);\n+ linkname[0]='\\0';\n+ tempname[MaxTextExtent-1]='\\0';\n+\n+ tempdir=getenv(\"MAGICK_TMPDIR\");\n+#if defined(POSIX)\n+ if (!tempdir)\n+ tempdir=getenv(\"TMPDIR\");\n+#endif /* POSIX */\n+#if defined(WIN32)\n+ if (!tempdir)\n+ tempdir=getenv(\"TMP\");\n+ if (!tempdir)\n+ tempdir=getenv(\"TEMP\");\n+#endif /* WIN32 */\n+#if defined(P_tmpdir)\n+ if (!tempdir)\n+ tempdir=P_tmpdir;\n+#endif\n+\n+ for (tries=0; tries < 15; tries++)\n+ {\n+ strncpy(tempname,\"gmXXXXXX\",MaxTextExtent-1);\n+ ComposeTemporaryFileName(tempname);\n+ strncpy(linkname,tempdir,MaxTextExtent-1);\n+ if (tempdir[strlen(tempdir)-1] != DirectorySeparator[0])\n+\tstrncat(linkname,DirectorySeparator,MaxTextExtent-1);\n+ strncat(linkname,tempname,MaxTextExtent-1);\n+ if (*name == '/')\n+ fd=symlink(name, linkname);\n+ else\n+ {\n+ char cname[MaxTextExtent];\n+\t if (!getcwd(cname,(size_t)MaxTextExtent))\n+\t return (False);\n+\t strncat(cname,DirectorySeparator,MaxTextExtent-1);\n+\t strncat(cname,name,MaxTextExtent-1);\n+\t fd=symlink(cname,linkname);\n+\t}\n+ if (fd != -1)\n+\t{\n+\t AddTemporaryFileToList(linkname);\n+\t return (True);\n+\t}\n+ }\n+ return (False);\n+}\n+\f\n+/*\n+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n+% %\n+% %\n+% %\n + A c q u i r e T e m p o r a r y F i l e D e s c r i p t o r %\n % %\n % %\nIndex: GraphicsMagick-1.3.18/magick/tempfile.h\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/tempfile.h\n+++ GraphicsMagick-1.3.18/magick/tempfile.h\n@@ -24,6 +24,7 @@ typedef enum\n \n MagickExport MagickPassFail\n AcquireTemporaryFileName(char *filename),\n+ AcquireTemporarySymlink(char *linkname, const char *name),\n LiberateTemporaryFile(char *filename);\n \n MagickExport int\nIndex: GraphicsMagick-1.3.18/magick/utility.c\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/utility.c\n+++ GraphicsMagick-1.3.18/magick/utility.c\n@@ -1253,6 +1253,72 @@ MagickExport void FormatString(char *str\n % %\n % %\n % %\n+% F o r m a t S t r i n g N u m e r i c %\n+% %\n+% %\n+% %\n+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n+%\n+% Method FormatStringNumeric formats output for a single numeric argument.\n+% It takes into account that the format string given might be untrusted\n+% user input, and returns a pointer to the formatted string.\n+%\n+% The format of the FormatStringNumeric method is:\n+%\n+% char * FormatStringNumeric(char *string,const char *format,int value)\n+%\n+% A description of each parameter follows.\n+%\n+% o format: A string describing the format to use to write the numeric\n+% argument. Only the first numeric format identifier is replaced.\n+%\n+% o value: Numeric value to substitute into format string.\n+%\n+%\n+*/\n+MagickExport char *FormatStringNumeric(const char *format,int value)\n+{\n+ char\n+ *p,\n+ *string;\n+\n+ string = NULL;\n+\n+ (void) CloneString(&string, format);\n+\n+ for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))\n+ { \n+ char\n+ *q;\n+\n+ q=(char *) p+1;\n+ if (*q == '0')\n+ (void) strtol(q,&q,10);\n+ if ((*q == '%') || (*q == 'd') || (*q == 'o') || (*q == 'x'))\n+ {\n+ char\n+ c;\n+\n+ q++;\n+ c=*q;\n+ *q='\\0';\n+ (void) snprintf(string+(p-format),MaxTextExtent-(p-format),p,value);\n+ *q=c;\n+ (void) ConcatenateString(&string,q);\n+ if (*(q-1) == '%')\n+ p++;\n+ else\n+ break;\n+ }\n+ }\n+ return string;\n+}\n+\f\n+/*\n+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n+% %\n+% %\n+% %\n % G e t E x e c u t i o n P a t h %\n % %\n % %\nIndex: GraphicsMagick-1.3.18/magick/utility.h\n===================================================================\n--- GraphicsMagick-1.3.18.orig/magick/utility.h\n+++ GraphicsMagick-1.3.18/magick/utility.h\n@@ -72,6 +72,7 @@ extern MagickExport char\n *AllocateString(const char *),\n *Base64Encode(const unsigned char *,const size_t,size_t *),\n *EscapeString(const char *,const char),\n+ *FormatStringNumeric(const char *,int),\n *GetPageGeometry(const char *),\n **ListFiles(const char *,const char *,long *),\n **StringToArgv(const char *,int *),"}], "metadata": {"id": "GraphicsMagick-5956-GraphicsMagick-debian-fixed.pa", "cve_id": "CVE-2016-9556", "package": "GraphicsMagick", "tier": "adapted", "has_source_context": false, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3455\n\nSquid 3.2.x before 3.2.14, 3.3.x before 3.3.14, 3.4.x before 3.4.13, and 3.5.x before 3.5.4, when configured with client-first SSL-bump, do not properly validate the domain or hostname fields of X.509 certificates, which allows man-in-the-middle attackers to spoof SSL servers via a valid certificate.\n\n## Package\nsquid\n\n## Upstream Fix\n```diff\n------------------------------------------------------------\nrevno: 12697\nrevision-id: squid3@treenet.co.nz-20160420111636-ft1dbd1iuktj8ift\nparent: squid3@treenet.co.nz-20160420101500-nm50i4u3iftemzs6\ncommitter: Amos Jeffries \nbranch nick: 3.3\ntimestamp: Wed 2016-04-20 23:16:36 +1200\nmessage:\n Fix several ESI element construction issues\n \n * Do not wrap active logic in assert().\n \n * Fix localbuf array bounds checking.\n \n * Add Must() conditions to verify array writes will succeed\n------------------------------------------------------------\n# Bazaar merge directive format 2 (Bazaar 0.90)\n# revision_id: squid3@treenet.co.nz-20160420111636-ft1dbd1iuktj8ift\n# target_branch: http://bzr.squid-cache.org/bzr/squid3/3.3\n# testament_sha1: 51aac9164cc49f99fb4332cec62403e3500433fd\n# timestamp: 2016-04-20 11:21:10 +0000\n# source_branch: http://bzr.squid-cache.org/bzr/squid3/3.3\n# base_revision_id: squid3@treenet.co.nz-20160420101500-\\\n# nm50i4u3iftemzs6\n# \n# Begin patch\n=== modified file 'src/esi/Esi.cc'\n--- src/esi/Esi.cc\t2013-01-02 03:44:55 +0000\n+++ src/esi/Esi.cc\t2016-04-20 11:16:36 +0000\n@@ -1007,7 +1007,7 @@\n ESIElement::Pointer element;\n int specifiedattcount = attrCount * 2;\n char *position;\n- assert (ellen < sizeof (localbuf)); /* prevent unexpected overruns. */\n+ Must(ellen < sizeof(localbuf)); /* prevent unexpected overruns. */\n \n debugs(86, 5, \"ESIContext::Start: element '\" << el << \"' with \" << specifiedattcount << \" tags\");\n \n@@ -1021,15 +1021,17 @@\n /* Spit out elements we aren't interested in */\n localbuf[0] = '<';\n localbuf[1] = '\\0';\n- assert (xstrncpy (&localbuf[1], el, sizeof(localbuf) - 2));\n+ xstrncpy(&localbuf[1], el, sizeof(localbuf) - 2);\n position = localbuf + strlen (localbuf);\n \n for (i = 0; i < specifiedattcount && attr[i]; i += 2) {\n+ Must(static_cast(position - localbuf) < sizeof(localbuf) - 1);\n *position = ' ';\n ++position;\n /* TODO: handle thisNode gracefully */\n- assert (xstrncpy (position, attr[i], sizeof(localbuf) + (position - localbuf)));\n+ xstrncpy(position, attr[i], sizeof(localbuf) - (position - localbuf));\n position += strlen (position);\n+ Must(static_cast(position - localbuf) < sizeof(localbuf) - 2);\n *position = '=';\n ++position;\n *position = '\\\"';\n@@ -1038,18 +1040,21 @@\n char ch;\n while ((ch = *chPtr++) != '\\0') {\n if (ch == '\\\"') {\n- assert( xstrncpy(position, \""\", sizeof(localbuf) + (position-localbuf)) );\n+ Must(static_cast(position - localbuf) < sizeof(localbuf) - 6);\n+ xstrncpy(position, \""\", sizeof(localbuf) - (position-localbuf));\n position += 6;\n } else {\n+ Must(static_cast(position - localbuf) < sizeof(localbuf) - 1);\n *position = ch;\n ++position;\n }\n }\n- position += strlen (position);\n+ Must(static_cast(position - localbuf) < sizeof(localbuf) - 1);\n *position = '\\\"';\n ++position;\n }\n \n+ Must(static_cast(position - localbuf) < sizeof(localbuf) - 2);\n *position = '>';\n ++position;\n *position = '\\0';\n@@ -1135,11 +1140,11 @@\n switch (ESIElement::IdentifyElement (el)) {\n \n case ESIElement::ESI_ELEMENT_NONE:\n- assert (ellen < sizeof (localbuf)); /* prevent unexpected overruns. */\n+ Must(ellen < sizeof(localbuf) - 3); /* prevent unexpected overruns. */\n /* Add elements we aren't interested in */\n localbuf[0] = '<';\n localbuf[1] = '/';\n- assert (xstrncpy (&localbuf[2], el, sizeof(localbuf) - 3));\n+ xstrncpy(&localbuf[2], el, sizeof(localbuf) - 3);\n position = localbuf + strlen (localbuf);\n *position = '>';\n ++position;\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "------------------------------------------------------------\nrevno: 12697\nrevision-id: squid3@treenet.co.nz-20160420111636-ft1dbd1iuktj8ift\nparent: squid3@treenet.co.nz-20160420101500-nm50i4u3iftemzs6\ncommitter: Amos Jeffries \nbranch nick: 3.3\ntimestamp: Wed 2016-04-20 23:16:36 +1200\nmessage:\n Fix several ESI element construction issues\n \n * Do not wrap active logic in assert().\n \n * Fix localbuf array bounds checking.\n \n * Add Must() conditions to verify array writes will succeed\n------------------------------------------------------------\n# Bazaar merge directive format 2 (Bazaar 0.90)\n# revision_id: squid3@treenet.co.nz-20160420111636-ft1dbd1iuktj8ift\n# target_branch: http://bzr.squid-cache.org/bzr/squid3/3.3\n# testament_sha1: 51aac9164cc49f99fb4332cec62403e3500433fd\n# timestamp: 2016-04-20 11:21:10 +0000\n# source_branch: http://bzr.squid-cache.org/bzr/squid3/3.3\n# base_revision_id: squid3@treenet.co.nz-20160420101500-\\\n# nm50i4u3iftemzs6\n# \n# Begin patch\n=== modified file 'src/esi/Esi.cc'\n--- src/esi/Esi.cc\t2013-01-02 03:44:55 +0000\n+++ src/esi/Esi.cc\t2016-04-20 11:16:36 +0000\n@@ -1007,7 +1007,7 @@\n ESIElement::Pointer element;\n int specifiedattcount = attrCount * 2;\n char *position;\n- assert (ellen < sizeof (localbuf)); /* prevent unexpected overruns. */\n+ Must(ellen < sizeof(localbuf)); /* prevent unexpected overruns. */\n \n debugs(86, 5, \"ESIContext::Start: element '\" << el << \"' with \" << specifiedattcount << \" tags\");\n \n@@ -1021,15 +1021,17 @@\n /* Spit out elements we aren't interested in */\n localbuf[0] = '<';\n localbuf[1] = '\\0';\n- assert (xstrncpy (&localbuf[1], el, sizeof(localbuf) - 2));\n+ xstrncpy(&localbuf[1], el, sizeof(localbuf) - 2);\n position = localbuf + strlen (localbuf);\n \n for (i = 0; i < specifiedattcount && attr[i]; i += 2) {\n+ Must(static_cast(position - localbuf) < sizeof(localbuf) - 1);\n *position = ' ';\n ++position;\n /* TODO: handle thisNode gracefully */\n- assert (xstrncpy (position, attr[i], sizeof(localbuf) + (position - localbuf)));\n+ xstrncpy(position, attr[i], sizeof(localbuf) - (position - localbuf));\n position += strlen (position);\n+ Must(static_cast(position - localbuf) < sizeof(localbuf) - 2);\n *position = '=';\n ++position;\n *position = '\\\"';\n@@ -1038,18 +1040,21 @@\n char ch;\n while ((ch = *chPtr++) != '\\0') {\n if (ch == '\\\"') {\n- assert( xstrncpy(position, \""\", sizeof(localbuf) + (position-localbuf)) );\n+ Must(static_cast(position - localbuf) < sizeof(localbuf) - 6);\n+ xstrncpy(position, \""\", sizeof(localbuf) - (position-localbuf));\n position += 6;\n } else {\n+ Must(static_cast(position - localbuf) < sizeof(localbuf) - 1);\n *position = ch;\n ++position;\n }\n }\n- position += strlen (position);\n+ Must(static_cast(position - localbuf) < sizeof(localbuf) - 1);\n *position = '\\\"';\n ++position;\n }\n \n+ Must(static_cast(position - localbuf) < sizeof(localbuf) - 2);\n *position = '>';\n ++position;\n *position = '\\0';\n@@ -1135,11 +1140,11 @@\n switch (ESIElement::IdentifyElement (el)) {\n \n case ESIElement::ESI_ELEMENT_NONE:\n- assert (ellen < sizeof (localbuf)); /* prevent unexpected overruns. */\n+ Must(ellen < sizeof(localbuf) - 3); /* prevent unexpected overruns. */\n /* Add elements we aren't interested in */\n localbuf[0] = '<';\n localbuf[1] = '/';\n- assert (xstrncpy (&localbuf[2], el, sizeof(localbuf) - 3));\n+ xstrncpy(&localbuf[2], el, sizeof(localbuf) - 3);\n position = localbuf + strlen (localbuf);\n *position = '>';\n ++position;"}], "metadata": {"id": "squid-5473-SQUID_2016_6.patch", "cve_id": "CVE-2015-3455", "package": "squid", "tier": "identical", "has_source_context": false, "license": "GPL-2.0-or-later"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-4658\n\nxpointer.c in libxml2 before 2.9.5 (as used in Apple iOS before 10, OS X before 10.12, tvOS before 10, and watchOS before 3, and other products) does not forbid namespace nodes in XPointer ranges, which allows remote attackers to execute arbitrary code or cause a denial of service (use-after-free and memory corruption) via a crafted XML document.\n\n## Package\nlibxml2\n\n## Files to modify\n- xzlib.h\n- xmlIO.c\n- xzlib.c\n- parser.c\n\n## Target Source Code\n\n### parser.c\n\n#### xmlParseDocument() [lines 10642-7078]\n```c\n\n```\n\n### xzlib.h\n\n#### __libxml2_xzopen() [lines 1-19]\n```c\n/**\n * xzlib.h: header for the front end for the transparent suport of lzma\n * compression at the I/O layer\n *\n * See Copyright for the status of this software.\n *\n * Anders F Bjorklund \n */\n\n#ifndef LIBXML2_XZLIB_H\n#define LIBXML2_XZLIB_H\ntypedef void *xzFile; /* opaque lzma file descriptor */\n\nxzFile __libxml2_xzopen(const char *path, const char *mode);\nxzFile __libxml2_xzdopen(int fd, const char *mode);\nint __libxml2_xzread(xzFile file, void *buf, unsigned len);\nint __libxml2_xzclose(xzFile file);\n#endif /* LIBXML2_XZLIB_H */\n\n```\n\n\n## Upstream Fix\n```diff\nFrom 63588f476f2dc89d4c6ef70a474d7230fbf4d45e Mon Sep 17 00:00:00 2001\nFrom: Daniel Veillard \nDate: Fri, 10 May 2013 14:01:46 +0800\nSubject: [PATCH] Fix a regression in xmlGetDocCompressMode()\n\nThe switch to xzlib had for consequence that the compression\nlevel of the input was not gathered anymore in ctxt->input->buf,\nthen the parser compression flags was left to -1 and propagated\nto the resulting document.\nFix the I/O layer to get compression detection in xzlib,\nthen carry it in the input buffer and the resulting document\n\n This should fix\n https://lsbbugs.linuxfoundation.org/show_bug.cgi?id=3456\n---\n parser.c | 4 ++++\n xmlIO.c | 17 +++++++++++++++++\n xzlib.c | 25 +++++++++++++++++++++++++\n xzlib.h | 1 +\n 4 files changed, 47 insertions(+)\n\ndiff --git a/parser.c b/parser.c\nindex 1d478c3d47..4a442bb918 100644\n--- a/parser.c\n+++ b/parser.c\n@@ -10681,6 +10681,10 @@ xmlParseDocument(xmlParserCtxtPtr ctxt) {\n ctxt->sax->startDocument(ctxt->userData);\n if (ctxt->instate == XML_PARSER_EOF)\n \treturn(-1);\n+ if ((ctxt->myDoc != NULL) && (ctxt->input != NULL) &&\n+ (ctxt->input->buf != NULL) && (ctxt->input->buf->compressed >= 0)) {\n+\tctxt->myDoc->compression = ctxt->input->buf->compressed;\n+ }\n \n /*\n * The Misc part of the Prolog\ndiff --git a/xmlIO.c b/xmlIO.c\nindex 847cb7edbb..fc4e111050 100644\n--- a/xmlIO.c\n+++ b/xmlIO.c\n@@ -2668,6 +2668,12 @@ __xmlParserInputBufferCreateFilename(const char *URI, xmlCharEncoding enc) {\n \t }\n #endif\n \t}\n+#endif\n+#ifdef HAVE_LZMA_H\n+\tif ((xmlInputCallbackTable[i].opencallback == xmlXzfileOpen) &&\n+\t\t(strcmp(URI, \"-\") != 0)) {\n+ ret->compressed = __libxml2_xzcompressed(context);\n+\t}\n #endif\n }\n else\n@@ -3325,6 +3331,17 @@ xmlParserInputBufferGrow(xmlParserInputBufferPtr in, int len) {\n if (res < 0) {\n \treturn(-1);\n }\n+\n+ /*\n+ * try to establish compressed status of input if not done already\n+ */\n+ if (in->compressed == -1) {\n+#ifdef HAVE_LZMA_H\n+\tif (in->readcallback == xmlXzfileRead)\n+ in->compressed = __libxml2_xzcompressed(in->context);\n+#endif\n+ }\n+\n len = res;\n if (in->encoder != NULL) {\n unsigned int use;\ndiff --git a/xzlib.c b/xzlib.c\nindex 928bd17cb7..150e80332a 100644\n--- a/xzlib.c\n+++ b/xzlib.c\n@@ -182,12 +182,37 @@ xz_open(const char *path, int fd, const char *mode ATTRIBUTE_UNUSED)\n return (xzFile) state;\n }\n \n+static int\n+xz_compressed(xzFile f) {\n+ xz_statep state;\n+\n+ if (f == NULL)\n+ return(-1);\n+ state = (xz_statep) f;\n+ if (state->init <= 0)\n+ return(-1);\n+\n+ switch (state->how) {\n+ case COPY:\n+\t return(0);\n+\tcase GZIP:\n+\tcase LZMA:\n+\t return(1);\n+ }\n+ return(-1);\n+}\n+\n xzFile\n __libxml2_xzopen(const char *path, const char *mode)\n {\n return xz_open(path, -1, mode);\n }\n \n+int\n+__libxml2_xzcompressed(xzFile f) {\n+ return xz_compressed(f);\n+}\n+\n xzFile\n __libxml2_xzdopen(int fd, const char *mode)\n {\ndiff --git a/xzlib.h b/xzlib.h\nindex 43c75e185b..29ba55e740 100644\n--- a/xzlib.h\n+++ b/xzlib.h\n@@ -15,4 +15,5 @@ xzFile __libxml2_xzopen(const char *path, const char *mode);\n xzFile __libxml2_xzdopen(int fd, const char *mode);\n int __libxml2_xzread(xzFile file, void *buf, unsigned len);\n int __libxml2_xzclose(xzFile file);\n+int __libxml2_xzcompressed(xzFile f);\n #endif /* LIBXML2_XZLIB_H */\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From 63588f476f2dc89d4c6ef70a474d7230fbf4d45e Mon Sep 17 00:00:00 2001\nFrom: Daniel Veillard \nDate: Fri, 10 May 2013 14:01:46 +0800\nSubject: [PATCH] Fix a regression in xmlGetDocCompressMode()\n\nThe switch to xzlib had for consequence that the compression\nlevel of the input was not gathered anymore in ctxt->input->buf,\nthen the parser compression flags was left to -1 and propagated\nto the resulting document.\nFix the I/O layer to get compression detection in xzlib,\nthen carry it in the input buffer and the resulting document\n\n This should fix\n https://lsbbugs.linuxfoundation.org/show_bug.cgi?id=3456\n---\n parser.c | 4 ++++\n xmlIO.c | 17 +++++++++++++++++\n xzlib.c | 25 +++++++++++++++++++++++++\n xzlib.h | 1 +\n 4 files changed, 47 insertions(+)\n\ndiff --git a/parser.c b/parser.c\nindex 1d478c3..4a442bb 100644\n--- a/parser.c\n+++ b/parser.c\n@@ -10681,6 +10681,10 @@ xmlParseDocument(xmlParserCtxtPtr ctxt) {\n ctxt->sax->startDocument(ctxt->userData);\n if (ctxt->instate == XML_PARSER_EOF)\n \treturn(-1);\n+ if ((ctxt->myDoc != NULL) && (ctxt->input != NULL) &&\n+ (ctxt->input->buf != NULL) && (ctxt->input->buf->compressed >= 0)) {\n+\tctxt->myDoc->compression = ctxt->input->buf->compressed;\n+ }\n \n /*\n * The Misc part of the Prolog\ndiff --git a/xmlIO.c b/xmlIO.c\nindex 847cb7e..fc4e111 100644\n--- a/xmlIO.c\n+++ b/xmlIO.c\n@@ -2669,6 +2669,12 @@ __xmlParserInputBufferCreateFilename(const char *URI, xmlCharEncoding enc) {\n #endif\n \t}\n #endif\n+#ifdef HAVE_LZMA_H\n+\tif ((xmlInputCallbackTable[i].opencallback == xmlXzfileOpen) &&\n+\t\t(strcmp(URI, \"-\") != 0)) {\n+ ret->compressed = __libxml2_xzcompressed(context);\n+\t}\n+#endif\n }\n else\n xmlInputCallbackTable[i].closecallback (context);\n@@ -3325,6 +3331,17 @@ xmlParserInputBufferGrow(xmlParserInputBufferPtr in, int len) {\n if (res < 0) {\n \treturn(-1);\n }\n+\n+ /*\n+ * try to establish compressed status of input if not done already\n+ */\n+ if (in->compressed == -1) {\n+#ifdef HAVE_LZMA_H\n+\tif (in->readcallback == xmlXzfileRead)\n+ in->compressed = __libxml2_xzcompressed(in->context);\n+#endif\n+ }\n+\n len = res;\n if (in->encoder != NULL) {\n unsigned int use;\ndiff --git a/xzlib.c b/xzlib.c\nindex 928bd17..150e803 100644\n--- a/xzlib.c\n+++ b/xzlib.c\n@@ -182,12 +182,37 @@ xz_open(const char *path, int fd, const char *mode ATTRIBUTE_UNUSED)\n return (xzFile) state;\n }\n \n+static int\n+xz_compressed(xzFile f) {\n+ xz_statep state;\n+\n+ if (f == NULL)\n+ return(-1);\n+ state = (xz_statep) f;\n+ if (state->init <= 0)\n+ return(-1);\n+\n+ switch (state->how) {\n+ case COPY:\n+\t return(0);\n+\tcase GZIP:\n+\tcase LZMA:\n+\t return(1);\n+ }\n+ return(-1);\n+}\n+\n xzFile\n __libxml2_xzopen(const char *path, const char *mode)\n {\n return xz_open(path, -1, mode);\n }\n \n+int\n+__libxml2_xzcompressed(xzFile f) {\n+ return xz_compressed(f);\n+}\n+\n xzFile\n __libxml2_xzdopen(int fd, const char *mode)\n {\ndiff --git a/xzlib.h b/xzlib.h\nindex 43c75e1..29ba55e 100644\n--- a/xzlib.h\n+++ b/xzlib.h\n@@ -15,4 +15,5 @@ xzFile __libxml2_xzopen(const char *path, const char *mode);\n xzFile __libxml2_xzdopen(int fd, const char *mode);\n int __libxml2_xzread(xzFile file, void *buf, unsigned len);\n int __libxml2_xzclose(xzFile file);\n+int __libxml2_xzcompressed(xzFile f);\n #endif /* LIBXML2_XZLIB_H */\n-- \n2.1.2"}], "metadata": {"id": "libxml2-5762-0001-Fix-a-regression-in-xmlGe", "cve_id": "CVE-2016-4658", "package": "libxml2", "upstream_enriched": true, "upstream_commit": "63588f476f2dc89d4c6ef70a474d7230fbf4d45e", "upstream_repo": "GNOME/libxml2", "tier": "adapted", "has_source_context": true, "context_tokens_est": 177, "context_files": 2, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-7555\n\nHeap-based buffer overflow in giffix.c in giffix in giflib 5.1.1 allows attackers to cause a denial of service (program crash) via crafted image and logical screen width fields in a GIF file.\n\n## Package\ngiflib\n\n## Files to modify\n- util/giffix.c\n\n## Upstream Fix\n```diff\nFrom 179510be300bf11115e37528d79619b53c884a63 Mon Sep 17 00:00:00 2001\nFrom: \"Eric S. Raymond\" \nDate: Tue, 5 Jan 2016 23:01:45 -0500\nSubject: [PATCH] Address SF bug #71: Buffer overwrite when giffixing a\n malformed gif.\n\n---\n util/giffix.c | 2 ++\n 1 file changed, 2 insertions(+)\n\ndiff --git a/util/giffix.c b/util/giffix.c\nindex 6fba84a..c14c45b 100644\n--- a/util/giffix.c\n+++ b/util/giffix.c\n@@ -112,6 +112,8 @@ int main(int argc, char **argv)\n \t\tHeight = GifFileIn->Image.Height;\n \t\tGifQprintf(\"\\n%s: Image %d at (%d, %d) [%dx%d]: \",\n \t\t PROGRAM_NAME, ++ImageNum, Col, Row, Width, Height);\n+\t\tif (Width > GifFileIn->SWidth)\n+\t\t GIF_EXIT(\"Image is wider than total\");\n \n \t\t/* Put the image descriptor to out file: */\n \t\tif (EGifPutImageDesc(GifFileOut, Col, Row, Width, Height,\n-- \n2.7.0\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From 179510be300bf11115e37528d79619b53c884a63 Mon Sep 17 00:00:00 2001\nFrom: \"Eric S. Raymond\" \nDate: Tue, 5 Jan 2016 23:01:45 -0500\nSubject: [PATCH] Address SF bug #71: Buffer overwrite when giffixing a\n malformed gif.\n\n---\n util/giffix.c | 2 ++\n 1 file changed, 2 insertions(+)\n\ndiff --git a/util/giffix.c b/util/giffix.c\nindex 6fba84a..c14c45b 100644\n--- a/util/giffix.c\n+++ b/util/giffix.c\n@@ -112,6 +112,8 @@ int main(int argc, char **argv)\n \t\tHeight = GifFileIn->Image.Height;\n \t\tGifQprintf(\"\\n%s: Image %d at (%d, %d) [%dx%d]: \",\n \t\t PROGRAM_NAME, ++ImageNum, Col, Row, Width, Height);\n+\t\tif (Width > GifFileIn->SWidth)\n+\t\t GIF_EXIT(\"Image is wider than total\");\n \n \t\t/* Put the image descriptor to out file: */\n \t\tif (EGifPutImageDesc(GifFileOut, Col, Row, Width, Height,\n-- \n2.7.0"}], "metadata": {"id": "giflib-4546-giflib-CVE-2015-7555.patch", "cve_id": "CVE-2015-7555", "package": "giflib", "tier": "identical", "has_source_context": false, "license": "MIT"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1i.orig/apps/gendh.c\n- openssl-1.0.1i/apps/gendh.c\n- openssl-1.0.1i/apps/dhparam.c\n- openssl-1.0.1i.orig/apps/dhparam.c\n- apps/dhparam.c\n\n## Target Source Code\n\n### apps/dhparam.c\n\n#### region() [lines 91-178]\n```c\n *\n * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\n * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR\n * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\n * OF THE POSSIBILITY OF SUCH DAMAGE.\n * ====================================================================\n *\n * This product includes cryptographic software written by Eric Young\n * (eay@cryptsoft.com). This product includes software written by Tim\n * Hudson (tjh@cryptsoft.com).\n *\n */\n\n#include \t/* for OPENSSL_NO_DH */\n#ifndef OPENSSL_NO_DH\n#include \n#include \n#include \n#include \n#include \"apps.h\"\n#include \n#include \n#include \n#include \n#include \n#include \n\n#ifndef OPENSSL_NO_DSA\n#include \n#endif\n\n#undef PROG\n#define PROG\tdhparam_main\n\n#define DEFBITS\t512\n\n/* -inform arg\t- input format - default PEM (DER or PEM)\n * -outform arg - output format - default PEM\n * -in arg\t- input file - default stdin\n * -out arg\t- output file - default stdout\n * -dsaparam - read or generate DSA parameters, convert to DH\n * -check\t- check the parameters are ok\n * -noout\n * -text\n * -C\n */\n\nstatic int MS_CALLBACK dh_cb(int p, int n, BN_GENCB *cb);\n\nint MAIN(int, char **);\n\nint MAIN(int argc, char **argv)\n\t{\n\tDH *dh=NULL;\n\tint i,badops=0,text=0;\n#ifndef OPENSSL_NO_DSA\n\tint dsaparam=0;\n#endif\n\tBIO *in=NULL,*out=NULL;\n\tint informat,outformat,check=0,noout=0,C=0,ret=1;\n\tchar *infile,*outfile,*prog;\n\tchar *inrand=NULL;\n#ifndef OPENSSL_NO_ENGINE\n\tchar *engine=NULL;\n#endif\n\tint num = 0, g = 0;\n\n\tapps_startup();\n\n\tif (bio_err == NULL)\n\t\tif ((bio_err=BIO_new(BIO_s_file())) != NULL)\n\t\t\tBIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);\n\n\tif (!load_config(bio_err, NULL))\n\t\tgoto end;\n\n\tinfile=NULL;\n\toutfile=NULL;\n\tinformat=FORMAT_PEM;\n\toutformat=FORMAT_PEM;\n```\n\n#### region() [lines 147-536]\n```c\n\nint MAIN(int, char **);\n\nint MAIN(int argc, char **argv)\n\t{\n\tDH *dh=NULL;\n\tint i,badops=0,text=0;\n#ifndef OPENSSL_NO_DSA\n\tint dsaparam=0;\n#endif\n\tBIO *in=NULL,*out=NULL;\n\tint informat,outformat,check=0,noout=0,C=0,ret=1;\n\tchar *infile,*outfile,*prog;\n\tchar *inrand=NULL;\n#ifndef OPENSSL_NO_ENGINE\n\tchar *engine=NULL;\n#endif\n\tint num = 0, g = 0;\n\n\tapps_startup();\n\n\tif (bio_err == NULL)\n\t\tif ((bio_err=BIO_new(BIO_s_file())) != NULL)\n\t\t\tBIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);\n\n\tif (!load_config(bio_err, NULL))\n\t\tgoto end;\n\n\tinfile=NULL;\n\toutfile=NULL;\n\tinformat=FORMAT_PEM;\n\toutformat=FORMAT_PEM;\n\n\tprog=argv[0];\n\targc--;\n\targv++;\n\twhile (argc >= 1)\n\t\t{\n\t\tif \t(strcmp(*argv,\"-inform\") == 0)\n\t\t\t{\n/* ... 57 lines omitted ... */\n\t\tBIO_printf(bio_err,\" -inform arg input format - one of DER PEM\\n\");\n\t\tBIO_printf(bio_err,\" -outform arg output format - one of DER PEM\\n\");\n\t\tBIO_printf(bio_err,\" -in arg input file\\n\");\n\t\tBIO_printf(bio_err,\" -out arg output file\\n\");\n#ifndef OPENSSL_NO_DSA\n\t\tBIO_printf(bio_err,\" -dsaparam read or generate DSA parameters, convert to DH\\n\");\n#endif\n\t\tBIO_printf(bio_err,\" -check check the DH parameters\\n\");\n\t\tBIO_printf(bio_err,\" -text print a text form of the DH parameters\\n\");\n\t\tBIO_printf(bio_err,\" -C Output C code\\n\");\n\t\tBIO_printf(bio_err,\" -2 generate parameters using 2 as the generator value\\n\");\n\t\tBIO_printf(bio_err,\" -5 generate parameters using 5 as the generator value\\n\");\n\t\tBIO_printf(bio_err,\" numbits number of bits in to generate (default 512)\\n\");\n#ifndef OPENSSL_NO_ENGINE\n\t\tBIO_printf(bio_err,\" -engine e use engine e, possibly a hardware device.\\n\");\n#endif\n\t\tBIO_printf(bio_err,\" -rand file%cfile%c...\\n\", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR);\n\t\tBIO_printf(bio_err,\" - load the file (or the files in the directory) into\\n\");\n\t\tBIO_printf(bio_err,\" the random number generator\\n\");\n\t\tBIO_printf(bio_err,\" -noout no output\\n\");\n\t\tgoto end;\n\t\t}\n\n\tERR_load_crypto_strings();\n\n#ifndef OPENSSL_NO_ENGINE\n setup_engine(bio_err, engine, 0);\n/* ... 246 lines omitted ... */\n\t\t\tBIO_printf(bio_err,\"bad output format specified for outfile\\n\");\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (!i)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,\"unable to write DH parameters\\n\");\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tret=0;\nend:\n\tif (in != NULL) BIO_free(in);\n\tif (out != NULL) BIO_free_all(out);\n\tif (dh != NULL) DH_free(dh);\n\tapps_shutdown();\n\tOPENSSL_EXIT(ret);\n\t}\n\n/* dh_cb is identical to dsa_cb in apps/dsaparam.c */\n```\n\n### apps/gendh.c\n\n#### region() [lines 39-126]\n```c\n * the apps directory (application code) you must include an acknowledgement:\n * \"This product includes software written by Tim Hudson (tjh@cryptsoft.com)\"\n * \n * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\n * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\n * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n * SUCH DAMAGE.\n * \n * The licence and distribution terms for any publically available version or\n * derivative of this code cannot be changed. i.e. this code cannot simply be\n * copied and put under another distribution licence\n * [including the GNU Public Licence.]\n */\n\n#include \n/* Until the key-gen callbacks are modified to use newer prototypes, we allow\n * deprecated functions for openssl-internal code */\n#ifdef OPENSSL_NO_DEPRECATED\n#undef OPENSSL_NO_DEPRECATED\n#endif\n\n#ifndef OPENSSL_NO_DH\n#include \n#include \n#include \n#include \n#include \"apps.h\"\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n#define DEFBITS\t512\n#undef PROG\n#define PROG gendh_main\n\nstatic int MS_CALLBACK dh_cb(int p, int n, BN_GENCB *cb);\n\nint MAIN(int, char **);\n\nint MAIN(int argc, char **argv)\n\t{\n\tBN_GENCB cb;\n\tDH *dh=NULL;\n\tint ret=1,num=DEFBITS;\n\tint g=2;\n\tchar *outfile=NULL;\n\tchar *inrand=NULL;\n#ifndef OPENSSL_NO_ENGINE\n\tchar *engine=NULL;\n#endif\n\tBIO *out=NULL;\n\n\tapps_startup();\n\n\tBN_GENCB_set(&cb, dh_cb, bio_err);\n\tif (bio_err == NULL)\n\t\tif ((bio_err=BIO_new(BIO_s_file())) != NULL)\n\t\t\tBIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);\n\n\tif (!load_config(bio_err, NULL))\n\t\tgoto end;\n\n\targv++;\n\targc--;\n\tfor (;;)\n\t\t{\n\t\tif (argc <= 0) break;\n\t\tif (strcmp(*argv,\"-out\") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\toutfile= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,\"-2\") == 0)\n\t\t\tg=2;\n\t/*\telse if (strcmp(*argv,\"-3\") == 0)\n\t\t\tg=3; */\n\t\telse if (strcmp(*argv,\"-5\") == 0)\n```\n\n\n## Upstream Fix\n```diff\nFrom 8568170d774f02880eec6cad5512f555d0c83f65 Mon Sep 17 00:00:00 2001\nFrom: Emilia Kasper \nDate: Wed, 13 May 2015 11:57:55 +0200\nSubject: [PATCH] dhparam: set the default to 2048 bits\n\nReviewed-by: Matt Caswell \nReviewed-by: Kurt Roeckx \n---\n apps/dhparam.c | 4 ++--\n apps/gendh.c | 2 +-\n 2 files changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/apps/dhparam.c b/apps/dhparam.c\nindex f86311c28fd36..d3b6d58ad2e5a 100644\n--- a/apps/dhparam.c\n+++ b/apps/dhparam.c\n@@ -130,7 +130,7 @@\n # undef PROG\n # define PROG dhparam_main\n \n-# define DEFBITS 512\n+# define DEFBITS 2048\n \n /*-\n * -inform arg - input format - default PEM (DER or PEM)\n@@ -254,7 +254,7 @@ int MAIN(int argc, char **argv)\n BIO_printf(bio_err,\n \" -5 generate parameters using 5 as the generator value\\n\");\n BIO_printf(bio_err,\n- \" numbits number of bits in to generate (default 512)\\n\");\n+ \" numbits number of bits in to generate (default 2048)\\n\");\n # ifndef OPENSSL_NO_ENGINE\n BIO_printf(bio_err,\n \" -engine e use engine e, possibly a hardware device.\\n\");\ndiff --git a/apps/gendh.c b/apps/gendh.c\nindex adaa101783dfd..fef6f1b1774d1 100644\n--- a/apps/gendh.c\n+++ b/apps/gendh.c\n@@ -80,7 +80,7 @@\n # include \n # include \n \n-# define DEFBITS 512\n+# define DEFBITS 2048\n # undef PROG\n # define PROG gendh_main\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From 8568170d774f02880eec6cad5512f555d0c83f65 Mon Sep 17 00:00:00 2001\nFrom: Emilia Kasper \nDate: Wed, 13 May 2015 11:57:55 +0200\nSubject: [PATCH 2/5] dhparam: set the default to 2048 bits\n\nReviewed-by: Matt Caswell \nReviewed-by: Kurt Roeckx \n---\n apps/dhparam.c | 4 ++--\n apps/gendh.c | 2 +-\n 2 files changed, 3 insertions(+), 3 deletions(-)\n\nIndex: openssl-1.0.1i/apps/dhparam.c\n===================================================================\n--- openssl-1.0.1i.orig/apps/dhparam.c\t2015-06-12 13:16:47.628625800 +0200\n+++ openssl-1.0.1i/apps/dhparam.c\t2015-06-12 13:17:23.851068922 +0200\n@@ -130,7 +130,7 @@\n #undef PROG\n #define PROG\tdhparam_main\n \n-#define DEFBITS\t512\n+#define DEFBITS\t2048\n \n /* -inform arg\t- input format - default PEM (DER or PEM)\n * -outform arg - output format - default PEM\n@@ -253,7 +253,7 @@ bad:\n \t\tBIO_printf(bio_err,\" -C Output C code\\n\");\n \t\tBIO_printf(bio_err,\" -2 generate parameters using 2 as the generator value\\n\");\n \t\tBIO_printf(bio_err,\" -5 generate parameters using 5 as the generator value\\n\");\n-\t\tBIO_printf(bio_err,\" numbits number of bits in to generate (default 512)\\n\");\n+\t\tBIO_printf(bio_err,\" numbits number of bits in to generate (default 2048)\\n\");\n #ifndef OPENSSL_NO_ENGINE\n \t\tBIO_printf(bio_err,\" -engine e use engine e, possibly a hardware device.\\n\");\n #endif\nIndex: openssl-1.0.1i/apps/gendh.c\n===================================================================\n--- openssl-1.0.1i.orig/apps/gendh.c\t2015-06-12 13:16:47.629625812 +0200\n+++ openssl-1.0.1i/apps/gendh.c\t2015-06-12 13:17:54.615474034 +0200\n@@ -78,7 +78,7 @@\n #include \n #include \n \n-#define DEFBITS\t512\n+#define DEFBITS\t2048\n #undef PROG\n #define PROG gendh_main"}], "metadata": {"id": "openssl-4598-0002-dhparam-set-the-default-t", "cve_id": "CVE-2015-3197", "package": "openssl", "upstream_enriched": true, "upstream_commit": "8568170d774f02880eec6cad5512f555d0c83f65", "upstream_repo": "openssl/openssl", "tier": "adapted", "has_source_context": true, "context_tokens_est": 1941, "context_files": 2, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3455\n\nSquid 3.2.x before 3.2.14, 3.3.x before 3.3.14, 3.4.x before 3.4.13, and 3.5.x before 3.5.4, when configured with client-first SSL-bump, do not properly validate the domain or hostname fields of X.509 certificates, which allows man-in-the-middle attackers to spoof SSL servers via a valid certificate.\n\n## Package\nsquid\n\n## Upstream Fix\n```diff\n------------------------------------------------------------\nrevno: 12695\nrevision-id: squid3@treenet.co.nz-20160420064259-k9dn77q0xna1doax\nparent: squid3@treenet.co.nz-20160330141606-19rqzzip0grq9a77\ncommitter: Amos Jeffries \nbranch nick: 3.3\ntimestamp: Wed 2016-04-20 18:42:59 +1200\nmessage:\n cachemgr.cgi: use dynamic MemBuf for internal content generation\n \n Using a fixed size buffer limits how big content lines can be. Modern\n HTTP is fast reaching the point where such limits are problematic.\n Also fixes incorrect uses of snprintf() by removing them.\n------------------------------------------------------------\n# Bazaar merge directive format 2 (Bazaar 0.90)\n# revision_id: squid3@treenet.co.nz-20160420064259-k9dn77q0xna1doax\n# target_branch: http://bzr.squid-cache.org/bzr/squid3/3.3\n# testament_sha1: 0c7cd2d0ababe794c0fd5b1dc94c647c064c122d\n# timestamp: 2016-04-20 06:50:48 +0000\n# source_branch: http://bzr.squid-cache.org/bzr/squid3/3.3\n# base_revision_id: squid3@treenet.co.nz-20160330141606-\\\n# 19rqzzip0grq9a77\n# \n# Begin patch\n=== modified file 'src/tests/Stub.list'\n--- src/tests/Stub.list\t2014-10-08 15:31:39 +0000\n+++ src/tests/Stub.list\t2016-04-20 06:42:59 +0000\n@@ -3,6 +3,7 @@\n \ttests/stub_acl.cc \\\n \ttests/stub_cache_cf.cc \\\n \ttests/stub_cache_manager.cc \\\n+\ttests/stub_cbdata.cc \\\n \ttests/stub_client_db.cc \\\n \ttests/stub_client_side_request.cc \\\n \ttests/stub_comm.cc \\\n\n=== added file 'src/tests/stub_cbdata.cc'\n--- src/tests/stub_cbdata.cc\t1970-01-01 00:00:00 +0000\n+++ src/tests/stub_cbdata.cc\t2016-04-20 06:42:59 +0000\n@@ -0,0 +1,30 @@\n+#include \"squid.h\"\n+#include \"cbdata.h\"\n+\n+#define STUB_API \"cbdata.cc\"\n+#include \"tests/STUB.h\"\n+\n+void cbdataRegisterWithCacheManager(void) STUB\n+void *cbdataInternalAlloc(cbdata_type type, const char *, int sz) {\n+ return xcalloc(1, sz);\n+}\n+void *cbdataInternalFree(void *p, const char *, int) {\n+ xfree(p);\n+ return nullptr;\n+}\n+#if USE_CBDATA_DEBUG\n+void *cbdataInternalAllocDbg(cbdata_type type, const char *, int) STUB_RETVAL(NULL)\n+void *cbdataInternalFreeDbg(void *p, const char *, int) STUB_RETVAL(NULL)\n+void cbdataInternalLockDbg(const void *p, const char *, int) STUB\n+void cbdataInternalUnlockDbg(const void *p, const char *, int) STUB\n+int cbdataInternalReferenceDoneValidDbg(void **p, void **tp, const char *, int) STUB_RETVAL(0)\n+#else\n+void *cbdataInternalAlloc(cbdata_type type) STUB_RETVAL(NULL)\n+void *cbdataInternalFree(void *p) STUB_RETVAL(NULL)\n+void cbdataInternalLock(const void *p) STUB\n+void cbdataInternalUnlock(const void *p) STUB\n+int cbdataInternalReferenceDoneValid(void **p, void **tp) STUB_RETVAL(0)\n+#endif\n+\n+int cbdataReferenceValid(const void *p) STUB_RETVAL(0)\n+cbdata_type cbdataInternalAddType(cbdata_type type, const char *label, int size, FREE * free_func) STUB_RETVAL(CBDATA_UNKNOWN)\n\n=== modified file 'src/tests/stub_mem.cc'\n--- src/tests/stub_mem.cc\t2012-08-29 07:29:35 +0000\n+++ src/tests/stub_mem.cc\t2016-04-20 06:42:59 +0000\n@@ -5,7 +5,7 @@\n #include \"squid.h\"\n \n #define STUB_API \"stub_mem.cc\"\n-#include \"STUB.h\"\n+#include \"tests/STUB.h\"\n #include \"Mem.h\"\n \n void\n\n=== modified file 'tools/Makefile.am'\n--- tools/Makefile.am\t2010-12-06 14:06:06 +0000\n+++ tools/Makefile.am\t2016-04-20 06:42:59 +0000\n@@ -34,15 +34,24 @@\n stub_debug.cc: $(top_srcdir)/src/tests/stub_debug.cc\n \tcp $(top_srcdir)/src/tests/stub_debug.cc .\n \n+MemBuf.cc: $(top_srcdir)/src/MemBuf.cc\n+\tcp $(top_srcdir)/src/MemBuf.cc $@\n+\n time.cc: $(top_srcdir)/src/time.cc\n \tcp $(top_srcdir)/src/time.cc .\n \n+stub_cbdata.cc: $(top_srcdir)/src/tests/stub_cbdata.cc\n+\tcp $(top_srcdir)/src/tests/stub_cbdata.cc $@\n+\n+stub_mem.cc: $(top_srcdir)/src/tests/stub_mem.cc\n+\tcp $(top_srcdir)/src/tests/stub_mem.cc $@\n+\n # stock tools for unit tests - library independent versions of dlink_list\n # etc.\n # globals.cc is needed by test_tools.cc.\n # Neither of these should be disted from here.\n TESTSOURCES= test_tools.cc\n-CLEANFILES += test_tools.cc stub_debug.cc time.cc\n+CLEANFILES += test_tools.cc MemBuf.cc stub_debug.cc time.cc stub_cbdata.cc stub_mem.cc\n \n ## ##### helper-mux #####\n \n@@ -73,7 +82,10 @@\n libexec_PROGRAMS = cachemgr$(CGIEXT)\n \n cachemgr__CGIEXT__SOURCES = cachemgr.cc \\\n+\tMemBuf.cc \\\n+\tstub_cbdata.cc \\\n \tstub_debug.cc \\\n+\tstub_mem.cc \\\n \ttest_tools.cc \\\n \ttime.cc\n \n\n=== modified file 'tools/cachemgr.cc'\n--- tools/cachemgr.cc\t2013-09-09 07:17:19 +0000\n+++ tools/cachemgr.cc\t2016-04-20 06:42:59 +0000\n@@ -35,6 +35,7 @@\n #include \"getfullhostname.h\"\n #include \"html_quote.h\"\n #include \"ip/Address.h\"\n+#include \"MemBuf.h\"\n #include \"rfc1123.h\"\n #include \"rfc1738.h\"\n #include \"util.h\"\n@@ -460,8 +461,8 @@\n return url;\n }\n \n-static const char *\n-munge_menu_line(const char *buf, cachemgr_request * req)\n+static void\n+munge_menu_line(MemBuf &out, const char *buf, cachemgr_request * req)\n {\n char *x;\n const char *a;\n@@ -469,15 +470,14 @@\n const char *p;\n char *a_url;\n char *buf_copy;\n- static char html[2 * 1024];\n-\n- if (strlen(buf) < 1)\n- return buf;\n-\n- if (*buf != ' ')\n- return buf;\n-\n- buf_copy = x = xstrdup(buf);\n+\n+ const char bufLen = strlen(buf);\n+ if (bufLen < 1 || *buf != ' ') {\n+ out.append(buf, bufLen);\n+ return;\n+ }\n+\n+ buf_copy = x = xstrndup(buf, bufLen);\n \n a = xstrtok(&x, '\\t');\n \n@@ -489,59 +489,56 @@\n \n /* no reason to give a url for a disabled action */\n if (!strcmp(p, \"disabled\"))\n- snprintf(html, sizeof(html), \"
  • %s (disabled).\\n\", d, a_url);\n+ out.Printf(\"
  • %s (disabled).\\n\", d, a_url);\n else\n /* disable a hidden action (requires a password, but password is not in squid.conf) */\n if (!strcmp(p, \"hidden\"))\n- snprintf(html, sizeof(html), \"
  • %s (hidden).\\n\", d, a_url);\n+ out.Printf(\"
  • %s (hidden).\\n\", d, a_url);\n else\n /* disable link if authentication is required and we have no password */\n if (!strcmp(p, \"protected\") && !req->passwd)\n- snprintf(html, sizeof(html), \"
  • %s (requires authentication).\\n\",\n- d, menu_url(req, \"authenticate\"), a_url);\n+ out.Printf(\"
  • %s (requires authentication).\\n\",\n+ d, menu_url(req, \"authenticate\"), a_url);\n else\n /* highlight protected but probably available entries */\n if (!strcmp(p, \"protected\"))\n- snprintf(html, sizeof(html), \"
  • %s\\n\",\n- a_url, d);\n+ out.Printf(\"
  • %s\\n\",\n+ a_url, d);\n \n /* public entry or unknown type of protection */\n else\n- snprintf(html, sizeof(html), \"
  • %s\\n\", a_url, d);\n+ out.Printf(\"
  • %s\\n\", a_url, d);\n \n xfree(a_url);\n \n xfree(buf_copy);\n-\n- return html;\n }\n \n-static const char *\n-munge_other_line(const char *buf, cachemgr_request * req)\n+static void\n+munge_other_line(MemBuf &out, const char *buf, cachemgr_request *)\n {\n static const char *ttags[] = {\"td\", \"th\"};\n \n- static char html[4096];\n static int table_line_num = 0;\n static int next_is_header = 0;\n int is_header = 0;\n const char *ttag;\n char *buf_copy;\n char *x, *p;\n- int l = 0;\n /* does it look like a table? */\n \n if (!strchr(buf, '\\t') || *buf == '\\t') {\n /* nope, just text */\n- snprintf(html, sizeof(html), \"%s%s\",\n- table_line_num ? \"\\n
    \" : \"\", html_quote(buf));\n+        if (\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "------------------------------------------------------------\nrevno: 12695\nrevision-id: squid3@treenet.co.nz-20160420064259-k9dn77q0xna1doax\nparent: squid3@treenet.co.nz-20160330141606-19rqzzip0grq9a77\ncommitter: Amos Jeffries \nbranch nick: 3.3\ntimestamp: Wed 2016-04-20 18:42:59 +1200\nmessage:\n  cachemgr.cgi: use dynamic MemBuf for internal content generation\n  \n  Using a fixed size buffer limits how big content lines can be. Modern\n  HTTP is fast reaching the point where such limits are problematic.\n  Also fixes incorrect uses of snprintf() by removing them.\n------------------------------------------------------------\n# Bazaar merge directive format 2 (Bazaar 0.90)\n# revision_id: squid3@treenet.co.nz-20160420064259-k9dn77q0xna1doax\n# target_branch: http://bzr.squid-cache.org/bzr/squid3/3.3\n# testament_sha1: 0c7cd2d0ababe794c0fd5b1dc94c647c064c122d\n# timestamp: 2016-04-20 06:50:48 +0000\n# source_branch: http://bzr.squid-cache.org/bzr/squid3/3.3\n# base_revision_id: squid3@treenet.co.nz-20160330141606-\\\n#   19rqzzip0grq9a77\n# \n# Begin patch\n=== modified file 'src/tests/Stub.list'\n--- src/tests/Stub.list\t2014-10-08 15:31:39 +0000\n+++ src/tests/Stub.list\t2016-04-20 06:42:59 +0000\n@@ -3,6 +3,7 @@\n \ttests/stub_acl.cc \\\n \ttests/stub_cache_cf.cc \\\n \ttests/stub_cache_manager.cc \\\n+\ttests/stub_cbdata.cc \\\n \ttests/stub_client_db.cc \\\n \ttests/stub_client_side_request.cc \\\n \ttests/stub_comm.cc \\\n\n=== added file 'src/tests/stub_cbdata.cc'\n--- src/tests/stub_cbdata.cc\t1970-01-01 00:00:00 +0000\n+++ src/tests/stub_cbdata.cc\t2016-04-20 06:42:59 +0000\n@@ -0,0 +1,30 @@\n+#include \"squid.h\"\n+#include \"cbdata.h\"\n+\n+#define STUB_API \"cbdata.cc\"\n+#include \"tests/STUB.h\"\n+\n+void cbdataRegisterWithCacheManager(void) STUB\n+void *cbdataInternalAlloc(cbdata_type type, const char *, int sz) {\n+    return xcalloc(1, sz);\n+}\n+void *cbdataInternalFree(void *p, const char *, int) {\n+    xfree(p);\n+    return nullptr;\n+}\n+#if USE_CBDATA_DEBUG\n+void *cbdataInternalAllocDbg(cbdata_type type, const char *, int) STUB_RETVAL(NULL)\n+void *cbdataInternalFreeDbg(void *p, const char *, int) STUB_RETVAL(NULL)\n+void cbdataInternalLockDbg(const void *p, const char *, int) STUB\n+void cbdataInternalUnlockDbg(const void *p, const char *, int) STUB\n+int cbdataInternalReferenceDoneValidDbg(void **p, void **tp, const char *, int) STUB_RETVAL(0)\n+#else\n+void *cbdataInternalAlloc(cbdata_type type) STUB_RETVAL(NULL)\n+void *cbdataInternalFree(void *p) STUB_RETVAL(NULL)\n+void cbdataInternalLock(const void *p) STUB\n+void cbdataInternalUnlock(const void *p) STUB\n+int cbdataInternalReferenceDoneValid(void **p, void **tp) STUB_RETVAL(0)\n+#endif\n+\n+int cbdataReferenceValid(const void *p) STUB_RETVAL(0)\n+cbdata_type cbdataInternalAddType(cbdata_type type, const char *label, int size, FREE * free_func) STUB_RETVAL(CBDATA_UNKNOWN)\n\n=== modified file 'src/tests/stub_mem.cc'\n--- src/tests/stub_mem.cc\t2012-08-29 07:29:35 +0000\n+++ src/tests/stub_mem.cc\t2016-04-20 06:42:59 +0000\n@@ -5,7 +5,7 @@\n #include \"squid.h\"\n \n #define STUB_API \"stub_mem.cc\"\n-#include \"STUB.h\"\n+#include \"tests/STUB.h\"\n #include \"Mem.h\"\n \n void\n\n=== modified file 'tools/Makefile.am'\n--- tools/Makefile.am\t2010-12-06 14:06:06 +0000\n+++ tools/Makefile.am\t2016-04-20 06:42:59 +0000\n@@ -34,15 +34,24 @@\n stub_debug.cc: $(top_srcdir)/src/tests/stub_debug.cc\n \tcp $(top_srcdir)/src/tests/stub_debug.cc .\n \n+MemBuf.cc: $(top_srcdir)/src/MemBuf.cc\n+\tcp $(top_srcdir)/src/MemBuf.cc $@\n+\n time.cc: $(top_srcdir)/src/time.cc\n \tcp $(top_srcdir)/src/time.cc .\n \n+stub_cbdata.cc: $(top_srcdir)/src/tests/stub_cbdata.cc\n+\tcp $(top_srcdir)/src/tests/stub_cbdata.cc $@\n+\n+stub_mem.cc: $(top_srcdir)/src/tests/stub_mem.cc\n+\tcp $(top_srcdir)/src/tests/stub_mem.cc $@\n+\n # stock tools for unit tests - library independent versions of dlink_list\n # etc.\n # globals.cc is needed by test_tools.cc.\n # Neither of these should be disted from here.\n TESTSOURCES= test_tools.cc\n-CLEANFILES += test_tools.cc stub_debug.cc time.cc\n+CLEANFILES += test_tools.cc MemBuf.cc stub_debug.cc time.cc stub_cbdata.cc stub_mem.cc\n \n ## ##### helper-mux #####\n \n@@ -73,7 +82,10 @@\n libexec_PROGRAMS = cachemgr$(CGIEXT)\n \n cachemgr__CGIEXT__SOURCES = cachemgr.cc \\\n+\tMemBuf.cc \\\n+\tstub_cbdata.cc \\\n \tstub_debug.cc \\\n+\tstub_mem.cc \\\n \ttest_tools.cc \\\n \ttime.cc\n \n\n=== modified file 'tools/cachemgr.cc'\n--- tools/cachemgr.cc\t2013-09-09 07:17:19 +0000\n+++ tools/cachemgr.cc\t2016-04-20 06:42:59 +0000\n@@ -35,6 +35,7 @@\n #include \"getfullhostname.h\"\n #include \"html_quote.h\"\n #include \"ip/Address.h\"\n+#include \"MemBuf.h\"\n #include \"rfc1123.h\"\n #include \"rfc1738.h\"\n #include \"util.h\"\n@@ -460,8 +461,8 @@\n     return url;\n }\n \n-static const char *\n-munge_menu_line(const char *buf, cachemgr_request * req)\n+static void\n+munge_menu_line(MemBuf &out, const char *buf, cachemgr_request * req)\n {\n     char *x;\n     const char *a;\n@@ -469,15 +470,14 @@\n     const char *p;\n     char *a_url;\n     char *buf_copy;\n-    static char html[2 * 1024];\n-\n-    if (strlen(buf) < 1)\n-        return buf;\n-\n-    if (*buf != ' ')\n-        return buf;\n-\n-    buf_copy = x = xstrdup(buf);\n+\n+    const char bufLen = strlen(buf);\n+    if (bufLen < 1 || *buf != ' ') {\n+        out.append(buf, bufLen);\n+        return;\n+    }\n+\n+    buf_copy = x = xstrndup(buf, bufLen);\n \n     a = xstrtok(&x, '\\t');\n \n@@ -489,59 +489,56 @@\n \n     /* no reason to give a url for a disabled action */\n     if (!strcmp(p, \"disabled\"))\n-        snprintf(html, sizeof(html), \"
  • %s (disabled).\\n\", d, a_url);\n+ out.Printf(\"
  • %s (disabled).\\n\", d, a_url);\n else\n /* disable a hidden action (requires a password, but password is not in squid.conf) */\n if (!strcmp(p, \"hidden\"))\n- snprintf(html, sizeof(html), \"
  • %s (hidden).\\n\", d, a_url);\n+ out.Printf(\"
  • %s (hidden).\\n\", d, a_url);\n else\n /* disable link if authentication is required and we have no password */\n if (!strcmp(p, \"protected\") && !req->passwd)\n- snprintf(html, sizeof(html), \"
  • %s (requires authentication).\\n\",\n- d, menu_url(req, \"authenticate\"), a_url);\n+ out.Printf(\"
  • %s (requires authentication).\\n\",\n+ d, menu_url(req, \"authenticate\"), a_url);\n else\n /* highlight protected but probably available entries */\n if (!strcmp(p, \"protected\"))\n- snprintf(html, sizeof(html), \"
  • %s\\n\",\n- a_url, d);\n+ out.Printf(\"
  • %s\\n\",\n+ a_url, d);\n \n /* public entry or unknown type of protection */\n else\n- snprintf(html, sizeof(html), \"
  • %s\\n\", a_url, d);\n+ out.Printf(\"
  • %s\\n\", a_url, d);\n \n xfree(a_url);\n \n xfree(buf_copy);\n-\n- return html;\n }\n \n-static const char *\n-munge_other_line(const char *buf, cachemgr_request * req)\n+static void\n+munge_other_line(MemBuf &out, const char *buf, cachemgr_request *)\n {\n static const char *ttags[] = {\"td\", \"th\"};\n \n- static char html[4096];\n static int table_line_num = 0;\n static int next_is_header = 0;\n int is_header = 0;\n const char *ttag;\n char *buf_copy;\n char *x, *p;\n- int l = 0;\n /* does it look like a table? */\n \n if (!strchr(buf, '\\t') || *buf == '\\t') {\n /* nope, just text */\n- snprintf(html, sizeof(html), \"%s%s\",\n- table_line_num ? \"\\n
    \" : \"\", html_quote(buf));\n+        if (table_line_num)\n+            out.append(\"\\n
    \", 14);\n+        out.Printf(\"%s\", html_quote(buf));\n         table_line_num = 0;\n-        return html;\n+        return;\n     }\n \n     /* start html table */\n     if (!table_line_num) {\n-        l += snprintf(html + l, sizeof(html) - l, \"
    \\n\");\n+ out.append(\"
    \\n\", 46);\n next_is_header = 0;\n }\n \n@@ -551,7 +548,7 @@\n ttag = ttags[is_header];\n \n /* record starts */\n- l += snprintf(html + l, sizeof(html) - l, \"\");\n+ out.append(\"\", 4);\n \n /* substitute '\\t' */\n buf_copy = x = xstrdup(buf);\n@@ -568,18 +565,17 @@\n ++x;\n }\n \n- l += snprintf(html + l, sizeof(html) - l, \"<%s colspan=\\\"%d\\\" align=\\\"%s\\\">%s\",\n- ttag, column_span,\n- is_header ? \"center\" : is_number(cell) ? \"right\" : \"left\",\n- html_quote(cell), ttag);\n+ out.Printf(\"<%s colspan=\\\"%d\\\" align=\\\"%s\\\">%s\",\n+ ttag, column_span,\n+ is_header ? \"center\" : is_number(cell) ? \"right\" : \"left\",\n+ html_quote(cell), ttag);\n }\n \n xfree(buf_copy);\n /* record ends */\n- snprintf(html + l, sizeof(html) - l, \"\\n\");\n+ out.append(\"\\n\", 6);\n next_is_header = is_header && strstr(buf, \"\\t\\t\");\n ++table_line_num;\n- return html;\n }\n \n static const char *\n@@ -736,14 +732,18 @@\n /* yes, fall through, we do not want to loose the first line */\n \n case isBody:\n+ {\n /* interpret [and reformat] cache response */\n-\n+ MemBuf out;\n+ out.init();\n if (parse_menu)\n- fputs(munge_menu_line(buf, req), stdout);\n+ munge_menu_line(out, buf, req);\n else\n- fputs(munge_other_line(buf, req), stdout);\n+ munge_other_line(out, buf, req);\n \n- break;\n+ fputs(out.buf, stdout);\n+ }\n+ break;\n \n case isForward:\n /* forward: no modifications allowed */\n\n------------------------------------------------------------\nrevno: 12696\nrevision-id: squid3@treenet.co.nz-20160420101500-nm50i4u3iftemzs6\nparent: squid3@treenet.co.nz-20160420064259-k9dn77q0xna1doax\ncommitter: Amos Jeffries \nbranch nick: 3.3\ntimestamp: Wed 2016-04-20 22:15:00 +1200\nmessage:\n nullptr is a C++11 feature\n------------------------------------------------------------\n# Bazaar merge directive format 2 (Bazaar 0.90)\n# revision_id: squid3@treenet.co.nz-20160420101500-nm50i4u3iftemzs6\n# target_branch: http://bzr.squid-cache.org/bzr/squid3/3.3\n# testament_sha1: 091f2aa4b835390972c0f42e67128484d653c2ee\n# timestamp: 2016-04-20 10:50:54 +0000\n# source_branch: http://bzr.squid-cache.org/bzr/squid3/3.3\n# base_revision_id: squid3@treenet.co.nz-20160420064259-\\\n# k9dn77q0xna1doax\n# \n# Begin patch\n=== modified file 'src/tests/stub_cbdata.cc'\n--- src/tests/stub_cbdata.cc\t2016-04-20 06:42:59 +0000\n+++ src/tests/stub_cbdata.cc\t2016-04-20 10:15:00 +0000\n@@ -10,7 +10,7 @@\n }\n void *cbdataInternalFree(void *p, const char *, int) {\n xfree(p);\n- return nullptr;\n+ return NULL;\n }\n #if USE_CBDATA_DEBUG\n void *cbdataInternalAllocDbg(cbdata_type type, const char *, int) STUB_RETVAL(NULL)"}], "metadata": {"id": "squid-5473-SQUID-2016_5.patch", "cve_id": "CVE-2015-3455", "package": "squid", "tier": "adapted", "has_source_context": false, "license": "GPL-2.0-or-later"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2012-2142\n\nThe error function in Error.cc in poppler before 0.21.4 allows remote attackers to execute arbitrary commands via a PDF containing an escape sequence for a terminal emulator.\n\n## Package\npoppler-qt\n\n## Upstream Fix\n```diff\nFrom dcbc923bd3592a81876f84005fbaddcea18641cc Mon Sep 17 00:00:00 2001\nFrom: Thomas Freitag \nDate: Sun, 22 Jul 2012 16:40:46 +0000\nSubject: Make sure xScale and yScale are always initialized\n\nBug #52215\n---\n(limited to 'poppler/PSOutputDev.cc')\n\ndiff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc\nindex a01a4b3..e15c2e9 100644\n--- a/poppler/PSOutputDev.cc\n+++ b/poppler/PSOutputDev.cc\n@@ -3521,6 +3521,7 @@ void PSOutputDev::startPage(int pageNum, GfxState *state) {\n saveState(NULL);\n }\n \n+ xScale = yScale = 1;\n switch (mode) {\n \n case psModePSOrigPageSizes:\n@@ -3631,8 +3632,6 @@ void PSOutputDev::startPage(int pageNum, GfxState *state) {\n } else {\n \tyScale = xScale;\n }\n- } else {\n- xScale = yScale = 1;\n }\n // deal with odd bounding boxes or clipping\n if (clipLLX0 < clipURX0 && clipLLY0 < clipURY0) {\n@@ -3694,7 +3693,6 @@ void PSOutputDev::startPage(int pageNum, GfxState *state) {\n if (tx != 0 || ty != 0) {\n writePSFmt(\"{0:.6g} {1:.6g} translate\\n\", tx, ty);\n }\n- xScale = yScale = 1;\n break;\n \n case psModeForm:\n@@ -3702,7 +3700,6 @@ void PSOutputDev::startPage(int pageNum, GfxState *state) {\n writePS(\"begin xpdf begin\\n\");\n writePS(\"pdfStartPage\\n\");\n tx = ty = 0;\n- xScale = yScale = 1;\n rotate = 0;\n break;\n }\n--\ncgit v0.9.0.2-2-gbebe\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From dcbc923bd3592a81876f84005fbaddcea18641cc Mon Sep 17 00:00:00 2001\nFrom: Thomas Freitag \nDate: Sun, 22 Jul 2012 16:40:46 +0000\nSubject: Make sure xScale and yScale are always initialized\n\nBug #52215\n---\n(limited to 'poppler/PSOutputDev.cc')\n\ndiff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc\nindex a01a4b3..e15c2e9 100644\n--- a/poppler/PSOutputDev.cc\n+++ b/poppler/PSOutputDev.cc\n@@ -3521,6 +3521,7 @@ void PSOutputDev::startPage(int pageNum, GfxState *state) {\n saveState(NULL);\n }\n \n+ xScale = yScale = 1;\n switch (mode) {\n \n case psModePSOrigPageSizes:\n@@ -3631,8 +3632,6 @@ void PSOutputDev::startPage(int pageNum, GfxState *state) {\n } else {\n \tyScale = xScale;\n }\n- } else {\n- xScale = yScale = 1;\n }\n // deal with odd bounding boxes or clipping\n if (clipLLX0 < clipURX0 && clipLLY0 < clipURY0) {\n@@ -3694,7 +3693,6 @@ void PSOutputDev::startPage(int pageNum, GfxState *state) {\n if (tx != 0 || ty != 0) {\n writePSFmt(\"{0:.6g} {1:.6g} translate\\n\", tx, ty);\n }\n- xScale = yScale = 1;\n break;\n \n case psModeForm:\n@@ -3702,7 +3700,6 @@ void PSOutputDev::startPage(int pageNum, GfxState *state) {\n writePS(\"begin xpdf begin\\n\");\n writePS(\"pdfStartPage\\n\");\n tx = ty = 0;\n- xScale = yScale = 1;\n rotate = 0;\n break;\n }\n--\ncgit v0.9.0.2-2-gbebe"}], "metadata": {"id": "poppler-qt-1943-dcbc923bd3592a81876f84005fbadd", "cve_id": "CVE-2012-2142", "package": "poppler-qt", "tier": "identical", "has_source_context": false, "license": "GPL-2.0-only OR GPL-3.0-only"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2015-3197\n\nssl/s2_srvr.c in OpenSSL 1.0.1 before 1.0.1r and 1.0.2 before 1.0.2f does not prevent use of disabled ciphers, which makes it easier for man-in-the-middle attackers to defeat cryptographic protection mechanisms by performing computations on SSLv2 traffic, related to the get_client_master_key and get_client_hello functions.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1i/crypto/asn1/tasn_dec.c\n- crypto/asn1/tasn_dec.c\n- openssl-1.0.1i.orig/crypto/asn1/tasn_dec.c\n\n## Target Source Code\n\n### crypto/asn1/tasn_dec.c\n\n#### ASN1_item_ex_d2i() [lines 151-528]\n```c\n * If 'opt' set and tag mismatch return -1 to handle OPTIONAL\n */\n\nint ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,\n\t\t\tconst ASN1_ITEM *it,\n\t\t\tint tag, int aclass, char opt, ASN1_TLC *ctx)\n\t{\n\tconst ASN1_TEMPLATE *tt, *errtt = NULL;\n\tconst ASN1_COMPAT_FUNCS *cf;\n\tconst ASN1_EXTERN_FUNCS *ef;\n\tconst ASN1_AUX *aux = it->funcs;\n\tASN1_aux_cb *asn1_cb;\n\tconst unsigned char *p = NULL, *q;\n\tunsigned char *wp=NULL;\t/* BIG FAT WARNING! BREAKS CONST WHERE USED */\n\tunsigned char imphack = 0, oclass;\n\tchar seq_eoc, seq_nolen, cst, isopt;\n\tlong tmplen;\n\tint i;\n\tint otag;\n\tint ret = 0;\n\tASN1_VALUE **pchptr, *ptmpval;\n\tif (!pval)\n\t\treturn 0;\n\tif (aux && aux->asn1_cb)\n\t\tasn1_cb = aux->asn1_cb;\n\telse asn1_cb = 0;\n\n\tswitch(it->itype)\n\t\t{\n\t\tcase ASN1_ITYPE_PRIMITIVE:\n\t\tif (it->templates)\n\t\t\t{\n\t\t\t/* tagging or OPTIONAL is currently illegal on an item\n\t\t\t * template because the flags can't get passed down.\n\t\t\t * In practice this isn't a problem: we include the\n\t\t\t * relevant flags from the item template in the\n\t\t\t * template itself.\n\t\t\t */\n\t\t\tif ((tag != -1) || opt)\n\t\t\t\t{\n/* ... 323 lines omitted ... */\n\t\tif (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL))\n\t\t\t\tgoto auxerr;\n\t\treturn 1;\n\n\t\tdefault:\n\t\treturn 0;\n\t\t}\n\tauxerr:\n\tASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_AUX_ERROR);\n\terr:\n\tASN1_item_ex_free(pval, it);\n\tif (errtt)\n\t\tERR_add_error_data(4, \"Field=\", errtt->field_name,\n\t\t\t\t\t\", Type=\", it->sname);\n\telse\n\t\tERR_add_error_data(2, \"Type=\", it->sname);\n\treturn 0;\n\t}\n\n/* Templates are handled with two separate functions.\n```\n\n#### asn1_template_noexp_d2i() [lines 615-766]\n```c\n\treturn 0;\n\t}\n\nstatic int asn1_template_noexp_d2i(ASN1_VALUE **val,\n\t\t\t\tconst unsigned char **in, long len,\n\t\t\t\tconst ASN1_TEMPLATE *tt, char opt,\n\t\t\t\tASN1_TLC *ctx)\n\t{\n\tint flags, aclass;\n\tint ret;\n\tconst unsigned char *p, *q;\n\tif (!val)\n\t\treturn 0;\n\tflags = tt->flags;\n\taclass = flags & ASN1_TFLG_TAG_CLASS;\n\n\tp = *in;\n\tq = p;\n\n\tif (flags & ASN1_TFLG_SK_MASK)\n\t\t{\n\t\t/* SET OF, SEQUENCE OF */\n\t\tint sktag, skaclass;\n\t\tchar sk_eoc;\n\t\t/* First work out expected inner tag value */\n\t\tif (flags & ASN1_TFLG_IMPTAG)\n\t\t\t{\n\t\t\tsktag = tt->tag;\n\t\t\tskaclass = aclass;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tskaclass = V_ASN1_UNIVERSAL;\n\t\t\tif (flags & ASN1_TFLG_SET_OF)\n\t\t\t\tsktag = V_ASN1_SET;\n\t\t\telse\n\t\t\t\tsktag = V_ASN1_SEQUENCE;\n\t\t\t}\n\t\t/* Get the tag */\n\t\tret = asn1_check_tlen(&len, NULL, NULL, &sk_eoc, NULL,\n/* ... 98 lines omitted ... */\n\t\t\t}\n\t\telse if (ret == -1)\n\t\t\treturn -1;\n\t\t}\n\n\t*in = p;\n\treturn 1;\n\n\terr:\n\tASN1_template_free(val, tt);\n\treturn 0;\n\t}\n\nstatic int asn1_d2i_ex_primitive(ASN1_VALUE **pval,\n```\n\n\n## Upstream Fix\n```diff\nFrom b29ffa392e839d05171206523e84909146f7a77c Mon Sep 17 00:00:00 2001\nFrom: \"Dr. Stephen Henson\" \nDate: Tue, 10 Nov 2015 19:03:07 +0000\nSubject: [PATCH] Fix leak with ASN.1 combine.\n\nWhen parsing a combined structure pass a flag to the decode routine\nso on error a pointer to the parent structure is not zeroed as\nthis will leak any additional components in the parent.\n\nThis can leak memory in any application parsing PKCS#7 or CMS structures.\n\nCVE-2015-3195.\n\nThanks to Adam Langley (Google/BoringSSL) for discovering this bug using\nlibFuzzer.\n\nPR#4131\n\nReviewed-by: Richard Levitte \n---\n crypto/asn1/tasn_dec.c | 7 +++++--\n 1 file changed, 5 insertions(+), 2 deletions(-)\n\ndiff --git a/crypto/asn1/tasn_dec.c b/crypto/asn1/tasn_dec.c\nindex febf6059cbe5a..9256049d15881 100644\n--- a/crypto/asn1/tasn_dec.c\n+++ b/crypto/asn1/tasn_dec.c\n@@ -180,6 +180,8 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,\n int otag;\n int ret = 0;\n ASN1_VALUE **pchptr, *ptmpval;\n+ int combine = aclass & ASN1_TFLG_COMBINE;\n+ aclass &= ~ASN1_TFLG_COMBINE;\n if (!pval)\n return 0;\n if (aux && aux->asn1_cb)\n@@ -500,7 +502,8 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,\n auxerr:\n ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_AUX_ERROR);\n err:\n- ASN1_item_ex_free(pval, it);\n+ if (combine == 0)\n+ ASN1_item_ex_free(pval, it);\n if (errtt)\n ERR_add_error_data(4, \"Field=\", errtt->field_name,\n \", Type=\", it->sname);\n@@ -689,7 +692,7 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,\n } else {\n /* Nothing special */\n ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item),\n- -1, 0, opt, ctx);\n+ -1, tt->flags & ASN1_TFLG_COMBINE, opt, ctx);\n if (!ret) {\n ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_NESTED_ASN1_ERROR);\n goto err;\n```\n\nGenerate a backported patch for the SUSE target version."}, {"role": "assistant", "content": "From b29ffa392e839d05171206523e84909146f7a77c Mon Sep 17 00:00:00 2001\nFrom: \"Dr. Stephen Henson\" \nDate: Tue, 10 Nov 2015 19:03:07 +0000\nSubject: [PATCH] Fix leak with ASN.1 combine.\n\nWhen parsing a combined structure pass a flag to the decode routine\nso on error a pointer to the parent structure is not zeroed as\nthis will leak any additional components in the parent.\n\nThis can leak memory in any application parsing PKCS#7 or CMS structures.\n\nCVE-2015-3195.\n\nThanks to Adam Langley (Google/BoringSSL) for discovering this bug using\nlibFuzzer.\n\nPR#4131\n\nReviewed-by: Richard Levitte \n---\n crypto/asn1/tasn_dec.c | 7 +++++--\n 1 file changed, 5 insertions(+), 2 deletions(-)\n\nIndex: openssl-1.0.1i/crypto/asn1/tasn_dec.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/asn1/tasn_dec.c\t2015-12-03 17:59:01.272944957 +0100\n+++ openssl-1.0.1i/crypto/asn1/tasn_dec.c\t2015-12-03 18:02:54.285726394 +0100\n@@ -169,6 +169,8 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval,\n \tint otag;\n \tint ret = 0;\n \tASN1_VALUE **pchptr, *ptmpval;\n+\tint combine = aclass & ASN1_TFLG_COMBINE;\n+\taclass &= ~ASN1_TFLG_COMBINE;\n \tif (!pval)\n \t\treturn 0;\n \tif (aux && aux->asn1_cb)\n@@ -534,7 +536,8 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval,\n \tauxerr:\n \tASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_AUX_ERROR);\n \terr:\n-\tASN1_item_ex_free(pval, it);\n+\tif (combine == 0)\n+\t\tASN1_item_ex_free(pval, it);\n \tif (errtt)\n \t\tERR_add_error_data(4, \"Field=\", errtt->field_name,\n \t\t\t\t\t\", Type=\", it->sname);\n@@ -762,7 +765,7 @@ static int asn1_template_noexp_d2i(ASN1_\n \t\t{\n \t\t/* Nothing special */\n \t\tret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item),\n-\t\t\t\t\t\t\t-1, 0, opt, ctx);\n+\t\t\t\t\t\t\t-1, tt->flags & ASN1_TFLG_COMBINE, opt, ctx);\n \t\tif (!ret)\n \t\t\t{\n \t\t\tASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,"}], "metadata": {"id": "openssl-4598-openssl-CVE-2015-3195.patch", "cve_id": "CVE-2015-3197", "package": "openssl", "upstream_enriched": true, "upstream_commit": "b29ffa392e839d05171206523e84909146f7a77c", "upstream_repo": "openssl/openssl", "tier": "adapted", "has_source_context": true, "context_tokens_est": 669, "context_files": 1, "license": "OpenSSL"}} {"messages": [{"role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged."}, {"role": "user", "content": "## CVE: CVE-2016-4658\n\nxpointer.c in libxml2 before 2.9.5 (as used in Apple iOS before 10, OS X before 10.12, tvOS before 10, and watchOS before 3, and other products) does not forbid namespace nodes in XPointer ranges, which allows remote attackers to execute arbitrary code or cause a denial of service (use-after-free and memory corruption) via a crafted XML document.\n\n## Package\nlibxml2\n\n## Files to modify\n- HTMLparser.c\n\n## Upstream Fix\n```diff\nFrom e724879d964d774df9b7969fc846605aa1bac54c Mon Sep 17 00:00:00 2001\nFrom: Daniel Veillard \nDate: Fri, 30 Oct 2015 21:14:55 +0800\nSubject: [PATCH] Fix parsing short unclosed comment uninitialized access\n\nFor https://bugzilla.gnome.org/show_bug.cgi?id=746048\nThe HTML parser was too optimistic when processing comments and\ndidn't check for the end of the stream on the first 2 characters\n---\n HTMLparser.c | 21 ++++++++++++++-------\n 1 file changed, 14 insertions(+), 7 deletions(-)\n\ndiff --git a/HTMLparser.c b/HTMLparser.c\nindex 19c10c3fea..bdf780711c 100644\n--- a/HTMLparser.c\n+++ b/HTMLparser.c\n@@ -3264,12 +3264,17 @@ htmlParseComment(htmlParserCtxtPtr ctxt) {\n \tctxt->instate = state;\n \treturn;\n }\n+ len = 0;\n+ buf[len] = 0;\n q = CUR_CHAR(ql);\n+ if (!IS_CHAR(q))\n+ goto unfinished;\n NEXTL(ql);\n r = CUR_CHAR(rl);\n+ if (!IS_CHAR(r))\n+ goto unfinished;\n NEXTL(rl);\n cur = CUR_CHAR(l);\n- len = 0;\n while (IS_CHAR(cur) &&\n ((cur != '>') ||\n \t (r != '-') || (q != '-'))) {\n@@ -3300,18 +3305,20 @@ htmlParseComment(htmlParserCtxtPtr ctxt) {\n \t}\n }\n buf[len] = 0;\n- if (!IS_CHAR(cur)) {\n-\thtmlParseErr(ctxt, XML_ERR_COMMENT_NOT_FINISHED,\n-\t \"Comment not terminated \\n