Text   |  XML   |  ReML   |   Visible Warnings:

File System Race Condition  at dbox-file.c:1301

No properties have been set. | edit properties
Jump to warning location ↓ warning details...
Show Events | Options

dbox_file_move

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib-storage/index/dbox/dbox-file.c)expand/collapse
Show more  
 1218  int dbox_file_move(struct dbox_file *file, bool alt_path)
 1219  {
 1220          struct ostream *output;
 1221          const char *dest_dir, *temp_path, *dest_path;
 1222          struct stat st;
 1223          bool deleted;
 1224          int out_fd, ret = 0;
 1225   
 1226          i_assert(file->input != NULL);
 1227   
 1228          if (file->alt_path == alt_path)
 1229                  return 0;
 1230   
 1231          if (stat(file->current_path, &st) < 0 && errno == ENOENT) {
 1232                  /* already expunged by another session */
 1233                  return 0;
 1234          }
 1235   
 1236          dest_dir = alt_path ? file->mbox->alt_path : file->mbox->path;
 1237          temp_path = t_strdup_printf("%s/%s", dest_dir,
 1238                                      dbox_generate_tmp_filename());
 1239   
 1240          /* first copy the file. make sure to catch every possible error 
 1241             since we really don't want to break the file. */
 1242          out_fd = open(temp_path, O_WRONLY | O_CREAT | O_TRUNC, 0600);
 1243          if (out_fd == -1 && errno == ENOENT) {
 1244                  if (mkdir_parents(dest_dir, 0700) < 0 && errno != EEXIST) {
 1245                          i_error("mkdir_parents(%s) failed: %m", dest_dir);
 1246                          return -1;
 1247                  }
 1248                  out_fd = open(temp_path, O_WRONLY | O_CREAT | O_TRUNC, 0600);
 1249          }
 1250          if (out_fd == -1) {
 1251                  i_error("open(%s, O_CREAT) failed: %m", temp_path);
 1252                  return -1;
 1253          }
 1254          output = o_stream_create_fd_file(out_fd, 0, FALSE);
 1255          i_stream_seek(file->input, 0);
 1256          while ((ret = o_stream_send_istream(output, file->input)) > 0) ;
 1257          if (ret == 0)
 1258[+]                 ret = o_stream_flush(output);
 1259          if (output->stream_errno != 0) {
 1260                  errno = output->stream_errno;
 1261                  i_error("write(%s) failed: %m", temp_path);
 1262                  ret = -1;
 1263          } else if (file->input->stream_errno != 0) {
 1264                  errno = file->input->stream_errno;
 1265                  i_error("read(%s) failed: %m", file->current_path);
 1266                  ret = -1;
 1267          } else if (ret < 0) {
 1268                  i_error("o_stream_send_istream(%s, %s) "
 1269                          "failed with unknown error",
 1270                          temp_path, file->current_path);
 1271          }
 1272          o_stream_unref(&output);
 1273   
 1274          if (!file->mbox->ibox.fsync_disable && ret == 0) {
 1275                  if (fsync(out_fd) < 0) {
 1276                          i_error("fsync(%s) failed: %m", temp_path);
 1277                          ret = -1;
 1278                  }
 1279          }
 1280          if (close(out_fd) < 0) {
 1281                  i_error("close(%s) failed: %m", temp_path);
 1282                  ret = -1;
 1283          }
 1284          if (ret < 0) {
 1285                  (void)unlink(temp_path);
 1286                  return -1;
 1287          }
 1288   
 1289          /* the temp file was successfully written. rename it now to the 
 1290             destination file. the destination shouldn't exist, but if it does
 1291             its contents should be the same (except for maybe older ) */
 1292[+]         dest_path = t_strdup_printf("%s/%s", dest_dir, file->fname);
 1293          if (rename(temp_path, dest_path) < 0) {
 1294                  i_error("rename(%s, %s) failed: %m", temp_path, dest_path);
 1295                  (void)unlink(temp_path);
 1296                  return -1;
 1297          }
 1298          if (!file->mbox->ibox.fsync_disable) {
 1299[+]                 if (fdatasync_path(dest_dir) < 0) {
 1300                          i_error("fdatasync(%s) failed: %m", dest_dir);
 1301                          (void)unlink(dest_path);
Show more  




Change Warning 7453.25038 : File System Race Condition

Because they are very similar, this warning shares annotations with warning 7453.25040.

Priority:
State:
Finding:
Owner:
Note: