Fix crash of `netstat -n`, refer #438.

This commit is contained in:
fengbojiang(姜凤波) 2019-10-29 15:31:14 +08:00
parent a36df1e44e
commit 7abbdf7aa5
2 changed files with 14 additions and 15 deletions

View File

@ -35,8 +35,8 @@ sysctl(int *name, unsigned namelen, void *old,
size_t *oldlenp, const void *new, size_t newlen) size_t *oldlenp, const void *new, size_t newlen)
{ {
struct ff_msg *msg, *retmsg = NULL; struct ff_msg *msg, *retmsg = NULL;
char *extra_buf = NULL; char *extra_buf = NULL, *original_buf = NULL;
size_t total_len; size_t total_len, original_buf_len;
if (old != NULL && oldlenp == NULL) { if (old != NULL && oldlenp == NULL) {
errno = EINVAL; errno = EINVAL;
@ -62,6 +62,8 @@ sysctl(int *name, unsigned namelen, void *old,
ff_ipc_msg_free(msg); ff_ipc_msg_free(msg);
return -1; return -1;
} }
original_buf = msg->buf_addr;
original_buf_len = msg->buf_len;
msg->buf_addr = extra_buf; msg->buf_addr = extra_buf;
msg->buf_len = total_len; msg->buf_len = total_len;
} }
@ -106,11 +108,7 @@ sysctl(int *name, unsigned namelen, void *old,
int ret = ff_ipc_send(msg); int ret = ff_ipc_send(msg);
if (ret < 0) { if (ret < 0) {
errno = EPIPE; errno = EPIPE;
ff_ipc_msg_free(msg); goto error;
if (extra_buf) {
rte_free(extra_buf);
}
return -1;
} }
do { do {
@ -120,11 +118,7 @@ sysctl(int *name, unsigned namelen, void *old,
ret = ff_ipc_recv(&retmsg, msg->msg_type); ret = ff_ipc_recv(&retmsg, msg->msg_type);
if (ret < 0) { if (ret < 0) {
errno = EPIPE; errno = EPIPE;
ff_ipc_msg_free(msg); goto error;
if (extra_buf) {
rte_free(extra_buf);
}
return -1;
} }
} while (msg != retmsg); } while (msg != retmsg);
@ -142,6 +136,11 @@ sysctl(int *name, unsigned namelen, void *old,
errno = retmsg->result; errno = retmsg->result;
} }
error:
if (original_buf) {
msg->buf_addr = original_buf;
msg->buf_len = original_buf_len;
}
ff_ipc_msg_free(msg); ff_ipc_msg_free(msg);
if (extra_buf) { if (extra_buf) {
rte_free(extra_buf); rte_free(extra_buf);