e2image: Fix potential overflow if the device name is too long

Adapted from SLES's patch: e2fsprogs-strncat.patch

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
This commit is contained in:
Theodore Ts'o 2008-01-27 15:45:30 -05:00
parent c2dbc18a94
commit df200fffd5

View File

@ -126,7 +126,7 @@ static void write_image_file(ext2_filsys fs, int fd)
hdr.magic_number = EXT2_ET_MAGIC_E2IMAGE;
strcpy(hdr.magic_descriptor, "Ext2 Image 1.0");
gethostname(hdr.fs_hostname, sizeof(hdr.fs_hostname));
strncat(hdr.fs_device_name, device_name, sizeof(hdr.fs_device_name));
strncpy(hdr.fs_device_name, device_name, sizeof(hdr.fs_device_name)-1);
hdr.fs_device_name[sizeof(hdr.fs_device_name) - 1] = 0;
hdr.fs_blocksize = fs->blocksize;