buggtkmm-utils - Bugs: bug #22518, Glib::Util::trim functions...

 
 

bug #22518: Glib::Util::trim functions segfault on empty strings

Submitted by:  Jonathon Jongsma <jonner>
Submitted on:  Sun 09 Mar 2008 02:50:59 AM UTC  
 
Category: glibmm-utilsSeverity: 3 - Normal
Item Group: NoneStatus: Fixed
Privacy: PublicAssigned to: Marko Anastasov <markoa>
Open/Closed: Closed

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

(Jump to the original submission Jump to the original submission)

Sun 27 Apr 2008 03:14:26 PM UTC, comment #6:

Committed, thanks.

Marko Anastasov <markoa>
Project AdministratorIn charge of this item.
Sun 27 Apr 2008 02:52:30 PM UTC, comment #5:

I forgot to mention. Other than the warnings it seems to work fine now.

Jonathon Jongsma <jonner>
Sun 27 Apr 2008 02:51:14 PM UTC, comment #4:

I'm attaching a patch that changes the implementation to not print a critical warning when passing empty strings to trim() (which is pretty easy to do with programmatically generated strings). My usage was generating lots of warnings. I could have worked around it by manually checking if the strings were empty before trimming them, but I think this is cleaner, and I don't think printing a warning is necessary anyway.

(file #15534)

Jonathon Jongsma <jonner>
Sat 26 Apr 2008 11:17:45 PM UTC, comment #3:

Jonathon, can you test against current master head?

(I would like to make a maintainance release in the following week.)

Marko Anastasov <markoa>
Project AdministratorIn charge of this item.
Sun 09 Mar 2008 04:49:25 PM UTC, comment #2:

I have added empty string checks to those functions, although I cannot reproduce the segfault when calling trim*() with an empty string or a newline.

An idea I just got is to make these functions simple wrappers around g_strchomp(), g_strchug() and g_strstrip().

Marko Anastasov <markoa>
Project AdministratorIn charge of this item.
Sun 09 Mar 2008 02:55:15 AM UTC, comment #1:

hmm, apparently this isn't as easy to work around as I had thought. I can't just check if the string is non-empty before calling trim(). I think what is happening is that I am getting a string that is only a newline (e.g. "\n"). It's not empty, but when I call trim, it calls trim_left(), after which it becomes an empty string. then it calls trim_right(), and segfaults...

Jonathon Jongsma <jonner>
Sun 09 Mar 2008 02:50:59 AM UTC, original submission:

Backtrace from agave that shows the issue. You could suggest that I shouldn't call trim() on an empty string, and I probably shouldn't, but it still shouldn't be fatal.

(gdb) bt
#0 0xb6ede107 in isspace () from /lib/tls/i686/cmov/libc.so.6
#1 0xb72e877a in Glib::Util::trim (str=@0xbfacbf04) at ustring.cc:101
#2 0x080b9b5c in agave::SavedSetParser::on_text (this=0xbfacc060,
context=@0xbfacc090, text=@0xbfacbf48) at color-set-manager.cc:111
#3 0xb7280f0f in Glib::Markup::ParserCallbacks::text (context=0x815b870,
text=0x815b8e0 "\n", text_len=1, user_data=0xbfacbf04, error=0xbfacbfc0)
at markup.cc:186
#4 0xb717b738 in IA__g_markup_parse_context_parse (context=0x815b870,
text=0x815bc8c "<sets>\n<set id=\"49770f72d871f5067a0c0bd1e654f273d15c8661\">\n<name>Color Set 2</name>\n<description>testing</description>\n<colors>\n<color>e84d0b</color>\n<color>ff9e0c</color>\n<color>ff0000</color>\n<color"...,
text_len=517, error=0xbfacc018) at gmarkup.c:1497
#5 0xb7280723 in Glib::Markup::ParseContext::parse (this=0xbfacc090,
text=@0xbfacc0b0) at markup.cc:296
#6 0x080b5b56 in agave::ColorSetManager::load (this=0x8126174)
at color-set-manager.cc:198
#7 0x080b60df in ColorSetManager (this=0x8126174, filename=@0xbfacc384)
at color-set-manager.cc:155
#8 0x080661fd in Priv (this=0x8126078) at application-window.cc:78
#9 0x0806094b in ApplicationWindow (this=0x80ee120)
at application-window.cc:244
#10 0x0805f571 in agave::Application::Priv::run (this=0x80ee090)
at application.cc:93
#11 0x0805ebe6 in agave::Application::run (this=0xbfacc504)
at application.cc:114
#12 0x0805e553 in main (argc=-1227840920, argv=0xb6d0a668) at agave.cc:30
(gdb) up
#1 0xb72e877a in Glib::Util::trim (str=@0xbfacbf04) at ustring.cc:101
101 trim_right(str);
(gdb) p str.c_str()
$1 = 0x815b8d4 ""

Jonathon Jongsma <jonner>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

Attached Files
file #15534:  0001-trim-don-t-print-a-critical-warning-when-trying-t.patch added by jonner (1KiB - text/x-patch - Proposed improvement)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by markoa (Posted a comment)
  • -unavailable- added by jonner (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 5 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sun 27 Apr 2008 03:14:26 PM UTCmarkoaStatusReady For Test=>Fixed
      Open/ClosedOpen=>Closed
    Sun 27 Apr 2008 02:51:14 PM UTCjonnerAttached File-=>Added 0001-trim-don-t-print-a-critical-warning-when-trying-t.patch, #15534
    Sun 09 Mar 2008 04:49:25 PM UTCmarkoaStatusNone=>Ready For Test
      Assigned toNone=>markoa

    Back to the top


    Powered by Savane 3.1-cleanup1