]> www.infradead.org Git - users/hch/nvme-cli.git/commit
Fix potential device string truncation
authorTony Asleson <tasleson@redhat.com>
Wed, 17 May 2017 19:59:01 +0000 (14:59 -0500)
committerTony Asleson <tasleson@redhat.com>
Wed, 17 May 2017 20:05:46 +0000 (15:05 -0500)
commit868d3cc750e038552cad6c16231cfee157c95eb8
tree2c843419287977041ab249638f306351f55cf28f
parent4b5b4d25889814c5eb24ba530eff8e8828f2a817
Fix potential device string truncation

While compiling using gcc 7.1.1 I ran into compile errors, eg.

nvme.c: In function ‘scan_dev_filter.part.5’:
nvme.c:797:35: error: ‘%s’ directive output may be truncated writing " \
   "up to 255 bytes into a region of size 251 [-Werror=format-truncation=]
   snprintf(path, sizeof(path), "%s%s", dev, d->d_name);

This is caused because the buffer on the stack is only 256 bytes and the
dirent.d_name is 256 and the constant string is "/dev/", so  256 + 5,
but I've rounded up to nearest 4/8 byte alignment of 264.

Signed-off-by: Tony Asleson <tasleson@redhat.com>
huawei-nvme.c
nvme.c