Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 9 Mar 2017 18:50:04 +0100
From:      "O. Hartmann" <ohartmann@walstatt.org>
To:        "Pedro F. Giffuni" <pfg@FreeBSD.org>
Cc:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r314961 - head/usr.bin/localedef
Message-ID:  <20170309185004.36c87595@thor.intern.walstatt.dynvpn.de>
In-Reply-To: <201703091521.v29FL3da010200@repo.freebsd.org>
References:  <201703091521.v29FL3da010200@repo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
--Sig_/f3l97cKOxFNVVDkp8FtVc7z
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Am Thu, 9 Mar 2017 15:21:03 +0000 (UTC)
"Pedro F. Giffuni" <pfg@FreeBSD.org> schrieb:

> Author: pfg
> Date: Thu Mar  9 15:21:03 2017
> New Revision: 314961
> URL: https://svnweb.freebsd.org/changeset/base/314961
>=20
> Log:
>   localedef(1): Fix for memory leaks reported by coverity.
>  =20
>   Also some small cleanups to match better current illumos.
>  =20
>   CID: 1338540, 1338541, 1338557, 1338566
>  =20
>   Obtained from:	illumos
>   Discussed with:	Yuri Pankov (@Nexenta)
>   MFC after:	5 days
>=20
> Modified:
>   head/usr.bin/localedef/collate.c
>   head/usr.bin/localedef/ctype.c
>   head/usr.bin/localedef/localedef.c
>   head/usr.bin/localedef/localedef.h
>   head/usr.bin/localedef/time.c
>=20
> Modified: head/usr.bin/localedef/collate.c
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
> --- head/usr.bin/localedef/collate.c	Thu Mar  9 13:41:57 2017	(r314960)
> +++ head/usr.bin/localedef/collate.c	Thu Mar  9 15:21:03 2017	(r314961)
> @@ -1,5 +1,5 @@
>  /*
> - * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
> + * Copyright 2017 Nexenta Systems, Inc.
>   * Copyright 2015 John Marino <draco@marino.st>
>   *
>   * This source code is derived from the illumos localedef command, and
> @@ -1291,21 +1291,25 @@ dump_collate(void)
>  	if ((wr_category(vers, COLLATE_STR_LEN, f) < 0) ||
>  	    (wr_category(&collinfo, sizeof (collinfo), f) < 0) ||
>  	    (wr_category(&chars, sizeof (chars), f) < 0)) {
> +	    	delete_category(f);
>  		return;
>  	}
> =20
>  	for (i =3D 0; i < NUM_WT; i++) {
>  		sz =3D  sizeof (collate_subst_t) * collinfo.subst_count[i];
>  		if (wr_category(subst[i], sz, f) < 0) {
> +			delete_category(f);
>  			return;
>  		}
>  	}
>  	sz =3D sizeof (collate_chain_t) * collinfo.chain_count;
>  	if (wr_category(chain, sz, f) < 0) {
> +		delete_category(f);
>  		return;
>  	}
>  	sz =3D sizeof (collate_large_t) * collinfo.large_count;
>  	if (wr_category(large, sz, f) < 0) {
> +		delete_category(f);
>  		return;
>  	}
> =20
>=20
> Modified: head/usr.bin/localedef/ctype.c
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
> --- head/usr.bin/localedef/ctype.c	Thu Mar  9 13:41:57 2017	(r314960)
> +++ head/usr.bin/localedef/ctype.c	Thu Mar  9 15:21:03 2017	(r314961)
> @@ -1,5 +1,5 @@
>  /*
> - * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
> + * Copyright 2017 Nexenta Systems, Inc.
>   * Copyright 2012 Garrett D'Amore <garrett@damore.org>  All rights reser=
ved.
>   * Copyright 2015 John Marino <draco@marino.st>
>   *
> @@ -306,7 +306,7 @@ dump_ctype(void)
>  		return;
> =20
>  	(void) memcpy(rl.magic, _FILE_RUNE_MAGIC_1, 8);
> -	(void) strncpy(rl.encoding, get_wide_encoding(), sizeof (rl.encoding));
> +	(void) strlcpy(rl.encoding, get_wide_encoding(), sizeof (rl.encoding));
> =20
>  	/*
>  	 * Initialize the identity map.
> @@ -379,12 +379,12 @@ dump_ctype(void)
>  		if ((ctn->ctype & _ISALPHA) &&
>  		    (ctn->ctype & (_ISPUNCT|_ISDIGIT)))
>  			conflict++;
> -		if ((ctn->ctype & _ISPUNCT) &
> +		if ((ctn->ctype & _ISPUNCT) &&
>  		    (ctn->ctype & (_ISDIGIT|_ISALPHA|_ISXDIGIT)))
>  			conflict++;
>  		if ((ctn->ctype & _ISSPACE) && (ctn->ctype & _ISGRAPH))
>  			conflict++;
> -		if ((ctn->ctype & _ISCNTRL) & _ISPRINT)
> +		if ((ctn->ctype & _ISCNTRL) && (ctn->ctype & _ISPRINT))
>  			conflict++;
>  		if ((wc =3D=3D ' ') && (ctn->ctype & (_ISPUNCT|_ISGRAPH)))
>  			conflict++;
> @@ -412,8 +412,10 @@ dump_ctype(void)
>  			ct[rl.runetype_ext_nranges-1].max =3D wc;
>  		} else {
>  			rl.runetype_ext_nranges++;
> -			ct =3D realloc(ct,
> -			    sizeof (*ct) * rl.runetype_ext_nranges);
> +			ct =3D realloc(ct, rl.runetype_ext_nranges *
> +			    sizeof (*ct));
> +			if (ct =3D=3D NULL)
> +			    goto fail;
>  			ct[rl.runetype_ext_nranges - 1].min =3D wc;
>  			ct[rl.runetype_ext_nranges - 1].max =3D wc;
>  			ct[rl.runetype_ext_nranges - 1].map =3D ctn->ctype;
> @@ -427,8 +429,10 @@ dump_ctype(void)
>  			last_lo =3D ctn;
>  		} else {
>  			rl.maplower_ext_nranges++;
> -			lo =3D realloc(lo,
> -			    sizeof (*lo) * rl.maplower_ext_nranges);
> +			lo =3D realloc(lo, rl.maplower_ext_nranges *
> +			    sizeof (*lo));
> +			if (lo =3D=3D NULL)
> +			    goto fail;
>  			lo[rl.maplower_ext_nranges - 1].min =3D wc;
>  			lo[rl.maplower_ext_nranges - 1].max =3D wc;
>  			lo[rl.maplower_ext_nranges - 1].map =3D ctn->tolower;
> @@ -443,8 +447,10 @@ dump_ctype(void)
>  			last_up =3D ctn;
>  		} else {
>  			rl.mapupper_ext_nranges++;
> -			up =3D realloc(up,
> -			    sizeof (*up) * rl.mapupper_ext_nranges);
> +			up =3D realloc(up, rl.mapupper_ext_nranges *
> +			    sizeof (*up));
> +			if (up =3D=3D NULL)
> +			    goto fail;
>  			up[rl.mapupper_ext_nranges - 1].min =3D wc;
>  			up[rl.mapupper_ext_nranges - 1].max =3D wc;
>  			up[rl.mapupper_ext_nranges - 1].map =3D ctn->toupper;
> @@ -452,12 +458,17 @@ dump_ctype(void)
>  		}
>  	}
> =20
> -	if ((wr_category(&rl, sizeof (rl), f) < 0) ||
> -	    (wr_category(ct, sizeof (*ct) * rl.runetype_ext_nranges, f) < 0) ||
> -	    (wr_category(lo, sizeof (*lo) * rl.maplower_ext_nranges, f) < 0) ||
> -	    (wr_category(up, sizeof (*up) * rl.mapupper_ext_nranges, f) < 0)) {
> -		return;
> +	if ((wr_category(&rl, sizeof (rl), f) =3D=3D 0) &&
> +	    (wr_category(ct, sizeof (*ct) * rl.runetype_ext_nranges, f) =3D=3D =
0) &&
> +	    (wr_category(lo, sizeof (*lo) * rl.maplower_ext_nranges, f) =3D=3D =
0) &&
> +	    (wr_category(up, sizeof (*up) * rl.mapupper_ext_nranges, f) =3D=3D =
0)) {
> +		close_category(f);
> +		goto out;
>  	}
> =20
> -	close_category(f);
> -}
> +fail:
> +	delete_category(f);
> +out:
> +	free(ct);
> +	free(lo);
> +	free(up);}
>=20
> Modified: head/usr.bin/localedef/localedef.c
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
> --- head/usr.bin/localedef/localedef.c	Thu Mar  9 13:41:57 2017	(r314960)
> +++ head/usr.bin/localedef/localedef.c	Thu Mar  9 15:21:03 2017	(r314961)
> @@ -1,5 +1,5 @@
>  /*
> - * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
> + * Copyright 2017 Nexenta Systems, Inc.
>   * Copyright 2015 John Marino <draco@marino.st>
>   *
>   * This source code is derived from the illumos localedef command, and
> @@ -126,12 +126,21 @@ open_category(void)
>  }
> =20
>  void
> +delete_category(FILE *f)
> +{
> +	(void) fclose(f);
> +	(void) unlink(category_file());
> +}
> +
> +void
>  close_category(FILE *f)
>  {
> -	if (fchmod(fileno(f), 0644) < 0) {
> +	if (fchmod(fileno(f), 0644) < 0 ||
> +	    fclose(f) !=3D 0) {
>  		(void) fclose(f);
>  		(void) unlink(category_file());
>  		errf(strerror(errno));
> +		delete_category(f);
>  	}
>  	if (fclose(f) < 0) {
>  		(void) unlink(category_file());
> @@ -193,15 +202,13 @@ int
>  putl_category(const char *s, FILE *f)
>  {
>  	if (s && fputs(s, f) =3D=3D EOF) {
> -		(void) fclose(f);
> -		(void) unlink(category_file());
>  		errf(strerror(errno));
> +		delete_category(f);
>  		return (EOF);
>  	}
>  	if (fputc('\n', f) =3D=3D EOF) {
> -		(void) fclose(f);
> -		(void) unlink(category_file());
>  		errf(strerror(errno));
> +		delete_category(f);
>  		return (EOF);
>  	}
>  	return (0);
> @@ -214,9 +221,8 @@ wr_category(void *buf, size_t sz, FILE *
>  		return (0);
>  	}
>  	if (fwrite(buf, sz, 1, f) < 1) {
> -		(void) fclose(f);
> -		(void) unlink(category_file());
>  		errf(strerror(errno));
> +		delete_category(f);
>  		return (EOF);
>  	}
>  	return (0);
>=20
> Modified: head/usr.bin/localedef/localedef.h
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
> --- head/usr.bin/localedef/localedef.h	Thu Mar  9 13:41:57 2017	(r314960)
> +++ head/usr.bin/localedef/localedef.h	Thu Mar  9 15:21:03 2017	(r314961)
> @@ -1,5 +1,5 @@
>  /*
> - * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
> + * Copyright 2017 Nexenta Systems, Inc.
>   * Copyright 2015 John Marino <draco@marino.st>
>   *
>   * This source code is derived from the illumos localedef command, and
> @@ -60,6 +60,7 @@ void warn(const char *, ...);
>  int putl_category(const char *, FILE *);
>  int wr_category(void *, size_t, FILE *);
>  FILE *open_category(void);
> +void delete_category(FILE *);
>  void close_category(FILE *);
>  void copy_category(char *);
>  const char *category_name(void);
>=20
> Modified: head/usr.bin/localedef/time.c
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
> --- head/usr.bin/localedef/time.c	Thu Mar  9 13:41:57 2017	(r314960)
> +++ head/usr.bin/localedef/time.c	Thu Mar  9 15:21:03 2017	(r314961)
> @@ -1,5 +1,5 @@
>  /*
> - * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
> + * Copyright 2017 Nexenta Systems, Inc.
>   * Copyright 2015 John Marino <draco@marino.st>
>   *
>   * This source code is derived from the illumos localedef command, and
> @@ -78,7 +78,7 @@ add_time_str(wchar_t *wcs)
>  		break;
>  	case T_DATE_FMT:
>  		/*
> -		 * This one is a Solaris extension, Too bad date just
> +		 * This one is a Solaris extension. Too bad date just
>  		 * doesn't use %c, which would be simpler.
>  		 */
>  		tm.date_fmt =3D str;
> _______________________________________________
> svn-src-head@freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/svn-src-head
> To unsubscribe, send any mail to "svn-src-head-unsubscribe@freebsd.org"

Something broke buildworld, I presume:

/usr/src/share/colldef/af_ZA.UTF-8.src: 2421: error: Bad file descriptor
*** [af_ZA.ISO8859-1.LC_COLLATE] Error code 4

make[4]: stopped in /usr/src/share/colldef
.ERROR_TARGET=3D'af_ZA.ISO8859-1.LC_COLLATE'


--=20
O. Hartmann

Ich widerspreche der Nutzung oder =C3=9Cbermittlung meiner Daten f=C3=BCr
Werbezwecke oder f=C3=BCr die Markt- oder Meinungsforschung (=C2=A7 28 Abs.=
 4 BDSG).

--Sig_/f3l97cKOxFNVVDkp8FtVc7z
Content-Type: application/pgp-signature
Content-Description: OpenPGP digital signature

-----BEGIN PGP SIGNATURE-----

iLUEARMKAB0WIQQZVZMzAtwC2T/86TrS528fyFhYlAUCWMGVzAAKCRDS528fyFhY
lIxtAgCHuHgtx/EtvqPpaU8d0I1BdUwMwE8lDZOSb6xdnLzZm3d3+3hzGKGKKl6Y
Ww44YQQUrzYl66n9DgO39gdxt2cOAf9WXz7kP84FLP2nSP6v4QLVIl1HQSGlzgOw
J5o+q6BkOEqAUL8OISgif50s7PGhDhcSHAnLLrmojNw1qyGan9YK
=9sGc
-----END PGP SIGNATURE-----

--Sig_/f3l97cKOxFNVVDkp8FtVc7z--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20170309185004.36c87595>