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
samba
c252546ceeb0925eb8a4061315e3ff0a8c55b48b
0
int canonical_checksum(int csum_type) { return csum_type >= CSUM_MD4 ? 1 : 0; }
CWE-354
1,625
12,073
193660441087916255519772839775936095723
null
null
null
samba
c252546ceeb0925eb8a4061315e3ff0a8c55b48b
0
int csum_len_for_type(int cst) { switch (cst) { case CSUM_NONE: return 1; case CSUM_MD4_ARCHAIC: return 2; case CSUM_MD4: case CSUM_MD4_OLD: case CSUM_MD4_BUSTED: return MD4_DIGEST_LEN; case CSUM_MD5: return MD5_DIGEST_LEN; } return 0; }
CWE-354
1,626
12,074
184229028751583676419777253716480662408
null
null
null
samba
c252546ceeb0925eb8a4061315e3ff0a8c55b48b
0
void file_checksum(const char *fname, const STRUCT_STAT *st_p, char *sum) { struct map_struct *buf; OFF_T i, len = st_p->st_size; md_context m; int32 remainder; int fd; memset(sum, 0, MAX_DIGEST_LEN); fd = do_open(fname, O_RDONLY, 0); if (fd == -1) return; buf = map_file(fd, len, MAX_MAP_SIZE, CSUM_CHUNK); switch (checksum_type) { case CSUM_MD5: md5_begin(&m); for (i = 0; i + CSUM_CHUNK <= len; i += CSUM_CHUNK) { md5_update(&m, (uchar *)map_ptr(buf, i, CSUM_CHUNK), CSUM_CHUNK); } remainder = (int32)(len - i); if (remainder > 0) md5_update(&m, (uchar *)map_ptr(buf, i, remainder), remainder); md5_result(&m, (uchar *)sum); break; case CSUM_MD4: case CSUM_MD4_OLD: case CSUM_MD4_BUSTED: case CSUM_MD4_ARCHAIC: mdfour_begin(&m); for (i = 0; i + CSUM_CHUNK <= len; i += CSUM_CHUNK) { mdfour_update(&m, (uchar *)map_ptr(buf, i, CSUM_CHUNK), CSUM_CHUNK); } /* Prior to version 27 an incorrect MD4 checksum was computed * by failing to call mdfour_tail() for block sizes that * are multiples of 64. This is fixed by calling mdfour_update() * even when there are no more bytes. */ remainder = (int32)(len - i); if (remainder > 0 || checksum_type > CSUM_MD4_BUSTED) mdfour_update(&m, (uchar *)map_ptr(buf, i, remainder), remainder); mdfour_result(&m, (uchar *)sum); break; default: rprintf(FERROR, "invalid checksum-choice for the --checksum option (%d)\n", checksum_type); exit_cleanup(RERR_UNSUPPORTED); } close(fd); unmap_file(buf); }
CWE-354
1,627
12,075
125851622096369313077256581406942981019
null
null
null
samba
c252546ceeb0925eb8a4061315e3ff0a8c55b48b
0
uint32 get_checksum1(char *buf1, int32 len) { int32 i; uint32 s1, s2; schar *buf = (schar *)buf1; s1 = s2 = 0; for (i = 0; i < (len-4); i+=4) { s2 += 4*(s1 + buf[i]) + 3*buf[i+1] + 2*buf[i+2] + buf[i+3] + 10*CHAR_OFFSET; s1 += (buf[i+0] + buf[i+1] + buf[i+2] + buf[i+3] + 4*CHAR_OFFSET); } for (; i < len; i++) { s1 += (buf[i]+CHAR_OFFSET); s2 += s1; } return (s1 & 0xffff) + (s2 << 16); }
CWE-354
1,628
12,076
75301084342273088445897954182390986616
null
null
null
samba
c252546ceeb0925eb8a4061315e3ff0a8c55b48b
0
void get_checksum2(char *buf, int32 len, char *sum) { md_context m; switch (xfersum_type) { case CSUM_MD5: { uchar seedbuf[4]; md5_begin(&m); if (proper_seed_order) { if (checksum_seed) { SIVALu(seedbuf, 0, checksum_seed); md5_update(&m, seedbuf, 4); } md5_update(&m, (uchar *)buf, len); } else { md5_update(&m, (uchar *)buf, len); if (checksum_seed) { SIVALu(seedbuf, 0, checksum_seed); md5_update(&m, seedbuf, 4); } } md5_result(&m, (uchar *)sum); break; } case CSUM_MD4: case CSUM_MD4_OLD: case CSUM_MD4_BUSTED: case CSUM_MD4_ARCHAIC: { int32 i; static char *buf1; static int32 len1; mdfour_begin(&m); if (len > len1) { if (buf1) free(buf1); buf1 = new_array(char, len+4); len1 = len; if (!buf1) out_of_memory("get_checksum2"); } memcpy(buf1, buf, len); if (checksum_seed) { SIVAL(buf1,len,checksum_seed); len += 4; } for (i = 0; i + CSUM_CHUNK <= len; i += CSUM_CHUNK) mdfour_update(&m, (uchar *)(buf1+i), CSUM_CHUNK); /* * Prior to version 27 an incorrect MD4 checksum was computed * by failing to call mdfour_tail() for block sizes that * are multiples of 64. This is fixed by calling mdfour_update() * even when there are no more bytes. */ if (len - i > 0 || xfersum_type > CSUM_MD4_BUSTED) mdfour_update(&m, (uchar *)(buf1+i), len-i); mdfour_result(&m, (uchar *)sum); break; } } }
CWE-354
1,629
12,077
216789401715292631631057693303234238765
null
null
null
samba
c252546ceeb0925eb8a4061315e3ff0a8c55b48b
0
int parse_checksum_choice(void) { char *cp = checksum_choice ? strchr(checksum_choice, ',') : NULL; if (cp) { xfersum_type = parse_csum_name(checksum_choice, cp - checksum_choice); checksum_type = parse_csum_name(cp+1, -1); } else xfersum_type = checksum_type = parse_csum_name(checksum_choice, -1); return xfersum_type == CSUM_NONE; }
CWE-354
1,630
12,078
249283556742817677152189937615542868134
null
null
null
samba
c252546ceeb0925eb8a4061315e3ff0a8c55b48b
0
int sum_end(char *sum) { switch (cursum_type) { case CSUM_MD5: md5_result(&md, (uchar *)sum); break; case CSUM_MD4: case CSUM_MD4_OLD: mdfour_update(&md, (uchar *)md.buffer, sumresidue); mdfour_result(&md, (uchar *)sum); break; case CSUM_MD4_BUSTED: case CSUM_MD4_ARCHAIC: if (sumresidue) mdfour_update(&md, (uchar *)md.buffer, sumresidue); mdfour_result(&md, (uchar *)sum); break; case CSUM_NONE: *sum = '\0'; break; } return csum_len_for_type(cursum_type); }
CWE-354
1,632
12,079
255945702532498951347498828520560436124
null
null
null
samba
c252546ceeb0925eb8a4061315e3ff0a8c55b48b
0
void sum_init(int csum_type, int seed) { char s[4]; if (csum_type < 0) csum_type = parse_csum_name(NULL, 0); cursum_type = csum_type; switch (csum_type) { case CSUM_MD5: md5_begin(&md); break; case CSUM_MD4: mdfour_begin(&md); sumresidue = 0; break; case CSUM_MD4_OLD: case CSUM_MD4_BUSTED: case CSUM_MD4_ARCHAIC: mdfour_begin(&md); sumresidue = 0; SIVAL(s, 0, seed); sum_update(s, 4); break; case CSUM_NONE: break; } }
CWE-354
1,633
12,080
225860520762941986021746965894306421820
null
null
null
samba
9a480deec4d20277d8e20bc55515ef0640ca1e55
0
void base64_encode(const char *buf, int len, char *out, int pad) { char *b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; int bit_offset, byte_offset, idx, i; const uchar *d = (const uchar *)buf; int bytes = (len*8 + 5)/6; for (i = 0; i < bytes; i++) { byte_offset = (i*6)/8; bit_offset = (i*6)%8; if (bit_offset < 3) { idx = (d[byte_offset] >> (2-bit_offset)) & 0x3F; } else { idx = (d[byte_offset] << (bit_offset-2)) & 0x3F; if (byte_offset+1 < len) { idx |= (d[byte_offset+1] >> (8-(bit_offset-2))); } } out[i] = b64[idx]; } while (pad && (i % 4)) out[i++] = '='; out[i] = '\0'; }
CWE-354
1,635
12,081
156429485937035668065782155173923924000
null
null
null
samba
9a480deec4d20277d8e20bc55515ef0640ca1e55
0
static const char *check_secret(int module, const char *user, const char *group, const char *challenge, const char *pass) { char line[1024]; char pass2[MAX_DIGEST_LEN*2]; const char *fname = lp_secrets_file(module); STRUCT_STAT st; int ok = 1; int user_len = strlen(user); int group_len = group ? strlen(group) : 0; char *err; FILE *fh; if (!fname || !*fname || (fh = fopen(fname, "r")) == NULL) return "no secrets file"; if (do_fstat(fileno(fh), &st) == -1) { rsyserr(FLOG, errno, "fstat(%s)", fname); ok = 0; } else if (lp_strict_modes(module)) { if ((st.st_mode & 06) != 0) { rprintf(FLOG, "secrets file must not be other-accessible (see strict modes option)\n"); ok = 0; } else if (MY_UID() == 0 && st.st_uid != 0) { rprintf(FLOG, "secrets file must be owned by root when running as root (see strict modes)\n"); ok = 0; } } if (!ok) { fclose(fh); return "ignoring secrets file"; } if (*user == '#') { /* Reject attempt to match a comment. */ fclose(fh); return "invalid username"; } /* Try to find a line that starts with the user (or @group) name and a ':'. */ err = "secret not found"; while ((user || group) && fgets(line, sizeof line, fh) != NULL) { const char **ptr, *s = strtok(line, "\n\r"); int len; if (!s) continue; if (*s == '@') { ptr = &group; len = group_len; s++; } else { ptr = &user; len = user_len; } if (!*ptr || strncmp(s, *ptr, len) != 0 || s[len] != ':') continue; generate_hash(s+len+1, challenge, pass2); if (strcmp(pass, pass2) == 0) { err = NULL; break; } err = "password mismatch"; *ptr = NULL; /* Don't look for name again. */ } fclose(fh); memset(line, 0, sizeof line); memset(pass2, 0, sizeof pass2); return err; }
CWE-354
1,636
12,082
317736770002059934584799942310156611753
null
null
null
samba
9a480deec4d20277d8e20bc55515ef0640ca1e55
0
static void gen_challenge(const char *addr, char *challenge) { char input[32]; char digest[MAX_DIGEST_LEN]; struct timeval tv; int len; memset(input, 0, sizeof input); strlcpy(input, addr, 17); sys_gettimeofday(&tv); SIVAL(input, 16, tv.tv_sec); SIVAL(input, 20, tv.tv_usec); SIVAL(input, 24, getpid()); sum_init(-1, 0); sum_update(input, sizeof input); len = sum_end(digest); base64_encode(digest, len, challenge, 0); }
CWE-354
1,637
12,083
248953918681498324475105758460278862206
null
null
null
samba
9a480deec4d20277d8e20bc55515ef0640ca1e55
0
static const char *getpassf(const char *filename) { STRUCT_STAT st; char buffer[512], *p; int n; if (!filename) return NULL; if (strcmp(filename, "-") == 0) { n = fgets(buffer, sizeof buffer, stdin) == NULL ? -1 : (int)strlen(buffer); } else { int fd; if ((fd = open(filename,O_RDONLY)) < 0) { rsyserr(FERROR, errno, "could not open password file %s", filename); exit_cleanup(RERR_SYNTAX); } if (do_stat(filename, &st) == -1) { rsyserr(FERROR, errno, "stat(%s)", filename); exit_cleanup(RERR_SYNTAX); } if ((st.st_mode & 06) != 0) { rprintf(FERROR, "ERROR: password file must not be other-accessible\n"); exit_cleanup(RERR_SYNTAX); } if (MY_UID() == 0 && st.st_uid != 0) { rprintf(FERROR, "ERROR: password file must be owned by root when running as root\n"); exit_cleanup(RERR_SYNTAX); } n = read(fd, buffer, sizeof buffer - 1); close(fd); } if (n > 0) { buffer[n] = '\0'; if ((p = strtok(buffer, "\n\r")) != NULL) return strdup(p); } rprintf(FERROR, "ERROR: failed to read a password from %s\n", filename); exit_cleanup(RERR_SYNTAX); }
CWE-354
1,639
12,084
285202233814914333346643644926078196798
null
null
null
samba
7b8a4ecd6ff9cdf4e5d3850ebf822f1e989255b3
0
void sum_update(const char *p, int32 len) { switch (cursum_type) { case CSUM_MD5: md5_update(&md, (uchar *)p, len); break; case CSUM_MD4: case CSUM_MD4_OLD: case CSUM_MD4_BUSTED: if (len + sumresidue < CSUM_CHUNK) { memcpy(md.buffer + sumresidue, p, len); sumresidue += len; break; } if (sumresidue) { int32 i = CSUM_CHUNK - sumresidue; memcpy(md.buffer + sumresidue, p, i); mdfour_update(&md, (uchar *)md.buffer, CSUM_CHUNK); len -= i; p += i; } while (len >= CSUM_CHUNK) { mdfour_update(&md, (uchar *)p, CSUM_CHUNK); len -= CSUM_CHUNK; p += CSUM_CHUNK; } sumresidue = len; if (sumresidue) memcpy(md.buffer, p, sumresidue); break; case CSUM_NONE: break; } }
CWE-354
1,640
12,085
322981719133908545030550916035933937828
null
null
null
busybox
0402cb32df015d9372578e3db27db47b33d5c7b0
0
void FAST_FUNC dealloc_bunzip(bunzip_data *bd) { free(bd->dbuf); free(bd); }
CWE-190
1,784
12,210
42695764464792534787323047321870578931
null
null
null
busybox
0402cb32df015d9372578e3db27db47b33d5c7b0
0
static unsigned get_bits(bunzip_data *bd, int bits_wanted) { unsigned bits = 0; /* Cache bd->inbufBitCount in a CPU register (hopefully): */ int bit_count = bd->inbufBitCount; /* If we need to get more data from the byte buffer, do so. (Loop getting one byte at a time to enforce endianness and avoid unaligned access.) */ while (bit_count < bits_wanted) { /* If we need to read more data from file into byte buffer, do so */ if (bd->inbufPos == bd->inbufCount) { /* if "no input fd" case: in_fd == -1, read fails, we jump */ bd->inbufCount = read(bd->in_fd, bd->inbuf, IOBUF_SIZE); if (bd->inbufCount <= 0) longjmp(bd->jmpbuf, RETVAL_UNEXPECTED_INPUT_EOF); bd->inbufPos = 0; } /* Avoid 32-bit overflow (dump bit buffer to top of output) */ if (bit_count >= 24) { bits = bd->inbufBits & ((1U << bit_count) - 1); bits_wanted -= bit_count; bits <<= bits_wanted; bit_count = 0; } /* Grab next 8 bits of input from buffer. */ bd->inbufBits = (bd->inbufBits << 8) | bd->inbuf[bd->inbufPos++]; bit_count += 8; } /* Calculate result */ bit_count -= bits_wanted; bd->inbufBitCount = bit_count; bits |= (bd->inbufBits >> bit_count) & ((1 << bits_wanted) - 1); return bits; }
CWE-190
1,785
12,211
95319439832710438980001681636021693776
null
null
null
busybox
0402cb32df015d9372578e3db27db47b33d5c7b0
0
int main(int argc, char **argv) { char c; int i = unpack_bz2_stream(0, 1); if (i < 0) fprintf(stderr, "%s\n", bunzip_errors[-i]); else if (read(STDIN_FILENO, &c, 1)) fprintf(stderr, "Trailing garbage ignored\n"); return -i; }
CWE-190
1,786
12,212
33355958527536991021520976777995402932
null
null
null
busybox
0402cb32df015d9372578e3db27db47b33d5c7b0
0
int FAST_FUNC read_bunzip(bunzip_data *bd, char *outbuf, int len) { const uint32_t *dbuf; int pos, current, previous; uint32_t CRC; /* If we already have error/end indicator, return it */ if (bd->writeCount < 0) return bd->writeCount; dbuf = bd->dbuf; /* Register-cached state (hopefully): */ pos = bd->writePos; current = bd->writeCurrent; CRC = bd->writeCRC; /* small loss on x86-32 (not enough regs), win on x86-64 */ /* We will always have pending decoded data to write into the output buffer unless this is the very first call (in which case we haven't Huffman-decoded a block into the intermediate buffer yet). */ if (bd->writeCopies) { dec_writeCopies: /* Inside the loop, writeCopies means extra copies (beyond 1) */ --bd->writeCopies; /* Loop outputting bytes */ for (;;) { /* If the output buffer is full, save cached state and return */ if (--len < 0) { /* Unlikely branch. * Use of "goto" instead of keeping code here * helps compiler to realize this. */ goto outbuf_full; } /* Write next byte into output buffer, updating CRC */ *outbuf++ = current; CRC = (CRC << 8) ^ bd->crc32Table[(CRC >> 24) ^ current]; /* Loop now if we're outputting multiple copies of this byte */ if (bd->writeCopies) { /* Unlikely branch */ /*--bd->writeCopies;*/ /*continue;*/ /* Same, but (ab)using other existing --writeCopies operation * (and this if() compiles into just test+branch pair): */ goto dec_writeCopies; } decode_next_byte: if (--bd->writeCount < 0) break; /* input block is fully consumed, need next one */ /* Follow sequence vector to undo Burrows-Wheeler transform */ previous = current; pos = dbuf[pos]; current = (uint8_t)pos; pos >>= 8; /* After 3 consecutive copies of the same byte, the 4th * is a repeat count. We count down from 4 instead * of counting up because testing for non-zero is faster */ if (--bd->writeRunCountdown != 0) { if (current != previous) bd->writeRunCountdown = 4; } else { /* Unlikely branch */ /* We have a repeated run, this byte indicates the count */ bd->writeCopies = current; current = previous; bd->writeRunCountdown = 5; /* Sometimes there are just 3 bytes (run length 0) */ if (!bd->writeCopies) goto decode_next_byte; /* Subtract the 1 copy we'd output anyway to get extras */ --bd->writeCopies; } } /* for(;;) */ /* Decompression of this input block completed successfully */ bd->writeCRC = CRC = ~CRC; bd->totalCRC = ((bd->totalCRC << 1) | (bd->totalCRC >> 31)) ^ CRC; /* If this block had a CRC error, force file level CRC error */ if (CRC != bd->headerCRC) { bd->totalCRC = bd->headerCRC + 1; return RETVAL_LAST_BLOCK; } } /* Refill the intermediate buffer by Huffman-decoding next block of input */ { int r = get_next_block(bd); if (r) { /* error/end */ bd->writeCount = r; return (r != RETVAL_LAST_BLOCK) ? r : len; } } CRC = ~0; pos = bd->writePos; current = bd->writeCurrent; goto decode_next_byte; outbuf_full: /* Output buffer is full, save cached state and return */ bd->writePos = pos; bd->writeCurrent = current; bd->writeCRC = CRC; bd->writeCopies++; return 0; }
CWE-190
1,787
12,213
217835509852794211828887391631518191788
null
null
null
busybox
0402cb32df015d9372578e3db27db47b33d5c7b0
0
int FAST_FUNC start_bunzip(bunzip_data **bdp, int in_fd, const void *inbuf, int len) { bunzip_data *bd; unsigned i; enum { BZh0 = ('B' << 24) + ('Z' << 16) + ('h' << 8) + '0', h0 = ('h' << 8) + '0', }; /* Figure out how much data to allocate */ i = sizeof(bunzip_data); if (in_fd != -1) i += IOBUF_SIZE; /* Allocate bunzip_data. Most fields initialize to zero. */ bd = *bdp = xzalloc(i); /* Setup input buffer */ bd->in_fd = in_fd; if (-1 == in_fd) { /* in this case, bd->inbuf is read-only */ bd->inbuf = (void*)inbuf; /* cast away const-ness */ } else { bd->inbuf = (uint8_t*)(bd + 1); memcpy(bd->inbuf, inbuf, len); } bd->inbufCount = len; /* Init the CRC32 table (big endian) */ crc32_filltable(bd->crc32Table, 1); /* Setup for I/O error handling via longjmp */ i = setjmp(bd->jmpbuf); if (i) return i; /* Ensure that file starts with "BZh['1'-'9']." */ /* Update: now caller verifies 1st two bytes, makes .gz/.bz2 * integration easier */ /* was: */ /* i = get_bits(bd, 32); */ /* if ((unsigned)(i - BZh0 - 1) >= 9) return RETVAL_NOT_BZIP_DATA; */ i = get_bits(bd, 16); if ((unsigned)(i - h0 - 1) >= 9) return RETVAL_NOT_BZIP_DATA; /* Fourth byte (ascii '1'-'9') indicates block size in units of 100k of uncompressed data. Allocate intermediate buffer for block. */ /* bd->dbufSize = 100000 * (i - BZh0); */ bd->dbufSize = 100000 * (i - h0); /* Cannot use xmalloc - may leak bd in NOFORK case! */ bd->dbuf = malloc_or_warn(bd->dbufSize * sizeof(bd->dbuf[0])); if (!bd->dbuf) { free(bd); xfunc_die(); } return RETVAL_OK; }
CWE-190
1,788
12,214
240914467626031312985603248330190337992
null
null
null
busybox
0402cb32df015d9372578e3db27db47b33d5c7b0
0
unpack_bz2_stream(transformer_state_t *xstate) { IF_DESKTOP(long long total_written = 0;) bunzip_data *bd; char *outbuf; int i; unsigned len; if (check_signature16(xstate, BZIP2_MAGIC)) return -1; outbuf = xmalloc(IOBUF_SIZE); len = 0; while (1) { /* "Process one BZ... stream" loop */ i = start_bunzip(&bd, xstate->src_fd, outbuf + 2, len); if (i == 0) { while (1) { /* "Produce some output bytes" loop */ i = read_bunzip(bd, outbuf, IOBUF_SIZE); if (i < 0) /* error? */ break; i = IOBUF_SIZE - i; /* number of bytes produced */ if (i == 0) /* EOF? */ break; if (i != transformer_write(xstate, outbuf, i)) { i = RETVAL_SHORT_WRITE; goto release_mem; } IF_DESKTOP(total_written += i;) } } if (i != RETVAL_LAST_BLOCK /* Observed case when i == RETVAL_OK: * "bzcat z.bz2", where "z.bz2" is a bzipped zero-length file * (to be exact, z.bz2 is exactly these 14 bytes: * 42 5a 68 39 17 72 45 38 50 90 00 00 00 00). */ && i != RETVAL_OK ) { bb_error_msg("bunzip error %d", i); break; } if (bd->headerCRC != bd->totalCRC) { bb_error_msg("CRC error"); break; } /* Successfully unpacked one BZ stream */ i = RETVAL_OK; /* Do we have "BZ..." after last processed byte? * pbzip2 (parallelized bzip2) produces such files. */ len = bd->inbufCount - bd->inbufPos; memcpy(outbuf, &bd->inbuf[bd->inbufPos], len); if (len < 2) { if (safe_read(xstate->src_fd, outbuf + len, 2 - len) != 2 - len) break; len = 2; } if (*(uint16_t*)outbuf != BZIP2_MAGIC) /* "BZ"? */ break; dealloc_bunzip(bd); len -= 2; } release_mem: dealloc_bunzip(bd); free(outbuf); return i ? i : IF_DESKTOP(total_written) + 0; }
CWE-190
1,789
12,215
88525178571536340812783402182057100670
null
null
null
libxfont
d11ee5886e9d9ec610051a206b135a4cdc1e09a0
0
BufCompressedSkip (BufFilePtr f, int bytes) { int c; while (bytes--) { c = BufFileGet(f); if (c == BUFFILEEOF) return BUFFILEEOF; } return 0; }
CWE-119
1,791
12,216
302053852644414366190049823985828632403
null
null
null
libxfont
d11ee5886e9d9ec610051a206b135a4cdc1e09a0
0
BufFilePushCompressed (BufFilePtr f) { int code; int maxbits; int hsize; CompressedFile *file; int extra; if ((BufFileGet(f) != (magic_header[0] & 0xFF)) || (BufFileGet(f) != (magic_header[1] & 0xFF))) { return 0; } code = BufFileGet (f); if (code == BUFFILEEOF) return 0; maxbits = code & BIT_MASK; if (maxbits > BITS || maxbits < 12) return 0; hsize = hsize_table[maxbits - 12]; extra = (1 << maxbits) * sizeof (char_type) + hsize * sizeof (unsigned short); file = malloc (sizeof (CompressedFile) + extra); if (!file) return 0; file->file = f; file->maxbits = maxbits; file->block_compress = code & BLOCK_MASK; file->maxmaxcode = 1 << file->maxbits; file->tab_suffix = (char_type *) &file[1]; file->tab_prefix = (unsigned short *) (file->tab_suffix + file->maxmaxcode); /* * As above, initialize the first 256 entries in the table. */ file->maxcode = MAXCODE(file->n_bits = INIT_BITS); for ( code = 255; code >= 0; code-- ) { file->tab_prefix[code] = 0; file->tab_suffix[code] = (char_type) code; } file->free_ent = ((file->block_compress) ? FIRST : 256 ); file->clear_flg = 0; file->offset = 0; file->size = 0; file->stackp = file->de_stack; bzero(file->buf, BITS); file->finchar = file->oldcode = getcode (file); if (file->oldcode != -1) *file->stackp++ = file->finchar; return BufFileCreate ((char *) file, BufCompressedFill, 0, BufCompressedSkip, BufCompressedClose); }
CWE-119
1,792
12,217
247278344235919819750145627448486585483
null
null
null
libxfont
d11ee5886e9d9ec610051a206b135a4cdc1e09a0
0
getcode(CompressedFile *file) { register code_int code; register int r_off, bits; register char_type *bp = file->buf; register BufFilePtr raw; if ( file->clear_flg > 0 || file->offset >= file->size || file->free_ent > file->maxcode ) { /* * If the next entry will be too big for the current code * size, then we must increase the size. This implies reading * a new buffer full, too. */ if ( file->free_ent > file->maxcode ) { file->n_bits++; if ( file->n_bits == file->maxbits ) file->maxcode = file->maxmaxcode; /* won't get any bigger now */ else file->maxcode = MAXCODE(file->n_bits); } if ( file->clear_flg > 0) { file->maxcode = MAXCODE (file->n_bits = INIT_BITS); file->clear_flg = 0; } bits = file->n_bits; raw = file->file; while (bits > 0 && (code = BufFileGet (raw)) != BUFFILEEOF) { *bp++ = code; --bits; } bp = file->buf; if (bits == file->n_bits) return -1; /* end of file */ file->size = file->n_bits - bits; file->offset = 0; /* Round size down to integral number of codes */ file->size = (file->size << 3) - (file->n_bits - 1); } r_off = file->offset; bits = file->n_bits; /* * Get to the first byte. */ bp += (r_off >> 3); r_off &= 7; /* Get first part (low order bits) */ #ifdef NO_UCHAR code = ((*bp++ >> r_off) & rmask[8 - r_off]) & 0xff; #else code = (*bp++ >> r_off); #endif /* NO_UCHAR */ bits -= (8 - r_off); r_off = 8 - r_off; /* now, offset into code word */ /* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */ if ( bits >= 8 ) { #ifdef NO_UCHAR code |= (*bp++ & 0xff) << r_off; #else code |= *bp++ << r_off; #endif /* NO_UCHAR */ r_off += 8; bits -= 8; } /* high order bits. */ code |= (*bp & rmask[bits]) << r_off; file->offset += file->n_bits; return code; }
CWE-119
1,793
12,218
48822413310210163837409194474513469280
null
null
null
libxfont
d11ee5886e9d9ec610051a206b135a4cdc1e09a0
0
main (int argc, char *argv[]) { BufFilePtr inputraw, input, output; int c; inputraw = BufFileOpenRead (0); input = BufFilePushCompressed (inputraw); output = BufFileOpenWrite (1); while ((c = BufFileGet (input)) != BUFFILEEOF) BufFilePut (c, output); BufFileClose (input, FALSE); BufFileClose (output, FALSE); return 0; }
CWE-119
1,794
12,219
26192463107185559799618258101848110285
null
null
null
musl
45ca5d3fcb6f874bf5ba55d0e9651cef68515395
0
int __lookup_name(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, int flags) { int cnt = 0, i, j; *canon = 0; if (name) { /* reject empty name and check len so it fits into temp bufs */ size_t l = strnlen(name, 255); if (l-1 >= 254) return EAI_NONAME; memcpy(canon, name, l+1); } /* Procedurally, a request for v6 addresses with the v4-mapped * flag set is like a request for unspecified family, followed * by filtering of the results. */ if (flags & AI_V4MAPPED) { if (family == AF_INET6) family = AF_UNSPEC; else flags -= AI_V4MAPPED; } /* Try each backend until there's at least one result. */ cnt = name_from_null(buf, name, family, flags); if (!cnt) cnt = name_from_numeric(buf, name, family); if (!cnt && !(flags & AI_NUMERICHOST)) { cnt = name_from_hosts(buf, canon, name, family); if (!cnt) cnt = name_from_dns_search(buf, canon, name, family); } if (cnt<=0) return cnt ? cnt : EAI_NONAME; /* Filter/transform results for v4-mapped lookup, if requested. */ if (flags & AI_V4MAPPED) { if (!(flags & AI_ALL)) { /* If any v6 results exist, remove v4 results. */ for (i=0; i<cnt && buf[i].family != AF_INET6; i++); if (i<cnt) { for (j=0; i<cnt; i++) { if (buf[i].family == AF_INET6) buf[j++] = buf[i]; } cnt = i = j; } } /* Translate any remaining v4 results to v6 */ for (i=0; i<cnt; i++) { if (buf[i].family != AF_INET) continue; memcpy(buf[i].addr+12, buf[i].addr, 4); memcpy(buf[i].addr, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12); buf[i].family = AF_INET6; } } /* No further processing is needed if there are fewer than 2 * results or if there are only IPv4 results. */ if (cnt<2 || family==AF_INET) return cnt; for (i=0; i<cnt; i++) if (buf[i].family != AF_INET) break; if (i==cnt) return cnt; int cs; pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); /* The following implements a subset of RFC 3484/6724 destination * address selection by generating a single 31-bit sort key for * each address. Rules 3, 4, and 7 are omitted for having * excessive runtime and code size cost and dubious benefit. * So far the label/precedence table cannot be customized. */ for (i=0; i<cnt; i++) { int key = 0; struct sockaddr_in6 sa, da = { .sin6_family = AF_INET6, .sin6_scope_id = buf[i].scopeid, .sin6_port = 65535 }; if (buf[i].family == AF_INET6) { memcpy(da.sin6_addr.s6_addr, buf[i].addr, 16); } else { memcpy(da.sin6_addr.s6_addr, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12); memcpy(da.sin6_addr.s6_addr+12, buf[i].addr, 4); } const struct policy *dpolicy = policyof(&da.sin6_addr); int dscope = scopeof(&da.sin6_addr); int dlabel = dpolicy->label; int dprec = dpolicy->prec; int prefixlen = 0; int fd = socket(AF_INET6, SOCK_DGRAM|SOCK_CLOEXEC, IPPROTO_UDP); if (fd >= 0) { if (!connect(fd, (void *)&da, sizeof da)) { key |= DAS_USABLE; if (!getsockname(fd, (void *)&sa, &(socklen_t){sizeof sa})) { if (dscope == scopeof(&sa.sin6_addr)) key |= DAS_MATCHINGSCOPE; if (dlabel == labelof(&sa.sin6_addr)) key |= DAS_MATCHINGLABEL; prefixlen = prefixmatch(&sa.sin6_addr, &da.sin6_addr); } } close(fd); } key |= dprec << DAS_PREC_SHIFT; key |= (15-dscope) << DAS_SCOPE_SHIFT; key |= prefixlen << DAS_PREFIX_SHIFT; key |= (MAXADDRS-i) << DAS_ORDER_SHIFT; buf[i].sortkey = key; } qsort(buf, cnt, sizeof *buf, addrcmp); pthread_setcancelstate(cs, 0); return cnt; }
CWE-119
1,795
12,220
200365439700952797001557974460319740834
null
null
null
musl
45ca5d3fcb6f874bf5ba55d0e9651cef68515395
0
static int addrcmp(const void *_a, const void *_b) { const struct address *a = _a, *b = _b; return b->sortkey - a->sortkey; }
CWE-119
1,796
12,221
292020200667436166637652860087811277816
null
null
null
musl
45ca5d3fcb6f874bf5ba55d0e9651cef68515395
0
static int is_valid_hostname(const char *host) { const unsigned char *s; if (strnlen(host, 255)-1 >= 254 || mbstowcs(0, host, 0) == -1) return 0; for (s=(void *)host; *s>=0x80 || *s=='.' || *s=='-' || isalnum(*s); s++); return !*s; }
CWE-119
1,797
12,222
149073162664376748407524687518669694601
null
null
null
musl
45ca5d3fcb6f874bf5ba55d0e9651cef68515395
0
static int labelof(const struct in6_addr *a) { return policyof(a)->label; }
CWE-119
1,798
12,223
262884113923693245496411351083300121166
null
null
null
musl
45ca5d3fcb6f874bf5ba55d0e9651cef68515395
0
static int name_from_dns(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, const struct resolvconf *conf) { unsigned char qbuf[2][280], abuf[2][512]; const unsigned char *qp[2] = { qbuf[0], qbuf[1] }; unsigned char *ap[2] = { abuf[0], abuf[1] }; int qlens[2], alens[2]; int i, nq = 0; struct dpc_ctx ctx = { .addrs = buf, .canon = canon }; static const struct { int af; int rr; } afrr[2] = { { .af = AF_INET6, .rr = RR_A }, { .af = AF_INET, .rr = RR_AAAA }, }; for (i=0; i<2; i++) { if (family != afrr[i].af) { qlens[nq] = __res_mkquery(0, name, 1, afrr[i].rr, 0, 0, 0, qbuf[nq], sizeof *qbuf); if (qlens[nq] == -1) return EAI_NONAME; nq++; } } if (__res_msend_rc(nq, qp, qlens, ap, alens, sizeof *abuf, conf) < 0) return EAI_SYSTEM; for (i=0; i<nq; i++) __dns_parse(abuf[i], alens[i], dns_parse_callback, &ctx); if (ctx.cnt) return ctx.cnt; if (alens[0] < 4 || (abuf[0][3] & 15) == 2) return EAI_AGAIN; if ((abuf[0][3] & 15) == 0) return EAI_NONAME; if ((abuf[0][3] & 15) == 3) return 0; return EAI_FAIL; }
CWE-119
1,799
12,224
15482331650705493209005847849126464953
null
null
null
musl
45ca5d3fcb6f874bf5ba55d0e9651cef68515395
0
static int name_from_dns_search(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family) { char search[256]; struct resolvconf conf; size_t l, dots; char *p, *z; if (__get_resolv_conf(&conf, search, sizeof search) < 0) return -1; /* Count dots, suppress search when >=ndots or name ends in * a dot, which is an explicit request for global scope. */ for (dots=l=0; name[l]; l++) if (name[l]=='.') dots++; if (dots >= conf.ndots || name[l-1]=='.') *search = 0; /* This can never happen; the caller already checked length. */ if (l >= 256) return EAI_NONAME; /* Name with search domain appended is setup in canon[]. This both * provides the desired default canonical name (if the requested * name is not a CNAME record) and serves as a buffer for passing * the full requested name to name_from_dns. */ memcpy(canon, name, l); canon[l] = '.'; for (p=search; *p; p=z) { for (; isspace(*p); p++); for (z=p; *z && !isspace(*z); z++); if (z==p) break; if (z-p < 256 - l - 1) { memcpy(canon+l+1, p, z-p); canon[z-p+1+l] = 0; int cnt = name_from_dns(buf, canon, canon, family, &conf); if (cnt) return cnt; } } canon[l] = 0; return name_from_dns(buf, canon, name, family, &conf); }
CWE-119
1,800
12,225
205784671568015793796369126368739620601
null
null
null
musl
45ca5d3fcb6f874bf5ba55d0e9651cef68515395
0
static int name_from_hosts(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family) { char line[512]; size_t l = strlen(name); int cnt = 0, badfam = 0; unsigned char _buf[1032]; FILE _f, *f = __fopen_rb_ca("/etc/hosts", &_f, _buf, sizeof _buf); if (!f) switch (errno) { case ENOENT: case ENOTDIR: case EACCES: return 0; default: return EAI_SYSTEM; } while (fgets(line, sizeof line, f) && cnt < MAXADDRS) { char *p, *z; if ((p=strchr(line, '#'))) *p++='\n', *p=0; for(p=line+1; (p=strstr(p, name)) && (!isspace(p[-1]) || !isspace(p[l])); p++); if (!p) continue; /* Isolate IP address to parse */ for (p=line; *p && !isspace(*p); p++); *p++ = 0; switch (name_from_numeric(buf+cnt, line, family)) { case 1: cnt++; break; case 0: continue; default: badfam = EAI_NONAME; continue; } /* Extract first name as canonical name */ for (; *p && isspace(*p); p++); for (z=p; *z && !isspace(*z); z++); *z = 0; if (is_valid_hostname(p)) memcpy(canon, p, z-p+1); } __fclose_ca(f); return cnt ? cnt : badfam; }
CWE-119
1,801
12,226
322706795451264161236274702689395869582
null
null
null
musl
45ca5d3fcb6f874bf5ba55d0e9651cef68515395
0
static int name_from_null(struct address buf[static 2], const char *name, int family, int flags) { int cnt = 0; if (name) return 0; if (flags & AI_PASSIVE) { if (family != AF_INET6) buf[cnt++] = (struct address){ .family = AF_INET }; if (family != AF_INET) buf[cnt++] = (struct address){ .family = AF_INET6 }; } else { if (family != AF_INET6) buf[cnt++] = (struct address){ .family = AF_INET, .addr = { 127,0,0,1 } }; if (family != AF_INET) buf[cnt++] = (struct address){ .family = AF_INET6, .addr = { [15] = 1 } }; } return cnt; }
CWE-119
1,802
12,227
39702672038737886146018878129279966692
null
null
null
musl
45ca5d3fcb6f874bf5ba55d0e9651cef68515395
0
static int name_from_numeric(struct address buf[static 1], const char *name, int family) { return __lookup_ipliteral(buf, name, family); }
CWE-119
1,803
12,228
177723214161727152381782996110477828095
null
null
null
musl
45ca5d3fcb6f874bf5ba55d0e9651cef68515395
0
static const struct policy *policyof(const struct in6_addr *a) { int i; for (i=0; ; i++) { if (memcmp(a->s6_addr, defpolicy[i].addr, defpolicy[i].len)) continue; if ((a->s6_addr[defpolicy[i].len] & defpolicy[i].mask) != defpolicy[i].addr[defpolicy[i].len]) continue; return defpolicy+i; } }
CWE-119
1,804
12,229
121000894085908288265803060601244817434
null
null
null
musl
45ca5d3fcb6f874bf5ba55d0e9651cef68515395
0
static int prefixmatch(const struct in6_addr *s, const struct in6_addr *d) { /* FIXME: The common prefix length should be limited to no greater * than the nominal length of the prefix portion of the source * address. However the definition of the source prefix length is * not clear and thus this limiting is not yet implemented. */ unsigned i; for (i=0; i<128 && !((s->s6_addr[i/8]^d->s6_addr[i/8])&(128>>(i%8))); i++); return i; }
CWE-119
1,805
12,230
213254517245134962808942112451398646393
null
null
null
musl
45ca5d3fcb6f874bf5ba55d0e9651cef68515395
0
static int scopeof(const struct in6_addr *a) { if (IN6_IS_ADDR_MULTICAST(a)) return a->s6_addr[1] & 15; if (IN6_IS_ADDR_LINKLOCAL(a)) return 2; if (IN6_IS_ADDR_LOOPBACK(a)) return 2; if (IN6_IS_ADDR_SITELOCAL(a)) return 5; return 14; }
CWE-119
1,806
12,231
142913441971814040765242107285171074518
null
null
null
systemd
505b6a61c22d5565e9308045c7b9bf79f7d0517e
0
int server_open_native_socket(Server*s) { union sockaddr_union sa; int one, r; struct epoll_event ev; assert(s); if (s->native_fd < 0) { s->native_fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0); if (s->native_fd < 0) { log_error("socket() failed: %m"); return -errno; } zero(sa); sa.un.sun_family = AF_UNIX; strncpy(sa.un.sun_path, "/run/systemd/journal/socket", sizeof(sa.un.sun_path)); unlink(sa.un.sun_path); r = bind(s->native_fd, &sa.sa, offsetof(union sockaddr_union, un.sun_path) + strlen(sa.un.sun_path)); if (r < 0) { log_error("bind() failed: %m"); return -errno; } chmod(sa.un.sun_path, 0666); } else fd_nonblock(s->native_fd, 1); one = 1; r = setsockopt(s->native_fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one)); if (r < 0) { log_error("SO_PASSCRED failed: %m"); return -errno; } #ifdef HAVE_SELINUX one = 1; r = setsockopt(s->syslog_fd, SOL_SOCKET, SO_PASSSEC, &one, sizeof(one)); if (r < 0) log_warning("SO_PASSSEC failed: %m"); #endif one = 1; r = setsockopt(s->native_fd, SOL_SOCKET, SO_TIMESTAMP, &one, sizeof(one)); if (r < 0) { log_error("SO_TIMESTAMP failed: %m"); return -errno; } zero(ev); ev.events = EPOLLIN; ev.data.fd = s->native_fd; if (epoll_ctl(s->epoll_fd, EPOLL_CTL_ADD, s->native_fd, &ev) < 0) { log_error("Failed to add native server fd to epoll object: %m"); return -errno; } return 0; }
CWE-189
1,816
12,240
314078961588913607644187327514464798908
null
null
null
systemd
505b6a61c22d5565e9308045c7b9bf79f7d0517e
0
void server_process_native_file( Server *s, int fd, struct ucred *ucred, struct timeval *tv, const char *label, size_t label_len) { struct stat st; void *p; ssize_t n; assert(s); assert(fd >= 0); /* Data is in the passed file, since it didn't fit in a * datagram. We can't map the file here, since clients might * then truncate it and trigger a SIGBUS for us. So let's * stupidly read it */ if (fstat(fd, &st) < 0) { log_error("Failed to stat passed file, ignoring: %m"); return; } if (!S_ISREG(st.st_mode)) { log_error("File passed is not regular. Ignoring."); return; } if (st.st_size <= 0) return; if (st.st_size > ENTRY_SIZE_MAX) { log_error("File passed too large. Ignoring."); return; } p = malloc(st.st_size); if (!p) { log_oom(); return; } n = pread(fd, p, st.st_size, 0); if (n < 0) log_error("Failed to read file, ignoring: %s", strerror(-n)); else if (n > 0) server_process_native_message(s, p, n, ucred, tv, label, label_len); free(p); }
CWE-189
1,817
12,241
217414656947684375370894011532563797720
null
null
null
systemd
505b6a61c22d5565e9308045c7b9bf79f7d0517e
0
static bool valid_user_field(const char *p, size_t l) { const char *a; /* We kinda enforce POSIX syntax recommendations for environment variables here, but make a couple of additional requirements. http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap08.html */ /* No empty field names */ if (l <= 0) return false; /* Don't allow names longer than 64 chars */ if (l > 64) return false; /* Variables starting with an underscore are protected */ if (p[0] == '_') return false; /* Don't allow digits as first character */ if (p[0] >= '0' && p[0] <= '9') return false; /* Only allow A-Z0-9 and '_' */ for (a = p; a < p + l; a++) if (!((*a >= 'A' && *a <= 'Z') || (*a >= '0' && *a <= '9') || *a == '_')) return false; return true; }
CWE-189
1,818
12,242
22236268475283663439700313919588633857
null
null
null
ghostscript
97096297d409ec6f206298444ba00719607e8ba8
0
copy_resource(fz_context *ctx, pdf_filter_processor *p, pdf_obj *key, const char *name) { pdf_obj *res, *obj; if (!name || name[0] == 0) return; res = pdf_dict_get(ctx, p->old_rdb, key); obj = pdf_dict_gets(ctx, res, name); if (obj) { res = pdf_dict_get(ctx, p->new_rdb, key); if (!res) { res = pdf_new_dict(ctx, pdf_get_bound_document(ctx, p->new_rdb), 1); pdf_dict_put_drop(ctx, p->new_rdb, key, res); } pdf_dict_putp(ctx, res, name, obj); } }
CWE-125
1,819
12,243
291869710006976599325913880959328590745
null
null
null
ghostscript
97096297d409ec6f206298444ba00719607e8ba8
0
static void filter_flush(fz_context *ctx, pdf_filter_processor *p, int flush) { filter_gstate *gstate = gstate_to_update(ctx, p); int i; if (gstate->pushed == 0) { gstate->pushed = 1; if (p->chain->op_q) p->chain->op_q(ctx, p->chain); } if (flush) flush_tags(ctx, p, &p->pending_tags); if (flush & FLUSH_CTM) { if (gstate->pending.ctm.a != 1 || gstate->pending.ctm.b != 0 || gstate->pending.ctm.c != 0 || gstate->pending.ctm.d != 1 || gstate->pending.ctm.e != 0 || gstate->pending.ctm.f != 0) { fz_matrix current = gstate->sent.ctm; if (p->chain->op_cm) p->chain->op_cm(ctx, p->chain, gstate->pending.ctm.a, gstate->pending.ctm.b, gstate->pending.ctm.c, gstate->pending.ctm.d, gstate->pending.ctm.e, gstate->pending.ctm.f); gstate->sent.ctm = fz_concat(current, gstate->pending.ctm); gstate->pending.ctm.a = 1; gstate->pending.ctm.b = 0; gstate->pending.ctm.c = 0; gstate->pending.ctm.d = 1; gstate->pending.ctm.e = 0; gstate->pending.ctm.f = 0; } } if (flush & FLUSH_COLOR_F) { if (gstate->pending.cs.cs == fz_device_gray(ctx) && !gstate->pending.sc.pat && !gstate->pending.sc.shd && gstate->pending.sc.n == 1 && (gstate->sent.cs.cs != fz_device_gray(ctx) || gstate->sent.sc.pat || gstate->sent.sc.shd || gstate->sent.sc.n != 1 || gstate->pending.sc.c[0] != gstate->sent.sc.c[0])) { if (p->chain->op_g) p->chain->op_g(ctx, p->chain, gstate->pending.sc.c[0]); goto done_sc; } if (gstate->pending.cs.cs == fz_device_rgb(ctx) && !gstate->pending.sc.pat && !gstate->pending.sc.shd && gstate->pending.sc.n == 3 && (gstate->sent.cs.cs != fz_device_rgb(ctx) || gstate->sent.sc.pat || gstate->sent.sc.shd || gstate->sent.sc.n != 3 || gstate->pending.sc.c[0] != gstate->sent.sc.c[0] || gstate->pending.sc.c[1] != gstate->sent.sc.c[1] || gstate->pending.sc.c[1] != gstate->sent.sc.c[1])) { if (p->chain->op_rg) p->chain->op_rg(ctx, p->chain, gstate->pending.sc.c[0], gstate->pending.sc.c[1], gstate->pending.sc.c[2]); goto done_sc; } if (gstate->pending.cs.cs == fz_device_cmyk(ctx) && !gstate->pending.sc.pat && !gstate->pending.sc.shd && gstate->pending.sc.n == 4 && (gstate->sent.cs.cs != fz_device_cmyk(ctx) || gstate->sent.sc.pat || gstate->sent.sc.shd || gstate->pending.sc.n != 4 || gstate->pending.sc.c[0] != gstate->sent.sc.c[0] || gstate->pending.sc.c[1] != gstate->sent.sc.c[1] || gstate->pending.sc.c[2] != gstate->sent.sc.c[2] || gstate->pending.sc.c[3] != gstate->sent.sc.c[3])) { if (p->chain->op_k) p->chain->op_k(ctx, p->chain, gstate->pending.sc.c[0], gstate->pending.sc.c[1], gstate->pending.sc.c[2], gstate->pending.sc.c[3]); goto done_sc; } if (strcmp(gstate->pending.cs.name, gstate->sent.cs.name)) { if (p->chain->op_cs) p->chain->op_cs(ctx, p->chain, gstate->pending.cs.name, gstate->pending.cs.cs); } /* pattern or shading */ if (gstate->pending.sc.name[0]) { int emit = 0; if (strcmp(gstate->pending.sc.name, gstate->sent.sc.name)) emit = 1; if (gstate->pending.sc.n != gstate->sent.sc.n) emit = 1; else for (i = 0; i < gstate->pending.sc.n; ++i) if (gstate->pending.sc.c[i] != gstate->sent.sc.c[i]) emit = 1; if (emit) { if (gstate->pending.sc.pat) if (p->chain->op_sc_pattern) p->chain->op_sc_pattern(ctx, p->chain, gstate->pending.sc.name, gstate->pending.sc.pat, gstate->pending.sc.n, gstate->pending.sc.c); if (gstate->pending.sc.shd) if (p->chain->op_sc_shade) p->chain->op_sc_shade(ctx, p->chain, gstate->pending.sc.name, gstate->pending.sc.shd); } } /* plain color */ else { int emit = 0; if (gstate->pending.sc.n != gstate->sent.sc.n) emit = 1; else for (i = 0; i < gstate->pending.sc.n; ++i) if (gstate->pending.sc.c[i] != gstate->sent.sc.c[i]) emit = 1; if (emit) { if (p->chain->op_sc_color) p->chain->op_sc_color(ctx, p->chain, gstate->pending.sc.n, gstate->pending.sc.c); } } done_sc: gstate->sent.cs = gstate->pending.cs; gstate->sent.sc = gstate->pending.sc; } if (flush & FLUSH_COLOR_S) { if (gstate->pending.CS.cs == fz_device_gray(ctx) && !gstate->pending.SC.pat && !gstate->pending.SC.shd && gstate->pending.SC.n == 1 && (gstate->sent.CS.cs != fz_device_gray(ctx) || gstate->sent.SC.pat || gstate->sent.SC.shd || gstate->sent.SC.n != 0 || gstate->pending.SC.c[0] != gstate->sent.SC.c[0])) { if (p->chain->op_G) p->chain->op_G(ctx, p->chain, gstate->pending.SC.c[0]); goto done_SC; } if (gstate->pending.CS.cs == fz_device_rgb(ctx) && !gstate->pending.SC.pat && !gstate->pending.SC.shd && gstate->pending.SC.n == 3 && (gstate->sent.CS.cs != fz_device_rgb(ctx) || gstate->sent.SC.pat || gstate->sent.SC.shd || gstate->sent.SC.n != 3 || gstate->pending.SC.c[0] != gstate->sent.SC.c[0] || gstate->pending.SC.c[1] != gstate->sent.SC.c[1] || gstate->pending.SC.c[1] != gstate->sent.SC.c[1])) { if (p->chain->op_RG) p->chain->op_RG(ctx, p->chain, gstate->pending.SC.c[0], gstate->pending.SC.c[1], gstate->pending.SC.c[2]); goto done_SC; } if (gstate->pending.CS.cs == fz_device_cmyk(ctx) && !gstate->pending.SC.pat && !gstate->pending.SC.shd && gstate->pending.SC.n == 4 && (gstate->sent.CS.cs != fz_device_cmyk(ctx) || gstate->sent.SC.pat || gstate->sent.SC.shd || gstate->pending.SC.n != 4 || gstate->pending.SC.c[0] != gstate->sent.SC.c[0] || gstate->pending.SC.c[1] != gstate->sent.SC.c[1] || gstate->pending.SC.c[2] != gstate->sent.SC.c[2] || gstate->pending.SC.c[3] != gstate->sent.SC.c[3])) { if (p->chain->op_K) p->chain->op_K(ctx, p->chain, gstate->pending.SC.c[0], gstate->pending.SC.c[1], gstate->pending.SC.c[2], gstate->pending.SC.c[3]); goto done_SC; } if (strcmp(gstate->pending.CS.name, gstate->sent.CS.name)) { if (p->chain->op_CS) p->chain->op_CS(ctx, p->chain, gstate->pending.CS.name, gstate->pending.CS.cs); } /* pattern or shading */ if (gstate->pending.SC.name[0]) { int emit = 0; if (strcmp(gstate->pending.SC.name, gstate->sent.SC.name)) emit = 1; if (gstate->pending.SC.n != gstate->sent.SC.n) emit = 1; else for (i = 0; i < gstate->pending.SC.n; ++i) if (gstate->pending.SC.c[i] != gstate->sent.SC.c[i]) emit = 1; if (emit) { if (gstate->pending.SC.pat) if (p->chain->op_SC_pattern) p->chain->op_SC_pattern(ctx, p->chain, gstate->pending.SC.name, gstate->pending.SC.pat, gstate->pending.SC.n, gstate->pending.SC.c); if (gstate->pending.SC.shd) if (p->chain->op_SC_shade) p->chain->op_SC_shade(ctx, p->chain, gstate->pending.SC.name, gstate->pending.SC.shd); } } /* plain color */ else { int emit = 0; if (gstate->pending.SC.n != gstate->sent.SC.n) emit = 1; else for (i = 0; i < gstate->pending.SC.n; ++i) if (gstate->pending.SC.c[i] != gstate->sent.SC.c[i]) emit = 1; if (emit) { if (p->chain->op_SC_color) p->chain->op_SC_color(ctx, p->chain, gstate->pending.SC.n, gstate->pending.SC.c); } } done_SC: gstate->sent.CS = gstate->pending.CS; gstate->sent.SC = gstate->pending.SC; } if (flush & FLUSH_STROKE) { if (gstate->pending.stroke.linecap != gstate->sent.stroke.linecap) { if (p->chain->op_J) p->chain->op_J(ctx, p->chain, gstate->pending.stroke.linecap); } if (gstate->pending.stroke.linejoin != gstate->sent.stroke.linejoin) { if (p->chain->op_j) p->chain->op_j(ctx, p->chain, gstate->pending.stroke.linejoin); } if (gstate->pending.stroke.linewidth != gstate->sent.stroke.linewidth) { if (p->chain->op_w) p->chain->op_w(ctx, p->chain, gstate->pending.stroke.linewidth); } if (gstate->pending.stroke.miterlimit != gstate->sent.stroke.miterlimit) { if (p->chain->op_M) p->chain->op_M(ctx, p->chain, gstate->pending.stroke.miterlimit); } gstate->sent.stroke = gstate->pending.stroke; } if (flush & FLUSH_TEXT) { if (p->BT_pending) { if (p->chain->op_BT) p->chain->op_BT(ctx, p->chain); p->BT_pending = 0; } if (gstate->pending.text.char_space != gstate->sent.text.char_space) { if (p->chain->op_Tc) p->chain->op_Tc(ctx, p->chain, gstate->pending.text.char_space); } if (gstate->pending.text.word_space != gstate->sent.text.word_space) { if (p->chain->op_Tw) p->chain->op_Tw(ctx, p->chain, gstate->pending.text.word_space); } if (gstate->pending.text.scale != gstate->sent.text.scale) { /* The value of scale in the gstate is divided by 100 from what is written in the file */ if (p->chain->op_Tz) p->chain->op_Tz(ctx, p->chain, gstate->pending.text.scale*100); } if (gstate->pending.text.leading != gstate->sent.text.leading) { if (p->chain->op_TL) p->chain->op_TL(ctx, p->chain, gstate->pending.text.leading); } if (gstate->pending.text.font != gstate->sent.text.font || gstate->pending.text.size != gstate->sent.text.size) { if (p->chain->op_Tf) p->chain->op_Tf(ctx, p->chain, p->font_name, gstate->pending.text.font, gstate->pending.text.size); } if (gstate->pending.text.render != gstate->sent.text.render) { if (p->chain->op_Tr) p->chain->op_Tr(ctx, p->chain, gstate->pending.text.render); } if (gstate->pending.text.rise != gstate->sent.text.rise) { if (p->chain->op_Ts) p->chain->op_Ts(ctx, p->chain, gstate->pending.text.rise); } pdf_drop_font(ctx, gstate->sent.text.font); gstate->sent.text = gstate->pending.text; gstate->sent.text.font = pdf_keep_font(ctx, gstate->pending.text.font); if (p->Tm_pending != 0) { if (p->chain->op_Tm) p->chain->op_Tm(ctx, p->chain, p->tos.tlm.a, p->tos.tlm.b, p->tos.tlm.c, p->tos.tlm.d, p->tos.tlm.e, p->tos.tlm.f); p->Tm_pending = 0; } } }
CWE-125
1,820
12,244
210079674866785920469403454579077267224
null
null
null
ghostscript
97096297d409ec6f206298444ba00719607e8ba8
0
filter_pop(fz_context *ctx, pdf_filter_processor *p) { filter_gstate *gstate = p->gstate; filter_gstate *old = gstate->next; /* We are at the top, so nothing to pop! */ if (old == NULL) return 1; if (gstate->pushed) if (p->chain->op_Q) p->chain->op_Q(ctx, p->chain); pdf_drop_font(ctx, gstate->pending.text.font); pdf_drop_font(ctx, gstate->sent.text.font); fz_free(ctx, gstate); p->gstate = old; return 0; }
CWE-125
1,821
12,245
215601006829918311182904724705453570839
null
null
null
ghostscript
97096297d409ec6f206298444ba00719607e8ba8
0
filter_push(fz_context *ctx, pdf_filter_processor *p) { filter_gstate *gstate = p->gstate; filter_gstate *new_gstate = fz_malloc_struct(ctx, filter_gstate); *new_gstate = *gstate; new_gstate->pushed = 0; new_gstate->next = gstate; p->gstate = new_gstate; pdf_keep_font(ctx, new_gstate->pending.text.font); pdf_keep_font(ctx, new_gstate->sent.text.font); }
CWE-125
1,822
12,246
310818860826799832971287594179285983067
null
null
null
ghostscript
97096297d409ec6f206298444ba00719607e8ba8
0
filter_show_char(fz_context *ctx, pdf_filter_processor *p, int cid, int *unicode) { filter_gstate *gstate = p->gstate; pdf_font_desc *fontdesc = gstate->pending.text.font; fz_matrix trm; int ucsbuf[8]; int ucslen; int remove = 0; (void)pdf_tos_make_trm(ctx, &p->tos, &gstate->pending.text, fontdesc, cid, &trm); ucslen = 0; if (fontdesc->to_unicode) ucslen = pdf_lookup_cmap_full(fontdesc->to_unicode, cid, ucsbuf); if (ucslen == 0 && (size_t)cid < fontdesc->cid_to_ucs_len) { ucsbuf[0] = fontdesc->cid_to_ucs[cid]; ucslen = 1; } if (ucslen == 0 || (ucslen == 1 && ucsbuf[0] == 0)) { ucsbuf[0] = FZ_REPLACEMENT_CHARACTER; ucslen = 1; } *unicode = ucsbuf[0]; if (p->text_filter) { fz_matrix ctm = fz_concat(gstate->sent.ctm, gstate->pending.ctm); fz_rect bbox; if (fontdesc->wmode == 0) { bbox.x0 = 0; bbox.y0 = fz_font_descender(ctx, fontdesc->font); bbox.x1 = fz_advance_glyph(ctx, fontdesc->font, p->tos.gid, 0); bbox.y1 = fz_font_ascender(ctx, fontdesc->font); } else { fz_rect font_bbox = fz_font_bbox(ctx, fontdesc->font); bbox.x0 = font_bbox.x0; bbox.x1 = font_bbox.x1; bbox.y0 = 0; bbox.y1 = fz_advance_glyph(ctx, fontdesc->font, p->tos.gid, 1); } remove = p->text_filter(ctx, p->opaque, ucsbuf, ucslen, trm, ctm, bbox); } pdf_tos_move_after_char(ctx, &p->tos); return remove; }
CWE-125
1,823
12,247
146336856554743256225995883893095816498
null
null
null
ghostscript
97096297d409ec6f206298444ba00719607e8ba8
0
filter_show_space(fz_context *ctx, pdf_filter_processor *p, float tadj) { filter_gstate *gstate = p->gstate; pdf_font_desc *fontdesc = gstate->pending.text.font; if (fontdesc->wmode == 0) p->tos.tm = fz_pre_translate(p->tos.tm, tadj * gstate->pending.text.scale, 0); else p->tos.tm = fz_pre_translate(p->tos.tm, 0, tadj); }
CWE-125
1,824
12,248
96070020756696015173706576538005908510
null
null
null
ghostscript
97096297d409ec6f206298444ba00719607e8ba8
0
static void flush_tags(fz_context *ctx, pdf_filter_processor *p, tag_record **tags) { tag_record *tag = *tags; if (tag == NULL) return; if (tag->prev) flush_tags(ctx, p, &tag->prev); if (tag->bdc) { if (p->chain->op_BDC) p->chain->op_BDC(ctx, p->chain, tag->tag, tag->raw, tag->cooked); } else if (p->chain->op_BMC) p->chain->op_BMC(ctx, p->chain, tag->tag); tag->prev = p->current_tags; p->current_tags = tag; *tags = NULL; }
CWE-125
1,825
12,249
28996447000906760727905495822828877951
null
null
null
ghostscript
97096297d409ec6f206298444ba00719607e8ba8
0
gstate_to_update(fz_context *ctx, pdf_filter_processor *p) { filter_gstate *gstate = p->gstate; /* If we're not the top, that's fine */ if (gstate->next != NULL) return gstate; /* We are the top. Push a group, so we're not */ filter_push(ctx, p); gstate = p->gstate; gstate->pushed = 1; if (p->chain->op_q) p->chain->op_q(ctx, p->chain); return p->gstate; }
CWE-125
1,826
12,250
304728457634007954937475005661353226783
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static char *addr_to_string(const char *format, struct sockaddr_storage *sa, socklen_t salen) { char *addr; char host[NI_MAXHOST]; char serv[NI_MAXSERV]; int err; size_t addrlen; if ((err = getnameinfo((struct sockaddr *)sa, salen, host, sizeof(host), serv, sizeof(serv), NI_NUMERICHOST | NI_NUMERICSERV)) != 0) { spice_warning("Cannot resolve address %d: %s", err, gai_strerror(err)); return NULL; } /* Enough for the existing format + the 2 vars we're * substituting in. */ addrlen = strlen(format) + strlen(host) + strlen(serv); addr = spice_malloc(addrlen + 1); snprintf(addr, addrlen, format, host, serv); addr[addrlen] = '\0'; return addr; }
CWE-119
1,827
12,251
193746454222605315184130404255541330550
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static inline void async_read_clear_handlers(AsyncRead *obj) { ssize_t ret; if (!s->sasl.encoded) { int err; err = sasl_encode(s->sasl.conn, (char *)buf, nbyte, (const char **)&s->sasl.encoded, &s->sasl.encodedLength); if (err != SASL_OK) { spice_warning("sasl_encode error: %d", err); return -1; } if (s->sasl.encodedLength == 0) { return 0; } if (!s->sasl.encoded) { spice_warning("sasl_encode didn't return a buffer!"); return 0; } s->sasl.encodedOffset = 0; } ret = s->write(s, s->sasl.encoded + s->sasl.encodedOffset, s->sasl.encodedLength - s->sasl.encodedOffset); if (ret <= 0) { return ret; } s->sasl.encodedOffset += ret; if (s->sasl.encodedOffset == s->sasl.encodedLength) { s->sasl.encoded = NULL; s->sasl.encodedOffset = s->sasl.encodedLength = 0; return nbyte; } /* we didn't flush the encoded buffer */ errno = EAGAIN; return -1; }
CWE-119
1,828
12,252
135053401401076418830194917042594073024
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void async_read_handler(int fd, int event, void *data) { AsyncRead *obj = (AsyncRead *)data; for (;;) { int n = obj->end - obj->now; spice_assert(n > 0); n = reds_stream_read(obj->stream, obj->now, n); if (n <= 0) { if (n < 0) { switch (errno) { case EAGAIN: if (!obj->stream->watch) { obj->stream->watch = core->watch_add(obj->stream->socket, SPICE_WATCH_EVENT_READ, async_read_handler, obj); } return; case EINTR: break; default: async_read_clear_handlers(obj); obj->error(obj->opaque, errno); return; } } else { async_read_clear_handlers(obj); obj->error(obj->opaque, 0); return; } } else { obj->now += n; if (obj->now == obj->end) { async_read_clear_handlers(obj); obj->done(obj->opaque); return; } } } }
CWE-119
1,829
12,253
87099173796977113185121086357307460466
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static SpiceCharDeviceState *attach_to_red_agent(SpiceCharDeviceInstance *sin) { VDIPortState *state = &reds->agent_state; SpiceCharDeviceInterface *sif; SpiceCharDeviceCallbacks char_dev_state_cbs; if (!state->base) { char_dev_state_cbs.read_one_msg_from_device = vdi_port_read_one_msg_from_device; char_dev_state_cbs.ref_msg_to_client = vdi_port_ref_msg_to_client; char_dev_state_cbs.unref_msg_to_client = vdi_port_unref_msg_to_client; char_dev_state_cbs.send_msg_to_client = vdi_port_send_msg_to_client; char_dev_state_cbs.send_tokens_to_client = vdi_port_send_tokens_to_client; char_dev_state_cbs.remove_client = vdi_port_remove_client; char_dev_state_cbs.on_free_self_token = vdi_port_on_free_self_token; state->base = spice_char_device_state_create(sin, REDS_TOKENS_TO_SEND, REDS_NUM_INTERNAL_AGENT_MESSAGES, &char_dev_state_cbs, NULL); } else { spice_char_device_state_reset_dev_instance(state->base, sin); } vdagent = sin; reds_update_mouse_mode(); sif = SPICE_CONTAINEROF(vdagent->base.sif, SpiceCharDeviceInterface, base); if (sif->state) { sif->state(vdagent, 1); } if (!reds_main_channel_connected()) { return state->base; } state->read_filter.discard_all = FALSE; reds->agent_state.plug_generation++; if (reds->agent_state.mig_data) { spice_assert(reds->agent_state.plug_generation == 1); reds_agent_state_restore(reds->agent_state.mig_data); free(reds->agent_state.mig_data); reds->agent_state.mig_data = NULL; } else if (!red_channel_waits_for_migrate_data(&reds->main_channel->base)) { /* we will assoicate the client with the char device, upon reds_on_main_agent_start, * in response to MSGC_AGENT_START */ main_channel_push_agent_connected(reds->main_channel); } else { spice_debug("waiting for migration data"); if (!spice_char_device_client_exists(reds->agent_state.base, reds_get_client())) { int client_added; client_added = spice_char_device_client_add(reds->agent_state.base, reds_get_client(), TRUE, /* flow control */ REDS_VDI_PORT_NUM_RECEIVE_BUFFS, REDS_AGENT_WINDOW_SIZE, ~0, TRUE); if (!client_added) { spice_warning("failed to add client to agent"); reds_disconnect(); } } } return state->base; }
CWE-119
1,830
12,254
47627753300060503972465853296624697480
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static int auth_sasl_check_ssf(RedsSASL *sasl, int *runSSF) { const void *val; int err, ssf; *runSSF = 0; if (!sasl->wantSSF) { return 1; } err = sasl_getprop(sasl->conn, SASL_SSF, &val); if (err != SASL_OK) { return 0; } ssf = *(const int *)val; spice_info("negotiated an SSF of %d", ssf); if (ssf < 56) { return 0; /* 56 is good for Kerberos */ } *runSSF = 1; /* We have a SSF that's good enough */ return 1; }
CWE-119
1,831
12,255
320993151206487472491939889992611162909
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static int channel_is_secondary(RedChannel *channel) { int i; for (i = 0 ; i < sizeof(secondary_channels)/sizeof(secondary_channels[0]); ++i) { if (channel->type == secondary_channels[i]) { return TRUE; } } return FALSE; }
CWE-119
1,832
12,256
129598303013909289636381099438899502740
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static int do_spice_init(SpiceCoreInterface *core_interface) { spice_info("starting %s", version_string); if (core_interface->base.major_version != SPICE_INTERFACE_CORE_MAJOR) { spice_warning("bad core interface version"); goto err; } core = core_interface; reds->listen_socket = -1; reds->secure_listen_socket = -1; init_vd_agent_resources(); ring_init(&reds->clients); reds->num_clients = 0; main_dispatcher_init(core); ring_init(&reds->channels); ring_init(&reds->mig_target_clients); ring_init(&reds->char_devs_states); ring_init(&reds->mig_wait_disconnect_clients); reds->vm_running = TRUE; /* for backward compatibility */ if (!(reds->mig_timer = core->timer_add(migrate_timeout, NULL))) { spice_error("migration timer create failed"); } #ifdef RED_STATISTICS int shm_name_len; int fd; shm_name_len = strlen(SPICE_STAT_SHM_NAME) + 20; reds->stat_shm_name = (char *)spice_malloc(shm_name_len); snprintf(reds->stat_shm_name, shm_name_len, SPICE_STAT_SHM_NAME, getpid()); if ((fd = shm_open(reds->stat_shm_name, O_CREAT | O_RDWR, 0444)) == -1) { spice_error("statistics shm_open failed, %s", strerror(errno)); } if (ftruncate(fd, REDS_STAT_SHM_SIZE) == -1) { spice_error("statistics ftruncate failed, %s", strerror(errno)); } reds->stat = (SpiceStat *)mmap(NULL, REDS_STAT_SHM_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (reds->stat == (SpiceStat *)MAP_FAILED) { spice_error("statistics mmap failed, %s", strerror(errno)); } memset(reds->stat, 0, REDS_STAT_SHM_SIZE); reds->stat->magic = SPICE_STAT_MAGIC; reds->stat->version = SPICE_STAT_VERSION; reds->stat->root_index = INVALID_STAT_REF; if (pthread_mutex_init(&reds->stat_lock, NULL)) { spice_error("mutex init failed"); } #endif if (!(reds->mm_timer = core->timer_add(mm_timer_proc, NULL))) { spice_error("mm timer create failed"); } reds_enable_mm_timer(); if (reds_init_net() < 0) { goto err; } if (reds->secure_listen_socket != -1) { if (reds_init_ssl() < 0) { goto err; } } #if HAVE_SASL int saslerr; if ((saslerr = sasl_server_init(NULL, sasl_appname ? sasl_appname : "spice")) != SASL_OK) { spice_error("Failed to initialize SASL auth %s", sasl_errstring(saslerr, NULL, NULL)); goto err; } #endif reds->main_channel = main_channel_init(); inputs_init(); reds->mouse_mode = SPICE_MOUSE_MODE_SERVER; reds_client_monitors_config_cleanup(); reds->allow_multiple_clients = getenv(SPICE_DEBUG_ALLOW_MC_ENV) != NULL; if (reds->allow_multiple_clients) { spice_warning("spice: allowing multiple client connections (crashy)"); } atexit(reds_exit); return 0; err: return -1; }
CWE-119
1,833
12,257
323891653518830343812590963901820008127
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static ChannelSecurityOptions *find_channel_security(int id) { ChannelSecurityOptions *now = channels_security; while (now && now->channel_id != id) { now = now->next; } return now; }
CWE-119
1,834
12,258
225935992047543144891328012478560961910
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void init_vd_agent_resources(void) { VDIPortState *state = &reds->agent_state; int i; ring_init(&state->read_bufs); agent_msg_filter_init(&state->write_filter, agent_copypaste, agent_file_xfer, TRUE); agent_msg_filter_init(&state->read_filter, agent_copypaste, agent_file_xfer, TRUE); state->read_state = VDI_PORT_READ_STATE_READ_HEADER; state->receive_pos = (uint8_t *)&state->vdi_chunk_header; state->receive_len = sizeof(state->vdi_chunk_header); for (i = 0; i < REDS_VDI_PORT_NUM_RECEIVE_BUFFS; i++) { VDIReadBuf *buf = spice_new0(VDIReadBuf, 1); ring_item_init(&buf->link); ring_add(&reds->agent_state.read_bufs, &buf->link); } }
CWE-119
1,835
12,259
185927151240425028829642108888447039721
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void insert_stat_node(StatNodeRef parent, StatNodeRef ref) { SpiceStatNode *node = &reds->stat->nodes[ref]; uint32_t pos = INVALID_STAT_REF; uint32_t node_index; uint32_t *head; SpiceStatNode *n; node->first_child_index = INVALID_STAT_REF; head = (parent == INVALID_STAT_REF ? &reds->stat->root_index : &reds->stat->nodes[parent].first_child_index); node_index = *head; while (node_index != INVALID_STAT_REF && (n = &reds->stat->nodes[node_index]) && strcmp(node->name, n->name) > 0) { pos = node_index; node_index = n->next_sibling_index; } if (pos == INVALID_STAT_REF) { node->next_sibling_index = *head; *head = ref; } else { n = &reds->stat->nodes[pos]; node->next_sibling_index = n->next_sibling_index; n->next_sibling_index = ref; } }
CWE-119
1,836
12,260
107843953502641570527359471623608713345
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static int load_dh_params(SSL_CTX *ctx, char *file) { DH *ret = 0; BIO *bio; if ((bio = BIO_new_file(file, "r")) == NULL) { spice_warning("Could not open DH file"); return -1; } ret = PEM_read_bio_DHparams(bio, NULL, NULL, NULL); BIO_free(bio); if (ret == 0) { spice_warning("Could not read DH params"); return -1; } if (SSL_CTX_set_tmp_dh(ctx, ret) < 0) { spice_warning("Could not set DH params"); return -1; } return 0; }
CWE-119
1,837
12,261
308290413115617456171702853637528523490
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void migrate_timeout(void *opaque) { spice_info(NULL); spice_assert(reds->mig_wait_connect || reds->mig_wait_disconnect); if (reds->mig_wait_connect) { /* we will fall back to the switch host scheme when migration completes */ main_channel_migrate_cancel_wait(reds->main_channel); /* in case part of the client haven't yet completed the previous migration, disconnect them */ reds_mig_target_client_disconnect_all(); reds_mig_cleanup(); } else { reds_mig_disconnect(); } }
CWE-119
1,838
12,262
82970861478139781140672943025794941281
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void mm_timer_proc(void *opaque) { red_dispatcher_set_mm_time(reds_get_mm_time()); core->timer_start(reds->mm_timer, MM_TIMER_GRANULARITY_MS); }
CWE-119
1,839
12,263
132045226265147468038192645491690140495
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void openssl_init(RedLinkInfo *link) { unsigned long f4 = RSA_F4; link->tiTicketing.bn = BN_new(); if (!link->tiTicketing.bn) { spice_error("OpenSSL BIGNUMS alloc failed"); } BN_set_word(link->tiTicketing.bn, f4); }
CWE-119
1,841
12,264
4352764498212606884822315975655967395
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void openssl_thread_setup(void) { int i; lock_cs = OPENSSL_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t)); lock_count = OPENSSL_malloc(CRYPTO_num_locks() * sizeof(long)); for (i = 0; i < CRYPTO_num_locks(); i++) { lock_count[i] = 0; pthread_mutex_init(&(lock_cs[i]), NULL); } CRYPTO_set_id_callback(pthreads_thread_id); CRYPTO_set_locking_callback(pthreads_locking_callback); }
CWE-119
1,842
12,265
191598020043079629831131877252185807708
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void pthreads_locking_callback(int mode, int type, const char *file, int line) { if (mode & CRYPTO_LOCK) { pthread_mutex_lock(&(lock_cs[type])); lock_count[type]++; } else { pthread_mutex_unlock(&(lock_cs[type])); } }
CWE-119
1,843
12,266
242928572001593405910943190113135684789
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static unsigned long pthreads_thread_id(void) { unsigned long ret; ret = (unsigned long)pthread_self(); return (ret); }
CWE-119
1,844
12,267
127351323319873153702695078495849589203
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void reds_accept(int fd, int event, void *data) { int socket; if ((socket = accept(reds->listen_socket, NULL, 0)) == -1) { spice_warning("accept failed, %s", strerror(errno)); return; } if (spice_server_add_client(reds, socket, 0) < 0) close(socket); }
CWE-119
1,845
12,268
174153925214091722731061336273506328116
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void reds_accept_ssl_connection(int fd, int event, void *data) { RedLinkInfo *link; int socket; if ((socket = accept(reds->secure_listen_socket, NULL, 0)) == -1) { spice_warning("accept failed, %s", strerror(errno)); return; } if (!(link = reds_init_client_ssl_connection(socket))) { close(socket); return; } }
CWE-119
1,846
12,269
107329125554326186303749992128463259998
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static int reds_agent_state_restore(SpiceMigrateDataMain *mig_data) { VDIPortState *agent_state = &reds->agent_state; uint32_t chunk_header_remaining; agent_state->vdi_chunk_header = mig_data->agent2client.chunk_header; spice_assert(mig_data->agent2client.chunk_header_size <= sizeof(VDIChunkHeader)); chunk_header_remaining = sizeof(VDIChunkHeader) - mig_data->agent2client.chunk_header_size; if (chunk_header_remaining) { agent_state->read_state = VDI_PORT_READ_STATE_READ_HEADER; agent_state->receive_pos = (uint8_t *)&agent_state->vdi_chunk_header + mig_data->agent2client.chunk_header_size; agent_state->receive_len = chunk_header_remaining; } else { agent_state->message_receive_len = agent_state->vdi_chunk_header.size; } if (!mig_data->agent2client.msg_header_done) { uint8_t *partial_msg_header; if (!chunk_header_remaining) { uint32_t cur_buf_size; agent_state->read_state = VDI_PORT_READ_STATE_READ_DATA; agent_state->current_read_buf = vdi_port_read_buf_get(); spice_assert(agent_state->current_read_buf); partial_msg_header = (uint8_t *)mig_data + mig_data->agent2client.msg_header_ptr - sizeof(SpiceMiniDataHeader); memcpy(agent_state->current_read_buf->data, partial_msg_header, mig_data->agent2client.msg_header_partial_len); agent_state->receive_pos = agent_state->current_read_buf->data + mig_data->agent2client.msg_header_partial_len; cur_buf_size = sizeof(agent_state->current_read_buf->data) - mig_data->agent2client.msg_header_partial_len; agent_state->receive_len = MIN(agent_state->message_receive_len, cur_buf_size); agent_state->current_read_buf->len = agent_state->receive_len + mig_data->agent2client.msg_header_partial_len; agent_state->message_receive_len -= agent_state->receive_len; } else { spice_assert(mig_data->agent2client.msg_header_partial_len == 0); } } else { agent_state->read_state = VDI_PORT_READ_STATE_GET_BUFF; agent_state->current_read_buf = NULL; agent_state->receive_pos = NULL; agent_state->read_filter.msg_data_to_read = mig_data->agent2client.msg_remaining; agent_state->read_filter.result = mig_data->agent2client.msg_filter_result; } agent_state->read_filter.discard_all = FALSE; agent_state->write_filter.discard_all = !mig_data->client_agent_started; agent_state->client_agent_started = mig_data->client_agent_started; agent_state->write_filter.msg_data_to_read = mig_data->client2agent.msg_remaining; agent_state->write_filter.result = mig_data->client2agent.msg_filter_result; spice_debug("to agent filter: discard all %d, wait_msg %u, msg_filter_result %d", agent_state->write_filter.discard_all, agent_state->write_filter.msg_data_to_read, agent_state->write_filter.result); spice_debug("from agent filter: discard all %d, wait_msg %u, msg_filter_result %d", agent_state->read_filter.discard_all, agent_state->read_filter.msg_data_to_read, agent_state->read_filter.result); return spice_char_device_state_restore(agent_state->base, &mig_data->agent_base); }
CWE-119
1,847
12,270
174468427287794016354450576968070498986
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void reds_channel_do_link(RedChannel *channel, RedClient *client, SpiceLinkMess *link_msg, RedsStream *stream) { uint32_t *caps; spice_assert(channel); spice_assert(link_msg); spice_assert(stream); caps = (uint32_t *)((uint8_t *)link_msg + link_msg->caps_offset); channel->client_cbs.connect(channel, client, stream, red_client_during_migrate_at_target(client), link_msg->num_common_caps, link_msg->num_common_caps ? caps : NULL, link_msg->num_channel_caps, link_msg->num_channel_caps ? caps + link_msg->num_common_caps : NULL); }
CWE-119
1,848
12,271
179312812562646998055875894345968835755
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void reds_channel_init_auth_caps(RedLinkInfo *link, RedChannel *channel) { if (sasl_enabled && !link->skip_auth) { red_channel_set_common_cap(channel, SPICE_COMMON_CAP_AUTH_SASL); } else { red_channel_set_common_cap(channel, SPICE_COMMON_CAP_AUTH_SPICE); } red_channel_set_common_cap(channel, SPICE_COMMON_CAP_PROTOCOL_AUTH_SELECTION); }
CWE-119
1,849
12,272
218857606052713572389077539675615643277
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void reds_char_device_add_state(SpiceCharDeviceState *st) { SpiceCharDeviceStateItem *item = spice_new0(SpiceCharDeviceStateItem, 1); item->st = st; ring_add(&reds->char_devs_states, &item->link); }
CWE-119
1,850
12,273
263474344591798535156497040299632756127
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void reds_char_device_remove_state(SpiceCharDeviceState *st) { RingItem *item; RING_FOREACH(item, &reds->char_devs_states) { SpiceCharDeviceStateItem *st_item; st_item = SPICE_CONTAINEROF(item, SpiceCharDeviceStateItem, link); if (st_item->st == st) { ring_remove(item); free(st_item); return; } } spice_error("char dev state not found %p", st); }
CWE-119
1,851
12,274
13673438940572954366547023740875602276
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
void reds_client_disconnect(RedClient *client) { RedsMigTargetClient *mig_client; if (exit_on_disconnect) { spice_info("Exiting server because of client disconnect.\n"); exit(0); } if (!client || client->disconnecting) { spice_debug("client %p already during disconnection", client); return; } spice_info(NULL); /* disconnecting is set to prevent recursion because of the following: * main_channel_client_on_disconnect-> * reds_client_disconnect->red_client_destroy->main_channel... */ client->disconnecting = TRUE; mig_client = reds_mig_target_client_find(client); if (mig_client) { reds_mig_target_client_free(mig_client); } if (reds->mig_wait_disconnect) { reds_mig_remove_wait_disconnect_client(client); } if (reds->agent_state.base) { /* note that vdagent might be NULL, if the vdagent was once * up and than was removed */ if (spice_char_device_client_exists(reds->agent_state.base, client)) { spice_char_device_client_remove(reds->agent_state.base, client); } } ring_remove(&client->link); reds->num_clients--; red_client_destroy(client); if (reds->num_clients == 0) { /* Let the agent know the client is disconnected */ if (reds->agent_state.base) { SpiceCharDeviceWriteBuffer *char_dev_buf; VDInternalBuf *internal_buf; uint32_t total_msg_size; total_msg_size = sizeof(VDIChunkHeader) + sizeof(VDAgentMessage); char_dev_buf = spice_char_device_write_buffer_get_server_no_token( reds->agent_state.base, total_msg_size); char_dev_buf->buf_used = total_msg_size; internal_buf = (VDInternalBuf *)char_dev_buf->buf; internal_buf->chunk_header.port = VDP_SERVER_PORT; internal_buf->chunk_header.size = sizeof(VDAgentMessage); internal_buf->header.protocol = VD_AGENT_PROTOCOL; internal_buf->header.type = VD_AGENT_CLIENT_DISCONNECTED; internal_buf->header.opaque = 0; internal_buf->header.size = 0; spice_char_device_write_buffer_add(reds->agent_state.base, char_dev_buf); } /* Reset write filter to start with clean state on client reconnect */ agent_msg_filter_init(&reds->agent_state.write_filter, agent_copypaste, agent_file_xfer, TRUE); /* Throw away pending chunks from the current (if any) and future * messages read from the agent */ reds->agent_state.read_filter.result = AGENT_MSG_FILTER_DISCARD; reds->agent_state.read_filter.discard_all = TRUE; free(reds->agent_state.mig_data); reds->agent_state.mig_data = NULL; reds_mig_cleanup(); } }
CWE-119
1,852
12,275
150006964587807204249134284519777707346
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void reds_client_monitors_config_cleanup(void) { RedsClientMonitorsConfig *cmc = &reds->client_monitors_config; cmc->buffer_size = cmc->buffer_pos = 0; free(cmc->buffer); cmc->buffer = NULL; cmc->mcc = NULL; }
CWE-119
1,853
12,276
76255074329616917614124481090842379997
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
void reds_disable_mm_timer(void) { core->timer_cancel(reds->mm_timer); reds->mm_timer_enabled = FALSE; }
CWE-119
1,854
12,277
289596526898153451679377750816814680701
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void reds_disconnect(void) { RingItem *link, *next; spice_info(NULL); RING_FOREACH_SAFE(link, next, &reds->clients) { reds_client_disconnect(SPICE_CONTAINEROF(link, RedClient, link)); } reds_mig_cleanup(); }
CWE-119
1,855
12,278
227974103045466862826161253169021090550
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
void reds_enable_mm_timer(void) { core->timer_start(reds->mm_timer, MM_TIMER_GRANULARITY_MS); reds->mm_timer_enabled = TRUE; reds->mm_time_latency = MM_TIME_DELTA; reds_send_mm_time(); }
CWE-119
1,856
12,279
53921578333092977962978064156045551625
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void reds_exit(void) { if (reds->main_channel) { main_channel_close(reds->main_channel); } #ifdef RED_STATISTICS shm_unlink(reds->stat_shm_name); free(reds->stat_shm_name); #endif }
CWE-119
1,857
12,280
122236368618946434653433701843638275760
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
int reds_expects_link_id(uint32_t connection_id) { spice_info("TODO: keep a list of connection_id's from migration, compare to them"); return 1; }
CWE-119
1,858
12,281
288205897830522365627281909345652157138
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
void reds_fill_channels(SpiceMsgChannels *channels_info) { RingItem *now; int used_channels = 0; channels_info->num_of_channels = reds->num_of_channels; RING_FOREACH(now, &reds->channels) { RedChannel *channel = SPICE_CONTAINEROF(now, RedChannel, link); if (reds->num_clients > 1 && !channel_is_secondary(channel)) { continue; } channels_info->channels[used_channels].type = channel->type; channels_info->channels[used_channels].id = channel->id; used_channels++; } channels_info->num_of_channels = used_channels; if (used_channels != reds->num_of_channels) { spice_warning("sent %d out of %d", used_channels, reds->num_of_channels); } }
CWE-119
1,859
12,282
47176025151417359399972874298445719410
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static RedChannel *reds_find_channel(uint32_t type, uint32_t id) { RingItem *now; RING_FOREACH(now, &reds->channels) { RedChannel *channel = SPICE_CONTAINEROF(now, RedChannel, link); if (channel->type == type && channel->id == id) { return channel; } } return NULL; }
CWE-119
1,860
12,283
136564569621868260104152859654507658525
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static int reds_find_client(RedClient *client) { RingItem *item; RING_FOREACH(item, &reds->clients) { RedClient *list_client; list_client = SPICE_CONTAINEROF(item, RedClient, link); if (list_client == client) { return TRUE; } } return FALSE; }
CWE-119
1,861
12,284
179904114079618612862974160002931833435
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
uint8_t *reds_get_agent_data_buffer(MainChannelClient *mcc, size_t size) { VDIPortState *dev_state = &reds->agent_state; RedClient *client; if (!dev_state->client_agent_started) { /* * agent got disconnected, and possibly got reconnected, but we still can receive * msgs that are addressed to the agent's old instance, in case they were * sent by the client before it received the AGENT_DISCONNECTED msg. * In such case, we will receive and discard the msgs (reds_reset_vdp takes care * of setting state->write_filter.result = AGENT_MSG_FILTER_DISCARD). */ return spice_malloc(size); } spice_assert(dev_state->recv_from_client_buf == NULL); client = main_channel_client_get_base(mcc)->client; dev_state->recv_from_client_buf = spice_char_device_write_buffer_get(dev_state->base, client, size + sizeof(VDIChunkHeader)); dev_state->recv_from_client_buf_pushed = FALSE; return dev_state->recv_from_client_buf->buf + sizeof(VDIChunkHeader); }
CWE-119
1,862
12,285
66978216020005097241925135111701217259
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
int reds_get_agent_mouse(void) { return agent_mouse; }
CWE-119
1,863
12,286
144868663520219950269311411880240235227
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static RedClient *reds_get_client(void) { spice_assert(reds->num_clients <= 1); if (reds->num_clients == 0) { return NULL; } return SPICE_CONTAINEROF(ring_get_head(&reds->clients), RedClient, link); }
CWE-119
1,864
12,287
285497458485121155199107360298318231786
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
uint32_t reds_get_mm_time(void) { struct timespec time_space; clock_gettime(CLOCK_MONOTONIC, &time_space); return time_space.tv_sec * 1000 + time_space.tv_nsec / 1000 / 1000; }
CWE-119
1,865
12,288
22154144940139197645371069670737796107
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
int reds_get_mouse_mode(void) { return reds->mouse_mode; }
CWE-119
1,866
12,289
266046598784734590071031907352811612240
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void reds_get_spice_ticket(RedLinkInfo *link) { AsyncRead *obj = &link->async_read; obj->now = (uint8_t *)&link->tiTicketing.encrypted_ticket.encrypted_data; obj->end = obj->now + link->tiTicketing.rsa_size; obj->done = reds_handle_ticket; async_read_handler(0, 0, &link->async_read); }
CWE-119
1,867
12,290
192656279418431911492891027828137206524
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
void reds_handle_agent_mouse_event(const VDAgentMouseState *mouse_state) { SpiceCharDeviceWriteBuffer *char_dev_buf; VDInternalBuf *internal_buf; uint32_t total_msg_size; if (!inputs_inited() || !reds->agent_state.base) { return; } total_msg_size = sizeof(VDIChunkHeader) + sizeof(VDAgentMessage) + sizeof(VDAgentMouseState); char_dev_buf = spice_char_device_write_buffer_get(reds->agent_state.base, NULL, total_msg_size); if (!char_dev_buf) { reds->pending_mouse_event = TRUE; return; } reds->pending_mouse_event = FALSE; internal_buf = (VDInternalBuf *)char_dev_buf->buf; internal_buf->chunk_header.port = VDP_SERVER_PORT; internal_buf->chunk_header.size = sizeof(VDAgentMessage) + sizeof(VDAgentMouseState); internal_buf->header.protocol = VD_AGENT_PROTOCOL; internal_buf->header.type = VD_AGENT_MOUSE_STATE; internal_buf->header.opaque = 0; internal_buf->header.size = sizeof(VDAgentMouseState); internal_buf->u.mouse_state = *mouse_state; char_dev_buf->buf_used = total_msg_size; spice_char_device_write_buffer_add(reds->agent_state.base, char_dev_buf); }
CWE-119
1,868
12,291
105637752762884645807287413469365630298
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void reds_handle_auth_mechanism(void *opaque) { RedLinkInfo *link = (RedLinkInfo *)opaque; spice_info("Auth method: %d", link->auth_mechanism.auth_mechanism); if (link->auth_mechanism.auth_mechanism == SPICE_COMMON_CAP_AUTH_SPICE && !sasl_enabled ) { reds_get_spice_ticket(link); #if HAVE_SASL } else if (link->auth_mechanism.auth_mechanism == SPICE_COMMON_CAP_AUTH_SASL) { spice_info("Starting SASL"); reds_start_auth_sasl(link); #endif } else { spice_warning("Unknown auth method, disconnecting"); if (sasl_enabled) { spice_warning("Your client doesn't handle SASL?"); } reds_send_link_error(link, SPICE_LINK_ERR_INVALID_DATA); reds_link_free(link); } }
CWE-119
1,869
12,292
15337848544551474108761388731466547303
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void reds_handle_auth_mechlen(void *opaque) { RedLinkInfo *link = (RedLinkInfo *)opaque; AsyncRead *obj = &link->async_read; RedsSASL *sasl = &link->stream->sasl; if (sasl->len < 1 || sasl->len > 100) { spice_warning("Got bad client mechname len %d", sasl->len); reds_link_free(link); return; } sasl->mechname = spice_malloc(sasl->len + 1); spice_info("Wait for client mechname"); obj->now = (uint8_t *)sasl->mechname; obj->end = obj->now + sasl->len; obj->done = reds_handle_auth_mechname; async_read_handler(0, 0, &link->async_read); }
CWE-119
1,870
12,293
302616390465038151469882725049528761318
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void reds_handle_auth_mechname(void *opaque) { RedLinkInfo *link = (RedLinkInfo *)opaque; AsyncRead *obj = &link->async_read; RedsSASL *sasl = &link->stream->sasl; sasl->mechname[sasl->len] = '\0'; spice_info("Got client mechname '%s' check against '%s'", sasl->mechname, sasl->mechlist); if (strncmp(sasl->mechlist, sasl->mechname, sasl->len) == 0) { if (sasl->mechlist[sasl->len] != '\0' && sasl->mechlist[sasl->len] != ',') { spice_info("One %d", sasl->mechlist[sasl->len]); reds_link_free(link); return; } } else { char *offset = strstr(sasl->mechlist, sasl->mechname); spice_info("Two %p", offset); if (!offset) { reds_send_link_error(link, SPICE_LINK_ERR_INVALID_DATA); return; } spice_info("Two '%s'", offset); if (offset[-1] != ',' || (offset[sasl->len] != '\0'&& offset[sasl->len] != ',')) { reds_send_link_error(link, SPICE_LINK_ERR_INVALID_DATA); return; } } free(sasl->mechlist); sasl->mechlist = spice_strdup(sasl->mechname); spice_info("Validated mechname '%s'", sasl->mechname); obj->now = (uint8_t *)&sasl->len; obj->end = obj->now + sizeof(uint32_t); obj->done = reds_handle_auth_startlen; async_read_handler(0, 0, &link->async_read); return; }
CWE-119
1,871
12,294
67408300172263278894498016429708446981
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void reds_handle_auth_sasl_start(void *opaque) { RedLinkInfo *link = (RedLinkInfo *)opaque; AsyncRead *obj = &link->async_read; const char *serverout; unsigned int serveroutlen; int err; char *clientdata = NULL; RedsSASL *sasl = &link->stream->sasl; uint32_t datalen = sasl->len; /* NB, distinction of NULL vs "" is *critical* in SASL */ if (datalen) { clientdata = sasl->data; clientdata[datalen - 1] = '\0'; /* Should be on wire, but make sure */ datalen--; /* Don't count NULL byte when passing to _start() */ } spice_info("Start SASL auth with mechanism %s. Data %p (%d bytes)", sasl->mechlist, clientdata, datalen); err = sasl_server_start(sasl->conn, sasl->mechlist, clientdata, datalen, &serverout, &serveroutlen); if (err != SASL_OK && err != SASL_CONTINUE) { spice_warning("sasl start failed %d (%s)", err, sasl_errdetail(sasl->conn)); goto authabort; } if (serveroutlen > SASL_DATA_MAX_LEN) { spice_warning("sasl start reply data too long %d", serveroutlen); goto authabort; } spice_info("SASL return data %d bytes, %p", serveroutlen, serverout); if (serveroutlen) { serveroutlen += 1; sync_write(link->stream, &serveroutlen, sizeof(uint32_t)); sync_write(link->stream, serverout, serveroutlen); } else { sync_write(link->stream, &serveroutlen, sizeof(uint32_t)); } /* Whether auth is complete */ sync_write_u8(link->stream, err == SASL_CONTINUE ? 0 : 1); if (err == SASL_CONTINUE) { spice_info("%s", "Authentication must continue (start)"); /* Wait for step length */ obj->now = (uint8_t *)&sasl->len; obj->end = obj->now + sizeof(uint32_t); obj->done = reds_handle_auth_sasl_steplen; async_read_handler(0, 0, &link->async_read); } else { int ssf; if (auth_sasl_check_ssf(sasl, &ssf) == 0) { spice_warning("Authentication rejected for weak SSF"); goto authreject; } spice_info("Authentication successful"); sync_write_u32(link->stream, SPICE_LINK_ERR_OK); /* Accept auth */ /* * Delay writing in SSF encoded until now */ sasl->runSSF = ssf; link->stream->writev = NULL; /* make sure writev isn't called directly anymore */ reds_handle_link(link); } return; authreject: sync_write_u32(link->stream, 1); /* Reject auth */ sync_write_u32(link->stream, sizeof("Authentication failed")); sync_write(link->stream, "Authentication failed", sizeof("Authentication failed")); authabort: reds_link_free(link); return; }
CWE-119
1,872
12,295
6403374681113668432403760423389702346
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void reds_handle_auth_sasl_step(void *opaque) { const char *serverout; unsigned int serveroutlen; int err; char *clientdata = NULL; RedLinkInfo *link = (RedLinkInfo *)opaque; RedsSASL *sasl = &link->stream->sasl; uint32_t datalen = sasl->len; AsyncRead *obj = &link->async_read; /* NB, distinction of NULL vs "" is *critical* in SASL */ if (datalen) { clientdata = sasl->data; clientdata[datalen - 1] = '\0'; /* Wire includes '\0', but make sure */ datalen--; /* Don't count NULL byte when passing to _start() */ } spice_info("Step using SASL Data %p (%d bytes)", clientdata, datalen); err = sasl_server_step(sasl->conn, clientdata, datalen, &serverout, &serveroutlen); if (err != SASL_OK && err != SASL_CONTINUE) { spice_warning("sasl step failed %d (%s)", err, sasl_errdetail(sasl->conn)); goto authabort; } if (serveroutlen > SASL_DATA_MAX_LEN) { spice_warning("sasl step reply data too long %d", serveroutlen); goto authabort; } spice_info("SASL return data %d bytes, %p", serveroutlen, serverout); if (serveroutlen) { serveroutlen += 1; sync_write(link->stream, &serveroutlen, sizeof(uint32_t)); sync_write(link->stream, serverout, serveroutlen); } else { sync_write(link->stream, &serveroutlen, sizeof(uint32_t)); } /* Whether auth is complete */ sync_write_u8(link->stream, err == SASL_CONTINUE ? 0 : 1); if (err == SASL_CONTINUE) { spice_info("%s", "Authentication must continue (step)"); /* Wait for step length */ obj->now = (uint8_t *)&sasl->len; obj->end = obj->now + sizeof(uint32_t); obj->done = reds_handle_auth_sasl_steplen; async_read_handler(0, 0, &link->async_read); } else { int ssf; if (auth_sasl_check_ssf(sasl, &ssf) == 0) { spice_warning("Authentication rejected for weak SSF"); goto authreject; } spice_info("Authentication successful"); sync_write_u32(link->stream, SPICE_LINK_ERR_OK); /* Accept auth */ /* * Delay writing in SSF encoded until now */ sasl->runSSF = ssf; link->stream->writev = NULL; /* make sure writev isn't called directly anymore */ reds_handle_link(link); } return; authreject: sync_write_u32(link->stream, 1); /* Reject auth */ sync_write_u32(link->stream, sizeof("Authentication failed")); sync_write(link->stream, "Authentication failed", sizeof("Authentication failed")); authabort: reds_link_free(link); return; }
CWE-119
1,873
12,296
224056774608558027787893273371980946616
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void reds_handle_auth_sasl_steplen(void *opaque) { RedLinkInfo *link = (RedLinkInfo *)opaque; AsyncRead *obj = &link->async_read; RedsSASL *sasl = &link->stream->sasl; spice_info("Got steplen %d", sasl->len); if (sasl->len > SASL_DATA_MAX_LEN) { spice_warning("Too much SASL data %d", sasl->len); reds_link_free(link); return; } if (sasl->len == 0) { return reds_handle_auth_sasl_step(opaque); } else { sasl->data = spice_realloc(sasl->data, sasl->len); obj->now = (uint8_t *)sasl->data; obj->end = obj->now + sasl->len; obj->done = reds_handle_auth_sasl_step; async_read_handler(0, 0, &link->async_read); } }
CWE-119
1,874
12,297
22455173760452071418322051444153412141
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void reds_handle_auth_startlen(void *opaque) { RedLinkInfo *link = (RedLinkInfo *)opaque; AsyncRead *obj = &link->async_read; RedsSASL *sasl = &link->stream->sasl; spice_info("Got client start len %d", sasl->len); if (sasl->len > SASL_DATA_MAX_LEN) { spice_warning("Too much SASL data %d", sasl->len); reds_send_link_error(link, SPICE_LINK_ERR_INVALID_DATA); reds_link_free(link); return; } if (sasl->len == 0) { reds_handle_auth_sasl_start(opaque); return; } sasl->data = spice_realloc(sasl->data, sasl->len); obj->now = (uint8_t *)sasl->data; obj->end = obj->now + sasl->len; obj->done = reds_handle_auth_sasl_start; async_read_handler(0, 0, &link->async_read); }
CWE-119
1,875
12,298
141895389034456165130991508937773986108
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
void reds_handle_channel_event(int event, SpiceChannelEventInfo *info) { if (core->base.minor_version >= 3 && core->channel_event != NULL) core->channel_event(event, info); if (event == SPICE_CHANNEL_EVENT_DISCONNECTED) { free(info); } }
CWE-119
1,876
12,299
6327112612440009128246526954568895813
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void reds_handle_link_error(void *opaque, int err) { RedLinkInfo *link = (RedLinkInfo *)opaque; switch (err) { case 0: case EPIPE: break; default: spice_warning("%s", strerror(errno)); break; } reds_link_free(link); }
CWE-119
1,878
12,300
70755214595952673092140663086949817023
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void reds_handle_main_link(RedLinkInfo *link) { RedClient *client; RedsStream *stream; SpiceLinkMess *link_mess; uint32_t *caps; uint32_t connection_id; MainChannelClient *mcc; int mig_target = FALSE; spice_info(NULL); spice_assert(reds->main_channel); link_mess = link->link_mess; if (!reds->allow_multiple_clients) { reds_disconnect(); } if (link_mess->connection_id == 0) { reds_send_link_result(link, SPICE_LINK_ERR_OK); while((connection_id = rand()) == 0); mig_target = FALSE; } else { reds_send_link_result(link, SPICE_LINK_ERR_OK); connection_id = link_mess->connection_id; mig_target = TRUE; } reds->mig_inprogress = FALSE; reds->mig_wait_connect = FALSE; reds->mig_wait_disconnect = FALSE; reds_info_new_channel(link, connection_id); stream = link->stream; reds_stream_remove_watch(stream); link->stream = NULL; link->link_mess = NULL; reds_link_free(link); caps = (uint32_t *)((uint8_t *)link_mess + link_mess->caps_offset); client = red_client_new(mig_target); ring_add(&reds->clients, &client->link); reds->num_clients++; mcc = main_channel_link(reds->main_channel, client, stream, connection_id, mig_target, link_mess->num_common_caps, link_mess->num_common_caps ? caps : NULL, link_mess->num_channel_caps, link_mess->num_channel_caps ? caps + link_mess->num_common_caps : NULL); spice_info("NEW Client %p mcc %p connect-id %d", client, mcc, connection_id); free(link_mess); red_client_set_main(client, mcc); if (vdagent) { if (mig_target) { spice_warning("unexpected: vdagent attached to destination during migration"); } reds->agent_state.read_filter.discard_all = FALSE; reds->agent_state.plug_generation++; } if (!mig_target) { main_channel_push_init(mcc, red_dispatcher_count(), reds->mouse_mode, reds->is_client_mouse_allowed, reds_get_mm_time() - MM_TIME_DELTA, red_dispatcher_qxl_ram_size()); if (spice_name) main_channel_push_name(mcc, spice_name); if (spice_uuid_is_set) main_channel_push_uuid(mcc, spice_uuid); } else { reds_mig_target_client_add(client); } main_channel_client_start_net_test(mcc, !mig_target); }
CWE-119
1,879
12,301
328122620684859854351595302289332293934
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
int reds_handle_migrate_data(MainChannelClient *mcc, SpiceMigrateDataMain *mig_data, uint32_t size) { VDIPortState *agent_state = &reds->agent_state; /* * Now that the client has switched to the target server, if main_channel * controls the mm-time, we update the client's mm-time. * (MSG_MAIN_INIT is not sent for a migrating connection) */ if (reds->mm_timer_enabled) { reds_send_mm_time(); } if (mig_data->agent_base.connected) { if (agent_state->base) { // agent was attached before migration data has arrived if (!vdagent) { spice_assert(agent_state->plug_generation > 0); main_channel_push_agent_disconnected(reds->main_channel); spice_debug("agent is no longer connected"); } else { if (agent_state->plug_generation > 1) { /* spice_char_device_state_reset takes care of not making the device wait for migration data */ spice_debug("agent has been detached and reattached before receiving migration data"); main_channel_push_agent_disconnected(reds->main_channel); main_channel_push_agent_connected(reds->main_channel); } else { return reds_agent_state_restore(mig_data); } } } else { /* restore agent starte when the agent gets attached */ spice_assert(agent_state->plug_generation == 0); agent_state->mig_data = spice_memdup(mig_data, size); } } else { if (vdagent) { /* spice_char_device_client_remove disables waiting for migration data */ spice_char_device_client_remove(agent_state->base, main_channel_client_get_base(mcc)->client); main_channel_push_agent_connected(reds->main_channel); } } return TRUE; }
CWE-119
1,880
12,302
225263967624812833948887424679372876099
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void reds_handle_new_link(RedLinkInfo *link) { AsyncRead *obj = &link->async_read; obj->opaque = link; obj->stream = link->stream; obj->now = (uint8_t *)&link->link_header; obj->end = (uint8_t *)((SpiceLinkHeader *)&link->link_header + 1); obj->done = reds_handle_read_header_done; obj->error = reds_handle_link_error; async_read_handler(0, 0, &link->async_read); }
CWE-119
1,881
12,303
270499767257444145224373059876109995121
null
null
null
spice
8af619009660b24e0b41ad26b30289eea288fcc2
0
static void reds_handle_other_links(RedLinkInfo *link) { RedChannel *channel; RedClient *client = NULL; SpiceLinkMess *link_mess; RedsMigTargetClient *mig_client; link_mess = link->link_mess; if (reds->main_channel) { client = main_channel_get_client_by_link_id(reds->main_channel, link_mess->connection_id); } if (!client) { reds_send_link_result(link, SPICE_LINK_ERR_BAD_CONNECTION_ID); reds_link_free(link); return; } if (!(channel = reds_find_channel(link_mess->channel_type, link_mess->channel_id))) { reds_send_link_result(link, SPICE_LINK_ERR_CHANNEL_NOT_AVAILABLE); reds_link_free(link); return; } reds_send_link_result(link, SPICE_LINK_ERR_OK); reds_info_new_channel(link, link_mess->connection_id); reds_stream_remove_watch(link->stream); mig_client = reds_mig_target_client_find(client); /* * In semi-seamless migration, we activate the channels only * after migration is completed. Since, the session starts almost from * scratch we don't mind if we skip some messages in between the src session end and * dst session start. * In seamless migration, in order to keep the continuousness of the session, and * in order not to lose any data, we activate the target channels before * migration completes, as soon as we receive SPICE_MSGC_MAIN_MIGRATE_DST_DO_SEAMLESS. * If a channel connects before receiving SPICE_MSGC_MAIN_MIGRATE_DST_DO_SEAMLESS, * reds_on_migrate_dst_set_seamless will take care of activating it */ if (red_client_during_migrate_at_target(client) && !reds->dst_do_seamless_migrate) { spice_assert(mig_client); reds_mig_target_client_add_pending_link(mig_client, link_mess, link->stream); } else { spice_assert(!mig_client); reds_channel_do_link(channel, client, link_mess, link->stream); free(link_mess); } link->stream = NULL; link->link_mess = NULL; reds_link_free(link); }
CWE-119
1,882
12,304
128714081008727075472908050594887277782
null
null
null