func
stringlengths
12
2.67k
cwe
stringclasses
7 values
__index_level_0__
int64
0
20k
check_owner_password_V4(std::string& user_password, std::string const& owner_password, QPDF::EncryptionData const& data) { // Algorithm 3.7 from the PDF 1.7 Reference Manual unsigned char key[OU_key_bytes_V4]; compute_O_rc4_key(user_password, owner_password, data, key); unsigned char O_data[key_bytes]; memcpy(O_data, QUtil::unsigned_char_pointer(data.getO()), key_bytes); std::string k1(reinterpret_cast<char*>(key), OU_key_bytes_V4); pad_short_parameter(k1, data.getLengthBytes()); iterate_rc4(O_data, key_bytes, QUtil::unsigned_char_pointer(k1), data.getLengthBytes(), (data.getR() >= 3) ? 20 : 1, true); std::string new_user_password = std::string(reinterpret_cast<char*>(O_data), key_bytes); bool result = false; if (check_user_password(new_user_password, data)) { result = true; user_password = new_user_password; } return result; }
CWE-787
16,720
static void doubleBoxSize(QPDFObjectHandle& page, char const* box_name) { // If there is a box of this name, replace it with a new box whose // elements are double the values of the original box. QPDFObjectHandle box = page.getKey(box_name); if (box.isNull()) { return; } if (! (box.isArray() && (box.getArrayNItems() == 4))) { throw std::runtime_error(std::string("box ") + box_name + " is not an array of four elements"); } std::vector<QPDFObjectHandle> doubled; for (unsigned int i = 0; i < 4; ++i) { doubled.push_back( QPDFObjectHandle::newReal( box.getArrayItem(i).getNumericValue() * 2.0, 2)); } page.replaceKey(box_name, QPDFObjectHandle::newArray(doubled)); }
CWE-787
16,721
static void handle_rotations(QPDF& pdf, Options& o) { QPDFPageDocumentHelper dh(pdf); std::vector<QPDFPageObjectHelper> pages = dh.getAllPages(); int npages = static_cast<int>(pages.size()); for (std::map<std::string, RotationSpec>::iterator iter = o.rotations.begin(); iter != o.rotations.end(); ++iter) { std::string const& range = (*iter).first; RotationSpec const& rspec = (*iter).second; // range has been previously validated std::vector<int> to_rotate = QUtil::parse_numrange(range.c_str(), npages); for (std::vector<int>::iterator i2 = to_rotate.begin(); i2 != to_rotate.end(); ++i2) { int pageno = *i2 - 1; if ((pageno >= 0) && (pageno < npages)) { pages.at(pageno).rotatePage(rspec.angle, rspec.relative); } } } }
CWE-787
16,722
load_vector_vector(BitStream& bit_stream, int nitems1, std::vector<T>& vec1, int T::*nitems2, int bits_wanted, std::vector<int> T::*vec2) { // nitems1 times, read nitems2 (from the ith element of vec1) items // into the vec2 vector field of the ith item of vec1. for (int i1 = 0; i1 < nitems1; ++i1) { for (int i2 = 0; i2 < vec1.at(i1).*nitems2; ++i2) { (vec1.at(i1).*vec2).push_back(bit_stream.getBits(bits_wanted)); } } bit_stream.skipToNextByte(); }
CWE-787
16,723
QUtil::safe_fopen(char const* filename, char const* mode) { FILE* f = 0; #ifdef _WIN32 // Convert the utf-8 encoded filename argument to wchar_t*. First, // convert to utf16, then to wchar_t*. Note that u16 will start // with the UTF16 marker, which we skip. std::string u16 = utf8_to_utf16(filename); size_t len = u16.length(); size_t wlen = (len / 2) - 1; PointerHolder<wchar_t> wfilenamep(true, new wchar_t[wlen + 1]); wchar_t* wfilename = wfilenamep.getPointer(); wfilename[wlen] = 0; for (unsigned int i = 2; i < len; i += 2) { wfilename[(i/2) - 1] = static_cast<wchar_t>( (static_cast<unsigned char>(u16.at(i)) << 8) + static_cast<unsigned char>(u16.at(i+1))); } PointerHolder<wchar_t> wmodep(true, new wchar_t[strlen(mode) + 1]); wchar_t* wmode = wmodep.getPointer(); wmode[strlen(mode)] = 0; for (size_t i = 0; i < strlen(mode); ++i) { wmode[i] = mode[i]; } #ifdef _MSC_VER errno_t err = _wfopen_s(&f, wfilename, wmode); if (err != 0) { errno = err; } #else f = _wfopen(wfilename, wmode); #endif if (f == 0) { throw_system_error(std::string("open ") + filename); } #else f = fopen_wrapper(std::string("open ") + filename, fopen(filename, mode)); #endif return f; }
CWE-787
16,727
WindowsCryptProvider() { if (!CryptAcquireContext(&crypt_prov, "Container", NULL, PROV_RSA_FULL, 0)) { #if ((defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || \ defined(__clang__)) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wold-style-cast" # pragma GCC diagnostic ignored "-Wsign-compare" #endif if (GetLastError() == NTE_BAD_KEYSET) #if ((defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || \ defined(__clang__)) # pragma GCC diagnostic pop #endif { if (! CryptAcquireContext(&crypt_prov, "Container", NULL, PROV_RSA_FULL, CRYPT_NEWKEYSET)) { throw std::runtime_error( "unable to acquire crypt context with new keyset"); } } else { throw std::runtime_error("unable to acquire crypt context"); } } }
CWE-787
16,728
BitStream::getBits(int nbits) { return read_bits(this->p, this->bit_offset, this->bits_available, nbits); }
CWE-787
16,729
compute_U_value_R3(std::string const& user_password, QPDF::EncryptionData const& data) { // Algorithm 3.5 from the PDF 1.7 Reference Manual std::string k1 = QPDF::compute_encryption_key(user_password, data); MD5 md5; md5.encodeDataIncrementally( pad_or_truncate_password_V4("").c_str(), key_bytes); md5.encodeDataIncrementally(data.getId1().c_str(), data.getId1().length()); MD5::Digest digest; md5.digest(digest); pad_short_parameter(k1, data.getLengthBytes()); iterate_rc4(digest, sizeof(MD5::Digest), QUtil::unsigned_char_pointer(k1), data.getLengthBytes(), 20, false); char result[key_bytes]; memcpy(result, digest, sizeof(MD5::Digest)); // pad with arbitrary data -- make it consistent for the sake of // testing for (unsigned int i = sizeof(MD5::Digest); i < key_bytes; ++i) { result[i] = static_cast<char>((i * i) % 0xff); } return std::string(result, key_bytes); }
CWE-787
16,730
QPDF::generateHintStream(std::map<int, QPDFXRefEntry> const& xref, std::map<int, qpdf_offset_t> const& lengths, std::map<int, int> const& obj_renumber, PointerHolder<Buffer>& hint_buffer, int& S, int& O) { // Populate actual hint table values calculateHPageOffset(xref, lengths, obj_renumber); calculateHSharedObject(xref, lengths, obj_renumber); calculateHOutline(xref, lengths, obj_renumber); // Write the hint stream itself into a compressed memory buffer. // Write through a counter so we can get offsets. Pl_Buffer hint_stream("hint stream"); Pl_Flate f("compress hint stream", &hint_stream, Pl_Flate::a_deflate); Pl_Count c("count", &f); BitWriter w(&c); writeHPageOffset(w); S = c.getCount(); writeHSharedObject(w); O = 0; if (this->m->outline_hints.nobjects > 0) { O = c.getCount(); writeHGeneric(w, this->m->outline_hints); } c.finish(); hint_buffer = hint_stream.getBuffer(); }
CWE-787
16,731
InputSource::findLast(char const* start_chars, qpdf_offset_t offset, size_t len, Finder& finder) { bool found = false; qpdf_offset_t after_found_offset = 0; qpdf_offset_t cur_offset = offset; size_t cur_len = len; while (this->findFirst(start_chars, cur_offset, cur_len, finder)) { if (found) { QTC::TC("libtests", "InputSource findLast found more than one"); } else { found = true; } after_found_offset = this->tell(); cur_offset = after_found_offset; cur_len = len - (cur_offset - offset); } if (found) { this->seek(after_found_offset, SEEK_SET); } return found; }
CWE-787
16,732
QPDF::pipeForeignStreamData( PointerHolder<ForeignStreamData> foreign, Pipeline* pipeline, unsigned long encode_flags, qpdf_stream_decode_level_e decode_level) { if (foreign->encp->encrypted) { QTC::TC("qpdf", "QPDF pipe foreign encrypted stream"); } return pipeStreamData( foreign->encp, foreign->file, *this, foreign->foreign_objid, foreign->foreign_generation, foreign->offset, foreign->length, foreign->local_dict, foreign->is_attachment_stream, pipeline, false, false); }
CWE-787
16,733
QPDFXRefEntry::getObjStreamNumber() const { if (this->type != 2) { throw std::logic_error( "getObjStreamNumber called for xref entry of type != 2"); } return this->field1; }
CWE-787
16,736
QUtil::toUTF16(unsigned long uval) { std::string result; if ((uval >= 0xd800) && (uval <= 0xdfff)) { result = "\xff\xfd"; } else if (uval <= 0xffff) { char out[2]; out[0] = (uval & 0xff00) >> 8; out[1] = (uval & 0xff); result = std::string(out, 2); } else if (uval <= 0x10ffff) { char out[4]; uval -= 0x10000; unsigned short high = ((uval & 0xffc00) >> 10) + 0xd800; unsigned short low = (uval & 0x3ff) + 0xdc00; out[0] = (high & 0xff00) >> 8; out[1] = (high & 0xff); out[2] = (low & 0xff00) >> 8; out[3] = (low & 0xff); result = std::string(out, 4); } else { result = "\xff\xfd"; } return result; }
CWE-787
16,738
static void read_file_into_memory( char const* filename, PointerHolder<char>& file_buf, size_t& size) { FILE* f = QUtil::safe_fopen(filename, "rb"); fseek(f, 0, SEEK_END); size = QUtil::tell(f); fseek(f, 0, SEEK_SET); file_buf = PointerHolder<char>(true, new char[size]); char* buf_p = file_buf.getPointer(); size_t bytes_read = 0; size_t len = 0; while ((len = fread(buf_p + bytes_read, 1, size - bytes_read, f)) > 0) { bytes_read += len; } if (bytes_read != size) { if (ferror(f)) { throw std::runtime_error( std::string("failure reading file ") + filename + " into memory: read " + QUtil::uint_to_string(bytes_read) + "; wanted " + QUtil::uint_to_string(size)); } else { throw std::logic_error( std::string("premature eof reading file ") + filename + " into memory: read " + QUtil::uint_to_string(bytes_read) + "; wanted " + QUtil::uint_to_string(size)); } } fclose(f); }
CWE-787
16,739
QUtil::seek(FILE* stream, qpdf_offset_t offset, int whence) { #if HAVE_FSEEKO return fseeko(stream, QIntC::IntConverter<qpdf_offset_t, off_t>::convert(offset), whence); #elif HAVE_FSEEKO64 return fseeko64(stream, offset, whence); #else # if defined _MSC_VER || defined __BORLANDC__ return _fseeki64(stream, offset, whence); # else return fseek(stream, QIntC::IntConverter<qpdf_offset_t, long>(offset), whence); # endif #endif }
CWE-787
16,741
void MD5::encode(unsigned char *output, UINT4 *input, unsigned int len) { unsigned int i, j; for (i = 0, j = 0; j < len; i++, j += 4) { output[j] = static_cast<unsigned char>(input[i] & 0xff); output[j+1] = static_cast<unsigned char>((input[i] >> 8) & 0xff); output[j+2] = static_cast<unsigned char>((input[i] >> 16) & 0xff); output[j+3] = static_cast<unsigned char>((input[i] >> 24) & 0xff); } }
CWE-787
16,743
QUtil::get_current_time() { #ifdef _WIN32 // The procedure to get local time at this resolution comes from // the Microsoft documentation. It says to convert a SYSTEMTIME // to a FILETIME, and to copy the FILETIME to a ULARGE_INTEGER. // The resulting number is the number of 100-nanosecond intervals // between January 1, 1601 and now. POSIX threads wants a time // based on January 1, 1970, so we adjust by subtracting the // number of seconds in that time period from the result we get // here. SYSTEMTIME sysnow; GetSystemTime(&sysnow); FILETIME filenow; SystemTimeToFileTime(&sysnow, &filenow); ULARGE_INTEGER uinow; uinow.LowPart = filenow.dwLowDateTime; uinow.HighPart = filenow.dwHighDateTime; ULONGLONG now = uinow.QuadPart; return ((now / 10000000LL) - 11644473600LL); #else return time(0); #endif }
CWE-787
16,744
QPDFWriter::writeObjectStreamOffsets(std::vector<qpdf_offset_t>& offsets, int first_obj) { for (unsigned int i = 0; i < offsets.size(); ++i) { if (i != 0) { writeStringQDF("\n"); writeStringNoQDF(" "); } writeString(QUtil::int_to_string(i + first_obj)); writeString(" "); writeString(QUtil::int_to_string(offsets.at(i))); } writeString("\n"); }
CWE-787
16,745
void MD5::encodeFile(char const *filename, int up_to_size) { unsigned char buffer[1024]; FILE *file = QUtil::safe_fopen(filename, "rb"); size_t len; int so_far = 0; int to_try = 1024; do { if ((up_to_size >= 0) && ((so_far + to_try) > up_to_size)) { to_try = up_to_size - so_far; } len = fread(buffer, 1, to_try, file); if (len > 0) { update(buffer, len); so_far += len; if ((up_to_size >= 0) && (so_far >= up_to_size)) { break; } } } while (len > 0); if (ferror(file)) { // Assume, perhaps incorrectly, that errno was set by the // underlying call to read.... (void) fclose(file); QUtil::throw_system_error( std::string("MD5: read error on ") + filename); } (void) fclose(file); final(); }
CWE-787
16,746
QPDFFormFieldObjectHelper::getQuadding() { int result = 0; QPDFObjectHandle fv = getInheritableFieldValue("/Q"); if (fv.isInteger()) { QTC::TC("qpdf", "QPDFFormFieldObjectHelper Q present"); result = static_cast<int>(fv.getIntValue()); } return result; }
CWE-787
16,747
static void check_page_contents(int pageno, QPDFObjectHandle page) { PointerHolder<Buffer> buf = page.getKey("/Contents").getStreamData(); std::string actual_contents = std::string(reinterpret_cast<char *>(buf->getBuffer()), buf->getSize()); std::string expected_contents = generate_page_contents(pageno); if (expected_contents != actual_contents) { std::cout << "page contents wrong for page " << pageno << std::endl << "ACTUAL: " << actual_contents << "EXPECTED: " << expected_contents << "----\n"; } }
CWE-787
16,749
sph_enc16be(void *dst, unsigned val) { ((unsigned char *)dst)[0] = (val >> 8); ((unsigned char *)dst)[1] = val; }
CWE-787
16,750
static void do_json_page_labels(QPDF& pdf, Options& o, JSON& j) { JSON j_labels = j.addDictionaryMember("pagelabels", JSON::makeArray()); QPDFPageLabelDocumentHelper pldh(pdf); QPDFPageDocumentHelper pdh(pdf); std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages(); if (pldh.hasPageLabels()) { std::vector<QPDFObjectHandle> labels; pldh.getLabelsForPageRange(0, pages.size() - 1, 0, labels); for (std::vector<QPDFObjectHandle>::iterator iter = labels.begin(); iter != labels.end(); ++iter) { std::vector<QPDFObjectHandle>::iterator next = iter; ++next; if (next == labels.end()) { // This can't happen, so ignore it. This could only // happen if getLabelsForPageRange somehow returned an // odd number of items. break; } JSON j_label = j_labels.addArrayElement(JSON::makeDictionary()); j_label.addDictionaryMember("index", (*iter).getJSON()); ++iter; j_label.addDictionaryMember("label", (*iter).getJSON()); } } }
CWE-787
16,751
QPDF_Array::insertItem(int at, QPDFObjectHandle const& item) { // As special case, also allow insert beyond the end if ((at < 0) || (at > static_cast<int>(this->items.size()))) { throw std::logic_error( "INTERNAL ERROR: bounds error accessing QPDF_Array element"); } this->items.insert(this->items.begin() + at, item); }
CWE-787
16,753
BitStream::BitStream(unsigned char const* p, int nbytes) : start(p), nbytes(nbytes) { reset(); }
CWE-787
16,754
void MD5::decode(UINT4 *output, unsigned char *input, unsigned int len) { unsigned int i, j; for (i = 0, j = 0; j < len; i++, j += 4) output[i] = static_cast<UINT4>(input[j]) | (static_cast<UINT4>(input[j+1]) << 8) | (static_cast<UINT4>(input[j+2]) << 16) | (static_cast<UINT4>(input[j+3]) << 24); }
CWE-787
16,755
Pl_LZWDecoder::getFirstChar(int code) { unsigned char result = '\0'; if (code < 256) { result = static_cast<unsigned char>(code); } else if (code > 257) { unsigned int idx = code - 258; if (idx >= table.size()) { throw std::logic_error( "Pl_LZWDecoder::getFirstChar: table overflow"); } Buffer& b = table.at(idx); result = b.getBuffer()[0]; } else { throw std::logic_error( "Pl_LZWDecoder::getFirstChar called with invalid code (" + QUtil::int_to_string(code) + ")"); } return result; }
CWE-787
16,756
QPDFObjectHandle::isRectangle() { if (! isArray()) { return false; } if (getArrayNItems() != 4) { return false; } for (size_t i = 0; i < 4; ++i) { if (! getArrayItem(i).isNumber()) { return false; } } return true; }
CWE-787
16,757
BitStream::getBitsSigned(int nbits) { unsigned long long bits = read_bits(this->p, this->bit_offset, this->bits_available, nbits); long long result = 0; if (static_cast<long long>(bits) > 1 << (nbits - 1)) { result = static_cast<long long>(bits - (1 << nbits)); } else { result = static_cast<long long>(bits); } return result; }
CWE-787
16,758
QPDFWriter::bytesNeeded(unsigned long long n) { int bytes = 0; while (n) { ++bytes; n >>= 8; } return bytes; }
CWE-787
16,759
ArgParser::argOiMinWidth(char* parameter) { o.oi_min_width = QUtil::string_to_int(parameter); }
CWE-787
16,760
Finder::check() { QPDFTokenizer tokenizer; QPDFTokenizer::Token t = tokenizer.readToken(is, "finder", true); qpdf_offset_t offset = this->is->tell(); bool result = (t == QPDFTokenizer::Token(QPDFTokenizer::tt_word, str)); this->is->seek(offset - this->str.length(), SEEK_SET); return result; }
CWE-787
16,761
process_with_aes(std::string const& key, bool encrypt, std::string const& data, size_t outlength = 0, unsigned int repetitions = 1, unsigned char const* iv = 0, size_t iv_length = 0) { Pl_Buffer buffer("buffer"); Pl_AES_PDF aes("aes", &buffer, encrypt, QUtil::unsigned_char_pointer(key), key.length()); if (iv) { aes.setIV(iv, iv_length); } else { aes.useZeroIV(); } aes.disablePadding(); for (unsigned int i = 0; i < repetitions; ++i) { aes.write(QUtil::unsigned_char_pointer(data), data.length()); } aes.finish(); PointerHolder<Buffer> bufp = buffer.getBuffer(); if (outlength == 0) { outlength = bufp->getSize(); } else { outlength = std::min(outlength, bufp->getSize()); } return std::string(reinterpret_cast<char*>(bufp->getBuffer()), outlength); }
CWE-787
16,762
static void test16(char const* infile, char const* password, char const* outfile, char const* outfile2) { unsigned long buflen = 0L; unsigned char const* buf = 0; FILE* f = 0; qpdf_read(qpdf, infile, password); print_info("/Author"); print_info("/Producer"); print_info("/Creator"); qpdf_set_info_key(qpdf, "/Author", "Mr. Potato Head"); qpdf_set_info_key(qpdf, "/Producer", "QPDF library"); qpdf_set_info_key(qpdf, "/Creator", 0); print_info("/Author"); print_info("/Producer"); print_info("/Creator"); qpdf_init_write_memory(qpdf); qpdf_set_static_ID(qpdf, QPDF_TRUE); qpdf_set_static_aes_IV(qpdf, QPDF_TRUE); qpdf_set_stream_data_mode(qpdf, qpdf_s_uncompress); qpdf_write(qpdf); f = safe_fopen(outfile, "wb"); buflen = qpdf_get_buffer_length(qpdf); buf = qpdf_get_buffer(qpdf); fwrite(buf, 1, buflen, f); fclose(f); report_errors(); }
CWE-787
16,763
QPDF_Array::setItem(int n, QPDFObjectHandle const& oh) { // Call getItem for bounds checking (void) getItem(n); this->items.at(n) = oh; }
CWE-787
16,765
QPDF::pipeStreamData(int objid, int generation, qpdf_offset_t offset, size_t length, QPDFObjectHandle stream_dict, Pipeline* pipeline, bool suppress_warnings, bool will_retry) { bool is_attachment_stream = this->m->attachment_streams.count( QPDFObjGen(objid, generation)); return pipeStreamData( this->m->encp, this->m->file, *this, objid, generation, offset, length, stream_dict, is_attachment_stream, pipeline, suppress_warnings, will_retry); }
CWE-787
16,769
QPDF::addPage(QPDFObjectHandle newpage, bool first) { if (first) { insertPage(newpage, 0); } else { insertPage(newpage, getRoot().getKey("/Pages").getKey("/Count").getIntValue()); } }
CWE-787
16,770
FileInputSource::read(char* buffer, size_t length) { this->last_offset = this->tell(); size_t len = fread(buffer, 1, length, this->file); if (len == 0) { if (ferror(this->file)) { throw QPDFExc(qpdf_e_system, this->filename, "", this->last_offset, std::string("read ") + QUtil::int_to_string(length) + " bytes"); } else if (length > 0) { this->seek(0, SEEK_END); this->last_offset = this->tell(); } } return len; }
CWE-787
16,771
RC4::process(unsigned char *in_data, int len, unsigned char* out_data) { if (out_data == 0) { // Convert in place out_data = in_data; } for (int i = 0; i < len; ++i) { key.x = (key.x + 1) % 256; key.y = (key.state[key.x] + key.y) % 256; swap_byte(key.state[key.x], key.state[key.y]); int xor_index = (key.state[key.x] + key.state[key.y]) % 256; out_data[i] = in_data[i] ^ key.state[xor_index]; } }
CWE-787
16,772
test_write_bits(unsigned char& ch, unsigned int& bit_offset, unsigned long val, int bits, Pl_Buffer* bp) { write_bits(ch, bit_offset, val, bits, bp); printf("ch = %02x, bit_offset = %d\n", static_cast<unsigned int>(ch), bit_offset); }
CWE-787
16,773
QPDFWriter::calculateXrefStreamPadding(int xref_bytes) { // This routine is called right after a linearization first pass // xref stream has been written without compression. Calculate // the amount of padding that would be required in the worst case, // assuming the number of uncompressed bytes remains the same. // The worst case for zlib is that the output is larger than the // input by 6 bytes plus 5 bytes per 16K, and then we'll add 10 // extra bytes for number length increases. return 16 + (5 * ((xref_bytes + 16383) / 16384)); }
CWE-787
16,774
Status ValidateInputs(const Tensor *a_indices, const Tensor *a_values, const Tensor *a_shape, const Tensor *b) { if (!TensorShapeUtils::IsMatrix(a_indices->shape())) { return errors::InvalidArgument( "Input a_indices should be a matrix but received shape: ", a_indices->shape().DebugString()); } if (!TensorShapeUtils::IsVector(a_values->shape()) || !TensorShapeUtils::IsVector(a_shape->shape())) { return errors::InvalidArgument( "Inputs a_values and a_shape should be vectors " "but received shapes: ", a_values->shape().DebugString(), " and ", a_shape->shape().DebugString()); } if (a_shape->NumElements() != b->dims()) { return errors::InvalidArgument( "Two operands have different ranks; received: ", a_shape->NumElements(), " and ", b->dims()); } const auto a_shape_flat = a_shape->flat<Index>(); for (int i = 0; i < b->dims(); ++i) { if (a_shape_flat(i) != b->dim_size(i)) { return errors::InvalidArgument( "Dimension ", i, " does not equal (no broadcasting is supported): sparse side ", a_shape_flat(i), " vs dense side ", b->dim_size(i)); } } return Status::OK(); }
CWE-20
16,776
win_goto(win_T *wp) { #ifdef FEAT_CONCEAL win_T *owp = curwin; #endif #ifdef FEAT_PROP_POPUP if (ERROR_IF_ANY_POPUP_WINDOW) return; if (popup_is_popup(wp)) { emsg(_(e_not_allowed_to_enter_popup_window)); return; } #endif if (text_locked()) { beep_flush(); text_locked_msg(); return; } if (curbuf_locked()) return; if (wp->w_buffer != curbuf) reset_VIsual_and_resel(); else if (VIsual_active) wp->w_cursor = curwin->w_cursor; #ifdef FEAT_GUI need_mouse_correct = TRUE; #endif win_enter(wp, TRUE); #ifdef FEAT_CONCEAL // Conceal cursor line in previous window, unconceal in current window. if (win_valid(owp) && owp->w_p_cole > 0 && !msg_scrolled) redrawWinline(owp, owp->w_cursor.lnum); if (curwin->w_p_cole > 0 && !msg_scrolled) need_cursor_line_redraw = TRUE; #endif }
CWE-787
16,782
TfLiteStatus Subgraph::AllocateTensors() { TFLITE_SCOPED_TAGGED_DEFAULT_PROFILE(profiler_.get(), "AllocateTensors"); if (!consistent_) { ReportError("AllocateTensors() called on inconsistent model."); return kTfLiteError; } // Restore delegation state if applicable. TF_LITE_ENSURE_STATUS(RedoAllDelegates()); // Explicit (re)allocation is necessary if nodes have been changed or tensors // have been resized. For inputs marked as dynamic, we can't short-circuit the // allocation as the client may have done the resize manually. if (state_ != kStateUninvokable && !HasDynamicTensorImpl(context_, inputs())) { if (memory_planner_ && !memory_planner_->HasNonPersistentMemory()) { // If the only change was the release of non-persistent memory via // ReleaseNonPersistentMemory(), just re-allocate it. For any other type // of memory-planning change (for eg, ResizeInputTensor), the state would // be kStateUninvokable. memory_planner_->AcquireNonPersistentMemory(); } return kTfLiteOk; } next_execution_plan_index_to_prepare_ = 0; next_execution_plan_index_to_plan_allocation_ = 0; next_original_execution_plan_index_to_prepare_ = 0; if (memory_planner_) { TF_LITE_ENSURE_STATUS(memory_planner_->ResetAllocations()); } TF_LITE_ENSURE_STATUS(PrepareOpsAndTensors()); state_ = kStateInvokable; // Reset the variable tensors to zero after (re)allocating the tensors. // Developers shouldn't rely on the side effect of this function to reset // variable tensors. They should call `ResetVariableTensors` directly // instead. ResetVariableTensors(); return kTfLiteOk; }
CWE-703
16,798
bool CModules::GetModInfo(CModInfo& ModInfo, const CString& sModule, CString& sRetMsg) { CString sModPath, sTmp; bool bSuccess; bool bHandled = false; GLOBALMODULECALL(OnGetModInfo(ModInfo, sModule, bSuccess, sRetMsg), &bHandled); if (bHandled) return bSuccess; if (!FindModPath(sModule, sModPath, sTmp)) { sRetMsg = t_f("Unable to find module {1}.")(sModule); return false; } return GetModPathInfo(ModInfo, sModule, sModPath, sRetMsg); }
CWE-20
16,817
bool CModules::GetModPathInfo(CModInfo& ModInfo, const CString& sModule, const CString& sModPath, CString& sRetMsg) { ModInfo.SetName(sModule); ModInfo.SetPath(sModPath); ModHandle p = OpenModule(sModule, sModPath, ModInfo, sRetMsg); if (!p) return false; dlclose(p); return true; }
CWE-20
16,818
parse_field(netdissect_options *ndo, const char **pptr, int *len) { const char *s; if (*len <= 0 || !pptr || !*pptr) return NULL; if (*pptr > (const char *) ndo->ndo_snapend) return NULL; s = *pptr; while (*pptr <= (const char *) ndo->ndo_snapend && *len >= 0 && **pptr) { (*pptr)++; (*len)--; } (*pptr)++; (*len)--; if (*len < 0 || *pptr > (const char *) ndo->ndo_snapend) return NULL; return s; }
CWE-125
16,820
R_API int r_core_bin_set_env(RCore *r, RBinFile *binfile) { RBinObject *binobj = binfile ? binfile->o: NULL; RBinInfo *info = binobj ? binobj->info: NULL; if (info) { int va = info->has_va; const char * arch = info->arch; ut16 bits = info->bits; ut64 baseaddr = r_bin_get_baddr (r->bin); /* Hack to make baddr work on some corner */ r_config_set_i (r->config, "io.va", (binobj->info)? binobj->info->has_va: 0); r_config_set_i (r->config, "bin.baddr", baseaddr); r_config_set (r->config, "asm.arch", arch); r_config_set_i (r->config, "asm.bits", bits); r_config_set (r->config, "anal.arch", arch); if (info->cpu && *info->cpu) { r_config_set (r->config, "anal.cpu", info->cpu); } else { r_config_set (r->config, "anal.cpu", arch); } r_asm_use (r->assembler, arch); r_core_bin_info (r, R_CORE_BIN_ACC_ALL, R_CORE_BIN_SET, va, NULL, NULL); r_core_bin_set_cur (r, binfile); return true; } return false; }
CWE-416
16,825
const char *enc_untrusted_inet_ntop(int af, const void *src, char *dst, socklen_t size) { if (!src || !dst) { errno = EFAULT; return nullptr; } size_t src_size = 0; if (af == AF_INET) { src_size = sizeof(struct in_addr); } else if (af == AF_INET6) { src_size = sizeof(struct in6_addr); } else { errno = EAFNOSUPPORT; return nullptr; } MessageWriter input; input.Push<int>(TokLinuxAfFamily(af)); input.PushByReference(Extent{reinterpret_cast<const char *>(src), src_size}); input.Push(size); MessageReader output; const auto status = NonSystemCallDispatcher( ::asylo::host_call::kInetNtopHandler, &input, &output); CheckStatusAndParamCount(status, output, "enc_untrusted_inet_ntop", 2); auto result = output.next(); int klinux_errno = output.next<int>(); if (result.empty()) { errno = FromkLinuxErrorNumber(klinux_errno); return nullptr; } memcpy(dst, result.data(), std::min(static_cast<size_t>(size), static_cast<size_t>(INET6_ADDRSTRLEN))); return dst; }
CWE-125
16,831
Status SparseCountSparseOutputShapeFn(InferenceContext *c) { auto rank = c->Dim(c->input(0), 1); auto nvals = c->UnknownDim(); c->set_output(0, c->Matrix(nvals, rank)); // out.indices c->set_output(1, c->Vector(nvals)); // out.values c->set_output(2, c->Vector(rank)); // out.dense_shape return Status::OK(); }
CWE-125
16,858
void exit_io_context(void) { struct io_context *ioc; task_lock(current); ioc = current->io_context; current->io_context = NULL; task_unlock(current); if (atomic_dec_and_test(&ioc->nr_tasks)) { if (ioc->aic && ioc->aic->exit) ioc->aic->exit(ioc->aic); cfq_exit(ioc); put_io_context(ioc); } }
CWE-20
16,864
asmlinkage void bad_mode(struct pt_regs *regs, int reason, unsigned int esr) { console_verbose(); pr_crit("Bad mode in %s handler detected, code 0x%08x\n", handler[reason], esr); die("Oops - bad mode", regs, 0); local_irq_disable(); panic("bad mode"); }
CWE-703
16,865
void Compute(OpKernelContext* ctx) override { StagingMap<Ordered>* map = nullptr; OP_REQUIRES_OK(ctx, GetStagingMap(ctx, def(), &map)); core::ScopedUnref scope(map); typename StagingMap<Ordered>::OptionalTuple tuple; const Tensor* key_tensor; const Tensor* indices_tensor; OpInputList values_tensor; OP_REQUIRES_OK(ctx, ctx->input("key", &key_tensor)); OP_REQUIRES_OK(ctx, ctx->input("indices", &indices_tensor)); OP_REQUIRES_OK(ctx, ctx->input_list("values", &values_tensor)); // Create copy for insertion into Staging Area Tensor key(*key_tensor); // Create the tuple to store for (std::size_t i = 0; i < values_tensor.size(); ++i) { tuple.push_back(values_tensor[i]); } // Store the tuple in the map OP_REQUIRES_OK(ctx, map->put(&key, indices_tensor, &tuple)); }
CWE-20
16,872
static int key_notify_policy_flush(const struct km_event *c) { struct sk_buff *skb_out; struct sadb_msg *hdr; skb_out = alloc_skb(sizeof(struct sadb_msg) + 16, GFP_ATOMIC); if (!skb_out) return -ENOBUFS; hdr = (struct sadb_msg *) skb_put(skb_out, sizeof(struct sadb_msg)); hdr->sadb_msg_type = SADB_X_SPDFLUSH; hdr->sadb_msg_seq = c->seq; hdr->sadb_msg_pid = c->portid; hdr->sadb_msg_version = PF_KEY_V2; hdr->sadb_msg_errno = (uint8_t) 0; hdr->sadb_msg_len = (sizeof(struct sadb_msg) / sizeof(uint64_t)); pfkey_broadcast(skb_out, GFP_ATOMIC, BROADCAST_ALL, NULL, c->net); return 0; }
CWE-119
16,877
int pure_strcmp(const char * const s1, const char * const s2) { return pure_memcmp(s1, s2, strlen(s1) + 1U); }
CWE-125
16,883
static __inline__ void ipv6_select_ident(struct frag_hdr *fhdr) { static u32 ipv6_fragmentation_id = 1; static DEFINE_SPINLOCK(ip6_id_lock); spin_lock_bh(&ip6_id_lock); fhdr->identification = htonl(ipv6_fragmentation_id); if (++ipv6_fragmentation_id == 0) ipv6_fragmentation_id = 1; spin_unlock_bh(&ip6_id_lock); }
CWE-703
16,884
static inline __u16 inet_getid(struct inet_peer *p, int more) { more++; inet_peer_refcheck(p); return atomic_add_return(more, &p->ip_id_count) - more; }
CWE-703
16,886
static inline int ip6_ufo_append_data(struct sock *sk, int getfrag(void *from, char *to, int offset, int len, int odd, struct sk_buff *skb), void *from, int length, int hh_len, int fragheaderlen, int transhdrlen, int mtu,unsigned int flags) { struct sk_buff *skb; int err; /* There is support for UDP large send offload by network * device, so create one single skb packet containing complete * udp datagram */ if ((skb = skb_peek_tail(&sk->sk_write_queue)) == NULL) { skb = sock_alloc_send_skb(sk, hh_len + fragheaderlen + transhdrlen + 20, (flags & MSG_DONTWAIT), &err); if (skb == NULL) return -ENOMEM; /* reserve space for Hardware header */ skb_reserve(skb, hh_len); /* create space for UDP/IP header */ skb_put(skb,fragheaderlen + transhdrlen); /* initialize network header pointer */ skb_reset_network_header(skb); /* initialize protocol header pointer */ skb->transport_header = skb->network_header + fragheaderlen; skb->ip_summed = CHECKSUM_PARTIAL; skb->csum = 0; } err = skb_append_datato_frags(sk,skb, getfrag, from, (length - transhdrlen)); if (!err) { struct frag_hdr fhdr; /* Specify the length of each IPv6 datagram fragment. * It has to be a multiple of 8. */ skb_shinfo(skb)->gso_size = (mtu - fragheaderlen - sizeof(struct frag_hdr)) & ~7; skb_shinfo(skb)->gso_type = SKB_GSO_UDP; ipv6_select_ident(&fhdr); skb_shinfo(skb)->ip6_frag_id = fhdr.identification; __skb_queue_tail(&sk->sk_write_queue, skb); return 0; } /* There is not enough support do UPD LSO, * so follow normal path */ kfree_skb(skb); return err; }
CWE-703
16,888
GF_Err stbl_AppendTime(GF_SampleTableBox *stbl, u32 duration, u32 nb_pack) { GF_TimeToSampleBox *stts = stbl->TimeToSample; if (!nb_pack) nb_pack = 1; if (stts->nb_entries) { if (stts->entries[stts->nb_entries-1].sampleDelta == duration) { stts->entries[stts->nb_entries-1].sampleCount += nb_pack; return GF_OK; } } if (stts->nb_entries==stts->alloc_size) { ALLOC_INC(stts->alloc_size); stts->entries = gf_realloc(stts->entries, sizeof(GF_SttsEntry)*stts->alloc_size); if (!stts->entries) return GF_OUT_OF_MEM; memset(&stts->entries[stts->nb_entries], 0, sizeof(GF_SttsEntry)*(stts->alloc_size-stts->nb_entries) ); } stts->entries[stts->nb_entries].sampleCount = nb_pack; stts->entries[stts->nb_entries].sampleDelta = duration; stts->nb_entries++; if (stts->max_ts_delta < duration ) stts->max_ts_delta = duration; return GF_OK; }
CWE-787
16,895
static int stellaris_enet_load(QEMUFile *f, void *opaque, int version_id) { stellaris_enet_state *s = (stellaris_enet_state *)opaque; int i; if (version_id != 1) return -EINVAL; s->ris = qemu_get_be32(f); s->im = qemu_get_be32(f); s->rctl = qemu_get_be32(f); s->tctl = qemu_get_be32(f); s->thr = qemu_get_be32(f); s->mctl = qemu_get_be32(f); s->mdv = qemu_get_be32(f); s->mtxd = qemu_get_be32(f); s->mrxd = qemu_get_be32(f); s->np = qemu_get_be32(f); s->tx_fifo_len = qemu_get_be32(f); qemu_get_buffer(f, s->tx_fifo, sizeof(s->tx_fifo)); for (i = 0; i < 31; i++) { s->rx[i].len = qemu_get_be32(f); qemu_get_buffer(f, s->rx[i].data, sizeof(s->rx[i].data)); } s->next_packet = qemu_get_be32(f); s->rx_fifo_offset = qemu_get_be32(f); return 0; }
CWE-119
16,898
static void stellaris_enet_save(QEMUFile *f, void *opaque) { stellaris_enet_state *s = (stellaris_enet_state *)opaque; int i; qemu_put_be32(f, s->ris); qemu_put_be32(f, s->im); qemu_put_be32(f, s->rctl); qemu_put_be32(f, s->tctl); qemu_put_be32(f, s->thr); qemu_put_be32(f, s->mctl); qemu_put_be32(f, s->mdv); qemu_put_be32(f, s->mtxd); qemu_put_be32(f, s->mrxd); qemu_put_be32(f, s->np); qemu_put_be32(f, s->tx_fifo_len); qemu_put_buffer(f, s->tx_fifo, sizeof(s->tx_fifo)); for (i = 0; i < 31; i++) { qemu_put_be32(f, s->rx[i].len); qemu_put_buffer(f, s->rx[i].data, sizeof(s->rx[i].data)); } qemu_put_be32(f, s->next_packet); qemu_put_be32(f, s->rx_fifo_offset); }
CWE-119
16,899
static int stellaris_enet_init(SysBusDevice *sbd) { DeviceState *dev = DEVICE(sbd); stellaris_enet_state *s = STELLARIS_ENET(dev); memory_region_init_io(&s->mmio, OBJECT(s), &stellaris_enet_ops, s, "stellaris_enet", 0x1000); sysbus_init_mmio(sbd, &s->mmio); sysbus_init_irq(sbd, &s->irq); qemu_macaddr_default_if_unset(&s->conf.macaddr); s->nic = qemu_new_nic(&net_stellaris_enet_info, &s->conf, object_get_typename(OBJECT(dev)), dev->id, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); stellaris_enet_reset(s); register_savevm(dev, "stellaris_enet", -1, 1, stellaris_enet_save, stellaris_enet_load, s); return 0; }
CWE-119
16,900
static void stellaris_enet_unrealize(DeviceState *dev, Error **errp) { stellaris_enet_state *s = STELLARIS_ENET(dev); unregister_savevm(DEVICE(s), "stellaris_enet", s); memory_region_destroy(&s->mmio); }
CWE-119
16,901
static void stellaris_enet_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); k->init = stellaris_enet_init; dc->unrealize = stellaris_enet_unrealize; dc->props = stellaris_enet_properties; }
CWE-119
16,902
static opj_bool pi_next_lrcp(opj_pi_iterator_t * pi) { opj_pi_comp_t *comp = NULL; opj_pi_resolution_t *res = NULL; long index = 0; if (!pi->first) { comp = &pi->comps[pi->compno]; res = &comp->resolutions[pi->resno]; goto LABEL_SKIP; } else { pi->first = 0; } for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) { for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) { for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) { comp = &pi->comps[pi->compno]; if (pi->resno >= comp->numresolutions) { continue; } res = &comp->resolutions[pi->resno]; if (!pi->tp_on) { pi->poc.precno1 = res->pw * res->ph; } for (pi->precno = pi->poc.precno0; pi->precno < pi->poc.precno1; pi->precno++) { index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; if (!pi->include[index]) { pi->include[index] = 1; return OPJ_TRUE; } LABEL_SKIP: ; } } } } return OPJ_FALSE; }
CWE-20
16,909
static opj_bool pi_next_rlcp(opj_pi_iterator_t * pi) { opj_pi_comp_t *comp = NULL; opj_pi_resolution_t *res = NULL; long index = 0; if (!pi->first) { comp = &pi->comps[pi->compno]; res = &comp->resolutions[pi->resno]; goto LABEL_SKIP; } else { pi->first = 0; } for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) { for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) { for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) { comp = &pi->comps[pi->compno]; if (pi->resno >= comp->numresolutions) { continue; } res = &comp->resolutions[pi->resno]; if (!pi->tp_on) { pi->poc.precno1 = res->pw * res->ph; } for (pi->precno = pi->poc.precno0; pi->precno < pi->poc.precno1; pi->precno++) { index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; if (!pi->include[index]) { pi->include[index] = 1; return OPJ_TRUE; } LABEL_SKIP: ; } } } } return OPJ_FALSE; }
CWE-20
16,912
void Magick::Image::read(MagickCore::Image *image, MagickCore::ExceptionInfo *exceptionInfo) { // Ensure that multiple image frames were not read. if (image != (MagickCore::Image *) NULL && image->next != (MagickCore::Image *) NULL) { MagickCore::Image *next; // Destroy any extra image frames next=image->next; image->next=(MagickCore::Image *) NULL; next->previous=(MagickCore::Image *) NULL; DestroyImageList(next); } replaceImage(image); if (exceptionInfo->severity == MagickCore::UndefinedException && image == (MagickCore::Image *) NULL) { (void) MagickCore::DestroyExceptionInfo(exceptionInfo); if (!quiet()) throwExceptionExplicit(MagickCore::ImageWarning, "No image was loaded."); } ThrowImageException; }
CWE-416
16,914
de265_error decoder_context::read_sps_NAL(bitreader& reader) { logdebug(LogHeaders,"----> read SPS\n"); std::shared_ptr<seq_parameter_set> new_sps = std::make_shared<seq_parameter_set>(); de265_error err; if ((err=new_sps->read(this, &reader)) != DE265_OK) { return err; } if (param_sps_headers_fd>=0) { new_sps->dump(param_sps_headers_fd); } sps[ new_sps->seq_parameter_set_id ] = new_sps; return DE265_OK; }
CWE-416
16,970
handle_mlppp(netdissect_options *ndo, const u_char *p, int length) { if (!ndo->ndo_eflag) ND_PRINT((ndo, "MLPPP, ")); ND_PRINT((ndo, "seq 0x%03x, Flags [%s], length %u", (EXTRACT_16BITS(p))&0x0fff, /* only support 12-Bit sequence space for now */ bittok2str(ppp_ml_flag_values, "none", *p & 0xc0), length)); }
CWE-125
16,980
struct xt_table_info *xt_alloc_table_info(unsigned int size) { struct xt_table_info *info = NULL; size_t sz = sizeof(*info) + size; /* Pedantry: prevent them from hitting BUG() in vmalloc.c --RR */ if ((SMP_ALIGN(size) >> PAGE_SHIFT) + 2 > totalram_pages) return NULL; if (sz <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER)) info = kmalloc(sz, GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY); if (!info) { info = vmalloc(sz); if (!info) return NULL; } memset(info, 0, sizeof(*info)); info->size = size; return info; }
CWE-703
16,983
INST_HANDLER (sts) { // STS k, Rr int r = ((buf[0] >> 4) & 0xf) | ((buf[1] & 0x1) << 4); int k = (buf[3] << 8) | buf[2]; op->ptr = k; ESIL_A ("r%d,", r); __generic_ld_st (op, "ram", 0, 1, 0, k, 1); op->cycles = 2; }
CWE-125
16,989
GF_Err tenc_box_read(GF_Box *s, GF_BitStream *bs) { u8 iv_size; GF_TrackEncryptionBox *ptr = (GF_TrackEncryptionBox*)s; ISOM_DECREASE_SIZE(ptr, 3); gf_bs_read_u8(bs); //reserved if (!ptr->version) { gf_bs_read_u8(bs); //reserved } else { ptr->crypt_byte_block = gf_bs_read_int(bs, 4); ptr->skip_byte_block = gf_bs_read_int(bs, 4); } ptr->isProtected = gf_bs_read_u8(bs); ISOM_DECREASE_SIZE(ptr, 17); ptr->key_info[0] = 0; ptr->key_info[1] = 0; ptr->key_info[2] = 0; ptr->key_info[3] = iv_size = gf_bs_read_u8(bs); gf_bs_read_data(bs, ptr->key_info+4, 16); if (!iv_size && ptr->isProtected) { ISOM_DECREASE_SIZE(ptr, 1); iv_size = ptr->key_info[20] = gf_bs_read_u8(bs); ISOM_DECREASE_SIZE(ptr, ptr->key_info[20]); gf_bs_read_data(bs, ptr->key_info+21, iv_size); } return GF_OK; }
CWE-787
16,990
cJSON *cJSON_CreateInt( int64_t num ) { cJSON *item = cJSON_New_Item(); if ( item ) { item->type = cJSON_Number; item->valuefloat = num; item->valueint = num; } return item; }
CWE-119
16,999
cJSON *cJSON_CreateArray( void ) { cJSON *item = cJSON_New_Item(); if ( item ) item->type = cJSON_Array; return item; }
CWE-119
17,000
void cJSON_AddItemReferenceToObject( cJSON *object, const char *string, cJSON *item ) { cJSON_AddItemToObject( object, string, create_reference( item ) ); }
CWE-119
17,001
cJSON *cJSON_GetArrayItem( cJSON *array, int item ) { cJSON *c = array->child; while ( c && item > 0 ) { --item; c = c->next; } return c; }
CWE-119
17,002
void cJSON_AddItemToObject( cJSON *object, const char *string, cJSON *item ) { if ( ! item ) return; if ( item->string ) cJSON_free( item->string ); item->string = cJSON_strdup( string ); cJSON_AddItemToArray( object, item ); }
CWE-119
17,003
void cJSON_ReplaceItemInArray( cJSON *array, int which, cJSON *newitem ) { cJSON *c = array->child; while ( c && which > 0 ) { c = c->next; --which; } if ( ! c ) return; newitem->next = c->next; newitem->prev = c->prev; if ( newitem->next ) newitem->next->prev = newitem; if ( c == array->child ) array->child = newitem; else newitem->prev->next = newitem; c->next = c->prev = 0; cJSON_Delete( c ); }
CWE-119
17,004
static const char *skip( const char *in ) { while ( in && *in && (unsigned char) *in <= 32 ) in++; return in; }
CWE-119
17,007
cJSON *cJSON_GetObjectItem( cJSON *object, const char *string ) { cJSON *c = object->child; while ( c && cJSON_strcasecmp( c->string, string ) ) c = c->next; return c; }
CWE-119
17,008
cJSON *cJSON_CreateIntArray( int64_t *numbers, int count ) { int i; cJSON *n = 0, *p = 0, *a = cJSON_CreateArray(); for ( i = 0; a && i < count; ++i ) { n = cJSON_CreateInt( numbers[i] ); if ( ! i ) a->child = n; else suffix_object( p, n ); p = n; } return a; }
CWE-119
17,009
static cJSON *create_reference( cJSON *item ) { cJSON *ref; if ( ! ( ref = cJSON_New_Item() ) ) return 0; memcpy( ref, item, sizeof(cJSON) ); ref->string = 0; ref->type |= cJSON_IsReference; ref->next = ref->prev = 0; return ref; }
CWE-119
17,010
static const char *parse_array( cJSON *item, const char *value ) { cJSON *child; if ( *value != '[' ) { /* Not an array! */ ep = value; return 0; } item->type = cJSON_Array; value = skip( value + 1 ); if ( *value == ']' ) return value + 1; /* empty array. */ if ( ! ( item->child = child = cJSON_New_Item() ) ) return 0; /* memory fail */ if ( ! ( value = skip( parse_value( child, skip( value ) ) ) ) ) return 0; while ( *value == ',' ) { cJSON *new_item; if ( ! ( new_item = cJSON_New_Item() ) ) return 0; /* memory fail */ child->next = new_item; new_item->prev = child; child = new_item; if ( ! ( value = skip( parse_value( child, skip( value+1 ) ) ) ) ) return 0; /* memory fail */ } if ( *value == ']' ) return value + 1; /* end of array */ /* Malformed. */ ep = value; return 0; }
CWE-119
17,011
void cJSON_AddItemReferenceToArray( cJSON *array, cJSON *item ) { cJSON_AddItemToArray( array, create_reference( item ) ); }
CWE-119
17,012
void cJSON_DeleteItemFromArray( cJSON *array, int which ) { cJSON_Delete( cJSON_DetachItemFromArray( array, which ) ); }
CWE-119
17,013
cJSON *cJSON_DetachItemFromArray( cJSON *array, int which ) { cJSON *c = array->child; while ( c && which > 0 ) { c = c->next; --which; } if ( ! c ) return 0; if ( c->prev ) c->prev->next = c->next; if ( c->next ) c->next->prev = c->prev; if ( c == array->child ) array->child = c->next; c->prev = c->next = 0; return c; }
CWE-119
17,014
static const char *parse_object( cJSON *item, const char *value ) { cJSON *child; if ( *value != '{' ) { /* Not an object! */ ep = value; return 0; } item->type = cJSON_Object; value =skip( value + 1 ); if ( *value == '}' ) return value + 1; /* empty array. */ if ( ! ( item->child = child = cJSON_New_Item() ) ) return 0; if ( ! ( value = skip( parse_string( child, skip( value ) ) ) ) ) return 0; child->string = child->valuestring; child->valuestring = 0; if ( *value != ':' ) { /* Fail! */ ep = value; return 0; } if ( ! ( value = skip( parse_value( child, skip( value + 1 ) ) ) ) ) return 0; while ( *value == ',' ) { cJSON *new_item; if ( ! ( new_item = cJSON_New_Item() ) ) return 0; /* memory fail */ child->next = new_item; new_item->prev = child; child = new_item; if ( ! ( value = skip( parse_string( child, skip( value + 1 ) ) ) ) ) return 0; child->string = child->valuestring; child->valuestring = 0; if ( *value != ':' ) { /* Fail! */ ep = value; return 0; } if ( ! ( value = skip( parse_value( child, skip( value + 1 ) ) ) ) ) return 0; } if ( *value == '}' ) return value + 1; /* end of array */ /* Malformed. */ ep = value; return 0; }
CWE-119
17,015
iperf_json_printf(const char *format, ...) { cJSON* o; va_list argp; const char *cp; char name[100]; char* np; cJSON* j; o = cJSON_CreateObject(); if (o == NULL) return NULL; va_start(argp, format); np = name; for (cp = format; *cp != '\0'; ++cp) { switch (*cp) { case ' ': break; case ':': *np = '\0'; break; case '%': ++cp; switch (*cp) { case 'b': j = cJSON_CreateBool(va_arg(argp, int)); break; case 'd': j = cJSON_CreateInt(va_arg(argp, int64_t)); break; case 'f': j = cJSON_CreateFloat(va_arg(argp, double)); break; case 's': j = cJSON_CreateString(va_arg(argp, char *)); break; default: return NULL; } if (j == NULL) return NULL; cJSON_AddItemToObject(o, name, j); np = name; break; default: *np++ = *cp; break; } } va_end(argp); return o; }
CWE-119
17,016
void cJSON_DeleteItemFromObject( cJSON *object, const char *string ) { cJSON_Delete( cJSON_DetachItemFromObject( object, string ) ); }
CWE-119
17,017
static char *print_string( cJSON *item ) { return print_string_ptr( item->valuestring ); }
CWE-119
17,019
static char *print_value( cJSON *item, int depth, int fmt ) { char *out = 0; if ( ! item ) return 0; switch ( ( item->type ) & 255 ) { case cJSON_NULL: out = cJSON_strdup( "null" ); break; case cJSON_False: out = cJSON_strdup( "false" ); break; case cJSON_True: out = cJSON_strdup( "true" ); break; case cJSON_Number: out = print_number( item ); break; case cJSON_String: out = print_string( item ); break; case cJSON_Array: out = print_array( item, depth, fmt ); break; case cJSON_Object: out = print_object( item, depth, fmt ); break; } return out; }
CWE-119
17,020
void cJSON_AddItemToArray( cJSON *array, cJSON *item ) { cJSON *c = array->child; if ( ! item ) return; if ( ! c ) { array->child = item; } else { while ( c && c->next ) c = c->next; suffix_object( c, item ); } }
CWE-119
17,021
cJSON *cJSON_Parse( const char *value ) { cJSON *c; ep = 0; if ( ! ( c = cJSON_New_Item() ) ) return 0; /* memory fail */ if ( ! parse_value( c, skip( value ) ) ) { cJSON_Delete( c ); return 0; } return c; }
CWE-119
17,022
cJSON *cJSON_CreateFloatArray( double *numbers, int count ) { int i; cJSON *n = 0, *p = 0, *a = cJSON_CreateArray(); for ( i = 0; a && i < count; ++i ) { n = cJSON_CreateFloat( numbers[i] ); if ( ! i ) a->child = n; else suffix_object( p, n ); p = n; } return a; }
CWE-119
17,023
cJSON *cJSON_CreateTrue( void ) { cJSON *item = cJSON_New_Item(); if ( item ) item->type = cJSON_True; return item; }
CWE-119
17,024
static double ipow( double n, int exp ) { double r; if ( exp < 0 ) return 1.0 / ipow( n, -exp ); r = 1; while ( exp > 0 ) { if ( exp & 1 ) r *= n; exp >>= 1; n *= n; } return r; }
CWE-119
17,025
static const char *parse_value( cJSON *item, const char *value ) { if ( ! value ) return 0; /* Fail on null. */ if ( ! strncmp( value, "null", 4 ) ) { item->type = cJSON_NULL; return value + 4; } if ( ! strncmp( value, "false", 5 ) ) { item->type = cJSON_False; return value + 5; } if ( ! strncmp( value, "true", 4 ) ) { item->type = cJSON_True; item->valueint = 1; return value + 4; } if ( *value == '\"' ) return parse_string( item, value ); if ( *value == '-' || ( *value >= '0' && *value <= '9' ) ) return parse_number( item, value ); if ( *value == '[' ) return parse_array( item, value ); if ( *value == '{' ) return parse_object( item, value ); /* Fail. */ ep = value; return 0; }
CWE-119
17,026
const char *cJSON_GetErrorPtr( void ) { return ep; }
CWE-119
17,027
static char* cJSON_strdup( const char* str ) { size_t len; char* copy; len = strlen( str ) + 1; if ( ! ( copy = (char*) cJSON_malloc( len ) ) ) return 0; memcpy( copy, str, len ); return copy; }
CWE-119
17,028
static cJSON *cJSON_New_Item( void ) { cJSON* node = (cJSON*) cJSON_malloc( sizeof(cJSON) ); if ( node ) memset( node, 0, sizeof(cJSON) ); return node; }
CWE-119
17,029