9pfs: proxy: assert if unmarshal fails
Replies from the virtfs proxy are made up of a fixed-size header (8 bytes) and a payload of variable size (maximum 64kb). When receiving a reply, the proxy backend first reads the whole header and then unmarshals it. If the header is okay, it then does the same operation with the payload. Since the proxy backend uses a pre-allocated buffer which has enough room for a header and the maximum payload size, marshalling should never fail with fixed size arguments. Any error here is likely to result from a more serious corruption in QEMU and we'd better dump core right away. This patch adds error checks where they are missing and converts the associated error paths into assertions. This should also address Coverity's complaints CID 1348519 and CID 1348520, about not always checking the return value of proxy_unmarshal(). Signed-off-by: Greg Kurz <groug@kaod.org> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
This commit is contained in:
parent
d5f2af7b95
commit
262169abe7
|
@ -165,7 +165,8 @@ static int v9fs_receive_response(V9fsProxy *proxy, int type,
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
reply->iov_len = PROXY_HDR_SZ;
|
reply->iov_len = PROXY_HDR_SZ;
|
||||||
proxy_unmarshal(reply, 0, "dd", &header.type, &header.size);
|
retval = proxy_unmarshal(reply, 0, "dd", &header.type, &header.size);
|
||||||
|
assert(retval == 4 * 2);
|
||||||
/*
|
/*
|
||||||
* if response size > PROXY_MAX_IO_SZ, read the response but ignore it and
|
* if response size > PROXY_MAX_IO_SZ, read the response but ignore it and
|
||||||
* return -ENOBUFS
|
* return -ENOBUFS
|
||||||
|
@ -194,9 +195,7 @@ static int v9fs_receive_response(V9fsProxy *proxy, int type,
|
||||||
if (header.type == T_ERROR) {
|
if (header.type == T_ERROR) {
|
||||||
int ret;
|
int ret;
|
||||||
ret = proxy_unmarshal(reply, PROXY_HDR_SZ, "d", status);
|
ret = proxy_unmarshal(reply, PROXY_HDR_SZ, "d", status);
|
||||||
if (ret < 0) {
|
assert(ret == 4);
|
||||||
*status = ret;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,6 +212,7 @@ static int v9fs_receive_response(V9fsProxy *proxy, int type,
|
||||||
&prstat.st_atim_sec, &prstat.st_atim_nsec,
|
&prstat.st_atim_sec, &prstat.st_atim_nsec,
|
||||||
&prstat.st_mtim_sec, &prstat.st_mtim_nsec,
|
&prstat.st_mtim_sec, &prstat.st_mtim_nsec,
|
||||||
&prstat.st_ctim_sec, &prstat.st_ctim_nsec);
|
&prstat.st_ctim_sec, &prstat.st_ctim_nsec);
|
||||||
|
assert(retval == 8 * 3 + 4 * 3 + 8 * 10);
|
||||||
prstat_to_stat(response, &prstat);
|
prstat_to_stat(response, &prstat);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -225,6 +225,7 @@ static int v9fs_receive_response(V9fsProxy *proxy, int type,
|
||||||
&prstfs.f_files, &prstfs.f_ffree,
|
&prstfs.f_files, &prstfs.f_ffree,
|
||||||
&prstfs.f_fsid[0], &prstfs.f_fsid[1],
|
&prstfs.f_fsid[0], &prstfs.f_fsid[1],
|
||||||
&prstfs.f_namelen, &prstfs.f_frsize);
|
&prstfs.f_namelen, &prstfs.f_frsize);
|
||||||
|
assert(retval == 8 * 11);
|
||||||
prstatfs_to_statfs(response, &prstfs);
|
prstatfs_to_statfs(response, &prstfs);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -246,7 +247,8 @@ static int v9fs_receive_response(V9fsProxy *proxy, int type,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case T_GETVERSION:
|
case T_GETVERSION:
|
||||||
proxy_unmarshal(reply, PROXY_HDR_SZ, "q", response);
|
retval = proxy_unmarshal(reply, PROXY_HDR_SZ, "q", response);
|
||||||
|
assert(retval == 8);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -274,18 +276,16 @@ static int v9fs_receive_status(V9fsProxy *proxy,
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
reply->iov_len = PROXY_HDR_SZ;
|
reply->iov_len = PROXY_HDR_SZ;
|
||||||
proxy_unmarshal(reply, 0, "dd", &header.type, &header.size);
|
retval = proxy_unmarshal(reply, 0, "dd", &header.type, &header.size);
|
||||||
if (header.size != sizeof(int)) {
|
assert(retval == 4 * 2);
|
||||||
*status = -ENOBUFS;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
retval = socket_read(proxy->sockfd,
|
retval = socket_read(proxy->sockfd,
|
||||||
reply->iov_base + PROXY_HDR_SZ, header.size);
|
reply->iov_base + PROXY_HDR_SZ, header.size);
|
||||||
if (retval < 0) {
|
if (retval < 0) {
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
reply->iov_len += header.size;
|
reply->iov_len += header.size;
|
||||||
proxy_unmarshal(reply, PROXY_HDR_SZ, "d", status);
|
retval = proxy_unmarshal(reply, PROXY_HDR_SZ, "d", status);
|
||||||
|
assert(retval == 4);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue