fix potential buffer overflow
be sure content sent to daemon is complete
Merge branch 'master' into for_bashu