From da0200a1e50b3b4335757086a7426495eaacb31b Mon Sep 17 00:00:00 2001 From: Baruch Siach Date: Mon, 15 Oct 2012 14:21:45 +0200 Subject: nanddump: use the right operator of logic AND Signed-off-by: Baruch Siach Signed-off-by: Denys Vlasenko --- miscutils/nandwrite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miscutils/nandwrite.c b/miscutils/nandwrite.c index c636a5aa2..a93433457 100644 --- a/miscutils/nandwrite.c +++ b/miscutils/nandwrite.c @@ -162,7 +162,7 @@ int nandwrite_main(int argc UNUSED_PARAM, char **argv) tmp = next_good_eraseblock(fd, &meminfo, blockstart); if (tmp != blockstart) { /* bad block(s), advance mtdoffset */ - if (IS_NANDDUMP & !(opts & OPT_b)) { + if (IS_NANDDUMP && !(opts & OPT_b)) { int bad_len = MIN(tmp, end_addr) - mtdoffset; dump_bad(&meminfo, bad_len, !(opts & OPT_o)); } -- cgit v1.2.3-55-g6feb From 98f6b2d399e5fc02989390a04bd6c955b309cf7d Mon Sep 17 00:00:00 2001 From: Baruch Siach Date: Mon, 15 Oct 2012 14:25:26 +0200 Subject: nanddump: skip bad blocks when instructed to do so Signed-off-by: Baruch Siach Signed-off-by: Denys Vlasenko --- miscutils/nandwrite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miscutils/nandwrite.c b/miscutils/nandwrite.c index a93433457..554d36249 100644 --- a/miscutils/nandwrite.c +++ b/miscutils/nandwrite.c @@ -182,7 +182,7 @@ int nandwrite_main(int argc UNUSED_PARAM, char **argv) mtdoffset = next_good_eraseblock(fd, &meminfo, blockstart); if (IS_NANDWRITE) printf("Writing at 0x%08x\n", mtdoffset); - else if (mtdoffset > blockstart) { + else if (mtdoffset > blockstart && !(opts & OPT_b)) { int bad_len = MIN(mtdoffset, limit) - blockstart; dump_bad(&meminfo, bad_len, !(opts & OPT_o)); } -- cgit v1.2.3-55-g6feb From 3aeb870b2284713a5f206bc40910b86da7d26966 Mon Sep 17 00:00:00 2001 From: Baruch Siach Date: Mon, 15 Oct 2012 14:32:23 +0200 Subject: nanddump: invert the meaning of the -o parameter to match upstream Signed-off-by: Baruch Siach Signed-off-by: Denys Vlasenko --- miscutils/nandwrite.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/miscutils/nandwrite.c b/miscutils/nandwrite.c index 554d36249..5908ac773 100644 --- a/miscutils/nandwrite.c +++ b/miscutils/nandwrite.c @@ -39,7 +39,7 @@ //usage: "[-o] [-b] [-s ADDR] [-f FILE] MTD_DEVICE" //usage:#define nanddump_full_usage "\n\n" //usage: "Dump the specified MTD device\n" -//usage: "\n -o Omit oob data" +//usage: "\n -o Dump oob data" //usage: "\n -b Omit bad block from the dump" //usage: "\n -s ADDR Start address" //usage: "\n -l LEN Length" @@ -164,7 +164,7 @@ int nandwrite_main(int argc UNUSED_PARAM, char **argv) /* bad block(s), advance mtdoffset */ if (IS_NANDDUMP && !(opts & OPT_b)) { int bad_len = MIN(tmp, end_addr) - mtdoffset; - dump_bad(&meminfo, bad_len, !(opts & OPT_o)); + dump_bad(&meminfo, bad_len, opts & OPT_o); } mtdoffset = tmp; } @@ -184,7 +184,7 @@ int nandwrite_main(int argc UNUSED_PARAM, char **argv) printf("Writing at 0x%08x\n", mtdoffset); else if (mtdoffset > blockstart && !(opts & OPT_b)) { int bad_len = MIN(mtdoffset, limit) - blockstart; - dump_bad(&meminfo, bad_len, !(opts & OPT_o)); + dump_bad(&meminfo, bad_len, opts & OPT_o); } if (mtdoffset >= limit) break; @@ -210,7 +210,7 @@ int nandwrite_main(int argc UNUSED_PARAM, char **argv) } xwrite(output_fd, filebuf, meminfo_writesize); - if (IS_NANDDUMP && !(opts & OPT_o)) { + if (IS_NANDDUMP && (opts & OPT_o)) { /* Dump OOB data */ oob.start = mtdoffset; xioctl(fd, MEMREADOOB, &oob); -- cgit v1.2.3-55-g6feb From 67dc7b21cae44627d0ee55aedb90e421f58ac9c9 Mon Sep 17 00:00:00 2001 From: Timo Teräs Date: Wed, 17 Oct 2012 19:39:34 +0200 Subject: fbsplash: fix regression from e4fa7b7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit e4fa7b7 (limit progress bar flicker) made the progress bar counter unsigned causing i < 0 to never come true. Signed-off-by: Timo Teräs Signed-off-by: Denys Vlasenko --- miscutils/fbsplash.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/miscutils/fbsplash.c b/miscutils/fbsplash.c index 37ca66559..05a77da23 100644 --- a/miscutils/fbsplash.c +++ b/miscutils/fbsplash.c @@ -312,8 +312,7 @@ static void fb_drawprogressbar(unsigned percent) pos_x = left_x; if (percent > 0) { - int y; - unsigned i; + int i, y; // actual progress bar pos_x += (unsigned)(width * percent) / 100; @@ -325,7 +324,7 @@ static void fb_drawprogressbar(unsigned percent) while (i >= 0) { // draw one-line thick "rectangle" // top line will have gray lvl 200, bottom one 100 - unsigned gray_level = 100 + i*100 / height; + unsigned gray_level = 100 + (unsigned)i*100 / height; fb_drawfullrectangle( left_x, y, pos_x, y, gray_level, gray_level, gray_level); -- cgit v1.2.3-55-g6feb From 5694afd72a0a424fcdd2ac85838229a1a86b7e84 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sat, 20 Oct 2012 15:01:26 -0400 Subject: build system: use pkg-config to look up selinux libs Newer versions of libselinux has started linking against more libs. Rather than continuing hardcoding things, switch to using pkg-config to query for its dependencies. Signed-off-by: Mike Frysinger --- Makefile | 1 + Makefile.flags | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b2e94775c..8995ff506 100644 --- a/Makefile +++ b/Makefile @@ -297,6 +297,7 @@ NM = $(CROSS_COMPILE)nm STRIP = $(CROSS_COMPILE)strip OBJCOPY = $(CROSS_COMPILE)objcopy OBJDUMP = $(CROSS_COMPILE)objdump +PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config AWK = awk GENKSYMS = scripts/genksyms/genksyms DEPMOD = /sbin/depmod diff --git a/Makefile.flags b/Makefile.flags index e77c0e527..307afa7f5 100644 --- a/Makefile.flags +++ b/Makefile.flags @@ -78,6 +78,12 @@ ARCH_FPIC ?= -fpic ARCH_FPIE ?= -fpie ARCH_PIE ?= -pie +# Usage: $(eval $(call pkg_check_modules,VARIABLE-PREFIX,MODULES)) +define pkg_check_modules +$(1)_CFLAGS := $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --cflags $(2)) +$(1)_LIBS := $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --libs $(2)) +endef + ifeq ($(CONFIG_BUILD_LIBBUSYBOX),y) # on i386: 14% smaller libbusybox.so # (code itself is 9% bigger, we save on relocs/PLT/GOT) @@ -89,6 +95,7 @@ endif ifeq ($(CONFIG_STATIC),y) CFLAGS_busybox += -static +PKG_CONFIG_FLAGS += --static endif ifeq ($(CONFIG_PIE),y) @@ -131,7 +138,10 @@ LDLIBS += pam pam_misc pthread endif ifeq ($(CONFIG_SELINUX),y) -LDLIBS += selinux sepol +SELINUX_PC_MODULES = libselinux libsepol +$(eval $(call pkg_check_modules,SELINUX,$(SELINUX_PC_MODULES))) +CPPFLAGS += $(SELINUX_CFLAGS) +LDLIBS += $(if $(SELINUX_LIBS),$(SELINUX_LIBS:-l%=%),$(SELINUX_PC_MODULES:lib%=%)) endif ifeq ($(CONFIG_EFENCE),y) -- cgit v1.2.3-55-g6feb From d2d5049c1d1ebb052387790df04740a3857fde63 Mon Sep 17 00:00:00 2001 From: S-G Bergh Date: Mon, 5 Nov 2012 13:16:07 +0100 Subject: blkid: show filesystem when both label and UUID are missing, but type is known Signed-off-by: S-G Bergh Signed-off-by: Denys Vlasenko --- util-linux/volume_id/get_devname.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/util-linux/volume_id/get_devname.c b/util-linux/volume_id/get_devname.c index 230102d89..665cb9b6e 100644 --- a/util-linux/volume_id/get_devname.c +++ b/util-linux/volume_id/get_devname.c @@ -49,7 +49,11 @@ get_label_uuid(int fd, char **label, char **uuid, const char **type) if (volume_id_probe_all(vid, /*0,*/ size) != 0) goto ret; - if (vid->label[0] != '\0' || vid->uuid[0] != '\0') { + if (vid->label[0] != '\0' || vid->uuid[0] != '\0' +#if ENABLE_FEATURE_BLKID_TYPE + || vid->type != NULL +#endif + ) { *label = xstrndup(vid->label, sizeof(vid->label)); *uuid = xstrndup(vid->uuid, sizeof(vid->uuid)); #if ENABLE_FEATURE_BLKID_TYPE -- cgit v1.2.3-55-g6feb From 11181335f9a97feddb30da4d09f9cd3739b8badd Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 5 Nov 2012 13:22:56 +0100 Subject: ifupdown: simple code shrink function old new delta execute 631 607 -24 Signed-off-by: Denys Vlasenko --- networking/ifupdown.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/networking/ifupdown.c b/networking/ifupdown.c index ad0a9971b..9fc1266da 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c @@ -259,7 +259,7 @@ static char *parse(const char *command, struct interface_defn_t *ifd) opt_depth++; command += 2; } else { - addstr(&result, "[", 1); + addstr(&result, command, 1); command++; } break; @@ -271,7 +271,7 @@ static char *parse(const char *command, struct interface_defn_t *ifd) } command += 2; } else { - addstr(&result, "]", 1); + addstr(&result, command, 1); command++; } break; -- cgit v1.2.3-55-g6feb From a803bfa0f06c10d8581bd457b9ba937466c73588 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 5 Nov 2012 14:18:36 +0100 Subject: ifupdown: remove unused errno assignments function old new delta execute 607 571 -36 Signed-off-by: Denys Vlasenko --- networking/ifupdown.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/networking/ifupdown.c b/networking/ifupdown.c index 9fc1266da..650cc706f 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c @@ -49,9 +49,6 @@ #include #define MAX_OPT_DEPTH 10 -#define EUNBALBRACK 10001 -#define EUNDEFVAR 10002 -#define EUNBALPER 10000 #if ENABLE_FEATURE_IFUPDOWN_MAPPING #define MAX_INTERFACE_LENGTH 10 @@ -283,7 +280,7 @@ static char *parse(const char *command, struct interface_defn_t *ifd) command++; nextpercent = strchr(command, '%'); if (!nextpercent) { - errno = EUNBALPER; + /* Unterminated %var% */ free(result); return NULL; } @@ -328,13 +325,13 @@ static char *parse(const char *command, struct interface_defn_t *ifd) } if (opt_depth > 1) { - errno = EUNBALBRACK; + /* Unbalanced bracket */ free(result); return NULL; } if (!okay[0]) { - errno = EUNDEFVAR; + /* Undefined variable and we aren't in a bracket */ free(result); return NULL; } -- cgit v1.2.3-55-g6feb From 3f21044f20ef304309651bbdef8b275475f03a28 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 9 Nov 2012 17:16:40 +0100 Subject: ifupdown: code shrink function old new delta execute 571 548 -23 Signed-off-by: Denys Vlasenko --- networking/ifupdown.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/networking/ifupdown.c b/networking/ifupdown.c index 650cc706f..818048284 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c @@ -230,7 +230,7 @@ static int count_netmask_bits(const char *dotted_quad) static char *parse(const char *command, struct interface_defn_t *ifd) { size_t old_pos[MAX_OPT_DEPTH] = { 0 }; - int okay[MAX_OPT_DEPTH] = { 1 }; + smallint okay[MAX_OPT_DEPTH] = { 1 }; int opt_depth = 1; char *result = NULL; @@ -241,13 +241,10 @@ static char *parse(const char *command, struct interface_defn_t *ifd) command++; break; case '\\': - if (command[1]) { - addstr(&result, command + 1, 1); - command += 2; - } else { - addstr(&result, command, 1); + if (command[1]) command++; - } + addstr(&result, command, 1); + command++; break; case '[': if (command[1] == '[' && opt_depth < MAX_OPT_DEPTH) { -- cgit v1.2.3-55-g6feb From e4b9451413013388757cf48fbb16d8137ddd1ccb Mon Sep 17 00:00:00 2001 From: S-G Bergh Date: Tue, 13 Nov 2012 14:40:37 +0100 Subject: volume_id: add exFAT detection function old new delta volume_id_probe_exfat - 294 +294 Signed-off-by: S-G Bergh Signed-off-by: Denys Vlasenko --- util-linux/Config.src | 9 +++ util-linux/volume_id/Kbuild.src | 1 + util-linux/volume_id/exfat.c | 130 ++++++++++++++++++++++++++++++ util-linux/volume_id/volume_id.c | 3 + util-linux/volume_id/volume_id_internal.h | 2 + 5 files changed, 145 insertions(+) create mode 100644 util-linux/volume_id/exfat.c diff --git a/util-linux/Config.src b/util-linux/Config.src index 3355e9729..e4516ddb7 100644 --- a/util-linux/Config.src +++ b/util-linux/Config.src @@ -734,6 +734,15 @@ config FEATURE_VOLUMEID_FAT help TODO +config FEATURE_VOLUMEID_EXFAT + bool "exFAT filesystem" + default y + depends on VOLUMEID + help + exFAT (extended FAT) is a proprietary file system designed especially + for flash drives. It has many features from NTFS, but with less + overhead. exFAT is used on most SDXC cards for consumer electronics. + config FEATURE_VOLUMEID_HFS bool "hfs filesystem" default y diff --git a/util-linux/volume_id/Kbuild.src b/util-linux/volume_id/Kbuild.src index 39a2d8cf4..759fdaae5 100644 --- a/util-linux/volume_id/Kbuild.src +++ b/util-linux/volume_id/Kbuild.src @@ -33,6 +33,7 @@ lib-$(CONFIG_FEATURE_VOLUMEID_LINUXSWAP) += linux_swap.o ### lib-$(CONFIG_FEATURE_VOLUMEID_MSDOS) += msdos.o lib-$(CONFIG_FEATURE_VOLUMEID_NILFS) += nilfs.o lib-$(CONFIG_FEATURE_VOLUMEID_NTFS) += ntfs.o +lib-$(CONFIG_FEATURE_VOLUMEID_EXFAT) += exfat.o lib-$(CONFIG_FEATURE_VOLUMEID_REISERFS) += reiserfs.o lib-$(CONFIG_FEATURE_VOLUMEID_UDF) += udf.o ### lib-$(CONFIG_FEATURE_VOLUMEID_UFS) += ufs.o diff --git a/util-linux/volume_id/exfat.c b/util-linux/volume_id/exfat.c new file mode 100644 index 000000000..a38a8916d --- /dev/null +++ b/util-linux/volume_id/exfat.c @@ -0,0 +1,130 @@ +/* + * volume_id - reads filesystem label and uuid + * + * Copyright (C) 2012 S-G Bergh + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "volume_id_internal.h" + +#define EXFAT_SB_OFFSET 0 +#define EXFAT_DIR_ENTRY_SZ 32 +#define EXFAT_MAX_DIR_ENTRIES 100 + +struct exfat_super_block { +/* 0x00 */ uint8_t boot_jump[3]; +/* 0x03 */ uint8_t fs_name[8]; +/* 0x0B */ uint8_t must_be_zero[53]; +/* 0x40 */ uint64_t partition_offset; +/* 0x48 */ uint64_t volume_length; +/* 0x50 */ uint32_t fat_offset; // Sector address of 1st FAT +/* 0x54 */ uint32_t fat_size; // In sectors +/* 0x58 */ uint32_t cluster_heap_offset; // Sector address of Data Region +/* 0x5C */ uint32_t cluster_count; +/* 0x60 */ uint32_t root_dir; // Cluster address of Root Directory +/* 0x64 */ uint8_t vol_serial_nr[4]; // Volume ID +/* 0x68 */ uint16_t fs_revision; // VV.MM +/* 0x6A */ uint16_t vol_flags; +/* 0x6C */ uint8_t bytes_per_sector; // Power of 2: 9 => 512, 12 => 4096 +/* 0x6D */ uint8_t sectors_per_cluster; // Power of 2 +/* 0x6E */ uint8_t nr_of_fats; // 2 for TexFAT +/* 0x6F */ // ... +} PACKED; + +struct exfat_dir_entry { +/* 0x00 */ uint8_t entry_type; + union { + struct volume_label { +/* 0x01 */ uint8_t char_count; // Length of label +/* 0x02 */ uint16_t vol_label[11]; // UTF16 string without null termination +/* 0x18 */ uint8_t reserved[8]; +/* 0x20 */ } PACKED label; + struct volume_guid { +/* 0x01 */ uint8_t sec_count; +/* 0x02 */ uint16_t set_checksum; +/* 0x04 */ uint16_t flags; +/* 0x06 */ uint8_t vol_guid[16]; +/* 0x16 */ uint8_t reserved[10]; +/* 0x20 */ } PACKED guid; + } PACKED type; +} PACKED; + +int FAST_FUNC volume_id_probe_exfat(struct volume_id *id /*,uint64_t off*/) +{ + struct exfat_super_block *sb; + struct exfat_dir_entry *de; + unsigned sector_sz; + unsigned cluster_sz; + uint64_t root_dir_off; + unsigned count; + unsigned need_lbl_guid; + + // Primary super block + dbg("exFAT: probing at offset 0x%x", EXFAT_SB_OFFSET); + sb = volume_id_get_buffer(id, EXFAT_SB_OFFSET, sizeof(*sb)); + + if (!sb) + return -1; + + if (memcmp(sb->fs_name, "EXFAT ", 8) != 0) + return -1; + + sector_sz = 1 << sb->bytes_per_sector; + cluster_sz = sector_sz << sb->sectors_per_cluster; + // There are no clusters 0 and 1, so the first cluster is 2. + root_dir_off = (uint64_t)EXFAT_SB_OFFSET + + // Hmm... should we cast sector_sz/cluster_sz to uint64_t? + (le32_to_cpu(sb->cluster_heap_offset)) * sector_sz + + (le32_to_cpu(sb->root_dir) - 2) * cluster_sz; + dbg("exFAT: sector size 0x%x bytes", sector_sz); + dbg("exFAT: cluster size 0x%x bytes", cluster_sz); + dbg("exFAT: root dir is at 0x%llx", (long long)root_dir_off); + + // Use DOS uuid as fallback, if no GUID set + volume_id_set_uuid(id, sb->vol_serial_nr, UUID_DOS); + + // EXFAT_MAX_DIR_ENTRIES is used as a safety belt. + // The Root Directory may hold an unlimited number of entries, + // so we do not want to check all. Usually label and GUID + // are in the beginning, but there are no guarantees. + need_lbl_guid = (1 << 0) | (1 << 1); + for (count = 0; count < EXFAT_MAX_DIR_ENTRIES; count++) { + de = volume_id_get_buffer(id, root_dir_off + (count * EXFAT_DIR_ENTRY_SZ), EXFAT_DIR_ENTRY_SZ); + if (de == NULL) + break; + if (de->entry_type == 0x00) { + // End of Directory Marker + dbg("exFAT: End of root directory reached after %u entries", count); + break; + } + if (de->entry_type == 0x83) { + // Volume Label Directory Entry + volume_id_set_label_unicode16(id, (uint8_t *)de->type.label.vol_label, + LE, 2 * de->type.label.char_count); + need_lbl_guid &= ~(1 << 0); + } + if (de->entry_type == 0xA0) { + // Volume GUID Directory Entry + volume_id_set_uuid(id, de->type.guid.vol_guid, UUID_DCE); + need_lbl_guid &= ~(1 << 1); + } + if (!need_lbl_guid) + break; + } + + IF_FEATURE_BLKID_TYPE(id->type = "exfat";) + return 0; +} diff --git a/util-linux/volume_id/volume_id.c b/util-linux/volume_id/volume_id.c index c1d615283..3c3c69818 100644 --- a/util-linux/volume_id/volume_id.c +++ b/util-linux/volume_id/volume_id.c @@ -93,6 +93,9 @@ static const probe_fptr fs1[] = { #if ENABLE_FEATURE_VOLUMEID_FAT volume_id_probe_vfat, #endif +#if ENABLE_FEATURE_VOLUMEID_EXFAT + volume_id_probe_exfat, +#endif #if ENABLE_FEATURE_VOLUMEID_MAC volume_id_probe_mac_partition_map, #endif diff --git a/util-linux/volume_id/volume_id_internal.h b/util-linux/volume_id/volume_id_internal.h index 1c2e0ffa6..03dc46f27 100644 --- a/util-linux/volume_id/volume_id_internal.h +++ b/util-linux/volume_id/volume_id_internal.h @@ -216,6 +216,8 @@ int FAST_FUNC volume_id_probe_nilfs(struct volume_id *id /*,uint64_t off*/); int FAST_FUNC volume_id_probe_ntfs(struct volume_id *id /*,uint64_t off*/); +int FAST_FUNC volume_id_probe_exfat(struct volume_id *id /*,uint64_t off*/); + int FAST_FUNC volume_id_probe_ocfs2(struct volume_id *id /*,uint64_t off*/); int FAST_FUNC volume_id_probe_reiserfs(struct volume_id *id /*,uint64_t off*/); -- cgit v1.2.3-55-g6feb From 4ba6c5d3ba3d2c7922aff6b5c2e73b8325f1cf17 Mon Sep 17 00:00:00 2001 From: Jon Tollefson Date: Tue, 13 Nov 2012 19:26:53 +0100 Subject: ash: fix a memory leak The script which triggers the leak: while true do while true do break; done Signed-off-by: Denys Vlasenko --- shell/ash.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shell/ash.c b/shell/ash.c index 010924db4..dda18e8b5 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -8676,6 +8676,8 @@ expredir(union node *n) #if ENABLE_ASH_BASH_COMPAT store_expfname: #endif + if (redir->nfile.expfname) + stunalloc(redir->nfile.expfname); redir->nfile.expfname = fn.list->text; break; case NFROMFD: -- cgit v1.2.3-55-g6feb From c71547ccfce9aff4e616c9c57a6602ca66c705e0 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 5 Dec 2012 01:04:54 +0100 Subject: decompress_uncompress: move 'code' variable into loop - sole user Apparently, gcc does this optimization itself, since generated code is the same. Signed-off-by: Denys Vlasenko --- archival/libarchive/decompress_uncompress.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/archival/libarchive/decompress_uncompress.c b/archival/libarchive/decompress_uncompress.c index e9bbfb9bd..4ccc8a697 100644 --- a/archival/libarchive/decompress_uncompress.c +++ b/archival/libarchive/decompress_uncompress.c @@ -78,7 +78,6 @@ unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd) IF_DESKTOP(long long total_written = 0;) IF_DESKTOP(long long) int retval = -1; unsigned char *stackp; - long code; int finchar; long oldcode; long incode; @@ -143,8 +142,10 @@ unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd) /* As above, initialize the first 256 entries in the table. */ /*clear_tab_prefixof(); - done by xzalloc */ - for (code = 255; code >= 0; --code) { - tab_suffixof(code) = (unsigned char) code; + { + int i; + for (i = 255; i >= 0; --i) + tab_suffixof(i) = (unsigned char) i; } do { @@ -175,6 +176,8 @@ unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd) (insize << 3) - (n_bits - 1)); while (inbits > posbits) { + long code; + if (free_ent > maxcode) { posbits = ((posbits - 1) + @@ -191,13 +194,12 @@ unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd) } { unsigned char *p = &inbuf[posbits >> 3]; - - code = ((((long) (p[0])) | ((long) (p[1]) << 8) | - ((long) (p[2]) << 16)) >> (posbits & 0x7)) & bitmask; + code = ((p[0] + | ((long) (p[1]) << 8) + | ((long) (p[2]) << 16)) >> (posbits & 0x7)) & bitmask; } posbits += n_bits; - if (oldcode == -1) { if (code >= 256) bb_error_msg_and_die("corrupted data"); /* %ld", code); */ @@ -244,7 +246,7 @@ unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd) } /* Generate output characters in reverse order */ - while ((long) code >= (long) 256) { + while (code >= 256) { if (stackp <= &htabof(0)) bb_error_msg_and_die("corrupted data"); *--stackp = tab_suffixof(code); @@ -285,11 +287,10 @@ unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd) } /* Generate the new entry. */ - code = free_ent; - if (code < maxmaxcode) { - tab_prefixof(code) = (unsigned short) oldcode; - tab_suffixof(code) = (unsigned char) finchar; - free_ent = code + 1; + if (free_ent < maxmaxcode) { + tab_prefixof(free_ent) = (unsigned short) oldcode; + tab_suffixof(free_ent) = (unsigned char) finchar; + free_ent++; } /* Remember previous code. */ -- cgit v1.2.3-55-g6feb From a8461173ba5431bb64cd37112eba44a6b51640c4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 5 Dec 2012 01:06:05 +0100 Subject: decompress_uncompress: comment out debug printout on corrupted data 99% plus of all people who'll get corrupted archive wouldn't bother debugging it. The rest can uncomment the code. function old new delta unpack_Z_stream 1304 1234 -70 Signed-off-by: Denys Vlasenko --- archival/libarchive/decompress_uncompress.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/archival/libarchive/decompress_uncompress.c b/archival/libarchive/decompress_uncompress.c index 4ccc8a697..0b2db94bb 100644 --- a/archival/libarchive/decompress_uncompress.c +++ b/archival/libarchive/decompress_uncompress.c @@ -232,11 +232,12 @@ unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd) posbits -= n_bits; p = &inbuf[posbits >> 3]; - +/* bb_error_msg ("insize:%d posbits:%d inbuf:%02X %02X %02X %02X %02X (%d)", insize, posbits, p[-1], p[0], p[1], p[2], p[3], (posbits & 07)); +*/ bb_error_msg("corrupted data"); goto err; } -- cgit v1.2.3-55-g6feb From 4d5955e9ece64e273e72c303983199be73022fab Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 5 Dec 2012 11:08:30 +0100 Subject: decompress_uncompress: comment out a bigger chunk of debug code Signed-off-by: Denys Vlasenko --- archival/libarchive/decompress_uncompress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archival/libarchive/decompress_uncompress.c b/archival/libarchive/decompress_uncompress.c index 0b2db94bb..3826a65ea 100644 --- a/archival/libarchive/decompress_uncompress.c +++ b/archival/libarchive/decompress_uncompress.c @@ -228,11 +228,11 @@ unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd) /* Special case for KwKwK string. */ if (code >= free_ent) { if (code > free_ent) { +/* unsigned char *p; posbits -= n_bits; p = &inbuf[posbits >> 3]; -/* bb_error_msg ("insize:%d posbits:%d inbuf:%02X %02X %02X %02X %02X (%d)", insize, posbits, p[-1], p[0], p[1], p[2], p[3], -- cgit v1.2.3-55-g6feb