diff options
author | Denis Vlasenko | 2007-03-26 22:58:21 +0000 |
---|---|---|
committer | Denis Vlasenko | 2007-03-26 22:58:21 +0000 |
commit | 3983bd5593ae3a18dd69072e549e3860820cb8ff (patch) | |
tree | c90f6a907087a587d4a72366164233eb7d5a8e3a | |
parent | 17a1526f9e2cb0a383fe0765ce803833be28773c (diff) | |
download | busybox-3983bd5593ae3a18dd69072e549e3860820cb8ff.zip busybox-3983bd5593ae3a18dd69072e549e3860820cb8ff.tar.gz |
diff: fix SEGV (NULL deref) in diff -N
-rw-r--r-- | coreutils/diff.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/coreutils/diff.c b/coreutils/diff.c index fa6ef10..911bfcf 100644 --- a/coreutils/diff.c +++ b/coreutils/diff.c @@ -997,24 +997,30 @@ static void do_diff(char *dir1, char *path1, char *dir2, char *path2) { int flags = D_HEADER; int val; + char *fullpath1 = NULL; /* if -N */ + char *fullpath2 = NULL; - char *fullpath1 = concat_path_file(dir1, path1); - char *fullpath2 = concat_path_file(dir2, path2); + if (path1) + fullpath1 = concat_path_file(dir1, path1); + if (path2) + fullpath2 = concat_path_file(dir2, path2); - if (stat(fullpath1, &stb1) != 0) { + if (!fullpath1 || stat(fullpath1, &stb1) != 0) { flags |= D_EMPTY1; memset(&stb1, 0, sizeof(stb1)); - if (ENABLE_FEATURE_CLEAN_UP) + if (path2) { free(fullpath1); - fullpath1 = concat_path_file(dir1, path2); + fullpath1 = concat_path_file(dir1, path2); + } } - if (stat(fullpath2, &stb2) != 0) { + if (!fullpath2 || stat(fullpath2, &stb2) != 0) { flags |= D_EMPTY2; memset(&stb2, 0, sizeof(stb2)); stb2.st_mode = stb1.st_mode; - if (ENABLE_FEATURE_CLEAN_UP) + if (path1) { free(fullpath2); - fullpath2 = concat_path_file(dir2, path1); + fullpath2 = concat_path_file(dir2, path1); + } } if (stb1.st_mode == 0) @@ -1022,7 +1028,7 @@ static void do_diff(char *dir1, char *path1, char *dir2, char *path2) if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) { printf("Common subdirectories: %s and %s\n", fullpath1, fullpath2); - return; + goto ret; } if (!S_ISREG(stb1.st_mode) && !S_ISDIR(stb1.st_mode)) @@ -1033,6 +1039,9 @@ static void do_diff(char *dir1, char *path1, char *dir2, char *path2) val = diffreg(fullpath1, fullpath2, flags); print_status(val, fullpath1, fullpath2, NULL); + ret: + free(fullpath1); + free(fullpath2); } #endif |