LKML Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] Stop docproc segfaulting when SRCTREE isn't set.
@ 2007-10-09  6:25 Rob Landley
  2007-10-09 13:03 ` Ahmed S. Darwish
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Rob Landley @ 2007-10-09  6:25 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, rdunlap

From: Rob Landley <rob@landley.net>

Prevent docproc from segfaulting when SRCTREE isn't set.

Signed-off-by: Rob Landley <rob@landley.net>
---

 scripts/basic/docproc.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff -r a26a53ed1101 scripts/basic/docproc.c
--- a/scripts/basic/docproc.c	Sun Oct 07 16:42:22 2007 -0700
+++ b/scripts/basic/docproc.c	Tue Oct 09 01:08:54 2007 -0500
@@ -64,12 +64,15 @@ FILELINE * entity_system;
 #define FUNCTION      "-function"
 #define NOFUNCTION    "-nofunction"
 
+char *srctree;
+
 void usage (void)
 {
 	fprintf(stderr, "Usage: docproc {doc|depend} file\n");
 	fprintf(stderr, "Input is read from file.tmpl. Output is sent to stdout\n");
 	fprintf(stderr, "doc: frontend when generating kernel documentation\n");
 	fprintf(stderr, "depend: generate list of files referenced within file\n");
+	fprintf(stderr, "Environment variable SRCTREE: absolute path to kernel source tree.\n");
 }
 
 /*
@@ -88,7 +91,7 @@ void exec_kernel_doc(char **svec)
 			exit(1);
 		case  0:
 			memset(real_filename, 0, sizeof(real_filename));
-			strncat(real_filename, getenv("SRCTREE"), PATH_MAX);
+			strncat(real_filename, srctree, PATH_MAX);
 			strncat(real_filename, KERNELDOCPATH KERNELDOC,
 					PATH_MAX - strlen(real_filename));
 			execvp(real_filename, svec);
@@ -168,7 +171,7 @@ void find_export_symbols(char * filename
 	if (filename_exist(filename) == NULL) {
 		char real_filename[PATH_MAX + 1];
 		memset(real_filename, 0, sizeof(real_filename));
-		strncat(real_filename, getenv("SRCTREE"), PATH_MAX);
+		strncat(real_filename, srctree, PATH_MAX);
 		strncat(real_filename, filename,
 				PATH_MAX - strlen(real_filename));
 		sym = add_new_file(filename);
@@ -335,6 +338,9 @@ int main(int argc, char *argv[])
 int main(int argc, char *argv[])
 {
 	FILE * infile;
+
+	srctree = getenv("SRCTREE");
+	if (!srctree) srctree = getcwd(NULL,0);
 	if (argc != 3) {
 		usage();
 		exit(1);

-- 
"One of my most productive days was throwing away 1000 lines of code."
  - Ken Thompson.

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

* Re: [PATCH] Stop docproc segfaulting when SRCTREE isn't set.
  2007-10-09  6:25 [PATCH] Stop docproc segfaulting when SRCTREE isn't set Rob Landley
@ 2007-10-09 13:03 ` Ahmed S. Darwish
  2007-10-09 15:55   ` Randy Dunlap
  2007-10-09 22:19   ` Rob Landley
  2007-10-09 15:56 ` Randy Dunlap
  2007-10-18 11:53 ` Sam Ravnborg
  2 siblings, 2 replies; 9+ messages in thread
From: Ahmed S. Darwish @ 2007-10-09 13:03 UTC (permalink / raw)
  To: Rob Landley; +Cc: akpm, linux-kernel, rdunlap

Hi Rob,

On Tue, Oct 09, 2007 at 01:25:18AM -0500, Rob Landley wrote:
[...]
>  	FILE * infile;
> +
> +	srctree = getenv("SRCTREE");
> +	if (!srctree) srctree = getcwd(NULL,0);
>  	if (argc != 3) {
>  		usage();
>  		exit(1);

$ man getcwd

 char *getcwd(char *buf, size_t size);
      
 As an extension to the POSIX.1 standard, Linux (libc4, libc5, glibc) getcwd() 
 allocates the buffer dynamically using malloc() if buf is NULL on call.

Shouldn't "srctree" be free()ed in case getenv("SRCTREE") failed ?

Regards,

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

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

* Re: [PATCH] Stop docproc segfaulting when SRCTREE isn't set.
  2007-10-09 13:03 ` Ahmed S. Darwish
@ 2007-10-09 15:55   ` Randy Dunlap
  2007-10-09 17:19     ` Ahmed S. Darwish
  2007-10-09 22:19   ` Rob Landley
  1 sibling, 1 reply; 9+ messages in thread
From: Randy Dunlap @ 2007-10-09 15:55 UTC (permalink / raw)
  To: Ahmed S. Darwish; +Cc: Rob Landley, akpm, linux-kernel, rdunlap

On Tue, 9 Oct 2007 15:03:15 +0200 Ahmed S. Darwish wrote:

> Hi Rob,
> 
> On Tue, Oct 09, 2007 at 01:25:18AM -0500, Rob Landley wrote:
> [...]
> >  	FILE * infile;
> > +
> > +	srctree = getenv("SRCTREE");
> > +	if (!srctree) srctree = getcwd(NULL,0);
> >  	if (argc != 3) {
> >  		usage();
> >  		exit(1);
> 
> $ man getcwd
> 
>  char *getcwd(char *buf, size_t size);
>       
>  As an extension to the POSIX.1 standard, Linux (libc4, libc5, glibc) getcwd() 
>  allocates the buffer dynamically using malloc() if buf is NULL on call.
> 
> Shouldn't "srctree" be free()ed in case getenv("SRCTREE") failed ?

What is there to free() at that point?  If getenv() fails (i.e.,
the env. variable is not found), it returns NULL.
or do I need another cup of coffee?

---
~Randy

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

* Re: [PATCH] Stop docproc segfaulting when SRCTREE isn't set.
  2007-10-09  6:25 [PATCH] Stop docproc segfaulting when SRCTREE isn't set Rob Landley
  2007-10-09 13:03 ` Ahmed S. Darwish
@ 2007-10-09 15:56 ` Randy Dunlap
  2007-10-18 11:53 ` Sam Ravnborg
  2 siblings, 0 replies; 9+ messages in thread
From: Randy Dunlap @ 2007-10-09 15:56 UTC (permalink / raw)
  To: Rob Landley; +Cc: akpm, linux-kernel, rdunlap

On Tue, 9 Oct 2007 01:25:18 -0500 Rob Landley wrote:

> From: Rob Landley <rob@landley.net>
> 
> Prevent docproc from segfaulting when SRCTREE isn't set.
> 
> Signed-off-by: Rob Landley <rob@landley.net>

Acked-by: Randy Dunlap <randy.dunlap@oracle.com>

but needs 2 coding style fixes... see near end, below.

> ---
> 
>  scripts/basic/docproc.c |   10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff -r a26a53ed1101 scripts/basic/docproc.c
> --- a/scripts/basic/docproc.c	Sun Oct 07 16:42:22 2007 -0700
> +++ b/scripts/basic/docproc.c	Tue Oct 09 01:08:54 2007 -0500
> @@ -64,12 +64,15 @@ FILELINE * entity_system;
>  #define FUNCTION      "-function"
>  #define NOFUNCTION    "-nofunction"
>  
> +char *srctree;
> +
>  void usage (void)
>  {
>  	fprintf(stderr, "Usage: docproc {doc|depend} file\n");
>  	fprintf(stderr, "Input is read from file.tmpl. Output is sent to stdout\n");
>  	fprintf(stderr, "doc: frontend when generating kernel documentation\n");
>  	fprintf(stderr, "depend: generate list of files referenced within file\n");
> +	fprintf(stderr, "Environment variable SRCTREE: absolute path to kernel source tree.\n");
>  }
>  
>  /*
> @@ -88,7 +91,7 @@ void exec_kernel_doc(char **svec)
>  			exit(1);
>  		case  0:
>  			memset(real_filename, 0, sizeof(real_filename));
> -			strncat(real_filename, getenv("SRCTREE"), PATH_MAX);
> +			strncat(real_filename, srctree, PATH_MAX);
>  			strncat(real_filename, KERNELDOCPATH KERNELDOC,
>  					PATH_MAX - strlen(real_filename));
>  			execvp(real_filename, svec);
> @@ -168,7 +171,7 @@ void find_export_symbols(char * filename
>  	if (filename_exist(filename) == NULL) {
>  		char real_filename[PATH_MAX + 1];
>  		memset(real_filename, 0, sizeof(real_filename));
> -		strncat(real_filename, getenv("SRCTREE"), PATH_MAX);
> +		strncat(real_filename, srctree, PATH_MAX);
>  		strncat(real_filename, filename,
>  				PATH_MAX - strlen(real_filename));
>  		sym = add_new_file(filename);
> @@ -335,6 +338,9 @@ int main(int argc, char *argv[])
>  int main(int argc, char *argv[])
>  {
>  	FILE * infile;
> +
> +	srctree = getenv("SRCTREE");
> +	if (!srctree) srctree = getcwd(NULL,0);

	if (!srctree)
		srctree = getcwd(NULL, 0);

>  	if (argc != 3) {
>  		usage();
>  		exit(1);
> 
> -- 


---
~Randy

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

* Re: [PATCH] Stop docproc segfaulting when SRCTREE isn't set.
  2007-10-09 15:55   ` Randy Dunlap
@ 2007-10-09 17:19     ` Ahmed S. Darwish
  2007-10-09 17:24       ` Randy Dunlap
  0 siblings, 1 reply; 9+ messages in thread
From: Ahmed S. Darwish @ 2007-10-09 17:19 UTC (permalink / raw)
  To: Randy Dunlap; +Cc: Rob Landley, akpm, linux-kernel, rdunlap

On Tue, Oct 09, 2007 at 08:55:00AM -0700, Randy Dunlap wrote:
> On Tue, 9 Oct 2007 15:03:15 +0200 Ahmed S. Darwish wrote:
> 
> > Hi Rob,
> > 
> > On Tue, Oct 09, 2007 at 01:25:18AM -0500, Rob Landley wrote:
> > [...]
> > >  	FILE * infile;
> > > +
> > > +	srctree = getenv("SRCTREE");
> > > +	if (!srctree) srctree = getcwd(NULL,0);
> > >  	if (argc != 3) {
> > >  		usage();
> > >  		exit(1);
> > 
> > $ man getcwd
> > 
> >  char *getcwd(char *buf, size_t size);
> >       
> >  As an extension to the POSIX.1 standard, Linux (libc4, libc5, glibc) getcwd() 
> >  allocates the buffer dynamically using malloc() if buf is NULL on call.
> > 
> > Shouldn't "srctree" be free()ed in case getenv("SRCTREE") failed ?
> 
> What is there to free() at that point?  If getenv() fails (i.e.,
> the env. variable is not found), it returns NULL.
> or do I need another cup of coffee?
>

I meant if getenv() failed, "srctree = getcwd(NULL, 0)" will let 
"srctree" point to a _ malloc()ed _ buffer representing PWD. 
As said in the manpage, this buffer needs to be free()ed after usage.
Right or I'm the one who needs that cup of coffee :) ?

Regards,

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

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

* Re: [PATCH] Stop docproc segfaulting when SRCTREE isn't set.
  2007-10-09 17:19     ` Ahmed S. Darwish
@ 2007-10-09 17:24       ` Randy Dunlap
  2007-10-09 17:51         ` Ahmed S. Darwish
  0 siblings, 1 reply; 9+ messages in thread
From: Randy Dunlap @ 2007-10-09 17:24 UTC (permalink / raw)
  To: Ahmed S. Darwish; +Cc: Rob Landley, akpm, linux-kernel, rdunlap

Ahmed S. Darwish wrote:
> On Tue, Oct 09, 2007 at 08:55:00AM -0700, Randy Dunlap wrote:
>> On Tue, 9 Oct 2007 15:03:15 +0200 Ahmed S. Darwish wrote:
>>
>>> Hi Rob,
>>>
>>> On Tue, Oct 09, 2007 at 01:25:18AM -0500, Rob Landley wrote:
>>> [...]
>>>>  	FILE * infile;
>>>> +
>>>> +	srctree = getenv("SRCTREE");
>>>> +	if (!srctree) srctree = getcwd(NULL,0);
>>>>  	if (argc != 3) {
>>>>  		usage();
>>>>  		exit(1);
>>> $ man getcwd
>>>
>>>  char *getcwd(char *buf, size_t size);
>>>       
>>>  As an extension to the POSIX.1 standard, Linux (libc4, libc5, glibc) getcwd() 
>>>  allocates the buffer dynamically using malloc() if buf is NULL on call.
>>>
>>> Shouldn't "srctree" be free()ed in case getenv("SRCTREE") failed ?
>> What is there to free() at that point?  If getenv() fails (i.e.,
>> the env. variable is not found), it returns NULL.
>> or do I need another cup of coffee?
>>
> 
> I meant if getenv() failed, "srctree = getcwd(NULL, 0)" will let 
> "srctree" point to a _ malloc()ed _ buffer representing PWD. 
> As said in the manpage, this buffer needs to be free()ed after usage.
> Right or I'm the one who needs that cup of coffee :) ?

so it needs to be freed at program termination, is that what you are
saying?  That will happen automatically (along with any open files being
closed, etc.).

-- 
~Randy

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

* Re: [PATCH] Stop docproc segfaulting when SRCTREE isn't set.
  2007-10-09 17:24       ` Randy Dunlap
@ 2007-10-09 17:51         ` Ahmed S. Darwish
  0 siblings, 0 replies; 9+ messages in thread
From: Ahmed S. Darwish @ 2007-10-09 17:51 UTC (permalink / raw)
  To: Randy Dunlap; +Cc: Rob Landley, akpm, linux-kernel, rdunlap

On Tue, Oct 09, 2007 at 10:24:03AM -0700, Randy Dunlap wrote:
> Ahmed S. Darwish wrote:
> >On Tue, Oct 09, 2007 at 08:55:00AM -0700, Randy Dunlap wrote:
> >>On Tue, 9 Oct 2007 15:03:15 +0200 Ahmed S. Darwish wrote:
> >>
> >>>Hi Rob,
> >>>
> >>>On Tue, Oct 09, 2007 at 01:25:18AM -0500, Rob Landley wrote:
> >>>[...]
> >>>> 	FILE * infile;
> >>>>+
> >>>>+	srctree = getenv("SRCTREE");
> >>>>+	if (!srctree) srctree = getcwd(NULL,0);
> >>>> 	if (argc != 3) {
> >>>> 		usage();
> >>>> 		exit(1);
> >>>$ man getcwd
> >>>
> >>> char *getcwd(char *buf, size_t size);
> >>>      
> >>> As an extension to the POSIX.1 standard, Linux (libc4, libc5, glibc) 
> >>> getcwd() allocates the buffer dynamically using malloc() if buf is NULL 
> >>> on call.
> >>>
> >>>Shouldn't "srctree" be free()ed in case getenv("SRCTREE") failed ?
> >>What is there to free() at that point?  If getenv() fails (i.e.,
> >>the env. variable is not found), it returns NULL.
> >>or do I need another cup of coffee?
> >>
> >
> >I meant if getenv() failed, "srctree = getcwd(NULL, 0)" will let 
> >"srctree" point to a _ malloc()ed _ buffer representing PWD. 
> >As said in the manpage, this buffer needs to be free()ed after usage.
> >Right or I'm the one who needs that cup of coffee :) ?
> 
> so it needs to be freed at program termination, is that what you are
> saying?  That will happen automatically (along with any open files being
> closed, etc.).
> 

I didn't know that leaked mem will be automatically freed at program 
termination. A new info, Thanks!.

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

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

* Re: [PATCH] Stop docproc segfaulting when SRCTREE isn't set.
  2007-10-09 13:03 ` Ahmed S. Darwish
  2007-10-09 15:55   ` Randy Dunlap
@ 2007-10-09 22:19   ` Rob Landley
  1 sibling, 0 replies; 9+ messages in thread
From: Rob Landley @ 2007-10-09 22:19 UTC (permalink / raw)
  To: Ahmed S. Darwish; +Cc: akpm, linux-kernel, rdunlap

On Tuesday 09 October 2007 8:03:15 am Ahmed S. Darwish wrote:
> $ man getcwd
>
>  char *getcwd(char *buf, size_t size);
>
>  As an extension to the POSIX.1 standard, Linux (libc4, libc5, glibc)
> getcwd() allocates the buffer dynamically using malloc() if buf is NULL on
> call.
>
> Shouldn't "srctree" be free()ed in case getenv("SRCTREE") failed ?

If exit() doesn't free all the memory the program allocated, we have bigger 
problems.

> Regards,

Rob
-- 
"One of my most productive days was throwing away 1000 lines of code."
  - Ken Thompson.

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

* Re: [PATCH] Stop docproc segfaulting when SRCTREE isn't set.
  2007-10-09  6:25 [PATCH] Stop docproc segfaulting when SRCTREE isn't set Rob Landley
  2007-10-09 13:03 ` Ahmed S. Darwish
  2007-10-09 15:56 ` Randy Dunlap
@ 2007-10-18 11:53 ` Sam Ravnborg
  2 siblings, 0 replies; 9+ messages in thread
From: Sam Ravnborg @ 2007-10-18 11:53 UTC (permalink / raw)
  To: Rob Landley; +Cc: akpm, linux-kernel, rdunlap

On Tue, Oct 09, 2007 at 01:25:18AM -0500, Rob Landley wrote:
> From: Rob Landley <rob@landley.net>
> 
> Prevent docproc from segfaulting when SRCTREE isn't set.
> 
> Signed-off-by: Rob Landley <rob@landley.net>

Applied to kbuild.git (with Randy's style fixup).

	Sam

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

end of thread, back to index

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-09  6:25 [PATCH] Stop docproc segfaulting when SRCTREE isn't set Rob Landley
2007-10-09 13:03 ` Ahmed S. Darwish
2007-10-09 15:55   ` Randy Dunlap
2007-10-09 17:19     ` Ahmed S. Darwish
2007-10-09 17:24       ` Randy Dunlap
2007-10-09 17:51         ` Ahmed S. Darwish
2007-10-09 22:19   ` Rob Landley
2007-10-09 15:56 ` Randy Dunlap
2007-10-18 11:53 ` Sam Ravnborg

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lkml.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lkml.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lkml.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lkml.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lkml.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lkml.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lkml.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lkml.kernel.org/lkml/7 lkml/git/7.git
	git clone --mirror https://lkml.kernel.org/lkml/8 lkml/git/8.git
	git clone --mirror https://lkml.kernel.org/lkml/9 lkml/git/9.git
	git clone --mirror https://lkml.kernel.org/lkml/10 lkml/git/10.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lkml.kernel.org/lkml \
		linux-kernel@vger.kernel.org
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git