xref: /aosp_15_r20/cts/hostsidetests/securitybulletin/securityPatch/CVE-2017-13234/poc.c (revision b7c941bb3fa97aba169d73cee0bed2de8ac964bf)
1 /**
2  * Copyright (C) 2020 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 <stdlib.h>
18 #include <string.h>
19 #include <stdbool.h>
20 #include "../includes/memutils_track.h"
21 #include "eas.h"
22 
23 char enable_selective_overload = ENABLE_NONE;
24 
is_tracking_required(size_t size)25 bool is_tracking_required(size_t size) {
26     return ((size != 1024) && (size != 4096));
27 }
28 
EAS_fread(void * handle,void * buf,int offset,int size)29 int EAS_fread(void *handle, void *buf, int offset, int size) {
30     fseek(handle, offset, SEEK_SET);
31     return fread(buf, 1, size, handle);
32 }
33 
EAS_fsize(void * handle)34 int EAS_fsize(void *handle) {
35     fseek(handle, 0, SEEK_END);
36     return ftell(handle);
37 }
38 
PlayFile(EAS_DATA_HANDLE easData,const char * filename)39 static void PlayFile(EAS_DATA_HANDLE easData, const char* filename) {
40     EAS_HANDLE handle;
41     EAS_FILE file;
42     file.handle = (void*) fopen(filename, "rb");
43     file.readAt = EAS_fread;
44     file.size = EAS_fsize;
45     enable_selective_overload = ENABLE_MALLOC_CHECK;
46     if (EAS_OpenFile(easData, &file, &handle) != EAS_SUCCESS) {
47         enable_selective_overload = ENABLE_NONE;
48         if(file.handle) {
49             fclose(file.handle);
50         }
51         return;
52     }
53     EAS_Prepare(easData, handle);
54     EAS_CloseFile(easData, handle);
55     enable_selective_overload = ENABLE_NONE;
56     if(file.handle) {
57         fclose(file.handle);
58     }
59     return;
60 }
61 
main(int argc,char ** argv)62 int main(int argc, char **argv) {
63     EAS_DATA_HANDLE easData;
64     EAS_RESULT result;
65 
66     if (argc < 2) {
67         return EXIT_FAILURE;
68     }
69 
70     result = EAS_Init(&easData);
71     if (result != EAS_SUCCESS) {
72         return EXIT_FAILURE;
73     }
74     PlayFile(easData, argv[1]);
75     EAS_Shutdown(easData);
76     return EXIT_SUCCESS;
77 }
78