mailing list of musl libc
 help / color / mirror / code / Atom feed
* passwd/getgrent_a.c bug
@ 2011-06-30 10:03 Szabolcs Nagy
  2011-06-30 10:18 ` Szabolcs Nagy
  0 siblings, 1 reply; 5+ messages in thread
From: Szabolcs Nagy @ 2011-06-30 10:03 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 212 bytes --]

__getgrent_a is wrong when *nmem==0
then
    mem[0][0] = mems;
    mem[0][1] = 0;
the correct behaviour is probably
    mem[0][0] = 0;

i made the allocated buffer bigger but i'm not sure
if that's the right fix

[-- Attachment #2: grent.diff --]
[-- Type: text/x-diff, Size: 439 bytes --]

diff --git a/src/passwd/getgrent_a.c b/src/passwd/getgrent_a.c
index ccb51d5..b099786 100644
--- a/src/passwd/getgrent_a.c
+++ b/src/passwd/getgrent_a.c
@@ -31,7 +31,7 @@ struct group *__getgrent_a(FILE *f, struct group *gr, char **line, size_t *size,
 	for (*nmem=!!*s; *s; s++)
 		if (*s==',') ++*nmem;
 	free(*mem);
-	*mem = calloc(sizeof(char *), *nmem+1);
+	*mem = calloc(**mem, *nmem+2);
 	if (!*mem) {
 		free(*line);
 		*line = 0;

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

* Re: passwd/getgrent_a.c bug
  2011-06-30 10:03 passwd/getgrent_a.c bug Szabolcs Nagy
@ 2011-06-30 10:18 ` Szabolcs Nagy
  2011-06-30 10:23   ` Szabolcs Nagy
  0 siblings, 1 reply; 5+ messages in thread
From: Szabolcs Nagy @ 2011-06-30 10:18 UTC (permalink / raw)
  To: musl

* Szabolcs Nagy <nsz@port70.net> [2011-06-30 12:03:03 +0200]:
> +	*mem = calloc(**mem, *nmem+2);

s/**mem/sizeof **mem/


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

* Re: passwd/getgrent_a.c bug
  2011-06-30 10:18 ` Szabolcs Nagy
@ 2011-06-30 10:23   ` Szabolcs Nagy
  2011-06-30 12:06     ` Rich Felker
  0 siblings, 1 reply; 5+ messages in thread
From: Szabolcs Nagy @ 2011-06-30 10:23 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 212 bytes --]

* Szabolcs Nagy <nsz@port70.net> [2011-06-30 12:18:42 +0200]:
> * Szabolcs Nagy <nsz@port70.net> [2011-06-30 12:03:03 +0200]:
> > +	*mem = calloc(**mem, *nmem+2);
> 
> s/**mem/sizeof **mem/

this is a better fix

[-- Attachment #2: grent.diff --]
[-- Type: text/x-diff, Size: 710 bytes --]

diff --git a/src/passwd/getgrent_a.c b/src/passwd/getgrent_a.c
index ccb51d5..6958006 100644
--- a/src/passwd/getgrent_a.c
+++ b/src/passwd/getgrent_a.c
@@ -31,7 +31,7 @@ struct group *__getgrent_a(FILE *f, struct group *gr, char **line, size_t *size,
 	for (*nmem=!!*s; *s; s++)
 		if (*s==',') ++*nmem;
 	free(*mem);
-	*mem = calloc(sizeof(char *), *nmem+1);
+	*mem = calloc(sizeof **mem, *nmem+1);
 	if (!*mem) {
 		free(*line);
 		*line = 0;
@@ -40,7 +40,7 @@ struct group *__getgrent_a(FILE *f, struct group *gr, char **line, size_t *size,
 	mem[0][0] = mems;
 	for (s=mems, i=0; *s; s++)
 		if (*s==',') *s++ = 0, mem[0][++i] = s;
-	mem[0][++i] = 0;
+	mem[0][i] = 0;
 	gr->gr_mem = *mem;
 	return gr;
 }

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

* Re: passwd/getgrent_a.c bug
  2011-06-30 10:23   ` Szabolcs Nagy
@ 2011-06-30 12:06     ` Rich Felker
  2011-06-30 12:16       ` Szabolcs Nagy
  0 siblings, 1 reply; 5+ messages in thread
From: Rich Felker @ 2011-06-30 12:06 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 350 bytes --]

On Thu, Jun 30, 2011 at 12:23:34PM +0200, Szabolcs Nagy wrote:
> * Szabolcs Nagy <nsz@port70.net> [2011-06-30 12:18:42 +0200]:
> > * Szabolcs Nagy <nsz@port70.net> [2011-06-30 12:03:03 +0200]:
> > > +	*mem = calloc(**mem, *nmem+2);
> > 
> > s/**mem/sizeof **mem/
> 
> this is a better fix

It's still wrong. See if the attached patch fixes it.

Rich

[-- Attachment #2: getgrent_a.diff --]
[-- Type: text/plain, Size: 596 bytes --]

diff --git a/src/passwd/getgrent_a.c b/src/passwd/getgrent_a.c
index ccb51d5..7c63c57 100644
--- a/src/passwd/getgrent_a.c
+++ b/src/passwd/getgrent_a.c
@@ -37,10 +37,14 @@ struct group *__getgrent_a(FILE *f, struct group *gr, char **line, size_t *size,
 		*line = 0;
 		return 0;
 	}
-	mem[0][0] = mems;
-	for (s=mems, i=0; *s; s++)
-		if (*s==',') *s++ = 0, mem[0][++i] = s;
-	mem[0][++i] = 0;
+	if (*mems) {
+		mem[0][0] = mems;
+		for (s=mems, i=0; *s; s++)
+			if (*s==',') *s++ = 0, mem[0][++i] = s;
+		mem[0][++i] = 0;
+	} else {
+		mem[0][0] = 0;
+	}
 	gr->gr_mem = *mem;
 	return gr;
 }

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

* Re: passwd/getgrent_a.c bug
  2011-06-30 12:06     ` Rich Felker
@ 2011-06-30 12:16       ` Szabolcs Nagy
  0 siblings, 0 replies; 5+ messages in thread
From: Szabolcs Nagy @ 2011-06-30 12:16 UTC (permalink / raw)
  To: musl

* Rich Felker <dalias@aerifal.cx> [2011-06-30 08:06:20 -0400]:
> On Thu, Jun 30, 2011 at 12:23:34PM +0200, Szabolcs Nagy wrote:
> > this is a better fix
> 
> It's still wrong. See if the attached patch fixes it.

damn..
yes, yours seems ok


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

end of thread, other threads:[~2011-06-30 12:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-30 10:03 passwd/getgrent_a.c bug Szabolcs Nagy
2011-06-30 10:18 ` Szabolcs Nagy
2011-06-30 10:23   ` Szabolcs Nagy
2011-06-30 12:06     ` Rich Felker
2011-06-30 12:16       ` 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).