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
4278ef25f64d5fdbf432ff1534e275416ec9561e
0
static ssize_t vfs_pread_fn(void *file, void *buf, size_t len, off_t offset) { struct files_struct *fsp = (struct files_struct *)file; return SMB_VFS_PREAD(fsp, buf, len, offset); }
CWE-264
2,669
12,863
264849568431931080543936798436015012388
null
null
null
samba
4278ef25f64d5fdbf432ff1534e275416ec9561e
0
ssize_t vfs_pwrite_data(struct smb_request *req, files_struct *fsp, const char *buffer, size_t N, off_t offset) { size_t total=0; ssize_t ret; if (req && req->unread_bytes) { int sockfd = req->xconn->transport.sock; SMB_ASSERT(req->unread_bytes == N); /* VFS_RECVFILE must drain the socket * before returning. */ req->unread_bytes = 0; /* * Leave the socket non-blocking and * use SMB_VFS_RECVFILE. If it returns * EAGAIN || EWOULDBLOCK temporarily set * the socket blocking and retry * the RECVFILE. */ while (total < N) { ret = SMB_VFS_RECVFILE(sockfd, fsp, offset + total, N - total); if (ret == 0 || (ret == -1 && (errno == EAGAIN || errno == EWOULDBLOCK))) { int old_flags; /* Ensure the socket is blocking. */ old_flags = fcntl(sockfd, F_GETFL, 0); if (set_blocking(sockfd, true) == -1) { return (ssize_t)-1; } ret = SMB_VFS_RECVFILE(sockfd, fsp, offset + total, N - total); if (fcntl(sockfd, F_SETFL, old_flags) == -1) { return (ssize_t)-1; } if (ret == -1) { return (ssize_t)-1; } total += ret; return (ssize_t)total; } /* Any other error case. */ if (ret == -1) { return ret; } total += ret; } return (ssize_t)total; } while (total < N) { ret = SMB_VFS_PWRITE(fsp, buffer + total, N - total, offset + total); if (ret == -1) return -1; if (ret == 0) return total; total += ret; } return (ssize_t)total; }
CWE-264
2,670
12,864
286706200622483148058430945214751380828
null
null
null
samba
4278ef25f64d5fdbf432ff1534e275416ec9561e
0
static ssize_t vfs_pwrite_fn(void *file, const void *buf, size_t len, off_t offset) { struct files_struct *fsp = (struct files_struct *)file; return SMB_VFS_PWRITE(fsp, buf, len, offset); }
CWE-264
2,671
12,865
12151740774815794305473801263730454843
null
null
null
samba
4278ef25f64d5fdbf432ff1534e275416ec9561e
0
ssize_t vfs_read_data(files_struct *fsp, char *buf, size_t byte_count) { size_t total=0; while (total < byte_count) { ssize_t ret = SMB_VFS_READ(fsp, buf + total, byte_count - total); if (ret == 0) return total; if (ret == -1) { if (errno == EINTR) continue; else return -1; } total += ret; } return (ssize_t)total; }
CWE-264
2,672
12,866
137294150240286892550895078498759034489
null
null
null
samba
4278ef25f64d5fdbf432ff1534e275416ec9561e
0
const char *vfs_readdirname(connection_struct *conn, void *p, SMB_STRUCT_STAT *sbuf, char **talloced) { struct dirent *ptr= NULL; const char *dname; char *translated; NTSTATUS status; if (!p) return(NULL); ptr = SMB_VFS_READDIR(conn, (DIR *)p, sbuf); if (!ptr) return(NULL); dname = ptr->d_name; #ifdef NEXT2 if (telldir(p) < 0) return(NULL); #endif #ifdef HAVE_BROKEN_READDIR_NAME /* using /usr/ucb/cc is BAD */ dname = dname - 2; #endif status = SMB_VFS_TRANSLATE_NAME(conn, dname, vfs_translate_to_windows, talloc_tos(), &translated); if (NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED)) { *talloced = NULL; return dname; } *talloced = translated; if (!NT_STATUS_IS_OK(status)) { return NULL; } return translated; }
CWE-264
2,673
12,867
312628252079778825487029440389802413951
null
null
null
samba
4278ef25f64d5fdbf432ff1534e275416ec9561e
0
void vfs_remove_fsp_extension(vfs_handle_struct *handle, files_struct *fsp) { struct vfs_fsp_data *curr; struct vfs_fsp_data *prev; for (curr = fsp->vfs_extension, prev = NULL; curr; prev = curr, curr = curr->next) { if (curr->owner == handle) { if (prev) { prev->next = curr->next; } else { fsp->vfs_extension = curr->next; } if (curr->destroy) { curr->destroy(EXT_DATA_AREA(curr)); } TALLOC_FREE(curr); return; } } }
CWE-264
2,675
12,868
62577659619870437535575472759496752777
null
null
null
samba
4278ef25f64d5fdbf432ff1534e275416ec9561e
0
int vfs_set_filelen(files_struct *fsp, off_t len) { int ret; contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_SET_FILE_LEN); DEBUG(10,("vfs_set_filelen: ftruncate %s to len %.0f\n", fsp_str_dbg(fsp), (double)len)); flush_write_cache(fsp, SAMBA_SIZECHANGE_FLUSH); if ((ret = SMB_VFS_FTRUNCATE(fsp, len)) != -1) { set_filelen_write_cache(fsp, len); notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED, FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_ATTRIBUTES, fsp->fsp_name->base_name); } contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_SET_FILE_LEN); return ret; }
CWE-264
2,676
12,869
5779533107458426681403301458623266259
null
null
null
samba
4278ef25f64d5fdbf432ff1534e275416ec9561e
0
int vfs_slow_fallocate(files_struct *fsp, off_t offset, off_t len) { ssize_t pwrite_ret; size_t total = 0; if (!sparse_buf) { sparse_buf = SMB_CALLOC_ARRAY(char, SPARSE_BUF_WRITE_SIZE); if (!sparse_buf) { errno = ENOMEM; return -1; } } while (total < len) { size_t curr_write_size = MIN(SPARSE_BUF_WRITE_SIZE, (len - total)); pwrite_ret = SMB_VFS_PWRITE(fsp, sparse_buf, curr_write_size, offset + total); if (pwrite_ret == -1) { int saved_errno = errno; DEBUG(10,("vfs_slow_fallocate: SMB_VFS_PWRITE for file " "%s failed with error %s\n", fsp_str_dbg(fsp), strerror(saved_errno))); errno = saved_errno; return -1; } total += pwrite_ret; } return 0; }
CWE-264
2,677
12,870
102098134014334891491371225302545132122
null
null
null
samba
4278ef25f64d5fdbf432ff1534e275416ec9561e
0
off_t vfs_transfer_file(files_struct *in, files_struct *out, off_t n) { return transfer_file_internal((void *)in, (void *)out, n, vfs_pread_fn, vfs_pwrite_fn); }
CWE-264
2,678
12,871
146103509210130400626076507458119762469
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
another_hunk (enum diff difftype, bool rev) { char *s; lin context = 0; size_t chars_read; char numbuf0[LINENUM_LENGTH_BOUND + 1]; char numbuf1[LINENUM_LENGTH_BOUND + 1]; char numbuf2[LINENUM_LENGTH_BOUND + 1]; char numbuf3[LINENUM_LENGTH_BOUND + 1]; set_hunkmax(); while (p_end >= 0) { if (p_end == p_efake) p_end = p_bfake; /* don't free twice */ else free(p_line[p_end]); p_end--; } assert(p_end == -1); p_efake = -1; if (p_c_function) { free (p_c_function); p_c_function = NULL; } p_max = hunkmax; /* gets reduced when --- found */ if (difftype == CONTEXT_DIFF || difftype == NEW_CONTEXT_DIFF) { file_offset line_beginning = file_tell (pfp); /* file pos of the current line */ lin repl_beginning = 0; /* index of --- line */ lin fillcnt = 0; /* #lines of missing ptrn or repl */ lin fillsrc; /* index of first line to copy */ lin filldst; /* index of first missing line */ bool ptrn_spaces_eaten = false; /* ptrn was slightly misformed */ bool some_context = false; /* (perhaps internal) context seen */ bool repl_could_be_missing = true; bool ptrn_missing = false; /* The pattern was missing. */ bool repl_missing = false; /* Likewise for replacement. */ file_offset repl_backtrack_position = 0; /* file pos of first repl line */ lin repl_patch_line; /* input line number for same */ lin repl_context; /* context for same */ lin ptrn_prefix_context = -1; /* lines in pattern prefix context */ lin ptrn_suffix_context = -1; /* lines in pattern suffix context */ lin repl_prefix_context = -1; /* lines in replac. prefix context */ lin ptrn_copiable = 0; /* # of copiable lines in ptrn */ lin repl_copiable = 0; /* Likewise for replacement. */ /* Pacify 'gcc -Wall'. */ fillsrc = filldst = repl_patch_line = repl_context = 0; chars_read = get_line (); if (chars_read == (size_t) -1 || chars_read <= 8 || strncmp (buf, "********", 8) != 0) { next_intuit_at(line_beginning,p_input_line); return chars_read == (size_t) -1 ? -1 : 0; } s = buf; while (*s == '*') s++; if (*s == ' ') { p_c_function = s; while (*s != '\n') s++; *s = '\0'; p_c_function = savestr (p_c_function); if (! p_c_function) return -1; } p_hunk_beg = p_input_line + 1; while (p_end < p_max) { chars_read = get_line (); if (chars_read == (size_t) -1) return -1; if (!chars_read) { if (repl_beginning && repl_could_be_missing) { repl_missing = true; goto hunk_done; } if (p_max - p_end < 4) { strcpy (buf, " \n"); /* assume blank lines got chopped */ chars_read = 3; } else { fatal ("unexpected end of file in patch"); } } p_end++; if (p_end == hunkmax) fatal ("unterminated hunk starting at line %s; giving up at line %s: %s", format_linenum (numbuf0, pch_hunk_beg ()), format_linenum (numbuf1, p_input_line), buf); assert(p_end < hunkmax); p_Char[p_end] = *buf; p_len[p_end] = 0; p_line[p_end] = 0; switch (*buf) { case '*': if (strnEQ(buf, "********", 8)) { if (repl_beginning && repl_could_be_missing) { repl_missing = true; goto hunk_done; } else fatal ("unexpected end of hunk at line %s", format_linenum (numbuf0, p_input_line)); } if (p_end != 0) { if (repl_beginning && repl_could_be_missing) { repl_missing = true; goto hunk_done; } fatal ("unexpected '***' at line %s: %s", format_linenum (numbuf0, p_input_line), buf); } context = 0; p_len[p_end] = strlen (buf); if (! (p_line[p_end] = savestr (buf))) { p_end--; return -1; } for (s = buf; *s && !ISDIGIT (*s); s++) /* do nothing */ ; if (strnEQ(s,"0,0",3)) remove_prefix (s, 2); s = scan_linenum (s, &p_first); if (*s == ',') { while (*s && !ISDIGIT (*s)) s++; scan_linenum (s, &p_ptrn_lines); p_ptrn_lines += 1 - p_first; if (p_ptrn_lines < 0) malformed (); } else if (p_first) p_ptrn_lines = 1; else { p_ptrn_lines = 0; p_first = 1; } if (p_first >= LINENUM_MAX - p_ptrn_lines || p_ptrn_lines >= LINENUM_MAX - 6) malformed (); p_max = p_ptrn_lines + 6; /* we need this much at least */ while (p_max + 1 >= hunkmax) if (! grow_hunkmax ()) return -1; p_max = hunkmax; break; case '-': if (buf[1] != '-') goto change_line; if (ptrn_prefix_context == -1) ptrn_prefix_context = context; ptrn_suffix_context = context; if (repl_beginning || (p_end != p_ptrn_lines + 1 + (p_Char[p_end - 1] == '\n'))) { if (p_end == 1) { /* 'Old' lines were omitted. Set up to fill them in from 'new' context lines. */ ptrn_missing = true; p_end = p_ptrn_lines + 1; ptrn_prefix_context = ptrn_suffix_context = -1; fillsrc = p_end + 1; filldst = 1; fillcnt = p_ptrn_lines; } else if (! repl_beginning) fatal ("%s '---' at line %s; check line numbers at line %s", (p_end <= p_ptrn_lines ? "Premature" : "Overdue"), format_linenum (numbuf0, p_input_line), format_linenum (numbuf1, p_hunk_beg)); else if (! repl_could_be_missing) fatal ("duplicate '---' at line %s; check line numbers at line %s", format_linenum (numbuf0, p_input_line), format_linenum (numbuf1, p_hunk_beg + repl_beginning)); else { repl_missing = true; goto hunk_done; } } repl_beginning = p_end; repl_backtrack_position = file_tell (pfp); repl_patch_line = p_input_line; repl_context = context; p_len[p_end] = strlen (buf); if (! (p_line[p_end] = savestr (buf))) { p_end--; return -1; } p_Char[p_end] = '='; for (s = buf; *s && ! ISDIGIT (*s); s++) /* do nothing */ ; s = scan_linenum (s, &p_newfirst); if (*s == ',') { do { if (!*++s) malformed (); } while (! ISDIGIT (*s)); scan_linenum (s, &p_repl_lines); p_repl_lines += 1 - p_newfirst; if (p_repl_lines < 0) malformed (); } else if (p_newfirst) p_repl_lines = 1; else { p_repl_lines = 0; p_newfirst = 1; } if (p_newfirst >= LINENUM_MAX - p_repl_lines || p_repl_lines >= LINENUM_MAX - p_end) malformed (); p_max = p_repl_lines + p_end; while (p_max + 1 >= hunkmax) if (! grow_hunkmax ()) return -1; if (p_repl_lines != ptrn_copiable && (p_prefix_context != 0 || context != 0 || p_repl_lines != 1)) repl_could_be_missing = false; context = 0; break; case '+': case '!': repl_could_be_missing = false; change_line: s = buf + 1; chars_read--; if (*s == '\n' && canonicalize_ws) { strcpy (s, " \n"); chars_read = 2; } if (*s == ' ' || *s == '\t') { s++; chars_read--; } else if (repl_beginning && repl_could_be_missing) { repl_missing = true; goto hunk_done; } if (! repl_beginning) { if (ptrn_prefix_context == -1) ptrn_prefix_context = context; } else { if (repl_prefix_context == -1) repl_prefix_context = context; } chars_read -= (1 < chars_read && p_end == (repl_beginning ? p_max : p_ptrn_lines) && incomplete_line ()); p_len[p_end] = chars_read; p_line[p_end] = savebuf (s, chars_read); if (chars_read && ! p_line[p_end]) { p_end--; return -1; } context = 0; break; case '\t': case '\n': /* assume spaces got eaten */ s = buf; if (*buf == '\t') { s++; chars_read--; } if (repl_beginning && repl_could_be_missing && (!ptrn_spaces_eaten || difftype == NEW_CONTEXT_DIFF) ) { repl_missing = true; goto hunk_done; } chars_read -= (1 < chars_read && p_end == (repl_beginning ? p_max : p_ptrn_lines) && incomplete_line ()); p_len[p_end] = chars_read; p_line[p_end] = savebuf (buf, chars_read); if (chars_read && ! p_line[p_end]) { p_end--; return -1; } if (p_end != p_ptrn_lines + 1) { ptrn_spaces_eaten |= (repl_beginning != 0); some_context = true; context++; if (repl_beginning) repl_copiable++; else ptrn_copiable++; p_Char[p_end] = ' '; } break; case ' ': s = buf + 1; chars_read--; if (*s == '\n' && canonicalize_ws) { strcpy (s, "\n"); chars_read = 2; } if (*s == ' ' || *s == '\t') { s++; chars_read--; } else if (repl_beginning && repl_could_be_missing) { repl_missing = true; goto hunk_done; } some_context = true; context++; if (repl_beginning) repl_copiable++; else ptrn_copiable++; chars_read -= (1 < chars_read && p_end == (repl_beginning ? p_max : p_ptrn_lines) && incomplete_line ()); p_len[p_end] = chars_read; p_line[p_end] = savebuf (s, chars_read); if (chars_read && ! p_line[p_end]) { p_end--; return -1; } break; default: if (repl_beginning && repl_could_be_missing) { repl_missing = true; goto hunk_done; } malformed (); } } hunk_done: if (p_end >=0 && !repl_beginning) fatal ("no '---' found in patch at line %s", format_linenum (numbuf0, pch_hunk_beg ())); if (repl_missing) { /* reset state back to just after --- */ p_input_line = repl_patch_line; context = repl_context; for (p_end--; p_end > repl_beginning; p_end--) free(p_line[p_end]); Fseek (pfp, repl_backtrack_position, SEEK_SET); /* redundant 'new' context lines were omitted - set */ /* up to fill them in from the old file context */ fillsrc = 1; filldst = repl_beginning+1; fillcnt = p_repl_lines; p_end = p_max; } else if (! ptrn_missing && ptrn_copiable != repl_copiable) fatal ("context mangled in hunk at line %s", format_linenum (numbuf0, p_hunk_beg)); else if (!some_context && fillcnt == 1) { /* the first hunk was a null hunk with no context */ /* and we were expecting one line -- fix it up. */ while (filldst < p_end) { p_line[filldst] = p_line[filldst+1]; p_Char[filldst] = p_Char[filldst+1]; p_len[filldst] = p_len[filldst+1]; filldst++; } #if 0 repl_beginning--; /* this doesn't need to be fixed */ #endif p_end--; p_first++; /* do append rather than insert */ fillcnt = 0; p_ptrn_lines = 0; } p_prefix_context = ((repl_prefix_context == -1 || (ptrn_prefix_context != -1 && ptrn_prefix_context < repl_prefix_context)) ? ptrn_prefix_context : repl_prefix_context); p_suffix_context = ((ptrn_suffix_context != -1 && ptrn_suffix_context < context) ? ptrn_suffix_context : context); if (p_prefix_context == -1 || p_suffix_context == -1) fatal ("replacement text or line numbers mangled in hunk at line %s", format_linenum (numbuf0, p_hunk_beg)); if (difftype == CONTEXT_DIFF && (fillcnt || (p_first > 1 && p_prefix_context + p_suffix_context < ptrn_copiable))) { if (verbosity == VERBOSE) say ("%s\n%s\n%s\n", "(Fascinating -- this is really a new-style context diff but without", "the telltale extra asterisks on the *** line that usually indicate", "the new style...)"); diff_type = difftype = NEW_CONTEXT_DIFF; } /* if there were omitted context lines, fill them in now */ if (fillcnt) { p_bfake = filldst; /* remember where not to free() */ p_efake = filldst + fillcnt - 1; while (fillcnt-- > 0) { while (fillsrc <= p_end && fillsrc != repl_beginning && p_Char[fillsrc] != ' ') fillsrc++; if (p_end < fillsrc || fillsrc == repl_beginning) { fatal ("replacement text or line numbers mangled in hunk at line %s", format_linenum (numbuf0, p_hunk_beg)); } p_line[filldst] = p_line[fillsrc]; p_Char[filldst] = p_Char[fillsrc]; p_len[filldst] = p_len[fillsrc]; fillsrc++; filldst++; } while (fillsrc <= p_end && fillsrc != repl_beginning) { if (p_Char[fillsrc] == ' ') fatal ("replacement text or line numbers mangled in hunk at line %s", format_linenum (numbuf0, p_hunk_beg)); fillsrc++; } if (debug & 64) printf ("fillsrc %s, filldst %s, rb %s, e+1 %s\n", format_linenum (numbuf0, fillsrc), format_linenum (numbuf1, filldst), format_linenum (numbuf2, repl_beginning), format_linenum (numbuf3, p_end + 1)); assert(fillsrc==p_end+1 || fillsrc==repl_beginning); assert(filldst==p_end+1 || filldst==repl_beginning); } } else if (difftype == UNI_DIFF) { file_offset line_beginning = file_tell (pfp); /* file pos of the current line */ lin fillsrc; /* index of old lines */ lin filldst; /* index of new lines */ char ch = '\0'; chars_read = get_line (); if (chars_read == (size_t) -1 || chars_read <= 4 || strncmp (buf, "@@ -", 4) != 0) { next_intuit_at(line_beginning,p_input_line); return chars_read == (size_t) -1 ? -1 : 0; } s = scan_linenum (buf + 4, &p_first); if (*s == ',') s = scan_linenum (s + 1, &p_ptrn_lines); else p_ptrn_lines = 1; if (p_first >= LINENUM_MAX - p_ptrn_lines) malformed (); if (*s == ' ') s++; if (*s != '+') malformed (); s = scan_linenum (s + 1, &p_newfirst); if (*s == ',') s = scan_linenum (s + 1, &p_repl_lines); else p_repl_lines = 1; if (p_newfirst >= LINENUM_MAX - p_repl_lines) malformed (); if (*s == ' ') s++; if (*s++ != '@') malformed (); if (*s++ == '@' && *s == ' ') { p_c_function = s; while (*s != '\n') s++; *s = '\0'; p_c_function = savestr (p_c_function); if (! p_c_function) return -1; } if (!p_ptrn_lines) p_first++; /* do append rather than insert */ if (!p_repl_lines) p_newfirst++; if (p_ptrn_lines >= LINENUM_MAX - (p_repl_lines + 1)) malformed (); p_max = p_ptrn_lines + p_repl_lines + 1; while (p_max + 1 >= hunkmax) if (! grow_hunkmax ()) return -1; fillsrc = 1; filldst = fillsrc + p_ptrn_lines; p_end = filldst + p_repl_lines; sprintf (buf, "*** %s,%s ****\n", format_linenum (numbuf0, p_first), format_linenum (numbuf1, p_first + p_ptrn_lines - 1)); p_len[0] = strlen (buf); if (! (p_line[0] = savestr (buf))) { p_end = -1; return -1; } p_Char[0] = '*'; sprintf (buf, "--- %s,%s ----\n", format_linenum (numbuf0, p_newfirst), format_linenum (numbuf1, p_newfirst + p_repl_lines - 1)); p_len[filldst] = strlen (buf); if (! (p_line[filldst] = savestr (buf))) { p_end = 0; return -1; } p_Char[filldst++] = '='; p_prefix_context = -1; p_hunk_beg = p_input_line + 1; while (fillsrc <= p_ptrn_lines || filldst <= p_end) { chars_read = get_line (); if (!chars_read) { if (p_max - filldst < 3) { strcpy (buf, " \n"); /* assume blank lines got chopped */ chars_read = 2; } else { fatal ("unexpected end of file in patch"); } } if (chars_read == (size_t) -1) s = 0; else if (*buf == '\t' || *buf == '\n') { ch = ' '; /* assume the space got eaten */ s = savebuf (buf, chars_read); } else { ch = *buf; s = savebuf (buf+1, --chars_read); } if (chars_read && ! s) { while (--filldst > p_ptrn_lines) free(p_line[filldst]); p_end = fillsrc-1; return -1; } switch (ch) { case '-': if (fillsrc > p_ptrn_lines) { free(s); p_end = filldst-1; malformed (); } chars_read -= fillsrc == p_ptrn_lines && incomplete_line (); p_Char[fillsrc] = ch; p_line[fillsrc] = s; p_len[fillsrc++] = chars_read; break; case '=': ch = ' '; /* FALL THROUGH */ case ' ': if (fillsrc > p_ptrn_lines) { free(s); while (--filldst > p_ptrn_lines) free(p_line[filldst]); p_end = fillsrc-1; malformed (); } context++; chars_read -= fillsrc == p_ptrn_lines && incomplete_line (); p_Char[fillsrc] = ch; p_line[fillsrc] = s; p_len[fillsrc++] = chars_read; s = savebuf (s, chars_read); if (chars_read && ! s) { while (--filldst > p_ptrn_lines) free(p_line[filldst]); p_end = fillsrc-1; return -1; } /* FALL THROUGH */ case '+': if (filldst > p_end) { free(s); while (--filldst > p_ptrn_lines) free(p_line[filldst]); p_end = fillsrc-1; malformed (); } chars_read -= filldst == p_end && incomplete_line (); p_Char[filldst] = ch; p_line[filldst] = s; p_len[filldst++] = chars_read; break; default: p_end = filldst; malformed (); } if (ch != ' ') { if (p_prefix_context == -1) p_prefix_context = context; context = 0; } }/* while */ if (p_prefix_context == -1) malformed (); p_suffix_context = context; } else { /* normal diff--fake it up */ char hunk_type; int i; lin min, max; file_offset line_beginning = file_tell (pfp); p_prefix_context = p_suffix_context = 0; chars_read = get_line (); if (chars_read == (size_t) -1 || !chars_read || !ISDIGIT (*buf)) { next_intuit_at(line_beginning,p_input_line); return chars_read == (size_t) -1 ? -1 : 0; } s = scan_linenum (buf, &p_first); if (*s == ',') { s = scan_linenum (s + 1, &p_ptrn_lines); p_ptrn_lines += 1 - p_first; } else p_ptrn_lines = (*s != 'a'); if (p_first >= LINENUM_MAX - p_ptrn_lines) malformed (); hunk_type = *s; if (hunk_type == 'a') p_first++; /* do append rather than insert */ s = scan_linenum (s + 1, &min); if (*s == ',') scan_linenum (s + 1, &max); else max = min; if (min > max || max - min == LINENUM_MAX) malformed (); if (hunk_type == 'd') min++; p_newfirst = min; p_repl_lines = max - min + 1; if (p_newfirst >= LINENUM_MAX - p_repl_lines) malformed (); if (p_ptrn_lines >= LINENUM_MAX - (p_repl_lines + 1)) malformed (); p_end = p_ptrn_lines + p_repl_lines + 1; while (p_end + 1 >= hunkmax) if (! grow_hunkmax ()) { p_end = -1; return -1; } sprintf (buf, "*** %s,%s\n", format_linenum (numbuf0, p_first), format_linenum (numbuf1, p_first + p_ptrn_lines - 1)); p_len[0] = strlen (buf); if (! (p_line[0] = savestr (buf))) { p_end = -1; return -1; } p_Char[0] = '*'; for (i=1; i<=p_ptrn_lines; i++) { chars_read = get_line (); if (chars_read == (size_t) -1) { p_end = i - 1; return -1; } if (!chars_read) fatal ("unexpected end of file in patch at line %s", format_linenum (numbuf0, p_input_line)); if (buf[0] != '<' || (buf[1] != ' ' && buf[1] != '\t')) fatal ("'<' followed by space or tab expected at line %s of patch", format_linenum (numbuf0, p_input_line)); chars_read -= 2 + (i == p_ptrn_lines && incomplete_line ()); p_len[i] = chars_read; p_line[i] = savebuf (buf + 2, chars_read); if (chars_read && ! p_line[i]) { p_end = i-1; return -1; } p_Char[i] = '-'; } if (hunk_type == 'c') { chars_read = get_line (); if (chars_read == (size_t) -1) { p_end = i - 1; return -1; } if (! chars_read) fatal ("unexpected end of file in patch at line %s", format_linenum (numbuf0, p_input_line)); if (*buf != '-') fatal ("'---' expected at line %s of patch", format_linenum (numbuf0, p_input_line)); } sprintf (buf, "--- %s,%s\n", format_linenum (numbuf0, min), format_linenum (numbuf1, max)); p_len[i] = strlen (buf); if (! (p_line[i] = savestr (buf))) { p_end = i-1; return -1; } p_Char[i] = '='; for (i++; i<=p_end; i++) { chars_read = get_line (); if (chars_read == (size_t) -1) { p_end = i - 1; return -1; } if (!chars_read) fatal ("unexpected end of file in patch at line %s", format_linenum (numbuf0, p_input_line)); if (buf[0] != '>' || (buf[1] != ' ' && buf[1] != '\t')) fatal ("'>' followed by space or tab expected at line %s of patch", format_linenum (numbuf0, p_input_line)); chars_read -= 2 + (i == p_end && incomplete_line ()); p_len[i] = chars_read; p_line[i] = savebuf (buf + 2, chars_read); if (chars_read && ! p_line[i]) { p_end = i-1; return -1; } p_Char[i] = '+'; } } if (rev) /* backwards patch? */ if (!pch_swap()) say ("Not enough memory to swap next hunk!\n"); assert (p_end + 1 < hunkmax); p_Char[p_end + 1] = '^'; /* add a stopper for apply_hunk */ if (debug & 2) { lin i; for (i = 0; i <= p_end + 1; i++) { fprintf (stderr, "%s %c", format_linenum (numbuf0, i), p_Char[i]); if (p_Char[i] == '*') fprintf (stderr, " %s,%s\n", format_linenum (numbuf0, p_first), format_linenum (numbuf1, p_ptrn_lines)); else if (p_Char[i] == '=') fprintf (stderr, " %s,%s\n", format_linenum (numbuf0, p_newfirst), format_linenum (numbuf1, p_repl_lines)); else if (p_Char[i] != '^') { fputs(" |", stderr); pch_write_line (i, stderr); } else fputc('\n', stderr); } fflush (stderr); } return 1; }
CWE-78
2,679
12,872
156789205795336027864206308151185582751
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
best_name (char *const *name, int const *ignore) { enum nametype i; int components[3]; int components_min = INT_MAX; size_t basename_len[3]; size_t basename_len_min = SIZE_MAX; size_t len[3]; size_t len_min = SIZE_MAX; for (i = OLD; i <= INDEX; i++) if (name[i] && !ignore[i]) { /* Take the names with the fewest prefix components. */ components[i] = prefix_components (name[i], false); if (components_min < components[i]) continue; components_min = components[i]; /* Of those, take the names with the shortest basename. */ basename_len[i] = base_len (name[i]); if (basename_len_min < basename_len[i]) continue; basename_len_min = basename_len[i]; /* Of those, take the shortest names. */ len[i] = strlen (name[i]); if (len_min < len[i]) continue; len_min = len[i]; } /* Of those, take the first name. */ for (i = OLD; i <= INDEX; i++) if (name[i] && !ignore[i] && name_is_valid (name[i]) && components[i] == components_min && basename_len[i] == basename_len_min && len[i] == len_min) break; return i; }
CWE-78
2,680
12,873
9509497684600764796030471890045279002
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
fetchmode (char const *str) { const char *s; mode_t mode; while (ISSPACE ((unsigned char) *str)) str++; for (s = str, mode = 0; s < str + 6; s++) { if (*s >= '0' && *s <= '7') mode = (mode << 3) + (*s - '0'); else { mode = 0; break; } } if (*s == '\r') s++; if (*s != '\n') mode = 0; /* NOTE: The "diff --git" format always sets the file mode permission bits of symlinks to 0. (On Linux, symlinks actually always have 0777 permissions, so this is not even consistent.) */ return mode; }
CWE-78
2,681
12,874
77035898437383166206549673216973259434
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
get_ed_command_letter (char const *line) { char const *p = line; char letter; bool pair = false; if (ISDIGIT (*p)) { while (ISDIGIT (*++p)) /* do nothing */ ; if (*p == ',') { if (! ISDIGIT (*++p)) return 0; while (ISDIGIT (*++p)) /* do nothing */ ; pair = true; } } letter = *p++; switch (letter) { case 'a': case 'i': if (pair) return 0; break; case 'c': case 'd': break; case 's': if (strncmp (p, "/.//", 4) != 0) return 0; p += 4; break; default: return 0; } while (*p == ' ' || *p == '\t') p++; if (*p == '\n') return letter; return 0; }
CWE-78
2,682
12,875
278989658672877047947289521512549004000
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
get_line (void) { return pget_line (p_indent, p_rfc934_nesting, p_strip_trailing_cr, p_pass_comments_through); }
CWE-78
2,683
12,876
196387020486838560634146065970881400300
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
get_sha1(char **sha1, char const *start, char const *end) { unsigned int len = end - start; *sha1 = xmalloc (len + 1); memcpy (*sha1, start, len); (*sha1)[len] = 0; }
CWE-78
2,684
12,877
240374617207334119589247185178968147697
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
grow_hunkmax (void) { hunkmax *= 2; assert (p_line && p_len && p_Char); if ((p_line = realloc (p_line, hunkmax * sizeof (*p_line))) && (p_len = realloc (p_len, hunkmax * sizeof (*p_len))) && (p_Char = realloc (p_Char, hunkmax * sizeof (*p_Char)))) return true; if (!using_plan_a) xalloc_die (); /* Don't free previous values of p_line etc., since some broken implementations free them for us. Whatever is null will be allocated again from within plan_a (), of all places. */ return false; }
CWE-78
2,685
12,878
216403562209770583840259555686118025211
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
incomplete_line (void) { FILE *fp = pfp; int c; file_offset line_beginning = file_tell (fp); if (getc (fp) == '\\') { while ((c = getc (fp)) != '\n' && c != EOF) /* do nothing */ ; return true; } else { /* We don't trust ungetc. */ Fseek (pfp, line_beginning, SEEK_SET); return false; } }
CWE-78
2,686
12,879
142473767899011448879986161054145298434
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
malformed (void) { char numbuf[LINENUM_LENGTH_BOUND + 1]; fatal ("malformed patch at line %s: %s", format_linenum (numbuf, p_input_line), buf); /* about as informative as "Syntax error" in C */ }
CWE-78
2,687
12,880
325628780710024540769367200438735479726
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
maybe_reverse (char const *name, bool nonexistent, bool is_empty) { bool looks_reversed = (! is_empty) < p_says_nonexistent[reverse ^ is_empty]; /* Allow to create and delete empty files when we know that they are empty: in the "diff --git" format, we know that from the index header. */ if (is_empty && p_says_nonexistent[reverse ^ nonexistent] == 1 && p_says_nonexistent[! reverse ^ nonexistent] == 2) return false; if (looks_reversed) reverse ^= ok_to_reverse ("The next patch%s would %s the file %s,\nwhich %s!", reverse ? ", when reversed," : "", (nonexistent ? "delete" : is_empty ? "empty out" : "create"), quotearg (name), (nonexistent ? "does not exist" : is_empty ? "is already empty" : "already exists")); return looks_reversed; }
CWE-78
2,688
12,881
111851605719924564068750091586893852298
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
name_is_valid (char const *name) { int i; bool is_valid = true; for (i = 0; i < ARRAY_SIZE (invalid_names); i++) { if (! invalid_names[i]) break; if (! strcmp (invalid_names[i], name)) return false; } is_valid = filename_is_safe (name); /* Allow any filename if we are in the filesystem root. */ if (! is_valid && cwd_is_root (name)) is_valid = true; if (! is_valid) { say ("Ignoring potentially dangerous file name %s\n", quotearg (name)); if (i < ARRAY_SIZE (invalid_names)) invalid_names[i] = name; } return is_valid; }
CWE-78
2,689
12,882
79862950876850191783741473211465739412
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
next_intuit_at (file_offset file_pos, lin file_line) { p_base = file_pos; p_bline = file_line; }
CWE-78
2,690
12,883
176657823479154785771307710812126835593
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
open_patch_file (char const *filename) { file_offset file_pos = 0; file_offset pos; struct stat st; if (!filename || !*filename || strEQ (filename, "-")) pfp = stdin; else { pfp = fopen (filename, binary_transput ? "rb" : "r"); if (!pfp) pfatal ("Can't open patch file %s", quotearg (filename)); } #if HAVE_SETMODE_DOS if (binary_transput) { if (isatty (fileno (pfp))) fatal ("cannot read binary data from tty on this platform"); setmode (fileno (pfp), O_BINARY); } #endif if (fstat (fileno (pfp), &st) != 0) pfatal ("fstat"); if (S_ISREG (st.st_mode) && (pos = file_tell (pfp)) != -1) file_pos = pos; else { size_t charsread; int fd; FILE *read_pfp = pfp; fd = make_tempfile (&TMPPATNAME, 'p', NULL, O_RDWR | O_BINARY, 0); if (fd == -1) pfatal ("Can't create temporary file %s", TMPPATNAME); TMPPATNAME_needs_removal = true; pfp = fdopen (fd, "w+b"); if (! pfp) pfatal ("Can't open stream for file %s", quotearg (TMPPATNAME)); for (st.st_size = 0; (charsread = fread (buf, 1, bufsize, read_pfp)) != 0; st.st_size += charsread) if (fwrite (buf, 1, charsread, pfp) != charsread) write_fatal (); if (ferror (read_pfp) || fclose (read_pfp) != 0) read_fatal (); if (fflush (pfp) != 0 || file_seek (pfp, (file_offset) 0, SEEK_SET) != 0) write_fatal (); } p_filesize = st.st_size; if (p_filesize != (file_offset) p_filesize) fatal ("patch file is too long"); next_intuit_at (file_pos, 1); }
CWE-78
2,691
12,884
182153303616940970883628113685128717113
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
pch_char (lin line) { return p_Char[line]; }
CWE-78
2,693
12,885
113189287940409646919659756563186133182
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
pch_end (void) { return p_end; }
CWE-78
2,695
12,886
213575755474852095490347293826935213439
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
pch_git_diff (void) { return p_git_diff; }
CWE-78
2,697
12,887
285589485354817064022962553969807012233
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
pch_hunk_beg (void) { return p_hunk_beg; }
CWE-78
2,698
12,888
87020067448146859747957118410636608848
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
pch_line_len (lin line) { return p_len[line]; }
CWE-78
2,699
12,889
171183517600254416054002244816257968307
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
pch_mode (bool which) { return p_mode[which]; }
CWE-78
2,700
12,890
4349191385757602892173594413396310731
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
pch_name (enum nametype type) { return type == NONE ? NULL : p_name[type]; }
CWE-78
2,701
12,891
62647585479943306808479560493127890294
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
pch_newfirst (void) { return p_newfirst; }
CWE-78
2,702
12,892
86801142811887168418296938212630772807
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
pch_prefix_context (void) { return p_prefix_context; }
CWE-78
2,703
12,893
254261737676717747578462751008844619811
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
bool pch_rename (void) { return p_rename[OLD] && p_rename[NEW]; }
CWE-78
2,705
12,894
278740633775403650369242929601860616501
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
pch_repl_lines (void) { return p_repl_lines; }
CWE-78
2,706
12,895
116134114917841570502402836261017220768
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
pch_says_nonexistent (bool which) { return p_says_nonexistent[which]; }
CWE-78
2,707
12,896
226208491458555413444690429979422332662
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
pch_sha1 (bool which) { return p_sha1[which]; }
CWE-78
2,708
12,897
285361766700519944141631926792165933768
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
pch_suffix_context (void) { return p_suffix_context; }
CWE-78
2,709
12,898
256839133313721429667725394858223030593
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
pch_timestr (bool which) { return p_timestr[which]; }
CWE-78
2,711
12,899
298705250631110871912547649882594516979
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
pget_line (size_t indent, int rfc934_nesting, bool strip_trailing_cr, bool pass_comments_through) { FILE *fp = pfp; int c; size_t i; char *b; size_t s; do { i = 0; for (;;) { c = getc (fp); if (c == EOF) { if (ferror (fp)) read_fatal (); return 0; } if (indent <= i) break; if (c == ' ' || c == 'X') i++; else if (c == '\t') i = (i + 8) & ~7; else break; } i = 0; b = buf; while (c == '-' && 0 <= --rfc934_nesting) { c = getc (fp); if (c == EOF) goto patch_ends_in_middle_of_line; if (c != ' ') { i = 1; b[0] = '-'; break; } c = getc (fp); if (c == EOF) goto patch_ends_in_middle_of_line; } s = bufsize; for (;;) { if (i == s - 1) { s *= 2; b = realloc (b, s); if (!b) { if (!using_plan_a) xalloc_die (); return (size_t) -1; } buf = b; bufsize = s; } b[i++] = c; if (c == '\n') break; c = getc (fp); if (c == EOF) goto patch_ends_in_middle_of_line; } p_input_line++; } while (*b == '#' && !pass_comments_through); if (strip_trailing_cr && 2 <= i && b[i - 2] == '\r') b[i-- - 2] = '\n'; b[i] = '\0'; return i; patch_ends_in_middle_of_line: if (ferror (fp)) read_fatal (); say ("patch unexpectedly ends in middle of line\n"); return 0; }
CWE-78
2,714
12,900
327183863968774372327013063844399679122
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
prefix_components (char *filename, bool checkdirs) { int count = 0; struct stat stat_buf; int stat_result; char *f = filename + FILE_SYSTEM_PREFIX_LEN (filename); if (*f) while (*++f) if (ISSLASH (f[0]) && ! ISSLASH (f[-1])) { if (checkdirs) { *f = '\0'; stat_result = safe_stat (filename, &stat_buf); *f = '/'; if (! (stat_result == 0 && S_ISDIR (stat_buf.st_mode))) break; } count++; } return count; }
CWE-78
2,715
12,901
292061560741285403456608184994631046250
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
re_patch (void) { p_first = 0; p_newfirst = 0; p_ptrn_lines = 0; p_repl_lines = 0; p_end = -1; p_max = 0; p_indent = 0; p_strip_trailing_cr = false; }
CWE-78
2,716
12,902
76447009485079843503993942368197297770
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
set_hunkmax (void) { if (!p_line) p_line = xmalloc (hunkmax * sizeof *p_line); if (!p_len) p_len = xmalloc (hunkmax * sizeof *p_len); if (!p_Char) p_Char = xmalloc (hunkmax * sizeof *p_Char); }
CWE-78
2,717
12,903
309383105853887750465030885797951301427
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
skip_hex_digits (char const *str) { char const *s; for (s = str; (*s >= '0' && *s <= '9') || (*s >= 'a' && *s <= 'f'); s++) /* do nothing */ ; return s == str ? NULL : s; }
CWE-78
2,719
12,904
167687049359867986571409947326156224923
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
skip_to (file_offset file_pos, lin file_line) { FILE *i = pfp; FILE *o = stdout; int c; assert(p_base <= file_pos); if ((verbosity == VERBOSE || !inname) && p_base < file_pos) { Fseek (i, p_base, SEEK_SET); say ("The text leading up to this was:\n--------------------------\n"); while (file_tell (i) < file_pos) { putc ('|', o); do { if ((c = getc (i)) == EOF) read_fatal (); putc (c, o); } while (c != '\n'); } say ("--------------------------\n"); } else Fseek (i, file_pos, SEEK_SET); p_input_line = file_line - 1; }
CWE-78
2,720
12,905
118079717602775582033523036532273790649
null
null
null
savannah
3fcd042d26d70856e826a42b5f93dc4854d80bf0
0
there_is_another_patch (bool need_header, mode_t *file_type) { if (p_base != 0 && p_base >= p_filesize) { if (verbosity == VERBOSE) say ("done\n"); return false; } if (verbosity == VERBOSE) say ("Hmm..."); diff_type = intuit_diff_type (need_header, file_type); if (diff_type == NO_DIFF) { if (verbosity == VERBOSE) say (p_base ? " Ignoring the trailing garbage.\ndone\n" : " I can't seem to find a patch in there anywhere.\n"); if (! p_base && p_filesize) fatal ("Only garbage was found in the patch input."); return false; } if (skip_rest_of_patch) { Fseek (pfp, p_start, SEEK_SET); p_input_line = p_sline - 1; return true; } if (verbosity == VERBOSE) say (" %sooks like %s to me...\n", (p_base == 0 ? "L" : "The next patch l"), diff_type == UNI_DIFF ? "a unified diff" : diff_type == CONTEXT_DIFF ? "a context diff" : diff_type == NEW_CONTEXT_DIFF ? "a new-style context diff" : diff_type == NORMAL_DIFF ? "a normal diff" : diff_type == GIT_BINARY_DIFF ? "a git binary diff" : "an ed script" ); if (no_strip_trailing_cr) p_strip_trailing_cr = false; if (verbosity != SILENT) { if (p_indent) say ("(Patch is indented %lu space%s.)\n", (unsigned long int) p_indent, p_indent==1?"":"s"); if (p_strip_trailing_cr) say ("(Stripping trailing CRs from patch; use --binary to disable.)\n"); if (! inname) { char numbuf[LINENUM_LENGTH_BOUND + 1]; say ("can't find file to patch at input line %s\n", format_linenum (numbuf, p_sline)); if (diff_type != ED_DIFF && diff_type != NORMAL_DIFF) say (strippath == -1 ? "Perhaps you should have used the -p or --strip option?\n" : "Perhaps you used the wrong -p or --strip option?\n"); } } skip_to(p_start,p_sline); while (!inname) { char *t; if (force | batch) { say ("No file to patch. Skipping patch.\n"); skip_rest_of_patch = true; return true; } ask ("File to patch: "); t = buf + strlen (buf); if (t > buf + 1 && *(t - 1) == '\n') { inname = xmemdup0 (buf, t - buf - 1); inerrno = stat_file (inname, &instat); if (inerrno) { perror (inname); fflush (stderr); free (inname); inname = 0; } else invc = -1; } if (!inname) { ask ("Skip this patch? [y] "); if (*buf != 'n') { if (verbosity != SILENT) say ("Skipping patch.\n"); skip_rest_of_patch = true; return true; } } } return true; }
CWE-78
2,721
12,906
130862108197889136443754308392250617713
null
null
null
savannah
dce4683cbbe107a95f1f0d45fabc304acfb5d71a
0
get_input_file (char const *filename, char const *outname, mode_t file_type) { bool elsewhere = strcmp (filename, outname) != 0; char const *cs; char *diffbuf; char *getbuf; if (inerrno == -1) inerrno = stat_file (filename, &instat); /* Perhaps look for RCS or SCCS versions. */ if (S_ISREG (file_type) && patch_get && invc != 0 && (inerrno || (! elsewhere && (/* No one can write to it. */ (instat.st_mode & (S_IWUSR|S_IWGRP|S_IWOTH)) == 0 /* Only the owner (who's not me) can write to it. */ || ((instat.st_mode & (S_IWGRP|S_IWOTH)) == 0 && instat.st_uid != geteuid ())))) && (invc = !! (cs = (version_controller (filename, elsewhere, inerrno ? (struct stat *) 0 : &instat, &getbuf, &diffbuf))))) { if (!inerrno) { if (!elsewhere && (instat.st_mode & (S_IWUSR|S_IWGRP|S_IWOTH)) != 0) /* Somebody can write to it. */ fatal ("File %s seems to be locked by somebody else under %s", quotearg (filename), cs); if (diffbuf) { /* It might be checked out unlocked. See if it's safe to check out the default version locked. */ if (verbosity == VERBOSE) say ("Comparing file %s to default %s version...\n", quotearg (filename), cs); if (systemic (diffbuf) != 0) { say ("warning: Patching file %s, which does not match default %s version\n", quotearg (filename), cs); cs = 0; } } if (dry_run) cs = 0; } if (cs && version_get (filename, cs, ! inerrno, elsewhere, getbuf, &instat)) inerrno = 0; free (getbuf); free (diffbuf); } if (inerrno) { instat.st_mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH; instat.st_size = 0; } else if (! ((S_ISREG (file_type) || S_ISLNK (file_type)) && (file_type & S_IFMT) == (instat.st_mode & S_IFMT))) { say ("File %s is not a %s -- refusing to patch\n", quotearg (filename), S_ISLNK (file_type) ? "symbolic link" : "regular file"); return false; } return true; }
CWE-59
2,722
12,907
228721102025008522762958712651040779357
null
null
null
savannah
dce4683cbbe107a95f1f0d45fabc304acfb5d71a
0
re_input (void) { if (using_plan_a) { if (i_buffer) { free (i_buffer); i_buffer = 0; free (i_ptr); } } else { if (tifd >= 0) close (tifd); tifd = -1; if (tibuf[0]) { free (tibuf[0]); tibuf[0] = 0; } tiline[0] = tiline[1] = -1; tireclen = 0; } }
CWE-59
2,724
12,908
74690872128934896264196972649331544762
null
null
null
savannah
dce4683cbbe107a95f1f0d45fabc304acfb5d71a
0
report_revision (bool found_revision) { char const *rev = quotearg (revision); if (found_revision) { if (verbosity == VERBOSE) say ("Good. This file appears to be the %s version.\n", rev); } else if (force) { if (verbosity != SILENT) say ("Warning: this file doesn't appear to be the %s version -- patching anyway.\n", rev); } else if (batch) fatal ("This file doesn't appear to be the %s version -- aborting.", rev); else { ask ("This file doesn't appear to be the %s version -- patch anyway? [n] ", rev); if (*buf != 'y') fatal ("aborted"); } }
CWE-59
2,725
12,909
226103584018110446519731301607306331767
null
null
null
savannah
dce4683cbbe107a95f1f0d45fabc304acfb5d71a
0
too_many_lines (char const *filename) { fatal ("File %s has too many lines", quotearg (filename)); }
CWE-59
2,726
12,910
36215866788484938822512525053552221506
null
null
null
savannah
dce4683cbbe107a95f1f0d45fabc304acfb5d71a
0
Fseek (FILE *stream, file_offset offset, int ptrname) { if (file_seek (stream, offset, ptrname) != 0) pfatal ("fseek"); }
CWE-59
2,727
12,911
18322165002801751204868294362859303179
null
null
null
savannah
dce4683cbbe107a95f1f0d45fabc304acfb5d71a
0
__insert_file_id (struct stat const *st, enum file_id_type type) { file_id *p; static file_id *next_slot; if (!next_slot) next_slot = xmalloc (sizeof *next_slot); next_slot->dev = st->st_dev; next_slot->ino = st->st_ino; next_slot->queued_output = false; p = hash_insert (file_id_table, next_slot); if (!p) xalloc_die (); if (p == next_slot) next_slot = NULL; p->type = type; return p; }
CWE-59
2,728
12,912
88520534876390845634753252763290236672
null
null
null
savannah
dce4683cbbe107a95f1f0d45fabc304acfb5d71a
0
__lookup_file_id (struct stat const *st) { file_id f; f.dev = st->st_dev; f.ino = st->st_ino; return hash_lookup (file_id_table, &f); }
CWE-59
2,729
12,913
102006220852737827116536475494245637014
null
null
null
savannah
dce4683cbbe107a95f1f0d45fabc304acfb5d71a
0
contains_slash (const char *s) { for (; *s; s++) if (ISSLASH(*s)) return true; return false; }
CWE-59
2,730
12,914
132215065949111178935411400000375616757
null
null
null
savannah
dce4683cbbe107a95f1f0d45fabc304acfb5d71a
0
copy_attr (char const *src_path, char const *dst_path) { return 0; }
CWE-59
2,732
12,915
138597939216080316486350701382973944418
null
null
null
savannah
dce4683cbbe107a95f1f0d45fabc304acfb5d71a
0
copy_attr_check (const char *name, struct error_context *ctx) { int action = attr_copy_action (name, ctx); return action == 0 || action == ATTR_ACTION_PERMISSIONS; }
CWE-59
2,733
12,916
235290618994882148767921612357734218263
null
null
null
savannah
dce4683cbbe107a95f1f0d45fabc304acfb5d71a
0
copy_attr_error (struct error_context *ctx, char const *fmt, ...) { int err = errno; va_list ap; if (err != ENOSYS && err != ENOTSUP && err != EPERM) { /* use verror module to print error message */ va_start (ap, fmt); verror (0, err, fmt, ap); va_end (ap); } }
CWE-59
2,734
12,917
314615643859749878214601363673695684776
null
null
null
savannah
dce4683cbbe107a95f1f0d45fabc304acfb5d71a
0
copy_attr_free (struct error_context *ctx, char const *str) { }
CWE-59
2,735
12,918
282182550043181706253388635534553228580
null
null
null
savannah
dce4683cbbe107a95f1f0d45fabc304acfb5d71a
0
copy_attr_quote (struct error_context *ctx, char const *str) { return quotearg (str); }
CWE-59
2,736
12,919
220758973781350260413621911537075867268
null
null
null
dbus
c3223ba6c401ba81df1305851312a47c485e6cd7
0
_dbus_header_cache_check (DBusHeader *header, int field) { _dbus_assert (field <= DBUS_HEADER_FIELD_LAST); if (header->fields[field].value_pos == _DBUS_HEADER_FIELD_VALUE_UNKNOWN) _dbus_header_cache_revalidate (header); if (header->fields[field].value_pos == _DBUS_HEADER_FIELD_VALUE_NONEXISTENT) return FALSE; return TRUE; }
CWE-20
2,737
12,920
144020075076020665207266784410943384792
null
null
null
dbus
c3223ba6c401ba81df1305851312a47c485e6cd7
0
_dbus_header_cache_invalidate_all (DBusHeader *header) { int i; i = 0; while (i <= DBUS_HEADER_FIELD_LAST) { header->fields[i].value_pos = _DBUS_HEADER_FIELD_VALUE_UNKNOWN; ++i; } }
CWE-20
2,738
12,921
317582301025191674991112171856488752383
null
null
null
dbus
c3223ba6c401ba81df1305851312a47c485e6cd7
0
_dbus_header_cache_known_nonexistent (DBusHeader *header, int field) { _dbus_assert (field <= DBUS_HEADER_FIELD_LAST); return (header->fields[field].value_pos == _DBUS_HEADER_FIELD_VALUE_NONEXISTENT); }
CWE-20
2,739
12,922
211413715981418779998331264403624937678
null
null
null
dbus
c3223ba6c401ba81df1305851312a47c485e6cd7
0
_dbus_header_cache_one (DBusHeader *header, int field_code, DBusTypeReader *variant_reader) { header->fields[field_code].value_pos = _dbus_type_reader_get_value_pos (variant_reader); #if 0 _dbus_verbose ("cached value_pos %d for field %d\n", header->fields[field_code].value_pos, field_code) #endif }
CWE-20
2,740
12,923
126355070039433636751440992799181045962
null
null
null
dbus
c3223ba6c401ba81df1305851312a47c485e6cd7
0
_dbus_header_cache_revalidate (DBusHeader *header) { DBusTypeReader array; DBusTypeReader reader; int i; i = 0; while (i <= DBUS_HEADER_FIELD_LAST) { header->fields[i].value_pos = _DBUS_HEADER_FIELD_VALUE_NONEXISTENT; ++i; } _dbus_type_reader_init (&reader, header->byte_order, &_dbus_header_signature_str, FIELDS_ARRAY_SIGNATURE_OFFSET, &header->data, FIELDS_ARRAY_LENGTH_OFFSET); _dbus_type_reader_recurse (&reader, &array); while (_dbus_type_reader_get_current_type (&array) != DBUS_TYPE_INVALID) { DBusTypeReader sub; DBusTypeReader variant; unsigned char field_code; _dbus_type_reader_recurse (&array, &sub); _dbus_assert (_dbus_type_reader_get_current_type (&sub) == DBUS_TYPE_BYTE); _dbus_type_reader_read_basic (&sub, &field_code); /* Unknown fields should be ignored */ if (field_code > DBUS_HEADER_FIELD_LAST) goto next_field; _dbus_type_reader_next (&sub); _dbus_assert (_dbus_type_reader_get_current_type (&sub) == DBUS_TYPE_VARIANT); _dbus_type_reader_recurse (&sub, &variant); _dbus_header_cache_one (header, field_code, &variant); next_field: _dbus_type_reader_next (&array); } }
CWE-20
2,741
12,924
322166570115088641801614144118335116734
null
null
null
dbus
c3223ba6c401ba81df1305851312a47c485e6cd7
0
_dbus_header_copy (const DBusHeader *header, DBusHeader *dest) { *dest = *header; if (!_dbus_string_init_preallocated (&dest->data, _dbus_string_get_length (&header->data))) return FALSE; if (!_dbus_string_copy (&header->data, 0, &dest->data, 0)) { _dbus_string_free (&dest->data); return FALSE; } /* Reset the serial */ _dbus_header_set_serial (dest, 0); return TRUE; }
CWE-20
2,742
12,925
266154531972123821894969474205805542473
null
null
null
dbus
c3223ba6c401ba81df1305851312a47c485e6cd7
0
_dbus_header_create (DBusHeader *header, int message_type, const char *destination, const char *path, const char *interface, const char *member, const char *error_name) { unsigned char v_BYTE; dbus_uint32_t v_UINT32; DBusTypeWriter writer; DBusTypeWriter array; _dbus_assert (((interface || message_type != DBUS_MESSAGE_TYPE_SIGNAL) && member) || (error_name) || !(interface || member || error_name)); _dbus_assert (_dbus_string_get_length (&header->data) == 0); if (!reserve_header_padding (header)) return FALSE; _dbus_type_writer_init_values_only (&writer, header->byte_order, &_dbus_header_signature_str, 0, &header->data, HEADER_END_BEFORE_PADDING (header)); v_BYTE = header->byte_order; if (!_dbus_type_writer_write_basic (&writer, DBUS_TYPE_BYTE, &v_BYTE)) goto oom; v_BYTE = message_type; if (!_dbus_type_writer_write_basic (&writer, DBUS_TYPE_BYTE, &v_BYTE)) goto oom; v_BYTE = 0; /* flags */ if (!_dbus_type_writer_write_basic (&writer, DBUS_TYPE_BYTE, &v_BYTE)) goto oom; v_BYTE = DBUS_MAJOR_PROTOCOL_VERSION; if (!_dbus_type_writer_write_basic (&writer, DBUS_TYPE_BYTE, &v_BYTE)) goto oom; v_UINT32 = 0; /* body length */ if (!_dbus_type_writer_write_basic (&writer, DBUS_TYPE_UINT32, &v_UINT32)) goto oom; v_UINT32 = 0; /* serial */ if (!_dbus_type_writer_write_basic (&writer, DBUS_TYPE_UINT32, &v_UINT32)) goto oom; if (!_dbus_type_writer_recurse (&writer, DBUS_TYPE_ARRAY, &_dbus_header_signature_str, FIELDS_ARRAY_SIGNATURE_OFFSET, &array)) goto oom; /* Marshal all the fields (Marshall Fields?) */ if (path != NULL) { if (!write_basic_field (&array, DBUS_HEADER_FIELD_PATH, DBUS_TYPE_OBJECT_PATH, &path)) goto oom; } if (destination != NULL) { if (!write_basic_field (&array, DBUS_HEADER_FIELD_DESTINATION, DBUS_TYPE_STRING, &destination)) goto oom; } if (interface != NULL) { if (!write_basic_field (&array, DBUS_HEADER_FIELD_INTERFACE, DBUS_TYPE_STRING, &interface)) goto oom; } if (member != NULL) { if (!write_basic_field (&array, DBUS_HEADER_FIELD_MEMBER, DBUS_TYPE_STRING, &member)) goto oom; } if (error_name != NULL) { if (!write_basic_field (&array, DBUS_HEADER_FIELD_ERROR_NAME, DBUS_TYPE_STRING, &error_name)) goto oom; } if (!_dbus_type_writer_unrecurse (&writer, &array)) goto oom; correct_header_padding (header); return TRUE; oom: _dbus_string_delete (&header->data, 0, _dbus_string_get_length (&header->data) - header->padding); correct_header_padding (header); return FALSE; }
CWE-20
2,743
12,926
39794338453660146939547425315036990661
null
null
null
dbus
c3223ba6c401ba81df1305851312a47c485e6cd7
0
_dbus_header_delete_field (DBusHeader *header, int field) { DBusTypeReader reader; DBusTypeReader realign_root; if (_dbus_header_cache_known_nonexistent (header, field)) return TRUE; /* nothing to do */ /* Scan to the field we want, delete and realign, reappend * padding. Field may turn out not to exist. */ if (!find_field_for_modification (header, field, &reader, &realign_root)) return TRUE; /* nothing to do */ if (!reserve_header_padding (header)) return FALSE; if (!_dbus_type_reader_delete (&reader, &realign_root)) return FALSE; correct_header_padding (header); _dbus_header_cache_invalidate_all (header); _dbus_assert (!_dbus_header_cache_check (header, field)); /* Expensive assertion ... */ return TRUE; }
CWE-20
2,744
12,927
336313583656515616917286777628770728629
null
null
null
dbus
c3223ba6c401ba81df1305851312a47c485e6cd7
0
_dbus_header_free (DBusHeader *header) { _dbus_string_free (&header->data); }
CWE-20
2,745
12,928
220017667161735045496684331985361782925
null
null
null
dbus
c3223ba6c401ba81df1305851312a47c485e6cd7
0
_dbus_header_get_field_raw (DBusHeader *header, int field, const DBusString **str, int *pos) { if (!_dbus_header_cache_check (header, field)) return FALSE; if (str) *str = &header->data; if (pos) *pos = header->fields[field].value_pos; return TRUE; }
CWE-20
2,747
12,929
263602942192859149409869219563544559913
null
null
null
dbus
c3223ba6c401ba81df1305851312a47c485e6cd7
0
_dbus_header_get_flag (DBusHeader *header, dbus_uint32_t flag) { const unsigned char *flags_p; flags_p = _dbus_string_get_const_data_len (&header->data, FLAGS_OFFSET, 1); return (*flags_p & flag) != 0; }
CWE-20
2,748
12,930
16736606330099789171411126925411232777
null
null
null
dbus
c3223ba6c401ba81df1305851312a47c485e6cd7
0
_dbus_header_get_serial (DBusHeader *header) { return _dbus_marshal_read_uint32 (&header->data, SERIAL_OFFSET, header->byte_order, NULL); }
CWE-20
2,750
12,931
154746899092142118536200609192215988797
null
null
null
dbus
c3223ba6c401ba81df1305851312a47c485e6cd7
0
_dbus_header_have_message_untrusted (int max_message_length, DBusValidity *validity, int *byte_order, int *fields_array_len, int *header_len, int *body_len, const DBusString *str, int start, int len) { dbus_uint32_t header_len_unsigned; dbus_uint32_t fields_array_len_unsigned; dbus_uint32_t body_len_unsigned; _dbus_assert (start >= 0); _dbus_assert (start < _DBUS_INT32_MAX / 2); _dbus_assert (len >= 0); _dbus_assert (start == (int) _DBUS_ALIGN_VALUE (start, 8)); *byte_order = _dbus_string_get_byte (str, start + BYTE_ORDER_OFFSET); if (*byte_order != DBUS_LITTLE_ENDIAN && *byte_order != DBUS_BIG_ENDIAN) { *validity = DBUS_INVALID_BAD_BYTE_ORDER; return FALSE; } _dbus_assert (FIELDS_ARRAY_LENGTH_OFFSET + 4 <= len); fields_array_len_unsigned = _dbus_marshal_read_uint32 (str, start + FIELDS_ARRAY_LENGTH_OFFSET, *byte_order, NULL); if (fields_array_len_unsigned > (unsigned) max_message_length) { *validity = DBUS_INVALID_INSANE_FIELDS_ARRAY_LENGTH; return FALSE; } _dbus_assert (BODY_LENGTH_OFFSET + 4 < len); body_len_unsigned = _dbus_marshal_read_uint32 (str, start + BODY_LENGTH_OFFSET, *byte_order, NULL); if (body_len_unsigned > (unsigned) max_message_length) { *validity = DBUS_INVALID_INSANE_BODY_LENGTH; return FALSE; } header_len_unsigned = FIRST_FIELD_OFFSET + fields_array_len_unsigned; header_len_unsigned = _DBUS_ALIGN_VALUE (header_len_unsigned, 8); /* overflow should be impossible since the lengths aren't allowed to * be huge. */ _dbus_assert (max_message_length < _DBUS_INT32_MAX / 2); if (body_len_unsigned + header_len_unsigned > (unsigned) max_message_length) { *validity = DBUS_INVALID_MESSAGE_TOO_LONG; return FALSE; } _dbus_assert (body_len_unsigned < (unsigned) _DBUS_INT32_MAX); _dbus_assert (fields_array_len_unsigned < (unsigned) _DBUS_INT32_MAX); _dbus_assert (header_len_unsigned < (unsigned) _DBUS_INT32_MAX); *body_len = body_len_unsigned; *fields_array_len = fields_array_len_unsigned; *header_len = header_len_unsigned; *validity = DBUS_VALID; _dbus_verbose ("have %d bytes, need body %u + header %u = %u\n", len, body_len_unsigned, header_len_unsigned, body_len_unsigned + header_len_unsigned); return (body_len_unsigned + header_len_unsigned) <= (unsigned) len; }
CWE-20
2,751
12,932
176748178290246832488498108577460128063
null
null
null
dbus
c3223ba6c401ba81df1305851312a47c485e6cd7
0
_dbus_header_init (DBusHeader *header, int byte_order) { if (!_dbus_string_init_preallocated (&header->data, 32)) return FALSE; _dbus_header_reinit (header, byte_order); return TRUE; }
CWE-20
2,752
12,933
246051285141552217921442573008928142113
null
null
null
dbus
c3223ba6c401ba81df1305851312a47c485e6cd7
0
_dbus_header_reinit (DBusHeader *header, int byte_order) { _dbus_string_set_length (&header->data, 0); header->byte_order = byte_order; header->padding = 0; _dbus_header_cache_invalidate_all (header); }
CWE-20
2,754
12,934
165059247421556405571403618334991914722
null
null
null
dbus
c3223ba6c401ba81df1305851312a47c485e6cd7
0
_dbus_header_set_field_basic (DBusHeader *header, int field, int type, const void *value) { _dbus_assert (field <= DBUS_HEADER_FIELD_LAST); if (!reserve_header_padding (header)) return FALSE; /* If the field exists we set, otherwise we append */ if (_dbus_header_cache_check (header, field)) { DBusTypeReader reader; DBusTypeReader realign_root; if (!find_field_for_modification (header, field, &reader, &realign_root)) _dbus_assert_not_reached ("field was marked present in cache but wasn't found"); if (!set_basic_field (&reader, field, type, value, &realign_root)) return FALSE; } else { DBusTypeWriter writer; DBusTypeWriter array; _dbus_type_writer_init_values_only (&writer, header->byte_order, &_dbus_header_signature_str, FIELDS_ARRAY_SIGNATURE_OFFSET, &header->data, FIELDS_ARRAY_LENGTH_OFFSET); /* recurse into array without creating a new length, and jump to * end of array. */ if (!_dbus_type_writer_append_array (&writer, &_dbus_header_signature_str, FIELDS_ARRAY_ELEMENT_SIGNATURE_OFFSET, &array)) _dbus_assert_not_reached ("recurse into ARRAY should not have used memory"); _dbus_assert (array.u.array.len_pos == FIELDS_ARRAY_LENGTH_OFFSET); _dbus_assert (array.u.array.start_pos == FIRST_FIELD_OFFSET); _dbus_assert (array.value_pos == HEADER_END_BEFORE_PADDING (header)); if (!write_basic_field (&array, field, type, value)) return FALSE; if (!_dbus_type_writer_unrecurse (&writer, &array)) _dbus_assert_not_reached ("unrecurse from ARRAY should not have used memory"); } correct_header_padding (header); /* We could be smarter about this (only invalidate fields after the * one we modified, or even only if the one we modified changed * length). But this hack is a start. */ _dbus_header_cache_invalidate_all (header); return TRUE; }
CWE-20
2,755
12,935
309199238343700374055923380007358474003
null
null
null
dbus
c3223ba6c401ba81df1305851312a47c485e6cd7
0
_dbus_header_set_serial (DBusHeader *header, dbus_uint32_t serial) { /* we use this function to set the serial on outgoing * messages, and to reset the serial in dbus_message_copy; * this assertion should catch a double-set on outgoing. */ _dbus_assert (_dbus_header_get_serial (header) == 0 || serial == 0); _dbus_marshal_set_uint32 (&header->data, SERIAL_OFFSET, serial, header->byte_order); }
CWE-20
2,756
12,936
265991713160041649102752722032656995272
null
null
null
dbus
c3223ba6c401ba81df1305851312a47c485e6cd7
0
_dbus_header_toggle_flag (DBusHeader *header, dbus_uint32_t flag, dbus_bool_t value) { unsigned char *flags_p; flags_p = _dbus_string_get_data_len (&header->data, FLAGS_OFFSET, 1); if (value) *flags_p |= flag; else *flags_p &= ~flag; }
CWE-20
2,757
12,937
339161512677815207216753732029639935062
null
null
null
dbus
c3223ba6c401ba81df1305851312a47c485e6cd7
0
_dbus_header_update_lengths (DBusHeader *header, int body_len) { _dbus_marshal_set_uint32 (&header->data, BODY_LENGTH_OFFSET, body_len, header->byte_order); }
CWE-20
2,758
12,938
236862773916220610991507944251342355598
null
null
null
dbus
c3223ba6c401ba81df1305851312a47c485e6cd7
0
_dbus_marshal_header_test (void) { return TRUE; }
CWE-20
2,759
12,939
254669144716916233123448112050671571792
null
null
null
dbus
c3223ba6c401ba81df1305851312a47c485e6cd7
0
find_field_for_modification (DBusHeader *header, int field, DBusTypeReader *reader, DBusTypeReader *realign_root) { dbus_bool_t retval; retval = FALSE; _dbus_type_reader_init (realign_root, header->byte_order, &_dbus_header_signature_str, FIELDS_ARRAY_SIGNATURE_OFFSET, &header->data, FIELDS_ARRAY_LENGTH_OFFSET); _dbus_type_reader_recurse (realign_root, reader); while (_dbus_type_reader_get_current_type (reader) != DBUS_TYPE_INVALID) { DBusTypeReader sub; unsigned char field_code; _dbus_type_reader_recurse (reader, &sub); _dbus_assert (_dbus_type_reader_get_current_type (&sub) == DBUS_TYPE_BYTE); _dbus_type_reader_read_basic (&sub, &field_code); if (field_code == (unsigned) field) { _dbus_assert (_dbus_type_reader_get_current_type (reader) == DBUS_TYPE_STRUCT); retval = TRUE; goto done; } _dbus_type_reader_next (reader); } done: return retval; }
CWE-20
2,762
12,940
108606903235215713374919759271850855759
null
null
null
dbus
c3223ba6c401ba81df1305851312a47c485e6cd7
0
reserve_header_padding (DBusHeader *header) { _dbus_assert (header->padding <= MAX_POSSIBLE_HEADER_PADDING); if (!_dbus_string_lengthen (&header->data, MAX_POSSIBLE_HEADER_PADDING - header->padding)) return FALSE; header->padding = MAX_POSSIBLE_HEADER_PADDING; return TRUE; }
CWE-20
2,763
12,941
152445938804848391861470896683819473469
null
null
null
dbus
c3223ba6c401ba81df1305851312a47c485e6cd7
0
set_basic_field (DBusTypeReader *reader, int field, int type, const void *value, const DBusTypeReader *realign_root) { DBusTypeReader sub; DBusTypeReader variant; _dbus_type_reader_recurse (reader, &sub); _dbus_assert (_dbus_type_reader_get_current_type (&sub) == DBUS_TYPE_BYTE); #ifndef DBUS_DISABLE_ASSERT { unsigned char v_BYTE; _dbus_type_reader_read_basic (&sub, &v_BYTE); _dbus_assert (((int) v_BYTE) == field); } #endif if (!_dbus_type_reader_next (&sub)) _dbus_assert_not_reached ("no variant field?"); _dbus_type_reader_recurse (&sub, &variant); _dbus_assert (_dbus_type_reader_get_current_type (&variant) == type); if (!_dbus_type_reader_set_basic (&variant, value, realign_root)) return FALSE; return TRUE; }
CWE-20
2,764
12,942
199355673086836482247536549439598911028
null
null
null
dbus
c3223ba6c401ba81df1305851312a47c485e6cd7
0
write_basic_field (DBusTypeWriter *writer, int field, int type, const void *value) { DBusTypeWriter sub; DBusTypeWriter variant; int start; int padding; unsigned char field_byte; DBusString contained_type; char buf[2]; start = writer->value_pos; padding = _dbus_string_get_length (writer->value_str) - start; if (!_dbus_type_writer_recurse (writer, DBUS_TYPE_STRUCT, NULL, 0, &sub)) goto append_failed; field_byte = field; if (!_dbus_type_writer_write_basic (&sub, DBUS_TYPE_BYTE, &field_byte)) goto append_failed; buf[0] = type; buf[1] = '\0'; _dbus_string_init_const_len (&contained_type, buf, 1); if (!_dbus_type_writer_recurse (&sub, DBUS_TYPE_VARIANT, &contained_type, 0, &variant)) goto append_failed; if (!_dbus_type_writer_write_basic (&variant, type, value)) goto append_failed; if (!_dbus_type_writer_unrecurse (&sub, &variant)) goto append_failed; if (!_dbus_type_writer_unrecurse (writer, &sub)) goto append_failed; return TRUE; append_failed: _dbus_string_delete (writer->value_str, start, _dbus_string_get_length (writer->value_str) - start - padding); return FALSE; }
CWE-20
2,765
12,943
176741231719318754951952034729941147712
null
null
null
ghostscript
79cccf641486a6595c43f1de1cd7ade696020a31
0
static RELOC_PTRS_WITH(device_reloc_ptrs, gx_device *dev) { dev->parent = gx_device_reloc_ptr(dev->parent, gcst); dev->child = gx_device_reloc_ptr(dev->child, gcst); }
CWE-78
2,775
12,953
304114002168998008427935802924625792959
null
null
null
ghostscript
79cccf641486a6595c43f1de1cd7ade696020a31
0
static RELOC_PTRS_WITH(device_forward_reloc_ptrs, gx_device_forward *fdev) { fdev->target = gx_device_reloc_ptr(fdev->target, gcst); }
CWE-78
2,776
12,954
219901455457111795503386596965286068935
null
null
null
ghostscript
79cccf641486a6595c43f1de1cd7ade696020a31
0
gs_closedevice(gx_device * dev) { int code = 0; if (dev->is_open) { code = (*dev_proc(dev, close_device))(dev); dev->is_open = false; if (code < 0) return_error(code); } return code; }
CWE-78
2,777
12,955
241688701805302856384816400702951191266
null
null
null
ghostscript
79cccf641486a6595c43f1de1cd7ade696020a31
0
gs_copydevice2(gx_device ** pnew_dev, const gx_device * dev, bool keep_open, gs_memory_t * mem) { gx_device *new_dev; const gs_memory_struct_type_t *std = dev->stype; const gs_memory_struct_type_t *new_std; gs_memory_struct_type_t *a_std = 0; int code; if (dev->stype_is_dynamic) { /* * We allocated the stype for this device previously. * Just allocate a new stype and copy the old one into it. */ a_std = (gs_memory_struct_type_t *) gs_alloc_bytes_immovable(mem->non_gc_memory, sizeof(*std), "gs_copydevice(stype)"); if (!a_std) return_error(gs_error_VMerror); *a_std = *std; new_std = a_std; } else if (std != 0 && std->ssize == dev->params_size) { /* Use the static stype. */ new_std = std; } else { /* We need to figure out or adjust the stype. */ a_std = (gs_memory_struct_type_t *) gs_alloc_bytes_immovable(mem->non_gc_memory, sizeof(*std), "gs_copydevice(stype)"); if (!a_std) return_error(gs_error_VMerror); gx_device_make_struct_type(a_std, dev); new_std = a_std; } /* * Because command list devices have complicated internal pointer * structures, we allocate all device instances as immovable. */ new_dev = gs_alloc_struct_immovable(mem, gx_device, new_std, "gs_copydevice(device)"); if (new_dev == 0) { gs_free_object(mem->non_gc_memory, a_std, "gs_copydevice(stype)"); return_error(gs_error_VMerror); } gx_device_init(new_dev, dev, mem, false); gx_device_set_procs(new_dev); new_dev->stype = new_std; new_dev->stype_is_dynamic = new_std != std; /* * keep_open is very dangerous. On the other hand, so is copydevice in * general, since it just copies the bits without any regard to pointers * (including self-pointers) that they may contain. We handle this by * making the default finish_copydevice forbid copying of anything other * than the device prototype. */ new_dev->is_open = dev->is_open && keep_open; fill_dev_proc(new_dev, finish_copydevice, gx_default_finish_copydevice); code = dev_proc(new_dev, finish_copydevice)(new_dev, dev); if (code < 0) { gs_free_object(mem, new_dev, "gs_copydevice(device)"); #if 0 /* gs_free_object above calls gx_device_finalize, which closes the device and releaszes its stype, i.e. a_std. */ if (a_std) gs_free_object(dev->memory->non_gc_memory, a_std, "gs_copydevice(stype)"); #endif return code; } *pnew_dev = new_dev; return 0; }
CWE-78
2,779
12,956
307728776456067779458865497893671105365
null
null
null
ghostscript
79cccf641486a6595c43f1de1cd7ade696020a31
0
gs_copypage(gs_gstate * pgs) { return gs_output_page(pgs, 1, 0); }
CWE-78
2,780
12,957
273863276612510727931962610343334494834
null
null
null
ghostscript
79cccf641486a6595c43f1de1cd7ade696020a31
0
gs_copyscanlines(gx_device * dev, int start_y, byte * data, uint size, int *plines_copied, uint * pbytes_copied) { uint line_size = gx_device_raster(dev, 0); uint count = size / line_size; uint i; byte *dest = data; for (i = 0; i < count; i++, dest += line_size) { int code = (*dev_proc(dev, get_bits)) (dev, start_y + i, dest, NULL); if (code < 0) { /* Might just be an overrun. */ if (start_y + i == dev->height) break; return_error(code); } } if (plines_copied != NULL) *plines_copied = i; if (pbytes_copied != NULL) *pbytes_copied = i * line_size; return 0; }
CWE-78
2,781
12,958
121176432738769502332367569983735657593
null
null
null
ghostscript
79cccf641486a6595c43f1de1cd7ade696020a31
0
gs_currentdevice(const gs_gstate * pgs) { return pgs->device; }
CWE-78
2,782
12,959
246589197504535079265117175458494341085
null
null
null
ghostscript
79cccf641486a6595c43f1de1cd7ade696020a31
0
gs_deviceinitialmatrix(gx_device * dev, gs_matrix * pmat) { fill_dev_proc(dev, get_initial_matrix, gx_default_get_initial_matrix); (*dev_proc(dev, get_initial_matrix)) (dev, pmat); }
CWE-78
2,783
12,960
241744422895354541430306144805543932130
null
null
null
ghostscript
79cccf641486a6595c43f1de1cd7ade696020a31
0
gs_flushpage(gs_gstate * pgs) { gx_device *dev = gs_currentdevice(pgs); return (*dev_proc(dev, sync_output)) (dev); }
CWE-78
2,785
12,961
118647578009158490564021947560840428871
null
null
null
ghostscript
79cccf641486a6595c43f1de1cd7ade696020a31
0
gs_getdefaultdevice(void) { return gs_getdefaultlibdevice(NULL); }
CWE-78
2,786
12,962
128246745710143340871378972202750341431
null
null
null
ghostscript
79cccf641486a6595c43f1de1cd7ade696020a31
0
gs_getdefaultlibdevice(gs_memory_t *mem) { const gx_device *const *list; int count = gs_lib_device_list(&list, NULL); const char *name, *end, *fin; int i; /* Search the compiled in device list for a known device name */ /* In the case the lib ctx hasn't been initialised */ if (mem && mem->gs_lib_ctx && mem->gs_lib_ctx->default_device_list) { name = mem->gs_lib_ctx->default_device_list; fin = name + strlen(name); } else { name = gs_dev_defaults; fin = name + strlen(name); } /* iterate through each name in the string */ while (name < fin) { /* split a name from any whitespace */ while ((name < fin) && (*name == ' ' || *name == '\t')) name++; end = name; while ((end < fin) && (*end != ' ') && (*end != '\t')) end++; /* return any matches */ for (i = 0; i < count; i++) if ((end - name) == strlen(list[i]->dname)) if (!memcmp(name, list[i]->dname, end - name)) return gs_getdevice(i); /* otherwise, try the next device name */ name = end; } /* Fall back to the first device in the list. */ return gs_getdevice(0); }
CWE-78
2,787
12,963
234235028076659671645978456511644152247
null
null
null
ghostscript
79cccf641486a6595c43f1de1cd7ade696020a31
0
gs_getdevice(int index) { const gx_device *const *list; int count = gs_lib_device_list(&list, NULL); if (index < 0 || index >= count) return 0; /* index out of range */ return list[index]; }
CWE-78
2,788
12,964
192197817241924709424374632389456486391
null
null
null
ghostscript
79cccf641486a6595c43f1de1cd7ade696020a31
0
gs_gstate_putdeviceparams(gs_gstate *pgs, gx_device *dev, gs_param_list *plist) { int code; gx_device *dev2; if (dev) dev2 = dev; else dev2 = pgs->device; code = gs_putdeviceparams(dev2, plist); if (code >= 0) gs_gstate_update_device(pgs, dev2); return code; }
CWE-78
2,789
12,965
284263465545604509825680000803297770986
null
null
null
ghostscript
79cccf641486a6595c43f1de1cd7ade696020a31
0
gs_gstate_update_device(gs_gstate *pgs, gx_device *dev) { gx_set_cmap_procs(pgs, dev); gx_unset_both_dev_colors(pgs); }
CWE-78
2,790
12,966
220349104624773155207484625699383784480
null
null
null
ghostscript
79cccf641486a6595c43f1de1cd7ade696020a31
0
gs_make_null_device(gx_device_null *dev_null, gx_device *dev, gs_memory_t * mem) { gx_device_init((gx_device *)dev_null, (const gx_device *)&gs_null_device, mem, true); gx_device_set_target((gx_device_forward *)dev_null, dev); if (dev) { /* The gx_device_copy_color_params() call below should probably copy over these new-style color mapping procs, as well as the old-style (map_rgb_color and friends). However, the change was made here instead, to minimize the potential impact of the patch. */ gx_device *dn = (gx_device *)dev_null; set_dev_proc(dn, get_color_mapping_procs, gx_forward_get_color_mapping_procs); set_dev_proc(dn, get_color_comp_index, gx_forward_get_color_comp_index); set_dev_proc(dn, encode_color, gx_forward_encode_color); set_dev_proc(dn, decode_color, gx_forward_decode_color); set_dev_proc(dn, get_profile, gx_forward_get_profile); set_dev_proc(dn, set_graphics_type_tag, gx_forward_set_graphics_type_tag); set_dev_proc(dn, begin_transparency_group, gx_default_begin_transparency_group); set_dev_proc(dn, end_transparency_group, gx_default_end_transparency_group); set_dev_proc(dn, begin_transparency_mask, gx_default_begin_transparency_mask); set_dev_proc(dn, end_transparency_mask, gx_default_end_transparency_mask); set_dev_proc(dn, discard_transparency_layer, gx_default_discard_transparency_layer); set_dev_proc(dn, pattern_manage, gx_default_pattern_manage); set_dev_proc(dn, push_transparency_state, gx_default_push_transparency_state); set_dev_proc(dn, pop_transparency_state, gx_default_pop_transparency_state); set_dev_proc(dn, put_image, gx_default_put_image); set_dev_proc(dn, copy_planes, gx_default_copy_planes); set_dev_proc(dn, copy_alpha_hl_color, gx_default_no_copy_alpha_hl_color); dn->graphics_type_tag = dev->graphics_type_tag; /* initialize to same as target */ gx_device_copy_color_params(dn, dev); } }
CWE-78
2,792
12,967
94838632952741693872968428266758473614
null
null
null
ghostscript
79cccf641486a6595c43f1de1cd7ade696020a31
0
gs_opendevice(gx_device *dev) { if (dev->is_open) return 0; check_device_separable(dev); gx_device_fill_in_procs(dev); { int code = (*dev_proc(dev, open_device))(dev); if (code < 0) return_error(code); dev->is_open = true; return 1; } }
CWE-78
2,793
12,968
17326740967496055171509446944394218123
null
null
null
ghostscript
79cccf641486a6595c43f1de1cd7ade696020a31
0
gs_output_page(gs_gstate * pgs, int num_copies, int flush) { gx_device *dev = gs_currentdevice(pgs); cmm_dev_profile_t *dev_profile; int code; /* for devices that hook 'fill_path' in order to pick up gs_gstate */ /* values such as dev_ht (such as tiffsep1), make a dummy call here */ /* to make sure that it has been called at least once */ code = gs_gsave(pgs); if (code < 0) return code; if (((code = gs_newpath(pgs)) < 0) || ((code = gs_moveto(pgs, 0.0, 0.0)) < 0) || ((code = gs_setgray(pgs, 0.0)) < 0) || ((code = gs_fill(pgs)) < 0)) { gs_grestore(pgs); return code; } code = gs_grestore(pgs); if (code < 0) return code; if (dev->IgnoreNumCopies) num_copies = 1; if ((code = (*dev_proc(dev, output_page)) (dev, num_copies, flush)) < 0) return code; code = dev_proc(dev, get_profile)(dev, &(dev_profile)); if (code < 0) return code; if (dev_profile->graydetection && !dev_profile->pageneutralcolor) { dev_profile->pageneutralcolor = true; /* start detecting again */ code = gsicc_mcm_begin_monitor(pgs->icc_link_cache, dev); } return code; }
CWE-78
2,794
12,969
239360874233814871717187230637911122089
null
null
null
ghostscript
79cccf641486a6595c43f1de1cd7ade696020a31
0
gs_setdevice_no_erase(gs_gstate * pgs, gx_device * dev) { int open_code = 0, code; gs_lib_ctx_t *libctx = gs_lib_ctx_get_interp_instance(pgs->memory); /* If the ICC manager is not yet initialized, set it up now. But only if we have file io capability now */ if (libctx->io_device_table != NULL) { cmm_dev_profile_t *dev_profile; if (pgs->icc_manager->lab_profile == NULL) { /* pick one not set externally */ gsicc_init_iccmanager(pgs); } /* Also, if the device profile is not yet set then take care of that before we start filling pages, if we can */ /* Although device methods should not be NULL, they are not completely filled in until * gx_device_fill_in_procs is called, and its possible for us to get here before this * happens, so we *must* make sure the method is not NULL before we use it. */ if (dev->procs.get_profile != NULL) { code = dev_proc(dev, get_profile)(dev, &dev_profile); if (code < 0) { return(code); } if (dev_profile == NULL || dev_profile->device_profile[gsDEFAULTPROFILE] == NULL) { if ((code = gsicc_init_device_profile_struct(dev, NULL, gsDEFAULTPROFILE)) < 0) return(code); /* set the intent too */ if ((code = gsicc_set_device_profile_intent(dev, gsRINOTSPECIFIED, gsDEFAULTPROFILE)) < 0) return(code); } } } /* Initialize the device */ if (!dev->is_open) { gx_device_fill_in_procs(dev); /* If we have not yet done so, and if we can, set the device profile * Doing so *before* the device is opened means that a device which * opens other devices can pass a profile on - for example, pswrite * also opens a bbox device */ if (libctx->io_device_table != NULL) { cmm_dev_profile_t *dev_profile; /* Although device methods should not be NULL, they are not completely filled in until * gx_device_fill_in_procs is called, and its possible for us to get here before this * happens, so we *must* make sure the method is not NULL before we use it. */ if (dev->procs.get_profile != NULL) { code = dev_proc(dev, get_profile)(dev, &dev_profile); if (code < 0) { return(code); } if (dev_profile == NULL || dev_profile->device_profile[gsDEFAULTPROFILE] == NULL) { if ((code = gsicc_init_device_profile_struct(dev, NULL, gsDEFAULTPROFILE)) < 0) return(code); } } } if (gs_device_is_memory(dev)) { /* Set the target to the current device. */ gx_device *odev = gs_currentdevice_inline(pgs); while (odev != 0 && gs_device_is_memory(odev)) odev = ((gx_device_memory *)odev)->target; gx_device_set_target(((gx_device_forward *)dev), odev); } code = open_code = gs_opendevice(dev); if (code < 0) return code; } gs_setdevice_no_init(pgs, dev); pgs->ctm_default_set = false; if ((code = gs_initmatrix(pgs)) < 0 || (code = gs_initclip(pgs)) < 0 ) return code; /* If we were in a charpath or a setcachedevice, */ /* we aren't any longer. */ pgs->in_cachedevice = 0; pgs->in_charpath = (gs_char_path_mode) 0; return open_code; }
CWE-78
2,795
12,970
287767588940161448798748841276764633729
null
null
null
ghostscript
79cccf641486a6595c43f1de1cd7ade696020a31
0
gs_setdevice_no_init(gs_gstate * pgs, gx_device * dev) { /* * Just set the device, possibly changing color space but no other * device parameters. * * Make sure we don't close the device if dev == pgs->device * This could be done by allowing the rc_assign to close the * old 'dev' if the rc goes to 0 (via the device structure's * finalization procedure), but then the 'code' from the dev * closedevice would not be propagated up. We want to allow * the code to be handled, particularly for the pdfwrite * device. */ if (pgs->device != NULL && pgs->device->rc.ref_count == 1 && pgs->device != dev) { int code = gs_closedevice(pgs->device); if (code < 0) return code; } rc_assign(pgs->device, dev, "gs_setdevice_no_init"); gs_gstate_update_device(pgs, dev); return pgs->overprint ? gs_do_set_overprint(pgs) : 0; }
CWE-78
2,796
12,971
297002467929152011942593160639752930541
null
null
null