After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 727130 - Gnucash crashes on saving report with Newline in Report Name
Gnucash crashes on saving report with Newline in Report Name
Status: RESOLVED FIXED
Product: GnuCash
Classification: Other
Component: Reports
2.4.x
Other Linux
: Normal normal
: ---
Assigned To: gnucash-reports-maint
gnucash-reports-maint
Depends on:
Blocks:
 
 
Reported: 2014-03-27 02:02 UTC by Jay
Modified: 2018-06-29 23:28 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch to be applied on top of GnuCash 2.6.2 (1.92 KB, patch)
2014-03-30 10:01 UTC, Carsten Rinke
committed Details | Review

Description Jay 2014-03-27 02:02:37 UTC
After pasting a string containing a newline character into the Report Name field of the report options, applying the report options and clicking on the Save (floppy disk) icon in the report toolbar, Gnucash terminates without any visible message. Presumably, the string value is not being sanitized before further processing during the save action.

Incidentally, the report name appears in the page tab split (i.e., with the newline displayed), while the title displayed within the report itself has no newline evident.
Comment 1 Carsten Rinke 2014-03-27 09:23:26 UTC
I can confirm this bug for GnuCash 2.6.2. with Guile 1.8.

Tried it with the Income Statement report.

This is from the gnucash trace:

Backtrace:
In unknown file:
   ?: 0* [gnc:report-to-template-new #]
In /opt/gnucash-2.6.2/share/gnucash/scm/report.scm:
 686: 1* [gnc:report-to-template # #f]
 647: 2  (let* (# # # #) (if # # #f))
 655: 3* [eval-string ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Options for saved report \"new
line\", based on template \"0b81a3bdfd504aff849ec2e8630524bc\"
(let ()
 (define (options-gen)
  (let ((options (gnc:report-template-new-options/report-guid \"0b81a3bdfd504aff849ec2e8630524bc\" \"Income Statement\")))

; Section: Entries


; Section: Display


; Section: Commodities


; Section: Accounts


; Section: General

(let ((option (gnc:lookup-option options
                                 \"General\"
                                 \"Report name\")))
  ((lambda (option) (if option ((gnc:option-setter option) \"new
line\"))) option))

  options))
 (gnc:define-report 
  'version 1
  'name \"new
line\"
  'report-guid \"feb0491628496531e1976a1488ae0d18\"
  'parent-type \"0b81a3bdfd504aff849ec2e8630524bc\"
  'options-generator options-gen
  'menu-path (list gnc:menuname-custom)
  'renderer (gnc:report-template-renderer/report-guid \"0b81a3bdfd504aff849ec2e8630524bc\" \"Income Statement\")))

"]

/opt/gnucash-2.6.2/share/gnucash/scm/report.scm:655:23: In procedure eval-string in expression (eval-string saved-form):
/opt/gnucash-2.6.2/share/gnucash/scm/report.scm:655:23: Unbound variable: line

Anybody with permission, please set this report into status NEW.
Comment 2 Carsten Rinke 2014-03-27 18:59:33 UTC
The problem occurs during the format expression in report.scm function
(gnc:report-template-serialize-internal name type templ-name options guid):

(format #f ";; Options for saved report ~S, based on template ~S\n"
           name type)

Here the report name is written into a comment including the line break, and a comment is not supposed to be broken into several lines.

Once you comment out the lines 569 & 570 in report.scm all works fine again.
(just tried it out: saves fine, and you can load the saved configuration fine)

So one solution is to manipulate the name in this line before it is put into the string formater and eliminate the whitespace characters specifically at this point.

On the other:
Should whitespace characters in general be prohibited in a report title?

INFO NEEDED
Comment 3 Jay 2014-03-27 19:48:27 UTC
@Carsten: Thanks for looking into this. I forgot to mention that this issue can result in data loss (not only from the unsaved report configuration, but also from any unsaved transactions). Ordinarily, I would have marked it a higher priority, but it seems like an unusual use case.

"Should whitespace characters in general be prohibited in a report title?"

No, since the report title is displayed in the report itself. However, I would recommend replacing non-printing whitespace characters (tabs, newlines, hard spaces) with regular spaces as soon as the user input is processed by the dialog, and stripping any other non-printing characters. This would seem to cover a variety of possible issues, with minimal impact.
Comment 4 Carsten Rinke 2014-03-30 10:01:52 UTC
Created attachment 273280 [details] [review]
patch to be applied on top of GnuCash 2.6.2

I propose to make use of the glib function g_strescape().

It makes the non-printable sequences visible by translating e.g. newline to "\n" and adds it to the string.

With that the use will immediately become aware that there where escape sequences in the new title when looking at the report tab, and can then decide to do necessary updates manually afterwards, or just leave it as it is.

With g_strcompress() the translation can be reverted back, for the case that the escape sequences shall be saved in the title as string for possible later use.

See also the proposed patch attached.
Comment 5 Jay 2014-03-30 23:45:18 UTC
@Carsten: Your approach seems quite reasonable. Thanks.
Comment 6 Geert Janssens 2014-04-04 19:04:47 UTC
Comment on attachment 273280 [details] [review]
patch to be applied on top of GnuCash 2.6.2

That was a clever idea!

I have committed the patch as
https://github.com/Gnucash/gnucash/commit/c9b5a81b083968695723fa4a215a7dba591c7a05

Thank you very much !
Comment 7 Geert Janssens 2014-04-04 19:05:04 UTC
This problem has been fixed in our software repository. The fix will go into the next software release. Thank you for your bug report.
Comment 8 John Ralls 2016-01-17 19:51:55 UTC
Actually a very bad idea. g_strescape not only escapes non-printable characters, it escapes all non-ascii characters as well, totally hosing i18n on this field, causing bug 760711. Amazing that it took almost two years for anyone to notice!
Comment 9 John Ralls 2017-09-24 22:43:46 UTC
Reassign version to 2.4.x so that individual 2.4 versions can be retired.
Comment 10 John Ralls 2018-06-29 23:28:48 UTC
GnuCash bug tracking has moved to a new Bugzilla host. This bug has been copied to https://bugs.gnucash.org/show_bug.cgi?id=727130. Please update any external references or bookmarks.