parser: fix strncpy bug
authorXiubo Li <xiubli@redhat.com>
Thu, 15 Apr 2021 03:55:42 +0000 (11:55 +0800)
committerXiubo Li <xiubli@redhat.com>
Thu, 15 Apr 2021 05:24:10 +0000 (13:24 +0800)
Fixes: http://tracker.ceph.com/issues/24579
Signed-off-by: Yan, Zheng <zyan@redhat.com>
parser.c

index 8f3f08638f963576344ab85626c0bd511d51a322..06547817e6aae43435d8fef9f1d8a95a76a18058 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -203,7 +203,7 @@ static char *get_optstr(char *buf, char string[])
        len = strnlen(string, BUFSIZE);
        sprintf(search_str, "%s=%%%ds\\n", string, BUFSIZE - len-1);
        if (1 == sscanf(line, search_str, &temp)) {
-               len = strnlen(temp, 4096);
+               len = strnlen(temp, 4095) + 1;
                ret_buf = malloc(len);
                strncpy(ret_buf, temp, len);
                return ret_buf;