diff options
author | sandman <sandman@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2002-07-19 00:05:54 +0000 |
---|---|---|
committer | sandman <sandman@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2002-07-19 00:05:54 +0000 |
commit | 88c37e3b6514ce684e6f5f38282176f34fc73d0d (patch) | |
tree | 945ff88bbbde5a32c2b3342b22d801be90ea40f2 /coreutils/ln.c | |
parent | d4dbffaf02bf1c39047688988c44c8d60277a76a (diff) | |
download | busybox-w32-88c37e3b6514ce684e6f5f38282176f34fc73d0d.tar.gz busybox-w32-88c37e3b6514ce684e6f5f38282176f34fc73d0d.tar.bz2 busybox-w32-88c37e3b6514ce684e6f5f38282176f34fc73d0d.zip |
Applied vodz' patches #49 and #50 (with a small correction in runshell.c)
#49: I found one memory overflow and memory leak in "ln" applet.
Last patch reduced also 54 bytes. ;)
#50: I found bug in loginutils/Makefile.in.
New patch have also new function to libbb and
aplied this to applets and other cosmetic changes.
git-svn-id: svn://busybox.net/trunk/busybox@5066 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'coreutils/ln.c')
-rw-r--r-- | coreutils/ln.c | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/coreutils/ln.c b/coreutils/ln.c index 1eb853d2f..427ffcc6e 100644 --- a/coreutils/ln.c +++ b/coreutils/ln.c | |||
@@ -43,45 +43,47 @@ static int fs_link(const char *link_destname, const char *link_srcname, | |||
43 | { | 43 | { |
44 | int status; | 44 | int status; |
45 | int src_is_dir; | 45 | int src_is_dir; |
46 | char *src_name; | 46 | char *src_name = 0; |
47 | const char *src; | ||
47 | 48 | ||
48 | if (link_destname==NULL) | 49 | if (link_destname==NULL) |
49 | return(FALSE); | 50 | return(FALSE); |
50 | 51 | ||
51 | src_name = (char *) xmalloc(strlen(link_srcname)+strlen(link_destname)+1); | ||
52 | |||
53 | if (link_srcname==NULL) | 52 | if (link_srcname==NULL) |
54 | strcpy(src_name, link_destname); | 53 | src = link_destname; |
55 | else | 54 | else |
56 | strcpy(src_name, link_srcname); | 55 | src = link_srcname; |
57 | 56 | ||
58 | if (flag&LN_NODEREFERENCE) | 57 | if (flag&LN_NODEREFERENCE) |
59 | src_is_dir = is_directory(src_name, TRUE, NULL); | 58 | src_is_dir = is_directory(src, TRUE, NULL); |
60 | else | 59 | else |
61 | src_is_dir = is_directory(src_name, FALSE, NULL); | 60 | src_is_dir = is_directory(src, FALSE, NULL); |
62 | 61 | ||
63 | if ((src_is_dir==TRUE)&&((flag&LN_NODEREFERENCE)==0)) { | 62 | if ((src_is_dir==TRUE)&&((flag&LN_NODEREFERENCE)==0)) { |
64 | char* srcdir_name; | 63 | char* srcdir_name; |
65 | 64 | ||
66 | srcdir_name = xstrdup(link_destname); | 65 | srcdir_name = xstrdup(link_destname); |
67 | strcat(src_name, "/"); | 66 | src_name = concat_path_file(src, get_last_path_component(srcdir_name)); |
68 | strcat(src_name, get_last_path_component(srcdir_name)); | 67 | src = src_name; |
69 | free(srcdir_name); | 68 | free(srcdir_name); |
70 | } | 69 | } |
71 | 70 | ||
72 | if (flag&LN_FORCE) | 71 | if (flag&LN_FORCE) |
73 | unlink(src_name); | 72 | unlink(src); |
74 | 73 | ||
75 | if (flag&LN_SYMLINK) | 74 | if (flag&LN_SYMLINK) |
76 | status = symlink(link_destname, src_name); | 75 | status = symlink(link_destname, src); |
77 | else | 76 | else |
78 | status = link(link_destname, src_name); | 77 | status = link(link_destname, src); |
79 | 78 | ||
80 | if (status != 0) { | 79 | if (status != 0) { |
81 | perror_msg(src_name); | 80 | perror_msg(src); |
82 | return(FALSE); | 81 | status = FALSE; |
82 | } else { | ||
83 | status = TRUE; | ||
83 | } | 84 | } |
84 | return(TRUE); | 85 | free(src_name); |
86 | return status; | ||
85 | } | 87 | } |
86 | 88 | ||
87 | extern int ln_main(int argc, char **argv) | 89 | extern int ln_main(int argc, char **argv) |