Utils: Change sprintf to snprintf

Using sprintf can cause segmentation fault by exceeding the size of buffer array.

Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
This commit is contained in:
Mateusz Kusiak 2021-08-12 13:48:48 +02:00 committed by Jes Sorensen
parent b8bbf264ee
commit feeb2785e6
1 changed files with 2 additions and 2 deletions

4
util.c
View File

@ -947,12 +947,12 @@ dev_t devnm2devid(char *devnm)
/* First look in /sys/block/$DEVNM/dev for %d:%d
* If that fails, try parsing out a number
*/
char path[100];
char path[PATH_MAX];
char *ep;
int fd;
int mjr,mnr;
sprintf(path, "/sys/block/%s/dev", devnm);
snprintf(path, sizeof(path), "/sys/block/%s/dev", devnm);
fd = open(path, O_RDONLY);
if (fd >= 0) {
char buf[20];