Commit graph

26 commits

Author SHA1 Message Date
Goffredo Baroncelli f27f0e2177 core: fix crashes if locale.conf contains invalid utf-8 string
In the parse_env_file_push() and load_env_file_push() functions, there
are two assert() call to check if the key or value parameters are utf8 valid.

If the strings aren't utf8 valid, assert does abort.

These function are used early by systemd to parse some files. For
example '/etc/locale.conf'. In my case this file contained a not utf8
sequence, which is bad, but systemd crashed during the boot, which
is even worse!

The enclosed patch removes the assert and return -EINVAL if the
sequence is invalid. This is possible because the caller of these
function [1] checks the errors.
So the check of an invalid utf8 sequence is still performed, but
systemd doesn't crash anymore and logs the error.

[1] parse_env_file_internal(), invoked by load_env_file() and
parse_env_file()
2014-02-08 13:07:39 -05:00
Shawn Landden d78a28e3d7 fix regression of read_full_file() in fileio.c
my e93c33d4aa broke this stupidly
2013-11-30 23:04:17 -05:00
Shawn Landden e93c33d4aa systemctl: add "systemctl cat" 2013-11-30 22:20:20 -05:00
Zbigniew Jędrzejewski-Szmek 7ff7394d9e Never call qsort on potentially NULL arrays
This extends 62678ded 'efi: never call qsort on potentially
NULL arrays' to all other places where qsort is used and it
is not obvious that the count is non-zero.
2013-10-13 17:56:54 -04:00
Zbigniew Jędrzejewski-Szmek 1e5413f74f Add more tests and fix capability logging 2013-09-19 16:22:59 -05:00
David Strauss c22428fb73 Spelling fix from later revision of committed patch from Shawn Landden <shawn@churchofgit.com>. 2013-09-18 15:46:51 -05:00
Zbigniew Jędrzejewski-Szmek 4ec29144dd Fix capability logging when effective caps are 0
Shawn Landen> Doesn't this also skip the last '0' when it is all '0's?
              You need to keep the last one.
2013-09-18 11:43:29 -05:00
Zbigniew Jędrzejewski-Szmek 0a7b53bdd2 util: restore get_process_capeff behaviour
69ab8088 unified parsing of status files and removed the logic of
skipping extra '0's when getting the effective capabilities. Restore
that logic, so that the same capabilities are always mapped to the
same strings in the journal.
2013-09-17 18:37:32 -05:00
Zbigniew Jędrzejewski-Szmek 69ab808815 Advertise hibernation only if there's enough free swap
Condition that is checked is taken from upower:
  active(anon) < free swap * 0.98

This is really stupid, because the kernel knows the situation better,
e.g. there could be two swap files, and then hibernation would be
impossible despite passing this check, or the kernel could start
supporting compressed swap and/or compressed hibernation images, and
then this this check would be too stringent. Nevertheless, until
we have something better, this should at least return a true negative
if there's no swap.

Logging of capabilities in the journal is changed to not strip leading
zeros. I consider this more readable anyway.

http://cgit.freedesktop.org/upower/tree/src/up-daemon.c#n613
https://bugzilla.redhat.com/show_bug.cgi?id=1007059
2013-09-13 19:41:52 -04:00
Zbigniew Jędrzejewski-Szmek 335c46b598 Disallow invalid UTF-8 configuration
It is best to catch such errors early. If invalid UTF-8 ends up being
given to dbus methods, the program will crash:

process 20801: arguments to dbus_message_iter_append_basic() were incorrect, assertion "_dbus_check_is_valid_utf8 (*string_p)" failed in file dbus-message.c line 2598.
2013-08-28 08:04:56 -04:00
Zbigniew Jędrzejewski-Szmek 68fee104e6 journalctl: use _COMM= match for scripts
In case of scripts, _EXE is set to the interpreter name, and
_COMM is set based on the file name. Add a match for _COMM,
and _EXE if the interpreter is not a link (e.g. for yum,
the interpreter is /usr/bin/python, but it is a link to
/usr/bin/python2, which in turn is a link to /usr/bin/python2.7,
at least on Fedora, so we end up with _EXE=/usr/bin/python2.7).
I don't think that such link chasing makes sense, because
the final _EXE name is more likely to change.
2013-07-26 12:16:57 -04:00
Lennart Poettering 4ad490007b core: general cgroup rework
Replace the very generic cgroup hookup with a much simpler one. With
this change only the high-level cgroup settings remain, the ability to
set arbitrary cgroup attributes is removed, so is support for adding
units to arbitrary cgroup controllers or setting arbitrary paths for
them (especially paths that are different for the various controllers).

This also introduces a new -.slice root slice, that is the parent of
system.slice and friends. This enables easy admin configuration of
root-level cgrouo properties.

This replaces DeviceDeny= by DevicePolicy=, and implicitly adds in
/dev/null, /dev/zero and friends if DeviceAllow= is used (unless this is
turned off by DevicePolicy=).
2013-06-27 04:17:34 +02:00
Zbigniew Jędrzejewski-Szmek b4bc041b17 fileio: split write_one_line_file into two
The new function allows one to write to an already
open file.
2013-05-06 22:51:47 +02:00
Lennart Poettering 2b77f67e78 fileio: unify how we chop off whitespace from key and value in parse_env_file_internal() 2013-04-24 19:02:13 -03:00
Harald Hoyer 98f59e59e0 fileio.c: do not parse comments after non-whitespace chars
systemd does not want to understand comments after the first
non-whitespace char occured.

key=foo #comment  will result into key == "foo #comment"
key="foo" #comment  will result into key == "foo#comment"
"key= #comment" will result into key == "#comment"
"key #comment" is an invalid line
2013-04-18 11:29:00 +02:00
Harald Hoyer 7fd1b19bc9 move _cleanup_ attribute in front of the type
http://lists.freedesktop.org/archives/systemd-devel/2013-April/010510.html
2013-04-18 09:11:22 +02:00
Harald Hoyer ebc05a09ad core/execute: report invalid environment variables from files
Because "export key=val" is not supported by systemd, an error is logged
where the invalid assignment is coming from.

Introduce strv_env_clean_log() to log invalid environment assignments,
where logging is possible and allowed.

parse_env_file_internal() is modified to allow WHITESPACE in keys, to
report the issues later on.
2013-04-17 15:31:45 +02:00
Harald Hoyer db53720916 fileio:parse_env_file_internal() fix environment file parsing
parse_env_file_internal() could not parse the following lines correctly:

export key="val"
key="val"#comment
2013-04-17 11:06:25 +02:00
Mantas Mikulėnas ced2d10a28 fileio: also escape $ and ` when writing out env vars
These are also considered special by sh and bash.
2013-04-17 00:32:02 -04:00
Lennart Poettering fec6fc6bae fileio: don't check for errors more often than really necessary 2013-04-03 20:12:57 +02:00
Lennart Poettering 768100efd5 fileio: write proper env var write-out code
This will properly escape all weird chars when writing env var files.
With this in place we can now read and write environment files where the
values contain arbitrary weird chars.

This enables hostnamed and suchlike to finally properly save pretty host
names with backlashes or quotes in them.
2013-04-03 20:12:57 +02:00
Lennart Poettering f73141d765 shared: rework env file reader
Implement this with a proper state machine, so that newlines and
escaped chars can appear in string assignments. This should bring the
parser much closer to shell.
2013-04-03 20:12:57 +02:00
Lennart Poettering 574d5f2dfc util: rename write_one_line_file() to write_string_file()
You can write much more than just one line with this call (and we
frequently do), so let's correct the naming.
2013-04-03 20:12:56 +02:00
Zbigniew Jędrzejewski-Szmek 8333c77edf Always use errno > 0 to help gcc
gcc thinks that errno might be negative, and functions could return
something positive on error (-errno). Should not matter in practice,
but makes an -O4 build much quieter.
2013-03-29 10:12:41 -04:00
Zbigniew Jędrzejewski-Szmek 1c17cbed55 fileio: use _cleanup_ 2013-03-13 22:50:04 -04:00
Harald Hoyer a5c32cff1f honor SELinux labels, when creating and writing config files
Also split out some fileio functions to fileio.c and provide a SELinux
aware pendant in fileio-label.c

see https://bugzilla.redhat.com/show_bug.cgi?id=881577
2013-02-14 16:19:38 +01:00