Re: parse.y: strndup() in cmdline_symset()

2018-11-06 Thread Claudio Jeker
On Wed, Nov 07, 2018 at 12:55:34PM +0800, Michael Mikonos wrote:
> ping?

OK claudio@
 
> On Thu, Nov 01, 2018 at 04:14:53PM +0800, Michael Mikonos wrote:
> > Hello,
> > 
> > When I updated cmdline_symset() in parse.y in the following commit
> > I missed src/sbin/{iked,ipsecctl,pfctl}/parse.y. OK to update them?
> > 
> > https://marc.info/?l=openbsd-cvs&m=153631079505256&w=2
> > 
> > 
> > Index: iked/parse.y
> > ===
> > RCS file: /cvs/src/sbin/iked/parse.y,v
> > retrieving revision 1.76
> > diff -u -p -u -r1.76 parse.y
> > --- iked/parse.y1 Nov 2018 00:18:44 -   1.76
> > +++ iked/parse.y1 Nov 2018 07:03:31 -
> > @@ -1660,17 +1660,13 @@ cmdline_symset(char *s)
> >  {
> > char*sym, *val;
> > int ret;
> > -   size_t  len;
> >  
> > if ((val = strrchr(s, '=')) == NULL)
> > return (-1);
> >  
> > -   len = strlen(s) - strlen(val) + 1;
> > -   if ((sym = malloc(len)) == NULL)
> > +   sym = strndup(s, val - s);
> > +   if (sym == NULL)
> > err(1, "%s", __func__);
> > -
> > -   strlcpy(sym, s, len);
> > -
> > ret = symset(sym, val + 1, 1);
> > free(sym);
> >  
> > Index: ipsecctl/parse.y
> > ===
> > RCS file: /cvs/src/sbin/ipsecctl/parse.y,v
> > retrieving revision 1.174
> > diff -u -p -u -r1.174 parse.y
> > --- ipsecctl/parse.y1 Nov 2018 00:18:44 -   1.174
> > +++ ipsecctl/parse.y1 Nov 2018 07:03:32 -
> > @@ -1426,17 +1426,13 @@ cmdline_symset(char *s)
> >  {
> > char*sym, *val;
> > int ret;
> > -   size_t  len;
> >  
> > if ((val = strrchr(s, '=')) == NULL)
> > return (-1);
> >  
> > -   len = strlen(s) - strlen(val) + 1;
> > -   if ((sym = malloc(len)) == NULL)
> > +   sym = strndup(s, val - s);
> > +   if (sym == NULL)
> > err(1, "%s", __func__);
> > -
> > -   strlcpy(sym, s, len);
> > -
> > ret = symset(sym, val + 1, 1);
> > free(sym);
> >  
> > Index: pfctl/parse.y
> > ===
> > RCS file: /cvs/src/sbin/pfctl/parse.y,v
> > retrieving revision 1.685
> > diff -u -p -u -r1.685 parse.y
> > --- pfctl/parse.y   1 Nov 2018 00:18:44 -   1.685
> > +++ pfctl/parse.y   1 Nov 2018 07:03:34 -
> > @@ -5564,11 +5564,9 @@ pfctl_cmdline_symset(char *s)
> > if ((val = strrchr(s, '=')) == NULL)
> > return (-1);
> >  
> > -   if ((sym = malloc(strlen(s) - strlen(val) + 1)) == NULL)
> > +   sym = strndup(s, val - s);  
> > +   if (sym == NULL);
> > err(1, "%s", __func__);
> > -
> > -   strlcpy(sym, s, strlen(s) - strlen(val) + 1);
> > -
> > ret = symset(sym, val + 1, 1);
> > free(sym);
> >  
> 

-- 
:wq Claudio



Re: parse.y: strndup() in cmdline_symset()

2018-11-06 Thread Alexandr Nedvedicky
Hello,

the change looks good to me. (I was delaying my OK hoping
someone else will chip-in with OK for iked & ipsecctl stuff).

IMO It makes sense to keep parse.y code in sync where possible,
so go for it.

OK sashan.


On Thu, Nov 01, 2018 at 04:14:53PM +0800, Michael Mikonos wrote:
> Hello,
> 
> When I updated cmdline_symset() in parse.y in the following commit
> I missed src/sbin/{iked,ipsecctl,pfctl}/parse.y. OK to update them?
> 
> https://marc.info/?l=openbsd-cvs&m=153631079505256&w=2
> 
> 
> Index: iked/parse.y
> ===
> RCS file: /cvs/src/sbin/iked/parse.y,v
> retrieving revision 1.76
> diff -u -p -u -r1.76 parse.y
> --- iked/parse.y  1 Nov 2018 00:18:44 -   1.76
> +++ iked/parse.y  1 Nov 2018 07:03:31 -
> @@ -1660,17 +1660,13 @@ cmdline_symset(char *s)
>  {
>   char*sym, *val;
>   int ret;
> - size_t  len;
>  
>   if ((val = strrchr(s, '=')) == NULL)
>   return (-1);
>  
> - len = strlen(s) - strlen(val) + 1;
> - if ((sym = malloc(len)) == NULL)
> + sym = strndup(s, val - s);
> + if (sym == NULL)
>   err(1, "%s", __func__);
> -
> - strlcpy(sym, s, len);
> -
>   ret = symset(sym, val + 1, 1);
>   free(sym);
>  
> Index: ipsecctl/parse.y
> ===
> RCS file: /cvs/src/sbin/ipsecctl/parse.y,v
> retrieving revision 1.174
> diff -u -p -u -r1.174 parse.y
> --- ipsecctl/parse.y  1 Nov 2018 00:18:44 -   1.174
> +++ ipsecctl/parse.y  1 Nov 2018 07:03:32 -
> @@ -1426,17 +1426,13 @@ cmdline_symset(char *s)
>  {
>   char*sym, *val;
>   int ret;
> - size_t  len;
>  
>   if ((val = strrchr(s, '=')) == NULL)
>   return (-1);
>  
> - len = strlen(s) - strlen(val) + 1;
> - if ((sym = malloc(len)) == NULL)
> + sym = strndup(s, val - s);
> + if (sym == NULL)
>   err(1, "%s", __func__);
> -
> - strlcpy(sym, s, len);
> -
>   ret = symset(sym, val + 1, 1);
>   free(sym);
>  
> Index: pfctl/parse.y
> ===
> RCS file: /cvs/src/sbin/pfctl/parse.y,v
> retrieving revision 1.685
> diff -u -p -u -r1.685 parse.y
> --- pfctl/parse.y 1 Nov 2018 00:18:44 -   1.685
> +++ pfctl/parse.y 1 Nov 2018 07:03:34 -
> @@ -5564,11 +5564,9 @@ pfctl_cmdline_symset(char *s)
>   if ((val = strrchr(s, '=')) == NULL)
>   return (-1);
>  
> - if ((sym = malloc(strlen(s) - strlen(val) + 1)) == NULL)
> + sym = strndup(s, val - s);  
> + if (sym == NULL);
>   err(1, "%s", __func__);
> -
> - strlcpy(sym, s, strlen(s) - strlen(val) + 1);
> -
>   ret = symset(sym, val + 1, 1);
>   free(sym);
>  
> 



Re: parse.y: strndup() in cmdline_symset()

2018-11-06 Thread Michael Mikonos
ping?

On Thu, Nov 01, 2018 at 04:14:53PM +0800, Michael Mikonos wrote:
> Hello,
> 
> When I updated cmdline_symset() in parse.y in the following commit
> I missed src/sbin/{iked,ipsecctl,pfctl}/parse.y. OK to update them?
> 
> https://marc.info/?l=openbsd-cvs&m=153631079505256&w=2
> 
> 
> Index: iked/parse.y
> ===
> RCS file: /cvs/src/sbin/iked/parse.y,v
> retrieving revision 1.76
> diff -u -p -u -r1.76 parse.y
> --- iked/parse.y  1 Nov 2018 00:18:44 -   1.76
> +++ iked/parse.y  1 Nov 2018 07:03:31 -
> @@ -1660,17 +1660,13 @@ cmdline_symset(char *s)
>  {
>   char*sym, *val;
>   int ret;
> - size_t  len;
>  
>   if ((val = strrchr(s, '=')) == NULL)
>   return (-1);
>  
> - len = strlen(s) - strlen(val) + 1;
> - if ((sym = malloc(len)) == NULL)
> + sym = strndup(s, val - s);
> + if (sym == NULL)
>   err(1, "%s", __func__);
> -
> - strlcpy(sym, s, len);
> -
>   ret = symset(sym, val + 1, 1);
>   free(sym);
>  
> Index: ipsecctl/parse.y
> ===
> RCS file: /cvs/src/sbin/ipsecctl/parse.y,v
> retrieving revision 1.174
> diff -u -p -u -r1.174 parse.y
> --- ipsecctl/parse.y  1 Nov 2018 00:18:44 -   1.174
> +++ ipsecctl/parse.y  1 Nov 2018 07:03:32 -
> @@ -1426,17 +1426,13 @@ cmdline_symset(char *s)
>  {
>   char*sym, *val;
>   int ret;
> - size_t  len;
>  
>   if ((val = strrchr(s, '=')) == NULL)
>   return (-1);
>  
> - len = strlen(s) - strlen(val) + 1;
> - if ((sym = malloc(len)) == NULL)
> + sym = strndup(s, val - s);
> + if (sym == NULL)
>   err(1, "%s", __func__);
> -
> - strlcpy(sym, s, len);
> -
>   ret = symset(sym, val + 1, 1);
>   free(sym);
>  
> Index: pfctl/parse.y
> ===
> RCS file: /cvs/src/sbin/pfctl/parse.y,v
> retrieving revision 1.685
> diff -u -p -u -r1.685 parse.y
> --- pfctl/parse.y 1 Nov 2018 00:18:44 -   1.685
> +++ pfctl/parse.y 1 Nov 2018 07:03:34 -
> @@ -5564,11 +5564,9 @@ pfctl_cmdline_symset(char *s)
>   if ((val = strrchr(s, '=')) == NULL)
>   return (-1);
>  
> - if ((sym = malloc(strlen(s) - strlen(val) + 1)) == NULL)
> + sym = strndup(s, val - s);  
> + if (sym == NULL);
>   err(1, "%s", __func__);
> -
> - strlcpy(sym, s, strlen(s) - strlen(val) + 1);
> -
>   ret = symset(sym, val + 1, 1);
>   free(sym);
>  



parse.y: strndup() in cmdline_symset()

2018-11-01 Thread Michael Mikonos
Hello,

When I updated cmdline_symset() in parse.y in the following commit
I missed src/sbin/{iked,ipsecctl,pfctl}/parse.y. OK to update them?

https://marc.info/?l=openbsd-cvs&m=153631079505256&w=2


Index: iked/parse.y
===
RCS file: /cvs/src/sbin/iked/parse.y,v
retrieving revision 1.76
diff -u -p -u -r1.76 parse.y
--- iked/parse.y1 Nov 2018 00:18:44 -   1.76
+++ iked/parse.y1 Nov 2018 07:03:31 -
@@ -1660,17 +1660,13 @@ cmdline_symset(char *s)
 {
char*sym, *val;
int ret;
-   size_t  len;
 
if ((val = strrchr(s, '=')) == NULL)
return (-1);
 
-   len = strlen(s) - strlen(val) + 1;
-   if ((sym = malloc(len)) == NULL)
+   sym = strndup(s, val - s);
+   if (sym == NULL)
err(1, "%s", __func__);
-
-   strlcpy(sym, s, len);
-
ret = symset(sym, val + 1, 1);
free(sym);
 
Index: ipsecctl/parse.y
===
RCS file: /cvs/src/sbin/ipsecctl/parse.y,v
retrieving revision 1.174
diff -u -p -u -r1.174 parse.y
--- ipsecctl/parse.y1 Nov 2018 00:18:44 -   1.174
+++ ipsecctl/parse.y1 Nov 2018 07:03:32 -
@@ -1426,17 +1426,13 @@ cmdline_symset(char *s)
 {
char*sym, *val;
int ret;
-   size_t  len;
 
if ((val = strrchr(s, '=')) == NULL)
return (-1);
 
-   len = strlen(s) - strlen(val) + 1;
-   if ((sym = malloc(len)) == NULL)
+   sym = strndup(s, val - s);
+   if (sym == NULL)
err(1, "%s", __func__);
-
-   strlcpy(sym, s, len);
-
ret = symset(sym, val + 1, 1);
free(sym);
 
Index: pfctl/parse.y
===
RCS file: /cvs/src/sbin/pfctl/parse.y,v
retrieving revision 1.685
diff -u -p -u -r1.685 parse.y
--- pfctl/parse.y   1 Nov 2018 00:18:44 -   1.685
+++ pfctl/parse.y   1 Nov 2018 07:03:34 -
@@ -5564,11 +5564,9 @@ pfctl_cmdline_symset(char *s)
if ((val = strrchr(s, '=')) == NULL)
return (-1);
 
-   if ((sym = malloc(strlen(s) - strlen(val) + 1)) == NULL)
+   sym = strndup(s, val - s);  
+   if (sym == NULL);
err(1, "%s", __func__);
-
-   strlcpy(sym, s, strlen(s) - strlen(val) + 1);
-
ret = symset(sym, val + 1, 1);
free(sym);