From 106b948b01ce817f9de41aa3c06f22798c3184b9 Mon Sep 17 00:00:00 2001 From: Enno Boland Date: Mon, 26 Mar 2018 13:14:51 +0200 Subject: [PATCH] accountsservice: write new musl patch that does more than just compile --- .../patches/musl-fgetspent_r.patch | 60 +++++++++---------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/srcpkgs/accountsservice/patches/musl-fgetspent_r.patch b/srcpkgs/accountsservice/patches/musl-fgetspent_r.patch index 7940ca87104..57ea3343846 100644 --- a/srcpkgs/accountsservice/patches/musl-fgetspent_r.patch +++ b/srcpkgs/accountsservice/patches/musl-fgetspent_r.patch @@ -1,34 +1,32 @@ -Musl libc does not support fgetspent_r(), so fall back -to using the non-thread-safe fgetspent() function. - ---- src/daemon.c 2016-09-06 21:48:50.000000000 +0200 -+++ src/daemon.c 2016-11-25 10:41:01.614534302 +0100 -@@ -174,7 +174,7 @@ - int ret = 0; +diff --git a/src/daemon.c b/src/daemon.c +index 312394a..e7b3c58 100644 +--- src/daemon.c ++++ src/daemon.c +@@ -140,6 +140,26 @@ error_get_type (void) + #define MAX_LOCAL_USERS 50 + #endif - shadow_entry_buffers = g_malloc0 (sizeof (*shadow_entry_buffers)); -- -+#if defined(__GLIBC__) - ret = fgetspent_r (fp, &shadow_entry_buffers->spbuf, shadow_entry_buffers->buf, sizeof (shadow_entry_buffers->buf), &shadow_entry); - if (ret == 0) { - g_hash_table_insert (shadow_users, g_strdup (shadow_entry->sp_namp), shadow_entry_buffers); -@@ -185,6 +185,19 @@ - break; - } - } -+#else -+ /* Musl libc does not support fgetspent_r(), so fall back -+ * to using the non-thread-safe fgetspent() function. -+ */ -+ shadow_entry = fgetspent(fp); -+ if (shadow_entry == NULL) { -+ g_free (shadow_entry_buffers); ++#ifndef __GLIBC__ ++ /* Musl libc does not support fgetspent_r(), write own ++ * wrapper ++ */ ++static int fgetspent_r(FILE *fp, struct spwd *spbuf, char *buf, size_t buflen, struct spwd **spbufp) { ++ struct spwd *shadow_entry = fgetspent(fp); ++ size_t namplen = strlen(shadow_entry->sp_namp); ++ size_t pwdplen = strlen(shadow_entry->sp_pwdp); + -+ if (errno != EINTR) { -+ break; -+ } -+ } ++ if(namplen + pwdplen + 2 > buflen) ++ return -1; ++ ++ *spbufp = memcpy(spbuf, shadow_entry, sizeof(struct spwd)); ++ spbuf->sp_namp = strncpy(buf, shadow_entry->sp_namp, namplen + 1); ++ spbuf->sp_pwdp = strncpy(buf + namplen + 1, shadow_entry->sp_pwdp, pwdplen + 1); ++ ++ return 0; ++} +#endif - } while (shadow_entry != NULL); - - fclose (fp); ++ + static struct passwd * + entry_generator_fgetpwent (Daemon *daemon, + GHashTable *users, +