Skip to content
  • Jeff King's avatar
    hash-object: fix buffer reuse with --path in a subdirectory · a1be47e4
    Jeff King authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    The hash-object command uses prefix_filename() without
    duplicating its return value. Since that function returns a
    static buffer, the value is overwritten by subsequent calls.
    
    This can cause incorrect results when we use --path along
    with hashing a file by its relative path, both of which need
    to call prefix_filename(). We overwrite the filename
    computed for --path, effectively ignoring it.
    
    We can fix this by calling xstrdup on the return value. Note
    that we don't bother freeing the "vpath" instance, as it
    remains valid until the program exit.
    
    Signed-off-by: default avatarJeff King <peff@peff.net>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    a1be47e4