Helper function get_label()

The helper function ssize_t get_label(char *dest, const char *src)
validates the given label and copies it to the dest buffer if
available.
(cherry picked from commit 09fdff9a456dec54a4c8548c9b9acbcbce48d59a)
Copy labels using get_label()

Copy and validate labels in a single transaction:

- No trust for having '\0' in the src buffer when copying
  labels.
- Improves performance by combining length calculation, validation
  and copying.
(cherry picked from commit 16f84d57e2766f1ccfd59ae77fad407b6cc5ff81)