aboutsummaryrefslogtreecommitdiff
path: root/toys/other/losetup.c
AgeCommit message (Collapse)Author
2019-10-26losetup: Fix memory leaks in loopback_setup()Alessio Balsini
The function loopback_setup() uses xabspath() to get the loopback path. This function allocates dynamic memory which should be freed by the function caller. But there are early return cases where the dynamic memory is not freed. Besides the special cases of perror_exit(), for which the "early" free operation is simply used to silence memory analysis tools, the if (racy && errno == EBUSY) return 1; branch may be a real cause of memory leak. Fix by adding a new free() in the racy+EBUSY branch and anticipating the existing free(). Signed-off-by: Alessio Balsini <balsini@android.com>
2019-10-14losetup: Fix null-termination of src string instead of dest after copyAlessio Balsini
The function loopback_setup(), after copying the loopback device name with xstrncpy(), ensures the null-termination of the string by forcing its last byte to 0. Unfortunately, this operation: - was probably intended to null-terminate dest instead; - does not affect the program execution because src is free()d right after; - if the size of src is smaller than the offset of the written zero, it modifies an unknown byte in the heap. Drop the null-termination line to fix the issue: xstrcpy() automatically null-terminates dest, or fails if the size of src is bigger than the the requested number of bytes to copy. Signed-off-by: Alessio Balsini <balsini@android.com>
2019-08-09losetup: fix the race.Elliott Hughes
There's a race between LOOP_CTL_GET_FREE and LOOP_SET_FD. Work around it by just retrying if we get EBUSY on the LOOP_SET_FD call. This is what similar code in ChromeOS already does. Bug: http://b/135716654
2019-06-26losetup: fix Android.Elliott Hughes
Use /dev/block/loop* more uniformly, and teach the tests which to expect.
2019-06-25losetup: minor fixes.Elliott Hughes
Fix `losetup -f` to not fail with an error. Add the missing \n for `losetup -f --show FILE`. Use decimal for the device number, like the desktop losetup. Switch to the FLAG macro. Make the tests runnable as tests, and expand coverage a bit. With this patch, the tests pass both with and without TEST_HOST on the desktop. Note though that this patch is part of fixing some real-life losetup issues, not part of the "test cleanup" I'm also looking at. losetup is low down that list!
2019-02-23Bumper typo cleanup.Elliott Hughes
Inspired by some of the small patches that have gone by recently. Limited to only things found in `generated/help.h`, plus a wider cleanup for the more common "milisecond" typo.
2019-02-23Switch losetup to short arg var style and force typecasts for printf.Rob Landley
2017-12-02Android has its loop devices under "block" as Elliott says "by reason ofRob Landley
historical accident", so fall back to check there. Also remove an obsolete comment TODO block, check !parent for dirtree top of tree instead of '/' in the filename, and typecast some printf arguments for 32-bit systems.
2016-01-05Add error_msg_raw() and friends, replace error_msg("%s", s) uses, enable formatRob Landley
checking, and fix up format checking complaints. Added out(type, value) function to stat to avoid a zillion printf typecasts.
2015-09-11Replace toys.exithelp with help_exit() in lib.Rob Landley
2015-01-01Switch a lot of strncpy() calls to xstrncpy().Rob Landley
2014-10-09Various bugfixes (mostly resource leaks) from Ashwini Sharma's static ↵Rob Landley
analysis, plus occasional tweak by me while reviewing them.
2014-07-30As long as I had to write xabspath(), no point in wrapping realpath().Rob Landley
2014-05-29Make "losetup /dev/loop0 filename" work.Rob Landley
Sigh. Implement the complex cases and you screw up the simple cases you already tested...
2013-04-14Move guts of help command into show_help() in lib/help.c, with config ↵Rob Landley
TOYBOX_HELP controlling infrastructure.
2013-02-03Some older build environments don't have LOOP_CTL_GET_FREE or ↵Rob Landley
LOOP_SET_CAPACITY. Substitute constants so they can get the rest of losetup without a build break.
2013-01-14Silence deeply stupid gcc warning. (First non-declaration line of function: ↵Rob Landley
if (file) ffd = open(); at end of of function: if (file) close(ffd); "file" is an argument to the function and nothing else assigns to it. gcc warning on that close, "ffd may be used uninitialized!" _HOW_?)
2013-01-02Have error_msg() and friends set TT.exitval to 1 if it's still 0, clean out ↵Rob Landley
other places that were setting it that no longer need to.
2012-12-30Add losetup. (Who knows, it might even work.)Rob Landley