diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-03-26 22:58:21 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-03-26 22:58:21 +0000 |
| commit | 3983bd5593ae3a18dd69072e549e3860820cb8ff (patch) | |
| tree | c90f6a907087a587d4a72366164233eb7d5a8e3a /coreutils/diff.c | |
| parent | 17a1526f9e2cb0a383fe0765ce803833be28773c (diff) | |
| download | busybox-w32-3983bd5593ae3a18dd69072e549e3860820cb8ff.tar.gz busybox-w32-3983bd5593ae3a18dd69072e549e3860820cb8ff.tar.bz2 busybox-w32-3983bd5593ae3a18dd69072e549e3860820cb8ff.zip | |
diff: fix SEGV (NULL deref) in diff -N
Diffstat (limited to 'coreutils/diff.c')
| -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 fa6ef105e..911bfcf4d 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) | |||
| 997 | { | 997 | { |
| 998 | int flags = D_HEADER; | 998 | int flags = D_HEADER; |
| 999 | int val; | 999 | int val; |
| 1000 | char *fullpath1 = NULL; /* if -N */ | ||
| 1001 | char *fullpath2 = NULL; | ||
| 1000 | 1002 | ||
| 1001 | char *fullpath1 = concat_path_file(dir1, path1); | 1003 | if (path1) |
| 1002 | char *fullpath2 = concat_path_file(dir2, path2); | 1004 | fullpath1 = concat_path_file(dir1, path1); |
| 1005 | if (path2) | ||
| 1006 | fullpath2 = concat_path_file(dir2, path2); | ||
| 1003 | 1007 | ||
| 1004 | if (stat(fullpath1, &stb1) != 0) { | 1008 | if (!fullpath1 || stat(fullpath1, &stb1) != 0) { |
| 1005 | flags |= D_EMPTY1; | 1009 | flags |= D_EMPTY1; |
| 1006 | memset(&stb1, 0, sizeof(stb1)); | 1010 | memset(&stb1, 0, sizeof(stb1)); |
| 1007 | if (ENABLE_FEATURE_CLEAN_UP) | 1011 | if (path2) { |
| 1008 | free(fullpath1); | 1012 | free(fullpath1); |
| 1009 | fullpath1 = concat_path_file(dir1, path2); | 1013 | fullpath1 = concat_path_file(dir1, path2); |
| 1014 | } | ||
| 1010 | } | 1015 | } |
| 1011 | if (stat(fullpath2, &stb2) != 0) { | 1016 | if (!fullpath2 || stat(fullpath2, &stb2) != 0) { |
| 1012 | flags |= D_EMPTY2; | 1017 | flags |= D_EMPTY2; |
| 1013 | memset(&stb2, 0, sizeof(stb2)); | 1018 | memset(&stb2, 0, sizeof(stb2)); |
| 1014 | stb2.st_mode = stb1.st_mode; | 1019 | stb2.st_mode = stb1.st_mode; |
| 1015 | if (ENABLE_FEATURE_CLEAN_UP) | 1020 | if (path1) { |
| 1016 | free(fullpath2); | 1021 | free(fullpath2); |
| 1017 | fullpath2 = concat_path_file(dir2, path1); | 1022 | fullpath2 = concat_path_file(dir2, path1); |
| 1023 | } | ||
| 1018 | } | 1024 | } |
| 1019 | 1025 | ||
| 1020 | if (stb1.st_mode == 0) | 1026 | if (stb1.st_mode == 0) |
| @@ -1022,7 +1028,7 @@ static void do_diff(char *dir1, char *path1, char *dir2, char *path2) | |||
| 1022 | 1028 | ||
| 1023 | if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) { | 1029 | if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) { |
| 1024 | printf("Common subdirectories: %s and %s\n", fullpath1, fullpath2); | 1030 | printf("Common subdirectories: %s and %s\n", fullpath1, fullpath2); |
| 1025 | return; | 1031 | goto ret; |
| 1026 | } | 1032 | } |
| 1027 | 1033 | ||
| 1028 | if (!S_ISREG(stb1.st_mode) && !S_ISDIR(stb1.st_mode)) | 1034 | 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) | |||
| 1033 | val = diffreg(fullpath1, fullpath2, flags); | 1039 | val = diffreg(fullpath1, fullpath2, flags); |
| 1034 | 1040 | ||
| 1035 | print_status(val, fullpath1, fullpath2, NULL); | 1041 | print_status(val, fullpath1, fullpath2, NULL); |
| 1042 | ret: | ||
| 1043 | free(fullpath1); | ||
| 1044 | free(fullpath2); | ||
| 1036 | } | 1045 | } |
| 1037 | #endif | 1046 | #endif |
| 1038 | 1047 | ||
