sunrpc/cache: fix off-by-one in qword_get()
authorStefan Hajnoczi <stefanha@redhat.com>
Thu, 18 Feb 2016 18:55:54 +0000 (18:55 +0000)
committerSasha Levin <sasha.levin@oracle.com>
Tue, 8 Mar 2016 06:14:06 +0000 (01:14 -0500)
commit7459f09bc5bd0f9beb22aa7643e2d5476431164e
treedd03ad00cef15bdf2e7a3802f265456c44384868
parentae5a9780d7bee99a2968abd95ec910f31a1e82bf
sunrpc/cache: fix off-by-one in qword_get()

[ Upstream commit b7052cd7bcf3c1478796e93e3dff2b44c9e82943 ]

The qword_get() function NUL-terminates its output buffer.  If the input
string is in hex format \xXXXX... and the same length as the output
buffer, there is an off-by-one:

  int qword_get(char **bpp, char *dest, int bufsize)
  {
      ...
      while (len < bufsize) {
          ...
          *dest++ = (h << 4) | l;
          len++;
      }
      ...
      *dest = '\0';
      return len;
  }

This patch ensures the NUL terminator doesn't fall outside the output
buffer.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Cc: stable@vger.kernel.org
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
net/sunrpc/cache.c