fix mgcp_verify_ci(): off-by-one in max len check
MGCP_CONN_ID_MAXLEN actually includes a terminating nul, so we need to compare
strlen() against MGCP_CONN_ID_MAXLEN-1.
Log the length if it is too long.
Add MDCX_TOO_LONG_CI test to mgcp_test.c, testing a conn id of 33 characters.
Before this patch, the test returns error code 515 meaning "not found", while
now it returns 510 meaning "invalid", showing the off-by-one. Same is
illustrated by the error log ("not found" before, "too long" now), but the
error log is not verified by mgcp_test.c.
Change-Id: I8d6cc96be252bb486e94f343a8c7cae641ff9429
diff --git a/src/libosmo-mgcp/mgcp_msg.c b/src/libosmo-mgcp/mgcp_msg.c
index f732158..648d86b 100644
--- a/src/libosmo-mgcp/mgcp_msg.c
+++ b/src/libosmo-mgcp/mgcp_msg.c
@@ -454,10 +454,10 @@
}
/* Check for over long connection identifiers */
- if (strlen(conn_id) > MGCP_CONN_ID_MAXLEN) {
+ if (strlen(conn_id) > (MGCP_CONN_ID_MAXLEN-1)) {
LOGP(DLMGCP, LOGL_ERROR,
- "endpoint:0x%x invalid ConnectionIdentifier (too long) 0x%s\n",
- ENDPOINT_NUMBER(endp), conn_id);
+ "endpoint:0x%x invalid ConnectionIdentifier (too long: %zu > %d) 0x%s\n",
+ ENDPOINT_NUMBER(endp), strlen(conn_id), MGCP_CONN_ID_MAXLEN-1, conn_id);
return 510;
}