diff options
author | Darrick J. Wong <darrick.wong@oracle.com> | 2019-04-26 15:44:21 -0500 |
---|---|---|
committer | Eric Sandeen <sandeen@redhat.com> | 2019-04-26 15:44:21 -0500 |
commit | 7f0d0b55f2c60bf46b9a1ecfa77f5f83d1cf17fa (patch) | |
tree | cddfa4659ec98f71f919a555db7b6c2bb04368d4 /quota | |
parent | 3d16890ebcfaf33b95ec2a64f5e412c9ec68f4c3 (diff) | |
download | xfsprogs-dev-7f0d0b55f2c60bf46b9a1ecfa77f5f83d1cf17fa.tar.gz |
misc: fix strncpy length complaints
Fix a number of complaints about feeding sizeof(dest) directly to
strncpy. We do this by feeding strncpy the length of the buffer minus
one, having checked that the allocated space are long enough.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Bill O'Donnell <billodo@redhat.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
Diffstat (limited to 'quota')
-rw-r--r-- | quota/edit.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/quota/edit.c b/quota/edit.c index b10a5b34d3..f9938b8acb 100644 --- a/quota/edit.c +++ b/quota/edit.c @@ -368,8 +368,7 @@ restore_file( uint type) { char buffer[512]; - char devbuffer[512]; - char *dev = NULL; + char dev[512]; uint mask; int cnt; uint32_t id; @@ -377,7 +376,11 @@ restore_file( while (fgets(buffer, sizeof(buffer), fp) != NULL) { if (strncmp("fs = ", buffer, 5) == 0) { - dev = strncpy(devbuffer, buffer+5, sizeof(devbuffer)); + /* + * Copy the device name to dev, strip off the trailing + * newline, and move on to the next line. + */ + strncpy(dev, buffer + 5, sizeof(dev) - 1); dev[strlen(dev) - 1] = '\0'; continue; } |