2010-01-18 Joel Sherrill <joel.sherrill@oarcorp.com>

Coverity Id 19
	Coverity Id 20
	Coverity Id 21
	* libfs/src/imfs/imfs_link.c, libfs/src/imfs/imfs_load_tar.c,
	libfs/src/imfs/imfs_mknod.c: Add comment to explain allocation is
	for life of file, not scope of method.
This commit is contained in:
Joel Sherrill
2010-01-18 23:39:31 +00:00
parent 2bac948920
commit 9ba0e55fc4
4 changed files with 51 additions and 29 deletions

View File

@@ -1,3 +1,12 @@
2010-01-18 Joel Sherrill <joel.sherrill@oarcorp.com>
Coverity Id 19
Coverity Id 20
Coverity Id 21
* libfs/src/imfs/imfs_link.c, libfs/src/imfs/imfs_load_tar.c,
libfs/src/imfs/imfs_mknod.c: Add comment to explain allocation is
for life of file, not scope of method.
2010-01-18 Joel Sherrill <joel.sherrill@oarcorp.com> 2010-01-18 Joel Sherrill <joel.sherrill@oarcorp.com>
Coverity Id 12 Coverity Id 12

View File

@@ -5,7 +5,7 @@
* name given in name. The link node is set to point to the node at * name given in name. The link node is set to point to the node at
* to_loc. * to_loc.
* *
* COPYRIGHT (c) 1989-1999. * COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR). * On-Line Applications Research Corporation (OAR).
* *
* The license and distribution terms for this file may be * The license and distribution terms for this file may be
@@ -51,6 +51,10 @@ int IMFS_link(
/* /*
* Create a new link node. * Create a new link node.
*
* NOTE: Coverity thinks this is a resource leak since a node
* is created but never deleted. The scope of the allocation
* is that of a file -- not this method. Coverity Id 19.
*/ */
new_node = IMFS_create_node( new_node = IMFS_create_node(

View File

@@ -1,4 +1,11 @@
/* /*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$ * $Id$
*/ */
@@ -6,13 +13,13 @@
#include "config.h" #include "config.h"
#endif #endif
/************************************************************************** /*
* This file implements the "mount" procedure for tar-based IMFS * This file implements the "mount" procedure for tar-based IMFS
* extensions. The TAR is not actually mounted under the IMFS. * extensions. The TAR is not actually mounted under the IMFS.
* Directories from the TAR file are created as usual in the IMFS. * Directories from the TAR file are created as usual in the IMFS.
* File entries are created as IMFS_LINEAR_FILE nodes with their nods * File entries are created as IMFS_LINEAR_FILE nodes with their nods
* pointing to addresses in the TAR image. * pointing to addresses in the TAR image.
*************************************************************************/ */
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
@@ -26,7 +33,7 @@
#include <rtems/untar.h> #include <rtems/untar.h>
#include <rtems/tar.h> #include <rtems/tar.h>
/************************************************************************** /*
* TAR file format: * TAR file format:
* *
* Offset Length Contents * Offset Length Contents
@@ -54,13 +61,13 @@
* sum = 0; * sum = 0;
* for(i = 0; i < 512; i++) * for(i = 0; i < 512; i++)
* sum += 0xFF & header[i]; * sum += 0xFF & header[i];
*************************************************************************/ */
#define MAX_NAME_FIELD_SIZE 99 #define MAX_NAME_FIELD_SIZE 99
#define MIN(a,b) ((a)>(b)?(b):(a)) #define MIN(a,b) ((a)>(b)?(b):(a))
/************************************************************************** /*
* rtems_tarfs_load * rtems_tarfs_load
* *
* Here we create the mountpoint directory and load the tarfs at * Here we create the mountpoint directory and load the tarfs at
@@ -70,9 +77,8 @@
* needed. * needed.
* - For files, we make our own calls to IMFS eval_for_make and * - For files, we make our own calls to IMFS eval_for_make and
* create_node. * create_node.
*************************************************************************/ */
int int rtems_tarfs_load(
rtems_tarfs_load(
char *mountpoint, char *mountpoint,
uint8_t *tar_image, uint8_t *tar_image,
size_t tar_size size_t tar_size
@@ -98,20 +104,19 @@ rtems_tarfs_load(
return(-1); return(-1);
if (root_loc.ops != &IMFS_ops) if (root_loc.ops != &IMFS_ops)
return(-1); return -1;
/*********************************************************************** /*
* Create an IMFS node structure pointing to tar image memory. * Create an IMFS node structure pointing to tar image memory.
**********************************************************************/ */
offset = 0; offset = 0;
while (1) while (1) {
{
if (offset + 512 > tar_size) if (offset + 512 > tar_size)
break; break;
/****************************************************************** /*
* Read a header. * Read a header.
******************************************************************/ */
hdr_ptr = (char *) &tar_image[offset]; hdr_ptr = (char *) &tar_image[offset];
offset += 512; offset += 512;
if (strncmp(&hdr_ptr[257], "ustar ", 7)) if (strncmp(&hdr_ptr[257], "ustar ", 7))
@@ -128,30 +133,31 @@ rtems_tarfs_load(
if (_rtems_tar_header_checksum(hdr_ptr) != hdr_chksum) if (_rtems_tar_header_checksum(hdr_ptr) != hdr_chksum)
break; break;
/****************************************************************** /*
* Generate an IMFS node depending on the file type. * Generate an IMFS node depending on the file type.
* - For directories, just create directories as usual. IMFS * - For directories, just create directories as usual. IMFS
* will take care of the rest. * will take care of the rest.
* - For files, create a file node with special tarfs properties. * - For files, create a file node with special tarfs properties.
*****************************************************************/ */
if (linkflag == DIRTYPE) if (linkflag == DIRTYPE) {
{
strcpy(full_filename, mountpoint); strcpy(full_filename, mountpoint);
if (full_filename[strlen(full_filename)-1] != '/') if (full_filename[strlen(full_filename)-1] != '/')
strcat(full_filename, "/"); strcat(full_filename, "/");
strcat(full_filename, filename); strcat(full_filename, filename);
mkdir(full_filename, S_IRWXU | S_IRWXG | S_IRWXO); mkdir(full_filename, S_IRWXU | S_IRWXG | S_IRWXO);
} }
/****************************************************************** /*
* Create a LINEAR_FILE node * Create a LINEAR_FILE node
*****************************************************************/ *
else if (linkflag == REGTYPE) * NOTE: Coverity thinks this is a resource leak since a node
{ * is created but never deleted. The scope of the allocation
* is that of a file -- not this method. Coverity Id 20.
*/
else if (linkflag == REGTYPE) {
const char *name; const char *name;
loc = root_loc; loc = root_loc;
if (IMFS_evaluate_for_make(filename, &loc, &name) == 0) if (IMFS_evaluate_for_make(filename, &loc, &name) == 0) {
{
node = IMFS_create_node(&loc, node = IMFS_create_node(&loc,
IMFS_LINEAR_FILE, (char *)name, IMFS_LINEAR_FILE, (char *)name,
(file_mode & (S_IRWXU | S_IRWXG | S_IRWXO)) | S_IFREG, (file_mode & (S_IRWXU | S_IRWXG | S_IRWXO)) | S_IFREG,
@@ -165,6 +171,6 @@ rtems_tarfs_load(
} }
} }
return(status); return status;
} }

View File

@@ -3,7 +3,7 @@
* *
* Routine to create a node in the IMFS file system. * Routine to create a node in the IMFS file system.
* *
* COPYRIGHT (c) 1989-1999. * COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR). * On-Line Applications Research Corporation (OAR).
* *
* The license and distribution terms for this file may be * The license and distribution terms for this file may be
@@ -63,8 +63,11 @@ int IMFS_mknod(
/* /*
* Allocate and fill in an IMFS jnode * Allocate and fill in an IMFS jnode
*
* NOTE: Coverity thinks this is a resource leak since a node
* is created but never deleted. The scope of the allocation
* is that of a file -- not this method. Coverity Id 21.
*/ */
new_node = IMFS_create_node( new_node = IMFS_create_node(
pathloc, pathloc,
type, type,