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>
Mon, 7 Mar 2016 21:30:48 +0000 (16:30 -0500)
commit4ba9f8051f7fc263cc5915fd6c2ac6d9195418b4
treec31fdfdaf55788d8a30cfd7711c8ed515affd905
parenta7927a04ac273abc6e15ffe31120f95d1f49b023
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