Parse hex code immediately to avoid SIGBUS.

On 32-bit devices we trigger SIGBUS by trying to copy around the
std::string, so parse it immediately to avoid trouble.

Test: manual with 32-bit binary
Bug: 73961200
Change-Id: I32028fd18a00f3a40d380145cb7a7874b758f5c4
This commit is contained in:
Jeff Sharkey
2018-03-27 13:17:19 -06:00
parent fe263b2505
commit 9c50b5e176
2 changed files with 6 additions and 6 deletions

View File

@@ -365,7 +365,10 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
partNum = newPartNum; partNum = newPartNum;
if ((partNum >= 0) && (partNum < (int) GetNumParts())) { if ((partNum >= 0) && (partNum < (int) GetNumParts())) {
// Remember the original hex value requested // Remember the original hex value requested
typeRaw[partNum] = GetString(typeCode, 2); string raw = GetString(typeCode, 2);
if (raw.size() == 4) {
typeRaw[partNum] = StrToHex(raw, 0);
}
typeHelper = GetString(typeCode, 2); typeHelper = GetString(typeCode, 2);
if ((typeHelper != (GUIDData) "00000000-0000-0000-0000-000000000000") && if ((typeHelper != (GUIDData) "00000000-0000-0000-0000-000000000000") &&
(ChangePartType(partNum, typeHelper))) { (ChangePartType(partNum, typeHelper))) {
@@ -499,10 +502,7 @@ int GPTDataCL::BuildMBR(char* argument, int isHybrid) {
// If we were created with a specific hex type, use that instead // If we were created with a specific hex type, use that instead
// of risking fidelity loss by doing a GUID-based lookup // of risking fidelity loss by doing a GUID-based lookup
if (typeRaw.count(origPartNum) == 1) { if (typeRaw.count(origPartNum) == 1) {
string raw = typeRaw[origPartNum]; newPart.SetType(typeRaw[origPartNum]);
if (raw.size() == 4) {
newPart.SetType(StrToHex(raw, 0));
}
} }
newMBR.AddPart(i + isHybrid, newPart); newMBR.AddPart(i + isHybrid, newPart);
} else { } else {

View File

@@ -37,7 +37,7 @@ class GPTDataCL : public GPTData {
int alignment, deletePartNum, infoPartNum, largestPartNum, bsdPartNum; int alignment, deletePartNum, infoPartNum, largestPartNum, bsdPartNum;
uint32_t tableSize; uint32_t tableSize;
poptContext poptCon; poptContext poptCon;
std::map<int, string> typeRaw; std::map<int, char> typeRaw;
int BuildMBR(char* argument, int isHybrid); int BuildMBR(char* argument, int isHybrid);
public: public: