Thread View: grisbi.bugsreports
1 messages
1 total messages
Started by Grisbi Bug Tracker
Mon, 23 Nov 2026 21:44
[Grisbi 0002412]: Buffer overflow audit report
Author: Grisbi Bug Tracker
Date: Mon, 23 Nov 2026 21:44
Date: Mon, 23 Nov 2026 21:44
355 lines
15963 bytes
15963 bytes
The following issue has been SUBMITTED.
======================================================================
https://www.grisbi.org/bugsreports/view.php?id=2412
======================================================================
Reported By: eboudrand
Assigned To:
======================================================================
Project: Grisbi
Issue ID: 2412
Category: Main
Reproducibility: have not tried
Severity: major
Priority: high
Status: new
OS: Fedora
Version exact Grisbi: 3.92.1
Version OS:
Version GTK:
======================================================================
Date Submitted: 2026-11-23 21:44 UTC
Last Modified: 2026-11-23 21:44 UTC
======================================================================
Summary: Buffer overflow audit report
Description:
Author: written by Mistral Large 4, an AI coding assistant, from an audit of the
source tree.
Scope: source code in src/ (190 C files).
Method: manual review of unsafe patterns (strcpy, sprintf, g_sprintf, memcpy,
strncpy, negative sizes, loops without an end check) plus a GCC warning pass
(-O2 -Wformat=2 -Warray-bounds -Wstringop-overflow -Wformat-overflow=2). The GCC
pass found no overflow warning. The manual review found the issues below.
The main attack vector is a crafted .gsb file that the user opens in Grisbi.
Issues are ranked by importance (severity x ease of triggering).
---------------------------------------------------------------------
1. Stack buffer overflow in utils_str_dtostr - SEVERITY: HIGH
Location: src/utils_str.c:941
Problem: the function writes with g_sprintf into a 39-byte stack buffer
(G_ASCII_DTOSTR_BUF_SIZE). g_sprintf has no size limit. The precision value
comes from the currency floating point. This value is read from the .gsb file
without range check (src/gsb_file_load.c:1837). A large floating point value
(for example 1,000,000) or a large amount (1e308 prints as 309 digits) writes
far past the 39-byte buffer. The return-value check at line 943 runs after the
write, so it cannot prevent the overflow. The check also uses > instead of >=,
so the trailing NUL byte can still write one byte past the buffer.
Callers: src/bet_data.c:806-815, src/gsb_file_save.c:891-895,
src/bet_data_finance.c:204
Trigger: open a .gsb file that sets a high currency floating point (or a huge
loan amount), then save the file.
---------------------------------------------------------------------
2. Stack buffer overflow in the loan schedule rate - SEVERITY: HIGH
Location: src/bet_finance_ui.c:208
Problem: g_sprintf writes s_echeance->taux with format "%.*f" into a 256-byte
stack buffer. taux is a double read from the .gsb file. A rate near 1e308 prints
about 313 characters, which overflows the 256-byte buffer.
Trigger: open a .gsb file with a huge loan rate, then display the amortization
table.
---------------------------------------------------------------------
3. Heap over-read and negative sizes in the OpenSSL plugin - SEVERITY: HIGH
Locations: src/plugins/openssl/openssl.c:172, 248, 264, 295, 315; detection at
src/gsb_file_load.c:4031-4032
Problem: Grisbi detects an encrypted file by comparing only the first 19 bytes
("Grisbi encryption v"). Then:
- If the file is 19 to 21 bytes long, length - V3_MARKER_SIZE is negative. This
negative value goes to g_malloc, memset, and EVP_CipherUpdate. The program
aborts or crashes. In decrypt_v2 and decrypt_v1, the unsigned subtraction length
- V2_MARKER_SIZE wraps to a huge value, so g_malloc aborts the program.
- If the file is 22 to 43 bytes long, strncmp reads up to 22/23 bytes from a
heap buffer that is only length - 22 (+1) bytes long. This is a heap over-read.
Trigger: open a fake encrypted file of 19 to 43 bytes.
---------------------------------------------------------------------
4. Out-of-bounds read and write in the QIF anonymizer - SEVERITY: MEDIUM
Location: src/file_obfuscate_qif.c:280-281, 240, 232-235, 242
Problems:
- The loop "while (file_content[*position] != '\n')" does not check for the NUL
terminator. If the file does not end with \n on a skipped line (!, ^, C, D, [),
the loop reads past the end of the heap buffer without limit.
- The main loop can read and write (file_content[position] =
g_random_int_range(...)) after the final NUL byte.
- filename[strlen(filename) - 4] = 0 has no length check. If the file name is
shorter than 4 characters, the index is negative and the write goes before the
buffer.
Trigger: run the QIF anonymizer on a crafted .qif file.
---------------------------------------------------------------------
5. One-byte heap overflow in the reconcile label builder - SEVERITY: LOW
Location: src/widgets/widget_reconcile.c:661
Problem: sprintf writes into a heap buffer sized from the name. If the reconcile
name ends with a 10-digit number >= 2^31 (for example R2147483648), atoi
overflows (src/utils_str.c:377). The result is an 11-character negative number,
which is longer than the allocated width of 10. sprintf then writes one byte
past the heap buffer. An empty name also causes undefined pointer arithmetic at
old_label + (strlen - 1).
Trigger: open a .gsb file that contains a reconcile named for example
R2147483648 (calls at src/gsb_assistant_reconcile_config.c:183 and
src/widget_reconcile.c:707).
---------------------------------------------------------------------
6. Negative index write - pattern strlen(x) - 4 without a guard - SEVERITY: LOW
Locations: src/file_obfuscate.c:419, 562, src/erreur.c:568,
src/file_obfuscate_qif.c:242
Problem: x[strlen(x) - 4] = 0 assumes the name is at least 4 characters long. A
file named for example "ab" gives index -2. The write goes before the start of
the buffer.
Note: src/gsb_dirs.c:374 and src/gsb_file.c:104 use the same pattern but check
the .gsb suffix first. They are safe.
---------------------------------------------------------------------
7. Missing NUL termination after strncpy in graph labels - SEVERITY: LOW
Locations: src/bet_graph.c:468, 488, 657, 772, 856
Problem: strncpy(dst, src, TAILLE_MAX_LIBELLE - 1) does not write a NUL byte if
the label is 49 characters or longer. Category or budget names can be that long,
for example after a file import. The code then reads past the end of the label
row.
Impact limit: the read stays inside the struct in this case, because tab_libelle
is not the last struct member.
---------------------------------------------------------------------
CHECKED AND NOT AFFECTED
- All g_printf/g_print calls use literal format strings. There is no
format-string vulnerability (-Wformat=2 reports nothing).
- g_sprintf(buffer, "%.0f", (gdouble) units.quot) at src/gsb_real.c:370, 948 is
safe: the value is a long long, so at most about 20 characters.
- strcpy(buffer_date, "???") at src/etats_support.c:290-404 is safe: the buffer
is 256 bytes.
- Whole-struct memcpy calls are safe: src/gsb_data_report.c:3865,
src/gsb_data_transaction.c:2156, src/gsb_data_scheduled.c:1705.
- gsb_file_save_append_part (src/gsb_file_save.c:2020-2044) is safe: the buffer
grows by 1.5x and the initial size is greater than 0 (line 1763).
- src/gsb_form.c:2629-2638 is safe: the copy fits exactly in the allocated
strlen + 2 bytes.
- src/utils_files.c:547 is safe: j + 1 + 30*sizeof(gchar) equals j + 31.
- Bounded g_snprintf with a return check: src/gsb_real.c:374,
src/dialog.c:880-881.
- src/csv_parse.c (sanitize_field) keeps all reads inside the string.
- There is no alloca, variable-length array, gets, strcat, or vsprintf in src/.
---------------------------------------------------------------------
Steps to Reproduce:
Issue 1 :
- file : issue1_currency_fl.gsb.
- Steps: start Grisbi, open issue1_currency_fl.gsb, then save the file (Ctrl+S).
- Before fix: stack buffer overflow in utils_str_dtostr on save (crash).
- After fix: the file saves normally and the floating point is clamped to 8.
Issue 2 :
- file : none; take issue2_to_modify.gsb and edit its XML: in the <General>
section set Bet_taux_annuel="1e308" (this attribute is read at
src/gsb_file_load.c:2024 into w_etat->bet_taux_annuel). Alternatively add a
saved loan with a huge rate: <Bet_loan Nb="1" ... Taux="1e308" .../> (attribute
"Taux" read at src/gsb_file_load.c:1331).
- Steps: open that crafted .gsb file, then open the BET tab (loan simulator) so
the amortization schedule is computed and displayed; the rate is formatted at
src/bet_finance_ui.c:208.
- Before fix: 256-byte stack buffer overflow in bet_finance_ui.c (g_sprintf of
the rate into buffer[256]; 1e308 prints about 313 characters).
- After fix: rate is written with g_snprintf and clamped, no overflow.
Issue 3 :
- file : issue3_encrypted_19b.gsb (19 bytes, starts with "Grisbi encryption v")
and issue3_encrypted_30b.gsb (30 bytes).
- Steps: start Grisbi and open one of these files. No password needs to be
entered: the files contain only a fake encryption marker, so any input in the
password dialog is accepted, and the bug triggers during the decryption attempt
itself, before any password validation.
- Before fix: issue3_encrypted_19b.gsb aborts (negative length goes to
g_malloc/EVP_CipherUpdate, then unsigned wrap in decrypt_v2);
issue3_encrypted_30b.gsb causes a heap over-read in the strncmp marker check of
decrypt_v2/decrypt_v1 (visible with AddressSanitizer).
- After fix: both files are rejected cleanly with a password/open error dialog.
Issue 4 :
- file : issue4_qif_nextline.qif (ends with a D line, no trailing newline) and
issue4_qif_mainloop.qif (ends with T-10.00, no trailing newline).
- Steps: in Grisbi, use the menu entry that anonymizes a QIF file and select the
PoC file.
- Before fix: file_obfuscate_qif_next_line scans past the NUL terminator without
limit (ASan heap-buffer-overflow / possible segfault), and the main loop can
read/write past the final NUL.
- After fix: the scan stops at the NUL byte and the file is processed or skipped
safely.
Issue 5 :
- file : issue5_reconcile.gsb
- Steps: open issue5_reconcile.gsb, then open the reconcile assistant / start a
reconciliation for the account (widget_reconcile_build_label is called).
- Before fix: atoi overflow makes sprintf write one byte past the heap buffer
(visible with AddressSanitizer).
- After fix: snprintf with the allocated size, label built safely.
Issue 6 :
- file : ab (1 byte, name shorter than 4 characters).
- Steps: open or anonymize a file named "ab" (the obfuscate/debug paths strip
the extension with strlen(x) - 4).
- Before fix: write at a negative index, before the buffer (1-byte heap
underflow).
- After fix: the .gsb/.qif suffix is checked first, no write happens.
Issue 7 :
- file : none; craft a .gsb file with a category or budget name of 49 characters
or more.
- Steps: open that file, then open the BET graph for that division.
- Before fix: strncpy does not NUL-terminate the label row and later reads go
past the row.
- After fix: the last byte of each row is forced to NUL.
======================================================================
Issue History
Date Modified Username Field Change
======================================================================
2026-11-23 21:44 eboudrand New Issue
2026-11-23 21:44 eboudrand File Added: ab
2026-11-23 21:44 eboudrand File Added: issue1_currency_fl.gsb
2026-11-23 21:44 eboudrand File Added: issue2_to_modify.gsb
2026-11-23 21:44 eboudrand File Added: issue3_encrypted_19b.gsb
2026-11-23 21:44 eboudrand File Added: issue3_encrypted_30b.gsb
2026-11-23 21:44 eboudrand File Added: issue4_qif_mainloop.qif
2026-11-23 21:44 eboudrand File Added: issue4_qif_nextline.qif
2026-11-23 21:44 eboudrand File Added: issue5_reconcile.gsb
======================================================================
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads