diff mbox

example: classifier: fix string overflow

Message ID 1437728351-17811-1-git-send-email-bala.manoharan@linaro.org
State Accepted
Commit 34dfe0180592858a154d8d49463db5fd6e477d3f
Headers show

Commit Message

Balasubramanian Manoharan July 24, 2015, 8:59 a.m. UTC
From: Bala Manoharan <bala.manoharan@linaro.org>

Fixes: https://bugs.linaro.org/show_bug.cgi?id=1512

Signed-off-by: Balasubramanian Manoharan <bala.manoharan@linaro.org>
---
 example/classifier/odp_classifier.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Bill Fischofer July 24, 2015, 12:20 p.m. UTC | #1
On Fri, Jul 24, 2015 at 3:59 AM, Balasubramanian Manoharan <
bala.manoharan@linaro.org> wrote:

> From: Bala Manoharan <bala.manoharan@linaro.org>
>
> Fixes: https://bugs.linaro.org/show_bug.cgi?id=1512
>
> Signed-off-by: Balasubramanian Manoharan <bala.manoharan@linaro.org>
>

Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org>


> ---
>  example/classifier/odp_classifier.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/example/classifier/odp_classifier.c
> b/example/classifier/odp_classifier.c
> index 4f741d0..030eb8b 100644
> --- a/example/classifier/odp_classifier.c
> +++ b/example/classifier/odp_classifier.c
> @@ -605,10 +605,10 @@ static int parse_pmr_policy(appl_args_t *appl_args,
> char *argv[], char *optarg)
>         switch (term)   {
>         case ODP_PMR_SIP_ADDR:
>                 token = strtok(NULL, ":");
> -               strcpy(stats[policy_count].value, token);
> +               strncpy(stats[policy_count].value, token,
> DISPLAY_STRING_LEN);
>                 parse_ipv4_addr(token, &stats[policy_count].rule.val);
>                 token = strtok(NULL, ":");
> -               strcpy(stats[policy_count].mask, token);
> +               strncpy(stats[policy_count].mask, token,
> DISPLAY_STRING_LEN);
>                 parse_ipv4_mask(token, &stats[policy_count].rule.mask);
>                 stats[policy_count].val_sz = 4;
>         break;
> @@ -619,7 +619,8 @@ static int parse_pmr_policy(appl_args_t *appl_args,
> char *argv[], char *optarg)
>
>         /* Queue Name */
>         token = strtok(NULL, ":");
> -       strcpy(stats[policy_count].queue_name, token);
> +
> +       strncpy(stats[policy_count].queue_name, token, ODP_QUEUE_NAME_LEN);
>         appl_args->policy_count++;
>         free(pmr_str);
>         return 0;
> --
> 1.9.1
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> https://lists.linaro.org/mailman/listinfo/lng-odp
>
Maxim Uvarov July 24, 2015, 1:38 p.m. UTC | #2
Merged.

Maxim.

On 07/24/15 15:20, Bill Fischofer wrote:
>
>
> On Fri, Jul 24, 2015 at 3:59 AM, Balasubramanian Manoharan 
> <bala.manoharan@linaro.org <mailto:bala.manoharan@linaro.org>> wrote:
>
>     From: Bala Manoharan <bala.manoharan@linaro.org
>     <mailto:bala.manoharan@linaro.org>>
>
>     Fixes: https://bugs.linaro.org/show_bug.cgi?id=1512
>
>     Signed-off-by: Balasubramanian Manoharan
>     <bala.manoharan@linaro.org <mailto:bala.manoharan@linaro.org>>
>
>
> Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org 
> <mailto:bill.fischofer@linaro.org>>
>
>     ---
>      example/classifier/odp_classifier.c | 7 ++++---
>      1 file changed, 4 insertions(+), 3 deletions(-)
>
>     diff --git a/example/classifier/odp_classifier.c
>     b/example/classifier/odp_classifier.c
>     index 4f741d0..030eb8b 100644
>     --- a/example/classifier/odp_classifier.c
>     +++ b/example/classifier/odp_classifier.c
>     @@ -605,10 +605,10 @@ static int parse_pmr_policy(appl_args_t
>     *appl_args, char *argv[], char *optarg)
>             switch (term)   {
>             case ODP_PMR_SIP_ADDR:
>                     token = strtok(NULL, ":");
>     -               strcpy(stats[policy_count].value, token);
>     +               strncpy(stats[policy_count].value, token,
>     DISPLAY_STRING_LEN);
>                     parse_ipv4_addr(token, &stats[policy_count].rule.val);
>                     token = strtok(NULL, ":");
>     -               strcpy(stats[policy_count].mask, token);
>     +               strncpy(stats[policy_count].mask, token,
>     DISPLAY_STRING_LEN);
>                     parse_ipv4_mask(token,
>     &stats[policy_count].rule.mask);
>                     stats[policy_count].val_sz = 4;
>             break;
>     @@ -619,7 +619,8 @@ static int parse_pmr_policy(appl_args_t
>     *appl_args, char *argv[], char *optarg)
>
>             /* Queue Name */
>             token = strtok(NULL, ":");
>     -       strcpy(stats[policy_count].queue_name, token);
>     +
>     +       strncpy(stats[policy_count].queue_name, token,
>     ODP_QUEUE_NAME_LEN);
>             appl_args->policy_count++;
>             free(pmr_str);
>             return 0;
>     --
>     1.9.1
>
>     _______________________________________________
>     lng-odp mailing list
>     lng-odp@lists.linaro.org <mailto:lng-odp@lists.linaro.org>
>     https://lists.linaro.org/mailman/listinfo/lng-odp
>
>
>
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> https://lists.linaro.org/mailman/listinfo/lng-odp
diff mbox

Patch

diff --git a/example/classifier/odp_classifier.c b/example/classifier/odp_classifier.c
index 4f741d0..030eb8b 100644
--- a/example/classifier/odp_classifier.c
+++ b/example/classifier/odp_classifier.c
@@ -605,10 +605,10 @@  static int parse_pmr_policy(appl_args_t *appl_args, char *argv[], char *optarg)
 	switch (term)	{
 	case ODP_PMR_SIP_ADDR:
 		token = strtok(NULL, ":");
-		strcpy(stats[policy_count].value, token);
+		strncpy(stats[policy_count].value, token, DISPLAY_STRING_LEN);
 		parse_ipv4_addr(token, &stats[policy_count].rule.val);
 		token = strtok(NULL, ":");
-		strcpy(stats[policy_count].mask, token);
+		strncpy(stats[policy_count].mask, token, DISPLAY_STRING_LEN);
 		parse_ipv4_mask(token, &stats[policy_count].rule.mask);
 		stats[policy_count].val_sz = 4;
 	break;
@@ -619,7 +619,8 @@  static int parse_pmr_policy(appl_args_t *appl_args, char *argv[], char *optarg)
 
 	/* Queue Name */
 	token = strtok(NULL, ":");
-	strcpy(stats[policy_count].queue_name, token);
+
+	strncpy(stats[policy_count].queue_name, token, ODP_QUEUE_NAME_LEN);
 	appl_args->policy_count++;
 	free(pmr_str);
 	return 0;