{"code": "function apply(changes, target, modify) {\n var obj, clone;\n if (modify) {\n obj = target;\n } else {\n clone = require('udc');\n obj = clone(target);\n }\n changes.forEach(function (ch) {\n var ptr, keys, len;\n switch (ch.type) {\n case 'put':\n ptr = obj;\n keys = ch.key;\n len = keys.length;\n if (len) {\n keys.forEach(function (prop, i) {\n if (!(prop in ptr)) {\n ptr[prop] = {};\n }\n\n if (i < len - 1) {\n ptr = ptr[prop];\n } else {\n ptr[prop] = ch.value;\n }\n });\n } else {\n obj = ch.value;\n }\n break;\n\n case 'del':\n ptr = obj;\n keys = ch.key;\n len = keys.length;\n if (len) {\n keys.forEach(function (prop, i) {\n if (!(prop in ptr)) {\n ptr[prop] = {};\n }\n\n if (i < len - 1) {\n ptr = ptr[prop];\n } else {\n if (Array.isArray(ptr)) {\n ptr.splice(parseInt(prop, 10), 1);\n } else {\n delete ptr[prop];\n }\n }\n });\n } else {\n obj = null;\n }\n break;\n }\n });\n return obj;\n}", "label_name": "CWE-1321", "label": 2} {"code": "\tfunction checkObj(instance,objTypeDef,path,additionalProp){\n\n\t\tif(typeof objTypeDef =='object'){\n\t\t\tif(typeof instance != 'object' || instance instanceof Array){\n\t\t\t\terrors.push({property:path,message:\"an object is required\"});\n\t\t\t}\n\t\t\t\n\t\t\tfor(var i in objTypeDef){ \n\t\t\t\tif(objTypeDef.hasOwnProperty(i)){\n\t\t\t\t\tvar value = instance[i];\n\t\t\t\t\t// skip _not_ specified properties\n\t\t\t\t\tif (value === undefined && options.existingOnly) continue;\n\t\t\t\t\tvar propDef = objTypeDef[i];\n\t\t\t\t\t// set default\n\t\t\t\t\tif(value === undefined && propDef[\"default\"]){\n\t\t\t\t\t\tvalue = instance[i] = propDef[\"default\"];\n\t\t\t\t\t}\n\t\t\t\t\tif(options.coerce && i in instance){\n\t\t\t\t\t\tvalue = instance[i] = options.coerce(value, propDef);\n\t\t\t\t\t}\n\t\t\t\t\tcheckProp(value,propDef,path,i);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(i in instance){\n\t\t\tif(instance.hasOwnProperty(i) && !(i.charAt(0) == '_' && i.charAt(1) == '_') && objTypeDef && !objTypeDef[i] && additionalProp===false){\n\t\t\t\tif (options.filter) {\n\t\t\t\t\tdelete instance[i];\n\t\t\t\t\tcontinue;\n\t\t\t\t} else {\n\t\t\t\t\terrors.push({property:path,message:\"The property \" + i +\n\t\t\t\t\t\t\" is not defined in the schema and the schema does not allow additional properties\"});\n\t\t\t\t}\n\t\t\t}\n\t\t\tvar requires = objTypeDef && objTypeDef[i] && objTypeDef[i].requires;\n\t\t\tif(requires && !(requires in instance)){\n\t\t\t\terrors.push({property:path,message:\"the presence of the property \" + i + \" requires that \" + requires + \" also be present\"});\n\t\t\t}\n\t\t\tvalue = instance[i];\n\t\t\tif(additionalProp && (!(objTypeDef && typeof objTypeDef == 'object') || !(i in objTypeDef))){\n\t\t\t\tif(options.coerce){\n\t\t\t\t\tvalue = instance[i] = options.coerce(value, additionalProp);\n\t\t\t\t}\n\t\t\t\tcheckProp(value,additionalProp,path,i);\n\t\t\t}\n\t\t\tif(!_changing && value && value.$schema){\n\t\t\t\terrors = errors.concat(checkProp(value,value.$schema,path,i));\n\t\t\t}\n\t\t}\n\t\treturn errors;\n\t}", "label_name": "CWE-1321", "label": 2} {"code": "void luaT_getvarargs (lua_State *L, CallInfo *ci, StkId where, int wanted) {\n int i;\n int nextra = ci->u.l.nextraargs;\n if (wanted < 0) {\n wanted = nextra; /* get all extra arguments available */\n checkstackp(L, nextra, where); /* ensure stack space */\n L->top = where + nextra; /* next instruction will need top */\n }\n for (i = 0; i < wanted && i < nextra; i++)\n setobjs2s(L, where + i, ci->func - nextra + i);\n for (; i < wanted; i++) /* complete required results with nil */\n setnilvalue(s2v(where + i));\n}", "label_name": "CWE-416", "label": 5} {"code": "static void clear_evtchn_to_irq_row(unsigned row)\n{\n\tunsigned col;\n\n\tfor (col = 0; col < EVTCHN_PER_ROW; col++)\n\t\tevtchn_to_irq[row][col] = -1;\n}", "label_name": "CWE-416", "label": 5} {"code": "clear_evalarg(evalarg_T *evalarg, exarg_T *eap)\n{\n if (evalarg != NULL)\n {\n\tif (evalarg->eval_tofree != NULL)\n\t{\n\t if (eap != NULL)\n\t {\n\t\t// We may need to keep the original command line, e.g. for\n\t\t// \":let\" it has the variable names. But we may also need the\n\t\t// new one, \"nextcmd\" points into it. Keep both.\n\t\tvim_free(eap->cmdline_tofree);\n\t\teap->cmdline_tofree = *eap->cmdlinep;\n\t\t*eap->cmdlinep = evalarg->eval_tofree;\n\t }\n\t else\n\t\tvim_free(evalarg->eval_tofree);\n\t evalarg->eval_tofree = NULL;\n\t}\n\n\tga_clear_strings(&evalarg->eval_tofree_ga);\n\tVIM_CLEAR(evalarg->eval_tofree_lambda);\n }\n}", "label_name": "CWE-416", "label": 5} {"code": "static int adis_update_scan_mode_burst(struct iio_dev *indio_dev,\n\tconst unsigned long *scan_mask)\n{\n\tstruct adis *adis = iio_device_get_drvdata(indio_dev);\n\tunsigned int burst_length;\n\tu8 *tx;\n\n\t/* All but the timestamp channel */\n\tburst_length = (indio_dev->num_channels - 1) * sizeof(u16);\n\tburst_length += adis->burst->extra_len;\n\n\tadis->xfer = kcalloc(2, sizeof(*adis->xfer), GFP_KERNEL);\n\tif (!adis->xfer)\n\t\treturn -ENOMEM;\n\n\tadis->buffer = kzalloc(burst_length + sizeof(u16), GFP_KERNEL);\n\tif (!adis->buffer)\n\t\treturn -ENOMEM;\n\n\ttx = adis->buffer + burst_length;\n\ttx[0] = ADIS_READ_REG(adis->burst->reg_cmd);\n\ttx[1] = 0;\n\n\tadis->xfer[0].tx_buf = tx;\n\tadis->xfer[0].bits_per_word = 8;\n\tadis->xfer[0].len = 2;\n\tadis->xfer[1].rx_buf = adis->buffer;\n\tadis->xfer[1].bits_per_word = 8;\n\tadis->xfer[1].len = burst_length;\n\n\tspi_message_init(&adis->msg);\n\tspi_message_add_tail(&adis->xfer[0], &adis->msg);\n\tspi_message_add_tail(&adis->xfer[1], &adis->msg);\n\n\treturn 0;\n}", "label_name": "CWE-401", "label": 7} {"code": "ASC_destroyAssociation(T_ASC_Association ** association)\n{\n OFCondition cond = EC_Normal;\n\n /* don't worry if already destroyed */\n if (association == NULL) return EC_Normal;\n if (*association == NULL) return EC_Normal;\n\n if ((*association)->DULassociation != NULL) {\n ASC_dropAssociation(*association);\n }\n\n if ((*association)->params != NULL) {\n cond = ASC_destroyAssociationParameters(&(*association)->params);\n if (cond.bad()) return cond;\n }\n\n if ((*association)->sendPDVBuffer != NULL)\n free((*association)->sendPDVBuffer);\n\n free(*association);\n *association = NULL;\n\n return EC_Normal;\n}", "label_name": "CWE-401", "label": 7} {"code": "vips_foreign_load_gif_scan_image( VipsForeignLoadGif *gif ) \n{\n\tVipsObjectClass *class = VIPS_OBJECT_GET_CLASS( gif );\n\tGifFileType *file = gif->file;\n\tColorMapObject *map = file->Image.ColorMap ?\n\t\tfile->Image.ColorMap : file->SColorMap;\n\n\tGifByteType *extension;\n\n\tif( DGifGetImageDesc( gif->file ) == GIF_ERROR ) {\n\t\tvips_foreign_load_gif_error( gif ); \n\t\treturn( -1 );\n\t}\n\n\t/* Check that the frame looks sane. Perhaps giflib checks\n\t * this for us.\n\t */\n\tif( file->Image.Left < 0 ||\n\t\tfile->Image.Width < 1 ||\n\t\tfile->Image.Width > 10000 ||\n\t\tfile->Image.Left + file->Image.Width > file->SWidth ||\n\t\tfile->Image.Top < 0 ||\n\t\tfile->Image.Height < 1 ||\n\t\tfile->Image.Height > 10000 ||\n\t\tfile->Image.Top + file->Image.Height > file->SHeight ) {\n\t\tvips_error( class->nickname, \"%s\", _( \"bad frame size\" ) ); \n\t\treturn( -1 ); \n\t}\n\n\t/* Test for a non-greyscale colourmap for this frame.\n\t */\n\tif( !gif->has_colour &&\n\t\tmap ) {\n\t\tint i;\n\n\t\tfor( i = 0; i < map->ColorCount; i++ ) \n\t\t\tif( map->Colors[i].Red != map->Colors[i].Green ||\n\t\t\t\tmap->Colors[i].Green != map->Colors[i].Blue ) {\n\t\t\t\tgif->has_colour = TRUE;\n\t\t\t\tbreak;\n\t\t\t}\n\t}\n\n\t/* Step over compressed image data.\n\t */\n\tdo {\n\t\tif( vips_foreign_load_gif_code_next( gif, &extension ) ) \n\t\t\treturn( -1 );\n\t} while( extension != NULL );\n\n\treturn( 0 );\n}", "label_name": "CWE-416", "label": 5} {"code": "BGD_DECLARE(void) gdImageWebp (gdImagePtr im, FILE * outFile)\n{\n\tgdIOCtx *out = gdNewFileCtx(outFile);\n\tif (out == NULL) {\n\t\treturn;\n\t}\n\tgdImageWebpCtx(im, out, -1);\n\tout->gd_free(out);\n}", "label_name": "CWE-415", "label": 4} {"code": "njs_function_frame_invoke(njs_vm_t *vm, njs_value_t *retval)\n{\n njs_native_frame_t *frame;\n\n frame = vm->top_frame;\n frame->retval = retval;\n\n if (njs_function_object_type(vm, frame->function)\n == NJS_OBJ_TYPE_ASYNC_FUNCTION)\n {\n return njs_async_function_frame_invoke(vm, retval);\n }\n\n if (frame->native) {\n return njs_function_native_call(vm);\n\n } else {\n return njs_function_lambda_call(vm);\n }\n}", "label_name": "CWE-416", "label": 5} {"code": "table_regex_match(const char *string, const char *pattern)\n{\n\tregex_t preg;\n\tint\tcflags = REG_EXTENDED|REG_NOSUB;\n\n\tif (strncmp(pattern, \"(?i)\", 4) == 0) {\n\t\tcflags |= REG_ICASE;\n\t\tpattern += 4;\n\t}\n\n\tif (regcomp(&preg, pattern, cflags) != 0)\n\t\treturn (0);\n\n\tif (regexec(&preg, string, 0, NULL, 0) != 0)\n\t\treturn (0);\n\n\treturn (1);\n}", "label_name": "CWE-401", "label": 7} {"code": "PJ_DEF(pj_status_t) pjsip_endpt_send_response( pjsip_endpoint *endpt,\n\t\t\t\t\t pjsip_response_addr *res_addr,\n\t\t\t\t\t pjsip_tx_data *tdata,\n\t\t\t\t\t void *token,\n\t\t\t\t\t pjsip_send_callback cb)\n{\n /* Determine which transports and addresses to send the response,\n * based on Section 18.2.2 of RFC 3261.\n */\n pjsip_send_state *send_state;\n pj_status_t status;\n\n /* Create structure to keep the sending state. */\n send_state = PJ_POOL_ZALLOC_T(tdata->pool, pjsip_send_state);\n send_state->endpt = endpt;\n send_state->tdata = tdata;\n send_state->token = token;\n send_state->app_cb = cb;\n\n if (res_addr->transport != NULL) {\n\tsend_state->cur_transport = res_addr->transport;\n\tpjsip_transport_add_ref(send_state->cur_transport);\n\n\tstatus = pjsip_transport_send( send_state->cur_transport, tdata, \n\t\t\t\t &res_addr->addr,\n\t\t\t\t res_addr->addr_len,\n\t\t\t\t send_state,\n\t\t\t\t &send_response_transport_cb );\n\tif (status == PJ_SUCCESS) {\n\t pj_ssize_t sent = tdata->buf.cur - tdata->buf.start;\n\t send_response_transport_cb(send_state, tdata, sent);\n\t return PJ_SUCCESS;\n\t} else if (status == PJ_EPENDING) {\n\t /* Callback will be called later. */\n\t return PJ_SUCCESS;\n\t} else {\n\t pjsip_transport_dec_ref(send_state->cur_transport);\n\t return status;\n\t}\n } else {\n\t/* Copy the destination host name to TX data */\n\tpj_strdup(tdata->pool, &tdata->dest_info.name, \n\t\t &res_addr->dst_host.addr.host);\n\n\tpjsip_endpt_resolve(endpt, tdata->pool, &res_addr->dst_host, \n\t\t\t send_state, &send_response_resolver_cb);\n\treturn PJ_SUCCESS;\n }\n}", "label_name": "CWE-297", "label": 15} {"code": "static int kvm_ioctl_create_device(struct kvm *kvm,\n\t\t\t\t struct kvm_create_device *cd)\n{\n\tstruct kvm_device_ops *ops = NULL;\n\tstruct kvm_device *dev;\n\tbool test = cd->flags & KVM_CREATE_DEVICE_TEST;\n\tint ret;\n\n\tif (cd->type >= ARRAY_SIZE(kvm_device_ops_table))\n\t\treturn -ENODEV;\n\n\tops = kvm_device_ops_table[cd->type];\n\tif (ops == NULL)\n\t\treturn -ENODEV;\n\n\tif (test)\n\t\treturn 0;\n\n\tdev = kzalloc(sizeof(*dev), GFP_KERNEL);\n\tif (!dev)\n\t\treturn -ENOMEM;\n\n\tdev->ops = ops;\n\tdev->kvm = kvm;\n\n\tmutex_lock(&kvm->lock);\n\tret = ops->create(dev, cd->type);\n\tif (ret < 0) {\n\t\tmutex_unlock(&kvm->lock);\n\t\tkfree(dev);\n\t\treturn ret;\n\t}\n\tlist_add(&dev->vm_node, &kvm->devices);\n\tmutex_unlock(&kvm->lock);\n\n\tif (ops->init)\n\t\tops->init(dev);\n\n\tret = anon_inode_getfd(ops->name, &kvm_device_fops, dev, O_RDWR | O_CLOEXEC);\n\tif (ret < 0) {\n\t\tmutex_lock(&kvm->lock);\n\t\tlist_del(&dev->vm_node);\n\t\tmutex_unlock(&kvm->lock);\n\t\tops->destroy(dev);\n\t\treturn ret;\n\t}\n\n\tkvm_get_kvm(kvm);\n\tcd->fd = ret;\n\treturn 0;\n}", "label_name": "CWE-416", "label": 5} {"code": "win_goto(win_T *wp)\n{\n#ifdef FEAT_CONCEAL\n win_T\t*owp = curwin;\n#endif\n\n#ifdef FEAT_PROP_POPUP\n if (ERROR_IF_ANY_POPUP_WINDOW)\n\treturn;\n if (popup_is_popup(wp))\n {\n\temsg(_(e_not_allowed_to_enter_popup_window));\n\treturn;\n }\n#endif\n if (text_locked())\n {\n\tbeep_flush();\n\ttext_locked_msg();\n\treturn;\n }\n if (curbuf_locked())\n\treturn;\n\n if (wp->w_buffer != curbuf)\n\treset_VIsual_and_resel();\n else if (VIsual_active)\n\twp->w_cursor = curwin->w_cursor;\n\n#ifdef FEAT_GUI\n need_mouse_correct = TRUE;\n#endif\n win_enter(wp, TRUE);\n\n#ifdef FEAT_CONCEAL\n // Conceal cursor line in previous window, unconceal in current window.\n if (win_valid(owp) && owp->w_p_cole > 0 && !msg_scrolled)\n\tredrawWinline(owp, owp->w_cursor.lnum);\n if (curwin->w_p_cole > 0 && !msg_scrolled)\n\tneed_cursor_line_redraw = TRUE;\n#endif\n}", "label_name": "CWE-122", "label": 8} {"code": "usm_free_usmStateReference(void *old)\n{\n struct usmStateReference *old_ref = (struct usmStateReference *) old;\n\n if (old_ref) {\n\n if (old_ref->usr_name_length)\n SNMP_FREE(old_ref->usr_name);\n if (old_ref->usr_engine_id_length)\n SNMP_FREE(old_ref->usr_engine_id);\n if (old_ref->usr_auth_protocol_length)\n SNMP_FREE(old_ref->usr_auth_protocol);\n if (old_ref->usr_priv_protocol_length)\n SNMP_FREE(old_ref->usr_priv_protocol);\n\n if (old_ref->usr_auth_key_length && old_ref->usr_auth_key) {\n SNMP_ZERO(old_ref->usr_auth_key, old_ref->usr_auth_key_length);\n SNMP_FREE(old_ref->usr_auth_key);\n }\n if (old_ref->usr_priv_key_length && old_ref->usr_priv_key) {\n SNMP_ZERO(old_ref->usr_priv_key, old_ref->usr_priv_key_length);\n SNMP_FREE(old_ref->usr_priv_key);\n }\n\n SNMP_ZERO(old_ref, sizeof(*old_ref));\n SNMP_FREE(old_ref);\n\n }\n\n} /* end usm_free_usmStateReference() */", "label_name": "CWE-415", "label": 4} {"code": "int snd_ctl_add(struct snd_card *card, struct snd_kcontrol *kcontrol)\n{\n\tstruct snd_ctl_elem_id id;\n\tunsigned int idx;\n\tint err = -EINVAL;\n\n\tif (! kcontrol)\n\t\treturn err;\n\tif (snd_BUG_ON(!card || !kcontrol->info))\n\t\tgoto error;\n\tid = kcontrol->id;\n\tdown_write(&card->controls_rwsem);\n\tif (snd_ctl_find_id(card, &id)) {\n\t\tup_write(&card->controls_rwsem);\n\t\tdev_err(card->dev, \"control %i:%i:%i:%s:%i is already present\\n\",\n\t\t\t\t\tid.iface,\n\t\t\t\t\tid.device,\n\t\t\t\t\tid.subdevice,\n\t\t\t\t\tid.name,\n\t\t\t\t\tid.index);\n\t\terr = -EBUSY;\n\t\tgoto error;\n\t}\n\tif (snd_ctl_find_hole(card, kcontrol->count) < 0) {\n\t\tup_write(&card->controls_rwsem);\n\t\terr = -ENOMEM;\n\t\tgoto error;\n\t}\n\tlist_add_tail(&kcontrol->list, &card->controls);\n\tcard->controls_count += kcontrol->count;\n\tkcontrol->id.numid = card->last_numid + 1;\n\tcard->last_numid += kcontrol->count;\n\tup_write(&card->controls_rwsem);\n\tfor (idx = 0; idx < kcontrol->count; idx++, id.index++, id.numid++)\n\t\tsnd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_ADD, &id);\n\treturn 0;\n\n error:\n\tsnd_ctl_free_one(kcontrol);\n\treturn err;\n}", "label_name": "CWE-416", "label": 5} {"code": "init_ccline(int firstc, int indent)\n{\n ccline.overstrike = FALSE;\t\t // always start in insert mode\n\n /*\n * set some variables for redrawcmd()\n */\n ccline.cmdfirstc = (firstc == '@' ? 0 : firstc);\n ccline.cmdindent = (firstc > 0 ? indent : 0);\n\n // alloc initial ccline.cmdbuff\n alloc_cmdbuff(exmode_active ? 250 : indent + 1);\n if (ccline.cmdbuff == NULL)\n\treturn FAIL;\n ccline.cmdlen = ccline.cmdpos = 0;\n ccline.cmdbuff[0] = NUL;\n sb_text_start_cmdline();\n\n // autoindent for :insert and :append\n if (firstc <= 0)\n {\n\tvim_memset(ccline.cmdbuff, ' ', indent);\n\tccline.cmdbuff[indent] = NUL;\n\tccline.cmdpos = indent;\n\tccline.cmdspos = indent;\n\tccline.cmdlen = indent;\n }\n\n return OK;\n}", "label_name": "CWE-122", "label": 8} {"code": "reg_match_visual(void)\n{\n pos_T\ttop, bot;\n linenr_T lnum;\n colnr_T\tcol;\n win_T\t*wp = rex.reg_win == NULL ? curwin : rex.reg_win;\n int\t\tmode;\n colnr_T\tstart, end;\n colnr_T\tstart2, end2;\n colnr_T\tcols;\n colnr_T\tcurswant;\n\n // Check if the buffer is the current buffer.\n if (rex.reg_buf != curbuf || VIsual.lnum == 0)\n\treturn FALSE;\n\n if (VIsual_active)\n {\n\tif (LT_POS(VIsual, wp->w_cursor))\n\t{\n\t top = VIsual;\n\t bot = wp->w_cursor;\n\t}\n\telse\n\t{\n\t top = wp->w_cursor;\n\t bot = VIsual;\n\t}\n\tmode = VIsual_mode;\n\tcurswant = wp->w_curswant;\n }\n else\n {\n\tif (LT_POS(curbuf->b_visual.vi_start, curbuf->b_visual.vi_end))\n\t{\n\t top = curbuf->b_visual.vi_start;\n\t bot = curbuf->b_visual.vi_end;\n\t}\n\telse\n\t{\n\t top = curbuf->b_visual.vi_end;\n\t bot = curbuf->b_visual.vi_start;\n\t}\n\tmode = curbuf->b_visual.vi_mode;\n\tcurswant = curbuf->b_visual.vi_curswant;\n }\n lnum = rex.lnum + rex.reg_firstlnum;\n if (lnum < top.lnum || lnum > bot.lnum)\n\treturn FALSE;\n\n if (mode == 'v')\n {\n\tcol = (colnr_T)(rex.input - rex.line);\n\tif ((lnum == top.lnum && col < top.col)\n\t\t|| (lnum == bot.lnum && col >= bot.col + (*p_sel != 'e')))\n\t return FALSE;\n }\n else if (mode == Ctrl_V)\n {\n\tgetvvcol(wp, &top, &start, NULL, &end);\n\tgetvvcol(wp, &bot, &start2, NULL, &end2);\n\tif (start2 < start)\n\t start = start2;\n\tif (end2 > end)\n\t end = end2;\n\tif (top.col == MAXCOL || bot.col == MAXCOL || curswant == MAXCOL)\n\t end = MAXCOL;\n\tcols = win_linetabsize(wp, rex.line, (colnr_T)(rex.input - rex.line));\n\tif (cols < start || cols > end - (*p_sel == 'e'))\n\t return FALSE;\n }\n return TRUE;\n}", "label_name": "CWE-416", "label": 5} {"code": "void rose_stop_idletimer(struct sock *sk)\n{\n\tdel_timer(&rose_sk(sk)->idletimer);\n}", "label_name": "CWE-416", "label": 5} {"code": "static void cil_reset_classperms_set(struct cil_classperms_set *cp_set)\n{\n\tcil_reset_classpermission(cp_set->set);\n}", "label_name": "CWE-416", "label": 5} {"code": "static int hci_uart_set_proto(struct hci_uart *hu, int id)\n{\n\tconst struct hci_uart_proto *p;\n\tint err;\n\n\tp = hci_uart_get_proto(id);\n\tif (!p)\n\t\treturn -EPROTONOSUPPORT;\n\n\thu->proto = p;\n\tset_bit(HCI_UART_PROTO_READY, &hu->flags);\n\n\terr = hci_uart_register_dev(hu);\n\tif (err) {\n\t\tclear_bit(HCI_UART_PROTO_READY, &hu->flags);\n\t\treturn err;\n\t}\n\n\treturn 0;\n}", "label_name": "CWE-416", "label": 5} {"code": "gen_values(codegen_scope *s, node *t, int val, int limit)\n{\n int n = 0;\n int first = 1;\n int slimit = GEN_VAL_STACK_MAX;\n\n if (limit == 0) limit = GEN_LIT_ARY_MAX;\n if (cursp() >= slimit) slimit = INT16_MAX;\n\n if (!val) {\n while (t) {\n codegen(s, t->car, NOVAL);\n n++;\n t = t->cdr;\n }\n return n;\n }\n\n while (t) {\n int is_splat = nint(t->car->car) == NODE_SPLAT;\n\n if (is_splat || n > limit || cursp() >= slimit) { /* flush stack */\n pop_n(n);\n if (first) {\n if (n == 0) {\n genop_1(s, OP_LOADNIL, cursp());\n }\n else {\n genop_2(s, OP_ARRAY, cursp(), n);\n }\n push();\n first = 0;\n limit = GEN_LIT_ARY_MAX;\n }\n else if (n > 0) {\n pop();\n genop_2(s, OP_ARYPUSH, cursp(), n);\n push();\n }\n n = 0;\n }\n codegen(s, t->car, val);\n if (is_splat) {\n pop(); pop();\n genop_1(s, OP_ARYCAT, cursp());\n push();\n }\n else {\n n++;\n }\n t = t->cdr;\n }\n if (!first) {\n pop();\n if (n > 0) {\n pop_n(n);\n genop_2(s, OP_ARYPUSH, cursp(), n);\n }\n return -1; /* variable length */\n }\n return n;\n}", "label_name": "CWE-122", "label": 8} {"code": "GF_Err infe_box_read(GF_Box *s, GF_BitStream *bs)\n{\n\tchar *buf;\n\tu32 buf_len, i, string_len, string_start;\n\tGF_ItemInfoEntryBox *ptr = (GF_ItemInfoEntryBox *)s;\n\n\tISOM_DECREASE_SIZE(ptr, 4);\n\tptr->item_ID = gf_bs_read_u16(bs);\n\tptr->item_protection_index = gf_bs_read_u16(bs);\n\n\tif (ptr->version == 2) {\n\t\tISOM_DECREASE_SIZE(ptr, 4);\n\t\tptr->item_type = gf_bs_read_u32(bs);\n\t}\n\tbuf_len = (u32) (ptr->size);\n\tbuf = (char*)gf_malloc(buf_len);\n\tif (!buf) return GF_OUT_OF_MEM;\n\tif (buf_len != gf_bs_read_data(bs, buf, buf_len)) {\n\t\tgf_free(buf);\n\t\treturn GF_ISOM_INVALID_FILE;\n\t}\n\tstring_len = 1;\n\tstring_start = 0;\n\tfor (i = 0; i < buf_len; i++) {\n\t\tif (buf[i] == 0) {\n\t\t\tif (!ptr->item_name) {\n\t\t\t\tptr->item_name = (char*)gf_malloc(sizeof(char)*string_len);\n\t\t\t\tif (!ptr->item_name) return GF_OUT_OF_MEM;\n\t\t\t\tmemcpy(ptr->item_name, buf+string_start, string_len);\n\t\t\t} else if (!ptr->content_type) {\n\t\t\t\tptr->content_type = (char*)gf_malloc(sizeof(char)*string_len);\n\t\t\t\tif (!ptr->content_type) return GF_OUT_OF_MEM;\n\t\t\t\tmemcpy(ptr->content_type, buf+string_start, string_len);\n\t\t\t} else {\n\t\t\t\tptr->content_encoding = (char*)gf_malloc(sizeof(char)*string_len);\n\t\t\t\tif (!ptr->content_encoding) return GF_OUT_OF_MEM;\n\t\t\t\tmemcpy(ptr->content_encoding, buf+string_start, string_len);\n\t\t\t}\n\t\t\tstring_start += string_len;\n\t\t\tstring_len = 0;\n\t\t\tif (ptr->content_encoding && ptr->version == 1) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tstring_len++;\n\t}\n\tgf_free(buf);\n\tif (!ptr->item_name || (!ptr->content_type && ptr->version < 2)) {\n\t\tGF_LOG(GF_LOG_WARNING, GF_LOG_CONTAINER, (\"[isoff] Infe without name or content type !\\n\"));\n\t}\n\treturn GF_OK;\n}", "label_name": "CWE-401", "label": 7} {"code": "int ipmi_destroy_user(struct ipmi_user *user)\n{\n\t_ipmi_destroy_user(user);\n\n\tcleanup_srcu_struct(&user->release_barrier);\n\tkref_put(&user->refcount, free_user);\n\n\treturn 0;\n}", "label_name": "CWE-416", "label": 5} {"code": "static void cil_reset_perm(struct cil_perm *perm)\n{\n\tcil_reset_classperms_list(perm->classperms);\n}", "label_name": "CWE-416", "label": 5} {"code": "void jbd2_journal_wait_updates(journal_t *journal)\n{\n\ttransaction_t *commit_transaction = journal->j_running_transaction;\n\n\tif (!commit_transaction)\n\t\treturn;\n\n\tspin_lock(&commit_transaction->t_handle_lock);\n\twhile (atomic_read(&commit_transaction->t_updates)) {\n\t\tDEFINE_WAIT(wait);\n\n\t\tprepare_to_wait(&journal->j_wait_updates, &wait,\n\t\t\t\t\tTASK_UNINTERRUPTIBLE);\n\t\tif (atomic_read(&commit_transaction->t_updates)) {\n\t\t\tspin_unlock(&commit_transaction->t_handle_lock);\n\t\t\twrite_unlock(&journal->j_state_lock);\n\t\t\tschedule();\n\t\t\twrite_lock(&journal->j_state_lock);\n\t\t\tspin_lock(&commit_transaction->t_handle_lock);\n\t\t}\n\t\tfinish_wait(&journal->j_wait_updates, &wait);\n\t}\n\tspin_unlock(&commit_transaction->t_handle_lock);\n}", "label_name": "CWE-416", "label": 5} {"code": "regtilde(char_u *source, int magic)\n{\n char_u\t*newsub = source;\n char_u\t*tmpsub;\n char_u\t*p;\n int\t\tlen;\n int\t\tprevlen;\n\n for (p = newsub; *p; ++p)\n {\n\tif ((*p == '~' && magic) || (*p == '\\\\' && *(p + 1) == '~' && !magic))\n\t{\n\t if (reg_prev_sub != NULL)\n\t {\n\t\t// length = len(newsub) - 1 + len(prev_sub) + 1\n\t\tprevlen = (int)STRLEN(reg_prev_sub);\n\t\ttmpsub = alloc(STRLEN(newsub) + prevlen);\n\t\tif (tmpsub != NULL)\n\t\t{\n\t\t // copy prefix\n\t\t len = (int)(p - newsub);\t// not including ~\n\t\t mch_memmove(tmpsub, newsub, (size_t)len);\n\t\t // interpret tilde\n\t\t mch_memmove(tmpsub + len, reg_prev_sub, (size_t)prevlen);\n\t\t // copy postfix\n\t\t if (!magic)\n\t\t\t++p;\t\t\t// back off backslash\n\t\t STRCPY(tmpsub + len + prevlen, p + 1);\n\n\t\t if (newsub != source)\t// already allocated newsub\n\t\t\tvim_free(newsub);\n\t\t newsub = tmpsub;\n\t\t p = newsub + len + prevlen;\n\t\t}\n\t }\n\t else if (magic)\n\t\tSTRMOVE(p, p + 1);\t// remove '~'\n\t else\n\t\tSTRMOVE(p, p + 2);\t// remove '\\~'\n\t --p;\n\t}\n\telse\n\t{\n\t if (*p == '\\\\' && p[1])\t\t// skip escaped characters\n\t\t++p;\n\t if (has_mbyte)\n\t\tp += (*mb_ptr2len)(p) - 1;\n\t}\n }\n\n vim_free(reg_prev_sub);\n if (newsub != source)\t// newsub was allocated, just keep it\n\treg_prev_sub = newsub;\n else\t\t\t// no ~ found, need to save newsub\n\treg_prev_sub = vim_strsave(newsub);\n return newsub;\n}", "label_name": "CWE-416", "label": 5} {"code": "int crypto_reportstat(struct sk_buff *in_skb, struct nlmsghdr *in_nlh,\n\t\t struct nlattr **attrs)\n{\n\tstruct net *net = sock_net(in_skb->sk);\n\tstruct crypto_user_alg *p = nlmsg_data(in_nlh);\n\tstruct crypto_alg *alg;\n\tstruct sk_buff *skb;\n\tstruct crypto_dump_info info;\n\tint err;\n\n\tif (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))\n\t\treturn -EINVAL;\n\n\talg = crypto_alg_match(p, 0);\n\tif (!alg)\n\t\treturn -ENOENT;\n\n\terr = -ENOMEM;\n\tskb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);\n\tif (!skb)\n\t\tgoto drop_alg;\n\n\tinfo.in_skb = in_skb;\n\tinfo.out_skb = skb;\n\tinfo.nlmsg_seq = in_nlh->nlmsg_seq;\n\tinfo.nlmsg_flags = 0;\n\n\terr = crypto_reportstat_alg(alg, &info);\n\ndrop_alg:\n\tcrypto_mod_put(alg);\n\n\tif (err)\n\t\treturn err;\n\n\treturn nlmsg_unicast(net->crypto_nlsk, skb, NETLINK_CB(in_skb).portid);\n}", "label_name": "CWE-401", "label": 7} {"code": "void vmacache_flush_all(struct mm_struct *mm)\n{\n\tstruct task_struct *g, *p;\n\n\tcount_vm_vmacache_event(VMACACHE_FULL_FLUSHES);\n\n\t/*\n\t * Single threaded tasks need not iterate the entire\n\t * list of process. We can avoid the flushing as well\n\t * since the mm's seqnum was increased and don't have\n\t * to worry about other threads' seqnum. Current's\n\t * flush will occur upon the next lookup.\n\t */\n\tif (atomic_read(&mm->mm_users) == 1)\n\t\treturn;\n\n\trcu_read_lock();\n\tfor_each_process_thread(g, p) {\n\t\t/*\n\t\t * Only flush the vmacache pointers as the\n\t\t * mm seqnum is already set and curr's will\n\t\t * be set upon invalidation when the next\n\t\t * lookup is done.\n\t\t */\n\t\tif (mm == p->mm)\n\t\t\tvmacache_flush(p);\n\t}\n\trcu_read_unlock();\n}", "label_name": "CWE-416", "label": 5} {"code": "eval_next_line(char_u *arg, evalarg_T *evalarg)\n{\n garray_T\t*gap = &evalarg->eval_ga;\n char_u\t*line;\n\n if (arg != NULL)\n {\n\tif (*arg == NL)\n\t return newline_skip_comments(arg);\n\t// Truncate before a trailing comment, so that concatenating the lines\n\t// won't turn the rest into a comment.\n\tif (*skipwhite(arg) == '#')\n\t *arg = NUL;\n }\n\n if (evalarg->eval_cookie != NULL)\n\tline = evalarg->eval_getline(0, evalarg->eval_cookie, 0,\n\t\t\t\t\t\t\t GETLINE_CONCAT_ALL);\n else\n\tline = next_line_from_context(evalarg->eval_cctx, TRUE);\n if (line == NULL)\n\treturn NULL;\n\n ++evalarg->eval_break_count;\n if (gap->ga_itemsize > 0 && ga_grow(gap, 1) == OK)\n {\n\tchar_u *p = skipwhite(line);\n\n\t// Going to concatenate the lines after parsing. For an empty or\n\t// comment line use an empty string.\n\tif (*p == NUL || vim9_comment_start(p))\n\t{\n\t vim_free(line);\n\t line = vim_strsave((char_u *)\"\");\n\t}\n\n\t((char_u **)gap->ga_data)[gap->ga_len] = line;\n\t++gap->ga_len;\n }\n else if (evalarg->eval_cookie != NULL)\n {\n\tvim_free(evalarg->eval_tofree);\n\tevalarg->eval_tofree = line;\n }\n\n // Advanced to the next line, \"arg\" no longer points into the previous\n // line.\n evalarg->eval_using_cmdline = FALSE;\n return skipwhite(line);\n}", "label_name": "CWE-416", "label": 5} {"code": "const char * util_acl_to_str(const sc_acl_entry_t *e)\n{\n\tstatic char line[80], buf[20];\n\tunsigned int acl;\n\n\tif (e == NULL)\n\t\treturn \"N/A\";\n\tline[0] = 0;\n\twhile (e != NULL) {\n\t\tacl = e->method;\n\n\t\tswitch (acl) {\n\t\tcase SC_AC_UNKNOWN:\n\t\t\treturn \"N/A\";\n\t\tcase SC_AC_NEVER:\n\t\t\treturn \"NEVR\";\n\t\tcase SC_AC_NONE:\n\t\t\treturn \"NONE\";\n\t\tcase SC_AC_CHV:\n\t\t\tstrcpy(buf, \"CHV\");\n\t\t\tif (e->key_ref != SC_AC_KEY_REF_NONE)\n\t\t\t\tsprintf(buf + 3, \"%d\", e->key_ref);\n\t\t\tbreak;\n\t\tcase SC_AC_TERM:\n\t\t\tstrcpy(buf, \"TERM\");\n\t\t\tbreak;\n\t\tcase SC_AC_PRO:\n\t\t\tstrcpy(buf, \"PROT\");\n\t\t\tbreak;\n\t\tcase SC_AC_AUT:\n\t\t\tstrcpy(buf, \"AUTH\");\n\t\t\tif (e->key_ref != SC_AC_KEY_REF_NONE)\n\t\t\t\tsprintf(buf + 4, \"%d\", e->key_ref);\n\t\t\tbreak;\n\t\tcase SC_AC_SEN:\n\t\t\tstrcpy(buf, \"Sec.Env. \");\n\t\t\tif (e->key_ref != SC_AC_KEY_REF_NONE)\n\t\t\t\tsprintf(buf + 3, \"#%d\", e->key_ref);\n\t\t\tbreak;\n\t\tcase SC_AC_SCB:\n\t\t\tstrcpy(buf, \"Sec.ControlByte \");\n\t\t\tif (e->key_ref != SC_AC_KEY_REF_NONE)\n\t\t\t\tsprintf(buf + 3, \"Ox%X\", e->key_ref);\n\t\t\tbreak;\n\t\tcase SC_AC_IDA:\n\t\t\tstrcpy(buf, \"PKCS#15 AuthID \");\n\t\t\tif (e->key_ref != SC_AC_KEY_REF_NONE)\n\t\t\t\tsprintf(buf + 3, \"#%d\", e->key_ref);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tstrcpy(buf, \"????\");\n\t\t\tbreak;\n\t\t}\n\t\tstrcat(line, buf);\n\t\tstrcat(line, \" \");\n\t\te = e->next;\n\t}\n\tline[strlen(line)-1] = 0; /* get rid of trailing space */\n\treturn line;\n}", "label_name": "CWE-415", "label": 4} {"code": "PJ_DEF(pj_status_t) pjsip_ua_unregister_dlg( pjsip_user_agent *ua,\n\t\t\t\t\t pjsip_dialog *dlg )\n{\n struct dlg_set *dlg_set;\n pjsip_dialog *d;\n\n /* Sanity-check arguments. */\n PJ_ASSERT_RETURN(ua && dlg, PJ_EINVAL);\n\n /* Check that dialog has been registered. */\n PJ_ASSERT_RETURN(dlg->dlg_set, PJ_EINVALIDOP);\n\n /* Lock user agent. */\n pj_mutex_lock(mod_ua.mutex);\n\n /* Find this dialog from the dialog set. */\n dlg_set = (struct dlg_set*) dlg->dlg_set;\n d = dlg_set->dlg_list.next;\n while (d != (pjsip_dialog*)&dlg_set->dlg_list && d != dlg) {\n\td = d->next;\n }\n\n if (d != dlg) {\n\tpj_assert(!\"Dialog is not registered!\");\n\tpj_mutex_unlock(mod_ua.mutex);\n\treturn PJ_EINVALIDOP;\n }\n\n /* Remove this dialog from the list. */\n pj_list_erase(dlg);\n\n /* If dialog list is empty, remove the dialog set from the hash table. */\n if (pj_list_empty(&dlg_set->dlg_list)) {\n\tpj_hash_set_lower(NULL, mod_ua.dlg_table, dlg->local.info->tag.ptr,\n\t\t (unsigned)dlg->local.info->tag.slen, \n\t\t\t dlg->local.tag_hval, NULL);\n\n\t/* Return dlg_set to free nodes. */\n\tpj_list_push_back(&mod_ua.free_dlgset_nodes, dlg_set);\n }\n\n /* Unlock user agent. */\n pj_mutex_unlock(mod_ua.mutex);\n\n /* Done. */\n return PJ_SUCCESS;\n}", "label_name": "CWE-416", "label": 5} {"code": "static ssize_t qrtr_tun_write_iter(struct kiocb *iocb, struct iov_iter *from)\n{\n\tstruct file *filp = iocb->ki_filp;\n\tstruct qrtr_tun *tun = filp->private_data;\n\tsize_t len = iov_iter_count(from);\n\tssize_t ret;\n\tvoid *kbuf;\n\n\tkbuf = kzalloc(len, GFP_KERNEL);\n\tif (!kbuf)\n\t\treturn -ENOMEM;\n\n\tif (!copy_from_iter_full(kbuf, len, from))\n\t\treturn -EFAULT;\n\n\tret = qrtr_endpoint_post(&tun->ep, kbuf, len);\n\n\treturn ret < 0 ? ret : len;\n}", "label_name": "CWE-401", "label": 7} {"code": "PJ_DEF(pj_status_t) pjsip_endpt_send_request_stateless(pjsip_endpoint *endpt, \n\t\t\t\t pjsip_tx_data *tdata,\n\t\t\t\t void *token,\n\t\t\t\t pjsip_send_callback cb)\n{\n pjsip_host_info dest_info;\n pjsip_send_state *stateless_data;\n pj_status_t status;\n\n PJ_ASSERT_RETURN(endpt && tdata, PJ_EINVAL);\n\n /* Get destination name to contact. */\n status = pjsip_process_route_set(tdata, &dest_info);\n if (status != PJ_SUCCESS)\n\treturn status;\n\n /* Keep stateless data. */\n stateless_data = PJ_POOL_ZALLOC_T(tdata->pool, pjsip_send_state);\n stateless_data->token = token;\n stateless_data->endpt = endpt;\n stateless_data->tdata = tdata;\n stateless_data->app_cb = cb;\n\n /* If destination info has not been initialized (this applies for most\n * all requests except CANCEL), resolve destination host. The processing\n * then resumed when the resolving callback is called. For CANCEL, the\n * destination info must have been copied from the original INVITE so\n * proceed to sending the request directly.\n */\n if (tdata->dest_info.addr.count == 0) {\n\t/* Copy the destination host name to TX data */\n\tpj_strdup(tdata->pool, &tdata->dest_info.name, &dest_info.addr.host);\n\n\tpjsip_endpt_resolve( endpt, tdata->pool, &dest_info, stateless_data,\n\t\t\t &stateless_send_resolver_callback);\n } else {\n\tPJ_LOG(5,(THIS_FILE, \"%s: skipping target resolution because \"\n\t \"address is already set\",\n\t\t\t pjsip_tx_data_get_info(tdata)));\n\tstateless_send_resolver_callback(PJ_SUCCESS, stateless_data,\n\t\t\t\t\t &tdata->dest_info.addr);\n }\n return PJ_SUCCESS;\n}", "label_name": "CWE-297", "label": 15} {"code": "static int muscle_list_files(sc_card_t *card, u8 *buf, size_t bufLen)\n{\n\tmuscle_private_t* priv = MUSCLE_DATA(card);\n\tmscfs_t *fs = priv->fs;\n\tint x;\n\tint count = 0;\n\n\tmscfs_check_cache(priv->fs);\n\n\tfor(x = 0; x < fs->cache.size; x++) {\n\t\tu8* oid= fs->cache.array[x].objectId.id;\n\t\tsc_debug(card->ctx, SC_LOG_DEBUG_NORMAL,\n\t\t\t\"FILE: %02X%02X%02X%02X\\n\",\n\t\t\toid[0],oid[1],oid[2],oid[3]);\n\t\tif(0 == memcmp(fs->currentPath, oid, 2)) {\n\t\t\tbuf[0] = oid[2];\n\t\t\tbuf[1] = oid[3];\n\t\t\tif(buf[0] == 0x00 && buf[1] == 0x00) continue; /* No directories/null names outside of root */\n\t\t\tbuf += 2;\n\t\t\tcount+=2;\n\t\t}\n\t}\n\treturn count;\n}", "label_name": "CWE-415", "label": 4} {"code": "tabstop_set(char_u *var, int **array)\n{\n int valcount = 1;\n int t;\n char_u *cp;\n\n if (var[0] == NUL || (var[0] == '0' && var[1] == NUL))\n {\n\t*array = NULL;\n\treturn TRUE;\n }\n\n for (cp = var; *cp != NUL; ++cp)\n {\n\tif (cp == var || cp[-1] == ',')\n\t{\n\t char_u *end;\n\n\t if (strtol((char *)cp, (char **)&end, 10) <= 0)\n\t {\n\t\tif (cp != end)\n\t\t emsg(_(e_positive));\n\t\telse\n\t\t emsg(_(e_invarg));\n\t\treturn FALSE;\n\t }\n\t}\n\n\tif (VIM_ISDIGIT(*cp))\n\t continue;\n\tif (cp[0] == ',' && cp > var && cp[-1] != ',' && cp[1] != NUL)\n\t{\n\t ++valcount;\n\t continue;\n\t}\n\temsg(_(e_invarg));\n\treturn FALSE;\n }\n\n *array = ALLOC_MULT(int, valcount + 1);\n if (*array == NULL)\n\treturn FALSE;\n (*array)[0] = valcount;\n\n t = 1;\n for (cp = var; *cp != NUL;)\n {\n\t(*array)[t++] = atoi((char *)cp);\n\twhile (*cp != NUL && *cp != ',')\n\t ++cp;\n\tif (*cp != NUL)\n\t ++cp;\n }\n\n return TRUE;\n}", "label_name": "CWE-122", "label": 8} {"code": "BGD_DECLARE(void) gdImageWBMPCtx(gdImagePtr image, int fg, gdIOCtx *out)\n{\n\tint x, y, pos;\n\tWbmp *wbmp;\n\n\t/* create the WBMP */\n\tif((wbmp = createwbmp(gdImageSX(image), gdImageSY(image), WBMP_WHITE)) == NULL) {\n\t\tgd_error(\"Could not create WBMP\\n\");\n\t\treturn;\n\t}\n\n\t/* fill up the WBMP structure */\n\tpos = 0;\n\tfor(y = 0; y < gdImageSY(image); y++) {\n\t\tfor(x = 0; x < gdImageSX(image); x++) {\n\t\t\tif(gdImageGetPixel(image, x, y) == fg) {\n\t\t\t\twbmp->bitmap[pos] = WBMP_BLACK;\n\t\t\t}\n\t\t\tpos++;\n\t\t}\n\t}\n\n\t/* write the WBMP to a gd file descriptor */\n\tif(writewbmp(wbmp, &gd_putout, out)) {\n\t\tgd_error(\"Could not save WBMP\\n\");\n\t}\n\n\t/* des submitted this bugfix: gdFree the memory. */\n\tfreewbmp(wbmp);\n}", "label_name": "CWE-415", "label": 4} {"code": "TEST_F(HeaderTableTests, set_capacity) {\n HPACKHeader accept(\"accept-encoding\", \"gzip\");\n uint32_t max = 10;\n uint32_t capacity = accept.bytes() * max;\n HeaderTable table(capacity);\n\n // fill the table\n for (size_t i = 0; i < max; i++) {\n EXPECT_EQ(table.add(accept), true);\n }\n // change capacity\n table.setCapacity(capacity / 2);\n EXPECT_EQ(table.size(), max / 2);\n EXPECT_EQ(table.bytes(), capacity / 2);\n}", "label_name": "CWE-416", "label": 5} {"code": "static unsigned HuffmanTree_makeFromFrequencies(HuffmanTree* tree, const unsigned* frequencies,\n size_t mincodes, size_t numcodes, unsigned maxbitlen)\n{\n unsigned error = 0;\n while(!frequencies[numcodes - 1] && numcodes > mincodes) numcodes--; /*trim zeroes*/\n tree->maxbitlen = maxbitlen;\n tree->numcodes = (unsigned)numcodes; /*number of symbols*/\n tree->lengths = (unsigned*)realloc(tree->lengths, numcodes * sizeof(unsigned));\n if(!tree->lengths) return 83; /*alloc fail*/\n /*initialize all lengths to 0*/\n memset(tree->lengths, 0, numcodes * sizeof(unsigned));\n\n error = lodepng_huffman_code_lengths(tree->lengths, frequencies, numcodes, maxbitlen);\n if(!error) error = HuffmanTree_makeFromLengths2(tree);\n return error;\n}", "label_name": "CWE-401", "label": 7} {"code": "func (m *ContainsNestedMap) Unmarshal(dAtA []byte) error {\n\tl := len(dAtA)\n\tiNdEx := 0\n\tfor iNdEx < l {\n\t\tpreIndex := iNdEx\n\t\tvar wire uint64\n\t\tfor shift := uint(0); ; shift += 7 {\n\t\t\tif shift >= 64 {\n\t\t\t\treturn ErrIntOverflowTheproto3\n\t\t\t}\n\t\t\tif iNdEx >= l {\n\t\t\t\treturn io.ErrUnexpectedEOF\n\t\t\t}\n\t\t\tb := dAtA[iNdEx]\n\t\t\tiNdEx++\n\t\t\twire |= uint64(b&0x7F) << shift\n\t\t\tif b < 0x80 {\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tfieldNum := int32(wire >> 3)\n\t\twireType := int(wire & 0x7)\n\t\tif wireType == 4 {\n\t\t\treturn fmt.Errorf(\"proto: ContainsNestedMap: wiretype end group for non-group\")\n\t\t}\n\t\tif fieldNum <= 0 {\n\t\t\treturn fmt.Errorf(\"proto: ContainsNestedMap: illegal tag %d (wire type %d)\", fieldNum, wire)\n\t\t}\n\t\tswitch fieldNum {\n\t\tdefault:\n\t\t\tiNdEx = preIndex\n\t\t\tskippy, err := skipTheproto3(dAtA[iNdEx:])\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tif skippy < 0 {\n\t\t\t\treturn ErrInvalidLengthTheproto3\n\t\t\t}\n\t\t\tif (iNdEx + skippy) < 0 {\n\t\t\t\treturn ErrInvalidLengthTheproto3\n\t\t\t}\n\t\t\tif (iNdEx + skippy) > l {\n\t\t\t\treturn io.ErrUnexpectedEOF\n\t\t\t}\n\t\t\tm.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...)\n\t\t\tiNdEx += skippy\n\t\t}\n\t}\n\n\tif iNdEx > l {\n\t\treturn io.ErrUnexpectedEOF\n\t}\n\treturn nil\n}", "label_name": "CWE-129", "label": 6} {"code": "func (m *Wilson) Unmarshal(dAtA []byte) error {\n\tl := len(dAtA)\n\tiNdEx := 0\n\tfor iNdEx < l {\n\t\tpreIndex := iNdEx\n\t\tvar wire uint64\n\t\tfor shift := uint(0); ; shift += 7 {\n\t\t\tif shift >= 64 {\n\t\t\t\treturn ErrIntOverflowCastvalue\n\t\t\t}\n\t\t\tif iNdEx >= l {\n\t\t\t\treturn io.ErrUnexpectedEOF\n\t\t\t}\n\t\t\tb := dAtA[iNdEx]\n\t\t\tiNdEx++\n\t\t\twire |= uint64(b&0x7F) << shift\n\t\t\tif b < 0x80 {\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tfieldNum := int32(wire >> 3)\n\t\twireType := int(wire & 0x7)\n\t\tif wireType == 4 {\n\t\t\treturn fmt.Errorf(\"proto: Wilson: wiretype end group for non-group\")\n\t\t}\n\t\tif fieldNum <= 0 {\n\t\t\treturn fmt.Errorf(\"proto: Wilson: illegal tag %d (wire type %d)\", fieldNum, wire)\n\t\t}\n\t\tswitch fieldNum {\n\t\tcase 1:\n\t\t\tif wireType != 0 {\n\t\t\t\treturn fmt.Errorf(\"proto: wrong wireType = %d for field Int64\", wireType)\n\t\t\t}\n\t\t\tvar v int64\n\t\t\tfor shift := uint(0); ; shift += 7 {\n\t\t\t\tif shift >= 64 {\n\t\t\t\t\treturn ErrIntOverflowCastvalue\n\t\t\t\t}\n\t\t\t\tif iNdEx >= l {\n\t\t\t\t\treturn io.ErrUnexpectedEOF\n\t\t\t\t}\n\t\t\t\tb := dAtA[iNdEx]\n\t\t\t\tiNdEx++\n\t\t\t\tv |= int64(b&0x7F) << shift\n\t\t\t\tif b < 0x80 {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t\tm.Int64 = &v\n\t\tdefault:\n\t\t\tiNdEx = preIndex\n\t\t\tskippy, err := skipCastvalue(dAtA[iNdEx:])\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tif skippy < 0 {\n\t\t\t\treturn ErrInvalidLengthCastvalue\n\t\t\t}\n\t\t\tif (iNdEx + skippy) < 0 {\n\t\t\t\treturn ErrInvalidLengthCastvalue\n\t\t\t}\n\t\t\tif (iNdEx + skippy) > l {\n\t\t\t\treturn io.ErrUnexpectedEOF\n\t\t\t}\n\t\t\tm.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...)\n\t\t\tiNdEx += skippy\n\t\t}\n\t}\n\n\tif iNdEx > l {\n\t\treturn io.ErrUnexpectedEOF\n\t}\n\treturn nil\n}", "label_name": "CWE-129", "label": 6} {"code": "func (m *Foo) Unmarshal(dAtA []byte) error {\n\tl := len(dAtA)\n\tiNdEx := 0\n\tfor iNdEx < l {\n\t\tpreIndex := iNdEx\n\t\tvar wire uint64\n\t\tfor shift := uint(0); ; shift += 7 {\n\t\t\tif shift >= 64 {\n\t\t\t\treturn ErrIntOverflowProto\n\t\t\t}\n\t\t\tif iNdEx >= l {\n\t\t\t\treturn io.ErrUnexpectedEOF\n\t\t\t}\n\t\t\tb := dAtA[iNdEx]\n\t\t\tiNdEx++\n\t\t\twire |= uint64(b&0x7F) << shift\n\t\t\tif b < 0x80 {\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tfieldNum := int32(wire >> 3)\n\t\twireType := int(wire & 0x7)\n\t\tif wireType == 4 {\n\t\t\treturn fmt.Errorf(\"proto: Foo: wiretype end group for non-group\")\n\t\t}\n\t\tif fieldNum <= 0 {\n\t\t\treturn fmt.Errorf(\"proto: Foo: illegal tag %d (wire type %d)\", fieldNum, wire)\n\t\t}\n\t\tswitch fieldNum {\n\t\tcase 1:\n\t\t\tif wireType != 2 {\n\t\t\t\treturn fmt.Errorf(\"proto: wrong wireType = %d for field Bar\", wireType)\n\t\t\t}\n\t\t\tvar byteLen int\n\t\t\tfor shift := uint(0); ; shift += 7 {\n\t\t\t\tif shift >= 64 {\n\t\t\t\t\treturn ErrIntOverflowProto\n\t\t\t\t}\n\t\t\t\tif iNdEx >= l {\n\t\t\t\t\treturn io.ErrUnexpectedEOF\n\t\t\t\t}\n\t\t\t\tb := dAtA[iNdEx]\n\t\t\t\tiNdEx++\n\t\t\t\tbyteLen |= int(b&0x7F) << shift\n\t\t\t\tif b < 0x80 {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t\tif byteLen < 0 {\n\t\t\t\treturn ErrInvalidLengthProto\n\t\t\t}\n\t\t\tpostIndex := iNdEx + byteLen\n\t\t\tif postIndex < 0 {\n\t\t\t\treturn ErrInvalidLengthProto\n\t\t\t}\n\t\t\tif postIndex > l {\n\t\t\t\treturn io.ErrUnexpectedEOF\n\t\t\t}\n\t\t\tm.Bar = append(m.Bar[:0], dAtA[iNdEx:postIndex]...)\n\t\t\tif m.Bar == nil {\n\t\t\t\tm.Bar = []byte{}\n\t\t\t}\n\t\t\tiNdEx = postIndex\n\t\tdefault:\n\t\t\tiNdEx = preIndex\n\t\t\tskippy, err := skipProto(dAtA[iNdEx:])\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tif skippy < 0 {\n\t\t\t\treturn ErrInvalidLengthProto\n\t\t\t}\n\t\t\tif (iNdEx + skippy) < 0 {\n\t\t\t\treturn ErrInvalidLengthProto\n\t\t\t}\n\t\t\tif (iNdEx + skippy) > l {\n\t\t\t\treturn io.ErrUnexpectedEOF\n\t\t\t}\n\t\t\tm.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...)\n\t\t\tiNdEx += skippy\n\t\t}\n\t}\n\n\tif iNdEx > l {\n\t\treturn io.ErrUnexpectedEOF\n\t}\n\treturn nil\n}", "label_name": "CWE-129", "label": 6} {"code": "func TestIsReqAuthenticated(t *testing.T) {\n\tpath, err := newTestConfig(globalMinioDefaultRegion)\n\tif err != nil {\n\t\tt.Fatalf(\"unable initialize config file, %s\", err)\n\t}\n\tdefer os.RemoveAll(path)\n\n\tcreds, err := auth.CreateCredentials(\"myuser\", \"mypassword\")\n\tif err != nil {\n\t\tt.Fatalf(\"unable create credential, %s\", err)\n\t}\n\n\tglobalServerConfig.SetCredential(creds)\n\n\t// List of test cases for validating http request authentication.\n\ttestCases := []struct {\n\t\treq *http.Request\n\t\ts3Error APIErrorCode\n\t}{\n\t\t// When request is nil, internal error is returned.\n\t\t{nil, ErrInternalError},\n\t\t// When request is unsigned, access denied is returned.\n\t\t{mustNewRequest(\"GET\", \"http://127.0.0.1:9000\", 0, nil, t), ErrAccessDenied},\n\t\t// Empty Content-Md5 header.\n\t\t{mustNewSignedEmptyMD5Request(\"PUT\", \"http://127.0.0.1:9000/\", 5, bytes.NewReader([]byte(\"hello\")), t), ErrInvalidDigest},\n\t\t// Short Content-Md5 header.\n\t\t{mustNewSignedShortMD5Request(\"PUT\", \"http://127.0.0.1:9000/\", 5, bytes.NewReader([]byte(\"hello\")), t), ErrInvalidDigest},\n\t\t// When request is properly signed, but has bad Content-MD5 header.\n\t\t{mustNewSignedBadMD5Request(\"PUT\", \"http://127.0.0.1:9000/\", 5, bytes.NewReader([]byte(\"hello\")), t), ErrBadDigest},\n\t\t// When request is properly signed, error is none.\n\t\t{mustNewSignedRequest(\"GET\", \"http://127.0.0.1:9000\", 0, nil, t), ErrNone},\n\t}\n\n\t// Validates all testcases.\n\tfor _, testCase := range testCases {\n\t\tif s3Error := isReqAuthenticated(testCase.req, globalServerConfig.GetRegion()); s3Error != testCase.s3Error {\n\t\t\tt.Fatalf(\"Unexpected s3error returned wanted %d, got %d\", testCase.s3Error, s3Error)\n\t\t}\n\t}\n}", "label_name": "CWE-774", "label": 13} {"code": "func (m *Empty) Unmarshal(dAtA []byte) error {\n\tl := len(dAtA)\n\tiNdEx := 0\n\tfor iNdEx < l {\n\t\tpreIndex := iNdEx\n\t\tvar wire uint64\n\t\tfor shift := uint(0); ; shift += 7 {\n\t\t\tif shift >= 64 {\n\t\t\t\treturn ErrIntOverflowEmpty\n\t\t\t}\n\t\t\tif iNdEx >= l {\n\t\t\t\treturn io.ErrUnexpectedEOF\n\t\t\t}\n\t\t\tb := dAtA[iNdEx]\n\t\t\tiNdEx++\n\t\t\twire |= uint64(b&0x7F) << shift\n\t\t\tif b < 0x80 {\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tfieldNum := int32(wire >> 3)\n\t\twireType := int(wire & 0x7)\n\t\tif wireType == 4 {\n\t\t\treturn fmt.Errorf(\"proto: Empty: wiretype end group for non-group\")\n\t\t}\n\t\tif fieldNum <= 0 {\n\t\t\treturn fmt.Errorf(\"proto: Empty: illegal tag %d (wire type %d)\", fieldNum, wire)\n\t\t}\n\t\tswitch fieldNum {\n\t\tdefault:\n\t\t\tiNdEx = preIndex\n\t\t\tskippy, err := skipEmpty(dAtA[iNdEx:])\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tif skippy < 0 {\n\t\t\t\treturn ErrInvalidLengthEmpty\n\t\t\t}\n\t\t\tif (iNdEx + skippy) < 0 {\n\t\t\t\treturn ErrInvalidLengthEmpty\n\t\t\t}\n\t\t\tif (iNdEx + skippy) > l {\n\t\t\t\treturn io.ErrUnexpectedEOF\n\t\t\t}\n\t\t\tm.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...)\n\t\t\tiNdEx += skippy\n\t\t}\n\t}\n\n\tif iNdEx > l {\n\t\treturn io.ErrUnexpectedEOF\n\t}\n\treturn nil\n}", "label_name": "CWE-129", "label": 6} {"code": "func (m *FakeMap) Unmarshal(dAtA []byte) error {\n\tl := len(dAtA)\n\tiNdEx := 0\n\tfor iNdEx < l {\n\t\tpreIndex := iNdEx\n\t\tvar wire uint64\n\t\tfor shift := uint(0); ; shift += 7 {\n\t\t\tif shift >= 64 {\n\t\t\t\treturn ErrIntOverflowMap\n\t\t\t}\n\t\t\tif iNdEx >= l {\n\t\t\t\treturn io.ErrUnexpectedEOF\n\t\t\t}\n\t\t\tb := dAtA[iNdEx]\n\t\t\tiNdEx++\n\t\t\twire |= uint64(b&0x7F) << shift\n\t\t\tif b < 0x80 {\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tfieldNum := int32(wire >> 3)\n\t\twireType := int(wire & 0x7)\n\t\tif wireType == 4 {\n\t\t\treturn fmt.Errorf(\"proto: FakeMap: wiretype end group for non-group\")\n\t\t}\n\t\tif fieldNum <= 0 {\n\t\t\treturn fmt.Errorf(\"proto: FakeMap: illegal tag %d (wire type %d)\", fieldNum, wire)\n\t\t}\n\t\tswitch fieldNum {\n\t\tcase 1:\n\t\t\tif wireType != 2 {\n\t\t\t\treturn fmt.Errorf(\"proto: wrong wireType = %d for field Entries\", wireType)\n\t\t\t}\n\t\t\tvar msglen int\n\t\t\tfor shift := uint(0); ; shift += 7 {\n\t\t\t\tif shift >= 64 {\n\t\t\t\t\treturn ErrIntOverflowMap\n\t\t\t\t}\n\t\t\t\tif iNdEx >= l {\n\t\t\t\t\treturn io.ErrUnexpectedEOF\n\t\t\t\t}\n\t\t\t\tb := dAtA[iNdEx]\n\t\t\t\tiNdEx++\n\t\t\t\tmsglen |= int(b&0x7F) << shift\n\t\t\t\tif b < 0x80 {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t\tif msglen < 0 {\n\t\t\t\treturn ErrInvalidLengthMap\n\t\t\t}\n\t\t\tpostIndex := iNdEx + msglen\n\t\t\tif postIndex < 0 {\n\t\t\t\treturn ErrInvalidLengthMap\n\t\t\t}\n\t\t\tif postIndex > l {\n\t\t\t\treturn io.ErrUnexpectedEOF\n\t\t\t}\n\t\t\tm.Entries = append(m.Entries, &FakeMapEntry{})\n\t\t\tif err := m.Entries[len(m.Entries)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tiNdEx = postIndex\n\t\tdefault:\n\t\t\tiNdEx = preIndex\n\t\t\tskippy, err := skipMap(dAtA[iNdEx:])\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tif skippy < 0 {\n\t\t\t\treturn ErrInvalidLengthMap\n\t\t\t}\n\t\t\tif (iNdEx + skippy) < 0 {\n\t\t\t\treturn ErrInvalidLengthMap\n\t\t\t}\n\t\t\tif (iNdEx + skippy) > l {\n\t\t\t\treturn io.ErrUnexpectedEOF\n\t\t\t}\n\t\t\tm.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...)\n\t\t\tiNdEx += skippy\n\t\t}\n\t}\n\n\tif iNdEx > l {\n\t\treturn io.ErrUnexpectedEOF\n\t}\n\treturn nil\n}", "label_name": "CWE-129", "label": 6} {"code": "func (m *NidRepNonByteCustomType) Unmarshal(dAtA []byte) error {\n\tl := len(dAtA)\n\tiNdEx := 0\n\tfor iNdEx < l {\n\t\tpreIndex := iNdEx\n\t\tvar wire uint64\n\t\tfor shift := uint(0); ; shift += 7 {\n\t\t\tif shift >= 64 {\n\t\t\t\treturn ErrIntOverflowThetest\n\t\t\t}\n\t\t\tif iNdEx >= l {\n\t\t\t\treturn io.ErrUnexpectedEOF\n\t\t\t}\n\t\t\tb := dAtA[iNdEx]\n\t\t\tiNdEx++\n\t\t\twire |= uint64(b&0x7F) << shift\n\t\t\tif b < 0x80 {\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tfieldNum := int32(wire >> 3)\n\t\twireType := int(wire & 0x7)\n\t\tif wireType == 4 {\n\t\t\treturn fmt.Errorf(\"proto: NidRepNonByteCustomType: wiretype end group for non-group\")\n\t\t}\n\t\tif fieldNum <= 0 {\n\t\t\treturn fmt.Errorf(\"proto: NidRepNonByteCustomType: illegal tag %d (wire type %d)\", fieldNum, wire)\n\t\t}\n\t\tswitch fieldNum {\n\t\tcase 1:\n\t\t\tif wireType != 2 {\n\t\t\t\treturn fmt.Errorf(\"proto: wrong wireType = %d for field Field1\", wireType)\n\t\t\t}\n\t\t\tvar msglen int\n\t\t\tfor shift := uint(0); ; shift += 7 {\n\t\t\t\tif shift >= 64 {\n\t\t\t\t\treturn ErrIntOverflowThetest\n\t\t\t\t}\n\t\t\t\tif iNdEx >= l {\n\t\t\t\t\treturn io.ErrUnexpectedEOF\n\t\t\t\t}\n\t\t\t\tb := dAtA[iNdEx]\n\t\t\t\tiNdEx++\n\t\t\t\tmsglen |= int(b&0x7F) << shift\n\t\t\t\tif b < 0x80 {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t\tif msglen < 0 {\n\t\t\t\treturn ErrInvalidLengthThetest\n\t\t\t}\n\t\t\tpostIndex := iNdEx + msglen\n\t\t\tif postIndex < 0 {\n\t\t\t\treturn ErrInvalidLengthThetest\n\t\t\t}\n\t\t\tif postIndex > l {\n\t\t\t\treturn io.ErrUnexpectedEOF\n\t\t\t}\n\t\t\tm.Field1 = append(m.Field1, T{})\n\t\t\tif err := m.Field1[len(m.Field1)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tiNdEx = postIndex\n\t\tdefault:\n\t\t\tiNdEx = preIndex\n\t\t\tskippy, err := skipThetest(dAtA[iNdEx:])\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tif skippy < 0 {\n\t\t\t\treturn ErrInvalidLengthThetest\n\t\t\t}\n\t\t\tif (iNdEx + skippy) < 0 {\n\t\t\t\treturn ErrInvalidLengthThetest\n\t\t\t}\n\t\t\tif (iNdEx + skippy) > l {\n\t\t\t\treturn io.ErrUnexpectedEOF\n\t\t\t}\n\t\t\tm.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...)\n\t\t\tiNdEx += skippy\n\t\t}\n\t}\n\n\tif iNdEx > l {\n\t\treturn io.ErrUnexpectedEOF\n\t}\n\treturn nil\n}", "label_name": "CWE-129", "label": 6}