• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 #include "../includes/common.h"
17 #include "../includes/memutils.h"
18 
19 #include <nfa_dm_int.h>
20 #include <rw_int.h>
21 #include <unistd.h>
22 
23 constexpr size_t kBufferSize = 2;
24 constexpr size_t kLengthVal = 0x30;
25 char enable_selective_overload = ENABLE_NONE;
26 bool testInProgress = false;
27 
28 struct sigaction new_action, old_action;
29 
sigsegv_handler(int signum,siginfo_t * info,void * context)30 void sigsegv_handler(int signum, siginfo_t *info, void *context) {
31     if (testInProgress && info->si_signo == SIGSEGV) {
32         (*old_action.sa_sigaction)(signum, info, context);
33         return;
34     }
35     _exit(EXIT_FAILURE);
36 }
37 
poc_cback(tRW_EVENT,tRW_DATA *)38 void poc_cback(tRW_EVENT, tRW_DATA*) {
39 }
40 
main()41 int main() {
42     sigemptyset(&new_action.sa_mask);
43     new_action.sa_flags = SA_SIGINFO;
44     new_action.sa_sigaction = sigsegv_handler;
45     sigaction(SIGSEGV, &new_action, &old_action);
46 
47     tNFC_ACTIVATE_DEVT p_activate_params = { };
48     p_activate_params.protocol = NFC_PROTOCOL_ISO_DEP;
49     p_activate_params.rf_tech_param.mode = NFC_DISCOVERY_TYPE_POLL_A;
50     RW_SetActivatedTagType(&p_activate_params, &poc_cback);
51     FAIL_CHECK(rw_cb.p_cback == &poc_cback);
52 
53     enable_selective_overload = ENABLE_ALL;
54     uint8_t *buffer = (uint8_t *)malloc(kBufferSize * sizeof(uint8_t));
55     FAIL_CHECK(buffer);
56     buffer[0] = NFC_PMID_ATR_RES_GEN_BYTES;
57     buffer[1] = kLengthVal;
58 
59     testInProgress = true;
60     nfa_dm_check_set_config(kBufferSize, buffer, false);
61     enable_selective_overload = ENABLE_FREE_CHECK | ENABLE_REALLOC_CHECK;
62     testInProgress = false;
63 
64     free(buffer);
65 
66     return EXIT_SUCCESS;
67 }
68