Skip to content

Commit a20d832

Browse files
Dan Phungsipma
authored andcommitted
add length-addr to the metadata for patch-records
The length address of the function is useful for some downstream patch record consumers that need the address to patch the input length. This is used in conjunction with the currently exported 'length-argument' field.
1 parent 2f0ff4f commit a20d832

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

chb/buffer/LibraryCallCallsites.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,25 @@ def lenarg(self) -> Optional["XXpr"]:
212212
return self.instr.call_arguments[lenindex - 1]
213213
return None
214214

215+
@property
216+
def lenaddr(self) -> Optional[str]:
217+
if self.lenarg is None:
218+
return None
219+
regname = str(self.lenarg)
220+
locs = self.instr.reaching_definitions(regname)
221+
valid = [loc for loc in locs if loc != "init"]
222+
if len(valid) == 1:
223+
return valid[0]
224+
elif len(valid) == 0:
225+
chklogger.logger.warning(
226+
"No valid reaching def for %s at %s", regname, self.instr.iaddr)
227+
return None
228+
else:
229+
# Multiple reaching defs means a join point — ambiguous, can't patch
230+
chklogger.logger.warning(
231+
"Multiple reaching defs for %s at %s: %s", regname, self.instr.iaddr, valid)
232+
return None
233+
215234
@property
216235
def lentype(self) -> str:
217236
lenarg = self.lenarg
@@ -254,6 +273,7 @@ def to_json_result(self,
254273
content["stack-offset"] = dstoffset
255274
if self.lenarg is not None:
256275
content["length-argument"] = str(self.lenarg)
276+
content["length-addr"] = self.lenaddr
257277
else:
258278
content["length-argument"] = None
259279
content["spare"] = spare

0 commit comments

Comments
 (0)