From a5668a610b1ff9d2196ef11aeb3f4633dda22dd7 Mon Sep 17 00:00:00 2001 From: erin_yueh Date: Tue, 25 Mar 2008 10:33:45 +0000 Subject: gsmd: fix clip & colp parser problem (Erin Yueh) git-svn-id: http://svn.openmoko.org/trunk/src/target/gsm@4245 99fdad57-331a-0410-800a-d7fa5415bdb3 --- src/gsmd/unsolicited.c | 55 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 19 deletions(-) (limited to 'src/gsmd') diff --git a/src/gsmd/unsolicited.c b/src/gsmd/unsolicited.c index 537e16a..97d4b55 100644 --- a/src/gsmd/unsolicited.c +++ b/src/gsmd/unsolicited.c @@ -348,23 +348,31 @@ static int clip_parse(const char *buf, int len, const char *param, struct gsmd_ucmd *ucmd = usock_build_event(GSMD_MSG_EVENT, GSMD_EVT_IN_CLIP, sizeof(struct gsmd_evt_auxdata)); struct gsmd_evt_auxdata *aux; - const char *comma = strchr(param, ','); + struct gsm_extrsp *er; - if (!ucmd) + if (!ucmd) return -ENOMEM; aux = (struct gsmd_evt_auxdata *) ucmd->buf; - if (!comma) - return -EINVAL; + er = extrsp_parse(gsmd_tallocs, param); - - if (comma - param > GSMD_ADDR_MAXLEN) - return -EINVAL; + if ( !er ) + return -ENOMEM; - aux->u.clip.addr.number[0] = '\0'; - strncat(aux->u.clip.addr.number, param, comma-param); - /* FIXME: parse of subaddr, etc. */ + if ( er->num_tokens >= 2 && + er->tokens[0].type == GSMD_ECMD_RTT_STRING && + er->tokens[1].type == GSMD_ECMD_RTT_NUMERIC ) { + /* + * ,[,,[,[][,]]] + */ + + strcpy(aux->u.clip.addr.number, er->tokens[0].u.string); + aux->u.clip.addr.type = er->tokens[1].u.numeric; + } else { + DEBUGP("Invalid Input : Parse error\n"); + return -EINVAL; + } return usock_evt_send(gsmd, ucmd, GSMD_EVT_IN_CLIP); } @@ -376,23 +384,32 @@ static int colp_parse(const char *buf, int len, const char *param, struct gsmd_ucmd *ucmd = usock_build_event(GSMD_MSG_EVENT, GSMD_EVT_OUT_COLP, sizeof(struct gsmd_evt_auxdata)); struct gsmd_evt_auxdata *aux; - const char *comma = strchr(param, ','); + struct gsm_extrsp *er; if (!ucmd) return -ENOMEM; aux = (struct gsmd_evt_auxdata *) ucmd->buf; - if (!comma) - return -EINVAL; - - if (comma - param > GSMD_ADDR_MAXLEN) - return -EINVAL; + er = extrsp_parse(gsmd_tallocs, param); - aux->u.colp.addr.number[0] = '\0'; - strncat(aux->u.colp.addr.number, param, comma-param); - /* FIXME: parse of subaddr, etc. */ + if ( !er ) + return -ENOMEM; + if ( er->num_tokens >= 2 && + er->tokens[0].type == GSMD_ECMD_RTT_STRING && + er->tokens[1].type == GSMD_ECMD_RTT_NUMERIC ) { + /* + * ,[,, [,]] + */ + + strcpy(aux->u.colp.addr.number, er->tokens[0].u.string); + aux->u.colp.addr.type = er->tokens[1].u.numeric; + } else { + DEBUGP("Invalid Input : Parse error\n"); + return -EINVAL; + } + return usock_evt_send(gsmd, ucmd, GSMD_EVT_OUT_COLP); } -- cgit v1.2.3