aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2006-05-29 07:42:02 +0000
committerRob Landley <rob@landley.net>2006-05-29 07:42:02 +0000
commit1ec5b2905484b7904aabb01f56c70265fb538c82 (patch)
tree87292bfd7e99ce26b226518e244f4a96914397f9
parenta6e131dab39ee67522687a56b39ed815b9ae15ec (diff)
downloadbusybox-w32-1ec5b2905484b7904aabb01f56c70265fb538c82.tar.gz
busybox-w32-1ec5b2905484b7904aabb01f56c70265fb538c82.tar.bz2
busybox-w32-1ec5b2905484b7904aabb01f56c70265fb538c82.zip
More size shrinkage.
-rw-r--r--archival/dpkg.c134
-rw-r--r--archival/gzip.c12
-rw-r--r--archival/libunarchive/data_extract_to_buffer.c17
-rw-r--r--archival/libunarchive/decompress_bunzip2.c3
-rw-r--r--archival/libunarchive/get_header_ar.c15
-rw-r--r--archival/libunarchive/get_header_cpio.c21
-rw-r--r--archival/libunarchive/get_header_tar.c6
-rw-r--r--archival/libunarchive/rangecoder.h4
-rw-r--r--archival/rpm.c11
-rw-r--r--archival/unzip.c3
-rw-r--r--networking/telnetd.c8
11 files changed, 37 insertions, 197 deletions
diff --git a/archival/dpkg.c b/archival/dpkg.c
index 2895f4f38..c911333e0 100644
--- a/archival/dpkg.c
+++ b/archival/dpkg.c
@@ -7,19 +7,7 @@
7 * 7 *
8 * Started life as a busybox implementation of udpkg 8 * Started life as a busybox implementation of udpkg
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify 10 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 */ 11 */
24 12
25/* 13/*
@@ -556,7 +544,7 @@ static unsigned int fill_package_struct(char *control_buffer)
556 "Conflicts", "Suggests", "Recommends", "Enhances", 0 544 "Conflicts", "Suggests", "Recommends", "Enhances", 0
557 }; 545 };
558 546
559 common_node_t *new_node = (common_node_t *) xcalloc(1, sizeof(common_node_t)); 547 common_node_t *new_node = (common_node_t *) xzalloc(sizeof(common_node_t));
560 char *field_name; 548 char *field_name;
561 char *field_value; 549 char *field_value;
562 int field_start = 0; 550 int field_start = 0;
@@ -677,8 +665,7 @@ static void set_status(const unsigned int status_node_num, const char *new_value
677 bb_error_msg_and_die("DEBUG ONLY: this shouldnt happen"); 665 bb_error_msg_and_die("DEBUG ONLY: this shouldnt happen");
678 } 666 }
679 667
680 new_status = (char *) xmalloc(want_len + flag_len + status_len + 3); 668 new_status = bb_xasprintf("%s %s %s", name_hashtable[want], name_hashtable[flag], name_hashtable[status]);
681 sprintf(new_status, "%s %s %s", name_hashtable[want], name_hashtable[flag], name_hashtable[status]);
682 status_hashtable[status_node_num]->status = search_name_hashtable(new_status); 669 status_hashtable[status_node_num]->status = search_name_hashtable(new_status);
683 free(new_status); 670 free(new_status);
684 return; 671 return;
@@ -741,79 +728,6 @@ static void index_status_file(const char *filename)
741 return; 728 return;
742} 729}
743 730
744#if 0 /* this code is no longer used */
745char *get_depends_field(common_node_t *package, const int depends_type)
746{
747 char *depends = NULL;
748 char *old_sep = (char *)xcalloc(1, 3);
749 char *new_sep = (char *)xcalloc(1, 3);
750 int line_size = 0;
751 int depends_size;
752
753 int i;
754
755 for (i = 0; i < package->num_of_edges; i++) {
756 if ((package->edge[i]->type == EDGE_OR_PRE_DEPENDS) ||
757 (package->edge[i]->type == EDGE_OR_DEPENDS)) {
758 }
759
760 if ((package->edge[i]->type == depends_type) ||
761 (package->edge[i]->type == depends_type + 1)) {
762 /* Check if its the first time through */
763
764 depends_size = 8 + strlen(name_hashtable[package->edge[i]->name])
765 + strlen(name_hashtable[package->edge[i]->version]);
766 line_size += depends_size;
767 depends = (char *) xrealloc(depends, line_size + 1);
768
769 /* Check to see if this dependency is the type we are looking for
770 * +1 to check for 'extra' types, e.g. ored dependecies */
771 strcpy(old_sep, new_sep);
772 if (package->edge[i]->type == depends_type) {
773 strcpy(new_sep, ", ");
774 }
775 else if (package->edge[i]->type == depends_type + 1) {
776 strcpy(new_sep, "| ");
777 }
778
779 if (depends_size == line_size) {
780 strcpy(depends, "");
781 } else {
782 if ((strcmp(old_sep, "| ") == 0) && (strcmp(new_sep, "| ") == 0)) {
783 strcat(depends, " | ");
784 } else {
785 strcat(depends, ", ");
786 }
787 }
788
789 strcat(depends, name_hashtable[package->edge[i]->name]);
790 if (strcmp(name_hashtable[package->edge[i]->version], "NULL") != 0) {
791 if (package->edge[i]->operator == VER_EQUAL) {
792 strcat(depends, " (= ");
793 }
794 else if (package->edge[i]->operator == VER_LESS) {
795 strcat(depends, " (<< ");
796 }
797 else if (package->edge[i]->operator == VER_LESS_EQUAL) {
798 strcat(depends, " (<= ");
799 }
800 else if (package->edge[i]->operator == VER_MORE) {
801 strcat(depends, " (>> ");
802 }
803 else if (package->edge[i]->operator == VER_MORE_EQUAL) {
804 strcat(depends, " (>= ");
805 } else {
806 strcat(depends, " (");
807 }
808 strcat(depends, name_hashtable[package->edge[i]->version]);
809 strcat(depends, ")");
810 }
811 }
812 }
813 return(depends);
814}
815#endif
816
817static void write_buffer_no_status(FILE *new_status_file, const char *control_buffer) 731static void write_buffer_no_status(FILE *new_status_file, const char *control_buffer)
818{ 732{
819 char *name; 733 char *name;
@@ -1027,11 +941,9 @@ static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
1027 package_hashtable[package_num]->edge[j]->operator); 941 package_hashtable[package_num]->edge[j]->operator);
1028 if (package_hashtable[conflicts_package_num] == NULL) { 942 if (package_hashtable[conflicts_package_num] == NULL) {
1029 /* create a new package */ 943 /* create a new package */
1030 common_node_t *new_node = (common_node_t *) xmalloc(sizeof(common_node_t)); 944 common_node_t *new_node = (common_node_t *) xzalloc(sizeof(common_node_t));
1031 new_node->name = package_hashtable[package_num]->edge[j]->name; 945 new_node->name = package_hashtable[package_num]->edge[j]->name;
1032 new_node->version = package_hashtable[package_num]->edge[j]->version; 946 new_node->version = package_hashtable[package_num]->edge[j]->version;
1033 new_node->num_of_edges = 0;
1034 new_node->edge = NULL;
1035 package_hashtable[conflicts_package_num] = new_node; 947 package_hashtable[conflicts_package_num] = new_node;
1036 } 948 }
1037 conflicts = xrealloc(conflicts, sizeof(int) * (conflicts_num + 1)); 949 conflicts = xrealloc(conflicts, sizeof(int) * (conflicts_num + 1));
@@ -1279,15 +1191,10 @@ static int run_package_script(const char *package_name, const char *script_type)
1279 char *script_path; 1191 char *script_path;
1280 int result; 1192 int result;
1281 1193
1282 script_path = xmalloc(strlen(package_name) + strlen(script_type) + 21); 1194 script_path = bb_xasprintf("/var/lib/dpkg/info/%s.%s", package_name, script_type);
1283 sprintf(script_path, "/var/lib/dpkg/info/%s.%s", package_name, script_type);
1284 1195
1285 /* If the file doesnt exist is isnt a fatal */ 1196 /* If the file doesnt exist is isnt a fatal */
1286 if (lstat(script_path, &path_stat) < 0) { 1197 result = lstat(script_path, &path_stat) < 0 ? EXIT_SUCCESS : system(script_path);
1287 result = EXIT_SUCCESS;
1288 } else {
1289 result = system(script_path);
1290 }
1291 free(script_path); 1198 free(script_path);
1292 return(result); 1199 return(result);
1293} 1200}
@@ -1301,13 +1208,11 @@ static char **all_control_list(const char *package_name)
1301 char **remove_files; 1208 char **remove_files;
1302 1209
1303 /* Create a list of all /var/lib/dpkg/info/<package> files */ 1210 /* Create a list of all /var/lib/dpkg/info/<package> files */
1304 remove_files = xmalloc(sizeof(all_control_files)); 1211 remove_files = xzalloc(sizeof(all_control_files));
1305 while (all_control_files[i]) { 1212 while (all_control_files[i]) {
1306 remove_files[i] = xmalloc(strlen(package_name) + strlen(all_control_files[i]) + 21); 1213 remove_files[i] = bb_xasprintf("/var/lib/dpkg/info/%s.%s", package_name, all_control_files[i]);
1307 sprintf(remove_files[i], "/var/lib/dpkg/info/%s.%s", package_name, all_control_files[i]);
1308 i++; 1214 i++;
1309 } 1215 }
1310 remove_files[sizeof(all_control_files)/sizeof(char*) - 1] = NULL;
1311 1216
1312 return(remove_files); 1217 return(remove_files);
1313} 1218}
@@ -1400,11 +1305,9 @@ static void remove_package(const unsigned int package_num, int noisy)
1400 free_array(remove_files); 1305 free_array(remove_files);
1401 1306
1402 /* Create a list of files in /var/lib/dpkg/info/<package>.* to keep */ 1307 /* Create a list of files in /var/lib/dpkg/info/<package>.* to keep */
1403 exclude_files = xmalloc(sizeof(char*) * 3); 1308 exclude_files = xzalloc(sizeof(char*) * 3);
1404 exclude_files[0] = bb_xstrdup(conffile_name); 1309 exclude_files[0] = bb_xstrdup(conffile_name);
1405 exclude_files[1] = xmalloc(package_name_length + 27); 1310 exclude_files[1] = bb_xasprintf("/var/lib/dpkg/info/%s.postrm", package_name);
1406 sprintf(exclude_files[1], "/var/lib/dpkg/info/%s.postrm", package_name);
1407 exclude_files[2] = NULL;
1408 1311
1409 /* Create a list of all /var/lib/dpkg/info/<package> files */ 1312 /* Create a list of all /var/lib/dpkg/info/<package> files */
1410 remove_files = all_control_list(package_name); 1313 remove_files = all_control_list(package_name);
@@ -1440,8 +1343,7 @@ static void purge_package(const unsigned int package_num)
1440 sprintf(list_name, "/var/lib/dpkg/info/%s.list", package_name); 1343 sprintf(list_name, "/var/lib/dpkg/info/%s.list", package_name);
1441 remove_files = create_list(list_name); 1344 remove_files = create_list(list_name);
1442 1345
1443 exclude_files = xmalloc(sizeof(char*)); 1346 exclude_files = xzalloc(sizeof(char*));
1444 exclude_files[0] = NULL;
1445 1347
1446 /* Some directories cant be removed straight away, so do multiple passes */ 1348 /* Some directories cant be removed straight away, so do multiple passes */
1447 while (remove_file_array(remove_files, exclude_files)); 1349 while (remove_file_array(remove_files, exclude_files));
@@ -1536,9 +1438,7 @@ static void data_extract_all_prefix(archive_handle_t *archive_handle)
1536 1438
1537 name_ptr += strspn(name_ptr, "./"); 1439 name_ptr += strspn(name_ptr, "./");
1538 if (name_ptr[0] != '\0') { 1440 if (name_ptr[0] != '\0') {
1539 archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 2 + strlen(name_ptr)); 1441 archive_handle->file_header->name = bb_xasprintf("%s%s", archive_handle->buffer, name_ptr);
1540 strcpy(archive_handle->file_header->name, archive_handle->buffer);
1541 strcat(archive_handle->file_header->name, name_ptr);
1542 data_extract_all(archive_handle); 1442 data_extract_all(archive_handle);
1543 } 1443 }
1544 return; 1444 return;
@@ -1567,14 +1467,12 @@ static void unpack_package(deb_file_t *deb_file)
1567 } 1467 }
1568 1468
1569 /* Extract control.tar.gz to /var/lib/dpkg/info/<package>.filename */ 1469 /* Extract control.tar.gz to /var/lib/dpkg/info/<package>.filename */
1570 info_prefix = (char *) xmalloc(strlen(package_name) + 20 + 4 + 2); 1470 info_prefix = bb_xasprintf("/var/lib/dpkg/info/%s.", package_name);
1571 sprintf(info_prefix, "/var/lib/dpkg/info/%s.", package_name);
1572 archive_handle = init_archive_deb_ar(deb_file->filename); 1471 archive_handle = init_archive_deb_ar(deb_file->filename);
1573 init_archive_deb_control(archive_handle); 1472 init_archive_deb_control(archive_handle);
1574 1473
1575 while(all_control_files[i]) { 1474 while(all_control_files[i]) {
1576 char *c = (char *) xmalloc(3 + strlen(all_control_files[i])); 1475 char *c = bb_xasprintf("./%s", all_control_files[i]);
1577 sprintf(c, "./%s", all_control_files[i]);
1578 llist_add_to(&accept_list, c); 1476 llist_add_to(&accept_list, c);
1579 i++; 1477 i++;
1580 } 1478 }
@@ -1699,7 +1597,7 @@ int dpkg_main(int argc, char **argv)
1699 while (optind < argc) { 1597 while (optind < argc) {
1700 /* deb_count = nb_elem - 1 and we need nb_elem + 1 to allocate terminal node [NULL pointer] */ 1598 /* deb_count = nb_elem - 1 and we need nb_elem + 1 to allocate terminal node [NULL pointer] */
1701 deb_file = xrealloc(deb_file, sizeof(deb_file_t *) * (deb_count + 2)); 1599 deb_file = xrealloc(deb_file, sizeof(deb_file_t *) * (deb_count + 2));
1702 deb_file[deb_count] = (deb_file_t *) xmalloc(sizeof(deb_file_t)); 1600 deb_file[deb_count] = (deb_file_t *) xzalloc(sizeof(deb_file_t));
1703 if (dpkg_opt & dpkg_opt_filename) { 1601 if (dpkg_opt & dpkg_opt_filename) {
1704 archive_handle_t *archive_handle; 1602 archive_handle_t *archive_handle;
1705 llist_t *control_list = NULL; 1603 llist_t *control_list = NULL;
@@ -1742,8 +1640,6 @@ int dpkg_main(int argc, char **argv)
1742 } 1640 }
1743 } 1641 }
1744 else if (dpkg_opt & dpkg_opt_package_name) { 1642 else if (dpkg_opt & dpkg_opt_package_name) {
1745 deb_file[deb_count]->filename = NULL;
1746 deb_file[deb_count]->control_file = NULL;
1747 deb_file[deb_count]->package = search_package_hashtable( 1643 deb_file[deb_count]->package = search_package_hashtable(
1748 search_name_hashtable(argv[optind]), 1644 search_name_hashtable(argv[optind]),
1749 search_name_hashtable("ANY"), VER_ANY); 1645 search_name_hashtable("ANY"), VER_ANY);
diff --git a/archival/gzip.c b/archival/gzip.c
index c31706af3..4f60c6b24 100644
--- a/archival/gzip.c
+++ b/archival/gzip.c
@@ -16,11 +16,7 @@
16 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 16 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
17 */ 17 */
18 18
19/* These defines are very important for BusyBox. Without these,
20 * huge chunks of ram are pre-allocated making the BusyBox bss
21 * size Freaking Huge(tm), which is a bad thing.*/
22#define SMALL_MEM 19#define SMALL_MEM
23#define DYN_ALLOC
24 20
25#include <stdlib.h> 21#include <stdlib.h>
26#include <stdio.h> 22#include <stdio.h>
@@ -87,17 +83,11 @@ typedef unsigned long ulg;
87# endif 83# endif
88#endif 84#endif
89 85
90#ifdef DYN_ALLOC
91# define DECLARE(type, array, size) static type * array 86# define DECLARE(type, array, size) static type * array
92# define ALLOC(type, array, size) { \ 87# define ALLOC(type, array, size) { \
93 array = (type*)xcalloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \ 88 array = (type*)xzalloc((size_t)(((size)+1L)/2) * 2*sizeof(type)); \
94 } 89 }
95# define FREE(array) {free(array), array=NULL;} 90# define FREE(array) {free(array), array=NULL;}
96#else
97# define DECLARE(type, array, size) static type array[size]
98# define ALLOC(type, array, size)
99# define FREE(array)
100#endif
101 91
102#define tab_suffix window 92#define tab_suffix window
103#define tab_prefix prev /* hash link (see deflate.c) */ 93#define tab_prefix prev /* hash link (see deflate.c) */
diff --git a/archival/libunarchive/data_extract_to_buffer.c b/archival/libunarchive/data_extract_to_buffer.c
index 1255fe1da..3eaca98b3 100644
--- a/archival/libunarchive/data_extract_to_buffer.c
+++ b/archival/libunarchive/data_extract_to_buffer.c
@@ -1,17 +1,7 @@
1/* 1/*
2 * This program is free software; you can redistribute it and/or modify 2 * Copyright 2002 Glenn McGrath
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 * 3 *
7 * This program is distributed in the hope that it will be useful, 4 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 */ 5 */
16 6
17#include "libbb.h" 7#include "libbb.h"
@@ -21,8 +11,7 @@ void data_extract_to_buffer(archive_handle_t *archive_handle)
21{ 11{
22 const unsigned int size = archive_handle->file_header->size; 12 const unsigned int size = archive_handle->file_header->size;
23 13
24 archive_handle->buffer = xmalloc(size + 1); 14 archive_handle->buffer = xzalloc(size + 1);
25 15
26 archive_xread_all(archive_handle, archive_handle->buffer, size); 16 archive_xread_all(archive_handle, archive_handle->buffer, size);
27 archive_handle->buffer[size] = '\0';
28} 17}
diff --git a/archival/libunarchive/decompress_bunzip2.c b/archival/libunarchive/decompress_bunzip2.c
index 5e26ffd9f..ae96ea375 100644
--- a/archival/libunarchive/decompress_bunzip2.c
+++ b/archival/libunarchive/decompress_bunzip2.c
@@ -644,8 +644,7 @@ static int start_bunzip(bunzip_data **bdp, int in_fd, unsigned char *inbuf,
644 644
645 /* Allocate bunzip_data. Most fields initialize to zero. */ 645 /* Allocate bunzip_data. Most fields initialize to zero. */
646 646
647 bd=*bdp=xmalloc(i); 647 bd=*bdp=xzalloc(i);
648 memset(bd,0,sizeof(bunzip_data));
649 648
650 /* Setup input buffer */ 649 /* Setup input buffer */
651 650
diff --git a/archival/libunarchive/get_header_ar.c b/archival/libunarchive/get_header_ar.c
index 385f33dbf..69c4bf2b2 100644
--- a/archival/libunarchive/get_header_ar.c
+++ b/archival/libunarchive/get_header_ar.c
@@ -1,17 +1,6 @@
1/* 1/* Copyright 2001 Glenn McGrath.
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 * 2 *
7 * This program is distributed in the hope that it will be useful, 3 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU Library General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 */ 4 */
16 5
17#include <stdio.h> 6#include <stdio.h>
diff --git a/archival/libunarchive/get_header_cpio.c b/archival/libunarchive/get_header_cpio.c
index 2bbcd8e5d..f54b5af69 100644
--- a/archival/libunarchive/get_header_cpio.c
+++ b/archival/libunarchive/get_header_cpio.c
@@ -1,17 +1,6 @@
1/* 1/* Copyright 2002 Laurence Anderson
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 * 2 *
7 * This program is distributed in the hope that it will be useful, 3 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU Library General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 */ 4 */
16 5
17#include <stdio.h> 6#include <stdio.h>
@@ -85,9 +74,8 @@ char get_header_cpio(archive_handle_t *archive_handle)
85 file_header->size = tmpsize; 74 file_header->size = tmpsize;
86 } 75 }
87 76
88 file_header->name = (char *) xmalloc(namesize + 1); 77 file_header->name = (char *) xzalloc(namesize + 1);
89 archive_xread_all(archive_handle, file_header->name, namesize); /* Read in filename */ 78 archive_xread_all(archive_handle, file_header->name, namesize); /* Read in filename */
90 file_header->name[namesize] = '\0';
91 archive_handle->offset += namesize; 79 archive_handle->offset += namesize;
92 80
93 /* Update offset amount and skip padding before file contents */ 81 /* Update offset amount and skip padding before file contents */
@@ -113,9 +101,8 @@ char get_header_cpio(archive_handle_t *archive_handle)
113 } 101 }
114 102
115 if (S_ISLNK(file_header->mode)) { 103 if (S_ISLNK(file_header->mode)) {
116 file_header->link_name = (char *) xmalloc(file_header->size + 1); 104 file_header->link_name = (char *) xzalloc(file_header->size + 1);
117 archive_xread_all(archive_handle, file_header->link_name, file_header->size); 105 archive_xread_all(archive_handle, file_header->link_name, file_header->size);
118 file_header->link_name[file_header->size] = '\0';
119 archive_handle->offset += file_header->size; 106 archive_handle->offset += file_header->size;
120 file_header->size = 0; /* Stop possible seeks in future */ 107 file_header->size = 0; /* Stop possible seeks in future */
121 } else { 108 } else {
diff --git a/archival/libunarchive/get_header_tar.c b/archival/libunarchive/get_header_tar.c
index c9308f906..f3f04b582 100644
--- a/archival/libunarchive/get_header_tar.c
+++ b/archival/libunarchive/get_header_tar.c
@@ -168,17 +168,15 @@ char get_header_tar(archive_handle_t *archive_handle)
168 break; 168 break;
169#ifdef CONFIG_FEATURE_TAR_GNU_EXTENSIONS 169#ifdef CONFIG_FEATURE_TAR_GNU_EXTENSIONS
170 case 'L': { 170 case 'L': {
171 longname = xmalloc(file_header->size + 1); 171 longname = xzalloc(file_header->size + 1);
172 archive_xread_all(archive_handle, longname, file_header->size); 172 archive_xread_all(archive_handle, longname, file_header->size);
173 longname[file_header->size] = '\0';
174 archive_handle->offset += file_header->size; 173 archive_handle->offset += file_header->size;
175 174
176 return(get_header_tar(archive_handle)); 175 return(get_header_tar(archive_handle));
177 } 176 }
178 case 'K': { 177 case 'K': {
179 linkname = xmalloc(file_header->size + 1); 178 linkname = xzalloc(file_header->size + 1);
180 archive_xread_all(archive_handle, linkname, file_header->size); 179 archive_xread_all(archive_handle, linkname, file_header->size);
181 linkname[file_header->size] = '\0';
182 archive_handle->offset += file_header->size; 180 archive_handle->offset += file_header->size;
183 181
184 file_header->name = linkname; 182 file_header->name = linkname;
diff --git a/archival/libunarchive/rangecoder.h b/archival/libunarchive/rangecoder.h
index e43ec3908..b806eebf6 100644
--- a/archival/libunarchive/rangecoder.h
+++ b/archival/libunarchive/rangecoder.h
@@ -36,12 +36,12 @@ static void rc_read(rc_t * rc)
36} 36}
37 37
38/* Called once */ 38/* Called once */
39static ATTRIBUTE_ALWAYS_INLINE void rc_init(rc_t * rc, int fd, int buffer_size) 39static void rc_init(rc_t * rc, int fd, int buffer_size)
40{ 40{
41 int i; 41 int i;
42 42
43 rc->fd = fd; 43 rc->fd = fd;
44 rc->buffer = malloc(buffer_size); 44 rc->buffer = xmalloc(buffer_size);
45 rc->buffer_size = buffer_size; 45 rc->buffer_size = buffer_size;
46 rc->buffer_end = rc->buffer + rc->buffer_size; 46 rc->buffer_end = rc->buffer + rc->buffer_size;
47 rc->ptr = rc->buffer_end; 47 rc->ptr = rc->buffer_end;
diff --git a/archival/rpm.c b/archival/rpm.c
index 7f69f0510..9bbc4a856 100644
--- a/archival/rpm.c
+++ b/archival/rpm.c
@@ -208,7 +208,7 @@ void extract_cpio_gz(int fd) {
208 208
209rpm_index **rpm_gettags(int fd, int *num_tags) 209rpm_index **rpm_gettags(int fd, int *num_tags)
210{ 210{
211 rpm_index **tags = calloc(200, sizeof(struct rpmtag *)); /* We should never need mode than 200, and realloc later */ 211 rpm_index **tags = xzalloc(200 * sizeof(struct rpmtag *)); /* We should never need mode than 200, and realloc later */
212 int pass, tagindex = 0; 212 int pass, tagindex = 0;
213 lseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */ 213 lseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */
214 214
@@ -327,13 +327,10 @@ void fileaction_list(char *filename, int ATTRIBUTE_UNUSED fileref)
327void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref)) 327void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref))
328{ 328{
329 int count = 0; 329 int count = 0;
330 char *filename, *tmp_dirname, *tmp_basename;
331 while (rpm_getstring(filetag, count)) { 330 while (rpm_getstring(filetag, count)) {
332 tmp_dirname = rpm_getstring(RPMTAG_DIRNAMES, rpm_getint(RPMTAG_DIRINDEXES, count)); /* 1st put on the directory */ 331 char * filename = bb_xasprintf("%s%s",
333 tmp_basename = rpm_getstring(RPMTAG_BASENAMES, count); 332 rpm_getstring(RPMTAG_DIRNAMES, rpm_getint(RPMTAG_DIRINDEXES,
334 filename = xmalloc(strlen(tmp_basename) + strlen(tmp_dirname) + 1); 333 count)), rpm_getstring(RPMTAG_BASENAMES, count));
335 strcpy(filename, tmp_dirname); /* First the directory name */
336 strcat(filename, tmp_basename); /* then the filename */
337 fileaction(filename, count++); 334 fileaction(filename, count++);
338 free(filename); 335 free(filename);
339 } 336 }
diff --git a/archival/unzip.c b/archival/unzip.c
index 0b1e6f997..c6ef9a183 100644
--- a/archival/unzip.c
+++ b/archival/unzip.c
@@ -275,9 +275,8 @@ int unzip_main(int argc, char **argv)
275 275
276 /* Read filename */ 276 /* Read filename */
277 free(dst_fn); 277 free(dst_fn);
278 dst_fn = xmalloc(zip_header.formated.filename_len + 1); 278 dst_fn = xzalloc(zip_header.formated.filename_len + 1);
279 unzip_read(src_fd, dst_fn, zip_header.formated.filename_len); 279 unzip_read(src_fd, dst_fn, zip_header.formated.filename_len);
280 dst_fn[zip_header.formated.filename_len] = 0;
281 280
282 /* Skip extra header bytes */ 281 /* Skip extra header bytes */
283 unzip_skip(src_fd, zip_header.formated.extra_len); 282 unzip_skip(src_fd, zip_header.formated.extra_len);
diff --git a/networking/telnetd.c b/networking/telnetd.c
index 5a11ffb8c..f2038395f 100644
--- a/networking/telnetd.c
+++ b/networking/telnetd.c
@@ -3,7 +3,7 @@
3 * Simple telnet server 3 * Simple telnet server
4 * Bjorn Wesen, Axis Communications AB (bjornw@axis.com) 4 * Bjorn Wesen, Axis Communications AB (bjornw@axis.com)
5 * 5 *
6 * Licensed under GPL, see file LICENSE in this tarball for details. 6 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
7 * 7 *
8 * --------------------------------------------------------------------------- 8 * ---------------------------------------------------------------------------
9 * (C) Copyright 2000, Axis Communications AB, LUND, SWEDEN 9 * (C) Copyright 2000, Axis Communications AB, LUND, SWEDEN
@@ -260,21 +260,17 @@ make_new_session(int sockfd)
260 struct termios termbuf; 260 struct termios termbuf;
261 int pty, pid; 261 int pty, pid;
262 char tty_name[32]; 262 char tty_name[32];
263 struct tsession *ts = malloc(sizeof(struct tsession) + BUFSIZE * 2); 263 struct tsession *ts = xzalloc(sizeof(struct tsession) + BUFSIZE * 2);
264 264
265 ts->buf1 = (char *)(&ts[1]); 265 ts->buf1 = (char *)(&ts[1]);
266 ts->buf2 = ts->buf1 + BUFSIZE; 266 ts->buf2 = ts->buf1 + BUFSIZE;
267 267
268#ifdef CONFIG_FEATURE_TELNETD_INETD 268#ifdef CONFIG_FEATURE_TELNETD_INETD
269 ts->sockfd_read = 0;
270 ts->sockfd_write = 1; 269 ts->sockfd_write = 1;
271#else /* CONFIG_FEATURE_TELNETD_INETD */ 270#else /* CONFIG_FEATURE_TELNETD_INETD */
272 ts->sockfd = sockfd; 271 ts->sockfd = sockfd;
273#endif /* CONFIG_FEATURE_TELNETD_INETD */ 272#endif /* CONFIG_FEATURE_TELNETD_INETD */
274 273
275 ts->rdidx1 = ts->wridx1 = ts->size1 = 0;
276 ts->rdidx2 = ts->wridx2 = ts->size2 = 0;
277
278 /* Got a new connection, set up a tty and spawn a shell. */ 274 /* Got a new connection, set up a tty and spawn a shell. */
279 275
280 pty = getpty(tty_name); 276 pty = getpty(tty_name);