aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2014-03-18 14:14:19 +0100
committerJacob Erlbeck <jerlbeck@sysmocom.de>2014-03-18 14:30:04 +0100
commit7e6211be3ddd988318f29affb213e26250c7705c (patch)
tree7a68046d72c52cc4008677e068ce764c0863a688
parent0f40fb6b520fd0dacd498ea4fbb28aa4aee16452 (diff)
msgb: Let msgb_hexdump be more tolerant
This patch makes msgb_hexdump accept out of range lXh pointers and shows info about them instead of aborting the dump entirely. Sponsored-by: On-Waves ehf
-rw-r--r--src/msgb.c46
1 files changed, 39 insertions, 7 deletions
diff --git a/src/msgb.c b/src/msgb.c
index c57c2ab3..ee28a45d 100644
--- a/src/msgb.c
+++ b/src/msgb.c
@@ -182,10 +182,25 @@ const char *msgb_hexdump(const struct msgb *msg)
if (!lxhs[i])
continue;
- if (lxhs[i] < msg->data)
- goto out_of_range;
+ if (lxhs[i] < msg->head)
+ continue;
+ if (lxhs[i] > msg->head + msg->data_len)
+ continue;
if (lxhs[i] > msg->tail)
- goto out_of_range;
+ continue;
+ if (lxhs[i] < msg->data || lxhs[i] > msg->tail) {
+ nchars = snprintf(buf + buf_offs, sizeof(buf) - buf_offs,
+ "(L%d=data%+d) ",
+ i+1, lxhs[i] - msg->data);
+ buf_offs += nchars;
+ continue;
+ }
+ if (lxhs[i] < start) {
+ nchars = snprintf(buf + buf_offs, sizeof(buf) - buf_offs,
+ "(L%d%+d) ", i+1, start - lxhs[i]);
+ buf_offs += nchars;
+ continue;
+ }
nchars = snprintf(buf + buf_offs, sizeof(buf) - buf_offs,
"%s[L%d]> ",
osmo_hexdump(start, lxhs[i] - start),
@@ -201,11 +216,28 @@ const char *msgb_hexdump(const struct msgb *msg)
if (nchars < 0 || nchars + buf_offs >= sizeof(buf))
return "ERROR";
- return buf;
+ buf_offs += nchars;
+
+ for (i = 0; i < ARRAY_SIZE(lxhs); i++) {
+ if (!lxhs[i])
+ continue;
+
+ if (lxhs[i] < msg->head || lxhs[i] > msg->head + msg->data_len) {
+ nchars = snprintf(buf + buf_offs, sizeof(buf) - buf_offs,
+ "(L%d out of range) ", i+1);
+ } else if (lxhs[i] <= msg->data + msg->data_len &&
+ lxhs[i] > msg->tail) {
+ nchars = snprintf(buf + buf_offs, sizeof(buf) - buf_offs,
+ "(L%d=tail%+d) ",
+ i+1, lxhs[i] - msg->tail);
+ } else
+ continue;
+
+ if (nchars < 0 || nchars + buf_offs >= sizeof(buf))
+ return "ERROR";
+ buf_offs += nchars;
+ }
-out_of_range:
- nchars = snprintf(buf, sizeof(buf) - buf_offs,
- "!!! L%d out of range", i+1);
return buf;
}