]> git.apps.os.sepia.ceph.com Git - ceph.git/commit
blkdev: using strncpy instead of strcpy. 2978/head
authorJianpeng Ma <jianpeng.ma@intel.com>
Fri, 21 Nov 2014 01:55:02 +0000 (09:55 +0800)
committerJianpeng Ma <jianpeng.ma@intel.com>
Fri, 21 Nov 2014 01:55:02 +0000 (09:55 +0800)
commit6c7bb8c068c975fd91843897a620000f6fddc8e4
treef2f0b5ee3401c0d3ed20151f72c93bd6a0e3c775
parentcb001e7a6bebdf03a26116c555ae8dd897cbf647
blkdev: using strncpy instead of strcpy.

Coverity Scan reported this bug:
> New defect(s) Reported-by: Coverity Scan Showing 1 of 1 defect(s)
> *** CID 1255369:  Copy into fixed size buffer  (STRING_OVERFLOW)
> /common/blkdev.cc: 34 in block_device_support_discard(const char *)()
> 28     bool block_device_support_discard(const char *devname)
> 29     {
> 30       bool can_trim = false;
> 31       char *p = strstr((char *)devname, "sd");
> 32       char name[32] = {0};
> 33
> >>>     CID 1255369:  Copy into fixed size buffer  (STRING_OVERFLOW)
> >>>     You might overrun the 32 byte fixed-size string "name" by
> >>>     copying "p" without checking the length.
> 34       strcpy(name, p);
> 35       for (unsigned int i = 0; i < strlen(name); i++) {
> 36         if(isdigit(name[i])) {
> 37           name[i] = 0;
> 38           break;
> 39         }
>

Signed-off-by: Jianpeng Ma <jianpeng.ma@intel.com>
src/common/blkdev.cc