Skip to content
  • Jeff King's avatar
    odb_mkstemp: write filename into strbuf · 594fa999
    Jeff King authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    The odb_mkstemp() function expects the caller to provide a
    fixed buffer to write the resulting tempfile name into. But
    it creates the template using snprintf without checking the
    return value. This means we could silently truncate the
    filename.
    
    In practice, it's unlikely that the truncation would end in
    the template-pattern that mkstemp needs to open the file. So
    we'd probably end up failing either way, unless the path was
    specially crafted.
    
    The simplest fix would be to notice the truncation and die.
    However, we can observe that most callers immediately
    xstrdup() the result anyway. So instead, let's switch to
    using a strbuf, which is easier for them (and isn't a big
    deal for the other 2 callers, who can just strbuf_release
    when they're done with it).
    
    Note that many of the callers used static buffers, but this
    was purely to avoid putting a large buffer on the stack. We
    never passed the static buffers out of the function, so
    there's no complicated memory handling we need to change.
    
    Signed-off-by: default avatarJeff King <peff@peff.net>
    594fa999