components/ipmitool/patches/7126312.patch
branchs11-sru
changeset 2369 dcf1e4110247
equal deleted inserted replaced
2367:aae8cddf5d23 2369:dcf1e4110247
       
     1 --- ipmitool-1.8.10.old/lib/helper.c	Fri Dec 14 12:56:53 2007
       
     2 +++ ipmitool-1.8.10/lib/helper.c	Mon Oct  1 15:17:37 2012
       
     3 @@ -289,19 +289,33 @@
       
     4  {
       
     5  	struct stat st1, st2;
       
     6  	FILE * fp;
       
     7 +	int fd = -1;
       
     8  
       
     9  	/* verify existance */
       
    10 +	errno = 0;
       
    11  	if (lstat(file, &st1) < 0) {
       
    12 -		if (rw) {
       
    13 +		if (rw && (errno == ENOENT)) {
       
    14  			/* does not exist, ok to create */
       
    15 -			fp = fopen(file, "w");
       
    16 -			if (fp == NULL) {
       
    17 +			fd = open(file,
       
    18 +			    O_WRONLY | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR
       
    19 +			    | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
       
    20 +
       
    21 +			if ( fd == -1 ) {
       
    22  				lperror(LOG_ERR, "Unable to open file %s "
       
    23  					"for write", file);
       
    24  				return NULL;
       
    25  			}
       
    26 -			/* created ok, now return the descriptor */
       
    27 -			return fp;
       
    28 +
       
    29 +			fp = fdopen(fd, "w");
       
    30 +			if (fp == NULL) {
       
    31 +				close(fd);
       
    32 +				lperror(LOG_ERR, "Unable to open file %s "
       
    33 +				    "for write", file);
       
    34 +				return NULL;
       
    35 +			} else
       
    36 +				/* created ok, now return the descriptor */
       
    37 +				return fp;
       
    38 +
       
    39  		} else {
       
    40  			lprintf(LOG_ERR, "File %s does not exist", file);
       
    41  			return NULL;
       
    42 @@ -322,7 +336,7 @@
       
    43  
       
    44  	/* it exists - only regular files, not links */
       
    45  	if (S_ISREG(st1.st_mode) == 0) {
       
    46 -		lprintf(LOG_ERR, "File %s has invalid mode: %d",
       
    47 +		lprintf(LOG_ERR, "File %s has invalid mode: %#o",
       
    48  			file, st1.st_mode);
       
    49  		return NULL;
       
    50  	}
       
    51 @@ -347,10 +361,18 @@
       
    52  		return NULL;
       
    53  	}
       
    54  
       
    55 +	/* verify dev */
       
    56 +	if (st1.st_dev != st2.st_dev) {
       
    57 +		lprintf(LOG_ERR, "File %s has invalid dev: %lu != %lu",
       
    58 +			file, (ulong_t)st1.st_dev, (ulong_t)st2.st_dev);
       
    59 +		fclose(fp);
       
    60 +		return NULL;
       
    61 +	}
       
    62 +
       
    63  	/* verify inode */
       
    64  	if (st1.st_ino != st2.st_ino) {
       
    65 -		lprintf(LOG_ERR, "File %s has invalid inode: %d != %d",
       
    66 -			file, st1.st_ino, st2.st_ino);
       
    67 +		lprintf(LOG_ERR, "File %s has invalid inode: %lu != %lu",
       
    68 +			file, (ulong_t)st1.st_ino, (ulong_t)st2.st_ino);
       
    69  		fclose(fp);
       
    70  		return NULL;
       
    71  	}
       
    72 @@ -427,7 +449,6 @@
       
    73  #endif
       
    74  
       
    75  	chdir("/");
       
    76 -	umask(0);
       
    77  
       
    78  	for (fd=0; fd<64; fd++) {
       
    79  		if (fd != intf->fd)