instruction
stringclasses
1 value
input
stringlengths
56
241k
output
int64
0
1
__index_level_0__
int64
0
175k
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static void formatString(Image *ofile, const char *s, int len) { char temp[MagickPathExtent]; (void) WriteBlobByte(ofile,'"'); for (; len > 0; len--, s++) { int c = (*s) & 255; switch (c) { case '&': (void) WriteBlobString(ofile,"&amp;"); break; #ifdef HANDLE_GT_LT case '<': (void) WriteBlobString(ofile,"&lt;"); break; case '>': (void) WriteBlobString(ofile,"&gt;"); break; #endif case '"': (void) WriteBlobString(ofile,"&quot;"); break; default: if (isprint(c)) (void) WriteBlobByte(ofile,(unsigned char) *s); else { (void) FormatLocaleString(temp,MagickPathExtent,"&#%d;", c & 255); (void) WriteBlobString(ofile,temp); } break; } } #if defined(MAGICKCORE_WINDOWS_SUPPORT) (void) WriteBlobString(ofile,"\"\r\n"); #else #if defined(macintosh) (void) WriteBlobString(ofile,"\"\r"); #else (void) WriteBlobString(ofile,"\"\n"); #endif #endif } Commit Message: ... CWE ID: CWE-119
0
91,159
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data) { struct kvm *kvm = vcpu->kvm; int lm = is_long_mode(vcpu); u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64 : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32; u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64 : kvm->arch.xen_hvm_config.blob_size_32; u32 page_num = data & ~PAGE_MASK; u64 page_addr = data & PAGE_MASK; u8 *page; int r; r = -E2BIG; if (page_num >= blob_size) goto out; r = -ENOMEM; page = memdup_user(blob_addr + (page_num * PAGE_SIZE), PAGE_SIZE); if (IS_ERR(page)) { r = PTR_ERR(page); goto out; } if (kvm_write_guest(kvm, page_addr, page, PAGE_SIZE)) goto out_free; r = 0; out_free: kfree(page); out: return r; } Commit Message: KVM: Ensure all vcpus are consistent with in-kernel irqchip settings (cherry picked from commit 3e515705a1f46beb1c942bb8043c16f8ac7b1e9e) If some vcpus are created before KVM_CREATE_IRQCHIP, then irqchip_in_kernel() and vcpu->arch.apic will be inconsistent, leading to potential NULL pointer dereferences. Fix by: - ensuring that no vcpus are installed when KVM_CREATE_IRQCHIP is called - ensuring that a vcpu has an apic if it is installed after KVM_CREATE_IRQCHIP This is somewhat long winded because vcpu->arch.apic is created without kvm->lock held. Based on earlier patch by Michael Ellerman. Signed-off-by: Michael Ellerman <michael@ellerman.id.au> Signed-off-by: Avi Kivity <avi@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> CWE ID: CWE-399
0
20,902
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: GF_Err video_sample_entry_AddBox(GF_Box *s, GF_Box *a) { GF_MPEGVisualSampleEntryBox *ptr = (GF_MPEGVisualSampleEntryBox *)s; switch (a->type) { case GF_ISOM_BOX_TYPE_ESDS: if (ptr->esd) ERROR_ON_DUPLICATED_BOX(a, ptr) ptr->esd = (GF_ESDBox *)a; break; case GF_ISOM_BOX_TYPE_SINF: gf_list_add(ptr->protections, a); break; case GF_ISOM_BOX_TYPE_RINF: if (ptr->rinf) ERROR_ON_DUPLICATED_BOX(a, ptr) ptr->rinf = (GF_RestrictedSchemeInfoBox *) a; break; case GF_ISOM_BOX_TYPE_AVCC: if (ptr->avc_config) ERROR_ON_DUPLICATED_BOX(a, ptr) ptr->avc_config = (GF_AVCConfigurationBox *)a; break; case GF_ISOM_BOX_TYPE_HVCC: if (ptr->hevc_config) ERROR_ON_DUPLICATED_BOX(a, ptr) ptr->hevc_config = (GF_HEVCConfigurationBox *)a; break; case GF_ISOM_BOX_TYPE_SVCC: if (ptr->svc_config) ERROR_ON_DUPLICATED_BOX(a, ptr) ptr->svc_config = (GF_AVCConfigurationBox *)a; break; case GF_ISOM_BOX_TYPE_MVCC: if (ptr->mvc_config) ERROR_ON_DUPLICATED_BOX(a, ptr) ptr->mvc_config = (GF_AVCConfigurationBox *)a; break; case GF_ISOM_BOX_TYPE_LHVC: if (ptr->lhvc_config) ERROR_ON_DUPLICATED_BOX(a, ptr) ptr->lhvc_config = (GF_HEVCConfigurationBox *)a; break; case GF_ISOM_BOX_TYPE_M4DS: if (ptr->descr) ERROR_ON_DUPLICATED_BOX(a, ptr) ptr->descr = (GF_MPEG4ExtensionDescriptorsBox *)a; break; case GF_ISOM_BOX_TYPE_UUID: if (! memcmp(((GF_UnknownUUIDBox*)a)->uuid, GF_ISOM_IPOD_EXT, 16)) { if (ptr->ipod_ext) ERROR_ON_DUPLICATED_BOX(a, ptr) ptr->ipod_ext = (GF_UnknownUUIDBox *)a; } else { return gf_isom_box_add_default(s, a); } break; case GF_ISOM_BOX_TYPE_D263: ptr->cfg_3gpp = (GF_3GPPConfigBox *)a; /*for 3GP config, remember sample entry type in config*/ ptr->cfg_3gpp->cfg.type = ptr->type; break; break; case GF_ISOM_BOX_TYPE_PASP: if (ptr->pasp) ERROR_ON_DUPLICATED_BOX(a, ptr) ptr->pasp = (GF_PixelAspectRatioBox *)a; break; case GF_ISOM_BOX_TYPE_CLAP: if (ptr->clap) ERROR_ON_DUPLICATED_BOX(a, ptr) ptr->clap = (GF_CleanAppertureBox *)a; break; case GF_ISOM_BOX_TYPE_RVCC: if (ptr->rvcc) ERROR_ON_DUPLICATED_BOX(a, ptr) ptr->rvcc = (GF_RVCConfigurationBox *)a; break; default: return gf_isom_box_add_default(s, a); } return GF_OK; } Commit Message: fixed 2 possible heap overflows (inc. #1088) CWE ID: CWE-125
0
80,660
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: list_del_event(struct perf_event *event, struct perf_event_context *ctx) { struct perf_cpu_context *cpuctx; WARN_ON_ONCE(event->ctx != ctx); lockdep_assert_held(&ctx->lock); /* * We can have double detach due to exit/hot-unplug + close. */ if (!(event->attach_state & PERF_ATTACH_CONTEXT)) return; event->attach_state &= ~PERF_ATTACH_CONTEXT; if (is_cgroup_event(event)) { ctx->nr_cgroups--; cpuctx = __get_cpu_context(ctx); /* * if there are no more cgroup events * then cler cgrp to avoid stale pointer * in update_cgrp_time_from_cpuctx() */ if (!ctx->nr_cgroups) cpuctx->cgrp = NULL; } if (has_branch_stack(event)) ctx->nr_branch_stack--; ctx->nr_events--; if (event->attr.inherit_stat) ctx->nr_stat--; list_del_rcu(&event->event_entry); if (event->group_leader == event) list_del_init(&event->group_entry); update_group_times(event); /* * If event was in error state, then keep it * that way, otherwise bogus counts will be * returned on read(). The only way to get out * of error state is by explicit re-enabling * of the event */ if (event->state > PERF_EVENT_STATE_OFF) event->state = PERF_EVENT_STATE_OFF; ctx->generation++; } Commit Message: perf: Fix event->ctx locking There have been a few reported issues wrt. the lack of locking around changing event->ctx. This patch tries to address those. It avoids the whole rwsem thing; and while it appears to work, please give it some thought in review. What I did fail at is sensible runtime checks on the use of event->ctx, the RCU use makes it very hard. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Link: http://lkml.kernel.org/r/20150123125834.209535886@infradead.org Signed-off-by: Ingo Molnar <mingo@kernel.org> CWE ID: CWE-264
0
50,446
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static void __perf_event_exit_context(void *__info) { struct perf_event_context *ctx = __info; struct perf_cpu_context *cpuctx = __get_cpu_context(ctx); struct perf_event *event; raw_spin_lock(&ctx->lock); list_for_each_entry(event, &ctx->event_list, event_entry) __perf_remove_from_context(event, cpuctx, ctx, (void *)DETACH_GROUP); raw_spin_unlock(&ctx->lock); } Commit Message: perf/core: Fix concurrent sys_perf_event_open() vs. 'move_group' race Di Shen reported a race between two concurrent sys_perf_event_open() calls where both try and move the same pre-existing software group into a hardware context. The problem is exactly that described in commit: f63a8daa5812 ("perf: Fix event->ctx locking") ... where, while we wait for a ctx->mutex acquisition, the event->ctx relation can have changed under us. That very same commit failed to recognise sys_perf_event_context() as an external access vector to the events and thereby didn't apply the established locking rules correctly. So while one sys_perf_event_open() call is stuck waiting on mutex_lock_double(), the other (which owns said locks) moves the group about. So by the time the former sys_perf_event_open() acquires the locks, the context we've acquired is stale (and possibly dead). Apply the established locking rules as per perf_event_ctx_lock_nested() to the mutex_lock_double() for the 'move_group' case. This obviously means we need to validate state after we acquire the locks. Reported-by: Di Shen (Keen Lab) Tested-by: John Dias <joaodias@google.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Kees Cook <keescook@chromium.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Min Chong <mchong@google.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Vince Weaver <vincent.weaver@maine.edu> Fixes: f63a8daa5812 ("perf: Fix event->ctx locking") Link: http://lkml.kernel.org/r/20170106131444.GZ3174@twins.programming.kicks-ass.net Signed-off-by: Ingo Molnar <mingo@kernel.org> CWE ID: CWE-362
0
68,291
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: void CL_CheckTimeout( void ) { if ( ( !CL_CheckPaused() || !sv_paused->integer ) && clc.state >= CA_CONNECTED && clc.state != CA_CINEMATIC && cls.realtime - clc.lastPacketTime > cl_timeout->value * 1000 ) { if ( ++cl.timeoutcount > 5 ) { // timeoutcount saves debugger Com_Printf( "\nServer connection timed out.\n" ); CL_Disconnect( qtrue ); return; } } else { cl.timeoutcount = 0; } } Commit Message: All: Don't load .pk3s as .dlls, and don't load user config files from .pk3s CWE ID: CWE-269
0
95,651
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static void n_tty_close(struct tty_struct *tty) { struct n_tty_data *ldata = tty->disc_data; if (tty->link) n_tty_packet_mode_flush(tty); vfree(ldata); tty->disc_data = NULL; } Commit Message: n_tty: Fix n_tty_write crash when echoing in raw mode The tty atomic_write_lock does not provide an exclusion guarantee for the tty driver if the termios settings are LECHO & !OPOST. And since it is unexpected and not allowed to call TTY buffer helpers like tty_insert_flip_string concurrently, this may lead to crashes when concurrect writers call pty_write. In that case the following two writers: * the ECHOing from a workqueue and * pty_write from the process race and can overflow the corresponding TTY buffer like follows. If we look into tty_insert_flip_string_fixed_flag, there is: int space = __tty_buffer_request_room(port, goal, flags); struct tty_buffer *tb = port->buf.tail; ... memcpy(char_buf_ptr(tb, tb->used), chars, space); ... tb->used += space; so the race of the two can result in something like this: A B __tty_buffer_request_room __tty_buffer_request_room memcpy(buf(tb->used), ...) tb->used += space; memcpy(buf(tb->used), ...) ->BOOM B's memcpy is past the tty_buffer due to the previous A's tb->used increment. Since the N_TTY line discipline input processing can output concurrently with a tty write, obtain the N_TTY ldisc output_lock to serialize echo output with normal tty writes. This ensures the tty buffer helper tty_insert_flip_string is not called concurrently and everything is fine. Note that this is nicely reproducible by an ordinary user using forkpty and some setup around that (raw termios + ECHO). And it is present in kernels at least after commit d945cb9cce20ac7143c2de8d88b187f62db99bdc (pty: Rework the pty layer to use the normal buffering logic) in 2.6.31-rc3. js: add more info to the commit log js: switch to bool js: lock unconditionally js: lock only the tty->ops->write call References: CVE-2014-0196 Reported-and-tested-by: Jiri Slaby <jslaby@suse.cz> Signed-off-by: Peter Hurley <peter@hurleysoftware.com> Signed-off-by: Jiri Slaby <jslaby@suse.cz> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Alan Cox <alan@lxorguk.ukuu.org.uk> Cc: <stable@vger.kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> CWE ID: CWE-362
0
39,803
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static int zrle_compress_data(VncState *vs, int level) { z_streamp zstream = &vs->zrle.stream; buffer_reset(&vs->zrle.zlib); if (zstream->opaque != vs) { int err; zstream->zalloc = vnc_zlib_zalloc; zstream->zfree = vnc_zlib_zfree; err = deflateInit2(zstream, level, Z_DEFLATED, MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY); if (err != Z_OK) { fprintf(stderr, "VNC: error initializing zlib\n"); return -1; } zstream->opaque = vs; } /* reserve memory in output buffer */ buffer_reserve(&vs->zrle.zlib, vs->zrle.zrle.offset + 64); /* set pointers */ zstream->next_in = vs->zrle.zrle.buffer; zstream->avail_in = vs->zrle.zrle.offset; zstream->next_out = vs->zrle.zlib.buffer + vs->zrle.zlib.offset; zstream->avail_out = vs->zrle.zlib.capacity - vs->zrle.zlib.offset; zstream->data_type = Z_BINARY; /* start encoding */ if (deflate(zstream, Z_SYNC_FLUSH) != Z_OK) { fprintf(stderr, "VNC: error during zrle compression\n"); return -1; } vs->zrle.zlib.offset = vs->zrle.zlib.capacity - zstream->avail_out; return vs->zrle.zlib.offset; } Commit Message: CWE ID: CWE-125
0
17,893
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static int parse_segments(struct MACH0_(obj_t)* bin, ut64 off) { int i, j, k, sect, len; ut32 size_sects; ut8 segcom[sizeof (struct MACH0_(segment_command))] = {0}; ut8 sec[sizeof (struct MACH0_(section))] = {0}; if (!UT32_MUL (&size_sects, bin->nsegs, sizeof (struct MACH0_(segment_command)))) { return false; } if (!size_sects || size_sects > bin->size) { return false; } if (off > bin->size || off + sizeof (struct MACH0_(segment_command)) > bin->size) { return false; } if (!(bin->segs = realloc (bin->segs, bin->nsegs * sizeof(struct MACH0_(segment_command))))) { perror ("realloc (seg)"); return false; } j = bin->nsegs - 1; len = r_buf_read_at (bin->b, off, segcom, sizeof (struct MACH0_(segment_command))); if (len != sizeof (struct MACH0_(segment_command))) { bprintf ("Error: read (seg)\n"); return false; } i = 0; bin->segs[j].cmd = r_read_ble32 (&segcom[i], bin->big_endian); i += sizeof (ut32); bin->segs[j].cmdsize = r_read_ble32 (&segcom[i], bin->big_endian); i += sizeof (ut32); memcpy (&bin->segs[j].segname, &segcom[i], 16); i += 16; #if R_BIN_MACH064 bin->segs[j].vmaddr = r_read_ble64 (&segcom[i], bin->big_endian); i += sizeof (ut64); bin->segs[j].vmsize = r_read_ble64 (&segcom[i], bin->big_endian); i += sizeof (ut64); bin->segs[j].fileoff = r_read_ble64 (&segcom[i], bin->big_endian); i += sizeof (ut64); bin->segs[j].filesize = r_read_ble64 (&segcom[i], bin->big_endian); i += sizeof (ut64); #else bin->segs[j].vmaddr = r_read_ble32 (&segcom[i], bin->big_endian); i += sizeof (ut32); bin->segs[j].vmsize = r_read_ble32 (&segcom[i], bin->big_endian); i += sizeof (ut32); bin->segs[j].fileoff = r_read_ble32 (&segcom[i], bin->big_endian); i += sizeof (ut32); bin->segs[j].filesize = r_read_ble32 (&segcom[i], bin->big_endian); i += sizeof (ut32); #endif bin->segs[j].maxprot = r_read_ble32 (&segcom[i], bin->big_endian); i += sizeof (ut32); bin->segs[j].initprot = r_read_ble32 (&segcom[i], bin->big_endian); i += sizeof (ut32); bin->segs[j].nsects = r_read_ble32 (&segcom[i], bin->big_endian); i += sizeof (ut32); bin->segs[j].flags = r_read_ble32 (&segcom[i], bin->big_endian); sdb_num_set (bin->kv, sdb_fmt ("mach0_segment_%d.offset", j), off, 0); sdb_num_set (bin->kv, "mach0_segments.count", 0, 0); sdb_set (bin->kv, "mach0_segment.format", "xd[16]zxxxxoodx " "cmd cmdsize segname vmaddr vmsize " "fileoff filesize maxprot initprot nsects flags", 0); if (bin->segs[j].nsects > 0) { sect = bin->nsects; bin->nsects += bin->segs[j].nsects; if (bin->nsects > 128) { int new_nsects = bin->nsects & 0xf; bprintf ("WARNING: mach0 header contains too many sections (%d). Wrapping to %d\n", bin->nsects, new_nsects); bin->nsects = new_nsects; } if ((int)bin->nsects < 1) { bprintf ("Warning: Invalid number of sections\n"); bin->nsects = sect; return false; } if (!UT32_MUL (&size_sects, bin->nsects-sect, sizeof (struct MACH0_(section)))){ bin->nsects = sect; return false; } if (!size_sects || size_sects > bin->size){ bin->nsects = sect; return false; } if (bin->segs[j].cmdsize != sizeof (struct MACH0_(segment_command)) \ + (sizeof (struct MACH0_(section))*bin->segs[j].nsects)){ bin->nsects = sect; return false; } if (off + sizeof (struct MACH0_(segment_command)) > bin->size ||\ off + sizeof (struct MACH0_(segment_command)) + size_sects > bin->size){ bin->nsects = sect; return false; } if (!(bin->sects = realloc (bin->sects, bin->nsects * sizeof (struct MACH0_(section))))) { perror ("realloc (sects)"); bin->nsects = sect; return false; } for (k = sect, j = 0; k < bin->nsects; k++, j++) { ut64 offset = off + sizeof (struct MACH0_(segment_command)) + j * sizeof (struct MACH0_(section)); len = r_buf_read_at (bin->b, offset, sec, sizeof (struct MACH0_(section))); if (len != sizeof (struct MACH0_(section))) { bprintf ("Error: read (sects)\n"); bin->nsects = sect; return false; } i = 0; memcpy (&bin->sects[k].sectname, &sec[i], 16); i += 16; memcpy (&bin->sects[k].segname, &sec[i], 16); bin->sects[k].segname[15] = 0; i += 16; #if R_BIN_MACH064 bin->sects[k].addr = r_read_ble64 (&sec[i], bin->big_endian); i += sizeof (ut64); bin->sects[k].size = r_read_ble64 (&sec[i], bin->big_endian); i += sizeof (ut64); #else bin->sects[k].addr = r_read_ble32 (&sec[i], bin->big_endian); i += sizeof (ut32); bin->sects[k].size = r_read_ble32 (&sec[i], bin->big_endian); i += sizeof (ut32); #endif bin->sects[k].offset = r_read_ble32 (&sec[i], bin->big_endian); i += sizeof (ut32); bin->sects[k].align = r_read_ble32 (&sec[i], bin->big_endian); i += sizeof (ut32); bin->sects[k].reloff = r_read_ble32 (&sec[i], bin->big_endian); i += sizeof (ut32); bin->sects[k].nreloc = r_read_ble32 (&sec[i], bin->big_endian); i += sizeof (ut32); bin->sects[k].flags = r_read_ble32 (&sec[i], bin->big_endian); i += sizeof (ut32); bin->sects[k].reserved1 = r_read_ble32 (&sec[i], bin->big_endian); i += sizeof (ut32); bin->sects[k].reserved2 = r_read_ble32 (&sec[i], bin->big_endian); #if R_BIN_MACH064 i += sizeof (ut32); bin->sects[k].reserved3 = r_read_ble32 (&sec[i], bin->big_endian); #endif } } return true; } Commit Message: Fix #9970 - heap oobread in mach0 parser (#10026) CWE ID: CWE-125
0
82,848
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: void RendererSchedulerImpl::MaybeAdvanceVirtualTime( base::TimeTicks new_virtual_time) { if (virtual_time_domain_) virtual_time_domain_->MaybeAdvanceVirtualTime(new_virtual_time); } Commit Message: [scheduler] Remove implicit fallthrough in switch Bail out early when a condition in the switch is fulfilled. This does not change behaviour due to RemoveTaskObserver being no-op when the task observer is not present in the list. R=thakis@chromium.org Bug: 177475 Change-Id: Ibc7772c79f8a8c8a1d63a997dabe1efda5d3a7bd Reviewed-on: https://chromium-review.googlesource.com/891187 Reviewed-by: Nico Weber <thakis@chromium.org> Commit-Queue: Alexander Timin <altimin@chromium.org> Cr-Commit-Position: refs/heads/master@{#532649} CWE ID: CWE-119
0
143,429
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: void vp9_set_mb_mi(VP9_COMMON *cm, int width, int height) { const int aligned_width = ALIGN_POWER_OF_TWO(width, MI_SIZE_LOG2); const int aligned_height = ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2); cm->mi_cols = aligned_width >> MI_SIZE_LOG2; cm->mi_rows = aligned_height >> MI_SIZE_LOG2; cm->mi_stride = calc_mi_size(cm->mi_cols); cm->mb_cols = (cm->mi_cols + 1) >> 1; cm->mb_rows = (cm->mi_rows + 1) >> 1; cm->MBs = cm->mb_rows * cm->mb_cols; } Commit Message: DO NOT MERGE libvpx: Cherry-pick 8b4c315 from upstream Description from upstream: vp9_alloc_context_buffers: clear cm->mi* on failure this fixes a crash in vp9_dec_setup_mi() via vp9_init_context_buffers() should decoding continue and the decoder resyncs on a smaller frame Bug: 30593752 Change-Id: Iafbf1c4114062bf796f51a6b03be71328f7bcc69 (cherry picked from commit 737c8493693243838128788fe9c3abc51f17338e) (cherry picked from commit 3e88ffac8c80b76e15286ef8a7b3bd8fa246c761) CWE ID: CWE-20
0
157,764
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: void WebGLRenderingContextBase::DrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount) { if (!ValidateDrawArrays("drawArraysInstancedANGLE")) return; if (!bound_vertex_array_object_->IsAllEnabledAttribBufferBound()) { SynthesizeGLError(GL_INVALID_OPERATION, "drawArraysInstancedANGLE", "no buffer is bound to enabled attribute"); return; } ScopedRGBEmulationColorMask emulation_color_mask(this, color_mask_, drawing_buffer_.get()); OnBeforeDrawCall(); ContextGL()->DrawArraysInstancedANGLE(mode, first, count, primcount); } Commit Message: Add GL_PROGRAM_COMPLETION_QUERY_CHROMIUM This makes the query of GL_COMPLETION_STATUS_KHR to programs much cheaper by minimizing the round-trip to the GPU thread. Bug: 881152, 957001 Change-Id: Iadfa798af29225e752c710ca5c25f50b3dd3101a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1586630 Commit-Queue: Kenneth Russell <kbr@chromium.org> Reviewed-by: Kentaro Hara <haraken@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Reviewed-by: Kenneth Russell <kbr@chromium.org> Cr-Commit-Position: refs/heads/master@{#657568} CWE ID: CWE-416
0
142,239
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: xmlHasFeature(xmlFeature feature) { switch (feature) { case XML_WITH_THREAD: #ifdef LIBXML_THREAD_ENABLED return(1); #else return(0); #endif case XML_WITH_TREE: #ifdef LIBXML_TREE_ENABLED return(1); #else return(0); #endif case XML_WITH_OUTPUT: #ifdef LIBXML_OUTPUT_ENABLED return(1); #else return(0); #endif case XML_WITH_PUSH: #ifdef LIBXML_PUSH_ENABLED return(1); #else return(0); #endif case XML_WITH_READER: #ifdef LIBXML_READER_ENABLED return(1); #else return(0); #endif case XML_WITH_PATTERN: #ifdef LIBXML_PATTERN_ENABLED return(1); #else return(0); #endif case XML_WITH_WRITER: #ifdef LIBXML_WRITER_ENABLED return(1); #else return(0); #endif case XML_WITH_SAX1: #ifdef LIBXML_SAX1_ENABLED return(1); #else return(0); #endif case XML_WITH_FTP: #ifdef LIBXML_FTP_ENABLED return(1); #else return(0); #endif case XML_WITH_HTTP: #ifdef LIBXML_HTTP_ENABLED return(1); #else return(0); #endif case XML_WITH_VALID: #ifdef LIBXML_VALID_ENABLED return(1); #else return(0); #endif case XML_WITH_HTML: #ifdef LIBXML_HTML_ENABLED return(1); #else return(0); #endif case XML_WITH_LEGACY: #ifdef LIBXML_LEGACY_ENABLED return(1); #else return(0); #endif case XML_WITH_C14N: #ifdef LIBXML_C14N_ENABLED return(1); #else return(0); #endif case XML_WITH_CATALOG: #ifdef LIBXML_CATALOG_ENABLED return(1); #else return(0); #endif case XML_WITH_XPATH: #ifdef LIBXML_XPATH_ENABLED return(1); #else return(0); #endif case XML_WITH_XPTR: #ifdef LIBXML_XPTR_ENABLED return(1); #else return(0); #endif case XML_WITH_XINCLUDE: #ifdef LIBXML_XINCLUDE_ENABLED return(1); #else return(0); #endif case XML_WITH_ICONV: #ifdef LIBXML_ICONV_ENABLED return(1); #else return(0); #endif case XML_WITH_ISO8859X: #ifdef LIBXML_ISO8859X_ENABLED return(1); #else return(0); #endif case XML_WITH_UNICODE: #ifdef LIBXML_UNICODE_ENABLED return(1); #else return(0); #endif case XML_WITH_REGEXP: #ifdef LIBXML_REGEXP_ENABLED return(1); #else return(0); #endif case XML_WITH_AUTOMATA: #ifdef LIBXML_AUTOMATA_ENABLED return(1); #else return(0); #endif case XML_WITH_EXPR: #ifdef LIBXML_EXPR_ENABLED return(1); #else return(0); #endif case XML_WITH_SCHEMAS: #ifdef LIBXML_SCHEMAS_ENABLED return(1); #else return(0); #endif case XML_WITH_SCHEMATRON: #ifdef LIBXML_SCHEMATRON_ENABLED return(1); #else return(0); #endif case XML_WITH_MODULES: #ifdef LIBXML_MODULES_ENABLED return(1); #else return(0); #endif case XML_WITH_DEBUG: #ifdef LIBXML_DEBUG_ENABLED return(1); #else return(0); #endif case XML_WITH_DEBUG_MEM: #ifdef DEBUG_MEMORY_LOCATION return(1); #else return(0); #endif case XML_WITH_DEBUG_RUN: #ifdef LIBXML_DEBUG_RUNTIME return(1); #else return(0); #endif case XML_WITH_ZLIB: #ifdef LIBXML_ZLIB_ENABLED return(1); #else return(0); #endif case XML_WITH_LZMA: #ifdef LIBXML_LZMA_ENABLED return(1); #else return(0); #endif case XML_WITH_ICU: #ifdef LIBXML_ICU_ENABLED return(1); #else return(0); #endif default: break; } return(0); } Commit Message: Detect infinite recursion in parameter entities When expanding a parameter entity in a DTD, infinite recursion could lead to an infinite loop or memory exhaustion. Thanks to Wei Lei for the first of many reports. Fixes bug 759579. CWE ID: CWE-835
0
59,440
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static void arcmsr_hbaC_stop_bgrb(struct AdapterControlBlock *pACB) { struct MessageUnit_C __iomem *reg = pACB->pmuC; pACB->acb_flags &= ~ACB_F_MSG_START_BGRB; writel(ARCMSR_INBOUND_MESG0_STOP_BGRB, &reg->inbound_msgaddr0); writel(ARCMSR_HBCMU_DRV2IOP_MESSAGE_CMD_DONE, &reg->inbound_doorbell); if (!arcmsr_hbaC_wait_msgint_ready(pACB)) { printk(KERN_NOTICE "arcmsr%d: wait 'stop adapter background rebulid' timeout\n" , pACB->host->host_no); } return; } Commit Message: scsi: arcmsr: Buffer overflow in arcmsr_iop_message_xfer() We need to put an upper bound on "user_len" so the memcpy() doesn't overflow. Cc: <stable@vger.kernel.org> Reported-by: Marco Grassi <marco.gra@gmail.com> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Reviewed-by: Tomas Henzl <thenzl@redhat.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> CWE ID: CWE-119
0
49,792
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static void TraceSquareLinecap(PrimitiveInfo *primitive_info, const size_t number_vertices,const double offset) { double distance; register double dx, dy; register ssize_t i; ssize_t j; dx=0.0; dy=0.0; for (i=1; i < (ssize_t) number_vertices; i++) { dx=primitive_info[0].point.x-primitive_info[i].point.x; dy=primitive_info[0].point.y-primitive_info[i].point.y; if ((fabs((double) dx) >= MagickEpsilon) || (fabs((double) dy) >= MagickEpsilon)) break; } if (i == (ssize_t) number_vertices) i=(ssize_t) number_vertices-1L; distance=hypot((double) dx,(double) dy); primitive_info[0].point.x=(double) (primitive_info[i].point.x+ dx*(distance+offset)/distance); primitive_info[0].point.y=(double) (primitive_info[i].point.y+ dy*(distance+offset)/distance); for (j=(ssize_t) number_vertices-2; j >= 0; j--) { dx=primitive_info[number_vertices-1].point.x-primitive_info[j].point.x; dy=primitive_info[number_vertices-1].point.y-primitive_info[j].point.y; if ((fabs((double) dx) >= MagickEpsilon) || (fabs((double) dy) >= MagickEpsilon)) break; } distance=hypot((double) dx,(double) dy); primitive_info[number_vertices-1].point.x=(double) (primitive_info[j].point.x+ dx*(distance+offset)/distance); primitive_info[number_vertices-1].point.y=(double) (primitive_info[j].point.y+ dy*(distance+offset)/distance); } Commit Message: Prevent buffer overflow in magick/draw.c CWE ID: CWE-119
0
53,028
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: void RenderFrameImpl::frameDetached(blink::WebFrame* frame) { CHECK(!is_detaching_); DCHECK(!frame_ || frame_ == frame); bool is_subframe = !!frame->parent(); Send(new FrameHostMsg_Detach(routing_id_)); render_view_->UnregisterSwappedOutChildFrame(this); is_detaching_ = true; FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers(), FrameDetached(frame)); FrameMap::iterator it = g_frame_map.Get().find(frame); CHECK(it != g_frame_map.Get().end()); CHECK_EQ(it->second, this); g_frame_map.Get().erase(it); if (is_subframe) frame->parent()->removeChild(frame); frame->close(); if (is_subframe) { delete this; } } Commit Message: Add logging to figure out which IPC we're failing to deserialize in RenderFrame. BUG=369553 R=creis@chromium.org Review URL: https://codereview.chromium.org/263833020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@268565 0039d316-1c4b-4281-b951-d872f2087c98 CWE ID: CWE-399
0
110,266
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: nlmsvc_cancel_blocked(struct net *net, struct nlm_file *file, struct nlm_lock *lock) { struct nlm_block *block; int status = 0; dprintk("lockd: nlmsvc_cancel(%s/%ld, pi=%d, %Ld-%Ld)\n", file_inode(file->f_file)->i_sb->s_id, file_inode(file->f_file)->i_ino, lock->fl.fl_pid, (long long)lock->fl.fl_start, (long long)lock->fl.fl_end); if (locks_in_grace(net)) return nlm_lck_denied_grace_period; mutex_lock(&file->f_mutex); block = nlmsvc_lookup_block(file, lock); mutex_unlock(&file->f_mutex); if (block != NULL) { vfs_cancel_lock(block->b_file->f_file, &block->b_call->a_args.lock.fl); status = nlmsvc_unlink_block(block); nlmsvc_release_block(block); } return status ? nlm_lck_denied : nlm_granted; } Commit Message: Merge tag 'nfsd-4.12' of git://linux-nfs.org/~bfields/linux Pull nfsd updates from Bruce Fields: "Another RDMA update from Chuck Lever, and a bunch of miscellaneous bugfixes" * tag 'nfsd-4.12' of git://linux-nfs.org/~bfields/linux: (26 commits) nfsd: Fix up the "supattr_exclcreat" attributes nfsd: encoders mustn't use unitialized values in error cases nfsd: fix undefined behavior in nfsd4_layout_verify lockd: fix lockd shutdown race NFSv4: Fix callback server shutdown SUNRPC: Refactor svc_set_num_threads() NFSv4.x/callback: Create the callback service through svc_create_pooled lockd: remove redundant check on block svcrdma: Clean out old XDR encoders svcrdma: Remove the req_map cache svcrdma: Remove unused RDMA Write completion handler svcrdma: Reduce size of sge array in struct svc_rdma_op_ctxt svcrdma: Clean up RPC-over-RDMA backchannel reply processing svcrdma: Report Write/Reply chunk overruns svcrdma: Clean up RDMA_ERROR path svcrdma: Use rdma_rw API in RPC reply path svcrdma: Introduce local rdma_rw API helpers svcrdma: Clean up svc_rdma_get_inv_rkey() svcrdma: Add helper to save pages under I/O svcrdma: Eliminate RPCRDMA_SQ_DEPTH_MULT ... CWE ID: CWE-404
0
65,214
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: xdr_gstrings_ret(XDR *xdrs, gstrings_ret *objp) { if (!xdr_ui_4(xdrs, &objp->api_version)) { return (FALSE); } if (!xdr_kadm5_ret_t(xdrs, &objp->code)) { return (FALSE); } if (objp->code == KADM5_OK) { if (!xdr_int(xdrs, &objp->count)) { return (FALSE); } if (!xdr_array(xdrs, (caddr_t *) &objp->strings, (unsigned int *) &objp->count, ~0, sizeof(krb5_string_attr), xdr_krb5_string_attr)) { return (FALSE); } } return (TRUE); } Commit Message: Fix kadm5/gssrpc XDR double free [CVE-2014-9421] [MITKRB5-SA-2015-001] In auth_gssapi_unwrap_data(), do not free partial deserialization results upon failure to deserialize. This responsibility belongs to the callers, svctcp_getargs() and svcudp_getargs(); doing it in the unwrap function results in freeing the results twice. In xdr_krb5_tl_data() and xdr_krb5_principal(), null out the pointers we are freeing, as other XDR functions such as xdr_bytes() and xdr_string(). ticket: 8056 (new) target_version: 1.13.1 tags: pullup CWE ID:
0
46,062
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: bool WebContentsImpl::HasPersistentVideo() const { return has_persistent_video_; } Commit Message: If JavaScript shows a dialog, cause the page to lose fullscreen. BUG=670135, 550017, 726761, 728276 Review-Url: https://codereview.chromium.org/2906133004 Cr-Commit-Position: refs/heads/master@{#478884} CWE ID: CWE-20
0
135,746
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: void WebLocalFrameImpl::LoadJavaScriptURL(const WebURL& url) { DCHECK(GetFrame()); Document* owner_document = GetFrame()->GetDocument(); if (!owner_document || !GetFrame()->GetPage()) return; if (SchemeRegistry::ShouldTreatURLSchemeAsNotAllowingJavascriptURLs( owner_document->Url().Protocol())) return; String script = DecodeURLEscapeSequences( static_cast<const KURL&>(url).GetString().Substring( strlen("javascript:"))); std::unique_ptr<UserGestureIndicator> gesture_indicator = Frame::NotifyUserActivation(GetFrame(), UserGestureToken::kNewGesture); v8::HandleScope handle_scope(ToIsolate(GetFrame())); v8::Local<v8::Value> result = GetFrame()->GetScriptController().ExecuteScriptInMainWorldAndReturnValue( ScriptSourceCode(script, ScriptSourceLocationType::kJavascriptUrl)); if (result.IsEmpty() || !result->IsString()) return; String script_result = ToCoreString(v8::Local<v8::String>::Cast(result)); if (!GetFrame()->GetNavigationScheduler().LocationChangePending()) { GetFrame()->Loader().ReplaceDocumentWhileExecutingJavaScriptURL( script_result, owner_document); } } Commit Message: Do not forward resource timing to parent frame after back-forward navigation LocalFrame has |should_send_resource_timing_info_to_parent_| flag not to send timing info to parent except for the first navigation. This flag is cleared when the first timing is sent to parent, however this does not happen if iframe's first navigation was by back-forward navigation. For such iframes, we shouldn't send timings to parent at all. Bug: 876822 Change-Id: I128b51a82ef278c439548afc8283ae63abdef5c5 Reviewed-on: https://chromium-review.googlesource.com/1186215 Reviewed-by: Kinuko Yasuda <kinuko@chromium.org> Commit-Queue: Kunihiko Sakamoto <ksakamoto@chromium.org> Cr-Commit-Position: refs/heads/master@{#585736} CWE ID: CWE-200
0
145,744
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: ASN1_TYPE *PKCS7_get_signed_attribute(PKCS7_SIGNER_INFO *si, int nid) { return (get_attribute(si->auth_attr, nid)); } Commit Message: PKCS#7: Fix NULL dereference with missing EncryptedContent. CVE-2015-1790 Reviewed-by: Rich Salz <rsalz@openssl.org> CWE ID:
0
44,225
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: SetupWildMatch(FontTablePtr table, FontNamePtr pat, int *leftp, int *rightp, int *privatep) { int nDashes; char c; char *t; char *firstWild; char *firstDigit; int first; int center, left, right; int result; char *name; name = pat->name; nDashes = pat->ndashes; firstWild = 0; firstDigit = 0; t = name; while ((c = *t++)) { if (isWild(c)) { if (!firstWild) firstWild = t - 1; } if (isDigit(c)) { if (!firstDigit) firstDigit = t - 1; } } left = 0; right = table->used; if (firstWild) *privatep = nDashes; else *privatep = -1; if (!table->sorted) { *leftp = left; *rightp = right; return -1; } else if (firstWild) { if (firstDigit && firstDigit < firstWild) first = firstDigit - name; else first = firstWild - name; while (left < right) { center = (left + right) / 2; result = strncmp(name, table->entries[center].name.name, first); if (result == 0) break; if (result < 0) right = center; else left = center + 1; } *leftp = left; *rightp = right; return -1; } else { while (left < right) { center = (left + right) / 2; result = strcmpn(name, table->entries[center].name.name); if (result == 0) return center; if (result < 0) right = center; else left = center + 1; } *leftp = 1; *rightp = 0; return -1; } } Commit Message: CWE ID: CWE-125
0
2,872
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static unsigned ZSTD_getFSEMaxSymbolValue(FSE_CTable const* ctable) { void const* ptr = ctable; U16 const* u16ptr = (U16 const*)ptr; U32 const maxSymbolValue = MEM_read16(u16ptr + 1); return maxSymbolValue; } Commit Message: fixed T36302429 CWE ID: CWE-362
0
90,074
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static int cm_rej_handler(struct cm_work *work) { struct cm_id_private *cm_id_priv; struct cm_rej_msg *rej_msg; int ret; rej_msg = (struct cm_rej_msg *)work->mad_recv_wc->recv_buf.mad; cm_id_priv = cm_acquire_rejected_id(rej_msg); if (!cm_id_priv) return -EINVAL; cm_format_rej_event(work); spin_lock_irq(&cm_id_priv->lock); switch (cm_id_priv->id.state) { case IB_CM_REQ_SENT: case IB_CM_MRA_REQ_RCVD: case IB_CM_REP_SENT: case IB_CM_MRA_REP_RCVD: ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg); /* fall through */ case IB_CM_REQ_RCVD: case IB_CM_MRA_REQ_SENT: if (__be16_to_cpu(rej_msg->reason) == IB_CM_REJ_STALE_CONN) cm_enter_timewait(cm_id_priv); else cm_reset_to_idle(cm_id_priv); break; case IB_CM_DREQ_SENT: ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg); /* fall through */ case IB_CM_REP_RCVD: case IB_CM_MRA_REP_SENT: cm_enter_timewait(cm_id_priv); break; case IB_CM_ESTABLISHED: if (cm_id_priv->id.lap_state == IB_CM_LAP_UNINIT || cm_id_priv->id.lap_state == IB_CM_LAP_SENT) { if (cm_id_priv->id.lap_state == IB_CM_LAP_SENT) ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg); cm_enter_timewait(cm_id_priv); break; } /* fall through */ default: spin_unlock_irq(&cm_id_priv->lock); ret = -EINVAL; goto out; } ret = atomic_inc_and_test(&cm_id_priv->work_count); if (!ret) list_add_tail(&work->list, &cm_id_priv->work_list); spin_unlock_irq(&cm_id_priv->lock); if (ret) cm_process_work(cm_id_priv, work); else cm_deref_id(cm_id_priv); return 0; out: cm_deref_id(cm_id_priv); return -EINVAL; } Commit Message: IB/core: Don't resolve passive side RoCE L2 address in CMA REQ handler The code that resolves the passive side source MAC within the rdma_cm connection request handler was both redundant and buggy, so remove it. It was redundant since later, when an RC QP is modified to RTR state, the resolution will take place in the ib_core module. It was buggy because this callback also deals with UD SIDR exchange, for which we incorrectly looked at the REQ member of the CM event and dereferenced a random value. Fixes: dd5f03beb4f7 ("IB/core: Ethernet L2 attributes in verbs/cm structures") Signed-off-by: Moni Shoua <monis@mellanox.com> Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com> Signed-off-by: Roland Dreier <roland@purestorage.com> CWE ID: CWE-20
0
38,412
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static void ucma_copy_ib_route(struct rdma_ucm_query_route_resp *resp, struct rdma_route *route) { struct rdma_dev_addr *dev_addr; resp->num_paths = route->num_paths; switch (route->num_paths) { case 0: dev_addr = &route->addr.dev_addr; rdma_addr_get_dgid(dev_addr, (union ib_gid *) &resp->ib_route[0].dgid); rdma_addr_get_sgid(dev_addr, (union ib_gid *) &resp->ib_route[0].sgid); resp->ib_route[0].pkey = cpu_to_be16(ib_addr_get_pkey(dev_addr)); break; case 2: ib_copy_path_rec_to_user(&resp->ib_route[1], &route->path_rec[1]); /* fall through */ case 1: ib_copy_path_rec_to_user(&resp->ib_route[0], &route->path_rec[0]); break; default: break; } } Commit Message: IB/security: Restrict use of the write() interface The drivers/infiniband stack uses write() as a replacement for bi-directional ioctl(). This is not safe. There are ways to trigger write calls that result in the return structure that is normally written to user space being shunted off to user specified kernel memory instead. For the immediate repair, detect and deny suspicious accesses to the write API. For long term, update the user space libraries and the kernel API to something that doesn't present the same security vulnerabilities (likely a structured ioctl() interface). The impacted uAPI interfaces are generally only available if hardware from drivers/infiniband is installed in the system. Reported-by: Jann Horn <jann@thejh.net> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com> [ Expanded check to all known write() entry points ] Cc: stable@vger.kernel.org Signed-off-by: Doug Ledford <dledford@redhat.com> CWE ID: CWE-264
0
52,838
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: PHP_FUNCTION(pg_send_query_params) { zval *pgsql_link, *pv_param_arr, **tmp; int num_params = 0; char **params = NULL; char *query; int query_len, id = -1; PGconn *pgsql; PGresult *res; int leftover = 0; int ret; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsa/", &pgsql_link, &query, &query_len, &pv_param_arr) == FAILURE) { return; } if (pgsql_link == NULL && id == -1) { RETURN_FALSE; } ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); if (PQ_SETNONBLOCKING(pgsql, 1)) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Cannot set connection to nonblocking mode"); RETURN_FALSE; } while ((res = PQgetResult(pgsql))) { PQclear(res); leftover = 1; } if (leftover) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "There are results on this connection. Call pg_get_result() until it returns FALSE"); } zend_hash_internal_pointer_reset(Z_ARRVAL_P(pv_param_arr)); num_params = zend_hash_num_elements(Z_ARRVAL_P(pv_param_arr)); if (num_params > 0) { int i = 0; params = (char **)safe_emalloc(sizeof(char *), num_params, 0); for(i = 0; i < num_params; i++) { if (zend_hash_get_current_data(Z_ARRVAL_P(pv_param_arr), (void **) &tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error getting parameter"); _php_pgsql_free_params(params, num_params); RETURN_FALSE; } if (Z_TYPE_PP(tmp) == IS_NULL) { params[i] = NULL; } else { zval tmp_val = **tmp; zval_copy_ctor(&tmp_val); convert_to_string(&tmp_val); if (Z_TYPE(tmp_val) != IS_STRING) { php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter"); zval_dtor(&tmp_val); _php_pgsql_free_params(params, num_params); RETURN_FALSE; } params[i] = estrndup(Z_STRVAL(tmp_val), Z_STRLEN(tmp_val)); zval_dtor(&tmp_val); } zend_hash_move_forward(Z_ARRVAL_P(pv_param_arr)); } } if (!PQsendQueryParams(pgsql, query, num_params, NULL, (const char * const *)params, NULL, NULL, 0)) { if ((PGG(auto_reset_persistent) & 2) && PQstatus(pgsql) != CONNECTION_OK) { PQreset(pgsql); } if (!PQsendQueryParams(pgsql, query, num_params, NULL, (const char * const *)params, NULL, NULL, 0)) { _php_pgsql_free_params(params, num_params); RETURN_FALSE; } } _php_pgsql_free_params(params, num_params); /* Wait to finish sending buffer */ while ((ret = PQflush(pgsql))) { if (ret == -1) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Could not empty PostgreSQL send buffer"); break; } usleep(10000); } if (PQ_SETNONBLOCKING(pgsql, 0)) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Cannot set connection to blocking mode"); } RETURN_TRUE; } Commit Message: CWE ID:
0
14,759
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: cff_parse_vsindex( CFF_Parser parser ) { /* vsindex operator can only be used in a Private DICT */ CFF_Private priv = (CFF_Private)parser->object; FT_Byte** data = parser->stack; CFF_Blend blend; FT_Error error; if ( !priv || !priv->subfont ) { error = FT_THROW( Invalid_File_Format ); goto Exit; } blend = &priv->subfont->blend; if ( blend->usedBV ) { FT_ERROR(( " cff_parse_vsindex: vsindex not allowed after blend\n" )); error = FT_THROW( Syntax_Error ); goto Exit; } priv->vsindex = (FT_UInt)cff_parse_num( parser, data++ ); FT_TRACE4(( " %d\n", priv->vsindex )); error = FT_Err_Ok; Exit: return error; } Commit Message: CWE ID: CWE-787
0
13,249
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: virtual status_t decrypt(Vector<uint8_t> const &sessionId, Vector<uint8_t> const &keyId, Vector<uint8_t> const &input, Vector<uint8_t> const &iv, Vector<uint8_t> &output) { Parcel data, reply; data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); writeVector(data, sessionId); writeVector(data, keyId); writeVector(data, input); writeVector(data, iv); status_t status = remote()->transact(DECRYPT, data, &reply); if (status != OK) { return status; } readVector(reply, output); return reply.readInt32(); } Commit Message: Fix info leak vulnerability of IDrm bug: 26323455 Change-Id: I25bb30d3666ab38d5150496375ed2f55ecb23ba8 CWE ID: CWE-264
0
161,282
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static unsigned readChunk_PLTE(LodePNGColorMode* color, const unsigned char* data, size_t chunkLength) { unsigned pos = 0, i; free(color->palette); color->palettesize = chunkLength / 3; color->palette = (unsigned char*)malloc(4 * color->palettesize); if(!color->palette && color->palettesize) { color->palettesize = 0; return 83; /*alloc fail*/ } if(color->palettesize > 256) return 38; /*error: palette too big*/ for(i = 0; i < color->palettesize; i++) { color->palette[4 * i + 0] = data[pos++]; /*R*/ color->palette[4 * i + 1] = data[pos++]; /*G*/ color->palette[4 * i + 2] = data[pos++]; /*B*/ color->palette[4 * i + 3] = 255; /*alpha*/ } return 0; /* OK */ } Commit Message: Fixed #5645: realloc return handling CWE ID: CWE-772
0
87,583
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static int ssl_parse_alpn_ext( mbedtls_ssl_context *ssl, const unsigned char *buf, size_t len ) { size_t list_len, cur_len, ours_len; const unsigned char *theirs, *start, *end; const char **ours; /* If ALPN not configured, just ignore the extension */ if( ssl->conf->alpn_list == NULL ) return( 0 ); /* * opaque ProtocolName<1..2^8-1>; * * struct { * ProtocolName protocol_name_list<2..2^16-1> * } ProtocolNameList; */ /* Min length is 2 (list_len) + 1 (name_len) + 1 (name) */ if( len < 4 ) { mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); return( MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO ); } list_len = ( buf[0] << 8 ) | buf[1]; if( list_len != len - 2 ) { mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); return( MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO ); } /* * Use our order of preference */ start = buf + 2; end = buf + len; for( ours = ssl->conf->alpn_list; *ours != NULL; ours++ ) { ours_len = strlen( *ours ); for( theirs = start; theirs != end; theirs += cur_len ) { /* If the list is well formed, we should get equality first */ if( theirs > end ) { mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER ); return( MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO ); } cur_len = *theirs++; /* Empty strings MUST NOT be included */ if( cur_len == 0 ) { mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER ); return( MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO ); } if( cur_len == ours_len && memcmp( theirs, *ours, cur_len ) == 0 ) { ssl->alpn_chosen = *ours; return( 0 ); } } } /* If we get there, no match was found */ mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_NO_APPLICATION_PROTOCOL ); return( MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO ); } Commit Message: Prevent bounds check bypass through overflow in PSK identity parsing The check `if( *p + n > end )` in `ssl_parse_client_psk_identity` is unsafe because `*p + n` might overflow, thus bypassing the check. As `n` is a user-specified value up to 65K, this is relevant if the library happens to be located in the last 65K of virtual memory. This commit replaces the check by a safe version. CWE ID: CWE-190
0
86,119
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: NOINLINE void MaybeTriggerAsanError(const GURL& url) { if (url == kChromeUICrashHeapOverflowURL) { LOG(ERROR) << "Intentionally causing ASAN heap overflow" << " because user navigated to " << url.spec(); base::debug::AsanHeapOverflow(); } else if (url == kChromeUICrashHeapUnderflowURL) { LOG(ERROR) << "Intentionally causing ASAN heap underflow" << " because user navigated to " << url.spec(); base::debug::AsanHeapUnderflow(); } else if (url == kChromeUICrashUseAfterFreeURL) { LOG(ERROR) << "Intentionally causing ASAN heap use-after-free" << " because user navigated to " << url.spec(); base::debug::AsanHeapUseAfterFree(); #if defined(OS_WIN) } else if (url == kChromeUICrashCorruptHeapBlockURL) { LOG(ERROR) << "Intentionally causing ASAN corrupt heap block" << " because user navigated to " << url.spec(); base::debug::AsanCorruptHeapBlock(); } else if (url == kChromeUICrashCorruptHeapURL) { LOG(ERROR) << "Intentionally causing ASAN corrupt heap" << " because user navigated to " << url.spec(); base::debug::AsanCorruptHeap(); #endif // OS_WIN } } Commit Message: Convert FrameHostMsg_DidAddMessageToConsole to Mojo. Note: Since this required changing the test RenderViewImplTest.DispatchBeforeUnloadCanDetachFrame, I manually re-introduced https://crbug.com/666714 locally (the bug the test was added for), and reran the test to confirm that it still covers the bug. Bug: 786836 Change-Id: I110668fa6f0f261fd2ac36bb91a8d8b31c99f4f1 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1526270 Commit-Queue: Lowell Manners <lowell@chromium.org> Reviewed-by: Daniel Cheng <dcheng@chromium.org> Reviewed-by: Camille Lamy <clamy@chromium.org> Cr-Commit-Position: refs/heads/master@{#653137} CWE ID: CWE-416
0
139,732
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static void __sctp_unhash_endpoint(struct sctp_endpoint *ep) { struct sctp_hashbucket *head; struct sctp_ep_common *epb; epb = &ep->base; if (hlist_unhashed(&epb->node)) return; epb->hashent = sctp_ep_hashfn(epb->bind_addr.port); head = &sctp_ep_hashtable[epb->hashent]; sctp_write_lock(&head->lock); __hlist_del(&epb->node); sctp_write_unlock(&head->lock); } Commit Message: sctp: Fix another socket race during accept/peeloff There is a race between sctp_rcv() and sctp_accept() where we have moved the association from the listening socket to the accepted socket, but sctp_rcv() processing cached the old socket and continues to use it. The easy solution is to check for the socket mismatch once we've grabed the socket lock. If we hit a mis-match, that means that were are currently holding the lock on the listening socket, but the association is refrencing a newly accepted socket. We need to drop the lock on the old socket and grab the lock on the new one. A more proper solution might be to create accepted sockets when the new association is established, similar to TCP. That would eliminate the race for 1-to-1 style sockets, but it would still existing for 1-to-many sockets where a user wished to peeloff an association. For now, we'll live with this easy solution as it addresses the problem. Reported-by: Michal Hocko <mhocko@suse.cz> Reported-by: Karsten Keil <kkeil@suse.de> Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com> Signed-off-by: David S. Miller <davem@davemloft.net> CWE ID: CWE-362
0
34,618
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: void hns_roce_exit(struct hns_roce_dev *hr_dev) { hns_roce_unregister_device(hr_dev); if (hr_dev->hw->hw_exit) hr_dev->hw->hw_exit(hr_dev); hns_roce_cleanup_bitmap(hr_dev); hns_roce_cleanup_hem(hr_dev); if (hr_dev->cmd_mod) hns_roce_cmd_use_polling(hr_dev); hr_dev->hw->cleanup_eq(hr_dev); hns_roce_cmd_cleanup(hr_dev); if (hr_dev->hw->cmq_exit) hr_dev->hw->cmq_exit(hr_dev); if (hr_dev->hw->reset) hr_dev->hw->reset(hr_dev, false); } Commit Message: RDMA/hns: Fix init resp when alloc ucontext The data in resp will be copied from kernel to userspace, thus it needs to be initialized to zeros to avoid copying uninited stack memory. Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Fixes: e088a685eae9 ("RDMA/hns: Support rq record doorbell for the user space") Signed-off-by: Yixian Liu <liuyixian@huawei.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com> CWE ID: CWE-665
0
87,734
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: void QQuickWebViewExperimental::invokeApplicationSchemeHandler(PassRefPtr<QtRefCountedNetworkRequestData> request) { RefPtr<QtRefCountedNetworkRequestData> req = request; const QObjectList children = schemeParent->children(); for (int index = 0; index < children.count(); index++) { QQuickUrlSchemeDelegate* delegate = qobject_cast<QQuickUrlSchemeDelegate*>(children.at(index)); if (!delegate) continue; if (!delegate->scheme().compare(QString(req->data().m_scheme), Qt::CaseInsensitive)) { delegate->request()->setNetworkRequestData(req); delegate->reply()->setNetworkRequestData(req); emit delegate->receivedRequest(); return; } } } Commit Message: [Qt][WK2] Allow transparent WebViews https://bugs.webkit.org/show_bug.cgi?id=80608 Reviewed by Tor Arne Vestbø. Added support for transparentBackground in QQuickWebViewExperimental. This uses the existing drawsTransparentBackground property in WebKit2. Also, changed LayerTreeHostQt to set the contentsOpaque flag when the root layer changes, otherwise the change doesn't take effect. A new API test was added. * UIProcess/API/qt/qquickwebview.cpp: (QQuickWebViewPrivate::setTransparentBackground): (QQuickWebViewPrivate::transparentBackground): (QQuickWebViewExperimental::transparentBackground): (QQuickWebViewExperimental::setTransparentBackground): * UIProcess/API/qt/qquickwebview_p.h: * UIProcess/API/qt/qquickwebview_p_p.h: (QQuickWebViewPrivate): * UIProcess/API/qt/tests/qquickwebview/tst_qquickwebview.cpp: (tst_QQuickWebView): (tst_QQuickWebView::transparentWebViews): * WebProcess/WebPage/qt/LayerTreeHostQt.cpp: (WebKit::LayerTreeHostQt::LayerTreeHostQt): (WebKit::LayerTreeHostQt::setRootCompositingLayer): git-svn-id: svn://svn.chromium.org/blink/trunk@110254 bbb929c8-8fbe-4397-9dbb-9b2b20218538 CWE ID: CWE-189
0
101,726
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: newkeys_from_blob(struct sshbuf *m, struct ssh *ssh, int mode) { struct sshbuf *b = NULL; struct sshcomp *comp; struct sshenc *enc; struct sshmac *mac; struct newkeys *newkey = NULL; size_t keylen, ivlen, maclen; int r; if ((newkey = calloc(1, sizeof(*newkey))) == NULL) { r = SSH_ERR_ALLOC_FAIL; goto out; } if ((r = sshbuf_froms(m, &b)) != 0) goto out; #ifdef DEBUG_PK sshbuf_dump(b, stderr); #endif enc = &newkey->enc; mac = &newkey->mac; comp = &newkey->comp; if ((r = sshbuf_get_cstring(b, &enc->name, NULL)) != 0 || (r = sshbuf_get(b, &enc->cipher, sizeof(enc->cipher))) != 0 || (r = sshbuf_get_u32(b, (u_int *)&enc->enabled)) != 0 || (r = sshbuf_get_u32(b, &enc->block_size)) != 0 || (r = sshbuf_get_string(b, &enc->key, &keylen)) != 0 || (r = sshbuf_get_string(b, &enc->iv, &ivlen)) != 0) goto out; if (cipher_authlen(enc->cipher) == 0) { if ((r = sshbuf_get_cstring(b, &mac->name, NULL)) != 0) goto out; if ((r = mac_setup(mac, mac->name)) != 0) goto out; if ((r = sshbuf_get_u32(b, (u_int *)&mac->enabled)) != 0 || (r = sshbuf_get_string(b, &mac->key, &maclen)) != 0) goto out; if (maclen > mac->key_len) { r = SSH_ERR_INVALID_FORMAT; goto out; } mac->key_len = maclen; } if ((r = sshbuf_get_u32(b, &comp->type)) != 0 || (r = sshbuf_get_u32(b, (u_int *)&comp->enabled)) != 0 || (r = sshbuf_get_cstring(b, &comp->name, NULL)) != 0) goto out; if (enc->name == NULL || cipher_by_name(enc->name) != enc->cipher) { r = SSH_ERR_INVALID_FORMAT; goto out; } if (sshbuf_len(b) != 0) { r = SSH_ERR_INVALID_FORMAT; goto out; } enc->key_len = keylen; enc->iv_len = ivlen; ssh->kex->newkeys[mode] = newkey; newkey = NULL; r = 0; out: free(newkey); sshbuf_free(b); return r; } Commit Message: Remove support for pre-authentication compression. Doing compression early in the protocol probably seemed reasonable in the 1990s, but today it's clearly a bad idea in terms of both cryptography (cf. multiple compression oracle attacks in TLS) and attack surface. Moreover, to support it across privilege-separation zlib needed the assistance of a complex shared-memory manager that made the required attack surface considerably larger. Prompted by Guido Vranken pointing out a compiler-elided security check in the shared memory manager found by Stack (http://css.csail.mit.edu/stack/); ok deraadt@ markus@ NB. pre-auth authentication has been disabled by default in sshd for >10 years. CWE ID: CWE-119
1
168,650
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static char * php_zipobj_get_filename(ze_zip_object *obj) /* {{{ */ { if (!obj) { return NULL; } if (obj->filename) { return obj->filename; } return NULL; } /* }}} */ Commit Message: Fix bug #71923 - integer overflow in ZipArchive::getFrom* CWE ID: CWE-190
0
54,439
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static void coroutine_fn v9fs_version(void *opaque) { ssize_t err; V9fsPDU *pdu = opaque; V9fsState *s = pdu->s; V9fsString version; size_t offset = 7; v9fs_string_init(&version); err = pdu_unmarshal(pdu, offset, "ds", &s->msize, &version); if (err < 0) { offset = err; goto out; } trace_v9fs_version(pdu->tag, pdu->id, s->msize, version.data); virtfs_reset(pdu); if (!strcmp(version.data, "9P2000.u")) { s->proto_version = V9FS_PROTO_2000U; } else if (!strcmp(version.data, "9P2000.L")) { s->proto_version = V9FS_PROTO_2000L; } else { v9fs_string_sprintf(&version, "unknown"); } err = pdu_marshal(pdu, offset, "ds", s->msize, &version); if (err < 0) { offset = err; goto out; } offset += err; trace_v9fs_version_return(pdu->tag, pdu->id, s->msize, version.data); out: pdu_complete(pdu, offset); v9fs_string_free(&version); } Commit Message: CWE ID: CWE-400
0
7,737
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static int check_call(struct bpf_verifier_env *env, int func_id, int insn_idx) { const struct bpf_func_proto *fn = NULL; struct bpf_reg_state *regs; struct bpf_call_arg_meta meta; bool changes_data; int i, err; /* find function prototype */ if (func_id < 0 || func_id >= __BPF_FUNC_MAX_ID) { verbose(env, "invalid func %s#%d\n", func_id_name(func_id), func_id); return -EINVAL; } if (env->ops->get_func_proto) fn = env->ops->get_func_proto(func_id); if (!fn) { verbose(env, "unknown func %s#%d\n", func_id_name(func_id), func_id); return -EINVAL; } /* eBPF programs must be GPL compatible to use GPL-ed functions */ if (!env->prog->gpl_compatible && fn->gpl_only) { verbose(env, "cannot call GPL only function from proprietary program\n"); return -EINVAL; } changes_data = bpf_helper_changes_pkt_data(fn->func); memset(&meta, 0, sizeof(meta)); meta.pkt_access = fn->pkt_access; /* We only support one arg being in raw mode at the moment, which * is sufficient for the helper functions we have right now. */ err = check_raw_mode(fn); if (err) { verbose(env, "kernel subsystem misconfigured func %s#%d\n", func_id_name(func_id), func_id); return err; } /* check args */ err = check_func_arg(env, BPF_REG_1, fn->arg1_type, &meta); if (err) return err; err = check_func_arg(env, BPF_REG_2, fn->arg2_type, &meta); if (err) return err; err = check_func_arg(env, BPF_REG_3, fn->arg3_type, &meta); if (err) return err; err = check_func_arg(env, BPF_REG_4, fn->arg4_type, &meta); if (err) return err; err = check_func_arg(env, BPF_REG_5, fn->arg5_type, &meta); if (err) return err; /* Mark slots with STACK_MISC in case of raw mode, stack offset * is inferred from register state. */ for (i = 0; i < meta.access_size; i++) { err = check_mem_access(env, insn_idx, meta.regno, i, BPF_B, BPF_WRITE, -1); if (err) return err; } regs = cur_regs(env); /* reset caller saved regs */ for (i = 0; i < CALLER_SAVED_REGS; i++) { mark_reg_not_init(env, regs, caller_saved[i]); check_reg_arg(env, caller_saved[i], DST_OP_NO_MARK); } /* update return register (already marked as written above) */ if (fn->ret_type == RET_INTEGER) { /* sets type to SCALAR_VALUE */ mark_reg_unknown(env, regs, BPF_REG_0); } else if (fn->ret_type == RET_VOID) { regs[BPF_REG_0].type = NOT_INIT; } else if (fn->ret_type == RET_PTR_TO_MAP_VALUE_OR_NULL) { struct bpf_insn_aux_data *insn_aux; regs[BPF_REG_0].type = PTR_TO_MAP_VALUE_OR_NULL; /* There is no offset yet applied, variable or fixed */ mark_reg_known_zero(env, regs, BPF_REG_0); regs[BPF_REG_0].off = 0; /* remember map_ptr, so that check_map_access() * can check 'value_size' boundary of memory access * to map element returned from bpf_map_lookup_elem() */ if (meta.map_ptr == NULL) { verbose(env, "kernel subsystem misconfigured verifier\n"); return -EINVAL; } regs[BPF_REG_0].map_ptr = meta.map_ptr; regs[BPF_REG_0].id = ++env->id_gen; insn_aux = &env->insn_aux_data[insn_idx]; if (!insn_aux->map_ptr) insn_aux->map_ptr = meta.map_ptr; else if (insn_aux->map_ptr != meta.map_ptr) insn_aux->map_ptr = BPF_MAP_PTR_POISON; } else { verbose(env, "unknown return type %d of func %s#%d\n", fn->ret_type, func_id_name(func_id), func_id); return -EINVAL; } err = check_map_func_compatibility(env, meta.map_ptr, func_id); if (err) return err; if (changes_data) clear_all_pkt_pointers(env); return 0; } Commit Message: bpf: fix branch pruning logic when the verifier detects that register contains a runtime constant and it's compared with another constant it will prune exploration of the branch that is guaranteed not to be taken at runtime. This is all correct, but malicious program may be constructed in such a way that it always has a constant comparison and the other branch is never taken under any conditions. In this case such path through the program will not be explored by the verifier. It won't be taken at run-time either, but since all instructions are JITed the malicious program may cause JITs to complain about using reserved fields, etc. To fix the issue we have to track the instructions explored by the verifier and sanitize instructions that are dead at run time with NOPs. We cannot reject such dead code, since llvm generates it for valid C code, since it doesn't do as much data flow analysis as the verifier does. Fixes: 17a5267067f3 ("bpf: verifier (add verifier core)") Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> CWE ID: CWE-20
0
59,105
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: void RenderFrameImpl::didChangeThemeColor() { if (frame_->parent()) return; Send(new FrameHostMsg_DidChangeThemeColor( routing_id_, frame_->document().themeColor())); } Commit Message: Connect WebUSB client interface to the devices app This provides a basic WebUSB client interface in content/renderer. Most of the interface is unimplemented, but this CL hooks up navigator.usb.getDevices() to the browser's Mojo devices app to enumerate available USB devices. BUG=492204 Review URL: https://codereview.chromium.org/1293253002 Cr-Commit-Position: refs/heads/master@{#344881} CWE ID: CWE-399
0
123,222
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: void IRCView::wipeLineParagraphs() { m_rememberLine = m_lastMarkerLine = 0; } Commit Message: CWE ID:
0
1,779
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: asmlinkage void do_ade(struct pt_regs *regs) { unsigned int __user *pc; mm_segment_t seg; perf_sw_event(PERF_COUNT_SW_ALIGNMENT_FAULTS, 1, 0, regs, regs->cp0_badvaddr); /* * Did we catch a fault trying to load an instruction? * Or are we running in MIPS16 mode? */ if ((regs->cp0_badvaddr == regs->cp0_epc) || (regs->cp0_epc & 0x1)) goto sigbus; pc = (unsigned int __user *) exception_epc(regs); if (user_mode(regs) && !test_thread_flag(TIF_FIXADE)) goto sigbus; if (unaligned_action == UNALIGNED_ACTION_SIGNAL) goto sigbus; else if (unaligned_action == UNALIGNED_ACTION_SHOW) show_registers(regs); /* * Do branch emulation only if we didn't forward the exception. * This is all so but ugly ... */ seg = get_fs(); if (!user_mode(regs)) set_fs(KERNEL_DS); emulate_load_store_insn(regs, (void __user *)regs->cp0_badvaddr, pc); set_fs(seg); return; sigbus: die_if_kernel("Kernel unaligned instruction access", regs); force_sig(SIGBUS, current); /* * XXX On return from the signal handler we should advance the epc */ } Commit Message: perf: Remove the nmi parameter from the swevent and overflow interface The nmi parameter indicated if we could do wakeups from the current context, if not, we would set some state and self-IPI and let the resulting interrupt do the wakeup. For the various event classes: - hardware: nmi=0; PMI is in fact an NMI or we run irq_work_run from the PMI-tail (ARM etc.) - tracepoint: nmi=0; since tracepoint could be from NMI context. - software: nmi=[0,1]; some, like the schedule thing cannot perform wakeups, and hence need 0. As one can see, there is very little nmi=1 usage, and the down-side of not using it is that on some platforms some software events can have a jiffy delay in wakeup (when arch_irq_work_raise isn't implemented). The up-side however is that we can remove the nmi parameter and save a bunch of conditionals in fast paths. Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Michael Cree <mcree@orcon.net.nz> Cc: Will Deacon <will.deacon@arm.com> Cc: Deng-Cheng Zhu <dengcheng.zhu@gmail.com> Cc: Anton Blanchard <anton@samba.org> Cc: Eric B Munson <emunson@mgebm.net> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Paul Mundt <lethal@linux-sh.org> Cc: David S. Miller <davem@davemloft.net> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jason Wessel <jason.wessel@windriver.com> Cc: Don Zickus <dzickus@redhat.com> Link: http://lkml.kernel.org/n/tip-agjev8eu666tvknpb3iaj0fg@git.kernel.org Signed-off-by: Ingo Molnar <mingo@elte.hu> CWE ID: CWE-399
1
165,784
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc, const char **argv,Image **image,ExceptionInfo *exception) { ChannelType channel; const char *format, *option; DrawInfo *draw_info; GeometryInfo geometry_info; Image *region_image; ImageInfo *mogrify_info; MagickStatusType status; MagickPixelPacket fill; MagickStatusType flags; QuantizeInfo *quantize_info; RectangleInfo geometry, region_geometry; register ssize_t i; /* Initialize method variables. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickCoreSignature); assert(image != (Image **) NULL); assert((*image)->signature == MagickCoreSignature); if ((*image)->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename); if (argc < 0) return(MagickTrue); mogrify_info=CloneImageInfo(image_info); draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL); quantize_info=AcquireQuantizeInfo(mogrify_info); SetGeometryInfo(&geometry_info); GetMagickPixelPacket(*image,&fill); SetMagickPixelPacket(*image,&(*image)->background_color,(IndexPacket *) NULL, &fill); channel=mogrify_info->channel; format=GetImageOption(mogrify_info,"format"); SetGeometry(*image,&region_geometry); region_image=NewImageList(); /* Transmogrify the image. */ for (i=0; i < (ssize_t) argc; i++) { Image *mogrify_image; ssize_t count; option=argv[i]; if (IsCommandOption(option) == MagickFalse) continue; count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option), 0L); if ((i+count) >= (ssize_t) argc) break; status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception); mogrify_image=(Image *) NULL; switch (*(option+1)) { case 'a': { if (LocaleCompare("adaptive-blur",option+1) == 0) { /* Adaptive blur image. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); if ((flags & SigmaValue) == 0) geometry_info.sigma=1.0; mogrify_image=AdaptiveBlurImageChannel(*image,channel, geometry_info.rho,geometry_info.sigma,exception); break; } if (LocaleCompare("adaptive-resize",option+1) == 0) { /* Adaptive resize image. */ (void) SyncImageSettings(mogrify_info,*image); (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception); mogrify_image=AdaptiveResizeImage(*image,geometry.width, geometry.height,exception); break; } if (LocaleCompare("adaptive-sharpen",option+1) == 0) { /* Adaptive sharpen image. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); if ((flags & SigmaValue) == 0) geometry_info.sigma=1.0; mogrify_image=AdaptiveSharpenImageChannel(*image,channel, geometry_info.rho,geometry_info.sigma,exception); break; } if (LocaleCompare("affine",option+1) == 0) { /* Affine matrix. */ if (*option == '+') { GetAffineMatrix(&draw_info->affine); break; } (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception); break; } if (LocaleCompare("alpha",option+1) == 0) { AlphaChannelType alpha_type; (void) SyncImageSettings(mogrify_info,*image); alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions, MagickFalse,argv[i+1]); (void) SetImageAlphaChannel(*image,alpha_type); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("annotate",option+1) == 0) { char *text, geometry[MaxTextExtent]; /* Annotate image. */ (void) SyncImageSettings(mogrify_info,*image); SetGeometryInfo(&geometry_info); flags=ParseGeometry(argv[i+1],&geometry_info); if ((flags & SigmaValue) == 0) geometry_info.sigma=geometry_info.rho; text=InterpretImageProperties(mogrify_info,*image,argv[i+2]); InheritException(exception,&(*image)->exception); if (text == (char *) NULL) break; (void) CloneString(&draw_info->text,text); text=DestroyString(text); (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f", geometry_info.xi,geometry_info.psi); (void) CloneString(&draw_info->geometry,geometry); draw_info->affine.sx=cos(DegreesToRadians( fmod(geometry_info.rho,360.0))); draw_info->affine.rx=sin(DegreesToRadians( fmod(geometry_info.rho,360.0))); draw_info->affine.ry=(-sin(DegreesToRadians( fmod(geometry_info.sigma,360.0)))); draw_info->affine.sy=cos(DegreesToRadians( fmod(geometry_info.sigma,360.0))); (void) AnnotateImage(*image,draw_info); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("antialias",option+1) == 0) { draw_info->stroke_antialias=(*option == '-') ? MagickTrue : MagickFalse; draw_info->text_antialias=(*option == '-') ? MagickTrue : MagickFalse; break; } if (LocaleCompare("auto-gamma",option+1) == 0) { /* Auto Adjust Gamma of image based on its mean */ (void) SyncImageSettings(mogrify_info,*image); (void) AutoGammaImageChannel(*image,channel); break; } if (LocaleCompare("auto-level",option+1) == 0) { /* Perfectly Normalize (max/min stretch) the image */ (void) SyncImageSettings(mogrify_info,*image); (void) AutoLevelImageChannel(*image,channel); break; } if (LocaleCompare("auto-orient",option+1) == 0) { (void) SyncImageSettings(mogrify_info,*image); mogrify_image=AutoOrientImage(*image,(*image)->orientation, exception); break; } break; } case 'b': { if (LocaleCompare("black-threshold",option+1) == 0) { /* Black threshold image. */ (void) SyncImageSettings(mogrify_info,*image); (void) BlackThresholdImageChannel(*image,channel,argv[i+1], exception); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("blue-shift",option+1) == 0) { /* Blue shift image. */ (void) SyncImageSettings(mogrify_info,*image); geometry_info.rho=1.5; if (*option == '-') flags=ParseGeometry(argv[i+1],&geometry_info); mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception); break; } if (LocaleCompare("blur",option+1) == 0) { /* Gaussian blur image. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); if ((flags & SigmaValue) == 0) geometry_info.sigma=1.0; mogrify_image=BlurImageChannel(*image,channel,geometry_info.rho, geometry_info.sigma,exception); break; } if (LocaleCompare("border",option+1) == 0) { /* Surround image with a border of solid color. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception); mogrify_image=BorderImage(*image,&geometry,exception); break; } if (LocaleCompare("bordercolor",option+1) == 0) { if (*option == '+') { (void) QueryColorDatabase(MogrifyBorderColor, &draw_info->border_color,exception); break; } (void) QueryColorDatabase(argv[i+1],&draw_info->border_color, exception); break; } if (LocaleCompare("box",option+1) == 0) { (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor, exception); break; } if (LocaleCompare("brightness-contrast",option+1) == 0) { double brightness, contrast; GeometryInfo geometry_info; MagickStatusType flags; /* Brightness / contrast image. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); brightness=geometry_info.rho; contrast=0.0; if ((flags & SigmaValue) != 0) contrast=geometry_info.sigma; (void) BrightnessContrastImageChannel(*image,channel,brightness, contrast); InheritException(exception,&(*image)->exception); break; } break; } case 'c': { if (LocaleCompare("canny",option+1) == 0) { /* Detect edges in the image. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); if ((flags & SigmaValue) == 0) geometry_info.sigma=1.0; if ((flags & XiValue) == 0) geometry_info.xi=0.10; if ((flags & PsiValue) == 0) geometry_info.psi=0.30; if ((flags & PercentValue) != 0) { geometry_info.xi/=100.0; geometry_info.psi/=100.0; } mogrify_image=CannyEdgeImage(*image,geometry_info.rho, geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception); break; } if (LocaleCompare("cdl",option+1) == 0) { char *color_correction_collection; /* Color correct with a color decision list. */ (void) SyncImageSettings(mogrify_info,*image); color_correction_collection=FileToString(argv[i+1],~0UL,exception); if (color_correction_collection == (char *) NULL) break; (void) ColorDecisionListImage(*image,color_correction_collection); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("channel",option+1) == 0) { if (*option == '+') channel=DefaultChannels; else channel=(ChannelType) ParseChannelOption(argv[i+1]); break; } if (LocaleCompare("charcoal",option+1) == 0) { /* Charcoal image. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); if ((flags & SigmaValue) == 0) geometry_info.sigma=1.0; mogrify_image=CharcoalImage(*image,geometry_info.rho, geometry_info.sigma,exception); break; } if (LocaleCompare("chop",option+1) == 0) { /* Chop the image. */ (void) SyncImageSettings(mogrify_info,*image); (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception); mogrify_image=ChopImage(*image,&geometry,exception); break; } if (LocaleCompare("clamp",option+1) == 0) { /* Clamp image. */ (void) SyncImageSettings(mogrify_info,*image); (void) ClampImageChannel(*image,channel); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("clip",option+1) == 0) { (void) SyncImageSettings(mogrify_info,*image); if (*option == '+') { (void) SetImageClipMask(*image,(Image *) NULL); InheritException(exception,&(*image)->exception); break; } (void) ClipImage(*image); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("clip-mask",option+1) == 0) { CacheView *mask_view; Image *mask_image; register PixelPacket *magick_restrict q; register ssize_t x; ssize_t y; (void) SyncImageSettings(mogrify_info,*image); if (*option == '+') { /* Remove a mask. */ (void) SetImageMask(*image,(Image *) NULL); InheritException(exception,&(*image)->exception); break; } /* Set the image mask. FUTURE: This Should Be a SetImageAlphaChannel() call, Or two. */ mask_image=GetImageCache(mogrify_info,argv[i+1],exception); if (mask_image == (Image *) NULL) break; if (SetImageStorageClass(mask_image,DirectClass) == MagickFalse) return(MagickFalse); mask_view=AcquireAuthenticCacheView(mask_image,exception); for (y=0; y < (ssize_t) mask_image->rows; y++) { q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1, exception); if (q == (PixelPacket *) NULL) break; for (x=0; x < (ssize_t) mask_image->columns; x++) { if (mask_image->matte == MagickFalse) SetPixelOpacity(q,ClampToQuantum(GetPixelIntensity(mask_image, q))); SetPixelRed(q,GetPixelOpacity(q)); SetPixelGreen(q,GetPixelOpacity(q)); SetPixelBlue(q,GetPixelOpacity(q)); q++; } if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse) break; } mask_view=DestroyCacheView(mask_view); mask_image->matte=MagickTrue; (void) SetImageClipMask(*image,mask_image); mask_image=DestroyImage(mask_image); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("clip-path",option+1) == 0) { (void) SyncImageSettings(mogrify_info,*image); (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue : MagickFalse); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("colorize",option+1) == 0) { /* Colorize the image. */ (void) SyncImageSettings(mogrify_info,*image); mogrify_image=ColorizeImage(*image,argv[i+1],draw_info->fill, exception); break; } if (LocaleCompare("color-matrix",option+1) == 0) { KernelInfo *kernel; (void) SyncImageSettings(mogrify_info,*image); kernel=AcquireKernelInfo(argv[i+1]); if (kernel == (KernelInfo *) NULL) break; mogrify_image=ColorMatrixImage(*image,kernel,exception); kernel=DestroyKernelInfo(kernel); break; } if (LocaleCompare("colors",option+1) == 0) { /* Reduce the number of colors in the image. */ (void) SyncImageSettings(mogrify_info,*image); quantize_info->number_colors=StringToUnsignedLong(argv[i+1]); if (quantize_info->number_colors == 0) break; if (((*image)->storage_class == DirectClass) || (*image)->colors > quantize_info->number_colors) (void) QuantizeImage(quantize_info,*image); else (void) CompressImageColormap(*image); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("colorspace",option+1) == 0) { ColorspaceType colorspace; (void) SyncImageSettings(mogrify_info,*image); if (*option == '+') { (void) TransformImageColorspace(*image,sRGBColorspace); InheritException(exception,&(*image)->exception); break; } colorspace=(ColorspaceType) ParseCommandOption( MagickColorspaceOptions,MagickFalse,argv[i+1]); (void) TransformImageColorspace(*image,colorspace); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("connected-components",option+1) == 0) { (void) SyncImageSettings(mogrify_info,*image); mogrify_image=ConnectedComponentsImage(*image, StringToInteger(argv[i+1]),exception); break; } if (LocaleCompare("contrast",option+1) == 0) { (void) SyncImageSettings(mogrify_info,*image); (void) ContrastImage(*image,(*option == '-') ? MagickTrue : MagickFalse); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("contrast-stretch",option+1) == 0) { double black_point, white_point; MagickStatusType flags; /* Contrast stretch image. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); black_point=geometry_info.rho; white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma : black_point; if ((flags & PercentValue) != 0) { black_point*=(double) (*image)->columns*(*image)->rows/100.0; white_point*=(double) (*image)->columns*(*image)->rows/100.0; } white_point=(MagickRealType) (*image)->columns*(*image)->rows- white_point; (void) ContrastStretchImageChannel(*image,channel,black_point, white_point); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("convolve",option+1) == 0) { double gamma; KernelInfo *kernel_info; register ssize_t j; size_t extent; (void) SyncImageSettings(mogrify_info,*image); kernel_info=AcquireKernelInfo(argv[i+1]); if (kernel_info == (KernelInfo *) NULL) break; extent=kernel_info->width*kernel_info->height; gamma=0.0; for (j=0; j < (ssize_t) extent; j++) gamma+=kernel_info->values[j]; gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); for (j=0; j < (ssize_t) extent; j++) kernel_info->values[j]*=gamma; mogrify_image=MorphologyImage(*image,CorrelateMorphology,1, kernel_info,exception); kernel_info=DestroyKernelInfo(kernel_info); break; } if (LocaleCompare("crop",option+1) == 0) { /* Crop a image to a smaller size */ (void) SyncImageSettings(mogrify_info,*image); #if 0 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception); if (((geometry.width != 0) || (geometry.height != 0)) && ((flags & XValue) == 0) && ((flags & YValue) == 0)) break; #endif #if 0 mogrify_image=CloneImage(*image,0,0,MagickTrue,&(*image)->exception); mogrify_image->next = mogrify_image->previous = (Image *) NULL; (void) TransformImage(&mogrify_image,argv[i+1],(char *) NULL); InheritException(exception,&mogrify_image->exception); #else mogrify_image=CropImageToTiles(*image,argv[i+1],exception); #endif break; } if (LocaleCompare("cycle",option+1) == 0) { /* Cycle an image colormap. */ (void) SyncImageSettings(mogrify_info,*image); (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1])); InheritException(exception,&(*image)->exception); break; } break; } case 'd': { if (LocaleCompare("decipher",option+1) == 0) { StringInfo *passkey; /* Decipher pixels. */ (void) SyncImageSettings(mogrify_info,*image); passkey=FileToStringInfo(argv[i+1],~0UL,exception); if (passkey != (StringInfo *) NULL) { (void) PasskeyDecipherImage(*image,passkey,exception); passkey=DestroyStringInfo(passkey); } break; } if (LocaleCompare("density",option+1) == 0) { /* Set image density. */ (void) CloneString(&draw_info->density,argv[i+1]); break; } if (LocaleCompare("depth",option+1) == 0) { (void) SyncImageSettings(mogrify_info,*image); if (*option == '+') { (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH); break; } (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1])); break; } if (LocaleCompare("deskew",option+1) == 0) { double threshold; /* Straighten the image. */ (void) SyncImageSettings(mogrify_info,*image); if (*option == '+') threshold=40.0*QuantumRange/100.0; else threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+ 1.0); mogrify_image=DeskewImage(*image,threshold,exception); break; } if (LocaleCompare("despeckle",option+1) == 0) { /* Reduce the speckles within an image. */ (void) SyncImageSettings(mogrify_info,*image); mogrify_image=DespeckleImage(*image,exception); break; } if (LocaleCompare("display",option+1) == 0) { (void) CloneString(&draw_info->server_name,argv[i+1]); break; } if (LocaleCompare("distort",option+1) == 0) { char *args, token[MaxTextExtent]; const char *p; DistortImageMethod method; double *arguments; register ssize_t x; size_t number_arguments; /* Distort image. */ (void) SyncImageSettings(mogrify_info,*image); method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions, MagickFalse,argv[i+1]); if (method == ResizeDistortion) { double resize_args[2]; /* Resize distortion. */ (void) ParseRegionGeometry(*image,argv[i+2],&geometry, exception); resize_args[0]=(double) geometry.width; resize_args[1]=(double) geometry.height; mogrify_image=DistortImage(*image,method,(size_t) 2, resize_args,MagickTrue,exception); break; } args=InterpretImageProperties(mogrify_info,*image,argv[i+2]); InheritException(exception,&(*image)->exception); if (args == (char *) NULL) break; p=(char *) args; for (x=0; *p != '\0'; x++) { GetNextToken(p,&p,MaxTextExtent,token); if (*token == ',') GetNextToken(p,&p,MaxTextExtent,token); } number_arguments=(size_t) x; arguments=(double *) AcquireQuantumMemory(number_arguments, sizeof(*arguments)); if (arguments == (double *) NULL) ThrowWandFatalException(ResourceLimitFatalError, "MemoryAllocationFailed",(*image)->filename); (void) memset(arguments,0,number_arguments*sizeof(*arguments)); p=(char *) args; for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++) { GetNextToken(p,&p,MaxTextExtent,token); if (*token == ',') GetNextToken(p,&p,MaxTextExtent,token); arguments[x]=StringToDouble(token,(char **) NULL); } args=DestroyString(args); mogrify_image=DistortImage(*image,method,number_arguments,arguments, (*option == '+') ? MagickTrue : MagickFalse,exception); arguments=(double *) RelinquishMagickMemory(arguments); break; } if (LocaleCompare("dither",option+1) == 0) { if (*option == '+') { quantize_info->dither=MagickFalse; break; } quantize_info->dither=MagickTrue; quantize_info->dither_method=(DitherMethod) ParseCommandOption( MagickDitherOptions,MagickFalse,argv[i+1]); if (quantize_info->dither_method == NoDitherMethod) quantize_info->dither=MagickFalse; break; } if (LocaleCompare("draw",option+1) == 0) { /* Draw image. */ (void) SyncImageSettings(mogrify_info,*image); (void) CloneString(&draw_info->primitive,argv[i+1]); (void) DrawImage(*image,draw_info); InheritException(exception,&(*image)->exception); break; } break; } case 'e': { if (LocaleCompare("edge",option+1) == 0) { /* Enhance edges in the image. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); if ((flags & SigmaValue) == 0) geometry_info.sigma=1.0; mogrify_image=EdgeImage(*image,geometry_info.rho,exception); break; } if (LocaleCompare("emboss",option+1) == 0) { /* Gaussian embossen image. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); if ((flags & SigmaValue) == 0) geometry_info.sigma=1.0; mogrify_image=EmbossImage(*image,geometry_info.rho, geometry_info.sigma,exception); break; } if (LocaleCompare("encipher",option+1) == 0) { StringInfo *passkey; /* Encipher pixels. */ (void) SyncImageSettings(mogrify_info,*image); passkey=FileToStringInfo(argv[i+1],~0UL,exception); if (passkey != (StringInfo *) NULL) { (void) PasskeyEncipherImage(*image,passkey,exception); passkey=DestroyStringInfo(passkey); } break; } if (LocaleCompare("encoding",option+1) == 0) { (void) CloneString(&draw_info->encoding,argv[i+1]); break; } if (LocaleCompare("enhance",option+1) == 0) { /* Enhance image. */ (void) SyncImageSettings(mogrify_info,*image); mogrify_image=EnhanceImage(*image,exception); break; } if (LocaleCompare("equalize",option+1) == 0) { /* Equalize image. */ (void) SyncImageSettings(mogrify_info,*image); (void) EqualizeImageChannel(*image,channel); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("evaluate",option+1) == 0) { double constant; MagickEvaluateOperator op; (void) SyncImageSettings(mogrify_info,*image); op=(MagickEvaluateOperator) ParseCommandOption( MagickEvaluateOptions,MagickFalse,argv[i+1]); constant=StringToDoubleInterval(argv[i+2],(double) QuantumRange+ 1.0); (void) EvaluateImageChannel(*image,channel,op,constant,exception); break; } if (LocaleCompare("extent",option+1) == 0) { /* Set the image extent. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception); if (geometry.width == 0) geometry.width=(*image)->columns; if (geometry.height == 0) geometry.height=(*image)->rows; mogrify_image=ExtentImage(*image,&geometry,exception); break; } break; } case 'f': { if (LocaleCompare("family",option+1) == 0) { if (*option == '+') { if (draw_info->family != (char *) NULL) draw_info->family=DestroyString(draw_info->family); break; } (void) CloneString(&draw_info->family,argv[i+1]); break; } if (LocaleCompare("features",option+1) == 0) { if (*option == '+') { (void) DeleteImageArtifact(*image,"identify:features"); break; } (void) SetImageArtifact(*image,"identify:features",argv[i+1]); (void) SetImageArtifact(*image,"verbose","true"); break; } if (LocaleCompare("fill",option+1) == 0) { ExceptionInfo *sans; GetMagickPixelPacket(*image,&fill); if (*option == '+') { (void) QueryMagickColor("none",&fill,exception); (void) QueryColorDatabase("none",&draw_info->fill,exception); if (draw_info->fill_pattern != (Image *) NULL) draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern); break; } sans=AcquireExceptionInfo(); (void) QueryMagickColor(argv[i+1],&fill,sans); status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans); sans=DestroyExceptionInfo(sans); if (status == MagickFalse) draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1], exception); break; } if (LocaleCompare("flip",option+1) == 0) { /* Flip image scanlines. */ (void) SyncImageSettings(mogrify_info,*image); mogrify_image=FlipImage(*image,exception); break; } if (LocaleCompare("floodfill",option+1) == 0) { MagickPixelPacket target; /* Floodfill image. */ (void) SyncImageSettings(mogrify_info,*image); (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception); (void) QueryMagickColor(argv[i+2],&target,exception); (void) FloodfillPaintImage(*image,channel,draw_info,&target, geometry.x,geometry.y,*option == '-' ? MagickFalse : MagickTrue); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("flop",option+1) == 0) { /* Flop image scanlines. */ (void) SyncImageSettings(mogrify_info,*image); mogrify_image=FlopImage(*image,exception); break; } if (LocaleCompare("font",option+1) == 0) { if (*option == '+') { if (draw_info->font != (char *) NULL) draw_info->font=DestroyString(draw_info->font); break; } (void) CloneString(&draw_info->font,argv[i+1]); break; } if (LocaleCompare("format",option+1) == 0) { format=argv[i+1]; break; } if (LocaleCompare("frame",option+1) == 0) { FrameInfo frame_info; /* Surround image with an ornamental border. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception); frame_info.width=geometry.width; frame_info.height=geometry.height; frame_info.outer_bevel=geometry.x; frame_info.inner_bevel=geometry.y; frame_info.x=(ssize_t) frame_info.width; frame_info.y=(ssize_t) frame_info.height; frame_info.width=(*image)->columns+2*frame_info.width; frame_info.height=(*image)->rows+2*frame_info.height; mogrify_image=FrameImage(*image,&frame_info,exception); break; } if (LocaleCompare("function",option+1) == 0) { char *arguments, token[MaxTextExtent]; const char *p; double *parameters; MagickFunction function; register ssize_t x; size_t number_parameters; /* Function Modify Image Values */ (void) SyncImageSettings(mogrify_info,*image); function=(MagickFunction) ParseCommandOption(MagickFunctionOptions, MagickFalse,argv[i+1]); arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]); InheritException(exception,&(*image)->exception); if (arguments == (char *) NULL) break; p=(char *) arguments; for (x=0; *p != '\0'; x++) { GetNextToken(p,&p,MaxTextExtent,token); if (*token == ',') GetNextToken(p,&p,MaxTextExtent,token); } number_parameters=(size_t) x; parameters=(double *) AcquireQuantumMemory(number_parameters, sizeof(*parameters)); if (parameters == (double *) NULL) ThrowWandFatalException(ResourceLimitFatalError, "MemoryAllocationFailed",(*image)->filename); (void) memset(parameters,0,number_parameters* sizeof(*parameters)); p=(char *) arguments; for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++) { GetNextToken(p,&p,MaxTextExtent,token); if (*token == ',') GetNextToken(p,&p,MaxTextExtent,token); parameters[x]=StringToDouble(token,(char **) NULL); } arguments=DestroyString(arguments); (void) FunctionImageChannel(*image,channel,function, number_parameters,parameters,exception); parameters=(double *) RelinquishMagickMemory(parameters); break; } break; } case 'g': { if (LocaleCompare("gamma",option+1) == 0) { /* Gamma image. */ (void) SyncImageSettings(mogrify_info,*image); if (*option == '+') (*image)->gamma=StringToDouble(argv[i+1],(char **) NULL); else { if (strchr(argv[i+1],',') != (char *) NULL) (void) GammaImage(*image,argv[i+1]); else (void) GammaImageChannel(*image,channel, StringToDouble(argv[i+1],(char **) NULL)); InheritException(exception,&(*image)->exception); } break; } if ((LocaleCompare("gaussian-blur",option+1) == 0) || (LocaleCompare("gaussian",option+1) == 0)) { /* Gaussian blur image. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); if ((flags & SigmaValue) == 0) geometry_info.sigma=1.0; mogrify_image=GaussianBlurImageChannel(*image,channel, geometry_info.rho,geometry_info.sigma,exception); break; } if (LocaleCompare("geometry",option+1) == 0) { /* Record Image offset, Resize last image. */ (void) SyncImageSettings(mogrify_info,*image); if (*option == '+') { if ((*image)->geometry != (char *) NULL) (*image)->geometry=DestroyString((*image)->geometry); break; } flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception); if (((flags & XValue) != 0) || ((flags & YValue) != 0)) (void) CloneString(&(*image)->geometry,argv[i+1]); else mogrify_image=ResizeImage(*image,geometry.width,geometry.height, (*image)->filter,(*image)->blur,exception); break; } if (LocaleCompare("gravity",option+1) == 0) { if (*option == '+') { draw_info->gravity=UndefinedGravity; break; } draw_info->gravity=(GravityType) ParseCommandOption( MagickGravityOptions,MagickFalse,argv[i+1]); break; } if (LocaleCompare("grayscale",option+1) == 0) { PixelIntensityMethod method; (void) SyncImagesSettings(mogrify_info,*image); method=(PixelIntensityMethod) ParseCommandOption( MagickPixelIntensityOptions,MagickFalse,argv[i+1]); (void) GrayscaleImage(*image,method); InheritException(exception,&(*image)->exception); break; } break; } case 'h': { if (LocaleCompare("highlight-color",option+1) == 0) { (void) SetImageArtifact(*image,"compare:highlight-color",argv[i+1]); break; } if (LocaleCompare("hough-lines",option+1) == 0) { /* Identify lines in the image. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); if ((flags & SigmaValue) == 0) geometry_info.sigma=geometry_info.rho; if ((flags & XiValue) == 0) geometry_info.xi=40; mogrify_image=HoughLineImage(*image,(size_t) geometry_info.rho, (size_t) geometry_info.sigma,(size_t) geometry_info.xi,exception); break; } break; } case 'i': { if (LocaleCompare("identify",option+1) == 0) { char *text; (void) SyncImageSettings(mogrify_info,*image); if (format == (char *) NULL) { (void) IdentifyImage(*image,stdout,mogrify_info->verbose); InheritException(exception,&(*image)->exception); break; } text=InterpretImageProperties(mogrify_info,*image,format); InheritException(exception,&(*image)->exception); if (text == (char *) NULL) break; (void) fputs(text,stdout); text=DestroyString(text); break; } if (LocaleCompare("implode",option+1) == 0) { /* Implode image. */ (void) SyncImageSettings(mogrify_info,*image); (void) ParseGeometry(argv[i+1],&geometry_info); mogrify_image=ImplodeImage(*image,geometry_info.rho,exception); break; } if (LocaleCompare("interline-spacing",option+1) == 0) { if (*option == '+') (void) ParseGeometry("0",&geometry_info); else (void) ParseGeometry(argv[i+1],&geometry_info); draw_info->interline_spacing=geometry_info.rho; break; } if (LocaleCompare("interword-spacing",option+1) == 0) { if (*option == '+') (void) ParseGeometry("0",&geometry_info); else (void) ParseGeometry(argv[i+1],&geometry_info); draw_info->interword_spacing=geometry_info.rho; break; } if (LocaleCompare("interpolative-resize",option+1) == 0) { /* Resize image using 'point sampled' interpolation */ (void) SyncImageSettings(mogrify_info,*image); (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception); mogrify_image=InterpolativeResizeImage(*image,geometry.width, geometry.height,(*image)->interpolate,exception); break; } break; } case 'k': { if (LocaleCompare("kerning",option+1) == 0) { if (*option == '+') (void) ParseGeometry("0",&geometry_info); else (void) ParseGeometry(argv[i+1],&geometry_info); draw_info->kerning=geometry_info.rho; break; } if (LocaleCompare("kuwahara",option+1) == 0) { /* Edge preserving blur. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); if ((flags & SigmaValue) == 0) geometry_info.sigma=geometry_info.rho-0.5; mogrify_image=KuwaharaImageChannel(*image,channel,geometry_info.rho, geometry_info.sigma,exception); break; } break; } case 'l': { if (LocaleCompare("lat",option+1) == 0) { /* Local adaptive threshold image. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); if ((flags & SigmaValue) == 0) geometry_info.sigma=1.0; if ((flags & PercentValue) != 0) geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0; mogrify_image=AdaptiveThresholdImage(*image,(size_t) geometry_info.rho,(size_t) geometry_info.sigma,(ssize_t) geometry_info.xi,exception); break; } if (LocaleCompare("level",option+1) == 0) { MagickRealType black_point, gamma, white_point; MagickStatusType flags; /* Parse levels. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); black_point=geometry_info.rho; white_point=(MagickRealType) QuantumRange; if ((flags & SigmaValue) != 0) white_point=geometry_info.sigma; gamma=1.0; if ((flags & XiValue) != 0) gamma=geometry_info.xi; if ((flags & PercentValue) != 0) { black_point*=(MagickRealType) (QuantumRange/100.0); white_point*=(MagickRealType) (QuantumRange/100.0); } if ((flags & SigmaValue) == 0) white_point=(MagickRealType) QuantumRange-black_point; if ((*option == '+') || ((flags & AspectValue) != 0)) (void) LevelizeImageChannel(*image,channel,black_point, white_point,gamma); else (void) LevelImageChannel(*image,channel,black_point,white_point, gamma); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("level-colors",option+1) == 0) { char token[MaxTextExtent]; const char *p; MagickPixelPacket black_point, white_point; p=(const char *) argv[i+1]; GetNextToken(p,&p,MaxTextExtent,token); /* get black point color */ if ((isalpha((int) *token) != 0) || ((*token == '#') != 0)) (void) QueryMagickColor(token,&black_point,exception); else (void) QueryMagickColor("#000000",&black_point,exception); if (isalpha((int) token[0]) || (token[0] == '#')) GetNextToken(p,&p,MaxTextExtent,token); if (*token == '\0') white_point=black_point; /* set everything to that color */ else { if ((isalpha((int) *token) == 0) && ((*token == '#') == 0)) GetNextToken(p,&p,MaxTextExtent,token); /* Get white point color. */ if ((isalpha((int) *token) != 0) || ((*token == '#') != 0)) (void) QueryMagickColor(token,&white_point,exception); else (void) QueryMagickColor("#ffffff",&white_point,exception); } (void) LevelColorsImageChannel(*image,channel,&black_point, &white_point,*option == '+' ? MagickTrue : MagickFalse); break; } if (LocaleCompare("linear-stretch",option+1) == 0) { double black_point, white_point; MagickStatusType flags; (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); black_point=geometry_info.rho; white_point=(MagickRealType) (*image)->columns*(*image)->rows; if ((flags & SigmaValue) != 0) white_point=geometry_info.sigma; if ((flags & PercentValue) != 0) { black_point*=(double) (*image)->columns*(*image)->rows/100.0; white_point*=(double) (*image)->columns*(*image)->rows/100.0; } if ((flags & SigmaValue) == 0) white_point=(MagickRealType) (*image)->columns*(*image)->rows- black_point; (void) LinearStretchImage(*image,black_point,white_point); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("linewidth",option+1) == 0) { draw_info->stroke_width=StringToDouble(argv[i+1],(char **) NULL); break; } if (LocaleCompare("liquid-rescale",option+1) == 0) { /* Liquid rescale image. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception); if ((flags & XValue) == 0) geometry.x=1; if ((flags & YValue) == 0) geometry.y=0; mogrify_image=LiquidRescaleImage(*image,geometry.width, geometry.height,1.0*geometry.x,1.0*geometry.y,exception); break; } if (LocaleCompare("local-contrast",option+1) == 0) { MagickStatusType flags; (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); if ((flags & RhoValue) == 0) geometry_info.rho=10; if ((flags & SigmaValue) == 0) geometry_info.sigma=12.5; mogrify_image=LocalContrastImage(*image,geometry_info.rho, geometry_info.sigma,exception); break; } if (LocaleCompare("lowlight-color",option+1) == 0) { (void) SetImageArtifact(*image,"compare:lowlight-color",argv[i+1]); break; } break; } case 'm': { if (LocaleCompare("magnify",option+1) == 0) { /* Double image size. */ (void) SyncImageSettings(mogrify_info,*image); mogrify_image=MagnifyImage(*image,exception); break; } if (LocaleCompare("map",option+1) == 0) { Image *remap_image; /* Transform image colors to match this set of colors. */ (void) SyncImageSettings(mogrify_info,*image); if (*option == '+') break; remap_image=GetImageCache(mogrify_info,argv[i+1],exception); if (remap_image == (Image *) NULL) break; (void) RemapImage(quantize_info,*image,remap_image); InheritException(exception,&(*image)->exception); remap_image=DestroyImage(remap_image); break; } if (LocaleCompare("mask",option+1) == 0) { Image *mask; (void) SyncImageSettings(mogrify_info,*image); if (*option == '+') { /* Remove a mask. */ (void) SetImageMask(*image,(Image *) NULL); InheritException(exception,&(*image)->exception); break; } /* Set the image mask. */ mask=GetImageCache(mogrify_info,argv[i+1],exception); if (mask == (Image *) NULL) break; (void) SetImageMask(*image,mask); mask=DestroyImage(mask); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("matte",option+1) == 0) { (void) SetImageAlphaChannel(*image,(*option == '-') ? SetAlphaChannel : DeactivateAlphaChannel ); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("mean-shift",option+1) == 0) { /* Delineate arbitrarily shaped clusters in the image. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); if ((flags & SigmaValue) == 0) geometry_info.sigma=geometry_info.rho; if ((flags & XiValue) == 0) geometry_info.xi=0.10*QuantumRange; if ((flags & PercentValue) != 0) geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0; mogrify_image=MeanShiftImage(*image,(size_t) geometry_info.rho, (size_t) geometry_info.sigma,(size_t) geometry_info.xi,exception); break; } if (LocaleCompare("median",option+1) == 0) { /* Median filter image. */ (void) SyncImageSettings(mogrify_info,*image); (void) ParseGeometry(argv[i+1],&geometry_info); mogrify_image=StatisticImageChannel(*image,channel,MedianStatistic, (size_t) geometry_info.rho,(size_t) geometry_info.rho,exception); break; } if (LocaleCompare("mode",option+1) == 0) { /* Mode image. */ (void) SyncImageSettings(mogrify_info,*image); (void) ParseGeometry(argv[i+1],&geometry_info); mogrify_image=StatisticImageChannel(*image,channel,ModeStatistic, (size_t) geometry_info.rho,(size_t) geometry_info.rho,exception); break; } if (LocaleCompare("modulate",option+1) == 0) { (void) SyncImageSettings(mogrify_info,*image); (void) ModulateImage(*image,argv[i+1]); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("moments",option+1) == 0) { if (*option == '+') { (void) DeleteImageArtifact(*image,"identify:moments"); break; } (void) SetImageArtifact(*image,"identify:moments",argv[i+1]); (void) SetImageArtifact(*image,"verbose","true"); break; } if (LocaleCompare("monitor",option+1) == 0) { if (*option == '+') { (void) SetImageProgressMonitor(*image, (MagickProgressMonitor) NULL,(void *) NULL); break; } (void) SetImageProgressMonitor(*image,MonitorProgress, (void *) NULL); break; } if (LocaleCompare("monochrome",option+1) == 0) { (void) SyncImageSettings(mogrify_info,*image); (void) SetImageType(*image,BilevelType); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("morphology",option+1) == 0) { char token[MaxTextExtent]; const char *p; KernelInfo *kernel; MorphologyMethod method; ssize_t iterations; /* Morphological Image Operation */ (void) SyncImageSettings(mogrify_info,*image); p=argv[i+1]; GetNextToken(p,&p,MaxTextExtent,token); method=(MorphologyMethod) ParseCommandOption( MagickMorphologyOptions,MagickFalse,token); iterations=1L; GetNextToken(p,&p,MaxTextExtent,token); if ((*p == ':') || (*p == ',')) GetNextToken(p,&p,MaxTextExtent,token); if ((*p != '\0')) iterations=(ssize_t) StringToLong(p); kernel=AcquireKernelInfo(argv[i+2]); if (kernel == (KernelInfo *) NULL) { (void) ThrowMagickException(exception,GetMagickModule(), OptionError,"UnabletoParseKernel","morphology"); status=MagickFalse; break; } mogrify_image=MorphologyImageChannel(*image,channel,method, iterations,kernel,exception); kernel=DestroyKernelInfo(kernel); break; } if (LocaleCompare("motion-blur",option+1) == 0) { /* Motion blur image. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); if ((flags & SigmaValue) == 0) geometry_info.sigma=1.0; mogrify_image=MotionBlurImageChannel(*image,channel, geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception); break; } break; } case 'n': { if (LocaleCompare("negate",option+1) == 0) { (void) SyncImageSettings(mogrify_info,*image); (void) NegateImageChannel(*image,channel,*option == '+' ? MagickTrue : MagickFalse); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("noise",option+1) == 0) { (void) SyncImageSettings(mogrify_info,*image); if (*option == '-') { flags=ParseGeometry(argv[i+1],&geometry_info); if ((flags & SigmaValue) == 0) geometry_info.sigma=geometry_info.rho; mogrify_image=StatisticImageChannel(*image,channel, NonpeakStatistic,(size_t) geometry_info.rho,(size_t) geometry_info.sigma,exception); } else { NoiseType noise; noise=(NoiseType) ParseCommandOption(MagickNoiseOptions, MagickFalse,argv[i+1]); mogrify_image=AddNoiseImageChannel(*image,channel,noise, exception); } break; } if (LocaleCompare("normalize",option+1) == 0) { (void) SyncImageSettings(mogrify_info,*image); (void) NormalizeImageChannel(*image,channel); InheritException(exception,&(*image)->exception); break; } break; } case 'o': { if (LocaleCompare("opaque",option+1) == 0) { MagickPixelPacket target; (void) SyncImageSettings(mogrify_info,*image); (void) QueryMagickColor(argv[i+1],&target,exception); (void) OpaquePaintImageChannel(*image,channel,&target,&fill, *option == '-' ? MagickFalse : MagickTrue); break; } if (LocaleCompare("ordered-dither",option+1) == 0) { (void) SyncImageSettings(mogrify_info,*image); (void) OrderedPosterizeImageChannel(*image,channel,argv[i+1], exception); break; } break; } case 'p': { if (LocaleCompare("paint",option+1) == 0) { (void) SyncImageSettings(mogrify_info,*image); (void) ParseGeometry(argv[i+1],&geometry_info); mogrify_image=OilPaintImage(*image,geometry_info.rho,exception); break; } if (LocaleCompare("pen",option+1) == 0) { if (*option == '+') { (void) QueryColorDatabase("none",&draw_info->fill,exception); break; } (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception); break; } if (LocaleCompare("perceptible",option+1) == 0) { /* Perceptible image. */ (void) SyncImageSettings(mogrify_info,*image); (void) PerceptibleImageChannel(*image,channel,StringToDouble( argv[i+1],(char **) NULL)); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("pointsize",option+1) == 0) { if (*option == '+') (void) ParseGeometry("12",&geometry_info); else (void) ParseGeometry(argv[i+1],&geometry_info); draw_info->pointsize=geometry_info.rho; break; } if (LocaleCompare("polaroid",option+1) == 0) { double angle; RandomInfo *random_info; /* Simulate a Polaroid picture. */ (void) SyncImageSettings(mogrify_info,*image); random_info=AcquireRandomInfo(); angle=22.5*(GetPseudoRandomValue(random_info)-0.5); random_info=DestroyRandomInfo(random_info); if (*option == '-') { SetGeometryInfo(&geometry_info); flags=ParseGeometry(argv[i+1],&geometry_info); angle=geometry_info.rho; } mogrify_image=PolaroidImage(*image,draw_info,angle,exception); break; } if (LocaleCompare("posterize",option+1) == 0) { /* Posterize image. */ (void) SyncImageSettings(mogrify_info,*image); (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]), quantize_info->dither); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("preview",option+1) == 0) { PreviewType preview_type; /* Preview image. */ (void) SyncImageSettings(mogrify_info,*image); if (*option == '+') preview_type=UndefinedPreview; else preview_type=(PreviewType) ParseCommandOption( MagickPreviewOptions,MagickFalse,argv[i+1]); mogrify_image=PreviewImage(*image,preview_type,exception); break; } if (LocaleCompare("profile",option+1) == 0) { const char *name; const StringInfo *profile; Image *profile_image; ImageInfo *profile_info; (void) SyncImageSettings(mogrify_info,*image); if (*option == '+') { /* Remove a profile from the image. */ (void) ProfileImage(*image,argv[i+1],(const unsigned char *) NULL,0,MagickTrue); InheritException(exception,&(*image)->exception); break; } /* Associate a profile with the image. */ profile_info=CloneImageInfo(mogrify_info); profile=GetImageProfile(*image,"iptc"); if (profile != (StringInfo *) NULL) profile_info->profile=(void *) CloneStringInfo(profile); profile_image=GetImageCache(profile_info,argv[i+1],exception); profile_info=DestroyImageInfo(profile_info); if (profile_image == (Image *) NULL) { StringInfo *profile; profile_info=CloneImageInfo(mogrify_info); (void) CopyMagickString(profile_info->filename,argv[i+1], MaxTextExtent); profile=FileToStringInfo(profile_info->filename,~0UL,exception); if (profile != (StringInfo *) NULL) { (void) SetImageInfo(profile_info,0,exception); (void) ProfileImage(*image,profile_info->magick, GetStringInfoDatum(profile),(size_t) GetStringInfoLength(profile),MagickFalse); profile=DestroyStringInfo(profile); } profile_info=DestroyImageInfo(profile_info); break; } ResetImageProfileIterator(profile_image); name=GetNextImageProfile(profile_image); while (name != (const char *) NULL) { profile=GetImageProfile(profile_image,name); if (profile != (StringInfo *) NULL) (void) ProfileImage(*image,name,GetStringInfoDatum(profile), (size_t) GetStringInfoLength(profile),MagickFalse); name=GetNextImageProfile(profile_image); } profile_image=DestroyImage(profile_image); break; } break; } case 'q': { if (LocaleCompare("quantize",option+1) == 0) { if (*option == '+') { quantize_info->colorspace=UndefinedColorspace; break; } quantize_info->colorspace=(ColorspaceType) ParseCommandOption( MagickColorspaceOptions,MagickFalse,argv[i+1]); break; } break; } case 'r': { if (LocaleCompare("radial-blur",option+1) == 0 || LocaleCompare("rotational-blur",option+1) == 0) { /* Radial blur image. */ (void) SyncImageSettings(mogrify_info,*image); mogrify_image=RotationalBlurImageChannel(*image,channel, StringToDouble(argv[i+1],(char **) NULL),exception); break; } if (LocaleCompare("raise",option+1) == 0) { /* Surround image with a raise of solid color. */ flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception); (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue : MagickFalse); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("random-threshold",option+1) == 0) { /* Threshold image. */ (void) SyncImageSettings(mogrify_info,*image); (void) RandomThresholdImageChannel(*image,channel,argv[i+1], exception); break; } if (LocaleCompare("recolor",option+1) == 0) { KernelInfo *kernel; (void) SyncImageSettings(mogrify_info,*image); kernel=AcquireKernelInfo(argv[i+1]); if (kernel == (KernelInfo *) NULL) break; mogrify_image=ColorMatrixImage(*image,kernel,exception); kernel=DestroyKernelInfo(kernel); break; } if (LocaleCompare("region",option+1) == 0) { (void) SyncImageSettings(mogrify_info,*image); if (region_image != (Image *) NULL) { /* Composite region. */ (void) CompositeImage(region_image,region_image->matte != MagickFalse ? CopyCompositeOp : OverCompositeOp,*image, region_geometry.x,region_geometry.y); InheritException(exception,&region_image->exception); *image=DestroyImage(*image); *image=region_image; region_image=(Image *) NULL; } if (*option == '+') break; /* Apply transformations to a selected region of the image. */ (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry, exception); mogrify_image=CropImage(*image,&region_geometry,exception); if (mogrify_image == (Image *) NULL) break; region_image=(*image); *image=mogrify_image; mogrify_image=(Image *) NULL; break; } if (LocaleCompare("render",option+1) == 0) { (void) SyncImageSettings(mogrify_info,*image); draw_info->render=(*option == '+') ? MagickTrue : MagickFalse; break; } if (LocaleCompare("remap",option+1) == 0) { Image *remap_image; /* Transform image colors to match this set of colors. */ (void) SyncImageSettings(mogrify_info,*image); if (*option == '+') break; remap_image=GetImageCache(mogrify_info,argv[i+1],exception); if (remap_image == (Image *) NULL) break; (void) RemapImage(quantize_info,*image,remap_image); InheritException(exception,&(*image)->exception); remap_image=DestroyImage(remap_image); break; } if (LocaleCompare("repage",option+1) == 0) { if (*option == '+') { (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page); break; } (void) ResetImagePage(*image,argv[i+1]); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("resample",option+1) == 0) { /* Resample image. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); if ((flags & SigmaValue) == 0) geometry_info.sigma=geometry_info.rho; mogrify_image=ResampleImage(*image,geometry_info.rho, geometry_info.sigma,(*image)->filter,(*image)->blur,exception); break; } if (LocaleCompare("resize",option+1) == 0) { /* Resize image. */ (void) SyncImageSettings(mogrify_info,*image); (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception); mogrify_image=ResizeImage(*image,geometry.width,geometry.height, (*image)->filter,(*image)->blur,exception); break; } if (LocaleCompare("roll",option+1) == 0) { /* Roll image. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception); if ((flags & PercentValue) != 0) { geometry.x*=(double) (*image)->columns/100.0; geometry.y*=(double) (*image)->rows/100.0; } mogrify_image=RollImage(*image,geometry.x,geometry.y,exception); break; } if (LocaleCompare("rotate",option+1) == 0) { char *geometry; /* Check for conditional image rotation. */ (void) SyncImageSettings(mogrify_info,*image); if (strchr(argv[i+1],'>') != (char *) NULL) if ((*image)->columns <= (*image)->rows) break; if (strchr(argv[i+1],'<') != (char *) NULL) if ((*image)->columns >= (*image)->rows) break; /* Rotate image. */ geometry=ConstantString(argv[i+1]); (void) SubstituteString(&geometry,">",""); (void) SubstituteString(&geometry,"<",""); (void) ParseGeometry(geometry,&geometry_info); geometry=DestroyString(geometry); mogrify_image=RotateImage(*image,geometry_info.rho,exception); break; } break; } case 's': { if (LocaleCompare("sample",option+1) == 0) { /* Sample image with pixel replication. */ (void) SyncImageSettings(mogrify_info,*image); (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception); mogrify_image=SampleImage(*image,geometry.width,geometry.height, exception); break; } if (LocaleCompare("scale",option+1) == 0) { /* Resize image. */ (void) SyncImageSettings(mogrify_info,*image); (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception); mogrify_image=ScaleImage(*image,geometry.width,geometry.height, exception); break; } if (LocaleCompare("selective-blur",option+1) == 0) { /* Selectively blur pixels within a contrast threshold. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); if ((flags & PercentValue) != 0) geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0; mogrify_image=SelectiveBlurImageChannel(*image,channel, geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception); break; } if (LocaleCompare("separate",option+1) == 0) { /* Break channels into separate images. WARNING: This can generate multiple images! */ (void) SyncImageSettings(mogrify_info,*image); mogrify_image=SeparateImages(*image,channel,exception); break; } if (LocaleCompare("sepia-tone",option+1) == 0) { double threshold; /* Sepia-tone image. */ (void) SyncImageSettings(mogrify_info,*image); threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+ 1.0); mogrify_image=SepiaToneImage(*image,threshold,exception); break; } if (LocaleCompare("segment",option+1) == 0) { /* Segment image. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); if ((flags & SigmaValue) == 0) geometry_info.sigma=1.0; (void) SegmentImage(*image,(*image)->colorspace, mogrify_info->verbose,geometry_info.rho,geometry_info.sigma); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("set",option+1) == 0) { char *value; /* Set image option. */ if (*option == '+') { if (LocaleNCompare(argv[i+1],"registry:",9) == 0) (void) DeleteImageRegistry(argv[i+1]+9); else if (LocaleNCompare(argv[i+1],"option:",7) == 0) { (void) DeleteImageOption(mogrify_info,argv[i+1]+7); (void) DeleteImageArtifact(*image,argv[i+1]+7); } else (void) DeleteImageProperty(*image,argv[i+1]); break; } value=InterpretImageProperties(mogrify_info,*image,argv[i+2]); InheritException(exception,&(*image)->exception); if (value == (char *) NULL) break; if (LocaleNCompare(argv[i+1],"registry:",9) == 0) (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value, exception); else if (LocaleNCompare(argv[i+1],"option:",7) == 0) { (void) SetImageOption(image_info,argv[i+1]+7,value); (void) SetImageOption(mogrify_info,argv[i+1]+7,value); (void) SetImageArtifact(*image,argv[i+1]+7,value); } else (void) SetImageProperty(*image,argv[i+1],value); value=DestroyString(value); break; } if (LocaleCompare("shade",option+1) == 0) { /* Shade image. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); if ((flags & SigmaValue) == 0) geometry_info.sigma=1.0; mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,exception); break; } if (LocaleCompare("shadow",option+1) == 0) { /* Shadow image. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); if ((flags & SigmaValue) == 0) geometry_info.sigma=1.0; if ((flags & XiValue) == 0) geometry_info.xi=4.0; if ((flags & PsiValue) == 0) geometry_info.psi=4.0; mogrify_image=ShadowImage(*image,geometry_info.rho, geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t) ceil(geometry_info.psi-0.5),exception); break; } if (LocaleCompare("sharpen",option+1) == 0) { /* Sharpen image. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); if ((flags & SigmaValue) == 0) geometry_info.sigma=1.0; mogrify_image=SharpenImageChannel(*image,channel,geometry_info.rho, geometry_info.sigma,exception); break; } if (LocaleCompare("shave",option+1) == 0) { /* Shave the image edges. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception); mogrify_image=ShaveImage(*image,&geometry,exception); break; } if (LocaleCompare("shear",option+1) == 0) { /* Shear image. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); if ((flags & SigmaValue) == 0) geometry_info.sigma=geometry_info.rho; mogrify_image=ShearImage(*image,geometry_info.rho, geometry_info.sigma,exception); break; } if (LocaleCompare("sigmoidal-contrast",option+1) == 0) { /* Sigmoidal non-linearity contrast control. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); if ((flags & SigmaValue) == 0) geometry_info.sigma=(double) QuantumRange/2.0; if ((flags & PercentValue) != 0) geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/ 100.0; (void) SigmoidalContrastImageChannel(*image,channel, (*option == '-') ? MagickTrue : MagickFalse,geometry_info.rho, geometry_info.sigma); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("sketch",option+1) == 0) { /* Sketch image. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); if ((flags & SigmaValue) == 0) geometry_info.sigma=1.0; mogrify_image=SketchImage(*image,geometry_info.rho, geometry_info.sigma,geometry_info.xi,exception); break; } if (LocaleCompare("solarize",option+1) == 0) { double threshold; (void) SyncImageSettings(mogrify_info,*image); threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+ 1.0); (void) SolarizeImageChannel(*image,channel,threshold,exception); break; } if (LocaleCompare("sparse-color",option+1) == 0) { SparseColorMethod method; char *arguments; /* Sparse Color Interpolated Gradient */ (void) SyncImageSettings(mogrify_info,*image); method=(SparseColorMethod) ParseCommandOption( MagickSparseColorOptions,MagickFalse,argv[i+1]); arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]); InheritException(exception,&(*image)->exception); if (arguments == (char *) NULL) break; mogrify_image=SparseColorOption(*image,channel,method,arguments, option[0] == '+' ? MagickTrue : MagickFalse,exception); arguments=DestroyString(arguments); break; } if (LocaleCompare("splice",option+1) == 0) { /* Splice a solid color into the image. */ (void) SyncImageSettings(mogrify_info,*image); (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception); mogrify_image=SpliceImage(*image,&geometry,exception); break; } if (LocaleCompare("spread",option+1) == 0) { /* Spread an image. */ (void) SyncImageSettings(mogrify_info,*image); (void) ParseGeometry(argv[i+1],&geometry_info); mogrify_image=SpreadImage(*image,geometry_info.rho,exception); break; } if (LocaleCompare("statistic",option+1) == 0) { StatisticType type; (void) SyncImageSettings(mogrify_info,*image); type=(StatisticType) ParseCommandOption(MagickStatisticOptions, MagickFalse,argv[i+1]); (void) ParseGeometry(argv[i+2],&geometry_info); mogrify_image=StatisticImageChannel(*image,channel,type,(size_t) geometry_info.rho,(size_t) geometry_info.sigma,exception); break; } if (LocaleCompare("stretch",option+1) == 0) { if (*option == '+') { draw_info->stretch=UndefinedStretch; break; } draw_info->stretch=(StretchType) ParseCommandOption( MagickStretchOptions,MagickFalse,argv[i+1]); break; } if (LocaleCompare("strip",option+1) == 0) { /* Strip image of profiles and comments. */ (void) SyncImageSettings(mogrify_info,*image); (void) StripImage(*image); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("stroke",option+1) == 0) { ExceptionInfo *sans; if (*option == '+') { (void) QueryColorDatabase("none",&draw_info->stroke,exception); if (draw_info->stroke_pattern != (Image *) NULL) draw_info->stroke_pattern=DestroyImage( draw_info->stroke_pattern); break; } sans=AcquireExceptionInfo(); status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans); sans=DestroyExceptionInfo(sans); if (status == MagickFalse) draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1], exception); break; } if (LocaleCompare("strokewidth",option+1) == 0) { draw_info->stroke_width=StringToDouble(argv[i+1],(char **) NULL); break; } if (LocaleCompare("style",option+1) == 0) { if (*option == '+') { draw_info->style=UndefinedStyle; break; } draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions, MagickFalse,argv[i+1]); break; } if (LocaleCompare("swirl",option+1) == 0) { /* Swirl image. */ (void) SyncImageSettings(mogrify_info,*image); (void) ParseGeometry(argv[i+1],&geometry_info); mogrify_image=SwirlImage(*image,geometry_info.rho,exception); break; } break; } case 't': { if (LocaleCompare("threshold",option+1) == 0) { double threshold; /* Threshold image. */ (void) SyncImageSettings(mogrify_info,*image); if (*option == '+') threshold=(double) QuantumRange/2; else threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+ 1.0); (void) BilevelImageChannel(*image,channel,threshold); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("thumbnail",option+1) == 0) { /* Thumbnail image. */ (void) SyncImageSettings(mogrify_info,*image); (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception); mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height, exception); break; } if (LocaleCompare("tile",option+1) == 0) { if (*option == '+') { if (draw_info->fill_pattern != (Image *) NULL) draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern); break; } draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1], exception); break; } if (LocaleCompare("tint",option+1) == 0) { /* Tint the image. */ (void) SyncImageSettings(mogrify_info,*image); mogrify_image=TintImage(*image,argv[i+1],draw_info->fill,exception); break; } if (LocaleCompare("transform",option+1) == 0) { /* Affine transform image. */ (void) SyncImageSettings(mogrify_info,*image); mogrify_image=AffineTransformImage(*image,&draw_info->affine, exception); break; } if (LocaleCompare("transparent",option+1) == 0) { MagickPixelPacket target; (void) SyncImageSettings(mogrify_info,*image); (void) QueryMagickColor(argv[i+1],&target,exception); (void) TransparentPaintImage(*image,&target,(Quantum) TransparentOpacity,*option == '-' ? MagickFalse : MagickTrue); InheritException(exception,&(*image)->exception); break; } if (LocaleCompare("transpose",option+1) == 0) { /* Transpose image scanlines. */ (void) SyncImageSettings(mogrify_info,*image); mogrify_image=TransposeImage(*image,exception); break; } if (LocaleCompare("transverse",option+1) == 0) { /* Transverse image scanlines. */ (void) SyncImageSettings(mogrify_info,*image); mogrify_image=TransverseImage(*image,exception); break; } if (LocaleCompare("treedepth",option+1) == 0) { quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]); break; } if (LocaleCompare("trim",option+1) == 0) { /* Trim image. */ (void) SyncImageSettings(mogrify_info,*image); mogrify_image=TrimImage(*image,exception); break; } if (LocaleCompare("type",option+1) == 0) { ImageType type; (void) SyncImageSettings(mogrify_info,*image); if (*option == '+') type=UndefinedType; else type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse, argv[i+1]); (*image)->type=UndefinedType; (void) SetImageType(*image,type); InheritException(exception,&(*image)->exception); break; } break; } case 'u': { if (LocaleCompare("undercolor",option+1) == 0) { (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor, exception); break; } if (LocaleCompare("unique",option+1) == 0) { if (*option == '+') { (void) DeleteImageArtifact(*image,"identify:unique-colors"); break; } (void) SetImageArtifact(*image,"identify:unique-colors","true"); (void) SetImageArtifact(*image,"verbose","true"); break; } if (LocaleCompare("unique-colors",option+1) == 0) { /* Unique image colors. */ (void) SyncImageSettings(mogrify_info,*image); mogrify_image=UniqueImageColors(*image,exception); break; } if (LocaleCompare("unsharp",option+1) == 0) { /* Unsharp mask image. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); if ((flags & SigmaValue) == 0) geometry_info.sigma=1.0; if ((flags & XiValue) == 0) geometry_info.xi=1.0; if ((flags & PsiValue) == 0) geometry_info.psi=0.05; mogrify_image=UnsharpMaskImageChannel(*image,channel, geometry_info.rho,geometry_info.sigma,geometry_info.xi, geometry_info.psi,exception); break; } break; } case 'v': { if (LocaleCompare("verbose",option+1) == 0) { (void) SetImageArtifact(*image,option+1, *option == '+' ? "false" : "true"); break; } if (LocaleCompare("vignette",option+1) == 0) { /* Vignette image. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); if ((flags & SigmaValue) == 0) geometry_info.sigma=1.0; if ((flags & XiValue) == 0) geometry_info.xi=0.1*(*image)->columns; if ((flags & PsiValue) == 0) geometry_info.psi=0.1*(*image)->rows; if ((flags & PercentValue) != 0) { geometry_info.xi*=(double) (*image)->columns/100.0; geometry_info.psi*=(double) (*image)->rows/100.0; } mogrify_image=VignetteImage(*image,geometry_info.rho, geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t) ceil(geometry_info.psi-0.5),exception); break; } if (LocaleCompare("virtual-pixel",option+1) == 0) { if (*option == '+') { (void) SetImageVirtualPixelMethod(*image, UndefinedVirtualPixelMethod); break; } (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod) ParseCommandOption(MagickVirtualPixelOptions,MagickFalse, argv[i+1])); break; } break; } case 'w': { if (LocaleCompare("wave",option+1) == 0) { /* Wave image. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); if ((flags & SigmaValue) == 0) geometry_info.sigma=1.0; mogrify_image=WaveImage(*image,geometry_info.rho, geometry_info.sigma,exception); break; } if (LocaleCompare("wavelet-denoise",option+1) == 0) { /* Wavelet denoise image. */ (void) SyncImageSettings(mogrify_info,*image); flags=ParseGeometry(argv[i+1],&geometry_info); if ((flags & PercentValue) != 0) { geometry_info.rho=QuantumRange*geometry_info.rho/100.0; geometry_info.sigma=QuantumRange*geometry_info.sigma/100.0; } if ((flags & SigmaValue) == 0) geometry_info.sigma=0.0; mogrify_image=WaveletDenoiseImage(*image,geometry_info.rho, geometry_info.sigma,exception); break; } if (LocaleCompare("weight",option+1) == 0) { ssize_t weight; weight=ParseCommandOption(MagickWeightOptions,MagickFalse, argv[i+1]); if (weight == -1) weight=StringToUnsignedLong(argv[i+1]); draw_info->weight=(size_t) weight; break; } if (LocaleCompare("white-threshold",option+1) == 0) { /* White threshold image. */ (void) SyncImageSettings(mogrify_info,*image); (void) WhiteThresholdImageChannel(*image,channel,argv[i+1], exception); InheritException(exception,&(*image)->exception); break; } break; } default: break; } /* Replace current image with any image that was generated. */ if (mogrify_image != (Image *) NULL) ReplaceImageInListReturnLast(image,mogrify_image); i+=count; } if (region_image != (Image *) NULL) { /* Composite transformed region onto image. */ (void) SyncImageSettings(mogrify_info,*image); (void) CompositeImage(region_image,region_image->matte != MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,region_geometry.x, region_geometry.y); InheritException(exception,&region_image->exception); *image=DestroyImage(*image); *image=region_image; region_image = (Image *) NULL; } /* Free resources. */ quantize_info=DestroyQuantizeInfo(quantize_info); draw_info=DestroyDrawInfo(draw_info); mogrify_info=DestroyImageInfo(mogrify_info); status=(MagickStatusType) (exception->severity < ErrorException ? 1 : 0); return(status == 0 ? MagickFalse : MagickTrue); } Commit Message: https://github.com/ImageMagick/ImageMagick/issues/1623 CWE ID: CWE-399
0
88,897
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: wait_for_gdb() { if (!waitforgdb) { return; } std::cout << std::endl << " Attach GDB to PID " << getpid() << " to debug!" << std::endl << " This thread will block until then!" << std::endl << " Once blocked here, you can set other breakpoints." << std::endl << " Do a \"set variable waitforgdb=$false\" to continue" << std::endl << std::endl; while (waitforgdb) { sleep(1); } } Commit Message: CWE ID: CWE-264
0
13,233
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: ATSParser::PSISection::~PSISection() { } Commit Message: Check section size when verifying CRC Bug: 28333006 Change-Id: Ief7a2da848face78f0edde21e2f2009316076679 CWE ID: CWE-119
0
160,522
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: isoent_cmp_key(const struct archive_rb_node *n, const void *key) { const struct isoent *e = (const struct isoent *)n; return (strcmp(e->file->basename.s, (const char *)key)); } Commit Message: Issue 711: Be more careful about verifying filename lengths when writing ISO9660 archives * Don't cast size_t to int, since this can lead to overflow on machines where sizeof(int) < sizeof(size_t) * Check a + b > limit by writing it as a > limit || b > limit || a + b > limit to avoid problems when a + b wraps around. CWE ID: CWE-190
0
50,823
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static RELOC_PTRS_WITH(pdf14_device_reloc_ptrs, pdf14_device *pdev) { { int i; for (i = 0; i < pdev->devn_params.separations.num_separations; ++i) { RELOC_PTR(pdf14_device, devn_params.separations.names[i].data); } } RELOC_VAR(pdev->ctx); RELOC_VAR(pdev->smaskcolor); RELOC_VAR(pdev->trans_group_parent_cmap_procs); pdev->target = gx_device_reloc_ptr(pdev->target, gcst); pdev->pclist_device = gx_device_reloc_ptr(pdev->pclist_device, gcst); } Commit Message: CWE ID: CWE-416
0
2,926
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static inline NPUTF8 *npidentifier_cache_get_string_copy(NPIdentifier ident) { NPIdentifierInfo *npi = npidentifier_cache_lookup(ident); if (G_UNLIKELY(npi == NULL || npi->string_len == 0)) return NULL; return NPW_MemAllocCopy(npi->string_len, npi->u.string); } Commit Message: Support all the new variables added CWE ID: CWE-264
0
27,157
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: void Field_CompletePlayerName( const char **names, int nameCount ) { qboolean whitespace; matchCount = 0; shortestMatch[ 0 ] = 0; if( nameCount <= 0 ) return; Name_PlayerNameCompletion( names, nameCount, FindMatches ); if( completionString[0] == '\0' ) { Com_PlayerNameToFieldString( shortestMatch, sizeof( shortestMatch ), names[ 0 ] ); } if( completionString[0] != '\0' && Q_stricmp( shortestMatch, completionString ) == 0 && nameCount > 1 ) { int i; for( i = 0; i < nameCount; i++ ) { if( Q_stricmp( names[ i ], completionString ) == 0 ) { i++; if( i >= nameCount ) { i = 0; } Com_PlayerNameToFieldString( shortestMatch, sizeof( shortestMatch ), names[ i ] ); break; } } } if( matchCount > 1 ) { Com_Printf( "]%s\n", completionField->buffer ); Name_PlayerNameCompletion( names, nameCount, PrintMatches ); } whitespace = nameCount == 1? qtrue: qfalse; if( !Field_CompletePlayerNameFinal( whitespace ) ) { } } Commit Message: Merge some file writing extension checks from OpenJK. Thanks Ensiform. https://github.com/JACoders/OpenJK/commit/05928a57f9e4aae15a3bd0 https://github.com/JACoders/OpenJK/commit/ef124fd0fc48af164581176 CWE ID: CWE-269
0
95,501
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: void ChromeContentBrowserClient::RenderProcessWillLaunch( content::RenderProcessHost* host, service_manager::mojom::ServiceRequest* service_request) { int id = host->GetID(); Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); host->AddFilter(new ChromeRenderMessageFilter(id, profile)); #if BUILDFLAG(ENABLE_EXTENSIONS) host->AddFilter(new cast::CastTransportHostFilter()); #endif #if BUILDFLAG(ENABLE_PRINTING) host->AddFilter(new printing::PrintingMessageFilter(id, profile)); #endif host->AddFilter(new prerender::PrerenderMessageFilter(id, profile)); host->AddFilter(new TtsMessageFilter(host->GetBrowserContext())); WebRtcLoggingHandlerHost* webrtc_logging_handler_host = new WebRtcLoggingHandlerHost(id, profile, g_browser_process->webrtc_log_uploader()); host->AddFilter(webrtc_logging_handler_host); host->SetUserData( WebRtcLoggingHandlerHost::kWebRtcLoggingHandlerHostKey, std::make_unique<base::UserDataAdapter<WebRtcLoggingHandlerHost>>( webrtc_logging_handler_host)); AudioDebugRecordingsHandler* audio_debug_recordings_handler = new AudioDebugRecordingsHandler(profile); host->SetUserData( AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey, std::make_unique<base::UserDataAdapter<AudioDebugRecordingsHandler>>( audio_debug_recordings_handler)); #if BUILDFLAG(ENABLE_NACL) host->AddFilter(new nacl::NaClHostMessageFilter(id, profile->IsOffTheRecord(), profile->GetPath())); #endif #if defined(OS_ANDROID) host->AddFilter( new cdm::CdmMessageFilterAndroid(!profile->IsOffTheRecord(), false)); host->SetUserData( CrashMemoryMetricsCollector::kCrashMemoryMetricsCollectorKey, std::make_unique<CrashMemoryMetricsCollector>(host)); #endif Profile* original_profile = profile->GetOriginalProfile(); RendererUpdaterFactory::GetForProfile(original_profile) ->InitializeRenderer(host); for (size_t i = 0; i < extra_parts_.size(); ++i) extra_parts_[i]->RenderProcessWillLaunch(host); service_manager::mojom::ServicePtr service; *service_request = mojo::MakeRequest(&service); service_manager::mojom::PIDReceiverPtr pid_receiver; service_manager::Identity renderer_identity = host->GetChildIdentity(); ChromeService::GetInstance()->connector()->RegisterServiceInstance( service_manager::Identity(chrome::mojom::kRendererServiceName, renderer_identity.instance_group(), renderer_identity.instance_id(), base::Token::CreateRandom()), std::move(service), mojo::MakeRequest(&pid_receiver)); } Commit Message: Move IsDataSaverEnabledByUser to be a static method and use it This method now officially becomes the source of truth that everything in the code base eventually calls into to determine whether or not DataSaver is enabled. Bug: 934399 Change-Id: Iae837b710ace8cc3101188f79d02cbc2d4f0fd93 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1537242 Reviewed-by: Joshua Pawlicki <waffles@chromium.org> Reviewed-by: Tarun Bansal <tbansal@chromium.org> Commit-Queue: Robert Ogden <robertogden@chromium.org> Cr-Commit-Position: refs/heads/master@{#643948} CWE ID: CWE-119
0
142,743
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: SSL_SESSION *SSL_SESSION_new(void) { SSL_SESSION *ss; ss = OPENSSL_malloc(sizeof(*ss)); if (ss == NULL) { SSLerr(SSL_F_SSL_SESSION_NEW, ERR_R_MALLOC_FAILURE); return (0); } memset(ss, 0, sizeof(*ss)); ss->verify_result = 1; /* avoid 0 (= X509_V_OK) just in case */ ss->references = 1; ss->timeout = 60 * 5 + 4; /* 5 minute timeout by default */ ss->time = (unsigned long)time(NULL); ss->prev = NULL; ss->next = NULL; ss->compress_meth = 0; ss->tlsext_hostname = NULL; #ifndef OPENSSL_NO_EC ss->tlsext_ecpointformatlist_length = 0; ss->tlsext_ecpointformatlist = NULL; ss->tlsext_ellipticcurvelist_length = 0; ss->tlsext_ellipticcurvelist = NULL; #endif CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data); #ifndef OPENSSL_NO_PSK ss->psk_identity_hint = NULL; ss->psk_identity = NULL; #endif #ifndef OPENSSL_NO_SRP ss->srp_username = NULL; #endif return (ss); } Commit Message: Fix race condition in NewSessionTicket If a NewSessionTicket is received by a multi-threaded client when attempting to reuse a previous ticket then a race condition can occur potentially leading to a double free of the ticket data. CVE-2015-1791 This also fixes RT#3808 where a session ID is changed for a session already in the client session cache. Since the session ID is the key to the cache this breaks the cache access. Parts of this patch were inspired by this Akamai change: https://github.com/akamai/openssl/commit/c0bf69a791239ceec64509f9f19fcafb2461b0d3 Reviewed-by: Rich Salz <rsalz@openssl.org> CWE ID: CWE-362
0
44,213
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: COMPAT_SYSCALL_DEFINE3(sigprocmask, int, how, compat_old_sigset_t __user *, nset, compat_old_sigset_t __user *, oset) { old_sigset_t old_set, new_set; sigset_t new_blocked; old_set = current->blocked.sig[0]; if (nset) { if (get_user(new_set, nset)) return -EFAULT; new_set &= ~(sigmask(SIGKILL) | sigmask(SIGSTOP)); new_blocked = current->blocked; switch (how) { case SIG_BLOCK: sigaddsetmask(&new_blocked, new_set); break; case SIG_UNBLOCK: sigdelsetmask(&new_blocked, new_set); break; case SIG_SETMASK: compat_sig_setmask(&new_blocked, new_set); break; default: return -EINVAL; } set_current_blocked(&new_blocked); } if (oset) { if (put_user(old_set, oset)) return -EFAULT; } return 0; } Commit Message: compat: fix 4-byte infoleak via uninitialized struct field Commit 3a4d44b61625 ("ntp: Move adjtimex related compat syscalls to native counterparts") removed the memset() in compat_get_timex(). Since then, the compat adjtimex syscall can invoke do_adjtimex() with an uninitialized ->tai. If do_adjtimex() doesn't write to ->tai (e.g. because the arguments are invalid), compat_put_timex() then copies the uninitialized ->tai field to userspace. Fix it by adding the memset() back. Fixes: 3a4d44b61625 ("ntp: Move adjtimex related compat syscalls to native counterparts") Signed-off-by: Jann Horn <jannh@google.com> Acked-by: Kees Cook <keescook@chromium.org> Acked-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> CWE ID: CWE-200
0
82,626
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: void NavigationControllerImpl::FindFramesToNavigate( FrameTreeNode* frame, FrameLoadVector* same_document_loads, FrameLoadVector* different_document_loads) { DCHECK(pending_entry_); DCHECK_GE(last_committed_entry_index_, 0); FrameNavigationEntry* new_item = pending_entry_->GetFrameEntry(frame); FrameNavigationEntry* old_item = GetLastCommittedEntry()->GetFrameEntry(frame); if (!new_item) return; if (!old_item || new_item->item_sequence_number() != old_item->item_sequence_number() || (new_item->site_instance() != nullptr && new_item->site_instance() != old_item->site_instance())) { if (old_item && new_item->document_sequence_number() == old_item->document_sequence_number() && !frame->current_frame_host()->GetLastCommittedURL().is_empty()) { same_document_loads->push_back(std::make_pair(frame, new_item)); return; } else { different_document_loads->push_back(std::make_pair(frame, new_item)); return; } } for (size_t i = 0; i < frame->child_count(); i++) { FindFramesToNavigate(frame->child_at(i), same_document_loads, different_document_loads); } } Commit Message: Preserve renderer-initiated bit when reloading in a new process. BUG=847718 TEST=See bug for repro steps. Change-Id: I6c3461793fbb23f1a4d731dc27b4e77312f29227 Reviewed-on: https://chromium-review.googlesource.com/1080235 Commit-Queue: Charlie Reis <creis@chromium.org> Reviewed-by: Nasko Oskov <nasko@chromium.org> Cr-Commit-Position: refs/heads/master@{#563312} CWE ID:
0
153,978
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: void ClearedCookiesOnIO(std::unique_ptr<ClearBrowserCookiesCallback> callback, uint32_t num_deleted) { DCHECK_CURRENTLY_ON(BrowserThread::IO); BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, base::BindOnce(&ClearBrowserCookiesCallback::sendSuccess, std::move(callback))); } Commit Message: DevTools: speculative fix for crash in NetworkHandler::Disable This keeps BrowserContext* and StoragePartition* instead of RenderProcessHost* in an attemp to resolve UAF of RenderProcessHost upon closure of DevTools front-end. Bug: 801117, 783067, 780694 Change-Id: I6c2cca60cc0c29f0949d189cf918769059f80c1b Reviewed-on: https://chromium-review.googlesource.com/876657 Commit-Queue: Andrey Kosyakov <caseq@chromium.org> Reviewed-by: Dmitry Gozman <dgozman@chromium.org> Cr-Commit-Position: refs/heads/master@{#531157} CWE ID: CWE-20
0
148,502
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: int static spl_array_object_count_elements_helper(spl_array_object *intern, long *count TSRMLS_DC) /* {{{ */ { HashTable *aht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); HashPosition pos; if (!aht) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and is no longer an array"); *count = 0; return FAILURE; } if (Z_TYPE_P(intern->array) == IS_OBJECT) { /* We need to store the 'pos' since we'll modify it in the functions * we're going to call and which do not support 'pos' as parameter. */ pos = intern->pos; *count = 0; spl_array_rewind(intern TSRMLS_CC); while(intern->pos && spl_array_next(intern TSRMLS_CC) == SUCCESS) { (*count)++; } spl_array_set_pos(intern, pos); return SUCCESS; } else { *count = zend_hash_num_elements(aht); return SUCCESS; } } /* }}} */ Commit Message: CWE ID:
0
12,375
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static int req_status_field(request_rec *r) { return r->status; } Commit Message: *) SECURITY: CVE-2015-0228 (cve.mitre.org) mod_lua: A maliciously crafted websockets PING after a script calls r:wsupgrade() can cause a child process crash. [Edward Lu <Chaosed0 gmail.com>] Discovered by Guido Vranken <guidovranken gmail.com> Submitted by: Edward Lu Committed by: covener git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1657261 13f79535-47bb-0310-9956-ffa450edef68 CWE ID: CWE-20
0
45,154
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static inline void add_tg_cfs_propagate(struct cfs_rq *cfs_rq, long runnable_sum) { cfs_rq->propagate = 1; cfs_rq->prop_runnable_sum += runnable_sum; } Commit Message: sched/fair: Fix infinite loop in update_blocked_averages() by reverting a9e7f6544b9c Zhipeng Xie, Xie XiuQi and Sargun Dhillon reported lockups in the scheduler under high loads, starting at around the v4.18 time frame, and Zhipeng Xie tracked it down to bugs in the rq->leaf_cfs_rq_list manipulation. Do a (manual) revert of: a9e7f6544b9c ("sched/fair: Fix O(nr_cgroups) in load balance path") It turns out that the list_del_leaf_cfs_rq() introduced by this commit is a surprising property that was not considered in followup commits such as: 9c2791f936ef ("sched/fair: Fix hierarchical order in rq->leaf_cfs_rq_list") As Vincent Guittot explains: "I think that there is a bigger problem with commit a9e7f6544b9c and cfs_rq throttling: Let take the example of the following topology TG2 --> TG1 --> root: 1) The 1st time a task is enqueued, we will add TG2 cfs_rq then TG1 cfs_rq to leaf_cfs_rq_list and we are sure to do the whole branch in one path because it has never been used and can't be throttled so tmp_alone_branch will point to leaf_cfs_rq_list at the end. 2) Then TG1 is throttled 3) and we add TG3 as a new child of TG1. 4) The 1st enqueue of a task on TG3 will add TG3 cfs_rq just before TG1 cfs_rq and tmp_alone_branch will stay on rq->leaf_cfs_rq_list. With commit a9e7f6544b9c, we can del a cfs_rq from rq->leaf_cfs_rq_list. So if the load of TG1 cfs_rq becomes NULL before step 2) above, TG1 cfs_rq is removed from the list. Then at step 4), TG3 cfs_rq is added at the beginning of rq->leaf_cfs_rq_list but tmp_alone_branch still points to TG3 cfs_rq because its throttled parent can't be enqueued when the lock is released. tmp_alone_branch doesn't point to rq->leaf_cfs_rq_list whereas it should. So if TG3 cfs_rq is removed or destroyed before tmp_alone_branch points on another TG cfs_rq, the next TG cfs_rq that will be added, will be linked outside rq->leaf_cfs_rq_list - which is bad. In addition, we can break the ordering of the cfs_rq in rq->leaf_cfs_rq_list but this ordering is used to update and propagate the update from leaf down to root." Instead of trying to work through all these cases and trying to reproduce the very high loads that produced the lockup to begin with, simplify the code temporarily by reverting a9e7f6544b9c - which change was clearly not thought through completely. This (hopefully) gives us a kernel that doesn't lock up so people can continue to enjoy their holidays without worrying about regressions. ;-) [ mingo: Wrote changelog, fixed weird spelling in code comment while at it. ] Analyzed-by: Xie XiuQi <xiexiuqi@huawei.com> Analyzed-by: Vincent Guittot <vincent.guittot@linaro.org> Reported-by: Zhipeng Xie <xiezhipeng1@huawei.com> Reported-by: Sargun Dhillon <sargun@sargun.me> Reported-by: Xie XiuQi <xiexiuqi@huawei.com> Tested-by: Zhipeng Xie <xiezhipeng1@huawei.com> Tested-by: Sargun Dhillon <sargun@sargun.me> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Acked-by: Vincent Guittot <vincent.guittot@linaro.org> Cc: <stable@vger.kernel.org> # v4.13+ Cc: Bin Li <huawei.libin@huawei.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Tejun Heo <tj@kernel.org> Cc: Thomas Gleixner <tglx@linutronix.de> Fixes: a9e7f6544b9c ("sched/fair: Fix O(nr_cgroups) in load balance path") Link: http://lkml.kernel.org/r/1545879866-27809-1-git-send-email-xiexiuqi@huawei.com Signed-off-by: Ingo Molnar <mingo@kernel.org> CWE ID: CWE-400
0
92,459
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: void PersistentHistogramAllocator::UpdateTrackingHistograms() { memory_allocator_->UpdateTrackingHistograms(); } Commit Message: Remove UMA.CreatePersistentHistogram.Result This histogram isn't showing anything meaningful and the problems it could show are better observed by looking at the allocators directly. Bug: 831013 Change-Id: Ibe968597758230192e53a7675e7390e968c9e5b9 Reviewed-on: https://chromium-review.googlesource.com/1008047 Commit-Queue: Brian White <bcwhite@chromium.org> Reviewed-by: Alexei Svitkine <asvitkine@chromium.org> Cr-Commit-Position: refs/heads/master@{#549986} CWE ID: CWE-264
0
131,135
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static void ReflectedNameAttributeGetter(const v8::FunctionCallbackInfo<v8::Value>& info) { v8::Local<v8::Object> holder = info.Holder(); TestObject* impl = V8TestObject::ToImpl(holder); V8SetReturnValueString(info, impl->GetNameAttribute(), info.GetIsolate()); } Commit Message: bindings: Support "attribute FrozenArray<T>?" Adds a quick hack to support a case of "attribute FrozenArray<T>?". Bug: 1028047 Change-Id: Ib3cecc4beb6bcc0fb0dbc667aca595454cc90c86 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1933866 Reviewed-by: Hitoshi Yoshida <peria@chromium.org> Commit-Queue: Yuki Shiino <yukishiino@chromium.org> Cr-Commit-Position: refs/heads/master@{#718676} CWE ID:
0
135,109
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static void crypto_ctr_exit_tfm(struct crypto_tfm *tfm) { struct crypto_ctr_ctx *ctx = crypto_tfm_ctx(tfm); crypto_free_cipher(ctx->child); } Commit Message: crypto: include crypto- module prefix in template This adds the module loading prefix "crypto-" to the template lookup as well. For example, attempting to load 'vfat(blowfish)' via AF_ALG now correctly includes the "crypto-" prefix at every level, correctly rejecting "vfat": net-pf-38 algif-hash crypto-vfat(blowfish) crypto-vfat(blowfish)-all crypto-vfat Reported-by: Mathias Krause <minipli@googlemail.com> Signed-off-by: Kees Cook <keescook@chromium.org> Acked-by: Mathias Krause <minipli@googlemail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> CWE ID: CWE-264
0
45,684
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: void OutOfProcessInstance::OnPrint(int32_t) { pp::PDF::Print(this); } Commit Message: Prevent leaking PDF data cross-origin BUG=520422 Review URL: https://codereview.chromium.org/1311973002 Cr-Commit-Position: refs/heads/master@{#345267} CWE ID: CWE-20
0
129,452
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: void Camera3Device::notifyError(const camera3_error_msg_t &msg, NotificationListener *listener) { static const ICameraDeviceCallbacks::CameraErrorCode halErrorMap[CAMERA3_MSG_NUM_ERRORS] = { ICameraDeviceCallbacks::ERROR_CAMERA_INVALID_ERROR, ICameraDeviceCallbacks::ERROR_CAMERA_DEVICE, ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST, ICameraDeviceCallbacks::ERROR_CAMERA_RESULT, ICameraDeviceCallbacks::ERROR_CAMERA_BUFFER }; ICameraDeviceCallbacks::CameraErrorCode errorCode = ((msg.error_code >= 0) && (msg.error_code < CAMERA3_MSG_NUM_ERRORS)) ? halErrorMap[msg.error_code] : ICameraDeviceCallbacks::ERROR_CAMERA_INVALID_ERROR; int streamId = 0; if (msg.error_stream != NULL) { Camera3Stream *stream = Camera3Stream::cast(msg.error_stream); streamId = stream->getId(); } ALOGV("Camera %d: %s: HAL error, frame %d, stream %d: %d", mId, __FUNCTION__, msg.frame_number, streamId, msg.error_code); CaptureResultExtras resultExtras; switch (errorCode) { case ICameraDeviceCallbacks::ERROR_CAMERA_DEVICE: SET_ERR("Camera HAL reported serious device error"); break; case ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST: case ICameraDeviceCallbacks::ERROR_CAMERA_RESULT: case ICameraDeviceCallbacks::ERROR_CAMERA_BUFFER: { Mutex::Autolock l(mInFlightLock); ssize_t idx = mInFlightMap.indexOfKey(msg.frame_number); if (idx >= 0) { InFlightRequest &r = mInFlightMap.editValueAt(idx); r.requestStatus = msg.error_code; resultExtras = r.resultExtras; } else { resultExtras.frameNumber = msg.frame_number; ALOGE("Camera %d: %s: cannot find in-flight request on " "frame %" PRId64 " error", mId, __FUNCTION__, resultExtras.frameNumber); } } if (listener != NULL) { listener->notifyError(errorCode, resultExtras); } else { ALOGE("Camera %d: %s: no listener available", mId, __FUNCTION__); } break; default: SET_ERR("Unknown error message from HAL: %d", msg.error_code); break; } } Commit Message: Camera3Device: Validate template ID Validate template ID before creating a default request. Bug: 26866110 Bug: 27568958 Change-Id: Ifda457024f1d5c2b1382f189c1a8d5fda852d30d CWE ID: CWE-264
0
161,070
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: int UDPSocketLibevent::Read(IOBuffer* buf, int buf_len, const CompletionCallback& callback) { return RecvFrom(buf, buf_len, NULL, callback); } Commit Message: Map posix error codes in bind better, and fix one windows mapping. r=wtc BUG=330233 Review URL: https://codereview.chromium.org/101193008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@242224 0039d316-1c4b-4281-b951-d872f2087c98 CWE ID: CWE-416
0
113,417
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: V8Debugger::PauseOnExceptionsState V8Debugger::getPauseOnExceptionsState() { DCHECK(enabled()); v8::HandleScope scope(m_isolate); v8::Context::Scope contextScope(debuggerContext()); v8::Local<v8::Value> argv[] = { v8::Undefined(m_isolate) }; v8::Local<v8::Value> result = callDebuggerMethod("pauseOnExceptionsState", 0, argv).ToLocalChecked(); return static_cast<V8Debugger::PauseOnExceptionsState>(result->Int32Value()); } Commit Message: [DevTools] Copy objects from debugger context to inspected context properly. BUG=637594 Review-Url: https://codereview.chromium.org/2253643002 Cr-Commit-Position: refs/heads/master@{#412436} CWE ID: CWE-79
0
130,374
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: make_optional_header_string(char *s) { char *p; Str hs; if (strchr(s, '\n') || strchr(s, '\r')) return NULL; for (p = s; *p && *p != ':'; p++) ; if (*p != ':' || p == s) return NULL; hs = Strnew_size(strlen(s) + 3); Strcopy_charp_n(hs, s, p - s); if (!Strcasecmp_charp(hs, "content-type")) override_content_type = TRUE; Strcat_charp(hs, ": "); if (*(++p)) { /* not null header */ SKIP_BLANKS(p); /* skip white spaces */ Strcat_charp(hs, p); } Strcat_charp(hs, "\r\n"); return hs; } Commit Message: Make temporary directory safely when ~/.w3m is unwritable CWE ID: CWE-59
0
84,516
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static void floatArrayAttributeAttributeGetter(const v8::PropertyCallbackInfo<v8::Value>& info) { TestObjectPython* imp = V8TestObjectPython::toNative(info.Holder()); v8SetReturnValue(info, v8Array(imp->floatArrayAttribute(), info.GetIsolate())); } Commit Message: document.location bindings fix BUG=352374 R=jochen@chromium.org Review URL: https://codereview.chromium.org/196343011 git-svn-id: svn://svn.chromium.org/blink/trunk@169176 bbb929c8-8fbe-4397-9dbb-9b2b20218538 CWE ID: CWE-399
0
122,313
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static void cmd_setacl(char *tag, const char *name, const char *identifier, const char *rights) { int r; mbentry_t *mbentry = NULL; char *intname = mboxname_from_external(name, &imapd_namespace, imapd_userid); /* is it remote? */ r = mlookup(tag, name, intname, &mbentry); if (r == IMAP_MAILBOX_MOVED) return; if (!r && (mbentry->mbtype & MBTYPE_REMOTE)) { /* remote mailbox */ struct backend *s = NULL; int res; s = proxy_findserver(mbentry->server, &imap_protocol, proxy_userid, &backend_cached, &backend_current, &backend_inbox, imapd_in); if (!s) r = IMAP_SERVER_UNAVAILABLE; if (!r && imapd_userisadmin && supports_referrals) { /* They aren't an admin remotely, so let's refer them */ imapd_refer(tag, mbentry->server, name); referral_kick = 1; mboxlist_entry_free(&mbentry); return; } mboxlist_entry_free(&mbentry); if (!r) { if (rights) { prot_printf(s->out, "%s Setacl {" SIZE_T_FMT "+}\r\n%s" " {" SIZE_T_FMT "+}\r\n%s {" SIZE_T_FMT "+}\r\n%s\r\n", tag, strlen(name), name, strlen(identifier), identifier, strlen(rights), rights); } else { prot_printf(s->out, "%s Deleteacl {" SIZE_T_FMT "+}\r\n%s" " {" SIZE_T_FMT "+}\r\n%s\r\n", tag, strlen(name), name, strlen(identifier), identifier); } res = pipe_until_tag(s, tag, 0); if (!CAPA(s, CAPA_MUPDATE) && res == PROXY_OK) { /* setup new ACL in MUPDATE */ } /* make sure we've seen the update */ if (ultraparanoid && res == PROXY_OK) kick_mupdate(); } imapd_check(s, 0); if (r) { prot_printf(imapd_out, "%s NO %s\r\n", tag, error_message(r)); } else { /* we're allowed to reference last_result since the noop, if sent, went to a different server */ prot_printf(imapd_out, "%s %s", tag, s->last_result.s); } free(intname); return; } mboxlist_entry_free(&mbentry); /* local mailbox */ if (!r) { char *err; /* send BAD response if rights string contains unrecognised chars */ if (rights && *rights) { r = cyrus_acl_checkstr(rights, &err); if (r) { prot_printf(imapd_out, "%s BAD %s\r\n", tag, err); free(err); free(intname); return; } } r = mboxlist_setacl(&imapd_namespace, intname, identifier, rights, imapd_userisadmin || imapd_userisproxyadmin, proxy_userid, imapd_authstate); } imapd_check(NULL, 0); if (r) { prot_printf(imapd_out, "%s NO %s\r\n", tag, error_message(r)); } else { if (config_mupdate_server) kick_mupdate(); prot_printf(imapd_out, "%s OK %s\r\n", tag, error_message(IMAP_OK_COMPLETED)); } free(intname); } Commit Message: imapd: check for isadmin BEFORE parsing sync lines CWE ID: CWE-20
0
95,163
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: ::Cursor GetCursor(int cursor_shape) { std::pair<std::map<int, ::Cursor>::iterator, bool> it = cache_.insert( std::make_pair(cursor_shape, 0)); if (it.second) { Display* display = base::MessagePumpForUI::GetDefaultXDisplay(); it.first->second = XCreateFontCursor(display, cursor_shape); } return it.first->second; } Commit Message: Make shared memory segments writable only by their rightful owners. BUG=143859 TEST=Chrome's UI still works on Linux and Chrome OS Review URL: https://chromiumcodereview.appspot.com/10854242 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@158289 0039d316-1c4b-4281-b951-d872f2087c98 CWE ID: CWE-264
0
119,163
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: user_cert_trusted_ca(struct ssh *ssh, struct passwd *pw, struct sshkey *key, struct sshauthopt **authoptsp) { char *ca_fp, *principals_file = NULL; const char *reason; struct sshauthopt *principals_opts = NULL, *cert_opts = NULL; struct sshauthopt *final_opts = NULL; int r, ret = 0, found_principal = 0, use_authorized_principals; if (authoptsp != NULL) *authoptsp = NULL; if (!sshkey_is_cert(key) || options.trusted_user_ca_keys == NULL) return 0; if ((ca_fp = sshkey_fingerprint(key->cert->signature_key, options.fingerprint_hash, SSH_FP_DEFAULT)) == NULL) return 0; if ((r = sshkey_in_file(key->cert->signature_key, options.trusted_user_ca_keys, 1, 0)) != 0) { debug2("%s: CA %s %s is not listed in %s: %s", __func__, sshkey_type(key->cert->signature_key), ca_fp, options.trusted_user_ca_keys, ssh_err(r)); goto out; } /* * If AuthorizedPrincipals is in use, then compare the certificate * principals against the names in that file rather than matching * against the username. */ if ((principals_file = authorized_principals_file(pw)) != NULL) { if (match_principals_file(ssh, pw, principals_file, key->cert, &principals_opts)) found_principal = 1; } /* Try querying command if specified */ if (!found_principal && match_principals_command(ssh, pw, key, &principals_opts)) found_principal = 1; /* If principals file or command is specified, then require a match */ use_authorized_principals = principals_file != NULL || options.authorized_principals_command != NULL; if (!found_principal && use_authorized_principals) { reason = "Certificate does not contain an authorized principal"; goto fail_reason; } if (use_authorized_principals && principals_opts == NULL) fatal("%s: internal error: missing principals_opts", __func__); if (sshkey_cert_check_authority(key, 0, 1, use_authorized_principals ? NULL : pw->pw_name, &reason) != 0) goto fail_reason; /* Check authority from options in key and from principals file/cmd */ if ((cert_opts = sshauthopt_from_cert(key)) == NULL) { reason = "Invalid certificate options"; goto fail_reason; } if (auth_authorise_keyopts(ssh, pw, cert_opts, 0, "cert") != 0) { reason = "Refused by certificate options"; goto fail_reason; } if (principals_opts == NULL) { final_opts = cert_opts; cert_opts = NULL; } else { if (auth_authorise_keyopts(ssh, pw, principals_opts, 0, "principals") != 0) { reason = "Refused by certificate principals options"; goto fail_reason; } if ((final_opts = sshauthopt_merge(principals_opts, cert_opts, &reason)) == NULL) { fail_reason: error("%s", reason); auth_debug_add("%s", reason); goto out; } } /* Success */ verbose("Accepted certificate ID \"%s\" (serial %llu) signed by " "%s CA %s via %s", key->cert->key_id, (unsigned long long)key->cert->serial, sshkey_type(key->cert->signature_key), ca_fp, options.trusted_user_ca_keys); if (authoptsp != NULL) { *authoptsp = final_opts; final_opts = NULL; } ret = 1; out: sshauthopt_free(principals_opts); sshauthopt_free(cert_opts); sshauthopt_free(final_opts); free(principals_file); free(ca_fp); return ret; } Commit Message: delay bailout for invalid authenticating user until after the packet containing the request has been fully parsed. Reported by Dariusz Tytko and Michał Sajdak; ok deraadt CWE ID: CWE-200
0
79,110
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: poppler_page_class_init (PopplerPageClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GParamSpec *pspec; gobject_class->finalize = poppler_page_finalize; gobject_class->get_property = poppler_page_get_property; pspec = g_param_spec_string ("label", "Page Label", "The label of the page", NULL, G_PARAM_READABLE); g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_LABEL, pspec); } Commit Message: CWE ID: CWE-189
0
767
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static int __init nvmet_fc_init_module(void) { return nvmet_register_transport(&nvmet_fc_tgt_fcp_ops); } Commit Message: nvmet-fc: ensure target queue id within range. When searching for queue id's ensure they are within the expected range. Signed-off-by: James Smart <james.smart@broadcom.com> Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@kernel.dk> CWE ID: CWE-119
0
93,619
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: ChromeContentBrowserClientExtensionsPart::ShouldTryToUseExistingProcessHost( Profile* profile, const GURL& url) { ExtensionRegistry* registry = profile ? ExtensionRegistry::Get(profile) : NULL; if (!registry) return false; const Extension* extension = registry->enabled_extensions().GetExtensionOrAppByURL(url); if (!extension) return false; if (!BackgroundInfo::HasBackgroundPage(extension)) return false; std::set<int> process_ids; size_t max_process_count = content::RenderProcessHost::GetMaxRendererProcessCount(); std::vector<Profile*> profiles = g_browser_process->profile_manager()-> GetLoadedProfiles(); for (size_t i = 0; i < profiles.size(); ++i) { ProcessManager* epm = ProcessManager::Get(profiles[i]); for (ExtensionHost* host : epm->background_hosts()) process_ids.insert(host->render_process_host()->GetID()); } return (process_ids.size() > (max_process_count * chrome::kMaxShareOfExtensionProcesses)); } Commit Message: [Extensions] Update navigations across hypothetical extension extents Update code to treat navigations across hypothetical extension extents (e.g. for nonexistent extensions) the same as we do for navigations crossing installed extension extents. Bug: 598265 Change-Id: Ibdf2f563ce1fd108ead279077901020a24de732b Reviewed-on: https://chromium-review.googlesource.com/617180 Commit-Queue: Devlin <rdevlin.cronin@chromium.org> Reviewed-by: Alex Moshchuk <alexmos@chromium.org> Reviewed-by: Nasko Oskov <nasko@chromium.org> Cr-Commit-Position: refs/heads/master@{#495779} CWE ID:
0
151,011
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: void CairoOutputDev::drawImageMaskRegular(GfxState *state, Object *ref, Stream *str, int width, int height, GBool invert, GBool inlineImg) { unsigned char *buffer; unsigned char *dest; cairo_surface_t *image; cairo_pattern_t *pattern; int x, y; ImageStream *imgStr; Guchar *pix; cairo_matrix_t matrix; int invert_bit; int row_stride; row_stride = (width + 3) & ~3; buffer = (unsigned char *) malloc (height * row_stride); if (buffer == NULL) { error(-1, "Unable to allocate memory for image."); return; } /* TODO: Do we want to cache these? */ imgStr = new ImageStream(str, width, 1, 1); imgStr->reset(); invert_bit = invert ? 1 : 0; for (y = 0; y < height; y++) { pix = imgStr->getLine(); dest = buffer + y * row_stride; for (x = 0; x < width; x++) { if (pix[x] ^ invert_bit) *dest++ = 0; else *dest++ = 255; } } image = cairo_image_surface_create_for_data (buffer, CAIRO_FORMAT_A8, width, height, row_stride); if (image == NULL) { delete imgStr; return; } pattern = cairo_pattern_create_for_surface (image); if (pattern == NULL) { delete imgStr; return; } cairo_matrix_init_translate (&matrix, 0, height); cairo_matrix_scale (&matrix, width, -height); cairo_pattern_set_matrix (pattern, &matrix); /* we should actually be using CAIRO_FILTER_NEAREST here. However, * cairo doesn't yet do minifaction filtering causing scaled down * images with CAIRO_FILTER_NEAREST to look really bad */ cairo_pattern_set_filter (pattern, CAIRO_FILTER_BEST); cairo_mask (cairo, pattern); if (cairo_shape) { #if 0 cairo_rectangle (cairo_shape, 0., 0., width, height); cairo_fill (cairo_shape); #else cairo_save (cairo_shape); /* this should draw a rectangle the size of the image * we use this instead of rect,fill because of the lack * of EXTEND_PAD */ /* NOTE: this will multiply the edges of the image twice */ cairo_set_source (cairo_shape, pattern); cairo_mask (cairo_shape, pattern); cairo_restore (cairo_shape); #endif } cairo_pattern_destroy (pattern); cairo_surface_destroy (image); free (buffer); delete imgStr; } Commit Message: CWE ID: CWE-189
0
893
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static int n_tty_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) { struct n_tty_data *ldata = tty->disc_data; int retval; switch (cmd) { case TIOCOUTQ: return put_user(tty_chars_in_buffer(tty), (int __user *) arg); case TIOCINQ: down_write(&tty->termios_rwsem); if (L_ICANON(tty)) retval = inq_canon(ldata); else retval = read_cnt(ldata); up_write(&tty->termios_rwsem); return put_user(retval, (unsigned int __user *) arg); default: return n_tty_ioctl_helper(tty, file, cmd, arg); } } Commit Message: n_tty: Fix n_tty_write crash when echoing in raw mode The tty atomic_write_lock does not provide an exclusion guarantee for the tty driver if the termios settings are LECHO & !OPOST. And since it is unexpected and not allowed to call TTY buffer helpers like tty_insert_flip_string concurrently, this may lead to crashes when concurrect writers call pty_write. In that case the following two writers: * the ECHOing from a workqueue and * pty_write from the process race and can overflow the corresponding TTY buffer like follows. If we look into tty_insert_flip_string_fixed_flag, there is: int space = __tty_buffer_request_room(port, goal, flags); struct tty_buffer *tb = port->buf.tail; ... memcpy(char_buf_ptr(tb, tb->used), chars, space); ... tb->used += space; so the race of the two can result in something like this: A B __tty_buffer_request_room __tty_buffer_request_room memcpy(buf(tb->used), ...) tb->used += space; memcpy(buf(tb->used), ...) ->BOOM B's memcpy is past the tty_buffer due to the previous A's tb->used increment. Since the N_TTY line discipline input processing can output concurrently with a tty write, obtain the N_TTY ldisc output_lock to serialize echo output with normal tty writes. This ensures the tty buffer helper tty_insert_flip_string is not called concurrently and everything is fine. Note that this is nicely reproducible by an ordinary user using forkpty and some setup around that (raw termios + ECHO). And it is present in kernels at least after commit d945cb9cce20ac7143c2de8d88b187f62db99bdc (pty: Rework the pty layer to use the normal buffering logic) in 2.6.31-rc3. js: add more info to the commit log js: switch to bool js: lock unconditionally js: lock only the tty->ops->write call References: CVE-2014-0196 Reported-and-tested-by: Jiri Slaby <jslaby@suse.cz> Signed-off-by: Peter Hurley <peter@hurleysoftware.com> Signed-off-by: Jiri Slaby <jslaby@suse.cz> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Alan Cox <alan@lxorguk.ukuu.org.uk> Cc: <stable@vger.kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> CWE ID: CWE-362
0
39,807
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static inline void SetPSDPixel(Image *image,const size_t channels, const ssize_t type,const size_t packet_size,const Quantum pixel,Quantum *q, ExceptionInfo *exception) { if (image->storage_class == PseudoClass) { if (packet_size == 1) SetPixelIndex(image,ScaleQuantumToChar(pixel),q); else SetPixelIndex(image,ScaleQuantumToShort(pixel),q); SetPixelViaPixelInfo(image,image->colormap+(ssize_t) ConstrainColormapIndex(image,GetPixelIndex(image,q),exception),q); return; } switch (type) { case -1: { SetPixelAlpha(image, pixel,q); break; } case -2: case 0: { SetPixelRed(image,pixel,q); if (channels == 1 || type == -2) SetPixelGray(image,pixel,q); break; } case 1: { if (image->storage_class == PseudoClass) SetPixelAlpha(image,pixel,q); else SetPixelGreen(image,pixel,q); break; } case 2: { if (image->storage_class == PseudoClass) SetPixelAlpha(image,pixel,q); else SetPixelBlue(image,pixel,q); break; } case 3: { if (image->colorspace == CMYKColorspace) SetPixelBlack(image,pixel,q); else if (image->alpha_trait != UndefinedPixelTrait) SetPixelAlpha(image,pixel,q); break; } case 4: { if ((IssRGBCompatibleColorspace(image->colorspace) != MagickFalse) && (channels > 3)) break; if (image->alpha_trait != UndefinedPixelTrait) SetPixelAlpha(image,pixel,q); break; } } } Commit Message: Fix improper cast that could cause an overflow as demonstrated in #347. CWE ID: CWE-119
0
69,054
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static MagickBooleanType GetTIFFInfo(const ImageInfo *image_info, TIFF *tiff,TIFFInfo *tiff_info) { const char *option; MagickStatusType flags; uint32 tile_columns, tile_rows; assert(tiff_info != (TIFFInfo *) NULL); (void) ResetMagickMemory(tiff_info,0,sizeof(*tiff_info)); option=GetImageOption(image_info,"tiff:tile-geometry"); if (option == (const char *) NULL) { uint32 rows_per_strip; option=GetImageOption(image_info,"tiff:rows-per-strip"); if (option != (const char *) NULL) rows_per_strip=(size_t) strtol(option,(char **) NULL,10); else if (TIFFGetField(tiff,TIFFTAG_IMAGELENGTH,&rows_per_strip) == 0) rows_per_strip=0; /* use default */ rows_per_strip=TIFFDefaultStripSize(tiff,rows_per_strip); (void) TIFFSetField(tiff,TIFFTAG_ROWSPERSTRIP,rows_per_strip); return(MagickTrue); } /* Create tiled TIFF, ignore "tiff:rows-per-strip". */ flags=ParseAbsoluteGeometry(option,&tiff_info->tile_geometry); if ((flags & HeightValue) == 0) tiff_info->tile_geometry.height=tiff_info->tile_geometry.width; tile_columns=(uint32) tiff_info->tile_geometry.width; tile_rows=(uint32) tiff_info->tile_geometry.height; TIFFDefaultTileSize(tiff,&tile_columns,&tile_rows); (void) TIFFSetField(tiff,TIFFTAG_TILEWIDTH,tile_columns); (void) TIFFSetField(tiff,TIFFTAG_TILELENGTH,tile_rows); tiff_info->tile_geometry.width=tile_columns; tiff_info->tile_geometry.height=tile_rows; tiff_info->scanlines=(unsigned char *) AcquireQuantumMemory((size_t) tile_rows*TIFFScanlineSize(tiff),sizeof(*tiff_info->scanlines)); tiff_info->pixels=(unsigned char *) AcquireQuantumMemory((size_t) tile_rows*TIFFTileSize(tiff),sizeof(*tiff_info->scanlines)); if ((tiff_info->scanlines == (unsigned char *) NULL) || (tiff_info->pixels == (unsigned char *) NULL)) { DestroyTIFFInfo(tiff_info); return(MagickFalse); } return(MagickTrue); } Commit Message: https://github.com/ImageMagick/ImageMagick/issues/298 CWE ID: CWE-476
0
72,656
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: void DataPipeProducerDispatcher::CompleteTransitAndClose() { node_controller_->SetPortObserver(control_port_, nullptr); base::AutoLock lock(lock_); DCHECK(in_transit_); transferred_ = true; in_transit_ = false; CloseNoLock(); } Commit Message: [mojo-core] Validate data pipe endpoint metadata Ensures that we don't blindly trust specified buffer size and offset metadata when deserializing data pipe consumer and producer handles. Bug: 877182 Change-Id: I30f3eceafb5cee06284c2714d08357ef911d6fd9 Reviewed-on: https://chromium-review.googlesource.com/1192922 Reviewed-by: Reilly Grant <reillyg@chromium.org> Commit-Queue: Ken Rockot <rockot@chromium.org> Cr-Commit-Position: refs/heads/master@{#586704} CWE ID: CWE-20
0
154,403
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static void dn_destroy_sock(struct sock *sk) { struct dn_scp *scp = DN_SK(sk); scp->nsp_rxtshift = 0; /* reset back off */ if (sk->sk_socket) { if (sk->sk_socket->state != SS_UNCONNECTED) sk->sk_socket->state = SS_DISCONNECTING; } sk->sk_state = TCP_CLOSE; switch (scp->state) { case DN_DN: dn_nsp_send_disc(sk, NSP_DISCCONF, NSP_REASON_DC, sk->sk_allocation); scp->persist_fxn = dn_destroy_timer; scp->persist = dn_nsp_persist(sk); break; case DN_CR: scp->state = DN_DR; goto disc_reject; case DN_RUN: scp->state = DN_DI; case DN_DI: case DN_DR: disc_reject: dn_nsp_send_disc(sk, NSP_DISCINIT, 0, sk->sk_allocation); case DN_NC: case DN_NR: case DN_RJ: case DN_DIC: case DN_CN: case DN_DRC: case DN_CI: case DN_CD: scp->persist_fxn = dn_destroy_timer; scp->persist = dn_nsp_persist(sk); break; default: printk(KERN_DEBUG "DECnet: dn_destroy_sock passed socket in invalid state\n"); case DN_O: dn_stop_slow_timer(sk); dn_unhash_sock_bh(sk); sock_put(sk); break; } } Commit Message: net: add validation for the socket syscall protocol argument 郭永刚 reported that one could simply crash the kernel as root by using a simple program: int socket_fd; struct sockaddr_in addr; addr.sin_port = 0; addr.sin_addr.s_addr = INADDR_ANY; addr.sin_family = 10; socket_fd = socket(10,3,0x40000000); connect(socket_fd , &addr,16); AF_INET, AF_INET6 sockets actually only support 8-bit protocol identifiers. inet_sock's skc_protocol field thus is sized accordingly, thus larger protocol identifiers simply cut off the higher bits and store a zero in the protocol fields. This could lead to e.g. NULL function pointer because as a result of the cut off inet_num is zero and we call down to inet_autobind, which is NULL for raw sockets. kernel: Call Trace: kernel: [<ffffffff816db90e>] ? inet_autobind+0x2e/0x70 kernel: [<ffffffff816db9a4>] inet_dgram_connect+0x54/0x80 kernel: [<ffffffff81645069>] SYSC_connect+0xd9/0x110 kernel: [<ffffffff810ac51b>] ? ptrace_notify+0x5b/0x80 kernel: [<ffffffff810236d8>] ? syscall_trace_enter_phase2+0x108/0x200 kernel: [<ffffffff81645e0e>] SyS_connect+0xe/0x10 kernel: [<ffffffff81779515>] tracesys_phase2+0x84/0x89 I found no particular commit which introduced this problem. CVE: CVE-2015-8543 Cc: Cong Wang <cwang@twopensource.com> Reported-by: 郭永刚 <guoyonggang@360.cn> Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org> Signed-off-by: David S. Miller <davem@davemloft.net> CWE ID:
0
41,481
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: MagickExport MagickBooleanType CLAHEImage(Image *image,const size_t width, const size_t height,const size_t number_bins,const double clip_limit, ExceptionInfo *exception) { #define CLAHEImageTag "CLAHE/Image" CacheView *image_view; ColorspaceType colorspace; MagickBooleanType status; MagickOffsetType progress; MemoryInfo *pixel_cache; RangeInfo range_info; RectangleInfo clahe_info, tile_info; size_t n; ssize_t y; unsigned short *pixels; /* Configure CLAHE parameters. */ assert(image != (Image *) NULL); assert(image->signature == MagickCoreSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); range_info.min=0; range_info.max=NumberCLAHEGrays-1; tile_info.width=width; if (tile_info.width == 0) tile_info.width=image->columns >> 3; tile_info.height=height; if (tile_info.height == 0) tile_info.height=image->rows >> 3; tile_info.x=0; if ((image->columns % tile_info.width) != 0) tile_info.x=(ssize_t) tile_info.width-(image->columns % tile_info.width); tile_info.y=0; if ((image->rows % tile_info.height) != 0) tile_info.y=(ssize_t) tile_info.height-(image->rows % tile_info.height); clahe_info.width=image->columns+tile_info.x; clahe_info.height=image->rows+tile_info.y; clahe_info.x=(ssize_t) clahe_info.width/tile_info.width; clahe_info.y=(ssize_t) clahe_info.height/tile_info.height; pixel_cache=AcquireVirtualMemory(clahe_info.width,clahe_info.height* sizeof(*pixels)); if (pixel_cache == (MemoryInfo *) NULL) ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", image->filename); pixels=(unsigned short *) GetVirtualMemoryBlob(pixel_cache); colorspace=image->colorspace; if (TransformImageColorspace(image,LabColorspace,exception) == MagickFalse) { pixel_cache=RelinquishVirtualMemory(pixel_cache); return(MagickFalse); } /* Initialize CLAHE pixels. */ image_view=AcquireVirtualCacheView(image,exception); progress=0; status=MagickTrue; n=0; for (y=0; y < (ssize_t) clahe_info.height; y++) { register const Quantum *magick_restrict p; register ssize_t x; if (status == MagickFalse) continue; p=GetCacheViewVirtualPixels(image_view,-(tile_info.x >> 1),y- (tile_info.y >> 1),clahe_info.width,1,exception); if (p == (const Quantum *) NULL) { status=MagickFalse; continue; } for (x=0; x < (ssize_t) clahe_info.width; x++) { pixels[n++]=ScaleQuantumToShort(p[0]); p+=GetPixelChannels(image); } if (image->progress_monitor != (MagickProgressMonitor) NULL) { MagickBooleanType proceed; #if defined(MAGICKCORE_OPENMP_SUPPORT) #pragma omp atomic #endif progress++; proceed=SetImageProgress(image,CLAHEImageTag,progress,2* GetPixelChannels(image)); if (proceed == MagickFalse) status=MagickFalse; } } image_view=DestroyCacheView(image_view); status=CLAHE(&clahe_info,&tile_info,&range_info,number_bins == 0 ? (size_t) 128 : MagickMin(number_bins,256),clip_limit,pixels); if (status == MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename); /* Push CLAHE pixels to CLAHE image. */ image_view=AcquireAuthenticCacheView(image,exception); n=clahe_info.width*(tile_info.y >> 1); for (y=0; y < (ssize_t) image->rows; y++) { register Quantum *magick_restrict q; register ssize_t x; if (status == MagickFalse) continue; q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception); if (q == (Quantum *) NULL) { status=MagickFalse; continue; } n+=tile_info.x >> 1; for (x=0; x < (ssize_t) image->columns; x++) { q[0]=ScaleShortToQuantum(pixels[n++]); q+=GetPixelChannels(image); } n+=(clahe_info.width-image->columns-(tile_info.x >> 1)); if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) status=MagickFalse; if (image->progress_monitor != (MagickProgressMonitor) NULL) { MagickBooleanType proceed; #if defined(MAGICKCORE_OPENMP_SUPPORT) #pragma omp atomic #endif progress++; proceed=SetImageProgress(image,CLAHEImageTag,progress,2* GetPixelChannels(image)); if (proceed == MagickFalse) status=MagickFalse; } } image_view=DestroyCacheView(image_view); pixel_cache=RelinquishVirtualMemory(pixel_cache); if (TransformImageColorspace(image,colorspace,exception) == MagickFalse) status=MagickFalse; return(status); } Commit Message: https://github.com/ImageMagick/ImageMagick/issues/1611 CWE ID: CWE-119
0
88,990
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: void ProfileSyncService::DisableForUser() { sync_prefs_.ClearPreferences(); ClearUnrecoverableError(); ShutdownImpl(true); if (!auto_start_enabled_) signin_->SignOut(); NotifyObservers(); } Commit Message: [Sync] Cleanup all tab sync enabling logic now that its on by default. BUG=none TEST= Review URL: https://chromiumcodereview.appspot.com/10443046 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139462 0039d316-1c4b-4281-b951-d872f2087c98 CWE ID: CWE-362
0
104,922
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static inline MagickBooleanType IsSameColor(const Image *image, const PixelPacket *p,const PixelPacket *q) { if ((GetPixelRed(p) != GetPixelRed(q)) || (GetPixelGreen(p) != GetPixelGreen(q)) || (GetPixelBlue(p) != GetPixelBlue(q))) return(MagickFalse); if ((image->matte != MagickFalse) && (GetPixelOpacity(p) != GetPixelOpacity(q))) return(MagickFalse); return(MagickTrue); } Commit Message: https://github.com/ImageMagick/ImageMagick/issues/574 CWE ID: CWE-772
0
62,713
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static char **t1_builtin_enc(void) { int i, a, b, c, counter = 0; char *r, *p, **glyph_names; /* At this moment "/Encoding" is the prefix of t1_line_array */ glyph_names = xtalloc(256, char *); for (i = 0; i < 256; i++) glyph_names[i] = notdef; if (t1_suffix("def")) { /* predefined encoding */ if (sscanf(t1_line_array + strlen("/Encoding"), "%255s", t1_buf_array) == 1 && strcmp(t1_buf_array, "StandardEncoding") == 0) { t1_encoding = ENC_STANDARD; for (i = 0; i < 256; i++) { if (standard_glyph_names[i] != notdef) glyph_names[i] = xstrdup(standard_glyph_names[i]); } return glyph_names; } pdftex_fail("cannot subset font (unknown predefined encoding `%s')", t1_buf_array); } /* At this moment "/Encoding" is the prefix of t1_line_array, and the encoding is * not a predefined encoding. * * We have two possible forms of Encoding vector. The first case is * * /Encoding [/a /b /c...] readonly def * * and the second case can look like * * /Encoding 256 array 0 1 255 {1 index exch /.notdef put} for * dup 0 /x put * dup 1 /y put * ... * readonly def */ t1_encoding = ENC_BUILTIN; if (t1_prefix("/Encoding [") || t1_prefix("/Encoding[")) { /* the first case */ r = strchr(t1_line_array, '[') + 1; skip(r, ' '); for (;;) { while (*r == '/') { for (p = t1_buf_array, r++; *r != 32 && *r != 10 && *r != ']' && *r != '/'; *p++ = *r++); *p = 0; skip(r, ' '); if (counter > 255) pdftex_fail("encoding vector contains more than 256 names"); if (strcmp(t1_buf_array, notdef) != 0) glyph_names[counter] = xstrdup(t1_buf_array); counter++; } if (*r != 10 && *r != '%') { if (str_prefix(r, "] def") || str_prefix(r, "] readonly def")) break; else { remove_eol(r, t1_line_array); pdftex_fail ("a name or `] def' or `] readonly def' expected: `%s'", t1_line_array); } } t1_getline(); r = t1_line_array; } } else { /* the second case */ p = strchr(t1_line_array, 10); for (;;) { if (*p == 10) { t1_getline(); p = t1_line_array; } /* check for `dup <index> <glyph> put' */ if (sscanf(p, "dup %i%255s put", &i, t1_buf_array) == 2 && *t1_buf_array == '/' && valid_code(i)) { if (strcmp(t1_buf_array + 1, notdef) != 0) glyph_names[i] = xstrdup(t1_buf_array + 1); p = strstr(p, " put") + strlen(" put"); skip(p, ' '); } /* check for `dup dup <to> exch <from> get put' */ else if (sscanf(p, "dup dup %i exch %i get put", &b, &a) == 2 && valid_code(a) && valid_code(b)) { copy_glyph_names(glyph_names, a, b); p = strstr(p, " get put") + strlen(" get put"); skip(p, ' '); } /* check for `dup dup <from> <size> getinterval <to> exch putinterval' */ else if (sscanf(p, "dup dup %i %i getinterval %i exch putinterval", &a, &c, &b) == 3 && valid_code(a) && valid_code(b) && valid_code(c)) { for (i = 0; i < c; i++) copy_glyph_names(glyph_names, a + i, b + i); p = strstr(p, " putinterval") + strlen(" putinterval"); skip(p, ' '); } /* check for `def' or `readonly def' */ else if ((p == t1_line_array || (p > t1_line_array && p[-1] == ' ')) && strcmp(p, "def\n") == 0) return glyph_names; /* skip an unrecognizable word */ else { while (*p != ' ' && *p != 10) p++; skip(p, ' '); } } } return glyph_names; } Commit Message: writet1 protection against buffer overflow git-svn-id: svn://tug.org/texlive/trunk/Build/source@48697 c570f23f-e606-0410-a88d-b1316a301751 CWE ID: CWE-119
0
76,718
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: Ins_SCANCTRL( INS_ARG ) { FT_Int A; /* Get Threshold */ A = (FT_Int)( args[0] & 0xFF ); if ( A == 0xFF ) { CUR.GS.scan_control = TRUE; return; } else if ( A == 0 ) { CUR.GS.scan_control = FALSE; return; } if ( ( args[0] & 0x100 ) != 0 && CUR.tt_metrics.ppem <= A ) CUR.GS.scan_control = TRUE; if ( ( args[0] & 0x200 ) != 0 && CUR.tt_metrics.rotated ) CUR.GS.scan_control = TRUE; if ( ( args[0] & 0x400 ) != 0 && CUR.tt_metrics.stretched ) CUR.GS.scan_control = TRUE; if ( ( args[0] & 0x800 ) != 0 && CUR.tt_metrics.ppem > A ) CUR.GS.scan_control = FALSE; if ( ( args[0] & 0x1000 ) != 0 && CUR.tt_metrics.rotated ) CUR.GS.scan_control = FALSE; if ( ( args[0] & 0x2000 ) != 0 && CUR.tt_metrics.stretched ) CUR.GS.scan_control = FALSE; } Commit Message: CWE ID: CWE-119
0
10,160
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: AVCodecParserContext *av_parser_init(int codec_id) { AVCodecParserContext *s = NULL; AVCodecParser *parser; int ret; if(codec_id == AV_CODEC_ID_NONE) return NULL; for(parser = av_first_parser; parser != NULL; parser = parser->next) { if (parser->codec_ids[0] == codec_id || parser->codec_ids[1] == codec_id || parser->codec_ids[2] == codec_id || parser->codec_ids[3] == codec_id || parser->codec_ids[4] == codec_id) goto found; } return NULL; found: s = av_mallocz(sizeof(AVCodecParserContext)); if (!s) goto err_out; s->parser = parser; s->priv_data = av_mallocz(parser->priv_data_size); if (!s->priv_data) goto err_out; s->fetch_timestamp=1; s->pict_type = AV_PICTURE_TYPE_I; if (parser->parser_init) { ret = parser->parser_init(s); if (ret != 0) goto err_out; } s->key_frame = -1; s->convergence_duration = 0; s->dts_sync_point = INT_MIN; s->dts_ref_dts_delta = INT_MIN; s->pts_dts_delta = INT_MIN; return s; err_out: if (s) av_freep(&s->priv_data); av_free(s); return NULL; } Commit Message: avcodec/parser: reset indexes on realloc failure Fixes Ticket2982 Signed-off-by: Michael Niedermayer <michaelni@gmx.at> CWE ID: CWE-119
0
28,022
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: const char* XMLRPC_GetValueID(XMLRPC_VALUE value) { return (const char*)((value && value->id.len) ? value->id.str : 0); } Commit Message: CWE ID: CWE-119
0
12,153
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: GLenum GLES2DecoderImpl::GetBoundReadFrameBufferInternalFormat() { FramebufferManager::FramebufferInfo* framebuffer = GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER); if (framebuffer != NULL) { return framebuffer->GetColorAttachmentFormat(); } else if (offscreen_target_frame_buffer_.get()) { return offscreen_target_color_format_; } else { return back_buffer_color_format_; } } Commit Message: Always write data to new buffer in SimulateAttrib0 This is to work around linux nvidia driver bug. TEST=asan BUG=118970 Review URL: http://codereview.chromium.org/10019003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@131538 0039d316-1c4b-4281-b951-d872f2087c98 CWE ID:
0
108,998
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: n_tty_receive_buf_standard(struct tty_struct *tty, const unsigned char *cp, char *fp, int count) { struct n_tty_data *ldata = tty->disc_data; char flag = TTY_NORMAL; while (count--) { if (fp) flag = *fp++; if (likely(flag == TTY_NORMAL)) { unsigned char c = *cp++; if (I_ISTRIP(tty)) c &= 0x7f; if (I_IUCLC(tty) && L_IEXTEN(tty)) c = tolower(c); if (L_EXTPROC(tty)) { put_tty_queue(c, ldata); continue; } if (!test_bit(c, ldata->char_map)) n_tty_receive_char_inline(tty, c); else if (n_tty_receive_char_special(tty, c) && count) { if (fp) flag = *fp++; n_tty_receive_char_lnext(tty, *cp++, flag); count--; } } else n_tty_receive_char_flagged(tty, *cp++, flag); } } Commit Message: n_tty: Fix n_tty_write crash when echoing in raw mode The tty atomic_write_lock does not provide an exclusion guarantee for the tty driver if the termios settings are LECHO & !OPOST. And since it is unexpected and not allowed to call TTY buffer helpers like tty_insert_flip_string concurrently, this may lead to crashes when concurrect writers call pty_write. In that case the following two writers: * the ECHOing from a workqueue and * pty_write from the process race and can overflow the corresponding TTY buffer like follows. If we look into tty_insert_flip_string_fixed_flag, there is: int space = __tty_buffer_request_room(port, goal, flags); struct tty_buffer *tb = port->buf.tail; ... memcpy(char_buf_ptr(tb, tb->used), chars, space); ... tb->used += space; so the race of the two can result in something like this: A B __tty_buffer_request_room __tty_buffer_request_room memcpy(buf(tb->used), ...) tb->used += space; memcpy(buf(tb->used), ...) ->BOOM B's memcpy is past the tty_buffer due to the previous A's tb->used increment. Since the N_TTY line discipline input processing can output concurrently with a tty write, obtain the N_TTY ldisc output_lock to serialize echo output with normal tty writes. This ensures the tty buffer helper tty_insert_flip_string is not called concurrently and everything is fine. Note that this is nicely reproducible by an ordinary user using forkpty and some setup around that (raw termios + ECHO). And it is present in kernels at least after commit d945cb9cce20ac7143c2de8d88b187f62db99bdc (pty: Rework the pty layer to use the normal buffering logic) in 2.6.31-rc3. js: add more info to the commit log js: switch to bool js: lock unconditionally js: lock only the tty->ops->write call References: CVE-2014-0196 Reported-and-tested-by: Jiri Slaby <jslaby@suse.cz> Signed-off-by: Peter Hurley <peter@hurleysoftware.com> Signed-off-by: Jiri Slaby <jslaby@suse.cz> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Alan Cox <alan@lxorguk.ukuu.org.uk> Cc: <stable@vger.kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> CWE ID: CWE-362
0
39,818
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: magic_file(struct magic_set *ms, const char *inname) { if (ms == NULL) return NULL; return file_or_fd(ms, inname, STDIN_FILENO); } Commit Message: - Add a limit to the number of ELF notes processed (Suggested by Alexander Cherepanov) - Restructure ELF note printing so that we don't print the same message multiple times on repeated notes of the same kind. CWE ID: CWE-399
0
45,979
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: _tiffDummyMapProc(thandle_t fd, void** pbase, toff_t* psize) { (void) fd; (void) pbase; (void) psize; return (0); } Commit Message: * libtiff/tif_{unix,vms,win32}.c (_TIFFmalloc): ANSI C does not require malloc() to return NULL pointer if requested allocation size is zero. Assure that _TIFFmalloc does. CWE ID: CWE-369
0
86,807
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink) { __be32 *p; int status = 0; *maxlink = 1; if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U))) return -EIO; if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) { READ_BUF(4); READ32(*maxlink); bitmap[0] &= ~FATTR4_WORD0_MAXLINK; } dprintk("%s: maxlink=%u\n", __func__, *maxlink); return status; } Commit Message: NFSv4: Convert the open and close ops to use fmode Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com> CWE ID:
0
22,991
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static int jas_icccurv_output(jas_iccattrval_t *attrval, jas_stream_t *out) { jas_icccurv_t *curv = &attrval->data.curv; unsigned int i; if (jas_iccputuint32(out, curv->numents)) goto error; for (i = 0; i < curv->numents; ++i) { if (jas_iccputuint16(out, curv->ents[i])) goto error; } return 0; error: return -1; } Commit Message: The generation of the configuration file jas_config.h has been completely reworked in order to avoid pollution of the global namespace. Some problematic types like uchar, ulong, and friends have been replaced with names with a jas_ prefix. An option max_samples has been added to the BMP and JPEG decoders to restrict the maximum size of image that they can decode. This change was made as a (possibly temporary) fix to address security concerns. A max_samples command-line option has also been added to imginfo. Whether an image component (for jas_image_t) is stored in memory or on disk is now based on the component size (rather than the image size). Some debug log message were added. Some new integer overflow checks were added. Some new safe integer add/multiply functions were added. More pre-C99 cruft was removed. JasPer has numerous "hacks" to handle pre-C99 compilers. JasPer now assumes C99 support. So, this pre-C99 cruft is unnecessary and can be removed. The regression jasper-doublefree-mem_close.jpg has been re-enabled. Theoretically, it should work more predictably now. CWE ID: CWE-190
0
72,695
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: ContentBrowserTestSuite(int argc, char** argv) : ContentTestSuiteBase(argc, argv) { } Commit Message: Fix content_shell with network service enabled not loading pages. This regressed in my earlier cl r528763. This is a reland of r547221. Bug: 833612 Change-Id: I4c2649414d42773f2530e1abe5912a04fcd0ed9b Reviewed-on: https://chromium-review.googlesource.com/1064702 Reviewed-by: Jay Civelli <jcivelli@chromium.org> Commit-Queue: John Abd-El-Malek <jam@chromium.org> Cr-Commit-Position: refs/heads/master@{#560011} CWE ID: CWE-264
0
131,067
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: void TextTrackCue::setId(const AtomicString& id) { if (id_ == id) return; CueWillChange(); id_ = id; CueDidChange(); } Commit Message: Support negative timestamps of TextTrackCue Ensure proper behaviour for negative timestamps of TextTrackCue. 1. Cues with negative startTime should become active from 0s. 2. Cues with negative startTime and endTime should never be active. Bug: 314032 Change-Id: Ib53710e58be0be770c933ea8c3c4709a0e5dec0d Reviewed-on: https://chromium-review.googlesource.com/863270 Commit-Queue: srirama chandra sekhar <srirama.m@samsung.com> Reviewed-by: Fredrik Söderquist <fs@opera.com> Cr-Commit-Position: refs/heads/master@{#529012} CWE ID:
0
125,039
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: int http_resync_states(struct session *s) { struct http_txn *txn = &s->txn; int old_req_state = txn->req.msg_state; int old_res_state = txn->rsp.msg_state; http_sync_req_state(s); while (1) { if (!http_sync_res_state(s)) break; if (!http_sync_req_state(s)) break; } /* OK, both state machines agree on a compatible state. * There are a few cases we're interested in : * - HTTP_MSG_TUNNEL on either means we have to disable both analysers * - HTTP_MSG_CLOSED on both sides means we've reached the end in both * directions, so let's simply disable both analysers. * - HTTP_MSG_CLOSED on the response only means we must abort the * request. * - HTTP_MSG_CLOSED on the request and HTTP_MSG_DONE on the response * with server-close mode means we've completed one request and we * must re-initialize the server connection. */ if (txn->req.msg_state == HTTP_MSG_TUNNEL || txn->rsp.msg_state == HTTP_MSG_TUNNEL || (txn->req.msg_state == HTTP_MSG_CLOSED && txn->rsp.msg_state == HTTP_MSG_CLOSED)) { s->req->analysers = 0; channel_auto_close(s->req); channel_auto_read(s->req); s->rep->analysers = 0; channel_auto_close(s->rep); channel_auto_read(s->rep); } else if ((txn->req.msg_state >= HTTP_MSG_DONE && (txn->rsp.msg_state == HTTP_MSG_CLOSED || (s->rep->flags & CF_SHUTW))) || txn->rsp.msg_state == HTTP_MSG_ERROR || txn->req.msg_state == HTTP_MSG_ERROR) { s->rep->analysers = 0; channel_auto_close(s->rep); channel_auto_read(s->rep); s->req->analysers = 0; channel_abort(s->req); channel_auto_close(s->req); channel_auto_read(s->req); bi_erase(s->req); } else if ((txn->req.msg_state == HTTP_MSG_DONE || txn->req.msg_state == HTTP_MSG_CLOSED) && txn->rsp.msg_state == HTTP_MSG_DONE && ((txn->flags & TX_CON_WANT_MSK) == TX_CON_WANT_SCL || (txn->flags & TX_CON_WANT_MSK) == TX_CON_WANT_KAL)) { /* server-close/keep-alive: terminate this transaction, * possibly killing the server connection and reinitialize * a fresh-new transaction. */ http_end_txn_clean_session(s); } return txn->req.msg_state != old_req_state || txn->rsp.msg_state != old_res_state; } Commit Message: CWE ID: CWE-189
0
9,812
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static int userauth_list (lua_State *L, int status, lua_KContext ctx) { char *auth_list = NULL; struct ssh_userdata *state = NULL; const char *username = luaL_checkstring(L, 2); state = (struct ssh_userdata *) nseU_checkudata(L, 1, SSH2_UDATA, "ssh2"); assert(state->session != NULL); while ((auth_list = libssh2_userauth_list(state->session, username, lua_rawlen(L, 2))) == NULL && libssh2_session_last_errno(state->session) == LIBSSH2_ERROR_EAGAIN) { luaL_getmetafield(L, 1, "filter"); lua_pushvalue(L, 1); assert(lua_status(L) == LUA_OK); lua_callk(L, 1, 0, 0, userauth_list); } if (auth_list) { const char *auth = strtok(auth_list, ","); lua_newtable(L); do { lua_pushstring(L, auth); lua_rawseti(L, -2, lua_rawlen(L, -2) + 1); } while ((auth = strtok(NULL, ","))); } else if (libssh2_userauth_authenticated(state->session)) { lua_pushliteral(L, "none_auth"); } else { return ssh_error(L, state->session, "userauth_list"); } return 1; } Commit Message: Avoid a crash (double-free) when SSH connection fails CWE ID: CWE-415
0
93,504
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static void ssl_write_max_fragment_length_ext( mbedtls_ssl_context *ssl, unsigned char *buf, size_t *olen ) { unsigned char *p = buf; const unsigned char *end = ssl->out_msg + MBEDTLS_SSL_MAX_CONTENT_LEN; *olen = 0; if( ssl->conf->mfl_code == MBEDTLS_SSL_MAX_FRAG_LEN_NONE ) { return; } MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, adding max_fragment_length extension" ) ); if( end < p || (size_t)( end - p ) < 5 ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "buffer too small" ) ); return; } *p++ = (unsigned char)( ( MBEDTLS_TLS_EXT_MAX_FRAGMENT_LENGTH >> 8 ) & 0xFF ); *p++ = (unsigned char)( ( MBEDTLS_TLS_EXT_MAX_FRAGMENT_LENGTH ) & 0xFF ); *p++ = 0x00; *p++ = 1; *p++ = ssl->conf->mfl_code; *olen = 5; } Commit Message: Add bounds check before length read CWE ID: CWE-125
0
83,378
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static void free_pte_range(struct mmu_gather *tlb, pmd_t *pmd, unsigned long addr) { pgtable_t token = pmd_pgtable(*pmd); pmd_clear(pmd); pte_free_tlb(tlb, token, addr); tlb->mm->nr_ptes--; } Commit Message: mm: thp: fix pmd_bad() triggering in code paths holding mmap_sem read mode commit 1a5a9906d4e8d1976b701f889d8f35d54b928f25 upstream. In some cases it may happen that pmd_none_or_clear_bad() is called with the mmap_sem hold in read mode. In those cases the huge page faults can allocate hugepmds under pmd_none_or_clear_bad() and that can trigger a false positive from pmd_bad() that will not like to see a pmd materializing as trans huge. It's not khugepaged causing the problem, khugepaged holds the mmap_sem in write mode (and all those sites must hold the mmap_sem in read mode to prevent pagetables to go away from under them, during code review it seems vm86 mode on 32bit kernels requires that too unless it's restricted to 1 thread per process or UP builds). The race is only with the huge pagefaults that can convert a pmd_none() into a pmd_trans_huge(). Effectively all these pmd_none_or_clear_bad() sites running with mmap_sem in read mode are somewhat speculative with the page faults, and the result is always undefined when they run simultaneously. This is probably why it wasn't common to run into this. For example if the madvise(MADV_DONTNEED) runs zap_page_range() shortly before the page fault, the hugepage will not be zapped, if the page fault runs first it will be zapped. Altering pmd_bad() not to error out if it finds hugepmds won't be enough to fix this, because zap_pmd_range would then proceed to call zap_pte_range (which would be incorrect if the pmd become a pmd_trans_huge()). The simplest way to fix this is to read the pmd in the local stack (regardless of what we read, no need of actual CPU barriers, only compiler barrier needed), and be sure it is not changing under the code that computes its value. Even if the real pmd is changing under the value we hold on the stack, we don't care. If we actually end up in zap_pte_range it means the pmd was not none already and it was not huge, and it can't become huge from under us (khugepaged locking explained above). All we need is to enforce that there is no way anymore that in a code path like below, pmd_trans_huge can be false, but pmd_none_or_clear_bad can run into a hugepmd. The overhead of a barrier() is just a compiler tweak and should not be measurable (I only added it for THP builds). I don't exclude different compiler versions may have prevented the race too by caching the value of *pmd on the stack (that hasn't been verified, but it wouldn't be impossible considering pmd_none_or_clear_bad, pmd_bad, pmd_trans_huge, pmd_none are all inlines and there's no external function called in between pmd_trans_huge and pmd_none_or_clear_bad). if (pmd_trans_huge(*pmd)) { if (next-addr != HPAGE_PMD_SIZE) { VM_BUG_ON(!rwsem_is_locked(&tlb->mm->mmap_sem)); split_huge_page_pmd(vma->vm_mm, pmd); } else if (zap_huge_pmd(tlb, vma, pmd, addr)) continue; /* fall through */ } if (pmd_none_or_clear_bad(pmd)) Because this race condition could be exercised without special privileges this was reported in CVE-2012-1179. The race was identified and fully explained by Ulrich who debugged it. I'm quoting his accurate explanation below, for reference. ====== start quote ======= mapcount 0 page_mapcount 1 kernel BUG at mm/huge_memory.c:1384! At some point prior to the panic, a "bad pmd ..." message similar to the following is logged on the console: mm/memory.c:145: bad pmd ffff8800376e1f98(80000000314000e7). The "bad pmd ..." message is logged by pmd_clear_bad() before it clears the page's PMD table entry. 143 void pmd_clear_bad(pmd_t *pmd) 144 { -> 145 pmd_ERROR(*pmd); 146 pmd_clear(pmd); 147 } After the PMD table entry has been cleared, there is an inconsistency between the actual number of PMD table entries that are mapping the page and the page's map count (_mapcount field in struct page). When the page is subsequently reclaimed, __split_huge_page() detects this inconsistency. 1381 if (mapcount != page_mapcount(page)) 1382 printk(KERN_ERR "mapcount %d page_mapcount %d\n", 1383 mapcount, page_mapcount(page)); -> 1384 BUG_ON(mapcount != page_mapcount(page)); The root cause of the problem is a race of two threads in a multithreaded process. Thread B incurs a page fault on a virtual address that has never been accessed (PMD entry is zero) while Thread A is executing an madvise() system call on a virtual address within the same 2 MB (huge page) range. virtual address space .---------------------. | | | | .-|---------------------| | | | | | |<-- B(fault) | | | 2 MB | |/////////////////////|-. huge < |/////////////////////| > A(range) page | |/////////////////////|-' | | | | | | '-|---------------------| | | | | '---------------------' - Thread A is executing an madvise(..., MADV_DONTNEED) system call on the virtual address range "A(range)" shown in the picture. sys_madvise // Acquire the semaphore in shared mode. down_read(&current->mm->mmap_sem) ... madvise_vma switch (behavior) case MADV_DONTNEED: madvise_dontneed zap_page_range unmap_vmas unmap_page_range zap_pud_range zap_pmd_range // // Assume that this huge page has never been accessed. // I.e. content of the PMD entry is zero (not mapped). // if (pmd_trans_huge(*pmd)) { // We don't get here due to the above assumption. } // // Assume that Thread B incurred a page fault and .---------> // sneaks in here as shown below. | // | if (pmd_none_or_clear_bad(pmd)) | { | if (unlikely(pmd_bad(*pmd))) | pmd_clear_bad | { | pmd_ERROR | // Log "bad pmd ..." message here. | pmd_clear | // Clear the page's PMD entry. | // Thread B incremented the map count | // in page_add_new_anon_rmap(), but | // now the page is no longer mapped | // by a PMD entry (-> inconsistency). | } | } | v - Thread B is handling a page fault on virtual address "B(fault)" shown in the picture. ... do_page_fault __do_page_fault // Acquire the semaphore in shared mode. down_read_trylock(&mm->mmap_sem) ... handle_mm_fault if (pmd_none(*pmd) && transparent_hugepage_enabled(vma)) // We get here due to the above assumption (PMD entry is zero). do_huge_pmd_anonymous_page alloc_hugepage_vma // Allocate a new transparent huge page here. ... __do_huge_pmd_anonymous_page ... spin_lock(&mm->page_table_lock) ... page_add_new_anon_rmap // Here we increment the page's map count (starts at -1). atomic_set(&page->_mapcount, 0) set_pmd_at // Here we set the page's PMD entry which will be cleared // when Thread A calls pmd_clear_bad(). ... spin_unlock(&mm->page_table_lock) The mmap_sem does not prevent the race because both threads are acquiring it in shared mode (down_read). Thread B holds the page_table_lock while the page's map count and PMD table entry are updated. However, Thread A does not synchronize on that lock. ====== end quote ======= [akpm@linux-foundation.org: checkpatch fixes] Reported-by: Ulrich Obergfell <uobergfe@redhat.com> Signed-off-by: Andrea Arcangeli <aarcange@redhat.com> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Cc: Mel Gorman <mgorman@suse.de> Cc: Hugh Dickins <hughd@google.com> Cc: Dave Jones <davej@redhat.com> Acked-by: Larry Woodman <lwoodman@redhat.com> Acked-by: Rik van Riel <riel@redhat.com> Cc: Mark Salter <msalter@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> CWE ID: CWE-264
0
21,232
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static int tg3_rx_prodring_xfer(struct tg3 *tp, struct tg3_rx_prodring_set *dpr, struct tg3_rx_prodring_set *spr) { u32 si, di, cpycnt, src_prod_idx; int i, err = 0; while (1) { src_prod_idx = spr->rx_std_prod_idx; /* Make sure updates to the rx_std_buffers[] entries and the * standard producer index are seen in the correct order. */ smp_rmb(); if (spr->rx_std_cons_idx == src_prod_idx) break; if (spr->rx_std_cons_idx < src_prod_idx) cpycnt = src_prod_idx - spr->rx_std_cons_idx; else cpycnt = tp->rx_std_ring_mask + 1 - spr->rx_std_cons_idx; cpycnt = min(cpycnt, tp->rx_std_ring_mask + 1 - dpr->rx_std_prod_idx); si = spr->rx_std_cons_idx; di = dpr->rx_std_prod_idx; for (i = di; i < di + cpycnt; i++) { if (dpr->rx_std_buffers[i].data) { cpycnt = i - di; err = -ENOSPC; break; } } if (!cpycnt) break; /* Ensure that updates to the rx_std_buffers ring and the * shadowed hardware producer ring from tg3_recycle_skb() are * ordered correctly WRT the skb check above. */ smp_rmb(); memcpy(&dpr->rx_std_buffers[di], &spr->rx_std_buffers[si], cpycnt * sizeof(struct ring_info)); for (i = 0; i < cpycnt; i++, di++, si++) { struct tg3_rx_buffer_desc *sbd, *dbd; sbd = &spr->rx_std[si]; dbd = &dpr->rx_std[di]; dbd->addr_hi = sbd->addr_hi; dbd->addr_lo = sbd->addr_lo; } spr->rx_std_cons_idx = (spr->rx_std_cons_idx + cpycnt) & tp->rx_std_ring_mask; dpr->rx_std_prod_idx = (dpr->rx_std_prod_idx + cpycnt) & tp->rx_std_ring_mask; } while (1) { src_prod_idx = spr->rx_jmb_prod_idx; /* Make sure updates to the rx_jmb_buffers[] entries and * the jumbo producer index are seen in the correct order. */ smp_rmb(); if (spr->rx_jmb_cons_idx == src_prod_idx) break; if (spr->rx_jmb_cons_idx < src_prod_idx) cpycnt = src_prod_idx - spr->rx_jmb_cons_idx; else cpycnt = tp->rx_jmb_ring_mask + 1 - spr->rx_jmb_cons_idx; cpycnt = min(cpycnt, tp->rx_jmb_ring_mask + 1 - dpr->rx_jmb_prod_idx); si = spr->rx_jmb_cons_idx; di = dpr->rx_jmb_prod_idx; for (i = di; i < di + cpycnt; i++) { if (dpr->rx_jmb_buffers[i].data) { cpycnt = i - di; err = -ENOSPC; break; } } if (!cpycnt) break; /* Ensure that updates to the rx_jmb_buffers ring and the * shadowed hardware producer ring from tg3_recycle_skb() are * ordered correctly WRT the skb check above. */ smp_rmb(); memcpy(&dpr->rx_jmb_buffers[di], &spr->rx_jmb_buffers[si], cpycnt * sizeof(struct ring_info)); for (i = 0; i < cpycnt; i++, di++, si++) { struct tg3_rx_buffer_desc *sbd, *dbd; sbd = &spr->rx_jmb[si].std; dbd = &dpr->rx_jmb[di].std; dbd->addr_hi = sbd->addr_hi; dbd->addr_lo = sbd->addr_lo; } spr->rx_jmb_cons_idx = (spr->rx_jmb_cons_idx + cpycnt) & tp->rx_jmb_ring_mask; dpr->rx_jmb_prod_idx = (dpr->rx_jmb_prod_idx + cpycnt) & tp->rx_jmb_ring_mask; } return err; } Commit Message: tg3: fix length overflow in VPD firmware parsing Commit 184b89044fb6e2a74611dafa69b1dce0d98612c6 ("tg3: Use VPD fw version when present") introduced VPD parsing that contained a potential length overflow. Limit the hardware's reported firmware string length (max 255 bytes) to stay inside the driver's firmware string length (32 bytes). On overflow, truncate the formatted firmware string instead of potentially overwriting portions of the tg3 struct. http://cansecwest.com/slides/2013/PrivateCore%20CSW%202013.pdf Signed-off-by: Kees Cook <keescook@chromium.org> Reported-by: Oded Horovitz <oded@privatecore.com> Reported-by: Brad Spengler <spender@grsecurity.net> Cc: stable@vger.kernel.org Cc: Matt Carlson <mcarlson@broadcom.com> Signed-off-by: David S. Miller <davem@davemloft.net> CWE ID: CWE-119
0
32,736
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: void WebLocalFrameImpl::SetIsolatedWorldSecurityOrigin( int world_id, const WebSecurityOrigin& security_origin) { DCHECK(GetFrame()); DOMWrapperWorld::SetIsolatedWorldSecurityOrigin(world_id, security_origin.Get()); } Commit Message: Inherit CSP when we inherit the security origin This prevents attacks that use main window navigation to get out of the existing csp constraints such as the related bug Bug: 747847 Change-Id: I1e57b50da17f65d38088205b0a3c7c49ef2ae4d8 Reviewed-on: https://chromium-review.googlesource.com/592027 Reviewed-by: Mike West <mkwst@chromium.org> Commit-Queue: Andy Paicu <andypaicu@chromium.org> Cr-Commit-Position: refs/heads/master@{#492333} CWE ID: CWE-732
0
134,409
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: static void addModuleArgument(sqlite3 *db, Table *pTable, char *zArg){ int nBytes = sizeof(char *)*(2+pTable->nModuleArg); char **azModuleArg; azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes); if( azModuleArg==0 ){ sqlite3DbFree(db, zArg); }else{ int i = pTable->nModuleArg++; azModuleArg[i] = zArg; azModuleArg[i+1] = 0; pTable->azModuleArg = azModuleArg; } } Commit Message: sqlite: safely move pointer values through SQL. This lands https://www.sqlite.org/src/timeline?c=d6a44b35 in third_party/sqlite/src/ and third_party/sqlite/patches/0013-Add-new-interfaces-sqlite3_bind_pointer-sqlite3_resu.patch and re-generates third_party/sqlite/amalgamation/* using the script at third_party/sqlite/google_generate_amalgamation.sh. The CL also adds a layout test that verifies the patch works as intended. BUG=742407 Change-Id: I2e1a457459cd2e975e6241b630e7b79c82545981 Reviewed-on: https://chromium-review.googlesource.com/572976 Reviewed-by: Chris Mumford <cmumford@chromium.org> Commit-Queue: Victor Costan <pwnall@chromium.org> Cr-Commit-Position: refs/heads/master@{#487275} CWE ID: CWE-119
0
136,279
Analyze the following code, commit message, and CWE ID. Determine whether it has a vulnerability. If it does, return '1'; if it doesn't, return '0'.
Code: GURL CreateResource(const std::string& content, const std::string& file_ext) { base::FilePath path; EXPECT_TRUE(base::CreateTemporaryFile(&path)); EXPECT_EQ(static_cast<int>(content.size()), base::WriteFile(path, content.c_str(), content.size())); base::FilePath path_with_extension; path_with_extension = path.AddExtension(FILE_PATH_LITERAL(file_ext)); EXPECT_TRUE(base::Move(path, path_with_extension)); return net::FilePathToFileURL(path_with_extension); } Commit Message: Revert "Don't sniff HTML from documents delivered via the file protocol" This reverts commit 3519e867dc606437f804561f889d7ed95b95876a. Reason for revert: crbug.com/786150. Application compatibility for Android WebView applications means we need to allow sniffing on that platform. Original change's description: > Don't sniff HTML from documents delivered via the file protocol > > To reduce attack surface, Chrome should not MIME-sniff to text/html for > any document delivered via the file protocol. This change only impacts > the file protocol (documents served via HTTP/HTTPS/etc are unaffected). > > Bug: 777737 > Cq-Include-Trybots: master.tryserver.chromium.android:android_cronet_tester;master.tryserver.chromium.mac:ios-simulator-cronet > Change-Id: I7086454356b8d2d092be9e1bca0f5ff6dd3b62c0 > Reviewed-on: https://chromium-review.googlesource.com/751402 > Reviewed-by: Ben Wells <benwells@chromium.org> > Reviewed-by: Sylvain Defresne <sdefresne@chromium.org> > Reviewed-by: Achuith Bhandarkar <achuith@chromium.org> > Reviewed-by: Asanka Herath <asanka@chromium.org> > Reviewed-by: Matt Menke <mmenke@chromium.org> > Commit-Queue: Eric Lawrence <elawrence@chromium.org> > Cr-Commit-Position: refs/heads/master@{#514372} TBR=achuith@chromium.org,benwells@chromium.org,mmenke@chromium.org,sdefresne@chromium.org,asanka@chromium.org,elawrence@chromium.org # Not skipping CQ checks because original CL landed > 1 day ago. Bug: 777737 Change-Id: I864ae060ce3277d41ea257ae75e0b80c51f3ea98 Cq-Include-Trybots: master.tryserver.chromium.android:android_cronet_tester;master.tryserver.chromium.mac:ios-simulator-cronet Reviewed-on: https://chromium-review.googlesource.com/790790 Reviewed-by: Eric Lawrence <elawrence@chromium.org> Reviewed-by: Matt Menke <mmenke@chromium.org> Commit-Queue: Eric Lawrence <elawrence@chromium.org> Cr-Commit-Position: refs/heads/master@{#519347} CWE ID:
1
172,738