Skip to content

Commit

Permalink
libuuu: do not crash when using FB: write -format without @off or `…
Browse files Browse the repository at this point in the history
…@size`

Check the return code of ucmd.find(), so we don't attempt to replace
with an out-of-bounds index when the command string does not contain the
`@off` and `@size` patterns.
  • Loading branch information
tq-schifferm authored and nxpfrankli committed Nov 23, 2023
1 parent f9080cc commit 3a5beb6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions libuuu/fastboot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1024,14 +1024,18 @@ string FBLoop::build_cmd(string& cmd, size_t off, size_t sz)
ucmd += cmd;

string_ex ex;
ex.format("0x%llx", off);

size_t pos= ucmd.find("@off");
ucmd = ucmd.replace(pos, 4, ex);
if (pos != string::npos) {
ex.format("0x%llx", off);
ucmd = ucmd.replace(pos, 4, ex);
}

ex.format("0x%llx", sz);
pos = ucmd.find("@size");
ucmd = ucmd.replace(pos, 5, ex);
if (pos != string::npos) {
ex.format("0x%llx", sz);
ucmd = ucmd.replace(pos, 5, ex);
}

return ucmd;
}
Expand Down

0 comments on commit 3a5beb6

Please sign in to comment.