From ed1b9eb881714d81d85f14afa35f51254e80d5b6 Mon Sep 17 00:00:00 2001 From: miko Date: Fri, 7 Sep 2018 07:35:30 +0000 Subject: replace malloc()+strlcpy() with strndup() in cmdline_symset(). "looks good" gilles@ halex@ --- usr.sbin/acme-client/parse.y | 13 ++++--------- usr.sbin/bgpd/parse.y | 13 ++++--------- usr.sbin/dvmrpd/parse.y | 13 ++++--------- usr.sbin/eigrpd/parse.y | 13 ++++--------- usr.sbin/httpd/parse.y | 13 ++++--------- usr.sbin/ifstated/parse.y | 11 +++-------- usr.sbin/iscsictl/parse.y | 13 ++++--------- usr.sbin/ldapd/parse.y | 13 ++++--------- usr.sbin/ldpd/parse.y | 13 ++++--------- usr.sbin/lpd/parse.y | 13 ++++--------- usr.sbin/ospf6d/parse.y | 13 ++++--------- usr.sbin/ospfd/parse.y | 13 ++++--------- usr.sbin/rad/parse.y | 13 ++++--------- usr.sbin/relayd/parse.y | 13 ++++--------- usr.sbin/ripd/parse.y | 13 ++++--------- usr.sbin/smtpd/parse.y | 13 ++++--------- usr.sbin/snmpd/parse.y | 13 ++++--------- usr.sbin/switchd/parse.y | 13 ++++--------- usr.sbin/vmd/parse.y | 13 ++++--------- usr.sbin/ypldap/parse.y | 13 ++++--------- 20 files changed, 79 insertions(+), 179 deletions(-) diff --git a/usr.sbin/acme-client/parse.y b/usr.sbin/acme-client/parse.y index a6ecdda6fe3..bcc8325506a 100644 --- a/usr.sbin/acme-client/parse.y +++ b/usr.sbin/acme-client/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.29 2018/08/03 17:57:21 benno Exp $ */ +/* $OpenBSD: parse.y,v 1.30 2018/09/07 07:35:30 miko Exp $ */ /* * Copyright (c) 2016 Kristaps Dzonsons @@ -839,17 +839,12 @@ 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) - errx(EXIT_FAILURE, "cmdline_symset: malloc"); - - strlcpy(sym, s, len); - + sym = strndup(s, val - s); + if (sym == NULL) + errx(EXIT_FAILURE, "%s: strndup", __func__); ret = symset(sym, val + 1, 1); free(sym); diff --git a/usr.sbin/bgpd/parse.y b/usr.sbin/bgpd/parse.y index 3554d6cada5..0778e2ebf5d 100644 --- a/usr.sbin/bgpd/parse.y +++ b/usr.sbin/bgpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.334 2018/09/07 05:43:33 claudio Exp $ */ +/* $OpenBSD: parse.y,v 1.335 2018/09/07 07:35:30 miko Exp $ */ /* * Copyright (c) 2002, 2003, 2004 Henning Brauer @@ -3213,17 +3213,12 @@ 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) - fatal("cmdline_symset: malloc"); - - strlcpy(sym, s, len); - + sym = strndup(s, val - s); + if (sym == NULL) + fatal("%s: strndup", __func__); ret = symset(sym, val + 1, 1); free(sym); diff --git a/usr.sbin/dvmrpd/parse.y b/usr.sbin/dvmrpd/parse.y index 4cde820bf4b..65966206072 100644 --- a/usr.sbin/dvmrpd/parse.y +++ b/usr.sbin/dvmrpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.36 2018/07/11 07:39:22 krw Exp $ */ +/* $OpenBSD: parse.y,v 1.37 2018/09/07 07:35:30 miko Exp $ */ /* * Copyright (c) 2004, 2005, 2006 Esben Norby @@ -834,17 +834,12 @@ 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) - errx(1, "cmdline_symset: malloc"); - - strlcpy(sym, s, len); - + sym = strndup(s, val - s); + if (sym == NULL) + errx(1, "%s: strndup", __func__); ret = symset(sym, val + 1, 1); free(sym); diff --git a/usr.sbin/eigrpd/parse.y b/usr.sbin/eigrpd/parse.y index eedb3a7e162..1bb69f092c5 100644 --- a/usr.sbin/eigrpd/parse.y +++ b/usr.sbin/eigrpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.27 2018/07/11 07:39:22 krw Exp $ */ +/* $OpenBSD: parse.y,v 1.28 2018/09/07 07:35:30 miko Exp $ */ /* * Copyright (c) 2015 Renato Westphal @@ -1094,17 +1094,12 @@ 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) - errx(1, "cmdline_symset: malloc"); - - strlcpy(sym, s, len); - + sym = strndup(s, val - s); + if (sym == NULL) + errx(1, "%s: strndup", __func__); ret = symset(sym, val + 1, 1); free(sym); diff --git a/usr.sbin/httpd/parse.y b/usr.sbin/httpd/parse.y index 962af87ffc2..4851182f5cd 100644 --- a/usr.sbin/httpd/parse.y +++ b/usr.sbin/httpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.105 2018/07/11 07:39:22 krw Exp $ */ +/* $OpenBSD: parse.y,v 1.106 2018/09/07 07:35:30 miko Exp $ */ /* * Copyright (c) 2007 - 2015 Reyk Floeter @@ -1819,17 +1819,12 @@ 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) - errx(1, "cmdline_symset: malloc"); - - (void)strlcpy(sym, s, len); - + sym = strndup(s, val - s); + if (sym == NULL) + errx(1, "%s: strndup", __func__); ret = symset(sym, val + 1, 1); free(sym); diff --git a/usr.sbin/ifstated/parse.y b/usr.sbin/ifstated/parse.y index 93feda6fddb..11577a6ca11 100644 --- a/usr.sbin/ifstated/parse.y +++ b/usr.sbin/ifstated/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.52 2018/07/11 07:39:22 krw Exp $ */ +/* $OpenBSD: parse.y,v 1.53 2018/09/07 07:35:31 miko Exp $ */ /* * Copyright (c) 2004 Ryan McBride @@ -871,17 +871,12 @@ 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); diff --git a/usr.sbin/iscsictl/parse.y b/usr.sbin/iscsictl/parse.y index 12262e8ee0e..e86657fa633 100644 --- a/usr.sbin/iscsictl/parse.y +++ b/usr.sbin/iscsictl/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.15 2018/07/11 07:39:22 krw Exp $ */ +/* $OpenBSD: parse.y,v 1.16 2018/09/07 07:35:31 miko Exp $ */ /* * Copyright (c) 2010 David Gwynne @@ -739,17 +739,12 @@ 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) - errx(1, "cmdline_symset: malloc"); - - strlcpy(sym, s, len); - + sym = strndup(s, val - s); + if (sym == NULL) + errx(1, "%s: strndup", __func__); ret = symset(sym, val + 1, 1); free(sym); diff --git a/usr.sbin/ldapd/parse.y b/usr.sbin/ldapd/parse.y index c0082ce3ee9..e33fea03a39 100644 --- a/usr.sbin/ldapd/parse.y +++ b/usr.sbin/ldapd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.32 2018/07/11 07:39:22 krw Exp $ */ +/* $OpenBSD: parse.y,v 1.33 2018/09/07 07:35:31 miko Exp $ */ /* * Copyright (c) 2009, 2010 Martin Hedenfalk @@ -911,17 +911,12 @@ 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) - fatal("cmdline_symset: malloc"); - - strlcpy(sym, s, len); - + sym = strndup(s, val - s); + if (sym == NULL) + fatal("%s: strndup", __func__); ret = symset(sym, val + 1, 1); free(sym); diff --git a/usr.sbin/ldpd/parse.y b/usr.sbin/ldpd/parse.y index cc70041d4d9..5197bb0c368 100644 --- a/usr.sbin/ldpd/parse.y +++ b/usr.sbin/ldpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.65 2018/07/11 07:39:22 krw Exp $ */ +/* $OpenBSD: parse.y,v 1.66 2018/09/07 07:35:31 miko Exp $ */ /* * Copyright (c) 2013, 2015, 2016 Renato Westphal @@ -1317,17 +1317,12 @@ 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) - errx(1, "cmdline_symset: malloc"); - - strlcpy(sym, s, len); - + sym = strndup(s, val - s); + if (sym == NULL) + errx(1, "%s: strndup", __func__); ret = symset(sym, val + 1, 1); free(sym); diff --git a/usr.sbin/lpd/parse.y b/usr.sbin/lpd/parse.y index eae721cf2ab..324076cb4d3 100644 --- a/usr.sbin/lpd/parse.y +++ b/usr.sbin/lpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.3 2018/07/11 07:39:22 krw Exp $ */ +/* $OpenBSD: parse.y,v 1.4 2018/09/07 07:35:31 miko Exp $ */ /* * Copyright (c) 2008 Gilles Chehade @@ -682,17 +682,12 @@ 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) - errx(1, "%s", __func__); - - (void)strlcpy(sym, s, len); - + sym = strndup(s, val - s); + if (sym == NULL) + errx(1, "%s: strndup", __func__); ret = symset(sym, val + 1, 1); free(sym); diff --git a/usr.sbin/ospf6d/parse.y b/usr.sbin/ospf6d/parse.y index 2b2476d0606..6b5ff9591a3 100644 --- a/usr.sbin/ospf6d/parse.y +++ b/usr.sbin/ospf6d/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.38 2018/07/12 13:45:03 remi Exp $ */ +/* $OpenBSD: parse.y,v 1.39 2018/09/07 07:35:31 miko Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby @@ -1095,17 +1095,12 @@ 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) - errx(1, "cmdline_symset: malloc"); - - strlcpy(sym, s, len); - + sym = strndup(s, val - s); + if (sym == NULL) + errx(1, "%s: strndup", __func__); ret = symset(sym, val + 1, 1); free(sym); diff --git a/usr.sbin/ospfd/parse.y b/usr.sbin/ospfd/parse.y index 2333711c1e1..439ce8c831b 100644 --- a/usr.sbin/ospfd/parse.y +++ b/usr.sbin/ospfd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.91 2018/07/11 07:39:22 krw Exp $ */ +/* $OpenBSD: parse.y,v 1.92 2018/09/07 07:35:31 miko Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby @@ -1294,17 +1294,12 @@ 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) - errx(1, "cmdline_symset: malloc"); - - strlcpy(sym, s, len); - + sym = strndup(s, val - s); + if (sym == NULL) + errx(1, "%s: strndup", __func__); ret = symset(sym, val + 1, 1); free(sym); diff --git a/usr.sbin/rad/parse.y b/usr.sbin/rad/parse.y index 45947eed6f8..87acb6f3175 100644 --- a/usr.sbin/rad/parse.y +++ b/usr.sbin/rad/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.8 2018/08/03 13:14:46 florian Exp $ */ +/* $OpenBSD: parse.y,v 1.9 2018/09/07 07:35:31 miko Exp $ */ /* * Copyright (c) 2018 Florian Obser @@ -914,17 +914,12 @@ 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) - errx(1, "cmdline_symset: malloc"); - - strlcpy(sym, s, len); - + sym = strndup(s, val - s); + if (sym == NULL) + errx(1, "%s: strndup", __func__); ret = symset(sym, val + 1, 1); free(sym); diff --git a/usr.sbin/relayd/parse.y b/usr.sbin/relayd/parse.y index 2af04c27bd9..c3fa2aef4dd 100644 --- a/usr.sbin/relayd/parse.y +++ b/usr.sbin/relayd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.227 2018/08/06 17:31:31 benno Exp $ */ +/* $OpenBSD: parse.y,v 1.228 2018/09/07 07:35:31 miko Exp $ */ /* * Copyright (c) 2007 - 2014 Reyk Floeter @@ -2902,17 +2902,12 @@ 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) - errx(1, "cmdline_symset: malloc"); - - (void)strlcpy(sym, s, len); - + sym = strndup(s, val - s); + if (sym == NULL) + errx(1, "%s: strndup", __func__); ret = symset(sym, val + 1, 1); free(sym); diff --git a/usr.sbin/ripd/parse.y b/usr.sbin/ripd/parse.y index a67f9aa1cc0..be6e1ede45c 100644 --- a/usr.sbin/ripd/parse.y +++ b/usr.sbin/ripd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.41 2018/07/11 07:39:22 krw Exp $ */ +/* $OpenBSD: parse.y,v 1.42 2018/09/07 07:35:31 miko Exp $ */ /* * Copyright (c) 2006 Michele Marchetto @@ -850,17 +850,12 @@ 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) - errx(1, "cmdline_symset: malloc"); - - strlcpy(sym, s, len); - + sym = strndup(s, val - s); + if (sym == NULL) + errx(1, "%s: strndup", __func__); ret = symset(sym, val + 1, 1); free(sym); diff --git a/usr.sbin/smtpd/parse.y b/usr.sbin/smtpd/parse.y index 3e6bcd7d5d8..d80fd6e9590 100644 --- a/usr.sbin/smtpd/parse.y +++ b/usr.sbin/smtpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.220 2018/09/05 08:47:34 gilles Exp $ */ +/* $OpenBSD: parse.y,v 1.221 2018/09/07 07:35:31 miko Exp $ */ /* * Copyright (c) 2008 Gilles Chehade @@ -2124,17 +2124,12 @@ 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) - errx(1, "cmdline_symset: malloc"); - - (void)strlcpy(sym, s, len); - + sym = strndup(s, val - s); + if (sym == NULL) + errx(1, "%s: strndup", __func__); ret = symset(sym, val + 1, 1); free(sym); diff --git a/usr.sbin/snmpd/parse.y b/usr.sbin/snmpd/parse.y index f4ac69a1701..f9a878b7828 100644 --- a/usr.sbin/snmpd/parse.y +++ b/usr.sbin/snmpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.51 2018/07/11 07:39:22 krw Exp $ */ +/* $OpenBSD: parse.y,v 1.52 2018/09/07 07:35:31 miko Exp $ */ /* * Copyright (c) 2007, 2008, 2012 Reyk Floeter @@ -1127,17 +1127,12 @@ 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) - errx(1, "cmdline_symset: malloc"); - - (void)strlcpy(sym, s, len); - + sym = strndup(s, val - s); + if (sym == NULL) + errx(1, "%s: strndup", __func__); ret = symset(sym, val + 1, 1); free(sym); diff --git a/usr.sbin/switchd/parse.y b/usr.sbin/switchd/parse.y index 81ab0dafd81..191e720e3a7 100644 --- a/usr.sbin/switchd/parse.y +++ b/usr.sbin/switchd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.10 2018/07/11 07:39:22 krw Exp $ */ +/* $OpenBSD: parse.y,v 1.11 2018/09/07 07:35:31 miko Exp $ */ /* * Copyright (c) 2007-2016 Reyk Floeter @@ -705,17 +705,12 @@ cmdline_symset(char *s) { char *sym, *val; int ret; - size_t len; if ((val = strrchr(s, '=')) == NULL) return (-1); - - len = (val - s) + 1; - if ((sym = malloc(len)) == NULL) - fatal("cmdline_symset: malloc"); - - (void)strlcpy(sym, s, len); - + sym = strndup(s, val - s); + if (sym == NULL) + fatal("%s: strndup", __func__); ret = symset(sym, val + 1, 1); free(sym); diff --git a/usr.sbin/vmd/parse.y b/usr.sbin/vmd/parse.y index 2b159d9b866..13cb3e3ce3f 100644 --- a/usr.sbin/vmd/parse.y +++ b/usr.sbin/vmd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.42 2018/07/13 08:42:49 reyk Exp $ */ +/* $OpenBSD: parse.y,v 1.43 2018/09/07 07:35:31 miko Exp $ */ /* * Copyright (c) 2007-2016 Reyk Floeter @@ -1154,17 +1154,12 @@ cmdline_symset(char *s) { char *sym, *val; int ret; - size_t len; if ((val = strrchr(s, '=')) == NULL) return (-1); - - len = (val - s) + 1; - if ((sym = malloc(len)) == NULL) - fatal("cmdline_symset: malloc"); - - (void)strlcpy(sym, s, len); - + sym = strndup(s, val - s); + if (sym == NULL) + fatal("%s: strndup", __func__); ret = symset(sym, val + 1, 1); free(sym); diff --git a/usr.sbin/ypldap/parse.y b/usr.sbin/ypldap/parse.y index c55e8ab876b..6048a3586c9 100644 --- a/usr.sbin/ypldap/parse.y +++ b/usr.sbin/ypldap/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.28 2018/07/11 07:39:22 krw Exp $ */ +/* $OpenBSD: parse.y,v 1.29 2018/09/07 07:35:31 miko Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard @@ -930,17 +930,12 @@ 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) - errx(1, "%s", __func__); - - (void)strlcpy(sym, s, len); - + sym = strndup(s, val - s); + if (sym == NULL) + errx(1, "%s: strndup", __func__); ret = symset(sym, val + 1, 1); free(sym); -- cgit v1.2.3-59-g8ed1b