• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <cstddef>
17 #include <cstdint>
18 #include <iostream>
19 #include <memory>
20 #include "audio_adapter.h"
21 #include "audio_system_manager.h"
22 #include "avsession_log.h"
23 #include "avsession_errors.h"
24 #include "audioadapterinterface_fuzzer.h"
25 
26 using namespace std;
27 using namespace OHOS;
28 using namespace OHOS::AVSession;
29 
30 const int32_t MAX_CODE_LEN = 512;
31 const int32_t MIN_SIZE_NUM = 4;
32 
AudioAdapterTest(uint8_t * data,size_t size)33 void OHOS::AVSession::AudioAdapterTest(uint8_t *data, size_t size)
34 {
35     if ((data == nullptr) || (size > MAX_CODE_LEN) || (size < MIN_SIZE_NUM)) {
36         return;
37     }
38     int32_t uid = *(reinterpret_cast<const int32_t *>(data));
39 
40     AudioStandard::RendererState rendererState;
41 
42     AudioAdapter audioAdapter;
43     audioAdapter.PauseAudioStream(uid);
44     audioAdapter.GetRendererState(uid, rendererState);
45 }
46 
47 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)48 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
49 {
50     /* Run your code on data */
51     OHOS::AVSession::AudioAdapterTest(const_cast<uint8_t*>(data), size);
52     return 0;
53 }