9
0
Fork 0
Commit Graph

399 Commits

Author SHA1 Message Date
Stefan Müller-Klieser 115bfd0009 lzo: check for length overrun in variable length encoding.
This corresponds to kernel commit 72cf90124e87d975d0b

This fix ensures that we never meet an integer overflow while adding
255 while parsing a variable length encoding. It works differently from
commit 206a81c ("lzo: properly check for overruns") because instead of
ensuring that we don't overrun the input, which is tricky to guarantee
due to many assumptions in the code, it simply checks that the cumulated
number of 255 read cannot overflow by bounding this number.

The MAX_255_COUNT is the maximum number of times we can add 255 to a base
count without overflowing an integer. The multiply will overflow when
multiplying 255 by more than MAXINT/255. The sum will overflow earlier
depending on the base count. Since the base count is taken from a u8
and a few bits, it is safe to assume that it will always be lower than
or equal to 2*255, thus we can always prevent any overflow by accepting
two less 255 steps.

This patch also reduces the CPU overhead and actually increases performance
by 1.1% compared to the initial code, while the previous fix costs 3.1%
(measured on x86_64).

The fix needs to be backported to all currently supported stable kernels.

Reported-by: Willem Pinckaers <willem@lekkertech.net>
Cc: "Don A. Bailey" <donb@securitymouse.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Stefan Müller-Klieser <s.mueller-klieser@phytec.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-03-25 09:47:51 +01:00
Stefan Müller-Klieser 69a6dcdc0e Revert "lzo: properly check for overruns"
This reverts barebox commit ecb1dc0b1e
This corresponds to kernel commit af958a38a60c7ca3d8

As analysed by Willem Pinckaers, this fix is still incomplete on
certain rare corner cases, and it is easier to restart from the
original code.

Reported-by: Willem Pinckaers <willem@lekkertech.net>
Cc: "Don A. Bailey" <donb@securitymouse.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Stefan Müller-Klieser <s.mueller-klieser@phytec.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-03-25 09:47:51 +01:00
Sascha Hauer 5dd5884801 lib: Add hex2bin and bin2hex implementations
Taken from the Kernel, put into the same place as in the kernel,
although the hexdump.c does not actually contain hexdum functions.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-03-13 08:22:27 +01:00
Sascha Hauer 55ab01c7ff Merge branch 'for-next/rockchip'
Conflicts:
	arch/arm/Kconfig
2015-03-09 08:30:35 +01:00
Andrey Panov 78d030226d lib: Add gcd() function
It calculates greatest common divisor.

Signed-off-by: Andrey Panov <rockford@yandex.ru>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-03-05 09:11:33 +01:00
Sascha Hauer e5c73e0fe1 cmndlinepart: skip devname if partstr already contains it
When the partition name already starts with "devname." skip this
when adding the partition.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-02-12 09:33:44 +01:00
Sascha Hauer c1156d841f cmdlinepart: add function to parse a cmdline partition string
This adds a function to parse a full cmdline partition string. The
addpart command is switched to use this function.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-02-12 09:33:43 +01:00
Sascha Hauer 10a0aaabfe cmdlinepart: make argument types safer
The return size should be loff_t to support partitions bigger
than 4G. Also use const for the devname and endp.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-02-12 09:33:43 +01:00
Sascha Hauer d397eb6162 cmdlinepart: Change SIZE_REMAINING to loff_t
For compatibility with devices > 4G.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-02-12 09:33:43 +01:00
Sascha Hauer 39f6392d93 move cmdline partition parsing code to separate file
So it's no longer local to the addpart/delpart code and can be used
from other code.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-02-12 09:33:43 +01:00
Sascha Hauer ce961e3412 Merge branch 'for-next/misc' 2015-02-04 19:09:15 +01:00
Masahiro Yamada 03dabc0fe4 param: add error check to __dev_add_param()
If strdup() fails with out-of-memory, __dev_add_param() should fail
with -ENOMEM.

(Note strdup() is always given with a non-NULL pointer.  If the
argument name is given with NULL, the system would already have
crashed in the get_param_by_name() function.)

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-02-02 11:46:31 +01:00
Masahiro Yamada 31cbf0880d param: add error check to dev_param_set_generic()
The function dev_param_set_generic() may fail because of
out of memory.  If so, return -ENOMEM.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-02-02 11:46:31 +01:00
Masahiro Yamada 13a1b45058 lib: decompress: remove redundant INT_MAX define
lib/decompress_bunzip2.c includes <common.h> and INT_MAX is already
defined there.  The definition in this file is redundant.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-01-21 14:58:07 +01:00
Sascha Hauer 39c6c3480a Merge branch 'for-next/mxs' 2015-01-09 17:38:26 +01:00
Sascha Hauer ff6383c8e4 Merge branch 'for-next/misc' 2015-01-09 17:38:26 +01:00
Sascha Hauer cc843dadfd Merge branch 'for-next/efi' 2015-01-09 17:38:26 +01:00
Masahiro Yamada d8753571b2 sizes.h: move include/sizes.h to include/linux/sizes.h
This file originates in Linux.  Linux has it under include/linux/
directory since commit dccd2304cc90.
Let's move it to the same place as well in barebox.

This commit was generated by the following commands:

  find -name '*.[chS]' | xargs sed -i -e 's:<sizes.h>:<linux/sizes.h>:'
  git mv include/sizes.h include/linux/

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-01-08 14:00:26 +01:00
Jean-Christophe PLAGNIOL-VILLARD 461710b119 graphic_utils: set_pixel only write 16bit in 16bit mode
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-01-05 11:36:40 +01:00
Sascha Hauer a9d7b3d00e Add PBL console support
This adds simple console support to the PBL which makes it
possible to print more complex messages in the PBL than just
strings or hex numbers. For now puts_ll is used to print the
messages, so it depends on CONFIG_DEBUG_LL which makes it
more a debugging option. However, this could be extended later
to get regular output from the PBL if desired.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-01-05 11:30:59 +01:00
Sascha Hauer 017da2273a printf: use local isdigit/isalnum implementation
To be independent of the _ctype array. This makes it possible
to add printf support to the PBL without adding _ctype aswell.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-01-05 11:30:58 +01:00
Sascha Hauer 8a7335f8b5 printf: move simple_strto*() functions to separate file
These are not needed in the PBL, so move them to a separate file.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-01-05 11:30:58 +01:00
Sascha Hauer ce5299b0bf printf: move panic() to common/misc.c
panic() is not really a printf like function, so move it to common/misc.c.
This is done because we want to have printf support in the PBL, but PBL
has it's own panic() implementation.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-01-05 11:30:58 +01:00
Lucas Stach 42c8b4589a lib: add wchar strdup
Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-12-09 09:59:10 +01:00
Sascha Hauer b01bc4c810 Merge branch 'for-next/randconfig-1' 2014-12-08 14:54:11 +01:00
Sascha Hauer 3eade89c75 Merge branch 'for-next/persistent-vars'
Conflicts:
	arch/arm/boards/efika-mx-smartbook/defaultenv-efikasb/config
2014-12-08 14:54:09 +01:00
Sascha Hauer c2b5a7015b Merge branch 'for-next/misc' 2014-12-08 14:53:59 +01:00
Jan Luebbe 0d752cb78c stringlist: the string argument should be const
Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-12-04 08:24:05 +01:00
Sascha Hauer 0d5c1b9e97 param: make string arguments to dev_add_param_fixed const
dev_add_param_fixed does not modify the strings, so make them
const.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-11-28 15:21:26 +01:00
Lucas Stach 93b7459e1c lib: decompress_xz: fix function header to match prototype
Fixes:
lib/uncompress.c:124:10: warning: assignment from incompatible pointer type

Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-11-24 14:04:11 +01:00
Jan Luebbe 7dc430e612 stringlist: string_list_contains can use a const string
Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-11-20 14:36:19 +01:00
Jan Weitzel 8e2c7b3de3 xymodem: select CRC16 from lib
Signed-off-by: Jan Weitzel <j.weitzel@phytec.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-11-12 09:22:22 +01:00
Sascha Hauer 9f11887009 libfile: Add copy_recursive
To recursively copy a directory tree.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-11-06 10:58:55 +01:00
Sascha Hauer 592d35a47c Merge branch 'for-next/xz' 2014-11-05 15:47:39 +01:00
Sascha Hauer e3c49aac69 Merge branch 'for-next/misc' 2014-11-05 15:47:39 +01:00
Sascha Hauer da1a9005c2 Merge branch 'for-next/fs' 2014-11-05 15:47:38 +01:00
Sascha Hauer ccb2816477 Add xz decompression support
This adds xz decompression support from the kernel. Both compressing
the barebox binary with xz and decompressing xz files on the commandline
is supported.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-11-04 12:18:55 +01:00
Rolf Evers-Fischer 9ab02e4ec6 lib: parameter: fixed doku renamed ip -> ipaddr
Long time ago all ".ip" parameters have been replaced with ".ipaddr".

Signed-off-by: Rolf Evers-Fischer <embedded24@evers-fischer.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-10-23 07:51:37 +02:00
Sascha Hauer 6cf5b986d9 libfile: add compare_file function
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-10-09 08:47:18 +02:00
Sascha Hauer ade0583602 param: let dev_add_param return the newly created param
dev_add_param creates a new parameter so it makes more sense to
return it than to return an error code. Since the return value
is hardly ever checked this is only a small patch.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-10-08 16:33:34 +02:00
Teresa Gámez 9d50b34845 read_file_2: Fix return value
Set return value correct in error case.
This prevents barebox from crashing in some conditions.

Signed-off-by: Teresa Gámez <t.gamez@phytec.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-09-25 07:44:12 +02:00
Sascha Hauer d3f4aa52ca readline: Fix history prev when history is empty
We cannot use list_entry() on an empty list. Without history
we have to return an empty line. This fixes a crash when the
cursor up button is pressed and no command has been entered
previously. Broken since:

commit ada160a34a
Author: Sascha Hauer <s.hauer@pengutronix.de>
Date:   Tue Jul 29 11:54:26 2014 +0200

    readline: reimplement history functions

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Reported-by: Teresa Gamez <t.gamez@phytec.de>
2014-09-01 14:24:50 +02:00
Sascha Hauer 7782c08047 Merge branch 'for-next/usb-gadget'
Conflicts:
	commands/Makefile
	common/Kconfig
	common/Makefile
	drivers/usb/gadget/dfu.c
2014-08-07 20:34:28 +02:00
Sascha Hauer 9cce00617b Merge branch 'for-next/rtc'
Conflicts:
	arch/mips/dts/jz4755.dtsi
	commands/Makefile
2014-08-07 13:13:45 +02:00
Sascha Hauer 38c3b2455e Merge branch 'for-next/misc'
Conflicts:
	lib/Makefile
2014-08-07 13:13:31 +02:00
Sascha Hauer 5b7b7ee5d9 Merge branch 'for-next/metadata'
Conflicts:
	arch/arm/dts/Makefile
	common/Makefile
	lib/Makefile
2014-08-07 06:15:16 +02:00
Sascha Hauer 28ce918d96 read_file: introduce read_file_2
read_file has some limitations:

- It is not possible to check the error code since read_file returns
  NULL for failure
- It is not possible to limit the buffer size to sensible limits.

This patch introduces read_file_2 which doesn't have these limitations.
read_file becomes a wrapper around read_file_2.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-08-07 06:13:52 +02:00
Sascha Hauer 3cfa4bc00c move file helper functions to separate file
We have our file helper functions in several places. Move them
all to lib/libfile.c.
With this we no longer have file helpers in fs/fs.c which contains
the core fs functions and no functions in lib/libbb.c which are
not from busybox.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-08-07 06:13:51 +02:00
Antony Pavlov 6d3fc76b77 lib: import 'bcd' from linux-3.15
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-07-31 07:30:51 +02:00
Sascha Hauer ada160a34a readline: reimplement history functions
This reimplements the history functions in readline.

- Use regular lists instead of homegrown list implementation
- Allocate history strings dynamically instead of copying strings
  to fixed buffers without checking the size
- saves us an initcall
- slightly smaller
- no longer add duplicates to the history
- when moving past the last history entry print an empty line

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-07-29 13:51:00 +02:00