diff options
author | Robert Griebl <griebl@gmx.de> | 2002-07-19 00:05:54 +0000 |
---|---|---|
committer | Robert Griebl <griebl@gmx.de> | 2002-07-19 00:05:54 +0000 |
commit | d378c3149c6c24e7788f04a6d20ba360f3ea407e (patch) | |
tree | 945ff88bbbde5a32c2b3342b22d801be90ea40f2 /coreutils | |
parent | 88947dd05e28a3b793b16dfd6db1b5414ca99017 (diff) | |
download | busybox-w32-d378c3149c6c24e7788f04a6d20ba360f3ea407e.tar.gz busybox-w32-d378c3149c6c24e7788f04a6d20ba360f3ea407e.tar.bz2 busybox-w32-d378c3149c6c24e7788f04a6d20ba360f3ea407e.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.
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/expr.c | 10 | ||||
-rw-r--r-- | coreutils/ln.c | 32 |
2 files changed, 19 insertions, 23 deletions
diff --git a/coreutils/expr.c b/coreutils/expr.c index 0299cc73a..55ae3a969 100644 --- a/coreutils/expr.c +++ b/coreutils/expr.c | |||
@@ -146,12 +146,8 @@ static int null (VALUE *v) | |||
146 | 146 | ||
147 | static void tostring (VALUE *v) | 147 | static void tostring (VALUE *v) |
148 | { | 148 | { |
149 | char *temp; | ||
150 | |||
151 | if (v->type == integer) { | 149 | if (v->type == integer) { |
152 | temp = xmalloc (4 * (sizeof (int) / sizeof (char))); | 150 | bb_asprintf (&(v->u.s), "%d", v->u.i); |
153 | sprintf (temp, "%d", v->u.i); | ||
154 | v->u.s = temp; | ||
155 | v->type = string; | 151 | v->type = string; |
156 | } | 152 | } |
157 | } | 153 | } |
@@ -377,9 +373,7 @@ static VALUE *eval6 (void) | |||
377 | else { | 373 | else { |
378 | v = xmalloc (sizeof(VALUE)); | 374 | v = xmalloc (sizeof(VALUE)); |
379 | v->type = string; | 375 | v->type = string; |
380 | v->u.s = strncpy ((char *) xmalloc (i2->u.i + 1), | 376 | v->u.s = xstrndup(l->u.s + i1->u.i - 1, i2->u.i); |
381 | l->u.s + i1->u.i - 1, i2->u.i); | ||
382 | v->u.s[i2->u.i] = 0; | ||
383 | } | 377 | } |
384 | freev (l); | 378 | freev (l); |
385 | freev (i1); | 379 | freev (i1); |
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) |