New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unit names with _{a-f}{a-f} in them cause dbus to crash #49

Merged
merged 1 commit into from Jun 28, 2014

Conversation

Projects
None yet
5 participants
@jonboulle
Contributor

jonboulle commented Jun 27, 2014

Fun and profit.

go program to reproduce:

package main

import (
    "fmt"
    "io/ioutil"
    "os"
    "strings"

    "github.com/coreos/go-systemd/dbus"
)

const contents = `[Service]
ExecStart=/bin/true
`

func log(f string, v ...interface{}) {
    msg := fmt.Sprintf(f, v...)
    if !strings.HasSuffix(msg, "\n") {
        msg += "\n"
    }
    fmt.Printf(msg)
}
func die(f string, v ...interface{}) {
    fmt.Fprintf(os.Stderr, f, v...)
    os.Exit(1)
}

func main() {
    if len(os.Args) != 2 {
        die("usage: %s UNIT_NAME\n", os.Args[0])
    }
    name := os.Args[1]
    path := "/tmp/" + name
    sd, err := dbus.New()
    if err != nil {
        die("error initializing dbus connection: %v\n", err)
    } else {
        log("initialized dbus connection")
    }

    if err := ioutil.WriteFile(path, []byte(contents), os.FileMode(0644)); err != nil {
        die("error writing unit: %v\n", err)
    } else {
        log("wrote unit to disk")
    }

    if _, err = sd.LinkUnitFiles([]string{path}, true, true); err != nil {
        die("error linking unit file: %v\n", err)
    } else {
        log("linked runtime unit file")
    }

    if err := sd.Reload(); err != nil {
        die("error reloading systemd: %v\n", err)
    } else {
        log("reloaded systemd")
    }

    if info, err := sd.GetUnitProperties(name); err != nil {
        die("error getting unit properties: %v\n", err)
    } else {
        log("unit properties: %v\n", info)
    }
    os.Exit(0)
}

script to test cases:

#!/bin/bash

trap "exit" INT

pkill dbus-daemon
for i in - _ a b c d e f g h i j k l m n o p q r s t u w x y z; do 
  for j in - _ a b c d e f g h i j k l m n o p q r s t u w x y z; do 
     name=_${i}${j}.service
     ./go-systemd ${name} &> /dev/null
     if [ $? -ne 0 ]; then
       echo "$name failed!"
       pkill dbus-daemon
       sleep 0.1
     fi
  done
done

results:

core-01 core # ./break.sh 
_aa.service failed!
_ab.service failed!
_ac.service failed!
_ad.service failed!
_ae.service failed!
_af.service failed!
_ba.service failed!
_bb.service failed!
_bc.service failed!
_bd.service failed!
_be.service failed!
_bf.service failed!
_ca.service failed!
_cb.service failed!
_cc.service failed!
_cd.service failed!
_ce.service failed!
_cf.service failed!
_da.service failed!
_db.service failed!
_dc.service failed!
_dd.service failed!
_de.service failed!
_df.service failed!
_ea.service failed!
_eb.service failed!
_ec.service failed!
_ed.service failed!
_ee.service failed!
_ef.service failed!
_fa.service failed!
_fb.service failed!
_fc.service failed!
_fd.service failed!
_fe.service failed!
_ff.service failed!
@jonboulle

This comment has been minimized.

Show comment
Hide comment
@marineam

This comment has been minimized.

Show comment
Hide comment
@marineam

marineam Jun 26, 2014

Contributor

WTF

Contributor

marineam commented Jun 26, 2014

WTF

@bcwaldon

This comment has been minimized.

Show comment
Hide comment
@jonboulle

This comment has been minimized.

Show comment
Hide comment
@jonboulle

jonboulle Jun 26, 2014

Contributor

Looks like it, those rules aren't sufficient. Still bizarre that dbus gets DOSed

Contributor

jonboulle commented Jun 26, 2014

Looks like it, those rules aren't sufficient. Still bizarre that dbus gets DOSed

@bcwaldon

This comment has been minimized.

Show comment
Hide comment
@bcwaldon

bcwaldon Jun 26, 2014

Contributor

Yeah, I remember this rabbit hole now. Sorry for not handling it fully in the first place.

On Jun 25, 2014, at 6:53 PM, Jonathan Boulle notifications@github.com wrote:

Looks like it, those rules aren't sufficient. Still bizarre that dbus gets DOSed


Reply to this email directly or view it on GitHub.

Contributor

bcwaldon commented Jun 26, 2014

Yeah, I remember this rabbit hole now. Sorry for not handling it fully in the first place.

On Jun 25, 2014, at 6:53 PM, Jonathan Boulle notifications@github.com wrote:

Looks like it, those rules aren't sufficient. Still bizarre that dbus gets DOSed


Reply to this email directly or view it on GitHub.

@jonboulle

This comment has been minimized.

Show comment
Hide comment
@jonboulle

jonboulle Jun 26, 2014

Contributor

#13

Contributor

jonboulle commented Jun 26, 2014

#13

@crawford

This comment has been minimized.

Show comment
Hide comment
@crawford

crawford Jun 26, 2014

Member

Doesn't this just need to escape the escape character?

path = strings.Replace(path, "_", "_5f", -1)
Member

crawford commented Jun 26, 2014

Doesn't this just need to escape the escape character?

path = strings.Replace(path, "_", "_5f", -1)
@jonboulle

This comment has been minimized.

Show comment
Hide comment
@jonboulle

jonboulle Jun 26, 2014

Contributor

That'll fix the immediate issue but it's probably better to escape everything that systemd does so we don't just end up here again

Contributor

jonboulle commented Jun 26, 2014

That'll fix the immediate issue but it's probably better to escape everything that systemd does so we don't just end up here again

@marineam

This comment has been minimized.

Show comment
Hide comment
@marineam

marineam Jun 26, 2014

Contributor

Yeah, we need to mimic systemctl exactly to avoid this sort of issue.

Contributor

marineam commented Jun 26, 2014

Yeah, we need to mimic systemctl exactly to avoid this sort of issue.

@jonboulle

This comment has been minimized.

Show comment
Hide comment
@jonboulle

jonboulle Jun 28, 2014

Contributor

ping

Contributor

jonboulle commented Jun 28, 2014

ping

@philips

This comment has been minimized.

Show comment
Hide comment
@philips

philips Jun 28, 2014

Member

lgtm, thank you!

Member

philips commented Jun 28, 2014

lgtm, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment