Summary: | Crash while reading service files with missing parameters | ||
---|---|---|---|
Product: | dbus | Reporter: | Mantas Mikulėnas <grawity> |
Component: | core | Assignee: | Havoc Pennington <hp> |
Status: | RESOLVED FIXED | QA Contact: | |
Severity: | normal | ||
Priority: | medium | CC: | chengwei.yang.cn |
Version: | unspecified | Keywords: | patch |
Hardware: | Other | ||
OS: | All | ||
Whiteboard: | review- | ||
i915 platform: | i915 features: | ||
Attachments: |
Fix dbus-deamon crash due to invalid service file
[PATCH v2] Fix dbus-daemon crash due to invalid service file |
Description
Mantas Mikulėnas
2013-02-14 17:55:41 UTC
Created attachment 80115 [details] [review] Fix dbus-deamon crash due to invalid service file This bug caused by invalid service file, whih key/value starts without any section, so in new_line(), it will try to access invalid address. Comment on attachment 80115 [details] [review] Fix dbus-deamon crash due to invalid service file Review of attachment 80115 [details] [review]: ----------------------------------------------------------------- ::: bus/desktop-file.c @@ +322,5 @@ > BusDesktopFileSection *section; > BusDesktopFileLine *line; > > + if (parser == NULL || parser->current_section < 0) > + return NULL; Is it valid for parser to be NULL here? If not, don't check for it. The only caller of new_line() assumes that returning NULL means out-of-memory: if (line == NULL) { dbus_free (value); parser_free (parser); BUS_SET_OOM (error); return FALSE; } so if you want new_line() to be able to fail, it will need to take a DBusError argument so it can signal the right error. However, I think a better way to fix this would be to change parse_key_value() so that it raises an error if current_section < 0 instead of calling new_line(), or even to change bus_desktop_file_load() so that it doesn't call parse_key_value() before it has opened the first section. Something like this pseudocode: if (/* it's a new section heading */) ... else if (/* .. it's a comment or blank */) ... else if (parser.current_section < 0) { raise error FAILED, "invalid desktop file: key=value before [Section]" } else { ... parse_key_value (...) ... } (In reply to comment #2) > Comment on attachment 80115 [details] [review] [review] > Fix dbus-deamon crash due to invalid service file > > Review of attachment 80115 [details] [review] [review]: > ----------------------------------------------------------------- > > ::: bus/desktop-file.c > @@ +322,5 @@ > > BusDesktopFileSection *section; > > BusDesktopFileLine *line; > > > > + if (parser == NULL || parser->current_section < 0) > > + return NULL; > > Is it valid for parser to be NULL here? If not, don't check for it. OK, will drop it in v2. > > The only caller of new_line() assumes that returning NULL means > out-of-memory: > > if (line == NULL) > { > dbus_free (value); > parser_free (parser); > BUS_SET_OOM (error); > return FALSE; > } > > so if you want new_line() to be able to fail, it will need to take a > DBusError argument so it can signal the right error. > > However, I think a better way to fix this would be to change > parse_key_value() so that it raises an error if current_section < 0 instead > of calling new_line(), or even to change bus_desktop_file_load() so that it > doesn't call parse_key_value() before it has opened the first section. Yes, a simple check is already there, however, I'll upload v2 with raise an error like below you suggested. > Something like this pseudocode: > > if (/* it's a new section heading */) > ... > else if (/* .. it's a comment or blank */) > ... > else if (parser.current_section < 0) > { > raise error FAILED, "invalid desktop file: key=value before [Section]" > } > else > { > ... parse_key_value (...) ... > } Created attachment 80380 [details] [review] [PATCH v2] Fix dbus-daemon crash due to invalid service file Applied, will be in 1.7.4. |
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.