In ebl_object_note, an NT_STAPSDT descriptor ends with three
NUL-terminated strings: provider, probe name, and arguments. When
locating the terminator of the argument string, the second memchr call
starts scanning at args, but passes the remaining byte count computed
from pname:
const char *args = memchr (pname, '\\0', desc + descsz - pname);
if (args == NULL ||
memchr (++args, '\\0', desc + descsz - pname) != desc + descsz -
1)
Because args is advanced past the probe name and its NUL terminator,
desc + descsz - pname overstates the remaining descriptor size by
args - pname bytes, allowing memchr to read past the end of the note
descriptor buffer if the argument string is not NUL-terminated. The
same expression also increments and reads args without an intervening
sequence point.
Advance args in its own statement after checking for NULL, and compute
the scan bound as desc + descsz - args.
* libebl/eblobjnote.c (ebl_object_note): Increment args before
calling memchr for the stapsdt argument string, and pass
desc + descsz - args as the maximum length.
Signed-off-by: Minseok Kim <[email protected]>
---
libebl/eblobjnote.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/libebl/eblobjnote.c b/libebl/eblobjnote.c
index cf6f680..5ec3a1e 100644
--- a/libebl/eblobjnote.c
+++ b/libebl/eblobjnote.c
@@ -103,8 +103,11 @@ ebl_object_note (Ebl *ebl, uint32_t namesz, const char
*name, uint32_t type,
++pname;
const char *args = memchr (pname, '\0', desc + descsz - pname);
- if (args == NULL ||
- memchr (++args, '\0', desc + descsz - pname) != desc + descsz - 1)
+ if (args == NULL)
+ goto invalid_sdt;
+
+ ++args;
+ if (memchr (args, '\0', desc + descsz - args) != desc + descsz - 1)
goto invalid_sdt;
GElf_Addr pc;
--
2.34.1