idx
int64
func_before
string
Vulnerability Classification
string
vul
int64
func_after
string
patch
string
CWE ID
string
lines_before
string
lines_after
string
1,600
static void vdi_port_unref_msg_to_client(SpiceCharDeviceMsgToClient *msg, void *opaque) { vdi_port_read_buf_unref(msg); }
DoS Overflow
0
static void vdi_port_unref_msg_to_client(SpiceCharDeviceMsgToClient *msg, void *opaque) { vdi_port_read_buf_unref(msg); }
@@ -1926,39 +1926,59 @@ static void reds_handle_link(RedLinkInfo *link) static void reds_handle_ticket(void *opaque) { RedLinkInfo *link = (RedLinkInfo *)opaque; - char password[SPICE_MAX_PASSWORD_LENGTH]; + char *password; time_t ltime; + int password_size; //todo: use monotonic time time(&ltime); - RSA_private_decrypt(link->tiTicketing.rsa_size, - link->tiTicketing.encrypted_ticket.encrypted_data, - (unsigned char *)password, link->tiTicketing.rsa, RSA_PKCS1_OAEP_PADDING); + if (RSA_size(link->tiTicketing.rsa) < SPICE_MAX_PASSWORD_LENGTH) { + spice_warning("RSA modulus size is smaller than SPICE_MAX_PASSWORD_LENGTH (%d < %d), " + "SPICE ticket sent from client may be truncated", + RSA_size(link->tiTicketing.rsa), SPICE_MAX_PASSWORD_LENGTH); + } + + password = g_malloc0(RSA_size(link->tiTicketing.rsa) + 1); + password_size = RSA_private_decrypt(link->tiTicketing.rsa_size, + link->tiTicketing.encrypted_ticket.encrypted_data, + (unsigned char *)password, + link->tiTicketing.rsa, + RSA_PKCS1_OAEP_PADDING); + if (password_size == -1) { + spice_warning("failed to decrypt RSA encrypted password: %s", + ERR_error_string(ERR_get_error(), NULL)); + goto error; + } + password[password_size] = '\0'; if (ticketing_enabled && !link->skip_auth) { int expired = taTicket.expiration_time < ltime; if (strlen(taTicket.password) == 0) { - reds_send_link_result(link, SPICE_LINK_ERR_PERMISSION_DENIED); spice_warning("Ticketing is enabled, but no password is set. " - "please set a ticket first"); - reds_link_free(link); - return; + "please set a ticket first"); + goto error; } - if (expired || strncmp(password, taTicket.password, SPICE_MAX_PASSWORD_LENGTH) != 0) { + if (expired || strcmp(password, taTicket.password) != 0) { if (expired) { spice_warning("Ticket has expired"); } else { spice_warning("Invalid password"); } - reds_send_link_result(link, SPICE_LINK_ERR_PERMISSION_DENIED); - reds_link_free(link); - return; + goto error; } } reds_handle_link(link); + goto end; + +error: + reds_send_link_result(link, SPICE_LINK_ERR_PERMISSION_DENIED); + reds_link_free(link); + +end: + g_free(password); } static inline void async_read_clear_handlers(AsyncRead *obj)
CWE-119
null
null
1,601
PHP_FUNCTION(openssl_x509_check_private_key) { zval ** zcert, **zkey; X509 * cert = NULL; EVP_PKEY * key = NULL; long certresource = -1, keyresource = -1; RETVAL_FALSE; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ZZ", &zcert, &zkey) == FAILURE) { return; } cert = php_openssl_x509_from_zval(zcert, 0, &certresource TSRMLS_CC); if (cert == NULL) { RETURN_FALSE; } key = php_openssl_evp_from_zval(zkey, 0, "", 1, &keyresource TSRMLS_CC); if (key) { RETVAL_BOOL(X509_check_private_key(cert, key)); } if (keyresource == -1 && key) { EVP_PKEY_free(key); } if (certresource == -1 && cert) { X509_free(cert); } }
null
0
PHP_FUNCTION(openssl_x509_check_private_key) { zval ** zcert, **zkey; X509 * cert = NULL; EVP_PKEY * key = NULL; long certresource = -1, keyresource = -1; RETVAL_FALSE; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ZZ", &zcert, &zkey) == FAILURE) { return; } cert = php_openssl_x509_from_zval(zcert, 0, &certresource TSRMLS_CC); if (cert == NULL) { RETURN_FALSE; } key = php_openssl_evp_from_zval(zkey, 0, "", 1, &keyresource TSRMLS_CC); if (key) { RETVAL_BOOL(X509_check_private_key(cert, key)); } if (keyresource == -1 && key) { EVP_PKEY_free(key); } if (certresource == -1 && cert) { X509_free(cert); } }
@@ -1398,6 +1398,74 @@ PHP_FUNCTION(openssl_x509_check_private_key) } /* }}} */ +/* Special handling of subjectAltName, see CVE-2013-4073 + * Christian Heimes + */ + +static int openssl_x509v3_subjectAltName(BIO *bio, X509_EXTENSION *extension) +{ + GENERAL_NAMES *names; + const X509V3_EXT_METHOD *method = NULL; + long i, length, num; + const unsigned char *p; + + method = X509V3_EXT_get(extension); + if (method == NULL) { + return -1; + } + + p = extension->value->data; + length = extension->value->length; + if (method->it) { + names = (GENERAL_NAMES*)(ASN1_item_d2i(NULL, &p, length, + ASN1_ITEM_ptr(method->it))); + } else { + names = (GENERAL_NAMES*)(method->d2i(NULL, &p, length)); + } + if (names == NULL) { + return -1; + } + + num = sk_GENERAL_NAME_num(names); + for (i = 0; i < num; i++) { + GENERAL_NAME *name; + ASN1_STRING *as; + name = sk_GENERAL_NAME_value(names, i); + switch (name->type) { + case GEN_EMAIL: + BIO_puts(bio, "email:"); + as = name->d.rfc822Name; + BIO_write(bio, ASN1_STRING_data(as), + ASN1_STRING_length(as)); + break; + case GEN_DNS: + BIO_puts(bio, "DNS:"); + as = name->d.dNSName; + BIO_write(bio, ASN1_STRING_data(as), + ASN1_STRING_length(as)); + break; + case GEN_URI: + BIO_puts(bio, "URI:"); + as = name->d.uniformResourceIdentifier; + BIO_write(bio, ASN1_STRING_data(as), + ASN1_STRING_length(as)); + break; + default: + /* use builtin print for GEN_OTHERNAME, GEN_X400, + * GEN_EDIPARTY, GEN_DIRNAME, GEN_IPADD and GEN_RID + */ + GENERAL_NAME_print(bio, name); + } + /* trailing ', ' except for last element */ + if (i < (num - 1)) { + BIO_puts(bio, ", "); + } + } + sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free); + + return 0; +} + /* {{{ proto array openssl_x509_parse(mixed x509 [, bool shortnames=true]) Returns an array of the fields/values of the CERT */ PHP_FUNCTION(openssl_x509_parse) @@ -1494,15 +1562,29 @@ PHP_FUNCTION(openssl_x509_parse) for (i = 0; i < X509_get_ext_count(cert); i++) { + int nid; extension = X509_get_ext(cert, i); - if (OBJ_obj2nid(X509_EXTENSION_get_object(extension)) != NID_undef) { + nid = OBJ_obj2nid(X509_EXTENSION_get_object(extension)); + if (nid != NID_undef) { extname = (char *)OBJ_nid2sn(OBJ_obj2nid(X509_EXTENSION_get_object(extension))); } else { OBJ_obj2txt(buf, sizeof(buf)-1, X509_EXTENSION_get_object(extension), 1); extname = buf; } bio_out = BIO_new(BIO_s_mem()); - if (X509V3_EXT_print(bio_out, extension, 0, 0)) { + if (nid == NID_subject_alt_name) { + if (openssl_x509v3_subjectAltName(bio_out, extension) == 0) { + add_assoc_stringl(subitem, extname, bio_buf->data, bio_buf->length, 1); + } else { + zval_dtor(return_value); + if (certresource == -1 && cert) { + X509_free(cert); + } + BIO_free(bio_out); + RETURN_FALSE; + } + } + else if (X509V3_EXT_print(bio_out, extension, 0, 0)) { BIO_get_mem_ptr(bio_out, &bio_buf); add_assoc_stringl(subitem, extname, bio_buf->data, bio_buf->length, 1); } else {
CWE-20
null
null
1,602
PHP_MINIT_FUNCTION(openssl) { char * config_filename; le_key = zend_register_list_destructors_ex(php_pkey_free, NULL, "OpenSSL key", module_number); le_x509 = zend_register_list_destructors_ex(php_x509_free, NULL, "OpenSSL X.509", module_number); le_csr = zend_register_list_destructors_ex(php_csr_free, NULL, "OpenSSL X.509 CSR", module_number); SSL_library_init(); OpenSSL_add_all_ciphers(); OpenSSL_add_all_digests(); OpenSSL_add_all_algorithms(); SSL_load_error_strings(); /* register a resource id number with OpenSSL so that we can map SSL -> stream structures in * OpenSSL callbacks */ ssl_stream_data_index = SSL_get_ex_new_index(0, "PHP stream index", NULL, NULL, NULL); REGISTER_STRING_CONSTANT("OPENSSL_VERSION_TEXT", OPENSSL_VERSION_TEXT, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_VERSION_NUMBER", OPENSSL_VERSION_NUMBER, CONST_CS|CONST_PERSISTENT); /* purposes for cert purpose checking */ REGISTER_LONG_CONSTANT("X509_PURPOSE_SSL_CLIENT", X509_PURPOSE_SSL_CLIENT, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("X509_PURPOSE_SSL_SERVER", X509_PURPOSE_SSL_SERVER, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("X509_PURPOSE_NS_SSL_SERVER", X509_PURPOSE_NS_SSL_SERVER, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("X509_PURPOSE_SMIME_SIGN", X509_PURPOSE_SMIME_SIGN, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("X509_PURPOSE_SMIME_ENCRYPT", X509_PURPOSE_SMIME_ENCRYPT, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("X509_PURPOSE_CRL_SIGN", X509_PURPOSE_CRL_SIGN, CONST_CS|CONST_PERSISTENT); #ifdef X509_PURPOSE_ANY REGISTER_LONG_CONSTANT("X509_PURPOSE_ANY", X509_PURPOSE_ANY, CONST_CS|CONST_PERSISTENT); #endif /* signature algorithm constants */ REGISTER_LONG_CONSTANT("OPENSSL_ALGO_SHA1", OPENSSL_ALGO_SHA1, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_ALGO_MD5", OPENSSL_ALGO_MD5, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_ALGO_MD4", OPENSSL_ALGO_MD4, CONST_CS|CONST_PERSISTENT); #ifdef HAVE_OPENSSL_MD2_H REGISTER_LONG_CONSTANT("OPENSSL_ALGO_MD2", OPENSSL_ALGO_MD2, CONST_CS|CONST_PERSISTENT); #endif REGISTER_LONG_CONSTANT("OPENSSL_ALGO_DSS1", OPENSSL_ALGO_DSS1, CONST_CS|CONST_PERSISTENT); #if OPENSSL_VERSION_NUMBER >= 0x0090708fL REGISTER_LONG_CONSTANT("OPENSSL_ALGO_SHA224", OPENSSL_ALGO_SHA224, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_ALGO_SHA256", OPENSSL_ALGO_SHA256, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_ALGO_SHA384", OPENSSL_ALGO_SHA384, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_ALGO_SHA512", OPENSSL_ALGO_SHA512, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_ALGO_RMD160", OPENSSL_ALGO_RMD160, CONST_CS|CONST_PERSISTENT); #endif /* flags for S/MIME */ REGISTER_LONG_CONSTANT("PKCS7_DETACHED", PKCS7_DETACHED, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PKCS7_TEXT", PKCS7_TEXT, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PKCS7_NOINTERN", PKCS7_NOINTERN, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PKCS7_NOVERIFY", PKCS7_NOVERIFY, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PKCS7_NOCHAIN", PKCS7_NOCHAIN, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PKCS7_NOCERTS", PKCS7_NOCERTS, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PKCS7_NOATTR", PKCS7_NOATTR, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PKCS7_BINARY", PKCS7_BINARY, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PKCS7_NOSIGS", PKCS7_NOSIGS, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_PKCS1_PADDING", RSA_PKCS1_PADDING, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_SSLV23_PADDING", RSA_SSLV23_PADDING, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_NO_PADDING", RSA_NO_PADDING, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_PKCS1_OAEP_PADDING", RSA_PKCS1_OAEP_PADDING, CONST_CS|CONST_PERSISTENT); /* Ciphers */ #ifndef OPENSSL_NO_RC2 REGISTER_LONG_CONSTANT("OPENSSL_CIPHER_RC2_40", PHP_OPENSSL_CIPHER_RC2_40, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_CIPHER_RC2_128", PHP_OPENSSL_CIPHER_RC2_128, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_CIPHER_RC2_64", PHP_OPENSSL_CIPHER_RC2_64, CONST_CS|CONST_PERSISTENT); #endif #ifndef OPENSSL_NO_DES REGISTER_LONG_CONSTANT("OPENSSL_CIPHER_DES", PHP_OPENSSL_CIPHER_DES, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_CIPHER_3DES", PHP_OPENSSL_CIPHER_3DES, CONST_CS|CONST_PERSISTENT); #endif #ifndef OPENSSL_NO_AES REGISTER_LONG_CONSTANT("OPENSSL_CIPHER_AES_128_CBC", PHP_OPENSSL_CIPHER_AES_128_CBC, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_CIPHER_AES_192_CBC", PHP_OPENSSL_CIPHER_AES_192_CBC, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_CIPHER_AES_256_CBC", PHP_OPENSSL_CIPHER_AES_256_CBC, CONST_CS|CONST_PERSISTENT); #endif /* Values for key types */ REGISTER_LONG_CONSTANT("OPENSSL_KEYTYPE_RSA", OPENSSL_KEYTYPE_RSA, CONST_CS|CONST_PERSISTENT); #ifndef NO_DSA REGISTER_LONG_CONSTANT("OPENSSL_KEYTYPE_DSA", OPENSSL_KEYTYPE_DSA, CONST_CS|CONST_PERSISTENT); #endif REGISTER_LONG_CONSTANT("OPENSSL_KEYTYPE_DH", OPENSSL_KEYTYPE_DH, CONST_CS|CONST_PERSISTENT); #ifdef EVP_PKEY_EC REGISTER_LONG_CONSTANT("OPENSSL_KEYTYPE_EC", OPENSSL_KEYTYPE_EC, CONST_CS|CONST_PERSISTENT); #endif REGISTER_LONG_CONSTANT("OPENSSL_RAW_DATA", OPENSSL_RAW_DATA, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_ZERO_PADDING", OPENSSL_ZERO_PADDING, CONST_CS|CONST_PERSISTENT); #if OPENSSL_VERSION_NUMBER >= 0x0090806fL && !defined(OPENSSL_NO_TLSEXT) /* SNI support included in OpenSSL >= 0.9.8j */ REGISTER_LONG_CONSTANT("OPENSSL_TLSEXT_SERVER_NAME", 1, CONST_CS|CONST_PERSISTENT); #endif /* Determine default SSL configuration file */ config_filename = getenv("OPENSSL_CONF"); if (config_filename == NULL) { config_filename = getenv("SSLEAY_CONF"); } /* default to 'openssl.cnf' if no environment variable is set */ if (config_filename == NULL) { snprintf(default_ssl_conf_filename, sizeof(default_ssl_conf_filename), "%s/%s", X509_get_default_cert_area(), "openssl.cnf"); } else { strlcpy(default_ssl_conf_filename, config_filename, sizeof(default_ssl_conf_filename)); } php_stream_xport_register("ssl", php_openssl_ssl_socket_factory TSRMLS_CC); php_stream_xport_register("sslv3", php_openssl_ssl_socket_factory TSRMLS_CC); #ifndef OPENSSL_NO_SSL2 php_stream_xport_register("sslv2", php_openssl_ssl_socket_factory TSRMLS_CC); #endif php_stream_xport_register("tls", php_openssl_ssl_socket_factory TSRMLS_CC); /* override the default tcp socket provider */ php_stream_xport_register("tcp", php_openssl_ssl_socket_factory TSRMLS_CC); php_register_url_stream_wrapper("https", &php_stream_http_wrapper TSRMLS_CC); php_register_url_stream_wrapper("ftps", &php_stream_ftp_wrapper TSRMLS_CC); return SUCCESS; }
null
0
PHP_MINIT_FUNCTION(openssl) { char * config_filename; le_key = zend_register_list_destructors_ex(php_pkey_free, NULL, "OpenSSL key", module_number); le_x509 = zend_register_list_destructors_ex(php_x509_free, NULL, "OpenSSL X.509", module_number); le_csr = zend_register_list_destructors_ex(php_csr_free, NULL, "OpenSSL X.509 CSR", module_number); SSL_library_init(); OpenSSL_add_all_ciphers(); OpenSSL_add_all_digests(); OpenSSL_add_all_algorithms(); SSL_load_error_strings(); /* register a resource id number with OpenSSL so that we can map SSL -> stream structures in * OpenSSL callbacks */ ssl_stream_data_index = SSL_get_ex_new_index(0, "PHP stream index", NULL, NULL, NULL); REGISTER_STRING_CONSTANT("OPENSSL_VERSION_TEXT", OPENSSL_VERSION_TEXT, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_VERSION_NUMBER", OPENSSL_VERSION_NUMBER, CONST_CS|CONST_PERSISTENT); /* purposes for cert purpose checking */ REGISTER_LONG_CONSTANT("X509_PURPOSE_SSL_CLIENT", X509_PURPOSE_SSL_CLIENT, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("X509_PURPOSE_SSL_SERVER", X509_PURPOSE_SSL_SERVER, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("X509_PURPOSE_NS_SSL_SERVER", X509_PURPOSE_NS_SSL_SERVER, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("X509_PURPOSE_SMIME_SIGN", X509_PURPOSE_SMIME_SIGN, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("X509_PURPOSE_SMIME_ENCRYPT", X509_PURPOSE_SMIME_ENCRYPT, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("X509_PURPOSE_CRL_SIGN", X509_PURPOSE_CRL_SIGN, CONST_CS|CONST_PERSISTENT); #ifdef X509_PURPOSE_ANY REGISTER_LONG_CONSTANT("X509_PURPOSE_ANY", X509_PURPOSE_ANY, CONST_CS|CONST_PERSISTENT); #endif /* signature algorithm constants */ REGISTER_LONG_CONSTANT("OPENSSL_ALGO_SHA1", OPENSSL_ALGO_SHA1, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_ALGO_MD5", OPENSSL_ALGO_MD5, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_ALGO_MD4", OPENSSL_ALGO_MD4, CONST_CS|CONST_PERSISTENT); #ifdef HAVE_OPENSSL_MD2_H REGISTER_LONG_CONSTANT("OPENSSL_ALGO_MD2", OPENSSL_ALGO_MD2, CONST_CS|CONST_PERSISTENT); #endif REGISTER_LONG_CONSTANT("OPENSSL_ALGO_DSS1", OPENSSL_ALGO_DSS1, CONST_CS|CONST_PERSISTENT); #if OPENSSL_VERSION_NUMBER >= 0x0090708fL REGISTER_LONG_CONSTANT("OPENSSL_ALGO_SHA224", OPENSSL_ALGO_SHA224, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_ALGO_SHA256", OPENSSL_ALGO_SHA256, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_ALGO_SHA384", OPENSSL_ALGO_SHA384, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_ALGO_SHA512", OPENSSL_ALGO_SHA512, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_ALGO_RMD160", OPENSSL_ALGO_RMD160, CONST_CS|CONST_PERSISTENT); #endif /* flags for S/MIME */ REGISTER_LONG_CONSTANT("PKCS7_DETACHED", PKCS7_DETACHED, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PKCS7_TEXT", PKCS7_TEXT, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PKCS7_NOINTERN", PKCS7_NOINTERN, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PKCS7_NOVERIFY", PKCS7_NOVERIFY, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PKCS7_NOCHAIN", PKCS7_NOCHAIN, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PKCS7_NOCERTS", PKCS7_NOCERTS, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PKCS7_NOATTR", PKCS7_NOATTR, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PKCS7_BINARY", PKCS7_BINARY, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PKCS7_NOSIGS", PKCS7_NOSIGS, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_PKCS1_PADDING", RSA_PKCS1_PADDING, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_SSLV23_PADDING", RSA_SSLV23_PADDING, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_NO_PADDING", RSA_NO_PADDING, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_PKCS1_OAEP_PADDING", RSA_PKCS1_OAEP_PADDING, CONST_CS|CONST_PERSISTENT); /* Ciphers */ #ifndef OPENSSL_NO_RC2 REGISTER_LONG_CONSTANT("OPENSSL_CIPHER_RC2_40", PHP_OPENSSL_CIPHER_RC2_40, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_CIPHER_RC2_128", PHP_OPENSSL_CIPHER_RC2_128, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_CIPHER_RC2_64", PHP_OPENSSL_CIPHER_RC2_64, CONST_CS|CONST_PERSISTENT); #endif #ifndef OPENSSL_NO_DES REGISTER_LONG_CONSTANT("OPENSSL_CIPHER_DES", PHP_OPENSSL_CIPHER_DES, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_CIPHER_3DES", PHP_OPENSSL_CIPHER_3DES, CONST_CS|CONST_PERSISTENT); #endif #ifndef OPENSSL_NO_AES REGISTER_LONG_CONSTANT("OPENSSL_CIPHER_AES_128_CBC", PHP_OPENSSL_CIPHER_AES_128_CBC, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_CIPHER_AES_192_CBC", PHP_OPENSSL_CIPHER_AES_192_CBC, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_CIPHER_AES_256_CBC", PHP_OPENSSL_CIPHER_AES_256_CBC, CONST_CS|CONST_PERSISTENT); #endif /* Values for key types */ REGISTER_LONG_CONSTANT("OPENSSL_KEYTYPE_RSA", OPENSSL_KEYTYPE_RSA, CONST_CS|CONST_PERSISTENT); #ifndef NO_DSA REGISTER_LONG_CONSTANT("OPENSSL_KEYTYPE_DSA", OPENSSL_KEYTYPE_DSA, CONST_CS|CONST_PERSISTENT); #endif REGISTER_LONG_CONSTANT("OPENSSL_KEYTYPE_DH", OPENSSL_KEYTYPE_DH, CONST_CS|CONST_PERSISTENT); #ifdef EVP_PKEY_EC REGISTER_LONG_CONSTANT("OPENSSL_KEYTYPE_EC", OPENSSL_KEYTYPE_EC, CONST_CS|CONST_PERSISTENT); #endif REGISTER_LONG_CONSTANT("OPENSSL_RAW_DATA", OPENSSL_RAW_DATA, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_ZERO_PADDING", OPENSSL_ZERO_PADDING, CONST_CS|CONST_PERSISTENT); #if OPENSSL_VERSION_NUMBER >= 0x0090806fL && !defined(OPENSSL_NO_TLSEXT) /* SNI support included in OpenSSL >= 0.9.8j */ REGISTER_LONG_CONSTANT("OPENSSL_TLSEXT_SERVER_NAME", 1, CONST_CS|CONST_PERSISTENT); #endif /* Determine default SSL configuration file */ config_filename = getenv("OPENSSL_CONF"); if (config_filename == NULL) { config_filename = getenv("SSLEAY_CONF"); } /* default to 'openssl.cnf' if no environment variable is set */ if (config_filename == NULL) { snprintf(default_ssl_conf_filename, sizeof(default_ssl_conf_filename), "%s/%s", X509_get_default_cert_area(), "openssl.cnf"); } else { strlcpy(default_ssl_conf_filename, config_filename, sizeof(default_ssl_conf_filename)); } php_stream_xport_register("ssl", php_openssl_ssl_socket_factory TSRMLS_CC); php_stream_xport_register("sslv3", php_openssl_ssl_socket_factory TSRMLS_CC); #ifndef OPENSSL_NO_SSL2 php_stream_xport_register("sslv2", php_openssl_ssl_socket_factory TSRMLS_CC); #endif php_stream_xport_register("tls", php_openssl_ssl_socket_factory TSRMLS_CC); /* override the default tcp socket provider */ php_stream_xport_register("tcp", php_openssl_ssl_socket_factory TSRMLS_CC); php_register_url_stream_wrapper("https", &php_stream_http_wrapper TSRMLS_CC); php_register_url_stream_wrapper("ftps", &php_stream_ftp_wrapper TSRMLS_CC); return SUCCESS; }
@@ -1398,6 +1398,74 @@ PHP_FUNCTION(openssl_x509_check_private_key) } /* }}} */ +/* Special handling of subjectAltName, see CVE-2013-4073 + * Christian Heimes + */ + +static int openssl_x509v3_subjectAltName(BIO *bio, X509_EXTENSION *extension) +{ + GENERAL_NAMES *names; + const X509V3_EXT_METHOD *method = NULL; + long i, length, num; + const unsigned char *p; + + method = X509V3_EXT_get(extension); + if (method == NULL) { + return -1; + } + + p = extension->value->data; + length = extension->value->length; + if (method->it) { + names = (GENERAL_NAMES*)(ASN1_item_d2i(NULL, &p, length, + ASN1_ITEM_ptr(method->it))); + } else { + names = (GENERAL_NAMES*)(method->d2i(NULL, &p, length)); + } + if (names == NULL) { + return -1; + } + + num = sk_GENERAL_NAME_num(names); + for (i = 0; i < num; i++) { + GENERAL_NAME *name; + ASN1_STRING *as; + name = sk_GENERAL_NAME_value(names, i); + switch (name->type) { + case GEN_EMAIL: + BIO_puts(bio, "email:"); + as = name->d.rfc822Name; + BIO_write(bio, ASN1_STRING_data(as), + ASN1_STRING_length(as)); + break; + case GEN_DNS: + BIO_puts(bio, "DNS:"); + as = name->d.dNSName; + BIO_write(bio, ASN1_STRING_data(as), + ASN1_STRING_length(as)); + break; + case GEN_URI: + BIO_puts(bio, "URI:"); + as = name->d.uniformResourceIdentifier; + BIO_write(bio, ASN1_STRING_data(as), + ASN1_STRING_length(as)); + break; + default: + /* use builtin print for GEN_OTHERNAME, GEN_X400, + * GEN_EDIPARTY, GEN_DIRNAME, GEN_IPADD and GEN_RID + */ + GENERAL_NAME_print(bio, name); + } + /* trailing ', ' except for last element */ + if (i < (num - 1)) { + BIO_puts(bio, ", "); + } + } + sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free); + + return 0; +} + /* {{{ proto array openssl_x509_parse(mixed x509 [, bool shortnames=true]) Returns an array of the fields/values of the CERT */ PHP_FUNCTION(openssl_x509_parse) @@ -1494,15 +1562,29 @@ PHP_FUNCTION(openssl_x509_parse) for (i = 0; i < X509_get_ext_count(cert); i++) { + int nid; extension = X509_get_ext(cert, i); - if (OBJ_obj2nid(X509_EXTENSION_get_object(extension)) != NID_undef) { + nid = OBJ_obj2nid(X509_EXTENSION_get_object(extension)); + if (nid != NID_undef) { extname = (char *)OBJ_nid2sn(OBJ_obj2nid(X509_EXTENSION_get_object(extension))); } else { OBJ_obj2txt(buf, sizeof(buf)-1, X509_EXTENSION_get_object(extension), 1); extname = buf; } bio_out = BIO_new(BIO_s_mem()); - if (X509V3_EXT_print(bio_out, extension, 0, 0)) { + if (nid == NID_subject_alt_name) { + if (openssl_x509v3_subjectAltName(bio_out, extension) == 0) { + add_assoc_stringl(subitem, extname, bio_buf->data, bio_buf->length, 1); + } else { + zval_dtor(return_value); + if (certresource == -1 && cert) { + X509_free(cert); + } + BIO_free(bio_out); + RETURN_FALSE; + } + } + else if (X509V3_EXT_print(bio_out, extension, 0, 0)) { BIO_get_mem_ptr(bio_out, &bio_buf); add_assoc_stringl(subitem, extname, bio_buf->data, bio_buf->length, 1); } else {
CWE-20
null
null
1,603
static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC) /* {{{ */ { /* This is how the time string is formatted: snprintf(p, sizeof(p), "%02d%02d%02d%02d%02d%02dZ",ts->tm_year%100, ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); */ time_t ret; struct tm thetime; char * strbuf; char * thestr; long gmadjust = 0; if (timestr->length < 13) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "extension author too lazy to parse %s correctly", timestr->data); return (time_t)-1; } strbuf = estrdup((char *)timestr->data); memset(&thetime, 0, sizeof(thetime)); /* we work backwards so that we can use atoi more easily */ thestr = strbuf + timestr->length - 3; thetime.tm_sec = atoi(thestr); *thestr = '\0'; thestr -= 2; thetime.tm_min = atoi(thestr); *thestr = '\0'; thestr -= 2; thetime.tm_hour = atoi(thestr); *thestr = '\0'; thestr -= 2; thetime.tm_mday = atoi(thestr); *thestr = '\0'; thestr -= 2; thetime.tm_mon = atoi(thestr)-1; *thestr = '\0'; thestr -= 2; thetime.tm_year = atoi(thestr); if (thetime.tm_year < 68) { thetime.tm_year += 100; } thetime.tm_isdst = -1; ret = mktime(&thetime); #if HAVE_TM_GMTOFF gmadjust = thetime.tm_gmtoff; #else /* ** If correcting for daylight savings time, we set the adjustment to ** the value of timezone - 3600 seconds. Otherwise, we need to overcorrect and ** set the adjustment to the main timezone + 3600 seconds. */ gmadjust = -(thetime.tm_isdst ? (long)timezone - 3600 : (long)timezone + 3600); #endif ret += gmadjust; efree(strbuf); return ret; } /* }}} */
null
0
static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC) /* {{{ */ { /* This is how the time string is formatted: snprintf(p, sizeof(p), "%02d%02d%02d%02d%02d%02dZ",ts->tm_year%100, ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); */ time_t ret; struct tm thetime; char * strbuf; char * thestr; long gmadjust = 0; if (timestr->length < 13) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "extension author too lazy to parse %s correctly", timestr->data); return (time_t)-1; } strbuf = estrdup((char *)timestr->data); memset(&thetime, 0, sizeof(thetime)); /* we work backwards so that we can use atoi more easily */ thestr = strbuf + timestr->length - 3; thetime.tm_sec = atoi(thestr); *thestr = '\0'; thestr -= 2; thetime.tm_min = atoi(thestr); *thestr = '\0'; thestr -= 2; thetime.tm_hour = atoi(thestr); *thestr = '\0'; thestr -= 2; thetime.tm_mday = atoi(thestr); *thestr = '\0'; thestr -= 2; thetime.tm_mon = atoi(thestr)-1; *thestr = '\0'; thestr -= 2; thetime.tm_year = atoi(thestr); if (thetime.tm_year < 68) { thetime.tm_year += 100; } thetime.tm_isdst = -1; ret = mktime(&thetime); #if HAVE_TM_GMTOFF gmadjust = thetime.tm_gmtoff; #else /* ** If correcting for daylight savings time, we set the adjustment to ** the value of timezone - 3600 seconds. Otherwise, we need to overcorrect and ** set the adjustment to the main timezone + 3600 seconds. */ gmadjust = -(thetime.tm_isdst ? (long)timezone - 3600 : (long)timezone + 3600); #endif ret += gmadjust; efree(strbuf); return ret; } /* }}} */
@@ -1398,6 +1398,74 @@ PHP_FUNCTION(openssl_x509_check_private_key) } /* }}} */ +/* Special handling of subjectAltName, see CVE-2013-4073 + * Christian Heimes + */ + +static int openssl_x509v3_subjectAltName(BIO *bio, X509_EXTENSION *extension) +{ + GENERAL_NAMES *names; + const X509V3_EXT_METHOD *method = NULL; + long i, length, num; + const unsigned char *p; + + method = X509V3_EXT_get(extension); + if (method == NULL) { + return -1; + } + + p = extension->value->data; + length = extension->value->length; + if (method->it) { + names = (GENERAL_NAMES*)(ASN1_item_d2i(NULL, &p, length, + ASN1_ITEM_ptr(method->it))); + } else { + names = (GENERAL_NAMES*)(method->d2i(NULL, &p, length)); + } + if (names == NULL) { + return -1; + } + + num = sk_GENERAL_NAME_num(names); + for (i = 0; i < num; i++) { + GENERAL_NAME *name; + ASN1_STRING *as; + name = sk_GENERAL_NAME_value(names, i); + switch (name->type) { + case GEN_EMAIL: + BIO_puts(bio, "email:"); + as = name->d.rfc822Name; + BIO_write(bio, ASN1_STRING_data(as), + ASN1_STRING_length(as)); + break; + case GEN_DNS: + BIO_puts(bio, "DNS:"); + as = name->d.dNSName; + BIO_write(bio, ASN1_STRING_data(as), + ASN1_STRING_length(as)); + break; + case GEN_URI: + BIO_puts(bio, "URI:"); + as = name->d.uniformResourceIdentifier; + BIO_write(bio, ASN1_STRING_data(as), + ASN1_STRING_length(as)); + break; + default: + /* use builtin print for GEN_OTHERNAME, GEN_X400, + * GEN_EDIPARTY, GEN_DIRNAME, GEN_IPADD and GEN_RID + */ + GENERAL_NAME_print(bio, name); + } + /* trailing ', ' except for last element */ + if (i < (num - 1)) { + BIO_puts(bio, ", "); + } + } + sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free); + + return 0; +} + /* {{{ proto array openssl_x509_parse(mixed x509 [, bool shortnames=true]) Returns an array of the fields/values of the CERT */ PHP_FUNCTION(openssl_x509_parse) @@ -1494,15 +1562,29 @@ PHP_FUNCTION(openssl_x509_parse) for (i = 0; i < X509_get_ext_count(cert); i++) { + int nid; extension = X509_get_ext(cert, i); - if (OBJ_obj2nid(X509_EXTENSION_get_object(extension)) != NID_undef) { + nid = OBJ_obj2nid(X509_EXTENSION_get_object(extension)); + if (nid != NID_undef) { extname = (char *)OBJ_nid2sn(OBJ_obj2nid(X509_EXTENSION_get_object(extension))); } else { OBJ_obj2txt(buf, sizeof(buf)-1, X509_EXTENSION_get_object(extension), 1); extname = buf; } bio_out = BIO_new(BIO_s_mem()); - if (X509V3_EXT_print(bio_out, extension, 0, 0)) { + if (nid == NID_subject_alt_name) { + if (openssl_x509v3_subjectAltName(bio_out, extension) == 0) { + add_assoc_stringl(subitem, extname, bio_buf->data, bio_buf->length, 1); + } else { + zval_dtor(return_value); + if (certresource == -1 && cert) { + X509_free(cert); + } + BIO_free(bio_out); + RETURN_FALSE; + } + } + else if (X509V3_EXT_print(bio_out, extension, 0, 0)) { BIO_get_mem_ptr(bio_out, &bio_buf); add_assoc_stringl(subitem, extname, bio_buf->data, bio_buf->length, 1); } else {
CWE-20
null
null
1,604
static int php_openssl_load_rand_file(const char * file, int *egdsocket, int *seeded TSRMLS_DC) /* {{{ */ { char buffer[MAXPATHLEN]; *egdsocket = 0; *seeded = 0; if (file == NULL) { file = RAND_file_name(buffer, sizeof(buffer)); } else if (RAND_egd(file) > 0) { /* if the given filename is an EGD socket, don't * write anything back to it */ *egdsocket = 1; return SUCCESS; } if (file == NULL || !RAND_load_file(file, -1)) { if (RAND_status() == 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to load random state; not enough random data!"); return FAILURE; } return FAILURE; } *seeded = 1; return SUCCESS; } /* }}} */
null
0
static int php_openssl_load_rand_file(const char * file, int *egdsocket, int *seeded TSRMLS_DC) /* {{{ */ { char buffer[MAXPATHLEN]; *egdsocket = 0; *seeded = 0; if (file == NULL) { file = RAND_file_name(buffer, sizeof(buffer)); } else if (RAND_egd(file) > 0) { /* if the given filename is an EGD socket, don't * write anything back to it */ *egdsocket = 1; return SUCCESS; } if (file == NULL || !RAND_load_file(file, -1)) { if (RAND_status() == 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to load random state; not enough random data!"); return FAILURE; } return FAILURE; } *seeded = 1; return SUCCESS; } /* }}} */
@@ -1398,6 +1398,74 @@ PHP_FUNCTION(openssl_x509_check_private_key) } /* }}} */ +/* Special handling of subjectAltName, see CVE-2013-4073 + * Christian Heimes + */ + +static int openssl_x509v3_subjectAltName(BIO *bio, X509_EXTENSION *extension) +{ + GENERAL_NAMES *names; + const X509V3_EXT_METHOD *method = NULL; + long i, length, num; + const unsigned char *p; + + method = X509V3_EXT_get(extension); + if (method == NULL) { + return -1; + } + + p = extension->value->data; + length = extension->value->length; + if (method->it) { + names = (GENERAL_NAMES*)(ASN1_item_d2i(NULL, &p, length, + ASN1_ITEM_ptr(method->it))); + } else { + names = (GENERAL_NAMES*)(method->d2i(NULL, &p, length)); + } + if (names == NULL) { + return -1; + } + + num = sk_GENERAL_NAME_num(names); + for (i = 0; i < num; i++) { + GENERAL_NAME *name; + ASN1_STRING *as; + name = sk_GENERAL_NAME_value(names, i); + switch (name->type) { + case GEN_EMAIL: + BIO_puts(bio, "email:"); + as = name->d.rfc822Name; + BIO_write(bio, ASN1_STRING_data(as), + ASN1_STRING_length(as)); + break; + case GEN_DNS: + BIO_puts(bio, "DNS:"); + as = name->d.dNSName; + BIO_write(bio, ASN1_STRING_data(as), + ASN1_STRING_length(as)); + break; + case GEN_URI: + BIO_puts(bio, "URI:"); + as = name->d.uniformResourceIdentifier; + BIO_write(bio, ASN1_STRING_data(as), + ASN1_STRING_length(as)); + break; + default: + /* use builtin print for GEN_OTHERNAME, GEN_X400, + * GEN_EDIPARTY, GEN_DIRNAME, GEN_IPADD and GEN_RID + */ + GENERAL_NAME_print(bio, name); + } + /* trailing ', ' except for last element */ + if (i < (num - 1)) { + BIO_puts(bio, ", "); + } + } + sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free); + + return 0; +} + /* {{{ proto array openssl_x509_parse(mixed x509 [, bool shortnames=true]) Returns an array of the fields/values of the CERT */ PHP_FUNCTION(openssl_x509_parse) @@ -1494,15 +1562,29 @@ PHP_FUNCTION(openssl_x509_parse) for (i = 0; i < X509_get_ext_count(cert); i++) { + int nid; extension = X509_get_ext(cert, i); - if (OBJ_obj2nid(X509_EXTENSION_get_object(extension)) != NID_undef) { + nid = OBJ_obj2nid(X509_EXTENSION_get_object(extension)); + if (nid != NID_undef) { extname = (char *)OBJ_nid2sn(OBJ_obj2nid(X509_EXTENSION_get_object(extension))); } else { OBJ_obj2txt(buf, sizeof(buf)-1, X509_EXTENSION_get_object(extension), 1); extname = buf; } bio_out = BIO_new(BIO_s_mem()); - if (X509V3_EXT_print(bio_out, extension, 0, 0)) { + if (nid == NID_subject_alt_name) { + if (openssl_x509v3_subjectAltName(bio_out, extension) == 0) { + add_assoc_stringl(subitem, extname, bio_buf->data, bio_buf->length, 1); + } else { + zval_dtor(return_value); + if (certresource == -1 && cert) { + X509_free(cert); + } + BIO_free(bio_out); + RETURN_FALSE; + } + } + else if (X509V3_EXT_print(bio_out, extension, 0, 0)) { BIO_get_mem_ptr(bio_out, &bio_buf); add_assoc_stringl(subitem, extname, bio_buf->data, bio_buf->length, 1); } else {
CWE-20
null
null
1,605
inline static int php_openssl_open_base_dir_chk(char *filename TSRMLS_DC) { if (php_check_open_basedir(filename TSRMLS_CC)) { return -1; } return 0; }
null
0
inline static int php_openssl_open_base_dir_chk(char *filename TSRMLS_DC) { if (php_check_open_basedir(filename TSRMLS_CC)) { return -1; } return 0; }
@@ -1398,6 +1398,74 @@ PHP_FUNCTION(openssl_x509_check_private_key) } /* }}} */ +/* Special handling of subjectAltName, see CVE-2013-4073 + * Christian Heimes + */ + +static int openssl_x509v3_subjectAltName(BIO *bio, X509_EXTENSION *extension) +{ + GENERAL_NAMES *names; + const X509V3_EXT_METHOD *method = NULL; + long i, length, num; + const unsigned char *p; + + method = X509V3_EXT_get(extension); + if (method == NULL) { + return -1; + } + + p = extension->value->data; + length = extension->value->length; + if (method->it) { + names = (GENERAL_NAMES*)(ASN1_item_d2i(NULL, &p, length, + ASN1_ITEM_ptr(method->it))); + } else { + names = (GENERAL_NAMES*)(method->d2i(NULL, &p, length)); + } + if (names == NULL) { + return -1; + } + + num = sk_GENERAL_NAME_num(names); + for (i = 0; i < num; i++) { + GENERAL_NAME *name; + ASN1_STRING *as; + name = sk_GENERAL_NAME_value(names, i); + switch (name->type) { + case GEN_EMAIL: + BIO_puts(bio, "email:"); + as = name->d.rfc822Name; + BIO_write(bio, ASN1_STRING_data(as), + ASN1_STRING_length(as)); + break; + case GEN_DNS: + BIO_puts(bio, "DNS:"); + as = name->d.dNSName; + BIO_write(bio, ASN1_STRING_data(as), + ASN1_STRING_length(as)); + break; + case GEN_URI: + BIO_puts(bio, "URI:"); + as = name->d.uniformResourceIdentifier; + BIO_write(bio, ASN1_STRING_data(as), + ASN1_STRING_length(as)); + break; + default: + /* use builtin print for GEN_OTHERNAME, GEN_X400, + * GEN_EDIPARTY, GEN_DIRNAME, GEN_IPADD and GEN_RID + */ + GENERAL_NAME_print(bio, name); + } + /* trailing ', ' except for last element */ + if (i < (num - 1)) { + BIO_puts(bio, ", "); + } + } + sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free); + + return 0; +} + /* {{{ proto array openssl_x509_parse(mixed x509 [, bool shortnames=true]) Returns an array of the fields/values of the CERT */ PHP_FUNCTION(openssl_x509_parse) @@ -1494,15 +1562,29 @@ PHP_FUNCTION(openssl_x509_parse) for (i = 0; i < X509_get_ext_count(cert); i++) { + int nid; extension = X509_get_ext(cert, i); - if (OBJ_obj2nid(X509_EXTENSION_get_object(extension)) != NID_undef) { + nid = OBJ_obj2nid(X509_EXTENSION_get_object(extension)); + if (nid != NID_undef) { extname = (char *)OBJ_nid2sn(OBJ_obj2nid(X509_EXTENSION_get_object(extension))); } else { OBJ_obj2txt(buf, sizeof(buf)-1, X509_EXTENSION_get_object(extension), 1); extname = buf; } bio_out = BIO_new(BIO_s_mem()); - if (X509V3_EXT_print(bio_out, extension, 0, 0)) { + if (nid == NID_subject_alt_name) { + if (openssl_x509v3_subjectAltName(bio_out, extension) == 0) { + add_assoc_stringl(subitem, extname, bio_buf->data, bio_buf->length, 1); + } else { + zval_dtor(return_value); + if (certresource == -1 && cert) { + X509_free(cert); + } + BIO_free(bio_out); + RETURN_FALSE; + } + } + else if (X509V3_EXT_print(bio_out, extension, 0, 0)) { BIO_get_mem_ptr(bio_out, &bio_buf); add_assoc_stringl(subitem, extname, bio_buf->data, bio_buf->length, 1); } else {
CWE-20
null
null
1,606
static int php_openssl_parse_config(struct php_x509_request * req, zval * optional_args TSRMLS_DC) /* {{{ */ { char * str; zval ** item; SET_OPTIONAL_STRING_ARG("config", req->config_filename, default_ssl_conf_filename); SET_OPTIONAL_STRING_ARG("config_section_name", req->section_name, "req"); req->global_config = CONF_load(NULL, default_ssl_conf_filename, NULL); req->req_config = CONF_load(NULL, req->config_filename, NULL); if (req->req_config == NULL) { return FAILURE; } /* read in the oids */ str = CONF_get_string(req->req_config, NULL, "oid_file"); if (str && !php_openssl_open_base_dir_chk(str TSRMLS_CC)) { BIO *oid_bio = BIO_new_file(str, "r"); if (oid_bio) { OBJ_create_objects(oid_bio); BIO_free(oid_bio); } } if (add_oid_section(req TSRMLS_CC) == FAILURE) { return FAILURE; } SET_OPTIONAL_STRING_ARG("digest_alg", req->digest_name, CONF_get_string(req->req_config, req->section_name, "default_md")); SET_OPTIONAL_STRING_ARG("x509_extensions", req->extensions_section, CONF_get_string(req->req_config, req->section_name, "x509_extensions")); SET_OPTIONAL_STRING_ARG("req_extensions", req->request_extensions_section, CONF_get_string(req->req_config, req->section_name, "req_extensions")); SET_OPTIONAL_LONG_ARG("private_key_bits", req->priv_key_bits, CONF_get_number(req->req_config, req->section_name, "default_bits")); SET_OPTIONAL_LONG_ARG("private_key_type", req->priv_key_type, OPENSSL_KEYTYPE_DEFAULT); if (optional_args && zend_hash_find(Z_ARRVAL_P(optional_args), "encrypt_key", sizeof("encrypt_key"), (void**)&item) == SUCCESS) { req->priv_key_encrypt = Z_BVAL_PP(item); } else { str = CONF_get_string(req->req_config, req->section_name, "encrypt_rsa_key"); if (str == NULL) { str = CONF_get_string(req->req_config, req->section_name, "encrypt_key"); } if (str && strcmp(str, "no") == 0) { req->priv_key_encrypt = 0; } else { req->priv_key_encrypt = 1; } } if (req->priv_key_encrypt && optional_args && zend_hash_find(Z_ARRVAL_P(optional_args), "encrypt_key_cipher", sizeof("encrypt_key_cipher"), (void**)&item) == SUCCESS) { long cipher_algo = Z_LVAL_PP(item); const EVP_CIPHER* cipher = php_openssl_get_evp_cipher_from_algo(cipher_algo); if (cipher == NULL) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown cipher algorithm for private key."); return FAILURE; } else { req->priv_key_encrypt_cipher = cipher; } } else { req->priv_key_encrypt_cipher = NULL; } /* digest alg */ if (req->digest_name == NULL) { req->digest_name = CONF_get_string(req->req_config, req->section_name, "default_md"); } if (req->digest_name) { req->digest = req->md_alg = EVP_get_digestbyname(req->digest_name); } if (req->md_alg == NULL) { req->md_alg = req->digest = EVP_md5(); } PHP_SSL_CONFIG_SYNTAX_CHECK(extensions_section); /* set the string mask */ str = CONF_get_string(req->req_config, req->section_name, "string_mask"); if (str && !ASN1_STRING_set_default_mask_asc(str)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid global string mask setting %s", str); return FAILURE; } PHP_SSL_CONFIG_SYNTAX_CHECK(request_extensions_section); return SUCCESS; } /* }}} */
null
0
static int php_openssl_parse_config(struct php_x509_request * req, zval * optional_args TSRMLS_DC) /* {{{ */ { char * str; zval ** item; SET_OPTIONAL_STRING_ARG("config", req->config_filename, default_ssl_conf_filename); SET_OPTIONAL_STRING_ARG("config_section_name", req->section_name, "req"); req->global_config = CONF_load(NULL, default_ssl_conf_filename, NULL); req->req_config = CONF_load(NULL, req->config_filename, NULL); if (req->req_config == NULL) { return FAILURE; } /* read in the oids */ str = CONF_get_string(req->req_config, NULL, "oid_file"); if (str && !php_openssl_open_base_dir_chk(str TSRMLS_CC)) { BIO *oid_bio = BIO_new_file(str, "r"); if (oid_bio) { OBJ_create_objects(oid_bio); BIO_free(oid_bio); } } if (add_oid_section(req TSRMLS_CC) == FAILURE) { return FAILURE; } SET_OPTIONAL_STRING_ARG("digest_alg", req->digest_name, CONF_get_string(req->req_config, req->section_name, "default_md")); SET_OPTIONAL_STRING_ARG("x509_extensions", req->extensions_section, CONF_get_string(req->req_config, req->section_name, "x509_extensions")); SET_OPTIONAL_STRING_ARG("req_extensions", req->request_extensions_section, CONF_get_string(req->req_config, req->section_name, "req_extensions")); SET_OPTIONAL_LONG_ARG("private_key_bits", req->priv_key_bits, CONF_get_number(req->req_config, req->section_name, "default_bits")); SET_OPTIONAL_LONG_ARG("private_key_type", req->priv_key_type, OPENSSL_KEYTYPE_DEFAULT); if (optional_args && zend_hash_find(Z_ARRVAL_P(optional_args), "encrypt_key", sizeof("encrypt_key"), (void**)&item) == SUCCESS) { req->priv_key_encrypt = Z_BVAL_PP(item); } else { str = CONF_get_string(req->req_config, req->section_name, "encrypt_rsa_key"); if (str == NULL) { str = CONF_get_string(req->req_config, req->section_name, "encrypt_key"); } if (str && strcmp(str, "no") == 0) { req->priv_key_encrypt = 0; } else { req->priv_key_encrypt = 1; } } if (req->priv_key_encrypt && optional_args && zend_hash_find(Z_ARRVAL_P(optional_args), "encrypt_key_cipher", sizeof("encrypt_key_cipher"), (void**)&item) == SUCCESS) { long cipher_algo = Z_LVAL_PP(item); const EVP_CIPHER* cipher = php_openssl_get_evp_cipher_from_algo(cipher_algo); if (cipher == NULL) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown cipher algorithm for private key."); return FAILURE; } else { req->priv_key_encrypt_cipher = cipher; } } else { req->priv_key_encrypt_cipher = NULL; } /* digest alg */ if (req->digest_name == NULL) { req->digest_name = CONF_get_string(req->req_config, req->section_name, "default_md"); } if (req->digest_name) { req->digest = req->md_alg = EVP_get_digestbyname(req->digest_name); } if (req->md_alg == NULL) { req->md_alg = req->digest = EVP_md5(); } PHP_SSL_CONFIG_SYNTAX_CHECK(extensions_section); /* set the string mask */ str = CONF_get_string(req->req_config, req->section_name, "string_mask"); if (str && !ASN1_STRING_set_default_mask_asc(str)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid global string mask setting %s", str); return FAILURE; } PHP_SSL_CONFIG_SYNTAX_CHECK(request_extensions_section); return SUCCESS; } /* }}} */
@@ -1398,6 +1398,74 @@ PHP_FUNCTION(openssl_x509_check_private_key) } /* }}} */ +/* Special handling of subjectAltName, see CVE-2013-4073 + * Christian Heimes + */ + +static int openssl_x509v3_subjectAltName(BIO *bio, X509_EXTENSION *extension) +{ + GENERAL_NAMES *names; + const X509V3_EXT_METHOD *method = NULL; + long i, length, num; + const unsigned char *p; + + method = X509V3_EXT_get(extension); + if (method == NULL) { + return -1; + } + + p = extension->value->data; + length = extension->value->length; + if (method->it) { + names = (GENERAL_NAMES*)(ASN1_item_d2i(NULL, &p, length, + ASN1_ITEM_ptr(method->it))); + } else { + names = (GENERAL_NAMES*)(method->d2i(NULL, &p, length)); + } + if (names == NULL) { + return -1; + } + + num = sk_GENERAL_NAME_num(names); + for (i = 0; i < num; i++) { + GENERAL_NAME *name; + ASN1_STRING *as; + name = sk_GENERAL_NAME_value(names, i); + switch (name->type) { + case GEN_EMAIL: + BIO_puts(bio, "email:"); + as = name->d.rfc822Name; + BIO_write(bio, ASN1_STRING_data(as), + ASN1_STRING_length(as)); + break; + case GEN_DNS: + BIO_puts(bio, "DNS:"); + as = name->d.dNSName; + BIO_write(bio, ASN1_STRING_data(as), + ASN1_STRING_length(as)); + break; + case GEN_URI: + BIO_puts(bio, "URI:"); + as = name->d.uniformResourceIdentifier; + BIO_write(bio, ASN1_STRING_data(as), + ASN1_STRING_length(as)); + break; + default: + /* use builtin print for GEN_OTHERNAME, GEN_X400, + * GEN_EDIPARTY, GEN_DIRNAME, GEN_IPADD and GEN_RID + */ + GENERAL_NAME_print(bio, name); + } + /* trailing ', ' except for last element */ + if (i < (num - 1)) { + BIO_puts(bio, ", "); + } + } + sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free); + + return 0; +} + /* {{{ proto array openssl_x509_parse(mixed x509 [, bool shortnames=true]) Returns an array of the fields/values of the CERT */ PHP_FUNCTION(openssl_x509_parse) @@ -1494,15 +1562,29 @@ PHP_FUNCTION(openssl_x509_parse) for (i = 0; i < X509_get_ext_count(cert); i++) { + int nid; extension = X509_get_ext(cert, i); - if (OBJ_obj2nid(X509_EXTENSION_get_object(extension)) != NID_undef) { + nid = OBJ_obj2nid(X509_EXTENSION_get_object(extension)); + if (nid != NID_undef) { extname = (char *)OBJ_nid2sn(OBJ_obj2nid(X509_EXTENSION_get_object(extension))); } else { OBJ_obj2txt(buf, sizeof(buf)-1, X509_EXTENSION_get_object(extension), 1); extname = buf; } bio_out = BIO_new(BIO_s_mem()); - if (X509V3_EXT_print(bio_out, extension, 0, 0)) { + if (nid == NID_subject_alt_name) { + if (openssl_x509v3_subjectAltName(bio_out, extension) == 0) { + add_assoc_stringl(subitem, extname, bio_buf->data, bio_buf->length, 1); + } else { + zval_dtor(return_value); + if (certresource == -1 && cert) { + X509_free(cert); + } + BIO_free(bio_out); + RETURN_FALSE; + } + } + else if (X509V3_EXT_print(bio_out, extension, 0, 0)) { BIO_get_mem_ptr(bio_out, &bio_buf); add_assoc_stringl(subitem, extname, bio_buf->data, bio_buf->length, 1); } else {
CWE-20
null
null
1,607
static X509 * php_openssl_x509_from_zval(zval ** val, int makeresource, long * resourceval TSRMLS_DC) { X509 *cert = NULL; if (resourceval) { *resourceval = -1; } if (Z_TYPE_PP(val) == IS_RESOURCE) { /* is it an x509 resource ? */ void * what; int type; what = zend_fetch_resource(val TSRMLS_CC, -1, "OpenSSL X.509", &type, 1, le_x509); if (!what) { return NULL; } /* this is so callers can decide if they should free the X509 */ if (resourceval) { *resourceval = Z_LVAL_PP(val); } if (type == le_x509) { return (X509*)what; } /* other types could be used here - eg: file pointers and read in the data from them */ return NULL; } if (!(Z_TYPE_PP(val) == IS_STRING || Z_TYPE_PP(val) == IS_OBJECT)) { return NULL; } /* force it to be a string and check if it refers to a file */ convert_to_string_ex(val); if (Z_STRLEN_PP(val) > 7 && memcmp(Z_STRVAL_PP(val), "file://", sizeof("file://") - 1) == 0) { /* read cert from the named file */ BIO *in; if (php_openssl_open_base_dir_chk(Z_STRVAL_PP(val) + (sizeof("file://") - 1) TSRMLS_CC)) { return NULL; } in = BIO_new_file(Z_STRVAL_PP(val) + (sizeof("file://") - 1), "r"); if (in == NULL) { return NULL; } cert = PEM_read_bio_X509(in, NULL, NULL, NULL); BIO_free(in); } else { BIO *in; in = BIO_new_mem_buf(Z_STRVAL_PP(val), Z_STRLEN_PP(val)); if (in == NULL) { return NULL; } #ifdef TYPEDEF_D2I_OF cert = (X509 *) PEM_ASN1_read_bio((d2i_of_void *)d2i_X509, PEM_STRING_X509, in, NULL, NULL, NULL); #else cert = (X509 *) PEM_ASN1_read_bio((char *(*)())d2i_X509, PEM_STRING_X509, in, NULL, NULL, NULL); #endif BIO_free(in); } if (cert && makeresource && resourceval) { *resourceval = zend_list_insert(cert, le_x509 TSRMLS_CC); } return cert; }
null
0
static X509 * php_openssl_x509_from_zval(zval ** val, int makeresource, long * resourceval TSRMLS_DC) { X509 *cert = NULL; if (resourceval) { *resourceval = -1; } if (Z_TYPE_PP(val) == IS_RESOURCE) { /* is it an x509 resource ? */ void * what; int type; what = zend_fetch_resource(val TSRMLS_CC, -1, "OpenSSL X.509", &type, 1, le_x509); if (!what) { return NULL; } /* this is so callers can decide if they should free the X509 */ if (resourceval) { *resourceval = Z_LVAL_PP(val); } if (type == le_x509) { return (X509*)what; } /* other types could be used here - eg: file pointers and read in the data from them */ return NULL; } if (!(Z_TYPE_PP(val) == IS_STRING || Z_TYPE_PP(val) == IS_OBJECT)) { return NULL; } /* force it to be a string and check if it refers to a file */ convert_to_string_ex(val); if (Z_STRLEN_PP(val) > 7 && memcmp(Z_STRVAL_PP(val), "file://", sizeof("file://") - 1) == 0) { /* read cert from the named file */ BIO *in; if (php_openssl_open_base_dir_chk(Z_STRVAL_PP(val) + (sizeof("file://") - 1) TSRMLS_CC)) { return NULL; } in = BIO_new_file(Z_STRVAL_PP(val) + (sizeof("file://") - 1), "r"); if (in == NULL) { return NULL; } cert = PEM_read_bio_X509(in, NULL, NULL, NULL); BIO_free(in); } else { BIO *in; in = BIO_new_mem_buf(Z_STRVAL_PP(val), Z_STRLEN_PP(val)); if (in == NULL) { return NULL; } #ifdef TYPEDEF_D2I_OF cert = (X509 *) PEM_ASN1_read_bio((d2i_of_void *)d2i_X509, PEM_STRING_X509, in, NULL, NULL, NULL); #else cert = (X509 *) PEM_ASN1_read_bio((char *(*)())d2i_X509, PEM_STRING_X509, in, NULL, NULL, NULL); #endif BIO_free(in); } if (cert && makeresource && resourceval) { *resourceval = zend_list_insert(cert, le_x509 TSRMLS_CC); } return cert; }
@@ -1398,6 +1398,74 @@ PHP_FUNCTION(openssl_x509_check_private_key) } /* }}} */ +/* Special handling of subjectAltName, see CVE-2013-4073 + * Christian Heimes + */ + +static int openssl_x509v3_subjectAltName(BIO *bio, X509_EXTENSION *extension) +{ + GENERAL_NAMES *names; + const X509V3_EXT_METHOD *method = NULL; + long i, length, num; + const unsigned char *p; + + method = X509V3_EXT_get(extension); + if (method == NULL) { + return -1; + } + + p = extension->value->data; + length = extension->value->length; + if (method->it) { + names = (GENERAL_NAMES*)(ASN1_item_d2i(NULL, &p, length, + ASN1_ITEM_ptr(method->it))); + } else { + names = (GENERAL_NAMES*)(method->d2i(NULL, &p, length)); + } + if (names == NULL) { + return -1; + } + + num = sk_GENERAL_NAME_num(names); + for (i = 0; i < num; i++) { + GENERAL_NAME *name; + ASN1_STRING *as; + name = sk_GENERAL_NAME_value(names, i); + switch (name->type) { + case GEN_EMAIL: + BIO_puts(bio, "email:"); + as = name->d.rfc822Name; + BIO_write(bio, ASN1_STRING_data(as), + ASN1_STRING_length(as)); + break; + case GEN_DNS: + BIO_puts(bio, "DNS:"); + as = name->d.dNSName; + BIO_write(bio, ASN1_STRING_data(as), + ASN1_STRING_length(as)); + break; + case GEN_URI: + BIO_puts(bio, "URI:"); + as = name->d.uniformResourceIdentifier; + BIO_write(bio, ASN1_STRING_data(as), + ASN1_STRING_length(as)); + break; + default: + /* use builtin print for GEN_OTHERNAME, GEN_X400, + * GEN_EDIPARTY, GEN_DIRNAME, GEN_IPADD and GEN_RID + */ + GENERAL_NAME_print(bio, name); + } + /* trailing ', ' except for last element */ + if (i < (num - 1)) { + BIO_puts(bio, ", "); + } + } + sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free); + + return 0; +} + /* {{{ proto array openssl_x509_parse(mixed x509 [, bool shortnames=true]) Returns an array of the fields/values of the CERT */ PHP_FUNCTION(openssl_x509_parse) @@ -1494,15 +1562,29 @@ PHP_FUNCTION(openssl_x509_parse) for (i = 0; i < X509_get_ext_count(cert); i++) { + int nid; extension = X509_get_ext(cert, i); - if (OBJ_obj2nid(X509_EXTENSION_get_object(extension)) != NID_undef) { + nid = OBJ_obj2nid(X509_EXTENSION_get_object(extension)); + if (nid != NID_undef) { extname = (char *)OBJ_nid2sn(OBJ_obj2nid(X509_EXTENSION_get_object(extension))); } else { OBJ_obj2txt(buf, sizeof(buf)-1, X509_EXTENSION_get_object(extension), 1); extname = buf; } bio_out = BIO_new(BIO_s_mem()); - if (X509V3_EXT_print(bio_out, extension, 0, 0)) { + if (nid == NID_subject_alt_name) { + if (openssl_x509v3_subjectAltName(bio_out, extension) == 0) { + add_assoc_stringl(subitem, extname, bio_buf->data, bio_buf->length, 1); + } else { + zval_dtor(return_value); + if (certresource == -1 && cert) { + X509_free(cert); + } + BIO_free(bio_out); + RETURN_FALSE; + } + } + else if (X509V3_EXT_print(bio_out, extension, 0, 0)) { BIO_get_mem_ptr(bio_out, &bio_buf); add_assoc_stringl(subitem, extname, bio_buf->data, bio_buf->length, 1); } else {
CWE-20
null
null
1,608
check_fstab(const char *progname, const char *mountpoint, const char *devname, char **options) { FILE *fstab; struct mntent *mnt; /* make sure this mount is listed in /etc/fstab */ fstab = setmntent(_PATH_MNTTAB, "r"); if (!fstab) { fprintf(stderr, "Couldn't open %s for reading!\n", _PATH_MNTTAB); return EX_FILEIO; } while ((mnt = getmntent(fstab))) { if (!strcmp(mountpoint, mnt->mnt_dir)) break; } endmntent(fstab); if (mnt == NULL || strcmp(mnt->mnt_fsname, devname)) { fprintf(stderr, "%s: permission denied: no match for " "%s found in %s\n", progname, mountpoint, _PATH_MNTTAB); return EX_USAGE; } /* * 'mount' munges the options from fstab before passing them * to us. It is non-trivial to test that we have the correct * set of options. We don't want to trust what the user * gave us, so just take whatever is in /etc/fstab. */ free(*options); *options = strdup(mnt->mnt_opts); return 0; }
DoS
0
check_fstab(const char *progname, const char *mountpoint, const char *devname, char **options) { FILE *fstab; struct mntent *mnt; /* make sure this mount is listed in /etc/fstab */ fstab = setmntent(_PATH_MNTTAB, "r"); if (!fstab) { fprintf(stderr, "Couldn't open %s for reading!\n", _PATH_MNTTAB); return EX_FILEIO; } while ((mnt = getmntent(fstab))) { if (!strcmp(mountpoint, mnt->mnt_dir)) break; } endmntent(fstab); if (mnt == NULL || strcmp(mnt->mnt_fsname, devname)) { fprintf(stderr, "%s: permission denied: no match for " "%s found in %s\n", progname, mountpoint, _PATH_MNTTAB); return EX_USAGE; } /* * 'mount' munges the options from fstab before passing them * to us. It is non-trivial to test that we have the correct * set of options. We don't want to trust what the user * gave us, so just take whatever is in /etc/fstab. */ free(*options); *options = strdup(mnt->mnt_opts); return 0; }
@@ -1419,8 +1419,7 @@ static int check_newline(const char *progname, const char *name) static int check_mtab(const char *progname, const char *devname, const char *dir) { - if (check_newline(progname, devname) == -1 || - check_newline(progname, dir) == -1) + if (check_newline(progname, devname) || check_newline(progname, dir)) return EX_USAGE; return 0; }
CWE-20
null
null
1,609
static int check_newline(const char *progname, const char *name) { const char *s; for (s = "\n"; *s; s++) { if (strchr(name, *s)) { fprintf(stderr, "%s: illegal character 0x%02x in mount entry\n", progname, *s); return EX_USAGE; } } return 0; }
DoS
0
static int check_newline(const char *progname, const char *name) { const char *s; for (s = "\n"; *s; s++) { if (strchr(name, *s)) { fprintf(stderr, "%s: illegal character 0x%02x in mount entry\n", progname, *s); return EX_USAGE; } } return 0; }
@@ -1419,8 +1419,7 @@ static int check_newline(const char *progname, const char *name) static int check_mtab(const char *progname, const char *devname, const char *dir) { - if (check_newline(progname, devname) == -1 || - check_newline(progname, dir) == -1) + if (check_newline(progname, devname) || check_newline(progname, dir)) return EX_USAGE; return 0; }
CWE-20
null
null
1,610
static int check_setuid(void) { if (geteuid()) { fprintf(stderr, "This program is not installed setuid root - " " \"user\" CIFS mounts not supported.\n"); return EX_USAGE; } #if CIFS_DISABLE_SETUID_CAPABILITY if (getuid() && !geteuid()) { printf("This mount.cifs program has been built with the " "ability to run as a setuid root program disabled.\n"); return EX_USAGE; } #endif /* CIFS_DISABLE_SETUID_CAPABILITY */ return 0; }
DoS
0
static int check_setuid(void) { if (geteuid()) { fprintf(stderr, "This program is not installed setuid root - " " \"user\" CIFS mounts not supported.\n"); return EX_USAGE; } #if CIFS_DISABLE_SETUID_CAPABILITY if (getuid() && !geteuid()) { printf("This mount.cifs program has been built with the " "ability to run as a setuid root program disabled.\n"); return EX_USAGE; } #endif /* CIFS_DISABLE_SETUID_CAPABILITY */ return 0; }
@@ -1419,8 +1419,7 @@ static int check_newline(const char *progname, const char *name) static int check_mtab(const char *progname, const char *devname, const char *dir) { - if (check_newline(progname, devname) == -1 || - check_newline(progname, dir) == -1) + if (check_newline(progname, devname) || check_newline(progname, dir)) return EX_USAGE; return 0; }
CWE-20
null
null
1,611
drop_capabilities(int parent) { capng_setpid(getpid()); capng_clear(CAPNG_SELECT_BOTH); if (parent) { if (capng_updatev(CAPNG_ADD, CAPNG_PERMITTED, CAP_DAC_READ_SEARCH, CAP_DAC_OVERRIDE, -1)) { fprintf(stderr, "Unable to update capability set.\n"); return EX_SYSERR; } if (capng_update(CAPNG_ADD, CAPNG_PERMITTED|CAPNG_EFFECTIVE, CAP_SYS_ADMIN)) { fprintf(stderr, "Unable to update capability set.\n"); return EX_SYSERR; } } else { if (capng_update(CAPNG_ADD, CAPNG_PERMITTED, CAP_DAC_READ_SEARCH)) { fprintf(stderr, "Unable to update capability set.\n"); return EX_SYSERR; } } if (capng_apply(CAPNG_SELECT_BOTH)) { fprintf(stderr, "Unable to apply new capability set.\n"); return EX_SYSERR; } return 0; }
DoS
0
drop_capabilities(int parent) { capng_setpid(getpid()); capng_clear(CAPNG_SELECT_BOTH); if (parent) { if (capng_updatev(CAPNG_ADD, CAPNG_PERMITTED, CAP_DAC_READ_SEARCH, CAP_DAC_OVERRIDE, -1)) { fprintf(stderr, "Unable to update capability set.\n"); return EX_SYSERR; } if (capng_update(CAPNG_ADD, CAPNG_PERMITTED|CAPNG_EFFECTIVE, CAP_SYS_ADMIN)) { fprintf(stderr, "Unable to update capability set.\n"); return EX_SYSERR; } } else { if (capng_update(CAPNG_ADD, CAPNG_PERMITTED, CAP_DAC_READ_SEARCH)) { fprintf(stderr, "Unable to update capability set.\n"); return EX_SYSERR; } } if (capng_apply(CAPNG_SELECT_BOTH)) { fprintf(stderr, "Unable to apply new capability set.\n"); return EX_SYSERR; } return 0; }
@@ -1419,8 +1419,7 @@ static int check_newline(const char *progname, const char *name) static int check_mtab(const char *progname, const char *devname, const char *dir) { - if (check_newline(progname, devname) == -1 || - check_newline(progname, dir) == -1) + if (check_newline(progname, devname) || check_newline(progname, dir)) return EX_USAGE; return 0; }
CWE-20
null
null
1,612
drop_capabilities(int parent) { int rc, ncaps; cap_t caps; cap_value_t cap_list[3]; rc = prune_bounding_set(); if (rc) return rc; caps = cap_get_proc(); if (caps == NULL) { fprintf(stderr, "Unable to get current capability set: %s\n", strerror(errno)); return EX_SYSERR; } if (cap_clear(caps) == -1) { fprintf(stderr, "Unable to clear capability set: %s\n", strerror(errno)); rc = EX_SYSERR; goto free_caps; } if (parent || getuid() == 0) { ncaps = 1; cap_list[0] = CAP_DAC_READ_SEARCH; if (parent) { cap_list[1] = CAP_DAC_OVERRIDE; cap_list[2] = CAP_SYS_ADMIN; ncaps += 2; } if (cap_set_flag(caps, CAP_PERMITTED, ncaps, cap_list, CAP_SET) == -1) { fprintf(stderr, "Unable to set permitted capabilities: %s\n", strerror(errno)); rc = EX_SYSERR; goto free_caps; } if (parent) { cap_list[0] = CAP_SYS_ADMIN; if (cap_set_flag(caps, CAP_EFFECTIVE, 1, cap_list, CAP_SET) == -1) { fprintf(stderr, "Unable to set effective capabilities: %s\n", strerror(errno)); rc = EX_SYSERR; goto free_caps; } } } if (cap_set_proc(caps) != 0) { fprintf(stderr, "Unable to set current process capabilities: %s\n", strerror(errno)); rc = EX_SYSERR; } free_caps: cap_free(caps); return rc; }
DoS
0
drop_capabilities(int parent) { int rc, ncaps; cap_t caps; cap_value_t cap_list[3]; rc = prune_bounding_set(); if (rc) return rc; caps = cap_get_proc(); if (caps == NULL) { fprintf(stderr, "Unable to get current capability set: %s\n", strerror(errno)); return EX_SYSERR; } if (cap_clear(caps) == -1) { fprintf(stderr, "Unable to clear capability set: %s\n", strerror(errno)); rc = EX_SYSERR; goto free_caps; } if (parent || getuid() == 0) { ncaps = 1; cap_list[0] = CAP_DAC_READ_SEARCH; if (parent) { cap_list[1] = CAP_DAC_OVERRIDE; cap_list[2] = CAP_SYS_ADMIN; ncaps += 2; } if (cap_set_flag(caps, CAP_PERMITTED, ncaps, cap_list, CAP_SET) == -1) { fprintf(stderr, "Unable to set permitted capabilities: %s\n", strerror(errno)); rc = EX_SYSERR; goto free_caps; } if (parent) { cap_list[0] = CAP_SYS_ADMIN; if (cap_set_flag(caps, CAP_EFFECTIVE, 1, cap_list, CAP_SET) == -1) { fprintf(stderr, "Unable to set effective capabilities: %s\n", strerror(errno)); rc = EX_SYSERR; goto free_caps; } } } if (cap_set_proc(caps) != 0) { fprintf(stderr, "Unable to set current process capabilities: %s\n", strerror(errno)); rc = EX_SYSERR; } free_caps: cap_free(caps); return rc; }
@@ -1419,8 +1419,7 @@ static int check_newline(const char *progname, const char *name) static int check_mtab(const char *progname, const char *devname, const char *dir) { - if (check_newline(progname, devname) == -1 || - check_newline(progname, dir) == -1) + if (check_newline(progname, devname) || check_newline(progname, dir)) return EX_USAGE; return 0; }
CWE-20
null
null
1,613
get_password_from_file(int file_descript, char *filename, struct parsed_mount_info *parsed_info) { int rc = 0; char buf[sizeof(parsed_info->password) + 1]; if (filename != NULL) { rc = toggle_dac_capability(0, 1); if (rc) return rc; rc = access(filename, R_OK); if (rc) { fprintf(stderr, "mount.cifs failed: access check of %s failed: %s\n", filename, strerror(errno)); toggle_dac_capability(0, 0); return EX_SYSERR; } file_descript = open(filename, O_RDONLY); if (file_descript < 0) { fprintf(stderr, "mount.cifs failed. %s attempting to open password file %s\n", strerror(errno), filename); toggle_dac_capability(0, 0); return EX_SYSERR; } rc = toggle_dac_capability(0, 0); if (rc) { rc = EX_SYSERR; goto get_pw_exit; } } memset(buf, 0, sizeof(buf)); rc = read(file_descript, buf, sizeof(buf) - 1); if (rc < 0) { fprintf(stderr, "mount.cifs failed. Error %s reading password file\n", strerror(errno)); rc = EX_SYSERR; goto get_pw_exit; } rc = set_password(parsed_info, buf); get_pw_exit: if (filename != NULL) close(file_descript); return rc; }
DoS
0
get_password_from_file(int file_descript, char *filename, struct parsed_mount_info *parsed_info) { int rc = 0; char buf[sizeof(parsed_info->password) + 1]; if (filename != NULL) { rc = toggle_dac_capability(0, 1); if (rc) return rc; rc = access(filename, R_OK); if (rc) { fprintf(stderr, "mount.cifs failed: access check of %s failed: %s\n", filename, strerror(errno)); toggle_dac_capability(0, 0); return EX_SYSERR; } file_descript = open(filename, O_RDONLY); if (file_descript < 0) { fprintf(stderr, "mount.cifs failed. %s attempting to open password file %s\n", strerror(errno), filename); toggle_dac_capability(0, 0); return EX_SYSERR; } rc = toggle_dac_capability(0, 0); if (rc) { rc = EX_SYSERR; goto get_pw_exit; } } memset(buf, 0, sizeof(buf)); rc = read(file_descript, buf, sizeof(buf) - 1); if (rc < 0) { fprintf(stderr, "mount.cifs failed. Error %s reading password file\n", strerror(errno)); rc = EX_SYSERR; goto get_pw_exit; } rc = set_password(parsed_info, buf); get_pw_exit: if (filename != NULL) close(file_descript); return rc; }
@@ -1419,8 +1419,7 @@ static int check_newline(const char *progname, const char *name) static int check_mtab(const char *progname, const char *devname, const char *dir) { - if (check_newline(progname, devname) == -1 || - check_newline(progname, dir) == -1) + if (check_newline(progname, devname) || check_newline(progname, dir)) return EX_USAGE; return 0; }
CWE-20
null
null
1,614
static int get_pw_from_env(struct parsed_mount_info *parsed_info) { int rc = 0; if (getenv("PASSWD")) rc = set_password(parsed_info, getenv("PASSWD")); else if (getenv("PASSWD_FD")) rc = get_password_from_file(atoi(getenv("PASSWD_FD")), NULL, parsed_info); else if (getenv("PASSWD_FILE")) rc = get_password_from_file(0, getenv("PASSWD_FILE"), parsed_info); return rc; }
DoS
0
static int get_pw_from_env(struct parsed_mount_info *parsed_info) { int rc = 0; if (getenv("PASSWD")) rc = set_password(parsed_info, getenv("PASSWD")); else if (getenv("PASSWD_FD")) rc = get_password_from_file(atoi(getenv("PASSWD_FD")), NULL, parsed_info); else if (getenv("PASSWD_FILE")) rc = get_password_from_file(0, getenv("PASSWD_FILE"), parsed_info); return rc; }
@@ -1419,8 +1419,7 @@ static int check_newline(const char *progname, const char *name) static int check_mtab(const char *progname, const char *devname, const char *dir) { - if (check_newline(progname, devname) == -1 || - check_newline(progname, dir) == -1) + if (check_newline(progname, devname) || check_newline(progname, dir)) return EX_USAGE; return 0; }
CWE-20
null
null
1,615
static char *getusername(uid_t uid) { char *username = NULL; struct passwd *password = getpwuid(uid); if (password) username = password->pw_name; return username; }
DoS
0
static char *getusername(uid_t uid) { char *username = NULL; struct passwd *password = getpwuid(uid); if (password) username = password->pw_name; return username; }
@@ -1419,8 +1419,7 @@ static int check_newline(const char *progname, const char *name) static int check_mtab(const char *progname, const char *devname, const char *dir) { - if (check_newline(progname, devname) == -1 || - check_newline(progname, dir) == -1) + if (check_newline(progname, devname) || check_newline(progname, dir)) return EX_USAGE; return 0; }
CWE-20
null
null
1,616
static int mount_cifs_usage(FILE * stream) { fprintf(stream, "\nUsage: %s <remotetarget> <dir> -o <options>\n", thisprogram); fprintf(stream, "\nMount the remote target, specified as a UNC name,"); fprintf(stream, " to a local directory.\n\nOptions:\n"); fprintf(stream, "\tuser=<arg>\n\tpass=<arg>\n\tdom=<arg>\n"); fprintf(stream, "\nLess commonly used options:"); fprintf(stream, "\n\tcredentials=<filename>,guest,perm,noperm,setuids,nosetuids,rw,ro,"); fprintf(stream, "\n\tsep=<char>,iocharset=<codepage>,suid,nosuid,exec,noexec,serverino,"); fprintf(stream, "\n\tmapchars,nomapchars,nolock,servernetbiosname=<SRV_RFC1001NAME>"); fprintf(stream, "\n\tdirectio,nounix,cifsacl,sec=<authentication mechanism>,sign,fsc"); fprintf(stream, "\n\nOptions not needed for servers supporting CIFS Unix extensions"); fprintf(stream, "\n\t(e.g. unneeded for mounts to most Samba versions):"); fprintf(stream, "\n\tuid=<uid>,gid=<gid>,dir_mode=<mode>,file_mode=<mode>,sfu"); fprintf(stream, "\n\nRarely used options:"); fprintf(stream, "\n\tport=<tcpport>,rsize=<size>,wsize=<size>,unc=<unc_name>,ip=<ip_address>,"); fprintf(stream, "\n\tdev,nodev,nouser_xattr,netbiosname=<OUR_RFC1001NAME>,hard,soft,intr,"); fprintf(stream, "\n\tnointr,ignorecase,noposixpaths,noacl,prefixpath=<path>,nobrl"); fprintf(stream, "\n\nOptions are described in more detail in the manual page"); fprintf(stream, "\n\tman 8 mount.cifs\n"); fprintf(stream, "\nTo display the version number of the mount helper:"); fprintf(stream, "\n\t%s -V\n", thisprogram); if (stream == stderr) return EX_USAGE; return 0; }
DoS
0
static int mount_cifs_usage(FILE * stream) { fprintf(stream, "\nUsage: %s <remotetarget> <dir> -o <options>\n", thisprogram); fprintf(stream, "\nMount the remote target, specified as a UNC name,"); fprintf(stream, " to a local directory.\n\nOptions:\n"); fprintf(stream, "\tuser=<arg>\n\tpass=<arg>\n\tdom=<arg>\n"); fprintf(stream, "\nLess commonly used options:"); fprintf(stream, "\n\tcredentials=<filename>,guest,perm,noperm,setuids,nosetuids,rw,ro,"); fprintf(stream, "\n\tsep=<char>,iocharset=<codepage>,suid,nosuid,exec,noexec,serverino,"); fprintf(stream, "\n\tmapchars,nomapchars,nolock,servernetbiosname=<SRV_RFC1001NAME>"); fprintf(stream, "\n\tdirectio,nounix,cifsacl,sec=<authentication mechanism>,sign,fsc"); fprintf(stream, "\n\nOptions not needed for servers supporting CIFS Unix extensions"); fprintf(stream, "\n\t(e.g. unneeded for mounts to most Samba versions):"); fprintf(stream, "\n\tuid=<uid>,gid=<gid>,dir_mode=<mode>,file_mode=<mode>,sfu"); fprintf(stream, "\n\nRarely used options:"); fprintf(stream, "\n\tport=<tcpport>,rsize=<size>,wsize=<size>,unc=<unc_name>,ip=<ip_address>,"); fprintf(stream, "\n\tdev,nodev,nouser_xattr,netbiosname=<OUR_RFC1001NAME>,hard,soft,intr,"); fprintf(stream, "\n\tnointr,ignorecase,noposixpaths,noacl,prefixpath=<path>,nobrl"); fprintf(stream, "\n\nOptions are described in more detail in the manual page"); fprintf(stream, "\n\tman 8 mount.cifs\n"); fprintf(stream, "\nTo display the version number of the mount helper:"); fprintf(stream, "\n\t%s -V\n", thisprogram); if (stream == stderr) return EX_USAGE; return 0; }
@@ -1419,8 +1419,7 @@ static int check_newline(const char *progname, const char *name) static int check_mtab(const char *progname, const char *devname, const char *dir) { - if (check_newline(progname, devname) == -1 || - check_newline(progname, dir) == -1) + if (check_newline(progname, devname) || check_newline(progname, dir)) return EX_USAGE; return 0; }
CWE-20
null
null
1,617
static int mount_smb2_usage(FILE *stream) { fprintf(stream, "\nUsage: %s <remotetarget> <dir> -o <options>\n", thisprogram); fprintf(stream, "\nMount the remote target, specified as a UNC name,"); fprintf(stream, " to a local directory.\n\nOptions:\n"); fprintf(stream, "\tuser=<arg>\n\tpass=<arg>\n\tdom=<arg>\n"); fprintf(stream, "\nLess commonly used options:"); fprintf(stream, "\n\tcredentials=<filename>,guest,perm,noperm,rw,ro,"); fprintf(stream, "\n\tsep=<char>,iocharset=<codepage>,exec,noexec"); fprintf(stream, "\n\tnolock,directio,sec=<authentication mechanism>,sign"); fprintf(stream, "\n\tuid=<uid>,gid=<gid>,dir_mode=<mode>,file_mode=<mode>"); fprintf(stream, "\n\nRarely used options:"); fprintf(stream, "\n\tport=<tcpport>,rsize=<size>,wsize=<size>,unc=<unc_name>,ip=<ip_address>,"); fprintf(stream, "\n\tdev,nodev,hard,soft,intr,"); fprintf(stream, "\n\tnointr,ignorecase,noacl,prefixpath=<path>,nobrl"); fprintf(stream, "\n\nOptions are described in more detail in the manual page"); fprintf(stream, "\n\tman 8 mount.smb2\n"); fprintf(stream, "\nTo display the version number of the mount helper:"); fprintf(stream, "\n\tmount.smb2 -V\n"); if (stream == stderr) return EX_USAGE; return 0; }
DoS
0
static int mount_smb2_usage(FILE *stream) { fprintf(stream, "\nUsage: %s <remotetarget> <dir> -o <options>\n", thisprogram); fprintf(stream, "\nMount the remote target, specified as a UNC name,"); fprintf(stream, " to a local directory.\n\nOptions:\n"); fprintf(stream, "\tuser=<arg>\n\tpass=<arg>\n\tdom=<arg>\n"); fprintf(stream, "\nLess commonly used options:"); fprintf(stream, "\n\tcredentials=<filename>,guest,perm,noperm,rw,ro,"); fprintf(stream, "\n\tsep=<char>,iocharset=<codepage>,exec,noexec"); fprintf(stream, "\n\tnolock,directio,sec=<authentication mechanism>,sign"); fprintf(stream, "\n\tuid=<uid>,gid=<gid>,dir_mode=<mode>,file_mode=<mode>"); fprintf(stream, "\n\nRarely used options:"); fprintf(stream, "\n\tport=<tcpport>,rsize=<size>,wsize=<size>,unc=<unc_name>,ip=<ip_address>,"); fprintf(stream, "\n\tdev,nodev,hard,soft,intr,"); fprintf(stream, "\n\tnointr,ignorecase,noacl,prefixpath=<path>,nobrl"); fprintf(stream, "\n\nOptions are described in more detail in the manual page"); fprintf(stream, "\n\tman 8 mount.smb2\n"); fprintf(stream, "\nTo display the version number of the mount helper:"); fprintf(stream, "\n\tmount.smb2 -V\n"); if (stream == stderr) return EX_USAGE; return 0; }
@@ -1419,8 +1419,7 @@ static int check_newline(const char *progname, const char *name) static int check_mtab(const char *progname, const char *devname, const char *dir) { - if (check_newline(progname, devname) == -1 || - check_newline(progname, dir) == -1) + if (check_newline(progname, devname) || check_newline(progname, dir)) return EX_USAGE; return 0; }
CWE-20
null
null
1,618
static void null_terminate_endl(char *source) { char *newline = strchr(source, '\n'); if (newline) *newline = '\0'; }
DoS
0
static void null_terminate_endl(char *source) { char *newline = strchr(source, '\n'); if (newline) *newline = '\0'; }
@@ -1419,8 +1419,7 @@ static int check_newline(const char *progname, const char *name) static int check_mtab(const char *progname, const char *devname, const char *dir) { - if (check_newline(progname, devname) == -1 || - check_newline(progname, dir) == -1) + if (check_newline(progname, devname) || check_newline(progname, dir)) return EX_USAGE; return 0; }
CWE-20
null
null
1,619
static int open_cred_file(char *file_name, struct parsed_mount_info *parsed_info) { char *line_buf = NULL; char *temp_val = NULL; FILE *fs = NULL; int i; const int line_buf_size = 4096; const int min_non_white = 10; i = toggle_dac_capability(0, 1); if (i) goto return_i; i = access(file_name, R_OK); if (i) { toggle_dac_capability(0, 0); goto return_i; } fs = fopen(file_name, "r"); if (fs == NULL) { toggle_dac_capability(0, 0); i = errno; goto return_i; } i = toggle_dac_capability(0, 0); if (i) goto return_i; line_buf = (char *)malloc(line_buf_size); if (line_buf == NULL) { i = EX_SYSERR; goto return_i; } /* parse line from credentials file */ while (fgets(line_buf, line_buf_size, fs)) { /* eat leading white space */ for (i = 0; i < line_buf_size - min_non_white + 1; i++) { if ((line_buf[i] != ' ') && (line_buf[i] != '\t')) break; } null_terminate_endl(line_buf); /* parse next token */ switch (parse_cred_line(line_buf + i, &temp_val)) { case CRED_USER: i = parse_username(temp_val, parsed_info); if (i) goto return_i; break; case CRED_PASS: i = set_password(parsed_info, temp_val); if (i) goto return_i; break; case CRED_DOM: if (parsed_info->verboseflag) fprintf(stderr, "domain=%s\n", temp_val); strlcpy(parsed_info->domain, temp_val, sizeof(parsed_info->domain)); break; case CRED_UNPARSEABLE: if (parsed_info->verboseflag) fprintf(stderr, "Credential formatted " "incorrectly: %s\n", temp_val ? temp_val : "(null)"); break; } } i = 0; return_i: if (fs != NULL) fclose(fs); /* make sure passwords are scrubbed from memory */ if (line_buf != NULL) memset(line_buf, 0, line_buf_size); SAFE_FREE(line_buf); return i; }
DoS
0
static int open_cred_file(char *file_name, struct parsed_mount_info *parsed_info) { char *line_buf = NULL; char *temp_val = NULL; FILE *fs = NULL; int i; const int line_buf_size = 4096; const int min_non_white = 10; i = toggle_dac_capability(0, 1); if (i) goto return_i; i = access(file_name, R_OK); if (i) { toggle_dac_capability(0, 0); goto return_i; } fs = fopen(file_name, "r"); if (fs == NULL) { toggle_dac_capability(0, 0); i = errno; goto return_i; } i = toggle_dac_capability(0, 0); if (i) goto return_i; line_buf = (char *)malloc(line_buf_size); if (line_buf == NULL) { i = EX_SYSERR; goto return_i; } /* parse line from credentials file */ while (fgets(line_buf, line_buf_size, fs)) { /* eat leading white space */ for (i = 0; i < line_buf_size - min_non_white + 1; i++) { if ((line_buf[i] != ' ') && (line_buf[i] != '\t')) break; } null_terminate_endl(line_buf); /* parse next token */ switch (parse_cred_line(line_buf + i, &temp_val)) { case CRED_USER: i = parse_username(temp_val, parsed_info); if (i) goto return_i; break; case CRED_PASS: i = set_password(parsed_info, temp_val); if (i) goto return_i; break; case CRED_DOM: if (parsed_info->verboseflag) fprintf(stderr, "domain=%s\n", temp_val); strlcpy(parsed_info->domain, temp_val, sizeof(parsed_info->domain)); break; case CRED_UNPARSEABLE: if (parsed_info->verboseflag) fprintf(stderr, "Credential formatted " "incorrectly: %s\n", temp_val ? temp_val : "(null)"); break; } } i = 0; return_i: if (fs != NULL) fclose(fs); /* make sure passwords are scrubbed from memory */ if (line_buf != NULL) memset(line_buf, 0, line_buf_size); SAFE_FREE(line_buf); return i; }
@@ -1419,8 +1419,7 @@ static int check_newline(const char *progname, const char *name) static int check_mtab(const char *progname, const char *devname, const char *dir) { - if (check_newline(progname, devname) == -1 || - check_newline(progname, dir) == -1) + if (check_newline(progname, devname) || check_newline(progname, dir)) return EX_USAGE; return 0; }
CWE-20
null
null
1,620
static int parse_cred_line(char *line, char **target) { if (line == NULL || target == NULL) goto parsing_err; /* position target at first char of value */ *target = strchr(line, '='); if (!*target) goto parsing_err; *target += 1; /* tell the caller which value target points to */ if (strncasecmp("user", line, 4) == 0) return CRED_USER; if (strncasecmp("pass", line, 4) == 0) return CRED_PASS; if (strncasecmp("dom", line, 3) == 0) return CRED_DOM; parsing_err: return CRED_UNPARSEABLE; }
DoS
0
static int parse_cred_line(char *line, char **target) { if (line == NULL || target == NULL) goto parsing_err; /* position target at first char of value */ *target = strchr(line, '='); if (!*target) goto parsing_err; *target += 1; /* tell the caller which value target points to */ if (strncasecmp("user", line, 4) == 0) return CRED_USER; if (strncasecmp("pass", line, 4) == 0) return CRED_PASS; if (strncasecmp("dom", line, 3) == 0) return CRED_DOM; parsing_err: return CRED_UNPARSEABLE; }
@@ -1419,8 +1419,7 @@ static int check_newline(const char *progname, const char *name) static int check_mtab(const char *progname, const char *devname, const char *dir) { - if (check_newline(progname, devname) == -1 || - check_newline(progname, dir) == -1) + if (check_newline(progname, devname) || check_newline(progname, dir)) return EX_USAGE; return 0; }
CWE-20
null
null
1,621
static int parse_opt_token(const char *token) { if (token == NULL) return OPT_ERROR; if (strncmp(token, "users", 5) == 0) return OPT_USERS; if (strncmp(token, "user_xattr", 10) == 0) return OPT_USER_XATTR; if (strncmp(token, "user", 4) == 0) return OPT_USER; if (strncmp(token, "pass", 4) == 0) return OPT_PASS; if (strncmp(token, "sec", 3) == 0) return OPT_SEC; if (strncmp(token, "ip", 2) == 0) return OPT_IP; if (strncmp(token, "unc", 3) == 0 || strncmp(token, "target", 6) == 0 || strncmp(token, "path", 4) == 0) return OPT_UNC; if (strncmp(token, "dom", 3) == 0 || strncmp(token, "workg", 5) == 0) return OPT_DOM; if (strncmp(token, "cred", 4) == 0) return OPT_CRED; if (strncmp(token, "uid", 3) == 0) return OPT_UID; if (strncmp(token, "cruid", 5) == 0) return OPT_CRUID; if (strncmp(token, "gid", 3) == 0) return OPT_GID; if (strncmp(token, "fmask", 5) == 0) return OPT_FMASK; if (strncmp(token, "file_mode", 9) == 0) return OPT_FILE_MODE; if (strncmp(token, "dmask", 5) == 0) return OPT_DMASK; if (strncmp(token, "dir_mode", 4) == 0 || strncmp(token, "dirm", 4) == 0) return OPT_DIR_MODE; if (strncmp(token, "nosuid", 6) == 0) return OPT_NO_SUID; if (strncmp(token, "suid", 4) == 0) return OPT_SUID; if (strncmp(token, "nodev", 5) == 0) return OPT_NO_DEV; if (strncmp(token, "nobrl", 5) == 0 || strncmp(token, "nolock", 6) == 0) return OPT_NO_LOCK; if (strncmp(token, "mand", 4) == 0) return OPT_MAND; if (strncmp(token, "nomand", 6) == 0) return OPT_NOMAND; if (strncmp(token, "dev", 3) == 0) return OPT_DEV; if (strncmp(token, "noexec", 6) == 0) return OPT_NO_EXEC; if (strncmp(token, "exec", 4) == 0) return OPT_EXEC; if (strncmp(token, "guest", 5) == 0) return OPT_GUEST; if (strncmp(token, "ro", 2) == 0) return OPT_RO; if (strncmp(token, "rw", 2) == 0) return OPT_RW; if (strncmp(token, "remount", 7) == 0) return OPT_REMOUNT; if (strncmp(token, "_netdev", 7) == 0) return OPT_IGNORE; return OPT_ERROR; }
DoS
0
static int parse_opt_token(const char *token) { if (token == NULL) return OPT_ERROR; if (strncmp(token, "users", 5) == 0) return OPT_USERS; if (strncmp(token, "user_xattr", 10) == 0) return OPT_USER_XATTR; if (strncmp(token, "user", 4) == 0) return OPT_USER; if (strncmp(token, "pass", 4) == 0) return OPT_PASS; if (strncmp(token, "sec", 3) == 0) return OPT_SEC; if (strncmp(token, "ip", 2) == 0) return OPT_IP; if (strncmp(token, "unc", 3) == 0 || strncmp(token, "target", 6) == 0 || strncmp(token, "path", 4) == 0) return OPT_UNC; if (strncmp(token, "dom", 3) == 0 || strncmp(token, "workg", 5) == 0) return OPT_DOM; if (strncmp(token, "cred", 4) == 0) return OPT_CRED; if (strncmp(token, "uid", 3) == 0) return OPT_UID; if (strncmp(token, "cruid", 5) == 0) return OPT_CRUID; if (strncmp(token, "gid", 3) == 0) return OPT_GID; if (strncmp(token, "fmask", 5) == 0) return OPT_FMASK; if (strncmp(token, "file_mode", 9) == 0) return OPT_FILE_MODE; if (strncmp(token, "dmask", 5) == 0) return OPT_DMASK; if (strncmp(token, "dir_mode", 4) == 0 || strncmp(token, "dirm", 4) == 0) return OPT_DIR_MODE; if (strncmp(token, "nosuid", 6) == 0) return OPT_NO_SUID; if (strncmp(token, "suid", 4) == 0) return OPT_SUID; if (strncmp(token, "nodev", 5) == 0) return OPT_NO_DEV; if (strncmp(token, "nobrl", 5) == 0 || strncmp(token, "nolock", 6) == 0) return OPT_NO_LOCK; if (strncmp(token, "mand", 4) == 0) return OPT_MAND; if (strncmp(token, "nomand", 6) == 0) return OPT_NOMAND; if (strncmp(token, "dev", 3) == 0) return OPT_DEV; if (strncmp(token, "noexec", 6) == 0) return OPT_NO_EXEC; if (strncmp(token, "exec", 4) == 0) return OPT_EXEC; if (strncmp(token, "guest", 5) == 0) return OPT_GUEST; if (strncmp(token, "ro", 2) == 0) return OPT_RO; if (strncmp(token, "rw", 2) == 0) return OPT_RW; if (strncmp(token, "remount", 7) == 0) return OPT_REMOUNT; if (strncmp(token, "_netdev", 7) == 0) return OPT_IGNORE; return OPT_ERROR; }
@@ -1419,8 +1419,7 @@ static int check_newline(const char *progname, const char *name) static int check_mtab(const char *progname, const char *devname, const char *dir) { - if (check_newline(progname, devname) == -1 || - check_newline(progname, dir) == -1) + if (check_newline(progname, devname) || check_newline(progname, dir)) return EX_USAGE; return 0; }
CWE-20
null
null
1,622
parse_options(const char *data, struct parsed_mount_info *parsed_info) { char *value = NULL; char *equals = NULL; char *next_keyword = NULL; char *out = parsed_info->options; unsigned long *filesys_flags = &parsed_info->flags; int out_len = 0; int word_len; int rc = 0; int got_uid = 0; int got_cruid = 0; int got_gid = 0; uid_t uid, cruid = 0; gid_t gid; char *ep; struct passwd *pw; struct group *gr; /* * max 32-bit uint in decimal is 4294967295 which is 10 chars wide * +1 for NULL, and +1 for good measure */ char txtbuf[12]; /* make sure we're starting from beginning */ out[0] = '\0'; /* BB fixme check for separator override BB */ uid = getuid(); if (uid != 0) got_uid = 1; gid = getgid(); if (gid != 0) got_gid = 1; if (!data) return EX_USAGE; /* * format is keyword,keyword2=value2,keyword3=value3... * data = next keyword * value = next value ie stuff after equal sign */ while (data && *data) { next_keyword = strchr(data, ','); /* BB handle sep= */ /* temporarily null terminate end of keyword=value pair */ if (next_keyword) *next_keyword++ = 0; /* temporarily null terminate keyword if there's a value */ value = NULL; if ((equals = strchr(data, '=')) != NULL) { *equals = '\0'; value = equals + 1; } switch(parse_opt_token(data)) { case OPT_USERS: if (!value || !*value) { *filesys_flags |= MS_USERS; goto nocopy; } break; case OPT_USER: if (!value || !*value) { if (data[4] == '\0') { *filesys_flags |= MS_USER; goto nocopy; } else { fprintf(stderr, "username specified with no parameter\n"); return EX_USAGE; } } else { /* domain/username%password */ const int max = MAX_DOMAIN_SIZE + MAX_USERNAME_SIZE + MOUNT_PASSWD_SIZE + 2; if (strnlen(value, max + 1) >= max + 1) { fprintf(stderr, "username too long\n"); return EX_USAGE; } rc = parse_username(value, parsed_info); if (rc) { fprintf(stderr, "problem parsing username\n"); return rc; } goto nocopy; } case OPT_PASS: if (parsed_info->got_password) { fprintf(stderr, "password specified twice, ignoring second\n"); goto nocopy; } if (!value || !*value) { parsed_info->got_password = 1; goto nocopy; } rc = set_password(parsed_info, value); if (rc) return rc; goto nocopy; case OPT_SEC: if (value) { if (!strncmp(value, "none", 4) || !strncmp(value, "krb5", 4)) parsed_info->got_password = 1; } break; case OPT_IP: if (!value || !*value) { fprintf(stderr, "target ip address argument missing\n"); } else if (strnlen(value, MAX_ADDRESS_LEN) <= MAX_ADDRESS_LEN) { strcpy(parsed_info->addrlist, value); if (parsed_info->verboseflag) fprintf(stderr, "ip address %s override specified\n", value); goto nocopy; } else { fprintf(stderr, "ip address too long\n"); return EX_USAGE; } break; /* unc || target || path */ case OPT_UNC: if (!value || !*value) { fprintf(stderr, "invalid path to network resource\n"); return EX_USAGE; } rc = parse_unc(value, parsed_info); if (rc) return rc; break; /* dom || workgroup */ case OPT_DOM: if (!value || !*value) { fprintf(stderr, "CIFS: invalid domain name\n"); return EX_USAGE; } if (strnlen(value, sizeof(parsed_info->domain)) >= sizeof(parsed_info->domain)) { fprintf(stderr, "domain name too long\n"); return EX_USAGE; } strlcpy(parsed_info->domain, value, sizeof(parsed_info->domain)); goto nocopy; case OPT_CRED: if (!value || !*value) { fprintf(stderr, "invalid credential file name specified\n"); return EX_USAGE; } rc = open_cred_file(value, parsed_info); if (rc) { fprintf(stderr, "error %d (%s) opening credential file %s\n", rc, strerror(rc), value); return rc; } break; case OPT_UID: if (!value || !*value) goto nocopy; got_uid = 1; errno = 0; uid = strtoul(value, &ep, 10); if (errno == 0) goto nocopy; pw = getpwnam(value); if (pw == NULL) { fprintf(stderr, "bad user name \"%s\"\n", value); return EX_USAGE; } uid = pw->pw_uid; goto nocopy; case OPT_CRUID: if (!value || !*value) goto nocopy; got_cruid = 1; errno = 0; cruid = strtoul(value, &ep, 10); if (errno == 0) goto nocopy; pw = getpwnam(value); if (pw == NULL) { fprintf(stderr, "bad user name \"%s\"\n", value); return EX_USAGE; } cruid = pw->pw_uid; goto nocopy; case OPT_GID: if (!value || !*value) goto nocopy; got_gid = 1; errno = 0; gid = strtoul(value, &ep, 10); if (errno == 0) goto nocopy; gr = getgrnam(value); if (gr == NULL) { fprintf(stderr, "bad group name \"%s\"\n", value); return EX_USAGE; } gid = gr->gr_gid; goto nocopy; /* fmask fall through to file_mode */ case OPT_FMASK: fprintf(stderr, "WARNING: CIFS mount option 'fmask' is\ deprecated. Use 'file_mode' instead.\n"); data = "file_mode"; /* BB fix this */ case OPT_FILE_MODE: if (!value || !*value) { fprintf(stderr, "Option '%s' requires a numerical argument\n", data); return EX_USAGE; } if (value[0] != '0') fprintf(stderr, "WARNING: '%s' not expressed in octal.\n", data); break; /* dmask falls through to dir_mode */ case OPT_DMASK: fprintf(stderr, "WARNING: CIFS mount option 'dmask' is\ deprecated. Use 'dir_mode' instead.\n"); data = "dir_mode"; case OPT_DIR_MODE: if (!value || !*value) { fprintf(stderr, "Option '%s' requires a numerical argument\n", data); return EX_USAGE; } if (value[0] != '0') fprintf(stderr, "WARNING: '%s' not expressed in octal.\n", data); break; /* the following mount options should be stripped out from what is passed into the kernel since these options are best passed as the mount flags rather than redundantly to the kernel and could generate spurious warnings depending on the level of the corresponding cifs vfs kernel code */ case OPT_NO_SUID: *filesys_flags |= MS_NOSUID; break; case OPT_SUID: *filesys_flags &= ~MS_NOSUID; break; case OPT_NO_DEV: *filesys_flags |= MS_NODEV; break; /* nolock || nobrl */ case OPT_NO_LOCK: *filesys_flags &= ~MS_MANDLOCK; break; case OPT_MAND: *filesys_flags |= MS_MANDLOCK; goto nocopy; case OPT_NOMAND: *filesys_flags &= ~MS_MANDLOCK; goto nocopy; case OPT_DEV: *filesys_flags &= ~MS_NODEV; break; case OPT_NO_EXEC: *filesys_flags |= MS_NOEXEC; break; case OPT_EXEC: *filesys_flags &= ~MS_NOEXEC; break; case OPT_GUEST: parsed_info->got_user = 1; parsed_info->got_password = 1; break; case OPT_RO: *filesys_flags |= MS_RDONLY; goto nocopy; case OPT_RW: *filesys_flags &= ~MS_RDONLY; goto nocopy; case OPT_REMOUNT: *filesys_flags |= MS_REMOUNT; break; case OPT_IGNORE: goto nocopy; } /* check size before copying option to buffer */ word_len = strlen(data); if (value) word_len += 1 + strlen(value); /* need 2 extra bytes for comma and null byte */ if (out_len + word_len + 2 > MAX_OPTIONS_LEN) { fprintf(stderr, "Options string too long\n"); return EX_USAGE; } /* put back equals sign, if any */ if (equals) *equals = '='; /* go ahead and copy */ if (out_len) strlcat(out, ",", MAX_OPTIONS_LEN); strlcat(out, data, MAX_OPTIONS_LEN); out_len = strlen(out); nocopy: data = next_keyword; } /* special-case the uid and gid */ if (got_uid) { word_len = snprintf(txtbuf, sizeof(txtbuf), "%u", uid); /* comma + "uid=" + terminating NULL == 6 */ if (out_len + word_len + 6 > MAX_OPTIONS_LEN) { fprintf(stderr, "Options string too long\n"); return EX_USAGE; } if (out_len) { strlcat(out, ",", MAX_OPTIONS_LEN); out_len++; } snprintf(out + out_len, word_len + 5, "uid=%s", txtbuf); out_len = strlen(out); } if (got_cruid) { word_len = snprintf(txtbuf, sizeof(txtbuf), "%u", cruid); /* comma + "cruid=" + terminating NULL == 6 */ if (out_len + word_len + 8 > MAX_OPTIONS_LEN) { fprintf(stderr, "Options string too long\n"); return EX_USAGE; } if (out_len) { strlcat(out, ",", MAX_OPTIONS_LEN); out_len++; } snprintf(out + out_len, word_len + 7, "cruid=%s", txtbuf); out_len = strlen(out); } if (got_gid) { word_len = snprintf(txtbuf, sizeof(txtbuf), "%u", gid); /* comma + "gid=" + terminating NULL == 6 */ if (out_len + word_len + 6 > MAX_OPTIONS_LEN) { fprintf(stderr, "Options string too long\n"); return EX_USAGE; } if (out_len) { strlcat(out, ",", MAX_OPTIONS_LEN); out_len++; } snprintf(out + out_len, word_len + 5, "gid=%s", txtbuf); } return 0; }
DoS
0
parse_options(const char *data, struct parsed_mount_info *parsed_info) { char *value = NULL; char *equals = NULL; char *next_keyword = NULL; char *out = parsed_info->options; unsigned long *filesys_flags = &parsed_info->flags; int out_len = 0; int word_len; int rc = 0; int got_uid = 0; int got_cruid = 0; int got_gid = 0; uid_t uid, cruid = 0; gid_t gid; char *ep; struct passwd *pw; struct group *gr; /* * max 32-bit uint in decimal is 4294967295 which is 10 chars wide * +1 for NULL, and +1 for good measure */ char txtbuf[12]; /* make sure we're starting from beginning */ out[0] = '\0'; /* BB fixme check for separator override BB */ uid = getuid(); if (uid != 0) got_uid = 1; gid = getgid(); if (gid != 0) got_gid = 1; if (!data) return EX_USAGE; /* * format is keyword,keyword2=value2,keyword3=value3... * data = next keyword * value = next value ie stuff after equal sign */ while (data && *data) { next_keyword = strchr(data, ','); /* BB handle sep= */ /* temporarily null terminate end of keyword=value pair */ if (next_keyword) *next_keyword++ = 0; /* temporarily null terminate keyword if there's a value */ value = NULL; if ((equals = strchr(data, '=')) != NULL) { *equals = '\0'; value = equals + 1; } switch(parse_opt_token(data)) { case OPT_USERS: if (!value || !*value) { *filesys_flags |= MS_USERS; goto nocopy; } break; case OPT_USER: if (!value || !*value) { if (data[4] == '\0') { *filesys_flags |= MS_USER; goto nocopy; } else { fprintf(stderr, "username specified with no parameter\n"); return EX_USAGE; } } else { /* domain/username%password */ const int max = MAX_DOMAIN_SIZE + MAX_USERNAME_SIZE + MOUNT_PASSWD_SIZE + 2; if (strnlen(value, max + 1) >= max + 1) { fprintf(stderr, "username too long\n"); return EX_USAGE; } rc = parse_username(value, parsed_info); if (rc) { fprintf(stderr, "problem parsing username\n"); return rc; } goto nocopy; } case OPT_PASS: if (parsed_info->got_password) { fprintf(stderr, "password specified twice, ignoring second\n"); goto nocopy; } if (!value || !*value) { parsed_info->got_password = 1; goto nocopy; } rc = set_password(parsed_info, value); if (rc) return rc; goto nocopy; case OPT_SEC: if (value) { if (!strncmp(value, "none", 4) || !strncmp(value, "krb5", 4)) parsed_info->got_password = 1; } break; case OPT_IP: if (!value || !*value) { fprintf(stderr, "target ip address argument missing\n"); } else if (strnlen(value, MAX_ADDRESS_LEN) <= MAX_ADDRESS_LEN) { strcpy(parsed_info->addrlist, value); if (parsed_info->verboseflag) fprintf(stderr, "ip address %s override specified\n", value); goto nocopy; } else { fprintf(stderr, "ip address too long\n"); return EX_USAGE; } break; /* unc || target || path */ case OPT_UNC: if (!value || !*value) { fprintf(stderr, "invalid path to network resource\n"); return EX_USAGE; } rc = parse_unc(value, parsed_info); if (rc) return rc; break; /* dom || workgroup */ case OPT_DOM: if (!value || !*value) { fprintf(stderr, "CIFS: invalid domain name\n"); return EX_USAGE; } if (strnlen(value, sizeof(parsed_info->domain)) >= sizeof(parsed_info->domain)) { fprintf(stderr, "domain name too long\n"); return EX_USAGE; } strlcpy(parsed_info->domain, value, sizeof(parsed_info->domain)); goto nocopy; case OPT_CRED: if (!value || !*value) { fprintf(stderr, "invalid credential file name specified\n"); return EX_USAGE; } rc = open_cred_file(value, parsed_info); if (rc) { fprintf(stderr, "error %d (%s) opening credential file %s\n", rc, strerror(rc), value); return rc; } break; case OPT_UID: if (!value || !*value) goto nocopy; got_uid = 1; errno = 0; uid = strtoul(value, &ep, 10); if (errno == 0) goto nocopy; pw = getpwnam(value); if (pw == NULL) { fprintf(stderr, "bad user name \"%s\"\n", value); return EX_USAGE; } uid = pw->pw_uid; goto nocopy; case OPT_CRUID: if (!value || !*value) goto nocopy; got_cruid = 1; errno = 0; cruid = strtoul(value, &ep, 10); if (errno == 0) goto nocopy; pw = getpwnam(value); if (pw == NULL) { fprintf(stderr, "bad user name \"%s\"\n", value); return EX_USAGE; } cruid = pw->pw_uid; goto nocopy; case OPT_GID: if (!value || !*value) goto nocopy; got_gid = 1; errno = 0; gid = strtoul(value, &ep, 10); if (errno == 0) goto nocopy; gr = getgrnam(value); if (gr == NULL) { fprintf(stderr, "bad group name \"%s\"\n", value); return EX_USAGE; } gid = gr->gr_gid; goto nocopy; /* fmask fall through to file_mode */ case OPT_FMASK: fprintf(stderr, "WARNING: CIFS mount option 'fmask' is\ deprecated. Use 'file_mode' instead.\n"); data = "file_mode"; /* BB fix this */ case OPT_FILE_MODE: if (!value || !*value) { fprintf(stderr, "Option '%s' requires a numerical argument\n", data); return EX_USAGE; } if (value[0] != '0') fprintf(stderr, "WARNING: '%s' not expressed in octal.\n", data); break; /* dmask falls through to dir_mode */ case OPT_DMASK: fprintf(stderr, "WARNING: CIFS mount option 'dmask' is\ deprecated. Use 'dir_mode' instead.\n"); data = "dir_mode"; case OPT_DIR_MODE: if (!value || !*value) { fprintf(stderr, "Option '%s' requires a numerical argument\n", data); return EX_USAGE; } if (value[0] != '0') fprintf(stderr, "WARNING: '%s' not expressed in octal.\n", data); break; /* the following mount options should be stripped out from what is passed into the kernel since these options are best passed as the mount flags rather than redundantly to the kernel and could generate spurious warnings depending on the level of the corresponding cifs vfs kernel code */ case OPT_NO_SUID: *filesys_flags |= MS_NOSUID; break; case OPT_SUID: *filesys_flags &= ~MS_NOSUID; break; case OPT_NO_DEV: *filesys_flags |= MS_NODEV; break; /* nolock || nobrl */ case OPT_NO_LOCK: *filesys_flags &= ~MS_MANDLOCK; break; case OPT_MAND: *filesys_flags |= MS_MANDLOCK; goto nocopy; case OPT_NOMAND: *filesys_flags &= ~MS_MANDLOCK; goto nocopy; case OPT_DEV: *filesys_flags &= ~MS_NODEV; break; case OPT_NO_EXEC: *filesys_flags |= MS_NOEXEC; break; case OPT_EXEC: *filesys_flags &= ~MS_NOEXEC; break; case OPT_GUEST: parsed_info->got_user = 1; parsed_info->got_password = 1; break; case OPT_RO: *filesys_flags |= MS_RDONLY; goto nocopy; case OPT_RW: *filesys_flags &= ~MS_RDONLY; goto nocopy; case OPT_REMOUNT: *filesys_flags |= MS_REMOUNT; break; case OPT_IGNORE: goto nocopy; } /* check size before copying option to buffer */ word_len = strlen(data); if (value) word_len += 1 + strlen(value); /* need 2 extra bytes for comma and null byte */ if (out_len + word_len + 2 > MAX_OPTIONS_LEN) { fprintf(stderr, "Options string too long\n"); return EX_USAGE; } /* put back equals sign, if any */ if (equals) *equals = '='; /* go ahead and copy */ if (out_len) strlcat(out, ",", MAX_OPTIONS_LEN); strlcat(out, data, MAX_OPTIONS_LEN); out_len = strlen(out); nocopy: data = next_keyword; } /* special-case the uid and gid */ if (got_uid) { word_len = snprintf(txtbuf, sizeof(txtbuf), "%u", uid); /* comma + "uid=" + terminating NULL == 6 */ if (out_len + word_len + 6 > MAX_OPTIONS_LEN) { fprintf(stderr, "Options string too long\n"); return EX_USAGE; } if (out_len) { strlcat(out, ",", MAX_OPTIONS_LEN); out_len++; } snprintf(out + out_len, word_len + 5, "uid=%s", txtbuf); out_len = strlen(out); } if (got_cruid) { word_len = snprintf(txtbuf, sizeof(txtbuf), "%u", cruid); /* comma + "cruid=" + terminating NULL == 6 */ if (out_len + word_len + 8 > MAX_OPTIONS_LEN) { fprintf(stderr, "Options string too long\n"); return EX_USAGE; } if (out_len) { strlcat(out, ",", MAX_OPTIONS_LEN); out_len++; } snprintf(out + out_len, word_len + 7, "cruid=%s", txtbuf); out_len = strlen(out); } if (got_gid) { word_len = snprintf(txtbuf, sizeof(txtbuf), "%u", gid); /* comma + "gid=" + terminating NULL == 6 */ if (out_len + word_len + 6 > MAX_OPTIONS_LEN) { fprintf(stderr, "Options string too long\n"); return EX_USAGE; } if (out_len) { strlcat(out, ",", MAX_OPTIONS_LEN); out_len++; } snprintf(out + out_len, word_len + 5, "gid=%s", txtbuf); } return 0; }
@@ -1419,8 +1419,7 @@ static int check_newline(const char *progname, const char *name) static int check_mtab(const char *progname, const char *devname, const char *dir) { - if (check_newline(progname, devname) == -1 || - check_newline(progname, dir) == -1) + if (check_newline(progname, devname) || check_newline(progname, dir)) return EX_USAGE; return 0; }
CWE-20
null
null
1,623
static int parse_unc(const char *unc_name, struct parsed_mount_info *parsed_info) { int length = strnlen(unc_name, MAX_UNC_LEN); const char *host, *share, *prepath; size_t hostlen, sharelen, prepathlen; if (length > (MAX_UNC_LEN - 1)) { fprintf(stderr, "mount error: UNC name too long\n"); return EX_USAGE; } if (length < 3) { fprintf(stderr, "mount error: UNC name too short\n"); return EX_USAGE; } if ((strncasecmp("cifs://", unc_name, 7) == 0) || (strncasecmp("smb://", unc_name, 6) == 0)) { fprintf(stderr, "Mounting cifs URL not implemented yet. Attempt to mount %s\n", unc_name); return EX_USAGE; } /* Set up "host" and "share" pointers based on UNC format. */ if (strncmp(unc_name, "//", 2) && strncmp(unc_name, "\\\\", 2)) { /* * check for nfs syntax (server:/share/prepath) * * FIXME: IPv6 addresses? */ host = unc_name; share = strchr(host, ':'); if (!share) { fprintf(stderr, "mount.cifs: bad UNC (%s)\n", unc_name); return EX_USAGE; } hostlen = share - host; share++; if (*share == '/') ++share; } else { host = unc_name + 2; hostlen = strcspn(host, "/\\"); if (!hostlen) { fprintf(stderr, "mount.cifs: bad UNC (%s)\n", unc_name); return EX_USAGE; } share = host + hostlen + 1; } if (hostlen + 1 > sizeof(parsed_info->host)) { fprintf(stderr, "mount.cifs: host portion of UNC too long\n"); return EX_USAGE; } sharelen = strcspn(share, "/\\"); if (sharelen + 1 > sizeof(parsed_info->share)) { fprintf(stderr, "mount.cifs: share portion of UNC too long\n"); return EX_USAGE; } prepath = share + sharelen; if (*prepath != '\0') prepath++; prepathlen = strlen(prepath); if (prepathlen + 1 > sizeof(parsed_info->prefix)) { fprintf(stderr, "mount.cifs: UNC prefixpath too long\n"); return EX_USAGE; } /* copy pieces into their resepective buffers */ memcpy(parsed_info->host, host, hostlen); memcpy(parsed_info->share, share, sharelen); memcpy(parsed_info->prefix, prepath, prepathlen); return 0; }
DoS
0
static int parse_unc(const char *unc_name, struct parsed_mount_info *parsed_info) { int length = strnlen(unc_name, MAX_UNC_LEN); const char *host, *share, *prepath; size_t hostlen, sharelen, prepathlen; if (length > (MAX_UNC_LEN - 1)) { fprintf(stderr, "mount error: UNC name too long\n"); return EX_USAGE; } if (length < 3) { fprintf(stderr, "mount error: UNC name too short\n"); return EX_USAGE; } if ((strncasecmp("cifs://", unc_name, 7) == 0) || (strncasecmp("smb://", unc_name, 6) == 0)) { fprintf(stderr, "Mounting cifs URL not implemented yet. Attempt to mount %s\n", unc_name); return EX_USAGE; } /* Set up "host" and "share" pointers based on UNC format. */ if (strncmp(unc_name, "//", 2) && strncmp(unc_name, "\\\\", 2)) { /* * check for nfs syntax (server:/share/prepath) * * FIXME: IPv6 addresses? */ host = unc_name; share = strchr(host, ':'); if (!share) { fprintf(stderr, "mount.cifs: bad UNC (%s)\n", unc_name); return EX_USAGE; } hostlen = share - host; share++; if (*share == '/') ++share; } else { host = unc_name + 2; hostlen = strcspn(host, "/\\"); if (!hostlen) { fprintf(stderr, "mount.cifs: bad UNC (%s)\n", unc_name); return EX_USAGE; } share = host + hostlen + 1; } if (hostlen + 1 > sizeof(parsed_info->host)) { fprintf(stderr, "mount.cifs: host portion of UNC too long\n"); return EX_USAGE; } sharelen = strcspn(share, "/\\"); if (sharelen + 1 > sizeof(parsed_info->share)) { fprintf(stderr, "mount.cifs: share portion of UNC too long\n"); return EX_USAGE; } prepath = share + sharelen; if (*prepath != '\0') prepath++; prepathlen = strlen(prepath); if (prepathlen + 1 > sizeof(parsed_info->prefix)) { fprintf(stderr, "mount.cifs: UNC prefixpath too long\n"); return EX_USAGE; } /* copy pieces into their resepective buffers */ memcpy(parsed_info->host, host, hostlen); memcpy(parsed_info->share, share, sharelen); memcpy(parsed_info->prefix, prepath, prepathlen); return 0; }
@@ -1419,8 +1419,7 @@ static int check_newline(const char *progname, const char *name) static int check_mtab(const char *progname, const char *devname, const char *dir) { - if (check_newline(progname, devname) == -1 || - check_newline(progname, dir) == -1) + if (check_newline(progname, devname) || check_newline(progname, dir)) return EX_USAGE; return 0; }
CWE-20
null
null
1,624
static int parse_username(char *rawuser, struct parsed_mount_info *parsed_info) { char *user, *password, slash; int rc = 0; /* everything after first % sign is a password */ password = strchr(rawuser, '%'); if (password) { rc = set_password(parsed_info, password + 1); if (rc) return rc; *password = '\0'; } /* everything after first '/' or '\' is a username */ user = strchr(rawuser, '/'); if (!user) user = strchr(rawuser, '\\'); /* everything before that slash is a domain */ if (user) { slash = *user; *user = '\0'; strlcpy(parsed_info->domain, rawuser, sizeof(parsed_info->domain)); *(user++) = slash; } else { user = rawuser; } strlcpy(parsed_info->username, user, sizeof(parsed_info->username)); parsed_info->got_user = 1; if (password) *password = '%'; return 0; }
DoS
0
static int parse_username(char *rawuser, struct parsed_mount_info *parsed_info) { char *user, *password, slash; int rc = 0; /* everything after first % sign is a password */ password = strchr(rawuser, '%'); if (password) { rc = set_password(parsed_info, password + 1); if (rc) return rc; *password = '\0'; } /* everything after first '/' or '\' is a username */ user = strchr(rawuser, '/'); if (!user) user = strchr(rawuser, '\\'); /* everything before that slash is a domain */ if (user) { slash = *user; *user = '\0'; strlcpy(parsed_info->domain, rawuser, sizeof(parsed_info->domain)); *(user++) = slash; } else { user = rawuser; } strlcpy(parsed_info->username, user, sizeof(parsed_info->username)); parsed_info->got_user = 1; if (password) *password = '%'; return 0; }
@@ -1419,8 +1419,7 @@ static int check_newline(const char *progname, const char *name) static int check_mtab(const char *progname, const char *devname, const char *dir) { - if (check_newline(progname, devname) == -1 || - check_newline(progname, dir) == -1) + if (check_newline(progname, devname) || check_newline(progname, dir)) return EX_USAGE; return 0; }
CWE-20
null
null
1,625
static void print_cifs_mount_version(void) { printf("mount.cifs version: %s\n", VERSION); }
DoS
0
static void print_cifs_mount_version(void) { printf("mount.cifs version: %s\n", VERSION); }
@@ -1419,8 +1419,7 @@ static int check_newline(const char *progname, const char *name) static int check_mtab(const char *progname, const char *devname, const char *dir) { - if (check_newline(progname, devname) == -1 || - check_newline(progname, dir) == -1) + if (check_newline(progname, devname) || check_newline(progname, dir)) return EX_USAGE; return 0; }
CWE-20
null
null
1,626
prune_bounding_set(void) { int i, rc = 0; static int bounding_set_cleared; if (bounding_set_cleared) return 0; for (i = 0; i <= CAP_LAST_CAP && rc == 0; ++i) rc = prctl(PR_CAPBSET_DROP, i); if (rc != 0) { fprintf(stderr, "Unable to clear capability bounding set: %d\n", rc); return EX_SYSERR; } ++bounding_set_cleared; return 0; }
DoS
0
prune_bounding_set(void) { int i, rc = 0; static int bounding_set_cleared; if (bounding_set_cleared) return 0; for (i = 0; i <= CAP_LAST_CAP && rc == 0; ++i) rc = prctl(PR_CAPBSET_DROP, i); if (rc != 0) { fprintf(stderr, "Unable to clear capability bounding set: %d\n", rc); return EX_SYSERR; } ++bounding_set_cleared; return 0; }
@@ -1419,8 +1419,7 @@ static int check_newline(const char *progname, const char *name) static int check_mtab(const char *progname, const char *devname, const char *dir) { - if (check_newline(progname, devname) == -1 || - check_newline(progname, dir) == -1) + if (check_newline(progname, devname) || check_newline(progname, dir)) return EX_USAGE; return 0; }
CWE-20
null
null
1,627
static int set_password(struct parsed_mount_info *parsed_info, const char *src) { char *dst = parsed_info->password; unsigned int i = 0, j = 0; while (src[i]) { if (src[i] == ',') dst[j++] = ','; dst[j++] = src[i++]; if (j > sizeof(parsed_info->password)) { fprintf(stderr, "Converted password too long!\n"); return EX_USAGE; } } dst[j] = '\0'; parsed_info->got_password = 1; return 0; }
DoS
0
static int set_password(struct parsed_mount_info *parsed_info, const char *src) { char *dst = parsed_info->password; unsigned int i = 0, j = 0; while (src[i]) { if (src[i] == ',') dst[j++] = ','; dst[j++] = src[i++]; if (j > sizeof(parsed_info->password)) { fprintf(stderr, "Converted password too long!\n"); return EX_USAGE; } } dst[j] = '\0'; parsed_info->got_password = 1; return 0; }
@@ -1419,8 +1419,7 @@ static int check_newline(const char *progname, const char *name) static int check_mtab(const char *progname, const char *devname, const char *dir) { - if (check_newline(progname, devname) == -1 || - check_newline(progname, dir) == -1) + if (check_newline(progname, devname) || check_newline(progname, dir)) return EX_USAGE; return 0; }
CWE-20
null
null
1,628
toggle_dac_capability(int writable, int enable) { unsigned int capability = writable ? CAP_DAC_OVERRIDE : CAP_DAC_READ_SEARCH; if (capng_update(enable ? CAPNG_ADD : CAPNG_DROP, CAPNG_EFFECTIVE, capability)) { fprintf(stderr, "Unable to update capability set.\n"); return EX_SYSERR; } if (capng_apply(CAPNG_SELECT_CAPS)) { fprintf(stderr, "Unable to apply new capability set.\n"); return EX_SYSERR; } return 0; }
DoS
0
toggle_dac_capability(int writable, int enable) { unsigned int capability = writable ? CAP_DAC_OVERRIDE : CAP_DAC_READ_SEARCH; if (capng_update(enable ? CAPNG_ADD : CAPNG_DROP, CAPNG_EFFECTIVE, capability)) { fprintf(stderr, "Unable to update capability set.\n"); return EX_SYSERR; } if (capng_apply(CAPNG_SELECT_CAPS)) { fprintf(stderr, "Unable to apply new capability set.\n"); return EX_SYSERR; } return 0; }
@@ -1419,8 +1419,7 @@ static int check_newline(const char *progname, const char *name) static int check_mtab(const char *progname, const char *devname, const char *dir) { - if (check_newline(progname, devname) == -1 || - check_newline(progname, dir) == -1) + if (check_newline(progname, devname) || check_newline(progname, dir)) return EX_USAGE; return 0; }
CWE-20
null
null
1,629
toggle_dac_capability(int writable, int enable) { int rc; cap_t caps; cap_value_t capability = writable ? CAP_DAC_OVERRIDE : CAP_DAC_READ_SEARCH; if (getuid() != 0) return 0; caps = cap_get_proc(); if (caps == NULL) { fprintf(stderr, "Unable to get current capability set: %s\n", strerror(errno)); return EX_SYSERR; } if (cap_set_flag(caps, CAP_EFFECTIVE, 1, &capability, enable ? CAP_SET : CAP_CLEAR) == -1) { fprintf(stderr, "Unable to %s effective capabilities: %s\n", enable ? "set" : "clear", strerror(errno)); rc = EX_SYSERR; goto free_caps; } if (cap_set_proc(caps) != 0) { fprintf(stderr, "Unable to set current process capabilities: %s\n", strerror(errno)); rc = EX_SYSERR; } free_caps: cap_free(caps); return 0; }
DoS
0
toggle_dac_capability(int writable, int enable) { int rc; cap_t caps; cap_value_t capability = writable ? CAP_DAC_OVERRIDE : CAP_DAC_READ_SEARCH; if (getuid() != 0) return 0; caps = cap_get_proc(); if (caps == NULL) { fprintf(stderr, "Unable to get current capability set: %s\n", strerror(errno)); return EX_SYSERR; } if (cap_set_flag(caps, CAP_EFFECTIVE, 1, &capability, enable ? CAP_SET : CAP_CLEAR) == -1) { fprintf(stderr, "Unable to %s effective capabilities: %s\n", enable ? "set" : "clear", strerror(errno)); rc = EX_SYSERR; goto free_caps; } if (cap_set_proc(caps) != 0) { fprintf(stderr, "Unable to set current process capabilities: %s\n", strerror(errno)); rc = EX_SYSERR; } free_caps: cap_free(caps); return 0; }
@@ -1419,8 +1419,7 @@ static int check_newline(const char *progname, const char *name) static int check_mtab(const char *progname, const char *devname, const char *dir) { - if (check_newline(progname, devname) == -1 || - check_newline(progname, dir) == -1) + if (check_newline(progname, devname) || check_newline(progname, dir)) return EX_USAGE; return 0; }
CWE-20
null
null
1,630
toggle_dac_capability(int writable, int enable) { return 0; }
DoS
0
toggle_dac_capability(int writable, int enable) { return 0; }
@@ -1419,8 +1419,7 @@ static int check_newline(const char *progname, const char *name) static int check_mtab(const char *progname, const char *devname, const char *dir) { - if (check_newline(progname, devname) == -1 || - check_newline(progname, dir) == -1) + if (check_newline(progname, devname) || check_newline(progname, dir)) return EX_USAGE; return 0; }
CWE-20
null
null
1,631
static int uppercase_string(char *string) { if (!string) return 1; while (*string) { /* check for unicode */ if ((unsigned char)string[0] & 0x80) return 0; *string = toupper((unsigned char)*string); string++; } return 1; }
DoS
0
static int uppercase_string(char *string) { if (!string) return 1; while (*string) { /* check for unicode */ if ((unsigned char)string[0] & 0x80) return 0; *string = toupper((unsigned char)*string); string++; } return 1; }
@@ -1419,8 +1419,7 @@ static int check_newline(const char *progname, const char *name) static int check_mtab(const char *progname, const char *devname, const char *dir) { - if (check_newline(progname, devname) == -1 || - check_newline(progname, dir) == -1) + if (check_newline(progname, devname) || check_newline(progname, dir)) return EX_USAGE; return 0; }
CWE-20
null
null
1,632
static int do_nothing_handle_message(RedChannelClient *rcc, uint16_t type, uint32_t size, uint8_t *msg) { return TRUE; }
DoS
0
static int do_nothing_handle_message(RedChannelClient *rcc, uint16_t type, uint32_t size, uint8_t *msg) { return TRUE; }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,633
static SpiceWatch *dummy_watch_add(int fd, int event_mask, SpiceWatchFunc func, void *opaque) { return NULL; // apparently allowed? }
DoS
0
static SpiceWatch *dummy_watch_add(int fd, int event_mask, SpiceWatchFunc func, void *opaque) { return NULL; // apparently allowed? }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,634
static void dummy_watch_remove(SpiceWatch *watch) { }
DoS
0
static void dummy_watch_remove(SpiceWatch *watch) { }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,635
static void dummy_watch_update_mask(SpiceWatch *watch, int event_mask) { }
DoS
0
static void dummy_watch_update_mask(SpiceWatch *watch, int event_mask) { }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,636
static uint32_t full_header_get_msg_size(SpiceDataHeaderOpaque *header) { return ((SpiceDataHeader *)header->data)->size; }
DoS
0
static uint32_t full_header_get_msg_size(SpiceDataHeaderOpaque *header) { return ((SpiceDataHeader *)header->data)->size; }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,637
static uint16_t full_header_get_msg_type(SpiceDataHeaderOpaque *header) { return ((SpiceDataHeader *)header->data)->type; }
DoS
0
static uint16_t full_header_get_msg_type(SpiceDataHeaderOpaque *header) { return ((SpiceDataHeader *)header->data)->type; }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,638
static void full_header_set_msg_type(SpiceDataHeaderOpaque *header, uint16_t type) { ((SpiceDataHeader *)header->data)->type = type; }
DoS
0
static void full_header_set_msg_type(SpiceDataHeaderOpaque *header, uint16_t type) { ((SpiceDataHeader *)header->data)->type = type; }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,639
static uint32_t mini_header_get_msg_size(SpiceDataHeaderOpaque *header) { return ((SpiceMiniDataHeader *)header->data)->size; }
DoS
0
static uint32_t mini_header_get_msg_size(SpiceDataHeaderOpaque *header) { return ((SpiceMiniDataHeader *)header->data)->size; }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,640
static uint16_t mini_header_get_msg_type(SpiceDataHeaderOpaque *header) { return ((SpiceMiniDataHeader *)header->data)->type; }
DoS
0
static uint16_t mini_header_get_msg_type(SpiceDataHeaderOpaque *header) { return ((SpiceMiniDataHeader *)header->data)->type; }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,641
static void mini_header_set_msg_serial(SpiceDataHeaderOpaque *header, uint64_t serial) { spice_error("attempt to set header serial on mini header"); }
DoS
0
static void mini_header_set_msg_serial(SpiceDataHeaderOpaque *header, uint64_t serial) { spice_error("attempt to set header serial on mini header"); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,642
static void mini_header_set_msg_size(SpiceDataHeaderOpaque *header, uint32_t size) { ((SpiceMiniDataHeader *)header->data)->size = size; }
DoS
0
static void mini_header_set_msg_size(SpiceDataHeaderOpaque *header, uint32_t size) { ((SpiceMiniDataHeader *)header->data)->size = size; }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,643
static void mini_header_set_msg_sub_list(SpiceDataHeaderOpaque *header, uint32_t sub_list) { spice_error("attempt to set header sub list on mini header"); }
DoS
0
static void mini_header_set_msg_sub_list(SpiceDataHeaderOpaque *header, uint32_t sub_list) { spice_error("attempt to set header sub list on mini header"); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,644
static void mini_header_set_msg_type(SpiceDataHeaderOpaque *header, uint16_t type) { ((SpiceMiniDataHeader *)header->data)->type = type; }
DoS
0
static void mini_header_set_msg_type(SpiceDataHeaderOpaque *header, uint16_t type) { ((SpiceMiniDataHeader *)header->data)->type = type; }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,645
static void red_channel_add_client(RedChannel *channel, RedChannelClient *rcc) { spice_assert(rcc); ring_add(&channel->clients, &rcc->channel_link); channel->clients_num++; }
DoS
0
static void red_channel_add_client(RedChannel *channel, RedChannelClient *rcc) { spice_assert(rcc); ring_add(&channel->clients, &rcc->channel_link); channel->clients_num++; }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,646
int red_channel_all_blocked(RedChannel *channel) { RingItem *link; RedChannelClient *rcc; if (!channel || channel->clients_num == 0) { return FALSE; } RING_FOREACH(link, &channel->clients) { rcc = SPICE_CONTAINEROF(link, RedChannelClient, channel_link); if (!rcc->send_data.blocked) { return FALSE; } } return TRUE; }
DoS
0
int red_channel_all_blocked(RedChannel *channel) { RingItem *link; RedChannelClient *rcc; if (!channel || channel->clients_num == 0) { return FALSE; } RING_FOREACH(link, &channel->clients) { rcc = SPICE_CONTAINEROF(link, RedChannelClient, channel_link); if (!rcc->send_data.blocked) { return FALSE; } } return TRUE; }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,647
int red_channel_any_blocked(RedChannel *channel) { RingItem *link; RedChannelClient *rcc; RING_FOREACH(link, &channel->clients) { rcc = SPICE_CONTAINEROF(link, RedChannelClient, channel_link); if (rcc->send_data.blocked) { return TRUE; } } return FALSE; }
DoS
0
int red_channel_any_blocked(RedChannel *channel) { RingItem *link; RedChannelClient *rcc; RING_FOREACH(link, &channel->clients) { rcc = SPICE_CONTAINEROF(link, RedChannelClient, channel_link); if (rcc->send_data.blocked) { return TRUE; } } return FALSE; }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,648
void red_channel_apply_clients(RedChannel *channel, channel_client_callback cb) { RingItem *link; RingItem *next; RedChannelClient *rcc; RING_FOREACH_SAFE(link, next, &channel->clients) { rcc = SPICE_CONTAINEROF(link, RedChannelClient, channel_link); cb(rcc); } }
DoS
0
void red_channel_apply_clients(RedChannel *channel, channel_client_callback cb) { RingItem *link; RingItem *next; RedChannelClient *rcc; RING_FOREACH_SAFE(link, next, &channel->clients) { rcc = SPICE_CONTAINEROF(link, RedChannelClient, channel_link); cb(rcc); } }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,649
void red_channel_apply_clients_data(RedChannel *channel, channel_client_callback_data cb, void *data) { RingItem *link; RingItem *next; RedChannelClient *rcc; RING_FOREACH_SAFE(link, next, &channel->clients) { rcc = SPICE_CONTAINEROF(link, RedChannelClient, channel_link); cb(rcc, data); } }
DoS
0
void red_channel_apply_clients_data(RedChannel *channel, channel_client_callback_data cb, void *data) { RingItem *link; RingItem *next; RedChannelClient *rcc; RING_FOREACH_SAFE(link, next, &channel->clients) { rcc = SPICE_CONTAINEROF(link, RedChannelClient, channel_link); cb(rcc, data); } }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,650
void red_channel_client_ack_set_client_window(RedChannelClient *rcc, int client_window) { rcc->ack_data.client_window = client_window; }
DoS
0
void red_channel_client_ack_set_client_window(RedChannelClient *rcc, int client_window) { rcc->ack_data.client_window = client_window; }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,651
void red_channel_client_begin_send_message(RedChannelClient *rcc) { SpiceMarshaller *m = rcc->send_data.marshaller; if (rcc->send_data.header.get_msg_type(&rcc->send_data.header) == 0) { spice_printerr("BUG: header->type == 0"); return; } /* canceling the latency test timer till the nework is idle */ red_channel_client_cancel_ping_timer(rcc); spice_marshaller_flush(m); rcc->send_data.size = spice_marshaller_get_total_size(m); rcc->send_data.header.set_msg_size(&rcc->send_data.header, rcc->send_data.size - rcc->send_data.header.header_size); rcc->ack_data.messages_window++; rcc->send_data.last_sent_serial = rcc->send_data.serial; rcc->send_data.header.data = NULL; /* avoid writing to this until we have a new message */ red_channel_client_send(rcc); }
DoS
0
void red_channel_client_begin_send_message(RedChannelClient *rcc) { SpiceMarshaller *m = rcc->send_data.marshaller; if (rcc->send_data.header.get_msg_type(&rcc->send_data.header) == 0) { spice_printerr("BUG: header->type == 0"); return; } /* canceling the latency test timer till the nework is idle */ red_channel_client_cancel_ping_timer(rcc); spice_marshaller_flush(m); rcc->send_data.size = spice_marshaller_get_total_size(m); rcc->send_data.header.set_msg_size(&rcc->send_data.header, rcc->send_data.size - rcc->send_data.header.header_size); rcc->ack_data.messages_window++; rcc->send_data.last_sent_serial = rcc->send_data.serial; rcc->send_data.header.data = NULL; /* avoid writing to this until we have a new message */ red_channel_client_send(rcc); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,652
static void red_channel_client_cancel_ping_timer(RedChannelClient *rcc) { if (!rcc->latency_monitor.timer) { return; } if (rcc->latency_monitor.state != PING_STATE_TIMER) { return; } rcc->channel->core->timer_cancel(rcc->latency_monitor.timer); rcc->latency_monitor.state = PING_STATE_NONE; }
DoS
0
static void red_channel_client_cancel_ping_timer(RedChannelClient *rcc) { if (!rcc->latency_monitor.timer) { return; } if (rcc->latency_monitor.state != PING_STATE_TIMER) { return; } rcc->channel->core->timer_cancel(rcc->latency_monitor.timer); rcc->latency_monitor.state = PING_STATE_NONE; }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,653
void red_channel_client_clear_sent_item(RedChannelClient *rcc) { if (rcc->send_data.item) { red_channel_client_release_item(rcc, rcc->send_data.item, TRUE); rcc->send_data.item = NULL; } rcc->send_data.blocked = FALSE; rcc->send_data.size = 0; }
DoS
0
void red_channel_client_clear_sent_item(RedChannelClient *rcc) { if (rcc->send_data.item) { red_channel_client_release_item(rcc, rcc->send_data.item, TRUE); rcc->send_data.item = NULL; } rcc->send_data.blocked = FALSE; rcc->send_data.size = 0; }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,654
RedChannelClient *red_channel_client_create(int size, RedChannel *channel, RedClient *client, RedsStream *stream, int monitor_latency, int num_common_caps, uint32_t *common_caps, int num_caps, uint32_t *caps) { RedChannelClient *rcc = NULL; pthread_mutex_lock(&client->lock); if (!red_channel_client_pre_create_validate(channel, client)) { goto error; } spice_assert(stream && channel && size >= sizeof(RedChannelClient)); rcc = spice_malloc0(size); rcc->stream = stream; rcc->channel = channel; rcc->client = client; rcc->refs = 1; rcc->ack_data.messages_window = ~0; // blocks send message (maybe use send_data.blocked + rcc->ack_data.client_generation = ~0; rcc->ack_data.client_window = CLIENT_ACK_WINDOW; rcc->send_data.main.marshaller = spice_marshaller_new(); rcc->send_data.urgent.marshaller = spice_marshaller_new(); rcc->send_data.marshaller = rcc->send_data.main.marshaller; rcc->incoming.opaque = rcc; rcc->incoming.cb = &channel->incoming_cb; rcc->outgoing.opaque = rcc; rcc->outgoing.cb = &channel->outgoing_cb; rcc->outgoing.pos = 0; rcc->outgoing.size = 0; red_channel_client_set_remote_caps(rcc, num_common_caps, common_caps, num_caps, caps); if (red_channel_client_test_remote_common_cap(rcc, SPICE_COMMON_CAP_MINI_HEADER)) { rcc->incoming.header = mini_header_wrapper; rcc->send_data.header = mini_header_wrapper; rcc->is_mini_header = TRUE; } else { rcc->incoming.header = full_header_wrapper; rcc->send_data.header = full_header_wrapper; rcc->is_mini_header = FALSE; } rcc->incoming.header.data = rcc->incoming.header_buf; rcc->incoming.serial = 1; if (!channel->channel_cbs.config_socket(rcc)) { goto error; } ring_init(&rcc->pipe); rcc->pipe_size = 0; stream->watch = channel->core->watch_add(stream->socket, SPICE_WATCH_EVENT_READ, red_channel_client_event, rcc); rcc->id = channel->clients_num; red_channel_add_client(channel, rcc); red_client_add_channel(client, rcc); red_channel_ref(channel); pthread_mutex_unlock(&client->lock); if (monitor_latency) { rcc->latency_monitor.timer = channel->core->timer_add( red_channel_client_ping_timer, rcc); if (!client->during_target_migrate) { red_channel_client_start_ping_timer(rcc, PING_TEST_IDLE_NET_TIMEOUT_MS); } rcc->latency_monitor.roundtrip = -1; } return rcc; error: free(rcc); reds_stream_free(stream); pthread_mutex_unlock(&client->lock); return NULL; }
DoS
0
RedChannelClient *red_channel_client_create(int size, RedChannel *channel, RedClient *client, RedsStream *stream, int monitor_latency, int num_common_caps, uint32_t *common_caps, int num_caps, uint32_t *caps) { RedChannelClient *rcc = NULL; pthread_mutex_lock(&client->lock); if (!red_channel_client_pre_create_validate(channel, client)) { goto error; } spice_assert(stream && channel && size >= sizeof(RedChannelClient)); rcc = spice_malloc0(size); rcc->stream = stream; rcc->channel = channel; rcc->client = client; rcc->refs = 1; rcc->ack_data.messages_window = ~0; // blocks send message (maybe use send_data.blocked + rcc->ack_data.client_generation = ~0; rcc->ack_data.client_window = CLIENT_ACK_WINDOW; rcc->send_data.main.marshaller = spice_marshaller_new(); rcc->send_data.urgent.marshaller = spice_marshaller_new(); rcc->send_data.marshaller = rcc->send_data.main.marshaller; rcc->incoming.opaque = rcc; rcc->incoming.cb = &channel->incoming_cb; rcc->outgoing.opaque = rcc; rcc->outgoing.cb = &channel->outgoing_cb; rcc->outgoing.pos = 0; rcc->outgoing.size = 0; red_channel_client_set_remote_caps(rcc, num_common_caps, common_caps, num_caps, caps); if (red_channel_client_test_remote_common_cap(rcc, SPICE_COMMON_CAP_MINI_HEADER)) { rcc->incoming.header = mini_header_wrapper; rcc->send_data.header = mini_header_wrapper; rcc->is_mini_header = TRUE; } else { rcc->incoming.header = full_header_wrapper; rcc->send_data.header = full_header_wrapper; rcc->is_mini_header = FALSE; } rcc->incoming.header.data = rcc->incoming.header_buf; rcc->incoming.serial = 1; if (!channel->channel_cbs.config_socket(rcc)) { goto error; } ring_init(&rcc->pipe); rcc->pipe_size = 0; stream->watch = channel->core->watch_add(stream->socket, SPICE_WATCH_EVENT_READ, red_channel_client_event, rcc); rcc->id = channel->clients_num; red_channel_add_client(channel, rcc); red_client_add_channel(client, rcc); red_channel_ref(channel); pthread_mutex_unlock(&client->lock); if (monitor_latency) { rcc->latency_monitor.timer = channel->core->timer_add( red_channel_client_ping_timer, rcc); if (!client->during_target_migrate) { red_channel_client_start_ping_timer(rcc, PING_TEST_IDLE_NET_TIMEOUT_MS); } rcc->latency_monitor.roundtrip = -1; } return rcc; error: free(rcc); reds_stream_free(stream); pthread_mutex_unlock(&client->lock); return NULL; }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,655
RedChannelClient *red_channel_client_create_dummy(int size, RedChannel *channel, RedClient *client, int num_common_caps, uint32_t *common_caps, int num_caps, uint32_t *caps) { RedChannelClient *rcc = NULL; spice_assert(size >= sizeof(RedChannelClient)); pthread_mutex_lock(&client->lock); if (!red_channel_client_pre_create_validate(channel, client)) { goto error; } rcc = spice_malloc0(size); rcc->refs = 1; rcc->client = client; rcc->channel = channel; red_channel_ref(channel); red_channel_client_set_remote_caps(rcc, num_common_caps, common_caps, num_caps, caps); if (red_channel_client_test_remote_common_cap(rcc, SPICE_COMMON_CAP_MINI_HEADER)) { rcc->incoming.header = mini_header_wrapper; rcc->send_data.header = mini_header_wrapper; rcc->is_mini_header = TRUE; } else { rcc->incoming.header = full_header_wrapper; rcc->send_data.header = full_header_wrapper; rcc->is_mini_header = FALSE; } rcc->incoming.header.data = rcc->incoming.header_buf; rcc->incoming.serial = 1; ring_init(&rcc->pipe); rcc->dummy = TRUE; rcc->dummy_connected = TRUE; red_channel_add_client(channel, rcc); red_client_add_channel(client, rcc); pthread_mutex_unlock(&client->lock); return rcc; error: pthread_mutex_unlock(&client->lock); return NULL; }
DoS
0
RedChannelClient *red_channel_client_create_dummy(int size, RedChannel *channel, RedClient *client, int num_common_caps, uint32_t *common_caps, int num_caps, uint32_t *caps) { RedChannelClient *rcc = NULL; spice_assert(size >= sizeof(RedChannelClient)); pthread_mutex_lock(&client->lock); if (!red_channel_client_pre_create_validate(channel, client)) { goto error; } rcc = spice_malloc0(size); rcc->refs = 1; rcc->client = client; rcc->channel = channel; red_channel_ref(channel); red_channel_client_set_remote_caps(rcc, num_common_caps, common_caps, num_caps, caps); if (red_channel_client_test_remote_common_cap(rcc, SPICE_COMMON_CAP_MINI_HEADER)) { rcc->incoming.header = mini_header_wrapper; rcc->send_data.header = mini_header_wrapper; rcc->is_mini_header = TRUE; } else { rcc->incoming.header = full_header_wrapper; rcc->send_data.header = full_header_wrapper; rcc->is_mini_header = FALSE; } rcc->incoming.header.data = rcc->incoming.header_buf; rcc->incoming.serial = 1; ring_init(&rcc->pipe); rcc->dummy = TRUE; rcc->dummy_connected = TRUE; red_channel_add_client(channel, rcc); red_client_add_channel(client, rcc); pthread_mutex_unlock(&client->lock); return rcc; error: pthread_mutex_unlock(&client->lock); return NULL; }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,656
static void red_channel_client_default_connect(RedChannel *channel, RedClient *client, RedsStream *stream, int migration, int num_common_caps, uint32_t *common_caps, int num_caps, uint32_t *caps) { spice_error("not implemented"); }
DoS
0
static void red_channel_client_default_connect(RedChannel *channel, RedClient *client, RedsStream *stream, int migration, int num_common_caps, uint32_t *common_caps, int num_caps, uint32_t *caps) { spice_error("not implemented"); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,657
static void red_channel_client_default_disconnect(RedChannelClient *base) { red_channel_client_disconnect(base); }
DoS
0
static void red_channel_client_default_disconnect(RedChannelClient *base) { red_channel_client_disconnect(base); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,658
void red_channel_client_default_migrate(RedChannelClient *rcc) { if (rcc->latency_monitor.timer) { red_channel_client_cancel_ping_timer(rcc); rcc->channel->core->timer_remove(rcc->latency_monitor.timer); rcc->latency_monitor.timer = NULL; } red_channel_client_pipe_add_type(rcc, PIPE_ITEM_TYPE_MIGRATE); }
DoS
0
void red_channel_client_default_migrate(RedChannelClient *rcc) { if (rcc->latency_monitor.timer) { red_channel_client_cancel_ping_timer(rcc); rcc->channel->core->timer_remove(rcc->latency_monitor.timer); rcc->latency_monitor.timer = NULL; } red_channel_client_pipe_add_type(rcc, PIPE_ITEM_TYPE_MIGRATE); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,659
static void red_channel_client_default_peer_on_error(RedChannelClient *rcc) { red_channel_client_disconnect(rcc); }
DoS
0
static void red_channel_client_default_peer_on_error(RedChannelClient *rcc) { red_channel_client_disconnect(rcc); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,660
static void red_channel_client_destroy_remote_caps(RedChannelClient* rcc) { rcc->remote_caps.num_common_caps = 0; free(rcc->remote_caps.common_caps); rcc->remote_caps.num_caps = 0; free(rcc->remote_caps.caps); }
DoS
0
static void red_channel_client_destroy_remote_caps(RedChannelClient* rcc) { rcc->remote_caps.num_common_caps = 0; free(rcc->remote_caps.common_caps); rcc->remote_caps.num_caps = 0; free(rcc->remote_caps.caps); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,661
void red_channel_client_disconnect(RedChannelClient *rcc) { spice_printerr("%p (channel %p type %d id %d)", rcc, rcc->channel, rcc->channel->type, rcc->channel->id); if (rcc->dummy) { red_channel_client_disconnect_dummy(rcc); return; } if (!red_channel_client_is_connected(rcc)) { return; } red_channel_client_pipe_clear(rcc); if (rcc->stream->watch) { rcc->channel->core->watch_remove(rcc->stream->watch); rcc->stream->watch = NULL; } reds_stream_free(rcc->stream); rcc->stream = NULL; if (rcc->latency_monitor.timer) { rcc->channel->core->timer_remove(rcc->latency_monitor.timer); rcc->latency_monitor.timer = NULL; } red_channel_remove_client(rcc); rcc->channel->channel_cbs.on_disconnect(rcc); }
DoS
0
void red_channel_client_disconnect(RedChannelClient *rcc) { spice_printerr("%p (channel %p type %d id %d)", rcc, rcc->channel, rcc->channel->type, rcc->channel->id); if (rcc->dummy) { red_channel_client_disconnect_dummy(rcc); return; } if (!red_channel_client_is_connected(rcc)) { return; } red_channel_client_pipe_clear(rcc); if (rcc->stream->watch) { rcc->channel->core->watch_remove(rcc->stream->watch); rcc->stream->watch = NULL; } reds_stream_free(rcc->stream); rcc->stream = NULL; if (rcc->latency_monitor.timer) { rcc->channel->core->timer_remove(rcc->latency_monitor.timer); rcc->latency_monitor.timer = NULL; } red_channel_remove_client(rcc); rcc->channel->channel_cbs.on_disconnect(rcc); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,662
static void red_channel_client_event(int fd, int event, void *data) { RedChannelClient *rcc = (RedChannelClient *)data; red_channel_client_ref(rcc); if (event & SPICE_WATCH_EVENT_READ) { red_channel_client_receive(rcc); } if (event & SPICE_WATCH_EVENT_WRITE) { red_channel_client_push(rcc); } red_channel_client_unref(rcc); }
DoS
0
static void red_channel_client_event(int fd, int event, void *data) { RedChannelClient *rcc = (RedChannelClient *)data; red_channel_client_ref(rcc); if (event & SPICE_WATCH_EVENT_READ) { red_channel_client_receive(rcc); } if (event & SPICE_WATCH_EVENT_WRITE) { red_channel_client_push(rcc); } red_channel_client_unref(rcc); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,663
SpiceMarshaller *red_channel_client_get_marshaller(RedChannelClient *rcc) { return rcc->send_data.marshaller; }
DoS
0
SpiceMarshaller *red_channel_client_get_marshaller(RedChannelClient *rcc) { return rcc->send_data.marshaller; }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,664
uint64_t red_channel_client_get_message_serial(RedChannelClient *rcc) { return rcc->send_data.serial; }
DoS
0
uint64_t red_channel_client_get_message_serial(RedChannelClient *rcc) { return rcc->send_data.serial; }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,665
int red_channel_client_get_roundtrip_ms(RedChannelClient *rcc) { if (rcc->latency_monitor.roundtrip < 0) { return rcc->latency_monitor.roundtrip; } return rcc->latency_monitor.roundtrip / 1000 / 1000; }
DoS
0
int red_channel_client_get_roundtrip_ms(RedChannelClient *rcc) { if (rcc->latency_monitor.roundtrip < 0) { return rcc->latency_monitor.roundtrip; } return rcc->latency_monitor.roundtrip / 1000 / 1000; }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,666
RedsStream *red_channel_client_get_stream(RedChannelClient *rcc) { return rcc->stream; }
DoS
0
RedsStream *red_channel_client_get_stream(RedChannelClient *rcc) { return rcc->stream; }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,667
int red_channel_client_handle_message(RedChannelClient *rcc, uint32_t size, uint16_t type, void *message) { switch (type) { case SPICE_MSGC_ACK_SYNC: if (size != sizeof(uint32_t)) { spice_printerr("bad message size"); return FALSE; } rcc->ack_data.client_generation = *(uint32_t *)(message); break; case SPICE_MSGC_ACK: if (rcc->ack_data.client_generation == rcc->ack_data.generation) { rcc->ack_data.messages_window -= rcc->ack_data.client_window; red_channel_client_push(rcc); } break; case SPICE_MSGC_DISCONNECTING: break; case SPICE_MSGC_MIGRATE_FLUSH_MARK: if (!rcc->wait_migrate_flush_mark) { spice_error("unexpected flush mark"); return FALSE; } red_channel_handle_migrate_flush_mark(rcc); rcc->wait_migrate_flush_mark = FALSE; break; case SPICE_MSGC_MIGRATE_DATA: red_channel_handle_migrate_data(rcc, size, message); break; case SPICE_MSGC_PONG: red_channel_client_handle_pong(rcc, message); break; default: spice_printerr("invalid message type %u", type); return FALSE; } return TRUE; }
DoS
0
int red_channel_client_handle_message(RedChannelClient *rcc, uint32_t size, uint16_t type, void *message) { switch (type) { case SPICE_MSGC_ACK_SYNC: if (size != sizeof(uint32_t)) { spice_printerr("bad message size"); return FALSE; } rcc->ack_data.client_generation = *(uint32_t *)(message); break; case SPICE_MSGC_ACK: if (rcc->ack_data.client_generation == rcc->ack_data.generation) { rcc->ack_data.messages_window -= rcc->ack_data.client_window; red_channel_client_push(rcc); } break; case SPICE_MSGC_DISCONNECTING: break; case SPICE_MSGC_MIGRATE_FLUSH_MARK: if (!rcc->wait_migrate_flush_mark) { spice_error("unexpected flush mark"); return FALSE; } red_channel_handle_migrate_flush_mark(rcc); rcc->wait_migrate_flush_mark = FALSE; break; case SPICE_MSGC_MIGRATE_DATA: red_channel_handle_migrate_data(rcc, size, message); break; case SPICE_MSGC_PONG: red_channel_client_handle_pong(rcc, message); break; default: spice_printerr("invalid message type %u", type); return FALSE; } return TRUE; }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,668
static void red_channel_client_init_outgoing_messages_window(RedChannelClient *rcc) { rcc->ack_data.messages_window = 0; red_channel_client_push(rcc); }
DoS
0
static void red_channel_client_init_outgoing_messages_window(RedChannelClient *rcc) { rcc->ack_data.messages_window = 0; red_channel_client_push(rcc); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,669
int red_channel_client_is_connected(RedChannelClient *rcc) { if (!rcc->dummy) { return rcc->stream != NULL; } else { return rcc->dummy_connected; } }
DoS
0
int red_channel_client_is_connected(RedChannelClient *rcc) { if (!rcc->dummy) { return rcc->stream != NULL; } else { return rcc->dummy_connected; } }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,670
int red_channel_client_no_item_being_sent(RedChannelClient *rcc) { return !rcc || (rcc->send_data.size == 0); }
DoS
0
int red_channel_client_no_item_being_sent(RedChannelClient *rcc) { return !rcc || (rcc->send_data.size == 0); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,671
static void red_channel_client_peer_on_out_block(void *opaque) { RedChannelClient *rcc = (RedChannelClient *)opaque; rcc->send_data.blocked = TRUE; rcc->channel->core->watch_update_mask(rcc->stream->watch, SPICE_WATCH_EVENT_READ | SPICE_WATCH_EVENT_WRITE); }
DoS
0
static void red_channel_client_peer_on_out_block(void *opaque) { RedChannelClient *rcc = (RedChannelClient *)opaque; rcc->send_data.blocked = TRUE; rcc->channel->core->watch_update_mask(rcc->stream->watch, SPICE_WATCH_EVENT_READ | SPICE_WATCH_EVENT_WRITE); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,672
static void red_channel_client_peer_prepare_out_msg( void *opaque, struct iovec *vec, int *vec_size, int pos) { RedChannelClient *rcc = (RedChannelClient *)opaque; *vec_size = spice_marshaller_fill_iovec(rcc->send_data.marshaller, vec, IOV_MAX, pos); }
DoS
0
static void red_channel_client_peer_prepare_out_msg( void *opaque, struct iovec *vec, int *vec_size, int pos) { RedChannelClient *rcc = (RedChannelClient *)opaque; *vec_size = spice_marshaller_fill_iovec(rcc->send_data.marshaller, vec, IOV_MAX, pos); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,673
static void red_channel_client_ping_timer(void *opaque) { int so_unsent_size = 0; RedChannelClient *rcc = opaque; spice_assert(rcc->latency_monitor.state == PING_STATE_TIMER); red_channel_client_cancel_ping_timer(rcc); /* retrieving the occupied size of the socket's tcp snd buffer (unacked + unsent) */ if (ioctl(rcc->stream->socket, TIOCOUTQ, &so_unsent_size) == -1) { spice_printerr("ioctl(TIOCOUTQ) failed, %s", strerror(errno)); } if (so_unsent_size > 0) { /* tcp snd buffer is still occupied. rescheduling ping */ red_channel_client_start_ping_timer(rcc, PING_TEST_IDLE_NET_TIMEOUT_MS); } else { red_channel_client_push_ping(rcc); } }
DoS
0
static void red_channel_client_ping_timer(void *opaque) { int so_unsent_size = 0; RedChannelClient *rcc = opaque; spice_assert(rcc->latency_monitor.state == PING_STATE_TIMER); red_channel_client_cancel_ping_timer(rcc); /* retrieving the occupied size of the socket's tcp snd buffer (unacked + unsent) */ if (ioctl(rcc->stream->socket, TIOCOUTQ, &so_unsent_size) == -1) { spice_printerr("ioctl(TIOCOUTQ) failed, %s", strerror(errno)); } if (so_unsent_size > 0) { /* tcp snd buffer is still occupied. rescheduling ping */ red_channel_client_start_ping_timer(rcc, PING_TEST_IDLE_NET_TIMEOUT_MS); } else { red_channel_client_push_ping(rcc); } }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,674
void red_channel_client_pipe_add(RedChannelClient *rcc, PipeItem *item) { spice_assert(rcc && item); rcc->pipe_size++; ring_add(&rcc->pipe, &item->link); }
DoS
0
void red_channel_client_pipe_add(RedChannelClient *rcc, PipeItem *item) { spice_assert(rcc && item); rcc->pipe_size++; ring_add(&rcc->pipe, &item->link); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,675
void red_channel_client_pipe_add_after(RedChannelClient *rcc, PipeItem *item, PipeItem *pos) { spice_assert(rcc); spice_assert(pos); spice_assert(item); rcc->pipe_size++; ring_add_after(&item->link, &pos->link); }
DoS
0
void red_channel_client_pipe_add_after(RedChannelClient *rcc, PipeItem *item, PipeItem *pos) { spice_assert(rcc); spice_assert(pos); spice_assert(item); rcc->pipe_size++; ring_add_after(&item->link, &pos->link); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,676
void red_channel_client_pipe_add_push(RedChannelClient *rcc, PipeItem *item) { red_channel_client_pipe_add(rcc, item); red_channel_client_push(rcc); }
DoS
0
void red_channel_client_pipe_add_push(RedChannelClient *rcc, PipeItem *item) { red_channel_client_pipe_add(rcc, item); red_channel_client_push(rcc); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,677
void red_channel_client_pipe_add_tail(RedChannelClient *rcc, PipeItem *item) { spice_assert(rcc); rcc->pipe_size++; ring_add_before(&item->link, &rcc->pipe); red_channel_client_push(rcc); }
DoS
0
void red_channel_client_pipe_add_tail(RedChannelClient *rcc, PipeItem *item) { spice_assert(rcc); rcc->pipe_size++; ring_add_before(&item->link, &rcc->pipe); red_channel_client_push(rcc); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,678
void red_channel_client_pipe_add_tail_no_push(RedChannelClient *rcc, PipeItem *item) { spice_assert(rcc); rcc->pipe_size++; ring_add_before(&item->link, &rcc->pipe); }
DoS
0
void red_channel_client_pipe_add_tail_no_push(RedChannelClient *rcc, PipeItem *item) { spice_assert(rcc); rcc->pipe_size++; ring_add_before(&item->link, &rcc->pipe); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,679
void red_channel_client_pipe_clear(RedChannelClient *rcc) { PipeItem *item; if (rcc) { red_channel_client_clear_sent_item(rcc); } while ((item = (PipeItem *)ring_get_head(&rcc->pipe))) { ring_remove(&item->link); red_channel_client_release_item(rcc, item, FALSE); } rcc->pipe_size = 0; }
DoS
0
void red_channel_client_pipe_clear(RedChannelClient *rcc) { PipeItem *item; if (rcc) { red_channel_client_clear_sent_item(rcc); } while ((item = (PipeItem *)ring_get_head(&rcc->pipe))) { ring_remove(&item->link); red_channel_client_release_item(rcc, item, FALSE); } rcc->pipe_size = 0; }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,680
int red_channel_client_pipe_item_is_linked(RedChannelClient *rcc, PipeItem *item) { return ring_item_is_linked(&item->link); }
DoS
0
int red_channel_client_pipe_item_is_linked(RedChannelClient *rcc, PipeItem *item) { return ring_item_is_linked(&item->link); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,681
void red_channel_client_pipe_remove_and_release(RedChannelClient *rcc, PipeItem *item) { red_channel_client_pipe_remove(rcc, item); red_channel_client_release_item(rcc, item, FALSE); }
DoS
0
void red_channel_client_pipe_remove_and_release(RedChannelClient *rcc, PipeItem *item) { red_channel_client_pipe_remove(rcc, item); red_channel_client_release_item(rcc, item, FALSE); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,682
static int red_channel_client_pre_create_validate(RedChannel *channel, RedClient *client) { if (red_client_get_channel(client, channel->type, channel->id)) { spice_printerr("Error client %p: duplicate channel type %d id %d", client, channel->type, channel->id); return FALSE; } return TRUE; }
DoS
0
static int red_channel_client_pre_create_validate(RedChannel *channel, RedClient *client) { if (red_client_get_channel(client, channel->type, channel->id)) { spice_printerr("Error client %p: duplicate channel type %d id %d", client, channel->type, channel->id); return FALSE; } return TRUE; }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,683
void red_channel_client_push(RedChannelClient *rcc) { PipeItem *pipe_item; if (!rcc->during_send) { rcc->during_send = TRUE; } else { return; } red_channel_client_ref(rcc); if (rcc->send_data.blocked) { red_channel_client_send(rcc); } if (!red_channel_client_no_item_being_sent(rcc) && !rcc->send_data.blocked) { rcc->send_data.blocked = TRUE; spice_printerr("ERROR: an item waiting to be sent and not blocked"); } while ((pipe_item = red_channel_client_pipe_item_get(rcc))) { red_channel_client_send_item(rcc, pipe_item); } rcc->during_send = FALSE; red_channel_client_unref(rcc); }
DoS
0
void red_channel_client_push(RedChannelClient *rcc) { PipeItem *pipe_item; if (!rcc->during_send) { rcc->during_send = TRUE; } else { return; } red_channel_client_ref(rcc); if (rcc->send_data.blocked) { red_channel_client_send(rcc); } if (!red_channel_client_no_item_being_sent(rcc) && !rcc->send_data.blocked) { rcc->send_data.blocked = TRUE; spice_printerr("ERROR: an item waiting to be sent and not blocked"); } while ((pipe_item = red_channel_client_pipe_item_get(rcc))) { red_channel_client_send_item(rcc, pipe_item); } rcc->during_send = FALSE; red_channel_client_unref(rcc); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,684
static void red_channel_client_push_ping(RedChannelClient *rcc) { spice_assert(rcc->latency_monitor.state == PING_STATE_NONE); rcc->latency_monitor.state = PING_STATE_WARMUP; rcc->latency_monitor.warmup_was_sent = FALSE; rcc->latency_monitor.id = rand(); red_channel_client_pipe_add_type(rcc, PIPE_ITEM_TYPE_PING); red_channel_client_pipe_add_type(rcc, PIPE_ITEM_TYPE_PING); }
DoS
0
static void red_channel_client_push_ping(RedChannelClient *rcc) { spice_assert(rcc->latency_monitor.state == PING_STATE_NONE); rcc->latency_monitor.state = PING_STATE_WARMUP; rcc->latency_monitor.warmup_was_sent = FALSE; rcc->latency_monitor.id = rand(); red_channel_client_pipe_add_type(rcc, PIPE_ITEM_TYPE_PING); red_channel_client_pipe_add_type(rcc, PIPE_ITEM_TYPE_PING); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,685
void red_channel_client_push_set_ack(RedChannelClient *rcc) { red_channel_client_pipe_add_type(rcc, PIPE_ITEM_TYPE_SET_ACK); }
DoS
0
void red_channel_client_push_set_ack(RedChannelClient *rcc) { red_channel_client_pipe_add_type(rcc, PIPE_ITEM_TYPE_SET_ACK); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,686
void red_channel_client_receive(RedChannelClient *rcc) { red_channel_client_ref(rcc); red_peer_handle_incoming(rcc->stream, &rcc->incoming); red_channel_client_unref(rcc); }
DoS
0
void red_channel_client_receive(RedChannelClient *rcc) { red_channel_client_ref(rcc); red_peer_handle_incoming(rcc->stream, &rcc->incoming); red_channel_client_unref(rcc); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,687
static void red_channel_client_release_item(RedChannelClient *rcc, PipeItem *item, int item_pushed) { int handled = TRUE; switch (item->type) { case PIPE_ITEM_TYPE_SET_ACK: case PIPE_ITEM_TYPE_EMPTY_MSG: case PIPE_ITEM_TYPE_MIGRATE: case PIPE_ITEM_TYPE_PING: free(item); break; default: handled = FALSE; } if (!handled) { rcc->channel->channel_cbs.release_item(rcc, item, item_pushed); } }
DoS
0
static void red_channel_client_release_item(RedChannelClient *rcc, PipeItem *item, int item_pushed) { int handled = TRUE; switch (item->type) { case PIPE_ITEM_TYPE_SET_ACK: case PIPE_ITEM_TYPE_EMPTY_MSG: case PIPE_ITEM_TYPE_MIGRATE: case PIPE_ITEM_TYPE_PING: free(item); break; default: handled = FALSE; } if (!handled) { rcc->channel->channel_cbs.release_item(rcc, item, item_pushed); } }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,688
static inline void red_channel_client_release_sent_item(RedChannelClient *rcc) { if (rcc->send_data.item) { red_channel_client_release_item(rcc, rcc->send_data.item, TRUE); rcc->send_data.item = NULL; } }
DoS
0
static inline void red_channel_client_release_sent_item(RedChannelClient *rcc) { if (rcc->send_data.item) { red_channel_client_release_item(rcc, rcc->send_data.item, TRUE); rcc->send_data.item = NULL; } }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,689
static void red_channel_client_reset_send_data(RedChannelClient *rcc) { spice_marshaller_reset(rcc->send_data.marshaller); rcc->send_data.header.data = spice_marshaller_reserve_space(rcc->send_data.marshaller, rcc->send_data.header.header_size); spice_marshaller_set_base(rcc->send_data.marshaller, rcc->send_data.header.header_size); rcc->send_data.header.set_msg_type(&rcc->send_data.header, 0); rcc->send_data.header.set_msg_size(&rcc->send_data.header, 0); /* Keeping the serial consecutive: reseting it if reset_send_data * has been called before, but no message has been sent since then. */ if (rcc->send_data.last_sent_serial != rcc->send_data.serial) { spice_assert(rcc->send_data.serial - rcc->send_data.last_sent_serial == 1); /* When the urgent marshaller is active, the serial was incremented by * the call to reset_send_data that was made for the main marshaller. * The urgent msg receives this serial, and the main msg serial is * the following one. Thus, (rcc->send_data.serial - rcc->send_data.last_sent_serial) * should be 1 in this case*/ if (!red_channel_client_urgent_marshaller_is_active(rcc)) { rcc->send_data.serial = rcc->send_data.last_sent_serial; } } rcc->send_data.serial++; if (!rcc->is_mini_header) { spice_assert(rcc->send_data.marshaller != rcc->send_data.urgent.marshaller); rcc->send_data.header.set_msg_sub_list(&rcc->send_data.header, 0); rcc->send_data.header.set_msg_serial(&rcc->send_data.header, rcc->send_data.serial); } }
DoS
0
static void red_channel_client_reset_send_data(RedChannelClient *rcc) { spice_marshaller_reset(rcc->send_data.marshaller); rcc->send_data.header.data = spice_marshaller_reserve_space(rcc->send_data.marshaller, rcc->send_data.header.header_size); spice_marshaller_set_base(rcc->send_data.marshaller, rcc->send_data.header.header_size); rcc->send_data.header.set_msg_type(&rcc->send_data.header, 0); rcc->send_data.header.set_msg_size(&rcc->send_data.header, 0); /* Keeping the serial consecutive: reseting it if reset_send_data * has been called before, but no message has been sent since then. */ if (rcc->send_data.last_sent_serial != rcc->send_data.serial) { spice_assert(rcc->send_data.serial - rcc->send_data.last_sent_serial == 1); /* When the urgent marshaller is active, the serial was incremented by * the call to reset_send_data that was made for the main marshaller. * The urgent msg receives this serial, and the main msg serial is * the following one. Thus, (rcc->send_data.serial - rcc->send_data.last_sent_serial) * should be 1 in this case*/ if (!red_channel_client_urgent_marshaller_is_active(rcc)) { rcc->send_data.serial = rcc->send_data.last_sent_serial; } } rcc->send_data.serial++; if (!rcc->is_mini_header) { spice_assert(rcc->send_data.marshaller != rcc->send_data.urgent.marshaller); rcc->send_data.header.set_msg_sub_list(&rcc->send_data.header, 0); rcc->send_data.header.set_msg_serial(&rcc->send_data.header, rcc->send_data.serial); } }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,690
static void red_channel_client_restart_ping_timer(RedChannelClient *rcc) { struct timespec ts; uint64_t passed, timeout; clock_gettime(CLOCK_MONOTONIC, &ts); passed = ts.tv_sec * 1000000000LL + ts.tv_nsec; passed = passed - rcc->latency_monitor.last_pong_time; passed /= 1000*1000; timeout = PING_TEST_IDLE_NET_TIMEOUT_MS; if (passed < PING_TEST_TIMEOUT_MS) { timeout += PING_TEST_TIMEOUT_MS - passed; } red_channel_client_start_ping_timer(rcc, timeout); }
DoS
0
static void red_channel_client_restart_ping_timer(RedChannelClient *rcc) { struct timespec ts; uint64_t passed, timeout; clock_gettime(CLOCK_MONOTONIC, &ts); passed = ts.tv_sec * 1000000000LL + ts.tv_nsec; passed = passed - rcc->latency_monitor.last_pong_time; passed /= 1000*1000; timeout = PING_TEST_IDLE_NET_TIMEOUT_MS; if (passed < PING_TEST_TIMEOUT_MS) { timeout += PING_TEST_TIMEOUT_MS - passed; } red_channel_client_start_ping_timer(rcc, timeout); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,691
static void red_channel_client_restore_main_sender(RedChannelClient *rcc) { spice_marshaller_reset(rcc->send_data.urgent.marshaller); rcc->send_data.marshaller = rcc->send_data.main.marshaller; rcc->send_data.header.data = rcc->send_data.main.header_data; if (!rcc->is_mini_header) { rcc->send_data.header.set_msg_serial(&rcc->send_data.header, rcc->send_data.serial); } rcc->send_data.item = rcc->send_data.main.item; }
DoS
0
static void red_channel_client_restore_main_sender(RedChannelClient *rcc) { spice_marshaller_reset(rcc->send_data.urgent.marshaller); rcc->send_data.marshaller = rcc->send_data.main.marshaller; rcc->send_data.header.data = rcc->send_data.main.header_data; if (!rcc->is_mini_header) { rcc->send_data.header.set_msg_serial(&rcc->send_data.header, rcc->send_data.serial); } rcc->send_data.item = rcc->send_data.main.item; }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,692
static void red_channel_client_seamless_migration_done(RedChannelClient *rcc) { rcc->wait_migrate_data = FALSE; pthread_mutex_lock(&rcc->client->lock); rcc->client->num_migrated_channels--; /* we assume we always have at least one channel who has migration data transfer, * otherwise, this flag will never be set back to FALSE*/ if (!rcc->client->num_migrated_channels) { rcc->client->during_target_migrate = FALSE; rcc->client->seamless_migrate = FALSE; /* migration completion might have been triggered from a different thread * than the main thread */ main_dispatcher_seamless_migrate_dst_complete(rcc->client); if (rcc->latency_monitor.timer) { red_channel_client_start_ping_timer(rcc, PING_TEST_IDLE_NET_TIMEOUT_MS); } } pthread_mutex_unlock(&rcc->client->lock); }
DoS
0
static void red_channel_client_seamless_migration_done(RedChannelClient *rcc) { rcc->wait_migrate_data = FALSE; pthread_mutex_lock(&rcc->client->lock); rcc->client->num_migrated_channels--; /* we assume we always have at least one channel who has migration data transfer, * otherwise, this flag will never be set back to FALSE*/ if (!rcc->client->num_migrated_channels) { rcc->client->during_target_migrate = FALSE; rcc->client->seamless_migrate = FALSE; /* migration completion might have been triggered from a different thread * than the main thread */ main_dispatcher_seamless_migrate_dst_complete(rcc->client); if (rcc->latency_monitor.timer) { red_channel_client_start_ping_timer(rcc, PING_TEST_IDLE_NET_TIMEOUT_MS); } } pthread_mutex_unlock(&rcc->client->lock); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,693
void red_channel_client_send(RedChannelClient *rcc) { red_channel_client_ref(rcc); red_peer_handle_outgoing(rcc->stream, &rcc->outgoing); red_channel_client_unref(rcc); }
DoS
0
void red_channel_client_send(RedChannelClient *rcc) { red_channel_client_ref(rcc); red_peer_handle_outgoing(rcc->stream, &rcc->outgoing); red_channel_client_unref(rcc); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,694
int red_channel_client_send_message_pending(RedChannelClient *rcc) { return rcc->send_data.header.get_msg_type(&rcc->send_data.header) != 0; }
DoS
0
int red_channel_client_send_message_pending(RedChannelClient *rcc) { return rcc->send_data.header.get_msg_type(&rcc->send_data.header) != 0; }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,695
static void red_channel_client_send_migrate(RedChannelClient *rcc) { SpiceMsgMigrate migrate; red_channel_client_init_send_data(rcc, SPICE_MSG_MIGRATE, NULL); migrate.flags = rcc->channel->migration_flags; spice_marshall_msg_migrate(rcc->send_data.marshaller, &migrate); if (rcc->channel->migration_flags & SPICE_MIGRATE_NEED_FLUSH) { rcc->wait_migrate_flush_mark = TRUE; } red_channel_client_begin_send_message(rcc); }
DoS
0
static void red_channel_client_send_migrate(RedChannelClient *rcc) { SpiceMsgMigrate migrate; red_channel_client_init_send_data(rcc, SPICE_MSG_MIGRATE, NULL); migrate.flags = rcc->channel->migration_flags; spice_marshall_msg_migrate(rcc->send_data.marshaller, &migrate); if (rcc->channel->migration_flags & SPICE_MIGRATE_NEED_FLUSH) { rcc->wait_migrate_flush_mark = TRUE; } red_channel_client_begin_send_message(rcc); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,696
static void red_channel_client_send_ping(RedChannelClient *rcc) { SpiceMsgPing ping; struct timespec ts; if (!rcc->latency_monitor.warmup_was_sent) { // latency test start int delay_val; socklen_t opt_size = sizeof(delay_val); rcc->latency_monitor.warmup_was_sent = TRUE; /* * When testing latency, TCP_NODELAY must be switched on, otherwise, * sending the ping message is delayed by Nagle algorithm, and the * roundtrip measurment is less accurate (bigger). */ rcc->latency_monitor.tcp_nodelay = 1; if (getsockopt(rcc->stream->socket, IPPROTO_TCP, TCP_NODELAY, &delay_val, &opt_size) == -1) { spice_warning("getsockopt failed, %s", strerror(errno)); } else { rcc->latency_monitor.tcp_nodelay = delay_val; if (!delay_val) { delay_val = 1; if (setsockopt(rcc->stream->socket, IPPROTO_TCP, TCP_NODELAY, &delay_val, sizeof(delay_val)) == -1) { if (errno != ENOTSUP) { spice_warning("setsockopt failed, %s", strerror(errno)); } } } } } red_channel_client_init_send_data(rcc, SPICE_MSG_PING, NULL); ping.id = rcc->latency_monitor.id; clock_gettime(CLOCK_MONOTONIC, &ts); ping.timestamp = ts.tv_sec * 1000000000LL + ts.tv_nsec; spice_marshall_msg_ping(rcc->send_data.marshaller, &ping); red_channel_client_begin_send_message(rcc); }
DoS
0
static void red_channel_client_send_ping(RedChannelClient *rcc) { SpiceMsgPing ping; struct timespec ts; if (!rcc->latency_monitor.warmup_was_sent) { // latency test start int delay_val; socklen_t opt_size = sizeof(delay_val); rcc->latency_monitor.warmup_was_sent = TRUE; /* * When testing latency, TCP_NODELAY must be switched on, otherwise, * sending the ping message is delayed by Nagle algorithm, and the * roundtrip measurment is less accurate (bigger). */ rcc->latency_monitor.tcp_nodelay = 1; if (getsockopt(rcc->stream->socket, IPPROTO_TCP, TCP_NODELAY, &delay_val, &opt_size) == -1) { spice_warning("getsockopt failed, %s", strerror(errno)); } else { rcc->latency_monitor.tcp_nodelay = delay_val; if (!delay_val) { delay_val = 1; if (setsockopt(rcc->stream->socket, IPPROTO_TCP, TCP_NODELAY, &delay_val, sizeof(delay_val)) == -1) { if (errno != ENOTSUP) { spice_warning("setsockopt failed, %s", strerror(errno)); } } } } } red_channel_client_init_send_data(rcc, SPICE_MSG_PING, NULL); ping.id = rcc->latency_monitor.id; clock_gettime(CLOCK_MONOTONIC, &ts); ping.timestamp = ts.tv_sec * 1000000000LL + ts.tv_nsec; spice_marshall_msg_ping(rcc->send_data.marshaller, &ping); red_channel_client_begin_send_message(rcc); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,697
static void red_channel_client_send_set_ack(RedChannelClient *rcc) { SpiceMsgSetAck ack; spice_assert(rcc); red_channel_client_init_send_data(rcc, SPICE_MSG_SET_ACK, NULL); ack.generation = ++rcc->ack_data.generation; ack.window = rcc->ack_data.client_window; rcc->ack_data.messages_window = 0; spice_marshall_msg_set_ack(rcc->send_data.marshaller, &ack); red_channel_client_begin_send_message(rcc); }
DoS
0
static void red_channel_client_send_set_ack(RedChannelClient *rcc) { SpiceMsgSetAck ack; spice_assert(rcc); red_channel_client_init_send_data(rcc, SPICE_MSG_SET_ACK, NULL); ack.generation = ++rcc->ack_data.generation; ack.window = rcc->ack_data.client_window; rcc->ack_data.messages_window = 0; spice_marshall_msg_set_ack(rcc->send_data.marshaller, &ack); red_channel_client_begin_send_message(rcc); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,698
void red_channel_client_set_header_sub_list(RedChannelClient *rcc, uint32_t sub_list) { rcc->send_data.header.set_msg_sub_list(&rcc->send_data.header, sub_list); }
DoS
0
void red_channel_client_set_header_sub_list(RedChannelClient *rcc, uint32_t sub_list) { rcc->send_data.header.set_msg_sub_list(&rcc->send_data.header, sub_list); }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null
1,699
void red_channel_client_set_message_serial(RedChannelClient *rcc, uint64_t serial) { rcc->send_data.last_sent_serial = serial; rcc->send_data.serial = serial; }
DoS
0
void red_channel_client_set_message_serial(RedChannelClient *rcc, uint64_t serial) { rcc->send_data.last_sent_serial = serial; rcc->send_data.serial = serial; }
@@ -1572,9 +1572,9 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_type( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), pipe_item_type); @@ -1593,9 +1593,9 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type) { - RingItem *link; + RingItem *link, *next; - RING_FOREACH(link, &channel->clients) { + RING_FOREACH_SAFE(link, next, &channel->clients) { red_channel_client_pipe_add_empty_msg( SPICE_CONTAINEROF(link, RedChannelClient, channel_link), msg_type);
CWE-399
null
null