code
stringlengths 14
2.05k
| label
int64 0
1
| programming_language
stringclasses 7
values | cwe_id
stringlengths 6
14
| cwe_name
stringlengths 5
98
⌀ | description
stringlengths 36
379
⌀ | url
stringlengths 36
48
⌀ | label_name
stringclasses 2
values |
---|---|---|---|---|---|---|---|
static s16 swf_get_s16(SWFReader *read)
{
return (s16) gf_bs_read_u16_le(read->bs);
} | 1 | C | CWE-1077 | Floating Point Comparison with Incorrect Operator | The code performs a comparison such as an
equality test between two float (floating point) values, but
it uses comparison operators that do not account for the
possibility of loss of precision. | https://cwe.mitre.org/data/definitions/1077.html | safe |
static u16 swf_get_16(SWFReader *read)
{
return gf_bs_read_u16_le(read->bs);
} | 1 | C | CWE-1077 | Floating Point Comparison with Incorrect Operator | The code performs a comparison such as an
equality test between two float (floating point) values, but
it uses comparison operators that do not account for the
possibility of loss of precision. | https://cwe.mitre.org/data/definitions/1077.html | safe |
static GF_Err mp4_mux_configure_pid(GF_Filter *filter, GF_FilterPid *pid, Bool is_remove)
{
GF_MP4MuxCtx *ctx = gf_filter_get_udta(filter);
if (is_remove) {
TrackWriter *tkw = gf_filter_pid_get_udta(pid);
if (tkw) {
gf_list_del_item(ctx->tracks, tkw);
if (ctx->ref_tkw == tkw) ctx->ref_tkw = gf_list_get(ctx->tracks, 0);
gf_free(tkw);
}
//removing last pid
if (ctx->opid && !gf_list_count(ctx->tracks)) {
if (ctx->file) {
//non-frag file, flush file
if (!ctx->init_movie_done) {
mp4_mux_done(ctx, GF_TRUE);
}
} else {
#ifndef GPAC_DISABLE_ISOM_FRAGMENTS
while (ctx->flush_size) {
GF_Err e = mp4_mux_flush_fragmented(ctx);
if (e) break;
}
#endif
}
//delete output pid (to flush destruction of filter chain)
gf_filter_pid_remove(ctx->opid);
ctx->opid = NULL;
}
return GF_OK;
}
return mp4_mux_setup_pid(filter, pid, GF_TRUE);
} | 1 | C | CWE-416 | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. | https://cwe.mitre.org/data/definitions/416.html | safe |
char *gf_bt_get_next(GF_BTParser *parser, Bool point_break)
{
u32 has_quote;
Bool go = 1;
s32 i;
gf_bt_check_line(parser);
i=0;
has_quote = 0;
while (go) {
if (parser->line_pos+i>=parser->line_size) break;
if (parser->line_buffer[parser->line_pos + i] == '\"') {
if (!has_quote) has_quote = 1;
else has_quote = 0;
parser->line_pos += 1;
continue;
}
if (!has_quote) {
switch (parser->line_buffer[parser->line_pos + i]) {
case 0:
case ' ':
case '\t':
case '\r':
case '\n':
case '{':
case '}':
case ']':
case '[':
case ',':
go = 0;
break;
case '.':
if (point_break) go = 0;
break;
}
if (!go) break;
}
parser->cur_buffer[i] = parser->line_buffer[parser->line_pos + i];
i++;
if (parser->line_pos+i==parser->line_size) break;
}
parser->cur_buffer[i] = 0;
parser->line_pos += i;
return parser->cur_buffer;
} | 1 | C | CWE-125 | Out-of-bounds Read | The product reads data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/125.html | safe |
GF_Err chnl_box_size(GF_Box *s)
{
GF_ChannelLayoutBox *ptr = (GF_ChannelLayoutBox *) s;
s->size += 1;
if (ptr->version==1) s->size++;
if (ptr->layout.stream_structure & 1) {
s->size += 1;
if (ptr->layout.definedLayout==0) {
u32 i;
if (ptr->version==1) s->size++;
for (i=0; i<ptr->layout.channels_count; i++) {
s->size+=1;
if (ptr->layout.layouts[i].position==126)
s->size+=3;
}
} else {
if (ptr->version==1) {
s->size += 1;
if (ptr->layout.omitted_channels_present)
s->size += 8;
} else {
s->size += 8;
}
}
}
if ((ptr->version==0) && (ptr->layout.stream_structure & 2)) {
s->size += 1;
}
return GF_OK;
} | 1 | C | CWE-125 | Out-of-bounds Read | The product reads data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/125.html | safe |
GF_Err chnl_box_write(GF_Box *s, GF_BitStream *bs)
{
GF_Err e;
GF_ChannelLayoutBox *ptr = (GF_ChannelLayoutBox *) s;
e = gf_isom_full_box_write(s, bs);
if (e) return e;
gf_bs_write_u8(bs, ptr->layout.stream_structure);
if (ptr->version==0) {
gf_bs_write_u8(bs, ptr->layout.stream_structure);
} else {
gf_bs_write_int(bs, ptr->layout.stream_structure, 4);
gf_bs_write_int(bs, ptr->layout.format_ordering, 4);
gf_bs_write_u8(bs, ptr->layout.base_channel_count);
}
if (ptr->layout.stream_structure & 1) {
gf_bs_write_u8(bs, ptr->layout.definedLayout);
if (ptr->layout.definedLayout==0) {
u32 i;
if (ptr->version==1) {
gf_bs_write_u8(bs, ptr->layout.channels_count);
}
for (i=0; i<ptr->layout.channels_count; i++) {
gf_bs_write_u8(bs, ptr->layout.layouts[i].position);
if (ptr->layout.layouts[i].position==126) {
gf_bs_write_int(bs, ptr->layout.layouts[i].azimuth, 16);
gf_bs_write_int(bs, ptr->layout.layouts[i].elevation, 8);
}
}
} else {
if (ptr->version==1) {
gf_bs_write_int(bs, 0, 4);
gf_bs_write_int(bs, ptr->layout.channel_order_definition, 3);
gf_bs_write_int(bs, ptr->layout.omitted_channels_present, 1);
if (ptr->layout.omitted_channels_present)
gf_bs_write_u64(bs, ptr->layout.omittedChannelsMap);
} else {
gf_bs_write_u64(bs, ptr->layout.omittedChannelsMap);
}
}
}
if ((ptr->version==0) && (ptr->layout.stream_structure & 2)) {
gf_bs_write_u8(bs, ptr->layout.object_count);
}
return GF_OK;
} | 1 | C | CWE-125 | Out-of-bounds Read | The product reads data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/125.html | safe |
GF_Err gf_isom_set_audio_layout(GF_ISOFile *movie, u32 trackNumber, u32 sampleDescriptionIndex, GF_AudioChannelLayout *layout)
{
GF_Err e;
GF_TrackBox *trak;
GF_SampleEntryBox *entry;
GF_AudioSampleEntryBox*aud_entry;
GF_SampleDescriptionBox *stsd;
GF_ChannelLayoutBox *chnl;
e = CanAccessMovie(movie, GF_ISOM_OPEN_WRITE);
if (e) return e;
if (!layout) return GF_BAD_PARAM;
if ((layout->stream_structure & 1) && (layout->definedLayout==0) && (layout->channels_count>=64))
return GF_BAD_PARAM;
trak = gf_isom_get_track_from_file(movie, trackNumber);
if (!trak) return GF_BAD_PARAM;
stsd = trak->Media->information->sampleTable->SampleDescription;
if (!stsd) {
return movie->LastError = GF_ISOM_INVALID_FILE;
}
if (!sampleDescriptionIndex || sampleDescriptionIndex > gf_list_count(stsd->child_boxes)) {
return movie->LastError = GF_BAD_PARAM;
}
entry = (GF_SampleEntryBox *)gf_list_get(stsd->child_boxes, sampleDescriptionIndex - 1);
//no support for generic sample entries (eg, no MPEG4 descriptor)
if (entry == NULL) return GF_BAD_PARAM;
if (!movie->keep_utc)
trak->Media->mediaHeader->modificationTime = gf_isom_get_mp4time();
if (entry->internal_type != GF_ISOM_SAMPLE_ENTRY_AUDIO) return GF_BAD_PARAM;
aud_entry = (GF_AudioSampleEntryBox*) entry;
if (aud_entry->qtff_mode) {
u32 sr = aud_entry->samplerate_hi;
if (aud_entry->type==GF_ISOM_BOX_TYPE_MLPA) {
sr <<= 16;
sr |= aud_entry->samplerate_lo;
}
e = gf_isom_set_audio_info(movie, trackNumber, sampleDescriptionIndex, sr, aud_entry->channel_count, (u8) aud_entry->bitspersample, GF_IMPORT_AUDIO_SAMPLE_ENTRY_v1_MPEG);
if (e) return e;
}
chnl = (GF_ChannelLayoutBox *) gf_isom_box_find_child(aud_entry->child_boxes, GF_ISOM_BOX_TYPE_CHNL);
if (!chnl) {
chnl = (GF_ChannelLayoutBox *)gf_isom_box_new_parent(&aud_entry->child_boxes, GF_ISOM_BOX_TYPE_CHNL);
if (!chnl) return GF_OUT_OF_MEM;
}
aud_entry->channel_count = layout->channels_count;
memcpy(&chnl->layout, layout, sizeof(GF_AudioChannelLayout));
return GF_OK;
} | 1 | C | CWE-125 | Out-of-bounds Read | The product reads data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/125.html | safe |
GF_Err gf_isom_use_compact_size(GF_ISOFile *movie, u32 trackNumber, Bool CompactionOn)
{
GF_TrackBox *trak;
u32 i, size;
GF_SampleSizeBox *stsz;
GF_Err e;
e = CanAccessMovie(movie, GF_ISOM_OPEN_WRITE);
if (e) return e;
trak = gf_isom_get_track_from_file(movie, trackNumber);
if (!trak) return GF_BAD_PARAM;
if (!trak->Media || !trak->Media->information
|| !trak->Media->information->sampleTable || !trak->Media->information->sampleTable->SampleSize)
return GF_ISOM_INVALID_FILE;
stsz = trak->Media->information->sampleTable->SampleSize;
//switch to regular table
if (!CompactionOn) {
if (stsz->type == GF_ISOM_BOX_TYPE_STSZ) return GF_OK;
stsz->type = GF_ISOM_BOX_TYPE_STSZ;
//invalidate the sampleSize and recompute it
stsz->sampleSize = 0;
if (!stsz->sampleCount) return GF_OK;
//if the table is empty we can only assume the track is empty (no size indication)
if (!stsz->sizes) return GF_OK;
size = stsz->sizes[0];
//check whether the sizes are all the same or not
for (i=1; i<stsz->sampleCount; i++) {
if (size != stsz->sizes[i]) {
size = 0;
break;
}
}
if (size) {
gf_free(stsz->sizes);
stsz->sizes = NULL;
stsz->sampleSize = size;
}
return GF_OK;
}
//switch to compact table
if (stsz->type == GF_ISOM_BOX_TYPE_STZ2) return GF_OK;
//fill the table. Although it seems weird , this is needed in case of edition
//after the function is called. NOte however than we force regular table
//at write time if all samples are of same size
if (stsz->sampleSize && stsz->sampleCount) {
//this is a weird table indeed ;)
if (stsz->sizes) gf_free(stsz->sizes);
stsz->sizes = (u32*) gf_malloc(sizeof(u32)*stsz->sampleCount);
if (!stsz->sizes) return GF_OUT_OF_MEM;
memset(stsz->sizes, stsz->sampleSize, sizeof(u32));
}
//set the SampleSize to 0 while the file is open
stsz->sampleSize = 0;
stsz->type = GF_ISOM_BOX_TYPE_STZ2;
return GF_OK;
} | 1 | C | CWE-787 | Out-of-bounds Write | The product writes data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/787.html | safe |
static GF_Err gf_isom_set_root_iod(GF_ISOFile *movie)
{
GF_IsomInitialObjectDescriptor *iod;
GF_IsomObjectDescriptor *od;
GF_Err e;
e = gf_isom_insert_moov(movie);
if (e) return e;
if (!movie->moov->iods) {
AddMovieIOD(movie->moov, 1);
return GF_OK;
}
//if OD, switch to IOD
if (movie->moov->iods->descriptor->tag == GF_ODF_ISOM_IOD_TAG) return GF_OK;
od = (GF_IsomObjectDescriptor *) movie->moov->iods->descriptor;
iod = (GF_IsomInitialObjectDescriptor*)gf_malloc(sizeof(GF_IsomInitialObjectDescriptor));
if (!iod) return GF_OUT_OF_MEM;
memset(iod, 0, sizeof(GF_IsomInitialObjectDescriptor));
iod->ES_ID_IncDescriptors = od->ES_ID_IncDescriptors;
od->ES_ID_IncDescriptors = NULL;
//not used in root OD
iod->ES_ID_RefDescriptors = NULL;
iod->extensionDescriptors = od->extensionDescriptors;
od->extensionDescriptors = NULL;
iod->IPMP_Descriptors = od->IPMP_Descriptors;
od->IPMP_Descriptors = NULL;
iod->objectDescriptorID = od->objectDescriptorID;
iod->OCIDescriptors = od->OCIDescriptors;
od->OCIDescriptors = NULL;
iod->tag = GF_ODF_ISOM_IOD_TAG;
iod->URLString = od->URLString;
od->URLString = NULL;
gf_odf_desc_del((GF_Descriptor *) od);
movie->moov->iods->descriptor = (GF_Descriptor *)iod;
return GF_OK;
} | 1 | C | CWE-787 | Out-of-bounds Write | The product writes data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/787.html | safe |
GF_Err gf_isom_update_sample_description_from_template(GF_ISOFile *file, u32 track, u32 sampleDescriptionIndex, u8 *data, u32 size)
{
GF_BitStream *bs;
GF_TrackBox *trak;
GF_Box *ent, *tpl_ent;
GF_Err e;
/*get orig sample desc and clone it*/
trak = gf_isom_get_track_from_file(file, track);
if (!trak || !sampleDescriptionIndex) return GF_BAD_PARAM;
if (!trak->Media || !trak->Media->handler || !trak->Media->information || !trak->Media->information->sampleTable || !trak->Media->information->sampleTable->SampleDescription)
return GF_ISOM_INVALID_FILE;
ent = gf_list_get(trak->Media->information->sampleTable->SampleDescription->child_boxes, sampleDescriptionIndex-1);
if (!ent) return GF_BAD_PARAM;
bs = gf_bs_new(data, size, GF_BITSTREAM_READ);
// e = gf_isom_box_parse(&tpl_ent, bs);
e = gf_isom_box_parse_ex(&tpl_ent, bs, GF_ISOM_BOX_TYPE_STSD, GF_FALSE, 0);
gf_bs_del(bs);
if (e) return e;
while (gf_list_count(tpl_ent->child_boxes)) {
u32 j=0;
Bool found = GF_FALSE;
GF_Box *abox = gf_list_pop_front(tpl_ent->child_boxes);
switch (abox->type) {
case GF_ISOM_BOX_TYPE_SINF:
case GF_ISOM_BOX_TYPE_RINF:
case GF_ISOM_BOX_TYPE_BTRT:
found = GF_TRUE;
break;
}
if (found) {
gf_isom_box_del(abox);
continue;
}
if (!ent->child_boxes) ent->child_boxes = gf_list_new();
for (j=0; j<gf_list_count(ent->child_boxes); j++) {
GF_Box *b = gf_list_get(ent->child_boxes, j);
if (b->type == abox->type) {
found = GF_TRUE;
break;
}
}
if (!found) {
gf_list_add(ent->child_boxes, abox);
} else {
gf_isom_box_del(abox);
}
}
gf_isom_box_del(tpl_ent);
//patch for old export
GF_Box *abox = gf_isom_box_find_child(ent->child_boxes, GF_ISOM_BOX_TYPE_SINF);
if (abox) {
gf_list_del_item(ent->child_boxes, abox);
gf_list_add(ent->child_boxes, abox);
}
return GF_OK;
} | 1 | C | CWE-787 | Out-of-bounds Write | The product writes data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/787.html | safe |
static GF_SampleGroupDescriptionBox *get_sgdp(GF_SampleTableBox *stbl, void *traf, u32 grouping_type, Bool *is_traf_sgdp)
#endif /* GPAC_DISABLE_ISOM_FRAGMENTS */
{
GF_List *groupList=NULL;
GF_List **parent=NULL;
GF_SampleGroupDescriptionBox *sgdesc=NULL;
u32 count, i;
#ifndef GPAC_DISABLE_ISOM_FRAGMENTS
if (!stbl && traf && traf->trex->track->Media->information->sampleTable)
stbl = traf->trex->track->Media->information->sampleTable;
#endif
if (stbl) {
if (!stbl->sampleGroupsDescription && !traf)
stbl->sampleGroupsDescription = gf_list_new();
groupList = stbl->sampleGroupsDescription;
if (is_traf_sgdp) *is_traf_sgdp = GF_FALSE;
parent = &stbl->child_boxes;
count = gf_list_count(groupList);
for (i=0; i<count; i++) {
sgdesc = (GF_SampleGroupDescriptionBox*)gf_list_get(groupList, i);
if (sgdesc->grouping_type==grouping_type) break;
sgdesc = NULL;
}
}
#ifndef GPAC_DISABLE_ISOM_FRAGMENTS
/*look in stbl or traf for sample sampleGroupsDescription*/
if (!sgdesc && traf) {
if (!traf->sampleGroupsDescription)
traf->sampleGroupsDescription = gf_list_new();
groupList = traf->sampleGroupsDescription;
parent = &traf->child_boxes;
if (is_traf_sgdp) *is_traf_sgdp = GF_TRUE;
count = gf_list_count(groupList);
for (i=0; i<count; i++) {
sgdesc = (GF_SampleGroupDescriptionBox*)gf_list_get(groupList, i);
if (sgdesc->grouping_type==grouping_type) break;
sgdesc = NULL;
}
}
#endif
if (!sgdesc) {
sgdesc = (GF_SampleGroupDescriptionBox *) gf_isom_box_new_parent(parent, GF_ISOM_BOX_TYPE_SGPD);
if (!sgdesc) return NULL;
sgdesc->grouping_type = grouping_type;
assert(groupList);
gf_list_add(groupList, sgdesc);
}
return sgdesc;
} | 1 | C | CWE-787 | Out-of-bounds Write | The product writes data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/787.html | safe |
u32 gf_isom_find_od_id_for_track(GF_ISOFile *file, u32 track)
{
u32 i, j, di, the_od_id;
GF_TrackBox *od_tk;
GF_TrackBox *tk = gf_isom_get_track_from_file(file, track);
if (!tk) return 0;
i=0;
while ( (od_tk = (GF_TrackBox*)gf_list_enum(file->moov->trackList, &i))) {
if (!od_tk || !od_tk->Media || !od_tk->Media->handler || !od_tk->Media->information ||
!od_tk->Media->information->sampleTable || !od_tk->Media->information->sampleTable->SampleSize ) {
continue;
}
if (od_tk->Media->handler->handlerType != GF_ISOM_MEDIA_OD) continue;
for (j=0; j<od_tk->Media->information->sampleTable->SampleSize->sampleCount; j++) {
GF_ISOSample *samp = gf_isom_get_sample(file, i, j+1, &di);
the_od_id = Media_FindOD_ID(od_tk->Media, samp, tk->Header->trackID);
gf_isom_sample_del(&samp);
if (the_od_id) return the_od_id;
}
}
return 0;
} | 1 | C | NVD-CWE-noinfo | null | null | null | safe |
GF_Err gf_avc_change_vui(GF_AVCConfig *avcc, GF_VUIInfo *vui_info)
{
GF_BitStream *orig, *mod;
AVCState avc;
u32 i, bit_offset, flag;
s32 idx;
GF_AVCConfigSlot *slc;
orig = NULL;
if (!avcc)
return GF_NON_COMPLIANT_BITSTREAM;
memset(&avc, 0, sizeof(AVCState));
avc.sps_active_idx = -1;
i=0;
while ((slc = (GF_AVCConfigSlot *)gf_list_enum(avcc->sequenceParameterSets, &i))) {
u8 *no_emulation_buf = NULL;
u32 no_emulation_buf_size = 0, emulation_bytes = 0;
idx = gf_avc_read_sps(slc->data, slc->size, &avc, 0, &bit_offset);
if (idx<0) {
if ( orig )
gf_bs_del(orig);
continue;
}
/*SPS still contains emulation bytes*/
no_emulation_buf = gf_malloc((slc->size - 1) * sizeof(char));
no_emulation_buf_size = gf_media_nalu_remove_emulation_bytes(slc->data + 1, no_emulation_buf, slc->size - 1);
orig = gf_bs_new(no_emulation_buf, no_emulation_buf_size, GF_BITSTREAM_READ);
gf_bs_read_data(orig, no_emulation_buf, no_emulation_buf_size);
gf_bs_seek(orig, 0);
mod = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE);
/*copy over till vui flag*/
assert(bit_offset >= 8);
while (bit_offset - 8/*bit_offset doesn't take care of the first byte (NALU type)*/) {
flag = gf_bs_read_int(orig, 1);
gf_bs_write_int(mod, flag, 1);
bit_offset--;
}
avc_hevc_vvc_rewrite_vui(vui_info, orig, mod, GF_CODECID_AVC);
/*finally copy over remaining*/
while (gf_bs_bits_available(orig)) {
flag = gf_bs_read_int(orig, 1);
gf_bs_write_int(mod, flag, 1);
}
gf_bs_del(orig);
orig = NULL;
gf_free(no_emulation_buf);
/*set anti-emulation*/
gf_bs_get_content(mod, &no_emulation_buf, &flag);
emulation_bytes = gf_media_nalu_emulation_bytes_add_count(no_emulation_buf, flag);
if (flag+emulation_bytes+1>slc->size)
slc->data = (char*)gf_realloc(slc->data, flag+emulation_bytes+1);
slc->size = gf_media_nalu_add_emulation_bytes(no_emulation_buf, slc->data + 1, flag) + 1;
gf_bs_del(mod);
gf_free(no_emulation_buf);
}
return GF_OK;
} | 1 | C | NVD-CWE-noinfo | null | null | null | safe |
GF_Err gf_media_change_pl(GF_ISOFile *file, u32 track, u32 profile, u32 compat, u32 level)
{
u32 i, count, stype;
GF_Err e;
GF_AVCConfig *avcc;
stype = gf_isom_get_media_subtype(file, track, 1);
switch (stype) {
case GF_ISOM_SUBTYPE_AVC_H264:
case GF_ISOM_SUBTYPE_AVC2_H264:
case GF_ISOM_SUBTYPE_AVC3_H264:
case GF_ISOM_SUBTYPE_AVC4_H264:
break;
default:
return GF_OK;
}
avcc = gf_isom_avc_config_get(file, track, 1);
if (!avcc)
return GF_NON_COMPLIANT_BITSTREAM;
if (level) avcc->AVCLevelIndication = level;
if (compat) avcc->profile_compatibility = compat;
if (profile) avcc->AVCProfileIndication = profile;
count = gf_list_count(avcc->sequenceParameterSets);
for (i=0; i<count; i++) {
GF_NALUFFParam *slc = gf_list_get(avcc->sequenceParameterSets, i);
if (profile) slc->data[1] = profile;
if (level) slc->data[3] = level;
}
e = gf_isom_avc_config_update(file, track, 1, avcc);
gf_odf_avc_cfg_del(avcc);
return e;
} | 1 | C | NVD-CWE-noinfo | null | null | null | safe |
subscription_update (subscriptionPtr subscription, guint flags)
{
UpdateRequest *request;
guint64 now;
guint count, maxcount;
if (!subscription)
return;
if (subscription->updateJob)
return;
debug1 (DEBUG_UPDATE, "Scheduling %s to be updated", node_get_title (subscription->node));
if (subscription_can_be_updated (subscription)) {
now = g_get_real_time();
subscription_reset_update_counter (subscription, &now);
request = update_request_new (
subscription_get_source (subscription),
subscription->updateState,
subscription->updateOptions
);
update_request_allow_commands (request, TRUE);
if (subscription_get_filter (subscription))
request->filtercmd = g_strdup (subscription_get_filter (subscription));
if (SUBSCRIPTION_TYPE (subscription)->prepare_update_request (subscription, request))
subscription->updateJob = update_execute_request (subscription, request, subscription_process_update_result, subscription, flags);
else
g_object_unref (request);
update_jobs_get_count (&count, &maxcount);
if (count > 1)
liferea_shell_set_status_bar (_("Updating (%d / %d) ..."), maxcount - count, maxcount);
else
liferea_shell_set_status_bar (_("Updating '%s'..."), node_get_title (subscription->node));
}
} | 1 | C | CWE-78 | Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') | The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/78.html | safe |
update_job_run (updateJobPtr job)
{
/* Here we decide on the source type and the proper execution
methods which then do anything they want with the job and
pass the processed job to update_process_finished_job()
for result dequeuing */
/* everything starting with '|' is a local command */
if (*(job->request->source) == '|') {
if (job->request->allowCommands) {
debug1 (DEBUG_UPDATE, "Recognized local command: %s", job->request->source);
update_exec_cmd (job);
} else {
debug1 (DEBUG_UPDATE, "Refusing to run local command from unexpected source: %s", job->request->source);
job->result->httpstatus = 403; /* Forbidden. */
update_process_finished_job (job);
}
return;
}
/* if it has a protocol "://" prefix, but not "file://" it is an URI */
if (strstr (job->request->source, "://") && strncmp (job->request->source, "file://", 7)) {
network_process_request (job);
return;
}
/* otherwise it must be a local file... */
{
debug1 (DEBUG_UPDATE, "Recognized file URI: %s", job->request->source);
update_load_file (job);
return;
}
} | 1 | C | CWE-78 | Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') | The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/78.html | safe |
update_request_allow_commands (UpdateRequest *request, gboolean allowCommands)
{
request->allowCommands = allowCommands;
} | 1 | C | CWE-78 | Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') | The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/78.html | safe |
create_new_keys(const char* jwkdir)
{
const char* alg[] = {"ES512", "ECMR", NULL};
char path[PATH_MAX];
/* Set default umask for file creation. */
umask(0337);
for (int i = 0; alg[i] != NULL; i++) {
json_auto_t* jwk = jwk_generate(alg[i]);
if (!jwk) {
return 0;
}
__attribute__ ((__cleanup__(cleanup_str))) char* thp = jwk_thumbprint(jwk, DEFAULT_THP_HASH);
if (!thp) {
return 0;
}
if (snprintf(path, PATH_MAX, "%s/%s.jwk", jwkdir, thp) < 0) {
fprintf(stderr, "Unable to prepare variable with file full path (%s)\n", thp);
return 0;
}
path[sizeof(path) - 1] = '\0';
if (json_dump_file(jwk, path, 0) == -1) {
fprintf(stderr, "Error saving JWK to file (%s)\n", path);
return 0;
}
/* Set 0440 permission for the new key. */
if (chmod(path, S_IRUSR | S_IRGRP) == -1) {
fprintf(stderr, "Unable to set permissions for JWK file (%s)\n", path);
return 0;
}
}
return 1;
} | 1 | C | CWE-362 | Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition') | The product contains a code sequence that can run concurrently with other code, and the code sequence requires temporary, exclusive access to a shared resource, but a timing window exists in which the shared resource can be modified by another code sequence that is operating concurrently. | https://cwe.mitre.org/data/definitions/362.html | safe |
p_ntp_time(netdissect_options *ndo,
const struct l_fixedpt *lfp)
{
uint32_t i;
uint32_t uf;
uint32_t f;
double ff;
i = GET_BE_U_4(lfp->int_part);
uf = GET_BE_U_4(lfp->fraction);
ff = uf;
if (ff < 0.0) /* some compilers are buggy */
ff += FMAXINT;
ff = ff / FMAXINT; /* shift radix point by 32 bits */
f = (uint32_t)(ff * 1000000000.0); /* treat fraction as parts per billion */
ND_PRINT("%u.%09u", i, f);
/*
* print the UTC time in human-readable format.
*/
if (i) {
int64_t seconds_64bit = (int64_t)i - JAN_1970;
time_t seconds;
char time_buf[128];
const char *time_string;
seconds = (time_t)seconds_64bit;
if (seconds != seconds_64bit) {
/*
* It doesn't fit into a time_t, so we can't hand it
* to gmtime.
*/
time_string = "[Time is too large to fit into a time_t]";
} else {
/* use ISO 8601 (RFC3339) format */
time_string = nd_format_time(time_buf, sizeof (time_buf),
"%Y-%m-%dT%H:%M:%SZ", gmtime(&seconds));
}
ND_PRINT(" (%s)", time_string);
}
} | 1 | C | CWE-787 | Out-of-bounds Write | The product writes data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/787.html | safe |
ahcp_time_print(netdissect_options *ndo,
const u_char *cp, uint8_t len)
{
time_t t;
char buf[sizeof("-yyyyyyyyyy-mm-dd hh:mm:ss UTC")];
if (len != 4)
goto invalid;
t = GET_BE_U_4(cp);
ND_PRINT(": %s",
nd_format_time(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S UTC",
gmtime(&t)));
return;
invalid:
nd_print_invalid(ndo);
ND_TCHECK_LEN(cp, len);
} | 1 | C | CWE-787 | Out-of-bounds Write | The product writes data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/787.html | safe |
arista_print_date_hms_time(netdissect_options *ndo, uint32_t seconds,
uint32_t nanoseconds)
{
time_t ts;
char buf[sizeof("-yyyyyyyyyy-mm-dd hh:mm:ss")];
ts = seconds + (nanoseconds / 1000000000);
nanoseconds %= 1000000000;
ND_PRINT("%s.%09u",
nd_format_time(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S",
gmtime(&ts)), nanoseconds);
} | 1 | C | CWE-787 | Out-of-bounds Write | The product writes data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/787.html | safe |
static void zep_print_ts(netdissect_options *ndo, const u_char *p)
{
int32_t i;
uint32_t uf;
uint32_t f;
float ff;
i = GET_BE_U_4(p);
uf = GET_BE_U_4(p + 4);
ff = (float) uf;
if (ff < 0.0) /* some compilers are buggy */
ff += FMAXINT;
ff = (float) (ff / FMAXINT); /* shift radix point by 32 bits */
f = (uint32_t) (ff * 1000000000.0); /* treat fraction as parts per
billion */
ND_PRINT("%u.%09d", i, f);
/*
* print the time in human-readable format.
*/
if (i) {
time_t seconds = i - JAN_1970;
char time_buf[128];
ND_PRINT(" (%s)",
nd_format_time(time_buf, sizeof (time_buf), "%Y/%m/%d %H:%M:%S",
localtime(&seconds)));
}
} | 1 | C | CWE-787 | Out-of-bounds Write | The product writes data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/787.html | safe |
MakeFilename(char *buffer, char *orig_name, int cnt, int max_chars)
{
char *filename = malloc(PATH_MAX + 1);
if (filename == NULL)
error("%s: malloc", __func__);
if (strlen(orig_name) == 0)
error("an empty string is not a valid file name");
/* Process with strftime if Gflag is set. */
if (Gflag != 0) {
struct tm *local_tm;
/* Convert Gflag_time to a usable format */
if ((local_tm = localtime(&Gflag_time)) == NULL) {
error("%s: localtime", __func__);
}
/* There's no good way to detect an error in strftime since a return
* value of 0 isn't necessarily failure; if orig_name is an empty
* string, the formatted string will be empty.
*
* However, the C90 standard says that, if there *is* a
* buffer overflow, the content of the buffer is undefined,
* so we must check for a buffer overflow.
*
* So we check above for an empty orig_name, and only call
* strftime() if it's non-empty, in which case the return
* value will only be 0 if the formatted date doesn't fit
* in the buffer.
*
* (We check above because, even if we don't use -G, we
* want a better error message than "tcpdump: : No such
* file or directory" for this case.)
*/
if (strftime(filename, PATH_MAX, orig_name, local_tm) == 0) {
error("%s: strftime", __func__);
}
} else {
strncpy(filename, orig_name, PATH_MAX);
}
if (cnt == 0 && max_chars == 0)
strncpy(buffer, filename, PATH_MAX + 1);
else
if (snprintf(buffer, PATH_MAX + 1, "%s%0*d", filename, max_chars, cnt) > PATH_MAX)
/* Report an error if the filename is too large */
error("too many output files or filename is too long (> %d)", PATH_MAX);
free(filename);
} | 1 | C | CWE-787 | Out-of-bounds Write | The product writes data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/787.html | safe |
nd_format_time(char *buf, size_t bufsize, const char *format,
const struct tm *timeptr)
{
if (timeptr != NULL) {
if (strftime(buf, bufsize, format, timeptr) != 0)
return (buf);
else
return ("[nd_format_time() buffer is too small]");
} else
return ("[localtime() or gmtime() couldn't convert the date and time]");
} | 1 | C | CWE-787 | Out-of-bounds Write | The product writes data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/787.html | safe |
ts_date_hmsfrac_print(netdissect_options *ndo, long sec, long usec,
enum date_flag date_flag, enum time_flag time_flag)
{
time_t Time = sec;
struct tm *tm;
char timebuf[32];
const char *timestr;
if ((unsigned)sec & 0x80000000) {
ND_PRINT("[Error converting time]");
return;
}
if (time_flag == LOCAL_TIME)
tm = localtime(&Time);
else
tm = gmtime(&Time);
if (date_flag == WITH_DATE) {
timestr = nd_format_time(timebuf, sizeof(timebuf),
"%Y-%m-%d %H:%M:%S", tm);
} else {
timestr = nd_format_time(timebuf, sizeof(timebuf),
"%H:%M:%S", tm);
}
ND_PRINT("%s", timestr);
ts_frac_print(ndo, usec);
} | 1 | C | CWE-787 | Out-of-bounds Write | The product writes data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/787.html | safe |
void hincrbyfloatCommand(client *c) {
long double value, incr;
long long ll;
robj *o;
sds new;
unsigned char *vstr;
unsigned int vlen;
if (getLongDoubleFromObjectOrReply(c,c->argv[3],&incr,NULL) != C_OK) return;
if (isnan(incr) || isinf(incr)) {
addReplyError(c,"value is NaN or Infinity");
return;
}
if ((o = hashTypeLookupWriteOrCreate(c,c->argv[1])) == NULL) return;
if (hashTypeGetValue(o,c->argv[2]->ptr,&vstr,&vlen,&ll) == C_OK) {
if (vstr) {
if (string2ld((char*)vstr,vlen,&value) == 0) {
addReplyError(c,"hash value is not a float");
return;
}
} else {
value = (long double)ll;
}
} else {
value = 0;
}
value += incr;
if (isnan(value) || isinf(value)) {
addReplyError(c,"increment would produce NaN or Infinity");
return;
}
char buf[MAX_LONG_DOUBLE_CHARS];
int len = ld2string(buf,sizeof(buf),value,LD_STR_HUMAN);
new = sdsnewlen(buf,len);
hashTypeSet(o,c->argv[2]->ptr,new,HASH_SET_TAKE_VALUE);
addReplyBulkCBuffer(c,buf,len);
signalModifiedKey(c,c->db,c->argv[1]);
notifyKeyspaceEvent(NOTIFY_HASH,"hincrbyfloat",c->argv[1],c->db->id);
server.dirty++;
/* Always replicate HINCRBYFLOAT as an HSET command with the final value
* in order to make sure that differences in float precision or formatting
* will not create differences in replicas or after an AOF restart. */
robj *newobj;
newobj = createRawStringObject(buf,len);
rewriteClientCommandArgument(c,0,shared.hset);
rewriteClientCommandArgument(c,3,newobj);
decrRefCount(newobj);
} | 1 | C | CWE-617 | Reachable Assertion | The product contains an assert() or similar statement that can be triggered by an attacker, which leads to an application exit or other behavior that is more severe than necessary. | https://cwe.mitre.org/data/definitions/617.html | safe |
void hrandfieldCommand(client *c) {
long l;
int withvalues = 0;
robj *hash;
listpackEntry ele;
if (c->argc >= 3) {
if (getLongFromObjectOrReply(c,c->argv[2],&l,NULL) != C_OK) return;
if (c->argc > 4 || (c->argc == 4 && strcasecmp(c->argv[3]->ptr,"withvalues"))) {
addReplyErrorObject(c,shared.syntaxerr);
return;
} else if (c->argc == 4) {
withvalues = 1;
if (l < LONG_MIN/2 || l > LONG_MAX/2) {
addReplyError(c,"value is out of range");
return;
}
}
hrandfieldWithCountCommand(c, l, withvalues);
return;
}
/* Handle variant without <count> argument. Reply with simple bulk string */
if ((hash = lookupKeyReadOrReply(c,c->argv[1],shared.null[c->resp]))== NULL ||
checkType(c,hash,OBJ_HASH)) {
return;
}
hashTypeRandomElement(hash,hashTypeLength(hash),&ele,NULL);
hashReplyFromListpackEntry(c, &ele);
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
void zrandmemberCommand(client *c) {
long l;
int withscores = 0;
robj *zset;
listpackEntry ele;
if (c->argc >= 3) {
if (getLongFromObjectOrReply(c,c->argv[2],&l,NULL) != C_OK) return;
if (c->argc > 4 || (c->argc == 4 && strcasecmp(c->argv[3]->ptr,"withscores"))) {
addReplyErrorObject(c,shared.syntaxerr);
return;
} else if (c->argc == 4) {
withscores = 1;
if (l < LONG_MIN/2 || l > LONG_MAX/2) {
addReplyError(c,"value is out of range");
return;
}
}
zrandmemberWithCountCommand(c, l, withscores);
return;
}
/* Handle variant without <count> argument. Reply with simple bulk string */
if ((zset = lookupKeyReadOrReply(c,c->argv[1],shared.null[c->resp]))== NULL ||
checkType(c,zset,OBJ_ZSET)) {
return;
}
zsetTypeRandomElement(zset, zsetLength(zset), &ele,NULL);
zsetReplyFromListpackEntry(c,&ele);
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
void msetGenericCommand(client *c, int nx) {
int j;
if ((c->argc % 2) == 0) {
addReplyErrorArity(c);
return;
}
/* Handle the NX flag. The MSETNX semantic is to return zero and don't
* set anything if at least one key already exists. */
if (nx) {
for (j = 1; j < c->argc; j += 2) {
if (lookupKeyWrite(c->db,c->argv[j]) != NULL) {
addReply(c, shared.czero);
return;
}
}
}
for (j = 1; j < c->argc; j += 2) {
c->argv[j+1] = tryObjectEncoding(c->argv[j+1]);
setKey(c, c->db, c->argv[j], c->argv[j + 1], 0);
notifyKeyspaceEvent(NOTIFY_STRING,"set",c->argv[j],c->db->id);
}
server.dirty += (c->argc-1)/2;
addReply(c, nx ? shared.cone : shared.ok);
} | 1 | C | CWE-77 | Improper Neutralization of Special Elements used in a Command ('Command Injection') | The product constructs all or part of a command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/77.html | safe |
static int anetListen(char *err, int s, struct sockaddr *sa, socklen_t len, int backlog, mode_t perm) {
if (bind(s,sa,len) == -1) {
anetSetError(err, "bind: %s", strerror(errno));
close(s);
return ANET_ERR;
}
if (sa->sa_family == AF_LOCAL && perm)
chmod(((struct sockaddr_un *) sa)->sun_path, perm);
if (listen(s, backlog) == -1) {
anetSetError(err, "listen: %s", strerror(errno));
close(s);
return ANET_ERR;
}
return ANET_OK;
} | 1 | C | CWE-668 | Exposure of Resource to Wrong Sphere | The product exposes a resource to the wrong control sphere, providing unintended actors with inappropriate access to the resource. | https://cwe.mitre.org/data/definitions/668.html | safe |
int anetUnixServer(char *err, char *path, mode_t perm, int backlog)
{
int s;
struct sockaddr_un sa;
if (strlen(path) > sizeof(sa.sun_path)-1) {
anetSetError(err,"unix socket path too long (%zu), must be under %zu", strlen(path), sizeof(sa.sun_path));
return ANET_ERR;
}
if ((s = anetCreateSocket(err,AF_LOCAL)) == ANET_ERR)
return ANET_ERR;
memset(&sa,0,sizeof(sa));
sa.sun_family = AF_LOCAL;
redis_strlcpy(sa.sun_path,path,sizeof(sa.sun_path));
if (anetListen(err,s,(struct sockaddr*)&sa,sizeof(sa),backlog,perm) == ANET_ERR)
return ANET_ERR;
return s;
} | 1 | C | CWE-668 | Exposure of Resource to Wrong Sphere | The product exposes a resource to the wrong control sphere, providing unintended actors with inappropriate access to the resource. | https://cwe.mitre.org/data/definitions/668.html | safe |
static int _anetTcpServer(char *err, int port, char *bindaddr, int af, int backlog)
{
int s = -1, rv;
char _port[6]; /* strlen("65535") */
struct addrinfo hints, *servinfo, *p;
snprintf(_port,6,"%d",port);
memset(&hints,0,sizeof(hints));
hints.ai_family = af;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE; /* No effect if bindaddr != NULL */
if (bindaddr && !strcmp("*", bindaddr))
bindaddr = NULL;
if (af == AF_INET6 && bindaddr && !strcmp("::*", bindaddr))
bindaddr = NULL;
if ((rv = getaddrinfo(bindaddr,_port,&hints,&servinfo)) != 0) {
anetSetError(err, "%s", gai_strerror(rv));
return ANET_ERR;
}
for (p = servinfo; p != NULL; p = p->ai_next) {
if ((s = socket(p->ai_family,p->ai_socktype,p->ai_protocol)) == -1)
continue;
if (af == AF_INET6 && anetV6Only(err,s) == ANET_ERR) goto error;
if (anetSetReuseAddr(err,s) == ANET_ERR) goto error;
if (anetListen(err,s,p->ai_addr,p->ai_addrlen,backlog,0) == ANET_ERR) s = ANET_ERR;
goto end;
}
if (p == NULL) {
anetSetError(err, "unable to bind socket, errno: %d", errno);
goto error;
}
error:
if (s != -1) close(s);
s = ANET_ERR;
end:
freeaddrinfo(servinfo);
return s;
} | 1 | C | CWE-668 | Exposure of Resource to Wrong Sphere | The product exposes a resource to the wrong control sphere, providing unintended actors with inappropriate access to the resource. | https://cwe.mitre.org/data/definitions/668.html | safe |
Tss2_RC_Decode(TSS2_RC rc)
{
static __thread char buf[TSS2_ERR_LAYER_NAME_MAX + TSS2_ERR_LAYER_ERROR_STR_MAX + 1];
clearbuf(buf);
UINT8 layer = tss2_rc_layer_number_get(rc);
TSS2_RC_HANDLER handler = layer_handler[layer].handler;
const char *lname = layer_handler[layer].name;
if (lname[0]) {
catbuf(buf, "%s:", lname);
} else {
catbuf(buf, "%u:", layer);
}
/*
* Handlers only need the error bits. This way they don't
* need to concern themselves with masking off the layer
* bits or anything else.
*/
if (handler) {
UINT16 err_bits = tpm2_error_get(rc);
const char *e = err_bits ? handler(err_bits) : "success";
if (e) {
catbuf(buf, "%s", e);
} else {
catbuf(buf, "0x%X", err_bits);
}
} else {
/*
* we don't want to drop any bits if we don't know what to do with it
* so drop the layer byte since we we already have that.
*/
const char *e = unknown_layer_handler(rc >> 8);
assert(e);
catbuf(buf, "%s", e);
}
return buf;
} | 1 | C | CWE-120 | Buffer Copy without Checking Size of Input ('Classic Buffer Overflow') | The product copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow. | https://cwe.mitre.org/data/definitions/120.html | safe |
unknown_layer_handler(TSS2_RC rc)
{
static __thread char buf[32];
clearbuf(buf);
catbuf(buf, "0x%X", rc);
return buf;
} | 1 | C | CWE-120 | Buffer Copy without Checking Size of Input ('Classic Buffer Overflow') | The product copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow. | https://cwe.mitre.org/data/definitions/120.html | safe |
test_custom_handler(void **state)
{
(void) state;
/*
* Test registering a custom handler
*/
TSS2_RC_HANDLER old = Tss2_RC_SetHandler(1, "cstm", custom_err_handler);
assert_null(old);
/*
* Test getting error strings
*/
unsigned i;
for (i = 1; i < 4; i++) {
// Make a layer 1 error with an error number of i.
TSS2_RC rc = TSS2_RC_LAYER(1) | i;
char buf[256];
snprintf(buf, sizeof(buf), "cstm:error %u", i);
const char *e = Tss2_RC_Decode(rc);
assert_string_equal(e, buf);
}
TSS2_RC rc = TSS2_RC_LAYER(1) | 42;
/*
* Test an unknown error
*/
const char *e = Tss2_RC_Decode(rc);
assert_string_equal(e, "cstm:0x2A");
/*
* Test clearing a handler
*/
old = Tss2_RC_SetHandler(1, "cstm", NULL);
assert_ptr_equal(old, custom_err_handler);
/*
* Test an unknown layer
*/
e = Tss2_RC_Decode(rc);
assert_string_equal(e, "1:0x100");
} | 1 | C | CWE-120 | Buffer Copy without Checking Size of Input ('Classic Buffer Overflow') | The product copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow. | https://cwe.mitre.org/data/definitions/120.html | safe |
test_all_FFs(void **state)
{
(void) state;
const char *e = Tss2_RC_Decode(0xFFFFFFFF);
assert_string_equal(e, "255:0xFFFFFF");
} | 1 | C | CWE-120 | Buffer Copy without Checking Size of Input ('Classic Buffer Overflow') | The product copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow. | https://cwe.mitre.org/data/definitions/120.html | safe |
main(int argc, char* argv[])
{
(void) argc;
(void) argv;
const struct CMUnitTest tests[] = {
/* Layer tests */
cmocka_unit_test(test_layers),
cmocka_unit_test(test_tpm_format_0_version2_0_error),
cmocka_unit_test(test_tpm_format_0_version2_0_warn),
cmocka_unit_test(test_tpm2_format_0_unknown),
cmocka_unit_test(test_tpm_format_1_unk_handle),
cmocka_unit_test(test_tpm_format_1_unk_parameter),
cmocka_unit_test(test_tpm_format_1_unk_session),
cmocka_unit_test(test_tpm_format_1_5_handle),
cmocka_unit_test(test_tpm2_format_1_unknown),
cmocka_unit_test(test_tpm2_format_1_success),
cmocka_unit_test(test_custom_handler),
cmocka_unit_test(test_zero_length_name),
cmocka_unit_test(test_over_length_name),
cmocka_unit_test(test_null_name),
cmocka_unit_test(test_sys),
cmocka_unit_test(test_esys),
cmocka_unit_test(test_mu),
cmocka_unit_test(test_tcti),
cmocka_unit_test(test_info_fmt0),
cmocka_unit_test(test_info_fmt1_parameter),
cmocka_unit_test(test_info_fmt1_handle),
cmocka_unit_test(test_info_fmt1_session),
cmocka_unit_test(test_info_null),
cmocka_unit_test(test_info_str_fmt1),
cmocka_unit_test(test_info_str_fmt1_ff),
cmocka_unit_test(test_info_str_fmt0_err),
cmocka_unit_test(test_info_str_fmt0_warn),
cmocka_unit_test(test_info_str_fmt0_ff),
cmocka_unit_test(test_info_str_null),
cmocka_unit_test(test_all_FFs),
cmocka_unit_test(test_all_FFs_set_handler)
};
return cmocka_run_group_tests(tests, NULL, NULL);
} | 1 | C | CWE-120 | Buffer Copy without Checking Size of Input ('Classic Buffer Overflow') | The product copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow. | https://cwe.mitre.org/data/definitions/120.html | safe |
test_all_FFs_set_handler(void **state)
{
(void) state;
Tss2_RC_SetHandler(0xFF, "garbage", custom_err_handler);
Tss2_RC_SetHandler(0xFF, NULL, NULL);
} | 1 | C | CWE-120 | Buffer Copy without Checking Size of Input ('Classic Buffer Overflow') | The product copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow. | https://cwe.mitre.org/data/definitions/120.html | safe |
sigterm_handler(int sig) // I - Signal number (unused)
{
(void)sig;
const char * const msg = "DEBUG: beh: Job canceled.\n";
// The if() is to eliminate the return value and silence the warning
// about an unused return value.
if (write(2, msg, strlen(msg)));
if (job_canceled)
_exit(CUPS_BACKEND_OK);
else
job_canceled = 1;
} | 1 | C | CWE-78 | Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') | The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/78.html | safe |
_pdfioFileConsume(pdfio_file_t *pdf, // I - PDF file
size_t bytes) // I - Bytes to consume
{
PDFIO_DEBUG("_pdfioFileConsume(pdf=%p, bytes=%u)\n", pdf, (unsigned)bytes);
if ((size_t)(pdf->bufend - pdf->bufptr) > bytes)
pdf->bufptr += bytes;
else if (_pdfioFileSeek(pdf, (off_t)bytes, SEEK_CUR) < 0)
return (false);
PDFIO_DEBUG("_pdfioFileConsume: pos=%ld\n", (long)(pdf->bufpos + pdf->bufptr - pdf->buffer));
return (true);
} | 1 | C | CWE-835 | Loop with Unreachable Exit Condition ('Infinite Loop') | The product contains an iteration or loop with an exit condition that cannot be reached, i.e., an infinite loop. | https://cwe.mitre.org/data/definitions/835.html | safe |
_pdfioDictRead(pdfio_file_t *pdf, // I - PDF file
pdfio_obj_t *obj, // I - Object, if any
_pdfio_token_t *tb, // I - Token buffer/stack
size_t depth) // I - Depth of dictionary
{
pdfio_dict_t *dict; // New dictionary
char key[256]; // Dictionary key
_pdfio_value_t value; // Dictionary value
PDFIO_DEBUG("_pdfioDictRead(pdf=%p)\n", pdf);
// Create a dictionary and start reading...
if ((dict = pdfioDictCreate(pdf)) == NULL)
return (NULL);
while (_pdfioTokenGet(tb, key, sizeof(key)))
{
// Get the next key or end-of-dictionary...
if (!strcmp(key, ">>"))
{
// End of dictionary...
return (dict);
}
else if (key[0] != '/')
{
_pdfioFileError(pdf, "Invalid dictionary contents.");
break;
}
else if (_pdfioDictGetValue(dict, key + 1))
{
_pdfioFileError(pdf, "Duplicate dictionary key '%s'.", key + 1);
return (NULL);
}
// Then get the next value...
PDFIO_DEBUG("_pdfioDictRead: Reading value for '%s'.\n", key + 1);
if (!_pdfioValueRead(pdf, obj, tb, &value, depth))
{
_pdfioFileError(pdf, "Missing value for dictionary key.");
break;
}
if (!_pdfioDictSetValue(dict, pdfioStringCreate(pdf, key + 1), &value))
break;
// PDFIO_DEBUG("_pdfioDictRead: Set %s.\n", key);
}
// Dictionary is invalid - pdfioFileClose will free the memory, return NULL
// to indicate an error...
return (NULL);
} | 1 | C | CWE-835 | Loop with Unreachable Exit Condition ('Infinite Loop') | The product contains an iteration or loop with an exit condition that cannot be reached, i.e., an infinite loop. | https://cwe.mitre.org/data/definitions/835.html | safe |
_pdfioDictSetValue(
pdfio_dict_t *dict, // I - Dictionary
const char *key, // I - Key
_pdfio_value_t *value) // I - Value
{
_pdfio_pair_t *pair; // Current pair
PDFIO_DEBUG("_pdfioDictSetValue(dict=%p, key=\"%s\", value=%p)\n", dict, key, (void *)value);
// See if the key is already set...
if (dict->num_pairs > 0)
{
_pdfio_pair_t pkey; // Search key
pkey.key = key;
if ((pair = (_pdfio_pair_t *)bsearch(&pkey, dict->pairs, dict->num_pairs, sizeof(_pdfio_pair_t), (int (*)(const void *, const void *))compare_pairs)) != NULL)
{
// Yes, replace the value...
PDFIO_DEBUG("_pdfioDictSetValue: Replacing existing value.\n");
if (pair->value.type == PDFIO_VALTYPE_BINARY)
free(pair->value.value.binary.data);
pair->value = *value;
return (true);
}
}
// Nope, add a pair...
if (dict->num_pairs >= dict->alloc_pairs)
{
// Expand the dictionary...
_pdfio_pair_t *temp = (_pdfio_pair_t *)realloc(dict->pairs, (dict->alloc_pairs + 8) * sizeof(_pdfio_pair_t));
if (!temp)
{
PDFIO_DEBUG("_pdfioDictSetValue: Out of memory.\n");
return (false);
}
dict->pairs = temp;
dict->alloc_pairs += 8;
}
pair = dict->pairs + dict->num_pairs;
dict->num_pairs ++;
pair->key = key;
pair->value = *value;
// Re-sort the dictionary and return...
if (dict->num_pairs > 1 && compare_pairs(pair - 1, pair) > 0)
qsort(dict->pairs, dict->num_pairs, sizeof(_pdfio_pair_t), (int (*)(const void *, const void *))compare_pairs);
#ifdef DEBUG
PDFIO_DEBUG("_pdfioDictSetValue(%p): %lu pairs\n", (void *)dict, (unsigned long)dict->num_pairs);
// PDFIO_DEBUG("_pdfioDictSetValue(%p): ", (void *)dict);
// PDFIO_DEBUG_DICT(dict);
// PDFIO_DEBUG("\n");
#endif // DEBUG
return (true);
} | 1 | C | CWE-835 | Loop with Unreachable Exit Condition ('Infinite Loop') | The product contains an iteration or loop with an exit condition that cannot be reached, i.e., an infinite loop. | https://cwe.mitre.org/data/definitions/835.html | safe |
_pdfioTokenGet(_pdfio_token_t *tb, // I - Token buffer/stack
char *buffer, // I - String buffer
size_t bufsize) // I - Size of string buffer
{
// See if we have a token waiting on the stack...
if (tb->num_tokens > 0)
{
// Yes, return it...
size_t len; // Length of token
tb->num_tokens --;
if ((len = strlen(tb->tokens[tb->num_tokens])) > (bufsize - 1))
{
// Value too large...
PDFIO_DEBUG("_pdfioTokenGet(tb=%p, buffer=%p, bufsize=%u): Token '%s' from stack too large.\n", tb, buffer, (unsigned)bufsize, tb->tokens[tb->num_tokens]);
*buffer = '\0';
return (false);
}
memcpy(buffer, tb->tokens[tb->num_tokens], len);
buffer[len] = '\0';
PDFIO_DEBUG("_pdfioTokenGet(tb=%p, buffer=%p, bufsize=%u): Popping '%s' from stack.\n", tb, buffer, (unsigned)bufsize, buffer);
free(tb->tokens[tb->num_tokens]);
tb->tokens[tb->num_tokens] = NULL;
return (true);
}
// No, read a new one...
return (_pdfioTokenRead(tb, buffer, bufsize));
} | 1 | C | CWE-835 | Loop with Unreachable Exit Condition ('Infinite Loop') | The product contains an iteration or loop with an exit condition that cannot be reached, i.e., an infinite loop. | https://cwe.mitre.org/data/definitions/835.html | safe |
get_char(_pdfio_token_t *tb) // I - Token buffer
{
ssize_t bytes; // Bytes peeked
// Refill the buffer as needed...
if (tb->bufptr >= tb->bufend)
{
// Consume previous bytes...
if (tb->bufend > tb->buffer)
{
PDFIO_DEBUG("get_char: Consuming %d bytes.\n", (int)(tb->bufend - tb->buffer));
(tb->consume_cb)(tb->cb_data, (size_t)(tb->bufend - tb->buffer));
}
// Peek new bytes...
if ((bytes = (tb->peek_cb)(tb->cb_data, tb->buffer, sizeof(tb->buffer))) <= 0)
{
tb->bufptr = tb->bufend = tb->buffer;
return (EOF);
}
// Update pointers...
tb->bufptr = tb->buffer;
tb->bufend = tb->buffer + bytes;
#if 0
#ifdef DEBUG
unsigned char *ptr; // Pointer into buffer
PDFIO_DEBUG("get_char: Read '");
for (ptr = tb->buffer; ptr < tb->bufend; ptr ++)
{
if (*ptr < ' ' || *ptr == 0x7f)
PDFIO_DEBUG("\\%03o", *ptr);
else
PDFIO_DEBUG("%c", *ptr);
}
PDFIO_DEBUG("'\n");
#endif // DEBUG
#endif // 0
}
// Return the next character...
return (*(tb->bufptr)++);
} | 1 | C | CWE-835 | Loop with Unreachable Exit Condition ('Infinite Loop') | The product contains an iteration or loop with an exit condition that cannot be reached, i.e., an infinite loop. | https://cwe.mitre.org/data/definitions/835.html | safe |
void gnrc_sixlowpan_iphc_send(gnrc_pktsnip_t *pkt, void *ctx, unsigned page)
{
gnrc_netif_hdr_t *netif_hdr = pkt->data;
gnrc_netif_t *netif = gnrc_netif_hdr_get_netif(netif_hdr);
gnrc_pktsnip_t *tmp;
/* datagram size before compression */
size_t orig_datagram_size = gnrc_pkt_len(pkt->next);
ipv6_hdr_t *ipv6_hdr = pkt->next->data;
ipv6_addr_t dst;
if (IS_USED(MODULE_GNRC_SIXLOWPAN_FRAG_MINFWD)) {
dst = ipv6_hdr->dst; /* copying original destination address */
}
if ((tmp = _iphc_encode(pkt, pkt->data, netif))) {
if (IS_USED(MODULE_GNRC_SIXLOWPAN_FRAG_MINFWD) && (ctx != NULL) &&
(gnrc_sixlowpan_frag_minfwd_frag_iphc(tmp, orig_datagram_size, &dst,
ctx) == 0)) {
DEBUG("6lo iphc minfwd: putting slack in first fragment\n");
return;
}
gnrc_sixlowpan_multiplex_by_size(tmp, orig_datagram_size, netif, page);
}
else {
if (IS_USED(MODULE_GNRC_SIXLOWPAN_FRAG_MINFWD)) {
gnrc_sixlowpan_frag_fb_t *fb = ctx;
if (fb->pkt == pkt) {
/* free provided fragmentation buffer */
fb->pkt = NULL;
}
}
gnrc_pktbuf_release(pkt);
}
} | 1 | C | CWE-476 | NULL Pointer Dereference | A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL, typically causing a crash or exit. | https://cwe.mitre.org/data/definitions/476.html | safe |
static inline bool _arq_scheduled(gnrc_sixlowpan_frag_fb_t *fbuf)
{
evtimer_event_t *ptr = _arq_timer.events;
evtimer_event_t *event = &fbuf->sfr.arq_timeout_event.event;
while (ptr) {
if (ptr == event) {
return true;
}
ptr = ptr->next;
}
return false;
} | 1 | C | CWE-362 | Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition') | The product contains a code sequence that can run concurrently with other code, and the code sequence requires temporary, exclusive access to a shared resource, but a timing window exists in which the shared resource can be modified by another code sequence that is operating concurrently. | https://cwe.mitre.org/data/definitions/362.html | safe |
static void _sched_arq_timeout(gnrc_sixlowpan_frag_fb_t *fbuf, uint32_t offset)
{
if (IS_ACTIVE(CONFIG_GNRC_SIXLOWPAN_SFR_MOCK_ARQ_TIMER)) {
/* mock does not need to be scheduled */
return;
}
if (_arq_scheduled(fbuf)) {
DEBUG("6lo sfr: ARQ timeout for datagram %u already scheduled\n",
(uint8_t)fbuf->tag);
return;
}
DEBUG("6lo sfr: arming ACK timeout in %lums for datagram %u\n",
(long unsigned)offset, fbuf->tag);
fbuf->sfr.arq_timeout_event.event.offset = offset;
fbuf->sfr.arq_timeout_event.msg.content.ptr = fbuf;
fbuf->sfr.arq_timeout_event.msg.type = GNRC_SIXLOWPAN_FRAG_SFR_ARQ_TIMEOUT_MSG;
evtimer_add_msg(&_arq_timer, &fbuf->sfr.arq_timeout_event,
_getpid());
} | 1 | C | CWE-362 | Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition') | The product contains a code sequence that can run concurrently with other code, and the code sequence requires temporary, exclusive access to a shared resource, but a timing window exists in which the shared resource can be modified by another code sequence that is operating concurrently. | https://cwe.mitre.org/data/definitions/362.html | safe |
compat_cipher_proposal(struct ssh *ssh, char *cipher_prop)
{
if (!(ssh->compat & SSH_BUG_BIGENDIANAES))
return xstrdup(cipher_prop);
debug2_f("original cipher proposal: %s", cipher_prop);
if ((cipher_prop = match_filter_denylist(cipher_prop, "aes*")) == NULL)
fatal("match_filter_denylist failed");
debug2_f("compat cipher proposal: %s", cipher_prop);
if (*cipher_prop == '\0')
fatal("No supported ciphers found");
return cipher_prop;
} | 1 | C | CWE-415 | Double Free | The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations. | https://cwe.mitre.org/data/definitions/415.html | safe |
compat_kex_proposal(struct ssh *ssh, char *p)
{
char *cp = NULL;
if ((ssh->compat & (SSH_BUG_CURVE25519PAD|SSH_OLD_DHGEX)) == 0)
return xstrdup(p);
debug2_f("original KEX proposal: %s", p);
if ((ssh->compat & SSH_BUG_CURVE25519PAD) != 0)
if ((p = match_filter_denylist(p,
"[email protected]")) == NULL)
fatal("match_filter_denylist failed");
if ((ssh->compat & SSH_OLD_DHGEX) != 0) {
cp = p;
if ((p = match_filter_denylist(p,
"diffie-hellman-group-exchange-sha256,"
"diffie-hellman-group-exchange-sha1")) == NULL)
fatal("match_filter_denylist failed");
free(cp);
}
debug2_f("compat KEX proposal: %s", p);
if (*p == '\0')
fatal("No supported key exchange algorithms found");
return p;
} | 1 | C | CWE-415 | Double Free | The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations. | https://cwe.mitre.org/data/definitions/415.html | safe |
compat_pkalg_proposal(struct ssh *ssh, char *pkalg_prop)
{
if (!(ssh->compat & SSH_BUG_RSASIGMD5))
return xstrdup(pkalg_prop);
debug2_f("original public key proposal: %s", pkalg_prop);
if ((pkalg_prop = match_filter_denylist(pkalg_prop, "ssh-rsa")) == NULL)
fatal("match_filter_denylist failed");
debug2_f("compat public key proposal: %s", pkalg_prop);
if (*pkalg_prop == '\0')
fatal("No supported PK algorithms found");
return pkalg_prop;
} | 1 | C | CWE-415 | Double Free | The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations. | https://cwe.mitre.org/data/definitions/415.html | safe |
dup_dest_constraint_hop(const struct dest_constraint_hop *dch,
struct dest_constraint_hop *out)
{
u_int i;
int r;
out->user = dch->user == NULL ? NULL : xstrdup(dch->user);
out->hostname = dch->hostname == NULL ? NULL : xstrdup(dch->hostname);
out->is_ca = dch->is_ca;
out->nkeys = dch->nkeys;
out->keys = out->nkeys == 0 ? NULL :
xcalloc(out->nkeys, sizeof(*out->keys));
out->key_is_ca = out->nkeys == 0 ? NULL :
xcalloc(out->nkeys, sizeof(*out->key_is_ca));
for (i = 0; i < dch->nkeys; i++) {
if (dch->keys[i] != NULL &&
(r = sshkey_from_private(dch->keys[i],
&(out->keys[i]))) != 0)
fatal_fr(r, "copy key");
out->key_is_ca[i] = dch->key_is_ca[i];
}
} | 1 | C | NVD-CWE-noinfo | null | null | null | safe |
dump_dest_constraint_hop(const struct dest_constraint_hop *dch)
{
u_int i;
char *fp;
debug_f("user %s hostname %s is_ca %d nkeys %u",
dch->user == NULL ? "(null)" : dch->user,
dch->hostname == NULL ? "(null)" : dch->hostname,
dch->is_ca, dch->nkeys);
for (i = 0; i < dch->nkeys; i++) {
fp = NULL;
if (dch->keys[i] != NULL &&
(fp = sshkey_fingerprint(dch->keys[i],
SSH_FP_HASH_DEFAULT, SSH_FP_DEFAULT)) == NULL)
fatal_f("fingerprint failed");
debug_f("key %u/%u: %s%s%s key_is_ca %d", i, dch->nkeys,
dch->keys[i] == NULL ? "" : sshkey_ssh_name(dch->keys[i]),
dch->keys[i] == NULL ? "" : " ",
dch->keys[i] == NULL ? "none" : fp,
dch->key_is_ca[i]);
free(fp);
}
} | 1 | C | NVD-CWE-noinfo | null | null | null | safe |
dup_dest_constraints(const struct dest_constraint *dcs, size_t ndcs)
{
size_t i;
struct dest_constraint *ret;
if (ndcs == 0)
return NULL;
ret = xcalloc(ndcs, sizeof(*ret));
for (i = 0; i < ndcs; i++) {
dup_dest_constraint_hop(&dcs[i].from, &ret[i].from);
dup_dest_constraint_hop(&dcs[i].to, &ret[i].to);
}
return ret;
} | 1 | C | NVD-CWE-noinfo | null | null | null | safe |
process_request_identities(SocketEntry *e)
{
Identity *id;
struct sshbuf *msg, *keys;
int r;
u_int i = 0, nentries = 0;
char *fp;
debug2_f("entering");
if ((msg = sshbuf_new()) == NULL || (keys = sshbuf_new()) == NULL)
fatal_f("sshbuf_new failed");
TAILQ_FOREACH(id, &idtab->idlist, next) {
if ((fp = sshkey_fingerprint(id->key, SSH_FP_HASH_DEFAULT,
SSH_FP_DEFAULT)) == NULL)
fatal_f("fingerprint failed");
debug_f("key %u / %u: %s %s", i++, idtab->nentries,
sshkey_ssh_name(id->key), fp);
dump_dest_constraints(__func__,
id->dest_constraints, id->ndest_constraints);
free(fp);
/* identity not visible, don't include in response */
if (identity_permitted(id, e, NULL, NULL, NULL) != 0)
continue;
if ((r = sshkey_puts_opts(id->key, keys,
SSHKEY_SERIALIZE_INFO)) != 0 ||
(r = sshbuf_put_cstring(keys, id->comment)) != 0) {
error_fr(r, "compose key/comment");
continue;
}
nentries++;
}
debug2_f("replying with %u allowed of %u available keys",
nentries, idtab->nentries);
if ((r = sshbuf_put_u8(msg, SSH2_AGENT_IDENTITIES_ANSWER)) != 0 ||
(r = sshbuf_put_u32(msg, nentries)) != 0 ||
(r = sshbuf_putb(msg, keys)) != 0)
fatal_fr(r, "compose");
if ((r = sshbuf_put_stringb(e->output, msg)) != 0)
fatal_fr(r, "enqueue");
sshbuf_free(msg);
sshbuf_free(keys);
} | 1 | C | NVD-CWE-noinfo | null | null | null | safe |
dump_dest_constraints(const char *context,
const struct dest_constraint *dcs, size_t ndcs)
{
#ifdef DEBUG_CONSTRAINTS
size_t i;
debug_f("%s: %zu constraints", context, ndcs);
for (i = 0; i < ndcs; i++) {
debug_f("constraint %zu / %zu: from: ", i, ndcs);
dump_dest_constraint_hop(&dcs[i].from);
debug_f("constraint %zu / %zu: to: ", i, ndcs);
dump_dest_constraint_hop(&dcs[i].to);
}
debug_f("done for %s", context);
#endif /* DEBUG_CONSTRAINTS */
} | 1 | C | NVD-CWE-noinfo | null | null | null | safe |
valid_ruser(const char *s)
{
size_t i;
if (*s == '-')
return 0;
for (i = 0; s[i] != 0; i++) {
if (strchr("'`\";&<>|(){}", s[i]) != NULL)
return 0;
/* Disallow '-' after whitespace */
if (isspace((u_char)s[i]) && s[i + 1] == '-')
return 0;
/* Disallow \ in last position */
if (s[i] == '\\' && s[i + 1] == '\0')
return 0;
}
return 1;
} | 1 | C | CWE-78 | Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') | The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/78.html | safe |
valid_hostname(const char *s)
{
size_t i;
if (*s == '-')
return 0;
for (i = 0; s[i] != 0; i++) {
if (strchr("'`\"$\\;&<>|(){}", s[i]) != NULL ||
isspace((u_char)s[i]) || iscntrl((u_char)s[i]))
return 0;
}
return 1;
} | 1 | C | CWE-78 | Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') | The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/78.html | safe |
static int ntlm_decode_field(struct wire_field_hdr *hdr,
struct ntlm_buffer *buffer,
size_t payload_offs,
struct ntlm_buffer *field)
{
struct ntlm_buffer b = { NULL, 0 };
uint32_t offs;
uint16_t len;
len = le16toh(hdr->len);
if (len == 0) goto done;
offs = le32toh(hdr->offset);
if ((offs < payload_offs) ||
(offs > buffer->length) ||
(UINT32_MAX - offs < len) ||
(offs + len > buffer->length)) {
return ERR_DECODE;
}
b.data = malloc(len);
if (!b.data) return ENOMEM;
b.length = len;
memcpy(b.data, &buffer->data[offs], b.length);
done:
*field = b;
return 0;
} | 1 | C | CWE-125 | Out-of-bounds Read | The product reads data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/125.html | safe |
static int ntlm_decode_oem_str(struct wire_field_hdr *str_hdr,
struct ntlm_buffer *buffer,
size_t payload_offs, char **_str)
{
uint16_t str_len;
uint32_t str_offs;
char *str = NULL;
str_len = le16toh(str_hdr->len);
if (str_len == 0) goto done;
str_offs = le32toh(str_hdr->offset);
if ((str_offs < payload_offs) ||
(str_offs > buffer->length) ||
(UINT32_MAX - str_offs < str_len) ||
(str_offs + str_len > buffer->length)) {
return ERR_DECODE;
}
str = strndup((const char *)&buffer->data[str_offs], str_len);
if (!str) return ENOMEM;
done:
*_str = str;
return 0;
} | 1 | C | CWE-125 | Out-of-bounds Read | The product reads data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/125.html | safe |
static int ntlm_decode_u16l_str_hdr(struct ntlm_ctx *ctx,
struct wire_field_hdr *str_hdr,
struct ntlm_buffer *buffer,
size_t payload_offs, char **str)
{
char *in, *out = NULL;
uint16_t str_len;
uint32_t str_offs;
size_t outlen;
int ret = 0;
str_len = le16toh(str_hdr->len);
if (str_len == 0) goto done;
str_offs = le32toh(str_hdr->offset);
if ((str_offs < payload_offs) ||
(str_offs > buffer->length) ||
(UINT32_MAX - str_offs < str_len) ||
(str_offs + str_len > buffer->length)) {
return ERR_DECODE;
}
in = (char *)&buffer->data[str_offs];
out = malloc(str_len * 2 + 1);
if (!out) return ENOMEM;
ret = ntlm_str_convert(ctx->to_oem, in, out, str_len, &outlen);
/* make sure to terminate output string */
out[outlen] = '\0';
done:
if (ret) {
safefree(out);
}
*str = out;
return ret;
} | 1 | C | CWE-125 | Out-of-bounds Read | The product reads data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/125.html | safe |
static int ntlm_decode_u16l_str_hdr(struct ntlm_ctx *ctx,
struct wire_field_hdr *str_hdr,
struct ntlm_buffer *buffer,
size_t payload_offs, char **str)
{
char *in, *out = NULL;
uint16_t str_len;
uint32_t str_offs;
size_t outlen = 0;
int ret = 0;
str_len = le16toh(str_hdr->len);
if (str_len == 0) goto done;
str_offs = le32toh(str_hdr->offset);
if ((str_offs < payload_offs) ||
(str_offs > buffer->length) ||
(UINT32_MAX - str_offs < str_len) ||
(str_offs + str_len > buffer->length)) {
return ERR_DECODE;
}
in = (char *)&buffer->data[str_offs];
out = malloc(str_len * 2 + 1);
if (!out) return ENOMEM;
ret = ntlm_str_convert(ctx->to_oem, in, out, str_len, &outlen);
done:
if (ret) {
safefree(out);
} else {
/* make sure to terminate output string */
out[outlen] = '\0';
}
*str = out;
return ret;
} | 1 | C | CWE-787 | Out-of-bounds Write | The product writes data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/787.html | safe |
void SetClipboardText(const char *text)
{
#if defined(PLATFORM_DESKTOP)
glfwSetClipboardString(CORE.Window.handle, text);
#endif
#if defined(PLATFORM_WEB)
// Security check to (partially) avoid malicious code
if (strchr(text, '\'') != NULL) TRACELOG(LOG_WARNING, "SYSTEM: Provided Clipboard could be potentially malicious, avoid [\'] character");
else emscripten_run_script(TextFormat("navigator.clipboard.writeText('%s')", text));
#endif
} | 1 | C | CWE-79 | Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') | The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. | https://cwe.mitre.org/data/definitions/79.html | safe |
void TakeScreenshot(const char *fileName)
{
#if defined(SUPPORT_MODULE_RTEXTURES)
// Security check to (partially) avoid malicious code on PLATFORM_WEB
if (strchr(fileName, '\'') != NULL) { TRACELOG(LOG_WARNING, "SYSTEM: Provided fileName could be potentially malicious, avoid [\'] character"); return; }
Vector2 scale = GetWindowScaleDPI();
unsigned char *imgData = rlReadScreenPixels((int)((float)CORE.Window.render.width*scale.x), (int)((float)CORE.Window.render.height*scale.y));
Image image = { imgData, (int)((float)CORE.Window.render.width*scale.x), (int)((float)CORE.Window.render.height*scale.y), 1, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 };
char path[2048] = { 0 };
strcpy(path, TextFormat("%s/%s", CORE.Storage.basePath, fileName));
ExportImage(image, path); // WARNING: Module required: rtextures
RL_FREE(imgData);
#if defined(PLATFORM_WEB)
// Download file from MEMFS (emscripten memory filesystem)
// saveFileFromMEMFSToDisk() function is defined in raylib/src/shell.html
emscripten_run_script(TextFormat("saveFileFromMEMFSToDisk('%s','%s')", GetFileName(path), GetFileName(path)));
#endif
TRACELOG(LOG_INFO, "SYSTEM: [%s] Screenshot taken successfully", path);
#else
TRACELOG(LOG_WARNING,"IMAGE: ExportImage() requires module: rtextures");
#endif
} | 1 | C | CWE-79 | Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') | The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. | https://cwe.mitre.org/data/definitions/79.html | safe |
const char *GetClipboardText(void)
{
#if defined(PLATFORM_DESKTOP)
return glfwGetClipboardString(CORE.Window.handle);
#endif
#if defined(PLATFORM_WEB)
/*
// Accessing clipboard data from browser is tricky due to security reasons
// The method to use is navigator.clipboard.readText() but this is an asynchronous method
// that will return at some moment after the function is called with the required data
emscripten_run_script_string("navigator.clipboard.readText() \
.then(text => { document.getElementById('clipboard').innerText = text; console.log('Pasted content: ', text); }) \
.catch(err => { console.error('Failed to read clipboard contents: ', err); });"
);
// The main issue is getting that data, one approach could be using ASYNCIFY and wait
// for the data but it requires adding Asyncify emscripten library on compilation
// Another approach could be just copy the data in a HTML text field and try to retrieve it
// later on if available... and clean it for future accesses
*/
return NULL;
#endif
return NULL;
} | 1 | C | CWE-79 | Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') | The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. | https://cwe.mitre.org/data/definitions/79.html | safe |
static memcached_return_t _read_one_response(memcached_instance_st *instance, char *buffer,
const size_t buffer_length,
memcached_result_st *result) {
memcached_server_response_decrement(instance);
if (result == NULL) {
Memcached *root = (Memcached *) instance->root;
result = &root->result;
}
memcached_return_t rc;
if (memcached_is_binary(instance->root)) {
do {
rc = binary_read_one_response(instance, buffer, buffer_length, result);
} while (rc == MEMCACHED_FETCH_NOTFINISHED);
} else {
rc = textual_read_one_response(instance, buffer, buffer_length, result);
}
if (memcached_fatal(rc)) {
memcached_io_reset(instance);
}
return rc;
} | 1 | C | CWE-200 | Exposure of Sensitive Information to an Unauthorized Actor | The product exposes sensitive information to an actor that is not explicitly authorized to have access to that information. | https://cwe.mitre.org/data/definitions/200.html | safe |
ascii_load_sockaddr(struct sockaddr_storage *ss, char *buf)
{
if (!strcmp("local", buf)) {
ss->ss_family = AF_LOCAL;
}
else if (buf[0] == '[' && buf[strlen(buf)-1] == ']') {
struct addrinfo hints, *res0;
buf[strlen(buf)-1] = '\0';
/* getaddrinfo() is used to support scoped addresses. */
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET6;
hints.ai_flags = AI_NUMERICHOST;
if (getaddrinfo(buf+1, NULL, &hints, &res0) != 0)
return 0;
memcpy(ss, res0->ai_addr, res0->ai_addrlen);
ss->ss_len = res0->ai_addrlen;
freeaddrinfo(res0);
}
else {
struct sockaddr_in ssin;
memset(&ssin, 0, sizeof ssin);
if (inet_pton(AF_INET, buf, &ssin.sin_addr) != 1)
return 0;
ssin.sin_family = AF_INET;
memcpy(ss, &ssin, sizeof(ssin));
ss->ss_len = sizeof(struct sockaddr_in);
}
return 1;
} | 1 | C | NVD-CWE-noinfo | null | null | null | safe |
lib_contains_symbol(const char *path, const char *s)
{
struct nlist nl[2];
int ret = -1, r;
memset(nl, 0, sizeof(nl));
nl[0].n_name = xstrdup(s);
nl[1].n_name = NULL;
if ((r = nlist(path, nl)) == -1) {
error_f("nlist failed for %s", path);
goto out;
}
if (r != 0 || nl[0].n_value == 0 || nl[0].n_type == 0) {
error_f("library %s does not contain symbol %s", path, s);
goto out;
}
/* success */
ret = 0;
out:
free(nl[0].n_name);
return ret;
} | 1 | C | CWE-428 | Unquoted Search Path or Element | The product uses a search path that contains an unquoted element, in which the element contains whitespace or other separators. This can cause the product to access resources in a parent path. | https://cwe.mitre.org/data/definitions/428.html | safe |
sshsk_open(const char *path)
{
struct sshsk_provider *ret = NULL;
uint32_t version;
if (path == NULL || *path == '\0') {
error("No FIDO SecurityKeyProvider specified");
return NULL;
}
if ((ret = calloc(1, sizeof(*ret))) == NULL) {
error_f("calloc failed");
return NULL;
}
if ((ret->path = strdup(path)) == NULL) {
error_f("strdup failed");
goto fail;
}
/* Skip the rest if we're using the linked in middleware */
if (strcasecmp(ret->path, "internal") == 0) {
ret->sk_enroll = ssh_sk_enroll;
ret->sk_sign = ssh_sk_sign;
ret->sk_load_resident_keys = ssh_sk_load_resident_keys;
return ret;
}
if (lib_contains_symbol(path, "sk_api_version") != 0) {
error("provider %s is not an OpenSSH FIDO library", path);
goto fail;
}
if ((ret->dlhandle = dlopen(path, RTLD_NOW)) == NULL) {
error("Provider \"%s\" dlopen failed: %s", path, dlerror());
goto fail;
}
if ((ret->sk_api_version = dlsym(ret->dlhandle,
"sk_api_version")) == NULL) {
fatal("Provider \"%s\" dlsym(sk_api_version) failed: %s",
path, dlerror());
}
version = ret->sk_api_version();
debug_f("provider %s implements version 0x%08lx", ret->path,
(u_long)version);
if ((version & SSH_SK_VERSION_MAJOR_MASK) != SSH_SK_VERSION_MAJOR) {
error("Provider \"%s\" implements unsupported "
"version 0x%08lx (supported: 0x%08lx)",
path, (u_long)version, (u_long)SSH_SK_VERSION_MAJOR);
goto fail;
}
if ((ret->sk_enroll = dlsym(ret->dlhandle, "sk_enroll")) == NULL) {
error("Provider %s dlsym(sk_enroll) failed: %s",
path, dlerror());
goto fail;
}
if ((ret->sk_sign = dlsym(ret->dlhandle, "sk_sign")) == NULL) {
error("Provider \"%s\" dlsym(sk_sign) failed: %s",
path, dlerror());
goto fail;
}
if ((ret->sk_load_resident_keys = dlsym(ret->dlhandle,
"sk_load_resident_keys")) == NULL) {
error("Provider \"%s\" dlsym(sk_load_resident_keys) "
"failed: %s", path, dlerror());
goto fail;
}
/* success */
return ret;
fail:
sshsk_free(ret);
return NULL;
} | 1 | C | CWE-428 | Unquoted Search Path or Element | The product uses a search path that contains an unquoted element, in which the element contains whitespace or other separators. This can cause the product to access resources in a parent path. | https://cwe.mitre.org/data/definitions/428.html | safe |
wsemul_sun_output_control(struct wsemul_sun_emuldata *edp,
struct wsemul_inputstate *instate)
{
int oargs;
int rc;
switch (instate->inchar) {
case '0': case '1': case '2': case '3': case '4': /* argument digit */
case '5': case '6': case '7': case '8': case '9':
/*
* If we receive more arguments than we are expecting,
* discard the earliest arguments.
*/
if (edp->nargs > SUN_EMUL_NARGS - 1) {
bcopy(edp->args + 1, edp->args,
(SUN_EMUL_NARGS - 1) * sizeof(edp->args[0]));
edp->args[edp->nargs = SUN_EMUL_NARGS - 1] = 0;
}
edp->args[edp->nargs] = (edp->args[edp->nargs] * 10) +
(instate->inchar - '0');
break;
case ';': /* argument terminator */
if (edp->nargs < SUN_EMUL_NARGS)
edp->nargs++;
break;
default: /* end of escape sequence */
oargs = edp->nargs;
if (edp->nargs < SUN_EMUL_NARGS)
edp->nargs++;
rc = wsemul_sun_control(edp, instate);
if (rc != 0) {
/* undo nargs progress */
edp->nargs = oargs;
return rc;
}
edp->state = SUN_EMUL_STATE_NORMAL;
break;
}
return 0;
} | 1 | C | CWE-862 | Missing Authorization | The product does not perform an authorization check when an actor attempts to access a resource or perform an action. | https://cwe.mitre.org/data/definitions/862.html | safe |
wsemul_vt100_output_csi(struct wsemul_vt100_emuldata *edp,
struct wsemul_inputstate *instate)
{
u_int newstate = VT100_EMUL_STATE_CSI;
int oargs;
int rc = 0;
switch (instate->inchar) {
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
/* argument digit */
if (edp->nargs > VT100_EMUL_NARGS - 1)
break;
edp->args[edp->nargs] = (edp->args[edp->nargs] * 10) +
(instate->inchar - '0');
break;
case ';': /* argument terminator */
if (edp->nargs < VT100_EMUL_NARGS)
edp->nargs++;
break;
case '?': /* DEC specific */
case '>': /* DA query */
edp->modif1 = (char)instate->inchar;
break;
case '!':
case '"':
case '$':
case '&':
edp->modif2 = (char)instate->inchar;
break;
default: /* end of escape sequence */
oargs = edp->nargs;
if (edp->nargs < VT100_EMUL_NARGS)
edp->nargs++;
rc = wsemul_vt100_handle_csi(edp, instate);
if (rc != 0) {
edp->nargs = oargs;
return rc;
}
newstate = VT100_EMUL_STATE_NORMAL;
break;
}
if (COLS_LEFT != 0)
edp->flags &= ~VTFL_LASTCHAR;
edp->state = newstate;
return 0;
} | 1 | C | CWE-862 | Missing Authorization | The product does not perform an authorization check when an actor attempts to access a resource or perform an action. | https://cwe.mitre.org/data/definitions/862.html | safe |
wsemul_vt100_output_dcs(struct wsemul_vt100_emuldata *edp,
struct wsemul_inputstate *instate)
{
u_int newstate = VT100_EMUL_STATE_DCS;
switch (instate->inchar) {
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
/* argument digit */
if (edp->nargs > VT100_EMUL_NARGS - 1)
break;
edp->args[edp->nargs] = (edp->args[edp->nargs] * 10) +
(instate->inchar - '0');
break;
case ';': /* argument terminator */
if (edp->nargs < VT100_EMUL_NARGS)
edp->nargs++;
break;
default:
if (edp->nargs < VT100_EMUL_NARGS)
edp->nargs++;
newstate = VT100_EMUL_STATE_STRING;
switch (instate->inchar) {
case '$':
newstate = VT100_EMUL_STATE_DCS_DOLLAR;
break;
case '{': /* DECDLD soft charset */ /* } */
case '!': /* DECRQUPSS user preferred supplemental set */
/* 'u' must follow - need another state */
case '|': /* DECUDK program F6..F20 */
#ifdef VT100_PRINTNOTIMPL
printf("DCS%c ignored\n", (char)instate->inchar);
#endif
break;
default:
#ifdef VT100_PRINTUNKNOWN
printf("DCS %x (%d, %d) unknown\n", instate->inchar,
ARG(0), ARG(1));
#endif
break;
}
}
edp->state = newstate;
return 0;
} | 1 | C | CWE-862 | Missing Authorization | The product does not perform an authorization check when an actor attempts to access a resource or perform an action. | https://cwe.mitre.org/data/definitions/862.html | safe |
static pj_status_t get_name(int rec_counter, const pj_uint8_t *pkt,
const pj_uint8_t *start, const pj_uint8_t *max,
pj_str_t *name)
{
const pj_uint8_t *p;
pj_status_t status;
/* Limit the number of recursion */
if (rec_counter > 10) {
/* Too many name recursion */
return PJLIB_UTIL_EDNSINNAMEPTR;
}
if (start >= max)
return PJLIB_UTIL_EDNSINNAMEPTR;
p = start;
while (*p) {
if ((*p & 0xc0) == 0xc0) {
/* Compression is found! */
pj_uint16_t offset;
/* Get the 14bit offset */
pj_memcpy(&offset, p, 2);
offset ^= pj_htons((pj_uint16_t)(0xc0 << 8));
offset = pj_ntohs(offset);
/* Check that offset is valid */
if (offset >= max - pkt)
return PJLIB_UTIL_EDNSINNAMEPTR;
/* Retrieve the name from that offset. */
status = get_name(rec_counter+1, pkt, pkt + offset, max, name);
if (status != PJ_SUCCESS)
return status;
return PJ_SUCCESS;
} else {
unsigned label_len = *p;
/* Check that label length is valid.
* Each label consists of an octet length (of size 1) followed
* by the octet of the specified length (label_len). Then it
* must be followed by either another label's octet length or
* a zero length octet (that terminates the sequence).
*/
if (p+1+label_len+1 > max)
return PJLIB_UTIL_EDNSINNAMEPTR;
pj_memcpy(name->ptr + name->slen, p+1, label_len);
name->slen += label_len;
p += label_len + 1;
if (*p != 0) {
*(name->ptr + name->slen) = '.';
++name->slen;
}
}
}
return PJ_SUCCESS;
} | 1 | C | CWE-120 | Buffer Copy without Checking Size of Input ('Classic Buffer Overflow') | The product copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow. | https://cwe.mitre.org/data/definitions/120.html | safe |
static pj_status_t get_name(int rec_counter, const pj_uint8_t *pkt,
const pj_uint8_t *start, const pj_uint8_t *max,
pj_str_t *name)
{
const pj_uint8_t *p;
pj_status_t status;
/* Limit the number of recursion */
if (rec_counter > 10) {
/* Too many name recursion */
return PJLIB_UTIL_EDNSINNAMEPTR;
}
if (start >= max)
return PJLIB_UTIL_EDNSINNAMEPTR;
p = start;
while (*p) {
if ((*p & 0xc0) == 0xc0) {
/* Compression is found! */
pj_uint16_t offset;
/* Get the 14bit offset */
pj_memcpy(&offset, p, 2);
offset ^= pj_htons((pj_uint16_t)(0xc0 << 8));
offset = pj_ntohs(offset);
/* Check that offset is valid */
if (offset >= max - pkt)
return PJLIB_UTIL_EDNSINNAMEPTR;
/* Retrieve the name from that offset. */
status = get_name(rec_counter+1, pkt, pkt + offset, max, name);
if (status != PJ_SUCCESS)
return status;
return PJ_SUCCESS;
} else {
unsigned label_len = *p;
/* Check that label length is valid.
* Each label consists of an octet length (of size 1) followed
* by the octet of the specified length (label_len). Then it
* must be followed by either another label's octet length or
* a zero length octet (that terminates the sequence).
*/
if (p+1+label_len+1 > max)
return PJLIB_UTIL_EDNSINNAMEPTR;
pj_memcpy(name->ptr + name->slen, p+1, label_len);
name->slen += label_len;
p += label_len + 1;
if (*p != 0) {
*(name->ptr + name->slen) = '.';
++name->slen;
}
}
}
return PJ_SUCCESS;
} | 1 | C | CWE-122 | Heap-based Buffer Overflow | A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc(). | https://cwe.mitre.org/data/definitions/122.html | safe |
static pj_status_t transport_destroy (pjmedia_transport *tp)
{
struct tp_adapter *adapter = (struct tp_adapter*)tp;
/* Close the slave transport */
if (adapter->del_base) {
pjmedia_transport_close(adapter->slave_tp);
}
if (adapter->base.grp_lock) {
pj_grp_lock_dec_ref(adapter->base.grp_lock);
} else {
adapter_on_destroy(tp);
}
return PJ_SUCCESS;
} | 1 | C | CWE-416 | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. | https://cwe.mitre.org/data/definitions/416.html | safe |
PJ_DEF(pj_status_t) pjmedia_tp_adapter_create( pjmedia_endpt *endpt,
const char *name,
pjmedia_transport *transport,
pj_bool_t del_base,
pjmedia_transport **p_tp)
{
pj_pool_t *pool;
struct tp_adapter *adapter;
if (name == NULL)
name = "tpad%p";
/* Create the pool and initialize the adapter structure */
pool = pjmedia_endpt_create_pool(endpt, name, 512, 512);
adapter = PJ_POOL_ZALLOC_T(pool, struct tp_adapter);
adapter->pool = pool;
pj_ansi_strxcpy(adapter->base.name, pool->obj_name,
sizeof(adapter->base.name));
adapter->base.type = (pjmedia_transport_type)
(PJMEDIA_TRANSPORT_TYPE_USER + 1);
adapter->base.op = &tp_adapter_op;
/* Save the transport as the slave transport */
adapter->slave_tp = transport;
adapter->del_base = del_base;
/* Setup group lock handler for destroy and callback synchronization */
if (transport && transport->grp_lock) {
pj_grp_lock_t *grp_lock = transport->grp_lock;
adapter->base.grp_lock = grp_lock;
pj_grp_lock_add_ref(grp_lock);
pj_grp_lock_add_handler(grp_lock, pool, adapter, &adapter_on_destroy);
}
/* Done */
*p_tp = &adapter->base;
return PJ_SUCCESS;
} | 1 | C | CWE-416 | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. | https://cwe.mitre.org/data/definitions/416.html | safe |
static void adapter_on_destroy(void *arg)
{
struct tp_adapter *adapter = (struct tp_adapter*)arg;
pj_pool_release(adapter->pool);
} | 1 | C | CWE-416 | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. | https://cwe.mitre.org/data/definitions/416.html | safe |
static pj_status_t transport_destroy(pjmedia_transport *tp)
{
struct transport_ice *tp_ice = (struct transport_ice*)tp;
PJ_LOG(4, (tp_ice->base.name, "Destroying ICE transport"));
/* Reset callback and user data */
pj_bzero(&tp_ice->cb, sizeof(tp_ice->cb));
tp_ice->base.user_data = NULL;
tp_ice->rtp_cb = NULL;
tp_ice->rtp_cb2 = NULL;
tp_ice->rtcp_cb = NULL;
if (tp_ice->ice_st) {
pj_grp_lock_t *grp_lock = pj_ice_strans_get_grp_lock(tp_ice->ice_st);
pj_ice_strans_destroy(tp_ice->ice_st);
tp_ice->ice_st = NULL;
pj_grp_lock_dec_ref(grp_lock);
} else {
tp_ice_on_destroy(tp);
}
return PJ_SUCCESS;
} | 1 | C | CWE-416 | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. | https://cwe.mitre.org/data/definitions/416.html | safe |
static void tp_ice_on_destroy(void *arg)
{
struct transport_ice *tp_ice = (struct transport_ice*)arg;
PJ_LOG(4, (tp_ice->base.name, "ICE transport destroyed"));
pj_pool_safe_release(&tp_ice->pool);
} | 1 | C | CWE-416 | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. | https://cwe.mitre.org/data/definitions/416.html | safe |
static pj_status_t transport_send_rtcp2(pjmedia_transport *tp,
const pj_sockaddr_t *addr,
unsigned addr_len,
const void *pkt,
pj_size_t size)
{
struct transport_loop *loop = (struct transport_loop*)tp;
unsigned i;
PJ_UNUSED_ARG(addr_len);
PJ_UNUSED_ARG(addr);
pj_grp_lock_add_ref(tp->grp_lock);
/* Distribute to users */
for (i=0; i<loop->user_cnt; ++i) {
if (!loop->users[i].rx_disabled && loop->users[i].rtcp_cb)
(*loop->users[i].rtcp_cb)(loop->users[i].user_data, (void*)pkt,
size);
}
pj_grp_lock_dec_ref(tp->grp_lock);
return PJ_SUCCESS;
} | 1 | C | CWE-416 | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. | https://cwe.mitre.org/data/definitions/416.html | safe |
static void tp_loop_on_destroy(void *arg)
{
struct transport_loop *loop = (struct transport_loop*) arg;
PJ_LOG(4, (loop->base.name, "Loop transport destroyed"));
pj_pool_release(loop->pool);
} | 1 | C | CWE-416 | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. | https://cwe.mitre.org/data/definitions/416.html | safe |
static pj_status_t transport_destroy(pjmedia_transport *tp)
{
/* Sanity check */
PJ_ASSERT_RETURN(tp, PJ_EINVAL);
pj_grp_lock_dec_ref(tp->grp_lock);
return PJ_SUCCESS;
} | 1 | C | CWE-416 | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. | https://cwe.mitre.org/data/definitions/416.html | safe |
pjmedia_transport_loop_create2(pjmedia_endpt *endpt,
const pjmedia_loop_tp_setting *opt,
pjmedia_transport **p_tp)
{
struct transport_loop *tp;
pj_pool_t *pool;
pj_grp_lock_t *grp_lock;
pj_status_t status;
/* Sanity check */
PJ_ASSERT_RETURN(endpt && p_tp, PJ_EINVAL);
/* Create transport structure */
pool = pjmedia_endpt_create_pool(endpt, "tploop", 512, 512);
if (!pool)
return PJ_ENOMEM;
tp = PJ_POOL_ZALLOC_T(pool, struct transport_loop);
tp->pool = pool;
pj_memcpy(tp->base.name, tp->pool->obj_name, PJ_MAX_OBJ_NAME);
tp->base.op = &transport_udp_op;
tp->base.type = PJMEDIA_TRANSPORT_TYPE_UDP;
/* Create group lock */
status = pj_grp_lock_create(pool, NULL, &grp_lock);
if (status != PJ_SUCCESS)
return status;
pj_grp_lock_add_ref(grp_lock);
pj_grp_lock_add_handler(grp_lock, pool, tp, &tp_loop_on_destroy);
if (opt) {
tp->setting = *opt;
} else {
pjmedia_loop_tp_setting_default(&tp->setting);
}
if (tp->setting.addr.slen) {
pj_strdup(pool, &tp->setting.addr, &opt->addr);
} else {
pj_strset2(&tp->setting.addr, (tp->setting.af == pj_AF_INET())?
"127.0.0.1": "::1");
}
if (tp->setting.port == 0)
tp->setting.port = 4000;
/* alloc users array */
tp->max_attach_cnt = tp->setting.max_attach_cnt;
if (tp->max_attach_cnt == 0)
tp->max_attach_cnt = 1;
tp->users = (struct tp_user *)pj_pool_calloc(pool, tp->max_attach_cnt, sizeof(struct tp_user));
/* Done */
*p_tp = &tp->base;
return PJ_SUCCESS;
} | 1 | C | CWE-416 | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. | https://cwe.mitre.org/data/definitions/416.html | safe |
static pj_status_t transport_send_rtp( pjmedia_transport *tp,
const void *pkt,
pj_size_t size)
{
struct transport_loop *loop = (struct transport_loop*)tp;
unsigned i;
/* Simulate packet lost on TX direction */
if (loop->tx_drop_pct) {
if ((pj_rand() % 100) <= (int)loop->tx_drop_pct) {
PJ_LOG(5,(loop->base.name,
"TX RTP packet dropped because of pkt lost "
"simulation"));
return PJ_SUCCESS;
}
}
/* Simulate packet lost on RX direction */
if (loop->rx_drop_pct) {
if ((pj_rand() % 100) <= (int)loop->rx_drop_pct) {
PJ_LOG(5,(loop->base.name,
"RX RTP packet dropped because of pkt lost "
"simulation"));
return PJ_SUCCESS;
}
}
pj_grp_lock_add_ref(tp->grp_lock);
/* Distribute to users */
for (i=0; i<loop->user_cnt; ++i) {
if (loop->users[i].rx_disabled) continue;
if (loop->users[i].rtp_cb2) {
pjmedia_tp_cb_param param;
pj_bzero(¶m, sizeof(param));
param.user_data = loop->users[i].user_data;
param.pkt = (void *)pkt;
param.size = size;
(*loop->users[i].rtp_cb2)(¶m);
} else if (loop->users[i].rtp_cb) {
(*loop->users[i].rtp_cb)(loop->users[i].user_data, (void*)pkt,
size);
}
}
pj_grp_lock_dec_ref(tp->grp_lock);
return PJ_SUCCESS;
} | 1 | C | CWE-416 | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. | https://cwe.mitre.org/data/definitions/416.html | safe |
static pj_status_t transport_destroy (pjmedia_transport *tp)
{
transport_srtp *srtp = (transport_srtp *) tp;
pj_status_t status;
unsigned i;
PJ_ASSERT_RETURN(tp, PJ_EINVAL);
PJ_LOG(4, (srtp->pool->obj_name, "Destroying SRTP transport"));
/* Close all keying. Note that any keying should not be destroyed before
* SRTP transport is destroyed as re-INVITE may initiate new keying method
* without destroying SRTP transport.
*/
for (i=0; i < srtp->all_keying_cnt; i++)
pjmedia_transport_close(srtp->all_keying[i]);
/* Close member if configured */
if (srtp->setting.close_member_tp && srtp->member_tp) {
pjmedia_transport_close(srtp->member_tp);
}
status = pjmedia_transport_srtp_stop(tp);
if (srtp->base.grp_lock) {
pj_grp_lock_dec_ref(srtp->base.grp_lock);
} else {
/* Only get here when the underlying transport does not have
* a group lock, race condition with callbacks may occur.
* Currently UDP, ICE, and loop have a group lock already.
*/
PJ_LOG(4,(srtp->pool->obj_name,
"Warning: underlying transport does not have group lock"));
/* In case mutex is being acquired by other thread.
* An effort to synchronize destroy() & callbacks when the underlying
* transport does not provide a group lock.
*/
pj_lock_acquire(srtp->mutex);
pj_lock_release(srtp->mutex);
srtp_on_destroy(srtp);
}
return status;
} | 1 | C | CWE-416 | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. | https://cwe.mitre.org/data/definitions/416.html | safe |
static void srtp_on_destroy(void *arg)
{
transport_srtp *srtp = (transport_srtp*)arg;
PJ_LOG(4, (srtp->pool->obj_name, "SRTP transport destroyed"));
pj_lock_destroy(srtp->mutex);
pj_pool_safe_release(&srtp->pool);
} | 1 | C | CWE-416 | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. | https://cwe.mitre.org/data/definitions/416.html | safe |
static void clock_cb(const pj_timestamp *ts, void *user_data)
{
dtls_srtp_channel *ds_ch = (dtls_srtp_channel*)user_data;
dtls_srtp *ds = ds_ch->dtls_srtp;
unsigned idx = ds_ch->channel;
PJ_UNUSED_ARG(ts);
DTLS_LOCK(ds);
if (!ds->ossl_ssl[idx]) {
DTLS_UNLOCK(ds);
return;
}
if (DTLSv1_handle_timeout(ds->ossl_ssl[idx]) > 0) {
DTLS_UNLOCK(ds);
ssl_flush_wbio(ds, idx);
} else {
DTLS_UNLOCK(ds);
}
} | 1 | C | CWE-416 | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. | https://cwe.mitre.org/data/definitions/416.html | safe |
static pj_status_t dtls_create(transport_srtp *srtp,
pjmedia_transport **p_keying)
{
dtls_srtp *ds;
pj_pool_t *pool;
pj_status_t status;
pool = pj_pool_create(srtp->pool->factory, "dtls%p",
2000, 256, NULL);
ds = PJ_POOL_ZALLOC_T(pool, dtls_srtp);
ds->pool = pool;
pj_ansi_strxcpy(ds->base.name, pool->obj_name, PJ_MAX_OBJ_NAME);
ds->base.type = (pjmedia_transport_type)PJMEDIA_SRTP_KEYING_DTLS_SRTP;
ds->base.op = &dtls_op;
ds->base.user_data = srtp;
ds->srtp = srtp;
/* Setup group lock handler for destroy and callback synchronization */
if (srtp->base.grp_lock) {
pj_grp_lock_t *grp_lock = srtp->base.grp_lock;
ds->base.grp_lock = grp_lock;
pj_grp_lock_add_ref(grp_lock);
pj_grp_lock_add_handler(grp_lock, pool, ds, &dtls_on_destroy);
} else {
status = pj_lock_create_simple_mutex(ds->pool, "dtls_ssl_lock%p",
&ds->ossl_lock);
if (status != PJ_SUCCESS)
return status;
}
*p_keying = &ds->base;
PJ_LOG(5,(srtp->pool->obj_name, "SRTP keying DTLS-SRTP created"));
return PJ_SUCCESS;
} | 1 | C | CWE-416 | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. | https://cwe.mitre.org/data/definitions/416.html | safe |
static pj_status_t ssl_match_fingerprint(dtls_srtp *ds, unsigned idx)
{
X509 *rem_cert;
pj_bool_t is_sha256;
char buf[128];
pj_size_t buf_len = sizeof(buf);
pj_status_t status;
/* Check hash algo, currently we only support SHA-256 & SHA-1 */
if (!pj_strnicmp2(&ds->rem_fingerprint, "SHA-256 ", 8))
is_sha256 = PJ_TRUE;
else if (!pj_strnicmp2(&ds->rem_fingerprint, "SHA-1 ", 6))
is_sha256 = PJ_FALSE;
else {
PJ_LOG(4,(ds->base.name, "Hash algo specified in remote SDP for "
"its DTLS certificate fingerprint is not supported"));
return PJ_ENOTSUP;
}
DTLS_LOCK(ds);
if (!ds->ossl_ssl[idx]) {
DTLS_UNLOCK(ds);
return PJ_EGONE;
}
/* Get remote cert & calculate the hash */
rem_cert = SSL_get_peer_certificate(ds->ossl_ssl[idx]);
DTLS_UNLOCK(ds);
if (!rem_cert)
return PJMEDIA_SRTP_DTLS_EPEERNOCERT;
status = ssl_get_fingerprint(rem_cert, is_sha256, buf, &buf_len);
X509_free(rem_cert);
if (status != PJ_SUCCESS)
return status;
/* Do they match? */
if (pj_stricmp2(&ds->rem_fingerprint, buf))
return PJMEDIA_SRTP_DTLS_EFPNOTMATCH;
return PJ_SUCCESS;
} | 1 | C | CWE-416 | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. | https://cwe.mitre.org/data/definitions/416.html | safe |
static pj_status_t ssl_on_recv_packet(dtls_srtp *ds, unsigned idx,
const void *data, pj_size_t len)
{
char tmp[128];
pj_size_t nwritten;
DTLS_LOCK(ds);
if (!ds->ossl_rbio[idx]) {
DTLS_UNLOCK(ds);
return PJ_EGONE;
}
nwritten = BIO_write(ds->ossl_rbio[idx], data, (int)len);
if (nwritten < len) {
/* Error? */
pj_status_t status;
status = GET_SSL_STATUS(ds);
#if DTLS_DEBUG
pj_perror(2, ds->base.name, status, "BIO_write() error");
#endif
DTLS_UNLOCK(ds);
return status;
}
if (!ds->ossl_ssl[idx]) {
DTLS_UNLOCK(ds);
return PJ_EGONE;
}
/* Consume (and ignore) the packet */
while (1) {
int rc = SSL_read(ds->ossl_ssl[idx], tmp, sizeof(tmp));
if (rc <= 0) {
#if DTLS_DEBUG
pj_status_t status = GET_SSL_STATUS(ds);
if (status != PJ_SUCCESS)
pj_perror(2, ds->base.name, status, "SSL_read() error");
#endif
break;
}
}
DTLS_UNLOCK(ds);
/* Flush anything pending in the write BIO */
return ssl_flush_wbio(ds, idx);
} | 1 | C | CWE-416 | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. | https://cwe.mitre.org/data/definitions/416.html | safe |
static pj_status_t dtls_destroy(pjmedia_transport *tp)
{
dtls_srtp *ds = (dtls_srtp *)tp;
#if DTLS_DEBUG
PJ_LOG(2,(ds->base.name, "dtls_destroy()"));
#endif
ds->is_destroying = PJ_TRUE;
DTLS_LOCK(ds);
dtls_destroy_channel(ds, RTP_CHANNEL);
dtls_destroy_channel(ds, RTCP_CHANNEL);
DTLS_UNLOCK(ds);
if (ds->base.grp_lock) {
pj_grp_lock_dec_ref(ds->base.grp_lock);
} else {
dtls_on_destroy(tp);
}
return PJ_SUCCESS;
} | 1 | C | CWE-416 | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. | https://cwe.mitre.org/data/definitions/416.html | safe |
static void DTLS_LOCK(dtls_srtp *ds) {
if (ds->base.grp_lock)
pj_grp_lock_acquire(ds->base.grp_lock);
else
pj_lock_acquire(ds->ossl_lock);
} | 1 | C | CWE-416 | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. | https://cwe.mitre.org/data/definitions/416.html | safe |
static void DTLS_UNLOCK(dtls_srtp *ds) {
if (ds->base.grp_lock)
pj_grp_lock_release(ds->base.grp_lock);
else
pj_lock_release(ds->ossl_lock);
} | 1 | C | CWE-416 | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. | https://cwe.mitre.org/data/definitions/416.html | safe |
static void ssl_destroy(dtls_srtp *ds, unsigned idx)
{
DTLS_LOCK(ds);
/* Destroy SSL instance */
if (ds->ossl_ssl[idx]) {
/**
* Avoid calling SSL_shutdown() if handshake wasn't completed.
* OpenSSL 1.0.2f complains if SSL_shutdown() is called during an
* SSL handshake, while previous versions always return 0.
*/
if (SSL_in_init(ds->ossl_ssl[idx]) == 0) {
SSL_shutdown(ds->ossl_ssl[idx]);
}
SSL_free(ds->ossl_ssl[idx]); /* this will also close BIOs */
ds->ossl_ssl[idx] = NULL;
/* thus reset the BIOs as well */
ds->ossl_rbio[idx] = NULL;
ds->ossl_wbio[idx] = NULL;
}
/* Destroy SSL context */
if (ds->ossl_ctx[idx]) {
SSL_CTX_free(ds->ossl_ctx[idx]);
ds->ossl_ctx[idx] = NULL;
}
DTLS_UNLOCK(ds);
} | 1 | C | CWE-416 | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. | https://cwe.mitre.org/data/definitions/416.html | safe |
static void dtls_on_destroy(void *arg) {
dtls_srtp *ds = (dtls_srtp *)arg;
if (ds->ossl_lock)
pj_lock_destroy(ds->ossl_lock);
pj_pool_safe_release(&ds->pool);
} | 1 | C | CWE-416 | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. | https://cwe.mitre.org/data/definitions/416.html | safe |
static pj_status_t transport_destroy(pjmedia_transport *tp)
{
struct transport_udp *udp = (struct transport_udp*) tp;
/* Sanity check */
PJ_ASSERT_RETURN(tp, PJ_EINVAL);
/* Must not close while application is using this */
//PJ_ASSERT_RETURN(!udp->attached, PJ_EINVALIDOP);
/* The following calls to pj_ioqueue_unregister() will block the execution
* if callback is still being called because allow_concurrent is false.
* So it is safe to release the pool immediately after.
*/
if (udp->rtp_key) {
pj_ioqueue_unregister(udp->rtp_key);
udp->rtp_key = NULL;
udp->rtp_sock = PJ_INVALID_SOCKET;
} else if (udp->rtp_sock != PJ_INVALID_SOCKET) {
pj_sock_close(udp->rtp_sock);
udp->rtp_sock = PJ_INVALID_SOCKET;
}
if (udp->rtcp_key) {
pj_ioqueue_unregister(udp->rtcp_key);
udp->rtcp_key = NULL;
udp->rtcp_sock = PJ_INVALID_SOCKET;
} else if (udp->rtcp_sock != PJ_INVALID_SOCKET) {
pj_sock_close(udp->rtcp_sock);
udp->rtcp_sock = PJ_INVALID_SOCKET;
}
pj_grp_lock_dec_ref(tp->grp_lock);
PJ_LOG(4,(udp->base.name, "UDP media transport destroyed"));
pj_pool_release(udp->pool);
return PJ_SUCCESS;
} | 1 | C | CWE-416 | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. | https://cwe.mitre.org/data/definitions/416.html | safe |
static RzList /*<RzDebugMap *>*/ *__io_maps(RzDebug *dbg) {
RzList *list = rz_list_new();
char *str = dbg->iob.system(dbg->iob.io, "dm");
if (!str) {
rz_list_free(list);
return NULL;
}
char *ostr = str;
ut64 map_start, map_end;
char perm[IO_MAPS_PERM_SZ + 1];
char name[IO_MAPS_NAME_SZ + 1];
for (;;) {
char *nl = strchr(str, '\n');
if (nl) {
*nl = 0;
*name = 0;
*perm = 0;
map_start = map_end = 0LL;
if (!strncmp(str, "sys ", 4)) {
char *sp = strchr(str + 4, ' ');
if (sp) {
str = sp + 1;
} else {
str += 4;
}
}
char *_s_ = strstr(str, " s ");
if (_s_) {
memmove(_s_, _s_ + 2, strlen(_s_));
}
_s_ = strstr(str, " ? ");
if (_s_) {
memmove(_s_, _s_ + 2, strlen(_s_));
}
sscanf(str, "0x%" PFMT64x " - 0x%" PFMT64x " %" RZ_STR_DEF(IO_MAPS_PERM_SZ) "s %" RZ_STR_DEF(IO_MAPS_NAME_SZ) "s",
&map_start, &map_end, perm, name);
if (map_end != 0LL) {
RzDebugMap *map = rz_debug_map_new(name, map_start, map_end, rz_str_rwx(perm), 0);
rz_list_append(list, map);
}
str = nl + 1;
} else {
break;
}
}
free(ostr);
rz_cons_reset();
return list;
} | 1 | C | CWE-120 | Buffer Copy without Checking Size of Input ('Classic Buffer Overflow') | The product copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow. | https://cwe.mitre.org/data/definitions/120.html | safe |
static RzList /*<RzDebugMap *>*/ *__io_maps(RzDebug *dbg) {
RzList *list = rz_list_new();
char *str = dbg->iob.system(dbg->iob.io, "dm");
if (!str) {
rz_list_free(list);
return NULL;
}
char *ostr = str;
ut64 map_start, map_end;
char perm[IO_MAPS_PERM_SZ + 1];
char name[IO_MAPS_NAME_SZ + 1];
for (;;) {
char *nl = strchr(str, '\n');
if (nl) {
*nl = 0;
*name = 0;
*perm = 0;
map_start = map_end = 0LL;
if (!strncmp(str, "sys ", 4)) {
char *sp = strchr(str + 4, ' ');
if (sp) {
str = sp + 1;
} else {
str += 4;
}
}
char *_s_ = strstr(str, " s ");
if (_s_) {
memmove(_s_, _s_ + 2, strlen(_s_));
}
_s_ = strstr(str, " ? ");
if (_s_) {
memmove(_s_, _s_ + 2, strlen(_s_));
}
sscanf(str, "0x%" PFMT64x " - 0x%" PFMT64x " %" RZ_STR_DEF(IO_MAPS_PERM_SZ) "s %" RZ_STR_DEF(IO_MAPS_NAME_SZ) "s",
&map_start, &map_end, perm, name);
if (map_end != 0LL) {
RzDebugMap *map = rz_debug_map_new(name, map_start, map_end, rz_str_rwx(perm), 0);
rz_list_append(list, map);
}
str = nl + 1;
} else {
break;
}
}
free(ostr);
rz_cons_reset();
return list;
} | 1 | C | CWE-121 | Stack-based Buffer Overflow | A stack-based buffer overflow condition is a condition where the buffer being overwritten is allocated on the stack (i.e., is a local variable or, rarely, a parameter to a function). | https://cwe.mitre.org/data/definitions/121.html | safe |
int delete_sdp_line( struct sip_msg * msg, char * s, struct sdp_stream_cell *stream)
{
char * start,*end;
if( !s )
return 1;
start = s;
end = s;
while(*start != '\n' && start > stream->body.s)
start--;
start++;
while(*end != '\n' && end < (stream->body.s+stream->body.len) )
end++;
end++;
/* delete the entry */
if( del_lump(msg, start - msg->buf, end - start,0) == NULL )
{
return -1;
}
return 0;
} | 1 | C | NVD-CWE-noinfo | null | null | null | safe |
int delete_sdp_line( struct sip_msg * msg, char * s, struct sdp_stream_cell *stream)
{
char * start,*end;
if( !s )
return 1;
start = s;
end = s;
while(*start != '\n' && start > stream->body.s)
start--;
start++;
while(*end != '\n' && end < (stream->body.s+stream->body.len) )
end++;
if ( *end == '\n')
end++;
/* delete the entry */
if( del_lump(msg, start - msg->buf, end - start,0) == NULL )
{
return -1;
}
return 0;
} | 1 | C | NVD-CWE-noinfo | null | null | null | safe |
char* parse_content_length( char* buffer, char* end, int* length)
{
int number;
char *p;
int size;
p = buffer;
/* search the beginning of the number */
while ( p<end && (*p==' ' || *p=='\t' || (*p=='\r' && *(p+1)=='\n') ||
(*p=='\n' && (*(p+1)==' '||*(p+1)=='\t')) ))
p++;
if (p==end)
goto error;
/* parse the number */
size = 0;
number = 0;
while (p<end && *p>='0' && *p<='9') {
/* do not actually cause an integer overflow, as it is UB! --liviu */
if (number > 214748363) {
LM_ERR("integer overflow risk at pos %d in len number [%.*s]\n",
(int)(p-buffer),(int)(end-buffer), buffer);
return 0;
}
number = number*10 + (*p)-'0';
size ++;
p++;
}
if (p==end || size==0)
goto error;
/* now we should have only spaces at the end */
while ( p<end && (*p==' ' || *p=='\t' ||
(*p=='\n' && (*(p+1)==' '||*(p+1)=='\t')) ))
p++;
if (p==end)
goto error;
/* the header ends proper? */
if ( (*(p++)!='\n') && (*(p-1)!='\r' || *(p++)!='\n' ) )
goto error;
*length = number;
return p;
error:
LM_ERR("parse error near char [%d][%c]\n",*p,*p);
return 0;
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.