summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* py3: ensure python output is not lostAndy Clayton2020-03-261-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Unbuffer python's stdio to avoid output getting stuck in buffer when stdout is not a TTY. Normally buffers are flushed by `Py_Finalize` but Boost has a long-standing issue preventing the proper shutdown of the interpreter with `Py_Finalize` when embedded [1]. This applies the same fix as 139beba but to any ledger usage rather than only the test suite. I removed `PYTHONUNBUFFERED=1` from tests as there is no expectation that users should need to have this set for ledger to function. For example without this fix piping ledger into cat usually loses any output (unless the output is large enough to cause the buffer to flush): $ ./ledger -f "test/baseline/feat-value_py3.test" reg <class 'bool'> True [...] $ ./ledger -f "test/baseline/feat-value_py3.test" reg | cat $ Interestingly `--verify` causes `python_interpreter_t` to be destroyed -- it doesn't appear to be otherwise -- which does call `Py_Finalize`. As expected this fixes the issue but can also crash due to the boost issue mentioned above: $ ./ledger -f "test/baseline/feat-value_py3.test" --verify reg <class 'bool'> True [...] Segmentation fault (core dumped) $ ./ledger -f "test/baseline/feat-value_py3.test" --verify reg | cat <class 'bool'> True [...] $ 1. https://www.boost.org/doc/libs/1_62_0/libs/python/doc/html/tutorial/tutorial/embedding.html
* py3: fix builtin ledger module for python commandAndy Clayton2020-03-261-13/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With python3 the `python` ledger command wound up loading the ledger module shared library rather than using the builtin module as intended. This resulted in duplicated initialization and crashing on cleanup. It was also visible as duplicate converter warnings when importing ledger: $ ./ledger --no-pager python Python 3.7.5 (default, Nov 20 2019, 09:21:52) [...] >>> import ledger /usr/lib/python3.7/importlib/_bootstrap.py:219: RuntimeWarning: to-Python converter for boost::posix_time::ptime already registered; second conversion method ignored. [...] /usr/lib/python3.7/importlib/_bootstrap.py:219: RuntimeWarning: to-Python converter for ledger::xact_t already registered; second conversion method ignored. [...] >>> ledger <module 'ledger' from '/home/q/src/ledger/ledger.so'> >>> exit() Segmentation fault (core dumped) After this change: Python 3.7.5 (default, Nov 20 2019, 09:21:52) [...] >>> import ledger >>> ledger <module 'ledger' (built-in)> >>> exit() $ Switches to PyImport_AppendInittab from python::detail::init_module because 1) that is what the boost docs and examples show and 2) init_module appears to be undocumented and not intended for outside use. Fixes #1867
* fix python3 command (argv) wchar_t conversionAndy Clayton2020-03-261-4/+6
| | | | | | | | | | Ensure strings passed to Py_Main have a terminating null character by including the extra character allocated for terminating null in the size passed to mbstowcs. Fix argv index so all arguments are not copied to argv[0]. Fixes potential buffer overflow due to passing argv[0] as destination with argv[i + 1] src and size to mbstowcs.
* Specify namespace of uintmax_takater2020-03-033-6/+6
| | | | | | | This fixes #1833 for me. @jwiegley said it's reasonable change, and nobody else took action so here it goes. The patch is the same as proposed originally, modulo whitespace.
* fix #1850: segfault when using ledger printTobias Pankrath2020-01-081-1/+1
|
* Add --averaged-lot-pricesJohn Wiegley2019-12-064-0/+81
| | | | | This joins together lots of the same underlying, averaging the reported price and using the date of the oldest lot.
* Port to python3Dimitri John Ledkov2019-12-058-17/+63
|
* Modernize CMake using backported FindPython module.Dimitri John Ledkov2019-12-051-14/+5
|
* Format annotations using format that can be parsedOleg Bulatov2019-11-272-1/+3
| | | | | | | | | | | | | | | | | I expect an output of `ledger print` to be consumable by ledger. But on the next journal ``` 2019/11/25 * test Foo 1 AAPL {1.00 EUR} [2019/11/24] Bar ``` it prints [19-Nov-24], which it does not understand with default options. With this patch it prints [2019/11/24].
* Correction to the way parens are parsed in query expressionsJohn Wiegley2019-09-172-9/+47
|
* Remove know-ification of elements due to post stateCandyAngel2019-08-271-20/+0
|
* Switch from using utf8::is_bom to utf8::starts_with_bomJohn Wiegley2019-08-181-1/+3
| | | | Fixes #1816
* option: fix typo in error messageChristian Dietrich2019-08-011-1/+1
|
* Remove an unneeded commentJohn Wiegley2019-07-051-9/+0
|
* Change --invert to invert displayed amounts and totals, not amountsJohn Wiegley2019-07-051-1/+2
|
* Add support for '%F' date format specifierMichael Budde2019-04-021-7/+7
| | | | | | | | | '%F' is equivalent to '%Y-%m-%d'. Using the '%F' format without this change this would not give any hard errors but instead give dates with wrong years because the 'has_year' trait would not be correctly detected and thus parsed dates would get set to the current year. Fixes #1775
* Remove dead codeMichael Budde2019-04-021-9/+0
|
* Fix tag value parsingMichael Budde2019-03-301-1/+1
| | | | | | | | | | | | If a tag is more than 2 characters from the beginning of the comment the tag value offset will be wrong. #1702 gives an example where the tag line starts with `;;` and the tag value thus becomes `: Bar` because of this bug. The use `index` in the offset calulation seems to be a lucky coincidence that works in the common case: "; tag: value" Fixes #1702
* Reject postings with comment after flagMichael Budde2019-03-301-1/+1
| | | | Fixes #1753
* Explicitly sort when creating the equity reportJohn Wiegley2019-03-151-11/+11
|
* Greatly simplify balance_t::operator==John Wiegley2019-03-151-8/+1
|
* Switch amounts_map to std::unordered_mapJohn Wiegley2019-03-152-1/+2
|
* Remove the 'org' command, which was always a hack to begin withJohn Wiegley2019-03-155-305/+0
|
* Change compare_by_commodity to return an integerJohn Wiegley2019-03-154-80/+108
|
* Further improvements to commodity sortingJohn Wiegley2019-03-151-4/+6
|
* Add more debugging information to compare_by_commodityJohn Wiegley2019-03-151-13/+41
|
* Add back some whitespace for clarityJohn Wiegley2019-01-301-1/+1
|
* Expose a new utility function for balances: sorted_amountsJohn Wiegley2019-01-302-9/+16
|
* Update copyright statement for 2019Martin Michlmayr2019-01-301-2/+2
|
* Add Travis CI setup for macOS and homebrew-installed BoostTim Landscheidt2019-01-301-1/+3
| | | | | | | | | | | | | | | | On macOS, CMake detects the Boost.Python component installed by homebrew only when named "python27". Thus this change not only adds a Travis CI setup for macOS, but also a CMake option to switch the component name between "python" and "python27". In addition, precompiling system.hh does not work with the current setup for Clang, so another CMake option to disable it is added. The currently used commands to compile specific versions of Boost do not produce a result that works out of the box on macOS. It should be possible just to mimic homebrew's formula for boost-python (https://github.com/Homebrew/homebrew-core/blob/master/Formula/boost-python.rb), but for the moment on macOS this change tests only against Boost installed by homebrew.
* Fix use-after-free when destroying filter chainMichael Budde2019-01-281-0/+1
| | | | | | | | | | | | | | | | When using the `--gain` option the `temporaries_t` in `changed_value_posts` filter stores a reference to the `<Revalued>` temp account created in `display_filter_posts`. When destroying the filter chain `display_filter_posts` is destroyed before `changed_value_posts` and this can result in a use-after-free in `temporaries_t::clear()` when `temps` in `changed_value_posts` is cleared during destruction if there are any temp posts referencing the `<Revalued>` account. Fix the issue by clearing the `temporaries_t` in `changed_value_posts` before destroying the rest of the filter chain (which includes `display_filter_posts`). Fixes #541
* Use CMAKE_CXX_COMPILER_ID for conditions based on compilerTim Landscheidt2019-01-261-2/+2
| | | | | | | | | CMAKE_CXX_COMPILER is the path to the compiler binary and does not need to follow a specific pattern. For example, on Linux with GCC and without an explicit "-DCMAKE_CXX_COMPILER:PATH=" option, CMAKE_CXX_COMPILER is "/usr/bin/c++" which does not match "g++". CMAKE_CXX_COMPILER_ID however will always reliably be "Clang" or "GNU".
* Fix possible stack overflow in option parsing routineMartin Michlmayr2019-01-261-0/+5
| | | | | | | | | | | | | | | It is possible to create a stack overflow by giving an option that is longer than the buffer that is used during option parsing because the length of the input string is not checked. Prevent the issue by always checking the input string length and discarding options that does not fit in the buffer as invalid. This issue has been assigned CVE-2017-12481. Thanks to Gwan Yeong Kim for reporting this issue. Fixes #1222
* Fix possible stack overflow in date parsing routineMichael Budde2019-01-261-1/+3
| | | | | | | | | | | | | | | It is possible to create a stack overflow by giving a date that is longer than the buffer that is used during date parsing because the length of the input string is not checked. The `VERIFY` macro is only enabled when debug-mode is enabled and the `--verify-memory` argument is used. Prevent the issue by always checking the input string length and discarding dates that does not fit in the buffer as invalid. This issue has been assigned CVE-2017-12482. Fixes #1224
* Merge pull request #1657 from ↵John Wiegley2019-01-251-1/+1
|\ | | | | | | | | nagakiran/timelog-checkin-multiple-accounts-at-a-time Timelog: Not able to check-in to multiple accounts at a time
| * Timelog: Not able to check-in to multiple accounts at a timeNaga Kiran2018-06-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | Checking-in to multiple accounts at a time throws the following error "When multiple check-ins are active, checking out requires an account" Issue is that the acount name was sent as 3rd parameter to time_xact_t constructor whereas it is supposed to be sent as 4th parameter Corrected the argument position of account name in constructor call to time_xact_t
* | Merge pull request #1726 from scfc/compile-strptime-only-on-windowsJohn Wiegley2019-01-252-5/+12
|\ \ | | | | | | Compile strptime.cc only on Windows
| * | Compile strptime.cc only on WindowsTim Landscheidt2019-01-162-5/+12
| | |
* | | Merge pull request #1736 from scfc/drop-conditionals-for-boost-earlier-than-1-49John Wiegley2019-01-257-62/+4
|\ \ \ | | | | | | | | | | | | | | | | Drop conditionals for Boost earlier than 1.49
| * | | Drop conditionals for Boost earlier than 1.49Tim Landscheidt2019-01-177-64/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Ledger requires Boost 1.49 or later and enforces this in CMakeLists.txt. This means BOOST_VERSION will always be 104900 or higher. Also, since Boost 1.46, BOOST_FILESYSTEM_VERSION is 3.
* | | | Merge pull request #1745 from mbudde/ignore-null-deferred-postingsJohn Wiegley2019-01-251-3/+5
|\ \ \ \ | | | | | | | | | | | | | | | | | | | | Ignore null deferred postings
| * | | | Ignore null deferred postingsMichael Budde2019-01-231-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | All-null transactions (i.e. a transaction where all postings have a null amount) are discarded during parsing and the `xact` object is free'd. But if the transaction contains a deferred posting this results in a use-after-free vulnerability because a reference to the deferred posting is stored in the account object which is later read when deferred postings are applied after parsing is finished. Ignore null deferred postings to prevent this – they should not have any effect any way. Thanks to Cory Duplantis for reporting this issue and providing an initial analysis. Ref TALOS-2017-0304, CVE-2017-2808 Fixes #1723
* | | | | Expose post_t::given_cost over pythonChristoph Dittmann2019-01-251-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes #1655 by making the post_t::given_cost variable accessible over python. This allows access to the given cost of a posting. For example, here it will be "-2 EUR": A -2 XXX {1 EUR} [2018-01-01] @@ 2 EUR If a per-unit cost is given, the given_cost variable will still contain the cost of the posting. For example, here it will be "-4 EUR": B -2 XXX {1 EUR} [2018-01-01] @ 2 EUR
* | | | | Drop support for gcc 2 and earlierTim Landscheidt2019-01-2514-97/+65
| | | | |
* | | | | Remove workaround for isspace() on FreeBSD 4 and earlierTim Landscheidt2019-01-251-5/+0
|/ / / / | | | | | | | | | | | | | | | | | | | | | | | | FreeBSD 4 was declared end-of-life in 2006 (https://lists.freebsd.org/pipermail/freebsd-security/2006-October/004111.html). Currently, only FreeBSD 11 and 12 are supported (https://www.freebsd.org/security/security.html#sup).
* / / / Remove unused development code related to USE_BOOST_FACETSTim Landscheidt2019-01-172-82/+2
|/ / / | | | | | | | | | | | | The code can be accessed by Git history and reused in a branch if necessary.
* / / Fix some boost format stringsTommi Komulainen2019-01-172-4/+4
|/ / | | | | | | | | | | Fixes: Error: boost::bad_format_string: format-string is ill-formed
* | Fix parsing issue involving effective datesMartin Michlmayr2019-01-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Cory Duplantis reported that "A specially crafted journal file can cause [an] integer underflow resulting in code execution". Cory provided this test case: Expenses:Food:Groceries $ 37.50 ; ] [=2004/01/01] Note the ] that comes before [ after the ;. This issue was reported and described in great detail by Cory Duplantis of Cisco Talos. This issue is known as TALOS-2017-0303 and has been assigned CVE-2017-2807. Cory's description can be found at https://www.talosintelligence.com/vulnerability_reports/TALOS-2017-0303 Fixes #1722
* | Merge branch 'next' into move-have-editJohn Wiegley2019-01-147-22/+9
|\ \
| * \ Merge pull request #1707 from scfc/remove-sys-stat-hJohn Wiegley2019-01-141-1/+0
| |\ \ | | | | | | | | Remove unnecessary include for sys/stat.h