Changeset 72649 in vbox for trunk/src/VBox/Runtime/common/fuzz/fuzzmastercmd.cpp
- Timestamp:
- Jun 22, 2018 7:40:23 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/fuzz/fuzzmastercmd.cpp
r72578 r72649 91 91 /** Flag whether to shutdown. */ 92 92 bool fShutdown; 93 /** Flag whether to send a response along with the ACK. */ 94 bool fAckResponse; 95 /** The response message. */ 96 char aszResponse[_1K]; 93 97 } RTFUZZCMDMASTER; 94 98 /** Pointer to a fuzzing master command state. */ … … 813 817 static int rtFuzzCmdMasterProcessJsonReqQueryStats(PRTFUZZCMDMASTER pThis, RTJSONVAL hJsonRoot, PRTERRINFO pErrInfo) 814 818 { 815 RT_NOREF(pThis, hJsonRoot, pErrInfo); 816 return VERR_NOT_IMPLEMENTED; 819 PRTFUZZRUN pFuzzRun; 820 int rc = rtFuzzCmdMasterQueryFuzzRunFromJson(pThis, hJsonRoot, "Id", pErrInfo, &pFuzzRun); 821 if (RT_SUCCESS(rc)) 822 { 823 RTFUZZOBSSTATS Stats; 824 rc = RTFuzzObsQueryStats(pFuzzRun->hFuzzObs, &Stats); 825 if (RT_SUCCESS(rc)) 826 { 827 const char s_szStats[] = "{ \"FuzzedInputsPerSec\": %u\n" 828 " \"FuzzedInputs\": %u\n" 829 " \"FuzzedInputsHang\": %u\n" 830 " \"FuzzedInputsCrash\": %u\n}"; 831 ssize_t cch = RTStrPrintf2(&pThis->aszResponse[0], sizeof(pThis->aszResponse), s_szStats, Stats.cFuzzedInputsPerSec, 832 Stats.cFuzzedInputs, Stats.cFuzzedInputsHang, Stats.cFuzzedInputsCrash); 833 if (cch > 0) 834 pThis->fAckResponse = true; 835 else 836 rc = rtFuzzCmdMasterErrorRc(pErrInfo, VERR_BUFFER_OVERFLOW, "Request error: Response data buffer overflow", rc); 837 } 838 else 839 rc = rtFuzzCmdMasterErrorRc(pErrInfo, rc, "Request error: Failed to query fuzzing statistics with %Rrc", rc); 840 } 841 842 return rc; 817 843 } 818 844 … … 902 928 * @returns nothing. 903 929 * @param hSocket The socket handle to send the ACK to. 904 */ 905 static void rtFuzzCmdMasterTcpSendAck(RTSOCKET hSocket) 930 * @param pszResponse Additional response data. 931 */ 932 static void rtFuzzCmdMasterTcpSendAck(RTSOCKET hSocket, const char *pszResponse) 906 933 { 907 934 const char s_szSucc[] = "{ \"Status\": \"ACK\" }\n"; 908 RTTcpWrite(hSocket, s_szSucc, sizeof(s_szSucc)); 935 const char s_szSuccResp[] = "{ \"Status\": \"ACK\"\n \"Response\":\n %s\n }\n"; 936 if (pszResponse) 937 { 938 char szTmp[_1K]; 939 ssize_t cchResp = RTStrPrintf2(szTmp, sizeof(szTmp), s_szSuccResp, pszResponse); 940 if (cchResp > 0) 941 RTTcpWrite(hSocket, szTmp, cchResp); 942 else 943 RTTcpWrite(hSocket, s_szSucc, strlen(s_szSucc)); 944 } 945 else 946 RTTcpWrite(hSocket, s_szSucc, sizeof(s_szSucc)); 909 947 } 910 948 … … 924 962 if (pErrInfo) 925 963 { 926 char szTmp[ 1024];964 char szTmp[_1K]; 927 965 ssize_t cchResp = RTStrPrintf2(szTmp, sizeof(szTmp), s_szFailInfo, pErrInfo->pszMsg); 928 966 if (cchResp > 0) … … 973 1011 RTErrInfoInitStatic(&ErrInfo); 974 1012 1013 pThis->fAckResponse = false; 1014 RT_ZERO(pThis->aszResponse); 975 1015 rc = RTJsonParseFromBuf(&hJsonReq, pbReq, cbReq, &ErrInfo.Core); 976 1016 if (RT_SUCCESS(rc)) … … 978 1018 rc = rtFuzzCmdMasterProcessJsonReq(pThis, hJsonReq, &ErrInfo.Core); 979 1019 if (RT_SUCCESS(rc)) 980 rtFuzzCmdMasterTcpSendAck(hSocket );1020 rtFuzzCmdMasterTcpSendAck(hSocket, pThis->fAckResponse ? pThis->aszResponse : NULL); 981 1021 else 982 1022 rtFuzzCmdMasterTcpSendNAck(hSocket, &ErrInfo.Core);
Note:
See TracChangeset
for help on using the changeset viewer.