[Pvfs2-cvs] commit by nlmills in pvfs2/src/apps/admin: pvfs2-xattr.c
CVS commit program
cvs at parl.clemson.edu
Tue Dec 14 15:39:55 EST 2010
Update of /projects/cvsroot/pvfs2/src/apps/admin
In directory parlweb1:/tmp/cvs-serv2385/src/apps/admin
Modified Files:
Tag: cu-security-branch
pvfs2-xattr.c
Log Message:
fixed some string comparison bugs (orange trac #13)
Index: pvfs2-xattr.c
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/apps/admin/pvfs2-xattr.c,v
diff -p -u -r1.6.8.10 -r1.6.8.11
--- pvfs2-xattr.c 22 Nov 2010 23:51:29 -0000 1.6.8.10
+++ pvfs2-xattr.c 14 Dec 2010 20:39:55 -0000 1.6.8.11
@@ -153,7 +153,9 @@ int main(int argc, char **argv)
, (char *) user_opts->key[0].buffer);
return -1;
}
- if (strncmp(user_opts->key[0].buffer,"user.pvfs2.meta_hint",20) == 0)
+ if (strncmp(user_opts->key[0].buffer
+ ,"user.pvfs2.meta_hint"
+ ,user_opts->key[0].buffer_sz) == 0)
{
tmp_val.buffer=¤t_meta_hint.flags;
tmp_val.buffer_sz=sizeof(current_meta_hint.flags);
@@ -179,9 +181,8 @@ int main(int argc, char **argv)
}
if (modify_val(&user_opts->key[0], &user_opts->val[0]) < 0)
{
- fprintf(stderr, "Invalid value for user-settable attribute %s, %s\n"
- , (char *) user_opts->key[0].buffer
- , (char *) user_opts->val[0].buffer);
+ fprintf(stderr, "Invalid value for user-settable attribute %s\n"
+ , (char *) user_opts->key[0].buffer);
return -1;
}
}
@@ -206,7 +207,7 @@ int main(int argc, char **argv)
{
if (strncmp(user_opts->key[0].buffer
,"user.pvfs2.meta_hint"
- ,SPECIAL_METAFILE_HINT_KEYLEN) == 0) {
+ ,user_opts->key[0].buffer_sz) == 0) {
PVFS_metafile_hint *hint =
(PVFS_metafile_hint *) user_opts->val[0].buffer;
printf("Metafile Hints (0X%08X)",(unsigned int)hint->flags);
@@ -225,7 +226,7 @@ int main(int argc, char **argv)
printf("\n");
} else if ( strncmp(user_opts->key[0].buffer
,"user.pvfs2.mirror.handles"
- ,sizeof("user.pvfs2.mirror.handles")) == 0)
+ ,user_opts->key[0].buffer_sz) == 0)
{
PVFS_handle *myHandles = (PVFS_handle *)user_opts->val[0].buffer;
int copies = *(int *)user_opts->val[1].buffer;
@@ -236,13 +237,13 @@ int main(int argc, char **argv)
}
} else if ( strncmp(user_opts->key[0].buffer
,"user.pvfs2.mirror.copies"
- ,sizeof("user.pvfs2.mirror.copies")) == 0)
+ ,user_opts->key[0].buffer_sz) == 0)
{
int *myCopies = (int *)user_opts->val[0].buffer;
printf("Number of Mirrored Copies : %d\n",*myCopies);
} else if ( strncmp(user_opts->key[0].buffer
,"user.pvfs2.mirror.status"
- ,sizeof("user.pvfs2.mirror.status")) == 0)
+ ,user_opts->key[0].buffer_sz) == 0)
{
int copies = *(int *)user_opts->val[1].buffer;
int dfile_count = src.u.pvfs2.attr.dfile_count;
@@ -254,7 +255,7 @@ int main(int argc, char **argv)
,llu(status[i]));
} else if ( strncmp(user_opts->key[0].buffer
,"user.pvfs2.mirror.mode"
- , sizeof("user.pvfs2.mirror.mode")) == 0)
+ ,user_opts->key[0].buffer_sz) == 0)
{
printf("Mirroring Mode : ");
switch(*(MIRROR_MODE *)user_opts->val[0].buffer)
@@ -292,59 +293,59 @@ static int modify_val(PVFS_ds_keyval *ke
*turned on and off with the pvfs2-setmattr and setmattr commands.
*/
if (strncmp(key_p->buffer,"user.pvfs2.meta_hint"
- , SPECIAL_METAFILE_HINT_KEYLEN) == 0)
+ ,key_p->buffer_sz) == 0)
{
- if (strncmp(val_p->buffer, "+immutable", 10) == 0)
+ if (strncmp(val_p->buffer, "+immutable", val_p->buffer_sz) == 0)
{
current_meta_hint.flags |= PVFS_IMMUTABLE_FL;
printf("Adding immutable to meta_hint...(0X%08X)\n"
,(unsigned int)current_meta_hint.flags);
}
- else if (strncmp(val_p->buffer, "-immutable", 10) == 0)
+ else if (strncmp(val_p->buffer, "-immutable", val_p->buffer_sz) == 0)
{
current_meta_hint.flags &= ~PVFS_IMMUTABLE_FL;
printf("Removing immutable from meta_hint...(0X%08X)\n"
,(unsigned int)current_meta_hint.flags);
}
- else if (strncmp(val_p->buffer,"=immutable",10) == 0)
+ else if (strncmp(val_p->buffer,"=immutable", val_p->buffer_sz) == 0)
{
current_meta_hint.flags =
(current_meta_hint.flags & ~ALL_FS_META_HINT_FLAGS) | PVFS_IMMUTABLE_FL;
printf("Setting meta_hint to immutable only (0X%08X)\n"
,(unsigned int)current_meta_hint.flags);
}
- else if (strncmp(val_p->buffer, "+append", 7) == 0)
+ else if (strncmp(val_p->buffer, "+append", val_p->buffer_sz) == 0)
{
current_meta_hint.flags |= PVFS_APPEND_FL;
printf("Adding append to meta_hint...(0X%08X)\n"
,(unsigned int)current_meta_hint.flags);
}
- else if (strncmp(val_p->buffer, "-append", 7) == 0)
+ else if (strncmp(val_p->buffer, "-append", val_p->buffer_sz) == 0)
{
current_meta_hint.flags &= ~PVFS_APPEND_FL;
printf("Removing append from meta_hint...(0X%08X)\n"
,(unsigned int)current_meta_hint.flags);
}
- else if (strncmp(val_p->buffer,"=append",7) == 0)
+ else if (strncmp(val_p->buffer,"=append", val_p->buffer_sz) == 0)
{
current_meta_hint.flags =
(current_meta_hint.flags & ~ALL_FS_META_HINT_FLAGS) | PVFS_APPEND_FL;
printf("Setting meta_hint to append only (0X%08X)\n"
,(unsigned int)current_meta_hint.flags);
}
- else if (strncmp(val_p->buffer, "+noatime", 8) == 0)
+ else if (strncmp(val_p->buffer, "+noatime", val_p->buffer_sz) == 0)
{
current_meta_hint.flags |= PVFS_NOATIME_FL;
printf("Adding noatime to meta_hint...(0X%08X)\n"
,(unsigned int)current_meta_hint.flags);
}
- else if (strncmp(val_p->buffer, "-noatime", 8) == 0)
+ else if (strncmp(val_p->buffer, "-noatime", val_p->buffer_sz) == 0)
{
current_meta_hint.flags &= ~PVFS_NOATIME_FL;
printf("Removing atime from meta_hint...(0X%08X)\n"
,(unsigned int)current_meta_hint.flags);
}
- else if (strncmp(val_p->buffer,"=noatime",8) == 0)
+ else if (strncmp(val_p->buffer,"=noatime", val_p->buffer_sz) == 0)
{
current_meta_hint.flags =
(current_meta_hint.flags & ~ALL_FS_META_HINT_FLAGS) | PVFS_NOATIME_FL;
@@ -358,11 +359,11 @@ static int modify_val(PVFS_ds_keyval *ke
memcpy(val_p->buffer, ¤t_meta_hint.flags, sizeof(current_meta_hint.flags));
val_p->buffer_sz = sizeof(current_meta_hint.flags);
} else if (strncmp(key_p->buffer,"user.pvfs2.mirror.mode"
- ,sizeof("user.pvfs2.mirror.mode")) == 0)
+ ,key_p->buffer_sz) == 0)
{
printf("Setting mirror mode to %d\n",*(int *)val_p->buffer);
} else if (strncmp(key_p->buffer,"user.pvfs2.mirror.copies"
- ,sizeof("user.pvfs2.mirror.mode")) == 0)
+ ,key_p->buffer_sz) == 0)
{
printf("Setting number of mirrored copies to %d\n"
,*(int *)val_p->buffer);
@@ -520,7 +521,7 @@ static struct options* parse_args(int ar
tmp_opts->get = 1;
/* look at command line arguments */
- while((one_opt = getopt(argc, argv, flags)) != EOF)
+ while((one_opt = getopt(argc, argv, flags)) != -1)
{
switch(one_opt){
case 't':
@@ -536,10 +537,10 @@ static struct options* parse_args(int ar
case 'v':
if (strncmp(tmp_opts->key[0].buffer
,"user.pvfs2.mirror.mode"
- ,sizeof("user.pvfs2.mirror.mode")) == 0 ||
+ ,tmp_opts->key[0].buffer_sz) == 0 ||
strncmp(tmp_opts->key[0].buffer
,"user.pvfs2.mirror.copies"
- ,sizeof("user.pvfs2.mirror.copies")) == 0)
+ ,tmp_opts->key[0].buffer_sz) == 0)
{ /*convert string argument into numeric argument*/
tmp_opts->val[0].buffer = malloc(sizeof(int));
if (!tmp_opts->val[0].buffer)
@@ -565,10 +566,13 @@ static struct options* parse_args(int ar
/*ensure that the given mode is supported by PVFS*/
if (!tmp_opts->get &&
- strcmp(tmp_opts->key[0].buffer,"user.pvfs2.mirror.mode") == 0)
- {
- if (*(int *)tmp_opts->val[0].buffer < BEGIN_MIRROR_MODE ||
- *(int *)tmp_opts->val[0].buffer > END_MIRROR_MODE )
+ strncmp(tmp_opts->key[0].buffer
+ ,"user.pvfs2.mirror.mode"
+ ,tmp_opts->key[0].buffer_sz) == 0)
+ {
+ if (tmp_opts->val[0].buffer &&
+ (*(int *)tmp_opts->val[0].buffer < BEGIN_MIRROR_MODE ||
+ *(int *)tmp_opts->val[0].buffer > END_MIRROR_MODE) )
{
fprintf(stderr,"Invalid Mirror Mode ==> %d\n"
"\tValid Modes\n"
@@ -586,8 +590,12 @@ static struct options* parse_args(int ar
/*if user wants mirror.handles or mirror.status, then we must also */
/*retrieve the number of copies, so we know how to display the */
/*information properly. */
- if (strcmp(tmp_opts->key[0].buffer,"user.pvfs2.mirror.handles") == 0 ||
- strcmp(tmp_opts->key[0].buffer,"user.pvfs2.mirror.status") == 0 )
+ if (strncmp(tmp_opts->key[0].buffer
+ ,"user.pvfs2.mirror.handles"
+ ,tmp_opts->key[0].buffer_sz) == 0 ||
+ strncmp(tmp_opts->key[0].buffer
+ ,"user.pvfs2.mirror.status"
+ ,tmp_opts->key[0].buffer_sz) == 0 )
{
tmp_opts->key_count = 2;
PVFS_ds_keyval *myKeys = malloc(tmp_opts->key_count *
@@ -597,8 +605,7 @@ static struct options* parse_args(int ar
fprintf(stderr,"Unable to allocate myKeys.\n");
exit(EXIT_FAILURE);
}
- memset(myKeys,0,sizeof(tmp_opts->key_count *
- sizeof(PVFS_ds_keyval)));
+ memset(myKeys,0,tmp_opts->key_count*sizeof(PVFS_ds_keyval));
myKeys[0] = *tmp_opts->key;
myKeys[1].buffer = strdup("user.pvfs2.mirror.copies");
myKeys[1].buffer_sz = sizeof("user.pvfs2.mirror.copies");
@@ -625,8 +632,7 @@ static struct options* parse_args(int ar
fprintf(stderr,"Unable to allocate myVals.\n");
exit(EXIT_FAILURE);
}
- memset(myVals,0,sizeof(tmp_opts->key_count *
- sizeof(PVFS_ds_keyval)));
+ memset(myVals,0,tmp_opts->key_count*sizeof(PVFS_ds_keyval));
myVals[0] = *tmp_opts->val;
free(tmp_opts->val);
More information about the Pvfs2-cvs
mailing list