VirtualBox

vbox的更動 60427 路徑 trunk/src


忽略:
時間撮記:
2016-4-11 下午02:30:32 (9 年 以前)
作者:
vboxsync
訊息:

Runtime/linux/sysfs.cpp: Fixes for the tstRTSystemQueryDmi testcase, don't seek to the end of the file to get the file size because that is often bogus for sysfs entries (the indicated file size is much bigger than what can be read really). Fix an inconsistency in RTLinuxSysFsReadStrFileV() which would return a VERR_BUFFER_OVERFLOW error if the given buffer matches the string size if there is a newline end the end which is filtered out anyway. Small adjustment for RTLinuxSysFsWriteStr() to also write zero terminators if the string size is not given

檔案:
修改 1 筆資料

圖例:

未更動
新增
刪除
  • trunk/src/VBox/Runtime/r3/linux/sysfs.cpp

    r60424 r60427  
    238238        /* Check for EOF */
    239239        uint64_t offCur = 0;
    240         uint64_t offEnd = 0;
     240        uint8_t bRead;
    241241        rc = RTFileSeek(hFile, 0, RTFILE_SEEK_CURRENT, &offCur);
    242242        if (RT_SUCCESS(rc))
    243             rc = RTFileSeek(hFile, 0, RTFILE_SEEK_END, &offEnd);
    244         if (   RT_SUCCESS(rc)
    245             && offEnd > offCur)
    246             rc = VERR_BUFFER_OVERFLOW;
     243        {
     244            int rc2 = RTFileRead(hFile, &bRead, 1, NULL);
     245            if (RT_SUCCESS(rc2))
     246            {
     247                rc = VERR_BUFFER_OVERFLOW;
     248
     249                rc2 = RTFileSeek(hFile, offCur, RTFILE_SEEK_BEGIN, NULL);
     250                if (RT_FAILURE(rc2))
     251                    rc = rc2;
     252            }
     253            else if (rc2 != VERR_EOF)
     254                rc = rc2;
     255        }
    247256    }
    248257    return rc;
     
    253262{
    254263    if (!cchBuf)
    255         cchBuf = strlen(pszBuf);
     264        cchBuf = strlen(pszBuf) + 1; /* Include the terminator */
    256265    return RTFileWrite(hFile, pszBuf, cchBuf, pcchWritten);
    257266}
     
    274283            /* Check for EOF */
    275284            uint64_t offCur = 0;
    276             uint64_t offEnd = 0;
     285            uint8_t bRead;
    277286            rc = RTFileSeek(hFile, 0, RTFILE_SEEK_CURRENT, &offCur);
    278287            if (RT_SUCCESS(rc))
    279                 rc = RTFileSeek(hFile, 0, RTFILE_SEEK_END, &offEnd);
    280             if (   RT_SUCCESS(rc)
    281                 && offEnd > offCur)
    282                 rc = VERR_BUFFER_OVERFLOW;
     288            {
     289                int rc2 = RTFileRead(hFile, &bRead, 1, NULL);
     290                if (RT_SUCCESS(rc2))
     291                {
     292                    rc = VERR_BUFFER_OVERFLOW;
     293
     294                    rc2 = RTFileSeek(hFile, offCur, RTFILE_SEEK_BEGIN, NULL);
     295                    if (RT_FAILURE(rc2))
     296                        rc = rc2;
     297                }
     298                else if (rc2 != VERR_EOF)
     299                    rc = rc2;
     300            }
    283301        }
    284302    }
     
    502520        size_t cchRead = 0;
    503521        rc = RTLinuxSysFsReadStr(hFile, pszBuf, cchBuf, &cchRead);
    504         RTFileClose(hFile);
    505522        if (   RT_SUCCESS(rc)
    506523            && cchRead > 0)
     
    508525            char *pchNewLine = (char *)memchr(pszBuf, '\n', cchRead);
    509526            if (pchNewLine)
     527            {
    510528                *pchNewLine = '\0';
    511         }
     529                cchRead--;
     530            }
     531        }
     532        else if (   rc == VERR_BUFFER_OVERFLOW
     533                 && cchRead > 0)
     534        {
     535            /*
     536             * Check if the last character would have been a newline we filter out
     537             * anyway and revert the buffer overflow.
     538             */
     539            char achBuf[2];
     540            size_t cchPeek = 0;
     541            uint64_t offCur = 0;
     542
     543            int rc2 = RTFileSeek(hFile, 0, RTFILE_SEEK_CURRENT, &offCur);
     544            if (RT_SUCCESS(rc2))
     545            {
     546                rc2 = RTLinuxSysFsReadStr(hFile, &achBuf[0], sizeof(achBuf), &cchPeek);
     547                if (   RT_SUCCESS(rc2)
     548                    && cchPeek > 0)
     549                    rc2 = RTFileSeek(hFile, offCur, RTFILE_SEEK_BEGIN, NULL);
     550                if (   RT_SUCCESS(rc2)
     551                    && cchPeek > 0
     552                    && achBuf[0] == '\n')
     553                    rc = VINF_SUCCESS;
     554            }
     555        }
     556
     557        RTFileClose(hFile);
    512558
    513559        if (pcchRead)
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette