Changeset 3654:9eb775ff3c55
- Timestamp:
- 2004-04-12 14:43:32 (5 years ago)
- Author:
- Thomas Roessler <roessler@…>
- Branch:
- HEAD
- Message:
-
Don't open a file for writing that we have unlinked before. Reported
embarassingly long ago by Jarno Huuskonen <Jarno.Huuskonen@…>.
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r3505
|
r3654
|
|
| 109 | 109 | goto bailout; |
| 110 | 110 | } |
| 111 | | unlink_newfile = 1; |
| | 111 | else |
| | 112 | unlink_newfile = 1; |
| 112 | 113 | } |
| 113 | 114 | else |
| … |
… |
|
| 174 | 175 | fclose (tfp); |
| 175 | 176 | mutt_unlink (a->filename); |
| 176 | | mutt_rename_file (tempfile, a->filename); |
| | 177 | if (mutt_rename_file (tempfile, a->filename) != 0) |
| | 178 | { |
| | 179 | mutt_perror _("Failure to rename file."); |
| | 180 | goto bailout; |
| | 181 | } |
| 177 | 182 | |
| 178 | 183 | mutt_free_body (&b); |
| … |
… |
|
| 236 | 241 | goto bailout; |
| 237 | 242 | } |
| 238 | | unlink_newfile = 1; |
| | 243 | else |
| | 244 | unlink_newfile = 1; |
| 239 | 245 | } |
| 240 | 246 | else |
| … |
… |
|
| 608 | 614 | rc = mutt_do_pager (descrip, pagerfile, |
| 609 | 615 | M_PAGER_ATTACHMENT | (is_message ? M_PAGER_MESSAGE : 0), &info); |
| | 616 | *pagerfile = '\0'; |
| 610 | 617 | } |
| 611 | 618 | else |
-
|
r3499
|
r3654
|
|
| 182 | 182 | void mutt_unlink (const char *s) |
| 183 | 183 | { |
| | 184 | int fd; |
| | 185 | int flags; |
| 184 | 186 | FILE *f; |
| 185 | 187 | struct stat sb; |
| 186 | 188 | char buf[2048]; |
| | 189 | |
| | 190 | /* Defend against symlink attacks */ |
| | 191 | |
| | 192 | #ifdef O_NOFOLLOW |
| | 193 | flags = O_RDWR | O_NOFOLLOW; |
| | 194 | #else |
| | 195 | flags = O_RDWR; |
| | 196 | #endif |
| 187 | 197 | |
| 188 | 198 | if (stat (s, &sb) == 0) |
| 189 | 199 | { |
| 190 | | if ((f = fopen (s, "r+"))) |
| | 200 | if ((fd = open (s, flags)) < 0) |
| | 201 | return; |
| | 202 | if ((f = fdopen (fd, "r+"))) |
| 191 | 203 | { |
| 192 | 204 | unlink (s); |