Changeset 82768 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Jan 15, 2020 9:58:56 AM (5 years ago)
- Location:
- trunk/src/VBox/Runtime/common/fuzz
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/fuzz/fuzz.cpp
r80585 r82768 369 369 uint32_t uPadding0; 370 370 #elif HC_ARCH_BITS == 64 371 #else372 371 /** Some padding. */ 373 372 uint64_t uPadding0; 373 #else 374 374 # error "Port me" 375 375 #endif -
trunk/src/VBox/Runtime/common/fuzz/fuzzmastercmd.cpp
r77758 r82768 708 708 709 709 /** 710 * Processes the given seed file and adds it to the input corpus. 711 * 712 * @returns IPRT status code. 713 * @param hFuzzCtx The fuzzing context handle. 714 * @param pszCompression Compression used for the seed. 715 * @param pszSeed The seed as a base64 encoded string. 716 * @param pErrInfo Where to store the error information on failure, optional. 717 */ 718 static int rtFuzzCmdMasterFuzzRunProcessSeedFile(RTFUZZCTX hFuzzCtx, const char *pszCompression, const char *pszFile, PRTERRINFO pErrInfo) 719 { 720 int rc = VINF_SUCCESS; 721 722 /* Decompress if applicable. */ 723 if (!RTStrICmp(pszCompression, "None")) 724 rc = RTFuzzCtxCorpusInputAddFromFile(hFuzzCtx, pszFile); 725 else 726 { 727 RTVFSIOSTREAM hVfsIosSeed; 728 rc = RTVfsIoStrmOpenNormal(pszFile, RTFILE_O_OPEN | RTFILE_O_READ, &hVfsIosSeed); 729 if (RT_SUCCESS(rc)) 730 { 731 RTVFSIOSTREAM hVfsDecomp = NIL_RTVFSIOSTREAM; 732 733 if (!RTStrICmp(pszCompression, "Gzip")) 734 rc = RTZipGzipDecompressIoStream(hVfsIosSeed, RTZIPGZIPDECOMP_F_ALLOW_ZLIB_HDR, &hVfsDecomp); 735 else 736 rc = rtFuzzCmdMasterErrorRc(pErrInfo, VERR_INVALID_STATE, "Request error: Compression \"%s\" is not known", pszCompression); 737 738 if (RT_SUCCESS(rc)) 739 { 740 RTVFSFILE hVfsFile; 741 rc = RTVfsMemFileCreate(hVfsDecomp, 2 * _1M, &hVfsFile); 742 if (RT_SUCCESS(rc)) 743 { 744 rc = RTVfsFileSeek(hVfsFile, 0, RTFILE_SEEK_BEGIN, NULL); 745 if (RT_SUCCESS(rc)) 746 { 747 /* The VFS file contains the buffer for the seed now. */ 748 rc = RTFuzzCtxCorpusInputAddFromVfsFile(hFuzzCtx, hVfsFile); 749 if (RT_FAILURE(rc)) 750 rc = rtFuzzCmdMasterErrorRc(pErrInfo, rc, "Request error: Failed to add input seed"); 751 RTVfsFileRelease(hVfsFile); 752 } 753 else 754 rc = rtFuzzCmdMasterErrorRc(pErrInfo, VERR_INVALID_STATE, "Request error: Failed to seek to the beginning of the seed"); 755 } 756 else 757 rc = rtFuzzCmdMasterErrorRc(pErrInfo, VERR_INVALID_STATE, "Request error: Failed to decompress input seed"); 758 759 RTVfsIoStrmRelease(hVfsDecomp); 760 } 761 762 RTVfsIoStrmRelease(hVfsIosSeed); 763 } 764 else 765 rc = rtFuzzCmdMasterErrorRc(pErrInfo, rc, "Request error: Failed to create I/O stream from seed buffer"); 766 } 767 768 return rc; 769 } 770 771 772 /** 773 * Processes a signle input seed given as a file path for the given fuzzing run. 774 * 775 * @returns IPRT status code. 776 * @param pFuzzRun The fuzzing run. 777 * @param hJsonSeed The seed node of the JSON request. 778 * @param pErrInfo Where to store the error information on failure, optional. 779 */ 780 static int rtFuzzCmdMasterFuzzRunProcessInputSeedFileSingle(PRTFUZZRUN pFuzzRun, RTJSONVAL hJsonSeed, PRTERRINFO pErrInfo) 781 { 782 RTFUZZCTX hFuzzCtx; 783 int rc = RTFuzzObsQueryCtx(pFuzzRun->hFuzzObs, &hFuzzCtx); 784 if (RT_SUCCESS(rc)) 785 { 786 RTJSONVAL hJsonValComp; 787 rc = RTJsonValueQueryByName(hJsonSeed, "Compression", &hJsonValComp); 788 if (RT_SUCCESS(rc)) 789 { 790 const char *pszCompression = RTJsonValueGetString(hJsonValComp); 791 if (RT_LIKELY(pszCompression)) 792 { 793 RTJSONVAL hJsonValFile; 794 rc = RTJsonValueQueryByName(hJsonSeed, "File", &hJsonValFile); 795 if (RT_SUCCESS(rc)) 796 { 797 const char *pszFile = RTJsonValueGetString(hJsonValFile); 798 if (RT_LIKELY(pszFile)) 799 rc = rtFuzzCmdMasterFuzzRunProcessSeedFile(hFuzzCtx, pszCompression, pszFile, pErrInfo); 800 else 801 rc = rtFuzzCmdMasterErrorRc(pErrInfo, VERR_INVALID_STATE, "JSON request malformed: \"File\" value is not a string"); 802 803 RTJsonValueRelease(hJsonValFile); 804 } 805 else 806 rc = rtFuzzCmdMasterErrorRc(pErrInfo, rc, "JSON request malformed: Couldn't find \"File\" value"); 807 } 808 else 809 rc = rtFuzzCmdMasterErrorRc(pErrInfo, VERR_INVALID_STATE, "JSON request malformed: \"Compression\" value is not a string"); 810 811 RTJsonValueRelease(hJsonValComp); 812 } 813 else 814 rc = rtFuzzCmdMasterErrorRc(pErrInfo, rc, "JSON request malformed: Couldn't find \"Compression\" value"); 815 816 RTFuzzCtxRelease(hFuzzCtx); 817 } 818 else 819 rc = rtFuzzCmdMasterErrorRc(pErrInfo, rc, "Failed to query fuzzing context from observer"); 820 821 return rc; 822 } 823 824 825 /** 710 826 * Processes input seed related configs for the given fuzzing run. 711 827 * … … 743 859 744 860 RTJsonValueRelease(hJsonValSeedArray); 861 } 862 else if (rc == VERR_NOT_FOUND) 863 rc = VINF_SUCCESS; 864 865 if (RT_SUCCESS(rc)) 866 { 867 rc = RTJsonValueQueryByName(hJsonRoot, "InputSeedFiles", &hJsonValSeedArray); 868 if (RT_SUCCESS(rc)) 869 { 870 RTJSONIT hIt; 871 rc = RTJsonIteratorBegin(hJsonValSeedArray, &hIt); 872 if (RT_SUCCESS(rc)) 873 { 874 RTJSONVAL hJsonInpSeed; 875 while ( RT_SUCCESS(rc) 876 && RTJsonIteratorQueryValue(hIt, &hJsonInpSeed, NULL) != VERR_JSON_ITERATOR_END) 877 { 878 rc = rtFuzzCmdMasterFuzzRunProcessInputSeedFileSingle(pFuzzRun, hJsonInpSeed, pErrInfo); 879 RTJsonValueRelease(hJsonInpSeed); 880 if (RT_FAILURE(rc)) 881 break; 882 rc = RTJsonIteratorNext(hIt); 883 } 884 885 if (rc == VERR_JSON_ITERATOR_END) 886 rc = VINF_SUCCESS; 887 } 888 else 889 rc = rtFuzzCmdMasterErrorRc(pErrInfo, rc, "JSON request malformed: Failed to create array iterator"); 890 891 RTJsonValueRelease(hJsonValSeedArray); 892 } 893 else if (rc == VERR_NOT_FOUND) 894 rc = VINF_SUCCESS; 745 895 } 746 896
Note:
See TracChangeset
for help on using the changeset viewer.