Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite Loop #2

Closed
grandnew opened this issue Aug 23, 2018 · 2 comments
Closed

Infinite Loop #2

grandnew opened this issue Aug 23, 2018 · 2 comments

Comments

@grandnew
Copy link

I used Clang 6.0 and AddressSanitizer to build dbf2txt, in order to build it with clang in ubuntu 16.04 , the DbfFile.cpp and DbfFile.h should be motified like following:

diff --git a/DbfFile.cpp b/DbfFile.cpp
index 9a7692e..8e19db2 100644
--- a/DbfFile.cpp
+++ b/DbfFile.cpp
@@ -23,7 +23,10 @@ DbfFile_c::DbfFile_c(const char *szFileName):
        clFile(szFileName, std::ios_base::binary | std::ios_base::in)
 {
        if(!clFile.good())
-               throw std::exception("Cannot open file");
+       {
+               std::logic_error ex("Cannot open file");
+               throw std::exception(ex);
+       }

        clFile.read(reinterpret_cast<char *>(&stHeader), sizeof(stHeader));
        size_t sz = sizeof(DbfRecord_s);
@@ -120,7 +123,8 @@ void DbfFile_c::DumpFields(const char *szDestFileName, const char **fields, size
        {
                std::stringstream stream;
                stream << "Field not found: " << fields[current];
-               throw std::exception(stream.str().c_str());
+               std::logic_error ex(stream.str().c_str());
+               throw std::exception(ex);
        }

        //Now build the skip table
diff --git a/DbfFile.h b/DbfFile.h
index ed7b4e1..4cda65b 100644
--- a/DbfFile.h
+++ b/DbfFile.h
@@ -15,10 +15,10 @@ subject to the following restrictions:

 #ifndef DBF_FILE_H
 #define DBF_FILE_H
-
+#include <stdexcept>
 #include <fstream>
 #include <vector>
-
+#include <string.h>
 typedef unsigned char uint8_t;
 typedef unsigned short uint16_t;
 typedef unsigned int uint32_t;
@@ -77,4 +77,4 @@ class DbfFile_c
 };

This file can cause infinite loop when executing this command:

./dbf2txt infinite_loop.dbf 1.txt
@bcsanches
Copy link
Owner

Fixed! Thanks

@bcsanches
Copy link
Owner

The infinite loops seems to be a corrupted file, anyway, added code to avoid the loop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants