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
openssl
e97763c92c655dcf4af2860b3abd2bc4c8a267f9
0
int tls1_save_sigalgs(SSL *s, const unsigned char *data, int dsize) { CERT *c = s->cert; /* Extension ignored for inappropriate versions */ if (!SSL_USE_SIGALGS(s)) return 1; /* Should never happen */ if (!c) return 0; OPENSSL_free(s->s3->tmp.peer_sigalgs); s->s3->tmp.peer_sigalgs = OPENSSL_malloc(dsize); if (s->s3->tmp.peer_sigalgs == NULL) return 0; s->s3->tmp.peer_sigalgslen = dsize; memcpy(s->s3->tmp.peer_sigalgs, data, dsize); return 1; }
CWE-20
9,462
16,417
315473114837830063899477934660082196110
null
null
null
openssl
e97763c92c655dcf4af2860b3abd2bc4c8a267f9
0
void tls1_set_cert_validity(SSL *s) { tls1_check_chain(s, NULL, NULL, NULL, SSL_PKEY_RSA_ENC); tls1_check_chain(s, NULL, NULL, NULL, SSL_PKEY_RSA_SIGN); tls1_check_chain(s, NULL, NULL, NULL, SSL_PKEY_DSA_SIGN); tls1_check_chain(s, NULL, NULL, NULL, SSL_PKEY_ECC); tls1_check_chain(s, NULL, NULL, NULL, SSL_PKEY_GOST01); tls1_check_chain(s, NULL, NULL, NULL, SSL_PKEY_GOST12_256); tls1_check_chain(s, NULL, NULL, NULL, SSL_PKEY_GOST12_512); }
CWE-20
9,463
16,418
69214961372901145908694677789456939418
null
null
null
openssl
e97763c92c655dcf4af2860b3abd2bc4c8a267f9
0
int tls1_set_curves(unsigned char **pext, size_t *pextlen, int *curves, size_t ncurves) { unsigned char *clist, *p; size_t i; /* * Bitmap of curves included to detect duplicates: only works while curve * ids < 32 */ unsigned long dup_list = 0; clist = OPENSSL_malloc(ncurves * 2); if (clist == NULL) return 0; for (i = 0, p = clist; i < ncurves; i++) { unsigned long idmask; int id; id = tls1_ec_nid2curve_id(curves[i]); idmask = 1L << id; if (!id || (dup_list & idmask)) { OPENSSL_free(clist); return 0; } dup_list |= idmask; s2n(id, p); } OPENSSL_free(*pext); *pext = clist; *pextlen = ncurves * 2; return 1; }
CWE-20
9,464
16,419
92018513180907584496862880045072608999
null
null
null
openssl
e97763c92c655dcf4af2860b3abd2bc4c8a267f9
0
static int tls1_set_ec_id(unsigned char *curve_id, unsigned char *comp_id, EC_KEY *ec) { int id; const EC_GROUP *grp; if (!ec) return 0; /* Determine if it is a prime field */ grp = EC_KEY_get0_group(ec); if (!grp) return 0; /* Determine curve ID */ id = EC_GROUP_get_curve_name(grp); id = tls1_ec_nid2curve_id(id); /* If no id return error: we don't support arbitrary explicit curves */ if (id == 0) return 0; curve_id[0] = 0; curve_id[1] = (unsigned char)id; if (comp_id) { if (EC_KEY_get0_public_key(ec) == NULL) return 0; if (EC_KEY_get_conv_form(ec) == POINT_CONVERSION_UNCOMPRESSED) { *comp_id = TLSEXT_ECPOINTFORMAT_uncompressed; } else { if ((nid_list[id - 1].flags & TLS_CURVE_TYPE) == TLS_CURVE_PRIME) *comp_id = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime; else *comp_id = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2; } } return 1; }
CWE-20
9,466
16,420
91273752138552851066880471691052878895
null
null
null
openssl
e97763c92c655dcf4af2860b3abd2bc4c8a267f9
0
int tls1_set_server_sigalgs(SSL *s) { int al; size_t i; /* Clear any shared signature algorithms */ OPENSSL_free(s->cert->shared_sigalgs); s->cert->shared_sigalgs = NULL; s->cert->shared_sigalgslen = 0; /* Clear certificate digests and validity flags */ for (i = 0; i < SSL_PKEY_NUM; i++) { s->s3->tmp.md[i] = NULL; s->s3->tmp.valid_flags[i] = 0; } /* If sigalgs received process it. */ if (s->s3->tmp.peer_sigalgs) { if (!tls1_process_sigalgs(s)) { SSLerr(SSL_F_TLS1_SET_SERVER_SIGALGS, ERR_R_MALLOC_FAILURE); al = SSL_AD_INTERNAL_ERROR; goto err; } /* Fatal error is no shared signature algorithms */ if (!s->cert->shared_sigalgs) { SSLerr(SSL_F_TLS1_SET_SERVER_SIGALGS, SSL_R_NO_SHARED_SIGNATURE_ALGORITHMS); al = SSL_AD_ILLEGAL_PARAMETER; goto err; } } else { ssl_set_default_md(s); } return 1; err: ssl3_send_alert(s, SSL3_AL_FATAL, al); return 0; }
CWE-20
9,467
16,421
161431749217936204276199211788096241914
null
null
null
openssl
e97763c92c655dcf4af2860b3abd2bc4c8a267f9
0
static int tls1_set_shared_sigalgs(SSL *s) { const unsigned char *pref, *allow, *conf; size_t preflen, allowlen, conflen; size_t nmatch; TLS_SIGALGS *salgs = NULL; CERT *c = s->cert; unsigned int is_suiteb = tls1_suiteb(s); OPENSSL_free(c->shared_sigalgs); c->shared_sigalgs = NULL; c->shared_sigalgslen = 0; /* If client use client signature algorithms if not NULL */ if (!s->server && c->client_sigalgs && !is_suiteb) { conf = c->client_sigalgs; conflen = c->client_sigalgslen; } else if (c->conf_sigalgs && !is_suiteb) { conf = c->conf_sigalgs; conflen = c->conf_sigalgslen; } else conflen = tls12_get_psigalgs(s, &conf); if (s->options & SSL_OP_CIPHER_SERVER_PREFERENCE || is_suiteb) { pref = conf; preflen = conflen; allow = s->s3->tmp.peer_sigalgs; allowlen = s->s3->tmp.peer_sigalgslen; } else { allow = conf; allowlen = conflen; pref = s->s3->tmp.peer_sigalgs; preflen = s->s3->tmp.peer_sigalgslen; } nmatch = tls12_shared_sigalgs(s, NULL, pref, preflen, allow, allowlen); if (nmatch) { salgs = OPENSSL_malloc(nmatch * sizeof(TLS_SIGALGS)); if (salgs == NULL) return 0; nmatch = tls12_shared_sigalgs(s, salgs, pref, preflen, allow, allowlen); } else { salgs = NULL; } c->shared_sigalgs = salgs; c->shared_sigalgslen = nmatch; return 1; }
CWE-20
9,468
16,422
307227763801077512271320164965308323805
null
null
null
openssl
e97763c92c655dcf4af2860b3abd2bc4c8a267f9
0
int tls1_set_sigalgs(CERT *c, const int *psig_nids, size_t salglen, int client) { unsigned char *sigalgs, *sptr; int rhash, rsign; size_t i; if (salglen & 1) return 0; sigalgs = OPENSSL_malloc(salglen); if (sigalgs == NULL) return 0; for (i = 0, sptr = sigalgs; i < salglen; i += 2) { rhash = tls12_find_id(*psig_nids++, tls12_md, OSSL_NELEM(tls12_md)); rsign = tls12_find_id(*psig_nids++, tls12_sig, OSSL_NELEM(tls12_sig)); if (rhash == -1 || rsign == -1) goto err; *sptr++ = rhash; *sptr++ = rsign; } if (client) { OPENSSL_free(c->client_sigalgs); c->client_sigalgs = sigalgs; c->client_sigalgslen = salglen; } else { OPENSSL_free(c->conf_sigalgs); c->conf_sigalgs = sigalgs; c->conf_sigalgslen = salglen; } return 1; err: OPENSSL_free(sigalgs); return 0; }
CWE-20
9,469
16,423
287945963395844414343217926439883024753
null
null
null
openssl
e97763c92c655dcf4af2860b3abd2bc4c8a267f9
0
int tls1_set_sigalgs_list(CERT *c, const char *str, int client) { sig_cb_st sig; sig.sigalgcnt = 0; if (!CONF_parse_list(str, ':', 1, sig_cb, &sig)) return 0; if (c == NULL) return 1; return tls1_set_sigalgs(c, sig.sigalgs, sig.sigalgcnt, client); }
CWE-20
9,470
16,424
314569206555822558318665829592038500115
null
null
null
openssl
e97763c92c655dcf4af2860b3abd2bc4c8a267f9
0
int tls1_shared_curve(SSL *s, int nmatch) { const unsigned char *pref, *supp; size_t num_pref, num_supp, i, j; int k; /* Can't do anything on client side */ if (s->server == 0) return -1; if (nmatch == -2) { if (tls1_suiteb(s)) { /* * For Suite B ciphersuite determines curve: we already know * these are acceptable due to previous checks. */ unsigned long cid = s->s3->tmp.new_cipher->id; if (cid == TLS1_CK_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256) return NID_X9_62_prime256v1; /* P-256 */ if (cid == TLS1_CK_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384) return NID_secp384r1; /* P-384 */ /* Should never happen */ return NID_undef; } /* If not Suite B just return first preference shared curve */ nmatch = 0; } /* * Avoid truncation. tls1_get_curvelist takes an int * but s->options is a long... */ if (!tls1_get_curvelist (s, (s->options & SSL_OP_CIPHER_SERVER_PREFERENCE) != 0, &supp, &num_supp)) /* In practice, NID_undef == 0 but let's be precise. */ return nmatch == -1 ? 0 : NID_undef; if (!tls1_get_curvelist (s, !(s->options & SSL_OP_CIPHER_SERVER_PREFERENCE), &pref, &num_pref)) return nmatch == -1 ? 0 : NID_undef; /* * If the client didn't send the elliptic_curves extension all of them * are allowed. */ if (num_supp == 0 && (s->options & SSL_OP_CIPHER_SERVER_PREFERENCE) != 0) { supp = eccurves_all; num_supp = sizeof(eccurves_all) / 2; } else if (num_pref == 0 && (s->options & SSL_OP_CIPHER_SERVER_PREFERENCE) == 0) { pref = eccurves_all; num_pref = sizeof(eccurves_all) / 2; } k = 0; for (i = 0; i < num_pref; i++, pref += 2) { const unsigned char *tsupp = supp; for (j = 0; j < num_supp; j++, tsupp += 2) { if (pref[0] == tsupp[0] && pref[1] == tsupp[1]) { if (!tls_curve_allowed(s, pref, SSL_SECOP_CURVE_SHARED)) continue; if (nmatch == k) { int id = (pref[0] << 8) | pref[1]; return tls1_ec_curve_id2nid(id, NULL); } k++; } } } if (nmatch == -1) return k; /* Out of range (nmatch > k). */ return NID_undef; }
CWE-20
9,471
16,425
165988685412200920210078799245469213148
null
null
null
openssl
e97763c92c655dcf4af2860b3abd2bc4c8a267f9
0
int tls_check_serverhello_tlsext_early(SSL *s, const PACKET *ext, const PACKET *session_id, SSL_SESSION **ret) { unsigned int i; PACKET local_ext = *ext; int retv = -1; int have_ticket = 0; int use_ticket = tls_use_ticket(s); *ret = NULL; s->tlsext_ticket_expected = 0; s->s3->flags &= ~TLS1_FLAGS_RECEIVED_EXTMS; /* * If tickets disabled behave as if no ticket present to permit stateful * resumption. */ if ((s->version <= SSL3_VERSION)) return 0; if (!PACKET_get_net_2(&local_ext, &i)) { retv = 0; goto end; } while (PACKET_remaining(&local_ext) >= 4) { unsigned int type, size; if (!PACKET_get_net_2(&local_ext, &type) || !PACKET_get_net_2(&local_ext, &size)) { /* Shouldn't ever happen */ retv = -1; goto end; } if (PACKET_remaining(&local_ext) < size) { retv = 0; goto end; } if (type == TLSEXT_TYPE_session_ticket && use_ticket) { int r; const unsigned char *etick; /* Duplicate extension */ if (have_ticket != 0) { retv = -1; goto end; } have_ticket = 1; if (size == 0) { /* * The client will accept a ticket but doesn't currently have * one. */ s->tlsext_ticket_expected = 1; retv = 1; continue; } if (s->tls_session_secret_cb) { /* * Indicate that the ticket couldn't be decrypted rather than * generating the session from ticket now, trigger * abbreviated handshake based on external mechanism to * calculate the master secret later. */ retv = 2; continue; } if (!PACKET_get_bytes(&local_ext, &etick, size)) { /* Shouldn't ever happen */ retv = -1; goto end; } r = tls_decrypt_ticket(s, etick, size, PACKET_data(session_id), PACKET_remaining(session_id), ret); switch (r) { case 2: /* ticket couldn't be decrypted */ s->tlsext_ticket_expected = 1; retv = 2; break; case 3: /* ticket was decrypted */ retv = r; break; case 4: /* ticket decrypted but need to renew */ s->tlsext_ticket_expected = 1; retv = 3; break; default: /* fatal error */ retv = -1; break; } continue; } else { if (type == TLSEXT_TYPE_extended_master_secret) s->s3->flags |= TLS1_FLAGS_RECEIVED_EXTMS; if (!PACKET_forward(&local_ext, size)) { retv = -1; goto end; } } } if (have_ticket == 0) retv = 0; end: return retv; }
CWE-20
9,472
16,426
170691800474401069001677995814668056392
null
null
null
openssl
e97763c92c655dcf4af2860b3abd2bc4c8a267f9
0
static int tls_curve_allowed(SSL *s, const unsigned char *curve, int op) { const tls_curve_info *cinfo; if (curve[0]) return 1; if ((curve[1] < 1) || ((size_t)curve[1] > OSSL_NELEM(nid_list))) return 0; cinfo = &nid_list[curve[1] - 1]; # ifdef OPENSSL_NO_EC2M if (cinfo->flags & TLS_CURVE_CHAR2) return 0; # endif return ssl_security(s, op, cinfo->secbits, cinfo->nid, (void *)curve); }
CWE-20
9,473
16,427
137267134108648517039663343370701650985
null
null
null
openssl
e97763c92c655dcf4af2860b3abd2bc4c8a267f9
0
static int tls_use_ticket(SSL *s) { if (s->options & SSL_OP_NO_TICKET) return 0; return ssl_security(s, SSL_SECOP_TICKET, 0, 0, NULL); }
CWE-20
9,474
16,428
245515905365591207417756160455778117546
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
static double LOG2D(int a) { if (a < 0) return 1.0 / (1UL << -a); return 1UL << a; }
CWE-399
9,475
16,429
128971758047047699917903451249911140791
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
static ALWAYS_INLINE double MAXD(double a, double b) { if (a > b) return a; return b; }
CWE-399
9,476
16,430
201734944153337175774427332552548793276
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
static ALWAYS_INLINE double MIND(double a, double b) { if (a < b) return a; return b; }
CWE-399
9,477
16,431
290788432344112865307495223490810997128
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
static ALWAYS_INLINE double SQRT(double X) { /* If this arch doesn't use IEEE 754 floats, fall back to using libm */ if (sizeof(float) != 4) return sqrt(X); /* This avoids needing libm, saves about 0.5k on x86-32 */ return my_SQRT(X); }
CWE-399
9,478
16,432
233191267173670274182681794294043336378
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
static ALWAYS_INLINE double SQUARE(double x) { return x * x; }
CWE-399
9,479
16,433
75827272428855499518574915511143482791
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
add_peers(const char *s) { llist_t *item; peer_t *p; p = xzalloc(sizeof(*p) + strlen(s)); strcpy(p->p_hostname, s); resolve_peer_hostname(p, /*loop_on_fail=*/ 1); /* Names like N.<country2chars>.pool.ntp.org are randomly resolved * to a pool of machines. Sometimes different N's resolve to the same IP. * It is not useful to have two peers with same IP. We skip duplicates. */ for (item = G.ntp_peers; item != NULL; item = item->link) { peer_t *pp = (peer_t *) item->data; if (strcmp(p->p_dotted, pp->p_dotted) == 0) { bb_error_msg("duplicate peer %s (%s)", s, p->p_dotted); free(p->p_lsa); free(p->p_dotted); free(p); return; } } p->p_fd = -1; p->p_xmt_msg.m_status = MODE_CLIENT | (NTP_VERSION << 3); p->next_action_time = G.cur_time; /* = set_next(p, 0); */ reset_peer_stats(p, STEP_THRESHOLD); llist_add_to(&G.ntp_peers, p); G.peer_cnt++; }
CWE-399
9,480
16,434
107932780647391594831239339761752609848
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
adjust_poll(int count) { G.polladj_count += count; if (G.polladj_count > POLLADJ_LIMIT) { G.polladj_count = 0; if (G.poll_exp < MAXPOLL) { G.poll_exp++; VERB4 bb_error_msg("polladj: discipline_jitter:%f ++poll_exp=%d", G.discipline_jitter, G.poll_exp); } } else if (G.polladj_count < -POLLADJ_LIMIT || (count < 0 && G.poll_exp > BIGPOLL)) { G.polladj_count = 0; if (G.poll_exp > MINPOLL) { llist_t *item; G.poll_exp--; /* Correct p->next_action_time in each peer * which waits for sending, so that they send earlier. * Old pp->next_action_time are on the order * of t + (1 << old_poll_exp) + small_random, * we simply need to subtract ~half of that. */ for (item = G.ntp_peers; item != NULL; item = item->link) { peer_t *pp = (peer_t *) item->data; if (pp->p_fd < 0) pp->next_action_time -= (1 << G.poll_exp); } VERB4 bb_error_msg("polladj: discipline_jitter:%f --poll_exp=%d", G.discipline_jitter, G.poll_exp); } } else { VERB4 bb_error_msg("polladj: count:%d", G.polladj_count); } }
CWE-399
9,481
16,435
269652324874375661435543511240980301683
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
static void clamp_pollexp_and_set_MAXSTRAT(void) { if (G.poll_exp < MINPOLL) G.poll_exp = MINPOLL; if (G.poll_exp > BIGPOLL) G.poll_exp = BIGPOLL; G.polladj_count = 0; G.stratum = MAXSTRAT; }
CWE-399
9,482
16,436
237938302075295395114248271499263021875
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
compare_point_edge(const void *aa, const void *bb) { const point_t *a = aa; const point_t *b = bb; if (a->edge < b->edge) { return -1; } return (a->edge > b->edge); }
CWE-399
9,483
16,437
67923942175710947631554238632503285420
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
compare_survivor_metric(const void *aa, const void *bb) { const survivor_t *a = aa; const survivor_t *b = bb; if (a->metric < b->metric) { return -1; } return (a->metric > b->metric); }
CWE-399
9,484
16,438
4761655406904133304852703942392456496
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
d_to_sfp(double d) { s_fixedpt_t sfp; sfp.int_parts = (uint16_t)d; sfp.fractions = (uint16_t)((d - sfp.int_parts) * USHRT_MAX); sfp.int_parts = htons(sfp.int_parts); sfp.fractions = htons(sfp.fractions); return sfp; }
CWE-399
9,486
16,439
150867912722720168231332353419963918519
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
d_to_tv(double d, struct timeval *tv) { tv->tv_sec = (long)d; tv->tv_usec = (d - tv->tv_sec) * 1000000; }
CWE-399
9,487
16,440
260234442699460162146966037896777479140
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
do_sendto(int fd, const struct sockaddr *from, const struct sockaddr *to, socklen_t addrlen, msg_t *msg, ssize_t len) { ssize_t ret; errno = 0; if (!from) { ret = sendto(fd, msg, len, MSG_DONTWAIT, to, addrlen); } else { ret = send_to_from(fd, msg, len, MSG_DONTWAIT, to, from, addrlen); } if (ret != len) { bb_perror_msg("send failed"); return -1; } return 0; }
CWE-399
9,489
16,441
218811700088133675561621850365926678881
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
filter_datapoints(peer_t *p) { int i, idx; double sum, wavg; datapoint_t *fdp; #if 0 /* Simulations have shown that use of *averaged* offset for p->filter_offset * is in fact worse than simply using last received one: with large poll intervals * (>= 2048) averaging code uses offset values which are outdated by hours, * and time/frequency correction goes totally wrong when fed essentially bogus offsets. */ int got_newest; double minoff, maxoff, w; double x = x; /* for compiler */ double oldest_off = oldest_off; double oldest_age = oldest_age; double newest_off = newest_off; double newest_age = newest_age; fdp = p->filter_datapoint; minoff = maxoff = fdp[0].d_offset; for (i = 1; i < NUM_DATAPOINTS; i++) { if (minoff > fdp[i].d_offset) minoff = fdp[i].d_offset; if (maxoff < fdp[i].d_offset) maxoff = fdp[i].d_offset; } idx = p->datapoint_idx; /* most recent datapoint's index */ /* Average offset: * Drop two outliers and take weighted average of the rest: * most_recent/2 + older1/4 + older2/8 ... + older5/32 + older6/32 * we use older6/32, not older6/64 since sum of weights should be 1: * 1/2 + 1/4 + 1/8 + 1/16 + 1/32 + 1/32 = 1 */ wavg = 0; w = 0.5; /* n-1 * --- dispersion(i) * filter_dispersion = \ ------------- * / (i+1) * --- 2 * i=0 */ got_newest = 0; sum = 0; for (i = 0; i < NUM_DATAPOINTS; i++) { VERB5 { bb_error_msg("datapoint[%d]: off:%f disp:%f(%f) age:%f%s", i, fdp[idx].d_offset, fdp[idx].d_dispersion, dispersion(&fdp[idx]), G.cur_time - fdp[idx].d_recv_time, (minoff == fdp[idx].d_offset || maxoff == fdp[idx].d_offset) ? " (outlier by offset)" : "" ); } sum += dispersion(&fdp[idx]) / (2 << i); if (minoff == fdp[idx].d_offset) { minoff -= 1; /* so that we don't match it ever again */ } else if (maxoff == fdp[idx].d_offset) { maxoff += 1; } else { oldest_off = fdp[idx].d_offset; oldest_age = G.cur_time - fdp[idx].d_recv_time; if (!got_newest) { got_newest = 1; newest_off = oldest_off; newest_age = oldest_age; } x = oldest_off * w; wavg += x; w /= 2; } idx = (idx - 1) & (NUM_DATAPOINTS - 1); } p->filter_dispersion = sum; wavg += x; /* add another older6/64 to form older6/32 */ /* Fix systematic underestimation with large poll intervals. * Imagine that we still have a bit of uncorrected drift, * and poll interval is big (say, 100 sec). Offsets form a progression: * 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 - 0.7 is most recent. * The algorithm above drops 0.0 and 0.7 as outliers, * and then we have this estimation, ~25% off from 0.7: * 0.1/32 + 0.2/32 + 0.3/16 + 0.4/8 + 0.5/4 + 0.6/2 = 0.503125 */ x = oldest_age - newest_age; if (x != 0) { x = newest_age / x; /* in above example, 100 / (600 - 100) */ if (x < 1) { /* paranoia check */ x = (newest_off - oldest_off) * x; /* 0.5 * 100/500 = 0.1 */ wavg += x; } } p->filter_offset = wavg; #else fdp = p->filter_datapoint; idx = p->datapoint_idx; /* most recent datapoint's index */ /* filter_offset: simply use the most recent value */ p->filter_offset = fdp[idx].d_offset; /* n-1 * --- dispersion(i) * filter_dispersion = \ ------------- * / (i+1) * --- 2 * i=0 */ wavg = 0; sum = 0; for (i = 0; i < NUM_DATAPOINTS; i++) { sum += dispersion(&fdp[idx]) / (2 << i); wavg += fdp[idx].d_offset; idx = (idx - 1) & (NUM_DATAPOINTS - 1); } wavg /= NUM_DATAPOINTS; p->filter_dispersion = sum; #endif /* +----- -----+ ^ 1/2 * | n-1 | * | --- | * | 1 \ 2 | * filter_jitter = | --- * / (avg-offset_j) | * | n --- | * | j=0 | * +----- -----+ * where n is the number of valid datapoints in the filter (n > 1); * if filter_jitter < precision then filter_jitter = precision */ sum = 0; for (i = 0; i < NUM_DATAPOINTS; i++) { sum += SQUARE(wavg - fdp[i].d_offset); } sum = SQRT(sum / NUM_DATAPOINTS); p->filter_jitter = sum > G_precision_sec ? sum : G_precision_sec; VERB4 bb_error_msg("filter offset:%+f disp:%f jitter:%f", p->filter_offset, p->filter_dispersion, p->filter_jitter); }
CWE-399
9,490
16,442
316344755919779243795883536113840634977
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
fit(peer_t *p, double rd) { if ((p->reachable_bits & (p->reachable_bits-1)) == 0) { /* One or zero bits in reachable_bits */ VERB4 bb_error_msg("peer %s unfit for selection: unreachable", p->p_dotted); return 0; } #if 0 /* we filter out such packets earlier */ if ((p->lastpkt_status & LI_ALARM) == LI_ALARM || p->lastpkt_stratum >= MAXSTRAT ) { VERB4 bb_error_msg("peer %s unfit for selection: bad status/stratum", p->p_dotted); return 0; } #endif /* rd is root_distance(p) */ if (rd > MAXDIST + FREQ_TOLERANCE * (1 << G.poll_exp)) { VERB4 bb_error_msg("peer %s unfit for selection: root distance too high", p->p_dotted); return 0; } return 1; }
CWE-399
9,491
16,443
155082364833235617860374328377495057904
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
gettime1900d(void) { struct timeval tv; gettimeofday(&tv, NULL); /* never fails */ G.cur_time = tv.tv_sec + (1.0e-6 * tv.tv_usec) + OFFSET_1900_1970; return G.cur_time; }
CWE-399
9,492
16,444
86229807742692257583261454953487568439
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
static NOINLINE double my_SQRT(double X) { union { float f; int32_t i; } v; double invsqrt; double Xhalf = X * 0.5; /* Fast and good approximation to 1/sqrt(X), black magic */ v.f = X; /*v.i = 0x5f3759df - (v.i >> 1);*/ v.i = 0x5f375a86 - (v.i >> 1); /* - this constant is slightly better */ invsqrt = v.f; /* better than 0.2% accuracy */ /* Refining it using Newton's method: x1 = x0 - f(x0)/f'(x0) * f(x) = 1/(x*x) - X (f==0 when x = 1/sqrt(X)) * f'(x) = -2/(x*x*x) * f(x)/f'(x) = (X - 1/(x*x)) / (2/(x*x*x)) = X*x*x*x/2 - x/2 * x1 = x0 - (X*x0*x0*x0/2 - x0/2) = 1.5*x0 - X*x0*x0*x0/2 = x0*(1.5 - (X/2)*x0*x0) */ invsqrt = invsqrt * (1.5 - Xhalf * invsqrt * invsqrt); /* ~0.05% accuracy */ /* invsqrt = invsqrt * (1.5 - Xhalf * invsqrt * invsqrt); 2nd iter: ~0.0001% accuracy */ /* With 4 iterations, more than half results will be exact, * at 6th iterations result stabilizes with about 72% results exact. * We are well satisfied with 0.05% accuracy. */ return X * invsqrt; /* X * 1/sqrt(X) ~= sqrt(X) */ }
CWE-399
9,494
16,445
8465992155792613601410765202530854515
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
static NOINLINE void ntp_init(char **argv) { unsigned opts; llist_t *peers; srand(getpid()); if (getuid()) bb_error_msg_and_die(bb_msg_you_must_be_root); /* Set some globals */ G.discipline_jitter = G_precision_sec; G.stratum = MAXSTRAT; if (BURSTPOLL != 0) G.poll_exp = BURSTPOLL; /* speeds up initial sync */ G.last_script_run = G.reftime = G.last_update_recv_time = gettime1900d(); /* sets G.cur_time too */ /* Parse options */ peers = NULL; opt_complementary = "dd:wn" /* -d: counter; -p: list; -w implies -n */ IF_FEATURE_NTPD_SERVER(":Il"); /* -I implies -l */ opts = getopt32(argv, "nqNx" /* compat */ "wp:*S:"IF_FEATURE_NTPD_SERVER("l") /* NOT compat */ IF_FEATURE_NTPD_SERVER("I:") /* compat */ "d" /* compat */ "46aAbgL", /* compat, ignored */ &peers,&G.script_name, #if ENABLE_FEATURE_NTPD_SERVER &G.if_name, #endif &G.verbose); #if ENABLE_FEATURE_NTPD_SERVER G_listen_fd = -1; if (opts & OPT_l) { G_listen_fd = create_and_bind_dgram_or_die(NULL, 123); if (G.if_name) { if (setsockopt_bindtodevice(G_listen_fd, G.if_name)) xfunc_die(); } socket_want_pktinfo(G_listen_fd); setsockopt_int(G_listen_fd, IPPROTO_IP, IP_TOS, IPTOS_LOWDELAY); } #endif /* I hesitate to set -20 prio. -15 should be high enough for timekeeping */ if (opts & OPT_N) setpriority(PRIO_PROCESS, 0, -15); /* add_peers() calls can retry DNS resolution (possibly forever). * Daemonize before them, or else boot can stall forever. */ if (!(opts & OPT_n)) { bb_daemonize_or_rexec(DAEMON_DEVNULL_STDIO, argv); logmode = LOGMODE_NONE; } if (peers) { while (peers) add_peers(llist_pop(&peers)); } #if ENABLE_FEATURE_NTPD_CONF else { parser_t *parser; char *token[3]; parser = config_open("/etc/ntp.conf"); while (config_read(parser, token, 3, 1, "# \t", PARSE_NORMAL)) { if (strcmp(token[0], "server") == 0 && token[1]) { add_peers(token[1]); continue; } bb_error_msg("skipping %s:%u: unimplemented command '%s'", "/etc/ntp.conf", parser->lineno, token[0] ); } config_close(parser); } #endif if (G.peer_cnt == 0) { if (!(opts & OPT_l)) bb_show_usage(); /* -l but no peers: "stratum 1 server" mode */ G.stratum = 1; } /* If network is up, syncronization occurs in ~10 seconds. * We give "ntpd -q" 10 seconds to get first reply, * then another 50 seconds to finish syncing. * * I tested ntpd 4.2.6p1 and apparently it never exits * (will try forever), but it does not feel right. * The goal of -q is to act like ntpdate: set time * after a reasonably small period of polling, or fail. */ if (opts & OPT_q) { option_mask32 |= OPT_qq; alarm(10); } bb_signals(0 | (1 << SIGTERM) | (1 << SIGINT) | (1 << SIGALRM) , record_signo ); bb_signals(0 | (1 << SIGPIPE) | (1 << SIGCHLD) , SIG_IGN ); }
CWE-399
9,495
16,446
292037079097914054063773773734710197070
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
int ntpd_main(int argc UNUSED_PARAM, char **argv) { #undef G struct globals G; struct pollfd *pfd; peer_t **idx2peer; unsigned cnt; memset(&G, 0, sizeof(G)); SET_PTR_TO_GLOBALS(&G); ntp_init(argv); /* If ENABLE_FEATURE_NTPD_SERVER, + 1 for listen_fd: */ cnt = G.peer_cnt + ENABLE_FEATURE_NTPD_SERVER; idx2peer = xzalloc(sizeof(idx2peer[0]) * cnt); pfd = xzalloc(sizeof(pfd[0]) * cnt); /* Countdown: we never sync before we sent INITIAL_SAMPLES+1 * packets to each peer. * NB: if some peer is not responding, we may end up sending * fewer packets to it and more to other peers. * NB2: sync usually happens using INITIAL_SAMPLES packets, * since last reply does not come back instantaneously. */ cnt = G.peer_cnt * (INITIAL_SAMPLES + 1); write_pidfile(CONFIG_PID_FILE_PATH "/ntpd.pid"); while (!bb_got_signal) { llist_t *item; unsigned i, j; int nfds, timeout; double nextaction; /* Nothing between here and poll() blocks for any significant time */ nextaction = G.cur_time + 3600; i = 0; #if ENABLE_FEATURE_NTPD_SERVER if (G_listen_fd != -1) { pfd[0].fd = G_listen_fd; pfd[0].events = POLLIN; i++; } #endif /* Pass over peer list, send requests, time out on receives */ for (item = G.ntp_peers; item != NULL; item = item->link) { peer_t *p = (peer_t *) item->data; if (p->next_action_time <= G.cur_time) { if (p->p_fd == -1) { /* Time to send new req */ if (--cnt == 0) { VERB4 bb_error_msg("disabling burst mode"); G.polladj_count = 0; G.poll_exp = MINPOLL; } send_query_to_peer(p); } else { /* Timed out waiting for reply */ close(p->p_fd); p->p_fd = -1; /* If poll interval is small, increase it */ if (G.poll_exp < BIGPOLL) adjust_poll(MINPOLL); timeout = poll_interval(NOREPLY_INTERVAL); bb_error_msg("timed out waiting for %s, reach 0x%02x, next query in %us", p->p_dotted, p->reachable_bits, timeout); /* What if don't see it because it changed its IP? */ if (p->reachable_bits == 0) resolve_peer_hostname(p, /*loop_on_fail=*/ 0); set_next(p, timeout); } } if (p->next_action_time < nextaction) nextaction = p->next_action_time; if (p->p_fd >= 0) { /* Wait for reply from this peer */ pfd[i].fd = p->p_fd; pfd[i].events = POLLIN; idx2peer[i] = p; i++; } } timeout = nextaction - G.cur_time; if (timeout < 0) timeout = 0; timeout++; /* (nextaction - G.cur_time) rounds down, compensating */ /* Here we may block */ VERB2 { if (i > (ENABLE_FEATURE_NTPD_SERVER && G_listen_fd != -1)) { /* We wait for at least one reply. * Poll for it, without wasting time for message. * Since replies often come under 1 second, this also * reduces clutter in logs. */ nfds = poll(pfd, i, 1000); if (nfds != 0) goto did_poll; if (--timeout <= 0) goto did_poll; } bb_error_msg("poll:%us sockets:%u interval:%us", timeout, i, 1 << G.poll_exp); } nfds = poll(pfd, i, timeout * 1000); did_poll: gettime1900d(); /* sets G.cur_time */ if (nfds <= 0) { if (!bb_got_signal /* poll wasn't interrupted by a signal */ && G.cur_time - G.last_script_run > 11*60 ) { /* Useful for updating battery-backed RTC and such */ run_script("periodic", G.last_update_offset); gettime1900d(); /* sets G.cur_time */ } goto check_unsync; } /* Process any received packets */ j = 0; #if ENABLE_FEATURE_NTPD_SERVER if (G.listen_fd != -1) { if (pfd[0].revents /* & (POLLIN|POLLERR)*/) { nfds--; recv_and_process_client_pkt(/*G.listen_fd*/); gettime1900d(); /* sets G.cur_time */ } j = 1; } #endif for (; nfds != 0 && j < i; j++) { if (pfd[j].revents /* & (POLLIN|POLLERR)*/) { /* * At init, alarm was set to 10 sec. * Now we did get a reply. * Increase timeout to 50 seconds to finish syncing. */ if (option_mask32 & OPT_qq) { option_mask32 &= ~OPT_qq; alarm(50); } nfds--; recv_and_process_peer_pkt(idx2peer[j]); gettime1900d(); /* sets G.cur_time */ } } check_unsync: if (G.ntp_peers && G.stratum != MAXSTRAT) { for (item = G.ntp_peers; item != NULL; item = item->link) { peer_t *p = (peer_t *) item->data; if (p->reachable_bits) goto have_reachable_peer; } /* No peer responded for last 8 packets, panic */ clamp_pollexp_and_set_MAXSTRAT(); run_script("unsync", 0.0); have_reachable_peer: ; } } /* while (!bb_got_signal) */ remove_pidfile(CONFIG_PID_FILE_PATH "/ntpd.pid"); kill_myself_with_sig(bb_got_signal); }
CWE-399
9,496
16,447
260997369552647115858795827573185733528
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
poll_interval(int upper_bound) { unsigned interval, r, mask; interval = 1 << G.poll_exp; if (interval > upper_bound) interval = upper_bound; mask = ((interval-1) >> 4) | 1; r = rand(); interval += r & mask; /* ~ random(0..1) * interval/16 */ VERB4 bb_error_msg("chose poll interval:%u (poll_exp:%d)", interval, G.poll_exp); return interval; }
CWE-399
9,497
16,448
323616184238656511011552959827844546425
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
recv_and_process_peer_pkt(peer_t *p) { int rc; ssize_t size; msg_t msg; double T1, T2, T3, T4; double offset; double prev_delay, delay; unsigned interval; datapoint_t *datapoint; peer_t *q; offset = 0; /* We can recvfrom here and check from.IP, but some multihomed * ntp servers reply from their *other IP*. * TODO: maybe we should check at least what we can: from.port == 123? */ recv_again: size = recv(p->p_fd, &msg, sizeof(msg), MSG_DONTWAIT); if (size < 0) { if (errno == EINTR) /* Signal caught */ goto recv_again; if (errno == EAGAIN) /* There was no packet after all * (poll() returning POLLIN for a fd * is not a ironclad guarantee that data is there) */ return; /* * If you need a different handling for a specific * errno, always explain it in comment. */ bb_perror_msg_and_die("recv(%s) error", p->p_dotted); } if (size != NTP_MSGSIZE_NOAUTH && size != NTP_MSGSIZE) { bb_error_msg("malformed packet received from %s", p->p_dotted); return; } if (msg.m_orgtime.int_partl != p->p_xmt_msg.m_xmttime.int_partl || msg.m_orgtime.fractionl != p->p_xmt_msg.m_xmttime.fractionl ) { /* Somebody else's packet */ return; } /* We do not expect any more packets from this peer for now. * Closing the socket informs kernel about it. * We open a new socket when we send a new query. */ close(p->p_fd); p->p_fd = -1; if ((msg.m_status & LI_ALARM) == LI_ALARM || msg.m_stratum == 0 || msg.m_stratum > NTP_MAXSTRATUM ) { bb_error_msg("reply from %s: peer is unsynced", p->p_dotted); /* * Stratum 0 responses may have commands in 32-bit m_refid field: * "DENY", "RSTR" - peer does not like us at all, * "RATE" - peer is overloaded, reduce polling freq. * If poll interval is small, increase it. */ if (G.poll_exp < BIGPOLL) goto increase_interval; goto pick_normal_interval; } /* * From RFC 2030 (with a correction to the delay math): * * Timestamp Name ID When Generated * ------------------------------------------------------------ * Originate Timestamp T1 time request sent by client * Receive Timestamp T2 time request received by server * Transmit Timestamp T3 time reply sent by server * Destination Timestamp T4 time reply received by client * * The roundtrip delay and local clock offset are defined as * * delay = (T4 - T1) - (T3 - T2); offset = ((T2 - T1) + (T3 - T4)) / 2 */ T1 = p->p_xmttime; T2 = lfp_to_d(msg.m_rectime); T3 = lfp_to_d(msg.m_xmttime); T4 = G.cur_time; /* The delay calculation is a special case. In cases where the * server and client clocks are running at different rates and * with very fast networks, the delay can appear negative. In * order to avoid violating the Principle of Least Astonishment, * the delay is clamped not less than the system precision. */ delay = (T4 - T1) - (T3 - T2); if (delay < G_precision_sec) delay = G_precision_sec; /* * If this packet's delay is much bigger than the last one, * it's better to just ignore it than use its much less precise value. */ prev_delay = p->p_raw_delay; p->p_raw_delay = delay; if (p->reachable_bits && delay > prev_delay * BAD_DELAY_GROWTH) { bb_error_msg("reply from %s: delay %f is too high, ignoring", p->p_dotted, delay); goto pick_normal_interval; } p->lastpkt_delay = delay; p->lastpkt_recv_time = T4; VERB6 bb_error_msg("%s->lastpkt_recv_time=%f", p->p_dotted, p->lastpkt_recv_time); p->lastpkt_status = msg.m_status; p->lastpkt_stratum = msg.m_stratum; p->lastpkt_rootdelay = sfp_to_d(msg.m_rootdelay); p->lastpkt_rootdisp = sfp_to_d(msg.m_rootdisp); p->lastpkt_refid = msg.m_refid; p->datapoint_idx = p->reachable_bits ? (p->datapoint_idx + 1) % NUM_DATAPOINTS : 0; datapoint = &p->filter_datapoint[p->datapoint_idx]; datapoint->d_recv_time = T4; datapoint->d_offset = offset = ((T2 - T1) + (T3 - T4)) / 2; datapoint->d_dispersion = LOG2D(msg.m_precision_exp) + G_precision_sec; if (!p->reachable_bits) { /* 1st datapoint ever - replicate offset in every element */ int i; for (i = 0; i < NUM_DATAPOINTS; i++) { p->filter_datapoint[i].d_offset = offset; } } p->reachable_bits |= 1; if ((MAX_VERBOSE && G.verbose) || (option_mask32 & OPT_w)) { bb_error_msg("reply from %s: offset:%+f delay:%f status:0x%02x strat:%d refid:0x%08x rootdelay:%f reach:0x%02x", p->p_dotted, offset, p->lastpkt_delay, p->lastpkt_status, p->lastpkt_stratum, p->lastpkt_refid, p->lastpkt_rootdelay, p->reachable_bits /* not shown: m_ppoll, m_precision_exp, m_rootdisp, * m_reftime, m_orgtime, m_rectime, m_xmttime */ ); } /* Muck with statictics and update the clock */ filter_datapoints(p); q = select_and_cluster(); rc = 0; if (q) { if (!(option_mask32 & OPT_w)) { rc = update_local_clock(q); #if 0 /* If drift is dangerously large, immediately * drop poll interval one step down. */ if (fabs(q->filter_offset) >= POLLDOWN_OFFSET) { VERB4 bb_error_msg("offset:%+f > POLLDOWN_OFFSET", q->filter_offset); adjust_poll(-POLLADJ_LIMIT * 3); rc = 0; } #endif } } else { /* No peer selected. * If poll interval is small, increase it. */ if (G.poll_exp < BIGPOLL) goto increase_interval; } if (rc != 0) { /* Adjust the poll interval by comparing the current offset * with the clock jitter. If the offset is less than * the clock jitter times a constant, then the averaging interval * is increased, otherwise it is decreased. A bit of hysteresis * helps calm the dance. Works best using burst mode. */ if (rc > 0 && G.offset_to_jitter_ratio <= POLLADJ_GATE) { /* was += G.poll_exp but it is a bit * too optimistic for my taste at high poll_exp's */ increase_interval: adjust_poll(MINPOLL); } else { VERB3 if (rc > 0) bb_error_msg("want smaller interval: offset/jitter = %u", G.offset_to_jitter_ratio); adjust_poll(-G.poll_exp * 2); } } /* Decide when to send new query for this peer */ pick_normal_interval: interval = poll_interval(INT_MAX); if (fabs(offset) >= BIGOFF && interval > BIGOFF_INTERVAL) { /* If we are synced, offsets are less than SLEW_THRESHOLD, * or at the very least not much larger than it. * Now we see a largish one. * Either this peer is feeling bad, or packet got corrupted, * or _our_ clock is wrong now and _all_ peers will show similar * largish offsets too. * I observed this with laptop suspend stopping clock. * In any case, it makes sense to make next request soonish: * cases 1 and 2: get a better datapoint, * case 3: allows to resync faster. */ interval = BIGOFF_INTERVAL; } set_next(p, interval); }
CWE-399
9,498
16,449
329175640069111594752752529443417387517
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
reset_peer_stats(peer_t *p, double offset) { int i; bool small_ofs = fabs(offset) < STEP_THRESHOLD; /* Used to set p->filter_datapoint[i].d_dispersion = MAXDISP * and clear reachable bits, but this proved to be too agressive: * after step (tested with suspending laptop for ~30 secs), * this caused all previous data to be considered invalid, * making us needing to collect full ~8 datapoins per peer * after step in order to start trusting them. * In turn, this was making poll interval decrease even after * step was done. (Poll interval decreases already before step * in this scenario, because we see large offsets and end up with * no good peer to select). */ for (i = 0; i < NUM_DATAPOINTS; i++) { if (small_ofs) { p->filter_datapoint[i].d_recv_time += offset; if (p->filter_datapoint[i].d_offset != 0) { p->filter_datapoint[i].d_offset -= offset; } } else { p->filter_datapoint[i].d_recv_time = G.cur_time; p->filter_datapoint[i].d_offset = 0; /*p->filter_datapoint[i].d_dispersion = MAXDISP;*/ } } if (small_ofs) { p->lastpkt_recv_time += offset; } else { /*p->reachable_bits = 0;*/ p->lastpkt_recv_time = G.cur_time; } filter_datapoints(p); /* recalc p->filter_xxx */ VERB6 bb_error_msg("%s->lastpkt_recv_time=%f", p->p_dotted, p->lastpkt_recv_time); }
CWE-399
9,499
16,450
137243100997537645453710939513918360045
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
resolve_peer_hostname(peer_t *p, int loop_on_fail) { len_and_sockaddr *lsa; again: lsa = host2sockaddr(p->p_hostname, 123); if (!lsa) { /* error message already emitted by host2sockaddr() */ if (!loop_on_fail) return; sleep(5); goto again; } free(p->p_lsa); free(p->p_dotted); p->p_lsa = lsa; p->p_dotted = xmalloc_sockaddr2dotted_noport(&lsa->u.sa); }
CWE-399
9,500
16,451
97386976363357319353858636380103409595
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
root_distance(peer_t *p) { /* The root synchronization distance is the maximum error due to * all causes of the local clock relative to the primary server. * It is defined as half the total delay plus total dispersion * plus peer jitter. */ return MAXD(MINDISP, p->lastpkt_rootdelay + p->lastpkt_delay) / 2 + p->lastpkt_rootdisp + p->filter_dispersion + FREQ_TOLERANCE * (G.cur_time - p->lastpkt_recv_time) + p->filter_jitter; }
CWE-399
9,501
16,452
240728064016572659268479668553419402689
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
static void run_script(const char *action, double offset) { char *argv[3]; char *env1, *env2, *env3, *env4; G.last_script_run = G.cur_time; if (!G.script_name) return; argv[0] = (char*) G.script_name; argv[1] = (char*) action; argv[2] = NULL; VERB1 bb_error_msg("executing '%s %s'", G.script_name, action); env1 = xasprintf("%s=%u", "stratum", G.stratum); putenv(env1); env2 = xasprintf("%s=%ld", "freq_drift_ppm", G.kernel_freq_drift); putenv(env2); env3 = xasprintf("%s=%u", "poll_interval", 1 << G.poll_exp); putenv(env3); env4 = xasprintf("%s=%f", "offset", offset); putenv(env4); /* Other items of potential interest: selected peer, * rootdelay, reftime, rootdisp, refid, ntp_status, * last_update_offset, last_update_recv_time, discipline_jitter, * how many peers have reachable_bits = 0? */ /* Don't want to wait: it may run hwclock --systohc, and that * may take some time (seconds): */ /*spawn_and_wait(argv);*/ spawn(argv); unsetenv("stratum"); unsetenv("freq_drift_ppm"); unsetenv("poll_interval"); unsetenv("offset"); free(env1); free(env2); free(env3); free(env4); }
CWE-399
9,502
16,453
46671045651261026128420200411959622793
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
select_and_cluster(void) { peer_t *p; llist_t *item; int i, j; int size = 3 * G.peer_cnt; /* for selection algorithm */ point_t point[size]; unsigned num_points, num_candidates; double low, high; unsigned num_falsetickers; /* for cluster algorithm */ survivor_t survivor[size]; unsigned num_survivors; /* Selection */ num_points = 0; item = G.ntp_peers; while (item != NULL) { double rd, offset; p = (peer_t *) item->data; rd = root_distance(p); offset = p->filter_offset; if (!fit(p, rd)) { item = item->link; continue; } VERB5 bb_error_msg("interval: [%f %f %f] %s", offset - rd, offset, offset + rd, p->p_dotted ); point[num_points].p = p; point[num_points].type = -1; point[num_points].edge = offset - rd; point[num_points].opt_rd = rd; num_points++; point[num_points].p = p; point[num_points].type = 0; point[num_points].edge = offset; point[num_points].opt_rd = rd; num_points++; point[num_points].p = p; point[num_points].type = 1; point[num_points].edge = offset + rd; point[num_points].opt_rd = rd; num_points++; item = item->link; } num_candidates = num_points / 3; if (num_candidates == 0) { VERB3 bb_error_msg("no valid datapoints%s", ", no peer selected"); return NULL; } qsort(point, num_points, sizeof(point[0]), compare_point_edge); /* Start with the assumption that there are no falsetickers. * Attempt to find a nonempty intersection interval containing * the midpoints of all truechimers. * If a nonempty interval cannot be found, increase the number * of assumed falsetickers by one and try again. * If a nonempty interval is found and the number of falsetickers * is less than the number of truechimers, a majority has been found * and the midpoint of each truechimer represents * the candidates available to the cluster algorithm. */ num_falsetickers = 0; while (1) { int c; unsigned num_midpoints = 0; low = 1 << 9; high = - (1 << 9); c = 0; for (i = 0; i < num_points; i++) { /* We want to do: * if (point[i].type == -1) c++; * if (point[i].type == 1) c--; * and it's simpler to do it this way: */ c -= point[i].type; if (c >= num_candidates - num_falsetickers) { /* If it was c++ and it got big enough... */ low = point[i].edge; break; } if (point[i].type == 0) num_midpoints++; } c = 0; for (i = num_points-1; i >= 0; i--) { c += point[i].type; if (c >= num_candidates - num_falsetickers) { high = point[i].edge; break; } if (point[i].type == 0) num_midpoints++; } /* If the number of midpoints is greater than the number * of allowed falsetickers, the intersection contains at * least one truechimer with no midpoint - bad. * Also, interval should be nonempty. */ if (num_midpoints <= num_falsetickers && low < high) break; num_falsetickers++; if (num_falsetickers * 2 >= num_candidates) { VERB3 bb_error_msg("falsetickers:%d, candidates:%d%s", num_falsetickers, num_candidates, ", no peer selected"); return NULL; } } VERB4 bb_error_msg("selected interval: [%f, %f]; candidates:%d falsetickers:%d", low, high, num_candidates, num_falsetickers); /* Clustering */ /* Construct a list of survivors (p, metric) * from the chime list, where metric is dominated * first by stratum and then by root distance. * All other things being equal, this is the order of preference. */ num_survivors = 0; for (i = 0; i < num_points; i++) { if (point[i].edge < low || point[i].edge > high) continue; p = point[i].p; survivor[num_survivors].p = p; /* x.opt_rd == root_distance(p); */ survivor[num_survivors].metric = MAXDIST * p->lastpkt_stratum + point[i].opt_rd; VERB5 bb_error_msg("survivor[%d] metric:%f peer:%s", num_survivors, survivor[num_survivors].metric, p->p_dotted); num_survivors++; } /* There must be at least MIN_SELECTED survivors to satisfy the * correctness assertions. Ordinarily, the Byzantine criteria * require four survivors, but for the demonstration here, one * is acceptable. */ if (num_survivors < MIN_SELECTED) { VERB3 bb_error_msg("survivors:%d%s", num_survivors, ", no peer selected"); return NULL; } qsort(survivor, num_survivors, sizeof(survivor[0]), compare_survivor_metric); /* For each association p in turn, calculate the selection * jitter p->sjitter as the square root of the sum of squares * (p->offset - q->offset) over all q associations. The idea is * to repeatedly discard the survivor with maximum selection * jitter until a termination condition is met. */ while (1) { unsigned max_idx = max_idx; double max_selection_jitter = max_selection_jitter; double min_jitter = min_jitter; if (num_survivors <= MIN_CLUSTERED) { VERB4 bb_error_msg("num_survivors %d <= %d, not discarding more", num_survivors, MIN_CLUSTERED); break; } /* To make sure a few survivors are left * for the clustering algorithm to chew on, * we stop if the number of survivors * is less than or equal to MIN_CLUSTERED (3). */ for (i = 0; i < num_survivors; i++) { double selection_jitter_sq; p = survivor[i].p; if (i == 0 || p->filter_jitter < min_jitter) min_jitter = p->filter_jitter; selection_jitter_sq = 0; for (j = 0; j < num_survivors; j++) { peer_t *q = survivor[j].p; selection_jitter_sq += SQUARE(p->filter_offset - q->filter_offset); } if (i == 0 || selection_jitter_sq > max_selection_jitter) { max_selection_jitter = selection_jitter_sq; max_idx = i; } VERB6 bb_error_msg("survivor %d selection_jitter^2:%f", i, selection_jitter_sq); } max_selection_jitter = SQRT(max_selection_jitter / num_survivors); VERB5 bb_error_msg("max_selection_jitter (at %d):%f min_jitter:%f", max_idx, max_selection_jitter, min_jitter); /* If the maximum selection jitter is less than the * minimum peer jitter, then tossing out more survivors * will not lower the minimum peer jitter, so we might * as well stop. */ if (max_selection_jitter < min_jitter) { VERB4 bb_error_msg("max_selection_jitter:%f < min_jitter:%f, num_survivors:%d, not discarding more", max_selection_jitter, min_jitter, num_survivors); break; } /* Delete survivor[max_idx] from the list * and go around again. */ VERB6 bb_error_msg("dropping survivor %d", max_idx); num_survivors--; while (max_idx < num_survivors) { survivor[max_idx] = survivor[max_idx + 1]; max_idx++; } } if (0) { /* Combine the offsets of the clustering algorithm survivors * using a weighted average with weight determined by the root * distance. Compute the selection jitter as the weighted RMS * difference between the first survivor and the remaining * survivors. In some cases the inherent clock jitter can be * reduced by not using this algorithm, especially when frequent * clockhopping is involved. bbox: thus we don't do it. */ double x, y, z, w; y = z = w = 0; for (i = 0; i < num_survivors; i++) { p = survivor[i].p; x = root_distance(p); y += 1 / x; z += p->filter_offset / x; w += SQUARE(p->filter_offset - survivor[0].p->filter_offset) / x; } } /* Pick the best clock. If the old system peer is on the list * and at the same stratum as the first survivor on the list, * then don't do a clock hop. Otherwise, select the first * survivor on the list as the new system peer. */ p = survivor[0].p; if (G.last_update_peer && G.last_update_peer->lastpkt_stratum <= p->lastpkt_stratum ) { /* Starting from 1 is ok here */ for (i = 1; i < num_survivors; i++) { if (G.last_update_peer == survivor[i].p) { VERB5 bb_error_msg("keeping old synced peer"); p = G.last_update_peer; goto keep_old; } } } G.last_update_peer = p; keep_old: VERB4 bb_error_msg("selected peer %s filter_offset:%+f age:%f", p->p_dotted, p->filter_offset, G.cur_time - p->lastpkt_recv_time ); return p; }
CWE-399
9,503
16,454
176742158190223113819961636187958143098
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
send_query_to_peer(peer_t *p) { /* Why do we need to bind()? * See what happens when we don't bind: * * socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 3 * setsockopt(3, SOL_IP, IP_TOS, [16], 4) = 0 * gettimeofday({1259071266, 327885}, NULL) = 0 * sendto(3, "xxx", 48, MSG_DONTWAIT, {sa_family=AF_INET, sin_port=htons(123), sin_addr=inet_addr("10.34.32.125")}, 16) = 48 * ^^^ we sent it from some source port picked by kernel. * time(NULL) = 1259071266 * write(2, "ntpd: entering poll 15 secs\n", 28) = 28 * poll([{fd=3, events=POLLIN}], 1, 15000) = 1 ([{fd=3, revents=POLLIN}]) * recv(3, "yyy", 68, MSG_DONTWAIT) = 48 * ^^^ this recv will receive packets to any local port! * * Uncomment this and use strace to see it in action: */ #define PROBE_LOCAL_ADDR /* { len_and_sockaddr lsa; lsa.len = LSA_SIZEOF_SA; getsockname(p->query.fd, &lsa.u.sa, &lsa.len); } */ if (p->p_fd == -1) { int fd, family; len_and_sockaddr *local_lsa; family = p->p_lsa->u.sa.sa_family; p->p_fd = fd = xsocket_type(&local_lsa, family, SOCK_DGRAM); /* local_lsa has "null" address and port 0 now. * bind() ensures we have a *particular port* selected by kernel * and remembered in p->p_fd, thus later recv(p->p_fd) * receives only packets sent to this port. */ PROBE_LOCAL_ADDR xbind(fd, &local_lsa->u.sa, local_lsa->len); PROBE_LOCAL_ADDR #if ENABLE_FEATURE_IPV6 if (family == AF_INET) #endif setsockopt_int(fd, IPPROTO_IP, IP_TOS, IPTOS_LOWDELAY); free(local_lsa); } /* Emit message _before_ attempted send. Think of a very short * roundtrip networks: we need to go back to recv loop ASAP, * to reduce delay. Printing messages after send works against that. */ VERB1 bb_error_msg("sending query to %s", p->p_dotted); /* * Send out a random 64-bit number as our transmit time. The NTP * server will copy said number into the originate field on the * response that it sends us. This is totally legal per the SNTP spec. * * The impact of this is two fold: we no longer send out the current * system time for the world to see (which may aid an attacker), and * it gives us a (not very secure) way of knowing that we're not * getting spoofed by an attacker that can't capture our traffic * but can spoof packets from the NTP server we're communicating with. * * Save the real transmit timestamp locally. */ p->p_xmt_msg.m_xmttime.int_partl = rand(); p->p_xmt_msg.m_xmttime.fractionl = rand(); p->p_xmttime = gettime1900d(); /* Were doing it only if sendto worked, but * loss of sync detection needs reachable_bits updated * even if sending fails *locally*: * "network is unreachable" because cable was pulled? * We still need to declare "unsync" if this condition persists. */ p->reachable_bits <<= 1; if (do_sendto(p->p_fd, /*from:*/ NULL, /*to:*/ &p->p_lsa->u.sa, /*addrlen:*/ p->p_lsa->len, &p->p_xmt_msg, NTP_MSGSIZE_NOAUTH) == -1 ) { close(p->p_fd); p->p_fd = -1; /* * We know that we sent nothing. * We can retry *soon* without fearing * that we are flooding the peer. */ set_next(p, RETRY_INTERVAL); return; } set_next(p, RESPONSE_INTERVAL); }
CWE-399
9,504
16,455
120107411742487538522478365011335490294
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
set_new_values(int disc_state, double offset, double recv_time) { /* Enter new state and set state variables. Note we use the time * of the last clock filter sample, which must be earlier than * the current time. */ VERB4 bb_error_msg("disc_state=%d last update offset=%f recv_time=%f", disc_state, offset, recv_time); G.discipline_state = disc_state; G.last_update_offset = offset; G.last_update_recv_time = recv_time; }
CWE-399
9,505
16,456
123735069645509022324789047759990730512
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
set_next(peer_t *p, unsigned t) { p->next_action_time = G.cur_time + t; }
CWE-399
9,506
16,457
226233107316426541761248807255750666693
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
sfp_to_d(s_fixedpt_t sfp) { double ret; sfp.int_parts = ntohs(sfp.int_parts); sfp.fractions = ntohs(sfp.fractions); ret = (double)sfp.int_parts + ((double)sfp.fractions / USHRT_MAX); return ret; }
CWE-399
9,507
16,458
30879514112349002960984149951674550248
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
step_time(double offset) { llist_t *item; double dtime; struct timeval tvc, tvn; char buf[sizeof("yyyy-mm-dd hh:mm:ss") + /*paranoia:*/ 4]; time_t tval; gettimeofday(&tvc, NULL); /* never fails */ dtime = tvc.tv_sec + (1.0e-6 * tvc.tv_usec) + offset; d_to_tv(dtime, &tvn); if (settimeofday(&tvn, NULL) == -1) bb_perror_msg_and_die("settimeofday"); VERB2 { tval = tvc.tv_sec; strftime_YYYYMMDDHHMMSS(buf, sizeof(buf), &tval); bb_error_msg("current time is %s.%06u", buf, (unsigned)tvc.tv_usec); } tval = tvn.tv_sec; strftime_YYYYMMDDHHMMSS(buf, sizeof(buf), &tval); bb_error_msg("setting time to %s.%06u (offset %+fs)", buf, (unsigned)tvn.tv_usec, offset); /* Correct various fields which contain time-relative values: */ /* Globals: */ G.cur_time += offset; G.last_update_recv_time += offset; G.last_script_run += offset; /* p->lastpkt_recv_time, p->next_action_time and such: */ for (item = G.ntp_peers; item != NULL; item = item->link) { peer_t *pp = (peer_t *) item->data; reset_peer_stats(pp, offset); pp->next_action_time += offset; if (pp->p_fd >= 0) { /* We wait for reply from this peer too. * But due to step we are doing, reply's data is no longer * useful (in fact, it'll be bogus). Stop waiting for it. */ close(pp->p_fd); pp->p_fd = -1; set_next(pp, RETRY_INTERVAL); } } }
CWE-399
9,508
16,459
237158062973360354573430765298950911303
null
null
null
busybox
150dc7a2b483b8338a3e185c478b4b23ee884e71
0
update_local_clock(peer_t *p) { int rc; struct timex tmx; /* Note: can use G.cluster_offset instead: */ double offset = p->filter_offset; double recv_time = p->lastpkt_recv_time; double abs_offset; #if !USING_KERNEL_PLL_LOOP double freq_drift; #endif #if !USING_KERNEL_PLL_LOOP || USING_INITIAL_FREQ_ESTIMATION double since_last_update; #endif double etemp, dtemp; abs_offset = fabs(offset); #if 0 /* If needed, -S script can do it by looking at $offset * env var and killing parent */ /* If the offset is too large, give up and go home */ if (abs_offset > PANIC_THRESHOLD) { bb_error_msg_and_die("offset %f far too big, exiting", offset); } #endif /* If this is an old update, for instance as the result * of a system peer change, avoid it. We never use * an old sample or the same sample twice. */ if (recv_time <= G.last_update_recv_time) { VERB3 bb_error_msg("update from %s: same or older datapoint, not using it", p->p_dotted); return 0; /* "leave poll interval as is" */ } /* Clock state machine transition function. This is where the * action is and defines how the system reacts to large time * and frequency errors. */ #if !USING_KERNEL_PLL_LOOP || USING_INITIAL_FREQ_ESTIMATION since_last_update = recv_time - G.reftime; #endif #if !USING_KERNEL_PLL_LOOP freq_drift = 0; #endif #if USING_INITIAL_FREQ_ESTIMATION if (G.discipline_state == STATE_FREQ) { /* Ignore updates until the stepout threshold */ if (since_last_update < WATCH_THRESHOLD) { VERB4 bb_error_msg("measuring drift, datapoint ignored, %f sec remains", WATCH_THRESHOLD - since_last_update); return 0; /* "leave poll interval as is" */ } # if !USING_KERNEL_PLL_LOOP freq_drift = (offset - G.last_update_offset) / since_last_update; # endif } #endif /* There are two main regimes: when the * offset exceeds the step threshold and when it does not. */ if (abs_offset > STEP_THRESHOLD) { #if 0 double remains; switch (G.discipline_state) { case STATE_SYNC: /* The first outlyer: ignore it, switch to SPIK state */ VERB3 bb_error_msg("update from %s: offset:%+f, spike%s", p->p_dotted, offset, ""); G.discipline_state = STATE_SPIK; return -1; /* "decrease poll interval" */ case STATE_SPIK: /* Ignore succeeding outlyers until either an inlyer * is found or the stepout threshold is exceeded. */ remains = WATCH_THRESHOLD - since_last_update; if (remains > 0) { VERB3 bb_error_msg("update from %s: offset:%+f, spike%s", p->p_dotted, offset, ", datapoint ignored"); return -1; /* "decrease poll interval" */ } /* fall through: we need to step */ } /* switch */ #endif /* Step the time and clamp down the poll interval. * * In NSET state an initial frequency correction is * not available, usually because the frequency file has * not yet been written. Since the time is outside the * capture range, the clock is stepped. The frequency * will be set directly following the stepout interval. * * In FSET state the initial frequency has been set * from the frequency file. Since the time is outside * the capture range, the clock is stepped immediately, * rather than after the stepout interval. Guys get * nervous if it takes 17 minutes to set the clock for * the first time. * * In SPIK state the stepout threshold has expired and * the phase is still above the step threshold. Note * that a single spike greater than the step threshold * is always suppressed, even at the longer poll * intervals. */ VERB4 bb_error_msg("stepping time by %+f; poll_exp=MINPOLL", offset); step_time(offset); if (option_mask32 & OPT_q) { /* We were only asked to set time once. Done. */ exit(0); } clamp_pollexp_and_set_MAXSTRAT(); run_script("step", offset); recv_time += offset; #if USING_INITIAL_FREQ_ESTIMATION if (G.discipline_state == STATE_NSET) { set_new_values(STATE_FREQ, /*offset:*/ 0, recv_time); return 1; /* "ok to increase poll interval" */ } #endif abs_offset = offset = 0; set_new_values(STATE_SYNC, offset, recv_time); } else { /* abs_offset <= STEP_THRESHOLD */ /* The ratio is calculated before jitter is updated to make * poll adjust code more sensitive to large offsets. */ G.offset_to_jitter_ratio = abs_offset / G.discipline_jitter; /* Compute the clock jitter as the RMS of exponentially * weighted offset differences. Used by the poll adjust code. */ etemp = SQUARE(G.discipline_jitter); dtemp = SQUARE(offset - G.last_update_offset); G.discipline_jitter = SQRT(etemp + (dtemp - etemp) / AVG); if (G.discipline_jitter < G_precision_sec) G.discipline_jitter = G_precision_sec; switch (G.discipline_state) { case STATE_NSET: if (option_mask32 & OPT_q) { /* We were only asked to set time once. * The clock is precise enough, no need to step. */ exit(0); } #if USING_INITIAL_FREQ_ESTIMATION /* This is the first update received and the frequency * has not been initialized. The first thing to do * is directly measure the oscillator frequency. */ set_new_values(STATE_FREQ, offset, recv_time); #else set_new_values(STATE_SYNC, offset, recv_time); #endif VERB4 bb_error_msg("transitioning to FREQ, datapoint ignored"); return 0; /* "leave poll interval as is" */ #if 0 /* this is dead code for now */ case STATE_FSET: /* This is the first update and the frequency * has been initialized. Adjust the phase, but * don't adjust the frequency until the next update. */ set_new_values(STATE_SYNC, offset, recv_time); /* freq_drift remains 0 */ break; #endif #if USING_INITIAL_FREQ_ESTIMATION case STATE_FREQ: /* since_last_update >= WATCH_THRESHOLD, we waited enough. * Correct the phase and frequency and switch to SYNC state. * freq_drift was already estimated (see code above) */ set_new_values(STATE_SYNC, offset, recv_time); break; #endif default: #if !USING_KERNEL_PLL_LOOP /* Compute freq_drift due to PLL and FLL contributions. * * The FLL and PLL frequency gain constants * depend on the poll interval and Allan * intercept. The FLL is not used below one-half * the Allan intercept. Above that the loop gain * increases in steps to 1 / AVG. */ if ((1 << G.poll_exp) > ALLAN / 2) { etemp = FLL - G.poll_exp; if (etemp < AVG) etemp = AVG; freq_drift += (offset - G.last_update_offset) / (MAXD(since_last_update, ALLAN) * etemp); } /* For the PLL the integration interval * (numerator) is the minimum of the update * interval and poll interval. This allows * oversampling, but not undersampling. */ etemp = MIND(since_last_update, (1 << G.poll_exp)); dtemp = (4 * PLL) << G.poll_exp; freq_drift += offset * etemp / SQUARE(dtemp); #endif set_new_values(STATE_SYNC, offset, recv_time); break; } if (G.stratum != p->lastpkt_stratum + 1) { G.stratum = p->lastpkt_stratum + 1; run_script("stratum", offset); } } G.reftime = G.cur_time; G.ntp_status = p->lastpkt_status; G.refid = p->lastpkt_refid; G.rootdelay = p->lastpkt_rootdelay + p->lastpkt_delay; dtemp = p->filter_jitter; // SQRT(SQUARE(p->filter_jitter) + SQUARE(G.cluster_jitter)); dtemp += MAXD(p->filter_dispersion + FREQ_TOLERANCE * (G.cur_time - p->lastpkt_recv_time) + abs_offset, MINDISP); G.rootdisp = p->lastpkt_rootdisp + dtemp; VERB4 bb_error_msg("updating leap/refid/reftime/rootdisp from peer %s", p->p_dotted); /* We are in STATE_SYNC now, but did not do adjtimex yet. * (Any other state does not reach this, they all return earlier) * By this time, freq_drift and offset are set * to values suitable for adjtimex. */ #if !USING_KERNEL_PLL_LOOP /* Calculate the new frequency drift and frequency stability (wander). * Compute the clock wander as the RMS of exponentially weighted * frequency differences. This is not used directly, but can, * along with the jitter, be a highly useful monitoring and * debugging tool. */ dtemp = G.discipline_freq_drift + freq_drift; G.discipline_freq_drift = MAXD(MIND(MAXDRIFT, dtemp), -MAXDRIFT); etemp = SQUARE(G.discipline_wander); dtemp = SQUARE(dtemp); G.discipline_wander = SQRT(etemp + (dtemp - etemp) / AVG); VERB4 bb_error_msg("discipline freq_drift=%.9f(int:%ld corr:%e) wander=%f", G.discipline_freq_drift, (long)(G.discipline_freq_drift * 65536e6), freq_drift, G.discipline_wander); #endif VERB4 { memset(&tmx, 0, sizeof(tmx)); if (adjtimex(&tmx) < 0) bb_perror_msg_and_die("adjtimex"); bb_error_msg("p adjtimex freq:%ld offset:%+ld status:0x%x tc:%ld", tmx.freq, tmx.offset, tmx.status, tmx.constant); } memset(&tmx, 0, sizeof(tmx)); #if 0 tmx.modes = ADJ_FREQUENCY | ADJ_OFFSET; /* 65536 is one ppm */ tmx.freq = G.discipline_freq_drift * 65536e6; #endif tmx.modes = ADJ_OFFSET | ADJ_STATUS | ADJ_TIMECONST;// | ADJ_MAXERROR | ADJ_ESTERROR; tmx.constant = (int)G.poll_exp - 4; /* EXPERIMENTAL. * The below if statement should be unnecessary, but... * It looks like Linux kernel's PLL is far too gentle in changing * tmx.freq in response to clock offset. Offset keeps growing * and eventually we fall back to smaller poll intervals. * We can make correction more agressive (about x2) by supplying * PLL time constant which is one less than the real one. * To be on a safe side, let's do it only if offset is significantly * larger than jitter. */ if (G.offset_to_jitter_ratio >= TIMECONST_HACK_GATE) tmx.constant--; tmx.offset = (long)(offset * 1000000); /* usec */ if (SLEW_THRESHOLD < STEP_THRESHOLD) { if (tmx.offset > (long)(SLEW_THRESHOLD * 1000000)) { tmx.offset = (long)(SLEW_THRESHOLD * 1000000); tmx.constant--; } if (tmx.offset < -(long)(SLEW_THRESHOLD * 1000000)) { tmx.offset = -(long)(SLEW_THRESHOLD * 1000000); tmx.constant--; } } if (tmx.constant < 0) tmx.constant = 0; tmx.status = STA_PLL; if (G.ntp_status & LI_PLUSSEC) tmx.status |= STA_INS; if (G.ntp_status & LI_MINUSSEC) tmx.status |= STA_DEL; rc = adjtimex(&tmx); if (rc < 0) bb_perror_msg_and_die("adjtimex"); /* NB: here kernel returns constant == G.poll_exp, not == G.poll_exp - 4. * Not sure why. Perhaps it is normal. */ VERB4 bb_error_msg("adjtimex:%d freq:%ld offset:%+ld status:0x%x", rc, tmx.freq, tmx.offset, tmx.status); G.kernel_freq_drift = tmx.freq / 65536; VERB2 bb_error_msg("update from:%s offset:%+f delay:%f jitter:%f clock drift:%+.3fppm tc:%d", p->p_dotted, offset, p->lastpkt_delay, G.discipline_jitter, (double)tmx.freq / 65536, (int)tmx.constant ); return 1; /* "ok to increase poll interval" */ }
CWE-399
9,509
16,460
271633643077713935882442198969145489728
null
null
null
savannah
1fbee57ef3c72db2206dd87e4162108b2f425555
0
stringprep_utf8_to_ucs4 (const char *str, ssize_t len, size_t * items_written) { size_t n; if (len < 0) n = strlen (str); else n = len; if (u8_check ((const uint8_t *) str, n)) return NULL; return g_utf8_to_ucs4_fast (str, (glong) len, (glong *) items_written); }
CWE-125
9,672
16,461
307570862487308839915548627019690414206
null
null
null
savannah
5e3cb9c7b5bf0ce665b9d68f5ddf095af5c9ba60
0
usage (int status) { if (status != EXIT_SUCCESS) fprintf (stderr, _("Try `%s --help' for more information.\n"), program_name); else { printf (_("\ Usage: %s [OPTION]... [STRINGS]...\n\ "), program_name); fputs (_("\ Internationalized Domain Name (IDN) convert STRINGS, or standard input.\n\ \n\ "), stdout); fputs (_("\ Command line interface to the internationalized domain name library.\n\ \n\ All strings are expected to be encoded in the preferred charset used\n\ by your locale. Use `--debug' to find out what this charset is. You\n\ can override the charset used by setting environment variable CHARSET.\n\ \n\ To process a string that starts with `-', for example `-foo', use `--'\n\ to signal the end of parameters, as in `idn --quiet -a -- -foo'.\n\ \n\ Mandatory arguments to long options are mandatory for short options too.\n\ "), stdout); fputs (_("\ -h, --help Print help and exit\n\ -V, --version Print version and exit\n\ "), stdout); fputs (_("\ -s, --stringprep Prepare string according to nameprep profile\n\ -d, --punycode-decode Decode Punycode\n\ -e, --punycode-encode Encode Punycode\n\ -a, --idna-to-ascii Convert to ACE according to IDNA (default mode)\n\ -u, --idna-to-unicode Convert from ACE according to IDNA\n\ "), stdout); fputs (_("\ --allow-unassigned Toggle IDNA AllowUnassigned flag (default off)\n\ --usestd3asciirules Toggle IDNA UseSTD3ASCIIRules flag (default off)\n\ "), stdout); fputs (_("\ --no-tld Don't check string for TLD specific rules\n\ Only for --idna-to-ascii and --idna-to-unicode\n\ "), stdout); fputs (_("\ -n, --nfkc Normalize string according to Unicode v3.2 NFKC\n\ "), stdout); fputs (_("\ -p, --profile=STRING Use specified stringprep profile instead\n\ Valid stringprep profiles: `Nameprep',\n\ `iSCSI', `Nodeprep', `Resourceprep', \n\ `trace', `SASLprep'\n\ "), stdout); fputs (_("\ --debug Print debugging information\n\ --quiet Silent operation\n\ "), stdout); emit_bug_reporting_address (); } exit (status); }
CWE-125
9,673
16,462
227533718889209662751767606212683059275
null
null
null
savannah
45a3c76b547511fa9d97aca34b150a0663257375
0
FT_Stream_Close( FT_Stream stream ) { if ( stream && stream->close ) stream->close( stream ); }
CWE-20
9,694
16,480
192366852316969082957060959754486019229
null
null
null
savannah
45a3c76b547511fa9d97aca34b150a0663257375
0
FT_Stream_ExitFrame( FT_Stream stream ) { /* IMPORTANT: The assertion stream->cursor != 0 was removed, given */ /* that it is possible to access a frame of length 0 in */ /* some weird fonts (usually, when accessing an array of */ /* 0 records, like in some strange kern tables). */ /* */ /* In this case, the loader code handles the 0-length table */ /* gracefully; however, stream.cursor is really set to 0 by the */ /* FT_Stream_EnterFrame() call, and this is not an error. */ /* */ FT_ASSERT( stream ); if ( stream->read ) { FT_Memory memory = stream->memory; #ifdef FT_DEBUG_MEMORY ft_mem_free( memory, stream->base ); stream->base = NULL; #else FT_FREE( stream->base ); #endif } stream->cursor = 0; stream->limit = 0; }
CWE-20
9,695
16,481
307126523087274404657249050491520739096
null
null
null
savannah
45a3c76b547511fa9d97aca34b150a0663257375
0
FT_Stream_ExtractFrame( FT_Stream stream, FT_ULong count, FT_Byte** pbytes ) { FT_Error error; error = FT_Stream_EnterFrame( stream, count ); if ( !error ) { *pbytes = (FT_Byte*)stream->cursor; /* equivalent to FT_Stream_ExitFrame(), with no memory block release */ stream->cursor = 0; stream->limit = 0; } return error; }
CWE-20
9,696
16,482
269167697704639503329234127306665346607
null
null
null
savannah
45a3c76b547511fa9d97aca34b150a0663257375
0
FT_Stream_GetChar( FT_Stream stream ) { FT_Char result; FT_ASSERT( stream && stream->cursor ); result = 0; if ( stream->cursor < stream->limit ) result = *stream->cursor++; return result; }
CWE-20
9,697
16,483
114465557621831875197559423984035860818
null
null
null
savannah
45a3c76b547511fa9d97aca34b150a0663257375
0
FT_Stream_GetLong( FT_Stream stream ) { FT_Byte* p; FT_Long result; FT_ASSERT( stream && stream->cursor ); result = 0; p = stream->cursor; if ( p + 3 < stream->limit ) result = FT_NEXT_LONG( p ); stream->cursor = p; return result; }
CWE-20
9,698
16,484
53281751961871315158373865025385146847
null
null
null
savannah
45a3c76b547511fa9d97aca34b150a0663257375
0
FT_Stream_GetLongLE( FT_Stream stream ) { FT_Byte* p; FT_Long result; FT_ASSERT( stream && stream->cursor ); result = 0; p = stream->cursor; if ( p + 3 < stream->limit ) result = FT_NEXT_LONG_LE( p ); stream->cursor = p; return result; }
CWE-20
9,699
16,485
91222455459814670365345979414147936758
null
null
null
savannah
45a3c76b547511fa9d97aca34b150a0663257375
0
FT_Stream_GetOffset( FT_Stream stream ) { FT_Byte* p; FT_Long result; FT_ASSERT( stream && stream->cursor ); result = 0; p = stream->cursor; if ( p + 2 < stream->limit ) result = FT_NEXT_OFF3( p ); stream->cursor = p; return result; }
CWE-20
9,700
16,486
277946085288578267644905204391100309967
null
null
null
savannah
45a3c76b547511fa9d97aca34b150a0663257375
0
FT_Stream_GetShort( FT_Stream stream ) { FT_Byte* p; FT_Short result; FT_ASSERT( stream && stream->cursor ); result = 0; p = stream->cursor; if ( p + 1 < stream->limit ) result = FT_NEXT_SHORT( p ); stream->cursor = p; return result; }
CWE-20
9,701
16,487
222850100057243449722912074892719814530
null
null
null
savannah
45a3c76b547511fa9d97aca34b150a0663257375
0
FT_Stream_GetShortLE( FT_Stream stream ) { FT_Byte* p; FT_Short result; FT_ASSERT( stream && stream->cursor ); result = 0; p = stream->cursor; if ( p + 1 < stream->limit ) result = FT_NEXT_SHORT_LE( p ); stream->cursor = p; return result; }
CWE-20
9,702
16,488
150275815824746364662447591223102670858
null
null
null
savannah
45a3c76b547511fa9d97aca34b150a0663257375
0
FT_Stream_Pos( FT_Stream stream ) { return stream->pos; }
CWE-20
9,704
16,489
10566939540200563746732985108556577943
null
null
null
savannah
45a3c76b547511fa9d97aca34b150a0663257375
0
FT_Stream_ReadAt( FT_Stream stream, FT_ULong pos, FT_Byte* buffer, FT_ULong count ) { FT_Error error = FT_Err_Ok; FT_ULong read_bytes; if ( pos >= stream->size ) { FT_ERROR(( "FT_Stream_ReadAt:" " invalid i/o; pos = 0x%lx, size = 0x%lx\n", pos, stream->size )); return FT_Err_Invalid_Stream_Operation; } if ( stream->read ) read_bytes = stream->read( stream, pos, buffer, count ); else { read_bytes = stream->size - pos; if ( read_bytes > count ) read_bytes = count; FT_MEM_COPY( buffer, stream->base + pos, read_bytes ); } stream->pos = pos + read_bytes; if ( read_bytes < count ) { FT_ERROR(( "FT_Stream_ReadAt:" " invalid read; expected %lu bytes, got %lu\n", count, read_bytes )); error = FT_Err_Invalid_Stream_Operation; } return error; }
CWE-20
9,705
16,490
203395670452963304752701937196108464214
null
null
null
savannah
45a3c76b547511fa9d97aca34b150a0663257375
0
FT_Stream_ReadChar( FT_Stream stream, FT_Error* error ) { FT_Byte result = 0; FT_ASSERT( stream ); *error = FT_Err_Ok; if ( stream->read ) { if ( stream->read( stream, stream->pos, &result, 1L ) != 1L ) goto Fail; } else { if ( stream->pos < stream->size ) result = stream->base[stream->pos]; else goto Fail; } stream->pos++; return result; Fail: *error = FT_Err_Invalid_Stream_Operation; FT_ERROR(( "FT_Stream_ReadChar:" " invalid i/o; pos = 0x%lx, size = 0x%lx\n", stream->pos, stream->size )); return 0; }
CWE-20
9,706
16,491
247656082135235685159797371277671579524
null
null
null
savannah
45a3c76b547511fa9d97aca34b150a0663257375
0
FT_Stream_ReadFields( FT_Stream stream, const FT_Frame_Field* fields, void* structure ) { FT_Error error; FT_Bool frame_accessed = 0; FT_Byte* cursor; if ( !fields || !stream ) return FT_Err_Invalid_Argument; cursor = stream->cursor; error = FT_Err_Ok; do { FT_ULong value; FT_Int sign_shift; FT_Byte* p; switch ( fields->value ) { case ft_frame_start: /* access a new frame */ error = FT_Stream_EnterFrame( stream, fields->offset ); if ( error ) goto Exit; frame_accessed = 1; cursor = stream->cursor; fields++; continue; /* loop! */ case ft_frame_bytes: /* read a byte sequence */ case ft_frame_skip: /* skip some bytes */ { FT_UInt len = fields->size; if ( cursor + len > stream->limit ) { error = FT_Err_Invalid_Stream_Operation; goto Exit; } if ( fields->value == ft_frame_bytes ) { p = (FT_Byte*)structure + fields->offset; FT_MEM_COPY( p, cursor, len ); } cursor += len; fields++; continue; } case ft_frame_byte: case ft_frame_schar: /* read a single byte */ value = FT_NEXT_BYTE(cursor); sign_shift = 24; break; case ft_frame_short_be: case ft_frame_ushort_be: /* read a 2-byte big-endian short */ value = FT_NEXT_USHORT(cursor); sign_shift = 16; break; case ft_frame_short_le: case ft_frame_ushort_le: /* read a 2-byte little-endian short */ value = FT_NEXT_USHORT_LE(cursor); sign_shift = 16; break; case ft_frame_long_be: case ft_frame_ulong_be: /* read a 4-byte big-endian long */ value = FT_NEXT_ULONG(cursor); sign_shift = 0; break; case ft_frame_long_le: case ft_frame_ulong_le: /* read a 4-byte little-endian long */ value = FT_NEXT_ULONG_LE(cursor); sign_shift = 0; break; case ft_frame_off3_be: case ft_frame_uoff3_be: /* read a 3-byte big-endian long */ value = FT_NEXT_UOFF3(cursor); sign_shift = 8; break; case ft_frame_off3_le: case ft_frame_uoff3_le: /* read a 3-byte little-endian long */ value = FT_NEXT_UOFF3_LE(cursor); sign_shift = 8; break; default: /* otherwise, exit the loop */ stream->cursor = cursor; goto Exit; } /* now, compute the signed value is necessary */ if ( fields->value & FT_FRAME_OP_SIGNED ) value = (FT_ULong)( (FT_Int32)( value << sign_shift ) >> sign_shift ); /* finally, store the value in the object */ p = (FT_Byte*)structure + fields->offset; switch ( fields->size ) { case (8 / FT_CHAR_BIT): *(FT_Byte*)p = (FT_Byte)value; break; case (16 / FT_CHAR_BIT): *(FT_UShort*)p = (FT_UShort)value; break; case (32 / FT_CHAR_BIT): *(FT_UInt32*)p = (FT_UInt32)value; break; default: /* for 64-bit systems */ *(FT_ULong*)p = (FT_ULong)value; } /* go to next field */ fields++; } while ( 1 ); Exit: /* close the frame if it was opened by this read */ if ( frame_accessed ) FT_Stream_ExitFrame( stream ); return error; }
CWE-20
9,707
16,492
238268960763395121028713224104878037574
null
null
null
savannah
45a3c76b547511fa9d97aca34b150a0663257375
0
FT_Stream_ReadLong( FT_Stream stream, FT_Error* error ) { FT_Byte reads[4]; FT_Byte* p = 0; FT_Long result = 0; FT_ASSERT( stream ); *error = FT_Err_Ok; if ( stream->pos + 3 < stream->size ) { if ( stream->read ) { if ( stream->read( stream, stream->pos, reads, 4L ) != 4L ) goto Fail; p = reads; } else { p = stream->base + stream->pos; } if ( p ) result = FT_NEXT_LONG( p ); } else goto Fail; stream->pos += 4; return result; Fail: *error = FT_Err_Invalid_Stream_Operation; FT_ERROR(( "FT_Stream_ReadLong:" " invalid i/o; pos = 0x%lx, size = 0x%lx\n", stream->pos, stream->size )); return 0; }
CWE-20
9,708
16,493
233984915232013972471074566965969322130
null
null
null
savannah
45a3c76b547511fa9d97aca34b150a0663257375
0
FT_Stream_ReadLongLE( FT_Stream stream, FT_Error* error ) { FT_Byte reads[4]; FT_Byte* p = 0; FT_Long result = 0; FT_ASSERT( stream ); *error = FT_Err_Ok; if ( stream->pos + 3 < stream->size ) { if ( stream->read ) { if ( stream->read( stream, stream->pos, reads, 4L ) != 4L ) goto Fail; p = reads; } else { p = stream->base + stream->pos; } if ( p ) result = FT_NEXT_LONG_LE( p ); } else goto Fail; stream->pos += 4; return result; Fail: *error = FT_Err_Invalid_Stream_Operation; FT_ERROR(( "FT_Stream_ReadLongLE:" " invalid i/o; pos = 0x%lx, size = 0x%lx\n", stream->pos, stream->size )); return 0; }
CWE-20
9,709
16,494
306366392045021660497038340346127250056
null
null
null
savannah
45a3c76b547511fa9d97aca34b150a0663257375
0
FT_Stream_ReadOffset( FT_Stream stream, FT_Error* error ) { FT_Byte reads[3]; FT_Byte* p = 0; FT_Long result = 0; FT_ASSERT( stream ); *error = FT_Err_Ok; if ( stream->pos + 2 < stream->size ) { if ( stream->read ) { if (stream->read( stream, stream->pos, reads, 3L ) != 3L ) goto Fail; p = reads; } else { p = stream->base + stream->pos; } if ( p ) result = FT_NEXT_OFF3( p ); } else goto Fail; stream->pos += 3; return result; Fail: *error = FT_Err_Invalid_Stream_Operation; FT_ERROR(( "FT_Stream_ReadOffset:" " invalid i/o; pos = 0x%lx, size = 0x%lx\n", stream->pos, stream->size )); return 0; }
CWE-20
9,710
16,495
253935062764460621528469430545422907969
null
null
null
savannah
45a3c76b547511fa9d97aca34b150a0663257375
0
FT_Stream_ReadShort( FT_Stream stream, FT_Error* error ) { FT_Byte reads[2]; FT_Byte* p = 0; FT_Short result = 0; FT_ASSERT( stream ); *error = FT_Err_Ok; if ( stream->pos + 1 < stream->size ) { if ( stream->read ) { if ( stream->read( stream, stream->pos, reads, 2L ) != 2L ) goto Fail; p = reads; } else { p = stream->base + stream->pos; } if ( p ) result = FT_NEXT_SHORT( p ); } else goto Fail; stream->pos += 2; return result; Fail: *error = FT_Err_Invalid_Stream_Operation; FT_ERROR(( "FT_Stream_ReadShort:" " invalid i/o; pos = 0x%lx, size = 0x%lx\n", stream->pos, stream->size )); return 0; }
CWE-20
9,711
16,496
74116980934002845357228756326691251691
null
null
null
savannah
45a3c76b547511fa9d97aca34b150a0663257375
0
FT_Stream_ReadShortLE( FT_Stream stream, FT_Error* error ) { FT_Byte reads[2]; FT_Byte* p = 0; FT_Short result = 0; FT_ASSERT( stream ); *error = FT_Err_Ok; if ( stream->pos + 1 < stream->size ) { if ( stream->read ) { if ( stream->read( stream, stream->pos, reads, 2L ) != 2L ) goto Fail; p = reads; } else { p = stream->base + stream->pos; } if ( p ) result = FT_NEXT_SHORT_LE( p ); } else goto Fail; stream->pos += 2; return result; Fail: *error = FT_Err_Invalid_Stream_Operation; FT_ERROR(( "FT_Stream_ReadShortLE:" " invalid i/o; pos = 0x%lx, size = 0x%lx\n", stream->pos, stream->size )); return 0; }
CWE-20
9,712
16,497
278823019607235800347268091257057674860
null
null
null
savannah
45a3c76b547511fa9d97aca34b150a0663257375
0
FT_Stream_ReleaseFrame( FT_Stream stream, FT_Byte** pbytes ) { if ( stream && stream->read ) { FT_Memory memory = stream->memory; #ifdef FT_DEBUG_MEMORY ft_mem_free( memory, *pbytes ); *pbytes = NULL; #else FT_FREE( *pbytes ); #endif } *pbytes = 0; }
CWE-20
9,713
16,498
174615735164713229294294182570624362471
null
null
null
savannah
45a3c76b547511fa9d97aca34b150a0663257375
0
FT_Stream_Seek( FT_Stream stream, FT_ULong pos ) { FT_Error error = FT_Err_Ok; if ( stream->read ) { if ( stream->read( stream, pos, 0, 0 ) ) { FT_ERROR(( "FT_Stream_Seek:" " invalid i/o; pos = 0x%lx, size = 0x%lx\n", pos, stream->size )); error = FT_Err_Invalid_Stream_Operation; } } /* note that seeking to the first position after the file is valid */ else if ( pos > stream->size ) { FT_ERROR(( "FT_Stream_Seek:" " invalid i/o; pos = 0x%lx, size = 0x%lx\n", pos, stream->size )); error = FT_Err_Invalid_Stream_Operation; } if ( !error ) stream->pos = pos; return error; }
CWE-20
9,714
16,499
273096986304687658894064764179180534092
null
null
null
savannah
45a3c76b547511fa9d97aca34b150a0663257375
0
FT_Stream_Skip( FT_Stream stream, FT_Long distance ) { if ( distance < 0 ) return FT_Err_Invalid_Stream_Operation; return FT_Stream_Seek( stream, (FT_ULong)( stream->pos + distance ) ); }
CWE-20
9,715
16,500
265501641232854443110663328094998306168
null
null
null
virglrenderer
28894a30a17a84529be102b21118e55d6c9f23fa
0
match_inst(const char **pcur, unsigned *saturate, const struct tgsi_opcode_info *info) { const char *cur = *pcur; /* simple case: the whole string matches the instruction name */ if (str_match_nocase_whole(&cur, info->mnemonic)) { *pcur = cur; *saturate = 0; return TRUE; } if (str_match_no_case(&cur, info->mnemonic)) { /* the instruction has a suffix, figure it out */ if (str_match_nocase_whole(&cur, "_SAT")) { *pcur = cur; *saturate = 1; return TRUE; } } return FALSE; }
CWE-119
9,717
16,501
322269072271668252518123448905734873168
null
null
null
virglrenderer
28894a30a17a84529be102b21118e55d6c9f23fa
0
static boolean parse_declaration( struct translate_ctx *ctx ) { struct tgsi_full_declaration decl; uint file; struct parsed_dcl_bracket brackets[2]; int num_brackets; uint writemask; const char *cur, *cur2; uint advance; boolean is_vs_input; if (!eat_white( &ctx->cur )) { report_error( ctx, "Syntax error" ); return FALSE; } if (!parse_register_dcl( ctx, &file, brackets, &num_brackets)) return FALSE; if (!parse_opt_writemask( ctx, &writemask )) return FALSE; decl = tgsi_default_full_declaration(); decl.Declaration.File = file; decl.Declaration.UsageMask = writemask; if (num_brackets == 1) { decl.Range.First = brackets[0].first; decl.Range.Last = brackets[0].last; } else { decl.Range.First = brackets[1].first; decl.Range.Last = brackets[1].last; decl.Declaration.Dimension = 1; decl.Dim.Index2D = brackets[0].first; } is_vs_input = (file == TGSI_FILE_INPUT && ctx->processor == TGSI_PROCESSOR_VERTEX); cur = ctx->cur; eat_opt_white( &cur ); if (*cur == ',') { cur2 = cur; cur2++; eat_opt_white( &cur2 ); if (str_match_nocase_whole( &cur2, "ARRAY" )) { int arrayid; if (*cur2 != '(') { report_error( ctx, "Expected `('" ); return FALSE; } cur2++; eat_opt_white( &cur2 ); if (!parse_int( &cur2, &arrayid )) { report_error( ctx, "Expected `,'" ); return FALSE; } eat_opt_white( &cur2 ); if (*cur2 != ')') { report_error( ctx, "Expected `)'" ); return FALSE; } cur2++; decl.Declaration.Array = 1; decl.Array.ArrayID = arrayid; ctx->cur = cur = cur2; } } if (*cur == ',' && !is_vs_input) { uint i, j; cur++; eat_opt_white( &cur ); if (file == TGSI_FILE_RESOURCE) { for (i = 0; i < TGSI_TEXTURE_COUNT; i++) { if (str_match_nocase_whole(&cur, tgsi_texture_names[i])) { decl.Resource.Resource = i; break; } } if (i == TGSI_TEXTURE_COUNT) { report_error(ctx, "Expected texture target"); return FALSE; } cur2 = cur; eat_opt_white(&cur2); while (*cur2 == ',') { cur2++; eat_opt_white(&cur2); if (str_match_nocase_whole(&cur2, "RAW")) { decl.Resource.Raw = 1; } else if (str_match_nocase_whole(&cur2, "WR")) { decl.Resource.Writable = 1; } else { break; } cur = cur2; eat_opt_white(&cur2); } ctx->cur = cur; } else if (file == TGSI_FILE_SAMPLER_VIEW) { for (i = 0; i < TGSI_TEXTURE_COUNT; i++) { if (str_match_nocase_whole(&cur, tgsi_texture_names[i])) { decl.SamplerView.Resource = i; break; } } if (i == TGSI_TEXTURE_COUNT) { report_error(ctx, "Expected texture target"); return FALSE; } eat_opt_white( &cur ); if (*cur != ',') { report_error( ctx, "Expected `,'" ); return FALSE; } ++cur; eat_opt_white( &cur ); for (j = 0; j < 4; ++j) { for (i = 0; i < TGSI_RETURN_TYPE_COUNT; ++i) { if (str_match_nocase_whole(&cur, tgsi_return_type_names[i])) { switch (j) { case 0: decl.SamplerView.ReturnTypeX = i; break; case 1: decl.SamplerView.ReturnTypeY = i; break; case 2: decl.SamplerView.ReturnTypeZ = i; break; case 3: decl.SamplerView.ReturnTypeW = i; break; default: assert(0); } break; } } if (i == TGSI_RETURN_TYPE_COUNT) { if (j == 0 || j > 2) { report_error(ctx, "Expected type name"); return FALSE; } break; } else { cur2 = cur; eat_opt_white( &cur2 ); if (*cur2 == ',') { cur2++; eat_opt_white( &cur2 ); cur = cur2; continue; } else break; } } if (j < 4) { decl.SamplerView.ReturnTypeY = decl.SamplerView.ReturnTypeZ = decl.SamplerView.ReturnTypeW = decl.SamplerView.ReturnTypeX; } ctx->cur = cur; } else { if (str_match_nocase_whole(&cur, "LOCAL")) { decl.Declaration.Local = 1; ctx->cur = cur; } cur = ctx->cur; eat_opt_white( &cur ); if (*cur == ',') { cur++; eat_opt_white( &cur ); for (i = 0; i < TGSI_SEMANTIC_COUNT; i++) { if (str_match_nocase_whole(&cur, tgsi_semantic_names[i])) { uint index; cur2 = cur; eat_opt_white( &cur2 ); if (*cur2 == '[') { cur2++; eat_opt_white( &cur2 ); if (!parse_uint( &cur2, &index )) { report_error( ctx, "Expected literal integer" ); return FALSE; } eat_opt_white( &cur2 ); if (*cur2 != ']') { report_error( ctx, "Expected `]'" ); return FALSE; } cur2++; decl.Semantic.Index = index; cur = cur2; } decl.Declaration.Semantic = 1; decl.Semantic.Name = i; ctx->cur = cur; break; } } } } } cur = ctx->cur; eat_opt_white( &cur ); if (*cur == ',' && !is_vs_input) { uint i; cur++; eat_opt_white( &cur ); for (i = 0; i < TGSI_INTERPOLATE_COUNT; i++) { if (str_match_nocase_whole( &cur, tgsi_interpolate_names[i] )) { decl.Declaration.Interpolate = 1; decl.Interp.Interpolate = i; ctx->cur = cur; break; } } if (i == TGSI_INTERPOLATE_COUNT) { report_error( ctx, "Expected semantic or interpolate attribute" ); return FALSE; } } cur = ctx->cur; eat_opt_white( &cur ); if (*cur == ',' && !is_vs_input) { uint i; cur++; eat_opt_white( &cur ); for (i = 0; i < TGSI_INTERPOLATE_LOC_COUNT; i++) { if (str_match_nocase_whole( &cur, tgsi_interpolate_locations[i] )) { decl.Interp.Location = i; ctx->cur = cur; break; } } } advance = tgsi_build_full_declaration( &decl, ctx->tokens_cur, ctx->header, (uint) (ctx->tokens_end - ctx->tokens_cur) ); if (advance == 0) return FALSE; ctx->tokens_cur += advance; return TRUE; }
CWE-119
9,718
16,502
3155356385645618350205239204741586809
null
null
null
virglrenderer
28894a30a17a84529be102b21118e55d6c9f23fa
0
static boolean parse_double( const char **pcur, uint32_t *val0, uint32_t *val1) { const char *cur = *pcur; union { double dval; uint32_t uval[2]; } v; v.dval = strtod(cur, (char**)pcur); if (*pcur == cur) return FALSE; *val0 = v.uval[0]; *val1 = v.uval[1]; return TRUE; }
CWE-119
9,719
16,503
241273819728621219618271202408893664374
null
null
null
virglrenderer
28894a30a17a84529be102b21118e55d6c9f23fa
0
parse_dst_operand( struct translate_ctx *ctx, struct tgsi_full_dst_register *dst ) { uint file; uint writemask; const char *cur; struct parsed_bracket bracket[2]; int parsed_opt_brackets; if (!parse_register_dst( ctx, &file, &bracket[0] )) return FALSE; if (!parse_opt_register_src_bracket(ctx, &bracket[1], &parsed_opt_brackets)) return FALSE; cur = ctx->cur; eat_opt_white( &cur ); if (!parse_opt_writemask( ctx, &writemask )) return FALSE; dst->Register.File = file; if (parsed_opt_brackets) { dst->Register.Dimension = 1; dst->Dimension.Indirect = 0; dst->Dimension.Dimension = 0; dst->Dimension.Index = bracket[0].index; if (bracket[0].ind_file != TGSI_FILE_NULL) { dst->Dimension.Indirect = 1; dst->DimIndirect.File = bracket[0].ind_file; dst->DimIndirect.Index = bracket[0].ind_index; dst->DimIndirect.Swizzle = bracket[0].ind_comp; dst->DimIndirect.ArrayID = bracket[0].ind_array; } bracket[0] = bracket[1]; } dst->Register.Index = bracket[0].index; dst->Register.WriteMask = writemask; if (bracket[0].ind_file != TGSI_FILE_NULL) { dst->Register.Indirect = 1; dst->Indirect.File = bracket[0].ind_file; dst->Indirect.Index = bracket[0].ind_index; dst->Indirect.Swizzle = bracket[0].ind_comp; dst->Indirect.ArrayID = bracket[0].ind_array; } return TRUE; }
CWE-119
9,720
16,504
115627618795651271842688256645090770589
null
null
null
virglrenderer
28894a30a17a84529be102b21118e55d6c9f23fa
0
parse_file( const char **pcur, uint *file ) { uint i; for (i = 0; i < TGSI_FILE_COUNT; i++) { const char *cur = *pcur; if (str_match_nocase_whole( &cur, tgsi_file_name(i) )) { *pcur = cur; *file = i; return TRUE; } } return FALSE; }
CWE-119
9,721
16,505
75307620741405708628920812666212776016
null
null
null
virglrenderer
28894a30a17a84529be102b21118e55d6c9f23fa
0
static boolean parse_float( const char **pcur, float *val ) { const char *cur = *pcur; boolean integral_part = FALSE; boolean fractional_part = FALSE; if (*cur == '0' && *(cur + 1) == 'x') { union fi fi; fi.ui = strtoul(cur, NULL, 16); *val = fi.f; cur += 10; goto out; } *val = (float) atof( cur ); if (*cur == '-' || *cur == '+') cur++; if (is_digit( cur )) { cur++; integral_part = TRUE; while (is_digit( cur )) cur++; } if (*cur == '.') { cur++; if (is_digit( cur )) { cur++; fractional_part = TRUE; while (is_digit( cur )) cur++; } } if (!integral_part && !fractional_part) return FALSE; if (uprcase( *cur ) == 'E') { cur++; if (*cur == '-' || *cur == '+') cur++; if (is_digit( cur )) { cur++; while (is_digit( cur )) cur++; } else return FALSE; } out: *pcur = cur; return TRUE; }
CWE-119
9,722
16,506
100253453035363592391244271208259403604
null
null
null
virglrenderer
28894a30a17a84529be102b21118e55d6c9f23fa
0
parse_fs_coord_origin( const char **pcur, uint *fs_coord_origin ) { uint i; for (i = 0; i < Elements(tgsi_fs_coord_origin_names); i++) { const char *cur = *pcur; if (str_match_nocase_whole( &cur, tgsi_fs_coord_origin_names[i])) { *fs_coord_origin = i; *pcur = cur; return TRUE; } } return FALSE; }
CWE-119
9,723
16,507
166122579202040371473278187233955704390
null
null
null
virglrenderer
28894a30a17a84529be102b21118e55d6c9f23fa
0
parse_fs_coord_pixel_center( const char **pcur, uint *fs_coord_pixel_center ) { uint i; for (i = 0; i < Elements(tgsi_fs_coord_pixel_center_names); i++) { const char *cur = *pcur; if (str_match_nocase_whole( &cur, tgsi_fs_coord_pixel_center_names[i])) { *fs_coord_pixel_center = i; *pcur = cur; return TRUE; } } return FALSE; }
CWE-119
9,724
16,508
147580351603608353055657386550791202827
null
null
null
virglrenderer
28894a30a17a84529be102b21118e55d6c9f23fa
0
static boolean parse_header( struct translate_ctx *ctx ) { uint processor; if (str_match_nocase_whole( &ctx->cur, "FRAG" )) processor = TGSI_PROCESSOR_FRAGMENT; else if (str_match_nocase_whole( &ctx->cur, "VERT" )) processor = TGSI_PROCESSOR_VERTEX; else if (str_match_nocase_whole( &ctx->cur, "GEOM" )) processor = TGSI_PROCESSOR_GEOMETRY; else if (str_match_nocase_whole( &ctx->cur, "TESS_CTRL" )) processor = TGSI_PROCESSOR_TESS_CTRL; else if (str_match_nocase_whole( &ctx->cur, "TESS_EVAL" )) processor = TGSI_PROCESSOR_TESS_EVAL; else if (str_match_nocase_whole( &ctx->cur, "COMP" )) processor = TGSI_PROCESSOR_COMPUTE; else { report_error( ctx, "Unknown header" ); return FALSE; } if (ctx->tokens_cur >= ctx->tokens_end) return FALSE; ctx->header = (struct tgsi_header *) ctx->tokens_cur++; *ctx->header = tgsi_build_header(); if (ctx->tokens_cur >= ctx->tokens_end) return FALSE; *(struct tgsi_processor *) ctx->tokens_cur++ = tgsi_build_processor( processor, ctx->header ); ctx->processor = processor; return TRUE; }
CWE-119
9,725
16,509
241004846058241759794002882286622793259
null
null
null
virglrenderer
28894a30a17a84529be102b21118e55d6c9f23fa
0
static boolean parse_identifier( const char **pcur, char *ret, size_t len ) { const char *cur = *pcur; int i = 0; if (is_alpha_underscore( cur )) { ret[i++] = *cur++; while (is_alpha_underscore( cur ) || is_digit( cur )) { if (i == len - 1) return FALSE; ret[i++] = *cur++; } ret[i++] = '\0'; *pcur = cur; return TRUE; } return FALSE; }
CWE-119
9,726
16,510
147153910378074028552659955910103053650
null
null
null
virglrenderer
28894a30a17a84529be102b21118e55d6c9f23fa
0
static boolean parse_immediate( struct translate_ctx *ctx ) { struct tgsi_full_immediate imm; uint advance; int type; if (*ctx->cur == '[') { uint uindex; ++ctx->cur; eat_opt_white( &ctx->cur ); if (!parse_uint( &ctx->cur, &uindex )) { report_error( ctx, "Expected literal unsigned integer" ); return FALSE; } if (uindex != ctx->num_immediates) { report_error( ctx, "Immediates must be sorted" ); return FALSE; } eat_opt_white( &ctx->cur ); if (*ctx->cur != ']') { report_error( ctx, "Expected `]'" ); return FALSE; } ctx->cur++; } if (!eat_white( &ctx->cur )) { report_error( ctx, "Syntax error" ); return FALSE; } for (type = 0; type < Elements(tgsi_immediate_type_names); ++type) { if (str_match_nocase_whole(&ctx->cur, tgsi_immediate_type_names[type])) break; } if (type == Elements(tgsi_immediate_type_names)) { report_error( ctx, "Expected immediate type" ); return FALSE; } imm = tgsi_default_full_immediate(); imm.Immediate.NrTokens += 4; imm.Immediate.DataType = type; parse_immediate_data(ctx, type, imm.u); advance = tgsi_build_full_immediate( &imm, ctx->tokens_cur, ctx->header, (uint) (ctx->tokens_end - ctx->tokens_cur) ); if (advance == 0) return FALSE; ctx->tokens_cur += advance; ctx->num_immediates++; return TRUE; }
CWE-119
9,727
16,511
296097291933930932262632161359243336576
null
null
null
virglrenderer
28894a30a17a84529be102b21118e55d6c9f23fa
0
static boolean parse_immediate_data(struct translate_ctx *ctx, unsigned type, union tgsi_immediate_data *values) { unsigned i; int ret; eat_opt_white( &ctx->cur ); if (*ctx->cur != '{') { report_error( ctx, "Expected `{'" ); return FALSE; } ctx->cur++; for (i = 0; i < 4; i++) { eat_opt_white( &ctx->cur ); if (i > 0) { if (*ctx->cur != ',') { report_error( ctx, "Expected `,'" ); return FALSE; } ctx->cur++; eat_opt_white( &ctx->cur ); } switch (type) { case TGSI_IMM_FLOAT64: ret = parse_double(&ctx->cur, &values[i].Uint, &values[i+1].Uint); i++; break; case TGSI_IMM_FLOAT32: ret = parse_float(&ctx->cur, &values[i].Float); break; case TGSI_IMM_UINT32: ret = parse_uint(&ctx->cur, &values[i].Uint); break; case TGSI_IMM_INT32: ret = parse_int(&ctx->cur, &values[i].Int); break; default: assert(0); ret = FALSE; break; } if (!ret) { report_error( ctx, "Expected immediate constant" ); return FALSE; } } eat_opt_white( &ctx->cur ); if (*ctx->cur != '}') { report_error( ctx, "Expected `}'" ); return FALSE; } ctx->cur++; return TRUE; }
CWE-119
9,728
16,512
8907359205129316447698588231493761044
null
null
null
virglrenderer
28894a30a17a84529be102b21118e55d6c9f23fa
0
static boolean parse_label( struct translate_ctx *ctx, uint *val ) { const char *cur = ctx->cur; if (parse_uint( &cur, val )) { eat_opt_white( &cur ); if (*cur == ':') { cur++; ctx->cur = cur; return TRUE; } } return FALSE; }
CWE-119
9,730
16,513
86800493018514873048815357392976760620
null
null
null
virglrenderer
28894a30a17a84529be102b21118e55d6c9f23fa
0
parse_opt_register_src_bracket( struct translate_ctx *ctx, struct parsed_bracket *brackets, int *parsed_brackets) { const char *cur = ctx->cur; *parsed_brackets = 0; eat_opt_white( &cur ); if (cur[0] == '[') { ++cur; ctx->cur = cur; if (!parse_register_bracket(ctx, brackets)) return FALSE; *parsed_brackets = 1; } return TRUE; }
CWE-119
9,731
16,514
27455105415370411836529956434492960750
null
null
null
virglrenderer
28894a30a17a84529be102b21118e55d6c9f23fa
0
parse_optional_swizzle( struct translate_ctx *ctx, uint *swizzle, boolean *parsed_swizzle, int components) { const char *cur = ctx->cur; *parsed_swizzle = FALSE; eat_opt_white( &cur ); if (*cur == '.') { uint i; cur++; eat_opt_white( &cur ); for (i = 0; i < components; i++) { if (uprcase( *cur ) == 'X') swizzle[i] = TGSI_SWIZZLE_X; else if (uprcase( *cur ) == 'Y') swizzle[i] = TGSI_SWIZZLE_Y; else if (uprcase( *cur ) == 'Z') swizzle[i] = TGSI_SWIZZLE_Z; else if (uprcase( *cur ) == 'W') swizzle[i] = TGSI_SWIZZLE_W; else { report_error( ctx, "Expected register swizzle component `x', `y', `z' or `w'" ); return FALSE; } cur++; } *parsed_swizzle = TRUE; ctx->cur = cur; } return TRUE; }
CWE-119
9,733
16,515
254588657320318438351659908525979335380
null
null
null
virglrenderer
28894a30a17a84529be102b21118e55d6c9f23fa
0
parse_primitive( const char **pcur, uint *primitive ) { uint i; for (i = 0; i < PIPE_PRIM_MAX; i++) { const char *cur = *pcur; if (str_match_nocase_whole( &cur, tgsi_primitive_names[i])) { *primitive = i; *pcur = cur; return TRUE; } } return FALSE; }
CWE-119
9,734
16,516
296110727739656544877123197409593125236
null
null
null
virglrenderer
28894a30a17a84529be102b21118e55d6c9f23fa
0
static boolean parse_property( struct translate_ctx *ctx ) { struct tgsi_full_property prop; uint property_name; uint values[8]; uint advance; char id[64]; if (!eat_white( &ctx->cur )) { report_error( ctx, "Syntax error" ); return FALSE; } if (!parse_identifier( &ctx->cur, id, sizeof(id) )) { report_error( ctx, "Syntax error" ); return FALSE; } for (property_name = 0; property_name < TGSI_PROPERTY_COUNT; ++property_name) { if (streq_nocase_uprcase(tgsi_property_names[property_name], id)) { break; } } if (property_name >= TGSI_PROPERTY_COUNT) { eat_until_eol( &ctx->cur ); report_error(ctx, "\nError: Unknown property : '%s'\n", id); return TRUE; } eat_opt_white( &ctx->cur ); switch(property_name) { case TGSI_PROPERTY_GS_INPUT_PRIM: case TGSI_PROPERTY_GS_OUTPUT_PRIM: if (!parse_primitive(&ctx->cur, &values[0] )) { report_error( ctx, "Unknown primitive name as property!" ); return FALSE; } if (property_name == TGSI_PROPERTY_GS_INPUT_PRIM && ctx->processor == TGSI_PROCESSOR_GEOMETRY) { ctx->implied_array_size = u_vertices_per_prim(values[0]); } break; case TGSI_PROPERTY_FS_COORD_ORIGIN: if (!parse_fs_coord_origin(&ctx->cur, &values[0] )) { report_error( ctx, "Unknown coord origin as property: must be UPPER_LEFT or LOWER_LEFT!" ); return FALSE; } break; case TGSI_PROPERTY_FS_COORD_PIXEL_CENTER: if (!parse_fs_coord_pixel_center(&ctx->cur, &values[0] )) { report_error( ctx, "Unknown coord pixel center as property: must be HALF_INTEGER or INTEGER!" ); return FALSE; } break; case TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS: default: if (!parse_uint(&ctx->cur, &values[0] )) { report_error( ctx, "Expected unsigned integer as property!" ); return FALSE; } } prop = tgsi_default_full_property(); prop.Property.PropertyName = property_name; prop.Property.NrTokens += 1; prop.u[0].Data = values[0]; advance = tgsi_build_full_property( &prop, ctx->tokens_cur, ctx->header, (uint) (ctx->tokens_end - ctx->tokens_cur) ); if (advance == 0) return FALSE; ctx->tokens_cur += advance; return TRUE; }
CWE-119
9,735
16,517
69001206720944764469627987897482443525
null
null
null
virglrenderer
28894a30a17a84529be102b21118e55d6c9f23fa
0
parse_register_1d(struct translate_ctx *ctx, uint *file, int *index ) { if (!parse_register_file_bracket_index( ctx, file, index )) return FALSE; eat_opt_white( &ctx->cur ); if (*ctx->cur != ']') { report_error( ctx, "Expected `]'" ); return FALSE; } ctx->cur++; return TRUE; }
CWE-119
9,736
16,518
10772654342126940052033382462306800874
null
null
null
virglrenderer
28894a30a17a84529be102b21118e55d6c9f23fa
0
parse_register_dcl( struct translate_ctx *ctx, uint *file, struct parsed_dcl_bracket *brackets, int *num_brackets) { const char *cur; *num_brackets = 0; if (!parse_register_file_bracket( ctx, file )) return FALSE; if (!parse_register_dcl_bracket( ctx, &brackets[0] )) return FALSE; *num_brackets = 1; cur = ctx->cur; eat_opt_white( &cur ); if (cur[0] == '[') { bool is_in = *file == TGSI_FILE_INPUT; bool is_out = *file == TGSI_FILE_OUTPUT; ++cur; ctx->cur = cur; if (!parse_register_dcl_bracket( ctx, &brackets[1] )) return FALSE; /* for geometry shader we don't really care about * the first brackets it's always the size of the * input primitive. so we want to declare just * the index relevant to the semantics which is in * the second bracket */ /* tessellation has similar constraints to geometry shader */ if ((ctx->processor == TGSI_PROCESSOR_GEOMETRY && is_in) || (ctx->processor == TGSI_PROCESSOR_TESS_EVAL && is_in) || (ctx->processor == TGSI_PROCESSOR_TESS_CTRL && (is_in || is_out))) { brackets[0] = brackets[1]; *num_brackets = 1; } else { *num_brackets = 2; } } return TRUE; }
CWE-119
9,738
16,519
119349489919729261025647339676376802730
null
null
null
virglrenderer
28894a30a17a84529be102b21118e55d6c9f23fa
0
parse_register_dst( struct translate_ctx *ctx, uint *file, struct parsed_bracket *brackets) { brackets->ind_comp = TGSI_SWIZZLE_X; if (!parse_register_file_bracket( ctx, file )) return FALSE; if (!parse_register_bracket( ctx, brackets )) return FALSE; return TRUE; }
CWE-119
9,740
16,520
306072997943435328738368953814262061017
null
null
null
virglrenderer
28894a30a17a84529be102b21118e55d6c9f23fa
0
parse_register_file_bracket( struct translate_ctx *ctx, uint *file ) { if (!parse_file( &ctx->cur, file )) { report_error( ctx, "Unknown register file" ); return FALSE; } eat_opt_white( &ctx->cur ); if (*ctx->cur != '[') { report_error( ctx, "Expected `['" ); return FALSE; } ctx->cur++; return TRUE; }
CWE-119
9,741
16,521
225920943564887518128864558020504578160
null
null
null
virglrenderer
28894a30a17a84529be102b21118e55d6c9f23fa
0
parse_src_operand( struct translate_ctx *ctx, struct tgsi_full_src_register *src ) { uint file; uint swizzle[4]; boolean parsed_swizzle; struct parsed_bracket bracket[2]; int parsed_opt_brackets; if (*ctx->cur == '-') { ctx->cur++; eat_opt_white( &ctx->cur ); src->Register.Negate = 1; } if (*ctx->cur == '|') { ctx->cur++; eat_opt_white( &ctx->cur ); src->Register.Absolute = 1; } if (!parse_register_src(ctx, &file, &bracket[0])) return FALSE; if (!parse_opt_register_src_bracket(ctx, &bracket[1], &parsed_opt_brackets)) return FALSE; src->Register.File = file; if (parsed_opt_brackets) { src->Register.Dimension = 1; src->Dimension.Indirect = 0; src->Dimension.Dimension = 0; src->Dimension.Index = bracket[0].index; if (bracket[0].ind_file != TGSI_FILE_NULL) { src->Dimension.Indirect = 1; src->DimIndirect.File = bracket[0].ind_file; src->DimIndirect.Index = bracket[0].ind_index; src->DimIndirect.Swizzle = bracket[0].ind_comp; src->DimIndirect.ArrayID = bracket[0].ind_array; } bracket[0] = bracket[1]; } src->Register.Index = bracket[0].index; if (bracket[0].ind_file != TGSI_FILE_NULL) { src->Register.Indirect = 1; src->Indirect.File = bracket[0].ind_file; src->Indirect.Index = bracket[0].ind_index; src->Indirect.Swizzle = bracket[0].ind_comp; src->Indirect.ArrayID = bracket[0].ind_array; } /* Parse optional swizzle. */ if (parse_optional_swizzle( ctx, swizzle, &parsed_swizzle, 4 )) { if (parsed_swizzle) { src->Register.SwizzleX = swizzle[0]; src->Register.SwizzleY = swizzle[1]; src->Register.SwizzleZ = swizzle[2]; src->Register.SwizzleW = swizzle[3]; } } if (src->Register.Absolute) { eat_opt_white( &ctx->cur ); if (*ctx->cur != '|') { report_error( ctx, "Expected `|'" ); return FALSE; } ctx->cur++; } return TRUE; }
CWE-119
9,744
16,522
214108191393218543565028130711001453820
null
null
null
virglrenderer
28894a30a17a84529be102b21118e55d6c9f23fa
0
parse_texoffset_operand( struct translate_ctx *ctx, struct tgsi_texture_offset *src ) { uint file; uint swizzle[3]; boolean parsed_swizzle; struct parsed_bracket bracket; if (!parse_register_src(ctx, &file, &bracket)) return FALSE; src->File = file; src->Index = bracket.index; /* Parse optional swizzle. */ if (parse_optional_swizzle( ctx, swizzle, &parsed_swizzle, 3 )) { if (parsed_swizzle) { src->SwizzleX = swizzle[0]; src->SwizzleY = swizzle[1]; src->SwizzleZ = swizzle[2]; } } return TRUE; }
CWE-119
9,745
16,523
243719028480469085182719484261616535227
null
null
null
virglrenderer
28894a30a17a84529be102b21118e55d6c9f23fa
0
static void report_error(struct translate_ctx *ctx, const char *format, ...) { va_list args; int line = 1; int column = 1; const char *itr = ctx->text; debug_printf("\nTGSI asm error: "); va_start(args, format); _debug_vprintf(format, args); va_end(args); while (itr != ctx->cur) { if (*itr == '\n') { column = 1; ++line; } ++column; ++itr; } debug_printf(" [%d : %d] \n", line, column); }
CWE-119
9,746
16,524
5833547282051635843156255266260477109
null
null
null
virglrenderer
28894a30a17a84529be102b21118e55d6c9f23fa
0
tgsi_text_translate( const char *text, struct tgsi_token *tokens, uint num_tokens ) { struct translate_ctx ctx = {0}; ctx.text = text; ctx.cur = text; ctx.tokens = tokens; ctx.tokens_cur = tokens; ctx.tokens_end = tokens + num_tokens; if (!translate( &ctx )) return FALSE; return tgsi_sanity_check( tokens ); }
CWE-119
9,747
16,525
238022307771255269756624188500757124095
null
null
null
virglrenderer
28894a30a17a84529be102b21118e55d6c9f23fa
0
static boolean translate( struct translate_ctx *ctx ) { eat_opt_white( &ctx->cur ); if (!parse_header( ctx )) return FALSE; if (ctx->processor == TGSI_PROCESSOR_TESS_CTRL || ctx->processor == TGSI_PROCESSOR_TESS_EVAL) ctx->implied_array_size = 32; while (*ctx->cur != '\0') { uint label_val = 0; if (!eat_white( &ctx->cur )) { report_error( ctx, "Syntax error" ); return FALSE; } if (*ctx->cur == '\0') break; if (parse_label( ctx, &label_val )) { if (!parse_instruction( ctx, TRUE )) return FALSE; } else if (str_match_nocase_whole( &ctx->cur, "DCL" )) { if (!parse_declaration( ctx )) return FALSE; } else if (str_match_nocase_whole( &ctx->cur, "IMM" )) { if (!parse_immediate( ctx )) return FALSE; } else if (str_match_nocase_whole( &ctx->cur, "PROPERTY" )) { if (!parse_property( ctx )) return FALSE; } else if (!parse_instruction( ctx, FALSE )) { return FALSE; } } return TRUE; }
CWE-119
9,748
16,526
254006993480805421327672259747913426914
null
null
null
haproxy
b4d05093bc89f71377230228007e69a1434c1a0c
0
static void __http_protocol_init(void) { acl_register_keywords(&acl_kws); sample_register_fetches(&sample_fetch_keywords); sample_register_convs(&sample_conv_kws); }
CWE-189
9,763
16,527
99361912543221006699788015400645986337
null
null
null
haproxy
b4d05093bc89f71377230228007e69a1434c1a0c
0
struct http_req_action_kw *action_http_req_custom(const char *kw) { if (!LIST_ISEMPTY(&http_req_keywords.list)) { struct http_req_action_kw_list *kw_list; int i; list_for_each_entry(kw_list, &http_req_keywords.list, list) { for (i = 0; kw_list->kw[i].kw != NULL; i++) { if (!strcmp(kw, kw_list->kw[i].kw)) return &kw_list->kw[i]; } } } return NULL; }
CWE-189
9,764
16,528
338732020618634798360317380009012548389
null
null
null
haproxy
b4d05093bc89f71377230228007e69a1434c1a0c
0
struct http_res_action_kw *action_http_res_custom(const char *kw) { if (!LIST_ISEMPTY(&http_res_keywords.list)) { struct http_res_action_kw_list *kw_list; int i; list_for_each_entry(kw_list, &http_res_keywords.list, list) { for (i = 0; kw_list->kw[i].kw != NULL; i++) { if (!strcmp(kw, kw_list->kw[i].kw)) return &kw_list->kw[i]; } } } return NULL; }
CWE-189
9,765
16,529
42297187404441934413978499602627551267
null
null
null
haproxy
b4d05093bc89f71377230228007e69a1434c1a0c
0
int apply_filter_to_req_headers(struct session *s, struct channel *req, struct hdr_exp *exp) { char *cur_ptr, *cur_end, *cur_next; int cur_idx, old_idx, last_hdr; struct http_txn *txn = &s->txn; struct hdr_idx_elem *cur_hdr; int delta; last_hdr = 0; cur_next = req->buf->p + hdr_idx_first_pos(&txn->hdr_idx); old_idx = 0; while (!last_hdr) { if (unlikely(txn->flags & (TX_CLDENY | TX_CLTARPIT))) return 1; else if (unlikely(txn->flags & TX_CLALLOW) && (exp->action == ACT_ALLOW || exp->action == ACT_DENY || exp->action == ACT_TARPIT)) return 0; cur_idx = txn->hdr_idx.v[old_idx].next; if (!cur_idx) break; cur_hdr = &txn->hdr_idx.v[cur_idx]; cur_ptr = cur_next; cur_end = cur_ptr + cur_hdr->len; cur_next = cur_end + cur_hdr->cr + 1; /* Now we have one header between cur_ptr and cur_end, * and the next header starts at cur_next. */ if (regex_exec_match2(exp->preg, cur_ptr, cur_end-cur_ptr, MAX_MATCH, pmatch)) { switch (exp->action) { case ACT_SETBE: /* It is not possible to jump a second time. * FIXME: should we return an HTTP/500 here so that * the admin knows there's a problem ? */ if (s->be != s->fe) break; /* Swithing Proxy */ session_set_backend(s, (struct proxy *)exp->replace); last_hdr = 1; break; case ACT_ALLOW: txn->flags |= TX_CLALLOW; last_hdr = 1; break; case ACT_DENY: txn->flags |= TX_CLDENY; last_hdr = 1; break; case ACT_TARPIT: txn->flags |= TX_CLTARPIT; last_hdr = 1; break; case ACT_REPLACE: trash.len = exp_replace(trash.str, trash.size, cur_ptr, exp->replace, pmatch); if (trash.len < 0) return -1; delta = buffer_replace2(req->buf, cur_ptr, cur_end, trash.str, trash.len); /* FIXME: if the user adds a newline in the replacement, the * index will not be recalculated for now, and the new line * will not be counted as a new header. */ cur_end += delta; cur_next += delta; cur_hdr->len += delta; http_msg_move_end(&txn->req, delta); break; case ACT_REMOVE: delta = buffer_replace2(req->buf, cur_ptr, cur_next, NULL, 0); cur_next += delta; http_msg_move_end(&txn->req, delta); txn->hdr_idx.v[old_idx].next = cur_hdr->next; txn->hdr_idx.used--; cur_hdr->len = 0; cur_end = NULL; /* null-term has been rewritten */ cur_idx = old_idx; break; } } /* keep the link from this header to next one in case of later * removal of next header. */ old_idx = cur_idx; } return 0; }
CWE-189
9,766
16,530
185481058285179211250636575037574113661
null
null
null
haproxy
b4d05093bc89f71377230228007e69a1434c1a0c
0
int apply_filter_to_req_line(struct session *s, struct channel *req, struct hdr_exp *exp) { char *cur_ptr, *cur_end; int done; struct http_txn *txn = &s->txn; int delta; if (unlikely(txn->flags & (TX_CLDENY | TX_CLTARPIT))) return 1; else if (unlikely(txn->flags & TX_CLALLOW) && (exp->action == ACT_ALLOW || exp->action == ACT_DENY || exp->action == ACT_TARPIT)) return 0; else if (exp->action == ACT_REMOVE) return 0; done = 0; cur_ptr = req->buf->p; cur_end = cur_ptr + txn->req.sl.rq.l; /* Now we have the request line between cur_ptr and cur_end */ if (regex_exec_match2(exp->preg, cur_ptr, cur_end-cur_ptr, MAX_MATCH, pmatch)) { switch (exp->action) { case ACT_SETBE: /* It is not possible to jump a second time. * FIXME: should we return an HTTP/500 here so that * the admin knows there's a problem ? */ if (s->be != s->fe) break; /* Swithing Proxy */ session_set_backend(s, (struct proxy *)exp->replace); done = 1; break; case ACT_ALLOW: txn->flags |= TX_CLALLOW; done = 1; break; case ACT_DENY: txn->flags |= TX_CLDENY; done = 1; break; case ACT_TARPIT: txn->flags |= TX_CLTARPIT; done = 1; break; case ACT_REPLACE: trash.len = exp_replace(trash.str, trash.size, cur_ptr, exp->replace, pmatch); if (trash.len < 0) return -1; delta = buffer_replace2(req->buf, cur_ptr, cur_end, trash.str, trash.len); /* FIXME: if the user adds a newline in the replacement, the * index will not be recalculated for now, and the new line * will not be counted as a new header. */ http_msg_move_end(&txn->req, delta); cur_end += delta; cur_end = (char *)http_parse_reqline(&txn->req, HTTP_MSG_RQMETH, cur_ptr, cur_end + 1, NULL, NULL); if (unlikely(!cur_end)) return -1; /* we have a full request and we know that we have either a CR * or an LF at <ptr>. */ txn->meth = find_http_meth(cur_ptr, txn->req.sl.rq.m_l); hdr_idx_set_start(&txn->hdr_idx, txn->req.sl.rq.l, *cur_end == '\r'); /* there is no point trying this regex on headers */ return 1; } } return done; }
CWE-189
9,767
16,531
253239459688155571867787220772861601744
null
null
null
haproxy
b4d05093bc89f71377230228007e69a1434c1a0c
0
int apply_filter_to_resp_headers(struct session *s, struct channel *rtr, struct hdr_exp *exp) { char *cur_ptr, *cur_end, *cur_next; int cur_idx, old_idx, last_hdr; struct http_txn *txn = &s->txn; struct hdr_idx_elem *cur_hdr; int delta; last_hdr = 0; cur_next = rtr->buf->p + hdr_idx_first_pos(&txn->hdr_idx); old_idx = 0; while (!last_hdr) { if (unlikely(txn->flags & TX_SVDENY)) return 1; else if (unlikely(txn->flags & TX_SVALLOW) && (exp->action == ACT_ALLOW || exp->action == ACT_DENY)) return 0; cur_idx = txn->hdr_idx.v[old_idx].next; if (!cur_idx) break; cur_hdr = &txn->hdr_idx.v[cur_idx]; cur_ptr = cur_next; cur_end = cur_ptr + cur_hdr->len; cur_next = cur_end + cur_hdr->cr + 1; /* Now we have one header between cur_ptr and cur_end, * and the next header starts at cur_next. */ if (regex_exec_match2(exp->preg, cur_ptr, cur_end-cur_ptr, MAX_MATCH, pmatch)) { switch (exp->action) { case ACT_ALLOW: txn->flags |= TX_SVALLOW; last_hdr = 1; break; case ACT_DENY: txn->flags |= TX_SVDENY; last_hdr = 1; break; case ACT_REPLACE: trash.len = exp_replace(trash.str, trash.size, cur_ptr, exp->replace, pmatch); if (trash.len < 0) return -1; delta = buffer_replace2(rtr->buf, cur_ptr, cur_end, trash.str, trash.len); /* FIXME: if the user adds a newline in the replacement, the * index will not be recalculated for now, and the new line * will not be counted as a new header. */ cur_end += delta; cur_next += delta; cur_hdr->len += delta; http_msg_move_end(&txn->rsp, delta); break; case ACT_REMOVE: delta = buffer_replace2(rtr->buf, cur_ptr, cur_next, NULL, 0); cur_next += delta; http_msg_move_end(&txn->rsp, delta); txn->hdr_idx.v[old_idx].next = cur_hdr->next; txn->hdr_idx.used--; cur_hdr->len = 0; cur_end = NULL; /* null-term has been rewritten */ cur_idx = old_idx; break; } } /* keep the link from this header to next one in case of later * removal of next header. */ old_idx = cur_idx; } return 0; }
CWE-189
9,768
16,532
44014739518182144092186268082407599835
null
null
null
haproxy
b4d05093bc89f71377230228007e69a1434c1a0c
0
int apply_filter_to_sts_line(struct session *s, struct channel *rtr, struct hdr_exp *exp) { char *cur_ptr, *cur_end; int done; struct http_txn *txn = &s->txn; int delta; if (unlikely(txn->flags & TX_SVDENY)) return 1; else if (unlikely(txn->flags & TX_SVALLOW) && (exp->action == ACT_ALLOW || exp->action == ACT_DENY)) return 0; else if (exp->action == ACT_REMOVE) return 0; done = 0; cur_ptr = rtr->buf->p; cur_end = cur_ptr + txn->rsp.sl.st.l; /* Now we have the status line between cur_ptr and cur_end */ if (regex_exec_match2(exp->preg, cur_ptr, cur_end-cur_ptr, MAX_MATCH, pmatch)) { switch (exp->action) { case ACT_ALLOW: txn->flags |= TX_SVALLOW; done = 1; break; case ACT_DENY: txn->flags |= TX_SVDENY; done = 1; break; case ACT_REPLACE: trash.len = exp_replace(trash.str, trash.size, cur_ptr, exp->replace, pmatch); if (trash.len < 0) return -1; delta = buffer_replace2(rtr->buf, cur_ptr, cur_end, trash.str, trash.len); /* FIXME: if the user adds a newline in the replacement, the * index will not be recalculated for now, and the new line * will not be counted as a new header. */ http_msg_move_end(&txn->rsp, delta); cur_end += delta; cur_end = (char *)http_parse_stsline(&txn->rsp, HTTP_MSG_RPVER, cur_ptr, cur_end + 1, NULL, NULL); if (unlikely(!cur_end)) return -1; /* we have a full respnse and we know that we have either a CR * or an LF at <ptr>. */ txn->status = strl2ui(rtr->buf->p + txn->rsp.sl.st.c, txn->rsp.sl.st.c_l); hdr_idx_set_start(&txn->hdr_idx, txn->rsp.sl.st.l, *cur_end == '\r'); /* there is no point trying this regex on headers */ return 1; } } return done; }
CWE-189
9,769
16,533
42509404027713417706957399990132793553
null
null
null