Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Register
  • Sign in
  • L libxml2
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 91
    • Issues 91
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 6
    • Merge requests 6
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Container Registry
    • Terraform modules
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GNOMEGNOME
  • libxml2
  • Merge requests
  • !173

Fix more overflow checks, off-by-ones and missing NUL terminators in xmlBuf and xmlBuffer

  • Review changes

  • Download
  • Patches
  • Plain diff
Closed David Kilzer requested to merge fix-more-xmlBuf-and-xmlBuffer-issues into master May 13, 2022
  • Overview 11
  • Commits 1
  • Pipelines 2
  • Changes 5

In broad strokes, this does the following:

  • Do not include the NUL terminator byte for lengths returned from functions. This lets functions be more defensive.
  • Set error messages when returning early due to out-of-memory or buffer-too-large errors.
  • Set NUL terminator consistently on buffer boundaries before returning.
  • Add a few more integer overflow checks.
  • buf.c: (xmlBufGrowInternal):
  • Do not include NUL terminator byte when returning length.
  • Always set NUL terminator at the end of the new buffer length before returning.
  • Call xmlBufMemoryError() when the buffer size would overflow.
  • Account for NUL terminator byte when using XML_MAX_TEXT_LENGTH.
  • Always set NUL terminator at the end of the current buffer after resizing the buffer. (xmlBufAddLen):
  • Return an error if the buffer does not have free space for the NUL terminator byte. (xmlBufAvail):
  • Do not include the NUL terminator byte in the length returned. (See changes to encoding.c and xmlIO.c.) (xmlBufResize):
  • Move setting of NUL terminator to common code. More than one path through the function failed to set it. (xmlBufAdd):
  • Call xmlBufMemoryError() when the buffer size would overflow. (xmlBufAddHead):
  • Set NUL terminator before returning early when shifting contents.
  • Add overflow checks similar to those in xmlBufAdd().
  • encoding.c: (xmlCharEncFirstLineInput): (xmlCharEncInput): (xmlCharEncOutput):
  • No longer need to subtract one from the return value of xmlBufAvail() since the function does this now.
  • testchar.c: (testCharRanges):
  • Pass the string length without the NUL terminator.
  • tree.c: (xmlBufferGrow):
  • Do not include NUL terminator byte when returning length.
  • Always set NUL terminator at the end of the new buffer length before returning.
  • Call xmlTreeErrMemory() when the buffer size would overflow.
  • Always set NUL terminator at the end of the current buffer after resizing the buffer. (xmlBufferDump):
  • Change type of the return variable to match fwrite().
  • Clamp return value to INT_MAX to prevent overflow. (xmlBufferResize):
  • Update error message in xmlTreeErrMemory() to be consistent with other similar messages.
  • Fix double semi-colon typos from commit 6c283d83.
  • Move setting of NUL terminator to common code. More than one path through the function failed to set it. (xmlBufferAdd):
  • Call xmlTreeErrMemory() when the buffer size would overflow. (xmlBufferAddHead):
  • Set NUL terminator before returning early when shifting contents.
  • Add overflow checks similar to those in xmlBufferAdd().
  • xmlIO.c: (xmlOutputBufferWriteEscape):
  • No longer need to subtract one from the return value of xmlBufAvail() since the function does this now.
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: fix-more-xmlBuf-and-xmlBuffer-issues