dhcpd is not escaping quotes (") in .leases
name: Bug report
about: dhcpd can't parse it's own .leases file when using events containing escaped " (")
Describe the bug
When a release and/or expire event is configured which contains an escaped quote (ie "this is a quote "." ) the event definition is also written to the leases file when applicable. The backslash used to escape the quote is not written.
When the daemon is restarted it can't parse the leases file and complains it is corrupt.
To Reproduce
- Run dhcpd containing the following config
on release {
set clip = binary-to-ascii(10, 8, ".", leased-address);
set clhw = binary-to-ascii(16, 8, ":", substring(hardware, 1, 6));
set cid = pick-first-value( concat( "\"", substring(option agent.circuit-id,2,256), "\""), "NO-CID");
set rid = pick-first-value( concat( "\"", substring(option agent.remote-id,2,256), "\""), "NO-RID");
log(info, concat( "RELEASE ", clip, " on ", clhw, " at ", cid, "/", rid));
}
- Wait for a client to obtain a lease and the .leases file to be updated.
- Observe that the leases file now contains
on release {
set clip =
binary-to-ascii (10, 8, ".", leased-address) ;
set clhw =
binary-to-ascii (16, 8, ":",
substring (hardware, 1, 6)) ;
set cid =
pick-first-value (concat (concat (""",
substring (option agent.circuit-id, 2,
256)), """), "NO-CID") ;
set rid =
pick-first-value (concat (concat (""",
substring (option agent.remote-id, 2,
256)), """), "NO-RID") ;
log (info,
concat (concat (concat (concat (concat (concat (concat ("RELEASE ", clip), " on "),
clhw), " at "), cid), "/"), rid));
}
- Restart dhpcd
- See errors about "comma expected" and "possibly corrupt lease file"
Expected behavior
Leases file should be written including the escaping backslash.
Environment:
-
ISC DHCP version: 4.4.2
-
OS: FreeBSD 12
-
Which features were compiled in
Describe the solution you'd like
I think the problem is in token_indent_data_string() in common/print.c. The purely ASCII path should insert a backslash where needed. It might be easier to just handle the string as binary, but that impacts human readability.