[Bug 190735] truncate(1) integer overflow issues with size command line arg -- diff with unit tests attached

bz-noreply at freebsd.org bz-noreply at freebsd.org
Sat Jun 7 22:37:01 UTC 2014


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=190735

--- Comment #2 from Kirk Russell <bugmeister at ba23.org> ---
Jilles, thanks for looking!

I have removed the new undocumented -D option and stopped using the macro from
<inttypes.h>.  I like your idea of using ktrace but I will want to research
that idea before including that in a diff -- I will remove this ktrace/-D stuff
from the patch -- I hope that is okay.  I will attach a new patch to this bug,
with the new changes.  

You can clarify your comment the expectations of off_t being OFF_MAX?  My idea
is the truncate utility needs to indicate an error if OFF_MAX < size < OFF_MIN.
 The function humanize_number() will allow numbers out-of-range for off_t and
we should tell the user as soon as possible about this conversion problem.  
What the OS does with an large off_t passed to truncate() is the OS's business.
 For example, it is possible to create a huge sparse file in ZFS.  I am not
sure what this sparse file is useful for, but it is nice to see that ls -h
works.

# printf "%d\n" 0x7fffffffffffffff
9223372036854775807
# /usr/obj/usr/src/usr.bin/truncate/truncate -s 9223372036854775807 sparse.txt
# ls -l sparse.txt 
-rw-r--r--  1 root  wheel  9223372036854775807 Jun  7 18:30 sparse.txt
# ls -lh sparse.txt 
-rw-r--r--  1 root  wheel   8.0E Jun  7 18:33 sparse.txt

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the freebsd-bugs mailing list