Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 13 Aug 2012 13:29:38 +0300
From: "Ivan Kanakarakis" <ivan.kanak@...il.com>
To: musl@...ts.openwall.com, "Arvid E. Picciani" <aep@...s.org>
Subject: Re: getpwent.c:  isn't line supposed to be set NULL?

On Mon, 13 Aug 2012 13:04:14 +0300, Arvid E. Picciani <aep@...s.org> wrote:

> the getpw* functions call getline in a dubious way
> for example:
>
> struct passwd *__getpwent_a(FILE *f, struct passwd *pw, char **line,  
> size_t *size)
> [..]
> 		if ((l=getline(line, size, f)) < 0) {
> 			free(*line);
> 			*line = 0;
>
>
> is called from
>
> struct passwd *fgetpwent(FILE *f)
> [..]
> 	static char *line;

per standard:
All objects with static storage duration shall be initialized (set to  
their initial values) before program startup.
This initialization applies to all objects having file scope and objects in  
block scope that have internal
linkage. The initial values may have been provided explicitly by the  
developer or implicitly by the implementation.
Once set, these objects are never reinitialized again during the current  
program invocation, even if main is called
recursively (permitted in C90, but not in C99 or C++)

As line is static, there is no need for explicit initialization ('char  
*line = 0;').


> 	return __getpwent_a(f, &pw, &line, &size);
>
>
> where line is uninitialized.
>
> first thing getdelim (forwarded from getline) does is:
>
> if (!*s) *n=0;
>
> so this looks wrong somewhere.
> maybe i'm just missing an =0 in between.
>
>


-- 
Ivan c00kiemon5ter Kanakarakis

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.