Replaced some large local variables by other means in libisofs/aaip_0_2.c
This commit is contained in:
parent
f08ae22dbe
commit
3ef67cb49d
@ -26,6 +26,7 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include "libisofs.h"
|
#include "libisofs.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#define Aaip_encode_debuG 1
|
#define Aaip_encode_debuG 1
|
||||||
@ -346,21 +347,23 @@ static ssize_t aaip_encode_acl_text(char *acl_text, mode_t st_mode,
|
|||||||
size_t result_size, unsigned char *result, int flag)
|
size_t result_size, unsigned char *result, int flag)
|
||||||
{
|
{
|
||||||
char *rpt, *npt, *cpt;
|
char *rpt, *npt, *cpt;
|
||||||
int qualifier= 0, perms, type, i, qualifier_len= 0, num_recs, needed= 0;
|
int qualifier= 0, perms, type, i, qualifier_len= 0, num_recs, needed= 0, ret;
|
||||||
unsigned int has_u= 0, has_g= 0, has_o= 0, has_m= 0, is_trivial= 1;
|
unsigned int has_u= 0, has_g= 0, has_o= 0, has_m= 0, is_trivial= 1;
|
||||||
uid_t uid, huid;
|
uid_t uid, huid;
|
||||||
gid_t gid, hgid;
|
gid_t gid, hgid;
|
||||||
ssize_t count= 0;
|
ssize_t count= 0;
|
||||||
struct passwd *pwd;
|
struct passwd *pwd;
|
||||||
struct group *grp;
|
struct group *grp;
|
||||||
char name[1024];
|
char *name = NULL;
|
||||||
|
int name_size= 1024;
|
||||||
double num;
|
double num;
|
||||||
|
|
||||||
|
LIBISO_ALLOC_MEM(name, char, name_size);
|
||||||
if(flag & 4) {
|
if(flag & 4) {
|
||||||
/* set SWITCH_MARK to indicate a default ACL */;
|
/* set SWITCH_MARK to indicate a default ACL */;
|
||||||
if(!(flag & 1)) {
|
if(!(flag & 1)) {
|
||||||
if((size_t) count >= result_size)
|
if((size_t) count >= result_size)
|
||||||
return(-1);
|
{ret= -1; goto ex;}
|
||||||
result[count]= (Aaip_SWITCH_MARK << 4) | Aaip_EXEC;
|
result[count]= (Aaip_SWITCH_MARK << 4) | Aaip_EXEC;
|
||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
@ -386,7 +389,7 @@ static ssize_t aaip_encode_acl_text(char *acl_text, mode_t st_mode,
|
|||||||
type= Aaip_ACL_USER_OBJ;
|
type= Aaip_ACL_USER_OBJ;
|
||||||
has_u++;
|
has_u++;
|
||||||
} else {
|
} else {
|
||||||
if(cpt - (rpt + 5) >= (int) sizeof(name))
|
if(cpt - (rpt + 5) >= name_size)
|
||||||
continue;
|
continue;
|
||||||
is_trivial= 0;
|
is_trivial= 0;
|
||||||
strncpy(name, rpt + 5, cpt - (rpt + 5));
|
strncpy(name, rpt + 5, cpt - (rpt + 5));
|
||||||
@ -419,7 +422,7 @@ user_by_name:;
|
|||||||
type= Aaip_ACL_GROUP_OBJ;
|
type= Aaip_ACL_GROUP_OBJ;
|
||||||
has_g++;
|
has_g++;
|
||||||
} else {
|
} else {
|
||||||
if(cpt - (rpt + 6) >= (int) sizeof(name))
|
if(cpt - (rpt + 6) >= name_size)
|
||||||
continue;
|
continue;
|
||||||
is_trivial= 0;
|
is_trivial= 0;
|
||||||
strncpy(name, rpt + 6, cpt - (rpt + 6));
|
strncpy(name, rpt + 6, cpt - (rpt + 6));
|
||||||
@ -462,7 +465,7 @@ group_by_name:;
|
|||||||
|
|
||||||
if(!(flag & 1)) {
|
if(!(flag & 1)) {
|
||||||
if((size_t) count >= result_size)
|
if((size_t) count >= result_size)
|
||||||
return(-1);
|
{ret= -1; goto ex;}
|
||||||
result[count]= perms | ((!!qualifier) << 3) | (type << 4);
|
result[count]= perms | ((!!qualifier) << 3) | (type << 4);
|
||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
@ -471,7 +474,7 @@ group_by_name:;
|
|||||||
num_recs= (qualifier_len / 127) + !!(qualifier_len % 127);
|
num_recs= (qualifier_len / 127) + !!(qualifier_len % 127);
|
||||||
if(!(flag & 1)) {
|
if(!(flag & 1)) {
|
||||||
if((size_t) (count + 1) > result_size)
|
if((size_t) (count + 1) > result_size)
|
||||||
return(-1);
|
{ret= -1; goto ex;}
|
||||||
for(i= 0; i < num_recs; i++) {
|
for(i= 0; i < num_recs; i++) {
|
||||||
if(i < num_recs - 1)
|
if(i < num_recs - 1)
|
||||||
result[count++]= 255;
|
result[count++]= 255;
|
||||||
@ -481,7 +484,7 @@ group_by_name:;
|
|||||||
result[count - 1]= 127;
|
result[count - 1]= 127;
|
||||||
}
|
}
|
||||||
if((size_t) (count + (result[count - 1] & 127)) > result_size)
|
if((size_t) (count + (result[count - 1] & 127)) > result_size)
|
||||||
return(-1);
|
{ret= -1; goto ex;}
|
||||||
memcpy(result + count, name + i * 127, result[count - 1] & 127);
|
memcpy(result + count, name + i * 127, result[count - 1] & 127);
|
||||||
count+= result[count - 1] & 127;
|
count+= result[count - 1] & 127;
|
||||||
}
|
}
|
||||||
@ -496,7 +499,7 @@ group_by_name:;
|
|||||||
count+= needed;
|
count+= needed;
|
||||||
else {
|
else {
|
||||||
if((size_t) (count + needed) > result_size)
|
if((size_t) (count + needed) > result_size)
|
||||||
return(-1);
|
{ret= -1; goto ex;}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((flag & 8) && needed > 0 && !(flag & 1)) {
|
if ((flag & 8) && needed > 0 && !(flag & 1)) {
|
||||||
@ -521,7 +524,10 @@ group_by_name:;
|
|||||||
result[count++]= perms | (Aaip_ACL_MASK << 4);
|
result[count++]= perms | (Aaip_ACL_MASK << 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return(count);
|
ret= count;
|
||||||
|
ex:;
|
||||||
|
LIBISO_FREE_MEM(name);
|
||||||
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2015,14 +2021,15 @@ int aaip_decode_acl(unsigned char *data, size_t num_data, size_t *consumed,
|
|||||||
size_t *acl_text_fill, int flag)
|
size_t *acl_text_fill, int flag)
|
||||||
{
|
{
|
||||||
unsigned char *rpt;
|
unsigned char *rpt;
|
||||||
char perm_text[4], *wpt, name[1024];
|
char perm_text[4], *wpt, *name= NULL;
|
||||||
int type, qualifier= 0, perm, ret, cnt;
|
int type, qualifier= 0, perm, ret, cnt, name_size= 1024;
|
||||||
size_t w_size, name_fill= 0, i;
|
size_t w_size, name_fill= 0, i;
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
gid_t gid;
|
gid_t gid;
|
||||||
struct passwd *pwd;
|
struct passwd *pwd;
|
||||||
struct group *grp;
|
struct group *grp;
|
||||||
|
|
||||||
|
LIBISO_ALLOC_MEM(name, char, name_size);
|
||||||
cnt= flag & 1;
|
cnt= flag & 1;
|
||||||
*consumed= 0;
|
*consumed= 0;
|
||||||
wpt= acl_text;
|
wpt= acl_text;
|
||||||
@ -2040,14 +2047,14 @@ int aaip_decode_acl(unsigned char *data, size_t num_data, size_t *consumed,
|
|||||||
|
|
||||||
type= (*rpt) >> 4;
|
type= (*rpt) >> 4;
|
||||||
if(type == Aaip_FUTURE_VERSION) /* indicate to caller: version mismatch */
|
if(type == Aaip_FUTURE_VERSION) /* indicate to caller: version mismatch */
|
||||||
return(-3);
|
{ret = -3; goto ex;}
|
||||||
|
|
||||||
qualifier= !!((*rpt) & 8);
|
qualifier= !!((*rpt) & 8);
|
||||||
if(qualifier) {
|
if(qualifier) {
|
||||||
ret= aaip_read_qualifier(rpt + 1, num_data - (rpt + 1 - data),
|
ret= aaip_read_qualifier(rpt + 1, num_data - (rpt + 1 - data),
|
||||||
name, sizeof(name), &name_fill, 0);
|
name, name_size, &name_fill, 0);
|
||||||
if(ret <= 0)
|
if(ret <= 0)
|
||||||
return(-1);
|
{ret = -1; goto ex;}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Advance read pointer */
|
/* Advance read pointer */
|
||||||
@ -2088,7 +2095,7 @@ int aaip_decode_acl(unsigned char *data, size_t num_data, size_t *consumed,
|
|||||||
pwd= getpwuid(uid);
|
pwd= getpwuid(uid);
|
||||||
if(pwd == NULL)
|
if(pwd == NULL)
|
||||||
sprintf(name, "%.f", (double) uid);
|
sprintf(name, "%.f", (double) uid);
|
||||||
else if(strlen(pwd->pw_name) >= sizeof(name))
|
else if(strlen(pwd->pw_name) >= (size_t) name_size)
|
||||||
sprintf(name, "%.f", (double) uid);
|
sprintf(name, "%.f", (double) uid);
|
||||||
else
|
else
|
||||||
strcpy(name, pwd->pw_name);
|
strcpy(name, pwd->pw_name);
|
||||||
@ -2102,7 +2109,7 @@ int aaip_decode_acl(unsigned char *data, size_t num_data, size_t *consumed,
|
|||||||
grp= getgrgid(gid);
|
grp= getgrgid(gid);
|
||||||
if(grp == NULL)
|
if(grp == NULL)
|
||||||
sprintf(name, "%.f", (double) gid);
|
sprintf(name, "%.f", (double) gid);
|
||||||
else if(strlen(grp->gr_name) >= sizeof(name))
|
else if(strlen(grp->gr_name) >= (size_t) name_size)
|
||||||
sprintf(name, "%.f", (double) gid);
|
sprintf(name, "%.f", (double) gid);
|
||||||
else
|
else
|
||||||
strcpy(name, grp->gr_name);
|
strcpy(name, grp->gr_name);
|
||||||
@ -2110,15 +2117,16 @@ int aaip_decode_acl(unsigned char *data, size_t num_data, size_t *consumed,
|
|||||||
ret= aaip_write_acl_line(&wpt, &w_size, "group", name, perm_text, cnt);
|
ret= aaip_write_acl_line(&wpt, &w_size, "group", name, perm_text, cnt);
|
||||||
} else {
|
} else {
|
||||||
/* indicate to caller: unknown type */
|
/* indicate to caller: unknown type */
|
||||||
return(-4);
|
{ret = -4; goto ex;}
|
||||||
}
|
}
|
||||||
if(ret <= 0)
|
if(ret <= 0)
|
||||||
return(-2);
|
{ret = -2; goto ex;}
|
||||||
}
|
}
|
||||||
ret= 1;
|
ret= 1;
|
||||||
ex:;
|
ex:;
|
||||||
if(flag & 1)
|
if(flag & 1)
|
||||||
*acl_text_fill= w_size + 1;
|
*acl_text_fill= w_size + 1;
|
||||||
|
LIBISO_FREE_MEM(name);
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user