1
1

Use secure version of strncpy and srtncat. Release the temporary

resources on error.

This commit was SVN r16124.
Этот коммит содержится в:
George Bosilca 2007-09-14 02:04:34 +00:00
родитель 61989cc4d4
Коммит 41ed50f901
2 изменённых файлов: 12 добавлений и 9 удалений

Просмотреть файл

@ -294,8 +294,8 @@ static int save_filename(const char *filename, lt_ptr data)
prefix = (char*)malloc(len);
snprintf(prefix, len, component_template, params->type);
prefix_len = strlen(prefix);
if (NULL != params->name) {
strcat(prefix, params->name);
if (0 < strlen(params->name)) {
strncat(prefix, params->name, len - prefix_len);
}
total_len = strlen(prefix);
@ -315,12 +315,14 @@ static int save_filename(const char *filename, lt_ptr data)
component_file = OBJ_NEW(component_file_item_t);
if (NULL == component_file) {
free(prefix);
return OPAL_ERR_OUT_OF_RESOURCE;
}
strcpy(component_file->type, params->type);
strcpy(component_file->name, basename + prefix_len);
strcpy(component_file->basename, basename);
strcpy(component_file->filename, filename);
strncpy(component_file->type, params->type, MCA_BASE_MAX_TYPE_NAME_LEN);
strncpy(component_file->name, basename + prefix_len,
MCA_BASE_MAX_COMPONENT_NAME_LEN);
strncpy(component_file->basename, basename, OMPI_PATH_MAX);
strncpy(component_file->filename, filename, OMPI_PATH_MAX);
component_file->status = UNVISITED;
opal_list_append(&found_files, (opal_list_item_t *) component_file);
@ -586,6 +588,7 @@ static int check_dependency(char *line, component_file_item_t *target_file,
bool happiness;
char buffer[BUFSIZ];
char *type, *name;
int len;
component_file_item_t *mitem;
dependency_item_t *ditem;
opal_list_item_t *cur;
@ -607,7 +610,8 @@ static int check_dependency(char *line, component_file_item_t *target_file,
return OPAL_ERR_OUT_OF_RESOURCE;
}
snprintf(buffer, BUFSIZ, component_template, type);
strcat(buffer, name);
len = strlen(buffer);
strncat(buffer, name, BUFSIZ - len);
/* Traverse down the list of files that we have, and see if we can
find it */

Просмотреть файл

@ -153,7 +153,7 @@ int mca_base_component_repository_retain(char *type,
/* Initialize the repository item */
strcpy(ri->ri_type, type);
strncpy(ri->ri_type, type, MCA_BASE_MAX_TYPE_NAME_LEN);
ri->ri_dlhandle = component_handle;
ri->ri_component_struct = component_struct;
@ -371,7 +371,6 @@ static void ri_destructor(opal_object_t *obj)
opal_list_item_t *item;
/* Close the component (and potentially unload it from memory */
lt_dlclose(ri->ri_dlhandle);
/* It should be obvious, but I'll state it anyway because it bit me