Skip to content

Commit bb13be5

Browse files
landleySam Ravnborg
authored andcommitted
kbuild: stop docproc segfaulting when SRCTREE isn't set.
Prevent docproc from segfaulting when SRCTREE isn't set. Signed-off-by: Rob Landley <[email protected]> Acked-by: Randy Dunlap <[email protected]> Signed-off-by: Sam Ravnborg <[email protected]>
1 parent 4b21960 commit bb13be5

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

scripts/basic/docproc.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,15 @@ FILELINE * entity_system;
6666
#define FUNCTION "-function"
6767
#define NOFUNCTION "-nofunction"
6868

69+
char *srctree;
70+
6971
void usage (void)
7072
{
7173
fprintf(stderr, "Usage: docproc {doc|depend} file\n");
7274
fprintf(stderr, "Input is read from file.tmpl. Output is sent to stdout\n");
7375
fprintf(stderr, "doc: frontend when generating kernel documentation\n");
7476
fprintf(stderr, "depend: generate list of files referenced within file\n");
77+
fprintf(stderr, "Environment variable SRCTREE: absolute path to kernel source tree.\n");
7578
}
7679

7780
/*
@@ -90,7 +93,7 @@ void exec_kernel_doc(char **svec)
9093
exit(1);
9194
case 0:
9295
memset(real_filename, 0, sizeof(real_filename));
93-
strncat(real_filename, getenv("SRCTREE"), PATH_MAX);
96+
strncat(real_filename, srctree, PATH_MAX);
9497
strncat(real_filename, KERNELDOCPATH KERNELDOC,
9598
PATH_MAX - strlen(real_filename));
9699
execvp(real_filename, svec);
@@ -171,7 +174,7 @@ void find_export_symbols(char * filename)
171174
if (filename_exist(filename) == NULL) {
172175
char real_filename[PATH_MAX + 1];
173176
memset(real_filename, 0, sizeof(real_filename));
174-
strncat(real_filename, getenv("SRCTREE"), PATH_MAX);
177+
strncat(real_filename, srctree, PATH_MAX);
175178
strncat(real_filename, filename,
176179
PATH_MAX - strlen(real_filename));
177180
sym = add_new_file(filename);
@@ -338,6 +341,10 @@ void parse_file(FILE *infile)
338341
int main(int argc, char *argv[])
339342
{
340343
FILE * infile;
344+
345+
srctree = getenv("SRCTREE");
346+
if (!srctree)
347+
srctree = getcwd(NULL, 0);
341348
if (argc != 3) {
342349
usage();
343350
exit(1);

0 commit comments

Comments
 (0)