(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/plugins/fts-squat/squat-trie.c) |
| |
| 1609 | | | static int squat_trie_write(struct squat_trie_build_context *ctx) |
| 1610 | | | { |
| 1611 | | | struct squat_trie *trie = ctx->trie; |
| 1612 | | | struct file_lock *file_lock = NULL; |
| 1613 | | | struct ostream *output; |
| 1614 | | | const char *path; |
| 1615 | | | int fd = -1, ret = 0; |
| 1616 | | | |
| 1617 | | | if ((trie->hdr.used_file_size > sizeof(trie->hdr) && |
| 1618 | | | trie->unmapped_child_count < trie->hdr.node_count/4) || 1) { |
| 1619 | | | |
| 1620 | | | ctx->compress_nodes = TRUE; |
| 1621 | | | |
| 1622 | | | path = t_strconcat(trie->path, ".tmp", NULL); |
| 1623 | | | fd = squat_trie_create_fd(trie, path, O_TRUNC);
x /usr/include/bits/fcntl.h |
| |
41 | #define O_TRUNC 01000 /* not fcntl */ |
| |
|
| 1624 | | | if (fd == -1) |
| 1625 | | | return -1; |
| 1626 | | | |
| 1627 | | | if (trie->lock_method != FILE_LOCK_METHOD_DOTLOCK) { |
| 1628 | | | ret = file_wait_lock(fd, path, F_WRLCK,
x /usr/include/bits/fcntl.h |
| |
133 | #define F_WRLCK 1 /* Write lock. */ |
| |
|
| 1629 | | | trie->lock_method, |
| 1630 | | | SQUAT_TRIE_LOCK_TIMEOUT, |
| 1631 | | | &file_lock); |
| 1632 | | | if (ret <= 0) { |
| 1633 | | | if (ret == 0) { |
| 1634 | | | i_error("file_wait_lock(%s) failed: %m", |
| 1635 | | | path); |
| 1636 | | | } |
| 1637 | | | (void)close(fd); |
| 1638 | | | return -1; |
| 1639 | | | } |
| 1640 | | | } |
| 1641 | | | |
| 1642 | | | output = o_stream_create_fd(fd, 0, FALSE); |
| 1643 | | | o_stream_cork(output); |
| 1644 | | | o_stream_send(output, &trie->hdr, sizeof(trie->hdr)); |
| 1645 | | | } else { |
| 1646 | | | |
| 1647 | | | path = trie->path; |
Unreachable Call
The highlighted code will not execute under any circumstances. This may be because of: |
|
| 1648 | | | ctx->compress_nodes = |
| 1649 | | | trie->hdr.used_file_size == sizeof(trie->hdr); |
| 1650 | | | |
| 1651 | | | if (trie->hdr.used_file_size == 0) { |
| 1652 | | | |
| 1653 | | | if (squat_trie_write_lock(ctx) < 0) |
| 1654 | | | return -1; |
| 1655 | | | } |
| 1656 | | | output = o_stream_create_fd(trie->fd, 0, FALSE); |
| 1657 | | | o_stream_cork(output); |
| 1658 | | | |
| 1659 | | | if (trie->hdr.used_file_size != 0) |
| 1660 | | | o_stream_seek(output, trie->hdr.used_file_size); |
| 1661 | | | else |
| 1662 | | | o_stream_send(output, &trie->hdr, sizeof(trie->hdr)); |
| 1663 | | | } |
| 1664 | | | |
| 1665 | | | ctx->output = output; |
| 1666 | | | ret = squat_write_nodes(ctx); |
| 1667 | | | ctx->output = NULL; |
| 1668 | | | |
| 1669 | | | |
| 1670 | | | |
| 1671 | | | o_stream_send(output, "", 1); |
| 1672 | | | |
| 1673 | | | if (trie->corrupted) |
| 1674 | | | ret = -1; |
| 1675 | | | if (ret == 0) |
| 1676 | | | ret = squat_trie_write_lock(ctx); |
| 1677 | | | if (ret == 0) { |
| 1678 | | | trie->hdr.used_file_size = output->offset; |
| 1679 | | | o_stream_seek(output, 0); |
| 1680 | | | o_stream_send(output, &trie->hdr, sizeof(trie->hdr)); |
| 1681 | | | } |
| 1682 | | | if (output->last_failed_errno != 0) { |
| 1683 | | | errno = output->last_failed_errno; |
| 1684 | | | i_error("write() to %s failed: %m", path); |
| 1685 | | | ret = -1; |
| 1686 | | | } |
| 1687 | | | o_stream_destroy(&output); |
| 1688 | | | |
| 1689 | | | if (fd == -1) { |
| 1690 | | | |
| 1691 | | | i_assert(file_lock == NULL);
x /home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/macros.h |
| |
189 | #define i_assert(expr) STMT_START{ \ |
190 | if (unlikely(!(expr))) \ |
191 | i_panic("file %s: line %d (%s): assertion failed: (%s)", \ |
192 | __FILE__, \ |
193 | __LINE__, \ |
194 | __PRETTY_FUNCTION__, \ |
195 | #expr); }STMT_END |
| |
|
| 1692 | | | return ret; |
| 1693 | | | } |
| 1694 | | | |
| 1695 | | | |
| 1696 | | | if (ret < 0) { |
| 1697 | | | if (close(fd) < 0) |
| 1698 | | | i_error("close(%s) failed: %m", path); |
| 1699 | | | fd = -1; |
| 1700 | | | } else if (rename(path, trie->path) < 0) { |
| 1701 | | | i_error("rename(%s, %s) failed: %m", path, trie->path); |
| 1702 | | | ret = -1; |
| 1703 | | | } |
| 1704 | | | |
| 1705 | | | if (ret < 0) { |
| 1706 | | | if (unlink(path) < 0 && errno != ENOENT)
x /usr/include/asm-generic/errno-base.h |
| |
5 | #define ENOENT 2 /* No such file or directory */ |
| |
|
| 1707 | | | i_error("unlink(%s) failed: %m", path); |
| 1708 | | | if (file_lock != NULL) |
| 1709 | | | file_lock_free(&file_lock); |
| 1710 | | | } else { |
| 1711 | | | squat_trie_close_fd(trie); |
| 1712 | | | trie->fd = fd; |
| 1713 | | | trie->locked_file_size = trie->hdr.used_file_size; |
| 1714 | | | if (trie->file_cache != NULL) |
| 1715 | | | file_cache_set_fd(trie->file_cache, trie->fd); |
| 1716 | | | |
| 1717 | | | if (ctx->file_lock != NULL) |
| 1718 | | | file_lock_free(&ctx->file_lock); |
| 1719 | | | ctx->file_lock = file_lock; |
| 1720 | | | } |
| 1721 | | | return ret; |
| 1722 | | | } |
| |