archive_write_disk_posix.c (346104) | archive_write_disk_posix.c (348607) |
---|---|
1/*- 2 * Copyright (c) 2003-2010 Tim Kientzle 3 * Copyright (c) 2012 Michihiro NAKAJIMA 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 2018 unchanged lines hidden (view full) --- 2027 */ 2028 int r = 0; 2029 /* 2030 * The SECURE_SYMLINKS logic has already removed a 2031 * symlink to a dir if the client wants that. So 2032 * follow the symlink if we're creating a dir. 2033 */ 2034 if (S_ISDIR(a->mode)) | 1/*- 2 * Copyright (c) 2003-2010 Tim Kientzle 3 * Copyright (c) 2012 Michihiro NAKAJIMA 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 2018 unchanged lines hidden (view full) --- 2027 */ 2028 int r = 0; 2029 /* 2030 * The SECURE_SYMLINKS logic has already removed a 2031 * symlink to a dir if the client wants that. So 2032 * follow the symlink if we're creating a dir. 2033 */ 2034 if (S_ISDIR(a->mode)) |
2035 r = stat(a->name, &a->st); | 2035 r = la_stat(a->name, &a->st); |
2036 /* 2037 * If it's not a dir (or it's a broken symlink), 2038 * then don't follow it. 2039 */ 2040 if (r != 0 || !S_ISDIR(a->mode)) 2041 r = lstat(a->name, &a->st); 2042 if (r != 0) { 2043 archive_set_error(&a->archive, errno, --- 149 unchanged lines hidden (view full) --- 2193 */ 2194 if (r == 0 && a->filesize <= 0) { 2195 a->todo = 0; 2196 a->deferred = 0; 2197 } else if (r == 0 && a->filesize > 0) { 2198#ifdef HAVE_LSTAT 2199 r = lstat(a->name, &st); 2200#else | 2036 /* 2037 * If it's not a dir (or it's a broken symlink), 2038 * then don't follow it. 2039 */ 2040 if (r != 0 || !S_ISDIR(a->mode)) 2041 r = lstat(a->name, &a->st); 2042 if (r != 0) { 2043 archive_set_error(&a->archive, errno, --- 149 unchanged lines hidden (view full) --- 2193 */ 2194 if (r == 0 && a->filesize <= 0) { 2195 a->todo = 0; 2196 a->deferred = 0; 2197 } else if (r == 0 && a->filesize > 0) { 2198#ifdef HAVE_LSTAT 2199 r = lstat(a->name, &st); 2200#else |
2201 r = stat(a->name, &st); | 2201 r = la_stat(a->name, &st); |
2202#endif 2203 if (r != 0) 2204 r = errno; 2205 else if ((st.st_mode & AE_IFMT) == AE_IFREG) { 2206 a->fd = open(a->name, O_WRONLY | O_TRUNC | 2207 O_BINARY | O_CLOEXEC | O_NOFOLLOW); 2208 __archive_ensure_cloexec_flag(a->fd); 2209 if (a->fd < 0) --- 497 unchanged lines hidden (view full) --- 2707 ARCHIVE_EXTRACT_SECURE_SYMLINKS) == 0) { 2708 /* 2709 * We are not the last element and we want to 2710 * follow symlinks if they are a directory. 2711 * 2712 * This is needed to extract hardlinks over 2713 * symlinks. 2714 */ | 2202#endif 2203 if (r != 0) 2204 r = errno; 2205 else if ((st.st_mode & AE_IFMT) == AE_IFREG) { 2206 a->fd = open(a->name, O_WRONLY | O_TRUNC | 2207 O_BINARY | O_CLOEXEC | O_NOFOLLOW); 2208 __archive_ensure_cloexec_flag(a->fd); 2209 if (a->fd < 0) --- 497 unchanged lines hidden (view full) --- 2707 ARCHIVE_EXTRACT_SECURE_SYMLINKS) == 0) { 2708 /* 2709 * We are not the last element and we want to 2710 * follow symlinks if they are a directory. 2711 * 2712 * This is needed to extract hardlinks over 2713 * symlinks. 2714 */ |
2715 r = stat(head, &st); | 2715 r = la_stat(head, &st); |
2716 if (r != 0) { 2717 tail[0] = c; 2718 if (errno == ENOENT) { 2719 break; 2720 } else { 2721 fsobj_error(a_eno, a_estr, 2722 errno, 2723 "Could not stat ", path); --- 323 unchanged lines hidden (view full) --- 3047 return (ARCHIVE_OK); 3048 } 3049 3050 /* 3051 * Yes, this should be stat() and not lstat(). Using lstat() 3052 * here loses the ability to extract through symlinks. Also note 3053 * that this should not use the a->st cache. 3054 */ | 2716 if (r != 0) { 2717 tail[0] = c; 2718 if (errno == ENOENT) { 2719 break; 2720 } else { 2721 fsobj_error(a_eno, a_estr, 2722 errno, 2723 "Could not stat ", path); --- 323 unchanged lines hidden (view full) --- 3047 return (ARCHIVE_OK); 3048 } 3049 3050 /* 3051 * Yes, this should be stat() and not lstat(). Using lstat() 3052 * here loses the ability to extract through symlinks. Also note 3053 * that this should not use the a->st cache. 3054 */ |
3055 if (stat(path, &st) == 0) { | 3055 if (la_stat(path, &st) == 0) { |
3056 if (S_ISDIR(st.st_mode)) 3057 return (ARCHIVE_OK); 3058 if ((a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE)) { 3059 archive_set_error(&a->archive, EEXIST, 3060 "Can't create directory '%s'", path); 3061 return (ARCHIVE_FAILED); 3062 } 3063 if (unlink(path) != 0) { --- 41 unchanged lines hidden (view full) --- 3105 } 3106 3107 /* 3108 * Without the following check, a/b/../b/c/d fails at the 3109 * second visit to 'b', so 'd' can't be created. Note that we 3110 * don't add it to the fixup list here, as it's already been 3111 * added. 3112 */ | 3056 if (S_ISDIR(st.st_mode)) 3057 return (ARCHIVE_OK); 3058 if ((a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE)) { 3059 archive_set_error(&a->archive, EEXIST, 3060 "Can't create directory '%s'", path); 3061 return (ARCHIVE_FAILED); 3062 } 3063 if (unlink(path) != 0) { --- 41 unchanged lines hidden (view full) --- 3105 } 3106 3107 /* 3108 * Without the following check, a/b/../b/c/d fails at the 3109 * second visit to 'b', so 'd' can't be created. Note that we 3110 * don't add it to the fixup list here, as it's already been 3111 * added. 3112 */ |
3113 if (stat(path, &st) == 0 && S_ISDIR(st.st_mode)) | 3113 if (la_stat(path, &st) == 0 && S_ISDIR(st.st_mode)) |
3114 return (ARCHIVE_OK); 3115 3116 archive_set_error(&a->archive, errno, "Failed to create dir '%s'", 3117 path); 3118 return (ARCHIVE_FAILED); 3119} 3120 3121/* --- 1222 unchanged lines hidden --- | 3114 return (ARCHIVE_OK); 3115 3116 archive_set_error(&a->archive, errno, "Failed to create dir '%s'", 3117 path); 3118 return (ARCHIVE_FAILED); 3119} 3120 3121/* --- 1222 unchanged lines hidden --- |