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

@ -114,7 +114,7 @@ parse_lcore_mask(struct ff_config *cfg, const char *coremask)
if ((1 << j) & val) {
proc_lcore[count] = idx;
if (cfg->dpdk.proc_id == count) {
zero_num = idx >> 2;
zero_num = idx >> 2;
shift = idx & 0x3;
memset(zero,'0',zero_num);
sprintf(buf, "%llx%s", (unsigned long long)1<<shift, zero);

View File

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