From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13608 Path: news.gmane.org!.POSTED!not-for-mail From: "A. Wilcox" Newsgroups: gmane.linux.lib.musl.general Subject: Re: function: fgetspent_r Date: Wed, 16 Jan 2019 15:38:06 -0600 Organization: =?UTF-8?Q?Ad=c3=a9lie_Linux?= Message-ID: References: <4ac5ac1b-217f-442f-fc35-bfbf015287bb@adelielinux.org> <20190116205046.GK23599@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="K0H9PUk9lHHGsL33l45B8uPWpK3t5z3s1" X-Trace: blaine.gmane.org 1547674547 18249 195.159.176.226 (16 Jan 2019 21:35:47 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 16 Jan 2019 21:35:47 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux ppc64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 To: musl@lists.openwall.com Original-X-From: musl-return-13624-gllmg-musl=m.gmane.org@lists.openwall.com Wed Jan 16 22:35:43 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1gjsqd-0004cz-1c for gllmg-musl@m.gmane.org; Wed, 16 Jan 2019 22:35:43 +0100 Original-Received: (qmail 28578 invoked by uid 550); 16 Jan 2019 21:37:52 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 28545 invoked from network); 16 Jan 2019 21:37:51 -0000 Openpgp: preference=signencrypt In-Reply-To: <20190116205046.GK23599@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:13608 Archived-At: This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --K0H9PUk9lHHGsL33l45B8uPWpK3t5z3s1 Content-Type: multipart/mixed; boundary="wNxTn5jNuRMjNNuWZFesFKAoOg3wzxb2e"; protected-headers="v1" From: "A. Wilcox" To: musl@lists.openwall.com Message-ID: Subject: Re: [musl] function: fgetspent_r References: <4ac5ac1b-217f-442f-fc35-bfbf015287bb@adelielinux.org> <20190116205046.GK23599@brightrain.aerifal.cx> In-Reply-To: <20190116205046.GK23599@brightrain.aerifal.cx> --wNxTn5jNuRMjNNuWZFesFKAoOg3wzxb2e Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 01/16/19 14:50, Rich Felker wrote: > On Wed, Jan 16, 2019 at 01:21:39PM -0600, A. Wilcox wrote: >> Hi muslers, >> >> fgetspent_r[1] is a re-entrant version of fgetspent which stores all >> strings in a caller-provided buffer to ensure that the memory is owned= >> by the caller instead of by the system. >> >> It is present in Solaris 9[2] and higher, and glibc[3] Linux. It is >> used by AccountsService[4]. >> >> Is it possible to add this API to musl? I could try to write it, if s= o. >> >> Best, >> --arw >> >> >> [1]: https://docs.oracle.com/cd/E88353_01/html/E37843/getspent-r-3c.ht= ml >> >> [2]: https://docs.oracle.com/cd/E19683-01/816-5214/6mbcfdl0v/index.htm= l >> >> [3]: https://linux.die.net/man/3/getspnam_r >> >> [4]: https://cgit.freedesktop.org/accountsservice/commit/?id=3D14ca424= 5 >=20 > I don't see any good reason why it couldn't be added, but it doesn't > look like a direct refactoring of the existing function since it uses > the messy char[] buffer idiom like a bunch of other _r functions in > this family. What do you mean by "messy char[] buffer idiom"? The buffer that is meant to contain the strings is passed to the function (char *buf), *not* returned by it. > I'm also not sure what should happen if the next entry > does not fit in the buffer. Should it discard the rest of the line and > move on (not retryable) or attempt to seek back? The Solaris docs specify: fgetspent_r() [ ... ] return a pointer to a struct spwd if they successfully enumerate an entry; otherwise they return NULL, indicating the end of the enumeration. The reentrant functions getspnam_r(), getspent_r(), and fgetspent_r() will return NULL and set errno to ERANGE if the length of the buffer supplied by caller is not large enough to store the result. The glibc docs specify: A pointer to the result (in case of success) or NULL (in case no entry was found or an error occurred) is stored in *spbufp. The reentrant functions return zero on success. In case of error, an error number is returned. ERANGE: Supplied buffer is too small. It seems like "end of file" and "error" are treated the same. In any case, it would appear to me that it's UB to continue iterating once NULL is returned. I would personally leave the fp where it is (not rewind) since all the other *get*ent functions don't rewind on error either. Best, --arw --=20 A. Wilcox (awilfox) Project Lead, Ad=C3=A9lie Linux https://www.adelielinux.org --wNxTn5jNuRMjNNuWZFesFKAoOg3wzxb2e-- --K0H9PUk9lHHGsL33l45B8uPWpK3t5z3s1 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEjNyWOYPU1SaTSMHHyynLUZIrnRQFAlw/pD4ACgkQyynLUZIr nRRVjRAA0bMjbarcLdXQh0zcp47vTs0E782/gB1mAa09BX5NgtmYUO1v/tay1UP0 I/o/mqhCRRy4zYd82jMnx0aSEYIvR9k7pun8r37YX3rCS2IMAzMXxsGwG5Zow5X5 UtLz/hd+iNTXvrEANY611qNpUYSLNiAR2Z8WnBM0zBfJSOgtkgoAGuKSFF4wxE1s rN4W8J1AagDseCQlgvArIu8Z9l3l84B8vK5Hzy+X0kLZ5I3OiLMEyC9zoutQ6Y8z vNX1nUZ+aB6TwI41DW9u8wrNtLUTqggYmNIn3P7OMlU7VXL64euRpNfiUMs71A+Y VkfOCIigMRhEZw+5luZepc0K6a2v+/F5xsgjkDp6d1j60NwmBcEhKvD359J3KQ70 wlGYMfn2ei3qWf/v0o0pAPDwxO3iUaNvVuU9vufQlst3355QvXCRmsqpoqJZ4l2O ZQ3T6a6lBN3Q7n4JT++hv18PABIERhVoEKWOPT/ykBtyLK1eBe7veNvv7on1sqvE +um4qzmCD+405wJrVCnjuRgzM+br6IxjPbgziC1sFIPvDTyMY1rZQtlCr7uTj14J Cg9QUr7k5gt7niqV57rd2qxYHvW66eKP32HkqEerC+zHlnq9NLEWv2bsW83y/EOT eOstl+O/hwkbICrkAb2J+Ttkx0kt4E0uA5WR/Pv2iJRyFZXGEAY= =o7eg -----END PGP SIGNATURE----- --K0H9PUk9lHHGsL33l45B8uPWpK3t5z3s1--