summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-login/sd-login.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-07-29 22:01:36 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-07-31 04:00:31 -0400
commita2a5291b3f5ab6ed4c92f51d0fd10a03047380d8 (patch)
tree1a74a85c70861b0a411d9dd325b039976de4fd4e /src/libsystemd/sd-login/sd-login.c
parent73381fcf54e38456067f0e87b8611a21eff99169 (diff)
Reject invalid quoted strings
String which ended in an unfinished quote were accepted, potentially with bad memory accesses. Reject anything which ends in a unfished quote, or contains non-whitespace characters right after the closing quote. _FOREACH_WORD now returns the invalid character in *state. But this return value is not checked anywhere yet. Also, make 'word' and 'state' variables const pointers, and rename 'w' to 'word' in various places. Things are easier to read if the same name is used consistently. mbiebl_> am I correct that something like this doesn't work mbiebl_> ExecStart=/usr/bin/encfs --extpass='/bin/systemd-ask-passwd "Unlock EncFS"' mbiebl_> systemd seems to strip of the quotes mbiebl_> systemctl status shows mbiebl_> ExecStart=/usr/bin/encfs --extpass='/bin/systemd-ask-password Unlock EncFS $RootDir $MountPoint mbiebl_> which is pretty weird
Diffstat (limited to 'src/libsystemd/sd-login/sd-login.c')
-rw-r--r--src/libsystemd/sd-login/sd-login.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/libsystemd/sd-login/sd-login.c b/src/libsystemd/sd-login/sd-login.c
index 38ff944892..95cb6ff581 100644
--- a/src/libsystemd/sd-login/sd-login.c
+++ b/src/libsystemd/sd-login/sd-login.c
@@ -226,11 +226,10 @@ _public_ int sd_uid_get_display(uid_t uid, char **session) {
}
_public_ int sd_uid_is_on_seat(uid_t uid, int require_active, const char *seat) {
- char *w, *state;
_cleanup_free_ char *t = NULL, *s = NULL, *p = NULL;
size_t l;
int r;
- const char *variable;
+ const char *word, *variable, *state;
assert_return(seat, -EINVAL);
@@ -251,8 +250,8 @@ _public_ int sd_uid_is_on_seat(uid_t uid, int require_active, const char *seat)
if (asprintf(&t, UID_FMT, uid) < 0)
return -ENOMEM;
- FOREACH_WORD(w, l, s, state) {
- if (strneq(t, w, l))
+ FOREACH_WORD(word, l, s, state) {
+ if (strneq(t, word, l))
return 1;
}
@@ -587,10 +586,10 @@ _public_ int sd_seat_get_sessions(const char *seat, char ***sessions, uid_t **ui
}
if (uids && t) {
- char *w, *state;
+ const char *word, *state;
size_t l;
- FOREACH_WORD(w, l, t, state)
+ FOREACH_WORD(word, l, t, state)
n++;
if (n > 0) {
@@ -600,10 +599,10 @@ _public_ int sd_seat_get_sessions(const char *seat, char ***sessions, uid_t **ui
if (!b)
return -ENOMEM;
- FOREACH_WORD(w, l, t, state) {
+ FOREACH_WORD(word, l, t, state) {
_cleanup_free_ char *k = NULL;
- k = strndup(w, l);
+ k = strndup(word, l);
if (!k)
return -ENOMEM;
@@ -789,9 +788,8 @@ _public_ int sd_machine_get_class(const char *machine, char **class) {
_public_ int sd_machine_get_ifindices(const char *machine, int **ifindices) {
_cleanup_free_ char *netif = NULL;
size_t l, allocated = 0, nr = 0;
- char *w, *state;
int *ni = NULL;
- const char *p;
+ const char *p, *word, *state;
int r;
assert_return(machine_name_is_valid(machine), -EINVAL);
@@ -806,11 +804,11 @@ _public_ int sd_machine_get_ifindices(const char *machine, int **ifindices) {
return 0;
}
- FOREACH_WORD(w, l, netif, state) {
+ FOREACH_WORD(word, l, netif, state) {
char buf[l+1];
int ifi;
- *(char*) (mempcpy(buf, w, l)) = 0;
+ *(char*) (mempcpy(buf, word, l)) = 0;
if (safe_atoi(buf, &ifi) < 0)
continue;