1 /**
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #define _GNU_SOURCE
17 #include <sys/types.h>
18 #include <sys/wait.h>
19 #include <openssl/bio.h>
20 #include <openssl/x509.h>
21 #include <openssl/err.h>
22 
23 unsigned char bad_bio[] = {
24   0x30, 0x84, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff,
25   0xff, 0xff
26 };
27 
28 
29 X509 *cert;
30 
main(void)31 int main(void){
32   unsigned long err = 0;
33   ERR_load_crypto_strings();
34   BIO *in = BIO_new(BIO_s_mem());
35   if(in != NULL){
36     BIO_write(in, bad_bio, sizeof(bad_bio));
37     cert = d2i_X509_bio(in, NULL); // x509 should be present on all Android systems
38     BIO_free(in);
39     if(cert != NULL){
40       X509_free(cert);
41     }
42     if((err = ERR_get_error())
43         == 0x07000041) // malloc error
44       return 113;
45   }
46 }
47