Skip to contentSkip to conversation

xfstests: fix up fs_perms test used by 126

PATCH Superseded Eric Sandeen 2 participants 5 messages Feb 5, 2010 – Feb 9, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfstests: fix up fs_perms test used by 126

Test 126 was failing intermittently for Ted & I; it seems that this is because we were passing an unterminated string to fopen for the mode; I'm not certain why this made it fail, but it's pretty clearly not a good thing to do, and fixing it fixes the test.

Rather than passing around characters, do things string-wise, since that is what is ultimately used in fopen().

Also make it at least possible to pass in the 2-character modes fopen can take (r+, w+, etc), I suppose testcases could be added for this later.

---

src/fs_perms.c +6 -7
index 2c5e3fa..f34c4f4 100644
@@ -42,7 +42,7 @@ int testsetup(mode_t mode, int cuserId, int cgroupId);
 int testfperm(int userId, int groupId, char* fperm);
 
 int main( int argc, char *argv[]) {
-   char fperm[1];
+   char fperm[3];
    int result, exresult=0,  cuserId=0, cgroupId=0, userId=0, groupId=0;
    mode_t mode;
 
@@ -53,7 +53,8 @@ int main( int argc, char *argv[]) {
               cgroupId = atoi(argv[3]);
               userId = atoi(argv[4]);
               groupId = atoi(argv[5]);
-              fperm[0] = *argv[6];
+              strncpy(fperm, argv[6], 3);
+              fperm[2] = '\0';
               exresult = atoi(argv[7]);
 	      break;
       default:
@@ -64,7 +65,7 @@ int main( int argc, char *argv[]) {
    testsetup(mode,cuserId,cgroupId);
    result=testfperm(userId,groupId,fperm);
    system("rm test.file");
-   printf("%c a %03o file owned by (%d/%d) as user/group(%d/%d)  ",fperm[0],mode,cuserId,cgroupId,userId,groupId);
+   printf("%s a %03o file owned by (%d/%d) as user/group(%d/%d)  ",fperm,mode,cuserId,cgroupId,userId,groupId);
    if (result == exresult) {
       printf("PASS\n");
       exit(0);
@@ -102,8 +103,7 @@ int testfperm(int userId, int groupId, char* fperm) {
            return(-1);
         }
 
-    switch(tolower(fperm[0])) {
-       case 'x': 
+    if (!strcmp("x", fperm)) {
           PID = fork();
 	  if (PID == 0) {
              execlp("./test.file","test.file",NULL); 
@@ -114,8 +114,7 @@ int testfperm(int userId, int groupId, char* fperm) {
           seteuid(0);
           setegid(0);
 	  return(nuthertmpi);
-
-       default: 
+    } else {
           if((testfile=fopen("test.file",fperm))){
             fclose(testfile);
             seteuid(0);

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#1 lore raw

src/fs_perms.c int main( int argc, char *argv[]) { · line 57

Quoted 7 lines · Eric Sandeen
src/fs_perms.c +2 -1
@@ -53,7 +53,8 @@ int main( int argc, char *argv[]) {
               cgroupId = atoi(argv[3]);
               userId = atoi(argv[4]);
               groupId = atoi(argv[5]);
-              fperm[0] = *argv[6];
+              strncpy(fperm, argv[6], 3);
+              fperm[2] = '\0';

This still looks rather weird to me. What's the reason for copying the string into a fixed length buffer? Why not leave fperm as a pointer to the original argument?

The rest of the patch looks fine, but a clean up pass on the whole file wouldn't hurt either, it's a grotty mess..

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#2 lore raw
Quoted 12 lines · Christoph Hellwig

src/fs_perms.c int main( int argc, char *argv[]) { · line 57

Quoted 7 lines · Eric Sandeen
src/fs_perms.c +2 -1
@@ -53,7 +53,8 @@ int main( int argc, char *argv[]) {
               cgroupId = atoi(argv[3]);
               userId = atoi(argv[4]);
               groupId = atoi(argv[5]);
-              fperm[0] = *argv[6];
+              strncpy(fperm, argv[6], 3);
+              fperm[2] = '\0';

This still looks rather weird to me. What's the reason for copying the string into a fixed length buffer? Why not leave fperm as a pointer to the original argument?

eh that's probably better, I guess I was just thinking copy based on how it was before. (which copied the char, right, it didn't assign a pointer, unless I'm short on coffee today...)

OTOH fopen only takes 2 chars anyway. But probably no reason to truncate what was given, just fail if it's something that's wrong...

-Eric

Quoted 3 lines

The rest of the patch looks fine, but a clean up pass on the whole file wouldn't hurt either, it's a grotty mess..

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#3 lore raw

PATCH v2 1/1 xfstests: fix up fs_perms test used by 126

In reply to Christoph Hellwig

Test 126 was failing intermittently for Ted & I; it seems that this is because we were passing an unterminated string to fopen for the mode; I'm not certain why this made it fail, but it's pretty clearly not a good thing to do, and fixing it fixes the test.

Rather than passing around characters, do things string-wise, since that is what is ultimately used in fopen().

---

V2: Just pass around pointer to passed-in mode argument

src/fs_perms.c +5 -7
index 2c5e3fa..ea188c4 100644
@@ -42,7 +42,7 @@ int testsetup(mode_t mode, int cuserId, int cgroupId);
 int testfperm(int userId, int groupId, char* fperm);
 
 int main( int argc, char *argv[]) {
-   char fperm[1];
+   char *fperm;
    int result, exresult=0,  cuserId=0, cgroupId=0, userId=0, groupId=0;
    mode_t mode;
 
@@ -53,7 +53,7 @@ int main( int argc, char *argv[]) {
               cgroupId = atoi(argv[3]);
               userId = atoi(argv[4]);
               groupId = atoi(argv[5]);
-              fperm[0] = *argv[6];
+              fperm = argv[6];
               exresult = atoi(argv[7]);
 	      break;
       default:
@@ -64,7 +64,7 @@ int main( int argc, char *argv[]) {
    testsetup(mode,cuserId,cgroupId);
    result=testfperm(userId,groupId,fperm);
    system("rm test.file");
-   printf("%c a %03o file owned by (%d/%d) as user/group(%d/%d)  ",fperm[0],mode,cuserId,cgroupId,userId,groupId);
+   printf("%s a %03o file owned by (%d/%d) as user/group(%d/%d)  ",fperm,mode,cuserId,cgroupId,userId,groupId);
    if (result == exresult) {
       printf("PASS\n");
       exit(0);
@@ -102,8 +102,7 @@ int testfperm(int userId, int groupId, char* fperm) {
            return(-1);
         }
 
-    switch(tolower(fperm[0])) {
-       case 'x': 
+    if (!strcmp("x", fperm)) {
           PID = fork();
 	  if (PID == 0) {
              execlp("./test.file","test.file",NULL); 
@@ -114,8 +113,7 @@ int testfperm(int userId, int groupId, char* fperm) {
           seteuid(0);
           setegid(0);
 	  return(nuthertmpi);
-
-       default: 
+    } else {
           if((testfile=fopen("test.file",fperm))){
             fclose(testfile);
             seteuid(0);

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

Reviewed-by on v2 1/1
#4 lore raw
Quoted 11 lines · Eric Sandeen

Test 126 was failing intermittently for Ted & I; it seems that this is because we were passing an unterminated string to fopen for the mode; I'm not certain why this made it fail, but it's pretty clearly not a good thing to do, and fixing it fixes the test.

Rather than passing around characters, do things string-wise, since that is what is ultimately used in fopen().

Looks good,

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs