Refactored error handling while encoding AAIP information.
Again Coverity CID 12564.
This commit is contained in:
parent
b3a183fceb
commit
79e6312397
@ -7,7 +7,7 @@
|
||||
See libisofs/aaip_0_2.h
|
||||
http://libburnia-project.org/wiki/AAIP
|
||||
|
||||
Copyright (c) 2009 - 2014 Thomas Schmitt, libburnia project, GPLv2+
|
||||
Copyright (c) 2009 - 2015 Thomas Schmitt, libburnia project, GPLv2+
|
||||
|
||||
*/
|
||||
|
||||
@ -88,26 +88,30 @@ static int aaip_encode_pair(char *name, size_t attr_length, char *attr,
|
||||
no longer needed
|
||||
@param flag Bitfield for control purposes
|
||||
bit0= set CONTINUE bit of last AAIP field to 1
|
||||
@return >0 is the number of SUSP fields generated,
|
||||
0 means error
|
||||
@return >= 0 is the number of SUSP fields generated,
|
||||
< 0 means error
|
||||
*/
|
||||
size_t aaip_encode(size_t num_attrs, char **names,
|
||||
ssize_t aaip_encode(size_t num_attrs, char **names,
|
||||
size_t *value_lengths, char **values,
|
||||
size_t *result_len, unsigned char **result, int flag)
|
||||
{
|
||||
size_t mem_size= 0, comp_size, ret;
|
||||
size_t mem_size= 0, comp_size;
|
||||
ssize_t ret;
|
||||
unsigned int number_of_fields, i, num_recs;
|
||||
|
||||
/* Predict memory needs, number of SUSP fields and component records */
|
||||
*result = NULL;
|
||||
*result_len= 0;
|
||||
for(i= 0; i < num_attrs; i++) {
|
||||
ret= aaip_encode_pair(names[i], value_lengths[i], values[i],
|
||||
&num_recs, &comp_size, NULL, (size_t) 0, 1);
|
||||
if(ret <= 0)
|
||||
if(ret < 0)
|
||||
return(ret);
|
||||
mem_size+= comp_size;
|
||||
}
|
||||
number_of_fields= mem_size / 250 + !!(mem_size % 250);
|
||||
if(number_of_fields == 0)
|
||||
return(0);
|
||||
mem_size+= number_of_fields * 5;
|
||||
|
||||
#ifdef Aaip_encode_debuG
|
||||
@ -118,14 +122,18 @@ size_t aaip_encode(size_t num_attrs, char **names,
|
||||
#endif
|
||||
|
||||
if(*result == NULL)
|
||||
return 0;
|
||||
return ISO_OUT_OF_MEM;
|
||||
|
||||
/* Encode pairs into result */
|
||||
for(i= 0; i < num_attrs; i++) {
|
||||
ret= aaip_encode_pair(names[i], value_lengths[i], values[i],
|
||||
&num_recs, &comp_size, *result, *result_len, 0);
|
||||
if(ret <= 0)
|
||||
if(ret < 0) {
|
||||
free(*result);
|
||||
*result = NULL;
|
||||
*result_len = 0;
|
||||
return(ret);
|
||||
}
|
||||
(*result_len)+= comp_size;
|
||||
}
|
||||
|
||||
|
@ -30,10 +30,10 @@
|
||||
no longer needed
|
||||
@param flag Bitfield for control purposes
|
||||
bit0= set CONTINUE bit of last AAIP field to 1
|
||||
@return >0 is the number of SUSP fields generated,
|
||||
0 means error
|
||||
@return >= 0 is the number of SUSP fields generated,
|
||||
< 0 means error
|
||||
*/
|
||||
size_t aaip_encode(size_t num_attrs, char **names,
|
||||
ssize_t aaip_encode(size_t num_attrs, char **names,
|
||||
size_t *value_lengths, char **values,
|
||||
size_t *result_len, unsigned char **result, int flag);
|
||||
|
||||
|
@ -500,7 +500,8 @@ static
|
||||
int lfs_get_aa_string(IsoFileSource *src, unsigned char **aa_string, int flag)
|
||||
{
|
||||
int ret;
|
||||
size_t num_attrs = 0, *value_lengths = NULL, result_len, sret;
|
||||
size_t num_attrs = 0, *value_lengths = NULL, result_len;
|
||||
ssize_t sret;
|
||||
char *path = NULL, **names = NULL, **values = NULL;
|
||||
unsigned char *result = NULL;
|
||||
|
||||
@ -533,8 +534,8 @@ int lfs_get_aa_string(IsoFileSource *src, unsigned char **aa_string, int flag)
|
||||
else {
|
||||
sret = aaip_encode(num_attrs, names,
|
||||
value_lengths, values, &result_len, &result, 0);
|
||||
if (sret == 0) {
|
||||
ret = ISO_OUT_OF_MEM;
|
||||
if (sret < 0) {
|
||||
ret = sret;
|
||||
goto ex;
|
||||
}
|
||||
}
|
||||
|
@ -1959,7 +1959,8 @@ int iso_node_set_attrs(IsoNode *node, size_t num_attrs, char **names,
|
||||
size_t *value_lengths, char **values, int flag)
|
||||
{
|
||||
int ret, acl_saved = 0;
|
||||
size_t sret, result_len, m_num = 0, *m_value_lengths = NULL, i;
|
||||
ssize_t sret;
|
||||
size_t result_len, m_num = 0, *m_value_lengths = NULL, i;
|
||||
unsigned char *result = NULL;
|
||||
char *a_acl = NULL, *d_acl = NULL, **m_names = NULL, **m_values = NULL;
|
||||
|
||||
@ -1999,8 +2000,8 @@ int iso_node_set_attrs(IsoNode *node, size_t num_attrs, char **names,
|
||||
}
|
||||
sret = aaip_encode(num_attrs, names, value_lengths, values,
|
||||
&result_len, &result, 0);
|
||||
if (sret == 0) {
|
||||
ret = ISO_OUT_OF_MEM;
|
||||
if (sret < 0) {
|
||||
ret = sret;
|
||||
goto ex;
|
||||
}
|
||||
|
||||
@ -2010,12 +2011,14 @@ int iso_node_set_attrs(IsoNode *node, size_t num_attrs, char **names,
|
||||
free(result);
|
||||
goto ex;
|
||||
}
|
||||
if (sret > 0) {
|
||||
ret = iso_node_add_xinfo(node, aaip_xinfo_func, result);
|
||||
if (ret < 0)
|
||||
goto ex;
|
||||
if (ret == 0) {
|
||||
|
||||
/* >>> something is messed up with xinfo: an aa_string still exists */;
|
||||
/* >>> something is messed up with xinfo:
|
||||
an aa_string still exists */;
|
||||
|
||||
ret = ISO_ERROR;
|
||||
goto ex;
|
||||
@ -2025,6 +2028,7 @@ int iso_node_set_attrs(IsoNode *node, size_t num_attrs, char **names,
|
||||
if (ret < 0)
|
||||
goto ex;
|
||||
}
|
||||
}
|
||||
ret = 1;
|
||||
ex:;
|
||||
/* Dispose eventual merged list */
|
||||
|
Loading…
Reference in New Issue
Block a user