cve_id
stringlengths
13
16
obtain_all_privilege
stringclasses
3 values
obtain_user_privilege
stringclasses
2 values
obtain_other_privilege
stringclasses
2 values
user_interaction_required
stringclasses
3 values
cvss2_vector_string
stringclasses
106 values
cvss2_access_vector
stringclasses
4 values
cvss2_access_complexity
stringclasses
4 values
cvss2_authentication
stringclasses
3 values
cvss2_confidentiality_impact
stringclasses
4 values
cvss2_integrity_impact
stringclasses
4 values
cvss2_availability_impact
stringclasses
4 values
cvss2_base_score
stringclasses
50 values
cvss3_vector_string
stringclasses
226 values
cvss3_attack_vector
stringclasses
5 values
cvss3_attack_complexity
stringclasses
3 values
cvss3_privileges_required
stringclasses
4 values
cvss3_user_interaction
stringclasses
3 values
cvss3_scope
stringclasses
3 values
cvss3_confidentiality_impact
stringclasses
4 values
cvss3_integrity_impact
stringclasses
4 values
cvss3_availability_impact
stringclasses
4 values
cvss3_base_score
stringclasses
55 values
cvss3_base_severity
stringclasses
5 values
exploitability_score
stringclasses
22 values
impact_score
stringclasses
15 values
ac_insuf_info
stringclasses
3 values
reference_json
stringlengths
221
23.3k
problemtype_json
stringclasses
200 values
severity
stringclasses
4 values
cve_nodes
stringlengths
2
33.1k
cve_description
stringlengths
64
1.99k
cve_last_modified_date
stringlengths
17
17
cve_published_date
stringlengths
17
17
cwe_name
stringclasses
125 values
cwe_description
stringclasses
124 values
cwe_extended_description
stringclasses
95 values
cwe_url
stringclasses
124 values
cwe_is_category
int64
0
1
commit_author
stringlengths
0
34
commit_author_date
stringlengths
25
25
commit_msg
stringlengths
0
13.3k
commit_hash
stringlengths
40
40
commit_is_merge
stringclasses
1 value
repo_name
stringclasses
467 values
repo_description
stringclasses
459 values
repo_date_created
stringclasses
467 values
repo_date_last_push
stringclasses
467 values
repo_homepage
stringclasses
294 values
repo_owner
stringclasses
470 values
repo_stars
stringclasses
406 values
repo_forks
stringclasses
352 values
function_name
stringlengths
3
120
function_signature
stringlengths
6
640
function_parameters
stringlengths
2
302
function
stringlengths
12
114k
function_token_count
stringlengths
1
5
function_before_change
stringclasses
1 value
labels
int64
1
1
CVE-2014-5386
False
False
False
False
AV:N/AC:L/Au:N/C:N/I:P/A:N
NETWORK
LOW
NONE
NONE
PARTIAL
NONE
5.0
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
[{'url': 'https://github.com/facebook/hhvm/commit/ab6fdeb84fb090b48606b6f7933028cfe7bf3a5e', 'name': 'https://github.com/facebook/hhvm/commit/ab6fdeb84fb090b48606b6f7933028cfe7bf3a5e', 'refsource': 'CONFIRM', 'tags': []}]
[{'description': [{'lang': 'en', 'value': 'CWE-310'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hiphop_virtual_machine:*:*:*:*:*:*:*:*', 'versionEndIncluding': '3.2.0', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'The mcrypt_create_iv function in hphp/runtime/ext/mcrypt/ext_mcrypt.cpp in Facebook HipHop Virtual Machine (HHVM) before 3.3.0 does not seed the random number generator, which makes it easier for remote attackers to defeat cryptographic protection mechanisms by leveraging the use of a single initialization vector.'}]
2014-12-30T15:33Z
2014-12-28T15:59Z
Cryptographic Issues
Weaknesses in this category are related to the design and implementation of data confidentiality and integrity. Frequently these deal with the use of encoding techniques, encryption libraries, and hashing algorithms. The weaknesses in this category could lead to a degradation of the quality data if they are not addressed.
https://cwe.mitre.org/data/definitions/310.html
1
Sara Golemon
2014-08-16 20:04:26-07:00
Fix mcrypt_create_iv(..., MCRYPT_RAND) to auto-seed RNG Summary: Without seeding the random number generator, we'll always get the same IV, and that reduces the security of this function. Fortunately, f_rand() has all of that logic for auto-seeding and selection of a suitable initial seed built-in. Realistically, using MCRYPT_RAND should be deprecated. I'm going to wait on PHP Internals to make a decision on https://wiki.php.net/rfc/deprecate_mcrypt_rand before adding that warning however, so that our test suite remains consistent. Credit: Theodore R. Smith of PHP Experts, Inc. <theodorephpexperts.pro> Closes #3496 Reviewed By: @ptarjan Differential Revision: D1502435
ab6fdeb84fb090b48606b6f7933028cfe7bf3a5e
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::HHVM_FUNCTION
HPHP::HHVM_FUNCTION( mcrypt_create_iv , int size , int source)
['mcrypt_create_iv', 'size', 'source']
Variant HHVM_FUNCTION(mcrypt_create_iv, int size, int source /* = 0 */) { if (size <= 0 || size >= INT_MAX) { raise_warning("Can not create an IV with a size of less than 1 or " "greater than %d", INT_MAX); return false; } int n = 0; char *iv = (char*)calloc(size + 1, 1); if (source == RANDOM || source == URANDOM) { int fd = open(source == RANDOM ? "/dev/random" : "/dev/urandom", O_RDONLY); if (fd < 0) { free(iv); raise_warning("Cannot open source device"); return false; } int read_bytes; for (read_bytes = 0; read_bytes < size && n >= 0; read_bytes += n) { n = read(fd, iv + read_bytes, size - read_bytes); } n = read_bytes; close(fd); if (n < size) { free(iv); raise_warning("Could not gather sufficient random data"); return false; } } else { n = size; while (size) { iv[--size] = (char)(255.0 * rand() / RAND_MAX); } } return String(iv, n, AttachString); }
218
True
1
CVE-2014-6228
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
[{'url': 'https://github.com/facebook/hhvm/commit/1f91e076a585118495b976a413c1df40f6fd3d41', 'name': 'https://github.com/facebook/hhvm/commit/1f91e076a585118495b976a413c1df40f6fd3d41', 'refsource': 'CONFIRM', 'tags': []}]
[{'description': [{'lang': 'en', 'value': 'CWE-189'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hiphop_virtual_machine:*:*:*:*:*:*:*:*', 'versionEndIncluding': '3.2.0', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Integer overflow in the string_chunk_split function in hphp/runtime/base/zend-string.cpp in Facebook HipHop Virtual Machine (HHVM) before 3.3.0 allows remote attackers to cause a denial of service (application crash) or possibly have unspecified other impact via crafted arguments to the chunk_split function.'}]
2014-12-30T15:34Z
2014-12-28T15:59Z
Numeric Errors
Weaknesses in this category are related to improper calculation or conversion of numbers.
https://cwe.mitre.org/data/definitions/189.html
1
Neal Poole
2014-08-25 22:29:37-07:00
Fix integer overflow in chunk_split Reviewed By: @ptarjan Differential Revision: D1515947
1f91e076a585118495b976a413c1df40f6fd3d41
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::string_chunk_split
HPHP::string_chunk_split( const char * src , int srclen , const char * end , int endlen , int chunklen)
['src', 'srclen', 'end', 'endlen', 'chunklen']
String string_chunk_split(const char *src, int srclen, const char *end, int endlen, int chunklen) { int chunks = srclen / chunklen; // complete chunks! int restlen = srclen - chunks * chunklen; /* srclen % chunklen */ int out_len = (chunks + 1) * endlen + srclen; String ret(out_len, ReserveString); char *dest = ret.bufferSlice().ptr; const char *p; char *q; const char *pMax = src + srclen - chunklen + 1; for (p = src, q = dest; p < pMax; ) { memcpy(q, p, chunklen); q += chunklen; memcpy(q, end, endlen); q += endlen; p += chunklen; } if (restlen) { memcpy(q, p, restlen); q += restlen; memcpy(q, end, endlen); q += endlen; } ret.setSize(q - dest); return ret; }
185
True
1
CVE-2014-6229
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
[{'url': 'http://hhvm.com/blog/6239/hhvm-3-3-0', 'name': 'http://hhvm.com/blog/6239/hhvm-3-3-0', 'refsource': 'CONFIRM', 'tags': ['Vendor Advisory']}, {'url': 'https://github.com/facebook/hhvm/commit/7135ec229882370a00411aa50030eada6034cc1b', 'name': 'https://github.com/facebook/hhvm/commit/7135ec229882370a00411aa50030eada6034cc1b', 'refsource': 'CONFIRM', 'tags': []}]
[{'description': [{'lang': 'en', 'value': 'CWE-200'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hiphop_virtual_machine:*:*:*:*:*:*:*:*', 'versionEndIncluding': '3.2.0', 'cpe_name': []}]}]
[{'lang': 'en', 'value': "The HashContext class in hphp/runtime/ext/ext_hash.cpp in Facebook HipHop Virtual Machine (HHVM) before 3.3.0 incorrectly expects that a certain key string uses '\\0' for termination, which allows remote attackers to obtain sensitive information by leveraging read access beyond the end of the string, and makes it easier for remote attackers to defeat cryptographic protection mechanisms by leveraging truncation of a string containing an internal '\\0' character."}]
2014-12-30T15:34Z
2014-12-28T15:59Z
Exposure of Sensitive Information to an Unauthorized Actor
The product exposes sensitive information to an actor that is not explicitly authorized to have access to that information.
There are many different kinds of mistakes that introduce information exposures. The severity of the error can range widely, depending on the context in which the product operates, the type of sensitive information that is revealed, and the benefits it may provide to an attacker. Some kinds of sensitive information include: private, personal information, such as personal messages, financial data, health records, geographic location, or contact details system status and environment, such as the operating system and installed packages business secrets and intellectual property network status and configuration the product's own code or internal state metadata, e.g. logging of connections or message headers indirect information, such as a discrepancy between two internal operations that can be observed by an outsider Information might be sensitive to different parties, each of which may have their own expectations for whether the information should be protected. These parties include: the product's own users people or organizations whose information is created or used by the product, even if they are not direct product users the product's administrators, including the admins of the system(s) and/or networks on which the product operates the developer Information exposures can occur in different ways: the code explicitly inserts sensitive information into resources or messages that are intentionally made accessible to unauthorized actors, but should not contain the information - i.e., the information should have been "scrubbed" or "sanitized" a different weakness or mistake indirectly inserts the sensitive information into resources, such as a web script error revealing the full system path of the program. the code manages resources that intentionally contain sensitive information, but the resources are unintentionally made accessible to unauthorized actors. In this case, the information exposure is resultant - i.e., a different weakness enabled the access to the information in the first place. It is common practice to describe any loss of confidentiality as an "information exposure," but this can lead to overuse of CWE-200 in CWE mapping. From the CWE perspective, loss of confidentiality is a technical impact that can arise from dozens of different weaknesses, such as insecure file permissions or out-of-bounds read. CWE-200 and its lower-level descendants are intended to cover the mistakes that occur in behaviors that explicitly manage, store, transfer, or cleanse sensitive information.
https://cwe.mitre.org/data/definitions/200.html
0
Owen Yamauchi
2014-09-03 10:07:05-07:00
Fix potential security leak in HashContext Summary: CVE-2014-6229 This is not a NUL-terminated string, it's a fixed-size block of data. The risks were key truncation (if there happens to be a NUL byte in the key) or over-reading (which would be information leakage). Reviewed By: @ptarjan Differential Revision: D1533546
7135ec229882370a00411aa50030eada6034cc1b
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::HashContext::HashContext
HPHP::HashContext::HashContext( const HashContext * ctx)
['ctx']
explicit HashContext(const HashContext* ctx) { assert(ctx->ops); assert(ctx->ops->context_size >= 0); ops = ctx->ops; context = malloc(ops->context_size); ops->hash_copy(context, ctx->context); options = ctx->options; key = ctx->key ? strdup(ctx->key) : nullptr; }
74
True
1
CVE-2014-9714
False
False
False
True
AV:N/AC:M/Au:N/C:N/I:P/A:N
NETWORK
MEDIUM
NONE
NONE
PARTIAL
NONE
4.3
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
[{'url': 'http://www.openwall.com/lists/oss-security/2015/04/07/3', 'name': '[oss-security] 20150407 Re: CVE request: MediaWiki 1.24.2/1.23.9/1.19.24', 'refsource': 'MLIST', 'tags': []}, {'url': 'https://lists.wikimedia.org/pipermail/mediawiki-announce/2015-March/000175.html', 'name': '[MediaWiki-announce] 20150331 MediaWiki Security and Maintenance Releases: 1.19.24, 1.23.9, and 1.24.2', 'refsource': 'MLIST', 'tags': ['Vendor Advisory']}, {'url': 'https://github.com/facebook/hhvm/commit/324701c9fd31beb4f070f1b7ef78b115fbdfec34', 'name': 'https://github.com/facebook/hhvm/commit/324701c9fd31beb4f070f1b7ef78b115fbdfec34', 'refsource': 'CONFIRM', 'tags': []}, {'url': 'https://github.com/facebook/hhvm/issues/4283', 'name': 'https://github.com/facebook/hhvm/issues/4283', 'refsource': 'CONFIRM', 'tags': []}, {'url': 'https://phabricator.wikimedia.org/T85851', 'name': 'https://phabricator.wikimedia.org/T85851', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Vendor Advisory']}, {'url': 'http://www.openwall.com/lists/oss-security/2015/04/01/1', 'name': '[oss-security] 20150331 CVE request: MediaWiki 1.24.2/1.23.9/1.19.24', 'refsource': 'MLIST', 'tags': []}, {'url': 'http://www.securityfocus.com/bid/74061', 'name': '74061', 'refsource': 'BID', 'tags': []}]
[{'description': [{'lang': 'en', 'value': 'CWE-79'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hiphop_virtual_machine:*:*:*:*:*:*:*:*', 'versionEndIncluding': '3.4.2', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Cross-site scripting (XSS) vulnerability in the WddxPacket::recursiveAddVar function in HHVM (aka the HipHop Virtual Machine) before 3.5.0 allows remote attackers to inject arbitrary web script or HTML via a crafted string to the wddx_serialize_value function.'}]
2016-06-24T15:55Z
2015-04-13T14:59Z
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The software does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
Cross-site scripting (XSS) vulnerabilities occur when: Untrusted data enters a web application, typically from a web request. The web application dynamically generates a web page that contains this untrusted data. During page generation, the application does not prevent the data from containing content that is executable by a web browser, such as JavaScript, HTML tags, HTML attributes, mouse events, Flash, ActiveX, etc. A victim visits the generated web page through a web browser, which contains malicious script that was injected using the untrusted data. Since the script comes from a web page that was sent by the web server, the victim's web browser executes the malicious script in the context of the web server's domain. This effectively violates the intention of the web browser's same-origin policy, which states that scripts in one domain should not be able to access resources or run code in a different domain. There are three main kinds of XSS: Type 1: Reflected XSS (or Non-Persistent) - The server reads data directly from the HTTP request and reflects it back in the HTTP response. Reflected XSS exploits occur when an attacker causes a victim to supply dangerous content to a vulnerable web application, which is then reflected back to the victim and executed by the web browser. The most common mechanism for delivering malicious content is to include it as a parameter in a URL that is posted publicly or e-mailed directly to the victim. URLs constructed in this manner constitute the core of many phishing schemes, whereby an attacker convinces a victim to visit a URL that refers to a vulnerable site. After the site reflects the attacker's content back to the victim, the content is executed by the victim's browser. Type 2: Stored XSS (or Persistent) - The application stores dangerous data in a database, message forum, visitor log, or other trusted data store. At a later time, the dangerous data is subsequently read back into the application and included in dynamic content. From an attacker's perspective, the optimal place to inject malicious content is in an area that is displayed to either many users or particularly interesting users. Interesting users typically have elevated privileges in the application or interact with sensitive data that is valuable to the attacker. If one of these users executes malicious content, the attacker may be able to perform privileged operations on behalf of the user or gain access to sensitive data belonging to the user. For example, the attacker might inject XSS into a log message, which might not be handled properly when an administrator views the logs. Type 0: DOM-Based XSS - In DOM-based XSS, the client performs the injection of XSS into the page; in the other types, the server performs the injection. DOM-based XSS generally involves server-controlled, trusted script that is sent to the client, such as Javascript that performs sanity checks on a form before the user submits it. If the server-supplied script processes user-supplied data and then injects it back into the web page (such as with dynamic HTML), then DOM-based XSS is possible. Once the malicious script is injected, the attacker can perform a variety of malicious activities. The attacker could transfer private information, such as cookies that may include session information, from the victim's machine to the attacker. The attacker could send malicious requests to a web site on behalf of the victim, which could be especially dangerous to the site if the victim has administrator privileges to manage that site. Phishing attacks could be used to emulate trusted web sites and trick the victim into entering a password, allowing the attacker to compromise the victim's account on that web site. Finally, the script could exploit a vulnerability in the web browser itself possibly taking over the victim's machine, sometimes referred to as "drive-by hacking." In many cases, the attack can be launched without the victim even being aware of it. Even with careful users, attackers frequently use a variety of methods to encode the malicious portion of the attack, such as URL encoding or Unicode, so the request looks less suspicious.
https://cwe.mitre.org/data/definitions/79.html
0
Paul Bissonnette
2014-11-20 16:50:22-08:00
HTMLEncode strings in wddx_serialize_value() Summary: Strings returned through wddx_serialize_value should be HTMLEncode()'d during serialization. Fixes #4283 {sync, type="child", parent="internal", parentrevid="1691695", parentrevfbid="1537976659780590", parentdiffid="5726084"} Reviewed By: @JoelMarcey Differential Revision: D1691695 Signature: t1:1691695:1416530595:722bfcdaf7c0dbee379bea886cd4c43d997ca7dd
324701c9fd31beb4f070f1b7ef78b115fbdfec34
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::WddxPacket::recursiveAddVar
HPHP::WddxPacket::recursiveAddVar( const String & varName , const Variant & varVariant , bool hasVarTag)
['varName', 'varVariant', 'hasVarTag']
bool WddxPacket::recursiveAddVar(const String& varName, const Variant& varVariant, bool hasVarTag) { bool isArray = varVariant.isArray(); bool isObject = varVariant.isObject(); if (isArray || isObject) { if (hasVarTag) { m_packetString += "<var name='"; m_packetString += varName.data(); m_packetString += "'>"; } Array varAsArray; Object varAsObject = varVariant.toObject(); if (isArray) varAsArray = varVariant.toArray(); if (isObject) varAsArray = varAsObject.toArray(); int length = varAsArray.length(); if (length > 0) { ArrayIter it = ArrayIter(varAsArray); if (it.first().isString()) isObject = true; if (isObject) { m_packetString += "<struct>"; if (!isArray) { m_packetString += "<var name='php_class_name'><string>"; m_packetString += varAsObject->o_getClassName().c_str(); m_packetString += "</string></var>"; } } else { m_packetString += "<array length='"; m_packetString += std::to_string(length); m_packetString += "'>"; } for (ArrayIter it(varAsArray); it; ++it) { Variant key = it.first(); Variant value = it.second(); recursiveAddVar(key.toString(), value, isObject); } if (isObject) { m_packetString += "</struct>"; } else { m_packetString += "</array>"; } } else { //empty object if (isObject) { m_packetString += "<struct>"; if (!isArray) { m_packetString += "<var name='php_class_name'><string>"; m_packetString += varAsObject->o_getClassName().c_str(); m_packetString += "</string></var>"; } m_packetString += "</struct>"; } } if (hasVarTag) { m_packetString += "</var>"; } return true; } std::string varType = getDataTypeString(varVariant.getType()).data(); if (!getWddxEncoded(varType, "", varName, false).empty()) { std::string varValue = varVariant.toString().data(); if (varType.compare("boolean") == 0) { varValue = varVariant.toBoolean() ? "true" : "false"; } m_packetString += getWddxEncoded(varType, varValue, varName, hasVarTag); return true; } return false; }
418
True
1
CVE-2020-1917
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'xbuf_format_converter, used as part of exif_read_data, was appending a terminating null character to the generated string, but was not using its standard append char function. As a result, if the buffer was full, it would result in an out-of-bounds write. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-17T19:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::MemFile::readImpl
HPHP::MemFile::readImpl( char * buffer , int64_t length)
['buffer', 'length']
int64_t MemFile::readImpl(char *buffer, int64_t length) { assertx(m_len != -1); assertx(length > 0); int64_t remaining = m_len - m_cursor; if (remaining < length) length = remaining; if (length > 0) { memcpy(buffer, (const void *)(m_data + m_cursor), length); } m_cursor += length; return length; }
78
True
1
CVE-2020-1918
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In-memory file operations (ie: using fopen on a data URI) did not properly restrict negative seeking, allowing for the reading of memory prior to the in-memory buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:53Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::MemFile::readImpl
HPHP::MemFile::readImpl( char * buffer , int64_t length)
['buffer', 'length']
int64_t MemFile::readImpl(char *buffer, int64_t length) { assertx(m_len != -1); assertx(length > 0); int64_t remaining = m_len - m_cursor; if (remaining < length) length = remaining; if (length > 0) { memcpy(buffer, (const void *)(m_data + m_cursor), length); } m_cursor += length; return length; }
78
True
1
CVE-2020-1919
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Incorrect bounds calculations in substr_compare could lead to an out-of-bounds read when the second string argument passed in is longer than the first. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:51Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::MemFile::readImpl
HPHP::MemFile::readImpl( char * buffer , int64_t length)
['buffer', 'length']
int64_t MemFile::readImpl(char *buffer, int64_t length) { assertx(m_len != -1); assertx(length > 0); int64_t remaining = m_len - m_cursor; if (remaining < length) length = remaining; if (length > 0) { memcpy(buffer, (const void *)(m_data + m_cursor), length); } m_cursor += length; return length; }
78
True
1
CVE-2020-1921
False
False
False
False
AV:N/AC:L/Au:N/C:N/I:N/A:P
NETWORK
LOW
NONE
NONE
NONE
PARTIAL
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
NONE
NONE
HIGH
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In the crypt function, we attempt to null terminate a buffer using the size of the input salt without validating that the offset is within the buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::MemFile::readImpl
HPHP::MemFile::readImpl( char * buffer , int64_t length)
['buffer', 'length']
int64_t MemFile::readImpl(char *buffer, int64_t length) { assertx(m_len != -1); assertx(length > 0); int64_t remaining = m_len - m_cursor; if (remaining < length) length = remaining; if (length > 0) { memcpy(buffer, (const void *)(m_data + m_cursor), length); } m_cursor += length; return length; }
78
True
1
CVE-2021-24025
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Third Party Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-190'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndIncluding': '4.93.1', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndIncluding': '4.80.1', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Due to incorrect string size calculations inside the preg_quote function, a large input string passed to the function can trigger an integer overflow leading to a heap overflow. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-16T12:45Z
2021-03-10T16:15Z
Integer Overflow or Wraparound
The software performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
An integer overflow or wraparound occurs when an integer value is incremented to a value that is too large to store in the associated representation. When this occurs, the value may wrap to become a very small or negative number. While this may be intended behavior in circumstances that rely on wrapping, it can have security consequences if the wrap is unexpected. This is especially the case if the integer overflow can be triggered using user-supplied inputs. This becomes security-critical when the result is used to control looping, make a security decision, or determine the offset or size in behaviors such as memory allocation, copying, concatenation, etc.
https://cwe.mitre.org/data/definitions/190.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::MemFile::readImpl
HPHP::MemFile::readImpl( char * buffer , int64_t length)
['buffer', 'length']
int64_t MemFile::readImpl(char *buffer, int64_t length) { assertx(m_len != -1); assertx(length > 0); int64_t remaining = m_len - m_cursor; if (remaining < length) length = remaining; if (length > 0) { memcpy(buffer, (const void *)(m_data + m_cursor), length); } m_cursor += length; return length; }
78
True
1
CVE-2020-1917
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'xbuf_format_converter, used as part of exif_read_data, was appending a terminating null character to the generated string, but was not using its standard append char function. As a result, if the buffer was full, it would result in an out-of-bounds write. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-17T19:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::MemFile::seek
HPHP::MemFile::seek( int64_t offset , int whence)
['offset', 'whence']
bool MemFile::seek(int64_t offset, int whence /* = SEEK_SET */) { assertx(m_len != -1); if (whence == SEEK_CUR) { if (offset > 0 && offset < bufferedLen()) { setReadPosition(getReadPosition() + offset); setPosition(getPosition() + offset); return true; } offset += getPosition(); whence = SEEK_SET; } // invalidate the current buffer setWritePosition(0); setReadPosition(0); if (whence == SEEK_SET) { m_cursor = offset; } else { assertx(whence == SEEK_END); m_cursor = m_len + offset; } setPosition(m_cursor); return true; }
119
True
1
CVE-2020-1918
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In-memory file operations (ie: using fopen on a data URI) did not properly restrict negative seeking, allowing for the reading of memory prior to the in-memory buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:53Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::MemFile::seek
HPHP::MemFile::seek( int64_t offset , int whence)
['offset', 'whence']
bool MemFile::seek(int64_t offset, int whence /* = SEEK_SET */) { assertx(m_len != -1); if (whence == SEEK_CUR) { if (offset > 0 && offset < bufferedLen()) { setReadPosition(getReadPosition() + offset); setPosition(getPosition() + offset); return true; } offset += getPosition(); whence = SEEK_SET; } // invalidate the current buffer setWritePosition(0); setReadPosition(0); if (whence == SEEK_SET) { m_cursor = offset; } else { assertx(whence == SEEK_END); m_cursor = m_len + offset; } setPosition(m_cursor); return true; }
119
True
1
CVE-2020-1919
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Incorrect bounds calculations in substr_compare could lead to an out-of-bounds read when the second string argument passed in is longer than the first. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:51Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::MemFile::seek
HPHP::MemFile::seek( int64_t offset , int whence)
['offset', 'whence']
bool MemFile::seek(int64_t offset, int whence /* = SEEK_SET */) { assertx(m_len != -1); if (whence == SEEK_CUR) { if (offset > 0 && offset < bufferedLen()) { setReadPosition(getReadPosition() + offset); setPosition(getPosition() + offset); return true; } offset += getPosition(); whence = SEEK_SET; } // invalidate the current buffer setWritePosition(0); setReadPosition(0); if (whence == SEEK_SET) { m_cursor = offset; } else { assertx(whence == SEEK_END); m_cursor = m_len + offset; } setPosition(m_cursor); return true; }
119
True
1
CVE-2020-1921
False
False
False
False
AV:N/AC:L/Au:N/C:N/I:N/A:P
NETWORK
LOW
NONE
NONE
NONE
PARTIAL
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
NONE
NONE
HIGH
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In the crypt function, we attempt to null terminate a buffer using the size of the input salt without validating that the offset is within the buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::MemFile::seek
HPHP::MemFile::seek( int64_t offset , int whence)
['offset', 'whence']
bool MemFile::seek(int64_t offset, int whence /* = SEEK_SET */) { assertx(m_len != -1); if (whence == SEEK_CUR) { if (offset > 0 && offset < bufferedLen()) { setReadPosition(getReadPosition() + offset); setPosition(getPosition() + offset); return true; } offset += getPosition(); whence = SEEK_SET; } // invalidate the current buffer setWritePosition(0); setReadPosition(0); if (whence == SEEK_SET) { m_cursor = offset; } else { assertx(whence == SEEK_END); m_cursor = m_len + offset; } setPosition(m_cursor); return true; }
119
True
1
CVE-2021-24025
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Third Party Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-190'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndIncluding': '4.93.1', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndIncluding': '4.80.1', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Due to incorrect string size calculations inside the preg_quote function, a large input string passed to the function can trigger an integer overflow leading to a heap overflow. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-16T12:45Z
2021-03-10T16:15Z
Integer Overflow or Wraparound
The software performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
An integer overflow or wraparound occurs when an integer value is incremented to a value that is too large to store in the associated representation. When this occurs, the value may wrap to become a very small or negative number. While this may be intended behavior in circumstances that rely on wrapping, it can have security consequences if the wrap is unexpected. This is especially the case if the integer overflow can be triggered using user-supplied inputs. This becomes security-critical when the result is used to control looping, make a security decision, or determine the offset or size in behaviors such as memory allocation, copying, concatenation, etc.
https://cwe.mitre.org/data/definitions/190.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::MemFile::seek
HPHP::MemFile::seek( int64_t offset , int whence)
['offset', 'whence']
bool MemFile::seek(int64_t offset, int whence /* = SEEK_SET */) { assertx(m_len != -1); if (whence == SEEK_CUR) { if (offset > 0 && offset < bufferedLen()) { setReadPosition(getReadPosition() + offset); setPosition(getPosition() + offset); return true; } offset += getPosition(); whence = SEEK_SET; } // invalidate the current buffer setWritePosition(0); setReadPosition(0); if (whence == SEEK_SET) { m_cursor = offset; } else { assertx(whence == SEEK_END); m_cursor = m_len + offset; } setPosition(m_cursor); return true; }
119
True
1
CVE-2020-1917
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'xbuf_format_converter, used as part of exif_read_data, was appending a terminating null character to the generated string, but was not using its standard append char function. As a result, if the buffer was full, it would result in an out-of-bounds write. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-17T19:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::StringData::setSize
HPHP::StringData::setSize( int len)
['len']
inline void StringData::setSize(int len) { assertx(!isImmutable() && !hasMultipleRefs()); assertx(len >= 0 && len <= capacity()); mutableData()[len] = 0; m_lenAndHash = len; assertx(m_hash == 0); assertx(checkSane()); }
62
True
1
CVE-2020-1918
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In-memory file operations (ie: using fopen on a data URI) did not properly restrict negative seeking, allowing for the reading of memory prior to the in-memory buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:53Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::StringData::setSize
HPHP::StringData::setSize( int len)
['len']
inline void StringData::setSize(int len) { assertx(!isImmutable() && !hasMultipleRefs()); assertx(len >= 0 && len <= capacity()); mutableData()[len] = 0; m_lenAndHash = len; assertx(m_hash == 0); assertx(checkSane()); }
62
True
1
CVE-2020-1919
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Incorrect bounds calculations in substr_compare could lead to an out-of-bounds read when the second string argument passed in is longer than the first. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:51Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::StringData::setSize
HPHP::StringData::setSize( int len)
['len']
inline void StringData::setSize(int len) { assertx(!isImmutable() && !hasMultipleRefs()); assertx(len >= 0 && len <= capacity()); mutableData()[len] = 0; m_lenAndHash = len; assertx(m_hash == 0); assertx(checkSane()); }
62
True
1
CVE-2020-1921
False
False
False
False
AV:N/AC:L/Au:N/C:N/I:N/A:P
NETWORK
LOW
NONE
NONE
NONE
PARTIAL
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
NONE
NONE
HIGH
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In the crypt function, we attempt to null terminate a buffer using the size of the input salt without validating that the offset is within the buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::StringData::setSize
HPHP::StringData::setSize( int len)
['len']
inline void StringData::setSize(int len) { assertx(!isImmutable() && !hasMultipleRefs()); assertx(len >= 0 && len <= capacity()); mutableData()[len] = 0; m_lenAndHash = len; assertx(m_hash == 0); assertx(checkSane()); }
62
True
1
CVE-2021-24025
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Third Party Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-190'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndIncluding': '4.93.1', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndIncluding': '4.80.1', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Due to incorrect string size calculations inside the preg_quote function, a large input string passed to the function can trigger an integer overflow leading to a heap overflow. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-16T12:45Z
2021-03-10T16:15Z
Integer Overflow or Wraparound
The software performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
An integer overflow or wraparound occurs when an integer value is incremented to a value that is too large to store in the associated representation. When this occurs, the value may wrap to become a very small or negative number. While this may be intended behavior in circumstances that rely on wrapping, it can have security consequences if the wrap is unexpected. This is especially the case if the integer overflow can be triggered using user-supplied inputs. This becomes security-critical when the result is used to control looping, make a security decision, or determine the offset or size in behaviors such as memory allocation, copying, concatenation, etc.
https://cwe.mitre.org/data/definitions/190.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::StringData::setSize
HPHP::StringData::setSize( int len)
['len']
inline void StringData::setSize(int len) { assertx(!isImmutable() && !hasMultipleRefs()); assertx(len >= 0 && len <= capacity()); mutableData()[len] = 0; m_lenAndHash = len; assertx(m_hash == 0); assertx(checkSane()); }
62
True
1
CVE-2020-1917
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'xbuf_format_converter, used as part of exif_read_data, was appending a terminating null character to the generated string, but was not using its standard append char function. As a result, if the buffer was full, it would result in an out-of-bounds write. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-17T19:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::StringData::size
HPHP::StringData::size() const
[]
inline int StringData::size() const { return m_len; }
11
True
1
CVE-2020-1918
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In-memory file operations (ie: using fopen on a data URI) did not properly restrict negative seeking, allowing for the reading of memory prior to the in-memory buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:53Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::StringData::size
HPHP::StringData::size() const
[]
inline int StringData::size() const { return m_len; }
11
True
1
CVE-2020-1919
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Incorrect bounds calculations in substr_compare could lead to an out-of-bounds read when the second string argument passed in is longer than the first. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:51Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::StringData::size
HPHP::StringData::size() const
[]
inline int StringData::size() const { return m_len; }
11
True
1
CVE-2020-1921
False
False
False
False
AV:N/AC:L/Au:N/C:N/I:N/A:P
NETWORK
LOW
NONE
NONE
NONE
PARTIAL
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
NONE
NONE
HIGH
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In the crypt function, we attempt to null terminate a buffer using the size of the input salt without validating that the offset is within the buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::StringData::size
HPHP::StringData::size() const
[]
inline int StringData::size() const { return m_len; }
11
True
1
CVE-2021-24025
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Third Party Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-190'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndIncluding': '4.93.1', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndIncluding': '4.80.1', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Due to incorrect string size calculations inside the preg_quote function, a large input string passed to the function can trigger an integer overflow leading to a heap overflow. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-16T12:45Z
2021-03-10T16:15Z
Integer Overflow or Wraparound
The software performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
An integer overflow or wraparound occurs when an integer value is incremented to a value that is too large to store in the associated representation. When this occurs, the value may wrap to become a very small or negative number. While this may be intended behavior in circumstances that rely on wrapping, it can have security consequences if the wrap is unexpected. This is especially the case if the integer overflow can be triggered using user-supplied inputs. This becomes security-critical when the result is used to control looping, make a security decision, or determine the offset or size in behaviors such as memory allocation, copying, concatenation, etc.
https://cwe.mitre.org/data/definitions/190.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::StringData::size
HPHP::StringData::size() const
[]
inline int StringData::size() const { return m_len; }
11
True
1
CVE-2020-1917
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'xbuf_format_converter, used as part of exif_read_data, was appending a terminating null character to the generated string, but was not using its standard append char function. As a result, if the buffer was full, it would result in an out-of-bounds write. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-17T19:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::String::length
HPHP::String::length() const
[]
int length() const { return m_str ? m_str->size() : 0; }
17
True
1
CVE-2020-1918
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In-memory file operations (ie: using fopen on a data URI) did not properly restrict negative seeking, allowing for the reading of memory prior to the in-memory buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:53Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::String::length
HPHP::String::length() const
[]
int length() const { return m_str ? m_str->size() : 0; }
17
True
1
CVE-2020-1919
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Incorrect bounds calculations in substr_compare could lead to an out-of-bounds read when the second string argument passed in is longer than the first. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:51Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::String::length
HPHP::String::length() const
[]
int length() const { return m_str ? m_str->size() : 0; }
17
True
1
CVE-2020-1921
False
False
False
False
AV:N/AC:L/Au:N/C:N/I:N/A:P
NETWORK
LOW
NONE
NONE
NONE
PARTIAL
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
NONE
NONE
HIGH
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In the crypt function, we attempt to null terminate a buffer using the size of the input salt without validating that the offset is within the buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::String::length
HPHP::String::length() const
[]
int length() const { return m_str ? m_str->size() : 0; }
17
True
1
CVE-2021-24025
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Third Party Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-190'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndIncluding': '4.93.1', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndIncluding': '4.80.1', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Due to incorrect string size calculations inside the preg_quote function, a large input string passed to the function can trigger an integer overflow leading to a heap overflow. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-16T12:45Z
2021-03-10T16:15Z
Integer Overflow or Wraparound
The software performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
An integer overflow or wraparound occurs when an integer value is incremented to a value that is too large to store in the associated representation. When this occurs, the value may wrap to become a very small or negative number. While this may be intended behavior in circumstances that rely on wrapping, it can have security consequences if the wrap is unexpected. This is especially the case if the integer overflow can be triggered using user-supplied inputs. This becomes security-critical when the result is used to control looping, make a security decision, or determine the offset or size in behaviors such as memory allocation, copying, concatenation, etc.
https://cwe.mitre.org/data/definitions/190.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::String::length
HPHP::String::length() const
[]
int length() const { return m_str ? m_str->size() : 0; }
17
True
1
CVE-2020-1917
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'xbuf_format_converter, used as part of exif_read_data, was appending a terminating null character to the generated string, but was not using its standard append char function. As a result, if the buffer was full, it would result in an out-of-bounds write. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-17T19:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::String::setSize
HPHP::String::setSize( int len)
['len']
const String& setSize(int len) { assertx(m_str); m_str->setSize(len); return *this; }
23
True
1
CVE-2020-1918
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In-memory file operations (ie: using fopen on a data URI) did not properly restrict negative seeking, allowing for the reading of memory prior to the in-memory buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:53Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::String::setSize
HPHP::String::setSize( int len)
['len']
const String& setSize(int len) { assertx(m_str); m_str->setSize(len); return *this; }
23
True
1
CVE-2020-1919
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Incorrect bounds calculations in substr_compare could lead to an out-of-bounds read when the second string argument passed in is longer than the first. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:51Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::String::setSize
HPHP::String::setSize( int len)
['len']
const String& setSize(int len) { assertx(m_str); m_str->setSize(len); return *this; }
23
True
1
CVE-2020-1921
False
False
False
False
AV:N/AC:L/Au:N/C:N/I:N/A:P
NETWORK
LOW
NONE
NONE
NONE
PARTIAL
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
NONE
NONE
HIGH
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In the crypt function, we attempt to null terminate a buffer using the size of the input salt without validating that the offset is within the buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::String::setSize
HPHP::String::setSize( int len)
['len']
const String& setSize(int len) { assertx(m_str); m_str->setSize(len); return *this; }
23
True
1
CVE-2021-24025
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Third Party Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-190'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndIncluding': '4.93.1', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndIncluding': '4.80.1', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Due to incorrect string size calculations inside the preg_quote function, a large input string passed to the function can trigger an integer overflow leading to a heap overflow. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-16T12:45Z
2021-03-10T16:15Z
Integer Overflow or Wraparound
The software performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
An integer overflow or wraparound occurs when an integer value is incremented to a value that is too large to store in the associated representation. When this occurs, the value may wrap to become a very small or negative number. While this may be intended behavior in circumstances that rely on wrapping, it can have security consequences if the wrap is unexpected. This is especially the case if the integer overflow can be triggered using user-supplied inputs. This becomes security-critical when the result is used to control looping, make a security decision, or determine the offset or size in behaviors such as memory allocation, copying, concatenation, etc.
https://cwe.mitre.org/data/definitions/190.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::String::setSize
HPHP::String::setSize( int len)
['len']
const String& setSize(int len) { assertx(m_str); m_str->setSize(len); return *this; }
23
True
1
CVE-2020-1917
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'xbuf_format_converter, used as part of exif_read_data, was appending a terminating null character to the generated string, but was not using its standard append char function. As a result, if the buffer was full, it would result in an out-of-bounds write. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-17T19:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::String::size
HPHP::String::size() const
[]
int size() const { return m_str ? m_str->size() : 0; }
17
True
1
CVE-2020-1918
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In-memory file operations (ie: using fopen on a data URI) did not properly restrict negative seeking, allowing for the reading of memory prior to the in-memory buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:53Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::String::size
HPHP::String::size() const
[]
int size() const { return m_str ? m_str->size() : 0; }
17
True
1
CVE-2020-1919
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Incorrect bounds calculations in substr_compare could lead to an out-of-bounds read when the second string argument passed in is longer than the first. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:51Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::String::size
HPHP::String::size() const
[]
int size() const { return m_str ? m_str->size() : 0; }
17
True
1
CVE-2020-1921
False
False
False
False
AV:N/AC:L/Au:N/C:N/I:N/A:P
NETWORK
LOW
NONE
NONE
NONE
PARTIAL
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
NONE
NONE
HIGH
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In the crypt function, we attempt to null terminate a buffer using the size of the input salt without validating that the offset is within the buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::String::size
HPHP::String::size() const
[]
int size() const { return m_str ? m_str->size() : 0; }
17
True
1
CVE-2021-24025
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Third Party Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-190'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndIncluding': '4.93.1', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndIncluding': '4.80.1', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Due to incorrect string size calculations inside the preg_quote function, a large input string passed to the function can trigger an integer overflow leading to a heap overflow. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-16T12:45Z
2021-03-10T16:15Z
Integer Overflow or Wraparound
The software performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
An integer overflow or wraparound occurs when an integer value is incremented to a value that is too large to store in the associated representation. When this occurs, the value may wrap to become a very small or negative number. While this may be intended behavior in circumstances that rely on wrapping, it can have security consequences if the wrap is unexpected. This is especially the case if the integer overflow can be triggered using user-supplied inputs. This becomes security-critical when the result is used to control looping, make a security decision, or determine the offset or size in behaviors such as memory allocation, copying, concatenation, etc.
https://cwe.mitre.org/data/definitions/190.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::String::size
HPHP::String::size() const
[]
int size() const { return m_str ? m_str->size() : 0; }
17
True
1
CVE-2020-1917
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'xbuf_format_converter, used as part of exif_read_data, was appending a terminating null character to the generated string, but was not using its standard append char function. As a result, if the buffer was full, it would result in an out-of-bounds write. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-17T19:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::MemoProfiler::writeStats
HPHP::MemoProfiler::writeStats( Array &)
[]
void writeStats(Array& /*ret*/) override { fprintf(stderr, "writeStats start\n"); // RetSame: the return value is the same instance every time // HasThis: call has a this argument // AllSame: all returns were the same data even though args are different // MemberCount: number of different arg sets (including this) fprintf(stderr, "Count Function MinSerLen MaxSerLen RetSame HasThis " "AllSame MemberCount\n"); for (auto& me : m_memos) { if (me.second.m_ignore) continue; if (me.second.m_count == 1) continue; int min_ser_len = 999999999; int max_ser_len = 0; int count = 0; int member_count = 0; bool all_same = true; if (me.second.m_has_this) { bool any_multiple = false; auto& fr = me.second.m_member_memos.begin()->second.m_return_value; member_count = me.second.m_member_memos.size(); for (auto& mme : me.second.m_member_memos) { if (mme.second.m_return_value != fr) all_same = false; count += mme.second.m_count; auto ser_len = mme.second.m_return_value.length(); min_ser_len = std::min(min_ser_len, ser_len); max_ser_len = std::max(max_ser_len, ser_len); if (mme.second.m_count > 1) any_multiple = true; } if (!any_multiple && !all_same) continue; } else { min_ser_len = max_ser_len = me.second.m_return_value.length(); count = me.second.m_count; all_same = me.second.m_ret_tv_same; } fprintf(stderr, "%d %s %d %d %s %s %s %d\n", count, me.first.data(), min_ser_len, max_ser_len, me.second.m_ret_tv_same ? " true" : "false", me.second.m_has_this ? " true" : "false", all_same ? " true" : "false", member_count ); } fprintf(stderr, "writeStats end\n"); }
309
True
1
CVE-2020-1918
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In-memory file operations (ie: using fopen on a data URI) did not properly restrict negative seeking, allowing for the reading of memory prior to the in-memory buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:53Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::MemoProfiler::writeStats
HPHP::MemoProfiler::writeStats( Array &)
[]
void writeStats(Array& /*ret*/) override { fprintf(stderr, "writeStats start\n"); // RetSame: the return value is the same instance every time // HasThis: call has a this argument // AllSame: all returns were the same data even though args are different // MemberCount: number of different arg sets (including this) fprintf(stderr, "Count Function MinSerLen MaxSerLen RetSame HasThis " "AllSame MemberCount\n"); for (auto& me : m_memos) { if (me.second.m_ignore) continue; if (me.second.m_count == 1) continue; int min_ser_len = 999999999; int max_ser_len = 0; int count = 0; int member_count = 0; bool all_same = true; if (me.second.m_has_this) { bool any_multiple = false; auto& fr = me.second.m_member_memos.begin()->second.m_return_value; member_count = me.second.m_member_memos.size(); for (auto& mme : me.second.m_member_memos) { if (mme.second.m_return_value != fr) all_same = false; count += mme.second.m_count; auto ser_len = mme.second.m_return_value.length(); min_ser_len = std::min(min_ser_len, ser_len); max_ser_len = std::max(max_ser_len, ser_len); if (mme.second.m_count > 1) any_multiple = true; } if (!any_multiple && !all_same) continue; } else { min_ser_len = max_ser_len = me.second.m_return_value.length(); count = me.second.m_count; all_same = me.second.m_ret_tv_same; } fprintf(stderr, "%d %s %d %d %s %s %s %d\n", count, me.first.data(), min_ser_len, max_ser_len, me.second.m_ret_tv_same ? " true" : "false", me.second.m_has_this ? " true" : "false", all_same ? " true" : "false", member_count ); } fprintf(stderr, "writeStats end\n"); }
309
True
1
CVE-2020-1919
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Incorrect bounds calculations in substr_compare could lead to an out-of-bounds read when the second string argument passed in is longer than the first. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:51Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::MemoProfiler::writeStats
HPHP::MemoProfiler::writeStats( Array &)
[]
void writeStats(Array& /*ret*/) override { fprintf(stderr, "writeStats start\n"); // RetSame: the return value is the same instance every time // HasThis: call has a this argument // AllSame: all returns were the same data even though args are different // MemberCount: number of different arg sets (including this) fprintf(stderr, "Count Function MinSerLen MaxSerLen RetSame HasThis " "AllSame MemberCount\n"); for (auto& me : m_memos) { if (me.second.m_ignore) continue; if (me.second.m_count == 1) continue; int min_ser_len = 999999999; int max_ser_len = 0; int count = 0; int member_count = 0; bool all_same = true; if (me.second.m_has_this) { bool any_multiple = false; auto& fr = me.second.m_member_memos.begin()->second.m_return_value; member_count = me.second.m_member_memos.size(); for (auto& mme : me.second.m_member_memos) { if (mme.second.m_return_value != fr) all_same = false; count += mme.second.m_count; auto ser_len = mme.second.m_return_value.length(); min_ser_len = std::min(min_ser_len, ser_len); max_ser_len = std::max(max_ser_len, ser_len); if (mme.second.m_count > 1) any_multiple = true; } if (!any_multiple && !all_same) continue; } else { min_ser_len = max_ser_len = me.second.m_return_value.length(); count = me.second.m_count; all_same = me.second.m_ret_tv_same; } fprintf(stderr, "%d %s %d %d %s %s %s %d\n", count, me.first.data(), min_ser_len, max_ser_len, me.second.m_ret_tv_same ? " true" : "false", me.second.m_has_this ? " true" : "false", all_same ? " true" : "false", member_count ); } fprintf(stderr, "writeStats end\n"); }
309
True
1
CVE-2020-1921
False
False
False
False
AV:N/AC:L/Au:N/C:N/I:N/A:P
NETWORK
LOW
NONE
NONE
NONE
PARTIAL
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
NONE
NONE
HIGH
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In the crypt function, we attempt to null terminate a buffer using the size of the input salt without validating that the offset is within the buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::MemoProfiler::writeStats
HPHP::MemoProfiler::writeStats( Array &)
[]
void writeStats(Array& /*ret*/) override { fprintf(stderr, "writeStats start\n"); // RetSame: the return value is the same instance every time // HasThis: call has a this argument // AllSame: all returns were the same data even though args are different // MemberCount: number of different arg sets (including this) fprintf(stderr, "Count Function MinSerLen MaxSerLen RetSame HasThis " "AllSame MemberCount\n"); for (auto& me : m_memos) { if (me.second.m_ignore) continue; if (me.second.m_count == 1) continue; int min_ser_len = 999999999; int max_ser_len = 0; int count = 0; int member_count = 0; bool all_same = true; if (me.second.m_has_this) { bool any_multiple = false; auto& fr = me.second.m_member_memos.begin()->second.m_return_value; member_count = me.second.m_member_memos.size(); for (auto& mme : me.second.m_member_memos) { if (mme.second.m_return_value != fr) all_same = false; count += mme.second.m_count; auto ser_len = mme.second.m_return_value.length(); min_ser_len = std::min(min_ser_len, ser_len); max_ser_len = std::max(max_ser_len, ser_len); if (mme.second.m_count > 1) any_multiple = true; } if (!any_multiple && !all_same) continue; } else { min_ser_len = max_ser_len = me.second.m_return_value.length(); count = me.second.m_count; all_same = me.second.m_ret_tv_same; } fprintf(stderr, "%d %s %d %d %s %s %s %d\n", count, me.first.data(), min_ser_len, max_ser_len, me.second.m_ret_tv_same ? " true" : "false", me.second.m_has_this ? " true" : "false", all_same ? " true" : "false", member_count ); } fprintf(stderr, "writeStats end\n"); }
309
True
1
CVE-2021-24025
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Third Party Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-190'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndIncluding': '4.93.1', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndIncluding': '4.80.1', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Due to incorrect string size calculations inside the preg_quote function, a large input string passed to the function can trigger an integer overflow leading to a heap overflow. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-16T12:45Z
2021-03-10T16:15Z
Integer Overflow or Wraparound
The software performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
An integer overflow or wraparound occurs when an integer value is incremented to a value that is too large to store in the associated representation. When this occurs, the value may wrap to become a very small or negative number. While this may be intended behavior in circumstances that rely on wrapping, it can have security consequences if the wrap is unexpected. This is especially the case if the integer overflow can be triggered using user-supplied inputs. This becomes security-critical when the result is used to control looping, make a security decision, or determine the offset or size in behaviors such as memory allocation, copying, concatenation, etc.
https://cwe.mitre.org/data/definitions/190.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::MemoProfiler::writeStats
HPHP::MemoProfiler::writeStats( Array &)
[]
void writeStats(Array& /*ret*/) override { fprintf(stderr, "writeStats start\n"); // RetSame: the return value is the same instance every time // HasThis: call has a this argument // AllSame: all returns were the same data even though args are different // MemberCount: number of different arg sets (including this) fprintf(stderr, "Count Function MinSerLen MaxSerLen RetSame HasThis " "AllSame MemberCount\n"); for (auto& me : m_memos) { if (me.second.m_ignore) continue; if (me.second.m_count == 1) continue; int min_ser_len = 999999999; int max_ser_len = 0; int count = 0; int member_count = 0; bool all_same = true; if (me.second.m_has_this) { bool any_multiple = false; auto& fr = me.second.m_member_memos.begin()->second.m_return_value; member_count = me.second.m_member_memos.size(); for (auto& mme : me.second.m_member_memos) { if (mme.second.m_return_value != fr) all_same = false; count += mme.second.m_count; auto ser_len = mme.second.m_return_value.length(); min_ser_len = std::min(min_ser_len, ser_len); max_ser_len = std::max(max_ser_len, ser_len); if (mme.second.m_count > 1) any_multiple = true; } if (!any_multiple && !all_same) continue; } else { min_ser_len = max_ser_len = me.second.m_return_value.length(); count = me.second.m_count; all_same = me.second.m_ret_tv_same; } fprintf(stderr, "%d %s %d %d %s %s %s %d\n", count, me.first.data(), min_ser_len, max_ser_len, me.second.m_ret_tv_same ? " true" : "false", me.second.m_has_this ? " true" : "false", all_same ? " true" : "false", member_count ); } fprintf(stderr, "writeStats end\n"); }
309
True
1
CVE-2020-1917
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'xbuf_format_converter, used as part of exif_read_data, was appending a terminating null character to the generated string, but was not using its standard append char function. As a result, if the buffer was full, it would result in an out-of-bounds write. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-17T19:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::HHVM_FUNCTION
HPHP::HHVM_FUNCTION( mcrypt_generic_init , const Resource & td , const String & key , const String & iv)
['mcrypt_generic_init', 'td', 'key', 'iv']
Variant HHVM_FUNCTION(mcrypt_generic_init, const Resource& td, const String& key, const String& iv) { auto pm = get_valid_mcrypt_resource(td); if (!pm) { return false; } int max_key_size = mcrypt_enc_get_key_size(pm->m_td); int iv_size = mcrypt_enc_get_iv_size(pm->m_td); if (key.empty()) { raise_warning("Key size is 0"); } unsigned char *key_s = (unsigned char *)malloc(key.size()); memset(key_s, 0, key.size()); unsigned char *iv_s = (unsigned char *)malloc(iv_size + 1); memset(iv_s, 0, iv_size + 1); int key_size; if (key.size() > max_key_size) { raise_warning("Key size too large; supplied length: %d, max: %d", key.size(), max_key_size); key_size = max_key_size; } else { key_size = key.size(); } memcpy(key_s, key.data(), key.size()); if (iv.size() != iv_size) { raise_warning("Iv size incorrect; supplied length: %d, needed: %d", iv.size(), iv_size); } memcpy(iv_s, iv.data(), std::min(iv_size, iv.size())); mcrypt_generic_deinit(pm->m_td); int result = mcrypt_generic_init(pm->m_td, key_s, key_size, iv_s); /* If this function fails, close the mcrypt module to prevent crashes * when further functions want to access this resource */ if (result < 0) { pm->close(); switch (result) { case -3: raise_warning("Key length incorrect"); break; case -4: raise_warning("Memory allocation error"); break; case -1: default: raise_warning("Unknown error"); break; } } else { pm->m_init = true; } free(iv_s); free(key_s); return result; }
343
True
1
CVE-2020-1918
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In-memory file operations (ie: using fopen on a data URI) did not properly restrict negative seeking, allowing for the reading of memory prior to the in-memory buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:53Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::HHVM_FUNCTION
HPHP::HHVM_FUNCTION( mcrypt_generic_init , const Resource & td , const String & key , const String & iv)
['mcrypt_generic_init', 'td', 'key', 'iv']
Variant HHVM_FUNCTION(mcrypt_generic_init, const Resource& td, const String& key, const String& iv) { auto pm = get_valid_mcrypt_resource(td); if (!pm) { return false; } int max_key_size = mcrypt_enc_get_key_size(pm->m_td); int iv_size = mcrypt_enc_get_iv_size(pm->m_td); if (key.empty()) { raise_warning("Key size is 0"); } unsigned char *key_s = (unsigned char *)malloc(key.size()); memset(key_s, 0, key.size()); unsigned char *iv_s = (unsigned char *)malloc(iv_size + 1); memset(iv_s, 0, iv_size + 1); int key_size; if (key.size() > max_key_size) { raise_warning("Key size too large; supplied length: %d, max: %d", key.size(), max_key_size); key_size = max_key_size; } else { key_size = key.size(); } memcpy(key_s, key.data(), key.size()); if (iv.size() != iv_size) { raise_warning("Iv size incorrect; supplied length: %d, needed: %d", iv.size(), iv_size); } memcpy(iv_s, iv.data(), std::min(iv_size, iv.size())); mcrypt_generic_deinit(pm->m_td); int result = mcrypt_generic_init(pm->m_td, key_s, key_size, iv_s); /* If this function fails, close the mcrypt module to prevent crashes * when further functions want to access this resource */ if (result < 0) { pm->close(); switch (result) { case -3: raise_warning("Key length incorrect"); break; case -4: raise_warning("Memory allocation error"); break; case -1: default: raise_warning("Unknown error"); break; } } else { pm->m_init = true; } free(iv_s); free(key_s); return result; }
343
True
1
CVE-2020-1919
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Incorrect bounds calculations in substr_compare could lead to an out-of-bounds read when the second string argument passed in is longer than the first. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:51Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::HHVM_FUNCTION
HPHP::HHVM_FUNCTION( mcrypt_generic_init , const Resource & td , const String & key , const String & iv)
['mcrypt_generic_init', 'td', 'key', 'iv']
Variant HHVM_FUNCTION(mcrypt_generic_init, const Resource& td, const String& key, const String& iv) { auto pm = get_valid_mcrypt_resource(td); if (!pm) { return false; } int max_key_size = mcrypt_enc_get_key_size(pm->m_td); int iv_size = mcrypt_enc_get_iv_size(pm->m_td); if (key.empty()) { raise_warning("Key size is 0"); } unsigned char *key_s = (unsigned char *)malloc(key.size()); memset(key_s, 0, key.size()); unsigned char *iv_s = (unsigned char *)malloc(iv_size + 1); memset(iv_s, 0, iv_size + 1); int key_size; if (key.size() > max_key_size) { raise_warning("Key size too large; supplied length: %d, max: %d", key.size(), max_key_size); key_size = max_key_size; } else { key_size = key.size(); } memcpy(key_s, key.data(), key.size()); if (iv.size() != iv_size) { raise_warning("Iv size incorrect; supplied length: %d, needed: %d", iv.size(), iv_size); } memcpy(iv_s, iv.data(), std::min(iv_size, iv.size())); mcrypt_generic_deinit(pm->m_td); int result = mcrypt_generic_init(pm->m_td, key_s, key_size, iv_s); /* If this function fails, close the mcrypt module to prevent crashes * when further functions want to access this resource */ if (result < 0) { pm->close(); switch (result) { case -3: raise_warning("Key length incorrect"); break; case -4: raise_warning("Memory allocation error"); break; case -1: default: raise_warning("Unknown error"); break; } } else { pm->m_init = true; } free(iv_s); free(key_s); return result; }
343
True
1
CVE-2020-1921
False
False
False
False
AV:N/AC:L/Au:N/C:N/I:N/A:P
NETWORK
LOW
NONE
NONE
NONE
PARTIAL
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
NONE
NONE
HIGH
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In the crypt function, we attempt to null terminate a buffer using the size of the input salt without validating that the offset is within the buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::HHVM_FUNCTION
HPHP::HHVM_FUNCTION( mcrypt_generic_init , const Resource & td , const String & key , const String & iv)
['mcrypt_generic_init', 'td', 'key', 'iv']
Variant HHVM_FUNCTION(mcrypt_generic_init, const Resource& td, const String& key, const String& iv) { auto pm = get_valid_mcrypt_resource(td); if (!pm) { return false; } int max_key_size = mcrypt_enc_get_key_size(pm->m_td); int iv_size = mcrypt_enc_get_iv_size(pm->m_td); if (key.empty()) { raise_warning("Key size is 0"); } unsigned char *key_s = (unsigned char *)malloc(key.size()); memset(key_s, 0, key.size()); unsigned char *iv_s = (unsigned char *)malloc(iv_size + 1); memset(iv_s, 0, iv_size + 1); int key_size; if (key.size() > max_key_size) { raise_warning("Key size too large; supplied length: %d, max: %d", key.size(), max_key_size); key_size = max_key_size; } else { key_size = key.size(); } memcpy(key_s, key.data(), key.size()); if (iv.size() != iv_size) { raise_warning("Iv size incorrect; supplied length: %d, needed: %d", iv.size(), iv_size); } memcpy(iv_s, iv.data(), std::min(iv_size, iv.size())); mcrypt_generic_deinit(pm->m_td); int result = mcrypt_generic_init(pm->m_td, key_s, key_size, iv_s); /* If this function fails, close the mcrypt module to prevent crashes * when further functions want to access this resource */ if (result < 0) { pm->close(); switch (result) { case -3: raise_warning("Key length incorrect"); break; case -4: raise_warning("Memory allocation error"); break; case -1: default: raise_warning("Unknown error"); break; } } else { pm->m_init = true; } free(iv_s); free(key_s); return result; }
343
True
1
CVE-2021-24025
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Third Party Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-190'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndIncluding': '4.93.1', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndIncluding': '4.80.1', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Due to incorrect string size calculations inside the preg_quote function, a large input string passed to the function can trigger an integer overflow leading to a heap overflow. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-16T12:45Z
2021-03-10T16:15Z
Integer Overflow or Wraparound
The software performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
An integer overflow or wraparound occurs when an integer value is incremented to a value that is too large to store in the associated representation. When this occurs, the value may wrap to become a very small or negative number. While this may be intended behavior in circumstances that rely on wrapping, it can have security consequences if the wrap is unexpected. This is especially the case if the integer overflow can be triggered using user-supplied inputs. This becomes security-critical when the result is used to control looping, make a security decision, or determine the offset or size in behaviors such as memory allocation, copying, concatenation, etc.
https://cwe.mitre.org/data/definitions/190.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::HHVM_FUNCTION
HPHP::HHVM_FUNCTION( mcrypt_generic_init , const Resource & td , const String & key , const String & iv)
['mcrypt_generic_init', 'td', 'key', 'iv']
Variant HHVM_FUNCTION(mcrypt_generic_init, const Resource& td, const String& key, const String& iv) { auto pm = get_valid_mcrypt_resource(td); if (!pm) { return false; } int max_key_size = mcrypt_enc_get_key_size(pm->m_td); int iv_size = mcrypt_enc_get_iv_size(pm->m_td); if (key.empty()) { raise_warning("Key size is 0"); } unsigned char *key_s = (unsigned char *)malloc(key.size()); memset(key_s, 0, key.size()); unsigned char *iv_s = (unsigned char *)malloc(iv_size + 1); memset(iv_s, 0, iv_size + 1); int key_size; if (key.size() > max_key_size) { raise_warning("Key size too large; supplied length: %d, max: %d", key.size(), max_key_size); key_size = max_key_size; } else { key_size = key.size(); } memcpy(key_s, key.data(), key.size()); if (iv.size() != iv_size) { raise_warning("Iv size incorrect; supplied length: %d, needed: %d", iv.size(), iv_size); } memcpy(iv_s, iv.data(), std::min(iv_size, iv.size())); mcrypt_generic_deinit(pm->m_td); int result = mcrypt_generic_init(pm->m_td, key_s, key_size, iv_s); /* If this function fails, close the mcrypt module to prevent crashes * when further functions want to access this resource */ if (result < 0) { pm->close(); switch (result) { case -3: raise_warning("Key length incorrect"); break; case -4: raise_warning("Memory allocation error"); break; case -1: default: raise_warning("Unknown error"); break; } } else { pm->m_init = true; } free(iv_s); free(key_s); return result; }
343
True
1
CVE-2020-1917
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'xbuf_format_converter, used as part of exif_read_data, was appending a terminating null character to the generated string, but was not using its standard append char function. As a result, if the buffer was full, it would result in an out-of-bounds write. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-17T19:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::php_openssl_config_check_syntax
HPHP::php_openssl_config_check_syntax( const char * section_label , const char * config_filename , const char * section , LHASH_OF(CONF_VALUE) * config)
['section_label', 'config_filename', 'section', 'config']
static inline bool php_openssl_config_check_syntax (const char *section_label, const char *config_filename, const char *section, LHASH_OF(CONF_VALUE) *config) { #else static inline bool php_openssl_config_check_syntax (const char *section_label, const char *config_filename, const char *section, LHASH *config) { #endif X509V3_CTX ctx; X509V3_set_ctx_test(&ctx); X509V3_set_conf_lhash(&ctx, config); if (!X509V3_EXT_add_conf(config, &ctx, (char*)section, nullptr)) { raise_warning("Error loading %s section %s of %s", section_label, section, config_filename); return false; } return true; } const StaticString s_config("config"), s_config_section_name("config_section_name"), s_digest_alg("digest_alg"), s_x509_extensions("x509_extensions"), s_req_extensions("req_extensions"), s_private_key_bits("private_key_bits"), s_private_key_type("private_key_type"), s_encrypt_key("encrypt_key"), s_curve_name("curve_name"); static bool php_openssl_parse_config(struct php_x509_request *req, const Array& args, std::vector<String> &strings) { req->config_filename = read_string(args, s_config, default_ssl_conf_filename, strings); req->section_name = read_string(args, s_config_section_name, "req", strings); req->global_config = CONF_load(nullptr, default_ssl_conf_filename, nullptr); req->req_config = CONF_load(nullptr, req->config_filename, nullptr); if (req->req_config == nullptr) { return false; } /* read in the oids */ char *str = CONF_get_string(req->req_config, nullptr, "oid_file"); if (str) { BIO *oid_bio = BIO_new_file(str, "r"); if (oid_bio) { OBJ_create_objects(oid_bio); BIO_free(oid_bio); } } if (!add_oid_section(req)) { return false; } req->digest_name = read_string(args, s_digest_alg, CONF_get_string(req->req_config, req->section_name, "default_md"), strings); req->extensions_section = read_string(args, s_x509_extensions, CONF_get_string(req->req_config, req->section_name, "x509_extensions"), strings); req->request_extensions_section = read_string(args, s_req_extensions, CONF_get_string(req->req_config, req->section_name, "req_extensions"), strings); req->priv_key_bits = read_integer(args, s_private_key_bits, CONF_get_number(req->req_config, req->section_name, "default_bits")); req->priv_key_type = read_integer(args, s_private_key_type, OPENSSL_KEYTYPE_DEFAULT); if (args.exists(s_encrypt_key)) { bool value = args[s_encrypt_key].toBoolean(); req->priv_key_encrypt = value ? 1 : 0; } else { str = CONF_get_string(req->req_config, req->section_name, "encrypt_rsa_key"); if (str == nullptr) { str = CONF_get_string(req->req_config, req->section_name, "encrypt_key"); } if (str && strcmp(str, "no") == 0) { req->priv_key_encrypt = 0; } else { req->priv_key_encrypt = 1; } } /* digest alg */ if (req->digest_name == nullptr) { req->digest_name = CONF_get_string(req->req_config, req->section_name, "default_md"); } if (req->digest_name) { req->digest = req->md_alg = EVP_get_digestbyname(req->digest_name); } if (req->md_alg == nullptr) { req->md_alg = req->digest = EVP_sha256(); } #ifdef HAVE_EVP_PKEY_EC /* set the ec group curve name */ req->curve_name = NID_undef; if (args.exists(s_curve_name)) { auto const curve_name = args[s_curve_name].toString(); req->curve_name = OBJ_sn2nid(curve_name.data()); if (req->curve_name == NID_undef) { raise_warning( "Unknown elliptic curve (short) name %s", curve_name.data() ); return false; } } #endif if (req->extensions_section && !php_openssl_config_check_syntax ("extensions_section", req->config_filename, req->extensions_section, req->req_config)) { return false; } /* set the string mask */ str = CONF_get_string(req->req_config, req->section_name, "string_mask"); if (str && !ASN1_STRING_set_default_mask_asc(str)) { raise_warning("Invalid global string mask setting %s", str); return false; } if (req->request_extensions_section && !php_openssl_config_check_syntax ("request_extensions_section", req->config_filename, req->request_extensions_section, req->req_config)) { return false; } return true; } static void php_openssl_dispose_config(struct php_x509_request *req) { if (req->global_config) { CONF_free(req->global_config); req->global_config = nullptr; } if (req->req_config) { CONF_free(req->req_config); req->req_config = nullptr; } } static STACK_OF(X509) *load_all_certs_from_file(const char *certfile) { STACK_OF(X509_INFO) *sk = nullptr; STACK_OF(X509) *stack = nullptr, *ret = nullptr; BIO *in = nullptr; X509_INFO *xi; if (!(stack = sk_X509_new_null())) { raise_warning("memory allocation failure"); goto end; } if (!(in = BIO_new_file(certfile, "r"))) { raise_warning("error opening the file, %s", certfile); sk_X509_free(stack); goto end; } /* This loads from a file, a stack of x509/crl/pkey sets */ if (!(sk = PEM_X509_INFO_read_bio(in, nullptr, nullptr, nullptr))) { raise_warning("error reading the file, %s", certfile); sk_X509_free(stack); goto end; } /* scan over it and pull out the certs */ while (sk_X509_INFO_num(sk)) { xi = sk_X509_INFO_shift(sk); if (xi->x509 != nullptr) { sk_X509_push(stack, xi->x509); xi->x509 = nullptr; } X509_INFO_free(xi); } if (!sk_X509_num(stack)) { raise_warning("no certificates in file, %s", certfile); sk_X509_free(stack); goto end; } ret = stack; end: BIO_free(in); sk_X509_INFO_free(sk); return ret; } /** * calist is an array containing file and directory names. create a * certificate store and add those certs to it for use in verification. */ static X509_STORE *setup_verify(const Array& calist) { X509_STORE *store = X509_STORE_new(); if (store == nullptr) { return nullptr; } X509_LOOKUP *dir_lookup, *file_lookup; int ndirs = 0, nfiles = 0; for (ArrayIter iter(calist); iter; ++iter) { String item = iter.second().toString(); struct stat sb; if (stat(item.data(), &sb) == -1) { raise_warning("unable to stat %s", item.data()); continue; } if ((sb.st_mode & S_IFREG) == S_IFREG) { file_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()); if (file_lookup == nullptr || !X509_LOOKUP_load_file(file_lookup, item.data(), X509_FILETYPE_PEM)) { raise_warning("error loading file %s", item.data()); } else { nfiles++; } file_lookup = nullptr; } else { dir_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir()); if (dir_lookup == nullptr || !X509_LOOKUP_add_dir(dir_lookup, item.data(), X509_FILETYPE_PEM)) { raise_warning("error loading directory %s", item.data()); } else { ndirs++; } dir_lookup = nullptr; } } if (nfiles == 0) { file_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()); if (file_lookup) { X509_LOOKUP_load_file(file_lookup, nullptr, X509_FILETYPE_DEFAULT); } } if (ndirs == 0) { dir_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir()); if (dir_lookup) { X509_LOOKUP_add_dir(dir_lookup, nullptr, X509_FILETYPE_DEFAULT); } } return store; } /////////////////////////////////////////////////////////////////////////////// static bool add_entries(X509_NAME *subj, const Array& items) { for (ArrayIter iter(items); iter; ++iter) { auto const index = iter.first().toString(); auto const item = iter.second().toString(); int nid = OBJ_txt2nid(index.data()); if (nid != NID_undef) { if (!X509_NAME_add_entry_by_NID(subj, nid, MBSTRING_ASC, (unsigned char*)item.data(), -1, -1, 0)) { raise_warning("dn: add_entry_by_NID %d -> %s (failed)", nid, item.data()); return false; } } else { raise_warning("dn: %s is not a recognized name", index.data()); } } return true; } static bool php_openssl_make_REQ(struct php_x509_request *req, X509_REQ *csr, const Array& dn, const Array& attribs) { char *dn_sect = CONF_get_string(req->req_config, req->section_name, "distinguished_name"); if (dn_sect == nullptr) return false; STACK_OF(CONF_VALUE) *dn_sk = CONF_get_section(req->req_config, dn_sect); if (dn_sk == nullptr) return false; char *attr_sect = CONF_get_string(req->req_config, req->section_name, "attributes"); STACK_OF(CONF_VALUE) *attr_sk = nullptr; if (attr_sect) { attr_sk = CONF_get_section(req->req_config, attr_sect); if (attr_sk == nullptr) { return false; } } /* setup the version number: version 1 */ if (X509_REQ_set_version(csr, 0L)) { X509_NAME *subj = X509_REQ_get_subject_name(csr); if (!add_entries(subj, dn)) return false; /* Finally apply defaults from config file */ for (int i = 0; i < sk_CONF_VALUE_num(dn_sk); i++) { CONF_VALUE *v = sk_CONF_VALUE_value(dn_sk, i); char *type = v->name; int len = strlen(type); if (len < (int)sizeof("_default")) { continue; } len -= sizeof("_default") - 1; if (strcmp("_default", type + len) != 0) { continue; } if (len > 200) { len = 200; } char buffer[200 + 1]; /*200 + \0 !*/ memcpy(buffer, type, len); buffer[len] = '\0'; type = buffer; /* Skip past any leading X. X: X, etc to allow for multiple instances */ for (char *str = type; *str; str++) { if (*str == ':' || *str == ',' || *str == '.') { str++; if (*str) { type = str; } break; } } /* if it is already set, skip this */ int nid = OBJ_txt2nid(type); if (X509_NAME_get_index_by_NID(subj, nid, -1) >= 0) { continue; } if (!X509_NAME_add_entry_by_txt(subj, type, MBSTRING_ASC, (unsigned char*)v->value, -1, -1, 0)) { raise_warning("add_entry_by_txt %s -> %s (failed)", type, v->value); return false; } if (!X509_NAME_entry_count(subj)) { raise_warning("no objects specified in config file"); return false; } } if (!add_entries(subj, attribs)) return false; if (attr_sk) { for (int i = 0; i < sk_CONF_VALUE_num(attr_sk); i++) { CONF_VALUE *v = sk_CONF_VALUE_value(attr_sk, i); /* if it is already set, skip this */ int nid = OBJ_txt2nid(v->name); if (X509_REQ_get_attr_by_NID(csr, nid, -1) >= 0) { continue; } if (!X509_REQ_add1_attr_by_txt(csr, v->name, MBSTRING_ASC, (unsigned char*)v->value, -1)) { /** * hzhao: mismatched version of conf file may have attributes that * are not recognizable, and I don't think it should be treated as * fatal errors. */ Logger::Verbose("add1_attr_by_txt %s -> %s (failed)", v->name, v->value); // return false; } } } } X509_REQ_set_pubkey(csr, req->priv_key); return true; } bool HHVM_FUNCTION(openssl_csr_export_to_file, const Variant& csr, const String& outfilename, bool notext /* = true */) { auto pcsr = CSRequest::Get(csr); if (!pcsr) return false; BIO *bio_out = BIO_new_file((char*)outfilename.data(), "w"); if (bio_out == nullptr) { raise_warning("error opening file %s", outfilename.data()); return false; } if (!notext) { X509_REQ_print(bio_out, pcsr->csr()); } PEM_write_bio_X509_REQ(bio_out, pcsr->csr()); BIO_free(bio_out); return true; } bool HHVM_FUNCTION(openssl_csr_export, const Variant& csr, Variant& out, bool notext /* = true */) { auto pcsr = CSRequest::Get(csr); if (!pcsr) return false; BIO *bio_out = BIO_new(BIO_s_mem()); if (!notext) { X509_REQ_print(bio_out, pcsr->csr()); } if (PEM_write_bio_X509_REQ(bio_out, pcsr->csr())) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); out = String((char*)bio_buf->data, bio_buf->length, CopyString); BIO_free(bio_out); return true; } BIO_free(bio_out); return false; } Variant HHVM_FUNCTION(openssl_csr_get_public_key, const Variant& csr) { auto pcsr = CSRequest::Get(csr); if (!pcsr) return false; auto input_csr = pcsr->csr(); #if OPENSSL_VERSION_NUMBER >= 0x10100000 /* Due to changes in OpenSSL 1.1 related to locking when decoding CSR, * the pub key is not changed after assigning. It means if we pass * a private key, it will be returned including the private part. * If we duplicate it, then we get just the public part which is * the same behavior as for OpenSSL 1.0 */ input_csr = X509_REQ_dup(input_csr); /* We need to free the CSR as it was duplicated */ SCOPE_EXIT { X509_REQ_free(input_csr); }; #endif auto pubkey = X509_REQ_get_pubkey(input_csr); if (!pubkey) return false; return Variant(req::make<Key>(pubkey)); } Variant HHVM_FUNCTION(openssl_csr_get_subject, const Variant& csr, bool use_shortnames /* = true */) { auto pcsr = CSRequest::Get(csr); if (!pcsr) return false; X509_NAME *subject = X509_REQ_get_subject_name(pcsr->csr()); Array ret = Array::CreateDArray(); add_assoc_name_entry(ret, nullptr, subject, use_shortnames); return ret; } Variant HHVM_FUNCTION(openssl_csr_new, const Variant& dn, Variant& privkey, const Variant& configargs /* = uninit_variant */, const Variant& extraattribs /* = uninit_variant */) { Variant ret = false; struct php_x509_request req; memset(&req, 0, sizeof(req)); req::ptr<Key> okey; X509_REQ *csr = nullptr; std::vector<String> strings; if (php_openssl_parse_config(&req, configargs.toArray(), strings)) { /* Generate or use a private key */ if (!privkey.isNull()) { okey = Key::Get(privkey, false); if (okey) { req.priv_key = okey->m_key; } } if (req.priv_key == nullptr) { req.generatePrivateKey(); if (req.priv_key) { okey = req::make<Key>(req.priv_key); } } if (req.priv_key == nullptr) { raise_warning("Unable to generate a private key"); } else { csr = X509_REQ_new(); if (csr && php_openssl_make_REQ(&req, csr, dn.toArray(), extraattribs.toArray())) { X509V3_CTX ext_ctx; X509V3_set_ctx(&ext_ctx, nullptr, nullptr, csr, nullptr, 0); X509V3_set_conf_lhash(&ext_ctx, req.req_config); /* Add extensions */ if (req.request_extensions_section && !X509V3_EXT_REQ_add_conf(req.req_config, &ext_ctx, (char*)req.request_extensions_section, csr)) { raise_warning("Error loading extension section %s", req.request_extensions_section); } else { ret = true; if (X509_REQ_sign(csr, req.priv_key, req.digest)) { ret = req::make<CSRequest>(csr); csr = nullptr; } else { raise_warning("Error signing request"); } privkey = Variant(okey); } } } } if (csr) { X509_REQ_free(csr); } php_openssl_dispose_config(&req); return ret; } Variant HHVM_FUNCTION(openssl_csr_sign, const Variant& csr, const Variant& cacert, const Variant& priv_key, int days, const Variant& configargs /* = null */, int serial /* = 0 */) { auto pcsr = CSRequest::Get(csr); if (!pcsr) return false; req::ptr<Certificate> ocert; if (!cacert.isNull()) { ocert = Certificate::Get(cacert); if (!ocert) { raise_warning("cannot get cert from parameter 2"); return false; } } auto okey = Key::Get(priv_key, false); if (!okey) { raise_warning("cannot get private key from parameter 3"); return false; } X509 *cert = nullptr; if (ocert) { cert = ocert->m_cert; } EVP_PKEY *pkey = okey->m_key; if (cert && !X509_check_private_key(cert, pkey)) { raise_warning("private key does not correspond to signing cert"); return false; } req::ptr<Certificate> onewcert; struct php_x509_request req; memset(&req, 0, sizeof(req)); Variant ret = false; std::vector<String> strings; if (!php_openssl_parse_config(&req, configargs.toArray(), strings)) { goto cleanup; } /* Check that the request matches the signature */ EVP_PKEY *key; key = X509_REQ_get_pubkey(pcsr->csr()); if (key == nullptr) { raise_warning("error unpacking public key"); goto cleanup; } int i; i = X509_REQ_verify(pcsr->csr(), key); if (i < 0) { raise_warning("Signature verification problems"); goto cleanup; } if (i == 0) { raise_warning("Signature did not match the certificate request"); goto cleanup; } /* Now we can get on with it */ X509 *new_cert; new_cert = X509_new(); if (new_cert == nullptr) { raise_warning("No memory"); goto cleanup; } onewcert = req::make<Certificate>(new_cert); /* Version 3 cert */ if (!X509_set_version(new_cert, 2)) { goto cleanup; } ASN1_INTEGER_set(X509_get_serialNumber(new_cert), serial); X509_set_subject_name(new_cert, X509_REQ_get_subject_name(pcsr->csr())); if (cert == nullptr) { cert = new_cert; } if (!X509_set_issuer_name(new_cert, X509_get_subject_name(cert))) { goto cleanup; } X509_gmtime_adj(X509_get_notBefore(new_cert), 0); X509_gmtime_adj(X509_get_notAfter(new_cert), (long)60 * 60 * 24 * days); i = X509_set_pubkey(new_cert, key); if (!i) { goto cleanup; } if (req.extensions_section) { X509V3_CTX ctx; X509V3_set_ctx(&ctx, cert, new_cert, pcsr->csr(), nullptr, 0); X509V3_set_conf_lhash(&ctx, req.req_config); if (!X509V3_EXT_add_conf(req.req_config, &ctx, (char*)req.extensions_section, new_cert)) { goto cleanup; } } /* Now sign it */ if (!X509_sign(new_cert, pkey, req.digest)) { raise_warning("failed to sign it"); goto cleanup; } /* Succeeded; lets return the cert */ ret = onewcert; cleanup: php_openssl_dispose_config(&req); return ret; } Variant HHVM_FUNCTION(openssl_error_string) { char buf[512]; unsigned long val = ERR_get_error(); if (val) { return String(ERR_error_string(val, buf), CopyString); } return false; } bool HHVM_FUNCTION(openssl_open, const String& sealed_data, Variant& open_data, const String& env_key, const Variant& priv_key_id, const String& method, /* = null_string */ const String& iv /* = null_string */) { const EVP_CIPHER *cipher_type; if (method.empty()) { cipher_type = EVP_rc4(); } else { cipher_type = EVP_get_cipherbyname(method.c_str()); if (!cipher_type) { raise_warning("Unknown cipher algorithm"); return false; } } auto okey = Key::Get(priv_key_id, false); if (!okey) { raise_warning("unable to coerce parameter 4 into a private key"); return false; } EVP_PKEY *pkey = okey->m_key; const unsigned char *iv_buf = nullptr; int iv_len = EVP_CIPHER_iv_length(cipher_type); if (iv_len > 0) { if (iv.empty()) { raise_warning( "Cipher algorithm requires an IV to be supplied as a sixth parameter"); return false; } if (iv.length() != iv_len) { raise_warning("IV length is invalid"); return false; } iv_buf = reinterpret_cast<const unsigned char*>(iv.c_str()); } String s = String(sealed_data.size(), ReserveString); unsigned char *buf = (unsigned char *)s.mutableData(); EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new(); if (ctx == nullptr) { raise_warning("Failed to allocate an EVP_CIPHER_CTX object"); return false; } SCOPE_EXIT { EVP_CIPHER_CTX_free(ctx); }; int len1, len2; if (!EVP_OpenInit( ctx, cipher_type, (unsigned char*)env_key.data(), env_key.size(), iv_buf, pkey) || !EVP_OpenUpdate( ctx, buf, &len1, (unsigned char*)sealed_data.data(), sealed_data.size()) || !EVP_OpenFinal(ctx, buf + len1, &len2) || len1 + len2 == 0) { return false; } open_data = s.setSize(len1 + len2); return true; } static STACK_OF(X509) *php_array_to_X509_sk(const Variant& certs) { STACK_OF(X509) *pcerts = sk_X509_new_null(); Array arrCerts; if (certs.isArray()) { arrCerts = certs.toArray(); } else { arrCerts.append(certs); } for (ArrayIter iter(arrCerts); iter; ++iter) { auto ocert = Certificate::Get(iter.second()); if (!ocert) { break; } sk_X509_push(pcerts, ocert->m_cert); } return pcerts; } const StaticString s_friendly_name("friendly_name"), s_extracerts("extracerts"); static bool openssl_pkcs12_export_impl(const Variant& x509, BIO *bio_out, const Variant& priv_key, const String& pass, const Variant& args /* = uninit_variant */) { auto ocert = Certificate::Get(x509); if (!ocert) { raise_warning("cannot get cert from parameter 1"); return false; } auto okey = Key::Get(priv_key, false); if (!okey) { raise_warning("cannot get private key from parameter 3"); return false; } X509 *cert = ocert->m_cert; EVP_PKEY *key = okey->m_key; if (cert && !X509_check_private_key(cert, key)) { raise_warning("private key does not correspond to cert"); return false; } Array arrArgs = args.toArray(); String friendly_name; if (arrArgs.exists(s_friendly_name)) { friendly_name = arrArgs[s_friendly_name].toString(); } STACK_OF(X509) *ca = nullptr; if (arrArgs.exists(s_extracerts)) { ca = php_array_to_X509_sk(arrArgs[s_extracerts]); } PKCS12 *p12 = PKCS12_create ((char*)pass.data(), (char*)(friendly_name.empty() ? nullptr : friendly_name.data()), key, cert, ca, 0, 0, 0, 0, 0); assertx(bio_out); bool ret = i2d_PKCS12_bio(bio_out, p12); PKCS12_free(p12); sk_X509_free(ca); return ret; } bool HHVM_FUNCTION(openssl_pkcs12_export_to_file, const Variant& x509, const String& filename, const Variant& priv_key, const String& pass, const Variant& args /* = uninit_variant */) { BIO *bio_out = BIO_new_file(filename.data(), "w"); if (bio_out == nullptr) { raise_warning("error opening file %s", filename.data()); return false; } bool ret = openssl_pkcs12_export_impl(x509, bio_out, priv_key, pass, args); BIO_free(bio_out); return ret; } bool HHVM_FUNCTION(openssl_pkcs12_export, const Variant& x509, Variant& out, const Variant& priv_key, const String& pass, const Variant& args /* = uninit_variant */) { BIO *bio_out = BIO_new(BIO_s_mem()); bool ret = openssl_pkcs12_export_impl(x509, bio_out, priv_key, pass, args); if (ret) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); out = String((char*)bio_buf->data, bio_buf->length, CopyString); } BIO_free(bio_out); return ret; } const StaticString s_cert("cert"), s_pkey("pkey"); bool HHVM_FUNCTION(openssl_pkcs12_read, const String& pkcs12, Variant& certs, const String& pass) { bool ret = false; PKCS12 *p12 = nullptr; BIO *bio_in = BIO_new(BIO_s_mem()); if (!BIO_write(bio_in, pkcs12.data(), pkcs12.size())) { goto cleanup; } if (d2i_PKCS12_bio(bio_in, &p12)) { EVP_PKEY *pkey = nullptr; X509 *cert = nullptr; STACK_OF(X509) *ca = nullptr; if (PKCS12_parse(p12, pass.data(), &pkey, &cert, &ca)) { Variant vcerts = Array::CreateDArray(); SCOPE_EXIT { certs = vcerts; }; BIO *bio_out = nullptr; if (cert) { bio_out = BIO_new(BIO_s_mem()); if (PEM_write_bio_X509(bio_out, cert)) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); vcerts.asArrRef().set(s_cert, String((char*)bio_buf->data, bio_buf->length, CopyString)); } BIO_free(bio_out); } if (pkey) { bio_out = BIO_new(BIO_s_mem()); if (PEM_write_bio_PrivateKey(bio_out, pkey, nullptr, nullptr, 0, 0, nullptr)) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); vcerts.asArrRef().set(s_pkey, String((char*)bio_buf->data, bio_buf->length, CopyString)); } BIO_free(bio_out); } if (ca) { Array extracerts; for (X509 *aCA = sk_X509_pop(ca); aCA; aCA = sk_X509_pop(ca)) { bio_out = BIO_new(BIO_s_mem()); if (PEM_write_bio_X509(bio_out, aCA)) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); extracerts.append(String((char*)bio_buf->data, bio_buf->length, CopyString)); } BIO_free(bio_out); X509_free(aCA); } sk_X509_free(ca); vcerts.asArrRef().set(s_extracerts, extracerts); } ret = true; PKCS12_free(p12); } } cleanup: if (bio_in) { BIO_free(bio_in); } return ret; } bool HHVM_FUNCTION(openssl_pkcs7_decrypt, const String& infilename, const String& outfilename, const Variant& recipcert, const Variant& recipkey /* = uninit_variant */) { bool ret = false; BIO *in = nullptr, *out = nullptr, *datain = nullptr; PKCS7 *p7 = nullptr; req::ptr<Key> okey; auto ocert = Certificate::Get(recipcert); if (!ocert) { raise_warning("unable to coerce parameter 3 to x509 cert"); goto clean_exit; } okey = Key::Get(recipkey.isNull() ? recipcert : recipkey, false); if (!okey) { raise_warning("unable to get private key"); goto clean_exit; } in = BIO_new_file(infilename.data(), "r"); if (in == nullptr) { raise_warning("error opening the file, %s", infilename.data()); goto clean_exit; } out = BIO_new_file(outfilename.data(), "w"); if (out == nullptr) { raise_warning("error opening the file, %s", outfilename.data()); goto clean_exit; } p7 = SMIME_read_PKCS7(in, &datain); if (p7 == nullptr) { goto clean_exit; } assertx(okey->m_key); assertx(ocert->m_cert); if (PKCS7_decrypt(p7, okey->m_key, ocert->m_cert, out, PKCS7_DETACHED)) { ret = true; } clean_exit: PKCS7_free(p7); BIO_free(datain); BIO_free(in); BIO_free(out); return ret; } static void print_headers(BIO *outfile, const Array& headers) { if (!headers.isNull()) { if (headers->isVectorData()) { for (ArrayIter iter(headers); iter; ++iter) { BIO_printf(outfile, "%s\n", iter.second().toString().data()); } } else { for (ArrayIter iter(headers); iter; ++iter) { BIO_printf(outfile, "%s: %s\n", iter.first().toString().data(), iter.second().toString().data()); } } } } bool HHVM_FUNCTION(openssl_pkcs7_encrypt, const String& infilename, const String& outfilename, const Variant& recipcerts, const Array& headers, int flags /* = 0 */, int cipherid /* = k_OPENSSL_CIPHER_RC2_40 */) { bool ret = false; BIO *infile = nullptr, *outfile = nullptr; STACK_OF(X509) *precipcerts = nullptr; PKCS7 *p7 = nullptr; const EVP_CIPHER *cipher = nullptr; infile = BIO_new_file(infilename.data(), (flags & PKCS7_BINARY) ? "rb" : "r"); if (infile == nullptr) { raise_warning("error opening the file, %s", infilename.data()); goto clean_exit; } outfile = BIO_new_file(outfilename.data(), "w"); if (outfile == nullptr) { raise_warning("error opening the file, %s", outfilename.data()); goto clean_exit; } precipcerts = php_array_to_X509_sk(recipcerts); /* sanity check the cipher */ switch (cipherid) { #ifndef OPENSSL_NO_RC2 case PHP_OPENSSL_CIPHER_RC2_40: cipher = EVP_rc2_40_cbc(); break; case PHP_OPENSSL_CIPHER_RC2_64: cipher = EVP_rc2_64_cbc(); break; case PHP_OPENSSL_CIPHER_RC2_128: cipher = EVP_rc2_cbc(); break; #endif #ifndef OPENSSL_NO_DES case PHP_OPENSSL_CIPHER_DES: cipher = EVP_des_cbc(); break; case PHP_OPENSSL_CIPHER_3DES: cipher = EVP_des_ede3_cbc(); break; #endif default: raise_warning("Invalid cipher type `%d'", cipherid); goto clean_exit; } if (cipher == nullptr) { raise_warning("Failed to get cipher"); goto clean_exit; } p7 = PKCS7_encrypt(precipcerts, infile, (EVP_CIPHER*)cipher, flags); if (p7 == nullptr) goto clean_exit; print_headers(outfile, headers); (void)BIO_reset(infile); SMIME_write_PKCS7(outfile, p7, infile, flags); ret = true; clean_exit: PKCS7_free(p7); BIO_free(infile); BIO_free(outfile); sk_X509_free(precipcerts); return ret; } bool HHVM_FUNCTION(openssl_pkcs7_sign, const String& infilename, const String& outfilename, const Variant& signcert, const Variant& privkey, const Variant& headers, int flags /* = k_PKCS7_DETACHED */, const String& extracerts /* = null_string */) { bool ret = false; STACK_OF(X509) *others = nullptr; BIO *infile = nullptr, *outfile = nullptr; PKCS7 *p7 = nullptr; req::ptr<Key> okey; req::ptr<Certificate> ocert; if (!extracerts.empty()) { others = load_all_certs_from_file(extracerts.data()); if (others == nullptr) { goto clean_exit; } } okey = Key::Get(privkey, false); if (!okey) { raise_warning("error getting private key"); goto clean_exit; } EVP_PKEY *key; key = okey->m_key; ocert = Certificate::Get(signcert); if (!ocert) { raise_warning("error getting cert"); goto clean_exit; } X509 *cert; cert = ocert->m_cert; infile = BIO_new_file(infilename.data(), (flags & PKCS7_BINARY) ? "rb" : "r"); if (infile == nullptr) { raise_warning("error opening input file %s!", infilename.data()); goto clean_exit; } outfile = BIO_new_file(outfilename.data(), "w"); if (outfile == nullptr) { raise_warning("error opening output file %s!", outfilename.data()); goto clean_exit; } p7 = PKCS7_sign(cert, key, others, infile, flags); if (p7 == nullptr) { raise_warning("error creating PKCS7 structure!"); goto clean_exit; } print_headers(outfile, headers.toArray()); (void)BIO_reset(infile); SMIME_write_PKCS7(outfile, p7, infile, flags); ret = true; clean_exit: PKCS7_free(p7); BIO_free(infile); BIO_free(outfile); if (others) { sk_X509_pop_free(others, X509_free); } return ret; } static int pkcs7_ignore_expiration(int ok, X509_STORE_CTX *ctx) { if (ok) { return ok; } int error = X509_STORE_CTX_get_error(ctx); if (error == X509_V_ERR_CERT_HAS_EXPIRED) { // ignore cert expirations Logger::Verbose("Ignoring cert expiration"); return 1; } return ok; } /** * NOTE: when ignore_cert_expiration is true, a custom certificate validation * callback is set up. Please be aware of this if you modify the function to * allow other certificate validation behaviors */ Variant openssl_pkcs7_verify_core( const String& filename, int flags, const Variant& voutfilename /* = null_string */, const Variant& vcainfo /* = null_array */, const Variant& vextracerts /* = null_string */, const Variant& vcontent /* = null_string */, bool ignore_cert_expiration ) { Variant ret = -1; X509_STORE *store = nullptr; BIO *in = nullptr; PKCS7 *p7 = nullptr; BIO *datain = nullptr; BIO *dataout = nullptr; auto cainfo = vcainfo.toArray(); auto extracerts = vextracerts.toString(); auto content = vcontent.toString(); STACK_OF(X509) *others = nullptr; if (!extracerts.empty()) { others = load_all_certs_from_file(extracerts.data()); if (others == nullptr) { goto clean_exit; } } flags = flags & ~PKCS7_DETACHED; store = setup_verify(cainfo); if (!store) { goto clean_exit; } if (ignore_cert_expiration) { #if (OPENSSL_VERSION_NUMBER >= 0x10000000) // make sure no other callback is specified #if OPENSSL_VERSION_NUMBER >= 0x10100000L assertx(!X509_STORE_get_verify_cb(store)); #else assertx(!store->verify_cb); #endif // ignore expired certs X509_STORE_set_verify_cb(store, pkcs7_ignore_expiration); #else always_assert(false); #endif } in = BIO_new_file(filename.data(), (flags & PKCS7_BINARY) ? "rb" : "r"); if (in == nullptr) { raise_warning("error opening the file, %s", filename.data()); goto clean_exit; } p7 = SMIME_read_PKCS7(in, &datain); if (p7 == nullptr) { goto clean_exit; } if (!content.empty()) { dataout = BIO_new_file(content.data(), "w"); if (dataout == nullptr) { raise_warning("error opening the file, %s", content.data()); goto clean_exit; } } if (PKCS7_verify(p7, others, store, datain, dataout, flags)) { ret = true; auto outfilename = voutfilename.toString(); if (!outfilename.empty()) { BIO *certout = BIO_new_file(outfilename.data(), "w"); if (certout) { STACK_OF(X509) *signers = PKCS7_get0_signers(p7, nullptr, flags); for (int i = 0; i < sk_X509_num(signers); i++) { PEM_write_bio_X509(certout, sk_X509_value(signers, i)); } BIO_free(certout); sk_X509_free(signers); } else { raise_warning("signature OK, but cannot open %s for writing", outfilename.data()); ret = -1; } } goto clean_exit; } else { ret = false; } clean_exit: X509_STORE_free(store); BIO_free(datain); BIO_free(in); BIO_free(dataout); PKCS7_free(p7); sk_X509_pop_free(others, X509_free); return ret; } Variant HHVM_FUNCTION(openssl_pkcs7_verify, const String& filename, int flags, const Variant& voutfilename /* = null_string */, const Variant& vcainfo /* = null_array */, const Variant& vextracerts /* = null_string */, const Variant& vcontent /* = null_string */) { return openssl_pkcs7_verify_core(filename, flags, voutfilename, vcainfo, vextracerts, vcontent, false); } static bool openssl_pkey_export_impl(const Variant& key, BIO *bio_out, const String& passphrase /* = null_string */, const Variant& configargs /* = uninit_variant */) { auto okey = Key::Get(key, false, passphrase.data()); if (!okey) { raise_warning("cannot get key from parameter 1"); return false; } EVP_PKEY *pkey = okey->m_key; struct php_x509_request req; memset(&req, 0, sizeof(req)); std::vector<String> strings; bool ret = false; if (php_openssl_parse_config(&req, configargs.toArray(), strings)) { const EVP_CIPHER *cipher; if (!passphrase.empty() && req.priv_key_encrypt) { cipher = (EVP_CIPHER *)EVP_des_ede3_cbc(); } else { cipher = nullptr; } assertx(bio_out); switch (EVP_PKEY_id(pkey)) { #ifdef HAVE_EVP_PKEY_EC case EVP_PKEY_EC: ret = PEM_write_bio_ECPrivateKey(bio_out, EVP_PKEY_get0_EC_KEY(pkey), cipher, (unsigned char *)passphrase.data(), passphrase.size(), nullptr, nullptr); break; #endif default: ret = PEM_write_bio_PrivateKey(bio_out, pkey, cipher, (unsigned char *)passphrase.data(), passphrase.size(), nullptr, nullptr); break; } } php_openssl_dispose_config(&req); return ret; } bool HHVM_FUNCTION(openssl_pkey_export_to_file, const Variant& key, const String& outfilename, const String& passphrase /* = null_string */, const Variant& configargs /* = uninit_variant */) { BIO *bio_out = BIO_new_file(outfilename.data(), "w"); if (bio_out == nullptr) { raise_warning("error opening the file, %s", outfilename.data()); return false; } bool ret = openssl_pkey_export_impl(key, bio_out, passphrase, configargs); BIO_free(bio_out); return ret; } bool HHVM_FUNCTION(openssl_pkey_export, const Variant& key, Variant& out, const String& passphrase /* = null_string */, const Variant& configargs /* = uninit_variant */) { BIO *bio_out = BIO_new(BIO_s_mem()); bool ret = openssl_pkey_export_impl(key, bio_out, passphrase, configargs); if (ret) { char *bio_mem_ptr; long bio_mem_len = BIO_get_mem_data(bio_out, &bio_mem_ptr); out = String(bio_mem_ptr, bio_mem_len, CopyString); } BIO_free(bio_out); return ret; } const StaticString s_bits("bits"), s_key("key"), s_type("type"), s_name("name"), s_hash("hash"), s_version("version"), s_serialNumber("serialNumber"), s_signatureAlgorithm("signatureAlgorithm"), s_validFrom("validFrom"), s_validTo("validTo"), s_validFrom_time_t("validFrom_time_t"), s_validTo_time_t("validTo_time_t"), s_alias("alias"), s_purposes("purposes"), s_extensions("extensions"), s_rsa("rsa"), s_dsa("dsa"), s_dh("dh"), s_ec("ec"), s_n("n"), s_e("e"), s_d("d"), s_p("p"), s_q("q"), s_g("g"), s_x("x"), s_y("y"), s_dmp1("dmp1"), s_dmq1("dmq1"), s_iqmp("iqmp"), s_priv_key("priv_key"), s_pub_key("pub_key"), s_curve_oid("curve_oid"); static void add_bignum_as_string(Array &arr, StaticString key, const BIGNUM *bn) { if (!bn) { return; } int num_bytes = BN_num_bytes(bn); String str{size_t(num_bytes), ReserveString}; BN_bn2bin(bn, (unsigned char*)str.mutableData()); str.setSize(num_bytes); arr.set(key, std::move(str)); } Array HHVM_FUNCTION(openssl_pkey_get_details, const Resource& key) { EVP_PKEY *pkey = cast<Key>(key)->m_key; BIO *out = BIO_new(BIO_s_mem()); PEM_write_bio_PUBKEY(out, pkey); char *pbio; unsigned int pbio_len = BIO_get_mem_data(out, &pbio); auto ret = make_darray( s_bits, EVP_PKEY_bits(pkey), s_key, String(pbio, pbio_len, CopyString) ); long ktype = -1; auto details = Array::CreateDArray(); switch (EVP_PKEY_id(pkey)) { case EVP_PKEY_RSA: case EVP_PKEY_RSA2: { ktype = OPENSSL_KEYTYPE_RSA; RSA *rsa = EVP_PKEY_get0_RSA(pkey); assertx(rsa); const BIGNUM *n, *e, *d, *p, *q, *dmp1, *dmq1, *iqmp; RSA_get0_key(rsa, &n, &e, &d); RSA_get0_factors(rsa, &p, &q); RSA_get0_crt_params(rsa, &dmp1, &dmq1, &iqmp); add_bignum_as_string(details, s_n, n); add_bignum_as_string(details, s_e, e); add_bignum_as_string(details, s_d, d); add_bignum_as_string(details, s_p, p); add_bignum_as_string(details, s_q, q); add_bignum_as_string(details, s_dmp1, dmp1); add_bignum_as_string(details, s_dmq1, dmq1); add_bignum_as_string(details, s_iqmp, iqmp); ret.set(s_rsa, details); break; } case EVP_PKEY_DSA: case EVP_PKEY_DSA2: case EVP_PKEY_DSA3: case EVP_PKEY_DSA4: { ktype = OPENSSL_KEYTYPE_DSA; DSA *dsa = EVP_PKEY_get0_DSA(pkey); assertx(dsa); const BIGNUM *p, *q, *g, *pub_key, *priv_key; DSA_get0_pqg(dsa, &p, &q, &g); DSA_get0_key(dsa, &pub_key, &priv_key); add_bignum_as_string(details, s_p, p); add_bignum_as_string(details, s_q, q); add_bignum_as_string(details, s_g, g); add_bignum_as_string(details, s_priv_key, priv_key); add_bignum_as_string(details, s_pub_key, pub_key); ret.set(s_dsa, details); break; } case EVP_PKEY_DH: { ktype = OPENSSL_KEYTYPE_DH; DH *dh = EVP_PKEY_get0_DH(pkey); assertx(dh); const BIGNUM *p, *q, *g, *pub_key, *priv_key; DH_get0_pqg(dh, &p, &q, &g); DH_get0_key(dh, &pub_key, &priv_key); add_bignum_as_string(details, s_p, p); add_bignum_as_string(details, s_g, g); add_bignum_as_string(details, s_priv_key, priv_key); add_bignum_as_string(details, s_pub_key, pub_key); ret.set(s_dh, details); break; } #ifdef HAVE_EVP_PKEY_EC case EVP_PKEY_EC: { ktype = OPENSSL_KEYTYPE_EC; auto const ec = EVP_PKEY_get0_EC_KEY(pkey); assertx(ec); auto const ec_group = EC_KEY_get0_group(ec); auto const nid = EC_GROUP_get_curve_name(ec_group); if (nid == NID_undef) { break; } auto const crv_sn = OBJ_nid2sn(nid); if (crv_sn != nullptr) { details.set(s_curve_name, String(crv_sn, CopyString)); } auto const obj = OBJ_nid2obj(nid); if (obj != nullptr) { SCOPE_EXIT { ASN1_OBJECT_free(obj); }; char oir_buf[256]; OBJ_obj2txt(oir_buf, sizeof(oir_buf) - 1, obj, 1); details.set(s_curve_oid, String(oir_buf, CopyString)); } auto x = BN_new(); auto y = BN_new(); SCOPE_EXIT { BN_free(x); BN_free(y); }; auto const pub = EC_KEY_get0_public_key(ec); if (EC_POINT_get_affine_coordinates_GFp(ec_group, pub, x, y, nullptr)) { add_bignum_as_string(details, s_x, x); add_bignum_as_string(details, s_y, y); } auto d = BN_dup(EC_KEY_get0_private_key(ec)); SCOPE_EXIT { BN_free(d); }; if (d != nullptr) { add_bignum_as_string(details, s_d, d); } ret.set(s_ec, details); } break; #endif } ret.set(s_type, ktype); BIO_free(out); return ret; } Variant HHVM_FUNCTION(openssl_pkey_get_private, const Variant& key, const String& passphrase /* = null_string */) { return toVariant(Key::Get(key, false, passphrase.data())); } Variant HHVM_FUNCTION(openssl_pkey_get_public, const Variant& certificate) { return toVariant(Key::Get(certificate, true)); } Variant HHVM_FUNCTION(openssl_pkey_new, const Variant& configargs /* = uninit_variant */) { struct php_x509_request req; memset(&req, 0, sizeof(req)); SCOPE_EXIT { php_openssl_dispose_config(&req); }; std::vector<String> strings; if (php_openssl_parse_config(&req, configargs.toArray(), strings) && req.generatePrivateKey()) { return Resource(req::make<Key>(req.priv_key)); } else { return false; } } bool HHVM_FUNCTION(openssl_private_decrypt, const String& data, Variant& decrypted, const Variant& key, int padding /* = k_OPENSSL_PKCS1_PADDING */) { auto okey = Key::Get(key, false); if (!okey) { raise_warning("key parameter is not a valid private key"); return false; } EVP_PKEY *pkey = okey->m_key; int cryptedlen = EVP_PKEY_size(pkey); String s = String(cryptedlen, ReserveString); unsigned char *cryptedbuf = (unsigned char *)s.mutableData(); int successful = 0; switch (EVP_PKEY_id(pkey)) { case EVP_PKEY_RSA: case EVP_PKEY_RSA2: cryptedlen = RSA_private_decrypt(data.size(), (unsigned char *)data.data(), cryptedbuf, EVP_PKEY_get0_RSA(pkey), padding); if (cryptedlen != -1) { successful = 1; } break; default: raise_warning("key type not supported"); } if (successful) { decrypted = s.setSize(cryptedlen); return true; } return false; } bool HHVM_FUNCTION(openssl_private_encrypt, const String& data, Variant& crypted, const Variant& key, int padding /* = k_OPENSSL_PKCS1_PADDING */) { auto okey = Key::Get(key, false); if (!okey) { raise_warning("key param is not a valid private key"); return false; } EVP_PKEY *pkey = okey->m_key; int cryptedlen = EVP_PKEY_size(pkey); String s = String(cryptedlen, ReserveString); unsigned char *cryptedbuf = (unsigned char *)s.mutableData(); int successful = 0; switch (EVP_PKEY_id(pkey)) { case EVP_PKEY_RSA: case EVP_PKEY_RSA2: successful = (RSA_private_encrypt(data.size(), (unsigned char *)data.data(), cryptedbuf, EVP_PKEY_get0_RSA(pkey), padding) == cryptedlen); break; default: raise_warning("key type not supported"); } if (successful) { crypted = s.setSize(cryptedlen); return true; } return false; } bool HHVM_FUNCTION(openssl_public_decrypt, const String& data, Variant& decrypted, const Variant& key, int padding /* = k_OPENSSL_PKCS1_PADDING */) { auto okey = Key::Get(key, true); if (!okey) { raise_warning("key parameter is not a valid public key"); return false; } EVP_PKEY *pkey = okey->m_key; int cryptedlen = EVP_PKEY_size(pkey); String s = String(cryptedlen, ReserveString); unsigned char *cryptedbuf = (unsigned char *)s.mutableData(); int successful = 0; switch (EVP_PKEY_id(pkey)) { case EVP_PKEY_RSA: case EVP_PKEY_RSA2: cryptedlen = RSA_public_decrypt(data.size(), (unsigned char *)data.data(), cryptedbuf, EVP_PKEY_get0_RSA(pkey), padding); if (cryptedlen != -1) { successful = 1; } break; default: raise_warning("key type not supported"); } if (successful) { decrypted = s.setSize(cryptedlen); return true; } return false; } bool HHVM_FUNCTION(openssl_public_encrypt, const String& data, Variant& crypted, const Variant& key, int padding /* = k_OPENSSL_PKCS1_PADDING */) { auto okey = Key::Get(key, true); if (!okey) { raise_warning("key parameter is not a valid public key"); return false; } EVP_PKEY *pkey = okey->m_key; int cryptedlen = EVP_PKEY_size(pkey); String s = String(cryptedlen, ReserveString); unsigned char *cryptedbuf = (unsigned char *)s.mutableData(); int successful = 0; switch (EVP_PKEY_id(pkey)) { case EVP_PKEY_RSA: case EVP_PKEY_RSA2: successful = (RSA_public_encrypt(data.size(), (unsigned char *)data.data(), cryptedbuf, EVP_PKEY_get0_RSA(pkey), padding) == cryptedlen); break; default: raise_warning("key type not supported"); } if (successful) { crypted = s.setSize(cryptedlen); return true; } return false; } Variant HHVM_FUNCTION(openssl_seal, const String& data, Variant& sealed_data, Variant& env_keys, const Array& pub_key_ids, const String& method, Variant& iv) { int nkeys = pub_key_ids.size(); if (nkeys == 0) { raise_warning("Fourth argument to openssl_seal() must be " "a non-empty array"); return false; } const EVP_CIPHER *cipher_type; if (method.empty()) { cipher_type = EVP_rc4(); } else { cipher_type = EVP_get_cipherbyname(method.c_str()); if (!cipher_type) { raise_warning("Unknown cipher algorithm"); return false; } } int iv_len = EVP_CIPHER_iv_length(cipher_type); unsigned char *iv_buf = nullptr; String iv_s; if (iv_len > 0) { iv_s = String(iv_len, ReserveString); iv_buf = (unsigned char*)iv_s.mutableData(); if (!RAND_bytes(iv_buf, iv_len)) { raise_warning("Could not generate an IV."); return false; } } EVP_PKEY **pkeys = (EVP_PKEY**)malloc(nkeys * sizeof(*pkeys)); int *eksl = (int*)malloc(nkeys * sizeof(*eksl)); unsigned char **eks = (unsigned char **)malloc(nkeys * sizeof(*eks)); memset(eks, 0, sizeof(*eks) * nkeys); // holder is needed to make sure none of the Keys get deleted prematurely. // The pkeys array points to elements inside of Keys returned from Key::Get() // which may be newly allocated and have no other owners. std::vector<req::ptr<Key>> holder; /* get the public keys we are using to seal this data */ bool ret = true; int i = 0; String s; unsigned char* buf = nullptr; EVP_CIPHER_CTX* ctx = nullptr; for (ArrayIter iter(pub_key_ids); iter; ++iter, ++i) { auto okey = Key::Get(iter.second(), true); if (!okey) { raise_warning("not a public key (%dth member of pubkeys)", i + 1); ret = false; goto clean_exit; } holder.push_back(okey); pkeys[i] = okey->m_key; eks[i] = (unsigned char *)malloc(EVP_PKEY_size(pkeys[i]) + 1); } ctx = EVP_CIPHER_CTX_new(); if (ctx == nullptr) { raise_warning("Failed to allocate an EVP_CIPHER_CTX object"); ret = false; goto clean_exit; } if (!EVP_EncryptInit_ex(ctx, cipher_type, nullptr, nullptr, nullptr)) { ret = false; goto clean_exit; } int len1, len2; s = String(data.size() + EVP_CIPHER_CTX_block_size(ctx), ReserveString); buf = (unsigned char *)s.mutableData(); if (EVP_SealInit(ctx, cipher_type, eks, eksl, iv_buf, pkeys, nkeys) <= 0 || !EVP_SealUpdate(ctx, buf, &len1, (unsigned char*)data.data(), data.size()) || !EVP_SealFinal(ctx, buf + len1, &len2)) { ret = false; goto clean_exit; } if (len1 + len2 > 0) { sealed_data = s.setSize(len1 + len2); auto ekeys = Array::CreateVArray(); for (i = 0; i < nkeys; i++) { eks[i][eksl[i]] = '\0'; ekeys.append(String((char*)eks[i], eksl[i], AttachString)); eks[i] = nullptr; } env_keys = ekeys; } clean_exit: for (i = 0; i < nkeys; i++) { if (eks[i]) free(eks[i]); } free(eks); free(eksl); free(pkeys); if (iv_buf != nullptr) { if (ret) { iv = iv_s.setSize(iv_len); } } if (ctx != nullptr) { EVP_CIPHER_CTX_free(ctx); } if (ret) return len1 + len2; return false; } static const EVP_MD *php_openssl_get_evp_md_from_algo(long algo) { switch (algo) { case OPENSSL_ALGO_SHA1: return EVP_sha1(); case OPENSSL_ALGO_MD5: return EVP_md5(); case OPENSSL_ALGO_MD4: return EVP_md4(); #ifdef HAVE_OPENSSL_MD2_H case OPENSSL_ALGO_MD2: return EVP_md2(); #endif #if OPENSSL_VERSION_NUMBER < 0x10100000L case OPENSSL_ALGO_DSS1: return EVP_dss1(); #endif #if OPENSSL_VERSION_NUMBER >= 0x0090708fL case OPENSSL_ALGO_SHA224: return EVP_sha224(); case OPENSSL_ALGO_SHA256: return EVP_sha256(); case OPENSSL_ALGO_SHA384: return EVP_sha384(); case OPENSSL_ALGO_SHA512: return EVP_sha512(); case OPENSSL_ALGO_RMD160: return EVP_ripemd160(); #endif } return nullptr; } bool HHVM_FUNCTION(openssl_sign, const String& data, Variant& signature, const Variant& priv_key_id, const Variant& signature_alg /* = k_OPENSSL_ALGO_SHA1 */) { auto okey = Key::Get(priv_key_id, false); if (!okey) { raise_warning("supplied key param cannot be coerced into a private key"); return false; } const EVP_MD *mdtype = nullptr; if (signature_alg.isInteger()) { mdtype = php_openssl_get_evp_md_from_algo(signature_alg.toInt64Val()); } else if (signature_alg.isString()) { mdtype = EVP_get_digestbyname(signature_alg.toString().data()); } if (!mdtype) { raise_warning("Unknown signature algorithm."); return false; } EVP_PKEY *pkey = okey->m_key; int siglen = EVP_PKEY_size(pkey); String s = String(siglen, ReserveString); unsigned char *sigbuf = (unsigned char *)s.mutableData(); EVP_MD_CTX *md_ctx = EVP_MD_CTX_new(); SCOPE_EXIT { EVP_MD_CTX_free(md_ctx); }; EVP_SignInit(md_ctx, mdtype); EVP_SignUpdate(md_ctx, (unsigned char *)data.data(), data.size()); if (EVP_SignFinal(md_ctx, sigbuf, (unsigned int *)&siglen, pkey)) { signature = s.setSize(siglen); return true; } return false; } Variant HHVM_FUNCTION(openssl_verify, const String& data, const String& signature, const Variant& pub_key_id, const Variant& signature_alg /* = k_OPENSSL_ALGO_SHA1 */) { int err; const EVP_MD *mdtype = nullptr; if (signature_alg.isInteger()) { mdtype = php_openssl_get_evp_md_from_algo(signature_alg.toInt64Val()); } else if (signature_alg.isString()) { mdtype = EVP_get_digestbyname(signature_alg.toString().data()); } if (!mdtype) { raise_warning("Unknown signature algorithm."); return false; } auto okey = Key::Get(pub_key_id, true); if (!okey) { raise_warning("supplied key param cannot be coerced into a public key"); return false; } EVP_MD_CTX *md_ctx = EVP_MD_CTX_new(); SCOPE_EXIT { EVP_MD_CTX_free(md_ctx); }; EVP_VerifyInit(md_ctx, mdtype); EVP_VerifyUpdate(md_ctx, (unsigned char*)data.data(), data.size()); err = EVP_VerifyFinal(md_ctx, (unsigned char *)signature.data(), signature.size(), okey->m_key); return err; } bool HHVM_FUNCTION(openssl_x509_check_private_key, const Variant& cert, const Variant& key) { auto ocert = Certificate::Get(cert); if (!ocert) { return false; } auto okey = Key::Get(key, false); if (!okey) { return false; } return X509_check_private_key(ocert->m_cert, okey->m_key); } static int check_cert(X509_STORE *ctx, X509 *x, STACK_OF(X509) *untrustedchain, int purpose) { X509_STORE_CTX *csc = X509_STORE_CTX_new(); if (csc == nullptr) { raise_warning("memory allocation failure"); return 0; } X509_STORE_CTX_init(csc, ctx, x, untrustedchain); if (purpose >= 0) { X509_STORE_CTX_set_purpose(csc, purpose); } int ret = X509_verify_cert(csc); X509_STORE_CTX_free(csc); return ret; } Variant HHVM_FUNCTION(openssl_x509_checkpurpose, const Variant& x509cert, int purpose, const Array& cainfo /* = null_array */, const String& untrustedfile /* = null_string */) { int ret = -1; STACK_OF(X509) *untrustedchain = nullptr; X509_STORE *pcainfo = nullptr; req::ptr<Certificate> ocert; if (!untrustedfile.empty()) { untrustedchain = load_all_certs_from_file(untrustedfile.data()); if (untrustedchain == nullptr) { goto clean_exit; } } pcainfo = setup_verify(cainfo); if (pcainfo == nullptr) { goto clean_exit; } ocert = Certificate::Get(x509cert); if (!ocert) { raise_warning("cannot get cert from parameter 1"); return false; } X509 *cert; cert = ocert->m_cert; assertx(cert); ret = check_cert(pcainfo, cert, untrustedchain, purpose); clean_exit: if (pcainfo) { X509_STORE_free(pcainfo); } if (untrustedchain) { sk_X509_pop_free(untrustedchain, X509_free); } return ret == 1 ? true : ret == 0 ? false : -1; } static bool openssl_x509_export_impl(const Variant& x509, BIO *bio_out, bool notext /* = true */) { auto ocert = Certificate::Get(x509); if (!ocert) { raise_warning("cannot get cert from parameter 1"); return false; } X509 *cert = ocert->m_cert; assertx(cert); assertx(bio_out); if (!notext) { X509_print(bio_out, cert); } return PEM_write_bio_X509(bio_out, cert); } bool HHVM_FUNCTION(openssl_x509_export_to_file, const Variant& x509, const String& outfilename, bool notext /* = true */) { BIO *bio_out = BIO_new_file((char*)outfilename.data(), "w"); if (bio_out == nullptr) { raise_warning("error opening file %s", outfilename.data()); return false; } bool ret = openssl_x509_export_impl(x509, bio_out, notext); BIO_free(bio_out); return ret; } bool HHVM_FUNCTION(openssl_x509_export, const Variant& x509, Variant& output, bool notext /* = true */) { BIO *bio_out = BIO_new(BIO_s_mem()); bool ret = openssl_x509_export_impl(x509, bio_out, notext); if (ret) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); output = String(bio_buf->data, bio_buf->length, CopyString); } BIO_free(bio_out); return ret; } /** * This is how the time string is formatted: * * snprintf(p, sizeof(p), "%02d%02d%02d%02d%02d%02dZ",ts->tm_year%100, * ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); */ static time_t asn1_time_to_time_t(ASN1_UTCTIME *timestr) { auto const timestr_type = ASN1_STRING_type(timestr); if (timestr_type != V_ASN1_UTCTIME && timestr_type != V_ASN1_GENERALIZEDTIME) { raise_warning("illegal ASN1 data type for timestamp"); return (time_t)-1; } auto const timestr_len = (size_t)ASN1_STRING_length(timestr); // Binary safety if (timestr_len != strlen((char*)ASN1_STRING_data(timestr))) { raise_warning("illegal length in timestamp"); return (time_t)-1; } if (timestr_len < 13 && timestr_len != 11) { raise_warning("unable to parse time string %s correctly", timestr->data); return (time_t)-1; } if (timestr_type == V_ASN1_GENERALIZEDTIME && timestr_len < 15) { raise_warning("unable to parse time string %s correctly", timestr->data); return (time_t)-1; } char *strbuf = strdup((char*)timestr->data); struct tm thetime; memset(&thetime, 0, sizeof(thetime)); /* we work backwards so that we can use atoi more easily */ char *thestr = strbuf + ASN1_STRING_length(timestr) - 3; if (ASN1_STRING_length(timestr) == 11) { thetime.tm_sec = 0; } else { thetime.tm_sec = atoi(thestr); *thestr = '\0'; thestr -= 2; } thetime.tm_min = atoi(thestr); *thestr = '\0'; thestr -= 2; thetime.tm_hour = atoi(thestr); *thestr = '\0'; thestr -= 2; thetime.tm_mday = atoi(thestr); *thestr = '\0'; thestr -= 2; thetime.tm_mon = atoi(thestr)-1; *thestr = '\0'; if (ASN1_STRING_type(timestr) == V_ASN1_UTCTIME) { thestr -= 2; thetime.tm_year = atoi(thestr); if (thetime.tm_year < 68) { thetime.tm_year += 100; } } else if (ASN1_STRING_type(timestr) == V_ASN1_GENERALIZEDTIME) { thestr -= 4; thetime.tm_year = atoi(thestr) - 1900; } thetime.tm_isdst = -1; time_t ret = mktime(&thetime); long gmadjust = 0; #if HAVE_TM_GMTOFF gmadjust = thetime.tm_gmtoff; #elif defined(_MSC_VER) TIME_ZONE_INFORMATION inf; GetTimeZoneInformation(&inf); gmadjust = thetime.tm_isdst ? inf.DaylightBias : inf.StandardBias; #else /** * If correcting for daylight savings time, we set the adjustment to * the value of timezone - 3600 seconds. Otherwise, we need to overcorrect * and set the adjustment to the main timezone + 3600 seconds. */ gmadjust = -(thetime.tm_isdst ? (long)timezone - 3600 : (long)timezone); #endif /* no adjustment for UTC */ if (timezone) ret += gmadjust; free(strbuf); return ret; } /* Special handling of subjectAltName, see CVE-2013-4073 * Christian Heimes */ static int openssl_x509v3_subjectAltName(BIO *bio, X509_EXTENSION *extension) { GENERAL_NAMES *names; const X509V3_EXT_METHOD *method = nullptr; long i, length, num; const unsigned char *p; method = X509V3_EXT_get(extension); if (method == nullptr) { return -1; } const auto data = X509_EXTENSION_get_data(extension); p = data->data; length = data->length; if (method->it) { names = (GENERAL_NAMES*)(ASN1_item_d2i(nullptr, &p, length, ASN1_ITEM_ptr(method->it))); } else { names = (GENERAL_NAMES*)(method->d2i(nullptr, &p, length)); } if (names == nullptr) { return -1; } num = sk_GENERAL_NAME_num(names); for (i = 0; i < num; i++) { GENERAL_NAME *name; ASN1_STRING *as; name = sk_GENERAL_NAME_value(names, i); switch (name->type) { case GEN_EMAIL: BIO_puts(bio, "email:"); as = name->d.rfc822Name; BIO_write(bio, ASN1_STRING_data(as), ASN1_STRING_length(as)); break; case GEN_DNS: BIO_puts(bio, "DNS:"); as = name->d.dNSName; BIO_write(bio, ASN1_STRING_data(as), ASN1_STRING_length(as)); break; case GEN_URI: BIO_puts(bio, "URI:"); as = name->d.uniformResourceIdentifier; BIO_write(bio, ASN1_STRING_data(as), ASN1_STRING_length(as)); break; default: /* use builtin print for GEN_OTHERNAME, GEN_X400, * GEN_EDIPARTY, GEN_DIRNAME, GEN_IPADD and GEN_RID */ GENERAL_NAME_print(bio, name); } /* trailing ', ' except for last element */ if (i < (num - 1)) { BIO_puts(bio, ", "); } } sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free); return 0; } Variant HHVM_FUNCTION(openssl_x509_parse, const Variant& x509cert, bool shortnames /* = true */) { auto ocert = Certificate::Get(x509cert); if (!ocert) { return false; } X509 *cert = ocert->m_cert; assertx(cert); auto ret = Array::CreateDArray(); const auto sn = X509_get_subject_name(cert); if (sn) { ret.set(s_name, String(X509_NAME_oneline(sn, nullptr, 0), CopyString)); } add_assoc_name_entry(ret, "subject", sn, shortnames); /* hash as used in CA directories to lookup cert by subject name */ { char buf[32]; snprintf(buf, sizeof(buf), "%08lx", X509_subject_name_hash(cert)); ret.set(s_hash, String(buf, CopyString)); } add_assoc_name_entry(ret, "issuer", X509_get_issuer_name(cert), shortnames); ret.set(s_version, X509_get_version(cert)); ret.set(s_serialNumber, String (i2s_ASN1_INTEGER(nullptr, X509_get_serialNumber(cert)), AttachString)); // Adding Signature Algorithm BIO *bio_out = BIO_new(BIO_s_mem()); SCOPE_EXIT { BIO_free(bio_out); }; if (i2a_ASN1_OBJECT(bio_out, X509_get0_tbs_sigalg(cert)->algorithm) > 0) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); ret.set(s_signatureAlgorithm, String((char*)bio_buf->data, bio_buf->length, CopyString)); } ASN1_STRING *str = X509_get_notBefore(cert); ret.set(s_validFrom, String((char*)str->data, str->length, CopyString)); str = X509_get_notAfter(cert); ret.set(s_validTo, String((char*)str->data, str->length, CopyString)); ret.set(s_validFrom_time_t, asn1_time_to_time_t(X509_get_notBefore(cert))); ret.set(s_validTo_time_t, asn1_time_to_time_t(X509_get_notAfter(cert))); char *tmpstr = (char *)X509_alias_get0(cert, nullptr); if (tmpstr) { ret.set(s_alias, String(tmpstr, CopyString)); } /* NOTE: the purposes are added as integer keys - the keys match up to the X509_PURPOSE_SSL_XXX defines in x509v3.h */ { Array subitem; for (int i = 0; i < X509_PURPOSE_get_count(); i++) { X509_PURPOSE *purp = X509_PURPOSE_get0(i); int id = X509_PURPOSE_get_id(purp); char * pname = shortnames ? X509_PURPOSE_get0_sname(purp) : X509_PURPOSE_get0_name(purp); auto subsub = make_varray( (bool)X509_check_purpose(cert, id, 0), (bool)X509_check_purpose(cert, id, 1), String(pname, CopyString) ); subitem.set(id, std::move(subsub)); } ret.set(s_purposes, subitem); } { auto subitem = Array::CreateDArray(); for (int i = 0; i < X509_get_ext_count(cert); i++) { int nid; X509_EXTENSION *extension = X509_get_ext(cert, i); char *extname; char buf[256]; nid = OBJ_obj2nid(X509_EXTENSION_get_object(extension)); if (nid != NID_undef) { extname = (char*)OBJ_nid2sn(OBJ_obj2nid (X509_EXTENSION_get_object(extension))); } else { OBJ_obj2txt(buf, sizeof(buf)-1, X509_EXTENSION_get_object(extension), 1); extname = buf; } BIO *bio_out = BIO_new(BIO_s_mem()); if (nid == NID_subject_alt_name) { if (openssl_x509v3_subjectAltName(bio_out, extension) == 0) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); subitem.set(String(extname, CopyString), String((char*)bio_buf->data, bio_buf->length, CopyString)); } else { BIO_free(bio_out); return false; } } else if (X509V3_EXT_print(bio_out, extension, 0, 0)) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); subitem.set(String(extname, CopyString), String((char*)bio_buf->data, bio_buf->length, CopyString)); } else { str = X509_EXTENSION_get_data(extension); subitem.set(String(extname, CopyString), String((char*)str->data, str->length, CopyString)); } BIO_free(bio_out); } ret.set(s_extensions, subitem); } return ret; } Variant HHVM_FUNCTION(openssl_x509_read, const Variant& x509certdata) { auto ocert = Certificate::Get(x509certdata); if (!ocert) { raise_warning("supplied parameter cannot be coerced into " "an X509 certificate!"); return false; } return Variant(ocert); } Variant HHVM_FUNCTION(openssl_random_pseudo_bytes, int length, bool& crypto_strong) { if (length <= 0) { return false; } unsigned char *buffer = nullptr; String s = String(length, ReserveString); buffer = (unsigned char *)s.mutableData(); if (RAND_bytes(buffer, length) <= 0) { crypto_strong = false; return false; } else { crypto_strong = true; s.setSize(length); return s; } } Variant HHVM_FUNCTION(openssl_cipher_iv_length, const String& method) { if (method.empty()) { raise_warning("Unknown cipher algorithm"); return false; } const EVP_CIPHER *cipher_type = EVP_get_cipherbyname(method.c_str()); if (!cipher_type) { raise_warning("Unknown cipher algorithm"); return false; } return EVP_CIPHER_iv_length(cipher_type); } /* Cipher mode info */ struct php_openssl_cipher_mode { /* Whether this mode uses authenticated encryption. True, for example, with the GCM and CCM modes */ bool is_aead; /* Whether this mode is a 'single run aead', meaning that DecryptFinal doesn't get called. For example, CCM mode is a single run aead mode. */ bool is_single_run_aead; /* The OpenSSL flag to get the computed tag, if this mode is aead. */ int aead_get_tag_flag; /* The OpenSSL flag to set the computed tag, if this mode is aead. */ int aead_set_tag_flag; /* The OpenSSL flag to set the IV length, if this mode is aead */ int aead_ivlen_flag; }; // initialize a php_openssl_cipher_mode corresponding to an EVP_CIPHER. static php_openssl_cipher_mode php_openssl_load_cipher_mode( const EVP_CIPHER* cipher_type) { php_openssl_cipher_mode mode = {}; switch (EVP_CIPHER_mode(cipher_type)) { #ifdef EVP_CIPH_GCM_MODE case EVP_CIPH_GCM_MODE: mode.is_aead = true; mode.is_single_run_aead = false; mode.aead_get_tag_flag = EVP_CTRL_GCM_GET_TAG; mode.aead_set_tag_flag = EVP_CTRL_GCM_SET_TAG; mode.aead_ivlen_flag = EVP_CTRL_GCM_SET_IVLEN; break; #endif #ifdef EVP_CIPH_CCM_MODE case EVP_CIPH_CCM_MODE: mode.is_aead = true; mode.is_single_run_aead = true; mode.aead_get_tag_flag = EVP_CTRL_CCM_GET_TAG; mode.aead_set_tag_flag = EVP_CTRL_CCM_SET_TAG; mode.aead_ivlen_flag = EVP_CTRL_CCM_SET_IVLEN; break; #endif default: break; } return mode; } static bool php_openssl_validate_iv( String piv, int iv_required_len, String& out, EVP_CIPHER_CTX* cipher_ctx, const php_openssl_cipher_mode* mode) { if (cipher_ctx == nullptr || mode == nullptr) { return false; } /* Best case scenario, user behaved */ if (piv.size() == iv_required_len) { out = std::move(piv); return true; } if (mode->is_aead) { if (EVP_CIPHER_CTX_ctrl( cipher_ctx, mode->aead_ivlen_flag, piv.size(), nullptr) != 1) { raise_warning( "Setting of IV length for AEAD mode failed, the expected length is " "%d bytes", iv_required_len); return false; } out = std::move(piv); return true; } String s = String(iv_required_len, ReserveString); char* iv_new = s.mutableData(); memset(iv_new, 0, iv_required_len); if (piv.size() <= 0) { /* BC behavior */ s.setSize(iv_required_len); out = std::move(s); return true; } if (piv.size() < iv_required_len) { raise_warning("IV passed is only %d bytes long, cipher " "expects an IV of precisely %d bytes, padding with \\0", piv.size(), iv_required_len); memcpy(iv_new, piv.data(), piv.size()); s.setSize(iv_required_len); out = std::move(s); return true; } raise_warning("IV passed is %d bytes long which is longer than the %d " "expected by selected cipher, truncating", piv.size(), iv_required_len); memcpy(iv_new, piv.data(), iv_required_len); s.setSize(iv_required_len); out = std::move(s); return true; } namespace { Variant openssl_encrypt_impl(const String& data, const String& method, const String& password, int options, const String& iv, Variant* tag_out, const String& aad, int tag_length) { const EVP_CIPHER *cipher_type = EVP_get_cipherbyname(method.c_str()); if (!cipher_type) { raise_warning("Unknown cipher algorithm"); return false; } EVP_CIPHER_CTX* cipher_ctx = EVP_CIPHER_CTX_new(); if (!cipher_ctx) { raise_warning("Failed to create cipher context"); return false; } SCOPE_EXIT { EVP_CIPHER_CTX_free(cipher_ctx); }; php_openssl_cipher_mode mode = php_openssl_load_cipher_mode(cipher_type); if (mode.is_aead && !tag_out) { raise_warning("Must call openssl_encrypt_with_tag when using an AEAD cipher"); return false; } int keylen = EVP_CIPHER_key_length(cipher_type); String key = password; /* * older openssl libraries can assert if the passed in password length is * less than keylen */ if (keylen > password.size()) { String s = String(keylen, ReserveString); char *keybuf = s.mutableData(); memset(keybuf, 0, keylen); memcpy(keybuf, password.data(), password.size()); key = s.setSize(keylen); } int max_iv_len = EVP_CIPHER_iv_length(cipher_type); if (iv.size() <= 0 && max_iv_len > 0 && !mode.is_aead) { raise_warning("Using an empty Initialization Vector (iv) is potentially " "insecure and not recommended"); } int result_len = 0; int outlen = data.size() + EVP_CIPHER_block_size(cipher_type); String rv = String(outlen, ReserveString); unsigned char *outbuf = (unsigned char*)rv.mutableData(); EVP_EncryptInit_ex(cipher_ctx, cipher_type, nullptr, nullptr, nullptr); String new_iv; // we do this after EncryptInit because validate_iv changes cipher_ctx for // aead modes (must be initialized first). if (!php_openssl_validate_iv( std::move(iv), max_iv_len, new_iv, cipher_ctx, &mode)) { return false; } // set the tag length for CCM mode/other modes that require tag lengths to // be set. if (mode.is_single_run_aead && !EVP_CIPHER_CTX_ctrl( cipher_ctx, mode.aead_set_tag_flag, tag_length, nullptr)) { raise_warning("Setting tag length failed"); return false; } if (password.size() > keylen) { EVP_CIPHER_CTX_set_key_length(cipher_ctx, password.size()); } EVP_EncryptInit_ex( cipher_ctx, nullptr, nullptr, (unsigned char*)key.data(), (unsigned char*)new_iv.data()); if (options & k_OPENSSL_ZERO_PADDING) { EVP_CIPHER_CTX_set_padding(cipher_ctx, 0); } // for single run aeads like CCM, we need to provide the length of the // plaintext before providing AAD or ciphertext. if (mode.is_single_run_aead && !EVP_EncryptUpdate( cipher_ctx, nullptr, &result_len, nullptr, data.size())) { raise_warning("Setting of data length failed"); return false; } // set up aad: if (mode.is_aead && !EVP_EncryptUpdate( cipher_ctx, nullptr, &result_len, (unsigned char*)aad.data(), aad.size())) { raise_warning("Setting of additional application data failed"); return false; } // OpenSSL before 0.9.8i asserts with size < 0 if (data.size() >= 0) { EVP_EncryptUpdate(cipher_ctx, outbuf, &result_len, (unsigned char *)data.data(), data.size()); } outlen = result_len; if (EVP_EncryptFinal_ex( cipher_ctx, (unsigned char*)outbuf + result_len, &result_len)) { outlen += result_len; rv.setSize(outlen); // Get tag if possible if (mode.is_aead) { String tagrv = String(tag_length, ReserveString); if (EVP_CIPHER_CTX_ctrl( cipher_ctx, mode.aead_get_tag_flag, tag_length, tagrv.mutableData()) == 1) { tagrv.setSize(tag_length); assertx(tag_out); *tag_out = tagrv; } else { raise_warning("Retrieving authentication tag failed"); return false; } } else if (tag_out) { raise_warning( "The authenticated tag cannot be provided for cipher that does not" " support AEAD"); } // Return encrypted data if (options & k_OPENSSL_RAW_DATA) { return rv; } else { return StringUtil::Base64Encode(rv); } } return false; } } // anonymous namespace Variant HHVM_FUNCTION(openssl_encrypt, const String& data, const String& method, const String& password, int options /* = 0 */, const String& iv /* = null_string */, const String& aad /* = null_string */, int tag_length /* = 16 */) { return openssl_encrypt_impl(data, method, password, options, iv, nullptr, aad, tag_length); } Variant HHVM_FUNCTION(openssl_encrypt_with_tag, const String& data, const String& method, const String& password, int options, const String& iv, Variant& tag_out, const String& aad /* = null_string */, int tag_length /* = 16 */) { return openssl_encrypt_impl(data, method, password, options, iv, &tag_out, aad, tag_length); } Variant HHVM_FUNCTION(openssl_decrypt, const String& data, const String& method, const String& password, int options /* = 0 */, const String& iv /* = null_string */, const String& tag /* = null_string */, const String& aad /* = null_string */) { const EVP_CIPHER *cipher_type = EVP_get_cipherbyname(method.c_str()); if (!cipher_type) { raise_warning("Unknown cipher algorithm"); return false; } EVP_CIPHER_CTX* cipher_ctx = EVP_CIPHER_CTX_new(); if (!cipher_ctx) { raise_warning("Failed to create cipher context"); return false; } SCOPE_EXIT { EVP_CIPHER_CTX_free(cipher_ctx); }; php_openssl_cipher_mode mode = php_openssl_load_cipher_mode(cipher_type); String decoded_data = data; if (!(options & k_OPENSSL_RAW_DATA)) { decoded_data = StringUtil::Base64Decode(data); } int keylen = EVP_CIPHER_key_length(cipher_type); String key = password; /* * older openssl libraries can assert if the passed in password length is * less than keylen */ if (keylen > password.size()) { String s = String(keylen, ReserveString); char *keybuf = s.mutableData(); memset(keybuf, 0, keylen); memcpy(keybuf, password.data(), password.size()); key = s.setSize(keylen); } int result_len = 0; int outlen = decoded_data.size() + EVP_CIPHER_block_size(cipher_type); String rv = String(outlen, ReserveString); unsigned char *outbuf = (unsigned char*)rv.mutableData(); EVP_DecryptInit_ex(cipher_ctx, cipher_type, nullptr, nullptr, nullptr); String new_iv; // we do this after DecryptInit because validate_iv changes cipher_ctx for // aead modes (must be initialized first). if (!php_openssl_validate_iv( std::move(iv), EVP_CIPHER_iv_length(cipher_type), new_iv, cipher_ctx, &mode)) { return false; } // set the tag if required: if (tag.size() > 0) { if (!mode.is_aead) { raise_warning( "The tag is being ignored because the cipher method does not" " support AEAD"); } else if (!EVP_CIPHER_CTX_ctrl( cipher_ctx, mode.aead_set_tag_flag, tag.size(), (unsigned char*)tag.data())) { raise_warning("Setting tag for AEAD cipher decryption failed"); return false; } } else { if (mode.is_aead) { raise_warning("A tag should be provided when using AEAD mode"); return false; } } if (password.size() > keylen) { EVP_CIPHER_CTX_set_key_length(cipher_ctx, password.size()); } EVP_DecryptInit_ex( cipher_ctx, nullptr, nullptr, (unsigned char*)key.data(), (unsigned char*)new_iv.data()); if (options & k_OPENSSL_ZERO_PADDING) { EVP_CIPHER_CTX_set_padding(cipher_ctx, 0); } // for single run aeads like CCM, we need to provide the length of the // ciphertext before providing AAD or ciphertext. if (mode.is_single_run_aead && !EVP_DecryptUpdate( cipher_ctx, nullptr, &result_len, nullptr, decoded_data.size())) { raise_warning("Setting of data length failed"); return false; } // set up aad: if (mode.is_aead && !EVP_DecryptUpdate( cipher_ctx, nullptr, &result_len, (unsigned char*)aad.data(), aad.size())) { raise_warning("Setting of additional application data failed"); return false; } if (!EVP_DecryptUpdate( cipher_ctx, outbuf, &result_len, (unsigned char*)decoded_data.data(), decoded_data.size())) { return false; } outlen = result_len; // if is_single_run_aead is enabled, DecryptFinal shouldn't be called. // if something went wrong in this case, we would've caught it at // DecryptUpdate. if (mode.is_single_run_aead || EVP_DecryptFinal_ex( cipher_ctx, (unsigned char*)outbuf + result_len, &result_len)) { // don't want to do this if is_single_run_aead was enabled, since we didn't // make a call to EVP_DecryptFinal. if (!mode.is_single_run_aead) { outlen += result_len; } rv.setSize(outlen); return rv; } else { return false; } } Variant HHVM_FUNCTION(openssl_digest, const String& data, const String& method, bool raw_output /* = false */) { const EVP_MD *mdtype = EVP_get_digestbyname(method.c_str()); if (!mdtype) { raise_warning("Unknown signature algorithm"); return false; } int siglen = EVP_MD_size(mdtype); String rv = String(siglen, ReserveString); unsigned char *sigbuf = (unsigned char *)rv.mutableData(); EVP_MD_CTX *md_ctx = EVP_MD_CTX_new(); SCOPE_EXIT { EVP_MD_CTX_free(md_ctx); }; EVP_DigestInit(md_ctx, mdtype); EVP_DigestUpdate(md_ctx, (unsigned char *)data.data(), data.size()); if (EVP_DigestFinal(md_ctx, (unsigned char *)sigbuf, (unsigned int *)&siglen)) { if (raw_output) { rv.setSize(siglen); return rv; } else { char* digest_str = string_bin2hex((char*)sigbuf, siglen); return String(digest_str, AttachString); } } else { return false; } } static void openssl_add_method_or_alias(const OBJ_NAME *name, void *arg) { Array *ret = (Array*)arg; ret->append(String((char *)name->name, CopyString)); } static void openssl_add_method(const OBJ_NAME *name, void *arg) { if (name->alias == 0) { Array *ret = (Array*)arg; ret->append(String((char *)name->name, CopyString)); } } Array HHVM_FUNCTION(openssl_get_cipher_methods, bool aliases /* = false */) { Array ret = Array::CreateVArray(); OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_CIPHER_METH, aliases ? openssl_add_method_or_alias: openssl_add_method, &ret); return ret; } Variant HHVM_FUNCTION(openssl_get_curve_names) { #ifdef HAVE_EVP_PKEY_EC const size_t len = EC_get_builtin_curves(nullptr, 0); std::unique_ptr<EC_builtin_curve[]> curves(new EC_builtin_curve[len]); if (!EC_get_builtin_curves(curves.get(), len)) { return false; } VArrayInit ret(len); for (size_t i = 0; i < len; ++i) { auto const sname = OBJ_nid2sn(curves[i].nid); if (sname != nullptr) { ret.append(String(sname, CopyString)); } } return ret.toArray(); #else return false; #endif } Array HHVM_FUNCTION(openssl_get_md_methods, bool aliases /* = false */) { Array ret = Array::CreateVArray(); OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_MD_METH, aliases ? openssl_add_method_or_alias: openssl_add_method, &ret); return ret; } ///////////////////////////////////////////////////////////////////////////// const StaticString s_OPENSSL_VERSION_TEXT("OPENSSL_VERSION_TEXT"); struct opensslExtension final : Extension { opensslExtension() : Extension("openssl") {} void moduleInit() override { HHVM_RC_INT(OPENSSL_RAW_DATA, k_OPENSSL_RAW_DATA); HHVM_RC_INT(OPENSSL_ZERO_PADDING, k_OPENSSL_ZERO_PADDING); HHVM_RC_INT(OPENSSL_NO_PADDING, k_OPENSSL_NO_PADDING); HHVM_RC_INT(OPENSSL_PKCS1_OAEP_PADDING, k_OPENSSL_PKCS1_OAEP_PADDING); HHVM_RC_INT(OPENSSL_SSLV23_PADDING, k_OPENSSL_SSLV23_PADDING); HHVM_RC_INT(OPENSSL_PKCS1_PADDING, k_OPENSSL_PKCS1_PADDING); HHVM_RC_INT_SAME(OPENSSL_ALGO_SHA1); HHVM_RC_INT_SAME(OPENSSL_ALGO_MD5); HHVM_RC_INT_SAME(OPENSSL_ALGO_MD4); #ifdef HAVE_OPENSSL_MD2_H HHVM_RC_INT_SAME(OPENSSL_ALGO_MD2); #endif HHVM_RC_INT_SAME(OPENSSL_ALGO_DSS1); HHVM_RC_INT_SAME(OPENSSL_ALGO_SHA224); HHVM_RC_INT_SAME(OPENSSL_ALGO_SHA256); HHVM_RC_INT_SAME(OPENSSL_ALGO_SHA384); HHVM_RC_INT_SAME(OPENSSL_ALGO_SHA512); HHVM_RC_INT_SAME(OPENSSL_ALGO_RMD160); HHVM_RC_INT(OPENSSL_CIPHER_RC2_40, PHP_OPENSSL_CIPHER_RC2_40); HHVM_RC_INT(OPENSSL_CIPHER_RC2_128, PHP_OPENSSL_CIPHER_RC2_128); HHVM_RC_INT(OPENSSL_CIPHER_RC2_64, PHP_OPENSSL_CIPHER_RC2_64); HHVM_RC_INT(OPENSSL_CIPHER_DES, PHP_OPENSSL_CIPHER_DES); HHVM_RC_INT(OPENSSL_CIPHER_3DES, PHP_OPENSSL_CIPHER_3DES); HHVM_RC_INT_SAME(OPENSSL_KEYTYPE_RSA); HHVM_RC_INT_SAME(OPENSSL_KEYTYPE_DSA); HHVM_RC_INT_SAME(OPENSSL_KEYTYPE_DH); #ifdef HAVE_EVP_PKEY_EC HHVM_RC_INT_SAME(OPENSSL_KEYTYPE_EC); #endif HHVM_RC_INT_SAME(OPENSSL_VERSION_NUMBER); HHVM_RC_INT_SAME(PKCS7_TEXT); HHVM_RC_INT_SAME(PKCS7_NOCERTS); HHVM_RC_INT_SAME(PKCS7_NOSIGS); HHVM_RC_INT_SAME(PKCS7_NOCHAIN); HHVM_RC_INT_SAME(PKCS7_NOINTERN); HHVM_RC_INT_SAME(PKCS7_NOVERIFY); HHVM_RC_INT_SAME(PKCS7_DETACHED); HHVM_RC_INT_SAME(PKCS7_BINARY); HHVM_RC_INT_SAME(PKCS7_NOATTR); HHVM_RC_STR_SAME(OPENSSL_VERSION_TEXT); HHVM_RC_INT_SAME(X509_PURPOSE_SSL_CLIENT); HHVM_RC_INT_SAME(X509_PURPOSE_SSL_SERVER); HHVM_RC_INT_SAME(X509_PURPOSE_NS_SSL_SERVER); HHVM_RC_INT_SAME(X509_PURPOSE_SMIME_SIGN); HHVM_RC_INT_SAME(X509_PURPOSE_SMIME_ENCRYPT); HHVM_RC_INT_SAME(X509_PURPOSE_CRL_SIGN); #ifdef X509_PURPOSE_ANY HHVM_RC_INT_SAME(X509_PURPOSE_ANY); #endif HHVM_FE(openssl_csr_export_to_file); HHVM_FE(openssl_csr_export); HHVM_FE(openssl_csr_get_public_key); HHVM_FE(openssl_csr_get_subject); HHVM_FE(openssl_csr_new); HHVM_FE(openssl_csr_sign); HHVM_FE(openssl_error_string); HHVM_FE(openssl_open); HHVM_FE(openssl_pkcs12_export_to_file); HHVM_FE(openssl_pkcs12_export); HHVM_FE(openssl_pkcs12_read); HHVM_FE(openssl_pkcs7_decrypt); HHVM_FE(openssl_pkcs7_encrypt); HHVM_FE(openssl_pkcs7_sign); HHVM_FE(openssl_pkcs7_verify); HHVM_FE(openssl_pkey_export_to_file); HHVM_FE(openssl_pkey_export); HHVM_FE(openssl_pkey_get_details); HHVM_FE(openssl_pkey_get_private); HHVM_FE(openssl_pkey_get_public); HHVM_FE(openssl_pkey_new); HHVM_FE(openssl_private_decrypt); HHVM_FE(openssl_private_encrypt); HHVM_FE(openssl_public_decrypt); HHVM_FE(openssl_public_encrypt); HHVM_FE(openssl_seal); HHVM_FE(openssl_sign); HHVM_FE(openssl_verify); HHVM_FE(openssl_x509_check_private_key); HHVM_FE(openssl_x509_checkpurpose); HHVM_FE(openssl_x509_export_to_file); HHVM_FE(openssl_x509_export); HHVM_FE(openssl_x509_parse); HHVM_FE(openssl_x509_read); HHVM_FE(openssl_random_pseudo_bytes); HHVM_FE(openssl_cipher_iv_length); HHVM_FE(openssl_encrypt); HHVM_FE(openssl_encrypt_with_tag); HHVM_FE(openssl_decrypt); HHVM_FE(openssl_digest); HHVM_FE(openssl_get_cipher_methods); HHVM_FE(openssl_get_curve_names); HHVM_FE(openssl_get_md_methods); loadSystemlib(); } } s_openssl_extension; /////////////////////////////////////////////////////////////////////////////// }
15409
True
1
CVE-2020-1918
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In-memory file operations (ie: using fopen on a data URI) did not properly restrict negative seeking, allowing for the reading of memory prior to the in-memory buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:53Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::php_openssl_config_check_syntax
HPHP::php_openssl_config_check_syntax( const char * section_label , const char * config_filename , const char * section , LHASH_OF(CONF_VALUE) * config)
['section_label', 'config_filename', 'section', 'config']
static inline bool php_openssl_config_check_syntax (const char *section_label, const char *config_filename, const char *section, LHASH_OF(CONF_VALUE) *config) { #else static inline bool php_openssl_config_check_syntax (const char *section_label, const char *config_filename, const char *section, LHASH *config) { #endif X509V3_CTX ctx; X509V3_set_ctx_test(&ctx); X509V3_set_conf_lhash(&ctx, config); if (!X509V3_EXT_add_conf(config, &ctx, (char*)section, nullptr)) { raise_warning("Error loading %s section %s of %s", section_label, section, config_filename); return false; } return true; } const StaticString s_config("config"), s_config_section_name("config_section_name"), s_digest_alg("digest_alg"), s_x509_extensions("x509_extensions"), s_req_extensions("req_extensions"), s_private_key_bits("private_key_bits"), s_private_key_type("private_key_type"), s_encrypt_key("encrypt_key"), s_curve_name("curve_name"); static bool php_openssl_parse_config(struct php_x509_request *req, const Array& args, std::vector<String> &strings) { req->config_filename = read_string(args, s_config, default_ssl_conf_filename, strings); req->section_name = read_string(args, s_config_section_name, "req", strings); req->global_config = CONF_load(nullptr, default_ssl_conf_filename, nullptr); req->req_config = CONF_load(nullptr, req->config_filename, nullptr); if (req->req_config == nullptr) { return false; } /* read in the oids */ char *str = CONF_get_string(req->req_config, nullptr, "oid_file"); if (str) { BIO *oid_bio = BIO_new_file(str, "r"); if (oid_bio) { OBJ_create_objects(oid_bio); BIO_free(oid_bio); } } if (!add_oid_section(req)) { return false; } req->digest_name = read_string(args, s_digest_alg, CONF_get_string(req->req_config, req->section_name, "default_md"), strings); req->extensions_section = read_string(args, s_x509_extensions, CONF_get_string(req->req_config, req->section_name, "x509_extensions"), strings); req->request_extensions_section = read_string(args, s_req_extensions, CONF_get_string(req->req_config, req->section_name, "req_extensions"), strings); req->priv_key_bits = read_integer(args, s_private_key_bits, CONF_get_number(req->req_config, req->section_name, "default_bits")); req->priv_key_type = read_integer(args, s_private_key_type, OPENSSL_KEYTYPE_DEFAULT); if (args.exists(s_encrypt_key)) { bool value = args[s_encrypt_key].toBoolean(); req->priv_key_encrypt = value ? 1 : 0; } else { str = CONF_get_string(req->req_config, req->section_name, "encrypt_rsa_key"); if (str == nullptr) { str = CONF_get_string(req->req_config, req->section_name, "encrypt_key"); } if (str && strcmp(str, "no") == 0) { req->priv_key_encrypt = 0; } else { req->priv_key_encrypt = 1; } } /* digest alg */ if (req->digest_name == nullptr) { req->digest_name = CONF_get_string(req->req_config, req->section_name, "default_md"); } if (req->digest_name) { req->digest = req->md_alg = EVP_get_digestbyname(req->digest_name); } if (req->md_alg == nullptr) { req->md_alg = req->digest = EVP_sha256(); } #ifdef HAVE_EVP_PKEY_EC /* set the ec group curve name */ req->curve_name = NID_undef; if (args.exists(s_curve_name)) { auto const curve_name = args[s_curve_name].toString(); req->curve_name = OBJ_sn2nid(curve_name.data()); if (req->curve_name == NID_undef) { raise_warning( "Unknown elliptic curve (short) name %s", curve_name.data() ); return false; } } #endif if (req->extensions_section && !php_openssl_config_check_syntax ("extensions_section", req->config_filename, req->extensions_section, req->req_config)) { return false; } /* set the string mask */ str = CONF_get_string(req->req_config, req->section_name, "string_mask"); if (str && !ASN1_STRING_set_default_mask_asc(str)) { raise_warning("Invalid global string mask setting %s", str); return false; } if (req->request_extensions_section && !php_openssl_config_check_syntax ("request_extensions_section", req->config_filename, req->request_extensions_section, req->req_config)) { return false; } return true; } static void php_openssl_dispose_config(struct php_x509_request *req) { if (req->global_config) { CONF_free(req->global_config); req->global_config = nullptr; } if (req->req_config) { CONF_free(req->req_config); req->req_config = nullptr; } } static STACK_OF(X509) *load_all_certs_from_file(const char *certfile) { STACK_OF(X509_INFO) *sk = nullptr; STACK_OF(X509) *stack = nullptr, *ret = nullptr; BIO *in = nullptr; X509_INFO *xi; if (!(stack = sk_X509_new_null())) { raise_warning("memory allocation failure"); goto end; } if (!(in = BIO_new_file(certfile, "r"))) { raise_warning("error opening the file, %s", certfile); sk_X509_free(stack); goto end; } /* This loads from a file, a stack of x509/crl/pkey sets */ if (!(sk = PEM_X509_INFO_read_bio(in, nullptr, nullptr, nullptr))) { raise_warning("error reading the file, %s", certfile); sk_X509_free(stack); goto end; } /* scan over it and pull out the certs */ while (sk_X509_INFO_num(sk)) { xi = sk_X509_INFO_shift(sk); if (xi->x509 != nullptr) { sk_X509_push(stack, xi->x509); xi->x509 = nullptr; } X509_INFO_free(xi); } if (!sk_X509_num(stack)) { raise_warning("no certificates in file, %s", certfile); sk_X509_free(stack); goto end; } ret = stack; end: BIO_free(in); sk_X509_INFO_free(sk); return ret; } /** * calist is an array containing file and directory names. create a * certificate store and add those certs to it for use in verification. */ static X509_STORE *setup_verify(const Array& calist) { X509_STORE *store = X509_STORE_new(); if (store == nullptr) { return nullptr; } X509_LOOKUP *dir_lookup, *file_lookup; int ndirs = 0, nfiles = 0; for (ArrayIter iter(calist); iter; ++iter) { String item = iter.second().toString(); struct stat sb; if (stat(item.data(), &sb) == -1) { raise_warning("unable to stat %s", item.data()); continue; } if ((sb.st_mode & S_IFREG) == S_IFREG) { file_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()); if (file_lookup == nullptr || !X509_LOOKUP_load_file(file_lookup, item.data(), X509_FILETYPE_PEM)) { raise_warning("error loading file %s", item.data()); } else { nfiles++; } file_lookup = nullptr; } else { dir_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir()); if (dir_lookup == nullptr || !X509_LOOKUP_add_dir(dir_lookup, item.data(), X509_FILETYPE_PEM)) { raise_warning("error loading directory %s", item.data()); } else { ndirs++; } dir_lookup = nullptr; } } if (nfiles == 0) { file_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()); if (file_lookup) { X509_LOOKUP_load_file(file_lookup, nullptr, X509_FILETYPE_DEFAULT); } } if (ndirs == 0) { dir_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir()); if (dir_lookup) { X509_LOOKUP_add_dir(dir_lookup, nullptr, X509_FILETYPE_DEFAULT); } } return store; } /////////////////////////////////////////////////////////////////////////////// static bool add_entries(X509_NAME *subj, const Array& items) { for (ArrayIter iter(items); iter; ++iter) { auto const index = iter.first().toString(); auto const item = iter.second().toString(); int nid = OBJ_txt2nid(index.data()); if (nid != NID_undef) { if (!X509_NAME_add_entry_by_NID(subj, nid, MBSTRING_ASC, (unsigned char*)item.data(), -1, -1, 0)) { raise_warning("dn: add_entry_by_NID %d -> %s (failed)", nid, item.data()); return false; } } else { raise_warning("dn: %s is not a recognized name", index.data()); } } return true; } static bool php_openssl_make_REQ(struct php_x509_request *req, X509_REQ *csr, const Array& dn, const Array& attribs) { char *dn_sect = CONF_get_string(req->req_config, req->section_name, "distinguished_name"); if (dn_sect == nullptr) return false; STACK_OF(CONF_VALUE) *dn_sk = CONF_get_section(req->req_config, dn_sect); if (dn_sk == nullptr) return false; char *attr_sect = CONF_get_string(req->req_config, req->section_name, "attributes"); STACK_OF(CONF_VALUE) *attr_sk = nullptr; if (attr_sect) { attr_sk = CONF_get_section(req->req_config, attr_sect); if (attr_sk == nullptr) { return false; } } /* setup the version number: version 1 */ if (X509_REQ_set_version(csr, 0L)) { X509_NAME *subj = X509_REQ_get_subject_name(csr); if (!add_entries(subj, dn)) return false; /* Finally apply defaults from config file */ for (int i = 0; i < sk_CONF_VALUE_num(dn_sk); i++) { CONF_VALUE *v = sk_CONF_VALUE_value(dn_sk, i); char *type = v->name; int len = strlen(type); if (len < (int)sizeof("_default")) { continue; } len -= sizeof("_default") - 1; if (strcmp("_default", type + len) != 0) { continue; } if (len > 200) { len = 200; } char buffer[200 + 1]; /*200 + \0 !*/ memcpy(buffer, type, len); buffer[len] = '\0'; type = buffer; /* Skip past any leading X. X: X, etc to allow for multiple instances */ for (char *str = type; *str; str++) { if (*str == ':' || *str == ',' || *str == '.') { str++; if (*str) { type = str; } break; } } /* if it is already set, skip this */ int nid = OBJ_txt2nid(type); if (X509_NAME_get_index_by_NID(subj, nid, -1) >= 0) { continue; } if (!X509_NAME_add_entry_by_txt(subj, type, MBSTRING_ASC, (unsigned char*)v->value, -1, -1, 0)) { raise_warning("add_entry_by_txt %s -> %s (failed)", type, v->value); return false; } if (!X509_NAME_entry_count(subj)) { raise_warning("no objects specified in config file"); return false; } } if (!add_entries(subj, attribs)) return false; if (attr_sk) { for (int i = 0; i < sk_CONF_VALUE_num(attr_sk); i++) { CONF_VALUE *v = sk_CONF_VALUE_value(attr_sk, i); /* if it is already set, skip this */ int nid = OBJ_txt2nid(v->name); if (X509_REQ_get_attr_by_NID(csr, nid, -1) >= 0) { continue; } if (!X509_REQ_add1_attr_by_txt(csr, v->name, MBSTRING_ASC, (unsigned char*)v->value, -1)) { /** * hzhao: mismatched version of conf file may have attributes that * are not recognizable, and I don't think it should be treated as * fatal errors. */ Logger::Verbose("add1_attr_by_txt %s -> %s (failed)", v->name, v->value); // return false; } } } } X509_REQ_set_pubkey(csr, req->priv_key); return true; } bool HHVM_FUNCTION(openssl_csr_export_to_file, const Variant& csr, const String& outfilename, bool notext /* = true */) { auto pcsr = CSRequest::Get(csr); if (!pcsr) return false; BIO *bio_out = BIO_new_file((char*)outfilename.data(), "w"); if (bio_out == nullptr) { raise_warning("error opening file %s", outfilename.data()); return false; } if (!notext) { X509_REQ_print(bio_out, pcsr->csr()); } PEM_write_bio_X509_REQ(bio_out, pcsr->csr()); BIO_free(bio_out); return true; } bool HHVM_FUNCTION(openssl_csr_export, const Variant& csr, Variant& out, bool notext /* = true */) { auto pcsr = CSRequest::Get(csr); if (!pcsr) return false; BIO *bio_out = BIO_new(BIO_s_mem()); if (!notext) { X509_REQ_print(bio_out, pcsr->csr()); } if (PEM_write_bio_X509_REQ(bio_out, pcsr->csr())) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); out = String((char*)bio_buf->data, bio_buf->length, CopyString); BIO_free(bio_out); return true; } BIO_free(bio_out); return false; } Variant HHVM_FUNCTION(openssl_csr_get_public_key, const Variant& csr) { auto pcsr = CSRequest::Get(csr); if (!pcsr) return false; auto input_csr = pcsr->csr(); #if OPENSSL_VERSION_NUMBER >= 0x10100000 /* Due to changes in OpenSSL 1.1 related to locking when decoding CSR, * the pub key is not changed after assigning. It means if we pass * a private key, it will be returned including the private part. * If we duplicate it, then we get just the public part which is * the same behavior as for OpenSSL 1.0 */ input_csr = X509_REQ_dup(input_csr); /* We need to free the CSR as it was duplicated */ SCOPE_EXIT { X509_REQ_free(input_csr); }; #endif auto pubkey = X509_REQ_get_pubkey(input_csr); if (!pubkey) return false; return Variant(req::make<Key>(pubkey)); } Variant HHVM_FUNCTION(openssl_csr_get_subject, const Variant& csr, bool use_shortnames /* = true */) { auto pcsr = CSRequest::Get(csr); if (!pcsr) return false; X509_NAME *subject = X509_REQ_get_subject_name(pcsr->csr()); Array ret = Array::CreateDArray(); add_assoc_name_entry(ret, nullptr, subject, use_shortnames); return ret; } Variant HHVM_FUNCTION(openssl_csr_new, const Variant& dn, Variant& privkey, const Variant& configargs /* = uninit_variant */, const Variant& extraattribs /* = uninit_variant */) { Variant ret = false; struct php_x509_request req; memset(&req, 0, sizeof(req)); req::ptr<Key> okey; X509_REQ *csr = nullptr; std::vector<String> strings; if (php_openssl_parse_config(&req, configargs.toArray(), strings)) { /* Generate or use a private key */ if (!privkey.isNull()) { okey = Key::Get(privkey, false); if (okey) { req.priv_key = okey->m_key; } } if (req.priv_key == nullptr) { req.generatePrivateKey(); if (req.priv_key) { okey = req::make<Key>(req.priv_key); } } if (req.priv_key == nullptr) { raise_warning("Unable to generate a private key"); } else { csr = X509_REQ_new(); if (csr && php_openssl_make_REQ(&req, csr, dn.toArray(), extraattribs.toArray())) { X509V3_CTX ext_ctx; X509V3_set_ctx(&ext_ctx, nullptr, nullptr, csr, nullptr, 0); X509V3_set_conf_lhash(&ext_ctx, req.req_config); /* Add extensions */ if (req.request_extensions_section && !X509V3_EXT_REQ_add_conf(req.req_config, &ext_ctx, (char*)req.request_extensions_section, csr)) { raise_warning("Error loading extension section %s", req.request_extensions_section); } else { ret = true; if (X509_REQ_sign(csr, req.priv_key, req.digest)) { ret = req::make<CSRequest>(csr); csr = nullptr; } else { raise_warning("Error signing request"); } privkey = Variant(okey); } } } } if (csr) { X509_REQ_free(csr); } php_openssl_dispose_config(&req); return ret; } Variant HHVM_FUNCTION(openssl_csr_sign, const Variant& csr, const Variant& cacert, const Variant& priv_key, int days, const Variant& configargs /* = null */, int serial /* = 0 */) { auto pcsr = CSRequest::Get(csr); if (!pcsr) return false; req::ptr<Certificate> ocert; if (!cacert.isNull()) { ocert = Certificate::Get(cacert); if (!ocert) { raise_warning("cannot get cert from parameter 2"); return false; } } auto okey = Key::Get(priv_key, false); if (!okey) { raise_warning("cannot get private key from parameter 3"); return false; } X509 *cert = nullptr; if (ocert) { cert = ocert->m_cert; } EVP_PKEY *pkey = okey->m_key; if (cert && !X509_check_private_key(cert, pkey)) { raise_warning("private key does not correspond to signing cert"); return false; } req::ptr<Certificate> onewcert; struct php_x509_request req; memset(&req, 0, sizeof(req)); Variant ret = false; std::vector<String> strings; if (!php_openssl_parse_config(&req, configargs.toArray(), strings)) { goto cleanup; } /* Check that the request matches the signature */ EVP_PKEY *key; key = X509_REQ_get_pubkey(pcsr->csr()); if (key == nullptr) { raise_warning("error unpacking public key"); goto cleanup; } int i; i = X509_REQ_verify(pcsr->csr(), key); if (i < 0) { raise_warning("Signature verification problems"); goto cleanup; } if (i == 0) { raise_warning("Signature did not match the certificate request"); goto cleanup; } /* Now we can get on with it */ X509 *new_cert; new_cert = X509_new(); if (new_cert == nullptr) { raise_warning("No memory"); goto cleanup; } onewcert = req::make<Certificate>(new_cert); /* Version 3 cert */ if (!X509_set_version(new_cert, 2)) { goto cleanup; } ASN1_INTEGER_set(X509_get_serialNumber(new_cert), serial); X509_set_subject_name(new_cert, X509_REQ_get_subject_name(pcsr->csr())); if (cert == nullptr) { cert = new_cert; } if (!X509_set_issuer_name(new_cert, X509_get_subject_name(cert))) { goto cleanup; } X509_gmtime_adj(X509_get_notBefore(new_cert), 0); X509_gmtime_adj(X509_get_notAfter(new_cert), (long)60 * 60 * 24 * days); i = X509_set_pubkey(new_cert, key); if (!i) { goto cleanup; } if (req.extensions_section) { X509V3_CTX ctx; X509V3_set_ctx(&ctx, cert, new_cert, pcsr->csr(), nullptr, 0); X509V3_set_conf_lhash(&ctx, req.req_config); if (!X509V3_EXT_add_conf(req.req_config, &ctx, (char*)req.extensions_section, new_cert)) { goto cleanup; } } /* Now sign it */ if (!X509_sign(new_cert, pkey, req.digest)) { raise_warning("failed to sign it"); goto cleanup; } /* Succeeded; lets return the cert */ ret = onewcert; cleanup: php_openssl_dispose_config(&req); return ret; } Variant HHVM_FUNCTION(openssl_error_string) { char buf[512]; unsigned long val = ERR_get_error(); if (val) { return String(ERR_error_string(val, buf), CopyString); } return false; } bool HHVM_FUNCTION(openssl_open, const String& sealed_data, Variant& open_data, const String& env_key, const Variant& priv_key_id, const String& method, /* = null_string */ const String& iv /* = null_string */) { const EVP_CIPHER *cipher_type; if (method.empty()) { cipher_type = EVP_rc4(); } else { cipher_type = EVP_get_cipherbyname(method.c_str()); if (!cipher_type) { raise_warning("Unknown cipher algorithm"); return false; } } auto okey = Key::Get(priv_key_id, false); if (!okey) { raise_warning("unable to coerce parameter 4 into a private key"); return false; } EVP_PKEY *pkey = okey->m_key; const unsigned char *iv_buf = nullptr; int iv_len = EVP_CIPHER_iv_length(cipher_type); if (iv_len > 0) { if (iv.empty()) { raise_warning( "Cipher algorithm requires an IV to be supplied as a sixth parameter"); return false; } if (iv.length() != iv_len) { raise_warning("IV length is invalid"); return false; } iv_buf = reinterpret_cast<const unsigned char*>(iv.c_str()); } String s = String(sealed_data.size(), ReserveString); unsigned char *buf = (unsigned char *)s.mutableData(); EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new(); if (ctx == nullptr) { raise_warning("Failed to allocate an EVP_CIPHER_CTX object"); return false; } SCOPE_EXIT { EVP_CIPHER_CTX_free(ctx); }; int len1, len2; if (!EVP_OpenInit( ctx, cipher_type, (unsigned char*)env_key.data(), env_key.size(), iv_buf, pkey) || !EVP_OpenUpdate( ctx, buf, &len1, (unsigned char*)sealed_data.data(), sealed_data.size()) || !EVP_OpenFinal(ctx, buf + len1, &len2) || len1 + len2 == 0) { return false; } open_data = s.setSize(len1 + len2); return true; } static STACK_OF(X509) *php_array_to_X509_sk(const Variant& certs) { STACK_OF(X509) *pcerts = sk_X509_new_null(); Array arrCerts; if (certs.isArray()) { arrCerts = certs.toArray(); } else { arrCerts.append(certs); } for (ArrayIter iter(arrCerts); iter; ++iter) { auto ocert = Certificate::Get(iter.second()); if (!ocert) { break; } sk_X509_push(pcerts, ocert->m_cert); } return pcerts; } const StaticString s_friendly_name("friendly_name"), s_extracerts("extracerts"); static bool openssl_pkcs12_export_impl(const Variant& x509, BIO *bio_out, const Variant& priv_key, const String& pass, const Variant& args /* = uninit_variant */) { auto ocert = Certificate::Get(x509); if (!ocert) { raise_warning("cannot get cert from parameter 1"); return false; } auto okey = Key::Get(priv_key, false); if (!okey) { raise_warning("cannot get private key from parameter 3"); return false; } X509 *cert = ocert->m_cert; EVP_PKEY *key = okey->m_key; if (cert && !X509_check_private_key(cert, key)) { raise_warning("private key does not correspond to cert"); return false; } Array arrArgs = args.toArray(); String friendly_name; if (arrArgs.exists(s_friendly_name)) { friendly_name = arrArgs[s_friendly_name].toString(); } STACK_OF(X509) *ca = nullptr; if (arrArgs.exists(s_extracerts)) { ca = php_array_to_X509_sk(arrArgs[s_extracerts]); } PKCS12 *p12 = PKCS12_create ((char*)pass.data(), (char*)(friendly_name.empty() ? nullptr : friendly_name.data()), key, cert, ca, 0, 0, 0, 0, 0); assertx(bio_out); bool ret = i2d_PKCS12_bio(bio_out, p12); PKCS12_free(p12); sk_X509_free(ca); return ret; } bool HHVM_FUNCTION(openssl_pkcs12_export_to_file, const Variant& x509, const String& filename, const Variant& priv_key, const String& pass, const Variant& args /* = uninit_variant */) { BIO *bio_out = BIO_new_file(filename.data(), "w"); if (bio_out == nullptr) { raise_warning("error opening file %s", filename.data()); return false; } bool ret = openssl_pkcs12_export_impl(x509, bio_out, priv_key, pass, args); BIO_free(bio_out); return ret; } bool HHVM_FUNCTION(openssl_pkcs12_export, const Variant& x509, Variant& out, const Variant& priv_key, const String& pass, const Variant& args /* = uninit_variant */) { BIO *bio_out = BIO_new(BIO_s_mem()); bool ret = openssl_pkcs12_export_impl(x509, bio_out, priv_key, pass, args); if (ret) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); out = String((char*)bio_buf->data, bio_buf->length, CopyString); } BIO_free(bio_out); return ret; } const StaticString s_cert("cert"), s_pkey("pkey"); bool HHVM_FUNCTION(openssl_pkcs12_read, const String& pkcs12, Variant& certs, const String& pass) { bool ret = false; PKCS12 *p12 = nullptr; BIO *bio_in = BIO_new(BIO_s_mem()); if (!BIO_write(bio_in, pkcs12.data(), pkcs12.size())) { goto cleanup; } if (d2i_PKCS12_bio(bio_in, &p12)) { EVP_PKEY *pkey = nullptr; X509 *cert = nullptr; STACK_OF(X509) *ca = nullptr; if (PKCS12_parse(p12, pass.data(), &pkey, &cert, &ca)) { Variant vcerts = Array::CreateDArray(); SCOPE_EXIT { certs = vcerts; }; BIO *bio_out = nullptr; if (cert) { bio_out = BIO_new(BIO_s_mem()); if (PEM_write_bio_X509(bio_out, cert)) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); vcerts.asArrRef().set(s_cert, String((char*)bio_buf->data, bio_buf->length, CopyString)); } BIO_free(bio_out); } if (pkey) { bio_out = BIO_new(BIO_s_mem()); if (PEM_write_bio_PrivateKey(bio_out, pkey, nullptr, nullptr, 0, 0, nullptr)) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); vcerts.asArrRef().set(s_pkey, String((char*)bio_buf->data, bio_buf->length, CopyString)); } BIO_free(bio_out); } if (ca) { Array extracerts; for (X509 *aCA = sk_X509_pop(ca); aCA; aCA = sk_X509_pop(ca)) { bio_out = BIO_new(BIO_s_mem()); if (PEM_write_bio_X509(bio_out, aCA)) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); extracerts.append(String((char*)bio_buf->data, bio_buf->length, CopyString)); } BIO_free(bio_out); X509_free(aCA); } sk_X509_free(ca); vcerts.asArrRef().set(s_extracerts, extracerts); } ret = true; PKCS12_free(p12); } } cleanup: if (bio_in) { BIO_free(bio_in); } return ret; } bool HHVM_FUNCTION(openssl_pkcs7_decrypt, const String& infilename, const String& outfilename, const Variant& recipcert, const Variant& recipkey /* = uninit_variant */) { bool ret = false; BIO *in = nullptr, *out = nullptr, *datain = nullptr; PKCS7 *p7 = nullptr; req::ptr<Key> okey; auto ocert = Certificate::Get(recipcert); if (!ocert) { raise_warning("unable to coerce parameter 3 to x509 cert"); goto clean_exit; } okey = Key::Get(recipkey.isNull() ? recipcert : recipkey, false); if (!okey) { raise_warning("unable to get private key"); goto clean_exit; } in = BIO_new_file(infilename.data(), "r"); if (in == nullptr) { raise_warning("error opening the file, %s", infilename.data()); goto clean_exit; } out = BIO_new_file(outfilename.data(), "w"); if (out == nullptr) { raise_warning("error opening the file, %s", outfilename.data()); goto clean_exit; } p7 = SMIME_read_PKCS7(in, &datain); if (p7 == nullptr) { goto clean_exit; } assertx(okey->m_key); assertx(ocert->m_cert); if (PKCS7_decrypt(p7, okey->m_key, ocert->m_cert, out, PKCS7_DETACHED)) { ret = true; } clean_exit: PKCS7_free(p7); BIO_free(datain); BIO_free(in); BIO_free(out); return ret; } static void print_headers(BIO *outfile, const Array& headers) { if (!headers.isNull()) { if (headers->isVectorData()) { for (ArrayIter iter(headers); iter; ++iter) { BIO_printf(outfile, "%s\n", iter.second().toString().data()); } } else { for (ArrayIter iter(headers); iter; ++iter) { BIO_printf(outfile, "%s: %s\n", iter.first().toString().data(), iter.second().toString().data()); } } } } bool HHVM_FUNCTION(openssl_pkcs7_encrypt, const String& infilename, const String& outfilename, const Variant& recipcerts, const Array& headers, int flags /* = 0 */, int cipherid /* = k_OPENSSL_CIPHER_RC2_40 */) { bool ret = false; BIO *infile = nullptr, *outfile = nullptr; STACK_OF(X509) *precipcerts = nullptr; PKCS7 *p7 = nullptr; const EVP_CIPHER *cipher = nullptr; infile = BIO_new_file(infilename.data(), (flags & PKCS7_BINARY) ? "rb" : "r"); if (infile == nullptr) { raise_warning("error opening the file, %s", infilename.data()); goto clean_exit; } outfile = BIO_new_file(outfilename.data(), "w"); if (outfile == nullptr) { raise_warning("error opening the file, %s", outfilename.data()); goto clean_exit; } precipcerts = php_array_to_X509_sk(recipcerts); /* sanity check the cipher */ switch (cipherid) { #ifndef OPENSSL_NO_RC2 case PHP_OPENSSL_CIPHER_RC2_40: cipher = EVP_rc2_40_cbc(); break; case PHP_OPENSSL_CIPHER_RC2_64: cipher = EVP_rc2_64_cbc(); break; case PHP_OPENSSL_CIPHER_RC2_128: cipher = EVP_rc2_cbc(); break; #endif #ifndef OPENSSL_NO_DES case PHP_OPENSSL_CIPHER_DES: cipher = EVP_des_cbc(); break; case PHP_OPENSSL_CIPHER_3DES: cipher = EVP_des_ede3_cbc(); break; #endif default: raise_warning("Invalid cipher type `%d'", cipherid); goto clean_exit; } if (cipher == nullptr) { raise_warning("Failed to get cipher"); goto clean_exit; } p7 = PKCS7_encrypt(precipcerts, infile, (EVP_CIPHER*)cipher, flags); if (p7 == nullptr) goto clean_exit; print_headers(outfile, headers); (void)BIO_reset(infile); SMIME_write_PKCS7(outfile, p7, infile, flags); ret = true; clean_exit: PKCS7_free(p7); BIO_free(infile); BIO_free(outfile); sk_X509_free(precipcerts); return ret; } bool HHVM_FUNCTION(openssl_pkcs7_sign, const String& infilename, const String& outfilename, const Variant& signcert, const Variant& privkey, const Variant& headers, int flags /* = k_PKCS7_DETACHED */, const String& extracerts /* = null_string */) { bool ret = false; STACK_OF(X509) *others = nullptr; BIO *infile = nullptr, *outfile = nullptr; PKCS7 *p7 = nullptr; req::ptr<Key> okey; req::ptr<Certificate> ocert; if (!extracerts.empty()) { others = load_all_certs_from_file(extracerts.data()); if (others == nullptr) { goto clean_exit; } } okey = Key::Get(privkey, false); if (!okey) { raise_warning("error getting private key"); goto clean_exit; } EVP_PKEY *key; key = okey->m_key; ocert = Certificate::Get(signcert); if (!ocert) { raise_warning("error getting cert"); goto clean_exit; } X509 *cert; cert = ocert->m_cert; infile = BIO_new_file(infilename.data(), (flags & PKCS7_BINARY) ? "rb" : "r"); if (infile == nullptr) { raise_warning("error opening input file %s!", infilename.data()); goto clean_exit; } outfile = BIO_new_file(outfilename.data(), "w"); if (outfile == nullptr) { raise_warning("error opening output file %s!", outfilename.data()); goto clean_exit; } p7 = PKCS7_sign(cert, key, others, infile, flags); if (p7 == nullptr) { raise_warning("error creating PKCS7 structure!"); goto clean_exit; } print_headers(outfile, headers.toArray()); (void)BIO_reset(infile); SMIME_write_PKCS7(outfile, p7, infile, flags); ret = true; clean_exit: PKCS7_free(p7); BIO_free(infile); BIO_free(outfile); if (others) { sk_X509_pop_free(others, X509_free); } return ret; } static int pkcs7_ignore_expiration(int ok, X509_STORE_CTX *ctx) { if (ok) { return ok; } int error = X509_STORE_CTX_get_error(ctx); if (error == X509_V_ERR_CERT_HAS_EXPIRED) { // ignore cert expirations Logger::Verbose("Ignoring cert expiration"); return 1; } return ok; } /** * NOTE: when ignore_cert_expiration is true, a custom certificate validation * callback is set up. Please be aware of this if you modify the function to * allow other certificate validation behaviors */ Variant openssl_pkcs7_verify_core( const String& filename, int flags, const Variant& voutfilename /* = null_string */, const Variant& vcainfo /* = null_array */, const Variant& vextracerts /* = null_string */, const Variant& vcontent /* = null_string */, bool ignore_cert_expiration ) { Variant ret = -1; X509_STORE *store = nullptr; BIO *in = nullptr; PKCS7 *p7 = nullptr; BIO *datain = nullptr; BIO *dataout = nullptr; auto cainfo = vcainfo.toArray(); auto extracerts = vextracerts.toString(); auto content = vcontent.toString(); STACK_OF(X509) *others = nullptr; if (!extracerts.empty()) { others = load_all_certs_from_file(extracerts.data()); if (others == nullptr) { goto clean_exit; } } flags = flags & ~PKCS7_DETACHED; store = setup_verify(cainfo); if (!store) { goto clean_exit; } if (ignore_cert_expiration) { #if (OPENSSL_VERSION_NUMBER >= 0x10000000) // make sure no other callback is specified #if OPENSSL_VERSION_NUMBER >= 0x10100000L assertx(!X509_STORE_get_verify_cb(store)); #else assertx(!store->verify_cb); #endif // ignore expired certs X509_STORE_set_verify_cb(store, pkcs7_ignore_expiration); #else always_assert(false); #endif } in = BIO_new_file(filename.data(), (flags & PKCS7_BINARY) ? "rb" : "r"); if (in == nullptr) { raise_warning("error opening the file, %s", filename.data()); goto clean_exit; } p7 = SMIME_read_PKCS7(in, &datain); if (p7 == nullptr) { goto clean_exit; } if (!content.empty()) { dataout = BIO_new_file(content.data(), "w"); if (dataout == nullptr) { raise_warning("error opening the file, %s", content.data()); goto clean_exit; } } if (PKCS7_verify(p7, others, store, datain, dataout, flags)) { ret = true; auto outfilename = voutfilename.toString(); if (!outfilename.empty()) { BIO *certout = BIO_new_file(outfilename.data(), "w"); if (certout) { STACK_OF(X509) *signers = PKCS7_get0_signers(p7, nullptr, flags); for (int i = 0; i < sk_X509_num(signers); i++) { PEM_write_bio_X509(certout, sk_X509_value(signers, i)); } BIO_free(certout); sk_X509_free(signers); } else { raise_warning("signature OK, but cannot open %s for writing", outfilename.data()); ret = -1; } } goto clean_exit; } else { ret = false; } clean_exit: X509_STORE_free(store); BIO_free(datain); BIO_free(in); BIO_free(dataout); PKCS7_free(p7); sk_X509_pop_free(others, X509_free); return ret; } Variant HHVM_FUNCTION(openssl_pkcs7_verify, const String& filename, int flags, const Variant& voutfilename /* = null_string */, const Variant& vcainfo /* = null_array */, const Variant& vextracerts /* = null_string */, const Variant& vcontent /* = null_string */) { return openssl_pkcs7_verify_core(filename, flags, voutfilename, vcainfo, vextracerts, vcontent, false); } static bool openssl_pkey_export_impl(const Variant& key, BIO *bio_out, const String& passphrase /* = null_string */, const Variant& configargs /* = uninit_variant */) { auto okey = Key::Get(key, false, passphrase.data()); if (!okey) { raise_warning("cannot get key from parameter 1"); return false; } EVP_PKEY *pkey = okey->m_key; struct php_x509_request req; memset(&req, 0, sizeof(req)); std::vector<String> strings; bool ret = false; if (php_openssl_parse_config(&req, configargs.toArray(), strings)) { const EVP_CIPHER *cipher; if (!passphrase.empty() && req.priv_key_encrypt) { cipher = (EVP_CIPHER *)EVP_des_ede3_cbc(); } else { cipher = nullptr; } assertx(bio_out); switch (EVP_PKEY_id(pkey)) { #ifdef HAVE_EVP_PKEY_EC case EVP_PKEY_EC: ret = PEM_write_bio_ECPrivateKey(bio_out, EVP_PKEY_get0_EC_KEY(pkey), cipher, (unsigned char *)passphrase.data(), passphrase.size(), nullptr, nullptr); break; #endif default: ret = PEM_write_bio_PrivateKey(bio_out, pkey, cipher, (unsigned char *)passphrase.data(), passphrase.size(), nullptr, nullptr); break; } } php_openssl_dispose_config(&req); return ret; } bool HHVM_FUNCTION(openssl_pkey_export_to_file, const Variant& key, const String& outfilename, const String& passphrase /* = null_string */, const Variant& configargs /* = uninit_variant */) { BIO *bio_out = BIO_new_file(outfilename.data(), "w"); if (bio_out == nullptr) { raise_warning("error opening the file, %s", outfilename.data()); return false; } bool ret = openssl_pkey_export_impl(key, bio_out, passphrase, configargs); BIO_free(bio_out); return ret; } bool HHVM_FUNCTION(openssl_pkey_export, const Variant& key, Variant& out, const String& passphrase /* = null_string */, const Variant& configargs /* = uninit_variant */) { BIO *bio_out = BIO_new(BIO_s_mem()); bool ret = openssl_pkey_export_impl(key, bio_out, passphrase, configargs); if (ret) { char *bio_mem_ptr; long bio_mem_len = BIO_get_mem_data(bio_out, &bio_mem_ptr); out = String(bio_mem_ptr, bio_mem_len, CopyString); } BIO_free(bio_out); return ret; } const StaticString s_bits("bits"), s_key("key"), s_type("type"), s_name("name"), s_hash("hash"), s_version("version"), s_serialNumber("serialNumber"), s_signatureAlgorithm("signatureAlgorithm"), s_validFrom("validFrom"), s_validTo("validTo"), s_validFrom_time_t("validFrom_time_t"), s_validTo_time_t("validTo_time_t"), s_alias("alias"), s_purposes("purposes"), s_extensions("extensions"), s_rsa("rsa"), s_dsa("dsa"), s_dh("dh"), s_ec("ec"), s_n("n"), s_e("e"), s_d("d"), s_p("p"), s_q("q"), s_g("g"), s_x("x"), s_y("y"), s_dmp1("dmp1"), s_dmq1("dmq1"), s_iqmp("iqmp"), s_priv_key("priv_key"), s_pub_key("pub_key"), s_curve_oid("curve_oid"); static void add_bignum_as_string(Array &arr, StaticString key, const BIGNUM *bn) { if (!bn) { return; } int num_bytes = BN_num_bytes(bn); String str{size_t(num_bytes), ReserveString}; BN_bn2bin(bn, (unsigned char*)str.mutableData()); str.setSize(num_bytes); arr.set(key, std::move(str)); } Array HHVM_FUNCTION(openssl_pkey_get_details, const Resource& key) { EVP_PKEY *pkey = cast<Key>(key)->m_key; BIO *out = BIO_new(BIO_s_mem()); PEM_write_bio_PUBKEY(out, pkey); char *pbio; unsigned int pbio_len = BIO_get_mem_data(out, &pbio); auto ret = make_darray( s_bits, EVP_PKEY_bits(pkey), s_key, String(pbio, pbio_len, CopyString) ); long ktype = -1; auto details = Array::CreateDArray(); switch (EVP_PKEY_id(pkey)) { case EVP_PKEY_RSA: case EVP_PKEY_RSA2: { ktype = OPENSSL_KEYTYPE_RSA; RSA *rsa = EVP_PKEY_get0_RSA(pkey); assertx(rsa); const BIGNUM *n, *e, *d, *p, *q, *dmp1, *dmq1, *iqmp; RSA_get0_key(rsa, &n, &e, &d); RSA_get0_factors(rsa, &p, &q); RSA_get0_crt_params(rsa, &dmp1, &dmq1, &iqmp); add_bignum_as_string(details, s_n, n); add_bignum_as_string(details, s_e, e); add_bignum_as_string(details, s_d, d); add_bignum_as_string(details, s_p, p); add_bignum_as_string(details, s_q, q); add_bignum_as_string(details, s_dmp1, dmp1); add_bignum_as_string(details, s_dmq1, dmq1); add_bignum_as_string(details, s_iqmp, iqmp); ret.set(s_rsa, details); break; } case EVP_PKEY_DSA: case EVP_PKEY_DSA2: case EVP_PKEY_DSA3: case EVP_PKEY_DSA4: { ktype = OPENSSL_KEYTYPE_DSA; DSA *dsa = EVP_PKEY_get0_DSA(pkey); assertx(dsa); const BIGNUM *p, *q, *g, *pub_key, *priv_key; DSA_get0_pqg(dsa, &p, &q, &g); DSA_get0_key(dsa, &pub_key, &priv_key); add_bignum_as_string(details, s_p, p); add_bignum_as_string(details, s_q, q); add_bignum_as_string(details, s_g, g); add_bignum_as_string(details, s_priv_key, priv_key); add_bignum_as_string(details, s_pub_key, pub_key); ret.set(s_dsa, details); break; } case EVP_PKEY_DH: { ktype = OPENSSL_KEYTYPE_DH; DH *dh = EVP_PKEY_get0_DH(pkey); assertx(dh); const BIGNUM *p, *q, *g, *pub_key, *priv_key; DH_get0_pqg(dh, &p, &q, &g); DH_get0_key(dh, &pub_key, &priv_key); add_bignum_as_string(details, s_p, p); add_bignum_as_string(details, s_g, g); add_bignum_as_string(details, s_priv_key, priv_key); add_bignum_as_string(details, s_pub_key, pub_key); ret.set(s_dh, details); break; } #ifdef HAVE_EVP_PKEY_EC case EVP_PKEY_EC: { ktype = OPENSSL_KEYTYPE_EC; auto const ec = EVP_PKEY_get0_EC_KEY(pkey); assertx(ec); auto const ec_group = EC_KEY_get0_group(ec); auto const nid = EC_GROUP_get_curve_name(ec_group); if (nid == NID_undef) { break; } auto const crv_sn = OBJ_nid2sn(nid); if (crv_sn != nullptr) { details.set(s_curve_name, String(crv_sn, CopyString)); } auto const obj = OBJ_nid2obj(nid); if (obj != nullptr) { SCOPE_EXIT { ASN1_OBJECT_free(obj); }; char oir_buf[256]; OBJ_obj2txt(oir_buf, sizeof(oir_buf) - 1, obj, 1); details.set(s_curve_oid, String(oir_buf, CopyString)); } auto x = BN_new(); auto y = BN_new(); SCOPE_EXIT { BN_free(x); BN_free(y); }; auto const pub = EC_KEY_get0_public_key(ec); if (EC_POINT_get_affine_coordinates_GFp(ec_group, pub, x, y, nullptr)) { add_bignum_as_string(details, s_x, x); add_bignum_as_string(details, s_y, y); } auto d = BN_dup(EC_KEY_get0_private_key(ec)); SCOPE_EXIT { BN_free(d); }; if (d != nullptr) { add_bignum_as_string(details, s_d, d); } ret.set(s_ec, details); } break; #endif } ret.set(s_type, ktype); BIO_free(out); return ret; } Variant HHVM_FUNCTION(openssl_pkey_get_private, const Variant& key, const String& passphrase /* = null_string */) { return toVariant(Key::Get(key, false, passphrase.data())); } Variant HHVM_FUNCTION(openssl_pkey_get_public, const Variant& certificate) { return toVariant(Key::Get(certificate, true)); } Variant HHVM_FUNCTION(openssl_pkey_new, const Variant& configargs /* = uninit_variant */) { struct php_x509_request req; memset(&req, 0, sizeof(req)); SCOPE_EXIT { php_openssl_dispose_config(&req); }; std::vector<String> strings; if (php_openssl_parse_config(&req, configargs.toArray(), strings) && req.generatePrivateKey()) { return Resource(req::make<Key>(req.priv_key)); } else { return false; } } bool HHVM_FUNCTION(openssl_private_decrypt, const String& data, Variant& decrypted, const Variant& key, int padding /* = k_OPENSSL_PKCS1_PADDING */) { auto okey = Key::Get(key, false); if (!okey) { raise_warning("key parameter is not a valid private key"); return false; } EVP_PKEY *pkey = okey->m_key; int cryptedlen = EVP_PKEY_size(pkey); String s = String(cryptedlen, ReserveString); unsigned char *cryptedbuf = (unsigned char *)s.mutableData(); int successful = 0; switch (EVP_PKEY_id(pkey)) { case EVP_PKEY_RSA: case EVP_PKEY_RSA2: cryptedlen = RSA_private_decrypt(data.size(), (unsigned char *)data.data(), cryptedbuf, EVP_PKEY_get0_RSA(pkey), padding); if (cryptedlen != -1) { successful = 1; } break; default: raise_warning("key type not supported"); } if (successful) { decrypted = s.setSize(cryptedlen); return true; } return false; } bool HHVM_FUNCTION(openssl_private_encrypt, const String& data, Variant& crypted, const Variant& key, int padding /* = k_OPENSSL_PKCS1_PADDING */) { auto okey = Key::Get(key, false); if (!okey) { raise_warning("key param is not a valid private key"); return false; } EVP_PKEY *pkey = okey->m_key; int cryptedlen = EVP_PKEY_size(pkey); String s = String(cryptedlen, ReserveString); unsigned char *cryptedbuf = (unsigned char *)s.mutableData(); int successful = 0; switch (EVP_PKEY_id(pkey)) { case EVP_PKEY_RSA: case EVP_PKEY_RSA2: successful = (RSA_private_encrypt(data.size(), (unsigned char *)data.data(), cryptedbuf, EVP_PKEY_get0_RSA(pkey), padding) == cryptedlen); break; default: raise_warning("key type not supported"); } if (successful) { crypted = s.setSize(cryptedlen); return true; } return false; } bool HHVM_FUNCTION(openssl_public_decrypt, const String& data, Variant& decrypted, const Variant& key, int padding /* = k_OPENSSL_PKCS1_PADDING */) { auto okey = Key::Get(key, true); if (!okey) { raise_warning("key parameter is not a valid public key"); return false; } EVP_PKEY *pkey = okey->m_key; int cryptedlen = EVP_PKEY_size(pkey); String s = String(cryptedlen, ReserveString); unsigned char *cryptedbuf = (unsigned char *)s.mutableData(); int successful = 0; switch (EVP_PKEY_id(pkey)) { case EVP_PKEY_RSA: case EVP_PKEY_RSA2: cryptedlen = RSA_public_decrypt(data.size(), (unsigned char *)data.data(), cryptedbuf, EVP_PKEY_get0_RSA(pkey), padding); if (cryptedlen != -1) { successful = 1; } break; default: raise_warning("key type not supported"); } if (successful) { decrypted = s.setSize(cryptedlen); return true; } return false; } bool HHVM_FUNCTION(openssl_public_encrypt, const String& data, Variant& crypted, const Variant& key, int padding /* = k_OPENSSL_PKCS1_PADDING */) { auto okey = Key::Get(key, true); if (!okey) { raise_warning("key parameter is not a valid public key"); return false; } EVP_PKEY *pkey = okey->m_key; int cryptedlen = EVP_PKEY_size(pkey); String s = String(cryptedlen, ReserveString); unsigned char *cryptedbuf = (unsigned char *)s.mutableData(); int successful = 0; switch (EVP_PKEY_id(pkey)) { case EVP_PKEY_RSA: case EVP_PKEY_RSA2: successful = (RSA_public_encrypt(data.size(), (unsigned char *)data.data(), cryptedbuf, EVP_PKEY_get0_RSA(pkey), padding) == cryptedlen); break; default: raise_warning("key type not supported"); } if (successful) { crypted = s.setSize(cryptedlen); return true; } return false; } Variant HHVM_FUNCTION(openssl_seal, const String& data, Variant& sealed_data, Variant& env_keys, const Array& pub_key_ids, const String& method, Variant& iv) { int nkeys = pub_key_ids.size(); if (nkeys == 0) { raise_warning("Fourth argument to openssl_seal() must be " "a non-empty array"); return false; } const EVP_CIPHER *cipher_type; if (method.empty()) { cipher_type = EVP_rc4(); } else { cipher_type = EVP_get_cipherbyname(method.c_str()); if (!cipher_type) { raise_warning("Unknown cipher algorithm"); return false; } } int iv_len = EVP_CIPHER_iv_length(cipher_type); unsigned char *iv_buf = nullptr; String iv_s; if (iv_len > 0) { iv_s = String(iv_len, ReserveString); iv_buf = (unsigned char*)iv_s.mutableData(); if (!RAND_bytes(iv_buf, iv_len)) { raise_warning("Could not generate an IV."); return false; } } EVP_PKEY **pkeys = (EVP_PKEY**)malloc(nkeys * sizeof(*pkeys)); int *eksl = (int*)malloc(nkeys * sizeof(*eksl)); unsigned char **eks = (unsigned char **)malloc(nkeys * sizeof(*eks)); memset(eks, 0, sizeof(*eks) * nkeys); // holder is needed to make sure none of the Keys get deleted prematurely. // The pkeys array points to elements inside of Keys returned from Key::Get() // which may be newly allocated and have no other owners. std::vector<req::ptr<Key>> holder; /* get the public keys we are using to seal this data */ bool ret = true; int i = 0; String s; unsigned char* buf = nullptr; EVP_CIPHER_CTX* ctx = nullptr; for (ArrayIter iter(pub_key_ids); iter; ++iter, ++i) { auto okey = Key::Get(iter.second(), true); if (!okey) { raise_warning("not a public key (%dth member of pubkeys)", i + 1); ret = false; goto clean_exit; } holder.push_back(okey); pkeys[i] = okey->m_key; eks[i] = (unsigned char *)malloc(EVP_PKEY_size(pkeys[i]) + 1); } ctx = EVP_CIPHER_CTX_new(); if (ctx == nullptr) { raise_warning("Failed to allocate an EVP_CIPHER_CTX object"); ret = false; goto clean_exit; } if (!EVP_EncryptInit_ex(ctx, cipher_type, nullptr, nullptr, nullptr)) { ret = false; goto clean_exit; } int len1, len2; s = String(data.size() + EVP_CIPHER_CTX_block_size(ctx), ReserveString); buf = (unsigned char *)s.mutableData(); if (EVP_SealInit(ctx, cipher_type, eks, eksl, iv_buf, pkeys, nkeys) <= 0 || !EVP_SealUpdate(ctx, buf, &len1, (unsigned char*)data.data(), data.size()) || !EVP_SealFinal(ctx, buf + len1, &len2)) { ret = false; goto clean_exit; } if (len1 + len2 > 0) { sealed_data = s.setSize(len1 + len2); auto ekeys = Array::CreateVArray(); for (i = 0; i < nkeys; i++) { eks[i][eksl[i]] = '\0'; ekeys.append(String((char*)eks[i], eksl[i], AttachString)); eks[i] = nullptr; } env_keys = ekeys; } clean_exit: for (i = 0; i < nkeys; i++) { if (eks[i]) free(eks[i]); } free(eks); free(eksl); free(pkeys); if (iv_buf != nullptr) { if (ret) { iv = iv_s.setSize(iv_len); } } if (ctx != nullptr) { EVP_CIPHER_CTX_free(ctx); } if (ret) return len1 + len2; return false; } static const EVP_MD *php_openssl_get_evp_md_from_algo(long algo) { switch (algo) { case OPENSSL_ALGO_SHA1: return EVP_sha1(); case OPENSSL_ALGO_MD5: return EVP_md5(); case OPENSSL_ALGO_MD4: return EVP_md4(); #ifdef HAVE_OPENSSL_MD2_H case OPENSSL_ALGO_MD2: return EVP_md2(); #endif #if OPENSSL_VERSION_NUMBER < 0x10100000L case OPENSSL_ALGO_DSS1: return EVP_dss1(); #endif #if OPENSSL_VERSION_NUMBER >= 0x0090708fL case OPENSSL_ALGO_SHA224: return EVP_sha224(); case OPENSSL_ALGO_SHA256: return EVP_sha256(); case OPENSSL_ALGO_SHA384: return EVP_sha384(); case OPENSSL_ALGO_SHA512: return EVP_sha512(); case OPENSSL_ALGO_RMD160: return EVP_ripemd160(); #endif } return nullptr; } bool HHVM_FUNCTION(openssl_sign, const String& data, Variant& signature, const Variant& priv_key_id, const Variant& signature_alg /* = k_OPENSSL_ALGO_SHA1 */) { auto okey = Key::Get(priv_key_id, false); if (!okey) { raise_warning("supplied key param cannot be coerced into a private key"); return false; } const EVP_MD *mdtype = nullptr; if (signature_alg.isInteger()) { mdtype = php_openssl_get_evp_md_from_algo(signature_alg.toInt64Val()); } else if (signature_alg.isString()) { mdtype = EVP_get_digestbyname(signature_alg.toString().data()); } if (!mdtype) { raise_warning("Unknown signature algorithm."); return false; } EVP_PKEY *pkey = okey->m_key; int siglen = EVP_PKEY_size(pkey); String s = String(siglen, ReserveString); unsigned char *sigbuf = (unsigned char *)s.mutableData(); EVP_MD_CTX *md_ctx = EVP_MD_CTX_new(); SCOPE_EXIT { EVP_MD_CTX_free(md_ctx); }; EVP_SignInit(md_ctx, mdtype); EVP_SignUpdate(md_ctx, (unsigned char *)data.data(), data.size()); if (EVP_SignFinal(md_ctx, sigbuf, (unsigned int *)&siglen, pkey)) { signature = s.setSize(siglen); return true; } return false; } Variant HHVM_FUNCTION(openssl_verify, const String& data, const String& signature, const Variant& pub_key_id, const Variant& signature_alg /* = k_OPENSSL_ALGO_SHA1 */) { int err; const EVP_MD *mdtype = nullptr; if (signature_alg.isInteger()) { mdtype = php_openssl_get_evp_md_from_algo(signature_alg.toInt64Val()); } else if (signature_alg.isString()) { mdtype = EVP_get_digestbyname(signature_alg.toString().data()); } if (!mdtype) { raise_warning("Unknown signature algorithm."); return false; } auto okey = Key::Get(pub_key_id, true); if (!okey) { raise_warning("supplied key param cannot be coerced into a public key"); return false; } EVP_MD_CTX *md_ctx = EVP_MD_CTX_new(); SCOPE_EXIT { EVP_MD_CTX_free(md_ctx); }; EVP_VerifyInit(md_ctx, mdtype); EVP_VerifyUpdate(md_ctx, (unsigned char*)data.data(), data.size()); err = EVP_VerifyFinal(md_ctx, (unsigned char *)signature.data(), signature.size(), okey->m_key); return err; } bool HHVM_FUNCTION(openssl_x509_check_private_key, const Variant& cert, const Variant& key) { auto ocert = Certificate::Get(cert); if (!ocert) { return false; } auto okey = Key::Get(key, false); if (!okey) { return false; } return X509_check_private_key(ocert->m_cert, okey->m_key); } static int check_cert(X509_STORE *ctx, X509 *x, STACK_OF(X509) *untrustedchain, int purpose) { X509_STORE_CTX *csc = X509_STORE_CTX_new(); if (csc == nullptr) { raise_warning("memory allocation failure"); return 0; } X509_STORE_CTX_init(csc, ctx, x, untrustedchain); if (purpose >= 0) { X509_STORE_CTX_set_purpose(csc, purpose); } int ret = X509_verify_cert(csc); X509_STORE_CTX_free(csc); return ret; } Variant HHVM_FUNCTION(openssl_x509_checkpurpose, const Variant& x509cert, int purpose, const Array& cainfo /* = null_array */, const String& untrustedfile /* = null_string */) { int ret = -1; STACK_OF(X509) *untrustedchain = nullptr; X509_STORE *pcainfo = nullptr; req::ptr<Certificate> ocert; if (!untrustedfile.empty()) { untrustedchain = load_all_certs_from_file(untrustedfile.data()); if (untrustedchain == nullptr) { goto clean_exit; } } pcainfo = setup_verify(cainfo); if (pcainfo == nullptr) { goto clean_exit; } ocert = Certificate::Get(x509cert); if (!ocert) { raise_warning("cannot get cert from parameter 1"); return false; } X509 *cert; cert = ocert->m_cert; assertx(cert); ret = check_cert(pcainfo, cert, untrustedchain, purpose); clean_exit: if (pcainfo) { X509_STORE_free(pcainfo); } if (untrustedchain) { sk_X509_pop_free(untrustedchain, X509_free); } return ret == 1 ? true : ret == 0 ? false : -1; } static bool openssl_x509_export_impl(const Variant& x509, BIO *bio_out, bool notext /* = true */) { auto ocert = Certificate::Get(x509); if (!ocert) { raise_warning("cannot get cert from parameter 1"); return false; } X509 *cert = ocert->m_cert; assertx(cert); assertx(bio_out); if (!notext) { X509_print(bio_out, cert); } return PEM_write_bio_X509(bio_out, cert); } bool HHVM_FUNCTION(openssl_x509_export_to_file, const Variant& x509, const String& outfilename, bool notext /* = true */) { BIO *bio_out = BIO_new_file((char*)outfilename.data(), "w"); if (bio_out == nullptr) { raise_warning("error opening file %s", outfilename.data()); return false; } bool ret = openssl_x509_export_impl(x509, bio_out, notext); BIO_free(bio_out); return ret; } bool HHVM_FUNCTION(openssl_x509_export, const Variant& x509, Variant& output, bool notext /* = true */) { BIO *bio_out = BIO_new(BIO_s_mem()); bool ret = openssl_x509_export_impl(x509, bio_out, notext); if (ret) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); output = String(bio_buf->data, bio_buf->length, CopyString); } BIO_free(bio_out); return ret; } /** * This is how the time string is formatted: * * snprintf(p, sizeof(p), "%02d%02d%02d%02d%02d%02dZ",ts->tm_year%100, * ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); */ static time_t asn1_time_to_time_t(ASN1_UTCTIME *timestr) { auto const timestr_type = ASN1_STRING_type(timestr); if (timestr_type != V_ASN1_UTCTIME && timestr_type != V_ASN1_GENERALIZEDTIME) { raise_warning("illegal ASN1 data type for timestamp"); return (time_t)-1; } auto const timestr_len = (size_t)ASN1_STRING_length(timestr); // Binary safety if (timestr_len != strlen((char*)ASN1_STRING_data(timestr))) { raise_warning("illegal length in timestamp"); return (time_t)-1; } if (timestr_len < 13 && timestr_len != 11) { raise_warning("unable to parse time string %s correctly", timestr->data); return (time_t)-1; } if (timestr_type == V_ASN1_GENERALIZEDTIME && timestr_len < 15) { raise_warning("unable to parse time string %s correctly", timestr->data); return (time_t)-1; } char *strbuf = strdup((char*)timestr->data); struct tm thetime; memset(&thetime, 0, sizeof(thetime)); /* we work backwards so that we can use atoi more easily */ char *thestr = strbuf + ASN1_STRING_length(timestr) - 3; if (ASN1_STRING_length(timestr) == 11) { thetime.tm_sec = 0; } else { thetime.tm_sec = atoi(thestr); *thestr = '\0'; thestr -= 2; } thetime.tm_min = atoi(thestr); *thestr = '\0'; thestr -= 2; thetime.tm_hour = atoi(thestr); *thestr = '\0'; thestr -= 2; thetime.tm_mday = atoi(thestr); *thestr = '\0'; thestr -= 2; thetime.tm_mon = atoi(thestr)-1; *thestr = '\0'; if (ASN1_STRING_type(timestr) == V_ASN1_UTCTIME) { thestr -= 2; thetime.tm_year = atoi(thestr); if (thetime.tm_year < 68) { thetime.tm_year += 100; } } else if (ASN1_STRING_type(timestr) == V_ASN1_GENERALIZEDTIME) { thestr -= 4; thetime.tm_year = atoi(thestr) - 1900; } thetime.tm_isdst = -1; time_t ret = mktime(&thetime); long gmadjust = 0; #if HAVE_TM_GMTOFF gmadjust = thetime.tm_gmtoff; #elif defined(_MSC_VER) TIME_ZONE_INFORMATION inf; GetTimeZoneInformation(&inf); gmadjust = thetime.tm_isdst ? inf.DaylightBias : inf.StandardBias; #else /** * If correcting for daylight savings time, we set the adjustment to * the value of timezone - 3600 seconds. Otherwise, we need to overcorrect * and set the adjustment to the main timezone + 3600 seconds. */ gmadjust = -(thetime.tm_isdst ? (long)timezone - 3600 : (long)timezone); #endif /* no adjustment for UTC */ if (timezone) ret += gmadjust; free(strbuf); return ret; } /* Special handling of subjectAltName, see CVE-2013-4073 * Christian Heimes */ static int openssl_x509v3_subjectAltName(BIO *bio, X509_EXTENSION *extension) { GENERAL_NAMES *names; const X509V3_EXT_METHOD *method = nullptr; long i, length, num; const unsigned char *p; method = X509V3_EXT_get(extension); if (method == nullptr) { return -1; } const auto data = X509_EXTENSION_get_data(extension); p = data->data; length = data->length; if (method->it) { names = (GENERAL_NAMES*)(ASN1_item_d2i(nullptr, &p, length, ASN1_ITEM_ptr(method->it))); } else { names = (GENERAL_NAMES*)(method->d2i(nullptr, &p, length)); } if (names == nullptr) { return -1; } num = sk_GENERAL_NAME_num(names); for (i = 0; i < num; i++) { GENERAL_NAME *name; ASN1_STRING *as; name = sk_GENERAL_NAME_value(names, i); switch (name->type) { case GEN_EMAIL: BIO_puts(bio, "email:"); as = name->d.rfc822Name; BIO_write(bio, ASN1_STRING_data(as), ASN1_STRING_length(as)); break; case GEN_DNS: BIO_puts(bio, "DNS:"); as = name->d.dNSName; BIO_write(bio, ASN1_STRING_data(as), ASN1_STRING_length(as)); break; case GEN_URI: BIO_puts(bio, "URI:"); as = name->d.uniformResourceIdentifier; BIO_write(bio, ASN1_STRING_data(as), ASN1_STRING_length(as)); break; default: /* use builtin print for GEN_OTHERNAME, GEN_X400, * GEN_EDIPARTY, GEN_DIRNAME, GEN_IPADD and GEN_RID */ GENERAL_NAME_print(bio, name); } /* trailing ', ' except for last element */ if (i < (num - 1)) { BIO_puts(bio, ", "); } } sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free); return 0; } Variant HHVM_FUNCTION(openssl_x509_parse, const Variant& x509cert, bool shortnames /* = true */) { auto ocert = Certificate::Get(x509cert); if (!ocert) { return false; } X509 *cert = ocert->m_cert; assertx(cert); auto ret = Array::CreateDArray(); const auto sn = X509_get_subject_name(cert); if (sn) { ret.set(s_name, String(X509_NAME_oneline(sn, nullptr, 0), CopyString)); } add_assoc_name_entry(ret, "subject", sn, shortnames); /* hash as used in CA directories to lookup cert by subject name */ { char buf[32]; snprintf(buf, sizeof(buf), "%08lx", X509_subject_name_hash(cert)); ret.set(s_hash, String(buf, CopyString)); } add_assoc_name_entry(ret, "issuer", X509_get_issuer_name(cert), shortnames); ret.set(s_version, X509_get_version(cert)); ret.set(s_serialNumber, String (i2s_ASN1_INTEGER(nullptr, X509_get_serialNumber(cert)), AttachString)); // Adding Signature Algorithm BIO *bio_out = BIO_new(BIO_s_mem()); SCOPE_EXIT { BIO_free(bio_out); }; if (i2a_ASN1_OBJECT(bio_out, X509_get0_tbs_sigalg(cert)->algorithm) > 0) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); ret.set(s_signatureAlgorithm, String((char*)bio_buf->data, bio_buf->length, CopyString)); } ASN1_STRING *str = X509_get_notBefore(cert); ret.set(s_validFrom, String((char*)str->data, str->length, CopyString)); str = X509_get_notAfter(cert); ret.set(s_validTo, String((char*)str->data, str->length, CopyString)); ret.set(s_validFrom_time_t, asn1_time_to_time_t(X509_get_notBefore(cert))); ret.set(s_validTo_time_t, asn1_time_to_time_t(X509_get_notAfter(cert))); char *tmpstr = (char *)X509_alias_get0(cert, nullptr); if (tmpstr) { ret.set(s_alias, String(tmpstr, CopyString)); } /* NOTE: the purposes are added as integer keys - the keys match up to the X509_PURPOSE_SSL_XXX defines in x509v3.h */ { Array subitem; for (int i = 0; i < X509_PURPOSE_get_count(); i++) { X509_PURPOSE *purp = X509_PURPOSE_get0(i); int id = X509_PURPOSE_get_id(purp); char * pname = shortnames ? X509_PURPOSE_get0_sname(purp) : X509_PURPOSE_get0_name(purp); auto subsub = make_varray( (bool)X509_check_purpose(cert, id, 0), (bool)X509_check_purpose(cert, id, 1), String(pname, CopyString) ); subitem.set(id, std::move(subsub)); } ret.set(s_purposes, subitem); } { auto subitem = Array::CreateDArray(); for (int i = 0; i < X509_get_ext_count(cert); i++) { int nid; X509_EXTENSION *extension = X509_get_ext(cert, i); char *extname; char buf[256]; nid = OBJ_obj2nid(X509_EXTENSION_get_object(extension)); if (nid != NID_undef) { extname = (char*)OBJ_nid2sn(OBJ_obj2nid (X509_EXTENSION_get_object(extension))); } else { OBJ_obj2txt(buf, sizeof(buf)-1, X509_EXTENSION_get_object(extension), 1); extname = buf; } BIO *bio_out = BIO_new(BIO_s_mem()); if (nid == NID_subject_alt_name) { if (openssl_x509v3_subjectAltName(bio_out, extension) == 0) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); subitem.set(String(extname, CopyString), String((char*)bio_buf->data, bio_buf->length, CopyString)); } else { BIO_free(bio_out); return false; } } else if (X509V3_EXT_print(bio_out, extension, 0, 0)) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); subitem.set(String(extname, CopyString), String((char*)bio_buf->data, bio_buf->length, CopyString)); } else { str = X509_EXTENSION_get_data(extension); subitem.set(String(extname, CopyString), String((char*)str->data, str->length, CopyString)); } BIO_free(bio_out); } ret.set(s_extensions, subitem); } return ret; } Variant HHVM_FUNCTION(openssl_x509_read, const Variant& x509certdata) { auto ocert = Certificate::Get(x509certdata); if (!ocert) { raise_warning("supplied parameter cannot be coerced into " "an X509 certificate!"); return false; } return Variant(ocert); } Variant HHVM_FUNCTION(openssl_random_pseudo_bytes, int length, bool& crypto_strong) { if (length <= 0) { return false; } unsigned char *buffer = nullptr; String s = String(length, ReserveString); buffer = (unsigned char *)s.mutableData(); if (RAND_bytes(buffer, length) <= 0) { crypto_strong = false; return false; } else { crypto_strong = true; s.setSize(length); return s; } } Variant HHVM_FUNCTION(openssl_cipher_iv_length, const String& method) { if (method.empty()) { raise_warning("Unknown cipher algorithm"); return false; } const EVP_CIPHER *cipher_type = EVP_get_cipherbyname(method.c_str()); if (!cipher_type) { raise_warning("Unknown cipher algorithm"); return false; } return EVP_CIPHER_iv_length(cipher_type); } /* Cipher mode info */ struct php_openssl_cipher_mode { /* Whether this mode uses authenticated encryption. True, for example, with the GCM and CCM modes */ bool is_aead; /* Whether this mode is a 'single run aead', meaning that DecryptFinal doesn't get called. For example, CCM mode is a single run aead mode. */ bool is_single_run_aead; /* The OpenSSL flag to get the computed tag, if this mode is aead. */ int aead_get_tag_flag; /* The OpenSSL flag to set the computed tag, if this mode is aead. */ int aead_set_tag_flag; /* The OpenSSL flag to set the IV length, if this mode is aead */ int aead_ivlen_flag; }; // initialize a php_openssl_cipher_mode corresponding to an EVP_CIPHER. static php_openssl_cipher_mode php_openssl_load_cipher_mode( const EVP_CIPHER* cipher_type) { php_openssl_cipher_mode mode = {}; switch (EVP_CIPHER_mode(cipher_type)) { #ifdef EVP_CIPH_GCM_MODE case EVP_CIPH_GCM_MODE: mode.is_aead = true; mode.is_single_run_aead = false; mode.aead_get_tag_flag = EVP_CTRL_GCM_GET_TAG; mode.aead_set_tag_flag = EVP_CTRL_GCM_SET_TAG; mode.aead_ivlen_flag = EVP_CTRL_GCM_SET_IVLEN; break; #endif #ifdef EVP_CIPH_CCM_MODE case EVP_CIPH_CCM_MODE: mode.is_aead = true; mode.is_single_run_aead = true; mode.aead_get_tag_flag = EVP_CTRL_CCM_GET_TAG; mode.aead_set_tag_flag = EVP_CTRL_CCM_SET_TAG; mode.aead_ivlen_flag = EVP_CTRL_CCM_SET_IVLEN; break; #endif default: break; } return mode; } static bool php_openssl_validate_iv( String piv, int iv_required_len, String& out, EVP_CIPHER_CTX* cipher_ctx, const php_openssl_cipher_mode* mode) { if (cipher_ctx == nullptr || mode == nullptr) { return false; } /* Best case scenario, user behaved */ if (piv.size() == iv_required_len) { out = std::move(piv); return true; } if (mode->is_aead) { if (EVP_CIPHER_CTX_ctrl( cipher_ctx, mode->aead_ivlen_flag, piv.size(), nullptr) != 1) { raise_warning( "Setting of IV length for AEAD mode failed, the expected length is " "%d bytes", iv_required_len); return false; } out = std::move(piv); return true; } String s = String(iv_required_len, ReserveString); char* iv_new = s.mutableData(); memset(iv_new, 0, iv_required_len); if (piv.size() <= 0) { /* BC behavior */ s.setSize(iv_required_len); out = std::move(s); return true; } if (piv.size() < iv_required_len) { raise_warning("IV passed is only %d bytes long, cipher " "expects an IV of precisely %d bytes, padding with \\0", piv.size(), iv_required_len); memcpy(iv_new, piv.data(), piv.size()); s.setSize(iv_required_len); out = std::move(s); return true; } raise_warning("IV passed is %d bytes long which is longer than the %d " "expected by selected cipher, truncating", piv.size(), iv_required_len); memcpy(iv_new, piv.data(), iv_required_len); s.setSize(iv_required_len); out = std::move(s); return true; } namespace { Variant openssl_encrypt_impl(const String& data, const String& method, const String& password, int options, const String& iv, Variant* tag_out, const String& aad, int tag_length) { const EVP_CIPHER *cipher_type = EVP_get_cipherbyname(method.c_str()); if (!cipher_type) { raise_warning("Unknown cipher algorithm"); return false; } EVP_CIPHER_CTX* cipher_ctx = EVP_CIPHER_CTX_new(); if (!cipher_ctx) { raise_warning("Failed to create cipher context"); return false; } SCOPE_EXIT { EVP_CIPHER_CTX_free(cipher_ctx); }; php_openssl_cipher_mode mode = php_openssl_load_cipher_mode(cipher_type); if (mode.is_aead && !tag_out) { raise_warning("Must call openssl_encrypt_with_tag when using an AEAD cipher"); return false; } int keylen = EVP_CIPHER_key_length(cipher_type); String key = password; /* * older openssl libraries can assert if the passed in password length is * less than keylen */ if (keylen > password.size()) { String s = String(keylen, ReserveString); char *keybuf = s.mutableData(); memset(keybuf, 0, keylen); memcpy(keybuf, password.data(), password.size()); key = s.setSize(keylen); } int max_iv_len = EVP_CIPHER_iv_length(cipher_type); if (iv.size() <= 0 && max_iv_len > 0 && !mode.is_aead) { raise_warning("Using an empty Initialization Vector (iv) is potentially " "insecure and not recommended"); } int result_len = 0; int outlen = data.size() + EVP_CIPHER_block_size(cipher_type); String rv = String(outlen, ReserveString); unsigned char *outbuf = (unsigned char*)rv.mutableData(); EVP_EncryptInit_ex(cipher_ctx, cipher_type, nullptr, nullptr, nullptr); String new_iv; // we do this after EncryptInit because validate_iv changes cipher_ctx for // aead modes (must be initialized first). if (!php_openssl_validate_iv( std::move(iv), max_iv_len, new_iv, cipher_ctx, &mode)) { return false; } // set the tag length for CCM mode/other modes that require tag lengths to // be set. if (mode.is_single_run_aead && !EVP_CIPHER_CTX_ctrl( cipher_ctx, mode.aead_set_tag_flag, tag_length, nullptr)) { raise_warning("Setting tag length failed"); return false; } if (password.size() > keylen) { EVP_CIPHER_CTX_set_key_length(cipher_ctx, password.size()); } EVP_EncryptInit_ex( cipher_ctx, nullptr, nullptr, (unsigned char*)key.data(), (unsigned char*)new_iv.data()); if (options & k_OPENSSL_ZERO_PADDING) { EVP_CIPHER_CTX_set_padding(cipher_ctx, 0); } // for single run aeads like CCM, we need to provide the length of the // plaintext before providing AAD or ciphertext. if (mode.is_single_run_aead && !EVP_EncryptUpdate( cipher_ctx, nullptr, &result_len, nullptr, data.size())) { raise_warning("Setting of data length failed"); return false; } // set up aad: if (mode.is_aead && !EVP_EncryptUpdate( cipher_ctx, nullptr, &result_len, (unsigned char*)aad.data(), aad.size())) { raise_warning("Setting of additional application data failed"); return false; } // OpenSSL before 0.9.8i asserts with size < 0 if (data.size() >= 0) { EVP_EncryptUpdate(cipher_ctx, outbuf, &result_len, (unsigned char *)data.data(), data.size()); } outlen = result_len; if (EVP_EncryptFinal_ex( cipher_ctx, (unsigned char*)outbuf + result_len, &result_len)) { outlen += result_len; rv.setSize(outlen); // Get tag if possible if (mode.is_aead) { String tagrv = String(tag_length, ReserveString); if (EVP_CIPHER_CTX_ctrl( cipher_ctx, mode.aead_get_tag_flag, tag_length, tagrv.mutableData()) == 1) { tagrv.setSize(tag_length); assertx(tag_out); *tag_out = tagrv; } else { raise_warning("Retrieving authentication tag failed"); return false; } } else if (tag_out) { raise_warning( "The authenticated tag cannot be provided for cipher that does not" " support AEAD"); } // Return encrypted data if (options & k_OPENSSL_RAW_DATA) { return rv; } else { return StringUtil::Base64Encode(rv); } } return false; } } // anonymous namespace Variant HHVM_FUNCTION(openssl_encrypt, const String& data, const String& method, const String& password, int options /* = 0 */, const String& iv /* = null_string */, const String& aad /* = null_string */, int tag_length /* = 16 */) { return openssl_encrypt_impl(data, method, password, options, iv, nullptr, aad, tag_length); } Variant HHVM_FUNCTION(openssl_encrypt_with_tag, const String& data, const String& method, const String& password, int options, const String& iv, Variant& tag_out, const String& aad /* = null_string */, int tag_length /* = 16 */) { return openssl_encrypt_impl(data, method, password, options, iv, &tag_out, aad, tag_length); } Variant HHVM_FUNCTION(openssl_decrypt, const String& data, const String& method, const String& password, int options /* = 0 */, const String& iv /* = null_string */, const String& tag /* = null_string */, const String& aad /* = null_string */) { const EVP_CIPHER *cipher_type = EVP_get_cipherbyname(method.c_str()); if (!cipher_type) { raise_warning("Unknown cipher algorithm"); return false; } EVP_CIPHER_CTX* cipher_ctx = EVP_CIPHER_CTX_new(); if (!cipher_ctx) { raise_warning("Failed to create cipher context"); return false; } SCOPE_EXIT { EVP_CIPHER_CTX_free(cipher_ctx); }; php_openssl_cipher_mode mode = php_openssl_load_cipher_mode(cipher_type); String decoded_data = data; if (!(options & k_OPENSSL_RAW_DATA)) { decoded_data = StringUtil::Base64Decode(data); } int keylen = EVP_CIPHER_key_length(cipher_type); String key = password; /* * older openssl libraries can assert if the passed in password length is * less than keylen */ if (keylen > password.size()) { String s = String(keylen, ReserveString); char *keybuf = s.mutableData(); memset(keybuf, 0, keylen); memcpy(keybuf, password.data(), password.size()); key = s.setSize(keylen); } int result_len = 0; int outlen = decoded_data.size() + EVP_CIPHER_block_size(cipher_type); String rv = String(outlen, ReserveString); unsigned char *outbuf = (unsigned char*)rv.mutableData(); EVP_DecryptInit_ex(cipher_ctx, cipher_type, nullptr, nullptr, nullptr); String new_iv; // we do this after DecryptInit because validate_iv changes cipher_ctx for // aead modes (must be initialized first). if (!php_openssl_validate_iv( std::move(iv), EVP_CIPHER_iv_length(cipher_type), new_iv, cipher_ctx, &mode)) { return false; } // set the tag if required: if (tag.size() > 0) { if (!mode.is_aead) { raise_warning( "The tag is being ignored because the cipher method does not" " support AEAD"); } else if (!EVP_CIPHER_CTX_ctrl( cipher_ctx, mode.aead_set_tag_flag, tag.size(), (unsigned char*)tag.data())) { raise_warning("Setting tag for AEAD cipher decryption failed"); return false; } } else { if (mode.is_aead) { raise_warning("A tag should be provided when using AEAD mode"); return false; } } if (password.size() > keylen) { EVP_CIPHER_CTX_set_key_length(cipher_ctx, password.size()); } EVP_DecryptInit_ex( cipher_ctx, nullptr, nullptr, (unsigned char*)key.data(), (unsigned char*)new_iv.data()); if (options & k_OPENSSL_ZERO_PADDING) { EVP_CIPHER_CTX_set_padding(cipher_ctx, 0); } // for single run aeads like CCM, we need to provide the length of the // ciphertext before providing AAD or ciphertext. if (mode.is_single_run_aead && !EVP_DecryptUpdate( cipher_ctx, nullptr, &result_len, nullptr, decoded_data.size())) { raise_warning("Setting of data length failed"); return false; } // set up aad: if (mode.is_aead && !EVP_DecryptUpdate( cipher_ctx, nullptr, &result_len, (unsigned char*)aad.data(), aad.size())) { raise_warning("Setting of additional application data failed"); return false; } if (!EVP_DecryptUpdate( cipher_ctx, outbuf, &result_len, (unsigned char*)decoded_data.data(), decoded_data.size())) { return false; } outlen = result_len; // if is_single_run_aead is enabled, DecryptFinal shouldn't be called. // if something went wrong in this case, we would've caught it at // DecryptUpdate. if (mode.is_single_run_aead || EVP_DecryptFinal_ex( cipher_ctx, (unsigned char*)outbuf + result_len, &result_len)) { // don't want to do this if is_single_run_aead was enabled, since we didn't // make a call to EVP_DecryptFinal. if (!mode.is_single_run_aead) { outlen += result_len; } rv.setSize(outlen); return rv; } else { return false; } } Variant HHVM_FUNCTION(openssl_digest, const String& data, const String& method, bool raw_output /* = false */) { const EVP_MD *mdtype = EVP_get_digestbyname(method.c_str()); if (!mdtype) { raise_warning("Unknown signature algorithm"); return false; } int siglen = EVP_MD_size(mdtype); String rv = String(siglen, ReserveString); unsigned char *sigbuf = (unsigned char *)rv.mutableData(); EVP_MD_CTX *md_ctx = EVP_MD_CTX_new(); SCOPE_EXIT { EVP_MD_CTX_free(md_ctx); }; EVP_DigestInit(md_ctx, mdtype); EVP_DigestUpdate(md_ctx, (unsigned char *)data.data(), data.size()); if (EVP_DigestFinal(md_ctx, (unsigned char *)sigbuf, (unsigned int *)&siglen)) { if (raw_output) { rv.setSize(siglen); return rv; } else { char* digest_str = string_bin2hex((char*)sigbuf, siglen); return String(digest_str, AttachString); } } else { return false; } } static void openssl_add_method_or_alias(const OBJ_NAME *name, void *arg) { Array *ret = (Array*)arg; ret->append(String((char *)name->name, CopyString)); } static void openssl_add_method(const OBJ_NAME *name, void *arg) { if (name->alias == 0) { Array *ret = (Array*)arg; ret->append(String((char *)name->name, CopyString)); } } Array HHVM_FUNCTION(openssl_get_cipher_methods, bool aliases /* = false */) { Array ret = Array::CreateVArray(); OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_CIPHER_METH, aliases ? openssl_add_method_or_alias: openssl_add_method, &ret); return ret; } Variant HHVM_FUNCTION(openssl_get_curve_names) { #ifdef HAVE_EVP_PKEY_EC const size_t len = EC_get_builtin_curves(nullptr, 0); std::unique_ptr<EC_builtin_curve[]> curves(new EC_builtin_curve[len]); if (!EC_get_builtin_curves(curves.get(), len)) { return false; } VArrayInit ret(len); for (size_t i = 0; i < len; ++i) { auto const sname = OBJ_nid2sn(curves[i].nid); if (sname != nullptr) { ret.append(String(sname, CopyString)); } } return ret.toArray(); #else return false; #endif } Array HHVM_FUNCTION(openssl_get_md_methods, bool aliases /* = false */) { Array ret = Array::CreateVArray(); OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_MD_METH, aliases ? openssl_add_method_or_alias: openssl_add_method, &ret); return ret; } ///////////////////////////////////////////////////////////////////////////// const StaticString s_OPENSSL_VERSION_TEXT("OPENSSL_VERSION_TEXT"); struct opensslExtension final : Extension { opensslExtension() : Extension("openssl") {} void moduleInit() override { HHVM_RC_INT(OPENSSL_RAW_DATA, k_OPENSSL_RAW_DATA); HHVM_RC_INT(OPENSSL_ZERO_PADDING, k_OPENSSL_ZERO_PADDING); HHVM_RC_INT(OPENSSL_NO_PADDING, k_OPENSSL_NO_PADDING); HHVM_RC_INT(OPENSSL_PKCS1_OAEP_PADDING, k_OPENSSL_PKCS1_OAEP_PADDING); HHVM_RC_INT(OPENSSL_SSLV23_PADDING, k_OPENSSL_SSLV23_PADDING); HHVM_RC_INT(OPENSSL_PKCS1_PADDING, k_OPENSSL_PKCS1_PADDING); HHVM_RC_INT_SAME(OPENSSL_ALGO_SHA1); HHVM_RC_INT_SAME(OPENSSL_ALGO_MD5); HHVM_RC_INT_SAME(OPENSSL_ALGO_MD4); #ifdef HAVE_OPENSSL_MD2_H HHVM_RC_INT_SAME(OPENSSL_ALGO_MD2); #endif HHVM_RC_INT_SAME(OPENSSL_ALGO_DSS1); HHVM_RC_INT_SAME(OPENSSL_ALGO_SHA224); HHVM_RC_INT_SAME(OPENSSL_ALGO_SHA256); HHVM_RC_INT_SAME(OPENSSL_ALGO_SHA384); HHVM_RC_INT_SAME(OPENSSL_ALGO_SHA512); HHVM_RC_INT_SAME(OPENSSL_ALGO_RMD160); HHVM_RC_INT(OPENSSL_CIPHER_RC2_40, PHP_OPENSSL_CIPHER_RC2_40); HHVM_RC_INT(OPENSSL_CIPHER_RC2_128, PHP_OPENSSL_CIPHER_RC2_128); HHVM_RC_INT(OPENSSL_CIPHER_RC2_64, PHP_OPENSSL_CIPHER_RC2_64); HHVM_RC_INT(OPENSSL_CIPHER_DES, PHP_OPENSSL_CIPHER_DES); HHVM_RC_INT(OPENSSL_CIPHER_3DES, PHP_OPENSSL_CIPHER_3DES); HHVM_RC_INT_SAME(OPENSSL_KEYTYPE_RSA); HHVM_RC_INT_SAME(OPENSSL_KEYTYPE_DSA); HHVM_RC_INT_SAME(OPENSSL_KEYTYPE_DH); #ifdef HAVE_EVP_PKEY_EC HHVM_RC_INT_SAME(OPENSSL_KEYTYPE_EC); #endif HHVM_RC_INT_SAME(OPENSSL_VERSION_NUMBER); HHVM_RC_INT_SAME(PKCS7_TEXT); HHVM_RC_INT_SAME(PKCS7_NOCERTS); HHVM_RC_INT_SAME(PKCS7_NOSIGS); HHVM_RC_INT_SAME(PKCS7_NOCHAIN); HHVM_RC_INT_SAME(PKCS7_NOINTERN); HHVM_RC_INT_SAME(PKCS7_NOVERIFY); HHVM_RC_INT_SAME(PKCS7_DETACHED); HHVM_RC_INT_SAME(PKCS7_BINARY); HHVM_RC_INT_SAME(PKCS7_NOATTR); HHVM_RC_STR_SAME(OPENSSL_VERSION_TEXT); HHVM_RC_INT_SAME(X509_PURPOSE_SSL_CLIENT); HHVM_RC_INT_SAME(X509_PURPOSE_SSL_SERVER); HHVM_RC_INT_SAME(X509_PURPOSE_NS_SSL_SERVER); HHVM_RC_INT_SAME(X509_PURPOSE_SMIME_SIGN); HHVM_RC_INT_SAME(X509_PURPOSE_SMIME_ENCRYPT); HHVM_RC_INT_SAME(X509_PURPOSE_CRL_SIGN); #ifdef X509_PURPOSE_ANY HHVM_RC_INT_SAME(X509_PURPOSE_ANY); #endif HHVM_FE(openssl_csr_export_to_file); HHVM_FE(openssl_csr_export); HHVM_FE(openssl_csr_get_public_key); HHVM_FE(openssl_csr_get_subject); HHVM_FE(openssl_csr_new); HHVM_FE(openssl_csr_sign); HHVM_FE(openssl_error_string); HHVM_FE(openssl_open); HHVM_FE(openssl_pkcs12_export_to_file); HHVM_FE(openssl_pkcs12_export); HHVM_FE(openssl_pkcs12_read); HHVM_FE(openssl_pkcs7_decrypt); HHVM_FE(openssl_pkcs7_encrypt); HHVM_FE(openssl_pkcs7_sign); HHVM_FE(openssl_pkcs7_verify); HHVM_FE(openssl_pkey_export_to_file); HHVM_FE(openssl_pkey_export); HHVM_FE(openssl_pkey_get_details); HHVM_FE(openssl_pkey_get_private); HHVM_FE(openssl_pkey_get_public); HHVM_FE(openssl_pkey_new); HHVM_FE(openssl_private_decrypt); HHVM_FE(openssl_private_encrypt); HHVM_FE(openssl_public_decrypt); HHVM_FE(openssl_public_encrypt); HHVM_FE(openssl_seal); HHVM_FE(openssl_sign); HHVM_FE(openssl_verify); HHVM_FE(openssl_x509_check_private_key); HHVM_FE(openssl_x509_checkpurpose); HHVM_FE(openssl_x509_export_to_file); HHVM_FE(openssl_x509_export); HHVM_FE(openssl_x509_parse); HHVM_FE(openssl_x509_read); HHVM_FE(openssl_random_pseudo_bytes); HHVM_FE(openssl_cipher_iv_length); HHVM_FE(openssl_encrypt); HHVM_FE(openssl_encrypt_with_tag); HHVM_FE(openssl_decrypt); HHVM_FE(openssl_digest); HHVM_FE(openssl_get_cipher_methods); HHVM_FE(openssl_get_curve_names); HHVM_FE(openssl_get_md_methods); loadSystemlib(); } } s_openssl_extension; /////////////////////////////////////////////////////////////////////////////// }
15409
True
1
CVE-2020-1919
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Incorrect bounds calculations in substr_compare could lead to an out-of-bounds read when the second string argument passed in is longer than the first. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:51Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::php_openssl_config_check_syntax
HPHP::php_openssl_config_check_syntax( const char * section_label , const char * config_filename , const char * section , LHASH_OF(CONF_VALUE) * config)
['section_label', 'config_filename', 'section', 'config']
static inline bool php_openssl_config_check_syntax (const char *section_label, const char *config_filename, const char *section, LHASH_OF(CONF_VALUE) *config) { #else static inline bool php_openssl_config_check_syntax (const char *section_label, const char *config_filename, const char *section, LHASH *config) { #endif X509V3_CTX ctx; X509V3_set_ctx_test(&ctx); X509V3_set_conf_lhash(&ctx, config); if (!X509V3_EXT_add_conf(config, &ctx, (char*)section, nullptr)) { raise_warning("Error loading %s section %s of %s", section_label, section, config_filename); return false; } return true; } const StaticString s_config("config"), s_config_section_name("config_section_name"), s_digest_alg("digest_alg"), s_x509_extensions("x509_extensions"), s_req_extensions("req_extensions"), s_private_key_bits("private_key_bits"), s_private_key_type("private_key_type"), s_encrypt_key("encrypt_key"), s_curve_name("curve_name"); static bool php_openssl_parse_config(struct php_x509_request *req, const Array& args, std::vector<String> &strings) { req->config_filename = read_string(args, s_config, default_ssl_conf_filename, strings); req->section_name = read_string(args, s_config_section_name, "req", strings); req->global_config = CONF_load(nullptr, default_ssl_conf_filename, nullptr); req->req_config = CONF_load(nullptr, req->config_filename, nullptr); if (req->req_config == nullptr) { return false; } /* read in the oids */ char *str = CONF_get_string(req->req_config, nullptr, "oid_file"); if (str) { BIO *oid_bio = BIO_new_file(str, "r"); if (oid_bio) { OBJ_create_objects(oid_bio); BIO_free(oid_bio); } } if (!add_oid_section(req)) { return false; } req->digest_name = read_string(args, s_digest_alg, CONF_get_string(req->req_config, req->section_name, "default_md"), strings); req->extensions_section = read_string(args, s_x509_extensions, CONF_get_string(req->req_config, req->section_name, "x509_extensions"), strings); req->request_extensions_section = read_string(args, s_req_extensions, CONF_get_string(req->req_config, req->section_name, "req_extensions"), strings); req->priv_key_bits = read_integer(args, s_private_key_bits, CONF_get_number(req->req_config, req->section_name, "default_bits")); req->priv_key_type = read_integer(args, s_private_key_type, OPENSSL_KEYTYPE_DEFAULT); if (args.exists(s_encrypt_key)) { bool value = args[s_encrypt_key].toBoolean(); req->priv_key_encrypt = value ? 1 : 0; } else { str = CONF_get_string(req->req_config, req->section_name, "encrypt_rsa_key"); if (str == nullptr) { str = CONF_get_string(req->req_config, req->section_name, "encrypt_key"); } if (str && strcmp(str, "no") == 0) { req->priv_key_encrypt = 0; } else { req->priv_key_encrypt = 1; } } /* digest alg */ if (req->digest_name == nullptr) { req->digest_name = CONF_get_string(req->req_config, req->section_name, "default_md"); } if (req->digest_name) { req->digest = req->md_alg = EVP_get_digestbyname(req->digest_name); } if (req->md_alg == nullptr) { req->md_alg = req->digest = EVP_sha256(); } #ifdef HAVE_EVP_PKEY_EC /* set the ec group curve name */ req->curve_name = NID_undef; if (args.exists(s_curve_name)) { auto const curve_name = args[s_curve_name].toString(); req->curve_name = OBJ_sn2nid(curve_name.data()); if (req->curve_name == NID_undef) { raise_warning( "Unknown elliptic curve (short) name %s", curve_name.data() ); return false; } } #endif if (req->extensions_section && !php_openssl_config_check_syntax ("extensions_section", req->config_filename, req->extensions_section, req->req_config)) { return false; } /* set the string mask */ str = CONF_get_string(req->req_config, req->section_name, "string_mask"); if (str && !ASN1_STRING_set_default_mask_asc(str)) { raise_warning("Invalid global string mask setting %s", str); return false; } if (req->request_extensions_section && !php_openssl_config_check_syntax ("request_extensions_section", req->config_filename, req->request_extensions_section, req->req_config)) { return false; } return true; } static void php_openssl_dispose_config(struct php_x509_request *req) { if (req->global_config) { CONF_free(req->global_config); req->global_config = nullptr; } if (req->req_config) { CONF_free(req->req_config); req->req_config = nullptr; } } static STACK_OF(X509) *load_all_certs_from_file(const char *certfile) { STACK_OF(X509_INFO) *sk = nullptr; STACK_OF(X509) *stack = nullptr, *ret = nullptr; BIO *in = nullptr; X509_INFO *xi; if (!(stack = sk_X509_new_null())) { raise_warning("memory allocation failure"); goto end; } if (!(in = BIO_new_file(certfile, "r"))) { raise_warning("error opening the file, %s", certfile); sk_X509_free(stack); goto end; } /* This loads from a file, a stack of x509/crl/pkey sets */ if (!(sk = PEM_X509_INFO_read_bio(in, nullptr, nullptr, nullptr))) { raise_warning("error reading the file, %s", certfile); sk_X509_free(stack); goto end; } /* scan over it and pull out the certs */ while (sk_X509_INFO_num(sk)) { xi = sk_X509_INFO_shift(sk); if (xi->x509 != nullptr) { sk_X509_push(stack, xi->x509); xi->x509 = nullptr; } X509_INFO_free(xi); } if (!sk_X509_num(stack)) { raise_warning("no certificates in file, %s", certfile); sk_X509_free(stack); goto end; } ret = stack; end: BIO_free(in); sk_X509_INFO_free(sk); return ret; } /** * calist is an array containing file and directory names. create a * certificate store and add those certs to it for use in verification. */ static X509_STORE *setup_verify(const Array& calist) { X509_STORE *store = X509_STORE_new(); if (store == nullptr) { return nullptr; } X509_LOOKUP *dir_lookup, *file_lookup; int ndirs = 0, nfiles = 0; for (ArrayIter iter(calist); iter; ++iter) { String item = iter.second().toString(); struct stat sb; if (stat(item.data(), &sb) == -1) { raise_warning("unable to stat %s", item.data()); continue; } if ((sb.st_mode & S_IFREG) == S_IFREG) { file_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()); if (file_lookup == nullptr || !X509_LOOKUP_load_file(file_lookup, item.data(), X509_FILETYPE_PEM)) { raise_warning("error loading file %s", item.data()); } else { nfiles++; } file_lookup = nullptr; } else { dir_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir()); if (dir_lookup == nullptr || !X509_LOOKUP_add_dir(dir_lookup, item.data(), X509_FILETYPE_PEM)) { raise_warning("error loading directory %s", item.data()); } else { ndirs++; } dir_lookup = nullptr; } } if (nfiles == 0) { file_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()); if (file_lookup) { X509_LOOKUP_load_file(file_lookup, nullptr, X509_FILETYPE_DEFAULT); } } if (ndirs == 0) { dir_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir()); if (dir_lookup) { X509_LOOKUP_add_dir(dir_lookup, nullptr, X509_FILETYPE_DEFAULT); } } return store; } /////////////////////////////////////////////////////////////////////////////// static bool add_entries(X509_NAME *subj, const Array& items) { for (ArrayIter iter(items); iter; ++iter) { auto const index = iter.first().toString(); auto const item = iter.second().toString(); int nid = OBJ_txt2nid(index.data()); if (nid != NID_undef) { if (!X509_NAME_add_entry_by_NID(subj, nid, MBSTRING_ASC, (unsigned char*)item.data(), -1, -1, 0)) { raise_warning("dn: add_entry_by_NID %d -> %s (failed)", nid, item.data()); return false; } } else { raise_warning("dn: %s is not a recognized name", index.data()); } } return true; } static bool php_openssl_make_REQ(struct php_x509_request *req, X509_REQ *csr, const Array& dn, const Array& attribs) { char *dn_sect = CONF_get_string(req->req_config, req->section_name, "distinguished_name"); if (dn_sect == nullptr) return false; STACK_OF(CONF_VALUE) *dn_sk = CONF_get_section(req->req_config, dn_sect); if (dn_sk == nullptr) return false; char *attr_sect = CONF_get_string(req->req_config, req->section_name, "attributes"); STACK_OF(CONF_VALUE) *attr_sk = nullptr; if (attr_sect) { attr_sk = CONF_get_section(req->req_config, attr_sect); if (attr_sk == nullptr) { return false; } } /* setup the version number: version 1 */ if (X509_REQ_set_version(csr, 0L)) { X509_NAME *subj = X509_REQ_get_subject_name(csr); if (!add_entries(subj, dn)) return false; /* Finally apply defaults from config file */ for (int i = 0; i < sk_CONF_VALUE_num(dn_sk); i++) { CONF_VALUE *v = sk_CONF_VALUE_value(dn_sk, i); char *type = v->name; int len = strlen(type); if (len < (int)sizeof("_default")) { continue; } len -= sizeof("_default") - 1; if (strcmp("_default", type + len) != 0) { continue; } if (len > 200) { len = 200; } char buffer[200 + 1]; /*200 + \0 !*/ memcpy(buffer, type, len); buffer[len] = '\0'; type = buffer; /* Skip past any leading X. X: X, etc to allow for multiple instances */ for (char *str = type; *str; str++) { if (*str == ':' || *str == ',' || *str == '.') { str++; if (*str) { type = str; } break; } } /* if it is already set, skip this */ int nid = OBJ_txt2nid(type); if (X509_NAME_get_index_by_NID(subj, nid, -1) >= 0) { continue; } if (!X509_NAME_add_entry_by_txt(subj, type, MBSTRING_ASC, (unsigned char*)v->value, -1, -1, 0)) { raise_warning("add_entry_by_txt %s -> %s (failed)", type, v->value); return false; } if (!X509_NAME_entry_count(subj)) { raise_warning("no objects specified in config file"); return false; } } if (!add_entries(subj, attribs)) return false; if (attr_sk) { for (int i = 0; i < sk_CONF_VALUE_num(attr_sk); i++) { CONF_VALUE *v = sk_CONF_VALUE_value(attr_sk, i); /* if it is already set, skip this */ int nid = OBJ_txt2nid(v->name); if (X509_REQ_get_attr_by_NID(csr, nid, -1) >= 0) { continue; } if (!X509_REQ_add1_attr_by_txt(csr, v->name, MBSTRING_ASC, (unsigned char*)v->value, -1)) { /** * hzhao: mismatched version of conf file may have attributes that * are not recognizable, and I don't think it should be treated as * fatal errors. */ Logger::Verbose("add1_attr_by_txt %s -> %s (failed)", v->name, v->value); // return false; } } } } X509_REQ_set_pubkey(csr, req->priv_key); return true; } bool HHVM_FUNCTION(openssl_csr_export_to_file, const Variant& csr, const String& outfilename, bool notext /* = true */) { auto pcsr = CSRequest::Get(csr); if (!pcsr) return false; BIO *bio_out = BIO_new_file((char*)outfilename.data(), "w"); if (bio_out == nullptr) { raise_warning("error opening file %s", outfilename.data()); return false; } if (!notext) { X509_REQ_print(bio_out, pcsr->csr()); } PEM_write_bio_X509_REQ(bio_out, pcsr->csr()); BIO_free(bio_out); return true; } bool HHVM_FUNCTION(openssl_csr_export, const Variant& csr, Variant& out, bool notext /* = true */) { auto pcsr = CSRequest::Get(csr); if (!pcsr) return false; BIO *bio_out = BIO_new(BIO_s_mem()); if (!notext) { X509_REQ_print(bio_out, pcsr->csr()); } if (PEM_write_bio_X509_REQ(bio_out, pcsr->csr())) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); out = String((char*)bio_buf->data, bio_buf->length, CopyString); BIO_free(bio_out); return true; } BIO_free(bio_out); return false; } Variant HHVM_FUNCTION(openssl_csr_get_public_key, const Variant& csr) { auto pcsr = CSRequest::Get(csr); if (!pcsr) return false; auto input_csr = pcsr->csr(); #if OPENSSL_VERSION_NUMBER >= 0x10100000 /* Due to changes in OpenSSL 1.1 related to locking when decoding CSR, * the pub key is not changed after assigning. It means if we pass * a private key, it will be returned including the private part. * If we duplicate it, then we get just the public part which is * the same behavior as for OpenSSL 1.0 */ input_csr = X509_REQ_dup(input_csr); /* We need to free the CSR as it was duplicated */ SCOPE_EXIT { X509_REQ_free(input_csr); }; #endif auto pubkey = X509_REQ_get_pubkey(input_csr); if (!pubkey) return false; return Variant(req::make<Key>(pubkey)); } Variant HHVM_FUNCTION(openssl_csr_get_subject, const Variant& csr, bool use_shortnames /* = true */) { auto pcsr = CSRequest::Get(csr); if (!pcsr) return false; X509_NAME *subject = X509_REQ_get_subject_name(pcsr->csr()); Array ret = Array::CreateDArray(); add_assoc_name_entry(ret, nullptr, subject, use_shortnames); return ret; } Variant HHVM_FUNCTION(openssl_csr_new, const Variant& dn, Variant& privkey, const Variant& configargs /* = uninit_variant */, const Variant& extraattribs /* = uninit_variant */) { Variant ret = false; struct php_x509_request req; memset(&req, 0, sizeof(req)); req::ptr<Key> okey; X509_REQ *csr = nullptr; std::vector<String> strings; if (php_openssl_parse_config(&req, configargs.toArray(), strings)) { /* Generate or use a private key */ if (!privkey.isNull()) { okey = Key::Get(privkey, false); if (okey) { req.priv_key = okey->m_key; } } if (req.priv_key == nullptr) { req.generatePrivateKey(); if (req.priv_key) { okey = req::make<Key>(req.priv_key); } } if (req.priv_key == nullptr) { raise_warning("Unable to generate a private key"); } else { csr = X509_REQ_new(); if (csr && php_openssl_make_REQ(&req, csr, dn.toArray(), extraattribs.toArray())) { X509V3_CTX ext_ctx; X509V3_set_ctx(&ext_ctx, nullptr, nullptr, csr, nullptr, 0); X509V3_set_conf_lhash(&ext_ctx, req.req_config); /* Add extensions */ if (req.request_extensions_section && !X509V3_EXT_REQ_add_conf(req.req_config, &ext_ctx, (char*)req.request_extensions_section, csr)) { raise_warning("Error loading extension section %s", req.request_extensions_section); } else { ret = true; if (X509_REQ_sign(csr, req.priv_key, req.digest)) { ret = req::make<CSRequest>(csr); csr = nullptr; } else { raise_warning("Error signing request"); } privkey = Variant(okey); } } } } if (csr) { X509_REQ_free(csr); } php_openssl_dispose_config(&req); return ret; } Variant HHVM_FUNCTION(openssl_csr_sign, const Variant& csr, const Variant& cacert, const Variant& priv_key, int days, const Variant& configargs /* = null */, int serial /* = 0 */) { auto pcsr = CSRequest::Get(csr); if (!pcsr) return false; req::ptr<Certificate> ocert; if (!cacert.isNull()) { ocert = Certificate::Get(cacert); if (!ocert) { raise_warning("cannot get cert from parameter 2"); return false; } } auto okey = Key::Get(priv_key, false); if (!okey) { raise_warning("cannot get private key from parameter 3"); return false; } X509 *cert = nullptr; if (ocert) { cert = ocert->m_cert; } EVP_PKEY *pkey = okey->m_key; if (cert && !X509_check_private_key(cert, pkey)) { raise_warning("private key does not correspond to signing cert"); return false; } req::ptr<Certificate> onewcert; struct php_x509_request req; memset(&req, 0, sizeof(req)); Variant ret = false; std::vector<String> strings; if (!php_openssl_parse_config(&req, configargs.toArray(), strings)) { goto cleanup; } /* Check that the request matches the signature */ EVP_PKEY *key; key = X509_REQ_get_pubkey(pcsr->csr()); if (key == nullptr) { raise_warning("error unpacking public key"); goto cleanup; } int i; i = X509_REQ_verify(pcsr->csr(), key); if (i < 0) { raise_warning("Signature verification problems"); goto cleanup; } if (i == 0) { raise_warning("Signature did not match the certificate request"); goto cleanup; } /* Now we can get on with it */ X509 *new_cert; new_cert = X509_new(); if (new_cert == nullptr) { raise_warning("No memory"); goto cleanup; } onewcert = req::make<Certificate>(new_cert); /* Version 3 cert */ if (!X509_set_version(new_cert, 2)) { goto cleanup; } ASN1_INTEGER_set(X509_get_serialNumber(new_cert), serial); X509_set_subject_name(new_cert, X509_REQ_get_subject_name(pcsr->csr())); if (cert == nullptr) { cert = new_cert; } if (!X509_set_issuer_name(new_cert, X509_get_subject_name(cert))) { goto cleanup; } X509_gmtime_adj(X509_get_notBefore(new_cert), 0); X509_gmtime_adj(X509_get_notAfter(new_cert), (long)60 * 60 * 24 * days); i = X509_set_pubkey(new_cert, key); if (!i) { goto cleanup; } if (req.extensions_section) { X509V3_CTX ctx; X509V3_set_ctx(&ctx, cert, new_cert, pcsr->csr(), nullptr, 0); X509V3_set_conf_lhash(&ctx, req.req_config); if (!X509V3_EXT_add_conf(req.req_config, &ctx, (char*)req.extensions_section, new_cert)) { goto cleanup; } } /* Now sign it */ if (!X509_sign(new_cert, pkey, req.digest)) { raise_warning("failed to sign it"); goto cleanup; } /* Succeeded; lets return the cert */ ret = onewcert; cleanup: php_openssl_dispose_config(&req); return ret; } Variant HHVM_FUNCTION(openssl_error_string) { char buf[512]; unsigned long val = ERR_get_error(); if (val) { return String(ERR_error_string(val, buf), CopyString); } return false; } bool HHVM_FUNCTION(openssl_open, const String& sealed_data, Variant& open_data, const String& env_key, const Variant& priv_key_id, const String& method, /* = null_string */ const String& iv /* = null_string */) { const EVP_CIPHER *cipher_type; if (method.empty()) { cipher_type = EVP_rc4(); } else { cipher_type = EVP_get_cipherbyname(method.c_str()); if (!cipher_type) { raise_warning("Unknown cipher algorithm"); return false; } } auto okey = Key::Get(priv_key_id, false); if (!okey) { raise_warning("unable to coerce parameter 4 into a private key"); return false; } EVP_PKEY *pkey = okey->m_key; const unsigned char *iv_buf = nullptr; int iv_len = EVP_CIPHER_iv_length(cipher_type); if (iv_len > 0) { if (iv.empty()) { raise_warning( "Cipher algorithm requires an IV to be supplied as a sixth parameter"); return false; } if (iv.length() != iv_len) { raise_warning("IV length is invalid"); return false; } iv_buf = reinterpret_cast<const unsigned char*>(iv.c_str()); } String s = String(sealed_data.size(), ReserveString); unsigned char *buf = (unsigned char *)s.mutableData(); EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new(); if (ctx == nullptr) { raise_warning("Failed to allocate an EVP_CIPHER_CTX object"); return false; } SCOPE_EXIT { EVP_CIPHER_CTX_free(ctx); }; int len1, len2; if (!EVP_OpenInit( ctx, cipher_type, (unsigned char*)env_key.data(), env_key.size(), iv_buf, pkey) || !EVP_OpenUpdate( ctx, buf, &len1, (unsigned char*)sealed_data.data(), sealed_data.size()) || !EVP_OpenFinal(ctx, buf + len1, &len2) || len1 + len2 == 0) { return false; } open_data = s.setSize(len1 + len2); return true; } static STACK_OF(X509) *php_array_to_X509_sk(const Variant& certs) { STACK_OF(X509) *pcerts = sk_X509_new_null(); Array arrCerts; if (certs.isArray()) { arrCerts = certs.toArray(); } else { arrCerts.append(certs); } for (ArrayIter iter(arrCerts); iter; ++iter) { auto ocert = Certificate::Get(iter.second()); if (!ocert) { break; } sk_X509_push(pcerts, ocert->m_cert); } return pcerts; } const StaticString s_friendly_name("friendly_name"), s_extracerts("extracerts"); static bool openssl_pkcs12_export_impl(const Variant& x509, BIO *bio_out, const Variant& priv_key, const String& pass, const Variant& args /* = uninit_variant */) { auto ocert = Certificate::Get(x509); if (!ocert) { raise_warning("cannot get cert from parameter 1"); return false; } auto okey = Key::Get(priv_key, false); if (!okey) { raise_warning("cannot get private key from parameter 3"); return false; } X509 *cert = ocert->m_cert; EVP_PKEY *key = okey->m_key; if (cert && !X509_check_private_key(cert, key)) { raise_warning("private key does not correspond to cert"); return false; } Array arrArgs = args.toArray(); String friendly_name; if (arrArgs.exists(s_friendly_name)) { friendly_name = arrArgs[s_friendly_name].toString(); } STACK_OF(X509) *ca = nullptr; if (arrArgs.exists(s_extracerts)) { ca = php_array_to_X509_sk(arrArgs[s_extracerts]); } PKCS12 *p12 = PKCS12_create ((char*)pass.data(), (char*)(friendly_name.empty() ? nullptr : friendly_name.data()), key, cert, ca, 0, 0, 0, 0, 0); assertx(bio_out); bool ret = i2d_PKCS12_bio(bio_out, p12); PKCS12_free(p12); sk_X509_free(ca); return ret; } bool HHVM_FUNCTION(openssl_pkcs12_export_to_file, const Variant& x509, const String& filename, const Variant& priv_key, const String& pass, const Variant& args /* = uninit_variant */) { BIO *bio_out = BIO_new_file(filename.data(), "w"); if (bio_out == nullptr) { raise_warning("error opening file %s", filename.data()); return false; } bool ret = openssl_pkcs12_export_impl(x509, bio_out, priv_key, pass, args); BIO_free(bio_out); return ret; } bool HHVM_FUNCTION(openssl_pkcs12_export, const Variant& x509, Variant& out, const Variant& priv_key, const String& pass, const Variant& args /* = uninit_variant */) { BIO *bio_out = BIO_new(BIO_s_mem()); bool ret = openssl_pkcs12_export_impl(x509, bio_out, priv_key, pass, args); if (ret) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); out = String((char*)bio_buf->data, bio_buf->length, CopyString); } BIO_free(bio_out); return ret; } const StaticString s_cert("cert"), s_pkey("pkey"); bool HHVM_FUNCTION(openssl_pkcs12_read, const String& pkcs12, Variant& certs, const String& pass) { bool ret = false; PKCS12 *p12 = nullptr; BIO *bio_in = BIO_new(BIO_s_mem()); if (!BIO_write(bio_in, pkcs12.data(), pkcs12.size())) { goto cleanup; } if (d2i_PKCS12_bio(bio_in, &p12)) { EVP_PKEY *pkey = nullptr; X509 *cert = nullptr; STACK_OF(X509) *ca = nullptr; if (PKCS12_parse(p12, pass.data(), &pkey, &cert, &ca)) { Variant vcerts = Array::CreateDArray(); SCOPE_EXIT { certs = vcerts; }; BIO *bio_out = nullptr; if (cert) { bio_out = BIO_new(BIO_s_mem()); if (PEM_write_bio_X509(bio_out, cert)) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); vcerts.asArrRef().set(s_cert, String((char*)bio_buf->data, bio_buf->length, CopyString)); } BIO_free(bio_out); } if (pkey) { bio_out = BIO_new(BIO_s_mem()); if (PEM_write_bio_PrivateKey(bio_out, pkey, nullptr, nullptr, 0, 0, nullptr)) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); vcerts.asArrRef().set(s_pkey, String((char*)bio_buf->data, bio_buf->length, CopyString)); } BIO_free(bio_out); } if (ca) { Array extracerts; for (X509 *aCA = sk_X509_pop(ca); aCA; aCA = sk_X509_pop(ca)) { bio_out = BIO_new(BIO_s_mem()); if (PEM_write_bio_X509(bio_out, aCA)) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); extracerts.append(String((char*)bio_buf->data, bio_buf->length, CopyString)); } BIO_free(bio_out); X509_free(aCA); } sk_X509_free(ca); vcerts.asArrRef().set(s_extracerts, extracerts); } ret = true; PKCS12_free(p12); } } cleanup: if (bio_in) { BIO_free(bio_in); } return ret; } bool HHVM_FUNCTION(openssl_pkcs7_decrypt, const String& infilename, const String& outfilename, const Variant& recipcert, const Variant& recipkey /* = uninit_variant */) { bool ret = false; BIO *in = nullptr, *out = nullptr, *datain = nullptr; PKCS7 *p7 = nullptr; req::ptr<Key> okey; auto ocert = Certificate::Get(recipcert); if (!ocert) { raise_warning("unable to coerce parameter 3 to x509 cert"); goto clean_exit; } okey = Key::Get(recipkey.isNull() ? recipcert : recipkey, false); if (!okey) { raise_warning("unable to get private key"); goto clean_exit; } in = BIO_new_file(infilename.data(), "r"); if (in == nullptr) { raise_warning("error opening the file, %s", infilename.data()); goto clean_exit; } out = BIO_new_file(outfilename.data(), "w"); if (out == nullptr) { raise_warning("error opening the file, %s", outfilename.data()); goto clean_exit; } p7 = SMIME_read_PKCS7(in, &datain); if (p7 == nullptr) { goto clean_exit; } assertx(okey->m_key); assertx(ocert->m_cert); if (PKCS7_decrypt(p7, okey->m_key, ocert->m_cert, out, PKCS7_DETACHED)) { ret = true; } clean_exit: PKCS7_free(p7); BIO_free(datain); BIO_free(in); BIO_free(out); return ret; } static void print_headers(BIO *outfile, const Array& headers) { if (!headers.isNull()) { if (headers->isVectorData()) { for (ArrayIter iter(headers); iter; ++iter) { BIO_printf(outfile, "%s\n", iter.second().toString().data()); } } else { for (ArrayIter iter(headers); iter; ++iter) { BIO_printf(outfile, "%s: %s\n", iter.first().toString().data(), iter.second().toString().data()); } } } } bool HHVM_FUNCTION(openssl_pkcs7_encrypt, const String& infilename, const String& outfilename, const Variant& recipcerts, const Array& headers, int flags /* = 0 */, int cipherid /* = k_OPENSSL_CIPHER_RC2_40 */) { bool ret = false; BIO *infile = nullptr, *outfile = nullptr; STACK_OF(X509) *precipcerts = nullptr; PKCS7 *p7 = nullptr; const EVP_CIPHER *cipher = nullptr; infile = BIO_new_file(infilename.data(), (flags & PKCS7_BINARY) ? "rb" : "r"); if (infile == nullptr) { raise_warning("error opening the file, %s", infilename.data()); goto clean_exit; } outfile = BIO_new_file(outfilename.data(), "w"); if (outfile == nullptr) { raise_warning("error opening the file, %s", outfilename.data()); goto clean_exit; } precipcerts = php_array_to_X509_sk(recipcerts); /* sanity check the cipher */ switch (cipherid) { #ifndef OPENSSL_NO_RC2 case PHP_OPENSSL_CIPHER_RC2_40: cipher = EVP_rc2_40_cbc(); break; case PHP_OPENSSL_CIPHER_RC2_64: cipher = EVP_rc2_64_cbc(); break; case PHP_OPENSSL_CIPHER_RC2_128: cipher = EVP_rc2_cbc(); break; #endif #ifndef OPENSSL_NO_DES case PHP_OPENSSL_CIPHER_DES: cipher = EVP_des_cbc(); break; case PHP_OPENSSL_CIPHER_3DES: cipher = EVP_des_ede3_cbc(); break; #endif default: raise_warning("Invalid cipher type `%d'", cipherid); goto clean_exit; } if (cipher == nullptr) { raise_warning("Failed to get cipher"); goto clean_exit; } p7 = PKCS7_encrypt(precipcerts, infile, (EVP_CIPHER*)cipher, flags); if (p7 == nullptr) goto clean_exit; print_headers(outfile, headers); (void)BIO_reset(infile); SMIME_write_PKCS7(outfile, p7, infile, flags); ret = true; clean_exit: PKCS7_free(p7); BIO_free(infile); BIO_free(outfile); sk_X509_free(precipcerts); return ret; } bool HHVM_FUNCTION(openssl_pkcs7_sign, const String& infilename, const String& outfilename, const Variant& signcert, const Variant& privkey, const Variant& headers, int flags /* = k_PKCS7_DETACHED */, const String& extracerts /* = null_string */) { bool ret = false; STACK_OF(X509) *others = nullptr; BIO *infile = nullptr, *outfile = nullptr; PKCS7 *p7 = nullptr; req::ptr<Key> okey; req::ptr<Certificate> ocert; if (!extracerts.empty()) { others = load_all_certs_from_file(extracerts.data()); if (others == nullptr) { goto clean_exit; } } okey = Key::Get(privkey, false); if (!okey) { raise_warning("error getting private key"); goto clean_exit; } EVP_PKEY *key; key = okey->m_key; ocert = Certificate::Get(signcert); if (!ocert) { raise_warning("error getting cert"); goto clean_exit; } X509 *cert; cert = ocert->m_cert; infile = BIO_new_file(infilename.data(), (flags & PKCS7_BINARY) ? "rb" : "r"); if (infile == nullptr) { raise_warning("error opening input file %s!", infilename.data()); goto clean_exit; } outfile = BIO_new_file(outfilename.data(), "w"); if (outfile == nullptr) { raise_warning("error opening output file %s!", outfilename.data()); goto clean_exit; } p7 = PKCS7_sign(cert, key, others, infile, flags); if (p7 == nullptr) { raise_warning("error creating PKCS7 structure!"); goto clean_exit; } print_headers(outfile, headers.toArray()); (void)BIO_reset(infile); SMIME_write_PKCS7(outfile, p7, infile, flags); ret = true; clean_exit: PKCS7_free(p7); BIO_free(infile); BIO_free(outfile); if (others) { sk_X509_pop_free(others, X509_free); } return ret; } static int pkcs7_ignore_expiration(int ok, X509_STORE_CTX *ctx) { if (ok) { return ok; } int error = X509_STORE_CTX_get_error(ctx); if (error == X509_V_ERR_CERT_HAS_EXPIRED) { // ignore cert expirations Logger::Verbose("Ignoring cert expiration"); return 1; } return ok; } /** * NOTE: when ignore_cert_expiration is true, a custom certificate validation * callback is set up. Please be aware of this if you modify the function to * allow other certificate validation behaviors */ Variant openssl_pkcs7_verify_core( const String& filename, int flags, const Variant& voutfilename /* = null_string */, const Variant& vcainfo /* = null_array */, const Variant& vextracerts /* = null_string */, const Variant& vcontent /* = null_string */, bool ignore_cert_expiration ) { Variant ret = -1; X509_STORE *store = nullptr; BIO *in = nullptr; PKCS7 *p7 = nullptr; BIO *datain = nullptr; BIO *dataout = nullptr; auto cainfo = vcainfo.toArray(); auto extracerts = vextracerts.toString(); auto content = vcontent.toString(); STACK_OF(X509) *others = nullptr; if (!extracerts.empty()) { others = load_all_certs_from_file(extracerts.data()); if (others == nullptr) { goto clean_exit; } } flags = flags & ~PKCS7_DETACHED; store = setup_verify(cainfo); if (!store) { goto clean_exit; } if (ignore_cert_expiration) { #if (OPENSSL_VERSION_NUMBER >= 0x10000000) // make sure no other callback is specified #if OPENSSL_VERSION_NUMBER >= 0x10100000L assertx(!X509_STORE_get_verify_cb(store)); #else assertx(!store->verify_cb); #endif // ignore expired certs X509_STORE_set_verify_cb(store, pkcs7_ignore_expiration); #else always_assert(false); #endif } in = BIO_new_file(filename.data(), (flags & PKCS7_BINARY) ? "rb" : "r"); if (in == nullptr) { raise_warning("error opening the file, %s", filename.data()); goto clean_exit; } p7 = SMIME_read_PKCS7(in, &datain); if (p7 == nullptr) { goto clean_exit; } if (!content.empty()) { dataout = BIO_new_file(content.data(), "w"); if (dataout == nullptr) { raise_warning("error opening the file, %s", content.data()); goto clean_exit; } } if (PKCS7_verify(p7, others, store, datain, dataout, flags)) { ret = true; auto outfilename = voutfilename.toString(); if (!outfilename.empty()) { BIO *certout = BIO_new_file(outfilename.data(), "w"); if (certout) { STACK_OF(X509) *signers = PKCS7_get0_signers(p7, nullptr, flags); for (int i = 0; i < sk_X509_num(signers); i++) { PEM_write_bio_X509(certout, sk_X509_value(signers, i)); } BIO_free(certout); sk_X509_free(signers); } else { raise_warning("signature OK, but cannot open %s for writing", outfilename.data()); ret = -1; } } goto clean_exit; } else { ret = false; } clean_exit: X509_STORE_free(store); BIO_free(datain); BIO_free(in); BIO_free(dataout); PKCS7_free(p7); sk_X509_pop_free(others, X509_free); return ret; } Variant HHVM_FUNCTION(openssl_pkcs7_verify, const String& filename, int flags, const Variant& voutfilename /* = null_string */, const Variant& vcainfo /* = null_array */, const Variant& vextracerts /* = null_string */, const Variant& vcontent /* = null_string */) { return openssl_pkcs7_verify_core(filename, flags, voutfilename, vcainfo, vextracerts, vcontent, false); } static bool openssl_pkey_export_impl(const Variant& key, BIO *bio_out, const String& passphrase /* = null_string */, const Variant& configargs /* = uninit_variant */) { auto okey = Key::Get(key, false, passphrase.data()); if (!okey) { raise_warning("cannot get key from parameter 1"); return false; } EVP_PKEY *pkey = okey->m_key; struct php_x509_request req; memset(&req, 0, sizeof(req)); std::vector<String> strings; bool ret = false; if (php_openssl_parse_config(&req, configargs.toArray(), strings)) { const EVP_CIPHER *cipher; if (!passphrase.empty() && req.priv_key_encrypt) { cipher = (EVP_CIPHER *)EVP_des_ede3_cbc(); } else { cipher = nullptr; } assertx(bio_out); switch (EVP_PKEY_id(pkey)) { #ifdef HAVE_EVP_PKEY_EC case EVP_PKEY_EC: ret = PEM_write_bio_ECPrivateKey(bio_out, EVP_PKEY_get0_EC_KEY(pkey), cipher, (unsigned char *)passphrase.data(), passphrase.size(), nullptr, nullptr); break; #endif default: ret = PEM_write_bio_PrivateKey(bio_out, pkey, cipher, (unsigned char *)passphrase.data(), passphrase.size(), nullptr, nullptr); break; } } php_openssl_dispose_config(&req); return ret; } bool HHVM_FUNCTION(openssl_pkey_export_to_file, const Variant& key, const String& outfilename, const String& passphrase /* = null_string */, const Variant& configargs /* = uninit_variant */) { BIO *bio_out = BIO_new_file(outfilename.data(), "w"); if (bio_out == nullptr) { raise_warning("error opening the file, %s", outfilename.data()); return false; } bool ret = openssl_pkey_export_impl(key, bio_out, passphrase, configargs); BIO_free(bio_out); return ret; } bool HHVM_FUNCTION(openssl_pkey_export, const Variant& key, Variant& out, const String& passphrase /* = null_string */, const Variant& configargs /* = uninit_variant */) { BIO *bio_out = BIO_new(BIO_s_mem()); bool ret = openssl_pkey_export_impl(key, bio_out, passphrase, configargs); if (ret) { char *bio_mem_ptr; long bio_mem_len = BIO_get_mem_data(bio_out, &bio_mem_ptr); out = String(bio_mem_ptr, bio_mem_len, CopyString); } BIO_free(bio_out); return ret; } const StaticString s_bits("bits"), s_key("key"), s_type("type"), s_name("name"), s_hash("hash"), s_version("version"), s_serialNumber("serialNumber"), s_signatureAlgorithm("signatureAlgorithm"), s_validFrom("validFrom"), s_validTo("validTo"), s_validFrom_time_t("validFrom_time_t"), s_validTo_time_t("validTo_time_t"), s_alias("alias"), s_purposes("purposes"), s_extensions("extensions"), s_rsa("rsa"), s_dsa("dsa"), s_dh("dh"), s_ec("ec"), s_n("n"), s_e("e"), s_d("d"), s_p("p"), s_q("q"), s_g("g"), s_x("x"), s_y("y"), s_dmp1("dmp1"), s_dmq1("dmq1"), s_iqmp("iqmp"), s_priv_key("priv_key"), s_pub_key("pub_key"), s_curve_oid("curve_oid"); static void add_bignum_as_string(Array &arr, StaticString key, const BIGNUM *bn) { if (!bn) { return; } int num_bytes = BN_num_bytes(bn); String str{size_t(num_bytes), ReserveString}; BN_bn2bin(bn, (unsigned char*)str.mutableData()); str.setSize(num_bytes); arr.set(key, std::move(str)); } Array HHVM_FUNCTION(openssl_pkey_get_details, const Resource& key) { EVP_PKEY *pkey = cast<Key>(key)->m_key; BIO *out = BIO_new(BIO_s_mem()); PEM_write_bio_PUBKEY(out, pkey); char *pbio; unsigned int pbio_len = BIO_get_mem_data(out, &pbio); auto ret = make_darray( s_bits, EVP_PKEY_bits(pkey), s_key, String(pbio, pbio_len, CopyString) ); long ktype = -1; auto details = Array::CreateDArray(); switch (EVP_PKEY_id(pkey)) { case EVP_PKEY_RSA: case EVP_PKEY_RSA2: { ktype = OPENSSL_KEYTYPE_RSA; RSA *rsa = EVP_PKEY_get0_RSA(pkey); assertx(rsa); const BIGNUM *n, *e, *d, *p, *q, *dmp1, *dmq1, *iqmp; RSA_get0_key(rsa, &n, &e, &d); RSA_get0_factors(rsa, &p, &q); RSA_get0_crt_params(rsa, &dmp1, &dmq1, &iqmp); add_bignum_as_string(details, s_n, n); add_bignum_as_string(details, s_e, e); add_bignum_as_string(details, s_d, d); add_bignum_as_string(details, s_p, p); add_bignum_as_string(details, s_q, q); add_bignum_as_string(details, s_dmp1, dmp1); add_bignum_as_string(details, s_dmq1, dmq1); add_bignum_as_string(details, s_iqmp, iqmp); ret.set(s_rsa, details); break; } case EVP_PKEY_DSA: case EVP_PKEY_DSA2: case EVP_PKEY_DSA3: case EVP_PKEY_DSA4: { ktype = OPENSSL_KEYTYPE_DSA; DSA *dsa = EVP_PKEY_get0_DSA(pkey); assertx(dsa); const BIGNUM *p, *q, *g, *pub_key, *priv_key; DSA_get0_pqg(dsa, &p, &q, &g); DSA_get0_key(dsa, &pub_key, &priv_key); add_bignum_as_string(details, s_p, p); add_bignum_as_string(details, s_q, q); add_bignum_as_string(details, s_g, g); add_bignum_as_string(details, s_priv_key, priv_key); add_bignum_as_string(details, s_pub_key, pub_key); ret.set(s_dsa, details); break; } case EVP_PKEY_DH: { ktype = OPENSSL_KEYTYPE_DH; DH *dh = EVP_PKEY_get0_DH(pkey); assertx(dh); const BIGNUM *p, *q, *g, *pub_key, *priv_key; DH_get0_pqg(dh, &p, &q, &g); DH_get0_key(dh, &pub_key, &priv_key); add_bignum_as_string(details, s_p, p); add_bignum_as_string(details, s_g, g); add_bignum_as_string(details, s_priv_key, priv_key); add_bignum_as_string(details, s_pub_key, pub_key); ret.set(s_dh, details); break; } #ifdef HAVE_EVP_PKEY_EC case EVP_PKEY_EC: { ktype = OPENSSL_KEYTYPE_EC; auto const ec = EVP_PKEY_get0_EC_KEY(pkey); assertx(ec); auto const ec_group = EC_KEY_get0_group(ec); auto const nid = EC_GROUP_get_curve_name(ec_group); if (nid == NID_undef) { break; } auto const crv_sn = OBJ_nid2sn(nid); if (crv_sn != nullptr) { details.set(s_curve_name, String(crv_sn, CopyString)); } auto const obj = OBJ_nid2obj(nid); if (obj != nullptr) { SCOPE_EXIT { ASN1_OBJECT_free(obj); }; char oir_buf[256]; OBJ_obj2txt(oir_buf, sizeof(oir_buf) - 1, obj, 1); details.set(s_curve_oid, String(oir_buf, CopyString)); } auto x = BN_new(); auto y = BN_new(); SCOPE_EXIT { BN_free(x); BN_free(y); }; auto const pub = EC_KEY_get0_public_key(ec); if (EC_POINT_get_affine_coordinates_GFp(ec_group, pub, x, y, nullptr)) { add_bignum_as_string(details, s_x, x); add_bignum_as_string(details, s_y, y); } auto d = BN_dup(EC_KEY_get0_private_key(ec)); SCOPE_EXIT { BN_free(d); }; if (d != nullptr) { add_bignum_as_string(details, s_d, d); } ret.set(s_ec, details); } break; #endif } ret.set(s_type, ktype); BIO_free(out); return ret; } Variant HHVM_FUNCTION(openssl_pkey_get_private, const Variant& key, const String& passphrase /* = null_string */) { return toVariant(Key::Get(key, false, passphrase.data())); } Variant HHVM_FUNCTION(openssl_pkey_get_public, const Variant& certificate) { return toVariant(Key::Get(certificate, true)); } Variant HHVM_FUNCTION(openssl_pkey_new, const Variant& configargs /* = uninit_variant */) { struct php_x509_request req; memset(&req, 0, sizeof(req)); SCOPE_EXIT { php_openssl_dispose_config(&req); }; std::vector<String> strings; if (php_openssl_parse_config(&req, configargs.toArray(), strings) && req.generatePrivateKey()) { return Resource(req::make<Key>(req.priv_key)); } else { return false; } } bool HHVM_FUNCTION(openssl_private_decrypt, const String& data, Variant& decrypted, const Variant& key, int padding /* = k_OPENSSL_PKCS1_PADDING */) { auto okey = Key::Get(key, false); if (!okey) { raise_warning("key parameter is not a valid private key"); return false; } EVP_PKEY *pkey = okey->m_key; int cryptedlen = EVP_PKEY_size(pkey); String s = String(cryptedlen, ReserveString); unsigned char *cryptedbuf = (unsigned char *)s.mutableData(); int successful = 0; switch (EVP_PKEY_id(pkey)) { case EVP_PKEY_RSA: case EVP_PKEY_RSA2: cryptedlen = RSA_private_decrypt(data.size(), (unsigned char *)data.data(), cryptedbuf, EVP_PKEY_get0_RSA(pkey), padding); if (cryptedlen != -1) { successful = 1; } break; default: raise_warning("key type not supported"); } if (successful) { decrypted = s.setSize(cryptedlen); return true; } return false; } bool HHVM_FUNCTION(openssl_private_encrypt, const String& data, Variant& crypted, const Variant& key, int padding /* = k_OPENSSL_PKCS1_PADDING */) { auto okey = Key::Get(key, false); if (!okey) { raise_warning("key param is not a valid private key"); return false; } EVP_PKEY *pkey = okey->m_key; int cryptedlen = EVP_PKEY_size(pkey); String s = String(cryptedlen, ReserveString); unsigned char *cryptedbuf = (unsigned char *)s.mutableData(); int successful = 0; switch (EVP_PKEY_id(pkey)) { case EVP_PKEY_RSA: case EVP_PKEY_RSA2: successful = (RSA_private_encrypt(data.size(), (unsigned char *)data.data(), cryptedbuf, EVP_PKEY_get0_RSA(pkey), padding) == cryptedlen); break; default: raise_warning("key type not supported"); } if (successful) { crypted = s.setSize(cryptedlen); return true; } return false; } bool HHVM_FUNCTION(openssl_public_decrypt, const String& data, Variant& decrypted, const Variant& key, int padding /* = k_OPENSSL_PKCS1_PADDING */) { auto okey = Key::Get(key, true); if (!okey) { raise_warning("key parameter is not a valid public key"); return false; } EVP_PKEY *pkey = okey->m_key; int cryptedlen = EVP_PKEY_size(pkey); String s = String(cryptedlen, ReserveString); unsigned char *cryptedbuf = (unsigned char *)s.mutableData(); int successful = 0; switch (EVP_PKEY_id(pkey)) { case EVP_PKEY_RSA: case EVP_PKEY_RSA2: cryptedlen = RSA_public_decrypt(data.size(), (unsigned char *)data.data(), cryptedbuf, EVP_PKEY_get0_RSA(pkey), padding); if (cryptedlen != -1) { successful = 1; } break; default: raise_warning("key type not supported"); } if (successful) { decrypted = s.setSize(cryptedlen); return true; } return false; } bool HHVM_FUNCTION(openssl_public_encrypt, const String& data, Variant& crypted, const Variant& key, int padding /* = k_OPENSSL_PKCS1_PADDING */) { auto okey = Key::Get(key, true); if (!okey) { raise_warning("key parameter is not a valid public key"); return false; } EVP_PKEY *pkey = okey->m_key; int cryptedlen = EVP_PKEY_size(pkey); String s = String(cryptedlen, ReserveString); unsigned char *cryptedbuf = (unsigned char *)s.mutableData(); int successful = 0; switch (EVP_PKEY_id(pkey)) { case EVP_PKEY_RSA: case EVP_PKEY_RSA2: successful = (RSA_public_encrypt(data.size(), (unsigned char *)data.data(), cryptedbuf, EVP_PKEY_get0_RSA(pkey), padding) == cryptedlen); break; default: raise_warning("key type not supported"); } if (successful) { crypted = s.setSize(cryptedlen); return true; } return false; } Variant HHVM_FUNCTION(openssl_seal, const String& data, Variant& sealed_data, Variant& env_keys, const Array& pub_key_ids, const String& method, Variant& iv) { int nkeys = pub_key_ids.size(); if (nkeys == 0) { raise_warning("Fourth argument to openssl_seal() must be " "a non-empty array"); return false; } const EVP_CIPHER *cipher_type; if (method.empty()) { cipher_type = EVP_rc4(); } else { cipher_type = EVP_get_cipherbyname(method.c_str()); if (!cipher_type) { raise_warning("Unknown cipher algorithm"); return false; } } int iv_len = EVP_CIPHER_iv_length(cipher_type); unsigned char *iv_buf = nullptr; String iv_s; if (iv_len > 0) { iv_s = String(iv_len, ReserveString); iv_buf = (unsigned char*)iv_s.mutableData(); if (!RAND_bytes(iv_buf, iv_len)) { raise_warning("Could not generate an IV."); return false; } } EVP_PKEY **pkeys = (EVP_PKEY**)malloc(nkeys * sizeof(*pkeys)); int *eksl = (int*)malloc(nkeys * sizeof(*eksl)); unsigned char **eks = (unsigned char **)malloc(nkeys * sizeof(*eks)); memset(eks, 0, sizeof(*eks) * nkeys); // holder is needed to make sure none of the Keys get deleted prematurely. // The pkeys array points to elements inside of Keys returned from Key::Get() // which may be newly allocated and have no other owners. std::vector<req::ptr<Key>> holder; /* get the public keys we are using to seal this data */ bool ret = true; int i = 0; String s; unsigned char* buf = nullptr; EVP_CIPHER_CTX* ctx = nullptr; for (ArrayIter iter(pub_key_ids); iter; ++iter, ++i) { auto okey = Key::Get(iter.second(), true); if (!okey) { raise_warning("not a public key (%dth member of pubkeys)", i + 1); ret = false; goto clean_exit; } holder.push_back(okey); pkeys[i] = okey->m_key; eks[i] = (unsigned char *)malloc(EVP_PKEY_size(pkeys[i]) + 1); } ctx = EVP_CIPHER_CTX_new(); if (ctx == nullptr) { raise_warning("Failed to allocate an EVP_CIPHER_CTX object"); ret = false; goto clean_exit; } if (!EVP_EncryptInit_ex(ctx, cipher_type, nullptr, nullptr, nullptr)) { ret = false; goto clean_exit; } int len1, len2; s = String(data.size() + EVP_CIPHER_CTX_block_size(ctx), ReserveString); buf = (unsigned char *)s.mutableData(); if (EVP_SealInit(ctx, cipher_type, eks, eksl, iv_buf, pkeys, nkeys) <= 0 || !EVP_SealUpdate(ctx, buf, &len1, (unsigned char*)data.data(), data.size()) || !EVP_SealFinal(ctx, buf + len1, &len2)) { ret = false; goto clean_exit; } if (len1 + len2 > 0) { sealed_data = s.setSize(len1 + len2); auto ekeys = Array::CreateVArray(); for (i = 0; i < nkeys; i++) { eks[i][eksl[i]] = '\0'; ekeys.append(String((char*)eks[i], eksl[i], AttachString)); eks[i] = nullptr; } env_keys = ekeys; } clean_exit: for (i = 0; i < nkeys; i++) { if (eks[i]) free(eks[i]); } free(eks); free(eksl); free(pkeys); if (iv_buf != nullptr) { if (ret) { iv = iv_s.setSize(iv_len); } } if (ctx != nullptr) { EVP_CIPHER_CTX_free(ctx); } if (ret) return len1 + len2; return false; } static const EVP_MD *php_openssl_get_evp_md_from_algo(long algo) { switch (algo) { case OPENSSL_ALGO_SHA1: return EVP_sha1(); case OPENSSL_ALGO_MD5: return EVP_md5(); case OPENSSL_ALGO_MD4: return EVP_md4(); #ifdef HAVE_OPENSSL_MD2_H case OPENSSL_ALGO_MD2: return EVP_md2(); #endif #if OPENSSL_VERSION_NUMBER < 0x10100000L case OPENSSL_ALGO_DSS1: return EVP_dss1(); #endif #if OPENSSL_VERSION_NUMBER >= 0x0090708fL case OPENSSL_ALGO_SHA224: return EVP_sha224(); case OPENSSL_ALGO_SHA256: return EVP_sha256(); case OPENSSL_ALGO_SHA384: return EVP_sha384(); case OPENSSL_ALGO_SHA512: return EVP_sha512(); case OPENSSL_ALGO_RMD160: return EVP_ripemd160(); #endif } return nullptr; } bool HHVM_FUNCTION(openssl_sign, const String& data, Variant& signature, const Variant& priv_key_id, const Variant& signature_alg /* = k_OPENSSL_ALGO_SHA1 */) { auto okey = Key::Get(priv_key_id, false); if (!okey) { raise_warning("supplied key param cannot be coerced into a private key"); return false; } const EVP_MD *mdtype = nullptr; if (signature_alg.isInteger()) { mdtype = php_openssl_get_evp_md_from_algo(signature_alg.toInt64Val()); } else if (signature_alg.isString()) { mdtype = EVP_get_digestbyname(signature_alg.toString().data()); } if (!mdtype) { raise_warning("Unknown signature algorithm."); return false; } EVP_PKEY *pkey = okey->m_key; int siglen = EVP_PKEY_size(pkey); String s = String(siglen, ReserveString); unsigned char *sigbuf = (unsigned char *)s.mutableData(); EVP_MD_CTX *md_ctx = EVP_MD_CTX_new(); SCOPE_EXIT { EVP_MD_CTX_free(md_ctx); }; EVP_SignInit(md_ctx, mdtype); EVP_SignUpdate(md_ctx, (unsigned char *)data.data(), data.size()); if (EVP_SignFinal(md_ctx, sigbuf, (unsigned int *)&siglen, pkey)) { signature = s.setSize(siglen); return true; } return false; } Variant HHVM_FUNCTION(openssl_verify, const String& data, const String& signature, const Variant& pub_key_id, const Variant& signature_alg /* = k_OPENSSL_ALGO_SHA1 */) { int err; const EVP_MD *mdtype = nullptr; if (signature_alg.isInteger()) { mdtype = php_openssl_get_evp_md_from_algo(signature_alg.toInt64Val()); } else if (signature_alg.isString()) { mdtype = EVP_get_digestbyname(signature_alg.toString().data()); } if (!mdtype) { raise_warning("Unknown signature algorithm."); return false; } auto okey = Key::Get(pub_key_id, true); if (!okey) { raise_warning("supplied key param cannot be coerced into a public key"); return false; } EVP_MD_CTX *md_ctx = EVP_MD_CTX_new(); SCOPE_EXIT { EVP_MD_CTX_free(md_ctx); }; EVP_VerifyInit(md_ctx, mdtype); EVP_VerifyUpdate(md_ctx, (unsigned char*)data.data(), data.size()); err = EVP_VerifyFinal(md_ctx, (unsigned char *)signature.data(), signature.size(), okey->m_key); return err; } bool HHVM_FUNCTION(openssl_x509_check_private_key, const Variant& cert, const Variant& key) { auto ocert = Certificate::Get(cert); if (!ocert) { return false; } auto okey = Key::Get(key, false); if (!okey) { return false; } return X509_check_private_key(ocert->m_cert, okey->m_key); } static int check_cert(X509_STORE *ctx, X509 *x, STACK_OF(X509) *untrustedchain, int purpose) { X509_STORE_CTX *csc = X509_STORE_CTX_new(); if (csc == nullptr) { raise_warning("memory allocation failure"); return 0; } X509_STORE_CTX_init(csc, ctx, x, untrustedchain); if (purpose >= 0) { X509_STORE_CTX_set_purpose(csc, purpose); } int ret = X509_verify_cert(csc); X509_STORE_CTX_free(csc); return ret; } Variant HHVM_FUNCTION(openssl_x509_checkpurpose, const Variant& x509cert, int purpose, const Array& cainfo /* = null_array */, const String& untrustedfile /* = null_string */) { int ret = -1; STACK_OF(X509) *untrustedchain = nullptr; X509_STORE *pcainfo = nullptr; req::ptr<Certificate> ocert; if (!untrustedfile.empty()) { untrustedchain = load_all_certs_from_file(untrustedfile.data()); if (untrustedchain == nullptr) { goto clean_exit; } } pcainfo = setup_verify(cainfo); if (pcainfo == nullptr) { goto clean_exit; } ocert = Certificate::Get(x509cert); if (!ocert) { raise_warning("cannot get cert from parameter 1"); return false; } X509 *cert; cert = ocert->m_cert; assertx(cert); ret = check_cert(pcainfo, cert, untrustedchain, purpose); clean_exit: if (pcainfo) { X509_STORE_free(pcainfo); } if (untrustedchain) { sk_X509_pop_free(untrustedchain, X509_free); } return ret == 1 ? true : ret == 0 ? false : -1; } static bool openssl_x509_export_impl(const Variant& x509, BIO *bio_out, bool notext /* = true */) { auto ocert = Certificate::Get(x509); if (!ocert) { raise_warning("cannot get cert from parameter 1"); return false; } X509 *cert = ocert->m_cert; assertx(cert); assertx(bio_out); if (!notext) { X509_print(bio_out, cert); } return PEM_write_bio_X509(bio_out, cert); } bool HHVM_FUNCTION(openssl_x509_export_to_file, const Variant& x509, const String& outfilename, bool notext /* = true */) { BIO *bio_out = BIO_new_file((char*)outfilename.data(), "w"); if (bio_out == nullptr) { raise_warning("error opening file %s", outfilename.data()); return false; } bool ret = openssl_x509_export_impl(x509, bio_out, notext); BIO_free(bio_out); return ret; } bool HHVM_FUNCTION(openssl_x509_export, const Variant& x509, Variant& output, bool notext /* = true */) { BIO *bio_out = BIO_new(BIO_s_mem()); bool ret = openssl_x509_export_impl(x509, bio_out, notext); if (ret) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); output = String(bio_buf->data, bio_buf->length, CopyString); } BIO_free(bio_out); return ret; } /** * This is how the time string is formatted: * * snprintf(p, sizeof(p), "%02d%02d%02d%02d%02d%02dZ",ts->tm_year%100, * ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); */ static time_t asn1_time_to_time_t(ASN1_UTCTIME *timestr) { auto const timestr_type = ASN1_STRING_type(timestr); if (timestr_type != V_ASN1_UTCTIME && timestr_type != V_ASN1_GENERALIZEDTIME) { raise_warning("illegal ASN1 data type for timestamp"); return (time_t)-1; } auto const timestr_len = (size_t)ASN1_STRING_length(timestr); // Binary safety if (timestr_len != strlen((char*)ASN1_STRING_data(timestr))) { raise_warning("illegal length in timestamp"); return (time_t)-1; } if (timestr_len < 13 && timestr_len != 11) { raise_warning("unable to parse time string %s correctly", timestr->data); return (time_t)-1; } if (timestr_type == V_ASN1_GENERALIZEDTIME && timestr_len < 15) { raise_warning("unable to parse time string %s correctly", timestr->data); return (time_t)-1; } char *strbuf = strdup((char*)timestr->data); struct tm thetime; memset(&thetime, 0, sizeof(thetime)); /* we work backwards so that we can use atoi more easily */ char *thestr = strbuf + ASN1_STRING_length(timestr) - 3; if (ASN1_STRING_length(timestr) == 11) { thetime.tm_sec = 0; } else { thetime.tm_sec = atoi(thestr); *thestr = '\0'; thestr -= 2; } thetime.tm_min = atoi(thestr); *thestr = '\0'; thestr -= 2; thetime.tm_hour = atoi(thestr); *thestr = '\0'; thestr -= 2; thetime.tm_mday = atoi(thestr); *thestr = '\0'; thestr -= 2; thetime.tm_mon = atoi(thestr)-1; *thestr = '\0'; if (ASN1_STRING_type(timestr) == V_ASN1_UTCTIME) { thestr -= 2; thetime.tm_year = atoi(thestr); if (thetime.tm_year < 68) { thetime.tm_year += 100; } } else if (ASN1_STRING_type(timestr) == V_ASN1_GENERALIZEDTIME) { thestr -= 4; thetime.tm_year = atoi(thestr) - 1900; } thetime.tm_isdst = -1; time_t ret = mktime(&thetime); long gmadjust = 0; #if HAVE_TM_GMTOFF gmadjust = thetime.tm_gmtoff; #elif defined(_MSC_VER) TIME_ZONE_INFORMATION inf; GetTimeZoneInformation(&inf); gmadjust = thetime.tm_isdst ? inf.DaylightBias : inf.StandardBias; #else /** * If correcting for daylight savings time, we set the adjustment to * the value of timezone - 3600 seconds. Otherwise, we need to overcorrect * and set the adjustment to the main timezone + 3600 seconds. */ gmadjust = -(thetime.tm_isdst ? (long)timezone - 3600 : (long)timezone); #endif /* no adjustment for UTC */ if (timezone) ret += gmadjust; free(strbuf); return ret; } /* Special handling of subjectAltName, see CVE-2013-4073 * Christian Heimes */ static int openssl_x509v3_subjectAltName(BIO *bio, X509_EXTENSION *extension) { GENERAL_NAMES *names; const X509V3_EXT_METHOD *method = nullptr; long i, length, num; const unsigned char *p; method = X509V3_EXT_get(extension); if (method == nullptr) { return -1; } const auto data = X509_EXTENSION_get_data(extension); p = data->data; length = data->length; if (method->it) { names = (GENERAL_NAMES*)(ASN1_item_d2i(nullptr, &p, length, ASN1_ITEM_ptr(method->it))); } else { names = (GENERAL_NAMES*)(method->d2i(nullptr, &p, length)); } if (names == nullptr) { return -1; } num = sk_GENERAL_NAME_num(names); for (i = 0; i < num; i++) { GENERAL_NAME *name; ASN1_STRING *as; name = sk_GENERAL_NAME_value(names, i); switch (name->type) { case GEN_EMAIL: BIO_puts(bio, "email:"); as = name->d.rfc822Name; BIO_write(bio, ASN1_STRING_data(as), ASN1_STRING_length(as)); break; case GEN_DNS: BIO_puts(bio, "DNS:"); as = name->d.dNSName; BIO_write(bio, ASN1_STRING_data(as), ASN1_STRING_length(as)); break; case GEN_URI: BIO_puts(bio, "URI:"); as = name->d.uniformResourceIdentifier; BIO_write(bio, ASN1_STRING_data(as), ASN1_STRING_length(as)); break; default: /* use builtin print for GEN_OTHERNAME, GEN_X400, * GEN_EDIPARTY, GEN_DIRNAME, GEN_IPADD and GEN_RID */ GENERAL_NAME_print(bio, name); } /* trailing ', ' except for last element */ if (i < (num - 1)) { BIO_puts(bio, ", "); } } sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free); return 0; } Variant HHVM_FUNCTION(openssl_x509_parse, const Variant& x509cert, bool shortnames /* = true */) { auto ocert = Certificate::Get(x509cert); if (!ocert) { return false; } X509 *cert = ocert->m_cert; assertx(cert); auto ret = Array::CreateDArray(); const auto sn = X509_get_subject_name(cert); if (sn) { ret.set(s_name, String(X509_NAME_oneline(sn, nullptr, 0), CopyString)); } add_assoc_name_entry(ret, "subject", sn, shortnames); /* hash as used in CA directories to lookup cert by subject name */ { char buf[32]; snprintf(buf, sizeof(buf), "%08lx", X509_subject_name_hash(cert)); ret.set(s_hash, String(buf, CopyString)); } add_assoc_name_entry(ret, "issuer", X509_get_issuer_name(cert), shortnames); ret.set(s_version, X509_get_version(cert)); ret.set(s_serialNumber, String (i2s_ASN1_INTEGER(nullptr, X509_get_serialNumber(cert)), AttachString)); // Adding Signature Algorithm BIO *bio_out = BIO_new(BIO_s_mem()); SCOPE_EXIT { BIO_free(bio_out); }; if (i2a_ASN1_OBJECT(bio_out, X509_get0_tbs_sigalg(cert)->algorithm) > 0) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); ret.set(s_signatureAlgorithm, String((char*)bio_buf->data, bio_buf->length, CopyString)); } ASN1_STRING *str = X509_get_notBefore(cert); ret.set(s_validFrom, String((char*)str->data, str->length, CopyString)); str = X509_get_notAfter(cert); ret.set(s_validTo, String((char*)str->data, str->length, CopyString)); ret.set(s_validFrom_time_t, asn1_time_to_time_t(X509_get_notBefore(cert))); ret.set(s_validTo_time_t, asn1_time_to_time_t(X509_get_notAfter(cert))); char *tmpstr = (char *)X509_alias_get0(cert, nullptr); if (tmpstr) { ret.set(s_alias, String(tmpstr, CopyString)); } /* NOTE: the purposes are added as integer keys - the keys match up to the X509_PURPOSE_SSL_XXX defines in x509v3.h */ { Array subitem; for (int i = 0; i < X509_PURPOSE_get_count(); i++) { X509_PURPOSE *purp = X509_PURPOSE_get0(i); int id = X509_PURPOSE_get_id(purp); char * pname = shortnames ? X509_PURPOSE_get0_sname(purp) : X509_PURPOSE_get0_name(purp); auto subsub = make_varray( (bool)X509_check_purpose(cert, id, 0), (bool)X509_check_purpose(cert, id, 1), String(pname, CopyString) ); subitem.set(id, std::move(subsub)); } ret.set(s_purposes, subitem); } { auto subitem = Array::CreateDArray(); for (int i = 0; i < X509_get_ext_count(cert); i++) { int nid; X509_EXTENSION *extension = X509_get_ext(cert, i); char *extname; char buf[256]; nid = OBJ_obj2nid(X509_EXTENSION_get_object(extension)); if (nid != NID_undef) { extname = (char*)OBJ_nid2sn(OBJ_obj2nid (X509_EXTENSION_get_object(extension))); } else { OBJ_obj2txt(buf, sizeof(buf)-1, X509_EXTENSION_get_object(extension), 1); extname = buf; } BIO *bio_out = BIO_new(BIO_s_mem()); if (nid == NID_subject_alt_name) { if (openssl_x509v3_subjectAltName(bio_out, extension) == 0) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); subitem.set(String(extname, CopyString), String((char*)bio_buf->data, bio_buf->length, CopyString)); } else { BIO_free(bio_out); return false; } } else if (X509V3_EXT_print(bio_out, extension, 0, 0)) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); subitem.set(String(extname, CopyString), String((char*)bio_buf->data, bio_buf->length, CopyString)); } else { str = X509_EXTENSION_get_data(extension); subitem.set(String(extname, CopyString), String((char*)str->data, str->length, CopyString)); } BIO_free(bio_out); } ret.set(s_extensions, subitem); } return ret; } Variant HHVM_FUNCTION(openssl_x509_read, const Variant& x509certdata) { auto ocert = Certificate::Get(x509certdata); if (!ocert) { raise_warning("supplied parameter cannot be coerced into " "an X509 certificate!"); return false; } return Variant(ocert); } Variant HHVM_FUNCTION(openssl_random_pseudo_bytes, int length, bool& crypto_strong) { if (length <= 0) { return false; } unsigned char *buffer = nullptr; String s = String(length, ReserveString); buffer = (unsigned char *)s.mutableData(); if (RAND_bytes(buffer, length) <= 0) { crypto_strong = false; return false; } else { crypto_strong = true; s.setSize(length); return s; } } Variant HHVM_FUNCTION(openssl_cipher_iv_length, const String& method) { if (method.empty()) { raise_warning("Unknown cipher algorithm"); return false; } const EVP_CIPHER *cipher_type = EVP_get_cipherbyname(method.c_str()); if (!cipher_type) { raise_warning("Unknown cipher algorithm"); return false; } return EVP_CIPHER_iv_length(cipher_type); } /* Cipher mode info */ struct php_openssl_cipher_mode { /* Whether this mode uses authenticated encryption. True, for example, with the GCM and CCM modes */ bool is_aead; /* Whether this mode is a 'single run aead', meaning that DecryptFinal doesn't get called. For example, CCM mode is a single run aead mode. */ bool is_single_run_aead; /* The OpenSSL flag to get the computed tag, if this mode is aead. */ int aead_get_tag_flag; /* The OpenSSL flag to set the computed tag, if this mode is aead. */ int aead_set_tag_flag; /* The OpenSSL flag to set the IV length, if this mode is aead */ int aead_ivlen_flag; }; // initialize a php_openssl_cipher_mode corresponding to an EVP_CIPHER. static php_openssl_cipher_mode php_openssl_load_cipher_mode( const EVP_CIPHER* cipher_type) { php_openssl_cipher_mode mode = {}; switch (EVP_CIPHER_mode(cipher_type)) { #ifdef EVP_CIPH_GCM_MODE case EVP_CIPH_GCM_MODE: mode.is_aead = true; mode.is_single_run_aead = false; mode.aead_get_tag_flag = EVP_CTRL_GCM_GET_TAG; mode.aead_set_tag_flag = EVP_CTRL_GCM_SET_TAG; mode.aead_ivlen_flag = EVP_CTRL_GCM_SET_IVLEN; break; #endif #ifdef EVP_CIPH_CCM_MODE case EVP_CIPH_CCM_MODE: mode.is_aead = true; mode.is_single_run_aead = true; mode.aead_get_tag_flag = EVP_CTRL_CCM_GET_TAG; mode.aead_set_tag_flag = EVP_CTRL_CCM_SET_TAG; mode.aead_ivlen_flag = EVP_CTRL_CCM_SET_IVLEN; break; #endif default: break; } return mode; } static bool php_openssl_validate_iv( String piv, int iv_required_len, String& out, EVP_CIPHER_CTX* cipher_ctx, const php_openssl_cipher_mode* mode) { if (cipher_ctx == nullptr || mode == nullptr) { return false; } /* Best case scenario, user behaved */ if (piv.size() == iv_required_len) { out = std::move(piv); return true; } if (mode->is_aead) { if (EVP_CIPHER_CTX_ctrl( cipher_ctx, mode->aead_ivlen_flag, piv.size(), nullptr) != 1) { raise_warning( "Setting of IV length for AEAD mode failed, the expected length is " "%d bytes", iv_required_len); return false; } out = std::move(piv); return true; } String s = String(iv_required_len, ReserveString); char* iv_new = s.mutableData(); memset(iv_new, 0, iv_required_len); if (piv.size() <= 0) { /* BC behavior */ s.setSize(iv_required_len); out = std::move(s); return true; } if (piv.size() < iv_required_len) { raise_warning("IV passed is only %d bytes long, cipher " "expects an IV of precisely %d bytes, padding with \\0", piv.size(), iv_required_len); memcpy(iv_new, piv.data(), piv.size()); s.setSize(iv_required_len); out = std::move(s); return true; } raise_warning("IV passed is %d bytes long which is longer than the %d " "expected by selected cipher, truncating", piv.size(), iv_required_len); memcpy(iv_new, piv.data(), iv_required_len); s.setSize(iv_required_len); out = std::move(s); return true; } namespace { Variant openssl_encrypt_impl(const String& data, const String& method, const String& password, int options, const String& iv, Variant* tag_out, const String& aad, int tag_length) { const EVP_CIPHER *cipher_type = EVP_get_cipherbyname(method.c_str()); if (!cipher_type) { raise_warning("Unknown cipher algorithm"); return false; } EVP_CIPHER_CTX* cipher_ctx = EVP_CIPHER_CTX_new(); if (!cipher_ctx) { raise_warning("Failed to create cipher context"); return false; } SCOPE_EXIT { EVP_CIPHER_CTX_free(cipher_ctx); }; php_openssl_cipher_mode mode = php_openssl_load_cipher_mode(cipher_type); if (mode.is_aead && !tag_out) { raise_warning("Must call openssl_encrypt_with_tag when using an AEAD cipher"); return false; } int keylen = EVP_CIPHER_key_length(cipher_type); String key = password; /* * older openssl libraries can assert if the passed in password length is * less than keylen */ if (keylen > password.size()) { String s = String(keylen, ReserveString); char *keybuf = s.mutableData(); memset(keybuf, 0, keylen); memcpy(keybuf, password.data(), password.size()); key = s.setSize(keylen); } int max_iv_len = EVP_CIPHER_iv_length(cipher_type); if (iv.size() <= 0 && max_iv_len > 0 && !mode.is_aead) { raise_warning("Using an empty Initialization Vector (iv) is potentially " "insecure and not recommended"); } int result_len = 0; int outlen = data.size() + EVP_CIPHER_block_size(cipher_type); String rv = String(outlen, ReserveString); unsigned char *outbuf = (unsigned char*)rv.mutableData(); EVP_EncryptInit_ex(cipher_ctx, cipher_type, nullptr, nullptr, nullptr); String new_iv; // we do this after EncryptInit because validate_iv changes cipher_ctx for // aead modes (must be initialized first). if (!php_openssl_validate_iv( std::move(iv), max_iv_len, new_iv, cipher_ctx, &mode)) { return false; } // set the tag length for CCM mode/other modes that require tag lengths to // be set. if (mode.is_single_run_aead && !EVP_CIPHER_CTX_ctrl( cipher_ctx, mode.aead_set_tag_flag, tag_length, nullptr)) { raise_warning("Setting tag length failed"); return false; } if (password.size() > keylen) { EVP_CIPHER_CTX_set_key_length(cipher_ctx, password.size()); } EVP_EncryptInit_ex( cipher_ctx, nullptr, nullptr, (unsigned char*)key.data(), (unsigned char*)new_iv.data()); if (options & k_OPENSSL_ZERO_PADDING) { EVP_CIPHER_CTX_set_padding(cipher_ctx, 0); } // for single run aeads like CCM, we need to provide the length of the // plaintext before providing AAD or ciphertext. if (mode.is_single_run_aead && !EVP_EncryptUpdate( cipher_ctx, nullptr, &result_len, nullptr, data.size())) { raise_warning("Setting of data length failed"); return false; } // set up aad: if (mode.is_aead && !EVP_EncryptUpdate( cipher_ctx, nullptr, &result_len, (unsigned char*)aad.data(), aad.size())) { raise_warning("Setting of additional application data failed"); return false; } // OpenSSL before 0.9.8i asserts with size < 0 if (data.size() >= 0) { EVP_EncryptUpdate(cipher_ctx, outbuf, &result_len, (unsigned char *)data.data(), data.size()); } outlen = result_len; if (EVP_EncryptFinal_ex( cipher_ctx, (unsigned char*)outbuf + result_len, &result_len)) { outlen += result_len; rv.setSize(outlen); // Get tag if possible if (mode.is_aead) { String tagrv = String(tag_length, ReserveString); if (EVP_CIPHER_CTX_ctrl( cipher_ctx, mode.aead_get_tag_flag, tag_length, tagrv.mutableData()) == 1) { tagrv.setSize(tag_length); assertx(tag_out); *tag_out = tagrv; } else { raise_warning("Retrieving authentication tag failed"); return false; } } else if (tag_out) { raise_warning( "The authenticated tag cannot be provided for cipher that does not" " support AEAD"); } // Return encrypted data if (options & k_OPENSSL_RAW_DATA) { return rv; } else { return StringUtil::Base64Encode(rv); } } return false; } } // anonymous namespace Variant HHVM_FUNCTION(openssl_encrypt, const String& data, const String& method, const String& password, int options /* = 0 */, const String& iv /* = null_string */, const String& aad /* = null_string */, int tag_length /* = 16 */) { return openssl_encrypt_impl(data, method, password, options, iv, nullptr, aad, tag_length); } Variant HHVM_FUNCTION(openssl_encrypt_with_tag, const String& data, const String& method, const String& password, int options, const String& iv, Variant& tag_out, const String& aad /* = null_string */, int tag_length /* = 16 */) { return openssl_encrypt_impl(data, method, password, options, iv, &tag_out, aad, tag_length); } Variant HHVM_FUNCTION(openssl_decrypt, const String& data, const String& method, const String& password, int options /* = 0 */, const String& iv /* = null_string */, const String& tag /* = null_string */, const String& aad /* = null_string */) { const EVP_CIPHER *cipher_type = EVP_get_cipherbyname(method.c_str()); if (!cipher_type) { raise_warning("Unknown cipher algorithm"); return false; } EVP_CIPHER_CTX* cipher_ctx = EVP_CIPHER_CTX_new(); if (!cipher_ctx) { raise_warning("Failed to create cipher context"); return false; } SCOPE_EXIT { EVP_CIPHER_CTX_free(cipher_ctx); }; php_openssl_cipher_mode mode = php_openssl_load_cipher_mode(cipher_type); String decoded_data = data; if (!(options & k_OPENSSL_RAW_DATA)) { decoded_data = StringUtil::Base64Decode(data); } int keylen = EVP_CIPHER_key_length(cipher_type); String key = password; /* * older openssl libraries can assert if the passed in password length is * less than keylen */ if (keylen > password.size()) { String s = String(keylen, ReserveString); char *keybuf = s.mutableData(); memset(keybuf, 0, keylen); memcpy(keybuf, password.data(), password.size()); key = s.setSize(keylen); } int result_len = 0; int outlen = decoded_data.size() + EVP_CIPHER_block_size(cipher_type); String rv = String(outlen, ReserveString); unsigned char *outbuf = (unsigned char*)rv.mutableData(); EVP_DecryptInit_ex(cipher_ctx, cipher_type, nullptr, nullptr, nullptr); String new_iv; // we do this after DecryptInit because validate_iv changes cipher_ctx for // aead modes (must be initialized first). if (!php_openssl_validate_iv( std::move(iv), EVP_CIPHER_iv_length(cipher_type), new_iv, cipher_ctx, &mode)) { return false; } // set the tag if required: if (tag.size() > 0) { if (!mode.is_aead) { raise_warning( "The tag is being ignored because the cipher method does not" " support AEAD"); } else if (!EVP_CIPHER_CTX_ctrl( cipher_ctx, mode.aead_set_tag_flag, tag.size(), (unsigned char*)tag.data())) { raise_warning("Setting tag for AEAD cipher decryption failed"); return false; } } else { if (mode.is_aead) { raise_warning("A tag should be provided when using AEAD mode"); return false; } } if (password.size() > keylen) { EVP_CIPHER_CTX_set_key_length(cipher_ctx, password.size()); } EVP_DecryptInit_ex( cipher_ctx, nullptr, nullptr, (unsigned char*)key.data(), (unsigned char*)new_iv.data()); if (options & k_OPENSSL_ZERO_PADDING) { EVP_CIPHER_CTX_set_padding(cipher_ctx, 0); } // for single run aeads like CCM, we need to provide the length of the // ciphertext before providing AAD or ciphertext. if (mode.is_single_run_aead && !EVP_DecryptUpdate( cipher_ctx, nullptr, &result_len, nullptr, decoded_data.size())) { raise_warning("Setting of data length failed"); return false; } // set up aad: if (mode.is_aead && !EVP_DecryptUpdate( cipher_ctx, nullptr, &result_len, (unsigned char*)aad.data(), aad.size())) { raise_warning("Setting of additional application data failed"); return false; } if (!EVP_DecryptUpdate( cipher_ctx, outbuf, &result_len, (unsigned char*)decoded_data.data(), decoded_data.size())) { return false; } outlen = result_len; // if is_single_run_aead is enabled, DecryptFinal shouldn't be called. // if something went wrong in this case, we would've caught it at // DecryptUpdate. if (mode.is_single_run_aead || EVP_DecryptFinal_ex( cipher_ctx, (unsigned char*)outbuf + result_len, &result_len)) { // don't want to do this if is_single_run_aead was enabled, since we didn't // make a call to EVP_DecryptFinal. if (!mode.is_single_run_aead) { outlen += result_len; } rv.setSize(outlen); return rv; } else { return false; } } Variant HHVM_FUNCTION(openssl_digest, const String& data, const String& method, bool raw_output /* = false */) { const EVP_MD *mdtype = EVP_get_digestbyname(method.c_str()); if (!mdtype) { raise_warning("Unknown signature algorithm"); return false; } int siglen = EVP_MD_size(mdtype); String rv = String(siglen, ReserveString); unsigned char *sigbuf = (unsigned char *)rv.mutableData(); EVP_MD_CTX *md_ctx = EVP_MD_CTX_new(); SCOPE_EXIT { EVP_MD_CTX_free(md_ctx); }; EVP_DigestInit(md_ctx, mdtype); EVP_DigestUpdate(md_ctx, (unsigned char *)data.data(), data.size()); if (EVP_DigestFinal(md_ctx, (unsigned char *)sigbuf, (unsigned int *)&siglen)) { if (raw_output) { rv.setSize(siglen); return rv; } else { char* digest_str = string_bin2hex((char*)sigbuf, siglen); return String(digest_str, AttachString); } } else { return false; } } static void openssl_add_method_or_alias(const OBJ_NAME *name, void *arg) { Array *ret = (Array*)arg; ret->append(String((char *)name->name, CopyString)); } static void openssl_add_method(const OBJ_NAME *name, void *arg) { if (name->alias == 0) { Array *ret = (Array*)arg; ret->append(String((char *)name->name, CopyString)); } } Array HHVM_FUNCTION(openssl_get_cipher_methods, bool aliases /* = false */) { Array ret = Array::CreateVArray(); OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_CIPHER_METH, aliases ? openssl_add_method_or_alias: openssl_add_method, &ret); return ret; } Variant HHVM_FUNCTION(openssl_get_curve_names) { #ifdef HAVE_EVP_PKEY_EC const size_t len = EC_get_builtin_curves(nullptr, 0); std::unique_ptr<EC_builtin_curve[]> curves(new EC_builtin_curve[len]); if (!EC_get_builtin_curves(curves.get(), len)) { return false; } VArrayInit ret(len); for (size_t i = 0; i < len; ++i) { auto const sname = OBJ_nid2sn(curves[i].nid); if (sname != nullptr) { ret.append(String(sname, CopyString)); } } return ret.toArray(); #else return false; #endif } Array HHVM_FUNCTION(openssl_get_md_methods, bool aliases /* = false */) { Array ret = Array::CreateVArray(); OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_MD_METH, aliases ? openssl_add_method_or_alias: openssl_add_method, &ret); return ret; } ///////////////////////////////////////////////////////////////////////////// const StaticString s_OPENSSL_VERSION_TEXT("OPENSSL_VERSION_TEXT"); struct opensslExtension final : Extension { opensslExtension() : Extension("openssl") {} void moduleInit() override { HHVM_RC_INT(OPENSSL_RAW_DATA, k_OPENSSL_RAW_DATA); HHVM_RC_INT(OPENSSL_ZERO_PADDING, k_OPENSSL_ZERO_PADDING); HHVM_RC_INT(OPENSSL_NO_PADDING, k_OPENSSL_NO_PADDING); HHVM_RC_INT(OPENSSL_PKCS1_OAEP_PADDING, k_OPENSSL_PKCS1_OAEP_PADDING); HHVM_RC_INT(OPENSSL_SSLV23_PADDING, k_OPENSSL_SSLV23_PADDING); HHVM_RC_INT(OPENSSL_PKCS1_PADDING, k_OPENSSL_PKCS1_PADDING); HHVM_RC_INT_SAME(OPENSSL_ALGO_SHA1); HHVM_RC_INT_SAME(OPENSSL_ALGO_MD5); HHVM_RC_INT_SAME(OPENSSL_ALGO_MD4); #ifdef HAVE_OPENSSL_MD2_H HHVM_RC_INT_SAME(OPENSSL_ALGO_MD2); #endif HHVM_RC_INT_SAME(OPENSSL_ALGO_DSS1); HHVM_RC_INT_SAME(OPENSSL_ALGO_SHA224); HHVM_RC_INT_SAME(OPENSSL_ALGO_SHA256); HHVM_RC_INT_SAME(OPENSSL_ALGO_SHA384); HHVM_RC_INT_SAME(OPENSSL_ALGO_SHA512); HHVM_RC_INT_SAME(OPENSSL_ALGO_RMD160); HHVM_RC_INT(OPENSSL_CIPHER_RC2_40, PHP_OPENSSL_CIPHER_RC2_40); HHVM_RC_INT(OPENSSL_CIPHER_RC2_128, PHP_OPENSSL_CIPHER_RC2_128); HHVM_RC_INT(OPENSSL_CIPHER_RC2_64, PHP_OPENSSL_CIPHER_RC2_64); HHVM_RC_INT(OPENSSL_CIPHER_DES, PHP_OPENSSL_CIPHER_DES); HHVM_RC_INT(OPENSSL_CIPHER_3DES, PHP_OPENSSL_CIPHER_3DES); HHVM_RC_INT_SAME(OPENSSL_KEYTYPE_RSA); HHVM_RC_INT_SAME(OPENSSL_KEYTYPE_DSA); HHVM_RC_INT_SAME(OPENSSL_KEYTYPE_DH); #ifdef HAVE_EVP_PKEY_EC HHVM_RC_INT_SAME(OPENSSL_KEYTYPE_EC); #endif HHVM_RC_INT_SAME(OPENSSL_VERSION_NUMBER); HHVM_RC_INT_SAME(PKCS7_TEXT); HHVM_RC_INT_SAME(PKCS7_NOCERTS); HHVM_RC_INT_SAME(PKCS7_NOSIGS); HHVM_RC_INT_SAME(PKCS7_NOCHAIN); HHVM_RC_INT_SAME(PKCS7_NOINTERN); HHVM_RC_INT_SAME(PKCS7_NOVERIFY); HHVM_RC_INT_SAME(PKCS7_DETACHED); HHVM_RC_INT_SAME(PKCS7_BINARY); HHVM_RC_INT_SAME(PKCS7_NOATTR); HHVM_RC_STR_SAME(OPENSSL_VERSION_TEXT); HHVM_RC_INT_SAME(X509_PURPOSE_SSL_CLIENT); HHVM_RC_INT_SAME(X509_PURPOSE_SSL_SERVER); HHVM_RC_INT_SAME(X509_PURPOSE_NS_SSL_SERVER); HHVM_RC_INT_SAME(X509_PURPOSE_SMIME_SIGN); HHVM_RC_INT_SAME(X509_PURPOSE_SMIME_ENCRYPT); HHVM_RC_INT_SAME(X509_PURPOSE_CRL_SIGN); #ifdef X509_PURPOSE_ANY HHVM_RC_INT_SAME(X509_PURPOSE_ANY); #endif HHVM_FE(openssl_csr_export_to_file); HHVM_FE(openssl_csr_export); HHVM_FE(openssl_csr_get_public_key); HHVM_FE(openssl_csr_get_subject); HHVM_FE(openssl_csr_new); HHVM_FE(openssl_csr_sign); HHVM_FE(openssl_error_string); HHVM_FE(openssl_open); HHVM_FE(openssl_pkcs12_export_to_file); HHVM_FE(openssl_pkcs12_export); HHVM_FE(openssl_pkcs12_read); HHVM_FE(openssl_pkcs7_decrypt); HHVM_FE(openssl_pkcs7_encrypt); HHVM_FE(openssl_pkcs7_sign); HHVM_FE(openssl_pkcs7_verify); HHVM_FE(openssl_pkey_export_to_file); HHVM_FE(openssl_pkey_export); HHVM_FE(openssl_pkey_get_details); HHVM_FE(openssl_pkey_get_private); HHVM_FE(openssl_pkey_get_public); HHVM_FE(openssl_pkey_new); HHVM_FE(openssl_private_decrypt); HHVM_FE(openssl_private_encrypt); HHVM_FE(openssl_public_decrypt); HHVM_FE(openssl_public_encrypt); HHVM_FE(openssl_seal); HHVM_FE(openssl_sign); HHVM_FE(openssl_verify); HHVM_FE(openssl_x509_check_private_key); HHVM_FE(openssl_x509_checkpurpose); HHVM_FE(openssl_x509_export_to_file); HHVM_FE(openssl_x509_export); HHVM_FE(openssl_x509_parse); HHVM_FE(openssl_x509_read); HHVM_FE(openssl_random_pseudo_bytes); HHVM_FE(openssl_cipher_iv_length); HHVM_FE(openssl_encrypt); HHVM_FE(openssl_encrypt_with_tag); HHVM_FE(openssl_decrypt); HHVM_FE(openssl_digest); HHVM_FE(openssl_get_cipher_methods); HHVM_FE(openssl_get_curve_names); HHVM_FE(openssl_get_md_methods); loadSystemlib(); } } s_openssl_extension; /////////////////////////////////////////////////////////////////////////////// }
15409
True
1
CVE-2020-1921
False
False
False
False
AV:N/AC:L/Au:N/C:N/I:N/A:P
NETWORK
LOW
NONE
NONE
NONE
PARTIAL
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
NONE
NONE
HIGH
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In the crypt function, we attempt to null terminate a buffer using the size of the input salt without validating that the offset is within the buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::php_openssl_config_check_syntax
HPHP::php_openssl_config_check_syntax( const char * section_label , const char * config_filename , const char * section , LHASH_OF(CONF_VALUE) * config)
['section_label', 'config_filename', 'section', 'config']
static inline bool php_openssl_config_check_syntax (const char *section_label, const char *config_filename, const char *section, LHASH_OF(CONF_VALUE) *config) { #else static inline bool php_openssl_config_check_syntax (const char *section_label, const char *config_filename, const char *section, LHASH *config) { #endif X509V3_CTX ctx; X509V3_set_ctx_test(&ctx); X509V3_set_conf_lhash(&ctx, config); if (!X509V3_EXT_add_conf(config, &ctx, (char*)section, nullptr)) { raise_warning("Error loading %s section %s of %s", section_label, section, config_filename); return false; } return true; } const StaticString s_config("config"), s_config_section_name("config_section_name"), s_digest_alg("digest_alg"), s_x509_extensions("x509_extensions"), s_req_extensions("req_extensions"), s_private_key_bits("private_key_bits"), s_private_key_type("private_key_type"), s_encrypt_key("encrypt_key"), s_curve_name("curve_name"); static bool php_openssl_parse_config(struct php_x509_request *req, const Array& args, std::vector<String> &strings) { req->config_filename = read_string(args, s_config, default_ssl_conf_filename, strings); req->section_name = read_string(args, s_config_section_name, "req", strings); req->global_config = CONF_load(nullptr, default_ssl_conf_filename, nullptr); req->req_config = CONF_load(nullptr, req->config_filename, nullptr); if (req->req_config == nullptr) { return false; } /* read in the oids */ char *str = CONF_get_string(req->req_config, nullptr, "oid_file"); if (str) { BIO *oid_bio = BIO_new_file(str, "r"); if (oid_bio) { OBJ_create_objects(oid_bio); BIO_free(oid_bio); } } if (!add_oid_section(req)) { return false; } req->digest_name = read_string(args, s_digest_alg, CONF_get_string(req->req_config, req->section_name, "default_md"), strings); req->extensions_section = read_string(args, s_x509_extensions, CONF_get_string(req->req_config, req->section_name, "x509_extensions"), strings); req->request_extensions_section = read_string(args, s_req_extensions, CONF_get_string(req->req_config, req->section_name, "req_extensions"), strings); req->priv_key_bits = read_integer(args, s_private_key_bits, CONF_get_number(req->req_config, req->section_name, "default_bits")); req->priv_key_type = read_integer(args, s_private_key_type, OPENSSL_KEYTYPE_DEFAULT); if (args.exists(s_encrypt_key)) { bool value = args[s_encrypt_key].toBoolean(); req->priv_key_encrypt = value ? 1 : 0; } else { str = CONF_get_string(req->req_config, req->section_name, "encrypt_rsa_key"); if (str == nullptr) { str = CONF_get_string(req->req_config, req->section_name, "encrypt_key"); } if (str && strcmp(str, "no") == 0) { req->priv_key_encrypt = 0; } else { req->priv_key_encrypt = 1; } } /* digest alg */ if (req->digest_name == nullptr) { req->digest_name = CONF_get_string(req->req_config, req->section_name, "default_md"); } if (req->digest_name) { req->digest = req->md_alg = EVP_get_digestbyname(req->digest_name); } if (req->md_alg == nullptr) { req->md_alg = req->digest = EVP_sha256(); } #ifdef HAVE_EVP_PKEY_EC /* set the ec group curve name */ req->curve_name = NID_undef; if (args.exists(s_curve_name)) { auto const curve_name = args[s_curve_name].toString(); req->curve_name = OBJ_sn2nid(curve_name.data()); if (req->curve_name == NID_undef) { raise_warning( "Unknown elliptic curve (short) name %s", curve_name.data() ); return false; } } #endif if (req->extensions_section && !php_openssl_config_check_syntax ("extensions_section", req->config_filename, req->extensions_section, req->req_config)) { return false; } /* set the string mask */ str = CONF_get_string(req->req_config, req->section_name, "string_mask"); if (str && !ASN1_STRING_set_default_mask_asc(str)) { raise_warning("Invalid global string mask setting %s", str); return false; } if (req->request_extensions_section && !php_openssl_config_check_syntax ("request_extensions_section", req->config_filename, req->request_extensions_section, req->req_config)) { return false; } return true; } static void php_openssl_dispose_config(struct php_x509_request *req) { if (req->global_config) { CONF_free(req->global_config); req->global_config = nullptr; } if (req->req_config) { CONF_free(req->req_config); req->req_config = nullptr; } } static STACK_OF(X509) *load_all_certs_from_file(const char *certfile) { STACK_OF(X509_INFO) *sk = nullptr; STACK_OF(X509) *stack = nullptr, *ret = nullptr; BIO *in = nullptr; X509_INFO *xi; if (!(stack = sk_X509_new_null())) { raise_warning("memory allocation failure"); goto end; } if (!(in = BIO_new_file(certfile, "r"))) { raise_warning("error opening the file, %s", certfile); sk_X509_free(stack); goto end; } /* This loads from a file, a stack of x509/crl/pkey sets */ if (!(sk = PEM_X509_INFO_read_bio(in, nullptr, nullptr, nullptr))) { raise_warning("error reading the file, %s", certfile); sk_X509_free(stack); goto end; } /* scan over it and pull out the certs */ while (sk_X509_INFO_num(sk)) { xi = sk_X509_INFO_shift(sk); if (xi->x509 != nullptr) { sk_X509_push(stack, xi->x509); xi->x509 = nullptr; } X509_INFO_free(xi); } if (!sk_X509_num(stack)) { raise_warning("no certificates in file, %s", certfile); sk_X509_free(stack); goto end; } ret = stack; end: BIO_free(in); sk_X509_INFO_free(sk); return ret; } /** * calist is an array containing file and directory names. create a * certificate store and add those certs to it for use in verification. */ static X509_STORE *setup_verify(const Array& calist) { X509_STORE *store = X509_STORE_new(); if (store == nullptr) { return nullptr; } X509_LOOKUP *dir_lookup, *file_lookup; int ndirs = 0, nfiles = 0; for (ArrayIter iter(calist); iter; ++iter) { String item = iter.second().toString(); struct stat sb; if (stat(item.data(), &sb) == -1) { raise_warning("unable to stat %s", item.data()); continue; } if ((sb.st_mode & S_IFREG) == S_IFREG) { file_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()); if (file_lookup == nullptr || !X509_LOOKUP_load_file(file_lookup, item.data(), X509_FILETYPE_PEM)) { raise_warning("error loading file %s", item.data()); } else { nfiles++; } file_lookup = nullptr; } else { dir_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir()); if (dir_lookup == nullptr || !X509_LOOKUP_add_dir(dir_lookup, item.data(), X509_FILETYPE_PEM)) { raise_warning("error loading directory %s", item.data()); } else { ndirs++; } dir_lookup = nullptr; } } if (nfiles == 0) { file_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()); if (file_lookup) { X509_LOOKUP_load_file(file_lookup, nullptr, X509_FILETYPE_DEFAULT); } } if (ndirs == 0) { dir_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir()); if (dir_lookup) { X509_LOOKUP_add_dir(dir_lookup, nullptr, X509_FILETYPE_DEFAULT); } } return store; } /////////////////////////////////////////////////////////////////////////////// static bool add_entries(X509_NAME *subj, const Array& items) { for (ArrayIter iter(items); iter; ++iter) { auto const index = iter.first().toString(); auto const item = iter.second().toString(); int nid = OBJ_txt2nid(index.data()); if (nid != NID_undef) { if (!X509_NAME_add_entry_by_NID(subj, nid, MBSTRING_ASC, (unsigned char*)item.data(), -1, -1, 0)) { raise_warning("dn: add_entry_by_NID %d -> %s (failed)", nid, item.data()); return false; } } else { raise_warning("dn: %s is not a recognized name", index.data()); } } return true; } static bool php_openssl_make_REQ(struct php_x509_request *req, X509_REQ *csr, const Array& dn, const Array& attribs) { char *dn_sect = CONF_get_string(req->req_config, req->section_name, "distinguished_name"); if (dn_sect == nullptr) return false; STACK_OF(CONF_VALUE) *dn_sk = CONF_get_section(req->req_config, dn_sect); if (dn_sk == nullptr) return false; char *attr_sect = CONF_get_string(req->req_config, req->section_name, "attributes"); STACK_OF(CONF_VALUE) *attr_sk = nullptr; if (attr_sect) { attr_sk = CONF_get_section(req->req_config, attr_sect); if (attr_sk == nullptr) { return false; } } /* setup the version number: version 1 */ if (X509_REQ_set_version(csr, 0L)) { X509_NAME *subj = X509_REQ_get_subject_name(csr); if (!add_entries(subj, dn)) return false; /* Finally apply defaults from config file */ for (int i = 0; i < sk_CONF_VALUE_num(dn_sk); i++) { CONF_VALUE *v = sk_CONF_VALUE_value(dn_sk, i); char *type = v->name; int len = strlen(type); if (len < (int)sizeof("_default")) { continue; } len -= sizeof("_default") - 1; if (strcmp("_default", type + len) != 0) { continue; } if (len > 200) { len = 200; } char buffer[200 + 1]; /*200 + \0 !*/ memcpy(buffer, type, len); buffer[len] = '\0'; type = buffer; /* Skip past any leading X. X: X, etc to allow for multiple instances */ for (char *str = type; *str; str++) { if (*str == ':' || *str == ',' || *str == '.') { str++; if (*str) { type = str; } break; } } /* if it is already set, skip this */ int nid = OBJ_txt2nid(type); if (X509_NAME_get_index_by_NID(subj, nid, -1) >= 0) { continue; } if (!X509_NAME_add_entry_by_txt(subj, type, MBSTRING_ASC, (unsigned char*)v->value, -1, -1, 0)) { raise_warning("add_entry_by_txt %s -> %s (failed)", type, v->value); return false; } if (!X509_NAME_entry_count(subj)) { raise_warning("no objects specified in config file"); return false; } } if (!add_entries(subj, attribs)) return false; if (attr_sk) { for (int i = 0; i < sk_CONF_VALUE_num(attr_sk); i++) { CONF_VALUE *v = sk_CONF_VALUE_value(attr_sk, i); /* if it is already set, skip this */ int nid = OBJ_txt2nid(v->name); if (X509_REQ_get_attr_by_NID(csr, nid, -1) >= 0) { continue; } if (!X509_REQ_add1_attr_by_txt(csr, v->name, MBSTRING_ASC, (unsigned char*)v->value, -1)) { /** * hzhao: mismatched version of conf file may have attributes that * are not recognizable, and I don't think it should be treated as * fatal errors. */ Logger::Verbose("add1_attr_by_txt %s -> %s (failed)", v->name, v->value); // return false; } } } } X509_REQ_set_pubkey(csr, req->priv_key); return true; } bool HHVM_FUNCTION(openssl_csr_export_to_file, const Variant& csr, const String& outfilename, bool notext /* = true */) { auto pcsr = CSRequest::Get(csr); if (!pcsr) return false; BIO *bio_out = BIO_new_file((char*)outfilename.data(), "w"); if (bio_out == nullptr) { raise_warning("error opening file %s", outfilename.data()); return false; } if (!notext) { X509_REQ_print(bio_out, pcsr->csr()); } PEM_write_bio_X509_REQ(bio_out, pcsr->csr()); BIO_free(bio_out); return true; } bool HHVM_FUNCTION(openssl_csr_export, const Variant& csr, Variant& out, bool notext /* = true */) { auto pcsr = CSRequest::Get(csr); if (!pcsr) return false; BIO *bio_out = BIO_new(BIO_s_mem()); if (!notext) { X509_REQ_print(bio_out, pcsr->csr()); } if (PEM_write_bio_X509_REQ(bio_out, pcsr->csr())) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); out = String((char*)bio_buf->data, bio_buf->length, CopyString); BIO_free(bio_out); return true; } BIO_free(bio_out); return false; } Variant HHVM_FUNCTION(openssl_csr_get_public_key, const Variant& csr) { auto pcsr = CSRequest::Get(csr); if (!pcsr) return false; auto input_csr = pcsr->csr(); #if OPENSSL_VERSION_NUMBER >= 0x10100000 /* Due to changes in OpenSSL 1.1 related to locking when decoding CSR, * the pub key is not changed after assigning. It means if we pass * a private key, it will be returned including the private part. * If we duplicate it, then we get just the public part which is * the same behavior as for OpenSSL 1.0 */ input_csr = X509_REQ_dup(input_csr); /* We need to free the CSR as it was duplicated */ SCOPE_EXIT { X509_REQ_free(input_csr); }; #endif auto pubkey = X509_REQ_get_pubkey(input_csr); if (!pubkey) return false; return Variant(req::make<Key>(pubkey)); } Variant HHVM_FUNCTION(openssl_csr_get_subject, const Variant& csr, bool use_shortnames /* = true */) { auto pcsr = CSRequest::Get(csr); if (!pcsr) return false; X509_NAME *subject = X509_REQ_get_subject_name(pcsr->csr()); Array ret = Array::CreateDArray(); add_assoc_name_entry(ret, nullptr, subject, use_shortnames); return ret; } Variant HHVM_FUNCTION(openssl_csr_new, const Variant& dn, Variant& privkey, const Variant& configargs /* = uninit_variant */, const Variant& extraattribs /* = uninit_variant */) { Variant ret = false; struct php_x509_request req; memset(&req, 0, sizeof(req)); req::ptr<Key> okey; X509_REQ *csr = nullptr; std::vector<String> strings; if (php_openssl_parse_config(&req, configargs.toArray(), strings)) { /* Generate or use a private key */ if (!privkey.isNull()) { okey = Key::Get(privkey, false); if (okey) { req.priv_key = okey->m_key; } } if (req.priv_key == nullptr) { req.generatePrivateKey(); if (req.priv_key) { okey = req::make<Key>(req.priv_key); } } if (req.priv_key == nullptr) { raise_warning("Unable to generate a private key"); } else { csr = X509_REQ_new(); if (csr && php_openssl_make_REQ(&req, csr, dn.toArray(), extraattribs.toArray())) { X509V3_CTX ext_ctx; X509V3_set_ctx(&ext_ctx, nullptr, nullptr, csr, nullptr, 0); X509V3_set_conf_lhash(&ext_ctx, req.req_config); /* Add extensions */ if (req.request_extensions_section && !X509V3_EXT_REQ_add_conf(req.req_config, &ext_ctx, (char*)req.request_extensions_section, csr)) { raise_warning("Error loading extension section %s", req.request_extensions_section); } else { ret = true; if (X509_REQ_sign(csr, req.priv_key, req.digest)) { ret = req::make<CSRequest>(csr); csr = nullptr; } else { raise_warning("Error signing request"); } privkey = Variant(okey); } } } } if (csr) { X509_REQ_free(csr); } php_openssl_dispose_config(&req); return ret; } Variant HHVM_FUNCTION(openssl_csr_sign, const Variant& csr, const Variant& cacert, const Variant& priv_key, int days, const Variant& configargs /* = null */, int serial /* = 0 */) { auto pcsr = CSRequest::Get(csr); if (!pcsr) return false; req::ptr<Certificate> ocert; if (!cacert.isNull()) { ocert = Certificate::Get(cacert); if (!ocert) { raise_warning("cannot get cert from parameter 2"); return false; } } auto okey = Key::Get(priv_key, false); if (!okey) { raise_warning("cannot get private key from parameter 3"); return false; } X509 *cert = nullptr; if (ocert) { cert = ocert->m_cert; } EVP_PKEY *pkey = okey->m_key; if (cert && !X509_check_private_key(cert, pkey)) { raise_warning("private key does not correspond to signing cert"); return false; } req::ptr<Certificate> onewcert; struct php_x509_request req; memset(&req, 0, sizeof(req)); Variant ret = false; std::vector<String> strings; if (!php_openssl_parse_config(&req, configargs.toArray(), strings)) { goto cleanup; } /* Check that the request matches the signature */ EVP_PKEY *key; key = X509_REQ_get_pubkey(pcsr->csr()); if (key == nullptr) { raise_warning("error unpacking public key"); goto cleanup; } int i; i = X509_REQ_verify(pcsr->csr(), key); if (i < 0) { raise_warning("Signature verification problems"); goto cleanup; } if (i == 0) { raise_warning("Signature did not match the certificate request"); goto cleanup; } /* Now we can get on with it */ X509 *new_cert; new_cert = X509_new(); if (new_cert == nullptr) { raise_warning("No memory"); goto cleanup; } onewcert = req::make<Certificate>(new_cert); /* Version 3 cert */ if (!X509_set_version(new_cert, 2)) { goto cleanup; } ASN1_INTEGER_set(X509_get_serialNumber(new_cert), serial); X509_set_subject_name(new_cert, X509_REQ_get_subject_name(pcsr->csr())); if (cert == nullptr) { cert = new_cert; } if (!X509_set_issuer_name(new_cert, X509_get_subject_name(cert))) { goto cleanup; } X509_gmtime_adj(X509_get_notBefore(new_cert), 0); X509_gmtime_adj(X509_get_notAfter(new_cert), (long)60 * 60 * 24 * days); i = X509_set_pubkey(new_cert, key); if (!i) { goto cleanup; } if (req.extensions_section) { X509V3_CTX ctx; X509V3_set_ctx(&ctx, cert, new_cert, pcsr->csr(), nullptr, 0); X509V3_set_conf_lhash(&ctx, req.req_config); if (!X509V3_EXT_add_conf(req.req_config, &ctx, (char*)req.extensions_section, new_cert)) { goto cleanup; } } /* Now sign it */ if (!X509_sign(new_cert, pkey, req.digest)) { raise_warning("failed to sign it"); goto cleanup; } /* Succeeded; lets return the cert */ ret = onewcert; cleanup: php_openssl_dispose_config(&req); return ret; } Variant HHVM_FUNCTION(openssl_error_string) { char buf[512]; unsigned long val = ERR_get_error(); if (val) { return String(ERR_error_string(val, buf), CopyString); } return false; } bool HHVM_FUNCTION(openssl_open, const String& sealed_data, Variant& open_data, const String& env_key, const Variant& priv_key_id, const String& method, /* = null_string */ const String& iv /* = null_string */) { const EVP_CIPHER *cipher_type; if (method.empty()) { cipher_type = EVP_rc4(); } else { cipher_type = EVP_get_cipherbyname(method.c_str()); if (!cipher_type) { raise_warning("Unknown cipher algorithm"); return false; } } auto okey = Key::Get(priv_key_id, false); if (!okey) { raise_warning("unable to coerce parameter 4 into a private key"); return false; } EVP_PKEY *pkey = okey->m_key; const unsigned char *iv_buf = nullptr; int iv_len = EVP_CIPHER_iv_length(cipher_type); if (iv_len > 0) { if (iv.empty()) { raise_warning( "Cipher algorithm requires an IV to be supplied as a sixth parameter"); return false; } if (iv.length() != iv_len) { raise_warning("IV length is invalid"); return false; } iv_buf = reinterpret_cast<const unsigned char*>(iv.c_str()); } String s = String(sealed_data.size(), ReserveString); unsigned char *buf = (unsigned char *)s.mutableData(); EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new(); if (ctx == nullptr) { raise_warning("Failed to allocate an EVP_CIPHER_CTX object"); return false; } SCOPE_EXIT { EVP_CIPHER_CTX_free(ctx); }; int len1, len2; if (!EVP_OpenInit( ctx, cipher_type, (unsigned char*)env_key.data(), env_key.size(), iv_buf, pkey) || !EVP_OpenUpdate( ctx, buf, &len1, (unsigned char*)sealed_data.data(), sealed_data.size()) || !EVP_OpenFinal(ctx, buf + len1, &len2) || len1 + len2 == 0) { return false; } open_data = s.setSize(len1 + len2); return true; } static STACK_OF(X509) *php_array_to_X509_sk(const Variant& certs) { STACK_OF(X509) *pcerts = sk_X509_new_null(); Array arrCerts; if (certs.isArray()) { arrCerts = certs.toArray(); } else { arrCerts.append(certs); } for (ArrayIter iter(arrCerts); iter; ++iter) { auto ocert = Certificate::Get(iter.second()); if (!ocert) { break; } sk_X509_push(pcerts, ocert->m_cert); } return pcerts; } const StaticString s_friendly_name("friendly_name"), s_extracerts("extracerts"); static bool openssl_pkcs12_export_impl(const Variant& x509, BIO *bio_out, const Variant& priv_key, const String& pass, const Variant& args /* = uninit_variant */) { auto ocert = Certificate::Get(x509); if (!ocert) { raise_warning("cannot get cert from parameter 1"); return false; } auto okey = Key::Get(priv_key, false); if (!okey) { raise_warning("cannot get private key from parameter 3"); return false; } X509 *cert = ocert->m_cert; EVP_PKEY *key = okey->m_key; if (cert && !X509_check_private_key(cert, key)) { raise_warning("private key does not correspond to cert"); return false; } Array arrArgs = args.toArray(); String friendly_name; if (arrArgs.exists(s_friendly_name)) { friendly_name = arrArgs[s_friendly_name].toString(); } STACK_OF(X509) *ca = nullptr; if (arrArgs.exists(s_extracerts)) { ca = php_array_to_X509_sk(arrArgs[s_extracerts]); } PKCS12 *p12 = PKCS12_create ((char*)pass.data(), (char*)(friendly_name.empty() ? nullptr : friendly_name.data()), key, cert, ca, 0, 0, 0, 0, 0); assertx(bio_out); bool ret = i2d_PKCS12_bio(bio_out, p12); PKCS12_free(p12); sk_X509_free(ca); return ret; } bool HHVM_FUNCTION(openssl_pkcs12_export_to_file, const Variant& x509, const String& filename, const Variant& priv_key, const String& pass, const Variant& args /* = uninit_variant */) { BIO *bio_out = BIO_new_file(filename.data(), "w"); if (bio_out == nullptr) { raise_warning("error opening file %s", filename.data()); return false; } bool ret = openssl_pkcs12_export_impl(x509, bio_out, priv_key, pass, args); BIO_free(bio_out); return ret; } bool HHVM_FUNCTION(openssl_pkcs12_export, const Variant& x509, Variant& out, const Variant& priv_key, const String& pass, const Variant& args /* = uninit_variant */) { BIO *bio_out = BIO_new(BIO_s_mem()); bool ret = openssl_pkcs12_export_impl(x509, bio_out, priv_key, pass, args); if (ret) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); out = String((char*)bio_buf->data, bio_buf->length, CopyString); } BIO_free(bio_out); return ret; } const StaticString s_cert("cert"), s_pkey("pkey"); bool HHVM_FUNCTION(openssl_pkcs12_read, const String& pkcs12, Variant& certs, const String& pass) { bool ret = false; PKCS12 *p12 = nullptr; BIO *bio_in = BIO_new(BIO_s_mem()); if (!BIO_write(bio_in, pkcs12.data(), pkcs12.size())) { goto cleanup; } if (d2i_PKCS12_bio(bio_in, &p12)) { EVP_PKEY *pkey = nullptr; X509 *cert = nullptr; STACK_OF(X509) *ca = nullptr; if (PKCS12_parse(p12, pass.data(), &pkey, &cert, &ca)) { Variant vcerts = Array::CreateDArray(); SCOPE_EXIT { certs = vcerts; }; BIO *bio_out = nullptr; if (cert) { bio_out = BIO_new(BIO_s_mem()); if (PEM_write_bio_X509(bio_out, cert)) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); vcerts.asArrRef().set(s_cert, String((char*)bio_buf->data, bio_buf->length, CopyString)); } BIO_free(bio_out); } if (pkey) { bio_out = BIO_new(BIO_s_mem()); if (PEM_write_bio_PrivateKey(bio_out, pkey, nullptr, nullptr, 0, 0, nullptr)) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); vcerts.asArrRef().set(s_pkey, String((char*)bio_buf->data, bio_buf->length, CopyString)); } BIO_free(bio_out); } if (ca) { Array extracerts; for (X509 *aCA = sk_X509_pop(ca); aCA; aCA = sk_X509_pop(ca)) { bio_out = BIO_new(BIO_s_mem()); if (PEM_write_bio_X509(bio_out, aCA)) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); extracerts.append(String((char*)bio_buf->data, bio_buf->length, CopyString)); } BIO_free(bio_out); X509_free(aCA); } sk_X509_free(ca); vcerts.asArrRef().set(s_extracerts, extracerts); } ret = true; PKCS12_free(p12); } } cleanup: if (bio_in) { BIO_free(bio_in); } return ret; } bool HHVM_FUNCTION(openssl_pkcs7_decrypt, const String& infilename, const String& outfilename, const Variant& recipcert, const Variant& recipkey /* = uninit_variant */) { bool ret = false; BIO *in = nullptr, *out = nullptr, *datain = nullptr; PKCS7 *p7 = nullptr; req::ptr<Key> okey; auto ocert = Certificate::Get(recipcert); if (!ocert) { raise_warning("unable to coerce parameter 3 to x509 cert"); goto clean_exit; } okey = Key::Get(recipkey.isNull() ? recipcert : recipkey, false); if (!okey) { raise_warning("unable to get private key"); goto clean_exit; } in = BIO_new_file(infilename.data(), "r"); if (in == nullptr) { raise_warning("error opening the file, %s", infilename.data()); goto clean_exit; } out = BIO_new_file(outfilename.data(), "w"); if (out == nullptr) { raise_warning("error opening the file, %s", outfilename.data()); goto clean_exit; } p7 = SMIME_read_PKCS7(in, &datain); if (p7 == nullptr) { goto clean_exit; } assertx(okey->m_key); assertx(ocert->m_cert); if (PKCS7_decrypt(p7, okey->m_key, ocert->m_cert, out, PKCS7_DETACHED)) { ret = true; } clean_exit: PKCS7_free(p7); BIO_free(datain); BIO_free(in); BIO_free(out); return ret; } static void print_headers(BIO *outfile, const Array& headers) { if (!headers.isNull()) { if (headers->isVectorData()) { for (ArrayIter iter(headers); iter; ++iter) { BIO_printf(outfile, "%s\n", iter.second().toString().data()); } } else { for (ArrayIter iter(headers); iter; ++iter) { BIO_printf(outfile, "%s: %s\n", iter.first().toString().data(), iter.second().toString().data()); } } } } bool HHVM_FUNCTION(openssl_pkcs7_encrypt, const String& infilename, const String& outfilename, const Variant& recipcerts, const Array& headers, int flags /* = 0 */, int cipherid /* = k_OPENSSL_CIPHER_RC2_40 */) { bool ret = false; BIO *infile = nullptr, *outfile = nullptr; STACK_OF(X509) *precipcerts = nullptr; PKCS7 *p7 = nullptr; const EVP_CIPHER *cipher = nullptr; infile = BIO_new_file(infilename.data(), (flags & PKCS7_BINARY) ? "rb" : "r"); if (infile == nullptr) { raise_warning("error opening the file, %s", infilename.data()); goto clean_exit; } outfile = BIO_new_file(outfilename.data(), "w"); if (outfile == nullptr) { raise_warning("error opening the file, %s", outfilename.data()); goto clean_exit; } precipcerts = php_array_to_X509_sk(recipcerts); /* sanity check the cipher */ switch (cipherid) { #ifndef OPENSSL_NO_RC2 case PHP_OPENSSL_CIPHER_RC2_40: cipher = EVP_rc2_40_cbc(); break; case PHP_OPENSSL_CIPHER_RC2_64: cipher = EVP_rc2_64_cbc(); break; case PHP_OPENSSL_CIPHER_RC2_128: cipher = EVP_rc2_cbc(); break; #endif #ifndef OPENSSL_NO_DES case PHP_OPENSSL_CIPHER_DES: cipher = EVP_des_cbc(); break; case PHP_OPENSSL_CIPHER_3DES: cipher = EVP_des_ede3_cbc(); break; #endif default: raise_warning("Invalid cipher type `%d'", cipherid); goto clean_exit; } if (cipher == nullptr) { raise_warning("Failed to get cipher"); goto clean_exit; } p7 = PKCS7_encrypt(precipcerts, infile, (EVP_CIPHER*)cipher, flags); if (p7 == nullptr) goto clean_exit; print_headers(outfile, headers); (void)BIO_reset(infile); SMIME_write_PKCS7(outfile, p7, infile, flags); ret = true; clean_exit: PKCS7_free(p7); BIO_free(infile); BIO_free(outfile); sk_X509_free(precipcerts); return ret; } bool HHVM_FUNCTION(openssl_pkcs7_sign, const String& infilename, const String& outfilename, const Variant& signcert, const Variant& privkey, const Variant& headers, int flags /* = k_PKCS7_DETACHED */, const String& extracerts /* = null_string */) { bool ret = false; STACK_OF(X509) *others = nullptr; BIO *infile = nullptr, *outfile = nullptr; PKCS7 *p7 = nullptr; req::ptr<Key> okey; req::ptr<Certificate> ocert; if (!extracerts.empty()) { others = load_all_certs_from_file(extracerts.data()); if (others == nullptr) { goto clean_exit; } } okey = Key::Get(privkey, false); if (!okey) { raise_warning("error getting private key"); goto clean_exit; } EVP_PKEY *key; key = okey->m_key; ocert = Certificate::Get(signcert); if (!ocert) { raise_warning("error getting cert"); goto clean_exit; } X509 *cert; cert = ocert->m_cert; infile = BIO_new_file(infilename.data(), (flags & PKCS7_BINARY) ? "rb" : "r"); if (infile == nullptr) { raise_warning("error opening input file %s!", infilename.data()); goto clean_exit; } outfile = BIO_new_file(outfilename.data(), "w"); if (outfile == nullptr) { raise_warning("error opening output file %s!", outfilename.data()); goto clean_exit; } p7 = PKCS7_sign(cert, key, others, infile, flags); if (p7 == nullptr) { raise_warning("error creating PKCS7 structure!"); goto clean_exit; } print_headers(outfile, headers.toArray()); (void)BIO_reset(infile); SMIME_write_PKCS7(outfile, p7, infile, flags); ret = true; clean_exit: PKCS7_free(p7); BIO_free(infile); BIO_free(outfile); if (others) { sk_X509_pop_free(others, X509_free); } return ret; } static int pkcs7_ignore_expiration(int ok, X509_STORE_CTX *ctx) { if (ok) { return ok; } int error = X509_STORE_CTX_get_error(ctx); if (error == X509_V_ERR_CERT_HAS_EXPIRED) { // ignore cert expirations Logger::Verbose("Ignoring cert expiration"); return 1; } return ok; } /** * NOTE: when ignore_cert_expiration is true, a custom certificate validation * callback is set up. Please be aware of this if you modify the function to * allow other certificate validation behaviors */ Variant openssl_pkcs7_verify_core( const String& filename, int flags, const Variant& voutfilename /* = null_string */, const Variant& vcainfo /* = null_array */, const Variant& vextracerts /* = null_string */, const Variant& vcontent /* = null_string */, bool ignore_cert_expiration ) { Variant ret = -1; X509_STORE *store = nullptr; BIO *in = nullptr; PKCS7 *p7 = nullptr; BIO *datain = nullptr; BIO *dataout = nullptr; auto cainfo = vcainfo.toArray(); auto extracerts = vextracerts.toString(); auto content = vcontent.toString(); STACK_OF(X509) *others = nullptr; if (!extracerts.empty()) { others = load_all_certs_from_file(extracerts.data()); if (others == nullptr) { goto clean_exit; } } flags = flags & ~PKCS7_DETACHED; store = setup_verify(cainfo); if (!store) { goto clean_exit; } if (ignore_cert_expiration) { #if (OPENSSL_VERSION_NUMBER >= 0x10000000) // make sure no other callback is specified #if OPENSSL_VERSION_NUMBER >= 0x10100000L assertx(!X509_STORE_get_verify_cb(store)); #else assertx(!store->verify_cb); #endif // ignore expired certs X509_STORE_set_verify_cb(store, pkcs7_ignore_expiration); #else always_assert(false); #endif } in = BIO_new_file(filename.data(), (flags & PKCS7_BINARY) ? "rb" : "r"); if (in == nullptr) { raise_warning("error opening the file, %s", filename.data()); goto clean_exit; } p7 = SMIME_read_PKCS7(in, &datain); if (p7 == nullptr) { goto clean_exit; } if (!content.empty()) { dataout = BIO_new_file(content.data(), "w"); if (dataout == nullptr) { raise_warning("error opening the file, %s", content.data()); goto clean_exit; } } if (PKCS7_verify(p7, others, store, datain, dataout, flags)) { ret = true; auto outfilename = voutfilename.toString(); if (!outfilename.empty()) { BIO *certout = BIO_new_file(outfilename.data(), "w"); if (certout) { STACK_OF(X509) *signers = PKCS7_get0_signers(p7, nullptr, flags); for (int i = 0; i < sk_X509_num(signers); i++) { PEM_write_bio_X509(certout, sk_X509_value(signers, i)); } BIO_free(certout); sk_X509_free(signers); } else { raise_warning("signature OK, but cannot open %s for writing", outfilename.data()); ret = -1; } } goto clean_exit; } else { ret = false; } clean_exit: X509_STORE_free(store); BIO_free(datain); BIO_free(in); BIO_free(dataout); PKCS7_free(p7); sk_X509_pop_free(others, X509_free); return ret; } Variant HHVM_FUNCTION(openssl_pkcs7_verify, const String& filename, int flags, const Variant& voutfilename /* = null_string */, const Variant& vcainfo /* = null_array */, const Variant& vextracerts /* = null_string */, const Variant& vcontent /* = null_string */) { return openssl_pkcs7_verify_core(filename, flags, voutfilename, vcainfo, vextracerts, vcontent, false); } static bool openssl_pkey_export_impl(const Variant& key, BIO *bio_out, const String& passphrase /* = null_string */, const Variant& configargs /* = uninit_variant */) { auto okey = Key::Get(key, false, passphrase.data()); if (!okey) { raise_warning("cannot get key from parameter 1"); return false; } EVP_PKEY *pkey = okey->m_key; struct php_x509_request req; memset(&req, 0, sizeof(req)); std::vector<String> strings; bool ret = false; if (php_openssl_parse_config(&req, configargs.toArray(), strings)) { const EVP_CIPHER *cipher; if (!passphrase.empty() && req.priv_key_encrypt) { cipher = (EVP_CIPHER *)EVP_des_ede3_cbc(); } else { cipher = nullptr; } assertx(bio_out); switch (EVP_PKEY_id(pkey)) { #ifdef HAVE_EVP_PKEY_EC case EVP_PKEY_EC: ret = PEM_write_bio_ECPrivateKey(bio_out, EVP_PKEY_get0_EC_KEY(pkey), cipher, (unsigned char *)passphrase.data(), passphrase.size(), nullptr, nullptr); break; #endif default: ret = PEM_write_bio_PrivateKey(bio_out, pkey, cipher, (unsigned char *)passphrase.data(), passphrase.size(), nullptr, nullptr); break; } } php_openssl_dispose_config(&req); return ret; } bool HHVM_FUNCTION(openssl_pkey_export_to_file, const Variant& key, const String& outfilename, const String& passphrase /* = null_string */, const Variant& configargs /* = uninit_variant */) { BIO *bio_out = BIO_new_file(outfilename.data(), "w"); if (bio_out == nullptr) { raise_warning("error opening the file, %s", outfilename.data()); return false; } bool ret = openssl_pkey_export_impl(key, bio_out, passphrase, configargs); BIO_free(bio_out); return ret; } bool HHVM_FUNCTION(openssl_pkey_export, const Variant& key, Variant& out, const String& passphrase /* = null_string */, const Variant& configargs /* = uninit_variant */) { BIO *bio_out = BIO_new(BIO_s_mem()); bool ret = openssl_pkey_export_impl(key, bio_out, passphrase, configargs); if (ret) { char *bio_mem_ptr; long bio_mem_len = BIO_get_mem_data(bio_out, &bio_mem_ptr); out = String(bio_mem_ptr, bio_mem_len, CopyString); } BIO_free(bio_out); return ret; } const StaticString s_bits("bits"), s_key("key"), s_type("type"), s_name("name"), s_hash("hash"), s_version("version"), s_serialNumber("serialNumber"), s_signatureAlgorithm("signatureAlgorithm"), s_validFrom("validFrom"), s_validTo("validTo"), s_validFrom_time_t("validFrom_time_t"), s_validTo_time_t("validTo_time_t"), s_alias("alias"), s_purposes("purposes"), s_extensions("extensions"), s_rsa("rsa"), s_dsa("dsa"), s_dh("dh"), s_ec("ec"), s_n("n"), s_e("e"), s_d("d"), s_p("p"), s_q("q"), s_g("g"), s_x("x"), s_y("y"), s_dmp1("dmp1"), s_dmq1("dmq1"), s_iqmp("iqmp"), s_priv_key("priv_key"), s_pub_key("pub_key"), s_curve_oid("curve_oid"); static void add_bignum_as_string(Array &arr, StaticString key, const BIGNUM *bn) { if (!bn) { return; } int num_bytes = BN_num_bytes(bn); String str{size_t(num_bytes), ReserveString}; BN_bn2bin(bn, (unsigned char*)str.mutableData()); str.setSize(num_bytes); arr.set(key, std::move(str)); } Array HHVM_FUNCTION(openssl_pkey_get_details, const Resource& key) { EVP_PKEY *pkey = cast<Key>(key)->m_key; BIO *out = BIO_new(BIO_s_mem()); PEM_write_bio_PUBKEY(out, pkey); char *pbio; unsigned int pbio_len = BIO_get_mem_data(out, &pbio); auto ret = make_darray( s_bits, EVP_PKEY_bits(pkey), s_key, String(pbio, pbio_len, CopyString) ); long ktype = -1; auto details = Array::CreateDArray(); switch (EVP_PKEY_id(pkey)) { case EVP_PKEY_RSA: case EVP_PKEY_RSA2: { ktype = OPENSSL_KEYTYPE_RSA; RSA *rsa = EVP_PKEY_get0_RSA(pkey); assertx(rsa); const BIGNUM *n, *e, *d, *p, *q, *dmp1, *dmq1, *iqmp; RSA_get0_key(rsa, &n, &e, &d); RSA_get0_factors(rsa, &p, &q); RSA_get0_crt_params(rsa, &dmp1, &dmq1, &iqmp); add_bignum_as_string(details, s_n, n); add_bignum_as_string(details, s_e, e); add_bignum_as_string(details, s_d, d); add_bignum_as_string(details, s_p, p); add_bignum_as_string(details, s_q, q); add_bignum_as_string(details, s_dmp1, dmp1); add_bignum_as_string(details, s_dmq1, dmq1); add_bignum_as_string(details, s_iqmp, iqmp); ret.set(s_rsa, details); break; } case EVP_PKEY_DSA: case EVP_PKEY_DSA2: case EVP_PKEY_DSA3: case EVP_PKEY_DSA4: { ktype = OPENSSL_KEYTYPE_DSA; DSA *dsa = EVP_PKEY_get0_DSA(pkey); assertx(dsa); const BIGNUM *p, *q, *g, *pub_key, *priv_key; DSA_get0_pqg(dsa, &p, &q, &g); DSA_get0_key(dsa, &pub_key, &priv_key); add_bignum_as_string(details, s_p, p); add_bignum_as_string(details, s_q, q); add_bignum_as_string(details, s_g, g); add_bignum_as_string(details, s_priv_key, priv_key); add_bignum_as_string(details, s_pub_key, pub_key); ret.set(s_dsa, details); break; } case EVP_PKEY_DH: { ktype = OPENSSL_KEYTYPE_DH; DH *dh = EVP_PKEY_get0_DH(pkey); assertx(dh); const BIGNUM *p, *q, *g, *pub_key, *priv_key; DH_get0_pqg(dh, &p, &q, &g); DH_get0_key(dh, &pub_key, &priv_key); add_bignum_as_string(details, s_p, p); add_bignum_as_string(details, s_g, g); add_bignum_as_string(details, s_priv_key, priv_key); add_bignum_as_string(details, s_pub_key, pub_key); ret.set(s_dh, details); break; } #ifdef HAVE_EVP_PKEY_EC case EVP_PKEY_EC: { ktype = OPENSSL_KEYTYPE_EC; auto const ec = EVP_PKEY_get0_EC_KEY(pkey); assertx(ec); auto const ec_group = EC_KEY_get0_group(ec); auto const nid = EC_GROUP_get_curve_name(ec_group); if (nid == NID_undef) { break; } auto const crv_sn = OBJ_nid2sn(nid); if (crv_sn != nullptr) { details.set(s_curve_name, String(crv_sn, CopyString)); } auto const obj = OBJ_nid2obj(nid); if (obj != nullptr) { SCOPE_EXIT { ASN1_OBJECT_free(obj); }; char oir_buf[256]; OBJ_obj2txt(oir_buf, sizeof(oir_buf) - 1, obj, 1); details.set(s_curve_oid, String(oir_buf, CopyString)); } auto x = BN_new(); auto y = BN_new(); SCOPE_EXIT { BN_free(x); BN_free(y); }; auto const pub = EC_KEY_get0_public_key(ec); if (EC_POINT_get_affine_coordinates_GFp(ec_group, pub, x, y, nullptr)) { add_bignum_as_string(details, s_x, x); add_bignum_as_string(details, s_y, y); } auto d = BN_dup(EC_KEY_get0_private_key(ec)); SCOPE_EXIT { BN_free(d); }; if (d != nullptr) { add_bignum_as_string(details, s_d, d); } ret.set(s_ec, details); } break; #endif } ret.set(s_type, ktype); BIO_free(out); return ret; } Variant HHVM_FUNCTION(openssl_pkey_get_private, const Variant& key, const String& passphrase /* = null_string */) { return toVariant(Key::Get(key, false, passphrase.data())); } Variant HHVM_FUNCTION(openssl_pkey_get_public, const Variant& certificate) { return toVariant(Key::Get(certificate, true)); } Variant HHVM_FUNCTION(openssl_pkey_new, const Variant& configargs /* = uninit_variant */) { struct php_x509_request req; memset(&req, 0, sizeof(req)); SCOPE_EXIT { php_openssl_dispose_config(&req); }; std::vector<String> strings; if (php_openssl_parse_config(&req, configargs.toArray(), strings) && req.generatePrivateKey()) { return Resource(req::make<Key>(req.priv_key)); } else { return false; } } bool HHVM_FUNCTION(openssl_private_decrypt, const String& data, Variant& decrypted, const Variant& key, int padding /* = k_OPENSSL_PKCS1_PADDING */) { auto okey = Key::Get(key, false); if (!okey) { raise_warning("key parameter is not a valid private key"); return false; } EVP_PKEY *pkey = okey->m_key; int cryptedlen = EVP_PKEY_size(pkey); String s = String(cryptedlen, ReserveString); unsigned char *cryptedbuf = (unsigned char *)s.mutableData(); int successful = 0; switch (EVP_PKEY_id(pkey)) { case EVP_PKEY_RSA: case EVP_PKEY_RSA2: cryptedlen = RSA_private_decrypt(data.size(), (unsigned char *)data.data(), cryptedbuf, EVP_PKEY_get0_RSA(pkey), padding); if (cryptedlen != -1) { successful = 1; } break; default: raise_warning("key type not supported"); } if (successful) { decrypted = s.setSize(cryptedlen); return true; } return false; } bool HHVM_FUNCTION(openssl_private_encrypt, const String& data, Variant& crypted, const Variant& key, int padding /* = k_OPENSSL_PKCS1_PADDING */) { auto okey = Key::Get(key, false); if (!okey) { raise_warning("key param is not a valid private key"); return false; } EVP_PKEY *pkey = okey->m_key; int cryptedlen = EVP_PKEY_size(pkey); String s = String(cryptedlen, ReserveString); unsigned char *cryptedbuf = (unsigned char *)s.mutableData(); int successful = 0; switch (EVP_PKEY_id(pkey)) { case EVP_PKEY_RSA: case EVP_PKEY_RSA2: successful = (RSA_private_encrypt(data.size(), (unsigned char *)data.data(), cryptedbuf, EVP_PKEY_get0_RSA(pkey), padding) == cryptedlen); break; default: raise_warning("key type not supported"); } if (successful) { crypted = s.setSize(cryptedlen); return true; } return false; } bool HHVM_FUNCTION(openssl_public_decrypt, const String& data, Variant& decrypted, const Variant& key, int padding /* = k_OPENSSL_PKCS1_PADDING */) { auto okey = Key::Get(key, true); if (!okey) { raise_warning("key parameter is not a valid public key"); return false; } EVP_PKEY *pkey = okey->m_key; int cryptedlen = EVP_PKEY_size(pkey); String s = String(cryptedlen, ReserveString); unsigned char *cryptedbuf = (unsigned char *)s.mutableData(); int successful = 0; switch (EVP_PKEY_id(pkey)) { case EVP_PKEY_RSA: case EVP_PKEY_RSA2: cryptedlen = RSA_public_decrypt(data.size(), (unsigned char *)data.data(), cryptedbuf, EVP_PKEY_get0_RSA(pkey), padding); if (cryptedlen != -1) { successful = 1; } break; default: raise_warning("key type not supported"); } if (successful) { decrypted = s.setSize(cryptedlen); return true; } return false; } bool HHVM_FUNCTION(openssl_public_encrypt, const String& data, Variant& crypted, const Variant& key, int padding /* = k_OPENSSL_PKCS1_PADDING */) { auto okey = Key::Get(key, true); if (!okey) { raise_warning("key parameter is not a valid public key"); return false; } EVP_PKEY *pkey = okey->m_key; int cryptedlen = EVP_PKEY_size(pkey); String s = String(cryptedlen, ReserveString); unsigned char *cryptedbuf = (unsigned char *)s.mutableData(); int successful = 0; switch (EVP_PKEY_id(pkey)) { case EVP_PKEY_RSA: case EVP_PKEY_RSA2: successful = (RSA_public_encrypt(data.size(), (unsigned char *)data.data(), cryptedbuf, EVP_PKEY_get0_RSA(pkey), padding) == cryptedlen); break; default: raise_warning("key type not supported"); } if (successful) { crypted = s.setSize(cryptedlen); return true; } return false; } Variant HHVM_FUNCTION(openssl_seal, const String& data, Variant& sealed_data, Variant& env_keys, const Array& pub_key_ids, const String& method, Variant& iv) { int nkeys = pub_key_ids.size(); if (nkeys == 0) { raise_warning("Fourth argument to openssl_seal() must be " "a non-empty array"); return false; } const EVP_CIPHER *cipher_type; if (method.empty()) { cipher_type = EVP_rc4(); } else { cipher_type = EVP_get_cipherbyname(method.c_str()); if (!cipher_type) { raise_warning("Unknown cipher algorithm"); return false; } } int iv_len = EVP_CIPHER_iv_length(cipher_type); unsigned char *iv_buf = nullptr; String iv_s; if (iv_len > 0) { iv_s = String(iv_len, ReserveString); iv_buf = (unsigned char*)iv_s.mutableData(); if (!RAND_bytes(iv_buf, iv_len)) { raise_warning("Could not generate an IV."); return false; } } EVP_PKEY **pkeys = (EVP_PKEY**)malloc(nkeys * sizeof(*pkeys)); int *eksl = (int*)malloc(nkeys * sizeof(*eksl)); unsigned char **eks = (unsigned char **)malloc(nkeys * sizeof(*eks)); memset(eks, 0, sizeof(*eks) * nkeys); // holder is needed to make sure none of the Keys get deleted prematurely. // The pkeys array points to elements inside of Keys returned from Key::Get() // which may be newly allocated and have no other owners. std::vector<req::ptr<Key>> holder; /* get the public keys we are using to seal this data */ bool ret = true; int i = 0; String s; unsigned char* buf = nullptr; EVP_CIPHER_CTX* ctx = nullptr; for (ArrayIter iter(pub_key_ids); iter; ++iter, ++i) { auto okey = Key::Get(iter.second(), true); if (!okey) { raise_warning("not a public key (%dth member of pubkeys)", i + 1); ret = false; goto clean_exit; } holder.push_back(okey); pkeys[i] = okey->m_key; eks[i] = (unsigned char *)malloc(EVP_PKEY_size(pkeys[i]) + 1); } ctx = EVP_CIPHER_CTX_new(); if (ctx == nullptr) { raise_warning("Failed to allocate an EVP_CIPHER_CTX object"); ret = false; goto clean_exit; } if (!EVP_EncryptInit_ex(ctx, cipher_type, nullptr, nullptr, nullptr)) { ret = false; goto clean_exit; } int len1, len2; s = String(data.size() + EVP_CIPHER_CTX_block_size(ctx), ReserveString); buf = (unsigned char *)s.mutableData(); if (EVP_SealInit(ctx, cipher_type, eks, eksl, iv_buf, pkeys, nkeys) <= 0 || !EVP_SealUpdate(ctx, buf, &len1, (unsigned char*)data.data(), data.size()) || !EVP_SealFinal(ctx, buf + len1, &len2)) { ret = false; goto clean_exit; } if (len1 + len2 > 0) { sealed_data = s.setSize(len1 + len2); auto ekeys = Array::CreateVArray(); for (i = 0; i < nkeys; i++) { eks[i][eksl[i]] = '\0'; ekeys.append(String((char*)eks[i], eksl[i], AttachString)); eks[i] = nullptr; } env_keys = ekeys; } clean_exit: for (i = 0; i < nkeys; i++) { if (eks[i]) free(eks[i]); } free(eks); free(eksl); free(pkeys); if (iv_buf != nullptr) { if (ret) { iv = iv_s.setSize(iv_len); } } if (ctx != nullptr) { EVP_CIPHER_CTX_free(ctx); } if (ret) return len1 + len2; return false; } static const EVP_MD *php_openssl_get_evp_md_from_algo(long algo) { switch (algo) { case OPENSSL_ALGO_SHA1: return EVP_sha1(); case OPENSSL_ALGO_MD5: return EVP_md5(); case OPENSSL_ALGO_MD4: return EVP_md4(); #ifdef HAVE_OPENSSL_MD2_H case OPENSSL_ALGO_MD2: return EVP_md2(); #endif #if OPENSSL_VERSION_NUMBER < 0x10100000L case OPENSSL_ALGO_DSS1: return EVP_dss1(); #endif #if OPENSSL_VERSION_NUMBER >= 0x0090708fL case OPENSSL_ALGO_SHA224: return EVP_sha224(); case OPENSSL_ALGO_SHA256: return EVP_sha256(); case OPENSSL_ALGO_SHA384: return EVP_sha384(); case OPENSSL_ALGO_SHA512: return EVP_sha512(); case OPENSSL_ALGO_RMD160: return EVP_ripemd160(); #endif } return nullptr; } bool HHVM_FUNCTION(openssl_sign, const String& data, Variant& signature, const Variant& priv_key_id, const Variant& signature_alg /* = k_OPENSSL_ALGO_SHA1 */) { auto okey = Key::Get(priv_key_id, false); if (!okey) { raise_warning("supplied key param cannot be coerced into a private key"); return false; } const EVP_MD *mdtype = nullptr; if (signature_alg.isInteger()) { mdtype = php_openssl_get_evp_md_from_algo(signature_alg.toInt64Val()); } else if (signature_alg.isString()) { mdtype = EVP_get_digestbyname(signature_alg.toString().data()); } if (!mdtype) { raise_warning("Unknown signature algorithm."); return false; } EVP_PKEY *pkey = okey->m_key; int siglen = EVP_PKEY_size(pkey); String s = String(siglen, ReserveString); unsigned char *sigbuf = (unsigned char *)s.mutableData(); EVP_MD_CTX *md_ctx = EVP_MD_CTX_new(); SCOPE_EXIT { EVP_MD_CTX_free(md_ctx); }; EVP_SignInit(md_ctx, mdtype); EVP_SignUpdate(md_ctx, (unsigned char *)data.data(), data.size()); if (EVP_SignFinal(md_ctx, sigbuf, (unsigned int *)&siglen, pkey)) { signature = s.setSize(siglen); return true; } return false; } Variant HHVM_FUNCTION(openssl_verify, const String& data, const String& signature, const Variant& pub_key_id, const Variant& signature_alg /* = k_OPENSSL_ALGO_SHA1 */) { int err; const EVP_MD *mdtype = nullptr; if (signature_alg.isInteger()) { mdtype = php_openssl_get_evp_md_from_algo(signature_alg.toInt64Val()); } else if (signature_alg.isString()) { mdtype = EVP_get_digestbyname(signature_alg.toString().data()); } if (!mdtype) { raise_warning("Unknown signature algorithm."); return false; } auto okey = Key::Get(pub_key_id, true); if (!okey) { raise_warning("supplied key param cannot be coerced into a public key"); return false; } EVP_MD_CTX *md_ctx = EVP_MD_CTX_new(); SCOPE_EXIT { EVP_MD_CTX_free(md_ctx); }; EVP_VerifyInit(md_ctx, mdtype); EVP_VerifyUpdate(md_ctx, (unsigned char*)data.data(), data.size()); err = EVP_VerifyFinal(md_ctx, (unsigned char *)signature.data(), signature.size(), okey->m_key); return err; } bool HHVM_FUNCTION(openssl_x509_check_private_key, const Variant& cert, const Variant& key) { auto ocert = Certificate::Get(cert); if (!ocert) { return false; } auto okey = Key::Get(key, false); if (!okey) { return false; } return X509_check_private_key(ocert->m_cert, okey->m_key); } static int check_cert(X509_STORE *ctx, X509 *x, STACK_OF(X509) *untrustedchain, int purpose) { X509_STORE_CTX *csc = X509_STORE_CTX_new(); if (csc == nullptr) { raise_warning("memory allocation failure"); return 0; } X509_STORE_CTX_init(csc, ctx, x, untrustedchain); if (purpose >= 0) { X509_STORE_CTX_set_purpose(csc, purpose); } int ret = X509_verify_cert(csc); X509_STORE_CTX_free(csc); return ret; } Variant HHVM_FUNCTION(openssl_x509_checkpurpose, const Variant& x509cert, int purpose, const Array& cainfo /* = null_array */, const String& untrustedfile /* = null_string */) { int ret = -1; STACK_OF(X509) *untrustedchain = nullptr; X509_STORE *pcainfo = nullptr; req::ptr<Certificate> ocert; if (!untrustedfile.empty()) { untrustedchain = load_all_certs_from_file(untrustedfile.data()); if (untrustedchain == nullptr) { goto clean_exit; } } pcainfo = setup_verify(cainfo); if (pcainfo == nullptr) { goto clean_exit; } ocert = Certificate::Get(x509cert); if (!ocert) { raise_warning("cannot get cert from parameter 1"); return false; } X509 *cert; cert = ocert->m_cert; assertx(cert); ret = check_cert(pcainfo, cert, untrustedchain, purpose); clean_exit: if (pcainfo) { X509_STORE_free(pcainfo); } if (untrustedchain) { sk_X509_pop_free(untrustedchain, X509_free); } return ret == 1 ? true : ret == 0 ? false : -1; } static bool openssl_x509_export_impl(const Variant& x509, BIO *bio_out, bool notext /* = true */) { auto ocert = Certificate::Get(x509); if (!ocert) { raise_warning("cannot get cert from parameter 1"); return false; } X509 *cert = ocert->m_cert; assertx(cert); assertx(bio_out); if (!notext) { X509_print(bio_out, cert); } return PEM_write_bio_X509(bio_out, cert); } bool HHVM_FUNCTION(openssl_x509_export_to_file, const Variant& x509, const String& outfilename, bool notext /* = true */) { BIO *bio_out = BIO_new_file((char*)outfilename.data(), "w"); if (bio_out == nullptr) { raise_warning("error opening file %s", outfilename.data()); return false; } bool ret = openssl_x509_export_impl(x509, bio_out, notext); BIO_free(bio_out); return ret; } bool HHVM_FUNCTION(openssl_x509_export, const Variant& x509, Variant& output, bool notext /* = true */) { BIO *bio_out = BIO_new(BIO_s_mem()); bool ret = openssl_x509_export_impl(x509, bio_out, notext); if (ret) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); output = String(bio_buf->data, bio_buf->length, CopyString); } BIO_free(bio_out); return ret; } /** * This is how the time string is formatted: * * snprintf(p, sizeof(p), "%02d%02d%02d%02d%02d%02dZ",ts->tm_year%100, * ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); */ static time_t asn1_time_to_time_t(ASN1_UTCTIME *timestr) { auto const timestr_type = ASN1_STRING_type(timestr); if (timestr_type != V_ASN1_UTCTIME && timestr_type != V_ASN1_GENERALIZEDTIME) { raise_warning("illegal ASN1 data type for timestamp"); return (time_t)-1; } auto const timestr_len = (size_t)ASN1_STRING_length(timestr); // Binary safety if (timestr_len != strlen((char*)ASN1_STRING_data(timestr))) { raise_warning("illegal length in timestamp"); return (time_t)-1; } if (timestr_len < 13 && timestr_len != 11) { raise_warning("unable to parse time string %s correctly", timestr->data); return (time_t)-1; } if (timestr_type == V_ASN1_GENERALIZEDTIME && timestr_len < 15) { raise_warning("unable to parse time string %s correctly", timestr->data); return (time_t)-1; } char *strbuf = strdup((char*)timestr->data); struct tm thetime; memset(&thetime, 0, sizeof(thetime)); /* we work backwards so that we can use atoi more easily */ char *thestr = strbuf + ASN1_STRING_length(timestr) - 3; if (ASN1_STRING_length(timestr) == 11) { thetime.tm_sec = 0; } else { thetime.tm_sec = atoi(thestr); *thestr = '\0'; thestr -= 2; } thetime.tm_min = atoi(thestr); *thestr = '\0'; thestr -= 2; thetime.tm_hour = atoi(thestr); *thestr = '\0'; thestr -= 2; thetime.tm_mday = atoi(thestr); *thestr = '\0'; thestr -= 2; thetime.tm_mon = atoi(thestr)-1; *thestr = '\0'; if (ASN1_STRING_type(timestr) == V_ASN1_UTCTIME) { thestr -= 2; thetime.tm_year = atoi(thestr); if (thetime.tm_year < 68) { thetime.tm_year += 100; } } else if (ASN1_STRING_type(timestr) == V_ASN1_GENERALIZEDTIME) { thestr -= 4; thetime.tm_year = atoi(thestr) - 1900; } thetime.tm_isdst = -1; time_t ret = mktime(&thetime); long gmadjust = 0; #if HAVE_TM_GMTOFF gmadjust = thetime.tm_gmtoff; #elif defined(_MSC_VER) TIME_ZONE_INFORMATION inf; GetTimeZoneInformation(&inf); gmadjust = thetime.tm_isdst ? inf.DaylightBias : inf.StandardBias; #else /** * If correcting for daylight savings time, we set the adjustment to * the value of timezone - 3600 seconds. Otherwise, we need to overcorrect * and set the adjustment to the main timezone + 3600 seconds. */ gmadjust = -(thetime.tm_isdst ? (long)timezone - 3600 : (long)timezone); #endif /* no adjustment for UTC */ if (timezone) ret += gmadjust; free(strbuf); return ret; } /* Special handling of subjectAltName, see CVE-2013-4073 * Christian Heimes */ static int openssl_x509v3_subjectAltName(BIO *bio, X509_EXTENSION *extension) { GENERAL_NAMES *names; const X509V3_EXT_METHOD *method = nullptr; long i, length, num; const unsigned char *p; method = X509V3_EXT_get(extension); if (method == nullptr) { return -1; } const auto data = X509_EXTENSION_get_data(extension); p = data->data; length = data->length; if (method->it) { names = (GENERAL_NAMES*)(ASN1_item_d2i(nullptr, &p, length, ASN1_ITEM_ptr(method->it))); } else { names = (GENERAL_NAMES*)(method->d2i(nullptr, &p, length)); } if (names == nullptr) { return -1; } num = sk_GENERAL_NAME_num(names); for (i = 0; i < num; i++) { GENERAL_NAME *name; ASN1_STRING *as; name = sk_GENERAL_NAME_value(names, i); switch (name->type) { case GEN_EMAIL: BIO_puts(bio, "email:"); as = name->d.rfc822Name; BIO_write(bio, ASN1_STRING_data(as), ASN1_STRING_length(as)); break; case GEN_DNS: BIO_puts(bio, "DNS:"); as = name->d.dNSName; BIO_write(bio, ASN1_STRING_data(as), ASN1_STRING_length(as)); break; case GEN_URI: BIO_puts(bio, "URI:"); as = name->d.uniformResourceIdentifier; BIO_write(bio, ASN1_STRING_data(as), ASN1_STRING_length(as)); break; default: /* use builtin print for GEN_OTHERNAME, GEN_X400, * GEN_EDIPARTY, GEN_DIRNAME, GEN_IPADD and GEN_RID */ GENERAL_NAME_print(bio, name); } /* trailing ', ' except for last element */ if (i < (num - 1)) { BIO_puts(bio, ", "); } } sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free); return 0; } Variant HHVM_FUNCTION(openssl_x509_parse, const Variant& x509cert, bool shortnames /* = true */) { auto ocert = Certificate::Get(x509cert); if (!ocert) { return false; } X509 *cert = ocert->m_cert; assertx(cert); auto ret = Array::CreateDArray(); const auto sn = X509_get_subject_name(cert); if (sn) { ret.set(s_name, String(X509_NAME_oneline(sn, nullptr, 0), CopyString)); } add_assoc_name_entry(ret, "subject", sn, shortnames); /* hash as used in CA directories to lookup cert by subject name */ { char buf[32]; snprintf(buf, sizeof(buf), "%08lx", X509_subject_name_hash(cert)); ret.set(s_hash, String(buf, CopyString)); } add_assoc_name_entry(ret, "issuer", X509_get_issuer_name(cert), shortnames); ret.set(s_version, X509_get_version(cert)); ret.set(s_serialNumber, String (i2s_ASN1_INTEGER(nullptr, X509_get_serialNumber(cert)), AttachString)); // Adding Signature Algorithm BIO *bio_out = BIO_new(BIO_s_mem()); SCOPE_EXIT { BIO_free(bio_out); }; if (i2a_ASN1_OBJECT(bio_out, X509_get0_tbs_sigalg(cert)->algorithm) > 0) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); ret.set(s_signatureAlgorithm, String((char*)bio_buf->data, bio_buf->length, CopyString)); } ASN1_STRING *str = X509_get_notBefore(cert); ret.set(s_validFrom, String((char*)str->data, str->length, CopyString)); str = X509_get_notAfter(cert); ret.set(s_validTo, String((char*)str->data, str->length, CopyString)); ret.set(s_validFrom_time_t, asn1_time_to_time_t(X509_get_notBefore(cert))); ret.set(s_validTo_time_t, asn1_time_to_time_t(X509_get_notAfter(cert))); char *tmpstr = (char *)X509_alias_get0(cert, nullptr); if (tmpstr) { ret.set(s_alias, String(tmpstr, CopyString)); } /* NOTE: the purposes are added as integer keys - the keys match up to the X509_PURPOSE_SSL_XXX defines in x509v3.h */ { Array subitem; for (int i = 0; i < X509_PURPOSE_get_count(); i++) { X509_PURPOSE *purp = X509_PURPOSE_get0(i); int id = X509_PURPOSE_get_id(purp); char * pname = shortnames ? X509_PURPOSE_get0_sname(purp) : X509_PURPOSE_get0_name(purp); auto subsub = make_varray( (bool)X509_check_purpose(cert, id, 0), (bool)X509_check_purpose(cert, id, 1), String(pname, CopyString) ); subitem.set(id, std::move(subsub)); } ret.set(s_purposes, subitem); } { auto subitem = Array::CreateDArray(); for (int i = 0; i < X509_get_ext_count(cert); i++) { int nid; X509_EXTENSION *extension = X509_get_ext(cert, i); char *extname; char buf[256]; nid = OBJ_obj2nid(X509_EXTENSION_get_object(extension)); if (nid != NID_undef) { extname = (char*)OBJ_nid2sn(OBJ_obj2nid (X509_EXTENSION_get_object(extension))); } else { OBJ_obj2txt(buf, sizeof(buf)-1, X509_EXTENSION_get_object(extension), 1); extname = buf; } BIO *bio_out = BIO_new(BIO_s_mem()); if (nid == NID_subject_alt_name) { if (openssl_x509v3_subjectAltName(bio_out, extension) == 0) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); subitem.set(String(extname, CopyString), String((char*)bio_buf->data, bio_buf->length, CopyString)); } else { BIO_free(bio_out); return false; } } else if (X509V3_EXT_print(bio_out, extension, 0, 0)) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); subitem.set(String(extname, CopyString), String((char*)bio_buf->data, bio_buf->length, CopyString)); } else { str = X509_EXTENSION_get_data(extension); subitem.set(String(extname, CopyString), String((char*)str->data, str->length, CopyString)); } BIO_free(bio_out); } ret.set(s_extensions, subitem); } return ret; } Variant HHVM_FUNCTION(openssl_x509_read, const Variant& x509certdata) { auto ocert = Certificate::Get(x509certdata); if (!ocert) { raise_warning("supplied parameter cannot be coerced into " "an X509 certificate!"); return false; } return Variant(ocert); } Variant HHVM_FUNCTION(openssl_random_pseudo_bytes, int length, bool& crypto_strong) { if (length <= 0) { return false; } unsigned char *buffer = nullptr; String s = String(length, ReserveString); buffer = (unsigned char *)s.mutableData(); if (RAND_bytes(buffer, length) <= 0) { crypto_strong = false; return false; } else { crypto_strong = true; s.setSize(length); return s; } } Variant HHVM_FUNCTION(openssl_cipher_iv_length, const String& method) { if (method.empty()) { raise_warning("Unknown cipher algorithm"); return false; } const EVP_CIPHER *cipher_type = EVP_get_cipherbyname(method.c_str()); if (!cipher_type) { raise_warning("Unknown cipher algorithm"); return false; } return EVP_CIPHER_iv_length(cipher_type); } /* Cipher mode info */ struct php_openssl_cipher_mode { /* Whether this mode uses authenticated encryption. True, for example, with the GCM and CCM modes */ bool is_aead; /* Whether this mode is a 'single run aead', meaning that DecryptFinal doesn't get called. For example, CCM mode is a single run aead mode. */ bool is_single_run_aead; /* The OpenSSL flag to get the computed tag, if this mode is aead. */ int aead_get_tag_flag; /* The OpenSSL flag to set the computed tag, if this mode is aead. */ int aead_set_tag_flag; /* The OpenSSL flag to set the IV length, if this mode is aead */ int aead_ivlen_flag; }; // initialize a php_openssl_cipher_mode corresponding to an EVP_CIPHER. static php_openssl_cipher_mode php_openssl_load_cipher_mode( const EVP_CIPHER* cipher_type) { php_openssl_cipher_mode mode = {}; switch (EVP_CIPHER_mode(cipher_type)) { #ifdef EVP_CIPH_GCM_MODE case EVP_CIPH_GCM_MODE: mode.is_aead = true; mode.is_single_run_aead = false; mode.aead_get_tag_flag = EVP_CTRL_GCM_GET_TAG; mode.aead_set_tag_flag = EVP_CTRL_GCM_SET_TAG; mode.aead_ivlen_flag = EVP_CTRL_GCM_SET_IVLEN; break; #endif #ifdef EVP_CIPH_CCM_MODE case EVP_CIPH_CCM_MODE: mode.is_aead = true; mode.is_single_run_aead = true; mode.aead_get_tag_flag = EVP_CTRL_CCM_GET_TAG; mode.aead_set_tag_flag = EVP_CTRL_CCM_SET_TAG; mode.aead_ivlen_flag = EVP_CTRL_CCM_SET_IVLEN; break; #endif default: break; } return mode; } static bool php_openssl_validate_iv( String piv, int iv_required_len, String& out, EVP_CIPHER_CTX* cipher_ctx, const php_openssl_cipher_mode* mode) { if (cipher_ctx == nullptr || mode == nullptr) { return false; } /* Best case scenario, user behaved */ if (piv.size() == iv_required_len) { out = std::move(piv); return true; } if (mode->is_aead) { if (EVP_CIPHER_CTX_ctrl( cipher_ctx, mode->aead_ivlen_flag, piv.size(), nullptr) != 1) { raise_warning( "Setting of IV length for AEAD mode failed, the expected length is " "%d bytes", iv_required_len); return false; } out = std::move(piv); return true; } String s = String(iv_required_len, ReserveString); char* iv_new = s.mutableData(); memset(iv_new, 0, iv_required_len); if (piv.size() <= 0) { /* BC behavior */ s.setSize(iv_required_len); out = std::move(s); return true; } if (piv.size() < iv_required_len) { raise_warning("IV passed is only %d bytes long, cipher " "expects an IV of precisely %d bytes, padding with \\0", piv.size(), iv_required_len); memcpy(iv_new, piv.data(), piv.size()); s.setSize(iv_required_len); out = std::move(s); return true; } raise_warning("IV passed is %d bytes long which is longer than the %d " "expected by selected cipher, truncating", piv.size(), iv_required_len); memcpy(iv_new, piv.data(), iv_required_len); s.setSize(iv_required_len); out = std::move(s); return true; } namespace { Variant openssl_encrypt_impl(const String& data, const String& method, const String& password, int options, const String& iv, Variant* tag_out, const String& aad, int tag_length) { const EVP_CIPHER *cipher_type = EVP_get_cipherbyname(method.c_str()); if (!cipher_type) { raise_warning("Unknown cipher algorithm"); return false; } EVP_CIPHER_CTX* cipher_ctx = EVP_CIPHER_CTX_new(); if (!cipher_ctx) { raise_warning("Failed to create cipher context"); return false; } SCOPE_EXIT { EVP_CIPHER_CTX_free(cipher_ctx); }; php_openssl_cipher_mode mode = php_openssl_load_cipher_mode(cipher_type); if (mode.is_aead && !tag_out) { raise_warning("Must call openssl_encrypt_with_tag when using an AEAD cipher"); return false; } int keylen = EVP_CIPHER_key_length(cipher_type); String key = password; /* * older openssl libraries can assert if the passed in password length is * less than keylen */ if (keylen > password.size()) { String s = String(keylen, ReserveString); char *keybuf = s.mutableData(); memset(keybuf, 0, keylen); memcpy(keybuf, password.data(), password.size()); key = s.setSize(keylen); } int max_iv_len = EVP_CIPHER_iv_length(cipher_type); if (iv.size() <= 0 && max_iv_len > 0 && !mode.is_aead) { raise_warning("Using an empty Initialization Vector (iv) is potentially " "insecure and not recommended"); } int result_len = 0; int outlen = data.size() + EVP_CIPHER_block_size(cipher_type); String rv = String(outlen, ReserveString); unsigned char *outbuf = (unsigned char*)rv.mutableData(); EVP_EncryptInit_ex(cipher_ctx, cipher_type, nullptr, nullptr, nullptr); String new_iv; // we do this after EncryptInit because validate_iv changes cipher_ctx for // aead modes (must be initialized first). if (!php_openssl_validate_iv( std::move(iv), max_iv_len, new_iv, cipher_ctx, &mode)) { return false; } // set the tag length for CCM mode/other modes that require tag lengths to // be set. if (mode.is_single_run_aead && !EVP_CIPHER_CTX_ctrl( cipher_ctx, mode.aead_set_tag_flag, tag_length, nullptr)) { raise_warning("Setting tag length failed"); return false; } if (password.size() > keylen) { EVP_CIPHER_CTX_set_key_length(cipher_ctx, password.size()); } EVP_EncryptInit_ex( cipher_ctx, nullptr, nullptr, (unsigned char*)key.data(), (unsigned char*)new_iv.data()); if (options & k_OPENSSL_ZERO_PADDING) { EVP_CIPHER_CTX_set_padding(cipher_ctx, 0); } // for single run aeads like CCM, we need to provide the length of the // plaintext before providing AAD or ciphertext. if (mode.is_single_run_aead && !EVP_EncryptUpdate( cipher_ctx, nullptr, &result_len, nullptr, data.size())) { raise_warning("Setting of data length failed"); return false; } // set up aad: if (mode.is_aead && !EVP_EncryptUpdate( cipher_ctx, nullptr, &result_len, (unsigned char*)aad.data(), aad.size())) { raise_warning("Setting of additional application data failed"); return false; } // OpenSSL before 0.9.8i asserts with size < 0 if (data.size() >= 0) { EVP_EncryptUpdate(cipher_ctx, outbuf, &result_len, (unsigned char *)data.data(), data.size()); } outlen = result_len; if (EVP_EncryptFinal_ex( cipher_ctx, (unsigned char*)outbuf + result_len, &result_len)) { outlen += result_len; rv.setSize(outlen); // Get tag if possible if (mode.is_aead) { String tagrv = String(tag_length, ReserveString); if (EVP_CIPHER_CTX_ctrl( cipher_ctx, mode.aead_get_tag_flag, tag_length, tagrv.mutableData()) == 1) { tagrv.setSize(tag_length); assertx(tag_out); *tag_out = tagrv; } else { raise_warning("Retrieving authentication tag failed"); return false; } } else if (tag_out) { raise_warning( "The authenticated tag cannot be provided for cipher that does not" " support AEAD"); } // Return encrypted data if (options & k_OPENSSL_RAW_DATA) { return rv; } else { return StringUtil::Base64Encode(rv); } } return false; } } // anonymous namespace Variant HHVM_FUNCTION(openssl_encrypt, const String& data, const String& method, const String& password, int options /* = 0 */, const String& iv /* = null_string */, const String& aad /* = null_string */, int tag_length /* = 16 */) { return openssl_encrypt_impl(data, method, password, options, iv, nullptr, aad, tag_length); } Variant HHVM_FUNCTION(openssl_encrypt_with_tag, const String& data, const String& method, const String& password, int options, const String& iv, Variant& tag_out, const String& aad /* = null_string */, int tag_length /* = 16 */) { return openssl_encrypt_impl(data, method, password, options, iv, &tag_out, aad, tag_length); } Variant HHVM_FUNCTION(openssl_decrypt, const String& data, const String& method, const String& password, int options /* = 0 */, const String& iv /* = null_string */, const String& tag /* = null_string */, const String& aad /* = null_string */) { const EVP_CIPHER *cipher_type = EVP_get_cipherbyname(method.c_str()); if (!cipher_type) { raise_warning("Unknown cipher algorithm"); return false; } EVP_CIPHER_CTX* cipher_ctx = EVP_CIPHER_CTX_new(); if (!cipher_ctx) { raise_warning("Failed to create cipher context"); return false; } SCOPE_EXIT { EVP_CIPHER_CTX_free(cipher_ctx); }; php_openssl_cipher_mode mode = php_openssl_load_cipher_mode(cipher_type); String decoded_data = data; if (!(options & k_OPENSSL_RAW_DATA)) { decoded_data = StringUtil::Base64Decode(data); } int keylen = EVP_CIPHER_key_length(cipher_type); String key = password; /* * older openssl libraries can assert if the passed in password length is * less than keylen */ if (keylen > password.size()) { String s = String(keylen, ReserveString); char *keybuf = s.mutableData(); memset(keybuf, 0, keylen); memcpy(keybuf, password.data(), password.size()); key = s.setSize(keylen); } int result_len = 0; int outlen = decoded_data.size() + EVP_CIPHER_block_size(cipher_type); String rv = String(outlen, ReserveString); unsigned char *outbuf = (unsigned char*)rv.mutableData(); EVP_DecryptInit_ex(cipher_ctx, cipher_type, nullptr, nullptr, nullptr); String new_iv; // we do this after DecryptInit because validate_iv changes cipher_ctx for // aead modes (must be initialized first). if (!php_openssl_validate_iv( std::move(iv), EVP_CIPHER_iv_length(cipher_type), new_iv, cipher_ctx, &mode)) { return false; } // set the tag if required: if (tag.size() > 0) { if (!mode.is_aead) { raise_warning( "The tag is being ignored because the cipher method does not" " support AEAD"); } else if (!EVP_CIPHER_CTX_ctrl( cipher_ctx, mode.aead_set_tag_flag, tag.size(), (unsigned char*)tag.data())) { raise_warning("Setting tag for AEAD cipher decryption failed"); return false; } } else { if (mode.is_aead) { raise_warning("A tag should be provided when using AEAD mode"); return false; } } if (password.size() > keylen) { EVP_CIPHER_CTX_set_key_length(cipher_ctx, password.size()); } EVP_DecryptInit_ex( cipher_ctx, nullptr, nullptr, (unsigned char*)key.data(), (unsigned char*)new_iv.data()); if (options & k_OPENSSL_ZERO_PADDING) { EVP_CIPHER_CTX_set_padding(cipher_ctx, 0); } // for single run aeads like CCM, we need to provide the length of the // ciphertext before providing AAD or ciphertext. if (mode.is_single_run_aead && !EVP_DecryptUpdate( cipher_ctx, nullptr, &result_len, nullptr, decoded_data.size())) { raise_warning("Setting of data length failed"); return false; } // set up aad: if (mode.is_aead && !EVP_DecryptUpdate( cipher_ctx, nullptr, &result_len, (unsigned char*)aad.data(), aad.size())) { raise_warning("Setting of additional application data failed"); return false; } if (!EVP_DecryptUpdate( cipher_ctx, outbuf, &result_len, (unsigned char*)decoded_data.data(), decoded_data.size())) { return false; } outlen = result_len; // if is_single_run_aead is enabled, DecryptFinal shouldn't be called. // if something went wrong in this case, we would've caught it at // DecryptUpdate. if (mode.is_single_run_aead || EVP_DecryptFinal_ex( cipher_ctx, (unsigned char*)outbuf + result_len, &result_len)) { // don't want to do this if is_single_run_aead was enabled, since we didn't // make a call to EVP_DecryptFinal. if (!mode.is_single_run_aead) { outlen += result_len; } rv.setSize(outlen); return rv; } else { return false; } } Variant HHVM_FUNCTION(openssl_digest, const String& data, const String& method, bool raw_output /* = false */) { const EVP_MD *mdtype = EVP_get_digestbyname(method.c_str()); if (!mdtype) { raise_warning("Unknown signature algorithm"); return false; } int siglen = EVP_MD_size(mdtype); String rv = String(siglen, ReserveString); unsigned char *sigbuf = (unsigned char *)rv.mutableData(); EVP_MD_CTX *md_ctx = EVP_MD_CTX_new(); SCOPE_EXIT { EVP_MD_CTX_free(md_ctx); }; EVP_DigestInit(md_ctx, mdtype); EVP_DigestUpdate(md_ctx, (unsigned char *)data.data(), data.size()); if (EVP_DigestFinal(md_ctx, (unsigned char *)sigbuf, (unsigned int *)&siglen)) { if (raw_output) { rv.setSize(siglen); return rv; } else { char* digest_str = string_bin2hex((char*)sigbuf, siglen); return String(digest_str, AttachString); } } else { return false; } } static void openssl_add_method_or_alias(const OBJ_NAME *name, void *arg) { Array *ret = (Array*)arg; ret->append(String((char *)name->name, CopyString)); } static void openssl_add_method(const OBJ_NAME *name, void *arg) { if (name->alias == 0) { Array *ret = (Array*)arg; ret->append(String((char *)name->name, CopyString)); } } Array HHVM_FUNCTION(openssl_get_cipher_methods, bool aliases /* = false */) { Array ret = Array::CreateVArray(); OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_CIPHER_METH, aliases ? openssl_add_method_or_alias: openssl_add_method, &ret); return ret; } Variant HHVM_FUNCTION(openssl_get_curve_names) { #ifdef HAVE_EVP_PKEY_EC const size_t len = EC_get_builtin_curves(nullptr, 0); std::unique_ptr<EC_builtin_curve[]> curves(new EC_builtin_curve[len]); if (!EC_get_builtin_curves(curves.get(), len)) { return false; } VArrayInit ret(len); for (size_t i = 0; i < len; ++i) { auto const sname = OBJ_nid2sn(curves[i].nid); if (sname != nullptr) { ret.append(String(sname, CopyString)); } } return ret.toArray(); #else return false; #endif } Array HHVM_FUNCTION(openssl_get_md_methods, bool aliases /* = false */) { Array ret = Array::CreateVArray(); OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_MD_METH, aliases ? openssl_add_method_or_alias: openssl_add_method, &ret); return ret; } ///////////////////////////////////////////////////////////////////////////// const StaticString s_OPENSSL_VERSION_TEXT("OPENSSL_VERSION_TEXT"); struct opensslExtension final : Extension { opensslExtension() : Extension("openssl") {} void moduleInit() override { HHVM_RC_INT(OPENSSL_RAW_DATA, k_OPENSSL_RAW_DATA); HHVM_RC_INT(OPENSSL_ZERO_PADDING, k_OPENSSL_ZERO_PADDING); HHVM_RC_INT(OPENSSL_NO_PADDING, k_OPENSSL_NO_PADDING); HHVM_RC_INT(OPENSSL_PKCS1_OAEP_PADDING, k_OPENSSL_PKCS1_OAEP_PADDING); HHVM_RC_INT(OPENSSL_SSLV23_PADDING, k_OPENSSL_SSLV23_PADDING); HHVM_RC_INT(OPENSSL_PKCS1_PADDING, k_OPENSSL_PKCS1_PADDING); HHVM_RC_INT_SAME(OPENSSL_ALGO_SHA1); HHVM_RC_INT_SAME(OPENSSL_ALGO_MD5); HHVM_RC_INT_SAME(OPENSSL_ALGO_MD4); #ifdef HAVE_OPENSSL_MD2_H HHVM_RC_INT_SAME(OPENSSL_ALGO_MD2); #endif HHVM_RC_INT_SAME(OPENSSL_ALGO_DSS1); HHVM_RC_INT_SAME(OPENSSL_ALGO_SHA224); HHVM_RC_INT_SAME(OPENSSL_ALGO_SHA256); HHVM_RC_INT_SAME(OPENSSL_ALGO_SHA384); HHVM_RC_INT_SAME(OPENSSL_ALGO_SHA512); HHVM_RC_INT_SAME(OPENSSL_ALGO_RMD160); HHVM_RC_INT(OPENSSL_CIPHER_RC2_40, PHP_OPENSSL_CIPHER_RC2_40); HHVM_RC_INT(OPENSSL_CIPHER_RC2_128, PHP_OPENSSL_CIPHER_RC2_128); HHVM_RC_INT(OPENSSL_CIPHER_RC2_64, PHP_OPENSSL_CIPHER_RC2_64); HHVM_RC_INT(OPENSSL_CIPHER_DES, PHP_OPENSSL_CIPHER_DES); HHVM_RC_INT(OPENSSL_CIPHER_3DES, PHP_OPENSSL_CIPHER_3DES); HHVM_RC_INT_SAME(OPENSSL_KEYTYPE_RSA); HHVM_RC_INT_SAME(OPENSSL_KEYTYPE_DSA); HHVM_RC_INT_SAME(OPENSSL_KEYTYPE_DH); #ifdef HAVE_EVP_PKEY_EC HHVM_RC_INT_SAME(OPENSSL_KEYTYPE_EC); #endif HHVM_RC_INT_SAME(OPENSSL_VERSION_NUMBER); HHVM_RC_INT_SAME(PKCS7_TEXT); HHVM_RC_INT_SAME(PKCS7_NOCERTS); HHVM_RC_INT_SAME(PKCS7_NOSIGS); HHVM_RC_INT_SAME(PKCS7_NOCHAIN); HHVM_RC_INT_SAME(PKCS7_NOINTERN); HHVM_RC_INT_SAME(PKCS7_NOVERIFY); HHVM_RC_INT_SAME(PKCS7_DETACHED); HHVM_RC_INT_SAME(PKCS7_BINARY); HHVM_RC_INT_SAME(PKCS7_NOATTR); HHVM_RC_STR_SAME(OPENSSL_VERSION_TEXT); HHVM_RC_INT_SAME(X509_PURPOSE_SSL_CLIENT); HHVM_RC_INT_SAME(X509_PURPOSE_SSL_SERVER); HHVM_RC_INT_SAME(X509_PURPOSE_NS_SSL_SERVER); HHVM_RC_INT_SAME(X509_PURPOSE_SMIME_SIGN); HHVM_RC_INT_SAME(X509_PURPOSE_SMIME_ENCRYPT); HHVM_RC_INT_SAME(X509_PURPOSE_CRL_SIGN); #ifdef X509_PURPOSE_ANY HHVM_RC_INT_SAME(X509_PURPOSE_ANY); #endif HHVM_FE(openssl_csr_export_to_file); HHVM_FE(openssl_csr_export); HHVM_FE(openssl_csr_get_public_key); HHVM_FE(openssl_csr_get_subject); HHVM_FE(openssl_csr_new); HHVM_FE(openssl_csr_sign); HHVM_FE(openssl_error_string); HHVM_FE(openssl_open); HHVM_FE(openssl_pkcs12_export_to_file); HHVM_FE(openssl_pkcs12_export); HHVM_FE(openssl_pkcs12_read); HHVM_FE(openssl_pkcs7_decrypt); HHVM_FE(openssl_pkcs7_encrypt); HHVM_FE(openssl_pkcs7_sign); HHVM_FE(openssl_pkcs7_verify); HHVM_FE(openssl_pkey_export_to_file); HHVM_FE(openssl_pkey_export); HHVM_FE(openssl_pkey_get_details); HHVM_FE(openssl_pkey_get_private); HHVM_FE(openssl_pkey_get_public); HHVM_FE(openssl_pkey_new); HHVM_FE(openssl_private_decrypt); HHVM_FE(openssl_private_encrypt); HHVM_FE(openssl_public_decrypt); HHVM_FE(openssl_public_encrypt); HHVM_FE(openssl_seal); HHVM_FE(openssl_sign); HHVM_FE(openssl_verify); HHVM_FE(openssl_x509_check_private_key); HHVM_FE(openssl_x509_checkpurpose); HHVM_FE(openssl_x509_export_to_file); HHVM_FE(openssl_x509_export); HHVM_FE(openssl_x509_parse); HHVM_FE(openssl_x509_read); HHVM_FE(openssl_random_pseudo_bytes); HHVM_FE(openssl_cipher_iv_length); HHVM_FE(openssl_encrypt); HHVM_FE(openssl_encrypt_with_tag); HHVM_FE(openssl_decrypt); HHVM_FE(openssl_digest); HHVM_FE(openssl_get_cipher_methods); HHVM_FE(openssl_get_curve_names); HHVM_FE(openssl_get_md_methods); loadSystemlib(); } } s_openssl_extension; /////////////////////////////////////////////////////////////////////////////// }
15409
True
1
CVE-2021-24025
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Third Party Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-190'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndIncluding': '4.93.1', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndIncluding': '4.80.1', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Due to incorrect string size calculations inside the preg_quote function, a large input string passed to the function can trigger an integer overflow leading to a heap overflow. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-16T12:45Z
2021-03-10T16:15Z
Integer Overflow or Wraparound
The software performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
An integer overflow or wraparound occurs when an integer value is incremented to a value that is too large to store in the associated representation. When this occurs, the value may wrap to become a very small or negative number. While this may be intended behavior in circumstances that rely on wrapping, it can have security consequences if the wrap is unexpected. This is especially the case if the integer overflow can be triggered using user-supplied inputs. This becomes security-critical when the result is used to control looping, make a security decision, or determine the offset or size in behaviors such as memory allocation, copying, concatenation, etc.
https://cwe.mitre.org/data/definitions/190.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::php_openssl_config_check_syntax
HPHP::php_openssl_config_check_syntax( const char * section_label , const char * config_filename , const char * section , LHASH_OF(CONF_VALUE) * config)
['section_label', 'config_filename', 'section', 'config']
static inline bool php_openssl_config_check_syntax (const char *section_label, const char *config_filename, const char *section, LHASH_OF(CONF_VALUE) *config) { #else static inline bool php_openssl_config_check_syntax (const char *section_label, const char *config_filename, const char *section, LHASH *config) { #endif X509V3_CTX ctx; X509V3_set_ctx_test(&ctx); X509V3_set_conf_lhash(&ctx, config); if (!X509V3_EXT_add_conf(config, &ctx, (char*)section, nullptr)) { raise_warning("Error loading %s section %s of %s", section_label, section, config_filename); return false; } return true; } const StaticString s_config("config"), s_config_section_name("config_section_name"), s_digest_alg("digest_alg"), s_x509_extensions("x509_extensions"), s_req_extensions("req_extensions"), s_private_key_bits("private_key_bits"), s_private_key_type("private_key_type"), s_encrypt_key("encrypt_key"), s_curve_name("curve_name"); static bool php_openssl_parse_config(struct php_x509_request *req, const Array& args, std::vector<String> &strings) { req->config_filename = read_string(args, s_config, default_ssl_conf_filename, strings); req->section_name = read_string(args, s_config_section_name, "req", strings); req->global_config = CONF_load(nullptr, default_ssl_conf_filename, nullptr); req->req_config = CONF_load(nullptr, req->config_filename, nullptr); if (req->req_config == nullptr) { return false; } /* read in the oids */ char *str = CONF_get_string(req->req_config, nullptr, "oid_file"); if (str) { BIO *oid_bio = BIO_new_file(str, "r"); if (oid_bio) { OBJ_create_objects(oid_bio); BIO_free(oid_bio); } } if (!add_oid_section(req)) { return false; } req->digest_name = read_string(args, s_digest_alg, CONF_get_string(req->req_config, req->section_name, "default_md"), strings); req->extensions_section = read_string(args, s_x509_extensions, CONF_get_string(req->req_config, req->section_name, "x509_extensions"), strings); req->request_extensions_section = read_string(args, s_req_extensions, CONF_get_string(req->req_config, req->section_name, "req_extensions"), strings); req->priv_key_bits = read_integer(args, s_private_key_bits, CONF_get_number(req->req_config, req->section_name, "default_bits")); req->priv_key_type = read_integer(args, s_private_key_type, OPENSSL_KEYTYPE_DEFAULT); if (args.exists(s_encrypt_key)) { bool value = args[s_encrypt_key].toBoolean(); req->priv_key_encrypt = value ? 1 : 0; } else { str = CONF_get_string(req->req_config, req->section_name, "encrypt_rsa_key"); if (str == nullptr) { str = CONF_get_string(req->req_config, req->section_name, "encrypt_key"); } if (str && strcmp(str, "no") == 0) { req->priv_key_encrypt = 0; } else { req->priv_key_encrypt = 1; } } /* digest alg */ if (req->digest_name == nullptr) { req->digest_name = CONF_get_string(req->req_config, req->section_name, "default_md"); } if (req->digest_name) { req->digest = req->md_alg = EVP_get_digestbyname(req->digest_name); } if (req->md_alg == nullptr) { req->md_alg = req->digest = EVP_sha256(); } #ifdef HAVE_EVP_PKEY_EC /* set the ec group curve name */ req->curve_name = NID_undef; if (args.exists(s_curve_name)) { auto const curve_name = args[s_curve_name].toString(); req->curve_name = OBJ_sn2nid(curve_name.data()); if (req->curve_name == NID_undef) { raise_warning( "Unknown elliptic curve (short) name %s", curve_name.data() ); return false; } } #endif if (req->extensions_section && !php_openssl_config_check_syntax ("extensions_section", req->config_filename, req->extensions_section, req->req_config)) { return false; } /* set the string mask */ str = CONF_get_string(req->req_config, req->section_name, "string_mask"); if (str && !ASN1_STRING_set_default_mask_asc(str)) { raise_warning("Invalid global string mask setting %s", str); return false; } if (req->request_extensions_section && !php_openssl_config_check_syntax ("request_extensions_section", req->config_filename, req->request_extensions_section, req->req_config)) { return false; } return true; } static void php_openssl_dispose_config(struct php_x509_request *req) { if (req->global_config) { CONF_free(req->global_config); req->global_config = nullptr; } if (req->req_config) { CONF_free(req->req_config); req->req_config = nullptr; } } static STACK_OF(X509) *load_all_certs_from_file(const char *certfile) { STACK_OF(X509_INFO) *sk = nullptr; STACK_OF(X509) *stack = nullptr, *ret = nullptr; BIO *in = nullptr; X509_INFO *xi; if (!(stack = sk_X509_new_null())) { raise_warning("memory allocation failure"); goto end; } if (!(in = BIO_new_file(certfile, "r"))) { raise_warning("error opening the file, %s", certfile); sk_X509_free(stack); goto end; } /* This loads from a file, a stack of x509/crl/pkey sets */ if (!(sk = PEM_X509_INFO_read_bio(in, nullptr, nullptr, nullptr))) { raise_warning("error reading the file, %s", certfile); sk_X509_free(stack); goto end; } /* scan over it and pull out the certs */ while (sk_X509_INFO_num(sk)) { xi = sk_X509_INFO_shift(sk); if (xi->x509 != nullptr) { sk_X509_push(stack, xi->x509); xi->x509 = nullptr; } X509_INFO_free(xi); } if (!sk_X509_num(stack)) { raise_warning("no certificates in file, %s", certfile); sk_X509_free(stack); goto end; } ret = stack; end: BIO_free(in); sk_X509_INFO_free(sk); return ret; } /** * calist is an array containing file and directory names. create a * certificate store and add those certs to it for use in verification. */ static X509_STORE *setup_verify(const Array& calist) { X509_STORE *store = X509_STORE_new(); if (store == nullptr) { return nullptr; } X509_LOOKUP *dir_lookup, *file_lookup; int ndirs = 0, nfiles = 0; for (ArrayIter iter(calist); iter; ++iter) { String item = iter.second().toString(); struct stat sb; if (stat(item.data(), &sb) == -1) { raise_warning("unable to stat %s", item.data()); continue; } if ((sb.st_mode & S_IFREG) == S_IFREG) { file_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()); if (file_lookup == nullptr || !X509_LOOKUP_load_file(file_lookup, item.data(), X509_FILETYPE_PEM)) { raise_warning("error loading file %s", item.data()); } else { nfiles++; } file_lookup = nullptr; } else { dir_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir()); if (dir_lookup == nullptr || !X509_LOOKUP_add_dir(dir_lookup, item.data(), X509_FILETYPE_PEM)) { raise_warning("error loading directory %s", item.data()); } else { ndirs++; } dir_lookup = nullptr; } } if (nfiles == 0) { file_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()); if (file_lookup) { X509_LOOKUP_load_file(file_lookup, nullptr, X509_FILETYPE_DEFAULT); } } if (ndirs == 0) { dir_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir()); if (dir_lookup) { X509_LOOKUP_add_dir(dir_lookup, nullptr, X509_FILETYPE_DEFAULT); } } return store; } /////////////////////////////////////////////////////////////////////////////// static bool add_entries(X509_NAME *subj, const Array& items) { for (ArrayIter iter(items); iter; ++iter) { auto const index = iter.first().toString(); auto const item = iter.second().toString(); int nid = OBJ_txt2nid(index.data()); if (nid != NID_undef) { if (!X509_NAME_add_entry_by_NID(subj, nid, MBSTRING_ASC, (unsigned char*)item.data(), -1, -1, 0)) { raise_warning("dn: add_entry_by_NID %d -> %s (failed)", nid, item.data()); return false; } } else { raise_warning("dn: %s is not a recognized name", index.data()); } } return true; } static bool php_openssl_make_REQ(struct php_x509_request *req, X509_REQ *csr, const Array& dn, const Array& attribs) { char *dn_sect = CONF_get_string(req->req_config, req->section_name, "distinguished_name"); if (dn_sect == nullptr) return false; STACK_OF(CONF_VALUE) *dn_sk = CONF_get_section(req->req_config, dn_sect); if (dn_sk == nullptr) return false; char *attr_sect = CONF_get_string(req->req_config, req->section_name, "attributes"); STACK_OF(CONF_VALUE) *attr_sk = nullptr; if (attr_sect) { attr_sk = CONF_get_section(req->req_config, attr_sect); if (attr_sk == nullptr) { return false; } } /* setup the version number: version 1 */ if (X509_REQ_set_version(csr, 0L)) { X509_NAME *subj = X509_REQ_get_subject_name(csr); if (!add_entries(subj, dn)) return false; /* Finally apply defaults from config file */ for (int i = 0; i < sk_CONF_VALUE_num(dn_sk); i++) { CONF_VALUE *v = sk_CONF_VALUE_value(dn_sk, i); char *type = v->name; int len = strlen(type); if (len < (int)sizeof("_default")) { continue; } len -= sizeof("_default") - 1; if (strcmp("_default", type + len) != 0) { continue; } if (len > 200) { len = 200; } char buffer[200 + 1]; /*200 + \0 !*/ memcpy(buffer, type, len); buffer[len] = '\0'; type = buffer; /* Skip past any leading X. X: X, etc to allow for multiple instances */ for (char *str = type; *str; str++) { if (*str == ':' || *str == ',' || *str == '.') { str++; if (*str) { type = str; } break; } } /* if it is already set, skip this */ int nid = OBJ_txt2nid(type); if (X509_NAME_get_index_by_NID(subj, nid, -1) >= 0) { continue; } if (!X509_NAME_add_entry_by_txt(subj, type, MBSTRING_ASC, (unsigned char*)v->value, -1, -1, 0)) { raise_warning("add_entry_by_txt %s -> %s (failed)", type, v->value); return false; } if (!X509_NAME_entry_count(subj)) { raise_warning("no objects specified in config file"); return false; } } if (!add_entries(subj, attribs)) return false; if (attr_sk) { for (int i = 0; i < sk_CONF_VALUE_num(attr_sk); i++) { CONF_VALUE *v = sk_CONF_VALUE_value(attr_sk, i); /* if it is already set, skip this */ int nid = OBJ_txt2nid(v->name); if (X509_REQ_get_attr_by_NID(csr, nid, -1) >= 0) { continue; } if (!X509_REQ_add1_attr_by_txt(csr, v->name, MBSTRING_ASC, (unsigned char*)v->value, -1)) { /** * hzhao: mismatched version of conf file may have attributes that * are not recognizable, and I don't think it should be treated as * fatal errors. */ Logger::Verbose("add1_attr_by_txt %s -> %s (failed)", v->name, v->value); // return false; } } } } X509_REQ_set_pubkey(csr, req->priv_key); return true; } bool HHVM_FUNCTION(openssl_csr_export_to_file, const Variant& csr, const String& outfilename, bool notext /* = true */) { auto pcsr = CSRequest::Get(csr); if (!pcsr) return false; BIO *bio_out = BIO_new_file((char*)outfilename.data(), "w"); if (bio_out == nullptr) { raise_warning("error opening file %s", outfilename.data()); return false; } if (!notext) { X509_REQ_print(bio_out, pcsr->csr()); } PEM_write_bio_X509_REQ(bio_out, pcsr->csr()); BIO_free(bio_out); return true; } bool HHVM_FUNCTION(openssl_csr_export, const Variant& csr, Variant& out, bool notext /* = true */) { auto pcsr = CSRequest::Get(csr); if (!pcsr) return false; BIO *bio_out = BIO_new(BIO_s_mem()); if (!notext) { X509_REQ_print(bio_out, pcsr->csr()); } if (PEM_write_bio_X509_REQ(bio_out, pcsr->csr())) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); out = String((char*)bio_buf->data, bio_buf->length, CopyString); BIO_free(bio_out); return true; } BIO_free(bio_out); return false; } Variant HHVM_FUNCTION(openssl_csr_get_public_key, const Variant& csr) { auto pcsr = CSRequest::Get(csr); if (!pcsr) return false; auto input_csr = pcsr->csr(); #if OPENSSL_VERSION_NUMBER >= 0x10100000 /* Due to changes in OpenSSL 1.1 related to locking when decoding CSR, * the pub key is not changed after assigning. It means if we pass * a private key, it will be returned including the private part. * If we duplicate it, then we get just the public part which is * the same behavior as for OpenSSL 1.0 */ input_csr = X509_REQ_dup(input_csr); /* We need to free the CSR as it was duplicated */ SCOPE_EXIT { X509_REQ_free(input_csr); }; #endif auto pubkey = X509_REQ_get_pubkey(input_csr); if (!pubkey) return false; return Variant(req::make<Key>(pubkey)); } Variant HHVM_FUNCTION(openssl_csr_get_subject, const Variant& csr, bool use_shortnames /* = true */) { auto pcsr = CSRequest::Get(csr); if (!pcsr) return false; X509_NAME *subject = X509_REQ_get_subject_name(pcsr->csr()); Array ret = Array::CreateDArray(); add_assoc_name_entry(ret, nullptr, subject, use_shortnames); return ret; } Variant HHVM_FUNCTION(openssl_csr_new, const Variant& dn, Variant& privkey, const Variant& configargs /* = uninit_variant */, const Variant& extraattribs /* = uninit_variant */) { Variant ret = false; struct php_x509_request req; memset(&req, 0, sizeof(req)); req::ptr<Key> okey; X509_REQ *csr = nullptr; std::vector<String> strings; if (php_openssl_parse_config(&req, configargs.toArray(), strings)) { /* Generate or use a private key */ if (!privkey.isNull()) { okey = Key::Get(privkey, false); if (okey) { req.priv_key = okey->m_key; } } if (req.priv_key == nullptr) { req.generatePrivateKey(); if (req.priv_key) { okey = req::make<Key>(req.priv_key); } } if (req.priv_key == nullptr) { raise_warning("Unable to generate a private key"); } else { csr = X509_REQ_new(); if (csr && php_openssl_make_REQ(&req, csr, dn.toArray(), extraattribs.toArray())) { X509V3_CTX ext_ctx; X509V3_set_ctx(&ext_ctx, nullptr, nullptr, csr, nullptr, 0); X509V3_set_conf_lhash(&ext_ctx, req.req_config); /* Add extensions */ if (req.request_extensions_section && !X509V3_EXT_REQ_add_conf(req.req_config, &ext_ctx, (char*)req.request_extensions_section, csr)) { raise_warning("Error loading extension section %s", req.request_extensions_section); } else { ret = true; if (X509_REQ_sign(csr, req.priv_key, req.digest)) { ret = req::make<CSRequest>(csr); csr = nullptr; } else { raise_warning("Error signing request"); } privkey = Variant(okey); } } } } if (csr) { X509_REQ_free(csr); } php_openssl_dispose_config(&req); return ret; } Variant HHVM_FUNCTION(openssl_csr_sign, const Variant& csr, const Variant& cacert, const Variant& priv_key, int days, const Variant& configargs /* = null */, int serial /* = 0 */) { auto pcsr = CSRequest::Get(csr); if (!pcsr) return false; req::ptr<Certificate> ocert; if (!cacert.isNull()) { ocert = Certificate::Get(cacert); if (!ocert) { raise_warning("cannot get cert from parameter 2"); return false; } } auto okey = Key::Get(priv_key, false); if (!okey) { raise_warning("cannot get private key from parameter 3"); return false; } X509 *cert = nullptr; if (ocert) { cert = ocert->m_cert; } EVP_PKEY *pkey = okey->m_key; if (cert && !X509_check_private_key(cert, pkey)) { raise_warning("private key does not correspond to signing cert"); return false; } req::ptr<Certificate> onewcert; struct php_x509_request req; memset(&req, 0, sizeof(req)); Variant ret = false; std::vector<String> strings; if (!php_openssl_parse_config(&req, configargs.toArray(), strings)) { goto cleanup; } /* Check that the request matches the signature */ EVP_PKEY *key; key = X509_REQ_get_pubkey(pcsr->csr()); if (key == nullptr) { raise_warning("error unpacking public key"); goto cleanup; } int i; i = X509_REQ_verify(pcsr->csr(), key); if (i < 0) { raise_warning("Signature verification problems"); goto cleanup; } if (i == 0) { raise_warning("Signature did not match the certificate request"); goto cleanup; } /* Now we can get on with it */ X509 *new_cert; new_cert = X509_new(); if (new_cert == nullptr) { raise_warning("No memory"); goto cleanup; } onewcert = req::make<Certificate>(new_cert); /* Version 3 cert */ if (!X509_set_version(new_cert, 2)) { goto cleanup; } ASN1_INTEGER_set(X509_get_serialNumber(new_cert), serial); X509_set_subject_name(new_cert, X509_REQ_get_subject_name(pcsr->csr())); if (cert == nullptr) { cert = new_cert; } if (!X509_set_issuer_name(new_cert, X509_get_subject_name(cert))) { goto cleanup; } X509_gmtime_adj(X509_get_notBefore(new_cert), 0); X509_gmtime_adj(X509_get_notAfter(new_cert), (long)60 * 60 * 24 * days); i = X509_set_pubkey(new_cert, key); if (!i) { goto cleanup; } if (req.extensions_section) { X509V3_CTX ctx; X509V3_set_ctx(&ctx, cert, new_cert, pcsr->csr(), nullptr, 0); X509V3_set_conf_lhash(&ctx, req.req_config); if (!X509V3_EXT_add_conf(req.req_config, &ctx, (char*)req.extensions_section, new_cert)) { goto cleanup; } } /* Now sign it */ if (!X509_sign(new_cert, pkey, req.digest)) { raise_warning("failed to sign it"); goto cleanup; } /* Succeeded; lets return the cert */ ret = onewcert; cleanup: php_openssl_dispose_config(&req); return ret; } Variant HHVM_FUNCTION(openssl_error_string) { char buf[512]; unsigned long val = ERR_get_error(); if (val) { return String(ERR_error_string(val, buf), CopyString); } return false; } bool HHVM_FUNCTION(openssl_open, const String& sealed_data, Variant& open_data, const String& env_key, const Variant& priv_key_id, const String& method, /* = null_string */ const String& iv /* = null_string */) { const EVP_CIPHER *cipher_type; if (method.empty()) { cipher_type = EVP_rc4(); } else { cipher_type = EVP_get_cipherbyname(method.c_str()); if (!cipher_type) { raise_warning("Unknown cipher algorithm"); return false; } } auto okey = Key::Get(priv_key_id, false); if (!okey) { raise_warning("unable to coerce parameter 4 into a private key"); return false; } EVP_PKEY *pkey = okey->m_key; const unsigned char *iv_buf = nullptr; int iv_len = EVP_CIPHER_iv_length(cipher_type); if (iv_len > 0) { if (iv.empty()) { raise_warning( "Cipher algorithm requires an IV to be supplied as a sixth parameter"); return false; } if (iv.length() != iv_len) { raise_warning("IV length is invalid"); return false; } iv_buf = reinterpret_cast<const unsigned char*>(iv.c_str()); } String s = String(sealed_data.size(), ReserveString); unsigned char *buf = (unsigned char *)s.mutableData(); EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new(); if (ctx == nullptr) { raise_warning("Failed to allocate an EVP_CIPHER_CTX object"); return false; } SCOPE_EXIT { EVP_CIPHER_CTX_free(ctx); }; int len1, len2; if (!EVP_OpenInit( ctx, cipher_type, (unsigned char*)env_key.data(), env_key.size(), iv_buf, pkey) || !EVP_OpenUpdate( ctx, buf, &len1, (unsigned char*)sealed_data.data(), sealed_data.size()) || !EVP_OpenFinal(ctx, buf + len1, &len2) || len1 + len2 == 0) { return false; } open_data = s.setSize(len1 + len2); return true; } static STACK_OF(X509) *php_array_to_X509_sk(const Variant& certs) { STACK_OF(X509) *pcerts = sk_X509_new_null(); Array arrCerts; if (certs.isArray()) { arrCerts = certs.toArray(); } else { arrCerts.append(certs); } for (ArrayIter iter(arrCerts); iter; ++iter) { auto ocert = Certificate::Get(iter.second()); if (!ocert) { break; } sk_X509_push(pcerts, ocert->m_cert); } return pcerts; } const StaticString s_friendly_name("friendly_name"), s_extracerts("extracerts"); static bool openssl_pkcs12_export_impl(const Variant& x509, BIO *bio_out, const Variant& priv_key, const String& pass, const Variant& args /* = uninit_variant */) { auto ocert = Certificate::Get(x509); if (!ocert) { raise_warning("cannot get cert from parameter 1"); return false; } auto okey = Key::Get(priv_key, false); if (!okey) { raise_warning("cannot get private key from parameter 3"); return false; } X509 *cert = ocert->m_cert; EVP_PKEY *key = okey->m_key; if (cert && !X509_check_private_key(cert, key)) { raise_warning("private key does not correspond to cert"); return false; } Array arrArgs = args.toArray(); String friendly_name; if (arrArgs.exists(s_friendly_name)) { friendly_name = arrArgs[s_friendly_name].toString(); } STACK_OF(X509) *ca = nullptr; if (arrArgs.exists(s_extracerts)) { ca = php_array_to_X509_sk(arrArgs[s_extracerts]); } PKCS12 *p12 = PKCS12_create ((char*)pass.data(), (char*)(friendly_name.empty() ? nullptr : friendly_name.data()), key, cert, ca, 0, 0, 0, 0, 0); assertx(bio_out); bool ret = i2d_PKCS12_bio(bio_out, p12); PKCS12_free(p12); sk_X509_free(ca); return ret; } bool HHVM_FUNCTION(openssl_pkcs12_export_to_file, const Variant& x509, const String& filename, const Variant& priv_key, const String& pass, const Variant& args /* = uninit_variant */) { BIO *bio_out = BIO_new_file(filename.data(), "w"); if (bio_out == nullptr) { raise_warning("error opening file %s", filename.data()); return false; } bool ret = openssl_pkcs12_export_impl(x509, bio_out, priv_key, pass, args); BIO_free(bio_out); return ret; } bool HHVM_FUNCTION(openssl_pkcs12_export, const Variant& x509, Variant& out, const Variant& priv_key, const String& pass, const Variant& args /* = uninit_variant */) { BIO *bio_out = BIO_new(BIO_s_mem()); bool ret = openssl_pkcs12_export_impl(x509, bio_out, priv_key, pass, args); if (ret) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); out = String((char*)bio_buf->data, bio_buf->length, CopyString); } BIO_free(bio_out); return ret; } const StaticString s_cert("cert"), s_pkey("pkey"); bool HHVM_FUNCTION(openssl_pkcs12_read, const String& pkcs12, Variant& certs, const String& pass) { bool ret = false; PKCS12 *p12 = nullptr; BIO *bio_in = BIO_new(BIO_s_mem()); if (!BIO_write(bio_in, pkcs12.data(), pkcs12.size())) { goto cleanup; } if (d2i_PKCS12_bio(bio_in, &p12)) { EVP_PKEY *pkey = nullptr; X509 *cert = nullptr; STACK_OF(X509) *ca = nullptr; if (PKCS12_parse(p12, pass.data(), &pkey, &cert, &ca)) { Variant vcerts = Array::CreateDArray(); SCOPE_EXIT { certs = vcerts; }; BIO *bio_out = nullptr; if (cert) { bio_out = BIO_new(BIO_s_mem()); if (PEM_write_bio_X509(bio_out, cert)) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); vcerts.asArrRef().set(s_cert, String((char*)bio_buf->data, bio_buf->length, CopyString)); } BIO_free(bio_out); } if (pkey) { bio_out = BIO_new(BIO_s_mem()); if (PEM_write_bio_PrivateKey(bio_out, pkey, nullptr, nullptr, 0, 0, nullptr)) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); vcerts.asArrRef().set(s_pkey, String((char*)bio_buf->data, bio_buf->length, CopyString)); } BIO_free(bio_out); } if (ca) { Array extracerts; for (X509 *aCA = sk_X509_pop(ca); aCA; aCA = sk_X509_pop(ca)) { bio_out = BIO_new(BIO_s_mem()); if (PEM_write_bio_X509(bio_out, aCA)) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); extracerts.append(String((char*)bio_buf->data, bio_buf->length, CopyString)); } BIO_free(bio_out); X509_free(aCA); } sk_X509_free(ca); vcerts.asArrRef().set(s_extracerts, extracerts); } ret = true; PKCS12_free(p12); } } cleanup: if (bio_in) { BIO_free(bio_in); } return ret; } bool HHVM_FUNCTION(openssl_pkcs7_decrypt, const String& infilename, const String& outfilename, const Variant& recipcert, const Variant& recipkey /* = uninit_variant */) { bool ret = false; BIO *in = nullptr, *out = nullptr, *datain = nullptr; PKCS7 *p7 = nullptr; req::ptr<Key> okey; auto ocert = Certificate::Get(recipcert); if (!ocert) { raise_warning("unable to coerce parameter 3 to x509 cert"); goto clean_exit; } okey = Key::Get(recipkey.isNull() ? recipcert : recipkey, false); if (!okey) { raise_warning("unable to get private key"); goto clean_exit; } in = BIO_new_file(infilename.data(), "r"); if (in == nullptr) { raise_warning("error opening the file, %s", infilename.data()); goto clean_exit; } out = BIO_new_file(outfilename.data(), "w"); if (out == nullptr) { raise_warning("error opening the file, %s", outfilename.data()); goto clean_exit; } p7 = SMIME_read_PKCS7(in, &datain); if (p7 == nullptr) { goto clean_exit; } assertx(okey->m_key); assertx(ocert->m_cert); if (PKCS7_decrypt(p7, okey->m_key, ocert->m_cert, out, PKCS7_DETACHED)) { ret = true; } clean_exit: PKCS7_free(p7); BIO_free(datain); BIO_free(in); BIO_free(out); return ret; } static void print_headers(BIO *outfile, const Array& headers) { if (!headers.isNull()) { if (headers->isVectorData()) { for (ArrayIter iter(headers); iter; ++iter) { BIO_printf(outfile, "%s\n", iter.second().toString().data()); } } else { for (ArrayIter iter(headers); iter; ++iter) { BIO_printf(outfile, "%s: %s\n", iter.first().toString().data(), iter.second().toString().data()); } } } } bool HHVM_FUNCTION(openssl_pkcs7_encrypt, const String& infilename, const String& outfilename, const Variant& recipcerts, const Array& headers, int flags /* = 0 */, int cipherid /* = k_OPENSSL_CIPHER_RC2_40 */) { bool ret = false; BIO *infile = nullptr, *outfile = nullptr; STACK_OF(X509) *precipcerts = nullptr; PKCS7 *p7 = nullptr; const EVP_CIPHER *cipher = nullptr; infile = BIO_new_file(infilename.data(), (flags & PKCS7_BINARY) ? "rb" : "r"); if (infile == nullptr) { raise_warning("error opening the file, %s", infilename.data()); goto clean_exit; } outfile = BIO_new_file(outfilename.data(), "w"); if (outfile == nullptr) { raise_warning("error opening the file, %s", outfilename.data()); goto clean_exit; } precipcerts = php_array_to_X509_sk(recipcerts); /* sanity check the cipher */ switch (cipherid) { #ifndef OPENSSL_NO_RC2 case PHP_OPENSSL_CIPHER_RC2_40: cipher = EVP_rc2_40_cbc(); break; case PHP_OPENSSL_CIPHER_RC2_64: cipher = EVP_rc2_64_cbc(); break; case PHP_OPENSSL_CIPHER_RC2_128: cipher = EVP_rc2_cbc(); break; #endif #ifndef OPENSSL_NO_DES case PHP_OPENSSL_CIPHER_DES: cipher = EVP_des_cbc(); break; case PHP_OPENSSL_CIPHER_3DES: cipher = EVP_des_ede3_cbc(); break; #endif default: raise_warning("Invalid cipher type `%d'", cipherid); goto clean_exit; } if (cipher == nullptr) { raise_warning("Failed to get cipher"); goto clean_exit; } p7 = PKCS7_encrypt(precipcerts, infile, (EVP_CIPHER*)cipher, flags); if (p7 == nullptr) goto clean_exit; print_headers(outfile, headers); (void)BIO_reset(infile); SMIME_write_PKCS7(outfile, p7, infile, flags); ret = true; clean_exit: PKCS7_free(p7); BIO_free(infile); BIO_free(outfile); sk_X509_free(precipcerts); return ret; } bool HHVM_FUNCTION(openssl_pkcs7_sign, const String& infilename, const String& outfilename, const Variant& signcert, const Variant& privkey, const Variant& headers, int flags /* = k_PKCS7_DETACHED */, const String& extracerts /* = null_string */) { bool ret = false; STACK_OF(X509) *others = nullptr; BIO *infile = nullptr, *outfile = nullptr; PKCS7 *p7 = nullptr; req::ptr<Key> okey; req::ptr<Certificate> ocert; if (!extracerts.empty()) { others = load_all_certs_from_file(extracerts.data()); if (others == nullptr) { goto clean_exit; } } okey = Key::Get(privkey, false); if (!okey) { raise_warning("error getting private key"); goto clean_exit; } EVP_PKEY *key; key = okey->m_key; ocert = Certificate::Get(signcert); if (!ocert) { raise_warning("error getting cert"); goto clean_exit; } X509 *cert; cert = ocert->m_cert; infile = BIO_new_file(infilename.data(), (flags & PKCS7_BINARY) ? "rb" : "r"); if (infile == nullptr) { raise_warning("error opening input file %s!", infilename.data()); goto clean_exit; } outfile = BIO_new_file(outfilename.data(), "w"); if (outfile == nullptr) { raise_warning("error opening output file %s!", outfilename.data()); goto clean_exit; } p7 = PKCS7_sign(cert, key, others, infile, flags); if (p7 == nullptr) { raise_warning("error creating PKCS7 structure!"); goto clean_exit; } print_headers(outfile, headers.toArray()); (void)BIO_reset(infile); SMIME_write_PKCS7(outfile, p7, infile, flags); ret = true; clean_exit: PKCS7_free(p7); BIO_free(infile); BIO_free(outfile); if (others) { sk_X509_pop_free(others, X509_free); } return ret; } static int pkcs7_ignore_expiration(int ok, X509_STORE_CTX *ctx) { if (ok) { return ok; } int error = X509_STORE_CTX_get_error(ctx); if (error == X509_V_ERR_CERT_HAS_EXPIRED) { // ignore cert expirations Logger::Verbose("Ignoring cert expiration"); return 1; } return ok; } /** * NOTE: when ignore_cert_expiration is true, a custom certificate validation * callback is set up. Please be aware of this if you modify the function to * allow other certificate validation behaviors */ Variant openssl_pkcs7_verify_core( const String& filename, int flags, const Variant& voutfilename /* = null_string */, const Variant& vcainfo /* = null_array */, const Variant& vextracerts /* = null_string */, const Variant& vcontent /* = null_string */, bool ignore_cert_expiration ) { Variant ret = -1; X509_STORE *store = nullptr; BIO *in = nullptr; PKCS7 *p7 = nullptr; BIO *datain = nullptr; BIO *dataout = nullptr; auto cainfo = vcainfo.toArray(); auto extracerts = vextracerts.toString(); auto content = vcontent.toString(); STACK_OF(X509) *others = nullptr; if (!extracerts.empty()) { others = load_all_certs_from_file(extracerts.data()); if (others == nullptr) { goto clean_exit; } } flags = flags & ~PKCS7_DETACHED; store = setup_verify(cainfo); if (!store) { goto clean_exit; } if (ignore_cert_expiration) { #if (OPENSSL_VERSION_NUMBER >= 0x10000000) // make sure no other callback is specified #if OPENSSL_VERSION_NUMBER >= 0x10100000L assertx(!X509_STORE_get_verify_cb(store)); #else assertx(!store->verify_cb); #endif // ignore expired certs X509_STORE_set_verify_cb(store, pkcs7_ignore_expiration); #else always_assert(false); #endif } in = BIO_new_file(filename.data(), (flags & PKCS7_BINARY) ? "rb" : "r"); if (in == nullptr) { raise_warning("error opening the file, %s", filename.data()); goto clean_exit; } p7 = SMIME_read_PKCS7(in, &datain); if (p7 == nullptr) { goto clean_exit; } if (!content.empty()) { dataout = BIO_new_file(content.data(), "w"); if (dataout == nullptr) { raise_warning("error opening the file, %s", content.data()); goto clean_exit; } } if (PKCS7_verify(p7, others, store, datain, dataout, flags)) { ret = true; auto outfilename = voutfilename.toString(); if (!outfilename.empty()) { BIO *certout = BIO_new_file(outfilename.data(), "w"); if (certout) { STACK_OF(X509) *signers = PKCS7_get0_signers(p7, nullptr, flags); for (int i = 0; i < sk_X509_num(signers); i++) { PEM_write_bio_X509(certout, sk_X509_value(signers, i)); } BIO_free(certout); sk_X509_free(signers); } else { raise_warning("signature OK, but cannot open %s for writing", outfilename.data()); ret = -1; } } goto clean_exit; } else { ret = false; } clean_exit: X509_STORE_free(store); BIO_free(datain); BIO_free(in); BIO_free(dataout); PKCS7_free(p7); sk_X509_pop_free(others, X509_free); return ret; } Variant HHVM_FUNCTION(openssl_pkcs7_verify, const String& filename, int flags, const Variant& voutfilename /* = null_string */, const Variant& vcainfo /* = null_array */, const Variant& vextracerts /* = null_string */, const Variant& vcontent /* = null_string */) { return openssl_pkcs7_verify_core(filename, flags, voutfilename, vcainfo, vextracerts, vcontent, false); } static bool openssl_pkey_export_impl(const Variant& key, BIO *bio_out, const String& passphrase /* = null_string */, const Variant& configargs /* = uninit_variant */) { auto okey = Key::Get(key, false, passphrase.data()); if (!okey) { raise_warning("cannot get key from parameter 1"); return false; } EVP_PKEY *pkey = okey->m_key; struct php_x509_request req; memset(&req, 0, sizeof(req)); std::vector<String> strings; bool ret = false; if (php_openssl_parse_config(&req, configargs.toArray(), strings)) { const EVP_CIPHER *cipher; if (!passphrase.empty() && req.priv_key_encrypt) { cipher = (EVP_CIPHER *)EVP_des_ede3_cbc(); } else { cipher = nullptr; } assertx(bio_out); switch (EVP_PKEY_id(pkey)) { #ifdef HAVE_EVP_PKEY_EC case EVP_PKEY_EC: ret = PEM_write_bio_ECPrivateKey(bio_out, EVP_PKEY_get0_EC_KEY(pkey), cipher, (unsigned char *)passphrase.data(), passphrase.size(), nullptr, nullptr); break; #endif default: ret = PEM_write_bio_PrivateKey(bio_out, pkey, cipher, (unsigned char *)passphrase.data(), passphrase.size(), nullptr, nullptr); break; } } php_openssl_dispose_config(&req); return ret; } bool HHVM_FUNCTION(openssl_pkey_export_to_file, const Variant& key, const String& outfilename, const String& passphrase /* = null_string */, const Variant& configargs /* = uninit_variant */) { BIO *bio_out = BIO_new_file(outfilename.data(), "w"); if (bio_out == nullptr) { raise_warning("error opening the file, %s", outfilename.data()); return false; } bool ret = openssl_pkey_export_impl(key, bio_out, passphrase, configargs); BIO_free(bio_out); return ret; } bool HHVM_FUNCTION(openssl_pkey_export, const Variant& key, Variant& out, const String& passphrase /* = null_string */, const Variant& configargs /* = uninit_variant */) { BIO *bio_out = BIO_new(BIO_s_mem()); bool ret = openssl_pkey_export_impl(key, bio_out, passphrase, configargs); if (ret) { char *bio_mem_ptr; long bio_mem_len = BIO_get_mem_data(bio_out, &bio_mem_ptr); out = String(bio_mem_ptr, bio_mem_len, CopyString); } BIO_free(bio_out); return ret; } const StaticString s_bits("bits"), s_key("key"), s_type("type"), s_name("name"), s_hash("hash"), s_version("version"), s_serialNumber("serialNumber"), s_signatureAlgorithm("signatureAlgorithm"), s_validFrom("validFrom"), s_validTo("validTo"), s_validFrom_time_t("validFrom_time_t"), s_validTo_time_t("validTo_time_t"), s_alias("alias"), s_purposes("purposes"), s_extensions("extensions"), s_rsa("rsa"), s_dsa("dsa"), s_dh("dh"), s_ec("ec"), s_n("n"), s_e("e"), s_d("d"), s_p("p"), s_q("q"), s_g("g"), s_x("x"), s_y("y"), s_dmp1("dmp1"), s_dmq1("dmq1"), s_iqmp("iqmp"), s_priv_key("priv_key"), s_pub_key("pub_key"), s_curve_oid("curve_oid"); static void add_bignum_as_string(Array &arr, StaticString key, const BIGNUM *bn) { if (!bn) { return; } int num_bytes = BN_num_bytes(bn); String str{size_t(num_bytes), ReserveString}; BN_bn2bin(bn, (unsigned char*)str.mutableData()); str.setSize(num_bytes); arr.set(key, std::move(str)); } Array HHVM_FUNCTION(openssl_pkey_get_details, const Resource& key) { EVP_PKEY *pkey = cast<Key>(key)->m_key; BIO *out = BIO_new(BIO_s_mem()); PEM_write_bio_PUBKEY(out, pkey); char *pbio; unsigned int pbio_len = BIO_get_mem_data(out, &pbio); auto ret = make_darray( s_bits, EVP_PKEY_bits(pkey), s_key, String(pbio, pbio_len, CopyString) ); long ktype = -1; auto details = Array::CreateDArray(); switch (EVP_PKEY_id(pkey)) { case EVP_PKEY_RSA: case EVP_PKEY_RSA2: { ktype = OPENSSL_KEYTYPE_RSA; RSA *rsa = EVP_PKEY_get0_RSA(pkey); assertx(rsa); const BIGNUM *n, *e, *d, *p, *q, *dmp1, *dmq1, *iqmp; RSA_get0_key(rsa, &n, &e, &d); RSA_get0_factors(rsa, &p, &q); RSA_get0_crt_params(rsa, &dmp1, &dmq1, &iqmp); add_bignum_as_string(details, s_n, n); add_bignum_as_string(details, s_e, e); add_bignum_as_string(details, s_d, d); add_bignum_as_string(details, s_p, p); add_bignum_as_string(details, s_q, q); add_bignum_as_string(details, s_dmp1, dmp1); add_bignum_as_string(details, s_dmq1, dmq1); add_bignum_as_string(details, s_iqmp, iqmp); ret.set(s_rsa, details); break; } case EVP_PKEY_DSA: case EVP_PKEY_DSA2: case EVP_PKEY_DSA3: case EVP_PKEY_DSA4: { ktype = OPENSSL_KEYTYPE_DSA; DSA *dsa = EVP_PKEY_get0_DSA(pkey); assertx(dsa); const BIGNUM *p, *q, *g, *pub_key, *priv_key; DSA_get0_pqg(dsa, &p, &q, &g); DSA_get0_key(dsa, &pub_key, &priv_key); add_bignum_as_string(details, s_p, p); add_bignum_as_string(details, s_q, q); add_bignum_as_string(details, s_g, g); add_bignum_as_string(details, s_priv_key, priv_key); add_bignum_as_string(details, s_pub_key, pub_key); ret.set(s_dsa, details); break; } case EVP_PKEY_DH: { ktype = OPENSSL_KEYTYPE_DH; DH *dh = EVP_PKEY_get0_DH(pkey); assertx(dh); const BIGNUM *p, *q, *g, *pub_key, *priv_key; DH_get0_pqg(dh, &p, &q, &g); DH_get0_key(dh, &pub_key, &priv_key); add_bignum_as_string(details, s_p, p); add_bignum_as_string(details, s_g, g); add_bignum_as_string(details, s_priv_key, priv_key); add_bignum_as_string(details, s_pub_key, pub_key); ret.set(s_dh, details); break; } #ifdef HAVE_EVP_PKEY_EC case EVP_PKEY_EC: { ktype = OPENSSL_KEYTYPE_EC; auto const ec = EVP_PKEY_get0_EC_KEY(pkey); assertx(ec); auto const ec_group = EC_KEY_get0_group(ec); auto const nid = EC_GROUP_get_curve_name(ec_group); if (nid == NID_undef) { break; } auto const crv_sn = OBJ_nid2sn(nid); if (crv_sn != nullptr) { details.set(s_curve_name, String(crv_sn, CopyString)); } auto const obj = OBJ_nid2obj(nid); if (obj != nullptr) { SCOPE_EXIT { ASN1_OBJECT_free(obj); }; char oir_buf[256]; OBJ_obj2txt(oir_buf, sizeof(oir_buf) - 1, obj, 1); details.set(s_curve_oid, String(oir_buf, CopyString)); } auto x = BN_new(); auto y = BN_new(); SCOPE_EXIT { BN_free(x); BN_free(y); }; auto const pub = EC_KEY_get0_public_key(ec); if (EC_POINT_get_affine_coordinates_GFp(ec_group, pub, x, y, nullptr)) { add_bignum_as_string(details, s_x, x); add_bignum_as_string(details, s_y, y); } auto d = BN_dup(EC_KEY_get0_private_key(ec)); SCOPE_EXIT { BN_free(d); }; if (d != nullptr) { add_bignum_as_string(details, s_d, d); } ret.set(s_ec, details); } break; #endif } ret.set(s_type, ktype); BIO_free(out); return ret; } Variant HHVM_FUNCTION(openssl_pkey_get_private, const Variant& key, const String& passphrase /* = null_string */) { return toVariant(Key::Get(key, false, passphrase.data())); } Variant HHVM_FUNCTION(openssl_pkey_get_public, const Variant& certificate) { return toVariant(Key::Get(certificate, true)); } Variant HHVM_FUNCTION(openssl_pkey_new, const Variant& configargs /* = uninit_variant */) { struct php_x509_request req; memset(&req, 0, sizeof(req)); SCOPE_EXIT { php_openssl_dispose_config(&req); }; std::vector<String> strings; if (php_openssl_parse_config(&req, configargs.toArray(), strings) && req.generatePrivateKey()) { return Resource(req::make<Key>(req.priv_key)); } else { return false; } } bool HHVM_FUNCTION(openssl_private_decrypt, const String& data, Variant& decrypted, const Variant& key, int padding /* = k_OPENSSL_PKCS1_PADDING */) { auto okey = Key::Get(key, false); if (!okey) { raise_warning("key parameter is not a valid private key"); return false; } EVP_PKEY *pkey = okey->m_key; int cryptedlen = EVP_PKEY_size(pkey); String s = String(cryptedlen, ReserveString); unsigned char *cryptedbuf = (unsigned char *)s.mutableData(); int successful = 0; switch (EVP_PKEY_id(pkey)) { case EVP_PKEY_RSA: case EVP_PKEY_RSA2: cryptedlen = RSA_private_decrypt(data.size(), (unsigned char *)data.data(), cryptedbuf, EVP_PKEY_get0_RSA(pkey), padding); if (cryptedlen != -1) { successful = 1; } break; default: raise_warning("key type not supported"); } if (successful) { decrypted = s.setSize(cryptedlen); return true; } return false; } bool HHVM_FUNCTION(openssl_private_encrypt, const String& data, Variant& crypted, const Variant& key, int padding /* = k_OPENSSL_PKCS1_PADDING */) { auto okey = Key::Get(key, false); if (!okey) { raise_warning("key param is not a valid private key"); return false; } EVP_PKEY *pkey = okey->m_key; int cryptedlen = EVP_PKEY_size(pkey); String s = String(cryptedlen, ReserveString); unsigned char *cryptedbuf = (unsigned char *)s.mutableData(); int successful = 0; switch (EVP_PKEY_id(pkey)) { case EVP_PKEY_RSA: case EVP_PKEY_RSA2: successful = (RSA_private_encrypt(data.size(), (unsigned char *)data.data(), cryptedbuf, EVP_PKEY_get0_RSA(pkey), padding) == cryptedlen); break; default: raise_warning("key type not supported"); } if (successful) { crypted = s.setSize(cryptedlen); return true; } return false; } bool HHVM_FUNCTION(openssl_public_decrypt, const String& data, Variant& decrypted, const Variant& key, int padding /* = k_OPENSSL_PKCS1_PADDING */) { auto okey = Key::Get(key, true); if (!okey) { raise_warning("key parameter is not a valid public key"); return false; } EVP_PKEY *pkey = okey->m_key; int cryptedlen = EVP_PKEY_size(pkey); String s = String(cryptedlen, ReserveString); unsigned char *cryptedbuf = (unsigned char *)s.mutableData(); int successful = 0; switch (EVP_PKEY_id(pkey)) { case EVP_PKEY_RSA: case EVP_PKEY_RSA2: cryptedlen = RSA_public_decrypt(data.size(), (unsigned char *)data.data(), cryptedbuf, EVP_PKEY_get0_RSA(pkey), padding); if (cryptedlen != -1) { successful = 1; } break; default: raise_warning("key type not supported"); } if (successful) { decrypted = s.setSize(cryptedlen); return true; } return false; } bool HHVM_FUNCTION(openssl_public_encrypt, const String& data, Variant& crypted, const Variant& key, int padding /* = k_OPENSSL_PKCS1_PADDING */) { auto okey = Key::Get(key, true); if (!okey) { raise_warning("key parameter is not a valid public key"); return false; } EVP_PKEY *pkey = okey->m_key; int cryptedlen = EVP_PKEY_size(pkey); String s = String(cryptedlen, ReserveString); unsigned char *cryptedbuf = (unsigned char *)s.mutableData(); int successful = 0; switch (EVP_PKEY_id(pkey)) { case EVP_PKEY_RSA: case EVP_PKEY_RSA2: successful = (RSA_public_encrypt(data.size(), (unsigned char *)data.data(), cryptedbuf, EVP_PKEY_get0_RSA(pkey), padding) == cryptedlen); break; default: raise_warning("key type not supported"); } if (successful) { crypted = s.setSize(cryptedlen); return true; } return false; } Variant HHVM_FUNCTION(openssl_seal, const String& data, Variant& sealed_data, Variant& env_keys, const Array& pub_key_ids, const String& method, Variant& iv) { int nkeys = pub_key_ids.size(); if (nkeys == 0) { raise_warning("Fourth argument to openssl_seal() must be " "a non-empty array"); return false; } const EVP_CIPHER *cipher_type; if (method.empty()) { cipher_type = EVP_rc4(); } else { cipher_type = EVP_get_cipherbyname(method.c_str()); if (!cipher_type) { raise_warning("Unknown cipher algorithm"); return false; } } int iv_len = EVP_CIPHER_iv_length(cipher_type); unsigned char *iv_buf = nullptr; String iv_s; if (iv_len > 0) { iv_s = String(iv_len, ReserveString); iv_buf = (unsigned char*)iv_s.mutableData(); if (!RAND_bytes(iv_buf, iv_len)) { raise_warning("Could not generate an IV."); return false; } } EVP_PKEY **pkeys = (EVP_PKEY**)malloc(nkeys * sizeof(*pkeys)); int *eksl = (int*)malloc(nkeys * sizeof(*eksl)); unsigned char **eks = (unsigned char **)malloc(nkeys * sizeof(*eks)); memset(eks, 0, sizeof(*eks) * nkeys); // holder is needed to make sure none of the Keys get deleted prematurely. // The pkeys array points to elements inside of Keys returned from Key::Get() // which may be newly allocated and have no other owners. std::vector<req::ptr<Key>> holder; /* get the public keys we are using to seal this data */ bool ret = true; int i = 0; String s; unsigned char* buf = nullptr; EVP_CIPHER_CTX* ctx = nullptr; for (ArrayIter iter(pub_key_ids); iter; ++iter, ++i) { auto okey = Key::Get(iter.second(), true); if (!okey) { raise_warning("not a public key (%dth member of pubkeys)", i + 1); ret = false; goto clean_exit; } holder.push_back(okey); pkeys[i] = okey->m_key; eks[i] = (unsigned char *)malloc(EVP_PKEY_size(pkeys[i]) + 1); } ctx = EVP_CIPHER_CTX_new(); if (ctx == nullptr) { raise_warning("Failed to allocate an EVP_CIPHER_CTX object"); ret = false; goto clean_exit; } if (!EVP_EncryptInit_ex(ctx, cipher_type, nullptr, nullptr, nullptr)) { ret = false; goto clean_exit; } int len1, len2; s = String(data.size() + EVP_CIPHER_CTX_block_size(ctx), ReserveString); buf = (unsigned char *)s.mutableData(); if (EVP_SealInit(ctx, cipher_type, eks, eksl, iv_buf, pkeys, nkeys) <= 0 || !EVP_SealUpdate(ctx, buf, &len1, (unsigned char*)data.data(), data.size()) || !EVP_SealFinal(ctx, buf + len1, &len2)) { ret = false; goto clean_exit; } if (len1 + len2 > 0) { sealed_data = s.setSize(len1 + len2); auto ekeys = Array::CreateVArray(); for (i = 0; i < nkeys; i++) { eks[i][eksl[i]] = '\0'; ekeys.append(String((char*)eks[i], eksl[i], AttachString)); eks[i] = nullptr; } env_keys = ekeys; } clean_exit: for (i = 0; i < nkeys; i++) { if (eks[i]) free(eks[i]); } free(eks); free(eksl); free(pkeys); if (iv_buf != nullptr) { if (ret) { iv = iv_s.setSize(iv_len); } } if (ctx != nullptr) { EVP_CIPHER_CTX_free(ctx); } if (ret) return len1 + len2; return false; } static const EVP_MD *php_openssl_get_evp_md_from_algo(long algo) { switch (algo) { case OPENSSL_ALGO_SHA1: return EVP_sha1(); case OPENSSL_ALGO_MD5: return EVP_md5(); case OPENSSL_ALGO_MD4: return EVP_md4(); #ifdef HAVE_OPENSSL_MD2_H case OPENSSL_ALGO_MD2: return EVP_md2(); #endif #if OPENSSL_VERSION_NUMBER < 0x10100000L case OPENSSL_ALGO_DSS1: return EVP_dss1(); #endif #if OPENSSL_VERSION_NUMBER >= 0x0090708fL case OPENSSL_ALGO_SHA224: return EVP_sha224(); case OPENSSL_ALGO_SHA256: return EVP_sha256(); case OPENSSL_ALGO_SHA384: return EVP_sha384(); case OPENSSL_ALGO_SHA512: return EVP_sha512(); case OPENSSL_ALGO_RMD160: return EVP_ripemd160(); #endif } return nullptr; } bool HHVM_FUNCTION(openssl_sign, const String& data, Variant& signature, const Variant& priv_key_id, const Variant& signature_alg /* = k_OPENSSL_ALGO_SHA1 */) { auto okey = Key::Get(priv_key_id, false); if (!okey) { raise_warning("supplied key param cannot be coerced into a private key"); return false; } const EVP_MD *mdtype = nullptr; if (signature_alg.isInteger()) { mdtype = php_openssl_get_evp_md_from_algo(signature_alg.toInt64Val()); } else if (signature_alg.isString()) { mdtype = EVP_get_digestbyname(signature_alg.toString().data()); } if (!mdtype) { raise_warning("Unknown signature algorithm."); return false; } EVP_PKEY *pkey = okey->m_key; int siglen = EVP_PKEY_size(pkey); String s = String(siglen, ReserveString); unsigned char *sigbuf = (unsigned char *)s.mutableData(); EVP_MD_CTX *md_ctx = EVP_MD_CTX_new(); SCOPE_EXIT { EVP_MD_CTX_free(md_ctx); }; EVP_SignInit(md_ctx, mdtype); EVP_SignUpdate(md_ctx, (unsigned char *)data.data(), data.size()); if (EVP_SignFinal(md_ctx, sigbuf, (unsigned int *)&siglen, pkey)) { signature = s.setSize(siglen); return true; } return false; } Variant HHVM_FUNCTION(openssl_verify, const String& data, const String& signature, const Variant& pub_key_id, const Variant& signature_alg /* = k_OPENSSL_ALGO_SHA1 */) { int err; const EVP_MD *mdtype = nullptr; if (signature_alg.isInteger()) { mdtype = php_openssl_get_evp_md_from_algo(signature_alg.toInt64Val()); } else if (signature_alg.isString()) { mdtype = EVP_get_digestbyname(signature_alg.toString().data()); } if (!mdtype) { raise_warning("Unknown signature algorithm."); return false; } auto okey = Key::Get(pub_key_id, true); if (!okey) { raise_warning("supplied key param cannot be coerced into a public key"); return false; } EVP_MD_CTX *md_ctx = EVP_MD_CTX_new(); SCOPE_EXIT { EVP_MD_CTX_free(md_ctx); }; EVP_VerifyInit(md_ctx, mdtype); EVP_VerifyUpdate(md_ctx, (unsigned char*)data.data(), data.size()); err = EVP_VerifyFinal(md_ctx, (unsigned char *)signature.data(), signature.size(), okey->m_key); return err; } bool HHVM_FUNCTION(openssl_x509_check_private_key, const Variant& cert, const Variant& key) { auto ocert = Certificate::Get(cert); if (!ocert) { return false; } auto okey = Key::Get(key, false); if (!okey) { return false; } return X509_check_private_key(ocert->m_cert, okey->m_key); } static int check_cert(X509_STORE *ctx, X509 *x, STACK_OF(X509) *untrustedchain, int purpose) { X509_STORE_CTX *csc = X509_STORE_CTX_new(); if (csc == nullptr) { raise_warning("memory allocation failure"); return 0; } X509_STORE_CTX_init(csc, ctx, x, untrustedchain); if (purpose >= 0) { X509_STORE_CTX_set_purpose(csc, purpose); } int ret = X509_verify_cert(csc); X509_STORE_CTX_free(csc); return ret; } Variant HHVM_FUNCTION(openssl_x509_checkpurpose, const Variant& x509cert, int purpose, const Array& cainfo /* = null_array */, const String& untrustedfile /* = null_string */) { int ret = -1; STACK_OF(X509) *untrustedchain = nullptr; X509_STORE *pcainfo = nullptr; req::ptr<Certificate> ocert; if (!untrustedfile.empty()) { untrustedchain = load_all_certs_from_file(untrustedfile.data()); if (untrustedchain == nullptr) { goto clean_exit; } } pcainfo = setup_verify(cainfo); if (pcainfo == nullptr) { goto clean_exit; } ocert = Certificate::Get(x509cert); if (!ocert) { raise_warning("cannot get cert from parameter 1"); return false; } X509 *cert; cert = ocert->m_cert; assertx(cert); ret = check_cert(pcainfo, cert, untrustedchain, purpose); clean_exit: if (pcainfo) { X509_STORE_free(pcainfo); } if (untrustedchain) { sk_X509_pop_free(untrustedchain, X509_free); } return ret == 1 ? true : ret == 0 ? false : -1; } static bool openssl_x509_export_impl(const Variant& x509, BIO *bio_out, bool notext /* = true */) { auto ocert = Certificate::Get(x509); if (!ocert) { raise_warning("cannot get cert from parameter 1"); return false; } X509 *cert = ocert->m_cert; assertx(cert); assertx(bio_out); if (!notext) { X509_print(bio_out, cert); } return PEM_write_bio_X509(bio_out, cert); } bool HHVM_FUNCTION(openssl_x509_export_to_file, const Variant& x509, const String& outfilename, bool notext /* = true */) { BIO *bio_out = BIO_new_file((char*)outfilename.data(), "w"); if (bio_out == nullptr) { raise_warning("error opening file %s", outfilename.data()); return false; } bool ret = openssl_x509_export_impl(x509, bio_out, notext); BIO_free(bio_out); return ret; } bool HHVM_FUNCTION(openssl_x509_export, const Variant& x509, Variant& output, bool notext /* = true */) { BIO *bio_out = BIO_new(BIO_s_mem()); bool ret = openssl_x509_export_impl(x509, bio_out, notext); if (ret) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); output = String(bio_buf->data, bio_buf->length, CopyString); } BIO_free(bio_out); return ret; } /** * This is how the time string is formatted: * * snprintf(p, sizeof(p), "%02d%02d%02d%02d%02d%02dZ",ts->tm_year%100, * ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); */ static time_t asn1_time_to_time_t(ASN1_UTCTIME *timestr) { auto const timestr_type = ASN1_STRING_type(timestr); if (timestr_type != V_ASN1_UTCTIME && timestr_type != V_ASN1_GENERALIZEDTIME) { raise_warning("illegal ASN1 data type for timestamp"); return (time_t)-1; } auto const timestr_len = (size_t)ASN1_STRING_length(timestr); // Binary safety if (timestr_len != strlen((char*)ASN1_STRING_data(timestr))) { raise_warning("illegal length in timestamp"); return (time_t)-1; } if (timestr_len < 13 && timestr_len != 11) { raise_warning("unable to parse time string %s correctly", timestr->data); return (time_t)-1; } if (timestr_type == V_ASN1_GENERALIZEDTIME && timestr_len < 15) { raise_warning("unable to parse time string %s correctly", timestr->data); return (time_t)-1; } char *strbuf = strdup((char*)timestr->data); struct tm thetime; memset(&thetime, 0, sizeof(thetime)); /* we work backwards so that we can use atoi more easily */ char *thestr = strbuf + ASN1_STRING_length(timestr) - 3; if (ASN1_STRING_length(timestr) == 11) { thetime.tm_sec = 0; } else { thetime.tm_sec = atoi(thestr); *thestr = '\0'; thestr -= 2; } thetime.tm_min = atoi(thestr); *thestr = '\0'; thestr -= 2; thetime.tm_hour = atoi(thestr); *thestr = '\0'; thestr -= 2; thetime.tm_mday = atoi(thestr); *thestr = '\0'; thestr -= 2; thetime.tm_mon = atoi(thestr)-1; *thestr = '\0'; if (ASN1_STRING_type(timestr) == V_ASN1_UTCTIME) { thestr -= 2; thetime.tm_year = atoi(thestr); if (thetime.tm_year < 68) { thetime.tm_year += 100; } } else if (ASN1_STRING_type(timestr) == V_ASN1_GENERALIZEDTIME) { thestr -= 4; thetime.tm_year = atoi(thestr) - 1900; } thetime.tm_isdst = -1; time_t ret = mktime(&thetime); long gmadjust = 0; #if HAVE_TM_GMTOFF gmadjust = thetime.tm_gmtoff; #elif defined(_MSC_VER) TIME_ZONE_INFORMATION inf; GetTimeZoneInformation(&inf); gmadjust = thetime.tm_isdst ? inf.DaylightBias : inf.StandardBias; #else /** * If correcting for daylight savings time, we set the adjustment to * the value of timezone - 3600 seconds. Otherwise, we need to overcorrect * and set the adjustment to the main timezone + 3600 seconds. */ gmadjust = -(thetime.tm_isdst ? (long)timezone - 3600 : (long)timezone); #endif /* no adjustment for UTC */ if (timezone) ret += gmadjust; free(strbuf); return ret; } /* Special handling of subjectAltName, see CVE-2013-4073 * Christian Heimes */ static int openssl_x509v3_subjectAltName(BIO *bio, X509_EXTENSION *extension) { GENERAL_NAMES *names; const X509V3_EXT_METHOD *method = nullptr; long i, length, num; const unsigned char *p; method = X509V3_EXT_get(extension); if (method == nullptr) { return -1; } const auto data = X509_EXTENSION_get_data(extension); p = data->data; length = data->length; if (method->it) { names = (GENERAL_NAMES*)(ASN1_item_d2i(nullptr, &p, length, ASN1_ITEM_ptr(method->it))); } else { names = (GENERAL_NAMES*)(method->d2i(nullptr, &p, length)); } if (names == nullptr) { return -1; } num = sk_GENERAL_NAME_num(names); for (i = 0; i < num; i++) { GENERAL_NAME *name; ASN1_STRING *as; name = sk_GENERAL_NAME_value(names, i); switch (name->type) { case GEN_EMAIL: BIO_puts(bio, "email:"); as = name->d.rfc822Name; BIO_write(bio, ASN1_STRING_data(as), ASN1_STRING_length(as)); break; case GEN_DNS: BIO_puts(bio, "DNS:"); as = name->d.dNSName; BIO_write(bio, ASN1_STRING_data(as), ASN1_STRING_length(as)); break; case GEN_URI: BIO_puts(bio, "URI:"); as = name->d.uniformResourceIdentifier; BIO_write(bio, ASN1_STRING_data(as), ASN1_STRING_length(as)); break; default: /* use builtin print for GEN_OTHERNAME, GEN_X400, * GEN_EDIPARTY, GEN_DIRNAME, GEN_IPADD and GEN_RID */ GENERAL_NAME_print(bio, name); } /* trailing ', ' except for last element */ if (i < (num - 1)) { BIO_puts(bio, ", "); } } sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free); return 0; } Variant HHVM_FUNCTION(openssl_x509_parse, const Variant& x509cert, bool shortnames /* = true */) { auto ocert = Certificate::Get(x509cert); if (!ocert) { return false; } X509 *cert = ocert->m_cert; assertx(cert); auto ret = Array::CreateDArray(); const auto sn = X509_get_subject_name(cert); if (sn) { ret.set(s_name, String(X509_NAME_oneline(sn, nullptr, 0), CopyString)); } add_assoc_name_entry(ret, "subject", sn, shortnames); /* hash as used in CA directories to lookup cert by subject name */ { char buf[32]; snprintf(buf, sizeof(buf), "%08lx", X509_subject_name_hash(cert)); ret.set(s_hash, String(buf, CopyString)); } add_assoc_name_entry(ret, "issuer", X509_get_issuer_name(cert), shortnames); ret.set(s_version, X509_get_version(cert)); ret.set(s_serialNumber, String (i2s_ASN1_INTEGER(nullptr, X509_get_serialNumber(cert)), AttachString)); // Adding Signature Algorithm BIO *bio_out = BIO_new(BIO_s_mem()); SCOPE_EXIT { BIO_free(bio_out); }; if (i2a_ASN1_OBJECT(bio_out, X509_get0_tbs_sigalg(cert)->algorithm) > 0) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); ret.set(s_signatureAlgorithm, String((char*)bio_buf->data, bio_buf->length, CopyString)); } ASN1_STRING *str = X509_get_notBefore(cert); ret.set(s_validFrom, String((char*)str->data, str->length, CopyString)); str = X509_get_notAfter(cert); ret.set(s_validTo, String((char*)str->data, str->length, CopyString)); ret.set(s_validFrom_time_t, asn1_time_to_time_t(X509_get_notBefore(cert))); ret.set(s_validTo_time_t, asn1_time_to_time_t(X509_get_notAfter(cert))); char *tmpstr = (char *)X509_alias_get0(cert, nullptr); if (tmpstr) { ret.set(s_alias, String(tmpstr, CopyString)); } /* NOTE: the purposes are added as integer keys - the keys match up to the X509_PURPOSE_SSL_XXX defines in x509v3.h */ { Array subitem; for (int i = 0; i < X509_PURPOSE_get_count(); i++) { X509_PURPOSE *purp = X509_PURPOSE_get0(i); int id = X509_PURPOSE_get_id(purp); char * pname = shortnames ? X509_PURPOSE_get0_sname(purp) : X509_PURPOSE_get0_name(purp); auto subsub = make_varray( (bool)X509_check_purpose(cert, id, 0), (bool)X509_check_purpose(cert, id, 1), String(pname, CopyString) ); subitem.set(id, std::move(subsub)); } ret.set(s_purposes, subitem); } { auto subitem = Array::CreateDArray(); for (int i = 0; i < X509_get_ext_count(cert); i++) { int nid; X509_EXTENSION *extension = X509_get_ext(cert, i); char *extname; char buf[256]; nid = OBJ_obj2nid(X509_EXTENSION_get_object(extension)); if (nid != NID_undef) { extname = (char*)OBJ_nid2sn(OBJ_obj2nid (X509_EXTENSION_get_object(extension))); } else { OBJ_obj2txt(buf, sizeof(buf)-1, X509_EXTENSION_get_object(extension), 1); extname = buf; } BIO *bio_out = BIO_new(BIO_s_mem()); if (nid == NID_subject_alt_name) { if (openssl_x509v3_subjectAltName(bio_out, extension) == 0) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); subitem.set(String(extname, CopyString), String((char*)bio_buf->data, bio_buf->length, CopyString)); } else { BIO_free(bio_out); return false; } } else if (X509V3_EXT_print(bio_out, extension, 0, 0)) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); subitem.set(String(extname, CopyString), String((char*)bio_buf->data, bio_buf->length, CopyString)); } else { str = X509_EXTENSION_get_data(extension); subitem.set(String(extname, CopyString), String((char*)str->data, str->length, CopyString)); } BIO_free(bio_out); } ret.set(s_extensions, subitem); } return ret; } Variant HHVM_FUNCTION(openssl_x509_read, const Variant& x509certdata) { auto ocert = Certificate::Get(x509certdata); if (!ocert) { raise_warning("supplied parameter cannot be coerced into " "an X509 certificate!"); return false; } return Variant(ocert); } Variant HHVM_FUNCTION(openssl_random_pseudo_bytes, int length, bool& crypto_strong) { if (length <= 0) { return false; } unsigned char *buffer = nullptr; String s = String(length, ReserveString); buffer = (unsigned char *)s.mutableData(); if (RAND_bytes(buffer, length) <= 0) { crypto_strong = false; return false; } else { crypto_strong = true; s.setSize(length); return s; } } Variant HHVM_FUNCTION(openssl_cipher_iv_length, const String& method) { if (method.empty()) { raise_warning("Unknown cipher algorithm"); return false; } const EVP_CIPHER *cipher_type = EVP_get_cipherbyname(method.c_str()); if (!cipher_type) { raise_warning("Unknown cipher algorithm"); return false; } return EVP_CIPHER_iv_length(cipher_type); } /* Cipher mode info */ struct php_openssl_cipher_mode { /* Whether this mode uses authenticated encryption. True, for example, with the GCM and CCM modes */ bool is_aead; /* Whether this mode is a 'single run aead', meaning that DecryptFinal doesn't get called. For example, CCM mode is a single run aead mode. */ bool is_single_run_aead; /* The OpenSSL flag to get the computed tag, if this mode is aead. */ int aead_get_tag_flag; /* The OpenSSL flag to set the computed tag, if this mode is aead. */ int aead_set_tag_flag; /* The OpenSSL flag to set the IV length, if this mode is aead */ int aead_ivlen_flag; }; // initialize a php_openssl_cipher_mode corresponding to an EVP_CIPHER. static php_openssl_cipher_mode php_openssl_load_cipher_mode( const EVP_CIPHER* cipher_type) { php_openssl_cipher_mode mode = {}; switch (EVP_CIPHER_mode(cipher_type)) { #ifdef EVP_CIPH_GCM_MODE case EVP_CIPH_GCM_MODE: mode.is_aead = true; mode.is_single_run_aead = false; mode.aead_get_tag_flag = EVP_CTRL_GCM_GET_TAG; mode.aead_set_tag_flag = EVP_CTRL_GCM_SET_TAG; mode.aead_ivlen_flag = EVP_CTRL_GCM_SET_IVLEN; break; #endif #ifdef EVP_CIPH_CCM_MODE case EVP_CIPH_CCM_MODE: mode.is_aead = true; mode.is_single_run_aead = true; mode.aead_get_tag_flag = EVP_CTRL_CCM_GET_TAG; mode.aead_set_tag_flag = EVP_CTRL_CCM_SET_TAG; mode.aead_ivlen_flag = EVP_CTRL_CCM_SET_IVLEN; break; #endif default: break; } return mode; } static bool php_openssl_validate_iv( String piv, int iv_required_len, String& out, EVP_CIPHER_CTX* cipher_ctx, const php_openssl_cipher_mode* mode) { if (cipher_ctx == nullptr || mode == nullptr) { return false; } /* Best case scenario, user behaved */ if (piv.size() == iv_required_len) { out = std::move(piv); return true; } if (mode->is_aead) { if (EVP_CIPHER_CTX_ctrl( cipher_ctx, mode->aead_ivlen_flag, piv.size(), nullptr) != 1) { raise_warning( "Setting of IV length for AEAD mode failed, the expected length is " "%d bytes", iv_required_len); return false; } out = std::move(piv); return true; } String s = String(iv_required_len, ReserveString); char* iv_new = s.mutableData(); memset(iv_new, 0, iv_required_len); if (piv.size() <= 0) { /* BC behavior */ s.setSize(iv_required_len); out = std::move(s); return true; } if (piv.size() < iv_required_len) { raise_warning("IV passed is only %d bytes long, cipher " "expects an IV of precisely %d bytes, padding with \\0", piv.size(), iv_required_len); memcpy(iv_new, piv.data(), piv.size()); s.setSize(iv_required_len); out = std::move(s); return true; } raise_warning("IV passed is %d bytes long which is longer than the %d " "expected by selected cipher, truncating", piv.size(), iv_required_len); memcpy(iv_new, piv.data(), iv_required_len); s.setSize(iv_required_len); out = std::move(s); return true; } namespace { Variant openssl_encrypt_impl(const String& data, const String& method, const String& password, int options, const String& iv, Variant* tag_out, const String& aad, int tag_length) { const EVP_CIPHER *cipher_type = EVP_get_cipherbyname(method.c_str()); if (!cipher_type) { raise_warning("Unknown cipher algorithm"); return false; } EVP_CIPHER_CTX* cipher_ctx = EVP_CIPHER_CTX_new(); if (!cipher_ctx) { raise_warning("Failed to create cipher context"); return false; } SCOPE_EXIT { EVP_CIPHER_CTX_free(cipher_ctx); }; php_openssl_cipher_mode mode = php_openssl_load_cipher_mode(cipher_type); if (mode.is_aead && !tag_out) { raise_warning("Must call openssl_encrypt_with_tag when using an AEAD cipher"); return false; } int keylen = EVP_CIPHER_key_length(cipher_type); String key = password; /* * older openssl libraries can assert if the passed in password length is * less than keylen */ if (keylen > password.size()) { String s = String(keylen, ReserveString); char *keybuf = s.mutableData(); memset(keybuf, 0, keylen); memcpy(keybuf, password.data(), password.size()); key = s.setSize(keylen); } int max_iv_len = EVP_CIPHER_iv_length(cipher_type); if (iv.size() <= 0 && max_iv_len > 0 && !mode.is_aead) { raise_warning("Using an empty Initialization Vector (iv) is potentially " "insecure and not recommended"); } int result_len = 0; int outlen = data.size() + EVP_CIPHER_block_size(cipher_type); String rv = String(outlen, ReserveString); unsigned char *outbuf = (unsigned char*)rv.mutableData(); EVP_EncryptInit_ex(cipher_ctx, cipher_type, nullptr, nullptr, nullptr); String new_iv; // we do this after EncryptInit because validate_iv changes cipher_ctx for // aead modes (must be initialized first). if (!php_openssl_validate_iv( std::move(iv), max_iv_len, new_iv, cipher_ctx, &mode)) { return false; } // set the tag length for CCM mode/other modes that require tag lengths to // be set. if (mode.is_single_run_aead && !EVP_CIPHER_CTX_ctrl( cipher_ctx, mode.aead_set_tag_flag, tag_length, nullptr)) { raise_warning("Setting tag length failed"); return false; } if (password.size() > keylen) { EVP_CIPHER_CTX_set_key_length(cipher_ctx, password.size()); } EVP_EncryptInit_ex( cipher_ctx, nullptr, nullptr, (unsigned char*)key.data(), (unsigned char*)new_iv.data()); if (options & k_OPENSSL_ZERO_PADDING) { EVP_CIPHER_CTX_set_padding(cipher_ctx, 0); } // for single run aeads like CCM, we need to provide the length of the // plaintext before providing AAD or ciphertext. if (mode.is_single_run_aead && !EVP_EncryptUpdate( cipher_ctx, nullptr, &result_len, nullptr, data.size())) { raise_warning("Setting of data length failed"); return false; } // set up aad: if (mode.is_aead && !EVP_EncryptUpdate( cipher_ctx, nullptr, &result_len, (unsigned char*)aad.data(), aad.size())) { raise_warning("Setting of additional application data failed"); return false; } // OpenSSL before 0.9.8i asserts with size < 0 if (data.size() >= 0) { EVP_EncryptUpdate(cipher_ctx, outbuf, &result_len, (unsigned char *)data.data(), data.size()); } outlen = result_len; if (EVP_EncryptFinal_ex( cipher_ctx, (unsigned char*)outbuf + result_len, &result_len)) { outlen += result_len; rv.setSize(outlen); // Get tag if possible if (mode.is_aead) { String tagrv = String(tag_length, ReserveString); if (EVP_CIPHER_CTX_ctrl( cipher_ctx, mode.aead_get_tag_flag, tag_length, tagrv.mutableData()) == 1) { tagrv.setSize(tag_length); assertx(tag_out); *tag_out = tagrv; } else { raise_warning("Retrieving authentication tag failed"); return false; } } else if (tag_out) { raise_warning( "The authenticated tag cannot be provided for cipher that does not" " support AEAD"); } // Return encrypted data if (options & k_OPENSSL_RAW_DATA) { return rv; } else { return StringUtil::Base64Encode(rv); } } return false; } } // anonymous namespace Variant HHVM_FUNCTION(openssl_encrypt, const String& data, const String& method, const String& password, int options /* = 0 */, const String& iv /* = null_string */, const String& aad /* = null_string */, int tag_length /* = 16 */) { return openssl_encrypt_impl(data, method, password, options, iv, nullptr, aad, tag_length); } Variant HHVM_FUNCTION(openssl_encrypt_with_tag, const String& data, const String& method, const String& password, int options, const String& iv, Variant& tag_out, const String& aad /* = null_string */, int tag_length /* = 16 */) { return openssl_encrypt_impl(data, method, password, options, iv, &tag_out, aad, tag_length); } Variant HHVM_FUNCTION(openssl_decrypt, const String& data, const String& method, const String& password, int options /* = 0 */, const String& iv /* = null_string */, const String& tag /* = null_string */, const String& aad /* = null_string */) { const EVP_CIPHER *cipher_type = EVP_get_cipherbyname(method.c_str()); if (!cipher_type) { raise_warning("Unknown cipher algorithm"); return false; } EVP_CIPHER_CTX* cipher_ctx = EVP_CIPHER_CTX_new(); if (!cipher_ctx) { raise_warning("Failed to create cipher context"); return false; } SCOPE_EXIT { EVP_CIPHER_CTX_free(cipher_ctx); }; php_openssl_cipher_mode mode = php_openssl_load_cipher_mode(cipher_type); String decoded_data = data; if (!(options & k_OPENSSL_RAW_DATA)) { decoded_data = StringUtil::Base64Decode(data); } int keylen = EVP_CIPHER_key_length(cipher_type); String key = password; /* * older openssl libraries can assert if the passed in password length is * less than keylen */ if (keylen > password.size()) { String s = String(keylen, ReserveString); char *keybuf = s.mutableData(); memset(keybuf, 0, keylen); memcpy(keybuf, password.data(), password.size()); key = s.setSize(keylen); } int result_len = 0; int outlen = decoded_data.size() + EVP_CIPHER_block_size(cipher_type); String rv = String(outlen, ReserveString); unsigned char *outbuf = (unsigned char*)rv.mutableData(); EVP_DecryptInit_ex(cipher_ctx, cipher_type, nullptr, nullptr, nullptr); String new_iv; // we do this after DecryptInit because validate_iv changes cipher_ctx for // aead modes (must be initialized first). if (!php_openssl_validate_iv( std::move(iv), EVP_CIPHER_iv_length(cipher_type), new_iv, cipher_ctx, &mode)) { return false; } // set the tag if required: if (tag.size() > 0) { if (!mode.is_aead) { raise_warning( "The tag is being ignored because the cipher method does not" " support AEAD"); } else if (!EVP_CIPHER_CTX_ctrl( cipher_ctx, mode.aead_set_tag_flag, tag.size(), (unsigned char*)tag.data())) { raise_warning("Setting tag for AEAD cipher decryption failed"); return false; } } else { if (mode.is_aead) { raise_warning("A tag should be provided when using AEAD mode"); return false; } } if (password.size() > keylen) { EVP_CIPHER_CTX_set_key_length(cipher_ctx, password.size()); } EVP_DecryptInit_ex( cipher_ctx, nullptr, nullptr, (unsigned char*)key.data(), (unsigned char*)new_iv.data()); if (options & k_OPENSSL_ZERO_PADDING) { EVP_CIPHER_CTX_set_padding(cipher_ctx, 0); } // for single run aeads like CCM, we need to provide the length of the // ciphertext before providing AAD or ciphertext. if (mode.is_single_run_aead && !EVP_DecryptUpdate( cipher_ctx, nullptr, &result_len, nullptr, decoded_data.size())) { raise_warning("Setting of data length failed"); return false; } // set up aad: if (mode.is_aead && !EVP_DecryptUpdate( cipher_ctx, nullptr, &result_len, (unsigned char*)aad.data(), aad.size())) { raise_warning("Setting of additional application data failed"); return false; } if (!EVP_DecryptUpdate( cipher_ctx, outbuf, &result_len, (unsigned char*)decoded_data.data(), decoded_data.size())) { return false; } outlen = result_len; // if is_single_run_aead is enabled, DecryptFinal shouldn't be called. // if something went wrong in this case, we would've caught it at // DecryptUpdate. if (mode.is_single_run_aead || EVP_DecryptFinal_ex( cipher_ctx, (unsigned char*)outbuf + result_len, &result_len)) { // don't want to do this if is_single_run_aead was enabled, since we didn't // make a call to EVP_DecryptFinal. if (!mode.is_single_run_aead) { outlen += result_len; } rv.setSize(outlen); return rv; } else { return false; } } Variant HHVM_FUNCTION(openssl_digest, const String& data, const String& method, bool raw_output /* = false */) { const EVP_MD *mdtype = EVP_get_digestbyname(method.c_str()); if (!mdtype) { raise_warning("Unknown signature algorithm"); return false; } int siglen = EVP_MD_size(mdtype); String rv = String(siglen, ReserveString); unsigned char *sigbuf = (unsigned char *)rv.mutableData(); EVP_MD_CTX *md_ctx = EVP_MD_CTX_new(); SCOPE_EXIT { EVP_MD_CTX_free(md_ctx); }; EVP_DigestInit(md_ctx, mdtype); EVP_DigestUpdate(md_ctx, (unsigned char *)data.data(), data.size()); if (EVP_DigestFinal(md_ctx, (unsigned char *)sigbuf, (unsigned int *)&siglen)) { if (raw_output) { rv.setSize(siglen); return rv; } else { char* digest_str = string_bin2hex((char*)sigbuf, siglen); return String(digest_str, AttachString); } } else { return false; } } static void openssl_add_method_or_alias(const OBJ_NAME *name, void *arg) { Array *ret = (Array*)arg; ret->append(String((char *)name->name, CopyString)); } static void openssl_add_method(const OBJ_NAME *name, void *arg) { if (name->alias == 0) { Array *ret = (Array*)arg; ret->append(String((char *)name->name, CopyString)); } } Array HHVM_FUNCTION(openssl_get_cipher_methods, bool aliases /* = false */) { Array ret = Array::CreateVArray(); OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_CIPHER_METH, aliases ? openssl_add_method_or_alias: openssl_add_method, &ret); return ret; } Variant HHVM_FUNCTION(openssl_get_curve_names) { #ifdef HAVE_EVP_PKEY_EC const size_t len = EC_get_builtin_curves(nullptr, 0); std::unique_ptr<EC_builtin_curve[]> curves(new EC_builtin_curve[len]); if (!EC_get_builtin_curves(curves.get(), len)) { return false; } VArrayInit ret(len); for (size_t i = 0; i < len; ++i) { auto const sname = OBJ_nid2sn(curves[i].nid); if (sname != nullptr) { ret.append(String(sname, CopyString)); } } return ret.toArray(); #else return false; #endif } Array HHVM_FUNCTION(openssl_get_md_methods, bool aliases /* = false */) { Array ret = Array::CreateVArray(); OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_MD_METH, aliases ? openssl_add_method_or_alias: openssl_add_method, &ret); return ret; } ///////////////////////////////////////////////////////////////////////////// const StaticString s_OPENSSL_VERSION_TEXT("OPENSSL_VERSION_TEXT"); struct opensslExtension final : Extension { opensslExtension() : Extension("openssl") {} void moduleInit() override { HHVM_RC_INT(OPENSSL_RAW_DATA, k_OPENSSL_RAW_DATA); HHVM_RC_INT(OPENSSL_ZERO_PADDING, k_OPENSSL_ZERO_PADDING); HHVM_RC_INT(OPENSSL_NO_PADDING, k_OPENSSL_NO_PADDING); HHVM_RC_INT(OPENSSL_PKCS1_OAEP_PADDING, k_OPENSSL_PKCS1_OAEP_PADDING); HHVM_RC_INT(OPENSSL_SSLV23_PADDING, k_OPENSSL_SSLV23_PADDING); HHVM_RC_INT(OPENSSL_PKCS1_PADDING, k_OPENSSL_PKCS1_PADDING); HHVM_RC_INT_SAME(OPENSSL_ALGO_SHA1); HHVM_RC_INT_SAME(OPENSSL_ALGO_MD5); HHVM_RC_INT_SAME(OPENSSL_ALGO_MD4); #ifdef HAVE_OPENSSL_MD2_H HHVM_RC_INT_SAME(OPENSSL_ALGO_MD2); #endif HHVM_RC_INT_SAME(OPENSSL_ALGO_DSS1); HHVM_RC_INT_SAME(OPENSSL_ALGO_SHA224); HHVM_RC_INT_SAME(OPENSSL_ALGO_SHA256); HHVM_RC_INT_SAME(OPENSSL_ALGO_SHA384); HHVM_RC_INT_SAME(OPENSSL_ALGO_SHA512); HHVM_RC_INT_SAME(OPENSSL_ALGO_RMD160); HHVM_RC_INT(OPENSSL_CIPHER_RC2_40, PHP_OPENSSL_CIPHER_RC2_40); HHVM_RC_INT(OPENSSL_CIPHER_RC2_128, PHP_OPENSSL_CIPHER_RC2_128); HHVM_RC_INT(OPENSSL_CIPHER_RC2_64, PHP_OPENSSL_CIPHER_RC2_64); HHVM_RC_INT(OPENSSL_CIPHER_DES, PHP_OPENSSL_CIPHER_DES); HHVM_RC_INT(OPENSSL_CIPHER_3DES, PHP_OPENSSL_CIPHER_3DES); HHVM_RC_INT_SAME(OPENSSL_KEYTYPE_RSA); HHVM_RC_INT_SAME(OPENSSL_KEYTYPE_DSA); HHVM_RC_INT_SAME(OPENSSL_KEYTYPE_DH); #ifdef HAVE_EVP_PKEY_EC HHVM_RC_INT_SAME(OPENSSL_KEYTYPE_EC); #endif HHVM_RC_INT_SAME(OPENSSL_VERSION_NUMBER); HHVM_RC_INT_SAME(PKCS7_TEXT); HHVM_RC_INT_SAME(PKCS7_NOCERTS); HHVM_RC_INT_SAME(PKCS7_NOSIGS); HHVM_RC_INT_SAME(PKCS7_NOCHAIN); HHVM_RC_INT_SAME(PKCS7_NOINTERN); HHVM_RC_INT_SAME(PKCS7_NOVERIFY); HHVM_RC_INT_SAME(PKCS7_DETACHED); HHVM_RC_INT_SAME(PKCS7_BINARY); HHVM_RC_INT_SAME(PKCS7_NOATTR); HHVM_RC_STR_SAME(OPENSSL_VERSION_TEXT); HHVM_RC_INT_SAME(X509_PURPOSE_SSL_CLIENT); HHVM_RC_INT_SAME(X509_PURPOSE_SSL_SERVER); HHVM_RC_INT_SAME(X509_PURPOSE_NS_SSL_SERVER); HHVM_RC_INT_SAME(X509_PURPOSE_SMIME_SIGN); HHVM_RC_INT_SAME(X509_PURPOSE_SMIME_ENCRYPT); HHVM_RC_INT_SAME(X509_PURPOSE_CRL_SIGN); #ifdef X509_PURPOSE_ANY HHVM_RC_INT_SAME(X509_PURPOSE_ANY); #endif HHVM_FE(openssl_csr_export_to_file); HHVM_FE(openssl_csr_export); HHVM_FE(openssl_csr_get_public_key); HHVM_FE(openssl_csr_get_subject); HHVM_FE(openssl_csr_new); HHVM_FE(openssl_csr_sign); HHVM_FE(openssl_error_string); HHVM_FE(openssl_open); HHVM_FE(openssl_pkcs12_export_to_file); HHVM_FE(openssl_pkcs12_export); HHVM_FE(openssl_pkcs12_read); HHVM_FE(openssl_pkcs7_decrypt); HHVM_FE(openssl_pkcs7_encrypt); HHVM_FE(openssl_pkcs7_sign); HHVM_FE(openssl_pkcs7_verify); HHVM_FE(openssl_pkey_export_to_file); HHVM_FE(openssl_pkey_export); HHVM_FE(openssl_pkey_get_details); HHVM_FE(openssl_pkey_get_private); HHVM_FE(openssl_pkey_get_public); HHVM_FE(openssl_pkey_new); HHVM_FE(openssl_private_decrypt); HHVM_FE(openssl_private_encrypt); HHVM_FE(openssl_public_decrypt); HHVM_FE(openssl_public_encrypt); HHVM_FE(openssl_seal); HHVM_FE(openssl_sign); HHVM_FE(openssl_verify); HHVM_FE(openssl_x509_check_private_key); HHVM_FE(openssl_x509_checkpurpose); HHVM_FE(openssl_x509_export_to_file); HHVM_FE(openssl_x509_export); HHVM_FE(openssl_x509_parse); HHVM_FE(openssl_x509_read); HHVM_FE(openssl_random_pseudo_bytes); HHVM_FE(openssl_cipher_iv_length); HHVM_FE(openssl_encrypt); HHVM_FE(openssl_encrypt_with_tag); HHVM_FE(openssl_decrypt); HHVM_FE(openssl_digest); HHVM_FE(openssl_get_cipher_methods); HHVM_FE(openssl_get_curve_names); HHVM_FE(openssl_get_md_methods); loadSystemlib(); } } s_openssl_extension; /////////////////////////////////////////////////////////////////////////////// }
15409
True
1
CVE-2020-1917
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'xbuf_format_converter, used as part of exif_read_data, was appending a terminating null character to the generated string, but was not using its standard append char function. As a result, if the buffer was full, it would result in an out-of-bounds write. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-17T19:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::set_sockaddr
HPHP::set_sockaddr( sockaddr_storage & sa_storage , req :: ptr<Socket> sock , const String & addr , int port , struct sockaddr * & sa_ptr , size_t & sa_size)
['sa_storage', 'sock', 'addr', 'port', 'sa_ptr', 'sa_size']
static bool set_sockaddr(sockaddr_storage &sa_storage, req::ptr<Socket> sock, const String& addr, int port, struct sockaddr *&sa_ptr, size_t &sa_size) { // Always zero it out: // - fields are added over time; zeroing it out is future-proofing; for // example, sockaddr_in6 did not originally include sin6_scope_id or // sin6_flowinfo. // - required for all on MacOS for correct behavior // - on Linux, required for sockaddr_un to deal with buggy sun_path readers // (they should look at the length) memset(&sa_storage, 0, sizeof(struct sockaddr_storage)); struct sockaddr *sock_type = (struct sockaddr*) &sa_storage; switch (sock->getType()) { case AF_UNIX: { #ifdef _MSC_VER return false; #else struct sockaddr_un *sa = (struct sockaddr_un *)sock_type; sa->sun_family = AF_UNIX; if (addr.length() > sizeof(sa->sun_path)) { raise_warning( "Unix socket path length (%d) is larger than system limit (%lu)", addr.length(), sizeof(sa->sun_path) ); return false; } memcpy(sa->sun_path, addr.data(), addr.length()); sa_ptr = (struct sockaddr *)sa; sa_size = offsetof(struct sockaddr_un, sun_path) + addr.length(); #ifdef __linux__ if (addr.length() == 0) { // Linux supports 3 kinds of unix sockets; behavior of this struct // is in `man 7 unix`; relevant parts: // - unnamed: 0-length path. As paths are not required to be // null-terminated, this needs to be undicated by the size. // These might be created by `socketpair()`, for eaxmple. // - pathname (common): nothing strange. struct size technically // indicates length, but null terminators are usually set. This // does matter if addr.length() == size of the char array though // - abstract: these have a meaningful name, but start with `\0` // // Setting sa_size to indicate a 0-length path is required to // distinguish between unnamed and abstract. sa_size = offsetof(struct sockaddr_un, sun_path); } #endif #endif // ifdef _MSC_VER } break; case AF_INET: { struct sockaddr_in *sa = (struct sockaddr_in *)sock_type; sa->sin_family = AF_INET; sa->sin_port = htons((unsigned short) port); if (!php_set_inet_addr(sa, addr.c_str(), sock)) { return false; } sa_ptr = (struct sockaddr *)sa; sa_size = sizeof(struct sockaddr_in); } break; case AF_INET6: { struct sockaddr_in6 *sa = (struct sockaddr_in6 *)sock_type; sa->sin6_family = AF_INET6; sa->sin6_port = htons((unsigned short) port); if (!php_set_inet6_addr(sa, addr.c_str(), sock)) { return false; } sa_ptr = (struct sockaddr *)sa; sa_size = sizeof(struct sockaddr_in6); } break; default: raise_warning("unsupported socket type '%d', must be " "AF_UNIX, AF_INET, or AF_INET6", sock->getType()); return false; } #ifdef __APPLE__ // This field is not in the relevant standards, not defined on Linux, but is // technically required on MacOS (and other BSDs) according to the man pages: // - `man 4 netintro` covers the base sa_len // - `man 4 unix` and `man 4 inet6` cover AF_UNIX sun_len and AF_INET6 // sin6_len // - ... At least MacOS Catalina includes the wrong `man 4 inet`. Look at the // (Net|Free|Open)BSD `man 4 inet` instead. // The MacOS man page says it starts with `sin_family`, which would conflict // with the base sockaddr definition. `sin_len` is actually the first field // in the header file, matching `sa_len`. sa_ptr->sa_len = sa_size; #endif return true; }
381
True
1
CVE-2020-1918
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In-memory file operations (ie: using fopen on a data URI) did not properly restrict negative seeking, allowing for the reading of memory prior to the in-memory buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:53Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::set_sockaddr
HPHP::set_sockaddr( sockaddr_storage & sa_storage , req :: ptr<Socket> sock , const String & addr , int port , struct sockaddr * & sa_ptr , size_t & sa_size)
['sa_storage', 'sock', 'addr', 'port', 'sa_ptr', 'sa_size']
static bool set_sockaddr(sockaddr_storage &sa_storage, req::ptr<Socket> sock, const String& addr, int port, struct sockaddr *&sa_ptr, size_t &sa_size) { // Always zero it out: // - fields are added over time; zeroing it out is future-proofing; for // example, sockaddr_in6 did not originally include sin6_scope_id or // sin6_flowinfo. // - required for all on MacOS for correct behavior // - on Linux, required for sockaddr_un to deal with buggy sun_path readers // (they should look at the length) memset(&sa_storage, 0, sizeof(struct sockaddr_storage)); struct sockaddr *sock_type = (struct sockaddr*) &sa_storage; switch (sock->getType()) { case AF_UNIX: { #ifdef _MSC_VER return false; #else struct sockaddr_un *sa = (struct sockaddr_un *)sock_type; sa->sun_family = AF_UNIX; if (addr.length() > sizeof(sa->sun_path)) { raise_warning( "Unix socket path length (%d) is larger than system limit (%lu)", addr.length(), sizeof(sa->sun_path) ); return false; } memcpy(sa->sun_path, addr.data(), addr.length()); sa_ptr = (struct sockaddr *)sa; sa_size = offsetof(struct sockaddr_un, sun_path) + addr.length(); #ifdef __linux__ if (addr.length() == 0) { // Linux supports 3 kinds of unix sockets; behavior of this struct // is in `man 7 unix`; relevant parts: // - unnamed: 0-length path. As paths are not required to be // null-terminated, this needs to be undicated by the size. // These might be created by `socketpair()`, for eaxmple. // - pathname (common): nothing strange. struct size technically // indicates length, but null terminators are usually set. This // does matter if addr.length() == size of the char array though // - abstract: these have a meaningful name, but start with `\0` // // Setting sa_size to indicate a 0-length path is required to // distinguish between unnamed and abstract. sa_size = offsetof(struct sockaddr_un, sun_path); } #endif #endif // ifdef _MSC_VER } break; case AF_INET: { struct sockaddr_in *sa = (struct sockaddr_in *)sock_type; sa->sin_family = AF_INET; sa->sin_port = htons((unsigned short) port); if (!php_set_inet_addr(sa, addr.c_str(), sock)) { return false; } sa_ptr = (struct sockaddr *)sa; sa_size = sizeof(struct sockaddr_in); } break; case AF_INET6: { struct sockaddr_in6 *sa = (struct sockaddr_in6 *)sock_type; sa->sin6_family = AF_INET6; sa->sin6_port = htons((unsigned short) port); if (!php_set_inet6_addr(sa, addr.c_str(), sock)) { return false; } sa_ptr = (struct sockaddr *)sa; sa_size = sizeof(struct sockaddr_in6); } break; default: raise_warning("unsupported socket type '%d', must be " "AF_UNIX, AF_INET, or AF_INET6", sock->getType()); return false; } #ifdef __APPLE__ // This field is not in the relevant standards, not defined on Linux, but is // technically required on MacOS (and other BSDs) according to the man pages: // - `man 4 netintro` covers the base sa_len // - `man 4 unix` and `man 4 inet6` cover AF_UNIX sun_len and AF_INET6 // sin6_len // - ... At least MacOS Catalina includes the wrong `man 4 inet`. Look at the // (Net|Free|Open)BSD `man 4 inet` instead. // The MacOS man page says it starts with `sin_family`, which would conflict // with the base sockaddr definition. `sin_len` is actually the first field // in the header file, matching `sa_len`. sa_ptr->sa_len = sa_size; #endif return true; }
381
True
1
CVE-2020-1919
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Incorrect bounds calculations in substr_compare could lead to an out-of-bounds read when the second string argument passed in is longer than the first. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:51Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::set_sockaddr
HPHP::set_sockaddr( sockaddr_storage & sa_storage , req :: ptr<Socket> sock , const String & addr , int port , struct sockaddr * & sa_ptr , size_t & sa_size)
['sa_storage', 'sock', 'addr', 'port', 'sa_ptr', 'sa_size']
static bool set_sockaddr(sockaddr_storage &sa_storage, req::ptr<Socket> sock, const String& addr, int port, struct sockaddr *&sa_ptr, size_t &sa_size) { // Always zero it out: // - fields are added over time; zeroing it out is future-proofing; for // example, sockaddr_in6 did not originally include sin6_scope_id or // sin6_flowinfo. // - required for all on MacOS for correct behavior // - on Linux, required for sockaddr_un to deal with buggy sun_path readers // (they should look at the length) memset(&sa_storage, 0, sizeof(struct sockaddr_storage)); struct sockaddr *sock_type = (struct sockaddr*) &sa_storage; switch (sock->getType()) { case AF_UNIX: { #ifdef _MSC_VER return false; #else struct sockaddr_un *sa = (struct sockaddr_un *)sock_type; sa->sun_family = AF_UNIX; if (addr.length() > sizeof(sa->sun_path)) { raise_warning( "Unix socket path length (%d) is larger than system limit (%lu)", addr.length(), sizeof(sa->sun_path) ); return false; } memcpy(sa->sun_path, addr.data(), addr.length()); sa_ptr = (struct sockaddr *)sa; sa_size = offsetof(struct sockaddr_un, sun_path) + addr.length(); #ifdef __linux__ if (addr.length() == 0) { // Linux supports 3 kinds of unix sockets; behavior of this struct // is in `man 7 unix`; relevant parts: // - unnamed: 0-length path. As paths are not required to be // null-terminated, this needs to be undicated by the size. // These might be created by `socketpair()`, for eaxmple. // - pathname (common): nothing strange. struct size technically // indicates length, but null terminators are usually set. This // does matter if addr.length() == size of the char array though // - abstract: these have a meaningful name, but start with `\0` // // Setting sa_size to indicate a 0-length path is required to // distinguish between unnamed and abstract. sa_size = offsetof(struct sockaddr_un, sun_path); } #endif #endif // ifdef _MSC_VER } break; case AF_INET: { struct sockaddr_in *sa = (struct sockaddr_in *)sock_type; sa->sin_family = AF_INET; sa->sin_port = htons((unsigned short) port); if (!php_set_inet_addr(sa, addr.c_str(), sock)) { return false; } sa_ptr = (struct sockaddr *)sa; sa_size = sizeof(struct sockaddr_in); } break; case AF_INET6: { struct sockaddr_in6 *sa = (struct sockaddr_in6 *)sock_type; sa->sin6_family = AF_INET6; sa->sin6_port = htons((unsigned short) port); if (!php_set_inet6_addr(sa, addr.c_str(), sock)) { return false; } sa_ptr = (struct sockaddr *)sa; sa_size = sizeof(struct sockaddr_in6); } break; default: raise_warning("unsupported socket type '%d', must be " "AF_UNIX, AF_INET, or AF_INET6", sock->getType()); return false; } #ifdef __APPLE__ // This field is not in the relevant standards, not defined on Linux, but is // technically required on MacOS (and other BSDs) according to the man pages: // - `man 4 netintro` covers the base sa_len // - `man 4 unix` and `man 4 inet6` cover AF_UNIX sun_len and AF_INET6 // sin6_len // - ... At least MacOS Catalina includes the wrong `man 4 inet`. Look at the // (Net|Free|Open)BSD `man 4 inet` instead. // The MacOS man page says it starts with `sin_family`, which would conflict // with the base sockaddr definition. `sin_len` is actually the first field // in the header file, matching `sa_len`. sa_ptr->sa_len = sa_size; #endif return true; }
381
True
1
CVE-2020-1921
False
False
False
False
AV:N/AC:L/Au:N/C:N/I:N/A:P
NETWORK
LOW
NONE
NONE
NONE
PARTIAL
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
NONE
NONE
HIGH
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In the crypt function, we attempt to null terminate a buffer using the size of the input salt without validating that the offset is within the buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::set_sockaddr
HPHP::set_sockaddr( sockaddr_storage & sa_storage , req :: ptr<Socket> sock , const String & addr , int port , struct sockaddr * & sa_ptr , size_t & sa_size)
['sa_storage', 'sock', 'addr', 'port', 'sa_ptr', 'sa_size']
static bool set_sockaddr(sockaddr_storage &sa_storage, req::ptr<Socket> sock, const String& addr, int port, struct sockaddr *&sa_ptr, size_t &sa_size) { // Always zero it out: // - fields are added over time; zeroing it out is future-proofing; for // example, sockaddr_in6 did not originally include sin6_scope_id or // sin6_flowinfo. // - required for all on MacOS for correct behavior // - on Linux, required for sockaddr_un to deal with buggy sun_path readers // (they should look at the length) memset(&sa_storage, 0, sizeof(struct sockaddr_storage)); struct sockaddr *sock_type = (struct sockaddr*) &sa_storage; switch (sock->getType()) { case AF_UNIX: { #ifdef _MSC_VER return false; #else struct sockaddr_un *sa = (struct sockaddr_un *)sock_type; sa->sun_family = AF_UNIX; if (addr.length() > sizeof(sa->sun_path)) { raise_warning( "Unix socket path length (%d) is larger than system limit (%lu)", addr.length(), sizeof(sa->sun_path) ); return false; } memcpy(sa->sun_path, addr.data(), addr.length()); sa_ptr = (struct sockaddr *)sa; sa_size = offsetof(struct sockaddr_un, sun_path) + addr.length(); #ifdef __linux__ if (addr.length() == 0) { // Linux supports 3 kinds of unix sockets; behavior of this struct // is in `man 7 unix`; relevant parts: // - unnamed: 0-length path. As paths are not required to be // null-terminated, this needs to be undicated by the size. // These might be created by `socketpair()`, for eaxmple. // - pathname (common): nothing strange. struct size technically // indicates length, but null terminators are usually set. This // does matter if addr.length() == size of the char array though // - abstract: these have a meaningful name, but start with `\0` // // Setting sa_size to indicate a 0-length path is required to // distinguish between unnamed and abstract. sa_size = offsetof(struct sockaddr_un, sun_path); } #endif #endif // ifdef _MSC_VER } break; case AF_INET: { struct sockaddr_in *sa = (struct sockaddr_in *)sock_type; sa->sin_family = AF_INET; sa->sin_port = htons((unsigned short) port); if (!php_set_inet_addr(sa, addr.c_str(), sock)) { return false; } sa_ptr = (struct sockaddr *)sa; sa_size = sizeof(struct sockaddr_in); } break; case AF_INET6: { struct sockaddr_in6 *sa = (struct sockaddr_in6 *)sock_type; sa->sin6_family = AF_INET6; sa->sin6_port = htons((unsigned short) port); if (!php_set_inet6_addr(sa, addr.c_str(), sock)) { return false; } sa_ptr = (struct sockaddr *)sa; sa_size = sizeof(struct sockaddr_in6); } break; default: raise_warning("unsupported socket type '%d', must be " "AF_UNIX, AF_INET, or AF_INET6", sock->getType()); return false; } #ifdef __APPLE__ // This field is not in the relevant standards, not defined on Linux, but is // technically required on MacOS (and other BSDs) according to the man pages: // - `man 4 netintro` covers the base sa_len // - `man 4 unix` and `man 4 inet6` cover AF_UNIX sun_len and AF_INET6 // sin6_len // - ... At least MacOS Catalina includes the wrong `man 4 inet`. Look at the // (Net|Free|Open)BSD `man 4 inet` instead. // The MacOS man page says it starts with `sin_family`, which would conflict // with the base sockaddr definition. `sin_len` is actually the first field // in the header file, matching `sa_len`. sa_ptr->sa_len = sa_size; #endif return true; }
381
True
1
CVE-2021-24025
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Third Party Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-190'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndIncluding': '4.93.1', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndIncluding': '4.80.1', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Due to incorrect string size calculations inside the preg_quote function, a large input string passed to the function can trigger an integer overflow leading to a heap overflow. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-16T12:45Z
2021-03-10T16:15Z
Integer Overflow or Wraparound
The software performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
An integer overflow or wraparound occurs when an integer value is incremented to a value that is too large to store in the associated representation. When this occurs, the value may wrap to become a very small or negative number. While this may be intended behavior in circumstances that rely on wrapping, it can have security consequences if the wrap is unexpected. This is especially the case if the integer overflow can be triggered using user-supplied inputs. This becomes security-critical when the result is used to control looping, make a security decision, or determine the offset or size in behaviors such as memory allocation, copying, concatenation, etc.
https://cwe.mitre.org/data/definitions/190.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::set_sockaddr
HPHP::set_sockaddr( sockaddr_storage & sa_storage , req :: ptr<Socket> sock , const String & addr , int port , struct sockaddr * & sa_ptr , size_t & sa_size)
['sa_storage', 'sock', 'addr', 'port', 'sa_ptr', 'sa_size']
static bool set_sockaddr(sockaddr_storage &sa_storage, req::ptr<Socket> sock, const String& addr, int port, struct sockaddr *&sa_ptr, size_t &sa_size) { // Always zero it out: // - fields are added over time; zeroing it out is future-proofing; for // example, sockaddr_in6 did not originally include sin6_scope_id or // sin6_flowinfo. // - required for all on MacOS for correct behavior // - on Linux, required for sockaddr_un to deal with buggy sun_path readers // (they should look at the length) memset(&sa_storage, 0, sizeof(struct sockaddr_storage)); struct sockaddr *sock_type = (struct sockaddr*) &sa_storage; switch (sock->getType()) { case AF_UNIX: { #ifdef _MSC_VER return false; #else struct sockaddr_un *sa = (struct sockaddr_un *)sock_type; sa->sun_family = AF_UNIX; if (addr.length() > sizeof(sa->sun_path)) { raise_warning( "Unix socket path length (%d) is larger than system limit (%lu)", addr.length(), sizeof(sa->sun_path) ); return false; } memcpy(sa->sun_path, addr.data(), addr.length()); sa_ptr = (struct sockaddr *)sa; sa_size = offsetof(struct sockaddr_un, sun_path) + addr.length(); #ifdef __linux__ if (addr.length() == 0) { // Linux supports 3 kinds of unix sockets; behavior of this struct // is in `man 7 unix`; relevant parts: // - unnamed: 0-length path. As paths are not required to be // null-terminated, this needs to be undicated by the size. // These might be created by `socketpair()`, for eaxmple. // - pathname (common): nothing strange. struct size technically // indicates length, but null terminators are usually set. This // does matter if addr.length() == size of the char array though // - abstract: these have a meaningful name, but start with `\0` // // Setting sa_size to indicate a 0-length path is required to // distinguish between unnamed and abstract. sa_size = offsetof(struct sockaddr_un, sun_path); } #endif #endif // ifdef _MSC_VER } break; case AF_INET: { struct sockaddr_in *sa = (struct sockaddr_in *)sock_type; sa->sin_family = AF_INET; sa->sin_port = htons((unsigned short) port); if (!php_set_inet_addr(sa, addr.c_str(), sock)) { return false; } sa_ptr = (struct sockaddr *)sa; sa_size = sizeof(struct sockaddr_in); } break; case AF_INET6: { struct sockaddr_in6 *sa = (struct sockaddr_in6 *)sock_type; sa->sin6_family = AF_INET6; sa->sin6_port = htons((unsigned short) port); if (!php_set_inet6_addr(sa, addr.c_str(), sock)) { return false; } sa_ptr = (struct sockaddr *)sa; sa_size = sizeof(struct sockaddr_in6); } break; default: raise_warning("unsupported socket type '%d', must be " "AF_UNIX, AF_INET, or AF_INET6", sock->getType()); return false; } #ifdef __APPLE__ // This field is not in the relevant standards, not defined on Linux, but is // technically required on MacOS (and other BSDs) according to the man pages: // - `man 4 netintro` covers the base sa_len // - `man 4 unix` and `man 4 inet6` cover AF_UNIX sun_len and AF_INET6 // sin6_len // - ... At least MacOS Catalina includes the wrong `man 4 inet`. Look at the // (Net|Free|Open)BSD `man 4 inet` instead. // The MacOS man page says it starts with `sin_family`, which would conflict // with the base sockaddr definition. `sin_len` is actually the first field // in the header file, matching `sa_len`. sa_ptr->sa_len = sa_size; #endif return true; }
381
True
1
CVE-2020-1917
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'xbuf_format_converter, used as part of exif_read_data, was appending a terminating null character to the generated string, but was not using its standard append char function. As a result, if the buffer was full, it would result in an out-of-bounds write. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-17T19:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::serialize_impl
HPHP::serialize_impl( const Variant & value , const SerializeOptions & opts)
['value', 'opts']
ALWAYS_INLINE String serialize_impl(const Variant& value, const SerializeOptions& opts) { switch (value.getType()) { case KindOfClass: case KindOfLazyClass: case KindOfPersistentString: case KindOfString: { auto const str = isStringType(value.getType()) ? value.getStringData() : isClassType(value.getType()) ? classToStringHelper(value.toClassVal()) : lazyClassToStringHelper(value.toLazyClassVal()); auto const size = str->size(); if (size >= RuntimeOption::MaxSerializedStringSize) { throw Exception("Size of serialized string (%d) exceeds max", size); } StringBuffer sb; sb.append("s:"); sb.append(size); sb.append(":\""); sb.append(str->data(), size); sb.append("\";"); return sb.detach(); } case KindOfResource: return s_Res; case KindOfUninit: case KindOfNull: case KindOfBoolean: case KindOfInt64: case KindOfFunc: case KindOfPersistentVec: case KindOfVec: case KindOfPersistentDict: case KindOfDict: case KindOfPersistentKeyset: case KindOfKeyset: case KindOfPersistentDArray: case KindOfDArray: case KindOfPersistentVArray: case KindOfVArray: case KindOfDouble: case KindOfObject: case KindOfClsMeth: case KindOfRClsMeth: case KindOfRFunc: case KindOfRecord: break; } VariableSerializer vs(VariableSerializer::Type::Serialize); if (opts.keepDVArrays) vs.keepDVArrays(); if (opts.forcePHPArrays) vs.setForcePHPArrays(); if (opts.warnOnHackArrays) vs.setHackWarn(); if (opts.warnOnPHPArrays) vs.setPHPWarn(); if (opts.ignoreLateInit) vs.setIgnoreLateInit(); if (opts.serializeProvenanceAndLegacy) vs.setSerializeProvenanceAndLegacy(); // Keep the count so recursive calls to serialize() embed references properly. return vs.serialize(value, true, true); }
328
True
1
CVE-2020-1918
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In-memory file operations (ie: using fopen on a data URI) did not properly restrict negative seeking, allowing for the reading of memory prior to the in-memory buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:53Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::serialize_impl
HPHP::serialize_impl( const Variant & value , const SerializeOptions & opts)
['value', 'opts']
ALWAYS_INLINE String serialize_impl(const Variant& value, const SerializeOptions& opts) { switch (value.getType()) { case KindOfClass: case KindOfLazyClass: case KindOfPersistentString: case KindOfString: { auto const str = isStringType(value.getType()) ? value.getStringData() : isClassType(value.getType()) ? classToStringHelper(value.toClassVal()) : lazyClassToStringHelper(value.toLazyClassVal()); auto const size = str->size(); if (size >= RuntimeOption::MaxSerializedStringSize) { throw Exception("Size of serialized string (%d) exceeds max", size); } StringBuffer sb; sb.append("s:"); sb.append(size); sb.append(":\""); sb.append(str->data(), size); sb.append("\";"); return sb.detach(); } case KindOfResource: return s_Res; case KindOfUninit: case KindOfNull: case KindOfBoolean: case KindOfInt64: case KindOfFunc: case KindOfPersistentVec: case KindOfVec: case KindOfPersistentDict: case KindOfDict: case KindOfPersistentKeyset: case KindOfKeyset: case KindOfPersistentDArray: case KindOfDArray: case KindOfPersistentVArray: case KindOfVArray: case KindOfDouble: case KindOfObject: case KindOfClsMeth: case KindOfRClsMeth: case KindOfRFunc: case KindOfRecord: break; } VariableSerializer vs(VariableSerializer::Type::Serialize); if (opts.keepDVArrays) vs.keepDVArrays(); if (opts.forcePHPArrays) vs.setForcePHPArrays(); if (opts.warnOnHackArrays) vs.setHackWarn(); if (opts.warnOnPHPArrays) vs.setPHPWarn(); if (opts.ignoreLateInit) vs.setIgnoreLateInit(); if (opts.serializeProvenanceAndLegacy) vs.setSerializeProvenanceAndLegacy(); // Keep the count so recursive calls to serialize() embed references properly. return vs.serialize(value, true, true); }
328
True
1
CVE-2020-1919
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Incorrect bounds calculations in substr_compare could lead to an out-of-bounds read when the second string argument passed in is longer than the first. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:51Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::serialize_impl
HPHP::serialize_impl( const Variant & value , const SerializeOptions & opts)
['value', 'opts']
ALWAYS_INLINE String serialize_impl(const Variant& value, const SerializeOptions& opts) { switch (value.getType()) { case KindOfClass: case KindOfLazyClass: case KindOfPersistentString: case KindOfString: { auto const str = isStringType(value.getType()) ? value.getStringData() : isClassType(value.getType()) ? classToStringHelper(value.toClassVal()) : lazyClassToStringHelper(value.toLazyClassVal()); auto const size = str->size(); if (size >= RuntimeOption::MaxSerializedStringSize) { throw Exception("Size of serialized string (%d) exceeds max", size); } StringBuffer sb; sb.append("s:"); sb.append(size); sb.append(":\""); sb.append(str->data(), size); sb.append("\";"); return sb.detach(); } case KindOfResource: return s_Res; case KindOfUninit: case KindOfNull: case KindOfBoolean: case KindOfInt64: case KindOfFunc: case KindOfPersistentVec: case KindOfVec: case KindOfPersistentDict: case KindOfDict: case KindOfPersistentKeyset: case KindOfKeyset: case KindOfPersistentDArray: case KindOfDArray: case KindOfPersistentVArray: case KindOfVArray: case KindOfDouble: case KindOfObject: case KindOfClsMeth: case KindOfRClsMeth: case KindOfRFunc: case KindOfRecord: break; } VariableSerializer vs(VariableSerializer::Type::Serialize); if (opts.keepDVArrays) vs.keepDVArrays(); if (opts.forcePHPArrays) vs.setForcePHPArrays(); if (opts.warnOnHackArrays) vs.setHackWarn(); if (opts.warnOnPHPArrays) vs.setPHPWarn(); if (opts.ignoreLateInit) vs.setIgnoreLateInit(); if (opts.serializeProvenanceAndLegacy) vs.setSerializeProvenanceAndLegacy(); // Keep the count so recursive calls to serialize() embed references properly. return vs.serialize(value, true, true); }
328
True
1
CVE-2020-1921
False
False
False
False
AV:N/AC:L/Au:N/C:N/I:N/A:P
NETWORK
LOW
NONE
NONE
NONE
PARTIAL
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
NONE
NONE
HIGH
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In the crypt function, we attempt to null terminate a buffer using the size of the input salt without validating that the offset is within the buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::serialize_impl
HPHP::serialize_impl( const Variant & value , const SerializeOptions & opts)
['value', 'opts']
ALWAYS_INLINE String serialize_impl(const Variant& value, const SerializeOptions& opts) { switch (value.getType()) { case KindOfClass: case KindOfLazyClass: case KindOfPersistentString: case KindOfString: { auto const str = isStringType(value.getType()) ? value.getStringData() : isClassType(value.getType()) ? classToStringHelper(value.toClassVal()) : lazyClassToStringHelper(value.toLazyClassVal()); auto const size = str->size(); if (size >= RuntimeOption::MaxSerializedStringSize) { throw Exception("Size of serialized string (%d) exceeds max", size); } StringBuffer sb; sb.append("s:"); sb.append(size); sb.append(":\""); sb.append(str->data(), size); sb.append("\";"); return sb.detach(); } case KindOfResource: return s_Res; case KindOfUninit: case KindOfNull: case KindOfBoolean: case KindOfInt64: case KindOfFunc: case KindOfPersistentVec: case KindOfVec: case KindOfPersistentDict: case KindOfDict: case KindOfPersistentKeyset: case KindOfKeyset: case KindOfPersistentDArray: case KindOfDArray: case KindOfPersistentVArray: case KindOfVArray: case KindOfDouble: case KindOfObject: case KindOfClsMeth: case KindOfRClsMeth: case KindOfRFunc: case KindOfRecord: break; } VariableSerializer vs(VariableSerializer::Type::Serialize); if (opts.keepDVArrays) vs.keepDVArrays(); if (opts.forcePHPArrays) vs.setForcePHPArrays(); if (opts.warnOnHackArrays) vs.setHackWarn(); if (opts.warnOnPHPArrays) vs.setPHPWarn(); if (opts.ignoreLateInit) vs.setIgnoreLateInit(); if (opts.serializeProvenanceAndLegacy) vs.setSerializeProvenanceAndLegacy(); // Keep the count so recursive calls to serialize() embed references properly. return vs.serialize(value, true, true); }
328
True
1
CVE-2021-24025
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Third Party Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-190'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndIncluding': '4.93.1', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndIncluding': '4.80.1', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Due to incorrect string size calculations inside the preg_quote function, a large input string passed to the function can trigger an integer overflow leading to a heap overflow. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-16T12:45Z
2021-03-10T16:15Z
Integer Overflow or Wraparound
The software performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
An integer overflow or wraparound occurs when an integer value is incremented to a value that is too large to store in the associated representation. When this occurs, the value may wrap to become a very small or negative number. While this may be intended behavior in circumstances that rely on wrapping, it can have security consequences if the wrap is unexpected. This is especially the case if the integer overflow can be triggered using user-supplied inputs. This becomes security-critical when the result is used to control looping, make a security decision, or determine the offset or size in behaviors such as memory allocation, copying, concatenation, etc.
https://cwe.mitre.org/data/definitions/190.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::serialize_impl
HPHP::serialize_impl( const Variant & value , const SerializeOptions & opts)
['value', 'opts']
ALWAYS_INLINE String serialize_impl(const Variant& value, const SerializeOptions& opts) { switch (value.getType()) { case KindOfClass: case KindOfLazyClass: case KindOfPersistentString: case KindOfString: { auto const str = isStringType(value.getType()) ? value.getStringData() : isClassType(value.getType()) ? classToStringHelper(value.toClassVal()) : lazyClassToStringHelper(value.toLazyClassVal()); auto const size = str->size(); if (size >= RuntimeOption::MaxSerializedStringSize) { throw Exception("Size of serialized string (%d) exceeds max", size); } StringBuffer sb; sb.append("s:"); sb.append(size); sb.append(":\""); sb.append(str->data(), size); sb.append("\";"); return sb.detach(); } case KindOfResource: return s_Res; case KindOfUninit: case KindOfNull: case KindOfBoolean: case KindOfInt64: case KindOfFunc: case KindOfPersistentVec: case KindOfVec: case KindOfPersistentDict: case KindOfDict: case KindOfPersistentKeyset: case KindOfKeyset: case KindOfPersistentDArray: case KindOfDArray: case KindOfPersistentVArray: case KindOfVArray: case KindOfDouble: case KindOfObject: case KindOfClsMeth: case KindOfRClsMeth: case KindOfRFunc: case KindOfRecord: break; } VariableSerializer vs(VariableSerializer::Type::Serialize); if (opts.keepDVArrays) vs.keepDVArrays(); if (opts.forcePHPArrays) vs.setForcePHPArrays(); if (opts.warnOnHackArrays) vs.setHackWarn(); if (opts.warnOnPHPArrays) vs.setPHPWarn(); if (opts.ignoreLateInit) vs.setIgnoreLateInit(); if (opts.serializeProvenanceAndLegacy) vs.setSerializeProvenanceAndLegacy(); // Keep the count so recursive calls to serialize() embed references properly. return vs.serialize(value, true, true); }
328
True
1
CVE-2020-1917
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'xbuf_format_converter, used as part of exif_read_data, was appending a terminating null character to the generated string, but was not using its standard append char function. As a result, if the buffer was full, it would result in an out-of-bounds write. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-17T19:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::HHVM_FUNCTION
HPHP::HHVM_FUNCTION( substr_compare , const String & main_str , const String & str , int offset , int length , bool case_insensitivity)
['substr_compare', 'main_str', 'str', 'offset', 'length', 'case_insensitivity']
TypedValue HHVM_FUNCTION(substr_compare, const String& main_str, const String& str, int offset, int length /* = INT_MAX */, bool case_insensitivity /* = false */) { int s1_len = main_str.size(); int s2_len = str.size(); if (length <= 0) { raise_warning("The length must be greater than zero"); return make_tv<KindOfBoolean>(false); } if (offset < 0) { offset = s1_len + offset; if (offset < 0) offset = 0; } if (offset >= s1_len) { raise_warning("The start position cannot exceed initial string length"); return make_tv<KindOfBoolean>(false); } int cmp_len = s1_len - offset; if (cmp_len < s2_len) cmp_len = s2_len; if (cmp_len > length) cmp_len = length; const char *s1 = main_str.data(); if (case_insensitivity) { return tvReturn(bstrcasecmp(s1 + offset, cmp_len, str.data(), cmp_len)); } return tvReturn(string_ncmp(s1 + offset, str.data(), cmp_len)); }
195
True
1
CVE-2020-1918
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In-memory file operations (ie: using fopen on a data URI) did not properly restrict negative seeking, allowing for the reading of memory prior to the in-memory buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:53Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::HHVM_FUNCTION
HPHP::HHVM_FUNCTION( substr_compare , const String & main_str , const String & str , int offset , int length , bool case_insensitivity)
['substr_compare', 'main_str', 'str', 'offset', 'length', 'case_insensitivity']
TypedValue HHVM_FUNCTION(substr_compare, const String& main_str, const String& str, int offset, int length /* = INT_MAX */, bool case_insensitivity /* = false */) { int s1_len = main_str.size(); int s2_len = str.size(); if (length <= 0) { raise_warning("The length must be greater than zero"); return make_tv<KindOfBoolean>(false); } if (offset < 0) { offset = s1_len + offset; if (offset < 0) offset = 0; } if (offset >= s1_len) { raise_warning("The start position cannot exceed initial string length"); return make_tv<KindOfBoolean>(false); } int cmp_len = s1_len - offset; if (cmp_len < s2_len) cmp_len = s2_len; if (cmp_len > length) cmp_len = length; const char *s1 = main_str.data(); if (case_insensitivity) { return tvReturn(bstrcasecmp(s1 + offset, cmp_len, str.data(), cmp_len)); } return tvReturn(string_ncmp(s1 + offset, str.data(), cmp_len)); }
195
True
1
CVE-2020-1919
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Incorrect bounds calculations in substr_compare could lead to an out-of-bounds read when the second string argument passed in is longer than the first. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:51Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::HHVM_FUNCTION
HPHP::HHVM_FUNCTION( substr_compare , const String & main_str , const String & str , int offset , int length , bool case_insensitivity)
['substr_compare', 'main_str', 'str', 'offset', 'length', 'case_insensitivity']
TypedValue HHVM_FUNCTION(substr_compare, const String& main_str, const String& str, int offset, int length /* = INT_MAX */, bool case_insensitivity /* = false */) { int s1_len = main_str.size(); int s2_len = str.size(); if (length <= 0) { raise_warning("The length must be greater than zero"); return make_tv<KindOfBoolean>(false); } if (offset < 0) { offset = s1_len + offset; if (offset < 0) offset = 0; } if (offset >= s1_len) { raise_warning("The start position cannot exceed initial string length"); return make_tv<KindOfBoolean>(false); } int cmp_len = s1_len - offset; if (cmp_len < s2_len) cmp_len = s2_len; if (cmp_len > length) cmp_len = length; const char *s1 = main_str.data(); if (case_insensitivity) { return tvReturn(bstrcasecmp(s1 + offset, cmp_len, str.data(), cmp_len)); } return tvReturn(string_ncmp(s1 + offset, str.data(), cmp_len)); }
195
True
1
CVE-2020-1921
False
False
False
False
AV:N/AC:L/Au:N/C:N/I:N/A:P
NETWORK
LOW
NONE
NONE
NONE
PARTIAL
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
NONE
NONE
HIGH
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In the crypt function, we attempt to null terminate a buffer using the size of the input salt without validating that the offset is within the buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::HHVM_FUNCTION
HPHP::HHVM_FUNCTION( substr_compare , const String & main_str , const String & str , int offset , int length , bool case_insensitivity)
['substr_compare', 'main_str', 'str', 'offset', 'length', 'case_insensitivity']
TypedValue HHVM_FUNCTION(substr_compare, const String& main_str, const String& str, int offset, int length /* = INT_MAX */, bool case_insensitivity /* = false */) { int s1_len = main_str.size(); int s2_len = str.size(); if (length <= 0) { raise_warning("The length must be greater than zero"); return make_tv<KindOfBoolean>(false); } if (offset < 0) { offset = s1_len + offset; if (offset < 0) offset = 0; } if (offset >= s1_len) { raise_warning("The start position cannot exceed initial string length"); return make_tv<KindOfBoolean>(false); } int cmp_len = s1_len - offset; if (cmp_len < s2_len) cmp_len = s2_len; if (cmp_len > length) cmp_len = length; const char *s1 = main_str.data(); if (case_insensitivity) { return tvReturn(bstrcasecmp(s1 + offset, cmp_len, str.data(), cmp_len)); } return tvReturn(string_ncmp(s1 + offset, str.data(), cmp_len)); }
195
True
1
CVE-2021-24025
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Third Party Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-190'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndIncluding': '4.93.1', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndIncluding': '4.80.1', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Due to incorrect string size calculations inside the preg_quote function, a large input string passed to the function can trigger an integer overflow leading to a heap overflow. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-16T12:45Z
2021-03-10T16:15Z
Integer Overflow or Wraparound
The software performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
An integer overflow or wraparound occurs when an integer value is incremented to a value that is too large to store in the associated representation. When this occurs, the value may wrap to become a very small or negative number. While this may be intended behavior in circumstances that rely on wrapping, it can have security consequences if the wrap is unexpected. This is especially the case if the integer overflow can be triggered using user-supplied inputs. This becomes security-critical when the result is used to control looping, make a security decision, or determine the offset or size in behaviors such as memory allocation, copying, concatenation, etc.
https://cwe.mitre.org/data/definitions/190.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::HHVM_FUNCTION
HPHP::HHVM_FUNCTION( substr_compare , const String & main_str , const String & str , int offset , int length , bool case_insensitivity)
['substr_compare', 'main_str', 'str', 'offset', 'length', 'case_insensitivity']
TypedValue HHVM_FUNCTION(substr_compare, const String& main_str, const String& str, int offset, int length /* = INT_MAX */, bool case_insensitivity /* = false */) { int s1_len = main_str.size(); int s2_len = str.size(); if (length <= 0) { raise_warning("The length must be greater than zero"); return make_tv<KindOfBoolean>(false); } if (offset < 0) { offset = s1_len + offset; if (offset < 0) offset = 0; } if (offset >= s1_len) { raise_warning("The start position cannot exceed initial string length"); return make_tv<KindOfBoolean>(false); } int cmp_len = s1_len - offset; if (cmp_len < s2_len) cmp_len = s2_len; if (cmp_len > length) cmp_len = length; const char *s1 = main_str.data(); if (case_insensitivity) { return tvReturn(bstrcasecmp(s1 + offset, cmp_len, str.data(), cmp_len)); } return tvReturn(string_ncmp(s1 + offset, str.data(), cmp_len)); }
195
True
1
CVE-2020-1917
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'xbuf_format_converter, used as part of exif_read_data, was appending a terminating null character to the generated string, but was not using its standard append char function. As a result, if the buffer was full, it would result in an out-of-bounds write. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-17T19:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::logToUSDT
HPHP::logToUSDT( const Array & bt)
['bt']
bool logToUSDT(const Array& bt) { std::lock_guard<std::mutex> lock(usdt_mutex); memset(&bt_slab, 0, sizeof(bt_slab)); int i = 0; IterateVNoInc( bt.get(), [&](TypedValue tv) -> bool { if (i >= strobelight::kMaxStackframes) { return true; } assertx(isArrayLikeType(type(tv))); ArrayData* bt_frame = val(tv).parr; strobelight::backtrace_frame_t* frame = &bt_slab.frames[i]; auto const line = bt_frame->get(s_line.get()); if (line.is_init()) { assertx(isIntType(type(line))); frame->line = val(line).num; } auto const file_name = bt_frame->get(s_file.get()); if (file_name.is_init()) { assertx(isStringType(type(file_name))); strncpy(frame->file_name, val(file_name).pstr->data(), std::min(val(file_name).pstr->size(), strobelight::kFileNameMax)); frame->file_name[strobelight::kFileNameMax - 1] = '\0'; } auto const class_name = bt_frame->get(s_class.get()); if (class_name.is_init()) { assertx(isStringType(type(class_name))); strncpy(frame->class_name, val(class_name).pstr->data(), std::min(val(class_name).pstr->size(), strobelight::kClassNameMax)); frame->class_name[strobelight::kClassNameMax - 1] = '\0'; } auto const function_name = bt_frame->get(s_function.get()); if (function_name.is_init()) { assertx(isStringType(type(function_name))); strncpy(frame->function, val(function_name).pstr->data(), std::min(val(function_name).pstr->size(), strobelight::kFunctionMax)); frame->function[strobelight::kFunctionMax - 1] = '\0'; } i++; return false; } ); bt_slab.len = i; // Allow BPF to read the now-formatted stacktrace FOLLY_SDT_WITH_SEMAPHORE(hhvm, hhvm_stack, &bt_slab); return true; }
443
True
1
CVE-2020-1918
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In-memory file operations (ie: using fopen on a data URI) did not properly restrict negative seeking, allowing for the reading of memory prior to the in-memory buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:53Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::logToUSDT
HPHP::logToUSDT( const Array & bt)
['bt']
bool logToUSDT(const Array& bt) { std::lock_guard<std::mutex> lock(usdt_mutex); memset(&bt_slab, 0, sizeof(bt_slab)); int i = 0; IterateVNoInc( bt.get(), [&](TypedValue tv) -> bool { if (i >= strobelight::kMaxStackframes) { return true; } assertx(isArrayLikeType(type(tv))); ArrayData* bt_frame = val(tv).parr; strobelight::backtrace_frame_t* frame = &bt_slab.frames[i]; auto const line = bt_frame->get(s_line.get()); if (line.is_init()) { assertx(isIntType(type(line))); frame->line = val(line).num; } auto const file_name = bt_frame->get(s_file.get()); if (file_name.is_init()) { assertx(isStringType(type(file_name))); strncpy(frame->file_name, val(file_name).pstr->data(), std::min(val(file_name).pstr->size(), strobelight::kFileNameMax)); frame->file_name[strobelight::kFileNameMax - 1] = '\0'; } auto const class_name = bt_frame->get(s_class.get()); if (class_name.is_init()) { assertx(isStringType(type(class_name))); strncpy(frame->class_name, val(class_name).pstr->data(), std::min(val(class_name).pstr->size(), strobelight::kClassNameMax)); frame->class_name[strobelight::kClassNameMax - 1] = '\0'; } auto const function_name = bt_frame->get(s_function.get()); if (function_name.is_init()) { assertx(isStringType(type(function_name))); strncpy(frame->function, val(function_name).pstr->data(), std::min(val(function_name).pstr->size(), strobelight::kFunctionMax)); frame->function[strobelight::kFunctionMax - 1] = '\0'; } i++; return false; } ); bt_slab.len = i; // Allow BPF to read the now-formatted stacktrace FOLLY_SDT_WITH_SEMAPHORE(hhvm, hhvm_stack, &bt_slab); return true; }
443
True
1
CVE-2020-1919
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Incorrect bounds calculations in substr_compare could lead to an out-of-bounds read when the second string argument passed in is longer than the first. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:51Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::logToUSDT
HPHP::logToUSDT( const Array & bt)
['bt']
bool logToUSDT(const Array& bt) { std::lock_guard<std::mutex> lock(usdt_mutex); memset(&bt_slab, 0, sizeof(bt_slab)); int i = 0; IterateVNoInc( bt.get(), [&](TypedValue tv) -> bool { if (i >= strobelight::kMaxStackframes) { return true; } assertx(isArrayLikeType(type(tv))); ArrayData* bt_frame = val(tv).parr; strobelight::backtrace_frame_t* frame = &bt_slab.frames[i]; auto const line = bt_frame->get(s_line.get()); if (line.is_init()) { assertx(isIntType(type(line))); frame->line = val(line).num; } auto const file_name = bt_frame->get(s_file.get()); if (file_name.is_init()) { assertx(isStringType(type(file_name))); strncpy(frame->file_name, val(file_name).pstr->data(), std::min(val(file_name).pstr->size(), strobelight::kFileNameMax)); frame->file_name[strobelight::kFileNameMax - 1] = '\0'; } auto const class_name = bt_frame->get(s_class.get()); if (class_name.is_init()) { assertx(isStringType(type(class_name))); strncpy(frame->class_name, val(class_name).pstr->data(), std::min(val(class_name).pstr->size(), strobelight::kClassNameMax)); frame->class_name[strobelight::kClassNameMax - 1] = '\0'; } auto const function_name = bt_frame->get(s_function.get()); if (function_name.is_init()) { assertx(isStringType(type(function_name))); strncpy(frame->function, val(function_name).pstr->data(), std::min(val(function_name).pstr->size(), strobelight::kFunctionMax)); frame->function[strobelight::kFunctionMax - 1] = '\0'; } i++; return false; } ); bt_slab.len = i; // Allow BPF to read the now-formatted stacktrace FOLLY_SDT_WITH_SEMAPHORE(hhvm, hhvm_stack, &bt_slab); return true; }
443
True
1
CVE-2020-1921
False
False
False
False
AV:N/AC:L/Au:N/C:N/I:N/A:P
NETWORK
LOW
NONE
NONE
NONE
PARTIAL
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
NONE
NONE
HIGH
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In the crypt function, we attempt to null terminate a buffer using the size of the input salt without validating that the offset is within the buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::logToUSDT
HPHP::logToUSDT( const Array & bt)
['bt']
bool logToUSDT(const Array& bt) { std::lock_guard<std::mutex> lock(usdt_mutex); memset(&bt_slab, 0, sizeof(bt_slab)); int i = 0; IterateVNoInc( bt.get(), [&](TypedValue tv) -> bool { if (i >= strobelight::kMaxStackframes) { return true; } assertx(isArrayLikeType(type(tv))); ArrayData* bt_frame = val(tv).parr; strobelight::backtrace_frame_t* frame = &bt_slab.frames[i]; auto const line = bt_frame->get(s_line.get()); if (line.is_init()) { assertx(isIntType(type(line))); frame->line = val(line).num; } auto const file_name = bt_frame->get(s_file.get()); if (file_name.is_init()) { assertx(isStringType(type(file_name))); strncpy(frame->file_name, val(file_name).pstr->data(), std::min(val(file_name).pstr->size(), strobelight::kFileNameMax)); frame->file_name[strobelight::kFileNameMax - 1] = '\0'; } auto const class_name = bt_frame->get(s_class.get()); if (class_name.is_init()) { assertx(isStringType(type(class_name))); strncpy(frame->class_name, val(class_name).pstr->data(), std::min(val(class_name).pstr->size(), strobelight::kClassNameMax)); frame->class_name[strobelight::kClassNameMax - 1] = '\0'; } auto const function_name = bt_frame->get(s_function.get()); if (function_name.is_init()) { assertx(isStringType(type(function_name))); strncpy(frame->function, val(function_name).pstr->data(), std::min(val(function_name).pstr->size(), strobelight::kFunctionMax)); frame->function[strobelight::kFunctionMax - 1] = '\0'; } i++; return false; } ); bt_slab.len = i; // Allow BPF to read the now-formatted stacktrace FOLLY_SDT_WITH_SEMAPHORE(hhvm, hhvm_stack, &bt_slab); return true; }
443
True
1
CVE-2021-24025
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Third Party Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-190'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndIncluding': '4.93.1', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndIncluding': '4.80.1', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Due to incorrect string size calculations inside the preg_quote function, a large input string passed to the function can trigger an integer overflow leading to a heap overflow. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-16T12:45Z
2021-03-10T16:15Z
Integer Overflow or Wraparound
The software performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
An integer overflow or wraparound occurs when an integer value is incremented to a value that is too large to store in the associated representation. When this occurs, the value may wrap to become a very small or negative number. While this may be intended behavior in circumstances that rely on wrapping, it can have security consequences if the wrap is unexpected. This is especially the case if the integer overflow can be triggered using user-supplied inputs. This becomes security-critical when the result is used to control looping, make a security decision, or determine the offset or size in behaviors such as memory allocation, copying, concatenation, etc.
https://cwe.mitre.org/data/definitions/190.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::logToUSDT
HPHP::logToUSDT( const Array & bt)
['bt']
bool logToUSDT(const Array& bt) { std::lock_guard<std::mutex> lock(usdt_mutex); memset(&bt_slab, 0, sizeof(bt_slab)); int i = 0; IterateVNoInc( bt.get(), [&](TypedValue tv) -> bool { if (i >= strobelight::kMaxStackframes) { return true; } assertx(isArrayLikeType(type(tv))); ArrayData* bt_frame = val(tv).parr; strobelight::backtrace_frame_t* frame = &bt_slab.frames[i]; auto const line = bt_frame->get(s_line.get()); if (line.is_init()) { assertx(isIntType(type(line))); frame->line = val(line).num; } auto const file_name = bt_frame->get(s_file.get()); if (file_name.is_init()) { assertx(isStringType(type(file_name))); strncpy(frame->file_name, val(file_name).pstr->data(), std::min(val(file_name).pstr->size(), strobelight::kFileNameMax)); frame->file_name[strobelight::kFileNameMax - 1] = '\0'; } auto const class_name = bt_frame->get(s_class.get()); if (class_name.is_init()) { assertx(isStringType(type(class_name))); strncpy(frame->class_name, val(class_name).pstr->data(), std::min(val(class_name).pstr->size(), strobelight::kClassNameMax)); frame->class_name[strobelight::kClassNameMax - 1] = '\0'; } auto const function_name = bt_frame->get(s_function.get()); if (function_name.is_init()) { assertx(isStringType(type(function_name))); strncpy(frame->function, val(function_name).pstr->data(), std::min(val(function_name).pstr->size(), strobelight::kFunctionMax)); frame->function[strobelight::kFunctionMax - 1] = '\0'; } i++; return false; } ); bt_slab.len = i; // Allow BPF to read the now-formatted stacktrace FOLLY_SDT_WITH_SEMAPHORE(hhvm, hhvm_stack, &bt_slab); return true; }
443
True
1
CVE-2020-1917
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'xbuf_format_converter, used as part of exif_read_data, was appending a terminating null character to the generated string, but was not using its standard append char function. As a result, if the buffer was full, it would result in an out-of-bounds write. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-17T19:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::xbuf_format_converter
HPHP::xbuf_format_converter( char ** outbuf , const char * fmt , va_list ap)
['outbuf', 'fmt', 'ap']
static int xbuf_format_converter(char **outbuf, const char *fmt, va_list ap) { register char *s = nullptr; char *q; int s_len; register int min_width = 0; int precision = 0; enum { LEFT, RIGHT } adjust; char pad_char; char prefix_char; double fp_num; wide_int i_num = (wide_int) 0; u_wide_int ui_num; char num_buf[NUM_BUF_SIZE]; char char_buf[2]; /* for printing %% and %<unknown> */ #ifdef HAVE_LOCALE_H struct lconv *lconv = nullptr; #endif /* * Flag variables */ length_modifier_e modifier; boolean_e alternate_form; boolean_e print_sign; boolean_e print_blank; boolean_e adjust_precision; boolean_e adjust_width; int is_negative; int size = 240; char *result = (char *)malloc(size); int outpos = 0; while (*fmt) { if (*fmt != '%') { appendchar(&result, &outpos, &size, *fmt); } else { /* * Default variable settings */ adjust = RIGHT; alternate_form = print_sign = print_blank = NO; pad_char = ' '; prefix_char = NUL; fmt++; /* * Try to avoid checking for flags, width or precision */ if (isascii((int)*fmt) && !islower((int)*fmt)) { /* * Recognize flags: -, #, BLANK, + */ for (;; fmt++) { if (*fmt == '-') adjust = LEFT; else if (*fmt == '+') print_sign = YES; else if (*fmt == '#') alternate_form = YES; else if (*fmt == ' ') print_blank = YES; else if (*fmt == '0') pad_char = '0'; else break; } /* * Check if a width was specified */ if (isdigit((int)*fmt)) { STR_TO_DEC(fmt, min_width); adjust_width = YES; } else if (*fmt == '*') { min_width = va_arg(ap, int); fmt++; adjust_width = YES; if (min_width < 0) { adjust = LEFT; min_width = -min_width; } } else adjust_width = NO; /* * Check if a precision was specified * * XXX: an unreasonable amount of precision may be specified * resulting in overflow of num_buf. Currently we * ignore this possibility. */ if (*fmt == '.') { adjust_precision = YES; fmt++; if (isdigit((int)*fmt)) { STR_TO_DEC(fmt, precision); } else if (*fmt == '*') { precision = va_arg(ap, int); fmt++; if (precision < 0) precision = 0; } else precision = 0; } else adjust_precision = NO; } else adjust_precision = adjust_width = NO; /* * Modifier check */ switch (*fmt) { case 'L': fmt++; modifier = LM_LONG_DOUBLE; break; case 'I': fmt++; #if SIZEOF_LONG_LONG if (*fmt == '6' && *(fmt+1) == '4') { fmt += 2; modifier = LM_LONG_LONG; } else #endif if (*fmt == '3' && *(fmt+1) == '2') { fmt += 2; modifier = LM_LONG; } else { #ifdef _WIN64 modifier = LM_LONG_LONG; #else modifier = LM_LONG; #endif } break; case 'l': fmt++; #if SIZEOF_LONG_LONG if (*fmt == 'l') { fmt++; modifier = LM_LONG_LONG; } else #endif modifier = LM_LONG; break; case 'z': fmt++; modifier = LM_SIZE_T; break; case 'j': fmt++; #if SIZEOF_INTMAX_T modifier = LM_INTMAX_T; #else modifier = LM_SIZE_T; #endif break; case 't': fmt++; #if SIZEOF_PTRDIFF_T modifier = LM_PTRDIFF_T; #else modifier = LM_SIZE_T; #endif break; case 'h': fmt++; if (*fmt == 'h') { fmt++; } /* these are promoted to int, so no break */ default: modifier = LM_STD; break; } /* * Argument extraction and printing. * First we determine the argument type. * Then, we convert the argument to a string. * On exit from the switch, s points to the string that * must be printed, s_len has the length of the string * The precision requirements, if any, are reflected in s_len. * * NOTE: pad_char may be set to '0' because of the 0 flag. * It is reset to ' ' by non-numeric formats */ switch (*fmt) { case 'u': switch(modifier) { default: i_num = (wide_int) va_arg(ap, unsigned int); break; case LM_LONG_DOUBLE: goto fmt_error; case LM_LONG: i_num = (wide_int) va_arg(ap, unsigned long int); break; case LM_SIZE_T: i_num = (wide_int) va_arg(ap, size_t); break; #if SIZEOF_LONG_LONG case LM_LONG_LONG: i_num = (wide_int) va_arg(ap, u_wide_int); break; #endif #if SIZEOF_INTMAX_T case LM_INTMAX_T: i_num = (wide_int) va_arg(ap, uintmax_t); break; #endif #if SIZEOF_PTRDIFF_T case LM_PTRDIFF_T: i_num = (wide_int) va_arg(ap, ptrdiff_t); break; #endif } /* * The rest also applies to other integer formats, so fall * into that case. */ case 'd': case 'i': /* * Get the arg if we haven't already. */ if ((*fmt) != 'u') { switch(modifier) { default: i_num = (wide_int) va_arg(ap, int); break; case LM_LONG_DOUBLE: goto fmt_error; case LM_LONG: i_num = (wide_int) va_arg(ap, long int); break; case LM_SIZE_T: #if SIZEOF_SSIZE_T i_num = (wide_int) va_arg(ap, ssize_t); #else i_num = (wide_int) va_arg(ap, size_t); #endif break; #if SIZEOF_LONG_LONG case LM_LONG_LONG: i_num = (wide_int) va_arg(ap, wide_int); break; #endif #if SIZEOF_INTMAX_T case LM_INTMAX_T: i_num = (wide_int) va_arg(ap, intmax_t); break; #endif #if SIZEOF_PTRDIFF_T case LM_PTRDIFF_T: i_num = (wide_int) va_arg(ap, ptrdiff_t); break; #endif } } s = ap_php_conv_10(i_num, (*fmt) == 'u', &is_negative, &num_buf[NUM_BUF_SIZE], &s_len); FIX_PRECISION(adjust_precision, precision, s, s_len); if (*fmt != 'u') { if (is_negative) prefix_char = '-'; else if (print_sign) prefix_char = '+'; else if (print_blank) prefix_char = ' '; } break; case 'o': switch(modifier) { default: ui_num = (u_wide_int) va_arg(ap, unsigned int); break; case LM_LONG_DOUBLE: goto fmt_error; case LM_LONG: ui_num = (u_wide_int) va_arg(ap, unsigned long int); break; case LM_SIZE_T: ui_num = (u_wide_int) va_arg(ap, size_t); break; #if SIZEOF_LONG_LONG case LM_LONG_LONG: ui_num = (u_wide_int) va_arg(ap, u_wide_int); break; #endif #if SIZEOF_INTMAX_T case LM_INTMAX_T: ui_num = (u_wide_int) va_arg(ap, uintmax_t); break; #endif #if SIZEOF_PTRDIFF_T case LM_PTRDIFF_T: ui_num = (u_wide_int) va_arg(ap, ptrdiff_t); break; #endif } s = ap_php_conv_p2(ui_num, 3, *fmt, &num_buf[NUM_BUF_SIZE], &s_len); FIX_PRECISION(adjust_precision, precision, s, s_len); if (alternate_form && *s != '0') { *--s = '0'; s_len++; } break; case 'x': case 'X': switch(modifier) { default: ui_num = (u_wide_int) va_arg(ap, unsigned int); break; case LM_LONG_DOUBLE: goto fmt_error; case LM_LONG: ui_num = (u_wide_int) va_arg(ap, unsigned long int); break; case LM_SIZE_T: ui_num = (u_wide_int) va_arg(ap, size_t); break; #if SIZEOF_LONG_LONG case LM_LONG_LONG: ui_num = (u_wide_int) va_arg(ap, u_wide_int); break; #endif #if SIZEOF_INTMAX_T case LM_INTMAX_T: ui_num = (u_wide_int) va_arg(ap, uintmax_t); break; #endif #if SIZEOF_PTRDIFF_T case LM_PTRDIFF_T: ui_num = (u_wide_int) va_arg(ap, ptrdiff_t); break; #endif } s = ap_php_conv_p2(ui_num, 4, *fmt, &num_buf[NUM_BUF_SIZE], &s_len); FIX_PRECISION(adjust_precision, precision, s, s_len); if (alternate_form && i_num != 0) { *--s = *fmt; /* 'x' or 'X' */ *--s = '0'; s_len += 2; } break; case 's': case 'v': s = va_arg(ap, char *); if (s != nullptr) { s_len = strlen(s); if (adjust_precision && precision < s_len) s_len = precision; } else { s = const_cast<char*>(s_null); s_len = S_NULL_LEN; } pad_char = ' '; break; case 'f': case 'F': case 'e': case 'E': switch(modifier) { case LM_LONG_DOUBLE: fp_num = (double) va_arg(ap, long double); break; case LM_STD: fp_num = va_arg(ap, double); break; default: goto fmt_error; } if (std::isnan(fp_num)) { s = const_cast<char*>("nan"); s_len = 3; } else if (std::isinf(fp_num)) { s = const_cast<char*>("inf"); s_len = 3; } else { #ifdef HAVE_LOCALE_H if (!lconv) { lconv = localeconv(); } #endif s = php_conv_fp((*fmt == 'f')?'F':*fmt, fp_num, alternate_form, (adjust_precision == NO) ? FLOAT_DIGITS : precision, (*fmt == 'f')?LCONV_DECIMAL_POINT:'.', &is_negative, &num_buf[1], &s_len); if (is_negative) prefix_char = '-'; else if (print_sign) prefix_char = '+'; else if (print_blank) prefix_char = ' '; } break; case 'g': case 'k': case 'G': case 'H': switch(modifier) { case LM_LONG_DOUBLE: fp_num = (double) va_arg(ap, long double); break; case LM_STD: fp_num = va_arg(ap, double); break; default: goto fmt_error; } if (std::isnan(fp_num)) { s = const_cast<char*>("NAN"); s_len = 3; break; } else if (std::isinf(fp_num)) { if (fp_num > 0) { s = const_cast<char*>("INF"); s_len = 3; } else { s = const_cast<char*>("-INF"); s_len = 4; } break; } if (adjust_precision == NO) precision = FLOAT_DIGITS; else if (precision == 0) precision = 1; /* * * We use &num_buf[ 1 ], so that we have room for the sign */ #ifdef HAVE_LOCALE_H if (!lconv) { lconv = localeconv(); } #endif s = php_gcvt(fp_num, precision, (*fmt=='H' || *fmt == 'k') ? '.' : LCONV_DECIMAL_POINT, (*fmt == 'G' || *fmt == 'H')?'E':'e', &num_buf[1]); if (*s == '-') prefix_char = *s++; else if (print_sign) prefix_char = '+'; else if (print_blank) prefix_char = ' '; s_len = strlen(s); if (alternate_form && (q = strchr(s, '.')) == nullptr) s[s_len++] = '.'; break; case 'c': char_buf[0] = (char) (va_arg(ap, int)); s = &char_buf[0]; s_len = 1; pad_char = ' '; break; case '%': char_buf[0] = '%'; s = &char_buf[0]; s_len = 1; pad_char = ' '; break; case 'n': *(va_arg(ap, int *)) = outpos; goto skip_output; /* * Always extract the argument as a "char *" pointer. We * should be using "void *" but there are still machines * that don't understand it. * If the pointer size is equal to the size of an unsigned * integer we convert the pointer to a hex number, otherwise * we print "%p" to indicate that we don't handle "%p". */ case 'p': if (sizeof(char *) <= sizeof(u_wide_int)) { ui_num = (u_wide_int)((size_t) va_arg(ap, char *)); s = ap_php_conv_p2(ui_num, 4, 'x', &num_buf[NUM_BUF_SIZE], &s_len); if (ui_num != 0) { *--s = 'x'; *--s = '0'; s_len += 2; } } else { s = const_cast<char*>("%p"); s_len = 2; } pad_char = ' '; break; case NUL: /* * The last character of the format string was %. * We ignore it. */ continue; fmt_error: throw Exception("Illegal length modifier specified '%c'", *fmt); /* * The default case is for unrecognized %'s. * We print %<char> to help the user identify what * option is not understood. * This is also useful in case the user wants to pass * the output of format_converter to another function * that understands some other %<char> (like syslog). * Note that we can't point s inside fmt because the * unknown <char> could be preceded by width etc. */ default: char_buf[0] = '%'; char_buf[1] = *fmt; s = char_buf; s_len = 2; pad_char = ' '; break; } if (prefix_char != NUL) { *--s = prefix_char; s_len++; } if (adjust_width && adjust == RIGHT && min_width > s_len) { if (pad_char == '0' && prefix_char != NUL) { appendchar(&result, &outpos, &size, *s); s++; s_len--; min_width--; } for (int i = 0; i < min_width - s_len; i++) { appendchar(&result, &outpos, &size, pad_char); } } /* * Print the (for now) non-null terminated string s. */ appendsimplestring(&result, &outpos, &size, s, s_len); if (adjust_width && adjust == LEFT && min_width > s_len) { for (int i = 0; i < min_width - s_len; i++) { appendchar(&result, &outpos, &size, pad_char); } } } skip_output: fmt++; } /* * Add the terminating null here since it wasn't added incrementally above * once the whole string has been composed. */ result[outpos] = NUL; *outbuf = result; return outpos; }
2303
True
1
CVE-2020-1918
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In-memory file operations (ie: using fopen on a data URI) did not properly restrict negative seeking, allowing for the reading of memory prior to the in-memory buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:53Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::xbuf_format_converter
HPHP::xbuf_format_converter( char ** outbuf , const char * fmt , va_list ap)
['outbuf', 'fmt', 'ap']
static int xbuf_format_converter(char **outbuf, const char *fmt, va_list ap) { register char *s = nullptr; char *q; int s_len; register int min_width = 0; int precision = 0; enum { LEFT, RIGHT } adjust; char pad_char; char prefix_char; double fp_num; wide_int i_num = (wide_int) 0; u_wide_int ui_num; char num_buf[NUM_BUF_SIZE]; char char_buf[2]; /* for printing %% and %<unknown> */ #ifdef HAVE_LOCALE_H struct lconv *lconv = nullptr; #endif /* * Flag variables */ length_modifier_e modifier; boolean_e alternate_form; boolean_e print_sign; boolean_e print_blank; boolean_e adjust_precision; boolean_e adjust_width; int is_negative; int size = 240; char *result = (char *)malloc(size); int outpos = 0; while (*fmt) { if (*fmt != '%') { appendchar(&result, &outpos, &size, *fmt); } else { /* * Default variable settings */ adjust = RIGHT; alternate_form = print_sign = print_blank = NO; pad_char = ' '; prefix_char = NUL; fmt++; /* * Try to avoid checking for flags, width or precision */ if (isascii((int)*fmt) && !islower((int)*fmt)) { /* * Recognize flags: -, #, BLANK, + */ for (;; fmt++) { if (*fmt == '-') adjust = LEFT; else if (*fmt == '+') print_sign = YES; else if (*fmt == '#') alternate_form = YES; else if (*fmt == ' ') print_blank = YES; else if (*fmt == '0') pad_char = '0'; else break; } /* * Check if a width was specified */ if (isdigit((int)*fmt)) { STR_TO_DEC(fmt, min_width); adjust_width = YES; } else if (*fmt == '*') { min_width = va_arg(ap, int); fmt++; adjust_width = YES; if (min_width < 0) { adjust = LEFT; min_width = -min_width; } } else adjust_width = NO; /* * Check if a precision was specified * * XXX: an unreasonable amount of precision may be specified * resulting in overflow of num_buf. Currently we * ignore this possibility. */ if (*fmt == '.') { adjust_precision = YES; fmt++; if (isdigit((int)*fmt)) { STR_TO_DEC(fmt, precision); } else if (*fmt == '*') { precision = va_arg(ap, int); fmt++; if (precision < 0) precision = 0; } else precision = 0; } else adjust_precision = NO; } else adjust_precision = adjust_width = NO; /* * Modifier check */ switch (*fmt) { case 'L': fmt++; modifier = LM_LONG_DOUBLE; break; case 'I': fmt++; #if SIZEOF_LONG_LONG if (*fmt == '6' && *(fmt+1) == '4') { fmt += 2; modifier = LM_LONG_LONG; } else #endif if (*fmt == '3' && *(fmt+1) == '2') { fmt += 2; modifier = LM_LONG; } else { #ifdef _WIN64 modifier = LM_LONG_LONG; #else modifier = LM_LONG; #endif } break; case 'l': fmt++; #if SIZEOF_LONG_LONG if (*fmt == 'l') { fmt++; modifier = LM_LONG_LONG; } else #endif modifier = LM_LONG; break; case 'z': fmt++; modifier = LM_SIZE_T; break; case 'j': fmt++; #if SIZEOF_INTMAX_T modifier = LM_INTMAX_T; #else modifier = LM_SIZE_T; #endif break; case 't': fmt++; #if SIZEOF_PTRDIFF_T modifier = LM_PTRDIFF_T; #else modifier = LM_SIZE_T; #endif break; case 'h': fmt++; if (*fmt == 'h') { fmt++; } /* these are promoted to int, so no break */ default: modifier = LM_STD; break; } /* * Argument extraction and printing. * First we determine the argument type. * Then, we convert the argument to a string. * On exit from the switch, s points to the string that * must be printed, s_len has the length of the string * The precision requirements, if any, are reflected in s_len. * * NOTE: pad_char may be set to '0' because of the 0 flag. * It is reset to ' ' by non-numeric formats */ switch (*fmt) { case 'u': switch(modifier) { default: i_num = (wide_int) va_arg(ap, unsigned int); break; case LM_LONG_DOUBLE: goto fmt_error; case LM_LONG: i_num = (wide_int) va_arg(ap, unsigned long int); break; case LM_SIZE_T: i_num = (wide_int) va_arg(ap, size_t); break; #if SIZEOF_LONG_LONG case LM_LONG_LONG: i_num = (wide_int) va_arg(ap, u_wide_int); break; #endif #if SIZEOF_INTMAX_T case LM_INTMAX_T: i_num = (wide_int) va_arg(ap, uintmax_t); break; #endif #if SIZEOF_PTRDIFF_T case LM_PTRDIFF_T: i_num = (wide_int) va_arg(ap, ptrdiff_t); break; #endif } /* * The rest also applies to other integer formats, so fall * into that case. */ case 'd': case 'i': /* * Get the arg if we haven't already. */ if ((*fmt) != 'u') { switch(modifier) { default: i_num = (wide_int) va_arg(ap, int); break; case LM_LONG_DOUBLE: goto fmt_error; case LM_LONG: i_num = (wide_int) va_arg(ap, long int); break; case LM_SIZE_T: #if SIZEOF_SSIZE_T i_num = (wide_int) va_arg(ap, ssize_t); #else i_num = (wide_int) va_arg(ap, size_t); #endif break; #if SIZEOF_LONG_LONG case LM_LONG_LONG: i_num = (wide_int) va_arg(ap, wide_int); break; #endif #if SIZEOF_INTMAX_T case LM_INTMAX_T: i_num = (wide_int) va_arg(ap, intmax_t); break; #endif #if SIZEOF_PTRDIFF_T case LM_PTRDIFF_T: i_num = (wide_int) va_arg(ap, ptrdiff_t); break; #endif } } s = ap_php_conv_10(i_num, (*fmt) == 'u', &is_negative, &num_buf[NUM_BUF_SIZE], &s_len); FIX_PRECISION(adjust_precision, precision, s, s_len); if (*fmt != 'u') { if (is_negative) prefix_char = '-'; else if (print_sign) prefix_char = '+'; else if (print_blank) prefix_char = ' '; } break; case 'o': switch(modifier) { default: ui_num = (u_wide_int) va_arg(ap, unsigned int); break; case LM_LONG_DOUBLE: goto fmt_error; case LM_LONG: ui_num = (u_wide_int) va_arg(ap, unsigned long int); break; case LM_SIZE_T: ui_num = (u_wide_int) va_arg(ap, size_t); break; #if SIZEOF_LONG_LONG case LM_LONG_LONG: ui_num = (u_wide_int) va_arg(ap, u_wide_int); break; #endif #if SIZEOF_INTMAX_T case LM_INTMAX_T: ui_num = (u_wide_int) va_arg(ap, uintmax_t); break; #endif #if SIZEOF_PTRDIFF_T case LM_PTRDIFF_T: ui_num = (u_wide_int) va_arg(ap, ptrdiff_t); break; #endif } s = ap_php_conv_p2(ui_num, 3, *fmt, &num_buf[NUM_BUF_SIZE], &s_len); FIX_PRECISION(adjust_precision, precision, s, s_len); if (alternate_form && *s != '0') { *--s = '0'; s_len++; } break; case 'x': case 'X': switch(modifier) { default: ui_num = (u_wide_int) va_arg(ap, unsigned int); break; case LM_LONG_DOUBLE: goto fmt_error; case LM_LONG: ui_num = (u_wide_int) va_arg(ap, unsigned long int); break; case LM_SIZE_T: ui_num = (u_wide_int) va_arg(ap, size_t); break; #if SIZEOF_LONG_LONG case LM_LONG_LONG: ui_num = (u_wide_int) va_arg(ap, u_wide_int); break; #endif #if SIZEOF_INTMAX_T case LM_INTMAX_T: ui_num = (u_wide_int) va_arg(ap, uintmax_t); break; #endif #if SIZEOF_PTRDIFF_T case LM_PTRDIFF_T: ui_num = (u_wide_int) va_arg(ap, ptrdiff_t); break; #endif } s = ap_php_conv_p2(ui_num, 4, *fmt, &num_buf[NUM_BUF_SIZE], &s_len); FIX_PRECISION(adjust_precision, precision, s, s_len); if (alternate_form && i_num != 0) { *--s = *fmt; /* 'x' or 'X' */ *--s = '0'; s_len += 2; } break; case 's': case 'v': s = va_arg(ap, char *); if (s != nullptr) { s_len = strlen(s); if (adjust_precision && precision < s_len) s_len = precision; } else { s = const_cast<char*>(s_null); s_len = S_NULL_LEN; } pad_char = ' '; break; case 'f': case 'F': case 'e': case 'E': switch(modifier) { case LM_LONG_DOUBLE: fp_num = (double) va_arg(ap, long double); break; case LM_STD: fp_num = va_arg(ap, double); break; default: goto fmt_error; } if (std::isnan(fp_num)) { s = const_cast<char*>("nan"); s_len = 3; } else if (std::isinf(fp_num)) { s = const_cast<char*>("inf"); s_len = 3; } else { #ifdef HAVE_LOCALE_H if (!lconv) { lconv = localeconv(); } #endif s = php_conv_fp((*fmt == 'f')?'F':*fmt, fp_num, alternate_form, (adjust_precision == NO) ? FLOAT_DIGITS : precision, (*fmt == 'f')?LCONV_DECIMAL_POINT:'.', &is_negative, &num_buf[1], &s_len); if (is_negative) prefix_char = '-'; else if (print_sign) prefix_char = '+'; else if (print_blank) prefix_char = ' '; } break; case 'g': case 'k': case 'G': case 'H': switch(modifier) { case LM_LONG_DOUBLE: fp_num = (double) va_arg(ap, long double); break; case LM_STD: fp_num = va_arg(ap, double); break; default: goto fmt_error; } if (std::isnan(fp_num)) { s = const_cast<char*>("NAN"); s_len = 3; break; } else if (std::isinf(fp_num)) { if (fp_num > 0) { s = const_cast<char*>("INF"); s_len = 3; } else { s = const_cast<char*>("-INF"); s_len = 4; } break; } if (adjust_precision == NO) precision = FLOAT_DIGITS; else if (precision == 0) precision = 1; /* * * We use &num_buf[ 1 ], so that we have room for the sign */ #ifdef HAVE_LOCALE_H if (!lconv) { lconv = localeconv(); } #endif s = php_gcvt(fp_num, precision, (*fmt=='H' || *fmt == 'k') ? '.' : LCONV_DECIMAL_POINT, (*fmt == 'G' || *fmt == 'H')?'E':'e', &num_buf[1]); if (*s == '-') prefix_char = *s++; else if (print_sign) prefix_char = '+'; else if (print_blank) prefix_char = ' '; s_len = strlen(s); if (alternate_form && (q = strchr(s, '.')) == nullptr) s[s_len++] = '.'; break; case 'c': char_buf[0] = (char) (va_arg(ap, int)); s = &char_buf[0]; s_len = 1; pad_char = ' '; break; case '%': char_buf[0] = '%'; s = &char_buf[0]; s_len = 1; pad_char = ' '; break; case 'n': *(va_arg(ap, int *)) = outpos; goto skip_output; /* * Always extract the argument as a "char *" pointer. We * should be using "void *" but there are still machines * that don't understand it. * If the pointer size is equal to the size of an unsigned * integer we convert the pointer to a hex number, otherwise * we print "%p" to indicate that we don't handle "%p". */ case 'p': if (sizeof(char *) <= sizeof(u_wide_int)) { ui_num = (u_wide_int)((size_t) va_arg(ap, char *)); s = ap_php_conv_p2(ui_num, 4, 'x', &num_buf[NUM_BUF_SIZE], &s_len); if (ui_num != 0) { *--s = 'x'; *--s = '0'; s_len += 2; } } else { s = const_cast<char*>("%p"); s_len = 2; } pad_char = ' '; break; case NUL: /* * The last character of the format string was %. * We ignore it. */ continue; fmt_error: throw Exception("Illegal length modifier specified '%c'", *fmt); /* * The default case is for unrecognized %'s. * We print %<char> to help the user identify what * option is not understood. * This is also useful in case the user wants to pass * the output of format_converter to another function * that understands some other %<char> (like syslog). * Note that we can't point s inside fmt because the * unknown <char> could be preceded by width etc. */ default: char_buf[0] = '%'; char_buf[1] = *fmt; s = char_buf; s_len = 2; pad_char = ' '; break; } if (prefix_char != NUL) { *--s = prefix_char; s_len++; } if (adjust_width && adjust == RIGHT && min_width > s_len) { if (pad_char == '0' && prefix_char != NUL) { appendchar(&result, &outpos, &size, *s); s++; s_len--; min_width--; } for (int i = 0; i < min_width - s_len; i++) { appendchar(&result, &outpos, &size, pad_char); } } /* * Print the (for now) non-null terminated string s. */ appendsimplestring(&result, &outpos, &size, s, s_len); if (adjust_width && adjust == LEFT && min_width > s_len) { for (int i = 0; i < min_width - s_len; i++) { appendchar(&result, &outpos, &size, pad_char); } } } skip_output: fmt++; } /* * Add the terminating null here since it wasn't added incrementally above * once the whole string has been composed. */ result[outpos] = NUL; *outbuf = result; return outpos; }
2303
True
1
CVE-2020-1919
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Incorrect bounds calculations in substr_compare could lead to an out-of-bounds read when the second string argument passed in is longer than the first. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:51Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::xbuf_format_converter
HPHP::xbuf_format_converter( char ** outbuf , const char * fmt , va_list ap)
['outbuf', 'fmt', 'ap']
static int xbuf_format_converter(char **outbuf, const char *fmt, va_list ap) { register char *s = nullptr; char *q; int s_len; register int min_width = 0; int precision = 0; enum { LEFT, RIGHT } adjust; char pad_char; char prefix_char; double fp_num; wide_int i_num = (wide_int) 0; u_wide_int ui_num; char num_buf[NUM_BUF_SIZE]; char char_buf[2]; /* for printing %% and %<unknown> */ #ifdef HAVE_LOCALE_H struct lconv *lconv = nullptr; #endif /* * Flag variables */ length_modifier_e modifier; boolean_e alternate_form; boolean_e print_sign; boolean_e print_blank; boolean_e adjust_precision; boolean_e adjust_width; int is_negative; int size = 240; char *result = (char *)malloc(size); int outpos = 0; while (*fmt) { if (*fmt != '%') { appendchar(&result, &outpos, &size, *fmt); } else { /* * Default variable settings */ adjust = RIGHT; alternate_form = print_sign = print_blank = NO; pad_char = ' '; prefix_char = NUL; fmt++; /* * Try to avoid checking for flags, width or precision */ if (isascii((int)*fmt) && !islower((int)*fmt)) { /* * Recognize flags: -, #, BLANK, + */ for (;; fmt++) { if (*fmt == '-') adjust = LEFT; else if (*fmt == '+') print_sign = YES; else if (*fmt == '#') alternate_form = YES; else if (*fmt == ' ') print_blank = YES; else if (*fmt == '0') pad_char = '0'; else break; } /* * Check if a width was specified */ if (isdigit((int)*fmt)) { STR_TO_DEC(fmt, min_width); adjust_width = YES; } else if (*fmt == '*') { min_width = va_arg(ap, int); fmt++; adjust_width = YES; if (min_width < 0) { adjust = LEFT; min_width = -min_width; } } else adjust_width = NO; /* * Check if a precision was specified * * XXX: an unreasonable amount of precision may be specified * resulting in overflow of num_buf. Currently we * ignore this possibility. */ if (*fmt == '.') { adjust_precision = YES; fmt++; if (isdigit((int)*fmt)) { STR_TO_DEC(fmt, precision); } else if (*fmt == '*') { precision = va_arg(ap, int); fmt++; if (precision < 0) precision = 0; } else precision = 0; } else adjust_precision = NO; } else adjust_precision = adjust_width = NO; /* * Modifier check */ switch (*fmt) { case 'L': fmt++; modifier = LM_LONG_DOUBLE; break; case 'I': fmt++; #if SIZEOF_LONG_LONG if (*fmt == '6' && *(fmt+1) == '4') { fmt += 2; modifier = LM_LONG_LONG; } else #endif if (*fmt == '3' && *(fmt+1) == '2') { fmt += 2; modifier = LM_LONG; } else { #ifdef _WIN64 modifier = LM_LONG_LONG; #else modifier = LM_LONG; #endif } break; case 'l': fmt++; #if SIZEOF_LONG_LONG if (*fmt == 'l') { fmt++; modifier = LM_LONG_LONG; } else #endif modifier = LM_LONG; break; case 'z': fmt++; modifier = LM_SIZE_T; break; case 'j': fmt++; #if SIZEOF_INTMAX_T modifier = LM_INTMAX_T; #else modifier = LM_SIZE_T; #endif break; case 't': fmt++; #if SIZEOF_PTRDIFF_T modifier = LM_PTRDIFF_T; #else modifier = LM_SIZE_T; #endif break; case 'h': fmt++; if (*fmt == 'h') { fmt++; } /* these are promoted to int, so no break */ default: modifier = LM_STD; break; } /* * Argument extraction and printing. * First we determine the argument type. * Then, we convert the argument to a string. * On exit from the switch, s points to the string that * must be printed, s_len has the length of the string * The precision requirements, if any, are reflected in s_len. * * NOTE: pad_char may be set to '0' because of the 0 flag. * It is reset to ' ' by non-numeric formats */ switch (*fmt) { case 'u': switch(modifier) { default: i_num = (wide_int) va_arg(ap, unsigned int); break; case LM_LONG_DOUBLE: goto fmt_error; case LM_LONG: i_num = (wide_int) va_arg(ap, unsigned long int); break; case LM_SIZE_T: i_num = (wide_int) va_arg(ap, size_t); break; #if SIZEOF_LONG_LONG case LM_LONG_LONG: i_num = (wide_int) va_arg(ap, u_wide_int); break; #endif #if SIZEOF_INTMAX_T case LM_INTMAX_T: i_num = (wide_int) va_arg(ap, uintmax_t); break; #endif #if SIZEOF_PTRDIFF_T case LM_PTRDIFF_T: i_num = (wide_int) va_arg(ap, ptrdiff_t); break; #endif } /* * The rest also applies to other integer formats, so fall * into that case. */ case 'd': case 'i': /* * Get the arg if we haven't already. */ if ((*fmt) != 'u') { switch(modifier) { default: i_num = (wide_int) va_arg(ap, int); break; case LM_LONG_DOUBLE: goto fmt_error; case LM_LONG: i_num = (wide_int) va_arg(ap, long int); break; case LM_SIZE_T: #if SIZEOF_SSIZE_T i_num = (wide_int) va_arg(ap, ssize_t); #else i_num = (wide_int) va_arg(ap, size_t); #endif break; #if SIZEOF_LONG_LONG case LM_LONG_LONG: i_num = (wide_int) va_arg(ap, wide_int); break; #endif #if SIZEOF_INTMAX_T case LM_INTMAX_T: i_num = (wide_int) va_arg(ap, intmax_t); break; #endif #if SIZEOF_PTRDIFF_T case LM_PTRDIFF_T: i_num = (wide_int) va_arg(ap, ptrdiff_t); break; #endif } } s = ap_php_conv_10(i_num, (*fmt) == 'u', &is_negative, &num_buf[NUM_BUF_SIZE], &s_len); FIX_PRECISION(adjust_precision, precision, s, s_len); if (*fmt != 'u') { if (is_negative) prefix_char = '-'; else if (print_sign) prefix_char = '+'; else if (print_blank) prefix_char = ' '; } break; case 'o': switch(modifier) { default: ui_num = (u_wide_int) va_arg(ap, unsigned int); break; case LM_LONG_DOUBLE: goto fmt_error; case LM_LONG: ui_num = (u_wide_int) va_arg(ap, unsigned long int); break; case LM_SIZE_T: ui_num = (u_wide_int) va_arg(ap, size_t); break; #if SIZEOF_LONG_LONG case LM_LONG_LONG: ui_num = (u_wide_int) va_arg(ap, u_wide_int); break; #endif #if SIZEOF_INTMAX_T case LM_INTMAX_T: ui_num = (u_wide_int) va_arg(ap, uintmax_t); break; #endif #if SIZEOF_PTRDIFF_T case LM_PTRDIFF_T: ui_num = (u_wide_int) va_arg(ap, ptrdiff_t); break; #endif } s = ap_php_conv_p2(ui_num, 3, *fmt, &num_buf[NUM_BUF_SIZE], &s_len); FIX_PRECISION(adjust_precision, precision, s, s_len); if (alternate_form && *s != '0') { *--s = '0'; s_len++; } break; case 'x': case 'X': switch(modifier) { default: ui_num = (u_wide_int) va_arg(ap, unsigned int); break; case LM_LONG_DOUBLE: goto fmt_error; case LM_LONG: ui_num = (u_wide_int) va_arg(ap, unsigned long int); break; case LM_SIZE_T: ui_num = (u_wide_int) va_arg(ap, size_t); break; #if SIZEOF_LONG_LONG case LM_LONG_LONG: ui_num = (u_wide_int) va_arg(ap, u_wide_int); break; #endif #if SIZEOF_INTMAX_T case LM_INTMAX_T: ui_num = (u_wide_int) va_arg(ap, uintmax_t); break; #endif #if SIZEOF_PTRDIFF_T case LM_PTRDIFF_T: ui_num = (u_wide_int) va_arg(ap, ptrdiff_t); break; #endif } s = ap_php_conv_p2(ui_num, 4, *fmt, &num_buf[NUM_BUF_SIZE], &s_len); FIX_PRECISION(adjust_precision, precision, s, s_len); if (alternate_form && i_num != 0) { *--s = *fmt; /* 'x' or 'X' */ *--s = '0'; s_len += 2; } break; case 's': case 'v': s = va_arg(ap, char *); if (s != nullptr) { s_len = strlen(s); if (adjust_precision && precision < s_len) s_len = precision; } else { s = const_cast<char*>(s_null); s_len = S_NULL_LEN; } pad_char = ' '; break; case 'f': case 'F': case 'e': case 'E': switch(modifier) { case LM_LONG_DOUBLE: fp_num = (double) va_arg(ap, long double); break; case LM_STD: fp_num = va_arg(ap, double); break; default: goto fmt_error; } if (std::isnan(fp_num)) { s = const_cast<char*>("nan"); s_len = 3; } else if (std::isinf(fp_num)) { s = const_cast<char*>("inf"); s_len = 3; } else { #ifdef HAVE_LOCALE_H if (!lconv) { lconv = localeconv(); } #endif s = php_conv_fp((*fmt == 'f')?'F':*fmt, fp_num, alternate_form, (adjust_precision == NO) ? FLOAT_DIGITS : precision, (*fmt == 'f')?LCONV_DECIMAL_POINT:'.', &is_negative, &num_buf[1], &s_len); if (is_negative) prefix_char = '-'; else if (print_sign) prefix_char = '+'; else if (print_blank) prefix_char = ' '; } break; case 'g': case 'k': case 'G': case 'H': switch(modifier) { case LM_LONG_DOUBLE: fp_num = (double) va_arg(ap, long double); break; case LM_STD: fp_num = va_arg(ap, double); break; default: goto fmt_error; } if (std::isnan(fp_num)) { s = const_cast<char*>("NAN"); s_len = 3; break; } else if (std::isinf(fp_num)) { if (fp_num > 0) { s = const_cast<char*>("INF"); s_len = 3; } else { s = const_cast<char*>("-INF"); s_len = 4; } break; } if (adjust_precision == NO) precision = FLOAT_DIGITS; else if (precision == 0) precision = 1; /* * * We use &num_buf[ 1 ], so that we have room for the sign */ #ifdef HAVE_LOCALE_H if (!lconv) { lconv = localeconv(); } #endif s = php_gcvt(fp_num, precision, (*fmt=='H' || *fmt == 'k') ? '.' : LCONV_DECIMAL_POINT, (*fmt == 'G' || *fmt == 'H')?'E':'e', &num_buf[1]); if (*s == '-') prefix_char = *s++; else if (print_sign) prefix_char = '+'; else if (print_blank) prefix_char = ' '; s_len = strlen(s); if (alternate_form && (q = strchr(s, '.')) == nullptr) s[s_len++] = '.'; break; case 'c': char_buf[0] = (char) (va_arg(ap, int)); s = &char_buf[0]; s_len = 1; pad_char = ' '; break; case '%': char_buf[0] = '%'; s = &char_buf[0]; s_len = 1; pad_char = ' '; break; case 'n': *(va_arg(ap, int *)) = outpos; goto skip_output; /* * Always extract the argument as a "char *" pointer. We * should be using "void *" but there are still machines * that don't understand it. * If the pointer size is equal to the size of an unsigned * integer we convert the pointer to a hex number, otherwise * we print "%p" to indicate that we don't handle "%p". */ case 'p': if (sizeof(char *) <= sizeof(u_wide_int)) { ui_num = (u_wide_int)((size_t) va_arg(ap, char *)); s = ap_php_conv_p2(ui_num, 4, 'x', &num_buf[NUM_BUF_SIZE], &s_len); if (ui_num != 0) { *--s = 'x'; *--s = '0'; s_len += 2; } } else { s = const_cast<char*>("%p"); s_len = 2; } pad_char = ' '; break; case NUL: /* * The last character of the format string was %. * We ignore it. */ continue; fmt_error: throw Exception("Illegal length modifier specified '%c'", *fmt); /* * The default case is for unrecognized %'s. * We print %<char> to help the user identify what * option is not understood. * This is also useful in case the user wants to pass * the output of format_converter to another function * that understands some other %<char> (like syslog). * Note that we can't point s inside fmt because the * unknown <char> could be preceded by width etc. */ default: char_buf[0] = '%'; char_buf[1] = *fmt; s = char_buf; s_len = 2; pad_char = ' '; break; } if (prefix_char != NUL) { *--s = prefix_char; s_len++; } if (adjust_width && adjust == RIGHT && min_width > s_len) { if (pad_char == '0' && prefix_char != NUL) { appendchar(&result, &outpos, &size, *s); s++; s_len--; min_width--; } for (int i = 0; i < min_width - s_len; i++) { appendchar(&result, &outpos, &size, pad_char); } } /* * Print the (for now) non-null terminated string s. */ appendsimplestring(&result, &outpos, &size, s, s_len); if (adjust_width && adjust == LEFT && min_width > s_len) { for (int i = 0; i < min_width - s_len; i++) { appendchar(&result, &outpos, &size, pad_char); } } } skip_output: fmt++; } /* * Add the terminating null here since it wasn't added incrementally above * once the whole string has been composed. */ result[outpos] = NUL; *outbuf = result; return outpos; }
2303
True
1
CVE-2020-1921
False
False
False
False
AV:N/AC:L/Au:N/C:N/I:N/A:P
NETWORK
LOW
NONE
NONE
NONE
PARTIAL
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
NONE
NONE
HIGH
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In the crypt function, we attempt to null terminate a buffer using the size of the input salt without validating that the offset is within the buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::xbuf_format_converter
HPHP::xbuf_format_converter( char ** outbuf , const char * fmt , va_list ap)
['outbuf', 'fmt', 'ap']
static int xbuf_format_converter(char **outbuf, const char *fmt, va_list ap) { register char *s = nullptr; char *q; int s_len; register int min_width = 0; int precision = 0; enum { LEFT, RIGHT } adjust; char pad_char; char prefix_char; double fp_num; wide_int i_num = (wide_int) 0; u_wide_int ui_num; char num_buf[NUM_BUF_SIZE]; char char_buf[2]; /* for printing %% and %<unknown> */ #ifdef HAVE_LOCALE_H struct lconv *lconv = nullptr; #endif /* * Flag variables */ length_modifier_e modifier; boolean_e alternate_form; boolean_e print_sign; boolean_e print_blank; boolean_e adjust_precision; boolean_e adjust_width; int is_negative; int size = 240; char *result = (char *)malloc(size); int outpos = 0; while (*fmt) { if (*fmt != '%') { appendchar(&result, &outpos, &size, *fmt); } else { /* * Default variable settings */ adjust = RIGHT; alternate_form = print_sign = print_blank = NO; pad_char = ' '; prefix_char = NUL; fmt++; /* * Try to avoid checking for flags, width or precision */ if (isascii((int)*fmt) && !islower((int)*fmt)) { /* * Recognize flags: -, #, BLANK, + */ for (;; fmt++) { if (*fmt == '-') adjust = LEFT; else if (*fmt == '+') print_sign = YES; else if (*fmt == '#') alternate_form = YES; else if (*fmt == ' ') print_blank = YES; else if (*fmt == '0') pad_char = '0'; else break; } /* * Check if a width was specified */ if (isdigit((int)*fmt)) { STR_TO_DEC(fmt, min_width); adjust_width = YES; } else if (*fmt == '*') { min_width = va_arg(ap, int); fmt++; adjust_width = YES; if (min_width < 0) { adjust = LEFT; min_width = -min_width; } } else adjust_width = NO; /* * Check if a precision was specified * * XXX: an unreasonable amount of precision may be specified * resulting in overflow of num_buf. Currently we * ignore this possibility. */ if (*fmt == '.') { adjust_precision = YES; fmt++; if (isdigit((int)*fmt)) { STR_TO_DEC(fmt, precision); } else if (*fmt == '*') { precision = va_arg(ap, int); fmt++; if (precision < 0) precision = 0; } else precision = 0; } else adjust_precision = NO; } else adjust_precision = adjust_width = NO; /* * Modifier check */ switch (*fmt) { case 'L': fmt++; modifier = LM_LONG_DOUBLE; break; case 'I': fmt++; #if SIZEOF_LONG_LONG if (*fmt == '6' && *(fmt+1) == '4') { fmt += 2; modifier = LM_LONG_LONG; } else #endif if (*fmt == '3' && *(fmt+1) == '2') { fmt += 2; modifier = LM_LONG; } else { #ifdef _WIN64 modifier = LM_LONG_LONG; #else modifier = LM_LONG; #endif } break; case 'l': fmt++; #if SIZEOF_LONG_LONG if (*fmt == 'l') { fmt++; modifier = LM_LONG_LONG; } else #endif modifier = LM_LONG; break; case 'z': fmt++; modifier = LM_SIZE_T; break; case 'j': fmt++; #if SIZEOF_INTMAX_T modifier = LM_INTMAX_T; #else modifier = LM_SIZE_T; #endif break; case 't': fmt++; #if SIZEOF_PTRDIFF_T modifier = LM_PTRDIFF_T; #else modifier = LM_SIZE_T; #endif break; case 'h': fmt++; if (*fmt == 'h') { fmt++; } /* these are promoted to int, so no break */ default: modifier = LM_STD; break; } /* * Argument extraction and printing. * First we determine the argument type. * Then, we convert the argument to a string. * On exit from the switch, s points to the string that * must be printed, s_len has the length of the string * The precision requirements, if any, are reflected in s_len. * * NOTE: pad_char may be set to '0' because of the 0 flag. * It is reset to ' ' by non-numeric formats */ switch (*fmt) { case 'u': switch(modifier) { default: i_num = (wide_int) va_arg(ap, unsigned int); break; case LM_LONG_DOUBLE: goto fmt_error; case LM_LONG: i_num = (wide_int) va_arg(ap, unsigned long int); break; case LM_SIZE_T: i_num = (wide_int) va_arg(ap, size_t); break; #if SIZEOF_LONG_LONG case LM_LONG_LONG: i_num = (wide_int) va_arg(ap, u_wide_int); break; #endif #if SIZEOF_INTMAX_T case LM_INTMAX_T: i_num = (wide_int) va_arg(ap, uintmax_t); break; #endif #if SIZEOF_PTRDIFF_T case LM_PTRDIFF_T: i_num = (wide_int) va_arg(ap, ptrdiff_t); break; #endif } /* * The rest also applies to other integer formats, so fall * into that case. */ case 'd': case 'i': /* * Get the arg if we haven't already. */ if ((*fmt) != 'u') { switch(modifier) { default: i_num = (wide_int) va_arg(ap, int); break; case LM_LONG_DOUBLE: goto fmt_error; case LM_LONG: i_num = (wide_int) va_arg(ap, long int); break; case LM_SIZE_T: #if SIZEOF_SSIZE_T i_num = (wide_int) va_arg(ap, ssize_t); #else i_num = (wide_int) va_arg(ap, size_t); #endif break; #if SIZEOF_LONG_LONG case LM_LONG_LONG: i_num = (wide_int) va_arg(ap, wide_int); break; #endif #if SIZEOF_INTMAX_T case LM_INTMAX_T: i_num = (wide_int) va_arg(ap, intmax_t); break; #endif #if SIZEOF_PTRDIFF_T case LM_PTRDIFF_T: i_num = (wide_int) va_arg(ap, ptrdiff_t); break; #endif } } s = ap_php_conv_10(i_num, (*fmt) == 'u', &is_negative, &num_buf[NUM_BUF_SIZE], &s_len); FIX_PRECISION(adjust_precision, precision, s, s_len); if (*fmt != 'u') { if (is_negative) prefix_char = '-'; else if (print_sign) prefix_char = '+'; else if (print_blank) prefix_char = ' '; } break; case 'o': switch(modifier) { default: ui_num = (u_wide_int) va_arg(ap, unsigned int); break; case LM_LONG_DOUBLE: goto fmt_error; case LM_LONG: ui_num = (u_wide_int) va_arg(ap, unsigned long int); break; case LM_SIZE_T: ui_num = (u_wide_int) va_arg(ap, size_t); break; #if SIZEOF_LONG_LONG case LM_LONG_LONG: ui_num = (u_wide_int) va_arg(ap, u_wide_int); break; #endif #if SIZEOF_INTMAX_T case LM_INTMAX_T: ui_num = (u_wide_int) va_arg(ap, uintmax_t); break; #endif #if SIZEOF_PTRDIFF_T case LM_PTRDIFF_T: ui_num = (u_wide_int) va_arg(ap, ptrdiff_t); break; #endif } s = ap_php_conv_p2(ui_num, 3, *fmt, &num_buf[NUM_BUF_SIZE], &s_len); FIX_PRECISION(adjust_precision, precision, s, s_len); if (alternate_form && *s != '0') { *--s = '0'; s_len++; } break; case 'x': case 'X': switch(modifier) { default: ui_num = (u_wide_int) va_arg(ap, unsigned int); break; case LM_LONG_DOUBLE: goto fmt_error; case LM_LONG: ui_num = (u_wide_int) va_arg(ap, unsigned long int); break; case LM_SIZE_T: ui_num = (u_wide_int) va_arg(ap, size_t); break; #if SIZEOF_LONG_LONG case LM_LONG_LONG: ui_num = (u_wide_int) va_arg(ap, u_wide_int); break; #endif #if SIZEOF_INTMAX_T case LM_INTMAX_T: ui_num = (u_wide_int) va_arg(ap, uintmax_t); break; #endif #if SIZEOF_PTRDIFF_T case LM_PTRDIFF_T: ui_num = (u_wide_int) va_arg(ap, ptrdiff_t); break; #endif } s = ap_php_conv_p2(ui_num, 4, *fmt, &num_buf[NUM_BUF_SIZE], &s_len); FIX_PRECISION(adjust_precision, precision, s, s_len); if (alternate_form && i_num != 0) { *--s = *fmt; /* 'x' or 'X' */ *--s = '0'; s_len += 2; } break; case 's': case 'v': s = va_arg(ap, char *); if (s != nullptr) { s_len = strlen(s); if (adjust_precision && precision < s_len) s_len = precision; } else { s = const_cast<char*>(s_null); s_len = S_NULL_LEN; } pad_char = ' '; break; case 'f': case 'F': case 'e': case 'E': switch(modifier) { case LM_LONG_DOUBLE: fp_num = (double) va_arg(ap, long double); break; case LM_STD: fp_num = va_arg(ap, double); break; default: goto fmt_error; } if (std::isnan(fp_num)) { s = const_cast<char*>("nan"); s_len = 3; } else if (std::isinf(fp_num)) { s = const_cast<char*>("inf"); s_len = 3; } else { #ifdef HAVE_LOCALE_H if (!lconv) { lconv = localeconv(); } #endif s = php_conv_fp((*fmt == 'f')?'F':*fmt, fp_num, alternate_form, (adjust_precision == NO) ? FLOAT_DIGITS : precision, (*fmt == 'f')?LCONV_DECIMAL_POINT:'.', &is_negative, &num_buf[1], &s_len); if (is_negative) prefix_char = '-'; else if (print_sign) prefix_char = '+'; else if (print_blank) prefix_char = ' '; } break; case 'g': case 'k': case 'G': case 'H': switch(modifier) { case LM_LONG_DOUBLE: fp_num = (double) va_arg(ap, long double); break; case LM_STD: fp_num = va_arg(ap, double); break; default: goto fmt_error; } if (std::isnan(fp_num)) { s = const_cast<char*>("NAN"); s_len = 3; break; } else if (std::isinf(fp_num)) { if (fp_num > 0) { s = const_cast<char*>("INF"); s_len = 3; } else { s = const_cast<char*>("-INF"); s_len = 4; } break; } if (adjust_precision == NO) precision = FLOAT_DIGITS; else if (precision == 0) precision = 1; /* * * We use &num_buf[ 1 ], so that we have room for the sign */ #ifdef HAVE_LOCALE_H if (!lconv) { lconv = localeconv(); } #endif s = php_gcvt(fp_num, precision, (*fmt=='H' || *fmt == 'k') ? '.' : LCONV_DECIMAL_POINT, (*fmt == 'G' || *fmt == 'H')?'E':'e', &num_buf[1]); if (*s == '-') prefix_char = *s++; else if (print_sign) prefix_char = '+'; else if (print_blank) prefix_char = ' '; s_len = strlen(s); if (alternate_form && (q = strchr(s, '.')) == nullptr) s[s_len++] = '.'; break; case 'c': char_buf[0] = (char) (va_arg(ap, int)); s = &char_buf[0]; s_len = 1; pad_char = ' '; break; case '%': char_buf[0] = '%'; s = &char_buf[0]; s_len = 1; pad_char = ' '; break; case 'n': *(va_arg(ap, int *)) = outpos; goto skip_output; /* * Always extract the argument as a "char *" pointer. We * should be using "void *" but there are still machines * that don't understand it. * If the pointer size is equal to the size of an unsigned * integer we convert the pointer to a hex number, otherwise * we print "%p" to indicate that we don't handle "%p". */ case 'p': if (sizeof(char *) <= sizeof(u_wide_int)) { ui_num = (u_wide_int)((size_t) va_arg(ap, char *)); s = ap_php_conv_p2(ui_num, 4, 'x', &num_buf[NUM_BUF_SIZE], &s_len); if (ui_num != 0) { *--s = 'x'; *--s = '0'; s_len += 2; } } else { s = const_cast<char*>("%p"); s_len = 2; } pad_char = ' '; break; case NUL: /* * The last character of the format string was %. * We ignore it. */ continue; fmt_error: throw Exception("Illegal length modifier specified '%c'", *fmt); /* * The default case is for unrecognized %'s. * We print %<char> to help the user identify what * option is not understood. * This is also useful in case the user wants to pass * the output of format_converter to another function * that understands some other %<char> (like syslog). * Note that we can't point s inside fmt because the * unknown <char> could be preceded by width etc. */ default: char_buf[0] = '%'; char_buf[1] = *fmt; s = char_buf; s_len = 2; pad_char = ' '; break; } if (prefix_char != NUL) { *--s = prefix_char; s_len++; } if (adjust_width && adjust == RIGHT && min_width > s_len) { if (pad_char == '0' && prefix_char != NUL) { appendchar(&result, &outpos, &size, *s); s++; s_len--; min_width--; } for (int i = 0; i < min_width - s_len; i++) { appendchar(&result, &outpos, &size, pad_char); } } /* * Print the (for now) non-null terminated string s. */ appendsimplestring(&result, &outpos, &size, s, s_len); if (adjust_width && adjust == LEFT && min_width > s_len) { for (int i = 0; i < min_width - s_len; i++) { appendchar(&result, &outpos, &size, pad_char); } } } skip_output: fmt++; } /* * Add the terminating null here since it wasn't added incrementally above * once the whole string has been composed. */ result[outpos] = NUL; *outbuf = result; return outpos; }
2303
True
1
CVE-2021-24025
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Third Party Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-190'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndIncluding': '4.93.1', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndIncluding': '4.80.1', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Due to incorrect string size calculations inside the preg_quote function, a large input string passed to the function can trigger an integer overflow leading to a heap overflow. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-16T12:45Z
2021-03-10T16:15Z
Integer Overflow or Wraparound
The software performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
An integer overflow or wraparound occurs when an integer value is incremented to a value that is too large to store in the associated representation. When this occurs, the value may wrap to become a very small or negative number. While this may be intended behavior in circumstances that rely on wrapping, it can have security consequences if the wrap is unexpected. This is especially the case if the integer overflow can be triggered using user-supplied inputs. This becomes security-critical when the result is used to control looping, make a security decision, or determine the offset or size in behaviors such as memory allocation, copying, concatenation, etc.
https://cwe.mitre.org/data/definitions/190.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::xbuf_format_converter
HPHP::xbuf_format_converter( char ** outbuf , const char * fmt , va_list ap)
['outbuf', 'fmt', 'ap']
static int xbuf_format_converter(char **outbuf, const char *fmt, va_list ap) { register char *s = nullptr; char *q; int s_len; register int min_width = 0; int precision = 0; enum { LEFT, RIGHT } adjust; char pad_char; char prefix_char; double fp_num; wide_int i_num = (wide_int) 0; u_wide_int ui_num; char num_buf[NUM_BUF_SIZE]; char char_buf[2]; /* for printing %% and %<unknown> */ #ifdef HAVE_LOCALE_H struct lconv *lconv = nullptr; #endif /* * Flag variables */ length_modifier_e modifier; boolean_e alternate_form; boolean_e print_sign; boolean_e print_blank; boolean_e adjust_precision; boolean_e adjust_width; int is_negative; int size = 240; char *result = (char *)malloc(size); int outpos = 0; while (*fmt) { if (*fmt != '%') { appendchar(&result, &outpos, &size, *fmt); } else { /* * Default variable settings */ adjust = RIGHT; alternate_form = print_sign = print_blank = NO; pad_char = ' '; prefix_char = NUL; fmt++; /* * Try to avoid checking for flags, width or precision */ if (isascii((int)*fmt) && !islower((int)*fmt)) { /* * Recognize flags: -, #, BLANK, + */ for (;; fmt++) { if (*fmt == '-') adjust = LEFT; else if (*fmt == '+') print_sign = YES; else if (*fmt == '#') alternate_form = YES; else if (*fmt == ' ') print_blank = YES; else if (*fmt == '0') pad_char = '0'; else break; } /* * Check if a width was specified */ if (isdigit((int)*fmt)) { STR_TO_DEC(fmt, min_width); adjust_width = YES; } else if (*fmt == '*') { min_width = va_arg(ap, int); fmt++; adjust_width = YES; if (min_width < 0) { adjust = LEFT; min_width = -min_width; } } else adjust_width = NO; /* * Check if a precision was specified * * XXX: an unreasonable amount of precision may be specified * resulting in overflow of num_buf. Currently we * ignore this possibility. */ if (*fmt == '.') { adjust_precision = YES; fmt++; if (isdigit((int)*fmt)) { STR_TO_DEC(fmt, precision); } else if (*fmt == '*') { precision = va_arg(ap, int); fmt++; if (precision < 0) precision = 0; } else precision = 0; } else adjust_precision = NO; } else adjust_precision = adjust_width = NO; /* * Modifier check */ switch (*fmt) { case 'L': fmt++; modifier = LM_LONG_DOUBLE; break; case 'I': fmt++; #if SIZEOF_LONG_LONG if (*fmt == '6' && *(fmt+1) == '4') { fmt += 2; modifier = LM_LONG_LONG; } else #endif if (*fmt == '3' && *(fmt+1) == '2') { fmt += 2; modifier = LM_LONG; } else { #ifdef _WIN64 modifier = LM_LONG_LONG; #else modifier = LM_LONG; #endif } break; case 'l': fmt++; #if SIZEOF_LONG_LONG if (*fmt == 'l') { fmt++; modifier = LM_LONG_LONG; } else #endif modifier = LM_LONG; break; case 'z': fmt++; modifier = LM_SIZE_T; break; case 'j': fmt++; #if SIZEOF_INTMAX_T modifier = LM_INTMAX_T; #else modifier = LM_SIZE_T; #endif break; case 't': fmt++; #if SIZEOF_PTRDIFF_T modifier = LM_PTRDIFF_T; #else modifier = LM_SIZE_T; #endif break; case 'h': fmt++; if (*fmt == 'h') { fmt++; } /* these are promoted to int, so no break */ default: modifier = LM_STD; break; } /* * Argument extraction and printing. * First we determine the argument type. * Then, we convert the argument to a string. * On exit from the switch, s points to the string that * must be printed, s_len has the length of the string * The precision requirements, if any, are reflected in s_len. * * NOTE: pad_char may be set to '0' because of the 0 flag. * It is reset to ' ' by non-numeric formats */ switch (*fmt) { case 'u': switch(modifier) { default: i_num = (wide_int) va_arg(ap, unsigned int); break; case LM_LONG_DOUBLE: goto fmt_error; case LM_LONG: i_num = (wide_int) va_arg(ap, unsigned long int); break; case LM_SIZE_T: i_num = (wide_int) va_arg(ap, size_t); break; #if SIZEOF_LONG_LONG case LM_LONG_LONG: i_num = (wide_int) va_arg(ap, u_wide_int); break; #endif #if SIZEOF_INTMAX_T case LM_INTMAX_T: i_num = (wide_int) va_arg(ap, uintmax_t); break; #endif #if SIZEOF_PTRDIFF_T case LM_PTRDIFF_T: i_num = (wide_int) va_arg(ap, ptrdiff_t); break; #endif } /* * The rest also applies to other integer formats, so fall * into that case. */ case 'd': case 'i': /* * Get the arg if we haven't already. */ if ((*fmt) != 'u') { switch(modifier) { default: i_num = (wide_int) va_arg(ap, int); break; case LM_LONG_DOUBLE: goto fmt_error; case LM_LONG: i_num = (wide_int) va_arg(ap, long int); break; case LM_SIZE_T: #if SIZEOF_SSIZE_T i_num = (wide_int) va_arg(ap, ssize_t); #else i_num = (wide_int) va_arg(ap, size_t); #endif break; #if SIZEOF_LONG_LONG case LM_LONG_LONG: i_num = (wide_int) va_arg(ap, wide_int); break; #endif #if SIZEOF_INTMAX_T case LM_INTMAX_T: i_num = (wide_int) va_arg(ap, intmax_t); break; #endif #if SIZEOF_PTRDIFF_T case LM_PTRDIFF_T: i_num = (wide_int) va_arg(ap, ptrdiff_t); break; #endif } } s = ap_php_conv_10(i_num, (*fmt) == 'u', &is_negative, &num_buf[NUM_BUF_SIZE], &s_len); FIX_PRECISION(adjust_precision, precision, s, s_len); if (*fmt != 'u') { if (is_negative) prefix_char = '-'; else if (print_sign) prefix_char = '+'; else if (print_blank) prefix_char = ' '; } break; case 'o': switch(modifier) { default: ui_num = (u_wide_int) va_arg(ap, unsigned int); break; case LM_LONG_DOUBLE: goto fmt_error; case LM_LONG: ui_num = (u_wide_int) va_arg(ap, unsigned long int); break; case LM_SIZE_T: ui_num = (u_wide_int) va_arg(ap, size_t); break; #if SIZEOF_LONG_LONG case LM_LONG_LONG: ui_num = (u_wide_int) va_arg(ap, u_wide_int); break; #endif #if SIZEOF_INTMAX_T case LM_INTMAX_T: ui_num = (u_wide_int) va_arg(ap, uintmax_t); break; #endif #if SIZEOF_PTRDIFF_T case LM_PTRDIFF_T: ui_num = (u_wide_int) va_arg(ap, ptrdiff_t); break; #endif } s = ap_php_conv_p2(ui_num, 3, *fmt, &num_buf[NUM_BUF_SIZE], &s_len); FIX_PRECISION(adjust_precision, precision, s, s_len); if (alternate_form && *s != '0') { *--s = '0'; s_len++; } break; case 'x': case 'X': switch(modifier) { default: ui_num = (u_wide_int) va_arg(ap, unsigned int); break; case LM_LONG_DOUBLE: goto fmt_error; case LM_LONG: ui_num = (u_wide_int) va_arg(ap, unsigned long int); break; case LM_SIZE_T: ui_num = (u_wide_int) va_arg(ap, size_t); break; #if SIZEOF_LONG_LONG case LM_LONG_LONG: ui_num = (u_wide_int) va_arg(ap, u_wide_int); break; #endif #if SIZEOF_INTMAX_T case LM_INTMAX_T: ui_num = (u_wide_int) va_arg(ap, uintmax_t); break; #endif #if SIZEOF_PTRDIFF_T case LM_PTRDIFF_T: ui_num = (u_wide_int) va_arg(ap, ptrdiff_t); break; #endif } s = ap_php_conv_p2(ui_num, 4, *fmt, &num_buf[NUM_BUF_SIZE], &s_len); FIX_PRECISION(adjust_precision, precision, s, s_len); if (alternate_form && i_num != 0) { *--s = *fmt; /* 'x' or 'X' */ *--s = '0'; s_len += 2; } break; case 's': case 'v': s = va_arg(ap, char *); if (s != nullptr) { s_len = strlen(s); if (adjust_precision && precision < s_len) s_len = precision; } else { s = const_cast<char*>(s_null); s_len = S_NULL_LEN; } pad_char = ' '; break; case 'f': case 'F': case 'e': case 'E': switch(modifier) { case LM_LONG_DOUBLE: fp_num = (double) va_arg(ap, long double); break; case LM_STD: fp_num = va_arg(ap, double); break; default: goto fmt_error; } if (std::isnan(fp_num)) { s = const_cast<char*>("nan"); s_len = 3; } else if (std::isinf(fp_num)) { s = const_cast<char*>("inf"); s_len = 3; } else { #ifdef HAVE_LOCALE_H if (!lconv) { lconv = localeconv(); } #endif s = php_conv_fp((*fmt == 'f')?'F':*fmt, fp_num, alternate_form, (adjust_precision == NO) ? FLOAT_DIGITS : precision, (*fmt == 'f')?LCONV_DECIMAL_POINT:'.', &is_negative, &num_buf[1], &s_len); if (is_negative) prefix_char = '-'; else if (print_sign) prefix_char = '+'; else if (print_blank) prefix_char = ' '; } break; case 'g': case 'k': case 'G': case 'H': switch(modifier) { case LM_LONG_DOUBLE: fp_num = (double) va_arg(ap, long double); break; case LM_STD: fp_num = va_arg(ap, double); break; default: goto fmt_error; } if (std::isnan(fp_num)) { s = const_cast<char*>("NAN"); s_len = 3; break; } else if (std::isinf(fp_num)) { if (fp_num > 0) { s = const_cast<char*>("INF"); s_len = 3; } else { s = const_cast<char*>("-INF"); s_len = 4; } break; } if (adjust_precision == NO) precision = FLOAT_DIGITS; else if (precision == 0) precision = 1; /* * * We use &num_buf[ 1 ], so that we have room for the sign */ #ifdef HAVE_LOCALE_H if (!lconv) { lconv = localeconv(); } #endif s = php_gcvt(fp_num, precision, (*fmt=='H' || *fmt == 'k') ? '.' : LCONV_DECIMAL_POINT, (*fmt == 'G' || *fmt == 'H')?'E':'e', &num_buf[1]); if (*s == '-') prefix_char = *s++; else if (print_sign) prefix_char = '+'; else if (print_blank) prefix_char = ' '; s_len = strlen(s); if (alternate_form && (q = strchr(s, '.')) == nullptr) s[s_len++] = '.'; break; case 'c': char_buf[0] = (char) (va_arg(ap, int)); s = &char_buf[0]; s_len = 1; pad_char = ' '; break; case '%': char_buf[0] = '%'; s = &char_buf[0]; s_len = 1; pad_char = ' '; break; case 'n': *(va_arg(ap, int *)) = outpos; goto skip_output; /* * Always extract the argument as a "char *" pointer. We * should be using "void *" but there are still machines * that don't understand it. * If the pointer size is equal to the size of an unsigned * integer we convert the pointer to a hex number, otherwise * we print "%p" to indicate that we don't handle "%p". */ case 'p': if (sizeof(char *) <= sizeof(u_wide_int)) { ui_num = (u_wide_int)((size_t) va_arg(ap, char *)); s = ap_php_conv_p2(ui_num, 4, 'x', &num_buf[NUM_BUF_SIZE], &s_len); if (ui_num != 0) { *--s = 'x'; *--s = '0'; s_len += 2; } } else { s = const_cast<char*>("%p"); s_len = 2; } pad_char = ' '; break; case NUL: /* * The last character of the format string was %. * We ignore it. */ continue; fmt_error: throw Exception("Illegal length modifier specified '%c'", *fmt); /* * The default case is for unrecognized %'s. * We print %<char> to help the user identify what * option is not understood. * This is also useful in case the user wants to pass * the output of format_converter to another function * that understands some other %<char> (like syslog). * Note that we can't point s inside fmt because the * unknown <char> could be preceded by width etc. */ default: char_buf[0] = '%'; char_buf[1] = *fmt; s = char_buf; s_len = 2; pad_char = ' '; break; } if (prefix_char != NUL) { *--s = prefix_char; s_len++; } if (adjust_width && adjust == RIGHT && min_width > s_len) { if (pad_char == '0' && prefix_char != NUL) { appendchar(&result, &outpos, &size, *s); s++; s_len--; min_width--; } for (int i = 0; i < min_width - s_len; i++) { appendchar(&result, &outpos, &size, pad_char); } } /* * Print the (for now) non-null terminated string s. */ appendsimplestring(&result, &outpos, &size, s, s_len); if (adjust_width && adjust == LEFT && min_width > s_len) { for (int i = 0; i < min_width - s_len; i++) { appendchar(&result, &outpos, &size, pad_char); } } } skip_output: fmt++; } /* * Add the terminating null here since it wasn't added incrementally above * once the whole string has been composed. */ result[outpos] = NUL; *outbuf = result; return outpos; }
2303
True
1
CVE-2020-1917
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'xbuf_format_converter, used as part of exif_read_data, was appending a terminating null character to the generated string, but was not using its standard append char function. As a result, if the buffer was full, it would result in an out-of-bounds write. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-17T19:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::string_crypt
HPHP::string_crypt( const char * key , const char * salt)
['key', 'salt']
char *string_crypt(const char *key, const char *salt) { assertx(key); assertx(salt); char random_salt[12]; if (!*salt) { memcpy(random_salt,"$1$",3); ito64(random_salt+3,rand(),8); random_salt[11] = '\0'; return string_crypt(key, random_salt); } auto const saltLen = strlen(salt); if ((saltLen > sizeof("$2X$00$")) && (salt[0] == '$') && (salt[1] == '2') && (salt[2] >= 'a') && (salt[2] <= 'z') && (salt[3] == '$') && (salt[4] >= '0') && (salt[4] <= '3') && (salt[5] >= '0') && (salt[5] <= '9') && (salt[6] == '$')) { // Bundled blowfish crypt() char output[61]; static constexpr size_t maxSaltLength = 123; char paddedSalt[maxSaltLength + 1]; paddedSalt[0] = paddedSalt[maxSaltLength] = '\0'; memset(&paddedSalt[1], '$', maxSaltLength - 1); memcpy(paddedSalt, salt, std::min(maxSaltLength, saltLen)); paddedSalt[saltLen] = '\0'; if (php_crypt_blowfish_rn(key, paddedSalt, output, sizeof(output))) { return strdup(output); } } else { // System crypt() function #ifdef USE_PHP_CRYPT_R return php_crypt_r(key, salt); #else static Mutex mutex; Lock lock(mutex); char *crypt_res = crypt(key,salt); if (crypt_res) { return strdup(crypt_res); } #endif } return ((salt[0] == '*') && (salt[1] == '0')) ? strdup("*1") : strdup("*0"); }
357
True
1
CVE-2020-1918
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In-memory file operations (ie: using fopen on a data URI) did not properly restrict negative seeking, allowing for the reading of memory prior to the in-memory buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:53Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::string_crypt
HPHP::string_crypt( const char * key , const char * salt)
['key', 'salt']
char *string_crypt(const char *key, const char *salt) { assertx(key); assertx(salt); char random_salt[12]; if (!*salt) { memcpy(random_salt,"$1$",3); ito64(random_salt+3,rand(),8); random_salt[11] = '\0'; return string_crypt(key, random_salt); } auto const saltLen = strlen(salt); if ((saltLen > sizeof("$2X$00$")) && (salt[0] == '$') && (salt[1] == '2') && (salt[2] >= 'a') && (salt[2] <= 'z') && (salt[3] == '$') && (salt[4] >= '0') && (salt[4] <= '3') && (salt[5] >= '0') && (salt[5] <= '9') && (salt[6] == '$')) { // Bundled blowfish crypt() char output[61]; static constexpr size_t maxSaltLength = 123; char paddedSalt[maxSaltLength + 1]; paddedSalt[0] = paddedSalt[maxSaltLength] = '\0'; memset(&paddedSalt[1], '$', maxSaltLength - 1); memcpy(paddedSalt, salt, std::min(maxSaltLength, saltLen)); paddedSalt[saltLen] = '\0'; if (php_crypt_blowfish_rn(key, paddedSalt, output, sizeof(output))) { return strdup(output); } } else { // System crypt() function #ifdef USE_PHP_CRYPT_R return php_crypt_r(key, salt); #else static Mutex mutex; Lock lock(mutex); char *crypt_res = crypt(key,salt); if (crypt_res) { return strdup(crypt_res); } #endif } return ((salt[0] == '*') && (salt[1] == '0')) ? strdup("*1") : strdup("*0"); }
357
True
1
CVE-2020-1919
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
NONE
NONE
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-125'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Incorrect bounds calculations in substr_compare could lead to an out-of-bounds read when the second string argument passed in is longer than the first. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:51Z
2021-03-10T16:15Z
Out-of-bounds Read
The software reads data past the end, or before the beginning, of the intended buffer.
Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/125.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::string_crypt
HPHP::string_crypt( const char * key , const char * salt)
['key', 'salt']
char *string_crypt(const char *key, const char *salt) { assertx(key); assertx(salt); char random_salt[12]; if (!*salt) { memcpy(random_salt,"$1$",3); ito64(random_salt+3,rand(),8); random_salt[11] = '\0'; return string_crypt(key, random_salt); } auto const saltLen = strlen(salt); if ((saltLen > sizeof("$2X$00$")) && (salt[0] == '$') && (salt[1] == '2') && (salt[2] >= 'a') && (salt[2] <= 'z') && (salt[3] == '$') && (salt[4] >= '0') && (salt[4] <= '3') && (salt[5] >= '0') && (salt[5] <= '9') && (salt[6] == '$')) { // Bundled blowfish crypt() char output[61]; static constexpr size_t maxSaltLength = 123; char paddedSalt[maxSaltLength + 1]; paddedSalt[0] = paddedSalt[maxSaltLength] = '\0'; memset(&paddedSalt[1], '$', maxSaltLength - 1); memcpy(paddedSalt, salt, std::min(maxSaltLength, saltLen)); paddedSalt[saltLen] = '\0'; if (php_crypt_blowfish_rn(key, paddedSalt, output, sizeof(output))) { return strdup(output); } } else { // System crypt() function #ifdef USE_PHP_CRYPT_R return php_crypt_r(key, salt); #else static Mutex mutex; Lock lock(mutex); char *crypt_res = crypt(key,salt); if (crypt_res) { return strdup(crypt_res); } #endif } return ((salt[0] == '*') && (salt[1] == '0')) ? strdup("*1") : strdup("*0"); }
357
True
1
CVE-2020-1921
False
False
False
False
AV:N/AC:L/Au:N/C:N/I:N/A:P
NETWORK
LOW
NONE
NONE
NONE
PARTIAL
5.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
NONE
NONE
HIGH
7.5
HIGH
3.9
3.6
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Vendor Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndExcluding': '4.93.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndExcluding': '4.80.2', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'In the crypt function, we attempt to null terminate a buffer using the size of the input salt without validating that the offset is within the buffer. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-15T15:29Z
2021-03-10T16:15Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::string_crypt
HPHP::string_crypt( const char * key , const char * salt)
['key', 'salt']
char *string_crypt(const char *key, const char *salt) { assertx(key); assertx(salt); char random_salt[12]; if (!*salt) { memcpy(random_salt,"$1$",3); ito64(random_salt+3,rand(),8); random_salt[11] = '\0'; return string_crypt(key, random_salt); } auto const saltLen = strlen(salt); if ((saltLen > sizeof("$2X$00$")) && (salt[0] == '$') && (salt[1] == '2') && (salt[2] >= 'a') && (salt[2] <= 'z') && (salt[3] == '$') && (salt[4] >= '0') && (salt[4] <= '3') && (salt[5] >= '0') && (salt[5] <= '9') && (salt[6] == '$')) { // Bundled blowfish crypt() char output[61]; static constexpr size_t maxSaltLength = 123; char paddedSalt[maxSaltLength + 1]; paddedSalt[0] = paddedSalt[maxSaltLength] = '\0'; memset(&paddedSalt[1], '$', maxSaltLength - 1); memcpy(paddedSalt, salt, std::min(maxSaltLength, saltLen)); paddedSalt[saltLen] = '\0'; if (php_crypt_blowfish_rn(key, paddedSalt, output, sizeof(output))) { return strdup(output); } } else { // System crypt() function #ifdef USE_PHP_CRYPT_R return php_crypt_r(key, salt); #else static Mutex mutex; Lock lock(mutex); char *crypt_res = crypt(key,salt); if (crypt_res) { return strdup(crypt_res); } #endif } return ((salt[0] == '*') && (salt[1] == '0')) ? strdup("*1") : strdup("*0"); }
357
True
1
CVE-2021-24025
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'name': 'https://github.com/facebook/hhvm/commit/08193b7f0cd3910256e00d599f0f3eb2519c44ca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'name': 'https://hhvm.com/blog/2021/02/25/security-update.html', 'refsource': 'MISC', 'tags': ['Release Notes', 'Third Party Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-190'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.95.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.96.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.97.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.98.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:4.94.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '4.56.3', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.81.0', 'versionEndIncluding': '4.93.1', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '4.57.0', 'versionEndIncluding': '4.80.1', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Due to incorrect string size calculations inside the preg_quote function, a large input string passed to the function can trigger an integer overflow leading to a heap overflow. This issue affects HHVM versions prior to 4.56.3, all versions between 4.57.0 and 4.80.1, all versions between 4.81.0 and 4.93.1, and versions 4.94.0, 4.95.0, 4.96.0, 4.97.0, 4.98.0.'}]
2021-03-16T12:45Z
2021-03-10T16:15Z
Integer Overflow or Wraparound
The software performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
An integer overflow or wraparound occurs when an integer value is incremented to a value that is too large to store in the associated representation. When this occurs, the value may wrap to become a very small or negative number. While this may be intended behavior in circumstances that rely on wrapping, it can have security consequences if the wrap is unexpected. This is especially the case if the integer overflow can be triggered using user-supplied inputs. This becomes security-critical when the result is used to control looping, make a security decision, or determine the offset or size in behaviors such as memory allocation, copying, concatenation, etc.
https://cwe.mitre.org/data/definitions/190.html
0
jjergus
2021-02-24 13:36:08-08:00
security fixes https://hhvm.com/blog/2021/02/25/security-update.html
08193b7f0cd3910256e00d599f0f3eb2519c44ca
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::string_crypt
HPHP::string_crypt( const char * key , const char * salt)
['key', 'salt']
char *string_crypt(const char *key, const char *salt) { assertx(key); assertx(salt); char random_salt[12]; if (!*salt) { memcpy(random_salt,"$1$",3); ito64(random_salt+3,rand(),8); random_salt[11] = '\0'; return string_crypt(key, random_salt); } auto const saltLen = strlen(salt); if ((saltLen > sizeof("$2X$00$")) && (salt[0] == '$') && (salt[1] == '2') && (salt[2] >= 'a') && (salt[2] <= 'z') && (salt[3] == '$') && (salt[4] >= '0') && (salt[4] <= '3') && (salt[5] >= '0') && (salt[5] <= '9') && (salt[6] == '$')) { // Bundled blowfish crypt() char output[61]; static constexpr size_t maxSaltLength = 123; char paddedSalt[maxSaltLength + 1]; paddedSalt[0] = paddedSalt[maxSaltLength] = '\0'; memset(&paddedSalt[1], '$', maxSaltLength - 1); memcpy(paddedSalt, salt, std::min(maxSaltLength, saltLen)); paddedSalt[saltLen] = '\0'; if (php_crypt_blowfish_rn(key, paddedSalt, output, sizeof(output))) { return strdup(output); } } else { // System crypt() function #ifdef USE_PHP_CRYPT_R return php_crypt_r(key, salt); #else static Mutex mutex; Lock lock(mutex); char *crypt_res = crypt(key,salt); if (crypt_res) { return strdup(crypt_res); } #endif } return ((salt[0] == '*') && (salt[1] == '0')) ? strdup("*1") : strdup("*0"); }
357
True
1
CVE-2014-1439
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
[{'url': 'http://www.hhvm.com/blog/3287/hhvm-2-4-0', 'name': 'http://www.hhvm.com/blog/3287/hhvm-2-4-0', 'refsource': 'CONFIRM', 'tags': ['Vendor Advisory']}, {'url': 'https://github.com/facebook/hhvm/commit/95f96e7287effe2fcdfb9a5338d1a7e4f55b083b', 'name': 'https://github.com/facebook/hhvm/commit/95f96e7287effe2fcdfb9a5338d1a7e4f55b083b', 'refsource': 'CONFIRM', 'tags': []}, {'url': 'https://exchange.xforce.ibmcloud.com/vulnerabilities/90979', 'name': 'hhvm-cve20141439-info-disc(90979)', 'refsource': 'XF', 'tags': []}]
[{'description': [{'lang': 'en', 'value': 'NVD-CWE-Other'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:hiphop_virtual_machine_for_php_project:hiphop_virtual_machine_for_php:2.1.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:hiphop_virtual_machine_for_php_project:hiphop_virtual_machine_for_php:2.0.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:hiphop_virtual_machine_for_php_project:hiphop_virtual_machine_for_php:2.0.1:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:hiphop_virtual_machine_for_php_project:hiphop_virtual_machine_for_php:2.3.1:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:hiphop_virtual_machine_for_php_project:hiphop_virtual_machine_for_php:2.2.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:hiphop_virtual_machine_for_php_project:hiphop_virtual_machine_for_php:2.0.2:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:hiphop_virtual_machine_for_php_project:hiphop_virtual_machine_for_php:2.3.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:hiphop_virtual_machine_for_php_project:hiphop_virtual_machine_for_php:*:*:*:*:*:*:*:*', 'versionEndIncluding': '2.3.2', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'The libxml_disable_entity_loader function in runtime/ext/ext_simplexml.cpp in HipHop Virtual Machine for PHP (HHVM) before 2.4.0 and 2.3.x before 2.3.3 does not properly disable a certain libxml handler, which allows remote attackers to conduct XML External Entity (XXE) attacks.'}]
2017-08-29T01:34Z
2014-02-05T19:55Z
Other
NVD is only using a subset of CWE for mapping instead of the entire CWE, and the weakness type is not covered by that subset.
Insufficient Information
https://nvd.nist.gov/vuln/categories
0
Scott MacVicar
2014-01-04 01:39:10-08:00
Fix libxml_disable_entity_loader() This wasn't calling requestInit and setting the libxml handler no null. So the first time an error came along it would reset the handler from no-op to reading again. This is a much better fix, we set our custom handler in requestInit and when libxml_disable_entity_loader we store that state as a member bool ensuring requestInit is always called to set our own handler. If the handler isn't inserted then the behavious is as before. The only time this could go pear shaped is say we wanted to make the default be off. In that case we'd need a global requestInit that is always called since there are libxml references everywhere. Reviewed By: @jdelong Differential Revision: D1116686
95f96e7287effe2fcdfb9a5338d1a7e4f55b083b
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::LibXmlErrors::requestInit
HPHP::LibXmlErrors::requestInit()
[]
virtual void requestInit() { m_use_error = false; m_errors.reset(); xmlParserInputBufferCreateFilenameDefault(nullptr); }
20
True
1
CVE-2014-1439
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
[{'url': 'http://www.hhvm.com/blog/3287/hhvm-2-4-0', 'name': 'http://www.hhvm.com/blog/3287/hhvm-2-4-0', 'refsource': 'CONFIRM', 'tags': ['Vendor Advisory']}, {'url': 'https://github.com/facebook/hhvm/commit/95f96e7287effe2fcdfb9a5338d1a7e4f55b083b', 'name': 'https://github.com/facebook/hhvm/commit/95f96e7287effe2fcdfb9a5338d1a7e4f55b083b', 'refsource': 'CONFIRM', 'tags': []}, {'url': 'https://exchange.xforce.ibmcloud.com/vulnerabilities/90979', 'name': 'hhvm-cve20141439-info-disc(90979)', 'refsource': 'XF', 'tags': []}]
[{'description': [{'lang': 'en', 'value': 'NVD-CWE-Other'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:hiphop_virtual_machine_for_php_project:hiphop_virtual_machine_for_php:2.1.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:hiphop_virtual_machine_for_php_project:hiphop_virtual_machine_for_php:2.0.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:hiphop_virtual_machine_for_php_project:hiphop_virtual_machine_for_php:2.0.1:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:hiphop_virtual_machine_for_php_project:hiphop_virtual_machine_for_php:2.3.1:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:hiphop_virtual_machine_for_php_project:hiphop_virtual_machine_for_php:2.2.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:hiphop_virtual_machine_for_php_project:hiphop_virtual_machine_for_php:2.0.2:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:hiphop_virtual_machine_for_php_project:hiphop_virtual_machine_for_php:2.3.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:hiphop_virtual_machine_for_php_project:hiphop_virtual_machine_for_php:*:*:*:*:*:*:*:*', 'versionEndIncluding': '2.3.2', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'The libxml_disable_entity_loader function in runtime/ext/ext_simplexml.cpp in HipHop Virtual Machine for PHP (HHVM) before 2.4.0 and 2.3.x before 2.3.3 does not properly disable a certain libxml handler, which allows remote attackers to conduct XML External Entity (XXE) attacks.'}]
2017-08-29T01:34Z
2014-02-05T19:55Z
Other
NVD is only using a subset of CWE for mapping instead of the entire CWE, and the weakness type is not covered by that subset.
Insufficient Information
https://nvd.nist.gov/vuln/categories
0
Scott MacVicar
2014-01-04 01:39:10-08:00
Fix libxml_disable_entity_loader() This wasn't calling requestInit and setting the libxml handler no null. So the first time an error came along it would reset the handler from no-op to reading again. This is a much better fix, we set our custom handler in requestInit and when libxml_disable_entity_loader we store that state as a member bool ensuring requestInit is always called to set our own handler. If the handler isn't inserted then the behavious is as before. The only time this could go pear shaped is say we wanted to make the default be off. In that case we'd need a global requestInit that is always called since there are libxml references everywhere. Reviewed By: @jdelong Differential Revision: D1116686
95f96e7287effe2fcdfb9a5338d1a7e4f55b083b
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::f_libxml_disable_entity_loader
HPHP::f_libxml_disable_entity_loader( bool disable)
['disable']
bool f_libxml_disable_entity_loader(bool disable /* = true */) { xmlParserInputBufferCreateFilenameFunc old; if (disable) { old = xmlParserInputBufferCreateFilenameDefault(hphp_libxml_input_buffer_noload); } else { old = xmlParserInputBufferCreateFilenameDefault(nullptr); } return (old == hphp_libxml_input_buffer_noload); }
40
True
1
CVE-2014-1439
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:N/A:N
NETWORK
LOW
NONE
PARTIAL
NONE
NONE
5.0
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
[{'url': 'http://www.hhvm.com/blog/3287/hhvm-2-4-0', 'name': 'http://www.hhvm.com/blog/3287/hhvm-2-4-0', 'refsource': 'CONFIRM', 'tags': ['Vendor Advisory']}, {'url': 'https://github.com/facebook/hhvm/commit/95f96e7287effe2fcdfb9a5338d1a7e4f55b083b', 'name': 'https://github.com/facebook/hhvm/commit/95f96e7287effe2fcdfb9a5338d1a7e4f55b083b', 'refsource': 'CONFIRM', 'tags': []}, {'url': 'https://exchange.xforce.ibmcloud.com/vulnerabilities/90979', 'name': 'hhvm-cve20141439-info-disc(90979)', 'refsource': 'XF', 'tags': []}]
[{'description': [{'lang': 'en', 'value': 'NVD-CWE-Other'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:hiphop_virtual_machine_for_php_project:hiphop_virtual_machine_for_php:2.1.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:hiphop_virtual_machine_for_php_project:hiphop_virtual_machine_for_php:2.0.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:hiphop_virtual_machine_for_php_project:hiphop_virtual_machine_for_php:2.0.1:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:hiphop_virtual_machine_for_php_project:hiphop_virtual_machine_for_php:2.3.1:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:hiphop_virtual_machine_for_php_project:hiphop_virtual_machine_for_php:2.2.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:hiphop_virtual_machine_for_php_project:hiphop_virtual_machine_for_php:2.0.2:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:hiphop_virtual_machine_for_php_project:hiphop_virtual_machine_for_php:2.3.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:hiphop_virtual_machine_for_php_project:hiphop_virtual_machine_for_php:*:*:*:*:*:*:*:*', 'versionEndIncluding': '2.3.2', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'The libxml_disable_entity_loader function in runtime/ext/ext_simplexml.cpp in HipHop Virtual Machine for PHP (HHVM) before 2.4.0 and 2.3.x before 2.3.3 does not properly disable a certain libxml handler, which allows remote attackers to conduct XML External Entity (XXE) attacks.'}]
2017-08-29T01:34Z
2014-02-05T19:55Z
Other
NVD is only using a subset of CWE for mapping instead of the entire CWE, and the weakness type is not covered by that subset.
Insufficient Information
https://nvd.nist.gov/vuln/categories
0
Scott MacVicar
2014-01-04 01:39:10-08:00
Fix libxml_disable_entity_loader() This wasn't calling requestInit and setting the libxml handler no null. So the first time an error came along it would reset the handler from no-op to reading again. This is a much better fix, we set our custom handler in requestInit and when libxml_disable_entity_loader we store that state as a member bool ensuring requestInit is always called to set our own handler. If the handler isn't inserted then the behavious is as before. The only time this could go pear shaped is say we wanted to make the default be off. In that case we'd need a global requestInit that is always called since there are libxml references everywhere. Reviewed By: @jdelong Differential Revision: D1116686
95f96e7287effe2fcdfb9a5338d1a7e4f55b083b
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::hphp_libxml_input_buffer_noload
HPHP::hphp_libxml_input_buffer_noload( const char * URI , xmlCharEncoding enc)
['URI', 'enc']
hphp_libxml_input_buffer_noload(const char *URI, xmlCharEncoding enc) { return nullptr; }
15
True
1
CVE-2014-9767
False
False
False
True
AV:N/AC:M/Au:N/C:N/I:P/A:N
NETWORK
MEDIUM
NONE
NONE
PARTIAL
NONE
4.3
CVSS:3.0/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:L/A:N
NETWORK
LOW
NONE
REQUIRED
UNCHANGED
NONE
LOW
NONE
4.3
MEDIUM
2.8
1.4
nan
[{'url': 'http://php.net/ChangeLog-5.php', 'name': 'http://php.net/ChangeLog-5.php', 'refsource': 'CONFIRM', 'tags': []}, {'url': 'https://bugs.php.net/bug.php?id=67996', 'name': 'https://bugs.php.net/bug.php?id=67996', 'refsource': 'CONFIRM', 'tags': ['Exploit']}, {'url': 'https://bugs.php.net/bug.php?id=70350', 'name': 'https://bugs.php.net/bug.php?id=70350', 'refsource': 'CONFIRM', 'tags': ['Exploit']}, {'url': 'https://github.com/facebook/hhvm/commit/65c95a01541dd2fbc9c978ac53bed235b5376686', 'name': 'https://github.com/facebook/hhvm/commit/65c95a01541dd2fbc9c978ac53bed235b5376686', 'refsource': 'CONFIRM', 'tags': []}, {'url': 'http://www.openwall.com/lists/oss-security/2016/03/16/20', 'name': '[oss-security] 20160316 Re: Three CVE requests for PHP', 'refsource': 'MLIST', 'tags': []}, {'url': 'http://www.securityfocus.com/bid/76652', 'name': '76652', 'refsource': 'BID', 'tags': []}, {'url': 'http://lists.opensuse.org/opensuse-security-announce/2016-04/msg00052.html', 'name': 'SUSE-SU-2016:1145', 'refsource': 'SUSE', 'tags': []}, {'url': 'http://lists.opensuse.org/opensuse-security-announce/2016-04/msg00057.html', 'name': 'openSUSE-SU-2016:1167', 'refsource': 'SUSE', 'tags': []}, {'url': 'http://lists.opensuse.org/opensuse-security-announce/2016-04/msg00058.html', 'name': 'openSUSE-SU-2016:1173', 'refsource': 'SUSE', 'tags': []}, {'url': 'http://lists.opensuse.org/opensuse-security-announce/2016-04/msg00056.html', 'name': 'SUSE-SU-2016:1166', 'refsource': 'SUSE', 'tags': []}, {'url': 'http://www.ubuntu.com/usn/USN-2952-1', 'name': 'USN-2952-1', 'refsource': 'UBUNTU', 'tags': []}, {'url': 'http://www.ubuntu.com/usn/USN-2952-2', 'name': 'USN-2952-2', 'refsource': 'UBUNTU', 'tags': []}, {'url': 'http://www.securitytracker.com/id/1035311', 'name': '1035311', 'refsource': 'SECTRACK', 'tags': []}, {'url': 'http://rhn.redhat.com/errata/RHSA-2016-2750.html', 'name': 'RHSA-2016:2750', 'refsource': 'REDHAT', 'tags': []}]
[{'description': [{'lang': 'en', 'value': 'CWE-22'}]}]
MEDIUM
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.6.1:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.6.5:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.5.19:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.6.12:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.5.25:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.5.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.6.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.5.1:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.5.5:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.6.6:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.6.4:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.5.14:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.5.6:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.6.10:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.5.21:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.5.11:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.6.7:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.5.27:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.5.8:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.5.7:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:*:*:*:*:*:*:*:*', 'versionEndIncluding': '5.4.45', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.6.11:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.6.2:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.5.24:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.5.23:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.5.12:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.5.3:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.5.26:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.5.18:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.6.9:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.5.22:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.5.10:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.5.2:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.6.8:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.5.28:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.5.20:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.5.9:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.6.3:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.5.13:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:php:php:5.5.4:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:hiphop_virtual_machine_for_php_project:hiphop_virtual_machine_for_php:*:*:*:*:*:*:*:*', 'versionEndIncluding': '3.12', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Directory traversal vulnerability in the ZipArchive::extractTo function in ext/zip/php_zip.c in PHP before 5.4.45, 5.5.x before 5.5.29, and 5.6.x before 5.6.13 and ext/zip/ext_zip.cpp in HHVM before 3.12.1 allows remote attackers to create arbitrary empty directories via a crafted ZIP archive.'}]
2018-01-05T02:29Z
2016-05-22T01:59Z
Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
The software uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the software does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.
Many file operations are intended to take place within a restricted directory. By using special elements such as ".." and "/" separators, attackers can escape outside of the restricted location to access files or directories that are elsewhere on the system. One of the most common special elements is the "../" sequence, which in most modern operating systems is interpreted as the parent directory of the current location. This is referred to as relative path traversal. Path traversal also covers the use of absolute pathnames such as "/usr/local/bin", which may also be useful in accessing unexpected files. This is referred to as absolute path traversal. In many programming languages, the injection of a null byte (the 0 or NUL) may allow an attacker to truncate a generated filename to widen the scope of attack. For example, the software may add ".txt" to any pathname, thus limiting the attacker to text files, but a null injection may effectively remove this restriction.
https://cwe.mitre.org/data/definitions/22.html
0
Paul Bissonnette
2016-02-29 15:59:56-08:00
ZipArchive::extractTo bug 70350 Summary:Don't allow upward directory traversal when extracting zip archive files. Files in zip files with `..` or starting at main root `/` should be normalized to something where the file being extracted winds up within the directory or a subdirectory where the actual extraction is taking place. http://git.php.net/?p=php-src.git;a=commit;h=f9c2bf73adb2ede0a486b0db466c264f2b27e0bb Reviewed By: FBNeal Differential Revision: D2798452 fb-gh-sync-id: 844549c93e011d1e991bb322bf85822246b04e30 shipit-source-id: 844549c93e011d1e991bb322bf85822246b04e30
65c95a01541dd2fbc9c978ac53bed235b5376686
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::extractFileTo
HPHP::extractFileTo( zip * zip , const std :: string & file , std :: string & to , char * buf , size_t len)
['zip', 'file', 'to', 'buf', 'len']
static bool extractFileTo(zip* zip, const std::string &file, std::string& to, char* buf, size_t len) { auto sep = file.rfind('/'); if (sep != std::string::npos) { auto path = to + file.substr(0, sep); if (!HHVM_FN(is_dir)(path) && !HHVM_FN(mkdir)(path, 0777, true)) { return false; } if (sep == file.length() - 1) { return true; } } to.append(file); struct zip_stat zipStat; if (zip_stat(zip, file.c_str(), 0, &zipStat) != 0) { return false; } auto zipFile = zip_fopen_index(zip, zipStat.index, 0); FAIL_IF_INVALID_PTR(zipFile); auto outFile = fopen(to.c_str(), "wb"); if (outFile == nullptr) { zip_fclose(zipFile); return false; } for (auto n = zip_fread(zipFile, buf, len); n != 0; n = zip_fread(zipFile, buf, len)) { if (n < 0 || fwrite(buf, sizeof(char), n, outFile) != n) { zip_fclose(zipFile); fclose(outFile); remove(to.c_str()); return false; } } zip_fclose(zipFile); if (fclose(outFile) != 0) { return false; } return true; }
294
True
1
CVE-2016-1000005
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/39e7e177473350b3a5c34e8824af3b98e25efa89', 'name': 'https://github.com/facebook/hhvm/commit/39e7e177473350b3a5c34e8824af3b98e25efa89', 'refsource': 'CONFIRM', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://www.facebook.com/security/advisories/cve-2016-1000005', 'name': 'https://www.facebook.com/security/advisories/cve-2016-1000005', 'refsource': 'CONFIRM', 'tags': ['Third Party Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-843'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '3.9.5', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '3.10.0', 'versionEndIncluding': '3.12.3', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '3.13.0', 'versionEndIncluding': '3.14.1', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'mcrypt_get_block_size did not enforce that the provided "module" parameter was a string, leading to type confusion if other types of data were passed in. This issue affects HHVM versions prior to 3.9.5, all versions between 3.10.0 and 3.12.3 (inclusive), and all versions between 3.13.0 and 3.14.1 (inclusive).'}]
2020-03-05T18:16Z
2020-02-19T13:15Z
Access of Resource Using Incompatible Type ('Type Confusion')
The program allocates or initializes a resource such as a pointer, object, or variable using one type, but it later accesses that resource using a type that is incompatible with the original type.
When the program accesses the resource using an incompatible type, this could trigger logical errors because the resource does not have expected properties. In languages without memory safety, such as C and C++, type confusion can lead to out-of-bounds memory access. While this weakness is frequently associated with unions when parsing data with many different embedded object types in C, it can be present in any application that can interpret the same variable or memory location in multiple ways. This weakness is not unique to C and C++. For example, errors in PHP applications can be triggered by providing array parameters when scalars are expected, or vice versa. Languages such as Perl, which perform automatic conversion of a variable of one type when it is accessed as if it were another type, can also contain these issues.
https://cwe.mitre.org/data/definitions/843.html
0
Max Wang
2016-07-01 09:08:51-07:00
Fix param types for mcrypt_get_block_size() to match PHP Reviewed By: edwinsmith Differential Revision: D3447281 fbshipit-source-id: a88549307faad886f5a0f78d421aa28e08d21b1c
39e7e177473350b3a5c34e8824af3b98e25efa89
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::HHVM_FUNCTION
HPHP::HHVM_FUNCTION( mcrypt_get_block_size , const String & cipher , const Variant & module)
['mcrypt_get_block_size', 'cipher', 'module']
Variant HHVM_FUNCTION(mcrypt_get_block_size, const String& cipher, const Variant& module /* = null_string */) { MCRYPT td = mcrypt_module_open((char*)cipher.data(), (char*)MCG(algorithms_dir).data(), (char*)module.asCStrRef().data(), (char*)MCG(modes_dir).data()); if (td == MCRYPT_FAILED) { MCRYPT_OPEN_MODULE_FAILED("mcrypt_get_block_size"); return false; } int64_t ret = mcrypt_enc_get_block_size(td); mcrypt_module_close(td); return ret; }
104
True
1
CVE-2016-1000004
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/8e7266fef1f329b805b37f32c9ad0090215ab269', 'name': 'https://github.com/facebook/hhvm/commit/8e7266fef1f329b805b37f32c9ad0090215ab269', 'refsource': 'CONFIRM', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://www.facebook.com/security/advisories/cve-2016-1000004', 'name': 'https://www.facebook.com/security/advisories/cve-2016-1000004', 'refsource': 'CONFIRM', 'tags': ['Third Party Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-345'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '3.9.5', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '3.10.0', 'versionEndIncluding': '3.12.3', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '3.13.0', 'versionEndIncluding': '3.14.1', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Insufficient type checks were employed prior to casting input data in SimpleXMLElement_exportNode and simplexml_import_dom. This issue affects HHVM versions prior to 3.9.5, all versions between 3.10.0 and 3.12.3 (inclusive), and all versions between 3.13.0 and 3.14.1 (inclusive).'}]
2020-03-05T18:02Z
2020-02-19T13:15Z
Insufficient Verification of Data Authenticity
The software does not sufficiently verify the origin or authenticity of data, in a way that causes it to accept invalid data.
https://cwe.mitre.org/data/definitions/345.html
0
Max Wang
2016-07-01 09:09:30-07:00
Type safety in simplexml import routines Reviewed By: Orvid Differential Revision: D3447275 fbshipit-source-id: d859c97f9d85c520b0e371cef6dcb19bb2ef7dbf
8e7266fef1f329b805b37f32c9ad0090215ab269
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::HHVM_FUNCTION
HPHP::HHVM_FUNCTION( simplexml_import_dom , const Object & node , const String & class_name)
['simplexml_import_dom', 'node', 'class_name']
static Variant HHVM_FUNCTION(simplexml_import_dom, const Object& node, const String& class_name /* = "SimpleXMLElement" */) { auto domnode = Native::data<DOMNode>(node); xmlNodePtr nodep = domnode->nodep(); if (nodep) { if (nodep->doc == nullptr) { raise_warning("Imported Node must have associated Document"); return init_null(); } if (nodep->type == XML_DOCUMENT_NODE || nodep->type == XML_HTML_DOCUMENT_NODE) { nodep = xmlDocGetRootElement((xmlDocPtr) nodep); } } if (nodep && nodep->type == XML_ELEMENT_NODE) { auto cls = class_from_name(class_name, "simplexml_import_dom"); if (!cls) { return init_null(); } Object obj = create_object(cls->nameStr(), Array(), false); auto sxe = Native::data<SimpleXMLElement>(obj.get()); sxe->node = libxml_register_node(nodep); return obj; } else { raise_warning("Invalid Nodetype to import"); return init_null(); } return false; }
187
True
1
CVE-2016-1000004
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
False
[{'url': 'https://github.com/facebook/hhvm/commit/8e7266fef1f329b805b37f32c9ad0090215ab269', 'name': 'https://github.com/facebook/hhvm/commit/8e7266fef1f329b805b37f32c9ad0090215ab269', 'refsource': 'CONFIRM', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://www.facebook.com/security/advisories/cve-2016-1000004', 'name': 'https://www.facebook.com/security/advisories/cve-2016-1000004', 'refsource': 'CONFIRM', 'tags': ['Third Party Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-345'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndExcluding': '3.9.5', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '3.10.0', 'versionEndIncluding': '3.12.3', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionStartIncluding': '3.13.0', 'versionEndIncluding': '3.14.1', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Insufficient type checks were employed prior to casting input data in SimpleXMLElement_exportNode and simplexml_import_dom. This issue affects HHVM versions prior to 3.9.5, all versions between 3.10.0 and 3.12.3 (inclusive), and all versions between 3.13.0 and 3.14.1 (inclusive).'}]
2020-03-05T18:02Z
2020-02-19T13:15Z
Insufficient Verification of Data Authenticity
The software does not sufficiently verify the origin or authenticity of data, in a way that causes it to accept invalid data.
https://cwe.mitre.org/data/definitions/345.html
0
Max Wang
2016-07-01 09:09:30-07:00
Type safety in simplexml import routines Reviewed By: Orvid Differential Revision: D3447275 fbshipit-source-id: d859c97f9d85c520b0e371cef6dcb19bb2ef7dbf
8e7266fef1f329b805b37f32c9ad0090215ab269
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::SimpleXMLElement_exportNode
HPHP::SimpleXMLElement_exportNode( const Object & sxe)
['sxe']
xmlNodePtr SimpleXMLElement_exportNode(const Object& sxe) { assert(sxe->instanceof(SimpleXMLElement_classof())); auto data = Native::data<SimpleXMLElement>(sxe.get()); return php_sxe_get_first_node(data, data->nodep()); }
50
True
1
CVE-2016-6870
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
True
[{'url': 'https://github.com/facebook/hhvm/commit/365abe807cab2d60dc9ec307292a06181f77a9c2', 'name': 'https://github.com/facebook/hhvm/commit/365abe807cab2d60dc9ec307292a06181f77a9c2', 'refsource': 'CONFIRM', 'tags': ['Patch', 'Vendor Advisory']}, {'url': 'http://www.openwall.com/lists/oss-security/2016/08/19/1', 'name': '[oss-security] 20160818 Re: CVE Requests Facebook HHVM', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Patch', 'Third Party Advisory']}, {'url': 'http://www.openwall.com/lists/oss-security/2016/08/11/1', 'name': '[oss-security] 20160811 CVE Requests Facebook HHVM', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Patch', 'Third Party Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndIncluding': '3.14.5', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Out-of-bounds write in the (1) mb_detect_encoding, (2) mb_send_mail, and (3) mb_detect_order functions in Facebook HHVM before 3.15.0 allows attackers to have unspecified impact via unknown vectors.'}]
2017-02-22T17:53Z
2017-02-17T17:59Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
Bill Nell
2016-07-01 09:55:16-07:00
Use req::strndup in php_mb_parse_encoding_list to prevent oob memory write. Summary: Fix out of bounds write access in mb_detect_encoding. Using strndup in php_mb_parse_encoding_list will cause strings with embedded nulls to be unexpectedly shortened. The expected length of the string is tracked in value_length but since strndup may copy fewer characters when there are mbedded null this can lead to oob writes into tmpstr. I've found a couple other places in this file that use strndup and replaced them with req::strndup as well. The use of strndup in mb_send_mail also seemed to be a leak. This replaces uses of strndup with req::strndup which can handle embedded nulls properly. It looks like I also accidentally fixed t11337047 at the same time. Adding it to the list of tasks. Reviewed By: paulbiss Differential Revision: D3360065 fbshipit-source-id: 99776cf9105e3789883380bf30240009eec52cec
365abe807cab2d60dc9ec307292a06181f77a9c2
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::HHVM_FUNCTION
HPHP::HHVM_FUNCTION( mb_parse_str , const String & encoded_string , VRefParam result)
['mb_parse_str', 'encoded_string', 'result']
bool HHVM_FUNCTION(mb_parse_str, const String& encoded_string, VRefParam result /* = null */) { php_mb_encoding_handler_info_t info; info.data_type = PARSE_STRING; info.separator = ";&"; info.force_register_globals = false; info.report_errors = 1; info.to_encoding = MBSTRG(current_internal_encoding); info.to_language = MBSTRG(current_language); info.from_encodings = MBSTRG(http_input_list); info.num_from_encodings = MBSTRG(http_input_list_size); info.from_language = MBSTRG(current_language); char *encstr = strndup(encoded_string.data(), encoded_string.size()); Array resultArr = Array::Create(); mbfl_encoding *detected = _php_mb_encoding_handler_ex(&info, resultArr, encstr); free(encstr); result.assignIfRef(resultArr); MBSTRG(http_input_identify) = detected; return detected != nullptr; }
152
True
1
CVE-2016-6870
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
True
[{'url': 'https://github.com/facebook/hhvm/commit/365abe807cab2d60dc9ec307292a06181f77a9c2', 'name': 'https://github.com/facebook/hhvm/commit/365abe807cab2d60dc9ec307292a06181f77a9c2', 'refsource': 'CONFIRM', 'tags': ['Patch', 'Vendor Advisory']}, {'url': 'http://www.openwall.com/lists/oss-security/2016/08/19/1', 'name': '[oss-security] 20160818 Re: CVE Requests Facebook HHVM', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Patch', 'Third Party Advisory']}, {'url': 'http://www.openwall.com/lists/oss-security/2016/08/11/1', 'name': '[oss-security] 20160811 CVE Requests Facebook HHVM', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Patch', 'Third Party Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndIncluding': '3.14.5', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Out-of-bounds write in the (1) mb_detect_encoding, (2) mb_send_mail, and (3) mb_detect_order functions in Facebook HHVM before 3.15.0 allows attackers to have unspecified impact via unknown vectors.'}]
2017-02-22T17:53Z
2017-02-17T17:59Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
Bill Nell
2016-07-01 09:55:16-07:00
Use req::strndup in php_mb_parse_encoding_list to prevent oob memory write. Summary: Fix out of bounds write access in mb_detect_encoding. Using strndup in php_mb_parse_encoding_list will cause strings with embedded nulls to be unexpectedly shortened. The expected length of the string is tracked in value_length but since strndup may copy fewer characters when there are mbedded null this can lead to oob writes into tmpstr. I've found a couple other places in this file that use strndup and replaced them with req::strndup as well. The use of strndup in mb_send_mail also seemed to be a leak. This replaces uses of strndup with req::strndup which can handle embedded nulls properly. It looks like I also accidentally fixed t11337047 at the same time. Adding it to the list of tasks. Reviewed By: paulbiss Differential Revision: D3360065 fbshipit-source-id: 99776cf9105e3789883380bf30240009eec52cec
365abe807cab2d60dc9ec307292a06181f77a9c2
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::HHVM_FUNCTION
HPHP::HHVM_FUNCTION( mb_send_mail , const String & to , const String & subject , const String & message , const Variant & opt_headers , const Variant & opt_extra_cmd)
['mb_send_mail', 'to', 'subject', 'message', 'opt_headers', 'opt_extra_cmd']
bool HHVM_FUNCTION(mb_send_mail, const String& to, const String& subject, const String& message, const Variant& opt_headers, const Variant& opt_extra_cmd) { const String headers = convertArg(opt_headers); const String extra_cmd = convertArg(opt_extra_cmd); /* initialize */ /* automatic allocateable buffer for additional header */ mbfl_memory_device device; mbfl_memory_device_init(&device, 0, 0); mbfl_string orig_str, conv_str; mbfl_string_init(&orig_str); mbfl_string_init(&conv_str); /* character-set, transfer-encoding */ mbfl_no_encoding tran_cs, /* transfar text charset */ head_enc, /* header transfar encoding */ body_enc; /* body transfar encoding */ tran_cs = mbfl_no_encoding_utf8; head_enc = mbfl_no_encoding_base64; body_enc = mbfl_no_encoding_base64; const mbfl_language *lang = mbfl_no2language(MBSTRG(current_language)); if (lang != nullptr) { tran_cs = lang->mail_charset; head_enc = lang->mail_header_encoding; body_enc = lang->mail_body_encoding; } Array ht_headers; if (!headers.empty()) { _php_mbstr_parse_mail_headers(ht_headers, headers.data(), headers.size()); } struct { unsigned int cnt_type:1; unsigned int cnt_trans_enc:1; } suppressed_hdrs = { 0, 0 }; static const StaticString s_CONTENT_TYPE("CONTENT-TYPE"); String s = ht_headers[s_CONTENT_TYPE].toString(); if (!s.isNull()) { char *tmp; char *param_name; char *charset = nullptr; char *p = const_cast<char*>(strchr(s.data(), ';')); if (p != nullptr) { /* skipping the padded spaces */ do { ++p; } while (*p == ' ' || *p == '\t'); if (*p != '\0') { if ((param_name = strtok_r(p, "= ", &tmp)) != nullptr) { if (strcasecmp(param_name, "charset") == 0) { mbfl_no_encoding _tran_cs = tran_cs; charset = strtok_r(nullptr, "= ", &tmp); if (charset != nullptr) { _tran_cs = mbfl_name2no_encoding(charset); } if (_tran_cs == mbfl_no_encoding_invalid) { raise_warning("Unsupported charset \"%s\" - " "will be regarded as ascii", charset); _tran_cs = mbfl_no_encoding_ascii; } tran_cs = _tran_cs; } } } } suppressed_hdrs.cnt_type = 1; } static const StaticString s_CONTENT_TRANSFER_ENCODING("CONTENT-TRANSFER-ENCODING"); s = ht_headers[s_CONTENT_TRANSFER_ENCODING].toString(); if (!s.isNull()) { mbfl_no_encoding _body_enc = mbfl_name2no_encoding(s.data()); switch (_body_enc) { case mbfl_no_encoding_base64: case mbfl_no_encoding_7bit: case mbfl_no_encoding_8bit: body_enc = _body_enc; break; default: raise_warning("Unsupported transfer encoding \"%s\" - " "will be regarded as 8bit", s.data()); body_enc = mbfl_no_encoding_8bit; break; } suppressed_hdrs.cnt_trans_enc = 1; } /* To: */ char *to_r = nullptr; int err = 0; if (!to.empty()) { int to_len = to.size(); if (to_len > 0) { to_r = strndup(to.data(), to_len); for (; to_len; to_len--) { if (!isspace((unsigned char)to_r[to_len - 1])) { break; } to_r[to_len - 1] = '\0'; } for (int i = 0; to_r[i]; i++) { if (iscntrl((unsigned char)to_r[i])) { /** * According to RFC 822, section 3.1.1 long headers may be * separated into parts using CRLF followed at least one * linear-white-space character ('\t' or ' '). * To prevent these separators from being replaced with a space, * we use the SKIP_LONG_HEADER_SEP_MBSTRING to skip over them. */ SKIP_LONG_HEADER_SEP_MBSTRING(to_r, i); to_r[i] = ' '; } } } else { to_r = (char*)to.data(); } } else { raise_warning("Missing To: field"); err = 1; } /* Subject: */ String encoded_subject; if (!subject.isNull()) { orig_str.no_language = MBSTRG(current_language); orig_str.val = (unsigned char *)subject.data(); orig_str.len = subject.size(); orig_str.no_encoding = MBSTRG(current_internal_encoding)->no_encoding; if (orig_str.no_encoding == mbfl_no_encoding_invalid || orig_str.no_encoding == mbfl_no_encoding_pass) { mbfl_encoding *encoding = (mbfl_encoding*) mbfl_identify_encoding2(&orig_str, (const mbfl_encoding**) MBSTRG(current_detect_order_list), MBSTRG(current_detect_order_list_size), MBSTRG(strict_detection)); orig_str.no_encoding = encoding != nullptr ? encoding->no_encoding : mbfl_no_encoding_invalid; } mbfl_string *pstr = mbfl_mime_header_encode (&orig_str, &conv_str, tran_cs, head_enc, "\n", sizeof("Subject: [PHP-jp nnnnnnnn]")); if (pstr != nullptr) { encoded_subject = String(reinterpret_cast<char*>(pstr->val), pstr->len, AttachString); } } else { raise_warning("Missing Subject: field"); err = 1; } /* message body */ String encoded_message; if (!message.empty()) { orig_str.no_language = MBSTRG(current_language); orig_str.val = (unsigned char*)message.data(); orig_str.len = message.size(); orig_str.no_encoding = MBSTRG(current_internal_encoding)->no_encoding; if (orig_str.no_encoding == mbfl_no_encoding_invalid || orig_str.no_encoding == mbfl_no_encoding_pass) { mbfl_encoding *encoding = (mbfl_encoding*) mbfl_identify_encoding2(&orig_str, (const mbfl_encoding**) MBSTRG(current_detect_order_list), MBSTRG(current_detect_order_list_size), MBSTRG(strict_detection)); orig_str.no_encoding = encoding != nullptr ? encoding->no_encoding : mbfl_no_encoding_invalid; } mbfl_string *pstr = nullptr; { mbfl_string tmpstr; if (mbfl_convert_encoding(&orig_str, &tmpstr, tran_cs) != nullptr) { tmpstr.no_encoding = mbfl_no_encoding_8bit; pstr = mbfl_convert_encoding(&tmpstr, &conv_str, body_enc); free(tmpstr.val); } } if (pstr != nullptr) { encoded_message = String(reinterpret_cast<char*>(pstr->val), pstr->len, AttachString); } } else { /* this is not really an error, so it is allowed. */ raise_warning("Empty message body"); } /* other headers */ #define PHP_MBSTR_MAIL_MIME_HEADER1 "Mime-Version: 1.0" #define PHP_MBSTR_MAIL_MIME_HEADER2 "Content-Type: text/plain" #define PHP_MBSTR_MAIL_MIME_HEADER3 "; charset=" #define PHP_MBSTR_MAIL_MIME_HEADER4 "Content-Transfer-Encoding: " if (!headers.empty()) { const char *p = headers.data(); int n = headers.size(); mbfl_memory_device_strncat(&device, p, n); if (n > 0 && p[n - 1] != '\n') { mbfl_memory_device_strncat(&device, "\n", 1); } } mbfl_memory_device_strncat(&device, PHP_MBSTR_MAIL_MIME_HEADER1, sizeof(PHP_MBSTR_MAIL_MIME_HEADER1) - 1); mbfl_memory_device_strncat(&device, "\n", 1); if (!suppressed_hdrs.cnt_type) { mbfl_memory_device_strncat(&device, PHP_MBSTR_MAIL_MIME_HEADER2, sizeof(PHP_MBSTR_MAIL_MIME_HEADER2) - 1); char *p = (char *)mbfl_no2preferred_mime_name(tran_cs); if (p != nullptr) { mbfl_memory_device_strncat(&device, PHP_MBSTR_MAIL_MIME_HEADER3, sizeof(PHP_MBSTR_MAIL_MIME_HEADER3) - 1); mbfl_memory_device_strcat(&device, p); } mbfl_memory_device_strncat(&device, "\n", 1); } if (!suppressed_hdrs.cnt_trans_enc) { mbfl_memory_device_strncat(&device, PHP_MBSTR_MAIL_MIME_HEADER4, sizeof(PHP_MBSTR_MAIL_MIME_HEADER4) - 1); const char *p = (char *)mbfl_no2preferred_mime_name(body_enc); if (p == nullptr) { p = "7bit"; } mbfl_memory_device_strcat(&device, p); mbfl_memory_device_strncat(&device, "\n", 1); } mbfl_memory_device_unput(&device); mbfl_memory_device_output('\0', &device); char *all_headers = (char *)device.buffer; String cmd = string_escape_shell_cmd(extra_cmd.c_str()); bool ret = (!err && php_mail(to_r, encoded_subject.data(), encoded_message.data(), all_headers, cmd.data())); mbfl_memory_device_clear(&device); return ret; }
1367
True
1
CVE-2016-6870
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
True
[{'url': 'https://github.com/facebook/hhvm/commit/365abe807cab2d60dc9ec307292a06181f77a9c2', 'name': 'https://github.com/facebook/hhvm/commit/365abe807cab2d60dc9ec307292a06181f77a9c2', 'refsource': 'CONFIRM', 'tags': ['Patch', 'Vendor Advisory']}, {'url': 'http://www.openwall.com/lists/oss-security/2016/08/19/1', 'name': '[oss-security] 20160818 Re: CVE Requests Facebook HHVM', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Patch', 'Third Party Advisory']}, {'url': 'http://www.openwall.com/lists/oss-security/2016/08/11/1', 'name': '[oss-security] 20160811 CVE Requests Facebook HHVM', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Patch', 'Third Party Advisory']}]
[{'description': [{'lang': 'en', 'value': 'CWE-787'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndIncluding': '3.14.5', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Out-of-bounds write in the (1) mb_detect_encoding, (2) mb_send_mail, and (3) mb_detect_order functions in Facebook HHVM before 3.15.0 allows attackers to have unspecified impact via unknown vectors.'}]
2017-02-22T17:53Z
2017-02-17T17:59Z
Out-of-bounds Write
The software writes data past the end, or before the beginning, of the intended buffer.
Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
https://cwe.mitre.org/data/definitions/787.html
0
Bill Nell
2016-07-01 09:55:16-07:00
Use req::strndup in php_mb_parse_encoding_list to prevent oob memory write. Summary: Fix out of bounds write access in mb_detect_encoding. Using strndup in php_mb_parse_encoding_list will cause strings with embedded nulls to be unexpectedly shortened. The expected length of the string is tracked in value_length but since strndup may copy fewer characters when there are mbedded null this can lead to oob writes into tmpstr. I've found a couple other places in this file that use strndup and replaced them with req::strndup as well. The use of strndup in mb_send_mail also seemed to be a leak. This replaces uses of strndup with req::strndup which can handle embedded nulls properly. It looks like I also accidentally fixed t11337047 at the same time. Adding it to the list of tasks. Reviewed By: paulbiss Differential Revision: D3360065 fbshipit-source-id: 99776cf9105e3789883380bf30240009eec52cec
365abe807cab2d60dc9ec307292a06181f77a9c2
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::php_mb_parse_encoding_list
HPHP::php_mb_parse_encoding_list( const char * value , int value_length , mbfl_encoding ** * return_list , int * return_size , int persistent)
['value', 'value_length', 'return_list', 'return_size', 'persistent']
static int php_mb_parse_encoding_list(const char *value, int value_length, mbfl_encoding ***return_list, int *return_size, int persistent) { int n, l, size, bauto, ret = 1; char *p, *p1, *p2, *endp, *tmpstr; mbfl_encoding *encoding; mbfl_no_encoding *src; mbfl_encoding **entry, **list; list = nullptr; if (value == nullptr || value_length <= 0) { if (return_list) { *return_list = nullptr; } if (return_size) { *return_size = 0; } return 0; } else { mbfl_no_encoding *identify_list; int identify_list_size; identify_list = MBSTRG(default_detect_order_list); identify_list_size = MBSTRG(default_detect_order_list_size); /* copy the value string for work */ if (value[0]=='"' && value[value_length-1]=='"' && value_length>2) { tmpstr = (char *)strndup(value+1, value_length-2); value_length -= 2; } else tmpstr = (char *)strndup(value, value_length); if (tmpstr == nullptr) { return 0; } /* count the number of listed encoding names */ endp = tmpstr + value_length; n = 1; p1 = tmpstr; while ((p2 = (char*)string_memnstr(p1, ",", 1, endp)) != nullptr) { p1 = p2 + 1; n++; } size = n + identify_list_size; /* make list */ list = (mbfl_encoding **)calloc(size, sizeof(mbfl_encoding*)); if (list != nullptr) { entry = list; n = 0; bauto = 0; p1 = tmpstr; do { p2 = p = (char*)string_memnstr(p1, ",", 1, endp); if (p == nullptr) { p = endp; } *p = '\0'; /* trim spaces */ while (p1 < p && (*p1 == ' ' || *p1 == '\t')) { p1++; } p--; while (p > p1 && (*p == ' ' || *p == '\t')) { *p = '\0'; p--; } /* convert to the encoding number and check encoding */ if (strcasecmp(p1, "auto") == 0) { if (!bauto) { bauto = 1; l = identify_list_size; src = identify_list; for (int i = 0; i < l; i++) { *entry++ = (mbfl_encoding*) mbfl_no2encoding(*src++); n++; } } } else { encoding = (mbfl_encoding*) mbfl_name2encoding(p1); if (encoding != nullptr) { *entry++ = encoding; n++; } else { ret = 0; } } p1 = p2 + 1; } while (n < size && p2 != nullptr); if (n > 0) { if (return_list) { *return_list = list; } else { free(list); } } else { free(list); if (return_list) { *return_list = nullptr; } ret = 0; } if (return_size) { *return_size = n; } } else { if (return_list) { *return_list = nullptr; } if (return_size) { *return_size = 0; } ret = 0; } free(tmpstr); } return ret; }
610
True
1
CVE-2016-6875
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
True
[{'url': 'https://github.com/facebook/hhvm/commit/1888810e77b446a79a7674784d5f139fcfa605e2', 'name': 'https://github.com/facebook/hhvm/commit/1888810e77b446a79a7674784d5f139fcfa605e2', 'refsource': 'CONFIRM', 'tags': ['Patch']}, {'url': 'http://www.openwall.com/lists/oss-security/2016/08/19/1', 'name': '[oss-security] 20160818 Re: CVE Requests Facebook HHVM', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Patch', 'Third Party Advisory']}, {'url': 'http://www.openwall.com/lists/oss-security/2016/08/11/1', 'name': '[oss-security] 20160811 CVE Requests Facebook HHVM', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Patch', 'Third Party Advisory']}]
[{'description': [{'lang': 'en', 'value': 'NVD-CWE-Other'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndIncluding': '3.14.5', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Infinite recursion in wddx in Facebook HHVM before 3.15.0 allows attackers to have unspecified impact via unknown vectors.'}]
2017-02-22T18:25Z
2017-02-17T17:59Z
Other
NVD is only using a subset of CWE for mapping instead of the entire CWE, and the weakness type is not covered by that subset.
Insufficient Information
https://nvd.nist.gov/vuln/categories
0
Christopher Dykes
2016-08-01 14:21:50-07:00
Fix infinite recursion in wddx Summary: It wasn't checking for infinite recursion due to references or self-referential objects. As it turns out closures always return themselves when converted to an array. Raising a warning and returning is how PHP-src deals with this problem, nothing special is done for closures. Reviewed By: alexmalyshev Differential Revision: D3465655 fbshipit-source-id: a42bc34d30cf4825faf33596139c0c05f8e4f5f1
1888810e77b446a79a7674784d5f139fcfa605e2
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::WddxPacket::recursiveAddVar
HPHP::WddxPacket::recursiveAddVar( const String & varName , const Variant & varVariant , bool hasVarTag)
['varName', 'varVariant', 'hasVarTag']
bool WddxPacket::recursiveAddVar(const String& varName, const Variant& varVariant, bool hasVarTag) { bool isArray = varVariant.isArray(); bool isObject = varVariant.isObject(); if (isArray || isObject) { if (hasVarTag) { m_packetString.append("<var name='"); m_packetString.append(varName.data()); m_packetString.append("'>"); } Array varAsArray; Object varAsObject = varVariant.toObject(); if (isArray) varAsArray = varVariant.toArray(); if (isObject) varAsArray = varAsObject.toArray(); int length = varAsArray.length(); if (length > 0) { ArrayIter it = ArrayIter(varAsArray); if (it.first().isString()) isObject = true; if (isObject) { m_packetString.append("<struct>"); if (!isArray) { m_packetString.append("<var name='php_class_name'><string>"); m_packetString.append(varAsObject->getClassName()); m_packetString.append("</string></var>"); } } else { m_packetString.append("<array length='"); m_packetString.append(std::to_string(length)); m_packetString.append("'>"); } for (ArrayIter it(varAsArray); it; ++it) { Variant key = it.first(); Variant value = it.second(); recursiveAddVar(key.toString(), value, isObject); } if (isObject) { m_packetString.append("</struct>"); } else { m_packetString.append("</array>"); } } else { //empty object if (isObject) { m_packetString.append("<struct>"); if (!isArray) { m_packetString.append("<var name='php_class_name'><string>"); m_packetString.append(varAsObject->getClassName()); m_packetString.append("</string></var>"); } m_packetString.append("</struct>"); } } if (hasVarTag) { m_packetString.append("</var>"); } return true; } String varType = getDataTypeString(varVariant.getType()); if (!getWddxEncoded(varType, "", varName, false).empty()) { String varValue; if (varType.compare("boolean") == 0) { varValue = varVariant.toBoolean() ? "true" : "false"; } else { varValue = StringUtil::HtmlEncode(varVariant.toString(), StringUtil::QuoteStyle::Double, "UTF-8", false, false).toCppString(); } m_packetString.append( getWddxEncoded(varType, varValue, varName, hasVarTag)); return true; } return false; }
481
True
1
CVE-2016-6874
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
True
[{'url': 'https://github.com/facebook/hhvm/commit/05e706d98f748f609b19d8697e490eaab5007d69', 'name': 'https://github.com/facebook/hhvm/commit/05e706d98f748f609b19d8697e490eaab5007d69', 'refsource': 'CONFIRM', 'tags': []}, {'url': 'http://www.openwall.com/lists/oss-security/2016/08/19/1', 'name': '[oss-security] 20160818 Re: CVE Requests Facebook HHVM', 'refsource': 'MLIST', 'tags': []}, {'url': 'http://www.openwall.com/lists/oss-security/2016/08/11/1', 'name': '[oss-security] 20160811 CVE Requests Facebook HHVM', 'refsource': 'MLIST', 'tags': []}]
[{'description': [{'lang': 'en', 'value': 'NVD-CWE-Other'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndIncluding': '3.14.5', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'The array_*_recursive functions in Facebook HHVM before 3.15.0 allows attackers to have unspecified impact via unknown vectors, related to recursion.'}]
2017-02-22T18:25Z
2017-02-17T17:59Z
Other
NVD is only using a subset of CWE for mapping instead of the entire CWE, and the weakness type is not covered by that subset.
Insufficient Information
https://nvd.nist.gov/vuln/categories
0
2016-08-01 15:13:00-07:00
Fix recursion checks in array_*_recursive Summary: array_merge_recursive and array_replace_recursive do recursion checks, but use the fact that normal arrays can't contain cycles except through references to avoid most of the checking. Unfortunately the $GLOBALS array is special, and /can/ contain cycles without references, and ProxyArrays could potentially do the same (via an as-yet unimplemented extension). Reviewed By: mxw Differential Revision: D3622612 fbshipit-source-id: ed90b747096a05919a80c4793e2a2b7c57584d56
05e706d98f748f609b19d8697e490eaab5007d69
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::php_array_merge_recursive
HPHP::php_array_merge_recursive( PointerSet & seen , bool check , Array & arr1 , const Array & arr2)
['seen', 'check', 'arr1', 'arr2']
static void php_array_merge_recursive(PointerSet &seen, bool check, Array &arr1, const Array& arr2) { if (check) { if (seen.find((void*)arr1.get()) != seen.end()) { raise_warning("array_merge_recursive(): recursion detected"); return; } seen.insert((void*)arr1.get()); } for (ArrayIter iter(arr2); iter; ++iter) { Variant key(iter.first()); const Variant& value(iter.secondRef()); if (key.isNumeric()) { arr1.appendWithRef(value); } else if (arr1.exists(key, true)) { // There is no need to do toKey() conversion, for a key that is already // in the array. Variant &v = arr1.lvalAt(key, AccessFlags::Key); auto subarr1 = v.toArray().copy(); php_array_merge_recursive(seen, v.isReferenced(), subarr1, value.toArray()); v.unset(); // avoid contamination of the value that was strongly bound v = subarr1; } else { arr1.setWithRef(key, value, true); } } if (check) { seen.erase((void*)arr1.get()); } }
233
True
1
CVE-2016-6874
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
True
[{'url': 'https://github.com/facebook/hhvm/commit/05e706d98f748f609b19d8697e490eaab5007d69', 'name': 'https://github.com/facebook/hhvm/commit/05e706d98f748f609b19d8697e490eaab5007d69', 'refsource': 'CONFIRM', 'tags': []}, {'url': 'http://www.openwall.com/lists/oss-security/2016/08/19/1', 'name': '[oss-security] 20160818 Re: CVE Requests Facebook HHVM', 'refsource': 'MLIST', 'tags': []}, {'url': 'http://www.openwall.com/lists/oss-security/2016/08/11/1', 'name': '[oss-security] 20160811 CVE Requests Facebook HHVM', 'refsource': 'MLIST', 'tags': []}]
[{'description': [{'lang': 'en', 'value': 'NVD-CWE-Other'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndIncluding': '3.14.5', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'The array_*_recursive functions in Facebook HHVM before 3.15.0 allows attackers to have unspecified impact via unknown vectors, related to recursion.'}]
2017-02-22T18:25Z
2017-02-17T17:59Z
Other
NVD is only using a subset of CWE for mapping instead of the entire CWE, and the weakness type is not covered by that subset.
Insufficient Information
https://nvd.nist.gov/vuln/categories
0
2016-08-01 15:13:00-07:00
Fix recursion checks in array_*_recursive Summary: array_merge_recursive and array_replace_recursive do recursion checks, but use the fact that normal arrays can't contain cycles except through references to avoid most of the checking. Unfortunately the $GLOBALS array is special, and /can/ contain cycles without references, and ProxyArrays could potentially do the same (via an as-yet unimplemented extension). Reviewed By: mxw Differential Revision: D3622612 fbshipit-source-id: ed90b747096a05919a80c4793e2a2b7c57584d56
05e706d98f748f609b19d8697e490eaab5007d69
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::php_array_replace_recursive
HPHP::php_array_replace_recursive( PointerSet & seen , bool check , Array & arr1 , const Array & arr2)
['seen', 'check', 'arr1', 'arr2']
static void php_array_replace_recursive(PointerSet &seen, bool check, Array &arr1, const Array& arr2) { if (check) { if (seen.find((void*)arr1.get()) != seen.end()) { raise_warning("array_replace_recursive(): recursion detected"); return; } seen.insert((void*)arr1.get()); } for (ArrayIter iter(arr2); iter; ++iter) { Variant key = iter.first(); const Variant& value = iter.secondRef(); if (arr1.exists(key, true) && value.isArray()) { Variant &v = arr1.lvalAt(key, AccessFlags::Key); if (v.isArray()) { Array subarr1 = v.toArray(); const ArrNR& arr_value = value.toArrNR(); php_array_replace_recursive(seen, v.isReferenced(), subarr1, arr_value); v = subarr1; } else { arr1.set(key, value, true); } } else { arr1.setWithRef(key, value, true); } } if (check) { seen.erase((void*)arr1.get()); } }
240
True
1
CVE-2016-6873
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
True
[{'url': 'https://github.com/facebook/hhvm/commit/e264f04ae825a5d97758130cf8eec99862517e7e', 'name': 'https://github.com/facebook/hhvm/commit/e264f04ae825a5d97758130cf8eec99862517e7e', 'refsource': 'CONFIRM', 'tags': ['Patch']}, {'url': 'http://www.openwall.com/lists/oss-security/2016/08/19/1', 'name': '[oss-security] 20160818 Re: CVE Requests Facebook HHVM', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'http://www.openwall.com/lists/oss-security/2016/08/11/1', 'name': '[oss-security] 20160811 CVE Requests Facebook HHVM', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}]
[{'description': [{'lang': 'en', 'value': 'NVD-CWE-Other'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndIncluding': '3.14.5', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Self recursion in compact in Facebook HHVM before 3.15.0 allows attackers to have unspecified impact via unknown vectors.'}]
2017-02-22T17:41Z
2017-02-17T17:59Z
Other
NVD is only using a subset of CWE for mapping instead of the entire CWE, and the weakness type is not covered by that subset.
Insufficient Information
https://nvd.nist.gov/vuln/categories
0
2016-08-01 15:13:07-07:00
Fix self recursion in compact Summary: There were no checks at all. Reviewed By: alexmalyshev Differential Revision: D3623763 fbshipit-source-id: 9d708deca05bbd121503e8f323b4f295fde8e835
e264f04ae825a5d97758130cf8eec99862517e7e
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::HHVM_FUNCTION
HPHP::HHVM_FUNCTION( __SystemLib_compact_sl , const Variant & varname , const Array & args)
['__SystemLib_compact_sl', 'varname', 'args']
Array HHVM_FUNCTION(__SystemLib_compact_sl, const Variant& varname, const Array& args /* = null array */) { Array ret = Array::attach(PackedArray::MakeReserve(args.size() + 1)); VarEnv* v = g_context->getOrCreateVarEnv(); if (v) { compact(v, ret, varname); compact(v, ret, args); } return ret; }
74
True
1
CVE-2016-6873
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
True
[{'url': 'https://github.com/facebook/hhvm/commit/e264f04ae825a5d97758130cf8eec99862517e7e', 'name': 'https://github.com/facebook/hhvm/commit/e264f04ae825a5d97758130cf8eec99862517e7e', 'refsource': 'CONFIRM', 'tags': ['Patch']}, {'url': 'http://www.openwall.com/lists/oss-security/2016/08/19/1', 'name': '[oss-security] 20160818 Re: CVE Requests Facebook HHVM', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'http://www.openwall.com/lists/oss-security/2016/08/11/1', 'name': '[oss-security] 20160811 CVE Requests Facebook HHVM', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}]
[{'description': [{'lang': 'en', 'value': 'NVD-CWE-Other'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndIncluding': '3.14.5', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Self recursion in compact in Facebook HHVM before 3.15.0 allows attackers to have unspecified impact via unknown vectors.'}]
2017-02-22T17:41Z
2017-02-17T17:59Z
Other
NVD is only using a subset of CWE for mapping instead of the entire CWE, and the weakness type is not covered by that subset.
Insufficient Information
https://nvd.nist.gov/vuln/categories
0
2016-08-01 15:13:07-07:00
Fix self recursion in compact Summary: There were no checks at all. Reviewed By: alexmalyshev Differential Revision: D3623763 fbshipit-source-id: 9d708deca05bbd121503e8f323b4f295fde8e835
e264f04ae825a5d97758130cf8eec99862517e7e
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::HHVM_FUNCTION
HPHP::HHVM_FUNCTION( compact , const Variant & varname , const Array & args)
['compact', 'varname', 'args']
Array HHVM_FUNCTION(compact, const Variant& varname, const Array& args /* = null array */) { raise_disallowed_dynamic_call("compact should not be called dynamically"); Array ret = Array::attach(PackedArray::MakeReserve(args.size() + 1)); VarEnv* v = g_context->getOrCreateVarEnv(); if (v) { compact(v, ret, varname); compact(v, ret, args); } return ret; }
79
True
1
CVE-2016-6873
False
False
False
False
AV:N/AC:L/Au:N/C:P/I:P/A:P
NETWORK
LOW
NONE
PARTIAL
PARTIAL
PARTIAL
7.5
CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NETWORK
LOW
NONE
NONE
UNCHANGED
HIGH
HIGH
HIGH
9.8
CRITICAL
3.9
5.9
True
[{'url': 'https://github.com/facebook/hhvm/commit/e264f04ae825a5d97758130cf8eec99862517e7e', 'name': 'https://github.com/facebook/hhvm/commit/e264f04ae825a5d97758130cf8eec99862517e7e', 'refsource': 'CONFIRM', 'tags': ['Patch']}, {'url': 'http://www.openwall.com/lists/oss-security/2016/08/19/1', 'name': '[oss-security] 20160818 Re: CVE Requests Facebook HHVM', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'http://www.openwall.com/lists/oss-security/2016/08/11/1', 'name': '[oss-security] 20160811 CVE Requests Facebook HHVM', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}]
[{'description': [{'lang': 'en', 'value': 'NVD-CWE-Other'}]}]
HIGH
[{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:facebook:hhvm:*:*:*:*:*:*:*:*', 'versionEndIncluding': '3.14.5', 'cpe_name': []}]}]
[{'lang': 'en', 'value': 'Self recursion in compact in Facebook HHVM before 3.15.0 allows attackers to have unspecified impact via unknown vectors.'}]
2017-02-22T17:41Z
2017-02-17T17:59Z
Other
NVD is only using a subset of CWE for mapping instead of the entire CWE, and the weakness type is not covered by that subset.
Insufficient Information
https://nvd.nist.gov/vuln/categories
0
2016-08-01 15:13:07-07:00
Fix self recursion in compact Summary: There were no checks at all. Reviewed By: alexmalyshev Differential Revision: D3623763 fbshipit-source-id: 9d708deca05bbd121503e8f323b4f295fde8e835
e264f04ae825a5d97758130cf8eec99862517e7e
False
facebook/hhvm
A virtual machine for executing programs written in Hack.
2010-01-02 01:17:06
2022-08-27 15:17:15
https://hhvm.com
facebook
17395.0
3000.0
HPHP::compact
HPHP::compact( VarEnv * v , Array & ret , const Variant & var)
['v', 'ret', 'var']
static void compact(VarEnv* v, Array &ret, const Variant& var) { if (var.isArray()) { for (ArrayIter iter(var.getArrayData()); iter; ++iter) { compact(v, ret, iter.second()); } } else { String varname = var.toString(); if (!varname.empty() && v->lookup(varname.get()) != NULL) { ret.set(varname, *reinterpret_cast<Variant*>(v->lookup(varname.get()))); } } }
121
True
1