NTFS_BUG() was broken because it relied on dereferencing a NULL pointer.
This is undefined behavior, and gcc was compiling out the statement.
Crashing in library code is also unfriendly in general.

There were only two users.  Make them just use regular error handling.

Signed-off-by: Eric Biggers <ebigge...@gmail.com>
---
 include/ntfs-3g/debug.h |  8 --------
 libntfs-3g/mft.c        | 12 ++++++++----
 2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/include/ntfs-3g/debug.h b/include/ntfs-3g/debug.h
index f7f3c6f..dba400b 100644
--- a/include/ntfs-3g/debug.h
+++ b/include/ntfs-3g/debug.h
@@ -36,12 +36,4 @@ extern void ntfs_debug_runlist_dump(const struct 
_runlist_element *rl);
 static __inline__ void ntfs_debug_runlist_dump(const struct _runlist_element 
*rl __attribute__((unused))) {}
 #endif
 
-#define NTFS_BUG(msg)                                                  \
-{                                                                      \
-       int ___i = 1;                                                   \
-       ntfs_log_critical("Bug in %s(): %s\n", __FUNCTION__, msg);      \
-       ntfs_log_debug("Forcing segmentation fault!");                  \
-       ___i = ((int*)NULL)[___i];                                      \
-}
-
 #endif /* defined _NTFS_DEBUG_H */
diff --git a/libntfs-3g/mft.c b/libntfs-3g/mft.c
index 29f1f4b..85cd120 100644
--- a/libntfs-3g/mft.c
+++ b/libntfs-3g/mft.c
@@ -1276,8 +1276,10 @@ static int ntfs_mft_record_init(ntfs_volume *vol, s64 
size)
        
        /* Sanity checks. */
        if (mft_na->data_size > mft_na->allocated_size ||
-           mft_na->initialized_size > mft_na->data_size)
-               NTFS_BUG("mft_na sanity checks failed");
+           mft_na->initialized_size > mft_na->data_size) {
+               ntfs_log_critical("mft_na sanity checks failed");
+               goto undo_data_init;
+       }
        
        /* Sync MFT to minimize data loss if there won't be clean unmount. */
        if (ntfs_inode_sync(mft_na->ni))
@@ -1343,8 +1345,10 @@ static int ntfs_mft_rec_init(ntfs_volume *vol, s64 size)
        
        /* Sanity checks. */
        if (mft_na->data_size > mft_na->allocated_size ||
-           mft_na->initialized_size > mft_na->data_size)
-               NTFS_BUG("mft_na sanity checks failed");
+           mft_na->initialized_size > mft_na->data_size) {
+               ntfs_log_critical("mft_na sanity checks failed");
+               goto undo_data_init;
+       }
 out:   
        ntfs_log_leave("\n");
        return ret;
-- 
2.9.3


------------------------------------------------------------------------------
_______________________________________________
ntfs-3g-devel mailing list
ntfs-3g-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ntfs-3g-devel

Reply via email to