FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Cluster Development

 
 
LinkBack Thread Tools
 
Old 11-23-2011, 09:15 AM
"Fabio M. Di Nitto"
 
Default qdiskd: fix possible resource leak in scandisk

Spotted by Coverity Scan

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
---
:100644 100644 477b8de... b99a672... M cman/qdisk/scandisk.c
cman/qdisk/scandisk.c | 12 ++++++++----
1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/cman/qdisk/scandisk.c b/cman/qdisk/scandisk.c
index 477b8de..b99a672 100644
--- a/cman/qdisk/scandisk.c
+++ b/cman/qdisk/scandisk.c
@@ -252,11 +252,12 @@ static int scanprocpart(struct devlisthead *devlisthead)
unsigned long long blkcnt;
char device[128];
struct devnode *startnode;
+
fp = fopen("/proc/partitions", "r");
if (!fp)
return 0;
- while (fgets(line, sizeof(line), fp)
- != NULL) {
+
+ while (fgets(line, sizeof(line) - 1, fp) != NULL) {

if (strlen(line) > 128 + (22))
continue;
@@ -270,16 +271,19 @@ static int scanprocpart(struct devlisthead *devlisthead)
*/
if (!strlen(device))
continue;
+
startnode =
find_dev_by_majmin(devlisthead->devnode, major, minor);
if (!startnode) {
startnode = alloc_list_obj(devlisthead, major, minor);
- if (!startnode)
+ if (!startnode) {
+ fclose(fp);
return -2;
+ }
}

startnode->procpart = 1;
- strcpy(startnode->procname, device);
+ strncpy(startnode->procname, device, sizeof(startnode->procname) - 1);
}

fclose(fp);
--
1.7.4.4
 
Old 11-29-2011, 05:04 PM
Lon Hohberger
 
Default qdiskd: fix possible resource leak in scandisk

On 11/23/2011 05:15 AM, Fabio M. Di Nitto wrote:

Spotted by Coverity Scan




- while (fgets(line, sizeof(line), fp)
- != NULL) {
+
+ while (fgets(line, sizeof(line) - 1, fp) != NULL) {


fgets takes at most size-1, this isn't needed

-- Lon
 

Thread Tools




All times are GMT. The time now is 11:02 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org