mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] musl: bugfix getspnam_r negative
@ 2019-05-16  2:31 chenjie6
  2019-05-16  8:03 ` Szabolcs Nagy
  0 siblings, 1 reply; 2+ messages in thread
From: chenjie6 @ 2019-05-16  2:31 UTC (permalink / raw)
  To: rtweed; +Cc: musl, chen jie

From: chen jie <chenjie6@huawei.com>

The /etc/shadow contain:
sshd:*:11880:0:90:7:-1:-1:0
the *s can not ++; __parsespent will not keep going down

Signed-off-by: jie chen<chenjie6@huawei.com>
---
 src/passwd/getspnam_r.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/passwd/getspnam_r.c b/src/passwd/getspnam_r.c
index 541e8531..1cb55bcd 100644
--- a/src/passwd/getspnam_r.c
+++ b/src/passwd/getspnam_r.c
@@ -15,8 +15,16 @@
 static long xatol(char **s)
 {
 	long x;
+	int sign;
+
 	if (**s == ':' || **s == '\n') return -1;
+
+	sign = (int)(unsigned char)**s;
+	if (sign == '-' || sign == '+') ++*s;
+
 	for (x=0; **s-'0'<10U; ++*s) x=10*x+(**s-'0');
+
+	if (sign == '-') return -x;
 	return x;
 }
 
-- 
2.18.GIT



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] musl: bugfix getspnam_r negative
  2019-05-16  2:31 [PATCH] musl: bugfix getspnam_r negative chenjie6
@ 2019-05-16  8:03 ` Szabolcs Nagy
  0 siblings, 0 replies; 2+ messages in thread
From: Szabolcs Nagy @ 2019-05-16  8:03 UTC (permalink / raw)
  To: musl; +Cc: rtweed, chen jie

* chenjie6@huawei.com <chenjie6@huawei.com> [2019-05-16 02:31:04 +0000]:
> From: chen jie <chenjie6@huawei.com>
> 
> The /etc/shadow contain:
> sshd:*:11880:0:90:7:-1:-1:0

note that it is not documented what -1 day means here.
http://man7.org/linux/man-pages/man5/shadow.5.html

glibc uses -1 internally to mark empty fields and parses
the field as signed int, so it happens to work, but you
may want to fix your /etc/shadow to match the specs.

> the *s can not ++; __parsespent will not keep going down
> 
> Signed-off-by: jie chen<chenjie6@huawei.com>
> ---
>  src/passwd/getspnam_r.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/src/passwd/getspnam_r.c b/src/passwd/getspnam_r.c
> index 541e8531..1cb55bcd 100644
> --- a/src/passwd/getspnam_r.c
> +++ b/src/passwd/getspnam_r.c
> @@ -15,8 +15,16 @@
>  static long xatol(char **s)
>  {
>  	long x;
> +	int sign;
> +
>  	if (**s == ':' || **s == '\n') return -1;
> +
> +	sign = (int)(unsigned char)**s;
> +	if (sign == '-' || sign == '+') ++*s;
> +
>  	for (x=0; **s-'0'<10U; ++*s) x=10*x+(**s-'0');
> +
> +	if (sign == '-') return -x;
>  	return x;
>  }
>  
> -- 
> 2.18.GIT


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-05-16  8:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-16  2:31 [PATCH] musl: bugfix getspnam_r negative chenjie6
2019-05-16  8:03 ` Szabolcs Nagy

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).