project
stringclasses
633 values
commit_id
stringlengths
7
81
target
int64
0
1
func
stringlengths
5
484k
cwe
stringclasses
131 values
big_vul_idx
float64
0
189k
idx
int64
0
522k
hash
stringlengths
34
39
size
float64
1
24k
message
stringlengths
0
11.5k
dataset
stringclasses
1 value
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static int ssl_password_cb(char *buf, int size, int flags, void *userdata) { char *pass = ssl_parameters.keyfile_password; if (size < strlen(pass) + 1) { return (0); } strcpy(buf, pass); return (strlen(pass)); }
CWE-119
1,996
12,405
92840310276165795868811741970900392477
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
uint64_t *stat_add_counter(StatNodeRef parent, const char *name, int visible) { StatNodeRef ref = stat_add_node(parent, name, visible); SpiceStatNode *node; if (ref == INVALID_STAT_REF) { return NULL; } node = &reds->stat->nodes[ref]; node->flags |= SPICE_STAT_NODE_FLAG_VALUE; return &node->value; }
CWE-119
1,997
12,406
134538988624076853435429440670279934796
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
StatNodeRef stat_add_node(StatNodeRef parent, const char *name, int visible) { StatNodeRef ref; SpiceStatNode *node; spice_assert(name && strlen(name) > 0); if (strlen(name) >= sizeof(node->name)) { return INVALID_STAT_REF; } pthread_mutex_lock(&reds->stat_lock); ref = (parent == INVALID_STAT_REF ? reds->stat->root_index : reds->stat->nodes[parent].first_child_index); while (ref != INVALID_STAT_REF) { node = &reds->stat->nodes[ref]; if (strcmp(name, node->name)) { ref = node->next_sibling_index; } else { pthread_mutex_unlock(&reds->stat_lock); return ref; } } if (reds->stat->num_of_nodes >= REDS_MAX_STAT_NODES || reds->stat == NULL) { pthread_mutex_unlock(&reds->stat_lock); return INVALID_STAT_REF; } reds->stat->generation++; reds->stat->num_of_nodes++; for (ref = 0; ref <= REDS_MAX_STAT_NODES; ref++) { node = &reds->stat->nodes[ref]; if (!(node->flags & SPICE_STAT_NODE_FLAG_ENABLED)) { break; } } spice_assert(!(node->flags & SPICE_STAT_NODE_FLAG_ENABLED)); node->value = 0; node->flags = SPICE_STAT_NODE_FLAG_ENABLED | (visible ? SPICE_STAT_NODE_FLAG_VISIBLE : 0); g_strlcpy(node->name, name, sizeof(node->name)); insert_stat_node(parent, ref); pthread_mutex_unlock(&reds->stat_lock); return ref; }
CWE-119
1,998
12,407
85022882264857108555938144188327492366
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void stat_remove(SpiceStatNode *node) { pthread_mutex_lock(&reds->stat_lock); node->flags &= ~SPICE_STAT_NODE_FLAG_ENABLED; reds->stat->generation++; reds->stat->num_of_nodes--; pthread_mutex_unlock(&reds->stat_lock); }
CWE-119
1,999
12,408
339867217351725156458088541637072026683
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
void stat_remove_counter(uint64_t *counter) { stat_remove((SpiceStatNode *)(counter - offsetof(SpiceStatNode, value))); }
CWE-119
2,000
12,409
30262875840956933709331269539334435473
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
void stat_remove_node(StatNodeRef ref) { stat_remove(&reds->stat->nodes[ref]); }
CWE-119
2,001
12,410
261157780722794458047712474146896982456
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static ssize_t stream_read_cb(RedsStream *s, void *buf, size_t size) { return read(s->socket, buf, size); }
CWE-119
2,002
12,411
246249156466847760741049894658452534307
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static ssize_t stream_ssl_write_cb(RedsStream *s, const void *buf, size_t size) { int return_code; SPICE_GNUC_UNUSED int ssl_error; return_code = SSL_write(s->ssl, buf, size); if (return_code < 0) { ssl_error = SSL_get_error(s->ssl, return_code); } return return_code; }
CWE-119
2,004
12,412
202640255323305355908102810362931161699
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static ssize_t stream_write_cb(RedsStream *s, const void *buf, size_t size) { return write(s->socket, buf, size); }
CWE-119
2,005
12,413
119060635093383872899642822908795306943
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static ssize_t stream_writev_cb(RedsStream *s, const struct iovec *iov, int iovcnt) { ssize_t ret = 0; do { int tosend; ssize_t n, expected = 0; int i; #ifdef IOV_MAX tosend = MIN(iovcnt, IOV_MAX); #else tosend = iovcnt; #endif for (i = 0; i < tosend; i++) { expected += iov[i].iov_len; } n = writev(s->socket, iov, tosend); if (n <= expected) { if (n > 0) ret += n; return ret == 0 ? n : ret; } ret += n; iov += tosend; iovcnt -= tosend; } while(iovcnt > 0); return ret; }
CWE-119
2,006
12,414
218923867132840411978914275543106985838
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static int sync_write(RedsStream *stream, const void *in_buf, size_t n) { const uint8_t *buf = (uint8_t *)in_buf; while (n) { int now = reds_stream_write(stream, buf, n); if (now <= 0) { if (now == -1 && (errno == EINTR || errno == EAGAIN)) { continue; } return FALSE; } n -= now; buf += now; } return TRUE; }
CWE-119
2,007
12,415
268217355482582757669120032374761979212
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void vdi_port_on_free_self_token(void *opaque) { if (inputs_inited() && reds->pending_mouse_event) { spice_debug("pending mouse event"); reds_handle_agent_mouse_event(inputs_get_mouse_state()); } }
CWE-119
2,008
12,416
264524266415630177698894183642583598962
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static VDIReadBuf *vdi_port_read_buf_get(void) { VDIPortState *state = &reds->agent_state; RingItem *item; VDIReadBuf *buf; if (!(item = ring_get_head(&state->read_bufs))) { return NULL; } ring_remove(item); buf = SPICE_CONTAINEROF(item, VDIReadBuf, link); buf->refs = 1; return buf; }
CWE-119
2,009
12,417
264460280148292198495169884089720161741
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static int vdi_port_read_buf_process(int port, VDIReadBuf *buf) { VDIPortState *state = &reds->agent_state; int res; switch (port) { case VDP_CLIENT_PORT: { res = agent_msg_filter_process_data(&state->read_filter, buf->data, buf->len); switch (res) { case AGENT_MSG_FILTER_OK: return TRUE; case AGENT_MSG_FILTER_DISCARD: return FALSE; case AGENT_MSG_FILTER_PROTO_ERROR: reds_agent_remove(); return FALSE; } } case VDP_SERVER_PORT: return FALSE; default: spice_warning("invalid port"); reds_agent_remove(); return FALSE; } }
CWE-119
2,010
12,418
42867169587943981431818551612402832644
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static VDIReadBuf* vdi_port_read_buf_ref(VDIReadBuf *buf) { buf->refs++; return buf; }
CWE-119
2,011
12,419
121925892393105141293862912695071576392
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void vdi_port_read_buf_release(uint8_t *data, void *opaque) { VDIReadBuf *buf = (VDIReadBuf *)opaque; vdi_port_read_buf_unref(buf); }
CWE-119
2,012
12,420
335000902358556184280792389564894045368
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void vdi_port_read_buf_unref(VDIReadBuf *buf) { if (!--buf->refs) { ring_add(&reds->agent_state.read_bufs, &buf->link); /* read_one_msg_from_vdi_port may have never completed because the read_bufs ring was empty. So we call it again so it can complete its work if necessary. Note that since we can be called from spice_char_device_wakeup this can cause recursion, but we have protection for that */ if (reds->agent_state.base) { spice_char_device_wakeup(reds->agent_state.base); } } }
CWE-119
2,013
12,421
293181148917323679762239796308548915869
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static SpiceCharDeviceMsgToClient *vdi_port_read_one_msg_from_device(SpiceCharDeviceInstance *sin, void *opaque) { VDIPortState *state = &reds->agent_state; SpiceCharDeviceInterface *sif; VDIReadBuf *dispatch_buf; int n; if (!vdagent) { return NULL; } spice_assert(vdagent == sin); sif = SPICE_CONTAINEROF(vdagent->base.sif, SpiceCharDeviceInterface, base); while (vdagent) { switch (state->read_state) { case VDI_PORT_READ_STATE_READ_HEADER: n = sif->read(vdagent, state->receive_pos, state->receive_len); if (!n) { return NULL; } if ((state->receive_len -= n)) { state->receive_pos += n; return NULL; } state->message_receive_len = state->vdi_chunk_header.size; state->read_state = VDI_PORT_READ_STATE_GET_BUFF; case VDI_PORT_READ_STATE_GET_BUFF: { if (!(state->current_read_buf = vdi_port_read_buf_get())) { return NULL; } state->receive_pos = state->current_read_buf->data; state->receive_len = MIN(state->message_receive_len, sizeof(state->current_read_buf->data)); state->current_read_buf->len = state->receive_len; state->message_receive_len -= state->receive_len; state->read_state = VDI_PORT_READ_STATE_READ_DATA; } case VDI_PORT_READ_STATE_READ_DATA: n = sif->read(vdagent, state->receive_pos, state->receive_len); if (!n) { return NULL; } if ((state->receive_len -= n)) { state->receive_pos += n; break; } dispatch_buf = state->current_read_buf; state->current_read_buf = NULL; state->receive_pos = NULL; if (state->message_receive_len == 0) { state->read_state = VDI_PORT_READ_STATE_READ_HEADER; state->receive_pos = (uint8_t *)&state->vdi_chunk_header; state->receive_len = sizeof(state->vdi_chunk_header); } else { state->read_state = VDI_PORT_READ_STATE_GET_BUFF; } if (vdi_port_read_buf_process(state->vdi_chunk_header.port, dispatch_buf)) { return dispatch_buf; } else { vdi_port_read_buf_unref(dispatch_buf); } } /* END switch */ } /* END while */ return NULL; }
CWE-119
2,014
12,422
187912399007493034463436990646914996621
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void vdi_port_send_msg_to_client(SpiceCharDeviceMsgToClient *msg, RedClient *client, void *opaque) { VDIReadBuf *agent_data_buf = msg; main_channel_client_push_agent_data(red_client_get_main(client), agent_data_buf->data, agent_data_buf->len, vdi_port_read_buf_release, vdi_port_read_buf_ref(agent_data_buf)); }
CWE-119
2,016
12,423
335575536623258601445550618244165868493
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void vdi_port_send_tokens_to_client(RedClient *client, uint32_t tokens, void *opaque) { main_channel_client_push_agent_tokens(red_client_get_main(client), tokens); }
CWE-119
2,017
12,424
129235570760915536956512642173259704226
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void vdi_port_unref_msg_to_client(SpiceCharDeviceMsgToClient *msg, void *opaque) { vdi_port_read_buf_unref(msg); }
CWE-119
2,018
12,425
336825986774491819414564973967569902635
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void add_capability(uint32_t **caps, int *num_caps, uint32_t cap) { int nbefore, n; nbefore = *num_caps; n = cap / 32; *num_caps = MAX(*num_caps, n + 1); *caps = spice_renew(uint32_t, *caps, *num_caps); memset(*caps + nbefore, 0, (*num_caps - nbefore) * sizeof(uint32_t)); (*caps)[n] |= (1 << (cap % 32)); }
CWE-399
2,056
12,448
188450141247495526117992335328701556218
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static int do_nothing_handle_message(RedChannelClient *rcc, uint16_t type, uint32_t size, uint8_t *msg) { return TRUE; }
CWE-399
2,057
12,449
272126603578031783050675408680454583304
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void dummy_watch_remove(SpiceWatch *watch) { }
CWE-399
2,059
12,450
109796567907449105029906963978480529261
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void dummy_watch_update_mask(SpiceWatch *watch, int event_mask) { }
CWE-399
2,060
12,451
83255161336949150368694610809556419614
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static uint32_t full_header_get_msg_size(SpiceDataHeaderOpaque *header) { return ((SpiceDataHeader *)header->data)->size; }
CWE-399
2,061
12,452
10883435013701069390865353299125014962
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static uint16_t full_header_get_msg_type(SpiceDataHeaderOpaque *header) { return ((SpiceDataHeader *)header->data)->type; }
CWE-399
2,062
12,453
181645502115536351135421030124008097456
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void full_header_set_msg_serial(SpiceDataHeaderOpaque *header, uint64_t serial) { ((SpiceDataHeader *)header->data)->serial = serial; }
CWE-399
2,063
12,454
1460836590764322587037511794242326774
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void full_header_set_msg_size(SpiceDataHeaderOpaque *header, uint32_t size) { ((SpiceDataHeader *)header->data)->size = size; }
CWE-399
2,064
12,455
321349219133263370727574349174100984402
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void full_header_set_msg_sub_list(SpiceDataHeaderOpaque *header, uint32_t sub_list) { ((SpiceDataHeader *)header->data)->sub_list = sub_list; }
CWE-399
2,065
12,456
46972540008577516237037491422816523285
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void full_header_set_msg_type(SpiceDataHeaderOpaque *header, uint16_t type) { ((SpiceDataHeader *)header->data)->type = type; }
CWE-399
2,066
12,457
289764831795732387192854936416402172856
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static uint32_t mini_header_get_msg_size(SpiceDataHeaderOpaque *header) { return ((SpiceMiniDataHeader *)header->data)->size; }
CWE-399
2,067
12,458
3426597417843624374300718298808840376
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static uint16_t mini_header_get_msg_type(SpiceDataHeaderOpaque *header) { return ((SpiceMiniDataHeader *)header->data)->type; }
CWE-399
2,068
12,459
121203179760172945879874671873086410700
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void mini_header_set_msg_serial(SpiceDataHeaderOpaque *header, uint64_t serial) { spice_error("attempt to set header serial on mini header"); }
CWE-399
2,069
12,460
178402698122359025598012383750769762976
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void mini_header_set_msg_size(SpiceDataHeaderOpaque *header, uint32_t size) { ((SpiceMiniDataHeader *)header->data)->size = size; }
CWE-399
2,070
12,461
160202804003749033796915235738392918571
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void mini_header_set_msg_sub_list(SpiceDataHeaderOpaque *header, uint32_t sub_list) { spice_error("attempt to set header sub list on mini header"); }
CWE-399
2,071
12,462
70137446854928260391351777366785910089
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void mini_header_set_msg_type(SpiceDataHeaderOpaque *header, uint16_t type) { ((SpiceMiniDataHeader *)header->data)->type = type; }
CWE-399
2,072
12,463
116647429650721002766471707421060289311
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void red_channel_add_client(RedChannel *channel, RedChannelClient *rcc) { spice_assert(rcc); ring_add(&channel->clients, &rcc->channel_link); channel->clients_num++; }
CWE-399
2,073
12,464
131179978566830898351263352343294718096
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
int red_channel_all_blocked(RedChannel *channel) { RingItem *link; RedChannelClient *rcc; if (!channel || channel->clients_num == 0) { return FALSE; } RING_FOREACH(link, &channel->clients) { rcc = SPICE_CONTAINEROF(link, RedChannelClient, channel_link); if (!rcc->send_data.blocked) { return FALSE; } } return TRUE; }
CWE-399
2,074
12,465
66987801933018767894015096545770377374
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
int red_channel_any_blocked(RedChannel *channel) { RingItem *link; RedChannelClient *rcc; RING_FOREACH(link, &channel->clients) { rcc = SPICE_CONTAINEROF(link, RedChannelClient, channel_link); if (rcc->send_data.blocked) { return TRUE; } } return FALSE; }
CWE-399
2,075
12,466
257058743439637625309339092513014528445
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
void red_channel_apply_clients(RedChannel *channel, channel_client_callback cb) { RingItem *link; RingItem *next; RedChannelClient *rcc; RING_FOREACH_SAFE(link, next, &channel->clients) { rcc = SPICE_CONTAINEROF(link, RedChannelClient, channel_link); cb(rcc); } }
CWE-399
2,076
12,467
203732446881483585974282148252419058459
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
void red_channel_apply_clients_data(RedChannel *channel, channel_client_callback_data cb, void *data) { RingItem *link; RingItem *next; RedChannelClient *rcc; RING_FOREACH_SAFE(link, next, &channel->clients) { rcc = SPICE_CONTAINEROF(link, RedChannelClient, channel_link); cb(rcc, data); } }
CWE-399
2,077
12,468
316377279344791791350158499744546022359
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
void red_channel_client_ack_set_client_window(RedChannelClient *rcc, int client_window) { rcc->ack_data.client_window = client_window; }
CWE-399
2,078
12,469
339714342989070143527789728280513770572
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
void red_channel_client_ack_zero_messages_window(RedChannelClient *rcc) { rcc->ack_data.messages_window = 0; }
CWE-399
2,079
12,470
316207662613070553406316332687101977207
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
int red_channel_client_blocked(RedChannelClient *rcc) { return rcc && rcc->send_data.blocked; }
CWE-399
2,081
12,471
43034628098284319259771737674075770320
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void red_channel_client_cancel_ping_timer(RedChannelClient *rcc) { if (!rcc->latency_monitor.timer) { return; } if (rcc->latency_monitor.state != PING_STATE_TIMER) { return; } rcc->channel->core->timer_cancel(rcc->latency_monitor.timer); rcc->latency_monitor.state = PING_STATE_NONE; }
CWE-399
2,082
12,472
133211873505958748640922855741285590220
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
void red_channel_client_clear_sent_item(RedChannelClient *rcc) { if (rcc->send_data.item) { red_channel_client_release_item(rcc, rcc->send_data.item, TRUE); rcc->send_data.item = NULL; } rcc->send_data.blocked = FALSE; rcc->send_data.size = 0; }
CWE-399
2,083
12,473
250256684305394395000307409798384919954
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
RedChannelClient *red_channel_client_create(int size, RedChannel *channel, RedClient *client, RedsStream *stream, int monitor_latency, int num_common_caps, uint32_t *common_caps, int num_caps, uint32_t *caps) { RedChannelClient *rcc = NULL; pthread_mutex_lock(&client->lock); if (!red_channel_client_pre_create_validate(channel, client)) { goto error; } spice_assert(stream && channel && size >= sizeof(RedChannelClient)); rcc = spice_malloc0(size); rcc->stream = stream; rcc->channel = channel; rcc->client = client; rcc->refs = 1; rcc->ack_data.messages_window = ~0; // blocks send message (maybe use send_data.blocked + rcc->ack_data.client_generation = ~0; rcc->ack_data.client_window = CLIENT_ACK_WINDOW; rcc->send_data.main.marshaller = spice_marshaller_new(); rcc->send_data.urgent.marshaller = spice_marshaller_new(); rcc->send_data.marshaller = rcc->send_data.main.marshaller; rcc->incoming.opaque = rcc; rcc->incoming.cb = &channel->incoming_cb; rcc->outgoing.opaque = rcc; rcc->outgoing.cb = &channel->outgoing_cb; rcc->outgoing.pos = 0; rcc->outgoing.size = 0; red_channel_client_set_remote_caps(rcc, num_common_caps, common_caps, num_caps, caps); if (red_channel_client_test_remote_common_cap(rcc, SPICE_COMMON_CAP_MINI_HEADER)) { rcc->incoming.header = mini_header_wrapper; rcc->send_data.header = mini_header_wrapper; rcc->is_mini_header = TRUE; } else { rcc->incoming.header = full_header_wrapper; rcc->send_data.header = full_header_wrapper; rcc->is_mini_header = FALSE; } rcc->incoming.header.data = rcc->incoming.header_buf; rcc->incoming.serial = 1; if (!channel->channel_cbs.config_socket(rcc)) { goto error; } ring_init(&rcc->pipe); rcc->pipe_size = 0; stream->watch = channel->core->watch_add(stream->socket, SPICE_WATCH_EVENT_READ, red_channel_client_event, rcc); rcc->id = channel->clients_num; red_channel_add_client(channel, rcc); red_client_add_channel(client, rcc); red_channel_ref(channel); pthread_mutex_unlock(&client->lock); if (monitor_latency) { rcc->latency_monitor.timer = channel->core->timer_add( red_channel_client_ping_timer, rcc); if (!client->during_target_migrate) { red_channel_client_start_ping_timer(rcc, PING_TEST_IDLE_NET_TIMEOUT_MS); } rcc->latency_monitor.roundtrip = -1; } return rcc; error: free(rcc); reds_stream_free(stream); pthread_mutex_unlock(&client->lock); return NULL; }
CWE-399
2,084
12,474
39047634947405305547234459322588405287
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
RedChannelClient *red_channel_client_create_dummy(int size, RedChannel *channel, RedClient *client, int num_common_caps, uint32_t *common_caps, int num_caps, uint32_t *caps) { RedChannelClient *rcc = NULL; spice_assert(size >= sizeof(RedChannelClient)); pthread_mutex_lock(&client->lock); if (!red_channel_client_pre_create_validate(channel, client)) { goto error; } rcc = spice_malloc0(size); rcc->refs = 1; rcc->client = client; rcc->channel = channel; red_channel_ref(channel); red_channel_client_set_remote_caps(rcc, num_common_caps, common_caps, num_caps, caps); if (red_channel_client_test_remote_common_cap(rcc, SPICE_COMMON_CAP_MINI_HEADER)) { rcc->incoming.header = mini_header_wrapper; rcc->send_data.header = mini_header_wrapper; rcc->is_mini_header = TRUE; } else { rcc->incoming.header = full_header_wrapper; rcc->send_data.header = full_header_wrapper; rcc->is_mini_header = FALSE; } rcc->incoming.header.data = rcc->incoming.header_buf; rcc->incoming.serial = 1; ring_init(&rcc->pipe); rcc->dummy = TRUE; rcc->dummy_connected = TRUE; red_channel_add_client(channel, rcc); red_client_add_channel(client, rcc); pthread_mutex_unlock(&client->lock); return rcc; error: pthread_mutex_unlock(&client->lock); return NULL; }
CWE-399
2,085
12,475
181971299844687575251950208390907630469
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void red_channel_client_default_connect(RedChannel *channel, RedClient *client, RedsStream *stream, int migration, int num_common_caps, uint32_t *common_caps, int num_caps, uint32_t *caps) { spice_error("not implemented"); }
CWE-399
2,086
12,476
293505153964649450640986666016324501483
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void red_channel_client_default_disconnect(RedChannelClient *base) { red_channel_client_disconnect(base); }
CWE-399
2,087
12,477
240444655632595504106164058801777667008
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
void red_channel_client_default_migrate(RedChannelClient *rcc) { if (rcc->latency_monitor.timer) { red_channel_client_cancel_ping_timer(rcc); rcc->channel->core->timer_remove(rcc->latency_monitor.timer); rcc->latency_monitor.timer = NULL; } red_channel_client_pipe_add_type(rcc, PIPE_ITEM_TYPE_MIGRATE); }
CWE-399
2,088
12,478
212447954332594959195600228963088511478
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void red_channel_client_default_peer_on_error(RedChannelClient *rcc) { red_channel_client_disconnect(rcc); }
CWE-399
2,089
12,479
308422912931546857109306741960673690647
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
void red_channel_client_destroy(RedChannelClient *rcc) { rcc->destroying = 1; red_channel_client_disconnect(rcc); red_client_remove_channel(rcc); red_channel_client_unref(rcc); }
CWE-399
2,090
12,480
310195645556634309428181583802655106135
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void red_channel_client_destroy_remote_caps(RedChannelClient* rcc) { rcc->remote_caps.num_common_caps = 0; free(rcc->remote_caps.common_caps); rcc->remote_caps.num_caps = 0; free(rcc->remote_caps.caps); }
CWE-399
2,091
12,481
118182134192609879738720113928135985792
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
void red_channel_client_disconnect(RedChannelClient *rcc) { spice_printerr("%p (channel %p type %d id %d)", rcc, rcc->channel, rcc->channel->type, rcc->channel->id); if (rcc->dummy) { red_channel_client_disconnect_dummy(rcc); return; } if (!red_channel_client_is_connected(rcc)) { return; } red_channel_client_pipe_clear(rcc); if (rcc->stream->watch) { rcc->channel->core->watch_remove(rcc->stream->watch); rcc->stream->watch = NULL; } reds_stream_free(rcc->stream); rcc->stream = NULL; if (rcc->latency_monitor.timer) { rcc->channel->core->timer_remove(rcc->latency_monitor.timer); rcc->latency_monitor.timer = NULL; } red_channel_remove_client(rcc); rcc->channel->channel_cbs.on_disconnect(rcc); }
CWE-399
2,092
12,482
167241092735823103973477106684094086743
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void red_channel_client_disconnect_dummy(RedChannelClient *rcc) { spice_assert(rcc->dummy); if (ring_item_is_linked(&rcc->channel_link)) { red_channel_remove_client(rcc); } rcc->dummy_connected = FALSE; }
CWE-399
2,093
12,483
29098143870400201391326811517874711020
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void red_channel_client_event(int fd, int event, void *data) { RedChannelClient *rcc = (RedChannelClient *)data; red_channel_client_ref(rcc); if (event & SPICE_WATCH_EVENT_READ) { red_channel_client_receive(rcc); } if (event & SPICE_WATCH_EVENT_WRITE) { red_channel_client_push(rcc); } red_channel_client_unref(rcc); }
CWE-399
2,094
12,484
250787660995906984782749243495505299396
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
SpiceMarshaller *red_channel_client_get_marshaller(RedChannelClient *rcc) { return rcc->send_data.marshaller; }
CWE-399
2,095
12,485
41532832280989111452989282377870432350
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
uint64_t red_channel_client_get_message_serial(RedChannelClient *rcc) { return rcc->send_data.serial; }
CWE-399
2,096
12,486
188359580687565606110336720515359684907
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
int red_channel_client_get_roundtrip_ms(RedChannelClient *rcc) { if (rcc->latency_monitor.roundtrip < 0) { return rcc->latency_monitor.roundtrip; } return rcc->latency_monitor.roundtrip / 1000 / 1000; }
CWE-399
2,097
12,487
206634879446086280749704470827932198326
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
RedsStream *red_channel_client_get_stream(RedChannelClient *rcc) { return rcc->stream; }
CWE-399
2,098
12,488
283985334689275047101334720544133451832
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
int red_channel_client_handle_message(RedChannelClient *rcc, uint32_t size, uint16_t type, void *message) { switch (type) { case SPICE_MSGC_ACK_SYNC: if (size != sizeof(uint32_t)) { spice_printerr("bad message size"); return FALSE; } rcc->ack_data.client_generation = *(uint32_t *)(message); break; case SPICE_MSGC_ACK: if (rcc->ack_data.client_generation == rcc->ack_data.generation) { rcc->ack_data.messages_window -= rcc->ack_data.client_window; red_channel_client_push(rcc); } break; case SPICE_MSGC_DISCONNECTING: break; case SPICE_MSGC_MIGRATE_FLUSH_MARK: if (!rcc->wait_migrate_flush_mark) { spice_error("unexpected flush mark"); return FALSE; } red_channel_handle_migrate_flush_mark(rcc); rcc->wait_migrate_flush_mark = FALSE; break; case SPICE_MSGC_MIGRATE_DATA: red_channel_handle_migrate_data(rcc, size, message); break; case SPICE_MSGC_PONG: red_channel_client_handle_pong(rcc, message); break; default: spice_printerr("invalid message type %u", type); return FALSE; } return TRUE; }
CWE-399
2,099
12,489
174899731145326658637893792016106606672
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void red_channel_client_handle_pong(RedChannelClient *rcc, SpiceMsgPing *ping) { uint64_t now; struct timespec ts; /* ignoring unexpected pongs, or post-migration pongs for pings that * started just before migration */ if (ping->id != rcc->latency_monitor.id) { spice_warning("ping-id (%u)!= pong-id %u", rcc->latency_monitor.id, ping->id); return; } clock_gettime(CLOCK_MONOTONIC, &ts); now = ts.tv_sec * 1000000000LL + ts.tv_nsec; if (rcc->latency_monitor.state == PING_STATE_WARMUP) { rcc->latency_monitor.state = PING_STATE_LATENCY; return; } else if (rcc->latency_monitor.state != PING_STATE_LATENCY) { spice_warning("unexpected"); return; } /* set TCO_NODELAY=0, in case we reverted it for the test*/ if (!rcc->latency_monitor.tcp_nodelay) { int delay_val = 0; if (setsockopt(rcc->stream->socket, IPPROTO_TCP, TCP_NODELAY, &delay_val, sizeof(delay_val)) == -1) { if (errno != ENOTSUP) { spice_warning("setsockopt failed, %s", strerror(errno)); } } } /* * The real network latency shouldn't change during the connection. However, * the measurements can be bigger than the real roundtrip due to other * threads or processes that are utilizing the network. We update the roundtrip * measurement with the minimal value we encountered till now. */ if (rcc->latency_monitor.roundtrip < 0 || now - ping->timestamp < rcc->latency_monitor.roundtrip) { rcc->latency_monitor.roundtrip = now - ping->timestamp; spice_debug("update roundtrip %.2f(ms)", rcc->latency_monitor.roundtrip/1000.0/1000.0); } rcc->latency_monitor.last_pong_time = now; rcc->latency_monitor.state = PING_STATE_NONE; red_channel_client_start_ping_timer(rcc, PING_TEST_TIMEOUT_MS); }
CWE-399
2,100
12,490
106405339623301499212516193270674662396
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void red_channel_client_init_outgoing_messages_window(RedChannelClient *rcc) { rcc->ack_data.messages_window = 0; red_channel_client_push(rcc); }
CWE-399
2,101
12,491
141849208860382595568762575322369971224
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
void red_channel_client_init_send_data(RedChannelClient *rcc, uint16_t msg_type, PipeItem *item) { spice_assert(red_channel_client_no_item_being_sent(rcc)); spice_assert(msg_type != 0); rcc->send_data.header.set_msg_type(&rcc->send_data.header, msg_type); rcc->send_data.item = item; if (item) { rcc->channel->channel_cbs.hold_item(rcc, item); } }
CWE-399
2,102
12,492
176356560730542475370157326759744558759
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
int red_channel_client_is_connected(RedChannelClient *rcc) { if (!rcc->dummy) { return rcc->stream != NULL; } else { return rcc->dummy_connected; } }
CWE-399
2,103
12,493
151123396248137330602672171066092836106
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
int red_channel_client_no_item_being_sent(RedChannelClient *rcc) { return !rcc || (rcc->send_data.size == 0); }
CWE-399
2,104
12,494
306036121509525028340479424994434395780
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void red_channel_client_on_output(void *opaque, int n) { RedChannelClient *rcc = opaque; stat_inc_counter(rcc->channel->out_bytes_counter, n); }
CWE-399
2,105
12,495
308689499149610052874276722827974416502
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static int red_channel_client_peer_get_out_msg_size(void *opaque) { RedChannelClient *rcc = (RedChannelClient *)opaque; return rcc->send_data.size; }
CWE-399
2,106
12,496
39724929485629619000910206551051079810
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void red_channel_client_peer_on_out_block(void *opaque) { RedChannelClient *rcc = (RedChannelClient *)opaque; rcc->send_data.blocked = TRUE; rcc->channel->core->watch_update_mask(rcc->stream->watch, SPICE_WATCH_EVENT_READ | SPICE_WATCH_EVENT_WRITE); }
CWE-399
2,107
12,497
117023710693509214212551465317061592446
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void red_channel_client_peer_prepare_out_msg( void *opaque, struct iovec *vec, int *vec_size, int pos) { RedChannelClient *rcc = (RedChannelClient *)opaque; *vec_size = spice_marshaller_fill_iovec(rcc->send_data.marshaller, vec, IOV_MAX, pos); }
CWE-399
2,108
12,498
205411247670967195154133644757375565
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void red_channel_client_ping_timer(void *opaque) { int so_unsent_size = 0; RedChannelClient *rcc = opaque; spice_assert(rcc->latency_monitor.state == PING_STATE_TIMER); red_channel_client_cancel_ping_timer(rcc); /* retrieving the occupied size of the socket's tcp snd buffer (unacked + unsent) */ if (ioctl(rcc->stream->socket, TIOCOUTQ, &so_unsent_size) == -1) { spice_printerr("ioctl(TIOCOUTQ) failed, %s", strerror(errno)); } if (so_unsent_size > 0) { /* tcp snd buffer is still occupied. rescheduling ping */ red_channel_client_start_ping_timer(rcc, PING_TEST_IDLE_NET_TIMEOUT_MS); } else { red_channel_client_push_ping(rcc); } }
CWE-399
2,109
12,499
207642064251902423522840961167480771532
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
void red_channel_client_pipe_add(RedChannelClient *rcc, PipeItem *item) { spice_assert(rcc && item); rcc->pipe_size++; ring_add(&rcc->pipe, &item->link); }
CWE-399
2,110
12,500
48026597918808002286647039320513901568
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
void red_channel_client_pipe_add_after(RedChannelClient *rcc, PipeItem *item, PipeItem *pos) { spice_assert(rcc); spice_assert(pos); spice_assert(item); rcc->pipe_size++; ring_add_after(&item->link, &pos->link); }
CWE-399
2,111
12,501
31159402757396885910180405942832412814
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type) { EmptyMsgPipeItem *item = spice_new(EmptyMsgPipeItem, 1); red_channel_pipe_item_init(rcc->channel, &item->base, PIPE_ITEM_TYPE_EMPTY_MSG); item->msg = msg_type; red_channel_client_pipe_add(rcc, &item->base); red_channel_client_push(rcc); }
CWE-399
2,112
12,502
279999390076151997351788618016167944941
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
void red_channel_client_pipe_add_push(RedChannelClient *rcc, PipeItem *item) { red_channel_client_pipe_add(rcc, item); red_channel_client_push(rcc); }
CWE-399
2,113
12,503
265541559332215420581530203267523311267
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
void red_channel_client_pipe_add_tail(RedChannelClient *rcc, PipeItem *item) { spice_assert(rcc); rcc->pipe_size++; ring_add_before(&item->link, &rcc->pipe); red_channel_client_push(rcc); }
CWE-399
2,114
12,504
95848967741031591841215380852483109025
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
void red_channel_client_pipe_add_tail_no_push(RedChannelClient *rcc, PipeItem *item) { spice_assert(rcc); rcc->pipe_size++; ring_add_before(&item->link, &rcc->pipe); }
CWE-399
2,115
12,505
292727043192440866307659477922870064792
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type) { PipeItem *item = spice_new(PipeItem, 1); red_channel_pipe_item_init(rcc->channel, item, pipe_item_type); red_channel_client_pipe_add(rcc, item); red_channel_client_push(rcc); }
CWE-399
2,116
12,506
115300301467680204982710916114714795127
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
void red_channel_client_pipe_clear(RedChannelClient *rcc) { PipeItem *item; if (rcc) { red_channel_client_clear_sent_item(rcc); } while ((item = (PipeItem *)ring_get_head(&rcc->pipe))) { ring_remove(&item->link); red_channel_client_release_item(rcc, item, FALSE); } rcc->pipe_size = 0; }
CWE-399
2,117
12,507
64785119222890204359130576946060755524
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static inline PipeItem *red_channel_client_pipe_item_get(RedChannelClient *rcc) { PipeItem *item; if (!rcc || rcc->send_data.blocked || red_channel_client_waiting_for_ack(rcc) || !(item = (PipeItem *)ring_get_tail(&rcc->pipe))) { return NULL; } red_channel_client_pipe_remove(rcc, item); return item; }
CWE-399
2,118
12,508
101279353215700462875416812600848072290
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
int red_channel_client_pipe_item_is_linked(RedChannelClient *rcc, PipeItem *item) { return ring_item_is_linked(&item->link); }
CWE-399
2,119
12,509
243125896199849388434979509703095097570
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void red_channel_client_pipe_remove(RedChannelClient *rcc, PipeItem *item) { rcc->pipe_size--; ring_remove(&item->link); }
CWE-399
2,120
12,510
66305986108527243472804647785517450785
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
void red_channel_client_pipe_remove_and_release(RedChannelClient *rcc, PipeItem *item) { red_channel_client_pipe_remove(rcc, item); red_channel_client_release_item(rcc, item, FALSE); }
CWE-399
2,121
12,511
200382958197519531696781801494692243274
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static int red_channel_client_pre_create_validate(RedChannel *channel, RedClient *client) { if (red_client_get_channel(client, channel->type, channel->id)) { spice_printerr("Error client %p: duplicate channel type %d id %d", client, channel->type, channel->id); return FALSE; } return TRUE; }
CWE-399
2,122
12,512
78162787864863263810841359483436061900
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
void red_channel_client_push(RedChannelClient *rcc) { PipeItem *pipe_item; if (!rcc->during_send) { rcc->during_send = TRUE; } else { return; } red_channel_client_ref(rcc); if (rcc->send_data.blocked) { red_channel_client_send(rcc); } if (!red_channel_client_no_item_being_sent(rcc) && !rcc->send_data.blocked) { rcc->send_data.blocked = TRUE; spice_printerr("ERROR: an item waiting to be sent and not blocked"); } while ((pipe_item = red_channel_client_pipe_item_get(rcc))) { red_channel_client_send_item(rcc, pipe_item); } rcc->during_send = FALSE; red_channel_client_unref(rcc); }
CWE-399
2,123
12,513
200629282118683312493515685004479894648
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void red_channel_client_push_ping(RedChannelClient *rcc) { spice_assert(rcc->latency_monitor.state == PING_STATE_NONE); rcc->latency_monitor.state = PING_STATE_WARMUP; rcc->latency_monitor.warmup_was_sent = FALSE; rcc->latency_monitor.id = rand(); red_channel_client_pipe_add_type(rcc, PIPE_ITEM_TYPE_PING); red_channel_client_pipe_add_type(rcc, PIPE_ITEM_TYPE_PING); }
CWE-399
2,124
12,514
287586455236945344650736668303892496966
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
void red_channel_client_push_set_ack(RedChannelClient *rcc) { red_channel_client_pipe_add_type(rcc, PIPE_ITEM_TYPE_SET_ACK); }
CWE-399
2,125
12,515
124948032223289768699411901857763937177
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
void red_channel_client_receive(RedChannelClient *rcc) { red_channel_client_ref(rcc); red_peer_handle_incoming(rcc->stream, &rcc->incoming); red_channel_client_unref(rcc); }
CWE-399
2,126
12,516
23387347746903638656824284578523162655
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void red_channel_client_release_item(RedChannelClient *rcc, PipeItem *item, int item_pushed) { int handled = TRUE; switch (item->type) { case PIPE_ITEM_TYPE_SET_ACK: case PIPE_ITEM_TYPE_EMPTY_MSG: case PIPE_ITEM_TYPE_MIGRATE: case PIPE_ITEM_TYPE_PING: free(item); break; default: handled = FALSE; } if (!handled) { rcc->channel->channel_cbs.release_item(rcc, item, item_pushed); } }
CWE-399
2,128
12,517
233232438958174519762859089831154433232
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static inline void red_channel_client_release_sent_item(RedChannelClient *rcc) { if (rcc->send_data.item) { red_channel_client_release_item(rcc, rcc->send_data.item, TRUE); rcc->send_data.item = NULL; } }
CWE-399
2,129
12,518
91131402320835704174835785660000404662
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void red_channel_client_restart_ping_timer(RedChannelClient *rcc) { struct timespec ts; uint64_t passed, timeout; clock_gettime(CLOCK_MONOTONIC, &ts); passed = ts.tv_sec * 1000000000LL + ts.tv_nsec; passed = passed - rcc->latency_monitor.last_pong_time; passed /= 1000*1000; timeout = PING_TEST_IDLE_NET_TIMEOUT_MS; if (passed < PING_TEST_TIMEOUT_MS) { timeout += PING_TEST_TIMEOUT_MS - passed; } red_channel_client_start_ping_timer(rcc, timeout); }
CWE-399
2,131
12,519
42324557255066916755883041553141151625
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void red_channel_client_restore_main_sender(RedChannelClient *rcc) { spice_marshaller_reset(rcc->send_data.urgent.marshaller); rcc->send_data.marshaller = rcc->send_data.main.marshaller; rcc->send_data.header.data = rcc->send_data.main.header_data; if (!rcc->is_mini_header) { rcc->send_data.header.set_msg_serial(&rcc->send_data.header, rcc->send_data.serial); } rcc->send_data.item = rcc->send_data.main.item; }
CWE-399
2,132
12,520
336070840931849960508204862565868717495
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
void red_channel_client_send(RedChannelClient *rcc) { red_channel_client_ref(rcc); red_peer_handle_outgoing(rcc->stream, &rcc->outgoing); red_channel_client_unref(rcc); }
CWE-399
2,134
12,521
263573522620107780099327741023770059467
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void red_channel_client_send_empty_msg(RedChannelClient *rcc, PipeItem *base) { EmptyMsgPipeItem *msg_pipe_item = SPICE_CONTAINEROF(base, EmptyMsgPipeItem, base); red_channel_client_init_send_data(rcc, msg_pipe_item->msg, NULL); red_channel_client_begin_send_message(rcc); }
CWE-399
2,135
12,522
111484224880135160991090139614451773965
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void red_channel_client_send_item(RedChannelClient *rcc, PipeItem *item) { int handled = TRUE; spice_assert(red_channel_client_no_item_being_sent(rcc)); red_channel_client_reset_send_data(rcc); switch (item->type) { case PIPE_ITEM_TYPE_SET_ACK: red_channel_client_send_set_ack(rcc); free(item); break; case PIPE_ITEM_TYPE_MIGRATE: red_channel_client_send_migrate(rcc); free(item); break; case PIPE_ITEM_TYPE_EMPTY_MSG: red_channel_client_send_empty_msg(rcc, item); free(item); break; case PIPE_ITEM_TYPE_PING: red_channel_client_send_ping(rcc); free(item); break; default: handled = FALSE; } if (!handled) { rcc->channel->channel_cbs.send_item(rcc, item); } }
CWE-399
2,136
12,523
140239143666874745107180242515296482704
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
int red_channel_client_send_message_pending(RedChannelClient *rcc) { return rcc->send_data.header.get_msg_type(&rcc->send_data.header) != 0; }
CWE-399
2,137
12,524
126875648302744325939571947656753740791
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void red_channel_client_send_migrate(RedChannelClient *rcc) { SpiceMsgMigrate migrate; red_channel_client_init_send_data(rcc, SPICE_MSG_MIGRATE, NULL); migrate.flags = rcc->channel->migration_flags; spice_marshall_msg_migrate(rcc->send_data.marshaller, &migrate); if (rcc->channel->migration_flags & SPICE_MIGRATE_NEED_FLUSH) { rcc->wait_migrate_flush_mark = TRUE; } red_channel_client_begin_send_message(rcc); }
CWE-399
2,138
12,525
119783338488392076401476943410696928803
null
null
null
spice
53488f0275d6c8a121af49f7ac817d09ce68090d
0
static void red_channel_client_send_ping(RedChannelClient *rcc) { SpiceMsgPing ping; struct timespec ts; if (!rcc->latency_monitor.warmup_was_sent) { // latency test start int delay_val; socklen_t opt_size = sizeof(delay_val); rcc->latency_monitor.warmup_was_sent = TRUE; /* * When testing latency, TCP_NODELAY must be switched on, otherwise, * sending the ping message is delayed by Nagle algorithm, and the * roundtrip measurment is less accurate (bigger). */ rcc->latency_monitor.tcp_nodelay = 1; if (getsockopt(rcc->stream->socket, IPPROTO_TCP, TCP_NODELAY, &delay_val, &opt_size) == -1) { spice_warning("getsockopt failed, %s", strerror(errno)); } else { rcc->latency_monitor.tcp_nodelay = delay_val; if (!delay_val) { delay_val = 1; if (setsockopt(rcc->stream->socket, IPPROTO_TCP, TCP_NODELAY, &delay_val, sizeof(delay_val)) == -1) { if (errno != ENOTSUP) { spice_warning("setsockopt failed, %s", strerror(errno)); } } } } } red_channel_client_init_send_data(rcc, SPICE_MSG_PING, NULL); ping.id = rcc->latency_monitor.id; clock_gettime(CLOCK_MONOTONIC, &ts); ping.timestamp = ts.tv_sec * 1000000000LL + ts.tv_nsec; spice_marshall_msg_ping(rcc->send_data.marshaller, &ping); red_channel_client_begin_send_message(rcc); }
CWE-399
2,139
12,526
338975790626838818873321445160841390803
null
null
null