[PATCH] nsss_unix_shadow_get: parse null/empty fields

From: John Regan <john_at_jrjrtech.com>
Date: Fri, 28 Sep 2018 01:16:17 -0400

nsss_unix_shadow_get experiences a bug where entries with null
values aren't returned. This patch instead treats empty fields
as a null string or -1.
---
 src/libnsss/nsss_unix_shadow_get.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/libnsss/nsss_unix_shadow_get.c b/src/libnsss/nsss_unix_shadow_get.c
index 0d87088..18d61b6 100644
--- a/src/libnsss/nsss_unix_shadow_get.c
+++ b/src/libnsss/nsss_unix_shadow_get.c
_at_@ -1,6 +1,7 @@
 /* ISC license. */
 
 #include <pthread.h>
+#include <limits.h>
 #include <skalibs/types.h>
 #include <skalibs/skamisc.h>
 #include <nsss/shadow-def.h>
_at_@ -15,19 +16,18 @@ static inline int shadow_parseline (struct spwd *sp, char *s, size_t max)
   if (!nsss_unix_field(&sp2.sp_namp, &s)) return 0 ;
   if (!nsss_unix_field(&sp2.sp_pwdp, &s)) return 0 ;
   if (!nsss_unix_field(&p, &s)) return 0 ;
-  if (!ulong0_scan(p, (unsigned long *)&sp2.sp_lstchg)) return 0 ;
+  if (!ulong0_scan(p, (unsigned long *)&sp2.sp_lstchg)) sp2.sp_lstchg = -1 ;
   if (!nsss_unix_field(&p, &s)) return 0 ;
-  if (!ulong0_scan(p, (unsigned long *)&sp2.sp_min)) return 0 ;
+  if (!ulong0_scan(p, (unsigned long *)&sp2.sp_min)) sp2.sp_min = -1 ;
   if (!nsss_unix_field(&p, &s)) return 0 ;
-  if (!ulong0_scan(p, (unsigned long *)&sp2.sp_max)) return 0 ;
+  if (!ulong0_scan(p, (unsigned long *)&sp2.sp_max)) sp2.sp_max = -1 ;
   if (!nsss_unix_field(&p, &s)) return 0 ;
-  if (!ulong0_scan(p, (unsigned long *)&sp2.sp_warn)) return 0 ;
+  if (!ulong0_scan(p, (unsigned long *)&sp2.sp_warn)) sp2.sp_warn = -1 ;
   if (!nsss_unix_field(&p, &s)) return 0 ;
-  if (!ulong0_scan(p, (unsigned long *)&sp2.sp_inact)) return 0 ;
+  if (!ulong0_scan(p, (unsigned long *)&sp2.sp_inact)) sp2.sp_inact = -1 ;
   if (!nsss_unix_field(&p, &s)) return 0 ;
-  if (!ulong0_scan(p, (unsigned long *)&sp2.sp_expire)) return 0 ;
-  if (!nsss_unix_field(&p, &s)) return 0 ;
-  if (!ulong0_scan(p, &sp2.sp_flag)) return 0 ;
+  if (!ulong0_scan(p, (unsigned long *)&sp2.sp_expire)) sp2.sp_expire = -1 ;
+  if (!nsss_unix_field(&p, &s) || !ulong0_scan(p, &sp2.sp_flag)) sp2.sp_flag = ULONG_MAX ;
   *sp = sp2 ;
   return 1 ;
 }
-- 
1.8.3.1
Received on Fri Sep 28 2018 - 05:16:17 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:38:49 UTC