idx
int64
func_before
string
Vulnerability Classification
string
vul
int64
func_after
string
patch
string
CWE ID
string
lines_before
string
lines_after
string
12,300
static PHP_FUNCTION(xmlwriter_start_dtd_element) { php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterStartDTDElement, "Invalid Element Name"); }
Bypass
0
static PHP_FUNCTION(xmlwriter_start_dtd_element) { php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterStartDTDElement, "Invalid Element Name"); }
@@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity) /* }}} */ #endif -/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source) +/* {{{ proto resource xmlwriter_open_uri(string source) Create new xmlwriter using source uri for output */ static PHP_FUNCTION(xmlwriter_open_uri) { @@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri) void *ioctx; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) { return; }
CWE-254
null
null
12,301
static PHP_FUNCTION(xmlwriter_end_dtd_element) { php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndDTDElement); }
Bypass
0
static PHP_FUNCTION(xmlwriter_end_dtd_element) { php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndDTDElement); }
@@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity) /* }}} */ #endif -/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source) +/* {{{ proto resource xmlwriter_open_uri(string source) Create new xmlwriter using source uri for output */ static PHP_FUNCTION(xmlwriter_open_uri) { @@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri) void *ioctx; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) { return; }
CWE-254
null
null
12,302
static PHP_FUNCTION(xmlwriter_write_dtd_element) { zval *pind; xmlwriter_object *intern; xmlTextWriterPtr ptr; char *name, *content; int name_len, content_len, retval; #ifdef ZEND_ENGINE_2 zval *this = getThis(); if (this) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &name_len, &content, &content_len) == FAILURE) { return; } XMLWRITER_FROM_OBJECT(intern, this); } else #endif { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &pind, &name, &name_len, &content, &content_len) == FAILURE) { return; } ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter); } XMLW_NAME_CHK("Invalid Element Name"); ptr = intern->ptr; if (ptr) { retval = xmlTextWriterWriteDTDElement(ptr, (xmlChar *)name, (xmlChar *)content); if (retval != -1) { RETURN_TRUE; } } RETURN_FALSE; }
Bypass
0
static PHP_FUNCTION(xmlwriter_write_dtd_element) { zval *pind; xmlwriter_object *intern; xmlTextWriterPtr ptr; char *name, *content; int name_len, content_len, retval; #ifdef ZEND_ENGINE_2 zval *this = getThis(); if (this) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &name_len, &content, &content_len) == FAILURE) { return; } XMLWRITER_FROM_OBJECT(intern, this); } else #endif { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &pind, &name, &name_len, &content, &content_len) == FAILURE) { return; } ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter); } XMLW_NAME_CHK("Invalid Element Name"); ptr = intern->ptr; if (ptr) { retval = xmlTextWriterWriteDTDElement(ptr, (xmlChar *)name, (xmlChar *)content); if (retval != -1) { RETURN_TRUE; } } RETURN_FALSE; }
@@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity) /* }}} */ #endif -/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source) +/* {{{ proto resource xmlwriter_open_uri(string source) Create new xmlwriter using source uri for output */ static PHP_FUNCTION(xmlwriter_open_uri) { @@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri) void *ioctx; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) { return; }
CWE-254
null
null
12,303
static PHP_FUNCTION(xmlwriter_start_dtd_attlist) { php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterStartDTDAttlist, "Invalid Element Name"); }
Bypass
0
static PHP_FUNCTION(xmlwriter_start_dtd_attlist) { php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterStartDTDAttlist, "Invalid Element Name"); }
@@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity) /* }}} */ #endif -/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source) +/* {{{ proto resource xmlwriter_open_uri(string source) Create new xmlwriter using source uri for output */ static PHP_FUNCTION(xmlwriter_open_uri) { @@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri) void *ioctx; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) { return; }
CWE-254
null
null
12,304
static PHP_FUNCTION(xmlwriter_end_dtd_attlist) { php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndDTDAttlist); }
Bypass
0
static PHP_FUNCTION(xmlwriter_end_dtd_attlist) { php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndDTDAttlist); }
@@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity) /* }}} */ #endif -/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source) +/* {{{ proto resource xmlwriter_open_uri(string source) Create new xmlwriter using source uri for output */ static PHP_FUNCTION(xmlwriter_open_uri) { @@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri) void *ioctx; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) { return; }
CWE-254
null
null
12,305
static PHP_FUNCTION(xmlwriter_write_dtd_attlist) { zval *pind; xmlwriter_object *intern; xmlTextWriterPtr ptr; char *name, *content; int name_len, content_len, retval; #ifdef ZEND_ENGINE_2 zval *this = getThis(); if (this) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &name_len, &content, &content_len) == FAILURE) { return; } XMLWRITER_FROM_OBJECT(intern, this); } else #endif { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &pind, &name, &name_len, &content, &content_len) == FAILURE) { return; } ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter); } XMLW_NAME_CHK("Invalid Element Name"); ptr = intern->ptr; if (ptr) { retval = xmlTextWriterWriteDTDAttlist(ptr, (xmlChar *)name, (xmlChar *)content); if (retval != -1) { RETURN_TRUE; } } RETURN_FALSE; }
Bypass
0
static PHP_FUNCTION(xmlwriter_write_dtd_attlist) { zval *pind; xmlwriter_object *intern; xmlTextWriterPtr ptr; char *name, *content; int name_len, content_len, retval; #ifdef ZEND_ENGINE_2 zval *this = getThis(); if (this) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &name_len, &content, &content_len) == FAILURE) { return; } XMLWRITER_FROM_OBJECT(intern, this); } else #endif { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &pind, &name, &name_len, &content, &content_len) == FAILURE) { return; } ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter); } XMLW_NAME_CHK("Invalid Element Name"); ptr = intern->ptr; if (ptr) { retval = xmlTextWriterWriteDTDAttlist(ptr, (xmlChar *)name, (xmlChar *)content); if (retval != -1) { RETURN_TRUE; } } RETURN_FALSE; }
@@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity) /* }}} */ #endif -/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source) +/* {{{ proto resource xmlwriter_open_uri(string source) Create new xmlwriter using source uri for output */ static PHP_FUNCTION(xmlwriter_open_uri) { @@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri) void *ioctx; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) { return; }
CWE-254
null
null
12,306
static PHP_FUNCTION(xmlwriter_end_dtd_entity) { php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndDTDEntity); }
Bypass
0
static PHP_FUNCTION(xmlwriter_end_dtd_entity) { php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndDTDEntity); }
@@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity) /* }}} */ #endif -/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source) +/* {{{ proto resource xmlwriter_open_uri(string source) Create new xmlwriter using source uri for output */ static PHP_FUNCTION(xmlwriter_open_uri) { @@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri) void *ioctx; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) { return; }
CWE-254
null
null
12,307
static PHP_FUNCTION(xmlwriter_write_dtd_entity) { zval *pind; xmlwriter_object *intern; xmlTextWriterPtr ptr; char *name, *content; int name_len, content_len, retval; /* Optional parameters */ char *pubid = NULL, *sysid = NULL, *ndataid = NULL; zend_bool pe = 0; int pubid_len, sysid_len, ndataid_len; #ifdef ZEND_ENGINE_2 zval *this = getThis(); if (this) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|bsss", &name, &name_len, &content, &content_len, &pe, &pubid, &pubid_len, &sysid, &sysid_len, &ndataid, &ndataid_len) == FAILURE) { return; } XMLWRITER_FROM_OBJECT(intern, this); } else #endif { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss|bsss", &pind, &name, &name_len, &content, &content_len, &pe, &pubid, &pubid_len, &sysid, &sysid_len, &ndataid, &ndataid_len) == FAILURE) { return; } ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter); } XMLW_NAME_CHK("Invalid Element Name"); ptr = intern->ptr; if (ptr) { retval = xmlTextWriterWriteDTDEntity(ptr, pe, (xmlChar *)name, (xmlChar *)pubid, (xmlChar *)sysid, (xmlChar *)ndataid, (xmlChar *)content); if (retval != -1) { RETURN_TRUE; } } RETURN_FALSE; }
Bypass
0
static PHP_FUNCTION(xmlwriter_write_dtd_entity) { zval *pind; xmlwriter_object *intern; xmlTextWriterPtr ptr; char *name, *content; int name_len, content_len, retval; /* Optional parameters */ char *pubid = NULL, *sysid = NULL, *ndataid = NULL; zend_bool pe = 0; int pubid_len, sysid_len, ndataid_len; #ifdef ZEND_ENGINE_2 zval *this = getThis(); if (this) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|bsss", &name, &name_len, &content, &content_len, &pe, &pubid, &pubid_len, &sysid, &sysid_len, &ndataid, &ndataid_len) == FAILURE) { return; } XMLWRITER_FROM_OBJECT(intern, this); } else #endif { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss|bsss", &pind, &name, &name_len, &content, &content_len, &pe, &pubid, &pubid_len, &sysid, &sysid_len, &ndataid, &ndataid_len) == FAILURE) { return; } ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter); } XMLW_NAME_CHK("Invalid Element Name"); ptr = intern->ptr; if (ptr) { retval = xmlTextWriterWriteDTDEntity(ptr, pe, (xmlChar *)name, (xmlChar *)pubid, (xmlChar *)sysid, (xmlChar *)ndataid, (xmlChar *)content); if (retval != -1) { RETURN_TRUE; } } RETURN_FALSE; }
@@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity) /* }}} */ #endif -/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source) +/* {{{ proto resource xmlwriter_open_uri(string source) Create new xmlwriter using source uri for output */ static PHP_FUNCTION(xmlwriter_open_uri) { @@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri) void *ioctx; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) { return; }
CWE-254
null
null
12,308
static PHP_FUNCTION(xmlwriter_output_memory) { php_xmlwriter_flush(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); }
Bypass
0
static PHP_FUNCTION(xmlwriter_output_memory) { php_xmlwriter_flush(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); }
@@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity) /* }}} */ #endif -/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source) +/* {{{ proto resource xmlwriter_open_uri(string source) Create new xmlwriter using source uri for output */ static PHP_FUNCTION(xmlwriter_open_uri) { @@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri) void *ioctx; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) { return; }
CWE-254
null
null
12,309
static PHP_FUNCTION(xmlwriter_flush) { php_xmlwriter_flush(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); }
Bypass
0
static PHP_FUNCTION(xmlwriter_flush) { php_xmlwriter_flush(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); }
@@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity) /* }}} */ #endif -/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source) +/* {{{ proto resource xmlwriter_open_uri(string source) Create new xmlwriter using source uri for output */ static PHP_FUNCTION(xmlwriter_open_uri) { @@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri) void *ioctx; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) { return; }
CWE-254
null
null
12,310
static PHP_MSHUTDOWN_FUNCTION(xmlwriter) { return SUCCESS; }
Bypass
0
static PHP_MSHUTDOWN_FUNCTION(xmlwriter) { return SUCCESS; }
@@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity) /* }}} */ #endif -/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source) +/* {{{ proto resource xmlwriter_open_uri(string source) Create new xmlwriter using source uri for output */ static PHP_FUNCTION(xmlwriter_open_uri) { @@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri) void *ioctx; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) { return; }
CWE-254
null
null
12,311
static char *_xmlwriter_get_valid_file_path(char *source, char *resolved_path, int resolved_path_len TSRMLS_DC) { xmlURI *uri; xmlChar *escsource; char *file_dest; int isFileUri = 0; uri = xmlCreateURI(); escsource = xmlURIEscapeStr((xmlChar *)source, (xmlChar *) ":"); xmlParseURIReference(uri, (char *)escsource); xmlFree(escsource); if (uri->scheme != NULL) { /* absolute file uris - libxml only supports localhost or empty host */ if (strncasecmp(source, "file:///", 8) == 0) { if (source[sizeof("file:///") - 1] == '\0') { xmlFreeURI(uri); return NULL; } isFileUri = 1; #ifdef PHP_WIN32 source += 8; #else source += 7; #endif } else if (strncasecmp(source, "file://localhost/",17) == 0) { if (source[sizeof("file://localhost/") - 1] == '\0') { xmlFreeURI(uri); return NULL; } isFileUri = 1; #ifdef PHP_WIN32 source += 17; #else source += 16; #endif } } if ((uri->scheme == NULL || isFileUri)) { char file_dirname[MAXPATHLEN]; size_t dir_len; if (!VCWD_REALPATH(source, resolved_path) && !expand_filepath(source, resolved_path TSRMLS_CC)) { xmlFreeURI(uri); return NULL; } memcpy(file_dirname, source, strlen(source)); dir_len = php_dirname(file_dirname, strlen(source)); if (dir_len > 0) { struct stat buf; if (php_sys_stat(file_dirname, &buf) != 0) { xmlFreeURI(uri); return NULL; } } file_dest = resolved_path; } else { file_dest = source; } xmlFreeURI(uri); return file_dest; }
Bypass
0
static char *_xmlwriter_get_valid_file_path(char *source, char *resolved_path, int resolved_path_len TSRMLS_DC) { xmlURI *uri; xmlChar *escsource; char *file_dest; int isFileUri = 0; uri = xmlCreateURI(); escsource = xmlURIEscapeStr((xmlChar *)source, (xmlChar *) ":"); xmlParseURIReference(uri, (char *)escsource); xmlFree(escsource); if (uri->scheme != NULL) { /* absolute file uris - libxml only supports localhost or empty host */ if (strncasecmp(source, "file:///", 8) == 0) { if (source[sizeof("file:///") - 1] == '\0') { xmlFreeURI(uri); return NULL; } isFileUri = 1; #ifdef PHP_WIN32 source += 8; #else source += 7; #endif } else if (strncasecmp(source, "file://localhost/",17) == 0) { if (source[sizeof("file://localhost/") - 1] == '\0') { xmlFreeURI(uri); return NULL; } isFileUri = 1; #ifdef PHP_WIN32 source += 17; #else source += 16; #endif } } if ((uri->scheme == NULL || isFileUri)) { char file_dirname[MAXPATHLEN]; size_t dir_len; if (!VCWD_REALPATH(source, resolved_path) && !expand_filepath(source, resolved_path TSRMLS_CC)) { xmlFreeURI(uri); return NULL; } memcpy(file_dirname, source, strlen(source)); dir_len = php_dirname(file_dirname, strlen(source)); if (dir_len > 0) { struct stat buf; if (php_sys_stat(file_dirname, &buf) != 0) { xmlFreeURI(uri); return NULL; } } file_dest = resolved_path; } else { file_dest = source; } xmlFreeURI(uri); return file_dest; }
@@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity) /* }}} */ #endif -/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source) +/* {{{ proto resource xmlwriter_open_uri(string source) Create new xmlwriter using source uri for output */ static PHP_FUNCTION(xmlwriter_open_uri) { @@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri) void *ioctx; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) { return; }
CWE-254
null
null
12,312
static void php_xmlwriter_end(INTERNAL_FUNCTION_PARAMETERS, xmlwriter_read_int_t internal_function) { zval *pind; xmlwriter_object *intern; xmlTextWriterPtr ptr; int retval; #ifdef ZEND_ENGINE_2 zval *this = getThis(); if (this) { XMLWRITER_FROM_OBJECT(intern, this); if (zend_parse_parameters_none() == FAILURE) { return; } } else #endif { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &pind) == FAILURE) { return; } ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter); } ptr = intern->ptr; if (ptr) { retval = internal_function(ptr); if (retval != -1) { RETURN_TRUE; } } RETURN_FALSE; }
Bypass
0
static void php_xmlwriter_end(INTERNAL_FUNCTION_PARAMETERS, xmlwriter_read_int_t internal_function) { zval *pind; xmlwriter_object *intern; xmlTextWriterPtr ptr; int retval; #ifdef ZEND_ENGINE_2 zval *this = getThis(); if (this) { XMLWRITER_FROM_OBJECT(intern, this); if (zend_parse_parameters_none() == FAILURE) { return; } } else #endif { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &pind) == FAILURE) { return; } ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter); } ptr = intern->ptr; if (ptr) { retval = internal_function(ptr); if (retval != -1) { RETURN_TRUE; } } RETURN_FALSE; }
@@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity) /* }}} */ #endif -/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source) +/* {{{ proto resource xmlwriter_open_uri(string source) Create new xmlwriter using source uri for output */ static PHP_FUNCTION(xmlwriter_open_uri) { @@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri) void *ioctx; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) { return; }
CWE-254
null
null
12,313
static void php_xmlwriter_flush(INTERNAL_FUNCTION_PARAMETERS, int force_string) { zval *pind; xmlwriter_object *intern; xmlTextWriterPtr ptr; xmlBufferPtr buffer; zend_bool empty = 1; int output_bytes; #ifdef ZEND_ENGINE_2 zval *this = getThis(); if (this) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &empty) == FAILURE) { return; } XMLWRITER_FROM_OBJECT(intern, this); } else #endif { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|b", &pind, &empty) == FAILURE) { return; } ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter); } ptr = intern->ptr; if (ptr) { buffer = intern->output; if (force_string == 1 && buffer == NULL) { RETURN_EMPTY_STRING(); } output_bytes = xmlTextWriterFlush(ptr); if (buffer) { RETVAL_STRING((char *) buffer->content, 1); if (empty) { xmlBufferEmpty(buffer); } } else { RETVAL_LONG(output_bytes); } return; } RETURN_EMPTY_STRING(); }
Bypass
0
static void php_xmlwriter_flush(INTERNAL_FUNCTION_PARAMETERS, int force_string) { zval *pind; xmlwriter_object *intern; xmlTextWriterPtr ptr; xmlBufferPtr buffer; zend_bool empty = 1; int output_bytes; #ifdef ZEND_ENGINE_2 zval *this = getThis(); if (this) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &empty) == FAILURE) { return; } XMLWRITER_FROM_OBJECT(intern, this); } else #endif { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|b", &pind, &empty) == FAILURE) { return; } ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter); } ptr = intern->ptr; if (ptr) { buffer = intern->output; if (force_string == 1 && buffer == NULL) { RETURN_EMPTY_STRING(); } output_bytes = xmlTextWriterFlush(ptr); if (buffer) { RETVAL_STRING((char *) buffer->content, 1); if (empty) { xmlBufferEmpty(buffer); } } else { RETVAL_LONG(output_bytes); } return; } RETURN_EMPTY_STRING(); }
@@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity) /* }}} */ #endif -/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source) +/* {{{ proto resource xmlwriter_open_uri(string source) Create new xmlwriter using source uri for output */ static PHP_FUNCTION(xmlwriter_open_uri) { @@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri) void *ioctx; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) { return; }
CWE-254
null
null
12,314
static int php_xmlwriter_streams_IO_close(void *context) { TSRMLS_FETCH(); return php_stream_close((php_stream*)context); }
Bypass
0
static int php_xmlwriter_streams_IO_close(void *context) { TSRMLS_FETCH(); return php_stream_close((php_stream*)context); }
@@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity) /* }}} */ #endif -/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source) +/* {{{ proto resource xmlwriter_open_uri(string source) Create new xmlwriter using source uri for output */ static PHP_FUNCTION(xmlwriter_open_uri) { @@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri) void *ioctx; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) { return; }
CWE-254
null
null
12,315
static int php_xmlwriter_streams_IO_write(void *context, const char *buffer, int len) { TSRMLS_FETCH(); return php_stream_write((php_stream*)context, buffer, len); }
Bypass
0
static int php_xmlwriter_streams_IO_write(void *context, const char *buffer, int len) { TSRMLS_FETCH(); return php_stream_write((php_stream*)context, buffer, len); }
@@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity) /* }}} */ #endif -/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source) +/* {{{ proto resource xmlwriter_open_uri(string source) Create new xmlwriter using source uri for output */ static PHP_FUNCTION(xmlwriter_open_uri) { @@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri) void *ioctx; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) { return; }
CWE-254
null
null
12,316
static void php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAMETERS, xmlwriter_read_one_char_t internal_function, char *err_string) { zval *pind; xmlwriter_object *intern; xmlTextWriterPtr ptr; char *name; int name_len, retval; #ifdef ZEND_ENGINE_2 zval *this = getThis(); if (this) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { return; } XMLWRITER_FROM_OBJECT(intern, this); } else #endif { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &pind, &name, &name_len) == FAILURE) { return; } ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter); } if (err_string != NULL) { XMLW_NAME_CHK(err_string); } ptr = intern->ptr; if (ptr) { retval = internal_function(ptr, (xmlChar *) name); if (retval != -1) { RETURN_TRUE; } } RETURN_FALSE; }
Bypass
0
static void php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAMETERS, xmlwriter_read_one_char_t internal_function, char *err_string) { zval *pind; xmlwriter_object *intern; xmlTextWriterPtr ptr; char *name; int name_len, retval; #ifdef ZEND_ENGINE_2 zval *this = getThis(); if (this) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { return; } XMLWRITER_FROM_OBJECT(intern, this); } else #endif { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &pind, &name, &name_len) == FAILURE) { return; } ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter); } if (err_string != NULL) { XMLW_NAME_CHK(err_string); } ptr = intern->ptr; if (ptr) { retval = internal_function(ptr, (xmlChar *) name); if (retval != -1) { RETURN_TRUE; } } RETURN_FALSE; }
@@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity) /* }}} */ #endif -/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source) +/* {{{ proto resource xmlwriter_open_uri(string source) Create new xmlwriter using source uri for output */ static PHP_FUNCTION(xmlwriter_open_uri) { @@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri) void *ioctx; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) { return; }
CWE-254
null
null
12,317
static void xmlwriter_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) { xmlwriter_object *intern; intern = (xmlwriter_object *) rsrc->ptr; xmlwriter_free_resource_ptr(intern TSRMLS_CC); }
Bypass
0
static void xmlwriter_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) { xmlwriter_object *intern; intern = (xmlwriter_object *) rsrc->ptr; xmlwriter_free_resource_ptr(intern TSRMLS_CC); }
@@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity) /* }}} */ #endif -/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source) +/* {{{ proto resource xmlwriter_open_uri(string source) Create new xmlwriter using source uri for output */ static PHP_FUNCTION(xmlwriter_open_uri) { @@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri) void *ioctx; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) { return; }
CWE-254
null
null
12,318
static void xmlwriter_object_free_storage(void *object TSRMLS_DC) { ze_xmlwriter_object * intern = (ze_xmlwriter_object *) object; if (!intern) { return; } if (intern->xmlwriter_ptr) { xmlwriter_free_resource_ptr(intern->xmlwriter_ptr TSRMLS_CC); } intern->xmlwriter_ptr = NULL; zend_object_std_dtor(&intern->zo TSRMLS_CC); efree(intern); }
Bypass
0
static void xmlwriter_object_free_storage(void *object TSRMLS_DC) { ze_xmlwriter_object * intern = (ze_xmlwriter_object *) object; if (!intern) { return; } if (intern->xmlwriter_ptr) { xmlwriter_free_resource_ptr(intern->xmlwriter_ptr TSRMLS_CC); } intern->xmlwriter_ptr = NULL; zend_object_std_dtor(&intern->zo TSRMLS_CC); efree(intern); }
@@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity) /* }}} */ #endif -/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source) +/* {{{ proto resource xmlwriter_open_uri(string source) Create new xmlwriter using source uri for output */ static PHP_FUNCTION(xmlwriter_open_uri) { @@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri) void *ioctx; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) { return; }
CWE-254
null
null
12,319
static zend_object_value xmlwriter_object_new(zend_class_entry *class_type TSRMLS_DC) { ze_xmlwriter_object *intern; zend_object_value retval; intern = emalloc(sizeof(ze_xmlwriter_object)); memset(&intern->zo, 0, sizeof(zend_object)); intern->xmlwriter_ptr = NULL; zend_object_std_init(&intern->zo, class_type TSRMLS_CC); object_properties_init(&intern->zo, class_type); retval.handle = zend_objects_store_put(intern, NULL, (zend_objects_free_object_storage_t) xmlwriter_object_free_storage, NULL TSRMLS_CC); retval.handlers = (zend_object_handlers *) & xmlwriter_object_handlers; return retval; }
Bypass
0
static zend_object_value xmlwriter_object_new(zend_class_entry *class_type TSRMLS_DC) { ze_xmlwriter_object *intern; zend_object_value retval; intern = emalloc(sizeof(ze_xmlwriter_object)); memset(&intern->zo, 0, sizeof(zend_object)); intern->xmlwriter_ptr = NULL; zend_object_std_init(&intern->zo, class_type TSRMLS_CC); object_properties_init(&intern->zo, class_type); retval.handle = zend_objects_store_put(intern, NULL, (zend_objects_free_object_storage_t) xmlwriter_object_free_storage, NULL TSRMLS_CC); retval.handlers = (zend_object_handlers *) & xmlwriter_object_handlers; return retval; }
@@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity) /* }}} */ #endif -/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source) +/* {{{ proto resource xmlwriter_open_uri(string source) Create new xmlwriter using source uri for output */ static PHP_FUNCTION(xmlwriter_open_uri) { @@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri) void *ioctx; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) { return; }
CWE-254
null
null
12,320
static PHP_FUNCTION(ob_gzhandler) { char *in_str; int in_len; long flags = 0; php_output_context ctx = {0}; int encoding, rv; /* * NOTE that the real ob_gzhandler is an alias to "zlib output compression". * This is a really bad hack, because * - we have to initialize a php_zlib_context on demand * - we have to clean it up in RSHUTDOWN * - OG(running) is not set or set to any other output handler * - we have to mess around with php_output_context */ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &in_str, &in_len, &flags)) { RETURN_FALSE; } if (!(encoding = php_zlib_output_encoding(TSRMLS_C))) { RETURN_FALSE; } if (flags & PHP_OUTPUT_HANDLER_START) { switch (encoding) { case PHP_ZLIB_ENCODING_GZIP: sapi_add_header_ex(ZEND_STRL("Content-Encoding: gzip"), 1, 1 TSRMLS_CC); break; case PHP_ZLIB_ENCODING_DEFLATE: sapi_add_header_ex(ZEND_STRL("Content-Encoding: deflate"), 1, 1 TSRMLS_CC); break; } sapi_add_header_ex(ZEND_STRL("Vary: Accept-Encoding"), 1, 0 TSRMLS_CC); } if (!ZLIBG(ob_gzhandler)) { ZLIBG(ob_gzhandler) = php_zlib_output_handler_context_init(TSRMLS_C); } TSRMLS_SET_CTX(ctx.tsrm_ls); ctx.op = flags; ctx.in.data = in_str; ctx.in.used = in_len; rv = php_zlib_output_handler_ex(ZLIBG(ob_gzhandler), &ctx); if (SUCCESS != rv) { if (ctx.out.data && ctx.out.free) { efree(ctx.out.data); } php_zlib_cleanup_ob_gzhandler_mess(TSRMLS_C); RETURN_FALSE; } if (ctx.out.data) { RETVAL_STRINGL(ctx.out.data, ctx.out.used, 1); if (ctx.out.free) { efree(ctx.out.data); } } else { RETVAL_EMPTY_STRING(); } }
Bypass
0
static PHP_FUNCTION(ob_gzhandler) { char *in_str; int in_len; long flags = 0; php_output_context ctx = {0}; int encoding, rv; /* * NOTE that the real ob_gzhandler is an alias to "zlib output compression". * This is a really bad hack, because * - we have to initialize a php_zlib_context on demand * - we have to clean it up in RSHUTDOWN * - OG(running) is not set or set to any other output handler * - we have to mess around with php_output_context */ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &in_str, &in_len, &flags)) { RETURN_FALSE; } if (!(encoding = php_zlib_output_encoding(TSRMLS_C))) { RETURN_FALSE; } if (flags & PHP_OUTPUT_HANDLER_START) { switch (encoding) { case PHP_ZLIB_ENCODING_GZIP: sapi_add_header_ex(ZEND_STRL("Content-Encoding: gzip"), 1, 1 TSRMLS_CC); break; case PHP_ZLIB_ENCODING_DEFLATE: sapi_add_header_ex(ZEND_STRL("Content-Encoding: deflate"), 1, 1 TSRMLS_CC); break; } sapi_add_header_ex(ZEND_STRL("Vary: Accept-Encoding"), 1, 0 TSRMLS_CC); } if (!ZLIBG(ob_gzhandler)) { ZLIBG(ob_gzhandler) = php_zlib_output_handler_context_init(TSRMLS_C); } TSRMLS_SET_CTX(ctx.tsrm_ls); ctx.op = flags; ctx.in.data = in_str; ctx.in.used = in_len; rv = php_zlib_output_handler_ex(ZLIBG(ob_gzhandler), &ctx); if (SUCCESS != rv) { if (ctx.out.data && ctx.out.free) { efree(ctx.out.data); } php_zlib_cleanup_ob_gzhandler_mess(TSRMLS_C); RETURN_FALSE; } if (ctx.out.data) { RETVAL_STRINGL(ctx.out.data, ctx.out.used, 1); if (ctx.out.free) { efree(ctx.out.data); } } else { RETVAL_EMPTY_STRING(); } }
@@ -581,7 +581,7 @@ static PHP_FUNCTION(gzopen) php_stream *stream; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ps|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { return; } @@ -609,7 +609,7 @@ static PHP_FUNCTION(readgzfile) int size; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &filename, &filename_len, &use_include_path) == FAILURE) { return; }
CWE-254
null
null
12,321
static PHP_FUNCTION(zlib_get_coding_type) { if (zend_parse_parameters_none() == FAILURE) { return; } switch (ZLIBG(compression_coding)) { case PHP_ZLIB_ENCODING_GZIP: RETURN_STRINGL("gzip", sizeof("gzip") - 1, 1); case PHP_ZLIB_ENCODING_DEFLATE: RETURN_STRINGL("deflate", sizeof("deflate") - 1, 1); default: RETURN_FALSE; } }
Bypass
0
static PHP_FUNCTION(zlib_get_coding_type) { if (zend_parse_parameters_none() == FAILURE) { return; } switch (ZLIBG(compression_coding)) { case PHP_ZLIB_ENCODING_GZIP: RETURN_STRINGL("gzip", sizeof("gzip") - 1, 1); case PHP_ZLIB_ENCODING_DEFLATE: RETURN_STRINGL("deflate", sizeof("deflate") - 1, 1); default: RETURN_FALSE; } }
@@ -581,7 +581,7 @@ static PHP_FUNCTION(gzopen) php_stream *stream; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ps|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { return; } @@ -609,7 +609,7 @@ static PHP_FUNCTION(readgzfile) int size; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &filename, &filename_len, &use_include_path) == FAILURE) { return; }
CWE-254
null
null
12,322
static PHP_FUNCTION(gzfile) { char *filename; int filename_len; int flags = REPORT_ERRORS; char buf[8192] = {0}; register int i = 0; long use_include_path = 0; php_stream *stream; if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &filename, &filename_len, &use_include_path)) { return; } if (use_include_path) { flags |= USE_PATH; } /* using a stream here is a bit more efficient (resource wise) than php_gzopen_wrapper */ stream = php_stream_gzopen(NULL, filename, "rb", flags, NULL, NULL STREAMS_CC TSRMLS_CC); if (!stream) { /* Error reporting is already done by stream code */ RETURN_FALSE; } /* Initialize return array */ array_init(return_value); /* Now loop through the file and do the magic quotes thing if needed */ memset(buf, 0, sizeof(buf)); while (php_stream_gets(stream, buf, sizeof(buf) - 1) != NULL) { add_index_string(return_value, i++, buf, 1); } php_stream_close(stream); }
Bypass
0
static PHP_FUNCTION(gzfile) { char *filename; int filename_len; int flags = REPORT_ERRORS; char buf[8192] = {0}; register int i = 0; long use_include_path = 0; php_stream *stream; if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &filename, &filename_len, &use_include_path)) { return; } if (use_include_path) { flags |= USE_PATH; } /* using a stream here is a bit more efficient (resource wise) than php_gzopen_wrapper */ stream = php_stream_gzopen(NULL, filename, "rb", flags, NULL, NULL STREAMS_CC TSRMLS_CC); if (!stream) { /* Error reporting is already done by stream code */ RETURN_FALSE; } /* Initialize return array */ array_init(return_value); /* Now loop through the file and do the magic quotes thing if needed */ memset(buf, 0, sizeof(buf)); while (php_stream_gets(stream, buf, sizeof(buf) - 1) != NULL) { add_index_string(return_value, i++, buf, 1); } php_stream_close(stream); }
@@ -581,7 +581,7 @@ static PHP_FUNCTION(gzopen) php_stream *stream; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ps|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { return; } @@ -609,7 +609,7 @@ static PHP_FUNCTION(readgzfile) int size; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &filename, &filename_len, &use_include_path) == FAILURE) { return; }
CWE-254
null
null
12,323
static PHP_INI_MH(OnUpdate_zlib_output_compression) { int status, int_value; char *ini_value; if (new_value == NULL) { return FAILURE; } if (!strncasecmp(new_value, "off", sizeof("off"))) { new_value = "0"; new_value_length = sizeof("0"); } else if (!strncasecmp(new_value, "on", sizeof("on"))) { new_value = "1"; new_value_length = sizeof("1"); } int_value = zend_atoi(new_value, new_value_length); ini_value = zend_ini_string("output_handler", sizeof("output_handler"), 0); if (ini_value && *ini_value && int_value) { php_error_docref("ref.outcontrol" TSRMLS_CC, E_CORE_ERROR, "Cannot use both zlib.output_compression and output_handler together!!"); return FAILURE; } if (stage == PHP_INI_STAGE_RUNTIME) { status = php_output_get_status(TSRMLS_C); if (status & PHP_OUTPUT_SENT) { php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "Cannot change zlib.output_compression - headers already sent"); return FAILURE; } } status = OnUpdateLong(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); ZLIBG(output_compression) = ZLIBG(output_compression_default); if (stage == PHP_INI_STAGE_RUNTIME && int_value) { if (!php_output_handler_started(ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME) TSRMLS_CC)) { php_zlib_output_compression_start(TSRMLS_C); } } return status; }
Bypass
0
static PHP_INI_MH(OnUpdate_zlib_output_compression) { int status, int_value; char *ini_value; if (new_value == NULL) { return FAILURE; } if (!strncasecmp(new_value, "off", sizeof("off"))) { new_value = "0"; new_value_length = sizeof("0"); } else if (!strncasecmp(new_value, "on", sizeof("on"))) { new_value = "1"; new_value_length = sizeof("1"); } int_value = zend_atoi(new_value, new_value_length); ini_value = zend_ini_string("output_handler", sizeof("output_handler"), 0); if (ini_value && *ini_value && int_value) { php_error_docref("ref.outcontrol" TSRMLS_CC, E_CORE_ERROR, "Cannot use both zlib.output_compression and output_handler together!!"); return FAILURE; } if (stage == PHP_INI_STAGE_RUNTIME) { status = php_output_get_status(TSRMLS_C); if (status & PHP_OUTPUT_SENT) { php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "Cannot change zlib.output_compression - headers already sent"); return FAILURE; } } status = OnUpdateLong(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); ZLIBG(output_compression) = ZLIBG(output_compression_default); if (stage == PHP_INI_STAGE_RUNTIME && int_value) { if (!php_output_handler_started(ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME) TSRMLS_CC)) { php_zlib_output_compression_start(TSRMLS_C); } } return status; }
@@ -581,7 +581,7 @@ static PHP_FUNCTION(gzopen) php_stream *stream; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ps|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { return; } @@ -609,7 +609,7 @@ static PHP_FUNCTION(readgzfile) int size; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &filename, &filename_len, &use_include_path) == FAILURE) { return; }
CWE-254
null
null
12,324
static PHP_INI_MH(OnUpdate_zlib_output_handler) { if (stage == PHP_INI_STAGE_RUNTIME && (php_output_get_status(TSRMLS_C) & PHP_OUTPUT_SENT)) { php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "Cannot change zlib.output_handler - headers already sent"); return FAILURE; } return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); }
Bypass
0
static PHP_INI_MH(OnUpdate_zlib_output_handler) { if (stage == PHP_INI_STAGE_RUNTIME && (php_output_get_status(TSRMLS_C) & PHP_OUTPUT_SENT)) { php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "Cannot change zlib.output_handler - headers already sent"); return FAILURE; } return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); }
@@ -581,7 +581,7 @@ static PHP_FUNCTION(gzopen) php_stream *stream; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ps|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { return; } @@ -609,7 +609,7 @@ static PHP_FUNCTION(readgzfile) int size; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &filename, &filename_len, &use_include_path) == FAILURE) { return; }
CWE-254
null
null
12,325
static PHP_MINFO_FUNCTION(zlib) { php_info_print_table_start(); php_info_print_table_header(2, "ZLib Support", "enabled"); php_info_print_table_row(2, "Stream Wrapper", "compress.zlib://"); php_info_print_table_row(2, "Stream Filter", "zlib.inflate, zlib.deflate"); php_info_print_table_row(2, "Compiled Version", ZLIB_VERSION); php_info_print_table_row(2, "Linked Version", (char *) zlibVersion()); php_info_print_table_end(); DISPLAY_INI_ENTRIES(); }
Bypass
0
static PHP_MINFO_FUNCTION(zlib) { php_info_print_table_start(); php_info_print_table_header(2, "ZLib Support", "enabled"); php_info_print_table_row(2, "Stream Wrapper", "compress.zlib://"); php_info_print_table_row(2, "Stream Filter", "zlib.inflate, zlib.deflate"); php_info_print_table_row(2, "Compiled Version", ZLIB_VERSION); php_info_print_table_row(2, "Linked Version", (char *) zlibVersion()); php_info_print_table_end(); DISPLAY_INI_ENTRIES(); }
@@ -581,7 +581,7 @@ static PHP_FUNCTION(gzopen) php_stream *stream; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ps|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { return; } @@ -609,7 +609,7 @@ static PHP_FUNCTION(readgzfile) int size; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &filename, &filename_len, &use_include_path) == FAILURE) { return; }
CWE-254
null
null
12,326
static PHP_MINIT_FUNCTION(zlib) { php_register_url_stream_wrapper("compress.zlib", &php_stream_gzip_wrapper TSRMLS_CC); php_stream_filter_register_factory("zlib.*", &php_zlib_filter_factory TSRMLS_CC); php_output_handler_alias_register(ZEND_STRL("ob_gzhandler"), php_zlib_output_handler_init TSRMLS_CC); php_output_handler_conflict_register(ZEND_STRL("ob_gzhandler"), php_zlib_output_conflict_check TSRMLS_CC); php_output_handler_conflict_register(ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME), php_zlib_output_conflict_check TSRMLS_CC); REGISTER_LONG_CONSTANT("FORCE_GZIP", PHP_ZLIB_ENCODING_GZIP, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("FORCE_DEFLATE", PHP_ZLIB_ENCODING_DEFLATE, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_ENCODING_RAW", PHP_ZLIB_ENCODING_RAW, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_ENCODING_GZIP", PHP_ZLIB_ENCODING_GZIP, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_ENCODING_DEFLATE", PHP_ZLIB_ENCODING_DEFLATE, CONST_CS|CONST_PERSISTENT); REGISTER_INI_ENTRIES(); return SUCCESS; }
Bypass
0
static PHP_MINIT_FUNCTION(zlib) { php_register_url_stream_wrapper("compress.zlib", &php_stream_gzip_wrapper TSRMLS_CC); php_stream_filter_register_factory("zlib.*", &php_zlib_filter_factory TSRMLS_CC); php_output_handler_alias_register(ZEND_STRL("ob_gzhandler"), php_zlib_output_handler_init TSRMLS_CC); php_output_handler_conflict_register(ZEND_STRL("ob_gzhandler"), php_zlib_output_conflict_check TSRMLS_CC); php_output_handler_conflict_register(ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME), php_zlib_output_conflict_check TSRMLS_CC); REGISTER_LONG_CONSTANT("FORCE_GZIP", PHP_ZLIB_ENCODING_GZIP, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("FORCE_DEFLATE", PHP_ZLIB_ENCODING_DEFLATE, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_ENCODING_RAW", PHP_ZLIB_ENCODING_RAW, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_ENCODING_GZIP", PHP_ZLIB_ENCODING_GZIP, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_ENCODING_DEFLATE", PHP_ZLIB_ENCODING_DEFLATE, CONST_CS|CONST_PERSISTENT); REGISTER_INI_ENTRIES(); return SUCCESS; }
@@ -581,7 +581,7 @@ static PHP_FUNCTION(gzopen) php_stream *stream; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ps|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { return; } @@ -609,7 +609,7 @@ static PHP_FUNCTION(readgzfile) int size; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &filename, &filename_len, &use_include_path) == FAILURE) { return; }
CWE-254
null
null
12,327
static PHP_MSHUTDOWN_FUNCTION(zlib) { php_unregister_url_stream_wrapper("zlib" TSRMLS_CC); php_stream_filter_unregister_factory("zlib.*" TSRMLS_CC); UNREGISTER_INI_ENTRIES(); return SUCCESS; }
Bypass
0
static PHP_MSHUTDOWN_FUNCTION(zlib) { php_unregister_url_stream_wrapper("zlib" TSRMLS_CC); php_stream_filter_unregister_factory("zlib.*" TSRMLS_CC); UNREGISTER_INI_ENTRIES(); return SUCCESS; }
@@ -581,7 +581,7 @@ static PHP_FUNCTION(gzopen) php_stream *stream; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ps|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { return; } @@ -609,7 +609,7 @@ static PHP_FUNCTION(readgzfile) int size; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &filename, &filename_len, &use_include_path) == FAILURE) { return; }
CWE-254
null
null
12,328
static PHP_RINIT_FUNCTION(zlib) { ZLIBG(compression_coding) = 0; if (!ZLIBG(handler_registered)) { ZLIBG(output_compression) = ZLIBG(output_compression_default); php_zlib_output_compression_start(TSRMLS_C); } return SUCCESS; }
Bypass
0
static PHP_RINIT_FUNCTION(zlib) { ZLIBG(compression_coding) = 0; if (!ZLIBG(handler_registered)) { ZLIBG(output_compression) = ZLIBG(output_compression_default); php_zlib_output_compression_start(TSRMLS_C); } return SUCCESS; }
@@ -581,7 +581,7 @@ static PHP_FUNCTION(gzopen) php_stream *stream; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ps|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { return; } @@ -609,7 +609,7 @@ static PHP_FUNCTION(readgzfile) int size; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &filename, &filename_len, &use_include_path) == FAILURE) { return; }
CWE-254
null
null
12,329
static PHP_RSHUTDOWN_FUNCTION(zlib) { php_zlib_cleanup_ob_gzhandler_mess(TSRMLS_C); ZLIBG(handler_registered) = 0; return SUCCESS; }
Bypass
0
static PHP_RSHUTDOWN_FUNCTION(zlib) { php_zlib_cleanup_ob_gzhandler_mess(TSRMLS_C); ZLIBG(handler_registered) = 0; return SUCCESS; }
@@ -581,7 +581,7 @@ static PHP_FUNCTION(gzopen) php_stream *stream; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ps|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { return; } @@ -609,7 +609,7 @@ static PHP_FUNCTION(readgzfile) int size; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &filename, &filename_len, &use_include_path) == FAILURE) { return; }
CWE-254
null
null
12,330
static ZEND_MODULE_GLOBALS_CTOR_D(zlib) { zlib_globals->ob_gzhandler = NULL; zlib_globals->handler_registered = 0; }
Bypass
0
static ZEND_MODULE_GLOBALS_CTOR_D(zlib) { zlib_globals->ob_gzhandler = NULL; zlib_globals->handler_registered = 0; }
@@ -581,7 +581,7 @@ static PHP_FUNCTION(gzopen) php_stream *stream; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ps|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { return; } @@ -609,7 +609,7 @@ static PHP_FUNCTION(readgzfile) int size; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &filename, &filename_len, &use_include_path) == FAILURE) { return; }
CWE-254
null
null
12,331
static voidpf php_zlib_alloc(voidpf opaque, uInt items, uInt size) { return (voidpf)safe_emalloc(items, size, 0); }
Bypass
0
static voidpf php_zlib_alloc(voidpf opaque, uInt items, uInt size) { return (voidpf)safe_emalloc(items, size, 0); }
@@ -581,7 +581,7 @@ static PHP_FUNCTION(gzopen) php_stream *stream; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ps|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { return; } @@ -609,7 +609,7 @@ static PHP_FUNCTION(readgzfile) int size; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &filename, &filename_len, &use_include_path) == FAILURE) { return; }
CWE-254
null
null
12,332
static int php_zlib_decode(const char *in_buf, size_t in_len, char **out_buf, size_t *out_len, int encoding, size_t max_len TSRMLS_DC) { int status = Z_DATA_ERROR; z_stream Z; memset(&Z, 0, sizeof(z_stream)); Z.zalloc = php_zlib_alloc; Z.zfree = php_zlib_free; if (in_len) { retry_raw_inflate: status = inflateInit2(&Z, encoding); if (Z_OK == status) { Z.next_in = (Bytef *) in_buf; Z.avail_in = in_len + 1; /* NOTE: data must be zero terminated */ switch (status = php_zlib_inflate_rounds(&Z, max_len, out_buf, out_len)) { case Z_STREAM_END: inflateEnd(&Z); return SUCCESS; case Z_DATA_ERROR: /* raw deflated data? */ if (PHP_ZLIB_ENCODING_ANY == encoding) { inflateEnd(&Z); encoding = PHP_ZLIB_ENCODING_RAW; goto retry_raw_inflate; } } inflateEnd(&Z); } } *out_buf = NULL; *out_len = 0; php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status)); return FAILURE; }
Bypass
0
static int php_zlib_decode(const char *in_buf, size_t in_len, char **out_buf, size_t *out_len, int encoding, size_t max_len TSRMLS_DC) { int status = Z_DATA_ERROR; z_stream Z; memset(&Z, 0, sizeof(z_stream)); Z.zalloc = php_zlib_alloc; Z.zfree = php_zlib_free; if (in_len) { retry_raw_inflate: status = inflateInit2(&Z, encoding); if (Z_OK == status) { Z.next_in = (Bytef *) in_buf; Z.avail_in = in_len + 1; /* NOTE: data must be zero terminated */ switch (status = php_zlib_inflate_rounds(&Z, max_len, out_buf, out_len)) { case Z_STREAM_END: inflateEnd(&Z); return SUCCESS; case Z_DATA_ERROR: /* raw deflated data? */ if (PHP_ZLIB_ENCODING_ANY == encoding) { inflateEnd(&Z); encoding = PHP_ZLIB_ENCODING_RAW; goto retry_raw_inflate; } } inflateEnd(&Z); } } *out_buf = NULL; *out_len = 0; php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status)); return FAILURE; }
@@ -581,7 +581,7 @@ static PHP_FUNCTION(gzopen) php_stream *stream; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ps|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { return; } @@ -609,7 +609,7 @@ static PHP_FUNCTION(readgzfile) int size; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &filename, &filename_len, &use_include_path) == FAILURE) { return; }
CWE-254
null
null
12,333
static void php_zlib_free(voidpf opaque, voidpf address) { efree((void*)address); }
Bypass
0
static void php_zlib_free(voidpf opaque, voidpf address) { efree((void*)address); }
@@ -581,7 +581,7 @@ static PHP_FUNCTION(gzopen) php_stream *stream; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ps|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { return; } @@ -609,7 +609,7 @@ static PHP_FUNCTION(readgzfile) int size; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &filename, &filename_len, &use_include_path) == FAILURE) { return; }
CWE-254
null
null
12,334
static inline int php_zlib_inflate_rounds(z_stream *Z, size_t max, char **buf, size_t *len) { int status, round = 0; php_zlib_buffer buffer = {NULL, NULL, 0, 0, 0}; *buf = NULL; *len = 0; buffer.size = (max && (max < Z->avail_in)) ? max : Z->avail_in; do { if ((max && (max <= buffer.used)) || !(buffer.aptr = erealloc_recoverable(buffer.data, buffer.size))) { status = Z_MEM_ERROR; } else { buffer.data = buffer.aptr; Z->avail_out = buffer.free = buffer.size - buffer.used; Z->next_out = (Bytef *) buffer.data + buffer.used; #if 0 fprintf(stderr, "\n%3d: %3d PRIOR: size=%7lu,\tfree=%7lu,\tused=%7lu,\tavail_in=%7lu,\tavail_out=%7lu\n", round, status, buffer.size, buffer.free, buffer.used, Z->avail_in, Z->avail_out); #endif status = inflate(Z, Z_NO_FLUSH); buffer.used += buffer.free - Z->avail_out; buffer.free = Z->avail_out; #if 0 fprintf(stderr, "%3d: %3d AFTER: size=%7lu,\tfree=%7lu,\tused=%7lu,\tavail_in=%7lu,\tavail_out=%7lu\n", round, status, buffer.size, buffer.free, buffer.used, Z->avail_in, Z->avail_out); #endif buffer.size += (buffer.size >> 3) + 1; } } while ((Z_BUF_ERROR == status || (Z_OK == status && Z->avail_in)) && ++round < 100); if (status == Z_STREAM_END) { buffer.data = erealloc(buffer.data, buffer.used + 1); buffer.data[buffer.used] = '\0'; *buf = buffer.data; *len = buffer.used; } else { if (buffer.data) { efree(buffer.data); } /* HACK: See zlib/examples/zpipe.c inf() function for explanation. */ /* This works as long as this function is not used for streaming. Required to catch very short invalid data. */ status = (status == Z_OK) ? Z_DATA_ERROR : status; } return status; }
Bypass
0
static inline int php_zlib_inflate_rounds(z_stream *Z, size_t max, char **buf, size_t *len) { int status, round = 0; php_zlib_buffer buffer = {NULL, NULL, 0, 0, 0}; *buf = NULL; *len = 0; buffer.size = (max && (max < Z->avail_in)) ? max : Z->avail_in; do { if ((max && (max <= buffer.used)) || !(buffer.aptr = erealloc_recoverable(buffer.data, buffer.size))) { status = Z_MEM_ERROR; } else { buffer.data = buffer.aptr; Z->avail_out = buffer.free = buffer.size - buffer.used; Z->next_out = (Bytef *) buffer.data + buffer.used; #if 0 fprintf(stderr, "\n%3d: %3d PRIOR: size=%7lu,\tfree=%7lu,\tused=%7lu,\tavail_in=%7lu,\tavail_out=%7lu\n", round, status, buffer.size, buffer.free, buffer.used, Z->avail_in, Z->avail_out); #endif status = inflate(Z, Z_NO_FLUSH); buffer.used += buffer.free - Z->avail_out; buffer.free = Z->avail_out; #if 0 fprintf(stderr, "%3d: %3d AFTER: size=%7lu,\tfree=%7lu,\tused=%7lu,\tavail_in=%7lu,\tavail_out=%7lu\n", round, status, buffer.size, buffer.free, buffer.used, Z->avail_in, Z->avail_out); #endif buffer.size += (buffer.size >> 3) + 1; } } while ((Z_BUF_ERROR == status || (Z_OK == status && Z->avail_in)) && ++round < 100); if (status == Z_STREAM_END) { buffer.data = erealloc(buffer.data, buffer.used + 1); buffer.data[buffer.used] = '\0'; *buf = buffer.data; *len = buffer.used; } else { if (buffer.data) { efree(buffer.data); } /* HACK: See zlib/examples/zpipe.c inf() function for explanation. */ /* This works as long as this function is not used for streaming. Required to catch very short invalid data. */ status = (status == Z_OK) ? Z_DATA_ERROR : status; } return status; }
@@ -581,7 +581,7 @@ static PHP_FUNCTION(gzopen) php_stream *stream; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ps|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { return; } @@ -609,7 +609,7 @@ static PHP_FUNCTION(readgzfile) int size; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &filename, &filename_len, &use_include_path) == FAILURE) { return; }
CWE-254
null
null
12,335
static void php_zlib_output_compression_start(TSRMLS_D) { zval *zoh; php_output_handler *h; switch (ZLIBG(output_compression)) { case 0: break; case 1: ZLIBG(output_compression) = PHP_OUTPUT_HANDLER_DEFAULT_SIZE; /* break omitted intentionally */ default: if ( php_zlib_output_encoding(TSRMLS_C) && (h = php_zlib_output_handler_init(ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME), ZLIBG(output_compression), PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC)) && (SUCCESS == php_output_handler_start(h TSRMLS_CC))) { if (ZLIBG(output_handler) && *ZLIBG(output_handler)) { MAKE_STD_ZVAL(zoh); ZVAL_STRING(zoh, ZLIBG(output_handler), 1); php_output_start_user(zoh, ZLIBG(output_compression), PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC); zval_ptr_dtor(&zoh); } } break; } }
Bypass
0
static void php_zlib_output_compression_start(TSRMLS_D) { zval *zoh; php_output_handler *h; switch (ZLIBG(output_compression)) { case 0: break; case 1: ZLIBG(output_compression) = PHP_OUTPUT_HANDLER_DEFAULT_SIZE; /* break omitted intentionally */ default: if ( php_zlib_output_encoding(TSRMLS_C) && (h = php_zlib_output_handler_init(ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME), ZLIBG(output_compression), PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC)) && (SUCCESS == php_output_handler_start(h TSRMLS_CC))) { if (ZLIBG(output_handler) && *ZLIBG(output_handler)) { MAKE_STD_ZVAL(zoh); ZVAL_STRING(zoh, ZLIBG(output_handler), 1); php_output_start_user(zoh, ZLIBG(output_compression), PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC); zval_ptr_dtor(&zoh); } } break; } }
@@ -581,7 +581,7 @@ static PHP_FUNCTION(gzopen) php_stream *stream; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ps|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { return; } @@ -609,7 +609,7 @@ static PHP_FUNCTION(readgzfile) int size; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &filename, &filename_len, &use_include_path) == FAILURE) { return; }
CWE-254
null
null
12,336
static int php_zlib_output_conflict_check(const char *handler_name, size_t handler_name_len TSRMLS_DC) { if (php_output_get_level(TSRMLS_C) > 0) { if (php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME) TSRMLS_CC) || php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("ob_gzhandler") TSRMLS_CC) || php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("mb_output_handler") TSRMLS_CC) || php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("URL-Rewriter") TSRMLS_CC)) { return FAILURE; } } return SUCCESS; }
Bypass
0
static int php_zlib_output_conflict_check(const char *handler_name, size_t handler_name_len TSRMLS_DC) { if (php_output_get_level(TSRMLS_C) > 0) { if (php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME) TSRMLS_CC) || php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("ob_gzhandler") TSRMLS_CC) || php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("mb_output_handler") TSRMLS_CC) || php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("URL-Rewriter") TSRMLS_CC)) { return FAILURE; } } return SUCCESS; }
@@ -581,7 +581,7 @@ static PHP_FUNCTION(gzopen) php_stream *stream; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ps|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { return; } @@ -609,7 +609,7 @@ static PHP_FUNCTION(readgzfile) int size; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &filename, &filename_len, &use_include_path) == FAILURE) { return; }
CWE-254
null
null
12,337
static int php_zlib_output_encoding(TSRMLS_D) { zval **enc; if (!ZLIBG(compression_coding)) { zend_is_auto_global(ZEND_STRL("_SERVER") TSRMLS_CC); if (PG(http_globals)[TRACK_VARS_SERVER] && SUCCESS == zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_ACCEPT_ENCODING", sizeof("HTTP_ACCEPT_ENCODING"), (void *) &enc)) { convert_to_string(*enc); if (strstr(Z_STRVAL_PP(enc), "gzip")) { ZLIBG(compression_coding) = PHP_ZLIB_ENCODING_GZIP; } else if (strstr(Z_STRVAL_PP(enc), "deflate")) { ZLIBG(compression_coding) = PHP_ZLIB_ENCODING_DEFLATE; } } } return ZLIBG(compression_coding); }
Bypass
0
static int php_zlib_output_encoding(TSRMLS_D) { zval **enc; if (!ZLIBG(compression_coding)) { zend_is_auto_global(ZEND_STRL("_SERVER") TSRMLS_CC); if (PG(http_globals)[TRACK_VARS_SERVER] && SUCCESS == zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_ACCEPT_ENCODING", sizeof("HTTP_ACCEPT_ENCODING"), (void *) &enc)) { convert_to_string(*enc); if (strstr(Z_STRVAL_PP(enc), "gzip")) { ZLIBG(compression_coding) = PHP_ZLIB_ENCODING_GZIP; } else if (strstr(Z_STRVAL_PP(enc), "deflate")) { ZLIBG(compression_coding) = PHP_ZLIB_ENCODING_DEFLATE; } } } return ZLIBG(compression_coding); }
@@ -581,7 +581,7 @@ static PHP_FUNCTION(gzopen) php_stream *stream; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ps|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { return; } @@ -609,7 +609,7 @@ static PHP_FUNCTION(readgzfile) int size; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &filename, &filename_len, &use_include_path) == FAILURE) { return; }
CWE-254
null
null
12,338
static int php_zlib_output_handler(void **handler_context, php_output_context *output_context) { php_zlib_context *ctx = *(php_zlib_context **) handler_context; PHP_OUTPUT_TSRMLS(output_context); if (!php_zlib_output_encoding(TSRMLS_C)) { /* "Vary: Accept-Encoding" header sent along uncompressed content breaks caching in MSIE, so let's just send it with successfully compressed content or unless the complete buffer gets discarded, see http://bugs.php.net/40325; Test as follows: +Vary: $ HTTP_ACCEPT_ENCODING=gzip ./sapi/cgi/php <<<'<?php ob_start("ob_gzhandler"); echo "foo\n";' +Vary: $ HTTP_ACCEPT_ENCODING= ./sapi/cgi/php <<<'<?php ob_start("ob_gzhandler"); echo "foo\n";' -Vary: $ HTTP_ACCEPT_ENCODING=gzip ./sapi/cgi/php <<<'<?php ob_start("ob_gzhandler"); echo "foo\n"; ob_end_clean();' -Vary: $ HTTP_ACCEPT_ENCODING= ./sapi/cgi/php <<<'<?php ob_start("ob_gzhandler"); echo "foo\n"; ob_end_clean();' */ if ((output_context->op & PHP_OUTPUT_HANDLER_START) && (output_context->op != (PHP_OUTPUT_HANDLER_START|PHP_OUTPUT_HANDLER_CLEAN|PHP_OUTPUT_HANDLER_FINAL)) ) { sapi_add_header_ex(ZEND_STRL("Vary: Accept-Encoding"), 1, 0 TSRMLS_CC); } return FAILURE; } if (SUCCESS != php_zlib_output_handler_ex(ctx, output_context)) { return FAILURE; } if (!(output_context->op & PHP_OUTPUT_HANDLER_CLEAN)) { int flags; if (SUCCESS == php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_GET_FLAGS, &flags TSRMLS_CC)) { /* only run this once */ if (!(flags & PHP_OUTPUT_HANDLER_STARTED)) { if (SG(headers_sent) || !ZLIBG(output_compression)) { deflateEnd(&ctx->Z); return FAILURE; } switch (ZLIBG(compression_coding)) { case PHP_ZLIB_ENCODING_GZIP: sapi_add_header_ex(ZEND_STRL("Content-Encoding: gzip"), 1, 1 TSRMLS_CC); break; case PHP_ZLIB_ENCODING_DEFLATE: sapi_add_header_ex(ZEND_STRL("Content-Encoding: deflate"), 1, 1 TSRMLS_CC); break; default: deflateEnd(&ctx->Z); return FAILURE; } sapi_add_header_ex(ZEND_STRL("Vary: Accept-Encoding"), 1, 0 TSRMLS_CC); php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE, NULL TSRMLS_CC); } } } return SUCCESS; }
Bypass
0
static int php_zlib_output_handler(void **handler_context, php_output_context *output_context) { php_zlib_context *ctx = *(php_zlib_context **) handler_context; PHP_OUTPUT_TSRMLS(output_context); if (!php_zlib_output_encoding(TSRMLS_C)) { /* "Vary: Accept-Encoding" header sent along uncompressed content breaks caching in MSIE, so let's just send it with successfully compressed content or unless the complete buffer gets discarded, see http://bugs.php.net/40325; Test as follows: +Vary: $ HTTP_ACCEPT_ENCODING=gzip ./sapi/cgi/php <<<'<?php ob_start("ob_gzhandler"); echo "foo\n";' +Vary: $ HTTP_ACCEPT_ENCODING= ./sapi/cgi/php <<<'<?php ob_start("ob_gzhandler"); echo "foo\n";' -Vary: $ HTTP_ACCEPT_ENCODING=gzip ./sapi/cgi/php <<<'<?php ob_start("ob_gzhandler"); echo "foo\n"; ob_end_clean();' -Vary: $ HTTP_ACCEPT_ENCODING= ./sapi/cgi/php <<<'<?php ob_start("ob_gzhandler"); echo "foo\n"; ob_end_clean();' */ if ((output_context->op & PHP_OUTPUT_HANDLER_START) && (output_context->op != (PHP_OUTPUT_HANDLER_START|PHP_OUTPUT_HANDLER_CLEAN|PHP_OUTPUT_HANDLER_FINAL)) ) { sapi_add_header_ex(ZEND_STRL("Vary: Accept-Encoding"), 1, 0 TSRMLS_CC); } return FAILURE; } if (SUCCESS != php_zlib_output_handler_ex(ctx, output_context)) { return FAILURE; } if (!(output_context->op & PHP_OUTPUT_HANDLER_CLEAN)) { int flags; if (SUCCESS == php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_GET_FLAGS, &flags TSRMLS_CC)) { /* only run this once */ if (!(flags & PHP_OUTPUT_HANDLER_STARTED)) { if (SG(headers_sent) || !ZLIBG(output_compression)) { deflateEnd(&ctx->Z); return FAILURE; } switch (ZLIBG(compression_coding)) { case PHP_ZLIB_ENCODING_GZIP: sapi_add_header_ex(ZEND_STRL("Content-Encoding: gzip"), 1, 1 TSRMLS_CC); break; case PHP_ZLIB_ENCODING_DEFLATE: sapi_add_header_ex(ZEND_STRL("Content-Encoding: deflate"), 1, 1 TSRMLS_CC); break; default: deflateEnd(&ctx->Z); return FAILURE; } sapi_add_header_ex(ZEND_STRL("Vary: Accept-Encoding"), 1, 0 TSRMLS_CC); php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE, NULL TSRMLS_CC); } } } return SUCCESS; }
@@ -581,7 +581,7 @@ static PHP_FUNCTION(gzopen) php_stream *stream; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ps|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { return; } @@ -609,7 +609,7 @@ static PHP_FUNCTION(readgzfile) int size; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &filename, &filename_len, &use_include_path) == FAILURE) { return; }
CWE-254
null
null
12,339
static php_zlib_context *php_zlib_output_handler_context_init(TSRMLS_D) { php_zlib_context *ctx = (php_zlib_context *) ecalloc(1, sizeof(php_zlib_context)); ctx->Z.zalloc = php_zlib_alloc; ctx->Z.zfree = php_zlib_free; return ctx; }
Bypass
0
static php_zlib_context *php_zlib_output_handler_context_init(TSRMLS_D) { php_zlib_context *ctx = (php_zlib_context *) ecalloc(1, sizeof(php_zlib_context)); ctx->Z.zalloc = php_zlib_alloc; ctx->Z.zfree = php_zlib_free; return ctx; }
@@ -581,7 +581,7 @@ static PHP_FUNCTION(gzopen) php_stream *stream; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ps|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { return; } @@ -609,7 +609,7 @@ static PHP_FUNCTION(readgzfile) int size; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &filename, &filename_len, &use_include_path) == FAILURE) { return; }
CWE-254
null
null
12,340
static int php_zlib_output_handler_ex(php_zlib_context *ctx, php_output_context *output_context) { int flags = Z_SYNC_FLUSH; PHP_OUTPUT_TSRMLS(output_context); if (output_context->op & PHP_OUTPUT_HANDLER_START) { /* start up */ if (Z_OK != deflateInit2(&ctx->Z, ZLIBG(output_compression_level), Z_DEFLATED, ZLIBG(compression_coding), MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY)) { return FAILURE; } } if (output_context->op & PHP_OUTPUT_HANDLER_CLEAN) { /* free buffers */ deflateEnd(&ctx->Z); if (output_context->op & PHP_OUTPUT_HANDLER_FINAL) { /* discard */ return SUCCESS; } else { /* restart */ if (Z_OK != deflateInit2(&ctx->Z, ZLIBG(output_compression_level), Z_DEFLATED, ZLIBG(compression_coding), MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY)) { return FAILURE; } ctx->buffer.used = 0; } } else { if (output_context->in.used) { /* append input */ if (ctx->buffer.free < output_context->in.used) { if (!(ctx->buffer.aptr = erealloc_recoverable(ctx->buffer.data, ctx->buffer.used + ctx->buffer.free + output_context->in.used))) { deflateEnd(&ctx->Z); return FAILURE; } ctx->buffer.data = ctx->buffer.aptr; ctx->buffer.free += output_context->in.used; } memcpy(ctx->buffer.data + ctx->buffer.used, output_context->in.data, output_context->in.used); ctx->buffer.free -= output_context->in.used; ctx->buffer.used += output_context->in.used; } output_context->out.size = PHP_ZLIB_BUFFER_SIZE_GUESS(output_context->in.used); output_context->out.data = emalloc(output_context->out.size); output_context->out.free = 1; output_context->out.used = 0; ctx->Z.avail_in = ctx->buffer.used; ctx->Z.next_in = (Bytef *) ctx->buffer.data; ctx->Z.avail_out = output_context->out.size; ctx->Z.next_out = (Bytef *) output_context->out.data; if (output_context->op & PHP_OUTPUT_HANDLER_FINAL) { flags = Z_FINISH; } else if (output_context->op & PHP_OUTPUT_HANDLER_FLUSH) { flags = Z_FULL_FLUSH; } switch (deflate(&ctx->Z, flags)) { case Z_OK: if (flags == Z_FINISH) { deflateEnd(&ctx->Z); return FAILURE; } case Z_STREAM_END: if (ctx->Z.avail_in) { memmove(ctx->buffer.data, ctx->buffer.data + ctx->buffer.used - ctx->Z.avail_in, ctx->Z.avail_in); } ctx->buffer.free += ctx->buffer.used - ctx->Z.avail_in; ctx->buffer.used = ctx->Z.avail_in; output_context->out.used = output_context->out.size - ctx->Z.avail_out; break; default: deflateEnd(&ctx->Z); return FAILURE; } if (output_context->op & PHP_OUTPUT_HANDLER_FINAL) { deflateEnd(&ctx->Z); } } return SUCCESS; }
Bypass
0
static int php_zlib_output_handler_ex(php_zlib_context *ctx, php_output_context *output_context) { int flags = Z_SYNC_FLUSH; PHP_OUTPUT_TSRMLS(output_context); if (output_context->op & PHP_OUTPUT_HANDLER_START) { /* start up */ if (Z_OK != deflateInit2(&ctx->Z, ZLIBG(output_compression_level), Z_DEFLATED, ZLIBG(compression_coding), MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY)) { return FAILURE; } } if (output_context->op & PHP_OUTPUT_HANDLER_CLEAN) { /* free buffers */ deflateEnd(&ctx->Z); if (output_context->op & PHP_OUTPUT_HANDLER_FINAL) { /* discard */ return SUCCESS; } else { /* restart */ if (Z_OK != deflateInit2(&ctx->Z, ZLIBG(output_compression_level), Z_DEFLATED, ZLIBG(compression_coding), MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY)) { return FAILURE; } ctx->buffer.used = 0; } } else { if (output_context->in.used) { /* append input */ if (ctx->buffer.free < output_context->in.used) { if (!(ctx->buffer.aptr = erealloc_recoverable(ctx->buffer.data, ctx->buffer.used + ctx->buffer.free + output_context->in.used))) { deflateEnd(&ctx->Z); return FAILURE; } ctx->buffer.data = ctx->buffer.aptr; ctx->buffer.free += output_context->in.used; } memcpy(ctx->buffer.data + ctx->buffer.used, output_context->in.data, output_context->in.used); ctx->buffer.free -= output_context->in.used; ctx->buffer.used += output_context->in.used; } output_context->out.size = PHP_ZLIB_BUFFER_SIZE_GUESS(output_context->in.used); output_context->out.data = emalloc(output_context->out.size); output_context->out.free = 1; output_context->out.used = 0; ctx->Z.avail_in = ctx->buffer.used; ctx->Z.next_in = (Bytef *) ctx->buffer.data; ctx->Z.avail_out = output_context->out.size; ctx->Z.next_out = (Bytef *) output_context->out.data; if (output_context->op & PHP_OUTPUT_HANDLER_FINAL) { flags = Z_FINISH; } else if (output_context->op & PHP_OUTPUT_HANDLER_FLUSH) { flags = Z_FULL_FLUSH; } switch (deflate(&ctx->Z, flags)) { case Z_OK: if (flags == Z_FINISH) { deflateEnd(&ctx->Z); return FAILURE; } case Z_STREAM_END: if (ctx->Z.avail_in) { memmove(ctx->buffer.data, ctx->buffer.data + ctx->buffer.used - ctx->Z.avail_in, ctx->Z.avail_in); } ctx->buffer.free += ctx->buffer.used - ctx->Z.avail_in; ctx->buffer.used = ctx->Z.avail_in; output_context->out.used = output_context->out.size - ctx->Z.avail_out; break; default: deflateEnd(&ctx->Z); return FAILURE; } if (output_context->op & PHP_OUTPUT_HANDLER_FINAL) { deflateEnd(&ctx->Z); } } return SUCCESS; }
@@ -581,7 +581,7 @@ static PHP_FUNCTION(gzopen) php_stream *stream; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ps|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { return; } @@ -609,7 +609,7 @@ static PHP_FUNCTION(readgzfile) int size; long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &filename, &filename_len, &use_include_path) == FAILURE) { return; }
CWE-254
null
null
12,341
SSH_PACKET_CALLBACK(ssh_packet_disconnect_callback){ int rc; uint32_t code = 0; char *error = NULL; ssh_string error_s; (void)user; (void)type; rc = buffer_get_u32(packet, &code); if (rc != 0) { code = ntohl(code); } error_s = buffer_get_ssh_string(packet); if (error_s != NULL) { error = ssh_string_to_char(error_s); ssh_string_free(error_s); } SSH_LOG(SSH_LOG_PACKET, "Received SSH_MSG_DISCONNECT %d:%s", code, error != NULL ? error : "no error"); ssh_set_error(session, SSH_FATAL, "Received SSH_MSG_DISCONNECT: %d:%s", code, error != NULL ? error : "no error"); SAFE_FREE(error); ssh_socket_close(session->socket); session->alive = 0; session->session_state = SSH_SESSION_STATE_ERROR; /* TODO: handle a graceful disconnect */ return SSH_PACKET_USED; }
DoS
0
SSH_PACKET_CALLBACK(ssh_packet_disconnect_callback){ int rc; uint32_t code = 0; char *error = NULL; ssh_string error_s; (void)user; (void)type; rc = buffer_get_u32(packet, &code); if (rc != 0) { code = ntohl(code); } error_s = buffer_get_ssh_string(packet); if (error_s != NULL) { error = ssh_string_to_char(error_s); ssh_string_free(error_s); } SSH_LOG(SSH_LOG_PACKET, "Received SSH_MSG_DISCONNECT %d:%s", code, error != NULL ? error : "no error"); ssh_set_error(session, SSH_FATAL, "Received SSH_MSG_DISCONNECT: %d:%s", code, error != NULL ? error : "no error"); SAFE_FREE(error); ssh_socket_close(session->socket); session->alive = 0; session->session_state = SSH_SESSION_STATE_ERROR; /* TODO: handle a graceful disconnect */ return SSH_PACKET_USED; }
@@ -94,7 +94,7 @@ SSH_PACKET_CALLBACK(ssh_packet_dh_reply){ (void)type; (void)user; SSH_LOG(SSH_LOG_PROTOCOL,"Received SSH_KEXDH_REPLY"); - if(session->session_state!= SSH_SESSION_STATE_DH && + if (session->session_state != SSH_SESSION_STATE_DH || session->dh_handshake_state != DH_STATE_INIT_SENT){ ssh_set_error(session,SSH_FATAL,"ssh_packet_dh_reply called in wrong state : %d:%d", session->session_state,session->dh_handshake_state); @@ -135,12 +135,16 @@ SSH_PACKET_CALLBACK(ssh_packet_newkeys){ (void)user; (void)type; SSH_LOG(SSH_LOG_PROTOCOL, "Received SSH_MSG_NEWKEYS"); - if(session->session_state!= SSH_SESSION_STATE_DH && - session->dh_handshake_state != DH_STATE_NEWKEYS_SENT){ - ssh_set_error(session,SSH_FATAL,"ssh_packet_newkeys called in wrong state : %d:%d", - session->session_state,session->dh_handshake_state); - goto error; + + if (session->session_state != SSH_SESSION_STATE_DH || + session->dh_handshake_state != DH_STATE_NEWKEYS_SENT) { + ssh_set_error(session, + SSH_FATAL, + "ssh_packet_newkeys called in wrong state : %d:%d", + session->session_state,session->dh_handshake_state); + goto error; } + if(session->server){ /* server things are done in server.c */ session->dh_handshake_state=DH_STATE_FINISHED;
null
null
null
12,342
SSH_PACKET_CALLBACK(ssh_packet_ignore_callback){ (void)session; /* unused */ (void)user; (void)type; (void)packet; SSH_LOG(SSH_LOG_PROTOCOL,"Received %s packet",type==SSH2_MSG_IGNORE ? "SSH_MSG_IGNORE" : "SSH_MSG_DEBUG"); /* TODO: handle a graceful disconnect */ return SSH_PACKET_USED; }
DoS
0
SSH_PACKET_CALLBACK(ssh_packet_ignore_callback){ (void)session; /* unused */ (void)user; (void)type; (void)packet; SSH_LOG(SSH_LOG_PROTOCOL,"Received %s packet",type==SSH2_MSG_IGNORE ? "SSH_MSG_IGNORE" : "SSH_MSG_DEBUG"); /* TODO: handle a graceful disconnect */ return SSH_PACKET_USED; }
@@ -94,7 +94,7 @@ SSH_PACKET_CALLBACK(ssh_packet_dh_reply){ (void)type; (void)user; SSH_LOG(SSH_LOG_PROTOCOL,"Received SSH_KEXDH_REPLY"); - if(session->session_state!= SSH_SESSION_STATE_DH && + if (session->session_state != SSH_SESSION_STATE_DH || session->dh_handshake_state != DH_STATE_INIT_SENT){ ssh_set_error(session,SSH_FATAL,"ssh_packet_dh_reply called in wrong state : %d:%d", session->session_state,session->dh_handshake_state); @@ -135,12 +135,16 @@ SSH_PACKET_CALLBACK(ssh_packet_newkeys){ (void)user; (void)type; SSH_LOG(SSH_LOG_PROTOCOL, "Received SSH_MSG_NEWKEYS"); - if(session->session_state!= SSH_SESSION_STATE_DH && - session->dh_handshake_state != DH_STATE_NEWKEYS_SENT){ - ssh_set_error(session,SSH_FATAL,"ssh_packet_newkeys called in wrong state : %d:%d", - session->session_state,session->dh_handshake_state); - goto error; + + if (session->session_state != SSH_SESSION_STATE_DH || + session->dh_handshake_state != DH_STATE_NEWKEYS_SENT) { + ssh_set_error(session, + SSH_FATAL, + "ssh_packet_newkeys called in wrong state : %d:%d", + session->session_state,session->dh_handshake_state); + goto error; } + if(session->server){ /* server things are done in server.c */ session->dh_handshake_state=DH_STATE_FINISHED;
null
null
null
12,343
static int server_set_kex(ssh_session session) { struct ssh_kex_struct *server = &session->next_crypto->server_kex; int i, j, rc; const char *wanted; char hostkeys[64] = {0}; enum ssh_keytypes_e keytype; size_t len; ZERO_STRUCTP(server); ssh_get_random(server->cookie, 16, 0); #ifdef HAVE_ECC if (session->srv.ecdsa_key != NULL) { snprintf(hostkeys, sizeof(hostkeys), "%s", session->srv.ecdsa_key->type_c); } #endif if (session->srv.dsa_key != NULL) { len = strlen(hostkeys); keytype = ssh_key_type(session->srv.dsa_key); snprintf(hostkeys + len, sizeof(hostkeys) - len, ",%s", ssh_key_type_to_char(keytype)); } if (session->srv.rsa_key != NULL) { len = strlen(hostkeys); keytype = ssh_key_type(session->srv.rsa_key); snprintf(hostkeys + len, sizeof(hostkeys) - len, ",%s", ssh_key_type_to_char(keytype)); } if (strlen(hostkeys) == 0) { return -1; } rc = ssh_options_set_algo(session, SSH_HOSTKEYS, hostkeys[0] == ',' ? hostkeys + 1 : hostkeys); if (rc < 0) { return -1; } for (i = 0; i < 10; i++) { if ((wanted = session->opts.wanted_methods[i]) == NULL) { wanted = ssh_kex_get_supported_method(i); } server->methods[i] = strdup(wanted); if (server->methods[i] == NULL) { for (j = 0; j < i; j++) { SAFE_FREE(server->methods[j]); } return -1; } } return 0; }
DoS
0
static int server_set_kex(ssh_session session) { struct ssh_kex_struct *server = &session->next_crypto->server_kex; int i, j, rc; const char *wanted; char hostkeys[64] = {0}; enum ssh_keytypes_e keytype; size_t len; ZERO_STRUCTP(server); ssh_get_random(server->cookie, 16, 0); #ifdef HAVE_ECC if (session->srv.ecdsa_key != NULL) { snprintf(hostkeys, sizeof(hostkeys), "%s", session->srv.ecdsa_key->type_c); } #endif if (session->srv.dsa_key != NULL) { len = strlen(hostkeys); keytype = ssh_key_type(session->srv.dsa_key); snprintf(hostkeys + len, sizeof(hostkeys) - len, ",%s", ssh_key_type_to_char(keytype)); } if (session->srv.rsa_key != NULL) { len = strlen(hostkeys); keytype = ssh_key_type(session->srv.rsa_key); snprintf(hostkeys + len, sizeof(hostkeys) - len, ",%s", ssh_key_type_to_char(keytype)); } if (strlen(hostkeys) == 0) { return -1; } rc = ssh_options_set_algo(session, SSH_HOSTKEYS, hostkeys[0] == ',' ? hostkeys + 1 : hostkeys); if (rc < 0) { return -1; } for (i = 0; i < 10; i++) { if ((wanted = session->opts.wanted_methods[i]) == NULL) { wanted = ssh_kex_get_supported_method(i); } server->methods[i] = strdup(wanted); if (server->methods[i] == NULL) { for (j = 0; j < i; j++) { SAFE_FREE(server->methods[j]); } return -1; } } return 0; }
@@ -165,7 +165,7 @@ static int ssh_server_kexdh_init(ssh_session session, ssh_buffer packet){ } SSH_PACKET_CALLBACK(ssh_packet_kexdh_init){ - int rc; + int rc = SSH_ERROR; (void)type; (void)user; @@ -193,9 +193,11 @@ SSH_PACKET_CALLBACK(ssh_packet_kexdh_init){ ssh_set_error(session,SSH_FATAL,"Wrong kex type in ssh_packet_kexdh_init"); rc = SSH_ERROR; } - if (rc == SSH_ERROR) + +error: + if (rc == SSH_ERROR) { session->session_state = SSH_SESSION_STATE_ERROR; - error: + } return SSH_PACKET_USED; }
null
null
null
12,344
static int ssh_server_kexdh_init(ssh_session session, ssh_buffer packet){ ssh_string e; e = buffer_get_ssh_string(packet); if (e == NULL) { ssh_set_error(session, SSH_FATAL, "No e number in client request"); return -1; } if (dh_import_e(session, e) < 0) { ssh_set_error(session, SSH_FATAL, "Cannot import e number"); session->session_state=SSH_SESSION_STATE_ERROR; } else { session->dh_handshake_state=DH_STATE_INIT_SENT; dh_handshake_server(session); } ssh_string_free(e); return SSH_OK; }
DoS
0
static int ssh_server_kexdh_init(ssh_session session, ssh_buffer packet){ ssh_string e; e = buffer_get_ssh_string(packet); if (e == NULL) { ssh_set_error(session, SSH_FATAL, "No e number in client request"); return -1; } if (dh_import_e(session, e) < 0) { ssh_set_error(session, SSH_FATAL, "Cannot import e number"); session->session_state=SSH_SESSION_STATE_ERROR; } else { session->dh_handshake_state=DH_STATE_INIT_SENT; dh_handshake_server(session); } ssh_string_free(e); return SSH_OK; }
@@ -165,7 +165,7 @@ static int ssh_server_kexdh_init(ssh_session session, ssh_buffer packet){ } SSH_PACKET_CALLBACK(ssh_packet_kexdh_init){ - int rc; + int rc = SSH_ERROR; (void)type; (void)user; @@ -193,9 +193,11 @@ SSH_PACKET_CALLBACK(ssh_packet_kexdh_init){ ssh_set_error(session,SSH_FATAL,"Wrong kex type in ssh_packet_kexdh_init"); rc = SSH_ERROR; } - if (rc == SSH_ERROR) + +error: + if (rc == SSH_ERROR) { session->session_state = SSH_SESSION_STATE_ERROR; - error: + } return SSH_PACKET_USED; }
null
null
null
12,345
void ERR_load_ASN1_strings(void) { #ifndef OPENSSL_NO_ERR if (ERR_func_error_string(ASN1_str_functs[0].error) == NULL) { ERR_load_strings(0, ASN1_str_functs); ERR_load_strings(0, ASN1_str_reasons); } #endif }
DoS
0
void ERR_load_ASN1_strings(void) { #ifndef OPENSSL_NO_ERR if (ERR_func_error_string(ASN1_str_functs[0].error) == NULL) { ERR_load_strings(0, ASN1_str_functs); ERR_load_strings(0, ASN1_str_reasons); } #endif }
@@ -1,6 +1,6 @@ /* crypto/asn1/asn1_err.c */ /* ==================================================================== - * Copyright (c) 1999-2014 The OpenSSL Project. All rights reserved. + * Copyright (c) 1999-2018 The OpenSSL Project. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -279,6 +279,7 @@ static ERR_STRING_DATA ASN1_str_reasons[] = { {ERR_REASON(ASN1_R_MSTRING_NOT_UNIVERSAL), "mstring not universal"}, {ERR_REASON(ASN1_R_MSTRING_WRONG_TAG), "mstring wrong tag"}, {ERR_REASON(ASN1_R_NESTED_ASN1_STRING), "nested asn1 string"}, + {ERR_REASON(ASN1_R_NESTED_TOO_DEEP), "nested too deep"}, {ERR_REASON(ASN1_R_NON_HEX_CHARACTERS), "non hex characters"}, {ERR_REASON(ASN1_R_NOT_ASCII_FORMAT), "not ascii format"}, {ERR_REASON(ASN1_R_NOT_ENOUGH_DATA), "not enough data"},
CWE-400
null
null
12,346
int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e_value, BN_GENCB *cb) { if (rsa->meth->rsa_keygen) return rsa->meth->rsa_keygen(rsa, bits, e_value, cb); return rsa_builtin_keygen(rsa, bits, e_value, cb); }
null
0
int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e_value, BN_GENCB *cb) { if (rsa->meth->rsa_keygen) return rsa->meth->rsa_keygen(rsa, bits, e_value, cb); return rsa_builtin_keygen(rsa, bits, e_value, cb); }
@@ -89,6 +89,8 @@ static int rsa_builtin_keygen(RSA *rsa, int bits, BIGNUM *e_value, if (BN_copy(rsa->e, e_value) == NULL) goto err; + BN_set_flags(rsa->p, BN_FLG_CONSTTIME); + BN_set_flags(rsa->q, BN_FLG_CONSTTIME); BN_set_flags(r2, BN_FLG_CONSTTIME); /* generate p and q */ for (;;) {
CWE-327
null
null
12,347
EC_PRE_COMP *EC_ec_pre_comp_dup(EC_PRE_COMP *pre) { int i; if (pre != NULL) CRYPTO_atomic_add(&pre->references, 1, &i, pre->lock); return pre; }
null
0
EC_PRE_COMP *EC_ec_pre_comp_dup(EC_PRE_COMP *pre) { int i; if (pre != NULL) CRYPTO_atomic_add(&pre->references, 1, &i, pre->lock); return pre; }
@@ -177,8 +177,8 @@ static int ec_mul_consttime(const EC_GROUP *group, EC_POINT *r, */ cardinality_bits = BN_num_bits(cardinality); group_top = bn_get_top(cardinality); - if ((bn_wexpand(k, group_top + 1) == NULL) - || (bn_wexpand(lambda, group_top + 1) == NULL)) + if ((bn_wexpand(k, group_top + 2) == NULL) + || (bn_wexpand(lambda, group_top + 2) == NULL)) { goto err; if (!BN_copy(k, scalar)) @@ -205,7 +205,7 @@ static int ec_mul_consttime(const EC_GROUP *group, EC_POINT *r, * k := scalar + 2*cardinality */ kbit = BN_is_bit_set(lambda, cardinality_bits); - BN_consttime_swap(kbit, k, lambda, group_top + 1); + BN_consttime_swap(kbit, k, lambda, group_top + 2); group_top = bn_get_top(group->field); if ((bn_wexpand(s->X, group_top) == NULL)
CWE-320
null
null
12,348
static EC_PRE_COMP *ec_pre_comp_new(const EC_GROUP *group) { EC_PRE_COMP *ret = NULL; if (!group) return NULL; ret = OPENSSL_zalloc(sizeof(*ret)); if (ret == NULL) { ECerr(EC_F_EC_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE); return ret; } ret->group = group; ret->blocksize = 8; /* default */ ret->w = 4; /* default */ ret->references = 1; ret->lock = CRYPTO_THREAD_lock_new(); if (ret->lock == NULL) { ECerr(EC_F_EC_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE); OPENSSL_free(ret); return NULL; } return ret; }
null
0
static EC_PRE_COMP *ec_pre_comp_new(const EC_GROUP *group) { EC_PRE_COMP *ret = NULL; if (!group) return NULL; ret = OPENSSL_zalloc(sizeof(*ret)); if (ret == NULL) { ECerr(EC_F_EC_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE); return ret; } ret->group = group; ret->blocksize = 8; /* default */ ret->w = 4; /* default */ ret->references = 1; ret->lock = CRYPTO_THREAD_lock_new(); if (ret->lock == NULL) { ECerr(EC_F_EC_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE); OPENSSL_free(ret); return NULL; } return ret; }
@@ -177,8 +177,8 @@ static int ec_mul_consttime(const EC_GROUP *group, EC_POINT *r, */ cardinality_bits = BN_num_bits(cardinality); group_top = bn_get_top(cardinality); - if ((bn_wexpand(k, group_top + 1) == NULL) - || (bn_wexpand(lambda, group_top + 1) == NULL)) + if ((bn_wexpand(k, group_top + 2) == NULL) + || (bn_wexpand(lambda, group_top + 2) == NULL)) { goto err; if (!BN_copy(k, scalar)) @@ -205,7 +205,7 @@ static int ec_mul_consttime(const EC_GROUP *group, EC_POINT *r, * k := scalar + 2*cardinality */ kbit = BN_is_bit_set(lambda, cardinality_bits); - BN_consttime_swap(kbit, k, lambda, group_top + 1); + BN_consttime_swap(kbit, k, lambda, group_top + 2); group_top = bn_get_top(group->field); if ((bn_wexpand(s->X, group_top) == NULL)
CWE-320
null
null
12,349
int ec_wNAF_have_precompute_mult(const EC_GROUP *group) { return HAVEPRECOMP(group, ec); }
null
0
int ec_wNAF_have_precompute_mult(const EC_GROUP *group) { return HAVEPRECOMP(group, ec); }
@@ -177,8 +177,8 @@ static int ec_mul_consttime(const EC_GROUP *group, EC_POINT *r, */ cardinality_bits = BN_num_bits(cardinality); group_top = bn_get_top(cardinality); - if ((bn_wexpand(k, group_top + 1) == NULL) - || (bn_wexpand(lambda, group_top + 1) == NULL)) + if ((bn_wexpand(k, group_top + 2) == NULL) + || (bn_wexpand(lambda, group_top + 2) == NULL)) { goto err; if (!BN_copy(k, scalar)) @@ -205,7 +205,7 @@ static int ec_mul_consttime(const EC_GROUP *group, EC_POINT *r, * k := scalar + 2*cardinality */ kbit = BN_is_bit_set(lambda, cardinality_bits); - BN_consttime_swap(kbit, k, lambda, group_top + 1); + BN_consttime_swap(kbit, k, lambda, group_top + 2); group_top = bn_get_top(group->field); if ((bn_wexpand(s->X, group_top) == NULL)
CWE-320
null
null
12,350
int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx) { BN_CTX *new_ctx = NULL; const EC_POINT *generator = NULL; EC_POINT *tmp = NULL; size_t totalnum; size_t blocksize = 0, numblocks = 0; /* for wNAF splitting */ size_t pre_points_per_block = 0; size_t i, j; int k; int r_is_inverted = 0; int r_is_at_infinity = 1; size_t *wsize = NULL; /* individual window sizes */ signed char **wNAF = NULL; /* individual wNAFs */ size_t *wNAF_len = NULL; size_t max_len = 0; size_t num_val; EC_POINT **val = NULL; /* precomputation */ EC_POINT **v; EC_POINT ***val_sub = NULL; /* pointers to sub-arrays of 'val' or * 'pre_comp->points' */ const EC_PRE_COMP *pre_comp = NULL; int num_scalar = 0; /* flag: will be set to 1 if 'scalar' must be * treated like other scalars, i.e. * precomputation is not available */ int ret = 0; if (!ec_point_is_compat(r, group)) { ECerr(EC_F_EC_WNAF_MUL, EC_R_INCOMPATIBLE_OBJECTS); return 0; } if ((scalar == NULL) && (num == 0)) { return EC_POINT_set_to_infinity(group, r); } if (!BN_is_zero(group->order) && !BN_is_zero(group->cofactor)) { /*- * Handle the common cases where the scalar is secret, enforcing a constant * time scalar multiplication algorithm. */ if ((scalar != NULL) && (num == 0)) { /*- * In this case we want to compute scalar * GeneratorPoint: this * codepath is reached most prominently by (ephemeral) key generation * of EC cryptosystems (i.e. ECDSA keygen and sign setup, ECDH * keygen/first half), where the scalar is always secret. This is why * we ignore if BN_FLG_CONSTTIME is actually set and we always call the * constant time version. */ return ec_mul_consttime(group, r, scalar, NULL, ctx); } if ((scalar == NULL) && (num == 1)) { /*- * In this case we want to compute scalar * GenericPoint: this codepath * is reached most prominently by the second half of ECDH, where the * secret scalar is multiplied by the peer's public point. To protect * the secret scalar, we ignore if BN_FLG_CONSTTIME is actually set and * we always call the constant time version. */ return ec_mul_consttime(group, r, scalars[0], points[0], ctx); } } for (i = 0; i < num; i++) { if (!ec_point_is_compat(points[i], group)) { ECerr(EC_F_EC_WNAF_MUL, EC_R_INCOMPATIBLE_OBJECTS); return 0; } } if (ctx == NULL) { ctx = new_ctx = BN_CTX_new(); if (ctx == NULL) goto err; } if (scalar != NULL) { generator = EC_GROUP_get0_generator(group); if (generator == NULL) { ECerr(EC_F_EC_WNAF_MUL, EC_R_UNDEFINED_GENERATOR); goto err; } /* look if we can use precomputed multiples of generator */ pre_comp = group->pre_comp.ec; if (pre_comp && pre_comp->numblocks && (EC_POINT_cmp(group, generator, pre_comp->points[0], ctx) == 0)) { blocksize = pre_comp->blocksize; /* * determine maximum number of blocks that wNAF splitting may * yield (NB: maximum wNAF length is bit length plus one) */ numblocks = (BN_num_bits(scalar) / blocksize) + 1; /* * we cannot use more blocks than we have precomputation for */ if (numblocks > pre_comp->numblocks) numblocks = pre_comp->numblocks; pre_points_per_block = (size_t)1 << (pre_comp->w - 1); /* check that pre_comp looks sane */ if (pre_comp->num != (pre_comp->numblocks * pre_points_per_block)) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); goto err; } } else { /* can't use precomputation */ pre_comp = NULL; numblocks = 1; num_scalar = 1; /* treat 'scalar' like 'num'-th element of * 'scalars' */ } } totalnum = num + numblocks; wsize = OPENSSL_malloc(totalnum * sizeof(wsize[0])); wNAF_len = OPENSSL_malloc(totalnum * sizeof(wNAF_len[0])); /* include space for pivot */ wNAF = OPENSSL_malloc((totalnum + 1) * sizeof(wNAF[0])); val_sub = OPENSSL_malloc(totalnum * sizeof(val_sub[0])); /* Ensure wNAF is initialised in case we end up going to err */ if (wNAF != NULL) wNAF[0] = NULL; /* preliminary pivot */ if (wsize == NULL || wNAF_len == NULL || wNAF == NULL || val_sub == NULL) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE); goto err; } /* * num_val will be the total number of temporarily precomputed points */ num_val = 0; for (i = 0; i < num + num_scalar; i++) { size_t bits; bits = i < num ? BN_num_bits(scalars[i]) : BN_num_bits(scalar); wsize[i] = EC_window_bits_for_scalar_size(bits); num_val += (size_t)1 << (wsize[i] - 1); wNAF[i + 1] = NULL; /* make sure we always have a pivot */ wNAF[i] = bn_compute_wNAF((i < num ? scalars[i] : scalar), wsize[i], &wNAF_len[i]); if (wNAF[i] == NULL) goto err; if (wNAF_len[i] > max_len) max_len = wNAF_len[i]; } if (numblocks) { /* we go here iff scalar != NULL */ if (pre_comp == NULL) { if (num_scalar != 1) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); goto err; } /* we have already generated a wNAF for 'scalar' */ } else { signed char *tmp_wNAF = NULL; size_t tmp_len = 0; if (num_scalar != 0) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); goto err; } /* * use the window size for which we have precomputation */ wsize[num] = pre_comp->w; tmp_wNAF = bn_compute_wNAF(scalar, wsize[num], &tmp_len); if (!tmp_wNAF) goto err; if (tmp_len <= max_len) { /* * One of the other wNAFs is at least as long as the wNAF * belonging to the generator, so wNAF splitting will not buy * us anything. */ numblocks = 1; totalnum = num + 1; /* don't use wNAF splitting */ wNAF[num] = tmp_wNAF; wNAF[num + 1] = NULL; wNAF_len[num] = tmp_len; /* * pre_comp->points starts with the points that we need here: */ val_sub[num] = pre_comp->points; } else { /* * don't include tmp_wNAF directly into wNAF array - use wNAF * splitting and include the blocks */ signed char *pp; EC_POINT **tmp_points; if (tmp_len < numblocks * blocksize) { /* * possibly we can do with fewer blocks than estimated */ numblocks = (tmp_len + blocksize - 1) / blocksize; if (numblocks > pre_comp->numblocks) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); OPENSSL_free(tmp_wNAF); goto err; } totalnum = num + numblocks; } /* split wNAF in 'numblocks' parts */ pp = tmp_wNAF; tmp_points = pre_comp->points; for (i = num; i < totalnum; i++) { if (i < totalnum - 1) { wNAF_len[i] = blocksize; if (tmp_len < blocksize) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); OPENSSL_free(tmp_wNAF); goto err; } tmp_len -= blocksize; } else /* * last block gets whatever is left (this could be * more or less than 'blocksize'!) */ wNAF_len[i] = tmp_len; wNAF[i + 1] = NULL; wNAF[i] = OPENSSL_malloc(wNAF_len[i]); if (wNAF[i] == NULL) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE); OPENSSL_free(tmp_wNAF); goto err; } memcpy(wNAF[i], pp, wNAF_len[i]); if (wNAF_len[i] > max_len) max_len = wNAF_len[i]; if (*tmp_points == NULL) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); OPENSSL_free(tmp_wNAF); goto err; } val_sub[i] = tmp_points; tmp_points += pre_points_per_block; pp += blocksize; } OPENSSL_free(tmp_wNAF); } } } /* * All points we precompute now go into a single array 'val'. * 'val_sub[i]' is a pointer to the subarray for the i-th point, or to a * subarray of 'pre_comp->points' if we already have precomputation. */ val = OPENSSL_malloc((num_val + 1) * sizeof(val[0])); if (val == NULL) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE); goto err; } val[num_val] = NULL; /* pivot element */ /* allocate points for precomputation */ v = val; for (i = 0; i < num + num_scalar; i++) { val_sub[i] = v; for (j = 0; j < ((size_t)1 << (wsize[i] - 1)); j++) { *v = EC_POINT_new(group); if (*v == NULL) goto err; v++; } } if (!(v == val + num_val)) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); goto err; } if ((tmp = EC_POINT_new(group)) == NULL) goto err; /*- * prepare precomputed values: * val_sub[i][0] := points[i] * val_sub[i][1] := 3 * points[i] * val_sub[i][2] := 5 * points[i] * ... */ for (i = 0; i < num + num_scalar; i++) { if (i < num) { if (!EC_POINT_copy(val_sub[i][0], points[i])) goto err; } else { if (!EC_POINT_copy(val_sub[i][0], generator)) goto err; } if (wsize[i] > 1) { if (!EC_POINT_dbl(group, tmp, val_sub[i][0], ctx)) goto err; for (j = 1; j < ((size_t)1 << (wsize[i] - 1)); j++) { if (!EC_POINT_add (group, val_sub[i][j], val_sub[i][j - 1], tmp, ctx)) goto err; } } } if (!EC_POINTs_make_affine(group, num_val, val, ctx)) goto err; r_is_at_infinity = 1; for (k = max_len - 1; k >= 0; k--) { if (!r_is_at_infinity) { if (!EC_POINT_dbl(group, r, r, ctx)) goto err; } for (i = 0; i < totalnum; i++) { if (wNAF_len[i] > (size_t)k) { int digit = wNAF[i][k]; int is_neg; if (digit) { is_neg = digit < 0; if (is_neg) digit = -digit; if (is_neg != r_is_inverted) { if (!r_is_at_infinity) { if (!EC_POINT_invert(group, r, ctx)) goto err; } r_is_inverted = !r_is_inverted; } /* digit > 0 */ if (r_is_at_infinity) { if (!EC_POINT_copy(r, val_sub[i][digit >> 1])) goto err; r_is_at_infinity = 0; } else { if (!EC_POINT_add (group, r, r, val_sub[i][digit >> 1], ctx)) goto err; } } } } } if (r_is_at_infinity) { if (!EC_POINT_set_to_infinity(group, r)) goto err; } else { if (r_is_inverted) if (!EC_POINT_invert(group, r, ctx)) goto err; } ret = 1; err: BN_CTX_free(new_ctx); EC_POINT_free(tmp); OPENSSL_free(wsize); OPENSSL_free(wNAF_len); if (wNAF != NULL) { signed char **w; for (w = wNAF; *w != NULL; w++) OPENSSL_free(*w); OPENSSL_free(wNAF); } if (val != NULL) { for (v = val; *v != NULL; v++) EC_POINT_clear_free(*v); OPENSSL_free(val); } OPENSSL_free(val_sub); return ret; }
null
0
int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx) { BN_CTX *new_ctx = NULL; const EC_POINT *generator = NULL; EC_POINT *tmp = NULL; size_t totalnum; size_t blocksize = 0, numblocks = 0; /* for wNAF splitting */ size_t pre_points_per_block = 0; size_t i, j; int k; int r_is_inverted = 0; int r_is_at_infinity = 1; size_t *wsize = NULL; /* individual window sizes */ signed char **wNAF = NULL; /* individual wNAFs */ size_t *wNAF_len = NULL; size_t max_len = 0; size_t num_val; EC_POINT **val = NULL; /* precomputation */ EC_POINT **v; EC_POINT ***val_sub = NULL; /* pointers to sub-arrays of 'val' or * 'pre_comp->points' */ const EC_PRE_COMP *pre_comp = NULL; int num_scalar = 0; /* flag: will be set to 1 if 'scalar' must be * treated like other scalars, i.e. * precomputation is not available */ int ret = 0; if (!ec_point_is_compat(r, group)) { ECerr(EC_F_EC_WNAF_MUL, EC_R_INCOMPATIBLE_OBJECTS); return 0; } if ((scalar == NULL) && (num == 0)) { return EC_POINT_set_to_infinity(group, r); } if (!BN_is_zero(group->order) && !BN_is_zero(group->cofactor)) { /*- * Handle the common cases where the scalar is secret, enforcing a constant * time scalar multiplication algorithm. */ if ((scalar != NULL) && (num == 0)) { /*- * In this case we want to compute scalar * GeneratorPoint: this * codepath is reached most prominently by (ephemeral) key generation * of EC cryptosystems (i.e. ECDSA keygen and sign setup, ECDH * keygen/first half), where the scalar is always secret. This is why * we ignore if BN_FLG_CONSTTIME is actually set and we always call the * constant time version. */ return ec_mul_consttime(group, r, scalar, NULL, ctx); } if ((scalar == NULL) && (num == 1)) { /*- * In this case we want to compute scalar * GenericPoint: this codepath * is reached most prominently by the second half of ECDH, where the * secret scalar is multiplied by the peer's public point. To protect * the secret scalar, we ignore if BN_FLG_CONSTTIME is actually set and * we always call the constant time version. */ return ec_mul_consttime(group, r, scalars[0], points[0], ctx); } } for (i = 0; i < num; i++) { if (!ec_point_is_compat(points[i], group)) { ECerr(EC_F_EC_WNAF_MUL, EC_R_INCOMPATIBLE_OBJECTS); return 0; } } if (ctx == NULL) { ctx = new_ctx = BN_CTX_new(); if (ctx == NULL) goto err; } if (scalar != NULL) { generator = EC_GROUP_get0_generator(group); if (generator == NULL) { ECerr(EC_F_EC_WNAF_MUL, EC_R_UNDEFINED_GENERATOR); goto err; } /* look if we can use precomputed multiples of generator */ pre_comp = group->pre_comp.ec; if (pre_comp && pre_comp->numblocks && (EC_POINT_cmp(group, generator, pre_comp->points[0], ctx) == 0)) { blocksize = pre_comp->blocksize; /* * determine maximum number of blocks that wNAF splitting may * yield (NB: maximum wNAF length is bit length plus one) */ numblocks = (BN_num_bits(scalar) / blocksize) + 1; /* * we cannot use more blocks than we have precomputation for */ if (numblocks > pre_comp->numblocks) numblocks = pre_comp->numblocks; pre_points_per_block = (size_t)1 << (pre_comp->w - 1); /* check that pre_comp looks sane */ if (pre_comp->num != (pre_comp->numblocks * pre_points_per_block)) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); goto err; } } else { /* can't use precomputation */ pre_comp = NULL; numblocks = 1; num_scalar = 1; /* treat 'scalar' like 'num'-th element of * 'scalars' */ } } totalnum = num + numblocks; wsize = OPENSSL_malloc(totalnum * sizeof(wsize[0])); wNAF_len = OPENSSL_malloc(totalnum * sizeof(wNAF_len[0])); /* include space for pivot */ wNAF = OPENSSL_malloc((totalnum + 1) * sizeof(wNAF[0])); val_sub = OPENSSL_malloc(totalnum * sizeof(val_sub[0])); /* Ensure wNAF is initialised in case we end up going to err */ if (wNAF != NULL) wNAF[0] = NULL; /* preliminary pivot */ if (wsize == NULL || wNAF_len == NULL || wNAF == NULL || val_sub == NULL) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE); goto err; } /* * num_val will be the total number of temporarily precomputed points */ num_val = 0; for (i = 0; i < num + num_scalar; i++) { size_t bits; bits = i < num ? BN_num_bits(scalars[i]) : BN_num_bits(scalar); wsize[i] = EC_window_bits_for_scalar_size(bits); num_val += (size_t)1 << (wsize[i] - 1); wNAF[i + 1] = NULL; /* make sure we always have a pivot */ wNAF[i] = bn_compute_wNAF((i < num ? scalars[i] : scalar), wsize[i], &wNAF_len[i]); if (wNAF[i] == NULL) goto err; if (wNAF_len[i] > max_len) max_len = wNAF_len[i]; } if (numblocks) { /* we go here iff scalar != NULL */ if (pre_comp == NULL) { if (num_scalar != 1) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); goto err; } /* we have already generated a wNAF for 'scalar' */ } else { signed char *tmp_wNAF = NULL; size_t tmp_len = 0; if (num_scalar != 0) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); goto err; } /* * use the window size for which we have precomputation */ wsize[num] = pre_comp->w; tmp_wNAF = bn_compute_wNAF(scalar, wsize[num], &tmp_len); if (!tmp_wNAF) goto err; if (tmp_len <= max_len) { /* * One of the other wNAFs is at least as long as the wNAF * belonging to the generator, so wNAF splitting will not buy * us anything. */ numblocks = 1; totalnum = num + 1; /* don't use wNAF splitting */ wNAF[num] = tmp_wNAF; wNAF[num + 1] = NULL; wNAF_len[num] = tmp_len; /* * pre_comp->points starts with the points that we need here: */ val_sub[num] = pre_comp->points; } else { /* * don't include tmp_wNAF directly into wNAF array - use wNAF * splitting and include the blocks */ signed char *pp; EC_POINT **tmp_points; if (tmp_len < numblocks * blocksize) { /* * possibly we can do with fewer blocks than estimated */ numblocks = (tmp_len + blocksize - 1) / blocksize; if (numblocks > pre_comp->numblocks) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); OPENSSL_free(tmp_wNAF); goto err; } totalnum = num + numblocks; } /* split wNAF in 'numblocks' parts */ pp = tmp_wNAF; tmp_points = pre_comp->points; for (i = num; i < totalnum; i++) { if (i < totalnum - 1) { wNAF_len[i] = blocksize; if (tmp_len < blocksize) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); OPENSSL_free(tmp_wNAF); goto err; } tmp_len -= blocksize; } else /* * last block gets whatever is left (this could be * more or less than 'blocksize'!) */ wNAF_len[i] = tmp_len; wNAF[i + 1] = NULL; wNAF[i] = OPENSSL_malloc(wNAF_len[i]); if (wNAF[i] == NULL) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE); OPENSSL_free(tmp_wNAF); goto err; } memcpy(wNAF[i], pp, wNAF_len[i]); if (wNAF_len[i] > max_len) max_len = wNAF_len[i]; if (*tmp_points == NULL) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); OPENSSL_free(tmp_wNAF); goto err; } val_sub[i] = tmp_points; tmp_points += pre_points_per_block; pp += blocksize; } OPENSSL_free(tmp_wNAF); } } } /* * All points we precompute now go into a single array 'val'. * 'val_sub[i]' is a pointer to the subarray for the i-th point, or to a * subarray of 'pre_comp->points' if we already have precomputation. */ val = OPENSSL_malloc((num_val + 1) * sizeof(val[0])); if (val == NULL) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE); goto err; } val[num_val] = NULL; /* pivot element */ /* allocate points for precomputation */ v = val; for (i = 0; i < num + num_scalar; i++) { val_sub[i] = v; for (j = 0; j < ((size_t)1 << (wsize[i] - 1)); j++) { *v = EC_POINT_new(group); if (*v == NULL) goto err; v++; } } if (!(v == val + num_val)) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); goto err; } if ((tmp = EC_POINT_new(group)) == NULL) goto err; /*- * prepare precomputed values: * val_sub[i][0] := points[i] * val_sub[i][1] := 3 * points[i] * val_sub[i][2] := 5 * points[i] * ... */ for (i = 0; i < num + num_scalar; i++) { if (i < num) { if (!EC_POINT_copy(val_sub[i][0], points[i])) goto err; } else { if (!EC_POINT_copy(val_sub[i][0], generator)) goto err; } if (wsize[i] > 1) { if (!EC_POINT_dbl(group, tmp, val_sub[i][0], ctx)) goto err; for (j = 1; j < ((size_t)1 << (wsize[i] - 1)); j++) { if (!EC_POINT_add (group, val_sub[i][j], val_sub[i][j - 1], tmp, ctx)) goto err; } } } if (!EC_POINTs_make_affine(group, num_val, val, ctx)) goto err; r_is_at_infinity = 1; for (k = max_len - 1; k >= 0; k--) { if (!r_is_at_infinity) { if (!EC_POINT_dbl(group, r, r, ctx)) goto err; } for (i = 0; i < totalnum; i++) { if (wNAF_len[i] > (size_t)k) { int digit = wNAF[i][k]; int is_neg; if (digit) { is_neg = digit < 0; if (is_neg) digit = -digit; if (is_neg != r_is_inverted) { if (!r_is_at_infinity) { if (!EC_POINT_invert(group, r, ctx)) goto err; } r_is_inverted = !r_is_inverted; } /* digit > 0 */ if (r_is_at_infinity) { if (!EC_POINT_copy(r, val_sub[i][digit >> 1])) goto err; r_is_at_infinity = 0; } else { if (!EC_POINT_add (group, r, r, val_sub[i][digit >> 1], ctx)) goto err; } } } } } if (r_is_at_infinity) { if (!EC_POINT_set_to_infinity(group, r)) goto err; } else { if (r_is_inverted) if (!EC_POINT_invert(group, r, ctx)) goto err; } ret = 1; err: BN_CTX_free(new_ctx); EC_POINT_free(tmp); OPENSSL_free(wsize); OPENSSL_free(wNAF_len); if (wNAF != NULL) { signed char **w; for (w = wNAF; *w != NULL; w++) OPENSSL_free(*w); OPENSSL_free(wNAF); } if (val != NULL) { for (v = val; *v != NULL; v++) EC_POINT_clear_free(*v); OPENSSL_free(val); } OPENSSL_free(val_sub); return ret; }
@@ -177,8 +177,8 @@ static int ec_mul_consttime(const EC_GROUP *group, EC_POINT *r, */ cardinality_bits = BN_num_bits(cardinality); group_top = bn_get_top(cardinality); - if ((bn_wexpand(k, group_top + 1) == NULL) - || (bn_wexpand(lambda, group_top + 1) == NULL)) + if ((bn_wexpand(k, group_top + 2) == NULL) + || (bn_wexpand(lambda, group_top + 2) == NULL)) { goto err; if (!BN_copy(k, scalar)) @@ -205,7 +205,7 @@ static int ec_mul_consttime(const EC_GROUP *group, EC_POINT *r, * k := scalar + 2*cardinality */ kbit = BN_is_bit_set(lambda, cardinality_bits); - BN_consttime_swap(kbit, k, lambda, group_top + 1); + BN_consttime_swap(kbit, k, lambda, group_top + 2); group_top = bn_get_top(group->field); if ((bn_wexpand(s->X, group_top) == NULL)
CWE-320
null
null
12,351
int ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *ctx) { const EC_POINT *generator; EC_POINT *tmp_point = NULL, *base = NULL, **var; BN_CTX *new_ctx = NULL; const BIGNUM *order; size_t i, bits, w, pre_points_per_block, blocksize, numblocks, num; EC_POINT **points = NULL; EC_PRE_COMP *pre_comp; int ret = 0; /* if there is an old EC_PRE_COMP object, throw it away */ EC_pre_comp_free(group); if ((pre_comp = ec_pre_comp_new(group)) == NULL) return 0; generator = EC_GROUP_get0_generator(group); if (generator == NULL) { ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, EC_R_UNDEFINED_GENERATOR); goto err; } if (ctx == NULL) { ctx = new_ctx = BN_CTX_new(); if (ctx == NULL) goto err; } BN_CTX_start(ctx); order = EC_GROUP_get0_order(group); if (order == NULL) goto err; if (BN_is_zero(order)) { ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, EC_R_UNKNOWN_ORDER); goto err; } bits = BN_num_bits(order); /* * The following parameters mean we precompute (approximately) one point * per bit. TBD: The combination 8, 4 is perfect for 160 bits; for other * bit lengths, other parameter combinations might provide better * efficiency. */ blocksize = 8; w = 4; if (EC_window_bits_for_scalar_size(bits) > w) { /* let's not make the window too small ... */ w = EC_window_bits_for_scalar_size(bits); } numblocks = (bits + blocksize - 1) / blocksize; /* max. number of blocks * to use for wNAF * splitting */ pre_points_per_block = (size_t)1 << (w - 1); num = pre_points_per_block * numblocks; /* number of points to compute * and store */ points = OPENSSL_malloc(sizeof(*points) * (num + 1)); if (points == NULL) { ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, ERR_R_MALLOC_FAILURE); goto err; } var = points; var[num] = NULL; /* pivot */ for (i = 0; i < num; i++) { if ((var[i] = EC_POINT_new(group)) == NULL) { ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, ERR_R_MALLOC_FAILURE); goto err; } } if ((tmp_point = EC_POINT_new(group)) == NULL || (base = EC_POINT_new(group)) == NULL) { ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, ERR_R_MALLOC_FAILURE); goto err; } if (!EC_POINT_copy(base, generator)) goto err; /* do the precomputation */ for (i = 0; i < numblocks; i++) { size_t j; if (!EC_POINT_dbl(group, tmp_point, base, ctx)) goto err; if (!EC_POINT_copy(*var++, base)) goto err; for (j = 1; j < pre_points_per_block; j++, var++) { /* * calculate odd multiples of the current base point */ if (!EC_POINT_add(group, *var, tmp_point, *(var - 1), ctx)) goto err; } if (i < numblocks - 1) { /* * get the next base (multiply current one by 2^blocksize) */ size_t k; if (blocksize <= 2) { ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, ERR_R_INTERNAL_ERROR); goto err; } if (!EC_POINT_dbl(group, base, tmp_point, ctx)) goto err; for (k = 2; k < blocksize; k++) { if (!EC_POINT_dbl(group, base, base, ctx)) goto err; } } } if (!EC_POINTs_make_affine(group, num, points, ctx)) goto err; pre_comp->group = group; pre_comp->blocksize = blocksize; pre_comp->numblocks = numblocks; pre_comp->w = w; pre_comp->points = points; points = NULL; pre_comp->num = num; SETPRECOMP(group, ec, pre_comp); pre_comp = NULL; ret = 1; err: if (ctx != NULL) BN_CTX_end(ctx); BN_CTX_free(new_ctx); EC_ec_pre_comp_free(pre_comp); if (points) { EC_POINT **p; for (p = points; *p != NULL; p++) EC_POINT_free(*p); OPENSSL_free(points); } EC_POINT_free(tmp_point); EC_POINT_free(base); return ret; }
null
0
int ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *ctx) { const EC_POINT *generator; EC_POINT *tmp_point = NULL, *base = NULL, **var; BN_CTX *new_ctx = NULL; const BIGNUM *order; size_t i, bits, w, pre_points_per_block, blocksize, numblocks, num; EC_POINT **points = NULL; EC_PRE_COMP *pre_comp; int ret = 0; /* if there is an old EC_PRE_COMP object, throw it away */ EC_pre_comp_free(group); if ((pre_comp = ec_pre_comp_new(group)) == NULL) return 0; generator = EC_GROUP_get0_generator(group); if (generator == NULL) { ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, EC_R_UNDEFINED_GENERATOR); goto err; } if (ctx == NULL) { ctx = new_ctx = BN_CTX_new(); if (ctx == NULL) goto err; } BN_CTX_start(ctx); order = EC_GROUP_get0_order(group); if (order == NULL) goto err; if (BN_is_zero(order)) { ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, EC_R_UNKNOWN_ORDER); goto err; } bits = BN_num_bits(order); /* * The following parameters mean we precompute (approximately) one point * per bit. TBD: The combination 8, 4 is perfect for 160 bits; for other * bit lengths, other parameter combinations might provide better * efficiency. */ blocksize = 8; w = 4; if (EC_window_bits_for_scalar_size(bits) > w) { /* let's not make the window too small ... */ w = EC_window_bits_for_scalar_size(bits); } numblocks = (bits + blocksize - 1) / blocksize; /* max. number of blocks * to use for wNAF * splitting */ pre_points_per_block = (size_t)1 << (w - 1); num = pre_points_per_block * numblocks; /* number of points to compute * and store */ points = OPENSSL_malloc(sizeof(*points) * (num + 1)); if (points == NULL) { ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, ERR_R_MALLOC_FAILURE); goto err; } var = points; var[num] = NULL; /* pivot */ for (i = 0; i < num; i++) { if ((var[i] = EC_POINT_new(group)) == NULL) { ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, ERR_R_MALLOC_FAILURE); goto err; } } if ((tmp_point = EC_POINT_new(group)) == NULL || (base = EC_POINT_new(group)) == NULL) { ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, ERR_R_MALLOC_FAILURE); goto err; } if (!EC_POINT_copy(base, generator)) goto err; /* do the precomputation */ for (i = 0; i < numblocks; i++) { size_t j; if (!EC_POINT_dbl(group, tmp_point, base, ctx)) goto err; if (!EC_POINT_copy(*var++, base)) goto err; for (j = 1; j < pre_points_per_block; j++, var++) { /* * calculate odd multiples of the current base point */ if (!EC_POINT_add(group, *var, tmp_point, *(var - 1), ctx)) goto err; } if (i < numblocks - 1) { /* * get the next base (multiply current one by 2^blocksize) */ size_t k; if (blocksize <= 2) { ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, ERR_R_INTERNAL_ERROR); goto err; } if (!EC_POINT_dbl(group, base, tmp_point, ctx)) goto err; for (k = 2; k < blocksize; k++) { if (!EC_POINT_dbl(group, base, base, ctx)) goto err; } } } if (!EC_POINTs_make_affine(group, num, points, ctx)) goto err; pre_comp->group = group; pre_comp->blocksize = blocksize; pre_comp->numblocks = numblocks; pre_comp->w = w; pre_comp->points = points; points = NULL; pre_comp->num = num; SETPRECOMP(group, ec, pre_comp); pre_comp = NULL; ret = 1; err: if (ctx != NULL) BN_CTX_end(ctx); BN_CTX_free(new_ctx); EC_ec_pre_comp_free(pre_comp); if (points) { EC_POINT **p; for (p = points; *p != NULL; p++) EC_POINT_free(*p); OPENSSL_free(points); } EC_POINT_free(tmp_point); EC_POINT_free(base); return ret; }
@@ -177,8 +177,8 @@ static int ec_mul_consttime(const EC_GROUP *group, EC_POINT *r, */ cardinality_bits = BN_num_bits(cardinality); group_top = bn_get_top(cardinality); - if ((bn_wexpand(k, group_top + 1) == NULL) - || (bn_wexpand(lambda, group_top + 1) == NULL)) + if ((bn_wexpand(k, group_top + 2) == NULL) + || (bn_wexpand(lambda, group_top + 2) == NULL)) { goto err; if (!BN_copy(k, scalar)) @@ -205,7 +205,7 @@ static int ec_mul_consttime(const EC_GROUP *group, EC_POINT *r, * k := scalar + 2*cardinality */ kbit = BN_is_bit_set(lambda, cardinality_bits); - BN_consttime_swap(kbit, k, lambda, group_top + 1); + BN_consttime_swap(kbit, k, lambda, group_top + 2); group_top = bn_get_top(group->field); if ((bn_wexpand(s->X, group_top) == NULL)
CWE-320
null
null
12,352
EC_PRE_COMP *EC_ec_pre_comp_dup(EC_PRE_COMP *pre) { int i; if (pre != NULL) CRYPTO_UP_REF(&pre->references, &i, pre->lock); return pre; }
null
0
EC_PRE_COMP *EC_ec_pre_comp_dup(EC_PRE_COMP *pre) { int i; if (pre != NULL) CRYPTO_UP_REF(&pre->references, &i, pre->lock); return pre; }
@@ -206,8 +206,8 @@ int ec_scalar_mul_ladder(const EC_GROUP *group, EC_POINT *r, */ cardinality_bits = BN_num_bits(cardinality); group_top = bn_get_top(cardinality); - if ((bn_wexpand(k, group_top + 1) == NULL) - || (bn_wexpand(lambda, group_top + 1) == NULL)) { + if ((bn_wexpand(k, group_top + 2) == NULL) + || (bn_wexpand(lambda, group_top + 2) == NULL)) { ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB); goto err; } @@ -244,7 +244,7 @@ int ec_scalar_mul_ladder(const EC_GROUP *group, EC_POINT *r, * k := scalar + 2*cardinality */ kbit = BN_is_bit_set(lambda, cardinality_bits); - BN_consttime_swap(kbit, k, lambda, group_top + 1); + BN_consttime_swap(kbit, k, lambda, group_top + 2); group_top = bn_get_top(group->field); if ((bn_wexpand(s->X, group_top) == NULL)
CWE-320
null
null
12,353
void EC_ec_pre_comp_free(EC_PRE_COMP *pre) { int i; if (pre == NULL) return; CRYPTO_DOWN_REF(&pre->references, &i, pre->lock); REF_PRINT_COUNT("EC_ec", pre); if (i > 0) return; REF_ASSERT_ISNT(i < 0); if (pre->points != NULL) { EC_POINT **pts; for (pts = pre->points; *pts != NULL; pts++) EC_POINT_free(*pts); OPENSSL_free(pre->points); } CRYPTO_THREAD_lock_free(pre->lock); OPENSSL_free(pre); }
null
0
void EC_ec_pre_comp_free(EC_PRE_COMP *pre) { int i; if (pre == NULL) return; CRYPTO_DOWN_REF(&pre->references, &i, pre->lock); REF_PRINT_COUNT("EC_ec", pre); if (i > 0) return; REF_ASSERT_ISNT(i < 0); if (pre->points != NULL) { EC_POINT **pts; for (pts = pre->points; *pts != NULL; pts++) EC_POINT_free(*pts); OPENSSL_free(pre->points); } CRYPTO_THREAD_lock_free(pre->lock); OPENSSL_free(pre); }
@@ -206,8 +206,8 @@ int ec_scalar_mul_ladder(const EC_GROUP *group, EC_POINT *r, */ cardinality_bits = BN_num_bits(cardinality); group_top = bn_get_top(cardinality); - if ((bn_wexpand(k, group_top + 1) == NULL) - || (bn_wexpand(lambda, group_top + 1) == NULL)) { + if ((bn_wexpand(k, group_top + 2) == NULL) + || (bn_wexpand(lambda, group_top + 2) == NULL)) { ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB); goto err; } @@ -244,7 +244,7 @@ int ec_scalar_mul_ladder(const EC_GROUP *group, EC_POINT *r, * k := scalar + 2*cardinality */ kbit = BN_is_bit_set(lambda, cardinality_bits); - BN_consttime_swap(kbit, k, lambda, group_top + 1); + BN_consttime_swap(kbit, k, lambda, group_top + 2); group_top = bn_get_top(group->field); if ((bn_wexpand(s->X, group_top) == NULL)
CWE-320
null
null
12,354
int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx) { const EC_POINT *generator = NULL; EC_POINT *tmp = NULL; size_t totalnum; size_t blocksize = 0, numblocks = 0; /* for wNAF splitting */ size_t pre_points_per_block = 0; size_t i, j; int k; int r_is_inverted = 0; int r_is_at_infinity = 1; size_t *wsize = NULL; /* individual window sizes */ signed char **wNAF = NULL; /* individual wNAFs */ size_t *wNAF_len = NULL; size_t max_len = 0; size_t num_val; EC_POINT **val = NULL; /* precomputation */ EC_POINT **v; EC_POINT ***val_sub = NULL; /* pointers to sub-arrays of 'val' or * 'pre_comp->points' */ const EC_PRE_COMP *pre_comp = NULL; int num_scalar = 0; /* flag: will be set to 1 if 'scalar' must be * treated like other scalars, i.e. * precomputation is not available */ int ret = 0; if (!BN_is_zero(group->order) && !BN_is_zero(group->cofactor)) { /*- * Handle the common cases where the scalar is secret, enforcing a * scalar multiplication implementation based on a Montgomery ladder, * with various timing attack defenses. */ if ((scalar != NULL) && (num == 0)) { /*- * In this case we want to compute scalar * GeneratorPoint: this * codepath is reached most prominently by (ephemeral) key * generation of EC cryptosystems (i.e. ECDSA keygen and sign setup, * ECDH keygen/first half), where the scalar is always secret. This * is why we ignore if BN_FLG_CONSTTIME is actually set and we * always call the ladder version. */ return ec_scalar_mul_ladder(group, r, scalar, NULL, ctx); } if ((scalar == NULL) && (num == 1)) { /*- * In this case we want to compute scalar * VariablePoint: this * codepath is reached most prominently by the second half of ECDH, * where the secret scalar is multiplied by the peer's public point. * To protect the secret scalar, we ignore if BN_FLG_CONSTTIME is * actually set and we always call the ladder version. */ return ec_scalar_mul_ladder(group, r, scalars[0], points[0], ctx); } } if (scalar != NULL) { generator = EC_GROUP_get0_generator(group); if (generator == NULL) { ECerr(EC_F_EC_WNAF_MUL, EC_R_UNDEFINED_GENERATOR); goto err; } /* look if we can use precomputed multiples of generator */ pre_comp = group->pre_comp.ec; if (pre_comp && pre_comp->numblocks && (EC_POINT_cmp(group, generator, pre_comp->points[0], ctx) == 0)) { blocksize = pre_comp->blocksize; /* * determine maximum number of blocks that wNAF splitting may * yield (NB: maximum wNAF length is bit length plus one) */ numblocks = (BN_num_bits(scalar) / blocksize) + 1; /* * we cannot use more blocks than we have precomputation for */ if (numblocks > pre_comp->numblocks) numblocks = pre_comp->numblocks; pre_points_per_block = (size_t)1 << (pre_comp->w - 1); /* check that pre_comp looks sane */ if (pre_comp->num != (pre_comp->numblocks * pre_points_per_block)) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); goto err; } } else { /* can't use precomputation */ pre_comp = NULL; numblocks = 1; num_scalar = 1; /* treat 'scalar' like 'num'-th element of * 'scalars' */ } } totalnum = num + numblocks; wsize = OPENSSL_malloc(totalnum * sizeof(wsize[0])); wNAF_len = OPENSSL_malloc(totalnum * sizeof(wNAF_len[0])); /* include space for pivot */ wNAF = OPENSSL_malloc((totalnum + 1) * sizeof(wNAF[0])); val_sub = OPENSSL_malloc(totalnum * sizeof(val_sub[0])); /* Ensure wNAF is initialised in case we end up going to err */ if (wNAF != NULL) wNAF[0] = NULL; /* preliminary pivot */ if (wsize == NULL || wNAF_len == NULL || wNAF == NULL || val_sub == NULL) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE); goto err; } /* * num_val will be the total number of temporarily precomputed points */ num_val = 0; for (i = 0; i < num + num_scalar; i++) { size_t bits; bits = i < num ? BN_num_bits(scalars[i]) : BN_num_bits(scalar); wsize[i] = EC_window_bits_for_scalar_size(bits); num_val += (size_t)1 << (wsize[i] - 1); wNAF[i + 1] = NULL; /* make sure we always have a pivot */ wNAF[i] = bn_compute_wNAF((i < num ? scalars[i] : scalar), wsize[i], &wNAF_len[i]); if (wNAF[i] == NULL) goto err; if (wNAF_len[i] > max_len) max_len = wNAF_len[i]; } if (numblocks) { /* we go here iff scalar != NULL */ if (pre_comp == NULL) { if (num_scalar != 1) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); goto err; } /* we have already generated a wNAF for 'scalar' */ } else { signed char *tmp_wNAF = NULL; size_t tmp_len = 0; if (num_scalar != 0) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); goto err; } /* * use the window size for which we have precomputation */ wsize[num] = pre_comp->w; tmp_wNAF = bn_compute_wNAF(scalar, wsize[num], &tmp_len); if (!tmp_wNAF) goto err; if (tmp_len <= max_len) { /* * One of the other wNAFs is at least as long as the wNAF * belonging to the generator, so wNAF splitting will not buy * us anything. */ numblocks = 1; totalnum = num + 1; /* don't use wNAF splitting */ wNAF[num] = tmp_wNAF; wNAF[num + 1] = NULL; wNAF_len[num] = tmp_len; /* * pre_comp->points starts with the points that we need here: */ val_sub[num] = pre_comp->points; } else { /* * don't include tmp_wNAF directly into wNAF array - use wNAF * splitting and include the blocks */ signed char *pp; EC_POINT **tmp_points; if (tmp_len < numblocks * blocksize) { /* * possibly we can do with fewer blocks than estimated */ numblocks = (tmp_len + blocksize - 1) / blocksize; if (numblocks > pre_comp->numblocks) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); OPENSSL_free(tmp_wNAF); goto err; } totalnum = num + numblocks; } /* split wNAF in 'numblocks' parts */ pp = tmp_wNAF; tmp_points = pre_comp->points; for (i = num; i < totalnum; i++) { if (i < totalnum - 1) { wNAF_len[i] = blocksize; if (tmp_len < blocksize) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); OPENSSL_free(tmp_wNAF); goto err; } tmp_len -= blocksize; } else /* * last block gets whatever is left (this could be * more or less than 'blocksize'!) */ wNAF_len[i] = tmp_len; wNAF[i + 1] = NULL; wNAF[i] = OPENSSL_malloc(wNAF_len[i]); if (wNAF[i] == NULL) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE); OPENSSL_free(tmp_wNAF); goto err; } memcpy(wNAF[i], pp, wNAF_len[i]); if (wNAF_len[i] > max_len) max_len = wNAF_len[i]; if (*tmp_points == NULL) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); OPENSSL_free(tmp_wNAF); goto err; } val_sub[i] = tmp_points; tmp_points += pre_points_per_block; pp += blocksize; } OPENSSL_free(tmp_wNAF); } } } /* * All points we precompute now go into a single array 'val'. * 'val_sub[i]' is a pointer to the subarray for the i-th point, or to a * subarray of 'pre_comp->points' if we already have precomputation. */ val = OPENSSL_malloc((num_val + 1) * sizeof(val[0])); if (val == NULL) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE); goto err; } val[num_val] = NULL; /* pivot element */ /* allocate points for precomputation */ v = val; for (i = 0; i < num + num_scalar; i++) { val_sub[i] = v; for (j = 0; j < ((size_t)1 << (wsize[i] - 1)); j++) { *v = EC_POINT_new(group); if (*v == NULL) goto err; v++; } } if (!(v == val + num_val)) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); goto err; } if ((tmp = EC_POINT_new(group)) == NULL) goto err; /*- * prepare precomputed values: * val_sub[i][0] := points[i] * val_sub[i][1] := 3 * points[i] * val_sub[i][2] := 5 * points[i] * ... */ for (i = 0; i < num + num_scalar; i++) { if (i < num) { if (!EC_POINT_copy(val_sub[i][0], points[i])) goto err; } else { if (!EC_POINT_copy(val_sub[i][0], generator)) goto err; } if (wsize[i] > 1) { if (!EC_POINT_dbl(group, tmp, val_sub[i][0], ctx)) goto err; for (j = 1; j < ((size_t)1 << (wsize[i] - 1)); j++) { if (!EC_POINT_add (group, val_sub[i][j], val_sub[i][j - 1], tmp, ctx)) goto err; } } } if (!EC_POINTs_make_affine(group, num_val, val, ctx)) goto err; r_is_at_infinity = 1; for (k = max_len - 1; k >= 0; k--) { if (!r_is_at_infinity) { if (!EC_POINT_dbl(group, r, r, ctx)) goto err; } for (i = 0; i < totalnum; i++) { if (wNAF_len[i] > (size_t)k) { int digit = wNAF[i][k]; int is_neg; if (digit) { is_neg = digit < 0; if (is_neg) digit = -digit; if (is_neg != r_is_inverted) { if (!r_is_at_infinity) { if (!EC_POINT_invert(group, r, ctx)) goto err; } r_is_inverted = !r_is_inverted; } /* digit > 0 */ if (r_is_at_infinity) { if (!EC_POINT_copy(r, val_sub[i][digit >> 1])) goto err; r_is_at_infinity = 0; } else { if (!EC_POINT_add (group, r, r, val_sub[i][digit >> 1], ctx)) goto err; } } } } } if (r_is_at_infinity) { if (!EC_POINT_set_to_infinity(group, r)) goto err; } else { if (r_is_inverted) if (!EC_POINT_invert(group, r, ctx)) goto err; } ret = 1; err: EC_POINT_free(tmp); OPENSSL_free(wsize); OPENSSL_free(wNAF_len); if (wNAF != NULL) { signed char **w; for (w = wNAF; *w != NULL; w++) OPENSSL_free(*w); OPENSSL_free(wNAF); } if (val != NULL) { for (v = val; *v != NULL; v++) EC_POINT_clear_free(*v); OPENSSL_free(val); } OPENSSL_free(val_sub); return ret; }
null
0
int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx) { const EC_POINT *generator = NULL; EC_POINT *tmp = NULL; size_t totalnum; size_t blocksize = 0, numblocks = 0; /* for wNAF splitting */ size_t pre_points_per_block = 0; size_t i, j; int k; int r_is_inverted = 0; int r_is_at_infinity = 1; size_t *wsize = NULL; /* individual window sizes */ signed char **wNAF = NULL; /* individual wNAFs */ size_t *wNAF_len = NULL; size_t max_len = 0; size_t num_val; EC_POINT **val = NULL; /* precomputation */ EC_POINT **v; EC_POINT ***val_sub = NULL; /* pointers to sub-arrays of 'val' or * 'pre_comp->points' */ const EC_PRE_COMP *pre_comp = NULL; int num_scalar = 0; /* flag: will be set to 1 if 'scalar' must be * treated like other scalars, i.e. * precomputation is not available */ int ret = 0; if (!BN_is_zero(group->order) && !BN_is_zero(group->cofactor)) { /*- * Handle the common cases where the scalar is secret, enforcing a * scalar multiplication implementation based on a Montgomery ladder, * with various timing attack defenses. */ if ((scalar != NULL) && (num == 0)) { /*- * In this case we want to compute scalar * GeneratorPoint: this * codepath is reached most prominently by (ephemeral) key * generation of EC cryptosystems (i.e. ECDSA keygen and sign setup, * ECDH keygen/first half), where the scalar is always secret. This * is why we ignore if BN_FLG_CONSTTIME is actually set and we * always call the ladder version. */ return ec_scalar_mul_ladder(group, r, scalar, NULL, ctx); } if ((scalar == NULL) && (num == 1)) { /*- * In this case we want to compute scalar * VariablePoint: this * codepath is reached most prominently by the second half of ECDH, * where the secret scalar is multiplied by the peer's public point. * To protect the secret scalar, we ignore if BN_FLG_CONSTTIME is * actually set and we always call the ladder version. */ return ec_scalar_mul_ladder(group, r, scalars[0], points[0], ctx); } } if (scalar != NULL) { generator = EC_GROUP_get0_generator(group); if (generator == NULL) { ECerr(EC_F_EC_WNAF_MUL, EC_R_UNDEFINED_GENERATOR); goto err; } /* look if we can use precomputed multiples of generator */ pre_comp = group->pre_comp.ec; if (pre_comp && pre_comp->numblocks && (EC_POINT_cmp(group, generator, pre_comp->points[0], ctx) == 0)) { blocksize = pre_comp->blocksize; /* * determine maximum number of blocks that wNAF splitting may * yield (NB: maximum wNAF length is bit length plus one) */ numblocks = (BN_num_bits(scalar) / blocksize) + 1; /* * we cannot use more blocks than we have precomputation for */ if (numblocks > pre_comp->numblocks) numblocks = pre_comp->numblocks; pre_points_per_block = (size_t)1 << (pre_comp->w - 1); /* check that pre_comp looks sane */ if (pre_comp->num != (pre_comp->numblocks * pre_points_per_block)) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); goto err; } } else { /* can't use precomputation */ pre_comp = NULL; numblocks = 1; num_scalar = 1; /* treat 'scalar' like 'num'-th element of * 'scalars' */ } } totalnum = num + numblocks; wsize = OPENSSL_malloc(totalnum * sizeof(wsize[0])); wNAF_len = OPENSSL_malloc(totalnum * sizeof(wNAF_len[0])); /* include space for pivot */ wNAF = OPENSSL_malloc((totalnum + 1) * sizeof(wNAF[0])); val_sub = OPENSSL_malloc(totalnum * sizeof(val_sub[0])); /* Ensure wNAF is initialised in case we end up going to err */ if (wNAF != NULL) wNAF[0] = NULL; /* preliminary pivot */ if (wsize == NULL || wNAF_len == NULL || wNAF == NULL || val_sub == NULL) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE); goto err; } /* * num_val will be the total number of temporarily precomputed points */ num_val = 0; for (i = 0; i < num + num_scalar; i++) { size_t bits; bits = i < num ? BN_num_bits(scalars[i]) : BN_num_bits(scalar); wsize[i] = EC_window_bits_for_scalar_size(bits); num_val += (size_t)1 << (wsize[i] - 1); wNAF[i + 1] = NULL; /* make sure we always have a pivot */ wNAF[i] = bn_compute_wNAF((i < num ? scalars[i] : scalar), wsize[i], &wNAF_len[i]); if (wNAF[i] == NULL) goto err; if (wNAF_len[i] > max_len) max_len = wNAF_len[i]; } if (numblocks) { /* we go here iff scalar != NULL */ if (pre_comp == NULL) { if (num_scalar != 1) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); goto err; } /* we have already generated a wNAF for 'scalar' */ } else { signed char *tmp_wNAF = NULL; size_t tmp_len = 0; if (num_scalar != 0) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); goto err; } /* * use the window size for which we have precomputation */ wsize[num] = pre_comp->w; tmp_wNAF = bn_compute_wNAF(scalar, wsize[num], &tmp_len); if (!tmp_wNAF) goto err; if (tmp_len <= max_len) { /* * One of the other wNAFs is at least as long as the wNAF * belonging to the generator, so wNAF splitting will not buy * us anything. */ numblocks = 1; totalnum = num + 1; /* don't use wNAF splitting */ wNAF[num] = tmp_wNAF; wNAF[num + 1] = NULL; wNAF_len[num] = tmp_len; /* * pre_comp->points starts with the points that we need here: */ val_sub[num] = pre_comp->points; } else { /* * don't include tmp_wNAF directly into wNAF array - use wNAF * splitting and include the blocks */ signed char *pp; EC_POINT **tmp_points; if (tmp_len < numblocks * blocksize) { /* * possibly we can do with fewer blocks than estimated */ numblocks = (tmp_len + blocksize - 1) / blocksize; if (numblocks > pre_comp->numblocks) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); OPENSSL_free(tmp_wNAF); goto err; } totalnum = num + numblocks; } /* split wNAF in 'numblocks' parts */ pp = tmp_wNAF; tmp_points = pre_comp->points; for (i = num; i < totalnum; i++) { if (i < totalnum - 1) { wNAF_len[i] = blocksize; if (tmp_len < blocksize) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); OPENSSL_free(tmp_wNAF); goto err; } tmp_len -= blocksize; } else /* * last block gets whatever is left (this could be * more or less than 'blocksize'!) */ wNAF_len[i] = tmp_len; wNAF[i + 1] = NULL; wNAF[i] = OPENSSL_malloc(wNAF_len[i]); if (wNAF[i] == NULL) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE); OPENSSL_free(tmp_wNAF); goto err; } memcpy(wNAF[i], pp, wNAF_len[i]); if (wNAF_len[i] > max_len) max_len = wNAF_len[i]; if (*tmp_points == NULL) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); OPENSSL_free(tmp_wNAF); goto err; } val_sub[i] = tmp_points; tmp_points += pre_points_per_block; pp += blocksize; } OPENSSL_free(tmp_wNAF); } } } /* * All points we precompute now go into a single array 'val'. * 'val_sub[i]' is a pointer to the subarray for the i-th point, or to a * subarray of 'pre_comp->points' if we already have precomputation. */ val = OPENSSL_malloc((num_val + 1) * sizeof(val[0])); if (val == NULL) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE); goto err; } val[num_val] = NULL; /* pivot element */ /* allocate points for precomputation */ v = val; for (i = 0; i < num + num_scalar; i++) { val_sub[i] = v; for (j = 0; j < ((size_t)1 << (wsize[i] - 1)); j++) { *v = EC_POINT_new(group); if (*v == NULL) goto err; v++; } } if (!(v == val + num_val)) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); goto err; } if ((tmp = EC_POINT_new(group)) == NULL) goto err; /*- * prepare precomputed values: * val_sub[i][0] := points[i] * val_sub[i][1] := 3 * points[i] * val_sub[i][2] := 5 * points[i] * ... */ for (i = 0; i < num + num_scalar; i++) { if (i < num) { if (!EC_POINT_copy(val_sub[i][0], points[i])) goto err; } else { if (!EC_POINT_copy(val_sub[i][0], generator)) goto err; } if (wsize[i] > 1) { if (!EC_POINT_dbl(group, tmp, val_sub[i][0], ctx)) goto err; for (j = 1; j < ((size_t)1 << (wsize[i] - 1)); j++) { if (!EC_POINT_add (group, val_sub[i][j], val_sub[i][j - 1], tmp, ctx)) goto err; } } } if (!EC_POINTs_make_affine(group, num_val, val, ctx)) goto err; r_is_at_infinity = 1; for (k = max_len - 1; k >= 0; k--) { if (!r_is_at_infinity) { if (!EC_POINT_dbl(group, r, r, ctx)) goto err; } for (i = 0; i < totalnum; i++) { if (wNAF_len[i] > (size_t)k) { int digit = wNAF[i][k]; int is_neg; if (digit) { is_neg = digit < 0; if (is_neg) digit = -digit; if (is_neg != r_is_inverted) { if (!r_is_at_infinity) { if (!EC_POINT_invert(group, r, ctx)) goto err; } r_is_inverted = !r_is_inverted; } /* digit > 0 */ if (r_is_at_infinity) { if (!EC_POINT_copy(r, val_sub[i][digit >> 1])) goto err; r_is_at_infinity = 0; } else { if (!EC_POINT_add (group, r, r, val_sub[i][digit >> 1], ctx)) goto err; } } } } } if (r_is_at_infinity) { if (!EC_POINT_set_to_infinity(group, r)) goto err; } else { if (r_is_inverted) if (!EC_POINT_invert(group, r, ctx)) goto err; } ret = 1; err: EC_POINT_free(tmp); OPENSSL_free(wsize); OPENSSL_free(wNAF_len); if (wNAF != NULL) { signed char **w; for (w = wNAF; *w != NULL; w++) OPENSSL_free(*w); OPENSSL_free(wNAF); } if (val != NULL) { for (v = val; *v != NULL; v++) EC_POINT_clear_free(*v); OPENSSL_free(val); } OPENSSL_free(val_sub); return ret; }
@@ -206,8 +206,8 @@ int ec_scalar_mul_ladder(const EC_GROUP *group, EC_POINT *r, */ cardinality_bits = BN_num_bits(cardinality); group_top = bn_get_top(cardinality); - if ((bn_wexpand(k, group_top + 1) == NULL) - || (bn_wexpand(lambda, group_top + 1) == NULL)) { + if ((bn_wexpand(k, group_top + 2) == NULL) + || (bn_wexpand(lambda, group_top + 2) == NULL)) { ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB); goto err; } @@ -244,7 +244,7 @@ int ec_scalar_mul_ladder(const EC_GROUP *group, EC_POINT *r, * k := scalar + 2*cardinality */ kbit = BN_is_bit_set(lambda, cardinality_bits); - BN_consttime_swap(kbit, k, lambda, group_top + 1); + BN_consttime_swap(kbit, k, lambda, group_top + 2); group_top = bn_get_top(group->field); if ((bn_wexpand(s->X, group_top) == NULL)
CWE-320
null
null
12,355
static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) { BIGNUM *kinv = NULL, *r = NULL, *s = NULL; BIGNUM *m, *blind, *blindm, *tmp; BN_CTX *ctx = NULL; int reason = ERR_R_BN_LIB; DSA_SIG *ret = NULL; int noredo = 0; if (dsa->p == NULL || dsa->q == NULL || dsa->g == NULL) { reason = DSA_R_MISSING_PARAMETERS; goto err; } s = BN_new(); if (s == NULL) goto err; ctx = BN_CTX_new(); if (ctx == NULL) goto err; m = BN_CTX_get(ctx); blind = BN_CTX_get(ctx); blindm = BN_CTX_get(ctx); tmp = BN_CTX_get(ctx); if (tmp == NULL) goto err; redo: if ((dsa->kinv == NULL) || (dsa->r == NULL)) { if (!DSA_sign_setup(dsa, ctx, &kinv, &r)) goto err; } else { kinv = dsa->kinv; dsa->kinv = NULL; r = dsa->r; dsa->r = NULL; noredo = 1; } if (dlen > BN_num_bytes(dsa->q)) /* * if the digest length is greater than the size of q use the * BN_num_bits(dsa->q) leftmost bits of the digest, see fips 186-3, * 4.2 */ dlen = BN_num_bytes(dsa->q); if (BN_bin2bn(dgst, dlen, m) == NULL) goto err; /* * The normal signature calculation is: * * s := k^-1 * (m + r * priv_key) mod q * * We will blind this to protect against side channel attacks * * s := blind^-1 * k^-1 * (blind * m + blind * r * priv_key) mod q */ /* Generate a blinding value */ do { if (!BN_rand(blind, BN_num_bits(dsa->q) - 1, -1, 0)) goto err; } while (BN_is_zero(blind)); BN_set_flags(blind, BN_FLG_CONSTTIME); BN_set_flags(blindm, BN_FLG_CONSTTIME); BN_set_flags(tmp, BN_FLG_CONSTTIME); /* tmp := blind * priv_key * r mod q */ if (!BN_mod_mul(tmp, blind, dsa->priv_key, dsa->q, ctx)) goto err; if (!BN_mod_mul(tmp, tmp, r, dsa->q, ctx)) goto err; /* blindm := blind * m mod q */ if (!BN_mod_mul(blindm, blind, m, dsa->q, ctx)) goto err; /* s : = (blind * priv_key * r) + (blind * m) mod q */ if (!BN_mod_add_quick(s, tmp, blindm, dsa->q)) goto err; /* s := s * k^-1 mod q */ if (!BN_mod_mul(s, s, kinv, dsa->q, ctx)) goto err; /* s:= s * blind^-1 mod q */ if (BN_mod_inverse(blind, blind, dsa->q, ctx) == NULL) goto err; if (!BN_mod_mul(s, s, blind, dsa->q, ctx)) goto err; /* * Redo if r or s is zero as required by FIPS 186-3: this is very * unlikely. */ if (BN_is_zero(r) || BN_is_zero(s)) { if (noredo) { reason = DSA_R_NEED_NEW_SETUP_VALUES; goto err; } goto redo; } ret = DSA_SIG_new(); if (ret == NULL) goto err; ret->r = r; ret->s = s; err: if (ret == NULL) { DSAerr(DSA_F_DSA_DO_SIGN, reason); BN_free(r); BN_free(s); } BN_CTX_free(ctx); BN_clear_free(kinv); return ret; }
null
0
static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) { BIGNUM *kinv = NULL, *r = NULL, *s = NULL; BIGNUM *m, *blind, *blindm, *tmp; BN_CTX *ctx = NULL; int reason = ERR_R_BN_LIB; DSA_SIG *ret = NULL; int noredo = 0; if (dsa->p == NULL || dsa->q == NULL || dsa->g == NULL) { reason = DSA_R_MISSING_PARAMETERS; goto err; } s = BN_new(); if (s == NULL) goto err; ctx = BN_CTX_new(); if (ctx == NULL) goto err; m = BN_CTX_get(ctx); blind = BN_CTX_get(ctx); blindm = BN_CTX_get(ctx); tmp = BN_CTX_get(ctx); if (tmp == NULL) goto err; redo: if ((dsa->kinv == NULL) || (dsa->r == NULL)) { if (!DSA_sign_setup(dsa, ctx, &kinv, &r)) goto err; } else { kinv = dsa->kinv; dsa->kinv = NULL; r = dsa->r; dsa->r = NULL; noredo = 1; } if (dlen > BN_num_bytes(dsa->q)) /* * if the digest length is greater than the size of q use the * BN_num_bits(dsa->q) leftmost bits of the digest, see fips 186-3, * 4.2 */ dlen = BN_num_bytes(dsa->q); if (BN_bin2bn(dgst, dlen, m) == NULL) goto err; /* * The normal signature calculation is: * * s := k^-1 * (m + r * priv_key) mod q * * We will blind this to protect against side channel attacks * * s := blind^-1 * k^-1 * (blind * m + blind * r * priv_key) mod q */ /* Generate a blinding value */ do { if (!BN_rand(blind, BN_num_bits(dsa->q) - 1, -1, 0)) goto err; } while (BN_is_zero(blind)); BN_set_flags(blind, BN_FLG_CONSTTIME); BN_set_flags(blindm, BN_FLG_CONSTTIME); BN_set_flags(tmp, BN_FLG_CONSTTIME); /* tmp := blind * priv_key * r mod q */ if (!BN_mod_mul(tmp, blind, dsa->priv_key, dsa->q, ctx)) goto err; if (!BN_mod_mul(tmp, tmp, r, dsa->q, ctx)) goto err; /* blindm := blind * m mod q */ if (!BN_mod_mul(blindm, blind, m, dsa->q, ctx)) goto err; /* s : = (blind * priv_key * r) + (blind * m) mod q */ if (!BN_mod_add_quick(s, tmp, blindm, dsa->q)) goto err; /* s := s * k^-1 mod q */ if (!BN_mod_mul(s, s, kinv, dsa->q, ctx)) goto err; /* s:= s * blind^-1 mod q */ if (BN_mod_inverse(blind, blind, dsa->q, ctx) == NULL) goto err; if (!BN_mod_mul(s, s, blind, dsa->q, ctx)) goto err; /* * Redo if r or s is zero as required by FIPS 186-3: this is very * unlikely. */ if (BN_is_zero(r) || BN_is_zero(s)) { if (noredo) { reason = DSA_R_NEED_NEW_SETUP_VALUES; goto err; } goto redo; } ret = DSA_SIG_new(); if (ret == NULL) goto err; ret->r = r; ret->s = s; err: if (ret == NULL) { DSAerr(DSA_F_DSA_DO_SIGN, reason); BN_free(r); BN_free(s); } BN_CTX_free(ctx); BN_clear_free(kinv); return ret; }
@@ -279,7 +279,7 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, goto err; /* Preallocate space */ - q_bits = BN_num_bits(dsa->q); + q_bits = BN_num_bits(dsa->q) + sizeof(dsa->q->d[0]) * 16; if (!BN_set_bit(&k, q_bits) || !BN_set_bit(&l, q_bits) || !BN_set_bit(&m, q_bits))
CWE-320
null
null
12,356
static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, DSA *dsa) { BN_CTX *ctx; BIGNUM u1, u2, t1; BN_MONT_CTX *mont = NULL; int ret = -1, i; if (!dsa->p || !dsa->q || !dsa->g) { DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_MISSING_PARAMETERS); return -1; } i = BN_num_bits(dsa->q); /* fips 186-3 allows only different sizes for q */ if (i != 160 && i != 224 && i != 256) { DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_BAD_Q_VALUE); return -1; } if (BN_num_bits(dsa->p) > OPENSSL_DSA_MAX_MODULUS_BITS) { DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_MODULUS_TOO_LARGE); return -1; } BN_init(&u1); BN_init(&u2); BN_init(&t1); if ((ctx = BN_CTX_new()) == NULL) goto err; if (BN_is_zero(sig->r) || BN_is_negative(sig->r) || BN_ucmp(sig->r, dsa->q) >= 0) { ret = 0; goto err; } if (BN_is_zero(sig->s) || BN_is_negative(sig->s) || BN_ucmp(sig->s, dsa->q) >= 0) { ret = 0; goto err; } /* * Calculate W = inv(S) mod Q save W in u2 */ if ((BN_mod_inverse(&u2, sig->s, dsa->q, ctx)) == NULL) goto err; /* save M in u1 */ if (dgst_len > (i >> 3)) /* * if the digest length is greater than the size of q use the * BN_num_bits(dsa->q) leftmost bits of the digest, see fips 186-3, * 4.2 */ dgst_len = (i >> 3); if (BN_bin2bn(dgst, dgst_len, &u1) == NULL) goto err; /* u1 = M * w mod q */ if (!BN_mod_mul(&u1, &u1, &u2, dsa->q, ctx)) goto err; /* u2 = r * w mod q */ if (!BN_mod_mul(&u2, sig->r, &u2, dsa->q, ctx)) goto err; if (dsa->flags & DSA_FLAG_CACHE_MONT_P) { mont = BN_MONT_CTX_set_locked(&dsa->method_mont_p, CRYPTO_LOCK_DSA, dsa->p, ctx); if (!mont) goto err; } DSA_MOD_EXP(goto err, dsa, &t1, dsa->g, &u1, dsa->pub_key, &u2, dsa->p, ctx, mont); /* BN_copy(&u1,&t1); */ /* let u1 = u1 mod q */ if (!BN_mod(&u1, &t1, dsa->q, ctx)) goto err; /* * V is now in u1. If the signature is correct, it will be equal to R. */ ret = (BN_ucmp(&u1, sig->r) == 0); err: if (ret < 0) DSAerr(DSA_F_DSA_DO_VERIFY, ERR_R_BN_LIB); if (ctx != NULL) BN_CTX_free(ctx); BN_free(&u1); BN_free(&u2); BN_free(&t1); return (ret); }
null
0
static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, DSA *dsa) { BN_CTX *ctx; BIGNUM u1, u2, t1; BN_MONT_CTX *mont = NULL; int ret = -1, i; if (!dsa->p || !dsa->q || !dsa->g) { DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_MISSING_PARAMETERS); return -1; } i = BN_num_bits(dsa->q); /* fips 186-3 allows only different sizes for q */ if (i != 160 && i != 224 && i != 256) { DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_BAD_Q_VALUE); return -1; } if (BN_num_bits(dsa->p) > OPENSSL_DSA_MAX_MODULUS_BITS) { DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_MODULUS_TOO_LARGE); return -1; } BN_init(&u1); BN_init(&u2); BN_init(&t1); if ((ctx = BN_CTX_new()) == NULL) goto err; if (BN_is_zero(sig->r) || BN_is_negative(sig->r) || BN_ucmp(sig->r, dsa->q) >= 0) { ret = 0; goto err; } if (BN_is_zero(sig->s) || BN_is_negative(sig->s) || BN_ucmp(sig->s, dsa->q) >= 0) { ret = 0; goto err; } /* * Calculate W = inv(S) mod Q save W in u2 */ if ((BN_mod_inverse(&u2, sig->s, dsa->q, ctx)) == NULL) goto err; /* save M in u1 */ if (dgst_len > (i >> 3)) /* * if the digest length is greater than the size of q use the * BN_num_bits(dsa->q) leftmost bits of the digest, see fips 186-3, * 4.2 */ dgst_len = (i >> 3); if (BN_bin2bn(dgst, dgst_len, &u1) == NULL) goto err; /* u1 = M * w mod q */ if (!BN_mod_mul(&u1, &u1, &u2, dsa->q, ctx)) goto err; /* u2 = r * w mod q */ if (!BN_mod_mul(&u2, sig->r, &u2, dsa->q, ctx)) goto err; if (dsa->flags & DSA_FLAG_CACHE_MONT_P) { mont = BN_MONT_CTX_set_locked(&dsa->method_mont_p, CRYPTO_LOCK_DSA, dsa->p, ctx); if (!mont) goto err; } DSA_MOD_EXP(goto err, dsa, &t1, dsa->g, &u1, dsa->pub_key, &u2, dsa->p, ctx, mont); /* BN_copy(&u1,&t1); */ /* let u1 = u1 mod q */ if (!BN_mod(&u1, &t1, dsa->q, ctx)) goto err; /* * V is now in u1. If the signature is correct, it will be equal to R. */ ret = (BN_ucmp(&u1, sig->r) == 0); err: if (ret < 0) DSAerr(DSA_F_DSA_DO_VERIFY, ERR_R_BN_LIB); if (ctx != NULL) BN_CTX_free(ctx); BN_free(&u1); BN_free(&u2); BN_free(&t1); return (ret); }
@@ -279,7 +279,7 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, goto err; /* Preallocate space */ - q_bits = BN_num_bits(dsa->q); + q_bits = BN_num_bits(dsa->q) + sizeof(dsa->q->d[0]) * 16; if (!BN_set_bit(&k, q_bits) || !BN_set_bit(&l, q_bits) || !BN_set_bit(&m, q_bits))
CWE-320
null
null
12,357
static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) { BIGNUM *kinv = NULL; BIGNUM *m, *blind, *blindm, *tmp; BN_CTX *ctx = NULL; int reason = ERR_R_BN_LIB; DSA_SIG *ret = NULL; int rv = 0; if (dsa->p == NULL || dsa->q == NULL || dsa->g == NULL) { reason = DSA_R_MISSING_PARAMETERS; goto err; } ret = DSA_SIG_new(); if (ret == NULL) goto err; ret->r = BN_new(); ret->s = BN_new(); if (ret->r == NULL || ret->s == NULL) goto err; ctx = BN_CTX_new(); if (ctx == NULL) goto err; m = BN_CTX_get(ctx); blind = BN_CTX_get(ctx); blindm = BN_CTX_get(ctx); tmp = BN_CTX_get(ctx); if (tmp == NULL) goto err; redo: if (!dsa_sign_setup(dsa, ctx, &kinv, &ret->r, dgst, dlen)) goto err; if (dlen > BN_num_bytes(dsa->q)) /* * if the digest length is greater than the size of q use the * BN_num_bits(dsa->q) leftmost bits of the digest, see fips 186-3, * 4.2 */ dlen = BN_num_bytes(dsa->q); if (BN_bin2bn(dgst, dlen, m) == NULL) goto err; /* * The normal signature calculation is: * * s := k^-1 * (m + r * priv_key) mod q * * We will blind this to protect against side channel attacks * * s := blind^-1 * k^-1 * (blind * m + blind * r * priv_key) mod q */ /* Generate a blinding value */ do { if (!BN_rand(blind, BN_num_bits(dsa->q) - 1, BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY)) goto err; } while (BN_is_zero(blind)); BN_set_flags(blind, BN_FLG_CONSTTIME); BN_set_flags(blindm, BN_FLG_CONSTTIME); BN_set_flags(tmp, BN_FLG_CONSTTIME); /* tmp := blind * priv_key * r mod q */ if (!BN_mod_mul(tmp, blind, dsa->priv_key, dsa->q, ctx)) goto err; if (!BN_mod_mul(tmp, tmp, ret->r, dsa->q, ctx)) goto err; /* blindm := blind * m mod q */ if (!BN_mod_mul(blindm, blind, m, dsa->q, ctx)) goto err; /* s : = (blind * priv_key * r) + (blind * m) mod q */ if (!BN_mod_add_quick(ret->s, tmp, blindm, dsa->q)) goto err; /* s := s * k^-1 mod q */ if (!BN_mod_mul(ret->s, ret->s, kinv, dsa->q, ctx)) goto err; /* s:= s * blind^-1 mod q */ if (BN_mod_inverse(blind, blind, dsa->q, ctx) == NULL) goto err; if (!BN_mod_mul(ret->s, ret->s, blind, dsa->q, ctx)) goto err; /* * Redo if r or s is zero as required by FIPS 186-3: this is very * unlikely. */ if (BN_is_zero(ret->r) || BN_is_zero(ret->s)) goto redo; rv = 1; err: if (rv == 0) { DSAerr(DSA_F_DSA_DO_SIGN, reason); DSA_SIG_free(ret); ret = NULL; } BN_CTX_free(ctx); BN_clear_free(kinv); return ret; }
null
0
static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) { BIGNUM *kinv = NULL; BIGNUM *m, *blind, *blindm, *tmp; BN_CTX *ctx = NULL; int reason = ERR_R_BN_LIB; DSA_SIG *ret = NULL; int rv = 0; if (dsa->p == NULL || dsa->q == NULL || dsa->g == NULL) { reason = DSA_R_MISSING_PARAMETERS; goto err; } ret = DSA_SIG_new(); if (ret == NULL) goto err; ret->r = BN_new(); ret->s = BN_new(); if (ret->r == NULL || ret->s == NULL) goto err; ctx = BN_CTX_new(); if (ctx == NULL) goto err; m = BN_CTX_get(ctx); blind = BN_CTX_get(ctx); blindm = BN_CTX_get(ctx); tmp = BN_CTX_get(ctx); if (tmp == NULL) goto err; redo: if (!dsa_sign_setup(dsa, ctx, &kinv, &ret->r, dgst, dlen)) goto err; if (dlen > BN_num_bytes(dsa->q)) /* * if the digest length is greater than the size of q use the * BN_num_bits(dsa->q) leftmost bits of the digest, see fips 186-3, * 4.2 */ dlen = BN_num_bytes(dsa->q); if (BN_bin2bn(dgst, dlen, m) == NULL) goto err; /* * The normal signature calculation is: * * s := k^-1 * (m + r * priv_key) mod q * * We will blind this to protect against side channel attacks * * s := blind^-1 * k^-1 * (blind * m + blind * r * priv_key) mod q */ /* Generate a blinding value */ do { if (!BN_rand(blind, BN_num_bits(dsa->q) - 1, BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY)) goto err; } while (BN_is_zero(blind)); BN_set_flags(blind, BN_FLG_CONSTTIME); BN_set_flags(blindm, BN_FLG_CONSTTIME); BN_set_flags(tmp, BN_FLG_CONSTTIME); /* tmp := blind * priv_key * r mod q */ if (!BN_mod_mul(tmp, blind, dsa->priv_key, dsa->q, ctx)) goto err; if (!BN_mod_mul(tmp, tmp, ret->r, dsa->q, ctx)) goto err; /* blindm := blind * m mod q */ if (!BN_mod_mul(blindm, blind, m, dsa->q, ctx)) goto err; /* s : = (blind * priv_key * r) + (blind * m) mod q */ if (!BN_mod_add_quick(ret->s, tmp, blindm, dsa->q)) goto err; /* s := s * k^-1 mod q */ if (!BN_mod_mul(ret->s, ret->s, kinv, dsa->q, ctx)) goto err; /* s:= s * blind^-1 mod q */ if (BN_mod_inverse(blind, blind, dsa->q, ctx) == NULL) goto err; if (!BN_mod_mul(ret->s, ret->s, blind, dsa->q, ctx)) goto err; /* * Redo if r or s is zero as required by FIPS 186-3: this is very * unlikely. */ if (BN_is_zero(ret->r) || BN_is_zero(ret->s)) goto redo; rv = 1; err: if (rv == 0) { DSAerr(DSA_F_DSA_DO_SIGN, reason); DSA_SIG_free(ret); ret = NULL; } BN_CTX_free(ctx); BN_clear_free(kinv); return ret; }
@@ -11,6 +11,7 @@ #include <stdio.h> #include "internal/cryptlib.h" +#include "internal/bn_int.h" #include <openssl/bn.h> #include <openssl/sha.h> #include "dsa_locl.h" @@ -182,9 +183,9 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, { BN_CTX *ctx = NULL; BIGNUM *k, *kinv = NULL, *r = *rp; - BIGNUM *l, *m; + BIGNUM *l; int ret = 0; - int q_bits; + int q_bits, q_words; if (!dsa->p || !dsa->q || !dsa->g) { DSAerr(DSA_F_DSA_SIGN_SETUP, DSA_R_MISSING_PARAMETERS); @@ -193,8 +194,7 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, k = BN_new(); l = BN_new(); - m = BN_new(); - if (k == NULL || l == NULL || m == NULL) + if (k == NULL || l == NULL) goto err; if (ctx_in == NULL) { @@ -205,9 +205,9 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, /* Preallocate space */ q_bits = BN_num_bits(dsa->q); - if (!BN_set_bit(k, q_bits) - || !BN_set_bit(l, q_bits) - || !BN_set_bit(m, q_bits)) + q_words = bn_get_top(dsa->q); + if (!bn_wexpand(k, q_words + 2) + || !bn_wexpand(l, q_words + 2)) goto err; /* Get random k */ @@ -242,14 +242,17 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, * small timing information leakage. We then choose the sum that is * one bit longer than the modulus. * - * TODO: revisit the BN_copy aiming for a memory access agnostic - * conditional copy. + * There are some concerns about the efficacy of doing this. More + * specificly refer to the discussion starting with: + * https://github.com/openssl/openssl/pull/7486#discussion_r228323705 + * The fix is to rework BN so these gymnastics aren't required. */ if (!BN_add(l, k, dsa->q) - || !BN_add(m, l, dsa->q) - || !BN_copy(k, BN_num_bits(l) > q_bits ? l : m)) + || !BN_add(k, l, dsa->q)) goto err; + BN_consttime_swap(BN_is_bit_set(l, q_bits), k, l, q_words + 2); + if ((dsa)->meth->bn_mod_exp != NULL) { if (!dsa->meth->bn_mod_exp(dsa, r, dsa->g, k, dsa->p, ctx, dsa->method_mont_p)) @@ -262,7 +265,7 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, if (!BN_mod(r, r, dsa->q, ctx)) goto err; - /* Compute part of 's = inv(k) (m + xr) mod q' */ + /* Compute part of 's = inv(k) (m + xr) mod q' */ if ((kinv = dsa_mod_inverse_fermat(k, dsa->q, ctx)) == NULL) goto err; @@ -277,7 +280,6 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BN_CTX_free(ctx); BN_clear_free(k); BN_clear_free(l); - BN_clear_free(m); return ret; }
CWE-320
null
null
12,358
int DH_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh) { #ifdef OPENSSL_FIPS if (FIPS_mode() && !(dh->meth->flags & DH_FLAG_FIPS_METHOD) && !(dh->flags & DH_FLAG_NON_FIPS_ALLOW)) { DHerr(DH_F_DH_COMPUTE_KEY, DH_R_NON_FIPS_METHOD); return 0; } #endif return dh->meth->compute_key(key, pub_key, dh); }
DoS
0
int DH_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh) { #ifdef OPENSSL_FIPS if (FIPS_mode() && !(dh->meth->flags & DH_FLAG_FIPS_METHOD) && !(dh->flags & DH_FLAG_NON_FIPS_ALLOW)) { DHerr(DH_F_DH_COMPUTE_KEY, DH_R_NON_FIPS_METHOD); return 0; } #endif return dh->meth->compute_key(key, pub_key, dh); }
@@ -130,10 +130,15 @@ static int generate_key(DH *dh) int ok = 0; int generate_new_key = 0; unsigned l; - BN_CTX *ctx; + BN_CTX *ctx = NULL; BN_MONT_CTX *mont = NULL; BIGNUM *pub_key = NULL, *priv_key = NULL; + if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) { + DHerr(DH_F_GENERATE_KEY, DH_R_MODULUS_TOO_LARGE); + return 0; + } + ctx = BN_CTX_new(); if (ctx == NULL) goto err;
CWE-320
null
null
12,359
int DH_compute_key_padded(unsigned char *key, const BIGNUM *pub_key, DH *dh) { int rv, pad; rv = dh->meth->compute_key(key, pub_key, dh); if (rv <= 0) return rv; pad = BN_num_bytes(dh->p) - rv; if (pad > 0) { memmove(key + pad, key, rv); memset(key, 0, pad); } return rv + pad; }
DoS
0
int DH_compute_key_padded(unsigned char *key, const BIGNUM *pub_key, DH *dh) { int rv, pad; rv = dh->meth->compute_key(key, pub_key, dh); if (rv <= 0) return rv; pad = BN_num_bytes(dh->p) - rv; if (pad > 0) { memmove(key + pad, key, rv); memset(key, 0, pad); } return rv + pad; }
@@ -130,10 +130,15 @@ static int generate_key(DH *dh) int ok = 0; int generate_new_key = 0; unsigned l; - BN_CTX *ctx; + BN_CTX *ctx = NULL; BN_MONT_CTX *mont = NULL; BIGNUM *pub_key = NULL, *priv_key = NULL; + if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) { + DHerr(DH_F_GENERATE_KEY, DH_R_MODULUS_TOO_LARGE); + return 0; + } + ctx = BN_CTX_new(); if (ctx == NULL) goto err;
CWE-320
null
null
12,360
int DH_generate_key(DH *dh) { #ifdef OPENSSL_FIPS if (FIPS_mode() && !(dh->meth->flags & DH_FLAG_FIPS_METHOD) && !(dh->flags & DH_FLAG_NON_FIPS_ALLOW)) { DHerr(DH_F_DH_GENERATE_KEY, DH_R_NON_FIPS_METHOD); return 0; } #endif return dh->meth->generate_key(dh); }
DoS
0
int DH_generate_key(DH *dh) { #ifdef OPENSSL_FIPS if (FIPS_mode() && !(dh->meth->flags & DH_FLAG_FIPS_METHOD) && !(dh->flags & DH_FLAG_NON_FIPS_ALLOW)) { DHerr(DH_F_DH_GENERATE_KEY, DH_R_NON_FIPS_METHOD); return 0; } #endif return dh->meth->generate_key(dh); }
@@ -130,10 +130,15 @@ static int generate_key(DH *dh) int ok = 0; int generate_new_key = 0; unsigned l; - BN_CTX *ctx; + BN_CTX *ctx = NULL; BN_MONT_CTX *mont = NULL; BIGNUM *pub_key = NULL, *priv_key = NULL; + if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) { + DHerr(DH_F_GENERATE_KEY, DH_R_MODULUS_TOO_LARGE); + return 0; + } + ctx = BN_CTX_new(); if (ctx == NULL) goto err;
CWE-320
null
null
12,361
int DH_generate_key(DH *dh) { return dh->meth->generate_key(dh); }
DoS
0
int DH_generate_key(DH *dh) { return dh->meth->generate_key(dh); }
@@ -78,10 +78,15 @@ static int generate_key(DH *dh) int ok = 0; int generate_new_key = 0; unsigned l; - BN_CTX *ctx; + BN_CTX *ctx = NULL; BN_MONT_CTX *mont = NULL; BIGNUM *pub_key = NULL, *priv_key = NULL; + if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) { + DHerr(DH_F_GENERATE_KEY, DH_R_MODULUS_TOO_LARGE); + return 0; + } + ctx = BN_CTX_new(); if (ctx == NULL) goto err;
CWE-320
null
null
12,362
const DH_METHOD *DH_get_default_method(void) { return default_DH_method; }
DoS
0
const DH_METHOD *DH_get_default_method(void) { return default_DH_method; }
@@ -78,10 +78,15 @@ static int generate_key(DH *dh) int ok = 0; int generate_new_key = 0; unsigned l; - BN_CTX *ctx; + BN_CTX *ctx = NULL; BN_MONT_CTX *mont = NULL; BIGNUM *pub_key = NULL, *priv_key = NULL; + if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) { + DHerr(DH_F_GENERATE_KEY, DH_R_MODULUS_TOO_LARGE); + return 0; + } + ctx = BN_CTX_new(); if (ctx == NULL) goto err;
CWE-320
null
null
12,363
void DH_set_default_method(const DH_METHOD *meth) { default_DH_method = meth; }
DoS
0
void DH_set_default_method(const DH_METHOD *meth) { default_DH_method = meth; }
@@ -78,10 +78,15 @@ static int generate_key(DH *dh) int ok = 0; int generate_new_key = 0; unsigned l; - BN_CTX *ctx; + BN_CTX *ctx = NULL; BN_MONT_CTX *mont = NULL; BIGNUM *pub_key = NULL, *priv_key = NULL; + if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) { + DHerr(DH_F_GENERATE_KEY, DH_R_MODULUS_TOO_LARGE); + return 0; + } + ctx = BN_CTX_new(); if (ctx == NULL) goto err;
CWE-320
null
null
12,364
bdfFreeFontBits(FontPtr pFont) { BitmapFontPtr bitmapFont; BitmapExtraPtr bitmapExtra; int i, nencoding; bitmapFont = (BitmapFontPtr) pFont->fontPrivate; bitmapExtra = (BitmapExtraPtr) bitmapFont->bitmapExtra; free(bitmapFont->ink_metrics); if(bitmapFont->encoding) { nencoding = (pFont->info.lastCol - pFont->info.firstCol + 1) * (pFont->info.lastRow - pFont->info.firstRow + 1); for(i=0; i<NUM_SEGMENTS(nencoding); i++) free(bitmapFont->encoding[i]); } free(bitmapFont->encoding); for (i = 0; i < bitmapFont->num_chars; i++) free(bitmapFont->metrics[i].bits); free(bitmapFont->metrics); if (bitmapExtra) { free (bitmapExtra->glyphNames); free (bitmapExtra->sWidths); free (bitmapExtra); } free(pFont->info.props); free(bitmapFont); }
DoS Exec Code Overflow
0
bdfFreeFontBits(FontPtr pFont) { BitmapFontPtr bitmapFont; BitmapExtraPtr bitmapExtra; int i, nencoding; bitmapFont = (BitmapFontPtr) pFont->fontPrivate; bitmapExtra = (BitmapExtraPtr) bitmapFont->bitmapExtra; free(bitmapFont->ink_metrics); if(bitmapFont->encoding) { nencoding = (pFont->info.lastCol - pFont->info.firstCol + 1) * (pFont->info.lastRow - pFont->info.firstRow + 1); for(i=0; i<NUM_SEGMENTS(nencoding); i++) free(bitmapFont->encoding[i]); } free(bitmapFont->encoding); for (i = 0; i < bitmapFont->num_chars; i++) free(bitmapFont->metrics[i].bits); free(bitmapFont->metrics); if (bitmapExtra) { free (bitmapExtra->glyphNames); free (bitmapExtra->sWidths); free (bitmapExtra); } free(pFont->info.props); free(bitmapFont); }
@@ -338,7 +338,7 @@ bdfReadCharacters(FontFilePtr file, FontPtr pFont, bdfFileState *pState, char charName[100]; int ignore; - if (sscanf((char *) line, "STARTCHAR %s", charName) != 1) { + if (sscanf((char *) line, "STARTCHAR %99s", charName) != 1) { bdfError("bad character name in BDF file\n"); goto BAILOUT; /* bottom of function, free and return error */ }
CWE-119
null
null
12,365
bdfPadToTerminal(FontPtr pFont) { BitmapFontPtr bitmapFont; BitmapExtraPtr bitmapExtra; int i; int new_size; CharInfoRec new; int w, h; bitmapFont = (BitmapFontPtr) pFont->fontPrivate; bzero(&new, sizeof(CharInfoRec)); new.metrics.ascent = pFont->info.fontAscent; new.metrics.descent = pFont->info.fontDescent; new.metrics.leftSideBearing = 0; new.metrics.rightSideBearing = pFont->info.minbounds.characterWidth; new.metrics.characterWidth = new.metrics.rightSideBearing; new_size = BYTES_FOR_GLYPH(&new, pFont->glyph); for (i = 0; i < bitmapFont->num_chars; i++) { new.bits = malloc(new_size); if (!new.bits) { bdfError("Couldn't allocate bits (%d)\n", new_size); return FALSE; } FontCharReshape(pFont, &bitmapFont->metrics[i], &new); new.metrics.attributes = bitmapFont->metrics[i].metrics.attributes; free(bitmapFont->metrics[i].bits); bitmapFont->metrics[i] = new; } bitmapExtra = bitmapFont->bitmapExtra; if (bitmapExtra) { w = GLYPHWIDTHPIXELS(&new); h = GLYPHHEIGHTPIXELS(&new); for (i = 0; i < GLYPHPADOPTIONS; i++) bitmapExtra->bitmapsSizes[i] = bitmapFont->num_chars * (BYTES_PER_ROW(w, 1 << i) * h); } return TRUE; }
DoS Exec Code Overflow
0
bdfPadToTerminal(FontPtr pFont) { BitmapFontPtr bitmapFont; BitmapExtraPtr bitmapExtra; int i; int new_size; CharInfoRec new; int w, h; bitmapFont = (BitmapFontPtr) pFont->fontPrivate; bzero(&new, sizeof(CharInfoRec)); new.metrics.ascent = pFont->info.fontAscent; new.metrics.descent = pFont->info.fontDescent; new.metrics.leftSideBearing = 0; new.metrics.rightSideBearing = pFont->info.minbounds.characterWidth; new.metrics.characterWidth = new.metrics.rightSideBearing; new_size = BYTES_FOR_GLYPH(&new, pFont->glyph); for (i = 0; i < bitmapFont->num_chars; i++) { new.bits = malloc(new_size); if (!new.bits) { bdfError("Couldn't allocate bits (%d)\n", new_size); return FALSE; } FontCharReshape(pFont, &bitmapFont->metrics[i], &new); new.metrics.attributes = bitmapFont->metrics[i].metrics.attributes; free(bitmapFont->metrics[i].bits); bitmapFont->metrics[i] = new; } bitmapExtra = bitmapFont->bitmapExtra; if (bitmapExtra) { w = GLYPHWIDTHPIXELS(&new); h = GLYPHHEIGHTPIXELS(&new); for (i = 0; i < GLYPHPADOPTIONS; i++) bitmapExtra->bitmapsSizes[i] = bitmapFont->num_chars * (BYTES_PER_ROW(w, 1 << i) * h); } return TRUE; }
@@ -338,7 +338,7 @@ bdfReadCharacters(FontFilePtr file, FontPtr pFont, bdfFileState *pState, char charName[100]; int ignore; - if (sscanf((char *) line, "STARTCHAR %s", charName) != 1) { + if (sscanf((char *) line, "STARTCHAR %99s", charName) != 1) { bdfError("bad character name in BDF file\n"); goto BAILOUT; /* bottom of function, free and return error */ }
CWE-119
null
null
12,366
bdfReadBitmap(CharInfoPtr pCI, FontFilePtr file, int bit, int byte, int glyph, int scan, CARD32 *sizes) { int widthBits, widthBytes, widthHexChars; int height, row; int i, inLineLen, nextByte; unsigned char *pInBits, *picture, *line = NULL; unsigned char lineBuf[BDFLINELEN]; widthBits = GLYPHWIDTHPIXELS(pCI); height = GLYPHHEIGHTPIXELS(pCI); widthBytes = BYTES_PER_ROW(widthBits, glyph); if (widthBytes * height > 0) { picture = malloc(widthBytes * height); if (!picture) { bdfError("Couldn't allocate picture (%d*%d)\n", widthBytes, height); goto BAILOUT; } } else picture = NULL; pCI->bits = (char *) picture; if (sizes) { for (i = 0; i < GLYPHPADOPTIONS; i++) sizes[i] += BYTES_PER_ROW(widthBits, (1 << i)) * height; } nextByte = 0; widthHexChars = BYTES_PER_ROW(widthBits, 1); /* 5/31/89 (ef) -- hack, hack, hack. what *am* I supposed to do with */ /* 0 width characters? */ for (row = 0; row < height; row++) { line = bdfGetLine(file, lineBuf, BDFLINELEN); if (!line) break; if (widthBits == 0) { if ((!line) || (bdfIsPrefix(line, "ENDCHAR"))) break; else continue; } pInBits = line; inLineLen = strlen((char *) pInBits); if (inLineLen & 1) { bdfError("odd number of characters in hex encoding\n"); line[inLineLen++] = '0'; line[inLineLen] = '\0'; } inLineLen >>= 1; i = inLineLen; if (i > widthHexChars) i = widthHexChars; for (; i > 0; i--, pInBits += 2) picture[nextByte++] = bdfHexByte(pInBits); /* pad if line is too short */ if (inLineLen < widthHexChars) { for (i = widthHexChars - inLineLen; i > 0; i--) picture[nextByte++] = 0; } else { unsigned char mask; mask = 0xff << (8 - (widthBits & 0x7)); if (mask && picture[nextByte - 1] & ~mask) { picture[nextByte - 1] &= mask; } } if (widthBytes > widthHexChars) { i = widthBytes - widthHexChars; while (i-- > 0) picture[nextByte++] = 0; } } if ((line && (!bdfIsPrefix(line, "ENDCHAR"))) || (height == 0)) line = bdfGetLine(file, lineBuf, BDFLINELEN); if ((!line) || (!bdfIsPrefix(line, "ENDCHAR"))) { bdfError("missing 'ENDCHAR'\n"); goto BAILOUT; } if (nextByte != height * widthBytes) { bdfError("bytes != rows * bytes_per_row (%d != %d * %d)\n", nextByte, height, widthBytes); goto BAILOUT; } if (picture != NULL) { if (bit == LSBFirst) BitOrderInvert(picture, nextByte); if (bit != byte) { if (scan == 2) TwoByteSwap(picture, nextByte); else if (scan == 4) FourByteSwap(picture, nextByte); } } return (TRUE); BAILOUT: if (picture) free(picture); pCI->bits = NULL; return (FALSE); }
DoS Exec Code Overflow
0
bdfReadBitmap(CharInfoPtr pCI, FontFilePtr file, int bit, int byte, int glyph, int scan, CARD32 *sizes) { int widthBits, widthBytes, widthHexChars; int height, row; int i, inLineLen, nextByte; unsigned char *pInBits, *picture, *line = NULL; unsigned char lineBuf[BDFLINELEN]; widthBits = GLYPHWIDTHPIXELS(pCI); height = GLYPHHEIGHTPIXELS(pCI); widthBytes = BYTES_PER_ROW(widthBits, glyph); if (widthBytes * height > 0) { picture = malloc(widthBytes * height); if (!picture) { bdfError("Couldn't allocate picture (%d*%d)\n", widthBytes, height); goto BAILOUT; } } else picture = NULL; pCI->bits = (char *) picture; if (sizes) { for (i = 0; i < GLYPHPADOPTIONS; i++) sizes[i] += BYTES_PER_ROW(widthBits, (1 << i)) * height; } nextByte = 0; widthHexChars = BYTES_PER_ROW(widthBits, 1); /* 5/31/89 (ef) -- hack, hack, hack. what *am* I supposed to do with */ /* 0 width characters? */ for (row = 0; row < height; row++) { line = bdfGetLine(file, lineBuf, BDFLINELEN); if (!line) break; if (widthBits == 0) { if ((!line) || (bdfIsPrefix(line, "ENDCHAR"))) break; else continue; } pInBits = line; inLineLen = strlen((char *) pInBits); if (inLineLen & 1) { bdfError("odd number of characters in hex encoding\n"); line[inLineLen++] = '0'; line[inLineLen] = '\0'; } inLineLen >>= 1; i = inLineLen; if (i > widthHexChars) i = widthHexChars; for (; i > 0; i--, pInBits += 2) picture[nextByte++] = bdfHexByte(pInBits); /* pad if line is too short */ if (inLineLen < widthHexChars) { for (i = widthHexChars - inLineLen; i > 0; i--) picture[nextByte++] = 0; } else { unsigned char mask; mask = 0xff << (8 - (widthBits & 0x7)); if (mask && picture[nextByte - 1] & ~mask) { picture[nextByte - 1] &= mask; } } if (widthBytes > widthHexChars) { i = widthBytes - widthHexChars; while (i-- > 0) picture[nextByte++] = 0; } } if ((line && (!bdfIsPrefix(line, "ENDCHAR"))) || (height == 0)) line = bdfGetLine(file, lineBuf, BDFLINELEN); if ((!line) || (!bdfIsPrefix(line, "ENDCHAR"))) { bdfError("missing 'ENDCHAR'\n"); goto BAILOUT; } if (nextByte != height * widthBytes) { bdfError("bytes != rows * bytes_per_row (%d != %d * %d)\n", nextByte, height, widthBytes); goto BAILOUT; } if (picture != NULL) { if (bit == LSBFirst) BitOrderInvert(picture, nextByte); if (bit != byte) { if (scan == 2) TwoByteSwap(picture, nextByte); else if (scan == 4) FourByteSwap(picture, nextByte); } } return (TRUE); BAILOUT: if (picture) free(picture); pCI->bits = NULL; return (FALSE); }
@@ -338,7 +338,7 @@ bdfReadCharacters(FontFilePtr file, FontPtr pFont, bdfFileState *pState, char charName[100]; int ignore; - if (sscanf((char *) line, "STARTCHAR %s", charName) != 1) { + if (sscanf((char *) line, "STARTCHAR %99s", charName) != 1) { bdfError("bad character name in BDF file\n"); goto BAILOUT; /* bottom of function, free and return error */ }
CWE-119
null
null
12,367
bdfReadHeader(FontFilePtr file, bdfFileState *pState) { unsigned char *line; char namebuf[BDFLINELEN]; unsigned char lineBuf[BDFLINELEN]; line = bdfGetLine(file, lineBuf, BDFLINELEN); if (!line || sscanf((char *) line, "STARTFONT %s", namebuf) != 1 || !bdfStrEqual(namebuf, "2.1")) { bdfError("bad 'STARTFONT'\n"); return (FALSE); } line = bdfGetLine(file, lineBuf, BDFLINELEN); if (!line || sscanf((char *) line, "FONT %[^\n]", pState->fontName) != 1) { bdfError("bad 'FONT'\n"); return (FALSE); } line = bdfGetLine(file, lineBuf, BDFLINELEN); if (!line || !bdfIsPrefix(line, "SIZE")) { bdfError("missing 'SIZE'\n"); return (FALSE); } if (sscanf((char *) line, "SIZE %f%d%d", &pState->pointSize, &pState->resolution_x, &pState->resolution_y) != 3) { bdfError("bad 'SIZE'\n"); return (FALSE); } if (pState->pointSize < 1 || pState->resolution_x < 1 || pState->resolution_y < 1) { bdfError("SIZE values must be > 0\n"); return (FALSE); } line = bdfGetLine(file, lineBuf, BDFLINELEN); if (!line || !bdfIsPrefix(line, "FONTBOUNDINGBOX")) { bdfError("missing 'FONTBOUNDINGBOX'\n"); return (FALSE); } return (TRUE); }
DoS Exec Code Overflow
0
bdfReadHeader(FontFilePtr file, bdfFileState *pState) { unsigned char *line; char namebuf[BDFLINELEN]; unsigned char lineBuf[BDFLINELEN]; line = bdfGetLine(file, lineBuf, BDFLINELEN); if (!line || sscanf((char *) line, "STARTFONT %s", namebuf) != 1 || !bdfStrEqual(namebuf, "2.1")) { bdfError("bad 'STARTFONT'\n"); return (FALSE); } line = bdfGetLine(file, lineBuf, BDFLINELEN); if (!line || sscanf((char *) line, "FONT %[^\n]", pState->fontName) != 1) { bdfError("bad 'FONT'\n"); return (FALSE); } line = bdfGetLine(file, lineBuf, BDFLINELEN); if (!line || !bdfIsPrefix(line, "SIZE")) { bdfError("missing 'SIZE'\n"); return (FALSE); } if (sscanf((char *) line, "SIZE %f%d%d", &pState->pointSize, &pState->resolution_x, &pState->resolution_y) != 3) { bdfError("bad 'SIZE'\n"); return (FALSE); } if (pState->pointSize < 1 || pState->resolution_x < 1 || pState->resolution_y < 1) { bdfError("SIZE values must be > 0\n"); return (FALSE); } line = bdfGetLine(file, lineBuf, BDFLINELEN); if (!line || !bdfIsPrefix(line, "FONTBOUNDINGBOX")) { bdfError("missing 'FONTBOUNDINGBOX'\n"); return (FALSE); } return (TRUE); }
@@ -338,7 +338,7 @@ bdfReadCharacters(FontFilePtr file, FontPtr pFont, bdfFileState *pState, char charName[100]; int ignore; - if (sscanf((char *) line, "STARTCHAR %s", charName) != 1) { + if (sscanf((char *) line, "STARTCHAR %99s", charName) != 1) { bdfError("bad character name in BDF file\n"); goto BAILOUT; /* bottom of function, free and return error */ }
CWE-119
null
null
12,368
bdfReadProperties(FontFilePtr file, FontPtr pFont, bdfFileState *pState) { int nProps, props_left, nextProp; char *stringProps; FontPropPtr props; char namebuf[BDFLINELEN], secondbuf[BDFLINELEN], thirdbuf[BDFLINELEN]; unsigned char *line; unsigned char lineBuf[BDFLINELEN]; BitmapFontPtr bitmapFont = (BitmapFontPtr) pFont->fontPrivate; line = bdfGetLine(file, lineBuf, BDFLINELEN); if (!line || !bdfIsPrefix(line, "STARTPROPERTIES")) { bdfError("missing 'STARTPROPERTIES'\n"); return (FALSE); } if (sscanf((char *) line, "STARTPROPERTIES %d", &nProps) != 1) { bdfError("bad 'STARTPROPERTIES'\n"); return (FALSE); } pFont->info.isStringProp = NULL; pFont->info.props = NULL; pFont->info.nprops = 0; stringProps = malloc((nProps + BDF_GENPROPS) * sizeof(char)); pFont->info.isStringProp = stringProps; if (stringProps == NULL) { bdfError("Couldn't allocate stringProps (%d*%d)\n", (nProps + BDF_GENPROPS), (int) sizeof(Bool)); goto BAILOUT; } pFont->info.props = props = calloc(nProps + BDF_GENPROPS, sizeof(FontPropRec)); if (props == NULL) { bdfError("Couldn't allocate props (%d*%d)\n", nProps + BDF_GENPROPS, (int) sizeof(FontPropRec)); goto BAILOUT; } nextProp = 0; props_left = nProps; while (props_left-- > 0) { line = bdfGetLine(file, lineBuf, BDFLINELEN); if (line == NULL || bdfIsPrefix(line, "ENDPROPERTIES")) { bdfError("\"STARTPROPERTIES %d\" followed by only %d properties\n", nProps, nProps - props_left - 1); goto BAILOUT; } while (*line && isspace(*line)) line++; switch (sscanf((char *) line, "%s%s%s", namebuf, secondbuf, thirdbuf)) { default: bdfError("missing '%s' parameter value\n", namebuf); goto BAILOUT; case 2: /* * Possibilites include: valid quoted string with no white space * valid integer value invalid value */ if (secondbuf[0] == '"') { stringProps[nextProp] = TRUE; props[nextProp].value = bdfGetPropertyValue((char *)line + strlen(namebuf) + 1); if (!props[nextProp].value) goto BAILOUT; break; } else if (bdfIsInteger(secondbuf)) { stringProps[nextProp] = FALSE; props[nextProp].value = atoi(secondbuf); break; } else { bdfError("invalid '%s' parameter value\n", namebuf); goto BAILOUT; } case 3: /* * Possibilites include: valid quoted string with some white space * invalid value (reject even if second string is integer) */ if (secondbuf[0] == '"') { stringProps[nextProp] = TRUE; props[nextProp].value = bdfGetPropertyValue((char *)line + strlen(namebuf) + 1); if (!props[nextProp].value) goto BAILOUT; break; } else { bdfError("invalid '%s' parameter value\n", namebuf); goto BAILOUT; } } props[nextProp].name = bdfForceMakeAtom(namebuf, NULL); if (props[nextProp].name == None) { bdfError("Empty property name.\n"); goto BAILOUT; } if (!bdfSpecialProperty(pFont, &props[nextProp], stringProps[nextProp], pState)) nextProp++; } line = bdfGetLine(file, lineBuf, BDFLINELEN); if (!line || !bdfIsPrefix(line, "ENDPROPERTIES")) { bdfError("missing 'ENDPROPERTIES'\n"); goto BAILOUT; } if (!pState->haveFontAscent || !pState->haveFontDescent) { bdfError("missing 'FONT_ASCENT' or 'FONT_DESCENT' properties\n"); goto BAILOUT; } if (bitmapFont->bitmapExtra) { bitmapFont->bitmapExtra->info.fontAscent = pFont->info.fontAscent; bitmapFont->bitmapExtra->info.fontDescent = pFont->info.fontDescent; } if (!pState->pointSizeProp) { props[nextProp].name = bdfForceMakeAtom("POINT_SIZE", NULL); props[nextProp].value = (INT32) (pState->pointSize * 10.0); stringProps[nextProp] = FALSE; pState->pointSizeProp = &props[nextProp]; nextProp++; } if (!pState->fontProp) { props[nextProp].name = bdfForceMakeAtom("FONT", NULL); props[nextProp].value = (INT32) bdfForceMakeAtom(pState->fontName, NULL); stringProps[nextProp] = TRUE; pState->fontProp = &props[nextProp]; nextProp++; } if (!pState->weightProp) { props[nextProp].name = bdfForceMakeAtom("WEIGHT", NULL); props[nextProp].value = -1; /* computed later */ stringProps[nextProp] = FALSE; pState->weightProp = &props[nextProp]; nextProp++; } if (!pState->resolutionProp && pState->resolution_x == pState->resolution_y) { props[nextProp].name = bdfForceMakeAtom("RESOLUTION", NULL); props[nextProp].value = (INT32) ((pState->resolution_x * 100.0) / 72.27); stringProps[nextProp] = FALSE; pState->resolutionProp = &props[nextProp]; nextProp++; } if (!pState->resolutionXProp) { props[nextProp].name = bdfForceMakeAtom("RESOLUTION_X", NULL); props[nextProp].value = (INT32) pState->resolution_x; stringProps[nextProp] = FALSE; pState->resolutionProp = &props[nextProp]; nextProp++; } if (!pState->resolutionYProp) { props[nextProp].name = bdfForceMakeAtom("RESOLUTION_Y", NULL); props[nextProp].value = (INT32) pState->resolution_y; stringProps[nextProp] = FALSE; pState->resolutionProp = &props[nextProp]; nextProp++; } if (!pState->xHeightProp) { props[nextProp].name = bdfForceMakeAtom("X_HEIGHT", NULL); props[nextProp].value = -1; /* computed later */ stringProps[nextProp] = FALSE; pState->xHeightProp = &props[nextProp]; nextProp++; } if (!pState->quadWidthProp) { props[nextProp].name = bdfForceMakeAtom("QUAD_WIDTH", NULL); props[nextProp].value = -1; /* computed later */ stringProps[nextProp] = FALSE; pState->quadWidthProp = &props[nextProp]; nextProp++; } pFont->info.nprops = nextProp; return (TRUE); BAILOUT: if (pFont->info.isStringProp) { free(pFont->info.isStringProp); pFont->info.isStringProp = NULL; } if (pFont->info.props) { free(pFont->info.props); pFont->info.props = NULL; } while (line && bdfIsPrefix(line, "ENDPROPERTIES")) line = bdfGetLine(file, lineBuf, BDFLINELEN); return (FALSE); }
DoS Exec Code Overflow
0
bdfReadProperties(FontFilePtr file, FontPtr pFont, bdfFileState *pState) { int nProps, props_left, nextProp; char *stringProps; FontPropPtr props; char namebuf[BDFLINELEN], secondbuf[BDFLINELEN], thirdbuf[BDFLINELEN]; unsigned char *line; unsigned char lineBuf[BDFLINELEN]; BitmapFontPtr bitmapFont = (BitmapFontPtr) pFont->fontPrivate; line = bdfGetLine(file, lineBuf, BDFLINELEN); if (!line || !bdfIsPrefix(line, "STARTPROPERTIES")) { bdfError("missing 'STARTPROPERTIES'\n"); return (FALSE); } if (sscanf((char *) line, "STARTPROPERTIES %d", &nProps) != 1) { bdfError("bad 'STARTPROPERTIES'\n"); return (FALSE); } pFont->info.isStringProp = NULL; pFont->info.props = NULL; pFont->info.nprops = 0; stringProps = malloc((nProps + BDF_GENPROPS) * sizeof(char)); pFont->info.isStringProp = stringProps; if (stringProps == NULL) { bdfError("Couldn't allocate stringProps (%d*%d)\n", (nProps + BDF_GENPROPS), (int) sizeof(Bool)); goto BAILOUT; } pFont->info.props = props = calloc(nProps + BDF_GENPROPS, sizeof(FontPropRec)); if (props == NULL) { bdfError("Couldn't allocate props (%d*%d)\n", nProps + BDF_GENPROPS, (int) sizeof(FontPropRec)); goto BAILOUT; } nextProp = 0; props_left = nProps; while (props_left-- > 0) { line = bdfGetLine(file, lineBuf, BDFLINELEN); if (line == NULL || bdfIsPrefix(line, "ENDPROPERTIES")) { bdfError("\"STARTPROPERTIES %d\" followed by only %d properties\n", nProps, nProps - props_left - 1); goto BAILOUT; } while (*line && isspace(*line)) line++; switch (sscanf((char *) line, "%s%s%s", namebuf, secondbuf, thirdbuf)) { default: bdfError("missing '%s' parameter value\n", namebuf); goto BAILOUT; case 2: /* * Possibilites include: valid quoted string with no white space * valid integer value invalid value */ if (secondbuf[0] == '"') { stringProps[nextProp] = TRUE; props[nextProp].value = bdfGetPropertyValue((char *)line + strlen(namebuf) + 1); if (!props[nextProp].value) goto BAILOUT; break; } else if (bdfIsInteger(secondbuf)) { stringProps[nextProp] = FALSE; props[nextProp].value = atoi(secondbuf); break; } else { bdfError("invalid '%s' parameter value\n", namebuf); goto BAILOUT; } case 3: /* * Possibilites include: valid quoted string with some white space * invalid value (reject even if second string is integer) */ if (secondbuf[0] == '"') { stringProps[nextProp] = TRUE; props[nextProp].value = bdfGetPropertyValue((char *)line + strlen(namebuf) + 1); if (!props[nextProp].value) goto BAILOUT; break; } else { bdfError("invalid '%s' parameter value\n", namebuf); goto BAILOUT; } } props[nextProp].name = bdfForceMakeAtom(namebuf, NULL); if (props[nextProp].name == None) { bdfError("Empty property name.\n"); goto BAILOUT; } if (!bdfSpecialProperty(pFont, &props[nextProp], stringProps[nextProp], pState)) nextProp++; } line = bdfGetLine(file, lineBuf, BDFLINELEN); if (!line || !bdfIsPrefix(line, "ENDPROPERTIES")) { bdfError("missing 'ENDPROPERTIES'\n"); goto BAILOUT; } if (!pState->haveFontAscent || !pState->haveFontDescent) { bdfError("missing 'FONT_ASCENT' or 'FONT_DESCENT' properties\n"); goto BAILOUT; } if (bitmapFont->bitmapExtra) { bitmapFont->bitmapExtra->info.fontAscent = pFont->info.fontAscent; bitmapFont->bitmapExtra->info.fontDescent = pFont->info.fontDescent; } if (!pState->pointSizeProp) { props[nextProp].name = bdfForceMakeAtom("POINT_SIZE", NULL); props[nextProp].value = (INT32) (pState->pointSize * 10.0); stringProps[nextProp] = FALSE; pState->pointSizeProp = &props[nextProp]; nextProp++; } if (!pState->fontProp) { props[nextProp].name = bdfForceMakeAtom("FONT", NULL); props[nextProp].value = (INT32) bdfForceMakeAtom(pState->fontName, NULL); stringProps[nextProp] = TRUE; pState->fontProp = &props[nextProp]; nextProp++; } if (!pState->weightProp) { props[nextProp].name = bdfForceMakeAtom("WEIGHT", NULL); props[nextProp].value = -1; /* computed later */ stringProps[nextProp] = FALSE; pState->weightProp = &props[nextProp]; nextProp++; } if (!pState->resolutionProp && pState->resolution_x == pState->resolution_y) { props[nextProp].name = bdfForceMakeAtom("RESOLUTION", NULL); props[nextProp].value = (INT32) ((pState->resolution_x * 100.0) / 72.27); stringProps[nextProp] = FALSE; pState->resolutionProp = &props[nextProp]; nextProp++; } if (!pState->resolutionXProp) { props[nextProp].name = bdfForceMakeAtom("RESOLUTION_X", NULL); props[nextProp].value = (INT32) pState->resolution_x; stringProps[nextProp] = FALSE; pState->resolutionProp = &props[nextProp]; nextProp++; } if (!pState->resolutionYProp) { props[nextProp].name = bdfForceMakeAtom("RESOLUTION_Y", NULL); props[nextProp].value = (INT32) pState->resolution_y; stringProps[nextProp] = FALSE; pState->resolutionProp = &props[nextProp]; nextProp++; } if (!pState->xHeightProp) { props[nextProp].name = bdfForceMakeAtom("X_HEIGHT", NULL); props[nextProp].value = -1; /* computed later */ stringProps[nextProp] = FALSE; pState->xHeightProp = &props[nextProp]; nextProp++; } if (!pState->quadWidthProp) { props[nextProp].name = bdfForceMakeAtom("QUAD_WIDTH", NULL); props[nextProp].value = -1; /* computed later */ stringProps[nextProp] = FALSE; pState->quadWidthProp = &props[nextProp]; nextProp++; } pFont->info.nprops = nextProp; return (TRUE); BAILOUT: if (pFont->info.isStringProp) { free(pFont->info.isStringProp); pFont->info.isStringProp = NULL; } if (pFont->info.props) { free(pFont->info.props); pFont->info.props = NULL; } while (line && bdfIsPrefix(line, "ENDPROPERTIES")) line = bdfGetLine(file, lineBuf, BDFLINELEN); return (FALSE); }
@@ -338,7 +338,7 @@ bdfReadCharacters(FontFilePtr file, FontPtr pFont, bdfFileState *pState, char charName[100]; int ignore; - if (sscanf((char *) line, "STARTCHAR %s", charName) != 1) { + if (sscanf((char *) line, "STARTCHAR %99s", charName) != 1) { bdfError("bad character name in BDF file\n"); goto BAILOUT; /* bottom of function, free and return error */ }
CWE-119
null
null
12,369
bdfSkipBitmap(FontFilePtr file, int height) { unsigned char *line; int i = 0; unsigned char lineBuf[BDFLINELEN]; do { line = bdfGetLine(file, lineBuf, BDFLINELEN); i++; } while (line && !bdfIsPrefix(line, "ENDCHAR") && i <= height); if (i > 1 && line && !bdfIsPrefix(line, "ENDCHAR")) { bdfError("Error in bitmap, missing 'ENDCHAR'\n"); return (FALSE); } return (TRUE); }
DoS Exec Code Overflow
0
bdfSkipBitmap(FontFilePtr file, int height) { unsigned char *line; int i = 0; unsigned char lineBuf[BDFLINELEN]; do { line = bdfGetLine(file, lineBuf, BDFLINELEN); i++; } while (line && !bdfIsPrefix(line, "ENDCHAR") && i <= height); if (i > 1 && line && !bdfIsPrefix(line, "ENDCHAR")) { bdfError("Error in bitmap, missing 'ENDCHAR'\n"); return (FALSE); } return (TRUE); }
@@ -338,7 +338,7 @@ bdfReadCharacters(FontFilePtr file, FontPtr pFont, bdfFileState *pState, char charName[100]; int ignore; - if (sscanf((char *) line, "STARTCHAR %s", charName) != 1) { + if (sscanf((char *) line, "STARTCHAR %99s", charName) != 1) { bdfError("bad character name in BDF file\n"); goto BAILOUT; /* bottom of function, free and return error */ }
CWE-119
null
null
12,370
dtls1_process_heartbeat(SSL *s) { unsigned char *p = &s->s3->rrec.data[0], *pl; unsigned short hbtype; unsigned int payload; unsigned int padding = 16; /* Use minimum padding */ /* Read type and payload length first */ hbtype = *p++; n2s(p, payload); pl = p; if (s->msg_callback) s->msg_callback(0, s->version, TLS1_RT_HEARTBEAT, &s->s3->rrec.data[0], s->s3->rrec.length, s, s->msg_callback_arg); if (hbtype == TLS1_HB_REQUEST) { unsigned char *buffer, *bp; int r; /* Allocate memory for the response, size is 1 byte * message type, plus 2 bytes payload length, plus * payload, plus padding */ buffer = OPENSSL_malloc(1 + 2 + payload + padding); bp = buffer; /* Enter response type, length and copy payload */ *bp++ = TLS1_HB_RESPONSE; s2n(payload, bp); memcpy(bp, pl, payload); bp += payload; /* Random padding */ RAND_pseudo_bytes(bp, padding); r = dtls1_write_bytes(s, TLS1_RT_HEARTBEAT, buffer, 3 + payload + padding); if (r >= 0 && s->msg_callback) s->msg_callback(1, s->version, TLS1_RT_HEARTBEAT, buffer, 3 + payload + padding, s, s->msg_callback_arg); OPENSSL_free(buffer); if (r < 0) return r; } else if (hbtype == TLS1_HB_RESPONSE) { unsigned int seq; /* We only send sequence numbers (2 bytes unsigned int), * and 16 random bytes, so we just try to read the * sequence number */ n2s(pl, seq); if (payload == 18 && seq == s->tlsext_hb_seq) { dtls1_stop_timer(s); s->tlsext_hb_seq++; s->tlsext_hb_pending = 0; } } return 0; }
DoS
0
dtls1_process_heartbeat(SSL *s) { unsigned char *p = &s->s3->rrec.data[0], *pl; unsigned short hbtype; unsigned int payload; unsigned int padding = 16; /* Use minimum padding */ /* Read type and payload length first */ hbtype = *p++; n2s(p, payload); pl = p; if (s->msg_callback) s->msg_callback(0, s->version, TLS1_RT_HEARTBEAT, &s->s3->rrec.data[0], s->s3->rrec.length, s, s->msg_callback_arg); if (hbtype == TLS1_HB_REQUEST) { unsigned char *buffer, *bp; int r; /* Allocate memory for the response, size is 1 byte * message type, plus 2 bytes payload length, plus * payload, plus padding */ buffer = OPENSSL_malloc(1 + 2 + payload + padding); bp = buffer; /* Enter response type, length and copy payload */ *bp++ = TLS1_HB_RESPONSE; s2n(payload, bp); memcpy(bp, pl, payload); bp += payload; /* Random padding */ RAND_pseudo_bytes(bp, padding); r = dtls1_write_bytes(s, TLS1_RT_HEARTBEAT, buffer, 3 + payload + padding); if (r >= 0 && s->msg_callback) s->msg_callback(1, s->version, TLS1_RT_HEARTBEAT, buffer, 3 + payload + padding, s, s->msg_callback_arg); OPENSSL_free(buffer); if (r < 0) return r; } else if (hbtype == TLS1_HB_RESPONSE) { unsigned int seq; /* We only send sequence numbers (2 bytes unsigned int), * and 16 random bytes, so we just try to read the * sequence number */ n2s(pl, seq); if (payload == 18 && seq == s->tlsext_hb_seq) { dtls1_stop_timer(s); s->tlsext_hb_seq++; s->tlsext_hb_pending = 0; } } return 0; }
@@ -214,6 +214,12 @@ dtls1_hm_fragment_new(unsigned long frag_len, int reassembly) static void dtls1_hm_fragment_free(hm_fragment *frag) { + + if (frag->msg_header.is_ccs) + { + EVP_CIPHER_CTX_free(frag->msg_header.saved_retransmit_state.enc_write_ctx); + EVP_MD_CTX_destroy(frag->msg_header.saved_retransmit_state.write_hash); + } if (frag->fragment) OPENSSL_free(frag->fragment); if (frag->reassembly) OPENSSL_free(frag->reassembly); OPENSSL_free(frag);
CWE-310
null
null
12,371
dtls1_reassemble_fragment(SSL *s, struct hm_header_st* msg_hdr, int *ok) { hm_fragment *frag = NULL; pitem *item = NULL; int i = -1, is_complete; unsigned char seq64be[8]; unsigned long frag_len = msg_hdr->frag_len, max_len; if ((msg_hdr->frag_off+frag_len) > msg_hdr->msg_len) goto err; /* Determine maximum allowed message size. Depends on (user set) * maximum certificate length, but 16k is minimum. */ if (DTLS1_HM_HEADER_LENGTH + SSL3_RT_MAX_ENCRYPTED_LENGTH < s->max_cert_list) max_len = s->max_cert_list; else max_len = DTLS1_HM_HEADER_LENGTH + SSL3_RT_MAX_ENCRYPTED_LENGTH; if ((msg_hdr->frag_off+frag_len) > max_len) goto err; /* Try to find item in queue */ memset(seq64be,0,sizeof(seq64be)); seq64be[6] = (unsigned char) (msg_hdr->seq>>8); seq64be[7] = (unsigned char) msg_hdr->seq; item = pqueue_find(s->d1->buffered_messages, seq64be); if (item == NULL) { frag = dtls1_hm_fragment_new(msg_hdr->msg_len, 1); if ( frag == NULL) goto err; memcpy(&(frag->msg_header), msg_hdr, sizeof(*msg_hdr)); frag->msg_header.frag_len = frag->msg_header.msg_len; frag->msg_header.frag_off = 0; } else frag = (hm_fragment*) item->data; /* If message is already reassembled, this must be a * retransmit and can be dropped. */ if (frag->reassembly == NULL) { unsigned char devnull [256]; while (frag_len) { i = s->method->ssl_read_bytes(s,SSL3_RT_HANDSHAKE, devnull, frag_len>sizeof(devnull)?sizeof(devnull):frag_len,0); if (i<=0) goto err; frag_len -= i; } return DTLS1_HM_FRAGMENT_RETRY; } /* read the body of the fragment (header has already been read */ i = s->method->ssl_read_bytes(s,SSL3_RT_HANDSHAKE, frag->fragment + msg_hdr->frag_off,frag_len,0); if (i<=0 || (unsigned long)i!=frag_len) goto err; RSMBLY_BITMASK_MARK(frag->reassembly, (long)msg_hdr->frag_off, (long)(msg_hdr->frag_off + frag_len)); RSMBLY_BITMASK_IS_COMPLETE(frag->reassembly, (long)msg_hdr->msg_len, is_complete); if (is_complete) { OPENSSL_free(frag->reassembly); frag->reassembly = NULL; } if (item == NULL) { memset(seq64be,0,sizeof(seq64be)); seq64be[6] = (unsigned char)(msg_hdr->seq>>8); seq64be[7] = (unsigned char)(msg_hdr->seq); item = pitem_new(seq64be, frag); if (item == NULL) { goto err; i = -1; } pqueue_insert(s->d1->buffered_messages, item); } return DTLS1_HM_FRAGMENT_RETRY; err: if (frag != NULL) dtls1_hm_fragment_free(frag); if (item != NULL) OPENSSL_free(item); *ok = 0; return i; }
DoS
0
dtls1_reassemble_fragment(SSL *s, struct hm_header_st* msg_hdr, int *ok) { hm_fragment *frag = NULL; pitem *item = NULL; int i = -1, is_complete; unsigned char seq64be[8]; unsigned long frag_len = msg_hdr->frag_len, max_len; if ((msg_hdr->frag_off+frag_len) > msg_hdr->msg_len) goto err; /* Determine maximum allowed message size. Depends on (user set) * maximum certificate length, but 16k is minimum. */ if (DTLS1_HM_HEADER_LENGTH + SSL3_RT_MAX_ENCRYPTED_LENGTH < s->max_cert_list) max_len = s->max_cert_list; else max_len = DTLS1_HM_HEADER_LENGTH + SSL3_RT_MAX_ENCRYPTED_LENGTH; if ((msg_hdr->frag_off+frag_len) > max_len) goto err; /* Try to find item in queue */ memset(seq64be,0,sizeof(seq64be)); seq64be[6] = (unsigned char) (msg_hdr->seq>>8); seq64be[7] = (unsigned char) msg_hdr->seq; item = pqueue_find(s->d1->buffered_messages, seq64be); if (item == NULL) { frag = dtls1_hm_fragment_new(msg_hdr->msg_len, 1); if ( frag == NULL) goto err; memcpy(&(frag->msg_header), msg_hdr, sizeof(*msg_hdr)); frag->msg_header.frag_len = frag->msg_header.msg_len; frag->msg_header.frag_off = 0; } else frag = (hm_fragment*) item->data; /* If message is already reassembled, this must be a * retransmit and can be dropped. */ if (frag->reassembly == NULL) { unsigned char devnull [256]; while (frag_len) { i = s->method->ssl_read_bytes(s,SSL3_RT_HANDSHAKE, devnull, frag_len>sizeof(devnull)?sizeof(devnull):frag_len,0); if (i<=0) goto err; frag_len -= i; } return DTLS1_HM_FRAGMENT_RETRY; } /* read the body of the fragment (header has already been read */ i = s->method->ssl_read_bytes(s,SSL3_RT_HANDSHAKE, frag->fragment + msg_hdr->frag_off,frag_len,0); if (i<=0 || (unsigned long)i!=frag_len) goto err; RSMBLY_BITMASK_MARK(frag->reassembly, (long)msg_hdr->frag_off, (long)(msg_hdr->frag_off + frag_len)); RSMBLY_BITMASK_IS_COMPLETE(frag->reassembly, (long)msg_hdr->msg_len, is_complete); if (is_complete) { OPENSSL_free(frag->reassembly); frag->reassembly = NULL; } if (item == NULL) { memset(seq64be,0,sizeof(seq64be)); seq64be[6] = (unsigned char)(msg_hdr->seq>>8); seq64be[7] = (unsigned char)(msg_hdr->seq); item = pitem_new(seq64be, frag); if (item == NULL) { goto err; i = -1; } pqueue_insert(s->d1->buffered_messages, item); } return DTLS1_HM_FRAGMENT_RETRY; err: if (frag != NULL) dtls1_hm_fragment_free(frag); if (item != NULL) OPENSSL_free(item); *ok = 0; return i; }
@@ -214,6 +214,12 @@ dtls1_hm_fragment_new(unsigned long frag_len, int reassembly) static void dtls1_hm_fragment_free(hm_fragment *frag) { + + if (frag->msg_header.is_ccs) + { + EVP_CIPHER_CTX_free(frag->msg_header.saved_retransmit_state.enc_write_ctx); + EVP_MD_CTX_destroy(frag->msg_header.saved_retransmit_state.write_hash); + } if (frag->fragment) OPENSSL_free(frag->fragment); if (frag->reassembly) OPENSSL_free(frag->reassembly); OPENSSL_free(frag);
CWE-310
null
null
12,372
static int tls1_P_hash(const EVP_MD *md, const unsigned char *sec, int sec_len, const void *seed1, int seed1_len, const void *seed2, int seed2_len, const void *seed3, int seed3_len, const void *seed4, int seed4_len, const void *seed5, int seed5_len, unsigned char *out, int olen) { int chunk; size_t j; EVP_MD_CTX ctx, ctx_tmp; EVP_PKEY *mac_key; unsigned char A1[EVP_MAX_MD_SIZE]; size_t A1_len; int ret = 0; chunk=EVP_MD_size(md); OPENSSL_assert(chunk >= 0); EVP_MD_CTX_init(&ctx); EVP_MD_CTX_init(&ctx_tmp); EVP_MD_CTX_set_flags(&ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW); EVP_MD_CTX_set_flags(&ctx_tmp, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW); mac_key = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, sec, sec_len); if (!mac_key) goto err; if (!EVP_DigestSignInit(&ctx,NULL,md, NULL, mac_key)) goto err; if (!EVP_DigestSignInit(&ctx_tmp,NULL,md, NULL, mac_key)) goto err; if (seed1 && !EVP_DigestSignUpdate(&ctx,seed1,seed1_len)) goto err; if (seed2 && !EVP_DigestSignUpdate(&ctx,seed2,seed2_len)) goto err; if (seed3 && !EVP_DigestSignUpdate(&ctx,seed3,seed3_len)) goto err; if (seed4 && !EVP_DigestSignUpdate(&ctx,seed4,seed4_len)) goto err; if (seed5 && !EVP_DigestSignUpdate(&ctx,seed5,seed5_len)) goto err; if (!EVP_DigestSignFinal(&ctx,A1,&A1_len)) goto err; for (;;) { /* Reinit mac contexts */ if (!EVP_DigestSignInit(&ctx,NULL,md, NULL, mac_key)) goto err; if (!EVP_DigestSignInit(&ctx_tmp,NULL,md, NULL, mac_key)) goto err; if (!EVP_DigestSignUpdate(&ctx,A1,A1_len)) goto err; if (!EVP_DigestSignUpdate(&ctx_tmp,A1,A1_len)) goto err; if (seed1 && !EVP_DigestSignUpdate(&ctx,seed1,seed1_len)) goto err; if (seed2 && !EVP_DigestSignUpdate(&ctx,seed2,seed2_len)) goto err; if (seed3 && !EVP_DigestSignUpdate(&ctx,seed3,seed3_len)) goto err; if (seed4 && !EVP_DigestSignUpdate(&ctx,seed4,seed4_len)) goto err; if (seed5 && !EVP_DigestSignUpdate(&ctx,seed5,seed5_len)) goto err; if (olen > chunk) { if (!EVP_DigestSignFinal(&ctx,out,&j)) goto err; out+=j; olen-=j; /* calc the next A1 value */ if (!EVP_DigestSignFinal(&ctx_tmp,A1,&A1_len)) goto err; } else /* last one */ { if (!EVP_DigestSignFinal(&ctx,A1,&A1_len)) goto err; memcpy(out,A1,olen); break; } } ret = 1; err: EVP_PKEY_free(mac_key); EVP_MD_CTX_cleanup(&ctx); EVP_MD_CTX_cleanup(&ctx_tmp); OPENSSL_cleanse(A1,sizeof(A1)); return ret; }
DoS
0
static int tls1_P_hash(const EVP_MD *md, const unsigned char *sec, int sec_len, const void *seed1, int seed1_len, const void *seed2, int seed2_len, const void *seed3, int seed3_len, const void *seed4, int seed4_len, const void *seed5, int seed5_len, unsigned char *out, int olen) { int chunk; size_t j; EVP_MD_CTX ctx, ctx_tmp; EVP_PKEY *mac_key; unsigned char A1[EVP_MAX_MD_SIZE]; size_t A1_len; int ret = 0; chunk=EVP_MD_size(md); OPENSSL_assert(chunk >= 0); EVP_MD_CTX_init(&ctx); EVP_MD_CTX_init(&ctx_tmp); EVP_MD_CTX_set_flags(&ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW); EVP_MD_CTX_set_flags(&ctx_tmp, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW); mac_key = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, sec, sec_len); if (!mac_key) goto err; if (!EVP_DigestSignInit(&ctx,NULL,md, NULL, mac_key)) goto err; if (!EVP_DigestSignInit(&ctx_tmp,NULL,md, NULL, mac_key)) goto err; if (seed1 && !EVP_DigestSignUpdate(&ctx,seed1,seed1_len)) goto err; if (seed2 && !EVP_DigestSignUpdate(&ctx,seed2,seed2_len)) goto err; if (seed3 && !EVP_DigestSignUpdate(&ctx,seed3,seed3_len)) goto err; if (seed4 && !EVP_DigestSignUpdate(&ctx,seed4,seed4_len)) goto err; if (seed5 && !EVP_DigestSignUpdate(&ctx,seed5,seed5_len)) goto err; if (!EVP_DigestSignFinal(&ctx,A1,&A1_len)) goto err; for (;;) { /* Reinit mac contexts */ if (!EVP_DigestSignInit(&ctx,NULL,md, NULL, mac_key)) goto err; if (!EVP_DigestSignInit(&ctx_tmp,NULL,md, NULL, mac_key)) goto err; if (!EVP_DigestSignUpdate(&ctx,A1,A1_len)) goto err; if (!EVP_DigestSignUpdate(&ctx_tmp,A1,A1_len)) goto err; if (seed1 && !EVP_DigestSignUpdate(&ctx,seed1,seed1_len)) goto err; if (seed2 && !EVP_DigestSignUpdate(&ctx,seed2,seed2_len)) goto err; if (seed3 && !EVP_DigestSignUpdate(&ctx,seed3,seed3_len)) goto err; if (seed4 && !EVP_DigestSignUpdate(&ctx,seed4,seed4_len)) goto err; if (seed5 && !EVP_DigestSignUpdate(&ctx,seed5,seed5_len)) goto err; if (olen > chunk) { if (!EVP_DigestSignFinal(&ctx,out,&j)) goto err; out+=j; olen-=j; /* calc the next A1 value */ if (!EVP_DigestSignFinal(&ctx_tmp,A1,&A1_len)) goto err; } else /* last one */ { if (!EVP_DigestSignFinal(&ctx,A1,&A1_len)) goto err; memcpy(out,A1,olen); break; } } ret = 1; err: EVP_PKEY_free(mac_key); EVP_MD_CTX_cleanup(&ctx); EVP_MD_CTX_cleanup(&ctx_tmp); OPENSSL_cleanse(A1,sizeof(A1)); return ret; }
@@ -414,15 +414,20 @@ int tls1_change_cipher_state(SSL *s, int which) s->mac_flags |= SSL_MAC_FLAG_WRITE_MAC_STREAM; else s->mac_flags &= ~SSL_MAC_FLAG_WRITE_MAC_STREAM; - if (s->enc_write_ctx != NULL) + if (s->enc_write_ctx != NULL && !SSL_IS_DTLS(s)) reuse_dd = 1; - else if ((s->enc_write_ctx=OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL) + else if ((s->enc_write_ctx=EVP_CIPHER_CTX_new()) == NULL) goto err; - else - /* make sure it's intialized in case we exit later with an error */ - EVP_CIPHER_CTX_init(s->enc_write_ctx); dd= s->enc_write_ctx; - mac_ctx = ssl_replace_hash(&s->write_hash,NULL); + if (SSL_IS_DTLS(s)) + { + mac_ctx = EVP_MD_CTX_create(); + if (!mac_ctx) + goto err; + s->write_hash = mac_ctx; + } + else + mac_ctx = ssl_replace_hash(&s->write_hash,NULL); #ifndef OPENSSL_NO_COMP if (s->compress != NULL) {
CWE-310
null
null
12,373
int tls1_cert_verify_mac(SSL *s, int md_nid, unsigned char *out) { unsigned int ret; EVP_MD_CTX ctx, *d=NULL; int i; if (s->s3->handshake_buffer) if (!ssl3_digest_cached_records(s)) return 0; for (i=0;i<SSL_MAX_DIGEST;i++) { if (s->s3->handshake_dgst[i]&&EVP_MD_CTX_type(s->s3->handshake_dgst[i])==md_nid) { d=s->s3->handshake_dgst[i]; break; } } if (!d) { SSLerr(SSL_F_TLS1_CERT_VERIFY_MAC,SSL_R_NO_REQUIRED_DIGEST); return 0; } EVP_MD_CTX_init(&ctx); EVP_MD_CTX_copy_ex(&ctx,d); EVP_DigestFinal_ex(&ctx,out,&ret); EVP_MD_CTX_cleanup(&ctx); return((int)ret); }
DoS
0
int tls1_cert_verify_mac(SSL *s, int md_nid, unsigned char *out) { unsigned int ret; EVP_MD_CTX ctx, *d=NULL; int i; if (s->s3->handshake_buffer) if (!ssl3_digest_cached_records(s)) return 0; for (i=0;i<SSL_MAX_DIGEST;i++) { if (s->s3->handshake_dgst[i]&&EVP_MD_CTX_type(s->s3->handshake_dgst[i])==md_nid) { d=s->s3->handshake_dgst[i]; break; } } if (!d) { SSLerr(SSL_F_TLS1_CERT_VERIFY_MAC,SSL_R_NO_REQUIRED_DIGEST); return 0; } EVP_MD_CTX_init(&ctx); EVP_MD_CTX_copy_ex(&ctx,d); EVP_DigestFinal_ex(&ctx,out,&ret); EVP_MD_CTX_cleanup(&ctx); return((int)ret); }
@@ -414,15 +414,20 @@ int tls1_change_cipher_state(SSL *s, int which) s->mac_flags |= SSL_MAC_FLAG_WRITE_MAC_STREAM; else s->mac_flags &= ~SSL_MAC_FLAG_WRITE_MAC_STREAM; - if (s->enc_write_ctx != NULL) + if (s->enc_write_ctx != NULL && !SSL_IS_DTLS(s)) reuse_dd = 1; - else if ((s->enc_write_ctx=OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL) + else if ((s->enc_write_ctx=EVP_CIPHER_CTX_new()) == NULL) goto err; - else - /* make sure it's intialized in case we exit later with an error */ - EVP_CIPHER_CTX_init(s->enc_write_ctx); dd= s->enc_write_ctx; - mac_ctx = ssl_replace_hash(&s->write_hash,NULL); + if (SSL_IS_DTLS(s)) + { + mac_ctx = EVP_MD_CTX_create(); + if (!mac_ctx) + goto err; + s->write_hash = mac_ctx; + } + else + mac_ctx = ssl_replace_hash(&s->write_hash,NULL); #ifndef OPENSSL_NO_COMP if (s->compress != NULL) {
CWE-310
null
null
12,374
int tls1_enc(SSL *s, int send) { SSL3_RECORD *rec; EVP_CIPHER_CTX *ds; unsigned long l; int bs,i,j,k,pad=0,ret,mac_size=0; const EVP_CIPHER *enc; if (send) { if (EVP_MD_CTX_md(s->write_hash)) { int n=EVP_MD_CTX_size(s->write_hash); OPENSSL_assert(n >= 0); } ds=s->enc_write_ctx; rec= &(s->s3->wrec); if (s->enc_write_ctx == NULL) enc=NULL; else { int ivlen; enc=EVP_CIPHER_CTX_cipher(s->enc_write_ctx); /* For TLSv1.1 and later explicit IV */ if (s->version >= TLS1_1_VERSION && EVP_CIPHER_mode(enc) == EVP_CIPH_CBC_MODE) ivlen = EVP_CIPHER_iv_length(enc); else ivlen = 0; if (ivlen > 1) { if ( rec->data != rec->input) /* we can't write into the input stream: * Can this ever happen?? (steve) */ fprintf(stderr, "%s:%d: rec->data != rec->input\n", __FILE__, __LINE__); else if (RAND_bytes(rec->input, ivlen) <= 0) return -1; } } } else { if (EVP_MD_CTX_md(s->read_hash)) { int n=EVP_MD_CTX_size(s->read_hash); OPENSSL_assert(n >= 0); } ds=s->enc_read_ctx; rec= &(s->s3->rrec); if (s->enc_read_ctx == NULL) enc=NULL; else enc=EVP_CIPHER_CTX_cipher(s->enc_read_ctx); } #ifdef KSSL_DEBUG printf("tls1_enc(%d)\n", send); #endif /* KSSL_DEBUG */ if ((s->session == NULL) || (ds == NULL) || (enc == NULL)) { memmove(rec->data,rec->input,rec->length); rec->input=rec->data; ret = 1; } else { l=rec->length; bs=EVP_CIPHER_block_size(ds->cipher); if (EVP_CIPHER_flags(ds->cipher)&EVP_CIPH_FLAG_AEAD_CIPHER) { unsigned char buf[13],*seq; seq = send?s->s3->write_sequence:s->s3->read_sequence; if (s->version == DTLS1_VERSION || s->version == DTLS1_BAD_VER) { unsigned char dtlsseq[9],*p=dtlsseq; s2n(send?s->d1->w_epoch:s->d1->r_epoch,p); memcpy(p,&seq[2],6); memcpy(buf,dtlsseq,8); } else { memcpy(buf,seq,8); for (i=7; i>=0; i--) /* increment */ { ++seq[i]; if (seq[i] != 0) break; } } buf[8]=rec->type; buf[9]=(unsigned char)(s->version>>8); buf[10]=(unsigned char)(s->version); buf[11]=rec->length>>8; buf[12]=rec->length&0xff; pad=EVP_CIPHER_CTX_ctrl(ds,EVP_CTRL_AEAD_TLS1_AAD,13,buf); if (send) { l+=pad; rec->length+=pad; } } else if ((bs != 1) && send) { i=bs-((int)l%bs); /* Add weird padding of upto 256 bytes */ /* we need to add 'i' padding bytes of value j */ j=i-1; if (s->options & SSL_OP_TLS_BLOCK_PADDING_BUG) { if (s->s3->flags & TLS1_FLAGS_TLS_PADDING_BUG) j++; } for (k=(int)l; k<(int)(l+i); k++) rec->input[k]=j; l+=i; rec->length+=i; } #ifdef KSSL_DEBUG { unsigned long ui; printf("EVP_Cipher(ds=%p,rec->data=%p,rec->input=%p,l=%ld) ==>\n", ds,rec->data,rec->input,l); printf("\tEVP_CIPHER_CTX: %d buf_len, %d key_len [%d %d], %d iv_len\n", ds->buf_len, ds->cipher->key_len, DES_KEY_SZ, DES_SCHEDULE_SZ, ds->cipher->iv_len); printf("\t\tIV: "); for (i=0; i<ds->cipher->iv_len; i++) printf("%02X", ds->iv[i]); printf("\n"); printf("\trec->input="); for (ui=0; ui<l; ui++) printf(" %02x", rec->input[ui]); printf("\n"); } #endif /* KSSL_DEBUG */ if (!send) { if (l == 0 || l%bs != 0) return 0; } i = EVP_Cipher(ds,rec->data,rec->input,l); if ((EVP_CIPHER_flags(ds->cipher)&EVP_CIPH_FLAG_CUSTOM_CIPHER) ?(i<0) :(i==0)) return -1; /* AEAD can fail to verify MAC */ if (EVP_CIPHER_mode(enc) == EVP_CIPH_GCM_MODE && !send) { rec->data += EVP_GCM_TLS_EXPLICIT_IV_LEN; rec->input += EVP_GCM_TLS_EXPLICIT_IV_LEN; rec->length -= EVP_GCM_TLS_EXPLICIT_IV_LEN; } #ifdef KSSL_DEBUG { unsigned long i; printf("\trec->data="); for (i=0; i<l; i++) printf(" %02x", rec->data[i]); printf("\n"); } #endif /* KSSL_DEBUG */ ret = 1; if (EVP_MD_CTX_md(s->read_hash) != NULL) mac_size = EVP_MD_CTX_size(s->read_hash); if ((bs != 1) && !send) ret = tls1_cbc_remove_padding(s, rec, bs, mac_size); if (pad && !send) rec->length -= pad; } return ret; }
DoS
0
int tls1_enc(SSL *s, int send) { SSL3_RECORD *rec; EVP_CIPHER_CTX *ds; unsigned long l; int bs,i,j,k,pad=0,ret,mac_size=0; const EVP_CIPHER *enc; if (send) { if (EVP_MD_CTX_md(s->write_hash)) { int n=EVP_MD_CTX_size(s->write_hash); OPENSSL_assert(n >= 0); } ds=s->enc_write_ctx; rec= &(s->s3->wrec); if (s->enc_write_ctx == NULL) enc=NULL; else { int ivlen; enc=EVP_CIPHER_CTX_cipher(s->enc_write_ctx); /* For TLSv1.1 and later explicit IV */ if (s->version >= TLS1_1_VERSION && EVP_CIPHER_mode(enc) == EVP_CIPH_CBC_MODE) ivlen = EVP_CIPHER_iv_length(enc); else ivlen = 0; if (ivlen > 1) { if ( rec->data != rec->input) /* we can't write into the input stream: * Can this ever happen?? (steve) */ fprintf(stderr, "%s:%d: rec->data != rec->input\n", __FILE__, __LINE__); else if (RAND_bytes(rec->input, ivlen) <= 0) return -1; } } } else { if (EVP_MD_CTX_md(s->read_hash)) { int n=EVP_MD_CTX_size(s->read_hash); OPENSSL_assert(n >= 0); } ds=s->enc_read_ctx; rec= &(s->s3->rrec); if (s->enc_read_ctx == NULL) enc=NULL; else enc=EVP_CIPHER_CTX_cipher(s->enc_read_ctx); } #ifdef KSSL_DEBUG printf("tls1_enc(%d)\n", send); #endif /* KSSL_DEBUG */ if ((s->session == NULL) || (ds == NULL) || (enc == NULL)) { memmove(rec->data,rec->input,rec->length); rec->input=rec->data; ret = 1; } else { l=rec->length; bs=EVP_CIPHER_block_size(ds->cipher); if (EVP_CIPHER_flags(ds->cipher)&EVP_CIPH_FLAG_AEAD_CIPHER) { unsigned char buf[13],*seq; seq = send?s->s3->write_sequence:s->s3->read_sequence; if (s->version == DTLS1_VERSION || s->version == DTLS1_BAD_VER) { unsigned char dtlsseq[9],*p=dtlsseq; s2n(send?s->d1->w_epoch:s->d1->r_epoch,p); memcpy(p,&seq[2],6); memcpy(buf,dtlsseq,8); } else { memcpy(buf,seq,8); for (i=7; i>=0; i--) /* increment */ { ++seq[i]; if (seq[i] != 0) break; } } buf[8]=rec->type; buf[9]=(unsigned char)(s->version>>8); buf[10]=(unsigned char)(s->version); buf[11]=rec->length>>8; buf[12]=rec->length&0xff; pad=EVP_CIPHER_CTX_ctrl(ds,EVP_CTRL_AEAD_TLS1_AAD,13,buf); if (send) { l+=pad; rec->length+=pad; } } else if ((bs != 1) && send) { i=bs-((int)l%bs); /* Add weird padding of upto 256 bytes */ /* we need to add 'i' padding bytes of value j */ j=i-1; if (s->options & SSL_OP_TLS_BLOCK_PADDING_BUG) { if (s->s3->flags & TLS1_FLAGS_TLS_PADDING_BUG) j++; } for (k=(int)l; k<(int)(l+i); k++) rec->input[k]=j; l+=i; rec->length+=i; } #ifdef KSSL_DEBUG { unsigned long ui; printf("EVP_Cipher(ds=%p,rec->data=%p,rec->input=%p,l=%ld) ==>\n", ds,rec->data,rec->input,l); printf("\tEVP_CIPHER_CTX: %d buf_len, %d key_len [%d %d], %d iv_len\n", ds->buf_len, ds->cipher->key_len, DES_KEY_SZ, DES_SCHEDULE_SZ, ds->cipher->iv_len); printf("\t\tIV: "); for (i=0; i<ds->cipher->iv_len; i++) printf("%02X", ds->iv[i]); printf("\n"); printf("\trec->input="); for (ui=0; ui<l; ui++) printf(" %02x", rec->input[ui]); printf("\n"); } #endif /* KSSL_DEBUG */ if (!send) { if (l == 0 || l%bs != 0) return 0; } i = EVP_Cipher(ds,rec->data,rec->input,l); if ((EVP_CIPHER_flags(ds->cipher)&EVP_CIPH_FLAG_CUSTOM_CIPHER) ?(i<0) :(i==0)) return -1; /* AEAD can fail to verify MAC */ if (EVP_CIPHER_mode(enc) == EVP_CIPH_GCM_MODE && !send) { rec->data += EVP_GCM_TLS_EXPLICIT_IV_LEN; rec->input += EVP_GCM_TLS_EXPLICIT_IV_LEN; rec->length -= EVP_GCM_TLS_EXPLICIT_IV_LEN; } #ifdef KSSL_DEBUG { unsigned long i; printf("\trec->data="); for (i=0; i<l; i++) printf(" %02x", rec->data[i]); printf("\n"); } #endif /* KSSL_DEBUG */ ret = 1; if (EVP_MD_CTX_md(s->read_hash) != NULL) mac_size = EVP_MD_CTX_size(s->read_hash); if ((bs != 1) && !send) ret = tls1_cbc_remove_padding(s, rec, bs, mac_size); if (pad && !send) rec->length -= pad; } return ret; }
@@ -414,15 +414,20 @@ int tls1_change_cipher_state(SSL *s, int which) s->mac_flags |= SSL_MAC_FLAG_WRITE_MAC_STREAM; else s->mac_flags &= ~SSL_MAC_FLAG_WRITE_MAC_STREAM; - if (s->enc_write_ctx != NULL) + if (s->enc_write_ctx != NULL && !SSL_IS_DTLS(s)) reuse_dd = 1; - else if ((s->enc_write_ctx=OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL) + else if ((s->enc_write_ctx=EVP_CIPHER_CTX_new()) == NULL) goto err; - else - /* make sure it's intialized in case we exit later with an error */ - EVP_CIPHER_CTX_init(s->enc_write_ctx); dd= s->enc_write_ctx; - mac_ctx = ssl_replace_hash(&s->write_hash,NULL); + if (SSL_IS_DTLS(s)) + { + mac_ctx = EVP_MD_CTX_create(); + if (!mac_ctx) + goto err; + s->write_hash = mac_ctx; + } + else + mac_ctx = ssl_replace_hash(&s->write_hash,NULL); #ifndef OPENSSL_NO_COMP if (s->compress != NULL) {
CWE-310
null
null
12,375
int tls1_final_finish_mac(SSL *s, const char *str, int slen, unsigned char *out) { unsigned int i; EVP_MD_CTX ctx; unsigned char buf[2*EVP_MAX_MD_SIZE]; unsigned char *q,buf2[12]; int idx; long mask; int err=0; const EVP_MD *md; q=buf; if (s->s3->handshake_buffer) if (!ssl3_digest_cached_records(s)) return 0; EVP_MD_CTX_init(&ctx); for (idx=0;ssl_get_handshake_digest(idx,&mask,&md);idx++) { if (mask & ssl_get_algorithm2(s)) { int hashsize = EVP_MD_size(md); EVP_MD_CTX *hdgst = s->s3->handshake_dgst[idx]; if (!hdgst || hashsize < 0 || hashsize > (int)(sizeof buf - (size_t)(q-buf))) { /* internal error: 'buf' is too small for this cipersuite! */ err = 1; } else { if (!EVP_MD_CTX_copy_ex(&ctx, hdgst) || !EVP_DigestFinal_ex(&ctx,q,&i) || (i != (unsigned int)hashsize)) err = 1; q+=hashsize; } } } if (!tls1_PRF(ssl_get_algorithm2(s), str,slen, buf,(int)(q-buf), NULL,0, NULL,0, NULL,0, s->session->master_key,s->session->master_key_length, out,buf2,sizeof buf2)) err = 1; EVP_MD_CTX_cleanup(&ctx); if (err) return 0; else return sizeof buf2; }
DoS
0
int tls1_final_finish_mac(SSL *s, const char *str, int slen, unsigned char *out) { unsigned int i; EVP_MD_CTX ctx; unsigned char buf[2*EVP_MAX_MD_SIZE]; unsigned char *q,buf2[12]; int idx; long mask; int err=0; const EVP_MD *md; q=buf; if (s->s3->handshake_buffer) if (!ssl3_digest_cached_records(s)) return 0; EVP_MD_CTX_init(&ctx); for (idx=0;ssl_get_handshake_digest(idx,&mask,&md);idx++) { if (mask & ssl_get_algorithm2(s)) { int hashsize = EVP_MD_size(md); EVP_MD_CTX *hdgst = s->s3->handshake_dgst[idx]; if (!hdgst || hashsize < 0 || hashsize > (int)(sizeof buf - (size_t)(q-buf))) { /* internal error: 'buf' is too small for this cipersuite! */ err = 1; } else { if (!EVP_MD_CTX_copy_ex(&ctx, hdgst) || !EVP_DigestFinal_ex(&ctx,q,&i) || (i != (unsigned int)hashsize)) err = 1; q+=hashsize; } } } if (!tls1_PRF(ssl_get_algorithm2(s), str,slen, buf,(int)(q-buf), NULL,0, NULL,0, NULL,0, s->session->master_key,s->session->master_key_length, out,buf2,sizeof buf2)) err = 1; EVP_MD_CTX_cleanup(&ctx); if (err) return 0; else return sizeof buf2; }
@@ -414,15 +414,20 @@ int tls1_change_cipher_state(SSL *s, int which) s->mac_flags |= SSL_MAC_FLAG_WRITE_MAC_STREAM; else s->mac_flags &= ~SSL_MAC_FLAG_WRITE_MAC_STREAM; - if (s->enc_write_ctx != NULL) + if (s->enc_write_ctx != NULL && !SSL_IS_DTLS(s)) reuse_dd = 1; - else if ((s->enc_write_ctx=OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL) + else if ((s->enc_write_ctx=EVP_CIPHER_CTX_new()) == NULL) goto err; - else - /* make sure it's intialized in case we exit later with an error */ - EVP_CIPHER_CTX_init(s->enc_write_ctx); dd= s->enc_write_ctx; - mac_ctx = ssl_replace_hash(&s->write_hash,NULL); + if (SSL_IS_DTLS(s)) + { + mac_ctx = EVP_MD_CTX_create(); + if (!mac_ctx) + goto err; + s->write_hash = mac_ctx; + } + else + mac_ctx = ssl_replace_hash(&s->write_hash,NULL); #ifndef OPENSSL_NO_COMP if (s->compress != NULL) {
CWE-310
null
null
12,376
static int tls1_generate_key_block(SSL *s, unsigned char *km, unsigned char *tmp, int num) { int ret; ret = tls1_PRF(ssl_get_algorithm2(s), TLS_MD_KEY_EXPANSION_CONST,TLS_MD_KEY_EXPANSION_CONST_SIZE, s->s3->server_random,SSL3_RANDOM_SIZE, s->s3->client_random,SSL3_RANDOM_SIZE, NULL,0,NULL,0, s->session->master_key,s->session->master_key_length, km,tmp,num); #ifdef KSSL_DEBUG printf("tls1_generate_key_block() ==> %d byte master_key =\n\t", s->session->master_key_length); { int i; for (i=0; i < s->session->master_key_length; i++) { printf("%02X", s->session->master_key[i]); } printf("\n"); } #endif /* KSSL_DEBUG */ return ret; }
DoS
0
static int tls1_generate_key_block(SSL *s, unsigned char *km, unsigned char *tmp, int num) { int ret; ret = tls1_PRF(ssl_get_algorithm2(s), TLS_MD_KEY_EXPANSION_CONST,TLS_MD_KEY_EXPANSION_CONST_SIZE, s->s3->server_random,SSL3_RANDOM_SIZE, s->s3->client_random,SSL3_RANDOM_SIZE, NULL,0,NULL,0, s->session->master_key,s->session->master_key_length, km,tmp,num); #ifdef KSSL_DEBUG printf("tls1_generate_key_block() ==> %d byte master_key =\n\t", s->session->master_key_length); { int i; for (i=0; i < s->session->master_key_length; i++) { printf("%02X", s->session->master_key[i]); } printf("\n"); } #endif /* KSSL_DEBUG */ return ret; }
@@ -414,15 +414,20 @@ int tls1_change_cipher_state(SSL *s, int which) s->mac_flags |= SSL_MAC_FLAG_WRITE_MAC_STREAM; else s->mac_flags &= ~SSL_MAC_FLAG_WRITE_MAC_STREAM; - if (s->enc_write_ctx != NULL) + if (s->enc_write_ctx != NULL && !SSL_IS_DTLS(s)) reuse_dd = 1; - else if ((s->enc_write_ctx=OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL) + else if ((s->enc_write_ctx=EVP_CIPHER_CTX_new()) == NULL) goto err; - else - /* make sure it's intialized in case we exit later with an error */ - EVP_CIPHER_CTX_init(s->enc_write_ctx); dd= s->enc_write_ctx; - mac_ctx = ssl_replace_hash(&s->write_hash,NULL); + if (SSL_IS_DTLS(s)) + { + mac_ctx = EVP_MD_CTX_create(); + if (!mac_ctx) + goto err; + s->write_hash = mac_ctx; + } + else + mac_ctx = ssl_replace_hash(&s->write_hash,NULL); #ifndef OPENSSL_NO_COMP if (s->compress != NULL) {
CWE-310
null
null
12,377
int tls1_generate_master_secret(SSL *s, unsigned char *out, unsigned char *p, int len) { unsigned char buff[SSL_MAX_MASTER_KEY_LENGTH]; const void *co = NULL, *so = NULL; int col = 0, sol = 0; #ifdef KSSL_DEBUG printf ("tls1_generate_master_secret(%p,%p, %p, %d)\n", s,out, p,len); #endif /* KSSL_DEBUG */ #ifdef TLSEXT_TYPE_opaque_prf_input if (s->s3->client_opaque_prf_input != NULL && s->s3->server_opaque_prf_input != NULL && s->s3->client_opaque_prf_input_len > 0 && s->s3->client_opaque_prf_input_len == s->s3->server_opaque_prf_input_len) { co = s->s3->client_opaque_prf_input; col = s->s3->server_opaque_prf_input_len; so = s->s3->server_opaque_prf_input; sol = s->s3->client_opaque_prf_input_len; /* must be same as col (see draft-rescorla-tls-opaque-prf-input-00.txt, section 3.1) */ } #endif tls1_PRF(ssl_get_algorithm2(s), TLS_MD_MASTER_SECRET_CONST,TLS_MD_MASTER_SECRET_CONST_SIZE, s->s3->client_random,SSL3_RANDOM_SIZE, co, col, s->s3->server_random,SSL3_RANDOM_SIZE, so, sol, p,len, s->session->master_key,buff,sizeof buff); #ifdef SSL_DEBUG fprintf(stderr, "Premaster Secret:\n"); BIO_dump_fp(stderr, (char *)p, len); fprintf(stderr, "Client Random:\n"); BIO_dump_fp(stderr, (char *)s->s3->client_random, SSL3_RANDOM_SIZE); fprintf(stderr, "Server Random:\n"); BIO_dump_fp(stderr, (char *)s->s3->server_random, SSL3_RANDOM_SIZE); fprintf(stderr, "Master Secret:\n"); BIO_dump_fp(stderr, (char *)s->session->master_key, SSL3_MASTER_SECRET_SIZE); #endif #ifdef KSSL_DEBUG printf ("tls1_generate_master_secret() complete\n"); #endif /* KSSL_DEBUG */ return(SSL3_MASTER_SECRET_SIZE); }
DoS
0
int tls1_generate_master_secret(SSL *s, unsigned char *out, unsigned char *p, int len) { unsigned char buff[SSL_MAX_MASTER_KEY_LENGTH]; const void *co = NULL, *so = NULL; int col = 0, sol = 0; #ifdef KSSL_DEBUG printf ("tls1_generate_master_secret(%p,%p, %p, %d)\n", s,out, p,len); #endif /* KSSL_DEBUG */ #ifdef TLSEXT_TYPE_opaque_prf_input if (s->s3->client_opaque_prf_input != NULL && s->s3->server_opaque_prf_input != NULL && s->s3->client_opaque_prf_input_len > 0 && s->s3->client_opaque_prf_input_len == s->s3->server_opaque_prf_input_len) { co = s->s3->client_opaque_prf_input; col = s->s3->server_opaque_prf_input_len; so = s->s3->server_opaque_prf_input; sol = s->s3->client_opaque_prf_input_len; /* must be same as col (see draft-rescorla-tls-opaque-prf-input-00.txt, section 3.1) */ } #endif tls1_PRF(ssl_get_algorithm2(s), TLS_MD_MASTER_SECRET_CONST,TLS_MD_MASTER_SECRET_CONST_SIZE, s->s3->client_random,SSL3_RANDOM_SIZE, co, col, s->s3->server_random,SSL3_RANDOM_SIZE, so, sol, p,len, s->session->master_key,buff,sizeof buff); #ifdef SSL_DEBUG fprintf(stderr, "Premaster Secret:\n"); BIO_dump_fp(stderr, (char *)p, len); fprintf(stderr, "Client Random:\n"); BIO_dump_fp(stderr, (char *)s->s3->client_random, SSL3_RANDOM_SIZE); fprintf(stderr, "Server Random:\n"); BIO_dump_fp(stderr, (char *)s->s3->server_random, SSL3_RANDOM_SIZE); fprintf(stderr, "Master Secret:\n"); BIO_dump_fp(stderr, (char *)s->session->master_key, SSL3_MASTER_SECRET_SIZE); #endif #ifdef KSSL_DEBUG printf ("tls1_generate_master_secret() complete\n"); #endif /* KSSL_DEBUG */ return(SSL3_MASTER_SECRET_SIZE); }
@@ -414,15 +414,20 @@ int tls1_change_cipher_state(SSL *s, int which) s->mac_flags |= SSL_MAC_FLAG_WRITE_MAC_STREAM; else s->mac_flags &= ~SSL_MAC_FLAG_WRITE_MAC_STREAM; - if (s->enc_write_ctx != NULL) + if (s->enc_write_ctx != NULL && !SSL_IS_DTLS(s)) reuse_dd = 1; - else if ((s->enc_write_ctx=OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL) + else if ((s->enc_write_ctx=EVP_CIPHER_CTX_new()) == NULL) goto err; - else - /* make sure it's intialized in case we exit later with an error */ - EVP_CIPHER_CTX_init(s->enc_write_ctx); dd= s->enc_write_ctx; - mac_ctx = ssl_replace_hash(&s->write_hash,NULL); + if (SSL_IS_DTLS(s)) + { + mac_ctx = EVP_MD_CTX_create(); + if (!mac_ctx) + goto err; + s->write_hash = mac_ctx; + } + else + mac_ctx = ssl_replace_hash(&s->write_hash,NULL); #ifndef OPENSSL_NO_COMP if (s->compress != NULL) {
CWE-310
null
null
12,378
int tls1_mac(SSL *ssl, unsigned char *md, int send) { SSL3_RECORD *rec; unsigned char *seq; EVP_MD_CTX *hash; size_t md_size, orig_len; int i; EVP_MD_CTX hmac, *mac_ctx; unsigned char header[13]; int stream_mac = (send?(ssl->mac_flags & SSL_MAC_FLAG_WRITE_MAC_STREAM):(ssl->mac_flags&SSL_MAC_FLAG_READ_MAC_STREAM)); int t; if (send) { rec= &(ssl->s3->wrec); seq= &(ssl->s3->write_sequence[0]); hash=ssl->write_hash; } else { rec= &(ssl->s3->rrec); seq= &(ssl->s3->read_sequence[0]); hash=ssl->read_hash; } t=EVP_MD_CTX_size(hash); OPENSSL_assert(t >= 0); md_size=t; /* I should fix this up TLS TLS TLS TLS TLS XXXXXXXX */ if (stream_mac) { mac_ctx = hash; } else { EVP_MD_CTX_copy(&hmac,hash); mac_ctx = &hmac; } if (ssl->version == DTLS1_VERSION || ssl->version == DTLS1_BAD_VER) { unsigned char dtlsseq[8],*p=dtlsseq; s2n(send?ssl->d1->w_epoch:ssl->d1->r_epoch, p); memcpy (p,&seq[2],6); memcpy(header, dtlsseq, 8); } else memcpy(header, seq, 8); /* kludge: tls1_cbc_remove_padding passes padding length in rec->type */ orig_len = rec->length+md_size+((unsigned int)rec->type>>8); rec->type &= 0xff; header[8]=rec->type; header[9]=(unsigned char)(ssl->version>>8); header[10]=(unsigned char)(ssl->version); header[11]=(rec->length)>>8; header[12]=(rec->length)&0xff; if (!send && EVP_CIPHER_CTX_mode(ssl->enc_read_ctx) == EVP_CIPH_CBC_MODE && ssl3_cbc_record_digest_supported(mac_ctx)) { /* This is a CBC-encrypted record. We must avoid leaking any * timing-side channel information about how many blocks of * data we are hashing because that gives an attacker a * timing-oracle. */ ssl3_cbc_digest_record( mac_ctx, md, &md_size, header, rec->input, rec->length + md_size, orig_len, ssl->s3->read_mac_secret, ssl->s3->read_mac_secret_size, 0 /* not SSLv3 */); } else { EVP_DigestSignUpdate(mac_ctx,header,sizeof(header)); EVP_DigestSignUpdate(mac_ctx,rec->input,rec->length); t=EVP_DigestSignFinal(mac_ctx,md,&md_size); OPENSSL_assert(t > 0); #ifdef OPENSSL_FIPS if (!send && FIPS_mode()) tls_fips_digest_extra( ssl->enc_read_ctx, mac_ctx, rec->input, rec->length, orig_len); #endif } if (!stream_mac) EVP_MD_CTX_cleanup(&hmac); #ifdef TLS_DEBUG printf("sec="); {unsigned int z; for (z=0; z<md_size; z++) printf("%02X ",mac_sec[z]); printf("\n"); } printf("seq="); {int z; for (z=0; z<8; z++) printf("%02X ",seq[z]); printf("\n"); } printf("buf="); {int z; for (z=0; z<5; z++) printf("%02X ",buf[z]); printf("\n"); } printf("rec="); {unsigned int z; for (z=0; z<rec->length; z++) printf("%02X ",buf[z]); printf("\n"); } #endif if (ssl->version != DTLS1_VERSION && ssl->version != DTLS1_BAD_VER) { for (i=7; i>=0; i--) { ++seq[i]; if (seq[i] != 0) break; } } #ifdef TLS_DEBUG {unsigned int z; for (z=0; z<md_size; z++) printf("%02X ",md[z]); printf("\n"); } #endif return(md_size); }
DoS
0
int tls1_mac(SSL *ssl, unsigned char *md, int send) { SSL3_RECORD *rec; unsigned char *seq; EVP_MD_CTX *hash; size_t md_size, orig_len; int i; EVP_MD_CTX hmac, *mac_ctx; unsigned char header[13]; int stream_mac = (send?(ssl->mac_flags & SSL_MAC_FLAG_WRITE_MAC_STREAM):(ssl->mac_flags&SSL_MAC_FLAG_READ_MAC_STREAM)); int t; if (send) { rec= &(ssl->s3->wrec); seq= &(ssl->s3->write_sequence[0]); hash=ssl->write_hash; } else { rec= &(ssl->s3->rrec); seq= &(ssl->s3->read_sequence[0]); hash=ssl->read_hash; } t=EVP_MD_CTX_size(hash); OPENSSL_assert(t >= 0); md_size=t; /* I should fix this up TLS TLS TLS TLS TLS XXXXXXXX */ if (stream_mac) { mac_ctx = hash; } else { EVP_MD_CTX_copy(&hmac,hash); mac_ctx = &hmac; } if (ssl->version == DTLS1_VERSION || ssl->version == DTLS1_BAD_VER) { unsigned char dtlsseq[8],*p=dtlsseq; s2n(send?ssl->d1->w_epoch:ssl->d1->r_epoch, p); memcpy (p,&seq[2],6); memcpy(header, dtlsseq, 8); } else memcpy(header, seq, 8); /* kludge: tls1_cbc_remove_padding passes padding length in rec->type */ orig_len = rec->length+md_size+((unsigned int)rec->type>>8); rec->type &= 0xff; header[8]=rec->type; header[9]=(unsigned char)(ssl->version>>8); header[10]=(unsigned char)(ssl->version); header[11]=(rec->length)>>8; header[12]=(rec->length)&0xff; if (!send && EVP_CIPHER_CTX_mode(ssl->enc_read_ctx) == EVP_CIPH_CBC_MODE && ssl3_cbc_record_digest_supported(mac_ctx)) { /* This is a CBC-encrypted record. We must avoid leaking any * timing-side channel information about how many blocks of * data we are hashing because that gives an attacker a * timing-oracle. */ ssl3_cbc_digest_record( mac_ctx, md, &md_size, header, rec->input, rec->length + md_size, orig_len, ssl->s3->read_mac_secret, ssl->s3->read_mac_secret_size, 0 /* not SSLv3 */); } else { EVP_DigestSignUpdate(mac_ctx,header,sizeof(header)); EVP_DigestSignUpdate(mac_ctx,rec->input,rec->length); t=EVP_DigestSignFinal(mac_ctx,md,&md_size); OPENSSL_assert(t > 0); #ifdef OPENSSL_FIPS if (!send && FIPS_mode()) tls_fips_digest_extra( ssl->enc_read_ctx, mac_ctx, rec->input, rec->length, orig_len); #endif } if (!stream_mac) EVP_MD_CTX_cleanup(&hmac); #ifdef TLS_DEBUG printf("sec="); {unsigned int z; for (z=0; z<md_size; z++) printf("%02X ",mac_sec[z]); printf("\n"); } printf("seq="); {int z; for (z=0; z<8; z++) printf("%02X ",seq[z]); printf("\n"); } printf("buf="); {int z; for (z=0; z<5; z++) printf("%02X ",buf[z]); printf("\n"); } printf("rec="); {unsigned int z; for (z=0; z<rec->length; z++) printf("%02X ",buf[z]); printf("\n"); } #endif if (ssl->version != DTLS1_VERSION && ssl->version != DTLS1_BAD_VER) { for (i=7; i>=0; i--) { ++seq[i]; if (seq[i] != 0) break; } } #ifdef TLS_DEBUG {unsigned int z; for (z=0; z<md_size; z++) printf("%02X ",md[z]); printf("\n"); } #endif return(md_size); }
@@ -414,15 +414,20 @@ int tls1_change_cipher_state(SSL *s, int which) s->mac_flags |= SSL_MAC_FLAG_WRITE_MAC_STREAM; else s->mac_flags &= ~SSL_MAC_FLAG_WRITE_MAC_STREAM; - if (s->enc_write_ctx != NULL) + if (s->enc_write_ctx != NULL && !SSL_IS_DTLS(s)) reuse_dd = 1; - else if ((s->enc_write_ctx=OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL) + else if ((s->enc_write_ctx=EVP_CIPHER_CTX_new()) == NULL) goto err; - else - /* make sure it's intialized in case we exit later with an error */ - EVP_CIPHER_CTX_init(s->enc_write_ctx); dd= s->enc_write_ctx; - mac_ctx = ssl_replace_hash(&s->write_hash,NULL); + if (SSL_IS_DTLS(s)) + { + mac_ctx = EVP_MD_CTX_create(); + if (!mac_ctx) + goto err; + s->write_hash = mac_ctx; + } + else + mac_ctx = ssl_replace_hash(&s->write_hash,NULL); #ifndef OPENSSL_NO_COMP if (s->compress != NULL) {
CWE-310
null
null
12,379
__imlib_RenderDisconnect(Display * d) { if (d != disp) return; disp = NULL; gc = gcm = NULL; last_depth = 0; }
DoS Overflow
0
__imlib_RenderDisconnect(Display * d) { if (d != disp) return; disp = NULL; gc = gcm = NULL; last_depth = 0; }
@@ -16,10 +16,6 @@ #include "scale.h" #include "ximage.h" -/* The maximum pixmap dimension is 65535. */ -/* However, for now, use 46340 (46340^2 < 2^31) to avoid buffer overflow issues. */ -#define X_MAX_DIM 46340 - /* size of the lines per segment we scale / render at a time */ #define LINESIZE 16
null
null
null
12,380
__imlib_RenderImage(Display * d, ImlibImage * im, Drawable w, Drawable m, Visual * v, Colormap cm, int depth, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, char antialias, char hiq, char blend, char dither_mask, int mat, ImlibColorModifier * cmod, ImlibOp op) { XImage *xim = NULL, *mxim = NULL; Context *ct; DATA32 *buf = NULL, *pointer = NULL, *back = NULL; int y, h, hh, jump; XGCValues gcv; ImlibScaleInfo *scaleinfo = NULL; int psx, psy, psw, psh; char shm = 0; ImlibRGBAFunction rgbaer; ImlibMaskFunction masker = NULL; ImlibBlendFunction blender = NULL; #ifdef DO_MMX_ASM int do_mmx; #endif blender = __imlib_GetBlendFunction(op, 1, 0, (!(im->flags & F_HAS_ALPHA)), NULL); /* dont do anything if we have a 0 widht or height image to render */ if ((dw == 0) || (dh == 0)) return; /* if the input rect size < 0 dont render either */ if ((sw <= 0) || (sh <= 0)) return; /* if the output is too big (8k arbitrary limit here) dont bother */ if ((abs(dw) > X_MAX_DIM) || (abs(dh) > X_MAX_DIM)) return; /* clip the source rect to be within the actual image */ psx = sx; psy = sy; psw = sw; psh = sh; CLIP(sx, sy, sw, sh, 0, 0, im->w, im->h); /* clip output coords to clipped input coords */ if (psx != sx) dx = (dx * sx) / psx; if (psy != sy) dy = (dy * sy) / psy; if (psw != sw) dw = (dw * sw) / psw; if (psh != sh) dh = (dh * sh) / psh; /* do a second check to see if we now have invalid coords */ /* dont do anything if we have a 0 widht or height image to render */ if ((dw == 0) || (dh == 0)) return; /* if the input rect size < 0 dont render either */ if ((sw <= 0) || (sh <= 0)) return; /* if the output is too big (8k arbitrary limit here) dont bother */ if ((abs(dw) > X_MAX_DIM) || (abs(dh) > X_MAX_DIM)) return; /* if we are scaling the image at all make a scaling buffer */ if (!((sw == dw) && (sh == dh))) { scaleinfo = __imlib_CalcScaleInfo(im, sw, sh, dw, dh, antialias); if (!scaleinfo) return; } /* Sign not needed anymore */ dw = abs(dw); dh = abs(dh); ct = __imlib_GetContext(d, v, cm, depth); __imlib_RGBASetupContext(ct); if ((blend) && (IMAGE_HAS_ALPHA(im))) { back = malloc(dw * dh * sizeof(DATA32)); if (!__imlib_GrabDrawableToRGBA (back, 0, 0, dw, dh, d, w, 0, v, cm, depth, dx, dy, dw, dh, 0, 1)) { free(back); back = NULL; } } /* get a new XImage - or get one from the cached list */ xim = __imlib_ProduceXImage(d, v, depth, dw, dh, &shm); if (!xim) { __imlib_FreeScaleInfo(scaleinfo); if (back) free(back); return; } if (m) { mxim = __imlib_ProduceXImage(d, v, 1, dw, dh, &shm); if (!mxim) { __imlib_ConsumeXImage(d, xim); __imlib_FreeScaleInfo(scaleinfo); if (back) free(back); return; } memset(mxim->data, 0, mxim->bytes_per_line * mxim->height); } /* if we are scaling the image at all make a scaling buffer */ if (scaleinfo) { /* allocate a buffer to render scaled RGBA data into */ buf = malloc(dw * LINESIZE * sizeof(DATA32)); if (!buf) { __imlib_ConsumeXImage(d, xim); if (m) __imlib_ConsumeXImage(d, mxim); __imlib_FreeScaleInfo(scaleinfo); if (back) free(back); return; } } /* setup h */ h = dh; /* scale in LINESIZE Y chunks and convert to depth */ /* Get rgba and mask functions for XImage rendering */ rgbaer = __imlib_GetRGBAFunction(xim->bits_per_pixel, v->red_mask, v->green_mask, v->blue_mask, hiq, ct->palette_type); if (m) masker = __imlib_GetMaskFunction(dither_mask); #ifdef DO_MMX_ASM do_mmx = __imlib_get_cpuid() & CPUID_MMX; #endif for (y = 0; y < dh; y += LINESIZE) { hh = LINESIZE; if (h < LINESIZE) hh = h; /* if we're scaling it */ if (scaleinfo) { /* scale the imagedata for this LINESIZE lines chunk of image data */ if (antialias) { #ifdef DO_MMX_ASM if (do_mmx) __imlib_Scale_mmx_AARGBA(scaleinfo, buf, ((sx * dw) / sw), ((sy * dh) / sh) + y, 0, 0, dw, hh, dw, im->w); else #endif if (IMAGE_HAS_ALPHA(im)) __imlib_ScaleAARGBA(scaleinfo, buf, ((sx * dw) / sw), ((sy * dh) / sh) + y, 0, 0, dw, hh, dw, im->w); else __imlib_ScaleAARGB(scaleinfo, buf, ((sx * dw) / sw), ((sy * dh) / sh) + y, 0, 0, dw, hh, dw, im->w); } else __imlib_ScaleSampleRGBA(scaleinfo, buf, ((sx * dw) / sw), ((sy * dh) / sh) + y, 0, 0, dw, hh, dw); jump = 0; pointer = buf; if (cmod) __imlib_DataCmodApply(buf, dw, hh, 0, NULL, cmod); } else { if (cmod) { if (!buf) buf = malloc(im->w * LINESIZE * sizeof(DATA32)); if (!buf) { __imlib_ConsumeXImage(d, xim); if (m) __imlib_ConsumeXImage(d, mxim); __imlib_FreeScaleInfo(scaleinfo); if (back) free(back); return; } memcpy(buf, im->data + ((y + sy) * im->w), im->w * hh * sizeof(DATA32)); __imlib_DataCmodApply(buf, im->w, hh, 0, NULL, cmod); pointer = buf + sx; jump = im->w - sw; } else { jump = im->w - sw; pointer = im->data + ((y + sy) * im->w) + sx; } } /* if we have a back buffer - we're blending to the bg */ if (back) { blender(pointer, jump + dw, back + (y * dw), dw, dw, hh, NULL); pointer = back + (y * dw); jump = 0; } /* once scaled... convert chunk to bit depth into XImage bufer */ if (rgbaer) rgbaer(pointer, jump, ((DATA8 *) xim->data) + (y * (xim->bytes_per_line)), xim->bytes_per_line, dw, hh, dx, dy + y); else __imlib_generic_render(pointer, jump, dw, hh, 0, y, xim, v, ct); if (m) masker(pointer, jump, ((DATA8 *) mxim->data) + (y * (mxim->bytes_per_line)), mxim->bytes_per_line, dw, hh, dx, dy + y, mat); h -= LINESIZE; } /* free up our buffers and poit tables */ if (buf) free(buf); if (scaleinfo) __imlib_FreeScaleInfo(scaleinfo); if (back) free(back); /* if we changed diplays or depth since last time... free old gc */ if ((gc) && ((last_depth != depth) || (disp != d))) { XFreeGC(disp, gc); gc = 0; } /* if we didn't have a gc... create it */ if (!gc) { disp = d; last_depth = depth; gcv.graphics_exposures = False; gc = XCreateGC(d, w, GCGraphicsExposures, &gcv); } if (m) { /* if we changed diplays since last time... free old gc */ if ((gcm) && (disp != d)) { XFreeGC(disp, gcm); gcm = 0; } if (!gcm) { gcv.graphics_exposures = False; gcm = XCreateGC(d, m, GCGraphicsExposures, &gcv); } /* write the mask */ if (shm) /* write shm XImage */ XShmPutImage(d, m, gcm, mxim, 0, 0, dx, dy, dw, dh, False); /* write regular XImage */ else XPutImage(d, m, gcm, mxim, 0, 0, dx, dy, dw, dh); } /* write the image */ if (shm) /* write shm XImage */ XShmPutImage(d, w, gc, xim, 0, 0, dx, dy, dw, dh, False); /* write regular XImage */ else XPutImage(d, w, gc, xim, 0, 0, dx, dy, dw, dh); /* free the XImage and put onto our free list */ /* wait for the write to be done */ if (shm) XSync(d, False); __imlib_ConsumeXImage(d, xim); if (m) __imlib_ConsumeXImage(d, mxim); }
DoS Overflow
0
__imlib_RenderImage(Display * d, ImlibImage * im, Drawable w, Drawable m, Visual * v, Colormap cm, int depth, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, char antialias, char hiq, char blend, char dither_mask, int mat, ImlibColorModifier * cmod, ImlibOp op) { XImage *xim = NULL, *mxim = NULL; Context *ct; DATA32 *buf = NULL, *pointer = NULL, *back = NULL; int y, h, hh, jump; XGCValues gcv; ImlibScaleInfo *scaleinfo = NULL; int psx, psy, psw, psh; char shm = 0; ImlibRGBAFunction rgbaer; ImlibMaskFunction masker = NULL; ImlibBlendFunction blender = NULL; #ifdef DO_MMX_ASM int do_mmx; #endif blender = __imlib_GetBlendFunction(op, 1, 0, (!(im->flags & F_HAS_ALPHA)), NULL); /* dont do anything if we have a 0 widht or height image to render */ if ((dw == 0) || (dh == 0)) return; /* if the input rect size < 0 dont render either */ if ((sw <= 0) || (sh <= 0)) return; /* if the output is too big (8k arbitrary limit here) dont bother */ if ((abs(dw) > X_MAX_DIM) || (abs(dh) > X_MAX_DIM)) return; /* clip the source rect to be within the actual image */ psx = sx; psy = sy; psw = sw; psh = sh; CLIP(sx, sy, sw, sh, 0, 0, im->w, im->h); /* clip output coords to clipped input coords */ if (psx != sx) dx = (dx * sx) / psx; if (psy != sy) dy = (dy * sy) / psy; if (psw != sw) dw = (dw * sw) / psw; if (psh != sh) dh = (dh * sh) / psh; /* do a second check to see if we now have invalid coords */ /* dont do anything if we have a 0 widht or height image to render */ if ((dw == 0) || (dh == 0)) return; /* if the input rect size < 0 dont render either */ if ((sw <= 0) || (sh <= 0)) return; /* if the output is too big (8k arbitrary limit here) dont bother */ if ((abs(dw) > X_MAX_DIM) || (abs(dh) > X_MAX_DIM)) return; /* if we are scaling the image at all make a scaling buffer */ if (!((sw == dw) && (sh == dh))) { scaleinfo = __imlib_CalcScaleInfo(im, sw, sh, dw, dh, antialias); if (!scaleinfo) return; } /* Sign not needed anymore */ dw = abs(dw); dh = abs(dh); ct = __imlib_GetContext(d, v, cm, depth); __imlib_RGBASetupContext(ct); if ((blend) && (IMAGE_HAS_ALPHA(im))) { back = malloc(dw * dh * sizeof(DATA32)); if (!__imlib_GrabDrawableToRGBA (back, 0, 0, dw, dh, d, w, 0, v, cm, depth, dx, dy, dw, dh, 0, 1)) { free(back); back = NULL; } } /* get a new XImage - or get one from the cached list */ xim = __imlib_ProduceXImage(d, v, depth, dw, dh, &shm); if (!xim) { __imlib_FreeScaleInfo(scaleinfo); if (back) free(back); return; } if (m) { mxim = __imlib_ProduceXImage(d, v, 1, dw, dh, &shm); if (!mxim) { __imlib_ConsumeXImage(d, xim); __imlib_FreeScaleInfo(scaleinfo); if (back) free(back); return; } memset(mxim->data, 0, mxim->bytes_per_line * mxim->height); } /* if we are scaling the image at all make a scaling buffer */ if (scaleinfo) { /* allocate a buffer to render scaled RGBA data into */ buf = malloc(dw * LINESIZE * sizeof(DATA32)); if (!buf) { __imlib_ConsumeXImage(d, xim); if (m) __imlib_ConsumeXImage(d, mxim); __imlib_FreeScaleInfo(scaleinfo); if (back) free(back); return; } } /* setup h */ h = dh; /* scale in LINESIZE Y chunks and convert to depth */ /* Get rgba and mask functions for XImage rendering */ rgbaer = __imlib_GetRGBAFunction(xim->bits_per_pixel, v->red_mask, v->green_mask, v->blue_mask, hiq, ct->palette_type); if (m) masker = __imlib_GetMaskFunction(dither_mask); #ifdef DO_MMX_ASM do_mmx = __imlib_get_cpuid() & CPUID_MMX; #endif for (y = 0; y < dh; y += LINESIZE) { hh = LINESIZE; if (h < LINESIZE) hh = h; /* if we're scaling it */ if (scaleinfo) { /* scale the imagedata for this LINESIZE lines chunk of image data */ if (antialias) { #ifdef DO_MMX_ASM if (do_mmx) __imlib_Scale_mmx_AARGBA(scaleinfo, buf, ((sx * dw) / sw), ((sy * dh) / sh) + y, 0, 0, dw, hh, dw, im->w); else #endif if (IMAGE_HAS_ALPHA(im)) __imlib_ScaleAARGBA(scaleinfo, buf, ((sx * dw) / sw), ((sy * dh) / sh) + y, 0, 0, dw, hh, dw, im->w); else __imlib_ScaleAARGB(scaleinfo, buf, ((sx * dw) / sw), ((sy * dh) / sh) + y, 0, 0, dw, hh, dw, im->w); } else __imlib_ScaleSampleRGBA(scaleinfo, buf, ((sx * dw) / sw), ((sy * dh) / sh) + y, 0, 0, dw, hh, dw); jump = 0; pointer = buf; if (cmod) __imlib_DataCmodApply(buf, dw, hh, 0, NULL, cmod); } else { if (cmod) { if (!buf) buf = malloc(im->w * LINESIZE * sizeof(DATA32)); if (!buf) { __imlib_ConsumeXImage(d, xim); if (m) __imlib_ConsumeXImage(d, mxim); __imlib_FreeScaleInfo(scaleinfo); if (back) free(back); return; } memcpy(buf, im->data + ((y + sy) * im->w), im->w * hh * sizeof(DATA32)); __imlib_DataCmodApply(buf, im->w, hh, 0, NULL, cmod); pointer = buf + sx; jump = im->w - sw; } else { jump = im->w - sw; pointer = im->data + ((y + sy) * im->w) + sx; } } /* if we have a back buffer - we're blending to the bg */ if (back) { blender(pointer, jump + dw, back + (y * dw), dw, dw, hh, NULL); pointer = back + (y * dw); jump = 0; } /* once scaled... convert chunk to bit depth into XImage bufer */ if (rgbaer) rgbaer(pointer, jump, ((DATA8 *) xim->data) + (y * (xim->bytes_per_line)), xim->bytes_per_line, dw, hh, dx, dy + y); else __imlib_generic_render(pointer, jump, dw, hh, 0, y, xim, v, ct); if (m) masker(pointer, jump, ((DATA8 *) mxim->data) + (y * (mxim->bytes_per_line)), mxim->bytes_per_line, dw, hh, dx, dy + y, mat); h -= LINESIZE; } /* free up our buffers and poit tables */ if (buf) free(buf); if (scaleinfo) __imlib_FreeScaleInfo(scaleinfo); if (back) free(back); /* if we changed diplays or depth since last time... free old gc */ if ((gc) && ((last_depth != depth) || (disp != d))) { XFreeGC(disp, gc); gc = 0; } /* if we didn't have a gc... create it */ if (!gc) { disp = d; last_depth = depth; gcv.graphics_exposures = False; gc = XCreateGC(d, w, GCGraphicsExposures, &gcv); } if (m) { /* if we changed diplays since last time... free old gc */ if ((gcm) && (disp != d)) { XFreeGC(disp, gcm); gcm = 0; } if (!gcm) { gcv.graphics_exposures = False; gcm = XCreateGC(d, m, GCGraphicsExposures, &gcv); } /* write the mask */ if (shm) /* write shm XImage */ XShmPutImage(d, m, gcm, mxim, 0, 0, dx, dy, dw, dh, False); /* write regular XImage */ else XPutImage(d, m, gcm, mxim, 0, 0, dx, dy, dw, dh); } /* write the image */ if (shm) /* write shm XImage */ XShmPutImage(d, w, gc, xim, 0, 0, dx, dy, dw, dh, False); /* write regular XImage */ else XPutImage(d, w, gc, xim, 0, 0, dx, dy, dw, dh); /* free the XImage and put onto our free list */ /* wait for the write to be done */ if (shm) XSync(d, False); __imlib_ConsumeXImage(d, xim); if (m) __imlib_ConsumeXImage(d, mxim); }
@@ -16,10 +16,6 @@ #include "scale.h" #include "ximage.h" -/* The maximum pixmap dimension is 65535. */ -/* However, for now, use 46340 (46340^2 < 2^31) to avoid buffer overflow issues. */ -#define X_MAX_DIM 46340 - /* size of the lines per segment we scale / render at a time */ #define LINESIZE 16
null
null
null
12,381
__imlib_generic_render(DATA32 * src, int jump, int w, int h, int dx, int dy, XImage * xim, Visual * v, Context * ct) { int x, y, hh; unsigned int r, g, b, val; unsigned int rmask, gmask, bmask; int i, rshift, gshift, bshift; static const DATA8 _dither_88[8][8] = { {0, 32, 8, 40, 2, 34, 10, 42}, {48, 16, 56, 24, 50, 18, 58, 26}, {12, 44, 4, 36, 14, 46, 6, 38}, {60, 28, 52, 20, 62, 30, 54, 22}, {3, 35, 11, 43, 1, 33, 9, 41}, {51, 19, 59, 27, 49, 17, 57, 25}, {15, 47, 7, 39, 13, 45, 5, 37}, {63, 31, 55, 23, 61, 29, 53, 21} }; if (xim->depth == 1) { hh = dy + h; for (y = dy; y < hh; y++) { for (x = dx; x < w; x++) { r = R_VAL(src); g = G_VAL(src); b = B_VAL(src); val = (R_VAL(src) + G_VAL(src) + B_VAL(src)) / 12; if (val > _dither_88[x & 0x3][y & 0x3]) val = ct->palette[1]; else val = ct->palette[0]; XPutPixel(xim, x, y, val); src++; } } return; } rmask = xim->red_mask; gmask = xim->green_mask; bmask = xim->blue_mask; rshift = 0; gshift = 0; bshift = 0; for (i = 31; i >= 0; i--) { if (rmask >= (1U << i)) { rshift = i - 7; break; } } for (i = 31; i >= 0; i--) { if (gmask >= (1U << i)) { gshift = i - 7; break; } } for (i = 31; i >= 0; i--) { if (bmask >= (1U << i)) { bshift = i - 7; break; } } hh = dy + h; for (y = dy; y < hh; y++) { for (x = dx; x < w; x++) { r = R_VAL(src); if (rshift >= 0) val = ((r << rshift) & rmask); else val = ((r >> (-rshift)) & rmask); g = G_VAL(src); if (gshift >= 0) val |= ((g << gshift) & gmask); else val |= ((g >> (-gshift)) & gmask); b = B_VAL(src); if (bshift >= 0) val |= ((b << bshift) & bmask); else val |= ((b >> (-bshift)) & bmask); XPutPixel(xim, x, y, val); src++; } } }
DoS Overflow
0
__imlib_generic_render(DATA32 * src, int jump, int w, int h, int dx, int dy, XImage * xim, Visual * v, Context * ct) { int x, y, hh; unsigned int r, g, b, val; unsigned int rmask, gmask, bmask; int i, rshift, gshift, bshift; static const DATA8 _dither_88[8][8] = { {0, 32, 8, 40, 2, 34, 10, 42}, {48, 16, 56, 24, 50, 18, 58, 26}, {12, 44, 4, 36, 14, 46, 6, 38}, {60, 28, 52, 20, 62, 30, 54, 22}, {3, 35, 11, 43, 1, 33, 9, 41}, {51, 19, 59, 27, 49, 17, 57, 25}, {15, 47, 7, 39, 13, 45, 5, 37}, {63, 31, 55, 23, 61, 29, 53, 21} }; if (xim->depth == 1) { hh = dy + h; for (y = dy; y < hh; y++) { for (x = dx; x < w; x++) { r = R_VAL(src); g = G_VAL(src); b = B_VAL(src); val = (R_VAL(src) + G_VAL(src) + B_VAL(src)) / 12; if (val > _dither_88[x & 0x3][y & 0x3]) val = ct->palette[1]; else val = ct->palette[0]; XPutPixel(xim, x, y, val); src++; } } return; } rmask = xim->red_mask; gmask = xim->green_mask; bmask = xim->blue_mask; rshift = 0; gshift = 0; bshift = 0; for (i = 31; i >= 0; i--) { if (rmask >= (1U << i)) { rshift = i - 7; break; } } for (i = 31; i >= 0; i--) { if (gmask >= (1U << i)) { gshift = i - 7; break; } } for (i = 31; i >= 0; i--) { if (bmask >= (1U << i)) { bshift = i - 7; break; } } hh = dy + h; for (y = dy; y < hh; y++) { for (x = dx; x < w; x++) { r = R_VAL(src); if (rshift >= 0) val = ((r << rshift) & rmask); else val = ((r >> (-rshift)) & rmask); g = G_VAL(src); if (gshift >= 0) val |= ((g << gshift) & gmask); else val |= ((g >> (-gshift)) & gmask); b = B_VAL(src); if (bshift >= 0) val |= ((b << bshift) & bmask); else val |= ((b >> (-bshift)) & bmask); XPutPixel(xim, x, y, val); src++; } } }
@@ -16,10 +16,6 @@ #include "scale.h" #include "ximage.h" -/* The maximum pixmap dimension is 65535. */ -/* However, for now, use 46340 (46340^2 < 2^31) to avoid buffer overflow issues. */ -#define X_MAX_DIM 46340 - /* size of the lines per segment we scale / render at a time */ #define LINESIZE 16
null
null
null
12,382
_pixman_bits_image_dest_iter_init (pixman_image_t *image, pixman_iter_t *iter) { if (iter->iter_flags & ITER_NARROW) { if ((iter->iter_flags & (ITER_IGNORE_RGB | ITER_IGNORE_ALPHA)) == (ITER_IGNORE_RGB | ITER_IGNORE_ALPHA)) { iter->get_scanline = _pixman_iter_get_scanline_noop; } else { iter->get_scanline = dest_get_scanline_narrow; } iter->write_back = dest_write_back_narrow; } else { iter->get_scanline = dest_get_scanline_wide; iter->write_back = dest_write_back_wide; } }
DoS Exec Code Overflow
0
_pixman_bits_image_dest_iter_init (pixman_image_t *image, pixman_iter_t *iter) { if (iter->iter_flags & ITER_NARROW) { if ((iter->iter_flags & (ITER_IGNORE_RGB | ITER_IGNORE_ALPHA)) == (ITER_IGNORE_RGB | ITER_IGNORE_ALPHA)) { iter->get_scanline = _pixman_iter_get_scanline_noop; } else { iter->get_scanline = dest_get_scanline_narrow; } iter->write_back = dest_write_back_narrow; } else { iter->get_scanline = dest_get_scanline_wide; iter->write_back = dest_write_back_wide; } }
@@ -926,7 +926,7 @@ create_bits (pixman_format_code_t format, if (_pixman_multiply_overflows_size (height, stride)) return NULL; - buf_size = height * stride; + buf_size = (size_t)height * stride; if (rowstride_bytes) *rowstride_bytes = stride;
CWE-189
null
null
12,383
_pixman_bits_image_src_iter_init (pixman_image_t *image, pixman_iter_t *iter) { pixman_format_code_t format = image->common.extended_format_code; uint32_t flags = image->common.flags; const fetcher_info_t *info; for (info = fetcher_info; info->format != PIXMAN_null; ++info) { if ((info->format == format || info->format == PIXMAN_any) && (info->flags & flags) == info->flags) { if (iter->iter_flags & ITER_NARROW) { iter->get_scanline = info->get_scanline_32; } else { iter->data = info->get_scanline_32; iter->get_scanline = info->get_scanline_float; } return; } } /* Just in case we somehow didn't find a scanline function */ iter->get_scanline = _pixman_iter_get_scanline_noop; }
DoS Exec Code Overflow
0
_pixman_bits_image_src_iter_init (pixman_image_t *image, pixman_iter_t *iter) { pixman_format_code_t format = image->common.extended_format_code; uint32_t flags = image->common.flags; const fetcher_info_t *info; for (info = fetcher_info; info->format != PIXMAN_null; ++info) { if ((info->format == format || info->format == PIXMAN_any) && (info->flags & flags) == info->flags) { if (iter->iter_flags & ITER_NARROW) { iter->get_scanline = info->get_scanline_32; } else { iter->data = info->get_scanline_32; iter->get_scanline = info->get_scanline_float; } return; } } /* Just in case we somehow didn't find a scanline function */ iter->get_scanline = _pixman_iter_get_scanline_noop; }
@@ -926,7 +926,7 @@ create_bits (pixman_format_code_t format, if (_pixman_multiply_overflows_size (height, stride)) return NULL; - buf_size = height * stride; + buf_size = (size_t)height * stride; if (rowstride_bytes) *rowstride_bytes = stride;
CWE-189
null
null
12,384
_pixman_image_get_scanline_generic_float (pixman_iter_t * iter, const uint32_t *mask) { pixman_iter_get_scanline_t fetch_32 = iter->data; uint32_t *buffer = iter->buffer; fetch_32 (iter, NULL); pixman_expand_to_float ((argb_t *)buffer, buffer, PIXMAN_a8r8g8b8, iter->width); return iter->buffer; }
DoS Exec Code Overflow
0
_pixman_image_get_scanline_generic_float (pixman_iter_t * iter, const uint32_t *mask) { pixman_iter_get_scanline_t fetch_32 = iter->data; uint32_t *buffer = iter->buffer; fetch_32 (iter, NULL); pixman_expand_to_float ((argb_t *)buffer, buffer, PIXMAN_a8r8g8b8, iter->width); return iter->buffer; }
@@ -926,7 +926,7 @@ create_bits (pixman_format_code_t format, if (_pixman_multiply_overflows_size (height, stride)) return NULL; - buf_size = height * stride; + buf_size = (size_t)height * stride; if (rowstride_bytes) *rowstride_bytes = stride;
CWE-189
null
null
12,385
bits_image_fetch_affine_no_alpha (pixman_iter_t * iter, const uint32_t * mask) { pixman_image_t *image = iter->image; int offset = iter->x; int line = iter->y++; int width = iter->width; uint32_t * buffer = iter->buffer; pixman_fixed_t x, y; pixman_fixed_t ux, uy; pixman_vector_t v; int i; /* reference point is the center of the pixel */ v.vector[0] = pixman_int_to_fixed (offset) + pixman_fixed_1 / 2; v.vector[1] = pixman_int_to_fixed (line) + pixman_fixed_1 / 2; v.vector[2] = pixman_fixed_1; if (image->common.transform) { if (!pixman_transform_point_3d (image->common.transform, &v)) return iter->buffer; ux = image->common.transform->matrix[0][0]; uy = image->common.transform->matrix[1][0]; } else { ux = pixman_fixed_1; uy = 0; } x = v.vector[0]; y = v.vector[1]; for (i = 0; i < width; ++i) { if (!mask || mask[i]) { buffer[i] = bits_image_fetch_pixel_filtered ( &image->bits, x, y, fetch_pixel_no_alpha); } x += ux; y += uy; } return buffer; }
DoS Exec Code Overflow
0
bits_image_fetch_affine_no_alpha (pixman_iter_t * iter, const uint32_t * mask) { pixman_image_t *image = iter->image; int offset = iter->x; int line = iter->y++; int width = iter->width; uint32_t * buffer = iter->buffer; pixman_fixed_t x, y; pixman_fixed_t ux, uy; pixman_vector_t v; int i; /* reference point is the center of the pixel */ v.vector[0] = pixman_int_to_fixed (offset) + pixman_fixed_1 / 2; v.vector[1] = pixman_int_to_fixed (line) + pixman_fixed_1 / 2; v.vector[2] = pixman_fixed_1; if (image->common.transform) { if (!pixman_transform_point_3d (image->common.transform, &v)) return iter->buffer; ux = image->common.transform->matrix[0][0]; uy = image->common.transform->matrix[1][0]; } else { ux = pixman_fixed_1; uy = 0; } x = v.vector[0]; y = v.vector[1]; for (i = 0; i < width; ++i) { if (!mask || mask[i]) { buffer[i] = bits_image_fetch_pixel_filtered ( &image->bits, x, y, fetch_pixel_no_alpha); } x += ux; y += uy; } return buffer; }
@@ -926,7 +926,7 @@ create_bits (pixman_format_code_t format, if (_pixman_multiply_overflows_size (height, stride)) return NULL; - buf_size = height * stride; + buf_size = (size_t)height * stride; if (rowstride_bytes) *rowstride_bytes = stride;
CWE-189
null
null
12,386
bits_image_fetch_pixel_convolution (bits_image_t *image, pixman_fixed_t x, pixman_fixed_t y, get_pixel_t get_pixel) { pixman_fixed_t *params = image->common.filter_params; int x_off = (params[0] - pixman_fixed_1) >> 1; int y_off = (params[1] - pixman_fixed_1) >> 1; int32_t cwidth = pixman_fixed_to_int (params[0]); int32_t cheight = pixman_fixed_to_int (params[1]); int32_t i, j, x1, x2, y1, y2; pixman_repeat_t repeat_mode = image->common.repeat; int width = image->width; int height = image->height; int srtot, sgtot, sbtot, satot; params += 2; x1 = pixman_fixed_to_int (x - pixman_fixed_e - x_off); y1 = pixman_fixed_to_int (y - pixman_fixed_e - y_off); x2 = x1 + cwidth; y2 = y1 + cheight; srtot = sgtot = sbtot = satot = 0; for (i = y1; i < y2; ++i) { for (j = x1; j < x2; ++j) { int rx = j; int ry = i; pixman_fixed_t f = *params; if (f) { uint32_t pixel; if (repeat_mode != PIXMAN_REPEAT_NONE) { repeat (repeat_mode, &rx, width); repeat (repeat_mode, &ry, height); pixel = get_pixel (image, rx, ry, FALSE); } else { pixel = get_pixel (image, rx, ry, TRUE); } srtot += (int)RED_8 (pixel) * f; sgtot += (int)GREEN_8 (pixel) * f; sbtot += (int)BLUE_8 (pixel) * f; satot += (int)ALPHA_8 (pixel) * f; } params++; } } satot = (satot + 0x8000) >> 16; srtot = (srtot + 0x8000) >> 16; sgtot = (sgtot + 0x8000) >> 16; sbtot = (sbtot + 0x8000) >> 16; satot = CLIP (satot, 0, 0xff); srtot = CLIP (srtot, 0, 0xff); sgtot = CLIP (sgtot, 0, 0xff); sbtot = CLIP (sbtot, 0, 0xff); return ((satot << 24) | (srtot << 16) | (sgtot << 8) | (sbtot)); }
DoS Exec Code Overflow
0
bits_image_fetch_pixel_convolution (bits_image_t *image, pixman_fixed_t x, pixman_fixed_t y, get_pixel_t get_pixel) { pixman_fixed_t *params = image->common.filter_params; int x_off = (params[0] - pixman_fixed_1) >> 1; int y_off = (params[1] - pixman_fixed_1) >> 1; int32_t cwidth = pixman_fixed_to_int (params[0]); int32_t cheight = pixman_fixed_to_int (params[1]); int32_t i, j, x1, x2, y1, y2; pixman_repeat_t repeat_mode = image->common.repeat; int width = image->width; int height = image->height; int srtot, sgtot, sbtot, satot; params += 2; x1 = pixman_fixed_to_int (x - pixman_fixed_e - x_off); y1 = pixman_fixed_to_int (y - pixman_fixed_e - y_off); x2 = x1 + cwidth; y2 = y1 + cheight; srtot = sgtot = sbtot = satot = 0; for (i = y1; i < y2; ++i) { for (j = x1; j < x2; ++j) { int rx = j; int ry = i; pixman_fixed_t f = *params; if (f) { uint32_t pixel; if (repeat_mode != PIXMAN_REPEAT_NONE) { repeat (repeat_mode, &rx, width); repeat (repeat_mode, &ry, height); pixel = get_pixel (image, rx, ry, FALSE); } else { pixel = get_pixel (image, rx, ry, TRUE); } srtot += (int)RED_8 (pixel) * f; sgtot += (int)GREEN_8 (pixel) * f; sbtot += (int)BLUE_8 (pixel) * f; satot += (int)ALPHA_8 (pixel) * f; } params++; } } satot = (satot + 0x8000) >> 16; srtot = (srtot + 0x8000) >> 16; sgtot = (sgtot + 0x8000) >> 16; sbtot = (sbtot + 0x8000) >> 16; satot = CLIP (satot, 0, 0xff); srtot = CLIP (srtot, 0, 0xff); sgtot = CLIP (sgtot, 0, 0xff); sbtot = CLIP (sbtot, 0, 0xff); return ((satot << 24) | (srtot << 16) | (sgtot << 8) | (sbtot)); }
@@ -926,7 +926,7 @@ create_bits (pixman_format_code_t format, if (_pixman_multiply_overflows_size (height, stride)) return NULL; - buf_size = height * stride; + buf_size = (size_t)height * stride; if (rowstride_bytes) *rowstride_bytes = stride;
CWE-189
null
null
12,387
bits_image_fetch_pixel_filtered (bits_image_t *image, pixman_fixed_t x, pixman_fixed_t y, get_pixel_t get_pixel) { switch (image->common.filter) { case PIXMAN_FILTER_NEAREST: case PIXMAN_FILTER_FAST: return bits_image_fetch_pixel_nearest (image, x, y, get_pixel); break; case PIXMAN_FILTER_BILINEAR: case PIXMAN_FILTER_GOOD: case PIXMAN_FILTER_BEST: return bits_image_fetch_pixel_bilinear (image, x, y, get_pixel); break; case PIXMAN_FILTER_CONVOLUTION: return bits_image_fetch_pixel_convolution (image, x, y, get_pixel); break; case PIXMAN_FILTER_SEPARABLE_CONVOLUTION: return bits_image_fetch_pixel_separable_convolution (image, x, y, get_pixel); break; default: break; } return 0; }
DoS Exec Code Overflow
0
bits_image_fetch_pixel_filtered (bits_image_t *image, pixman_fixed_t x, pixman_fixed_t y, get_pixel_t get_pixel) { switch (image->common.filter) { case PIXMAN_FILTER_NEAREST: case PIXMAN_FILTER_FAST: return bits_image_fetch_pixel_nearest (image, x, y, get_pixel); break; case PIXMAN_FILTER_BILINEAR: case PIXMAN_FILTER_GOOD: case PIXMAN_FILTER_BEST: return bits_image_fetch_pixel_bilinear (image, x, y, get_pixel); break; case PIXMAN_FILTER_CONVOLUTION: return bits_image_fetch_pixel_convolution (image, x, y, get_pixel); break; case PIXMAN_FILTER_SEPARABLE_CONVOLUTION: return bits_image_fetch_pixel_separable_convolution (image, x, y, get_pixel); break; default: break; } return 0; }
@@ -926,7 +926,7 @@ create_bits (pixman_format_code_t format, if (_pixman_multiply_overflows_size (height, stride)) return NULL; - buf_size = height * stride; + buf_size = (size_t)height * stride; if (rowstride_bytes) *rowstride_bytes = stride;
CWE-189
null
null
12,388
bits_image_fetch_pixel_nearest (bits_image_t *image, pixman_fixed_t x, pixman_fixed_t y, get_pixel_t get_pixel) { int x0 = pixman_fixed_to_int (x - pixman_fixed_e); int y0 = pixman_fixed_to_int (y - pixman_fixed_e); if (image->common.repeat != PIXMAN_REPEAT_NONE) { repeat (image->common.repeat, &x0, image->width); repeat (image->common.repeat, &y0, image->height); return get_pixel (image, x0, y0, FALSE); } else { return get_pixel (image, x0, y0, TRUE); } }
DoS Exec Code Overflow
0
bits_image_fetch_pixel_nearest (bits_image_t *image, pixman_fixed_t x, pixman_fixed_t y, get_pixel_t get_pixel) { int x0 = pixman_fixed_to_int (x - pixman_fixed_e); int y0 = pixman_fixed_to_int (y - pixman_fixed_e); if (image->common.repeat != PIXMAN_REPEAT_NONE) { repeat (image->common.repeat, &x0, image->width); repeat (image->common.repeat, &y0, image->height); return get_pixel (image, x0, y0, FALSE); } else { return get_pixel (image, x0, y0, TRUE); } }
@@ -926,7 +926,7 @@ create_bits (pixman_format_code_t format, if (_pixman_multiply_overflows_size (height, stride)) return NULL; - buf_size = height * stride; + buf_size = (size_t)height * stride; if (rowstride_bytes) *rowstride_bytes = stride;
CWE-189
null
null
12,389
bits_image_fetch_pixel_separable_convolution (bits_image_t *image, pixman_fixed_t x, pixman_fixed_t y, get_pixel_t get_pixel) { pixman_fixed_t *params = image->common.filter_params; pixman_repeat_t repeat_mode = image->common.repeat; int width = image->width; int height = image->height; int cwidth = pixman_fixed_to_int (params[0]); int cheight = pixman_fixed_to_int (params[1]); int x_phase_bits = pixman_fixed_to_int (params[2]); int y_phase_bits = pixman_fixed_to_int (params[3]); int x_phase_shift = 16 - x_phase_bits; int y_phase_shift = 16 - y_phase_bits; int x_off = ((cwidth << 16) - pixman_fixed_1) >> 1; int y_off = ((cheight << 16) - pixman_fixed_1) >> 1; pixman_fixed_t *y_params; int srtot, sgtot, sbtot, satot; int32_t x1, x2, y1, y2; int32_t px, py; int i, j; /* Round x and y to the middle of the closest phase before continuing. This * ensures that the convolution matrix is aligned right, since it was * positioned relative to a particular phase (and not relative to whatever * exact fraction we happen to get here). */ x = ((x >> x_phase_shift) << x_phase_shift) + ((1 << x_phase_shift) >> 1); y = ((y >> y_phase_shift) << y_phase_shift) + ((1 << y_phase_shift) >> 1); px = (x & 0xffff) >> x_phase_shift; py = (y & 0xffff) >> y_phase_shift; y_params = params + 4 + (1 << x_phase_bits) * cwidth + py * cheight; x1 = pixman_fixed_to_int (x - pixman_fixed_e - x_off); y1 = pixman_fixed_to_int (y - pixman_fixed_e - y_off); x2 = x1 + cwidth; y2 = y1 + cheight; srtot = sgtot = sbtot = satot = 0; for (i = y1; i < y2; ++i) { pixman_fixed_48_16_t fy = *y_params++; pixman_fixed_t *x_params = params + 4 + px * cwidth; if (fy) { for (j = x1; j < x2; ++j) { pixman_fixed_t fx = *x_params++; int rx = j; int ry = i; if (fx) { pixman_fixed_t f; uint32_t pixel; if (repeat_mode != PIXMAN_REPEAT_NONE) { repeat (repeat_mode, &rx, width); repeat (repeat_mode, &ry, height); pixel = get_pixel (image, rx, ry, FALSE); } else { pixel = get_pixel (image, rx, ry, TRUE); } f = (fy * fx + 0x8000) >> 16; srtot += (int)RED_8 (pixel) * f; sgtot += (int)GREEN_8 (pixel) * f; sbtot += (int)BLUE_8 (pixel) * f; satot += (int)ALPHA_8 (pixel) * f; } } } } satot = (satot + 0x8000) >> 16; srtot = (srtot + 0x8000) >> 16; sgtot = (sgtot + 0x8000) >> 16; sbtot = (sbtot + 0x8000) >> 16; satot = CLIP (satot, 0, 0xff); srtot = CLIP (srtot, 0, 0xff); sgtot = CLIP (sgtot, 0, 0xff); sbtot = CLIP (sbtot, 0, 0xff); return ((satot << 24) | (srtot << 16) | (sgtot << 8) | (sbtot)); }
DoS Exec Code Overflow
0
bits_image_fetch_pixel_separable_convolution (bits_image_t *image, pixman_fixed_t x, pixman_fixed_t y, get_pixel_t get_pixel) { pixman_fixed_t *params = image->common.filter_params; pixman_repeat_t repeat_mode = image->common.repeat; int width = image->width; int height = image->height; int cwidth = pixman_fixed_to_int (params[0]); int cheight = pixman_fixed_to_int (params[1]); int x_phase_bits = pixman_fixed_to_int (params[2]); int y_phase_bits = pixman_fixed_to_int (params[3]); int x_phase_shift = 16 - x_phase_bits; int y_phase_shift = 16 - y_phase_bits; int x_off = ((cwidth << 16) - pixman_fixed_1) >> 1; int y_off = ((cheight << 16) - pixman_fixed_1) >> 1; pixman_fixed_t *y_params; int srtot, sgtot, sbtot, satot; int32_t x1, x2, y1, y2; int32_t px, py; int i, j; /* Round x and y to the middle of the closest phase before continuing. This * ensures that the convolution matrix is aligned right, since it was * positioned relative to a particular phase (and not relative to whatever * exact fraction we happen to get here). */ x = ((x >> x_phase_shift) << x_phase_shift) + ((1 << x_phase_shift) >> 1); y = ((y >> y_phase_shift) << y_phase_shift) + ((1 << y_phase_shift) >> 1); px = (x & 0xffff) >> x_phase_shift; py = (y & 0xffff) >> y_phase_shift; y_params = params + 4 + (1 << x_phase_bits) * cwidth + py * cheight; x1 = pixman_fixed_to_int (x - pixman_fixed_e - x_off); y1 = pixman_fixed_to_int (y - pixman_fixed_e - y_off); x2 = x1 + cwidth; y2 = y1 + cheight; srtot = sgtot = sbtot = satot = 0; for (i = y1; i < y2; ++i) { pixman_fixed_48_16_t fy = *y_params++; pixman_fixed_t *x_params = params + 4 + px * cwidth; if (fy) { for (j = x1; j < x2; ++j) { pixman_fixed_t fx = *x_params++; int rx = j; int ry = i; if (fx) { pixman_fixed_t f; uint32_t pixel; if (repeat_mode != PIXMAN_REPEAT_NONE) { repeat (repeat_mode, &rx, width); repeat (repeat_mode, &ry, height); pixel = get_pixel (image, rx, ry, FALSE); } else { pixel = get_pixel (image, rx, ry, TRUE); } f = (fy * fx + 0x8000) >> 16; srtot += (int)RED_8 (pixel) * f; sgtot += (int)GREEN_8 (pixel) * f; sbtot += (int)BLUE_8 (pixel) * f; satot += (int)ALPHA_8 (pixel) * f; } } } } satot = (satot + 0x8000) >> 16; srtot = (srtot + 0x8000) >> 16; sgtot = (sgtot + 0x8000) >> 16; sbtot = (sbtot + 0x8000) >> 16; satot = CLIP (satot, 0, 0xff); srtot = CLIP (srtot, 0, 0xff); sgtot = CLIP (sgtot, 0, 0xff); sbtot = CLIP (sbtot, 0, 0xff); return ((satot << 24) | (srtot << 16) | (sgtot << 8) | (sbtot)); }
@@ -926,7 +926,7 @@ create_bits (pixman_format_code_t format, if (_pixman_multiply_overflows_size (height, stride)) return NULL; - buf_size = height * stride; + buf_size = (size_t)height * stride; if (rowstride_bytes) *rowstride_bytes = stride;
CWE-189
null
null
12,390
bits_image_fetch_untransformed_32 (pixman_iter_t * iter, const uint32_t *mask) { pixman_image_t *image = iter->image; int x = iter->x; int y = iter->y; int width = iter->width; uint32_t * buffer = iter->buffer; if (image->common.repeat == PIXMAN_REPEAT_NONE) { bits_image_fetch_untransformed_repeat_none ( &image->bits, FALSE, x, y, width, buffer); } else { bits_image_fetch_untransformed_repeat_normal ( &image->bits, FALSE, x, y, width, buffer); } iter->y++; return buffer; }
DoS Exec Code Overflow
0
bits_image_fetch_untransformed_32 (pixman_iter_t * iter, const uint32_t *mask) { pixman_image_t *image = iter->image; int x = iter->x; int y = iter->y; int width = iter->width; uint32_t * buffer = iter->buffer; if (image->common.repeat == PIXMAN_REPEAT_NONE) { bits_image_fetch_untransformed_repeat_none ( &image->bits, FALSE, x, y, width, buffer); } else { bits_image_fetch_untransformed_repeat_normal ( &image->bits, FALSE, x, y, width, buffer); } iter->y++; return buffer; }
@@ -926,7 +926,7 @@ create_bits (pixman_format_code_t format, if (_pixman_multiply_overflows_size (height, stride)) return NULL; - buf_size = height * stride; + buf_size = (size_t)height * stride; if (rowstride_bytes) *rowstride_bytes = stride;
CWE-189
null
null
12,391
bits_image_fetch_untransformed_repeat_none (bits_image_t *image, pixman_bool_t wide, int x, int y, int width, uint32_t * buffer) { uint32_t w; if (y < 0 || y >= image->height) { memset (buffer, 0, width * (wide? sizeof (argb_t) : 4)); return; } if (x < 0) { w = MIN (width, -x); memset (buffer, 0, w * (wide ? sizeof (argb_t) : 4)); width -= w; buffer += w * (wide? 4 : 1); x += w; } if (x < image->width) { w = MIN (width, image->width - x); if (wide) image->fetch_scanline_float (image, x, y, w, buffer, NULL); else image->fetch_scanline_32 (image, x, y, w, buffer, NULL); width -= w; buffer += w * (wide? 4 : 1); x += w; } memset (buffer, 0, width * (wide ? sizeof (argb_t) : 4)); }
DoS Exec Code Overflow
0
bits_image_fetch_untransformed_repeat_none (bits_image_t *image, pixman_bool_t wide, int x, int y, int width, uint32_t * buffer) { uint32_t w; if (y < 0 || y >= image->height) { memset (buffer, 0, width * (wide? sizeof (argb_t) : 4)); return; } if (x < 0) { w = MIN (width, -x); memset (buffer, 0, w * (wide ? sizeof (argb_t) : 4)); width -= w; buffer += w * (wide? 4 : 1); x += w; } if (x < image->width) { w = MIN (width, image->width - x); if (wide) image->fetch_scanline_float (image, x, y, w, buffer, NULL); else image->fetch_scanline_32 (image, x, y, w, buffer, NULL); width -= w; buffer += w * (wide? 4 : 1); x += w; } memset (buffer, 0, width * (wide ? sizeof (argb_t) : 4)); }
@@ -926,7 +926,7 @@ create_bits (pixman_format_code_t format, if (_pixman_multiply_overflows_size (height, stride)) return NULL; - buf_size = height * stride; + buf_size = (size_t)height * stride; if (rowstride_bytes) *rowstride_bytes = stride;
CWE-189
null
null
12,392
bits_image_fetch_untransformed_repeat_normal (bits_image_t *image, pixman_bool_t wide, int x, int y, int width, uint32_t * buffer) { uint32_t w; while (y < 0) y += image->height; while (y >= image->height) y -= image->height; if (image->width == 1) { if (wide) replicate_pixel_float (image, 0, y, width, buffer); else replicate_pixel_32 (image, 0, y, width, buffer); return; } while (width) { while (x < 0) x += image->width; while (x >= image->width) x -= image->width; w = MIN (width, image->width - x); if (wide) image->fetch_scanline_float (image, x, y, w, buffer, NULL); else image->fetch_scanline_32 (image, x, y, w, buffer, NULL); buffer += w * (wide? 4 : 1); x += w; width -= w; } }
DoS Exec Code Overflow
0
bits_image_fetch_untransformed_repeat_normal (bits_image_t *image, pixman_bool_t wide, int x, int y, int width, uint32_t * buffer) { uint32_t w; while (y < 0) y += image->height; while (y >= image->height) y -= image->height; if (image->width == 1) { if (wide) replicate_pixel_float (image, 0, y, width, buffer); else replicate_pixel_32 (image, 0, y, width, buffer); return; } while (width) { while (x < 0) x += image->width; while (x >= image->width) x -= image->width; w = MIN (width, image->width - x); if (wide) image->fetch_scanline_float (image, x, y, w, buffer, NULL); else image->fetch_scanline_32 (image, x, y, w, buffer, NULL); buffer += w * (wide? 4 : 1); x += w; width -= w; } }
@@ -926,7 +926,7 @@ create_bits (pixman_format_code_t format, if (_pixman_multiply_overflows_size (height, stride)) return NULL; - buf_size = height * stride; + buf_size = (size_t)height * stride; if (rowstride_bytes) *rowstride_bytes = stride;
CWE-189
null
null
12,393
bits_image_property_changed (pixman_image_t *image) { _pixman_bits_image_setup_accessors (&image->bits); }
DoS Exec Code Overflow
0
bits_image_property_changed (pixman_image_t *image) { _pixman_bits_image_setup_accessors (&image->bits); }
@@ -926,7 +926,7 @@ create_bits (pixman_format_code_t format, if (_pixman_multiply_overflows_size (height, stride)) return NULL; - buf_size = height * stride; + buf_size = (size_t)height * stride; if (rowstride_bytes) *rowstride_bytes = stride;
CWE-189
null
null
12,394
dest_get_scanline_narrow (pixman_iter_t *iter, const uint32_t *mask) { pixman_image_t *image = iter->image; int x = iter->x; int y = iter->y; int width = iter->width; uint32_t * buffer = iter->buffer; image->bits.fetch_scanline_32 (&image->bits, x, y, width, buffer, mask); if (image->common.alpha_map) { uint32_t *alpha; if ((alpha = malloc (width * sizeof (uint32_t)))) { int i; x -= image->common.alpha_origin_x; y -= image->common.alpha_origin_y; image->common.alpha_map->fetch_scanline_32 ( image->common.alpha_map, x, y, width, alpha, mask); for (i = 0; i < width; ++i) { buffer[i] &= ~0xff000000; buffer[i] |= (alpha[i] & 0xff000000); } free (alpha); } } return iter->buffer; }
DoS Exec Code Overflow
0
dest_get_scanline_narrow (pixman_iter_t *iter, const uint32_t *mask) { pixman_image_t *image = iter->image; int x = iter->x; int y = iter->y; int width = iter->width; uint32_t * buffer = iter->buffer; image->bits.fetch_scanline_32 (&image->bits, x, y, width, buffer, mask); if (image->common.alpha_map) { uint32_t *alpha; if ((alpha = malloc (width * sizeof (uint32_t)))) { int i; x -= image->common.alpha_origin_x; y -= image->common.alpha_origin_y; image->common.alpha_map->fetch_scanline_32 ( image->common.alpha_map, x, y, width, alpha, mask); for (i = 0; i < width; ++i) { buffer[i] &= ~0xff000000; buffer[i] |= (alpha[i] & 0xff000000); } free (alpha); } } return iter->buffer; }
@@ -926,7 +926,7 @@ create_bits (pixman_format_code_t format, if (_pixman_multiply_overflows_size (height, stride)) return NULL; - buf_size = height * stride; + buf_size = (size_t)height * stride; if (rowstride_bytes) *rowstride_bytes = stride;
CWE-189
null
null
12,395
dest_get_scanline_wide (pixman_iter_t *iter, const uint32_t *mask) { bits_image_t * image = &iter->image->bits; int x = iter->x; int y = iter->y; int width = iter->width; argb_t * buffer = (argb_t *)iter->buffer; image->fetch_scanline_float ( image, x, y, width, (uint32_t *)buffer, mask); if (image->common.alpha_map) { argb_t *alpha; if ((alpha = malloc (width * sizeof (argb_t)))) { int i; x -= image->common.alpha_origin_x; y -= image->common.alpha_origin_y; image->common.alpha_map->fetch_scanline_float ( image->common.alpha_map, x, y, width, (uint32_t *)alpha, mask); for (i = 0; i < width; ++i) buffer[i].a = alpha[i].a; free (alpha); } } return iter->buffer; }
DoS Exec Code Overflow
0
dest_get_scanline_wide (pixman_iter_t *iter, const uint32_t *mask) { bits_image_t * image = &iter->image->bits; int x = iter->x; int y = iter->y; int width = iter->width; argb_t * buffer = (argb_t *)iter->buffer; image->fetch_scanline_float ( image, x, y, width, (uint32_t *)buffer, mask); if (image->common.alpha_map) { argb_t *alpha; if ((alpha = malloc (width * sizeof (argb_t)))) { int i; x -= image->common.alpha_origin_x; y -= image->common.alpha_origin_y; image->common.alpha_map->fetch_scanline_float ( image->common.alpha_map, x, y, width, (uint32_t *)alpha, mask); for (i = 0; i < width; ++i) buffer[i].a = alpha[i].a; free (alpha); } } return iter->buffer; }
@@ -926,7 +926,7 @@ create_bits (pixman_format_code_t format, if (_pixman_multiply_overflows_size (height, stride)) return NULL; - buf_size = height * stride; + buf_size = (size_t)height * stride; if (rowstride_bytes) *rowstride_bytes = stride;
CWE-189
null
null
12,396
dest_write_back_narrow (pixman_iter_t *iter) { bits_image_t * image = &iter->image->bits; int x = iter->x; int y = iter->y; int width = iter->width; const uint32_t *buffer = iter->buffer; image->store_scanline_32 (image, x, y, width, buffer); if (image->common.alpha_map) { x -= image->common.alpha_origin_x; y -= image->common.alpha_origin_y; image->common.alpha_map->store_scanline_32 ( image->common.alpha_map, x, y, width, buffer); } iter->y++; }
DoS Exec Code Overflow
0
dest_write_back_narrow (pixman_iter_t *iter) { bits_image_t * image = &iter->image->bits; int x = iter->x; int y = iter->y; int width = iter->width; const uint32_t *buffer = iter->buffer; image->store_scanline_32 (image, x, y, width, buffer); if (image->common.alpha_map) { x -= image->common.alpha_origin_x; y -= image->common.alpha_origin_y; image->common.alpha_map->store_scanline_32 ( image->common.alpha_map, x, y, width, buffer); } iter->y++; }
@@ -926,7 +926,7 @@ create_bits (pixman_format_code_t format, if (_pixman_multiply_overflows_size (height, stride)) return NULL; - buf_size = height * stride; + buf_size = (size_t)height * stride; if (rowstride_bytes) *rowstride_bytes = stride;
CWE-189
null
null
12,397
dest_write_back_wide (pixman_iter_t *iter) { bits_image_t * image = &iter->image->bits; int x = iter->x; int y = iter->y; int width = iter->width; const uint32_t *buffer = iter->buffer; image->store_scanline_float (image, x, y, width, buffer); if (image->common.alpha_map) { x -= image->common.alpha_origin_x; y -= image->common.alpha_origin_y; image->common.alpha_map->store_scanline_float ( image->common.alpha_map, x, y, width, buffer); } iter->y++; }
DoS Exec Code Overflow
0
dest_write_back_wide (pixman_iter_t *iter) { bits_image_t * image = &iter->image->bits; int x = iter->x; int y = iter->y; int width = iter->width; const uint32_t *buffer = iter->buffer; image->store_scanline_float (image, x, y, width, buffer); if (image->common.alpha_map) { x -= image->common.alpha_origin_x; y -= image->common.alpha_origin_y; image->common.alpha_map->store_scanline_float ( image->common.alpha_map, x, y, width, buffer); } iter->y++; }
@@ -926,7 +926,7 @@ create_bits (pixman_format_code_t format, if (_pixman_multiply_overflows_size (height, stride)) return NULL; - buf_size = height * stride; + buf_size = (size_t)height * stride; if (rowstride_bytes) *rowstride_bytes = stride;
CWE-189
null
null
12,398
fetch_pixel_general (bits_image_t *image, int x, int y, pixman_bool_t check_bounds) { uint32_t pixel; if (check_bounds && (x < 0 || x >= image->width || y < 0 || y >= image->height)) { return 0; } pixel = image->fetch_pixel_32 (image, x, y); if (image->common.alpha_map) { uint32_t pixel_a; x -= image->common.alpha_origin_x; y -= image->common.alpha_origin_y; if (x < 0 || x >= image->common.alpha_map->width || y < 0 || y >= image->common.alpha_map->height) { pixel_a = 0; } else { pixel_a = image->common.alpha_map->fetch_pixel_32 ( image->common.alpha_map, x, y); pixel_a = ALPHA_8 (pixel_a); } pixel &= 0x00ffffff; pixel |= (pixel_a << 24); } return pixel; }
DoS Exec Code Overflow
0
fetch_pixel_general (bits_image_t *image, int x, int y, pixman_bool_t check_bounds) { uint32_t pixel; if (check_bounds && (x < 0 || x >= image->width || y < 0 || y >= image->height)) { return 0; } pixel = image->fetch_pixel_32 (image, x, y); if (image->common.alpha_map) { uint32_t pixel_a; x -= image->common.alpha_origin_x; y -= image->common.alpha_origin_y; if (x < 0 || x >= image->common.alpha_map->width || y < 0 || y >= image->common.alpha_map->height) { pixel_a = 0; } else { pixel_a = image->common.alpha_map->fetch_pixel_32 ( image->common.alpha_map, x, y); pixel_a = ALPHA_8 (pixel_a); } pixel &= 0x00ffffff; pixel |= (pixel_a << 24); } return pixel; }
@@ -926,7 +926,7 @@ create_bits (pixman_format_code_t format, if (_pixman_multiply_overflows_size (height, stride)) return NULL; - buf_size = height * stride; + buf_size = (size_t)height * stride; if (rowstride_bytes) *rowstride_bytes = stride;
CWE-189
null
null
12,399
pixman_image_create_bits (pixman_format_code_t format, int width, int height, uint32_t * bits, int rowstride_bytes) { return create_bits_image_internal ( format, width, height, bits, rowstride_bytes, TRUE); }
DoS Exec Code Overflow
0
pixman_image_create_bits (pixman_format_code_t format, int width, int height, uint32_t * bits, int rowstride_bytes) { return create_bits_image_internal ( format, width, height, bits, rowstride_bytes, TRUE); }
@@ -926,7 +926,7 @@ create_bits (pixman_format_code_t format, if (_pixman_multiply_overflows_size (height, stride)) return NULL; - buf_size = height * stride; + buf_size = (size_t)height * stride; if (rowstride_bytes) *rowstride_bytes = stride;
CWE-189
null
null