Linux机器3.2.0-34-通用,x86_64
来源:libtar
版本:1.2.11-8
#include <stdio.h>
#include <libtar.h>
#include <fcntl.h>
int main(void)
{
TAR *pTar;
char *tarFilename = "file.tar";
char *srcDir = "/home/test";
char *extractTo = ".";
tar_open(&pTar, tarFilename, NULL, O_WRONLY | O_CREAT, 0644, TAR_GNU);
tar_append_tree(pTar, srcDir, extractTo);
tar_close(pTar);
return (0);
}
编译为:
gcc main.c-o run-ltar
获取segfault
现在使用“gcc main.c-g3-O0-o run-ltar”
Program received signal SIGABRT, Aborted.
0x00007ffff7845425 in __GI_raise (sig=<optimized out>)
at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
64 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
0 0x00007ffff7845425 in __GI_raise (sig=<optimized out>)
at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
1 0x00007ffff7848b8b in __GI_abort () at abort.c:91
2 0x00007ffff788339e in __libc_message (do_abort=2,
fmt=0x7ffff798ae3f "*** %s ***: %s terminated\n")
at ../sysdeps/unix/sysv/linux/libc_fatal.c:201
3 0x00007ffff7919807 in __GI___fortify_fail (
msg=0x7ffff798add6 "buffer overflow detected") at fortify_fail.c:32
4 0x00007ffff7918700 in __GI___chk_fail () at chk_fail.c:29
5 0x00007ffff79179e6 in __strncpy_chk (s1=<optimized out>,
s2=<optimized out>, n=<optimized out>, s1len=<optimized out>)
at strncpy_chk.c:34
6 0x00007ffff7bd12ef in th_finish () from /usr/lib/libtar.so.0
7 0x00007ffff7bd0dc1 in th_write () from /usr/lib/libtar.so.0
8 0x00007ffff7bd07f0 in tar_append_file () from /usr/lib/libtar.so.0
9 0x00007ffff7bd3c12 in tar_append_tree () from /usr/lib/libtar.so.0
10 0x00000000004006f1 in main () at main.c:12
所有示例,此处为f.e
Using libtar to compress a directory
似乎工作得很好。。。。
最佳答案
看起来像是图书馆的缺陷
https://bugzilla.redhat.com/show_bug.cgi?id=538770
您可能需要升级libtar-devel