ibstat.c: fix buffer-not-null-terminated
PATCH 2/6 ibstat.c: fix buffer-not-null-terminated
From: Dan Ben Yosef <[email protected]>
Buffer may not have a null terminator if the source string's length is equal to the buffer size.
--- src/ibstat.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
src/ibstat.c +2 -1
@@ -279,6 +279,7 @@ int main(int argc, char *argv[])int dev_port =-1 ;int n, i; +memset (names,0 ,sizeof (names[0 ][0 ] *UMAD_MAX_DEVICES *UMAD_CA_NAME_LEN ));const struct ibdiag_opt opts[] = { {"list_of_cas" ,'l' ,0 ,NULL ,"list all IB devices" }, {"short" ,'s' ,0 ,NULL ,"short output" },
@@ -314,7 +315,7 @@ int main(int argc, char *argv[])if (i >= n)IBPANIC ("'%s' IB device can't be found" , argv[0 ]); -strncpy (names[i], argv[0 ],sizeof names[i]); +strncpy (names[i], argv[0 ],sizeof names[i]-1 ); n =1 ; }
Signature · 6 lines
1.7.8.2 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 4 lines · On Wed, 12 Jun 2013 09:55:32 -0400 Hal Rosenstock…
From: Dan Ben Yosef <[email protected]>
Buffer may not have a null terminator if the source string's length is equal to the buffer size.
Good catch, but I think this is an issue in umad_get_cas_names!
Quoted 12 lines
Signed-off-by Dan Ben Yosef <[email protected]>--- src/ibstat.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)src/ibstat.c +0
-0
src/ibstat.c int main(int argc, char *argv[]) · line 282
Quoted 4 lines
src/ibstat.c +1
-0@@ -279,6 +279,7 @@ int main(int argc, char *argv[])int dev_port =-1 ;int n, i; +memset (names,0 ,sizeof (names[0 ][0 ] *UMAD_MAX_DEVICES *UMAD_CA_NAME_LEN ));
I don't think you need this as it will not fix umad_get_cas_names.
src/ibstat.c int main(int argc, char *argv[]) · line 318
Quoted 9 lines
src/ibstat.c +1
-1const struct ibdiag_opt opts[] = { {"list_of_cas" ,'l' ,0 ,NULL ,"list all IB devices" }, {"short" ,'s' ,0 ,NULL ,"short output" },@@ -314,7 +315,7 @@ int main(int argc, char *argv[])if (i >= n)IBPANIC ("'%s' IB device can't be found" , argv[0 ]); -strncpy (names[i], argv[0 ],sizeof names[i]); +strncpy (names[i], argv[0 ],sizeof names[i]-1 );
This is actually dead code. IBPANIC exits, if your linking to libibmad. Do you have a different IBPANIC which does not exit? Do you have a use case which hits this bug?
[root@iqa-136 sbin]# ./ibstat myverylongca_name_0123456789_0123456789
ibpanic: [9262] main: 'myverylongca_name_0123456789_0123456789' IB device can't be found: Success [root@iqa-136 sbin]# ./ibstat notfoundca
ibpanic: [9273] main: 'notfoundca' IB device can't be found: Success
Ira
Quoted 6 lines
src/ibstat.c +0
-0n =1 ; }Signature · 1 line
1.7.8.2
Signature · 5 lines
Ira Weiny <[email protected]> -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 25 lines · Ira Weiny
Quoted 4 lines · On Wed, 12 Jun 2013 09:55:32 -0400 Hal Rosenstock…
From: Dan Ben Yosef <[email protected]>
Buffer may not have a null terminator if the source string's length is equal to the buffer size.
Good catch, but I think this is an issue in
umad_get_cas_names!Quoted 15 lines
Signed-off-by Dan Ben Yosef <[email protected]>--- src/ibstat.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)src/ibstat.c +0
-0@@ -279,6 +279,7 @@ int main(int argc, char *argv[])int dev_port =-1 ;int n, i;
Quoted 3 lines
src/ibstat.c int main(int argc, char *argv[]) · line 282
Quoted 1 line
src/ibstat.c +1
-0+memset (names,0 ,sizeof (names[0 ][0 ] *UMAD_MAX_DEVICES *UMAD_CA_NAME_LEN ));I don't think you need this as it will not fix
umad_get_cas_names.
The proper memset is already in the tree.
Quoted 12 lines
src/ibstat.c int main(int argc, char *argv[]) · line 318
Quoted 9 lines
src/ibstat.c +1
-1const struct ibdiag_opt opts[] = { {"list_of_cas" ,'l' ,0 ,NULL ,"list all IB devices" }, {"short" ,'s' ,0 ,NULL ,"short output" },@@ -314,7 +315,7 @@ int main(int argc, char *argv[])if (i >= n)IBPANIC ("'%s' IB device can't be found" , argv[0 ]); -strncpy (names[i], argv[0 ],sizeof names[i]); +strncpy (names[i], argv[0 ],sizeof names[i]-1 );This is actually dead code. IBPANIC exits, if your linking to libibmad. Do you have a different IBPANIC which does not exit? Do you have a use case which hits this bug?
Quoted 4 lines
[root@iqa-136 sbin]# ./ibstat
myverylongca_name_0123456789_0123456789
ibpanic: [9262] main: 'myverylongca_name_0123456789_0123456789' IB device can't be found: Success [root@iqa-136 sbin]# ./ibstat notfoundca
ibpanic: [9273] main: 'notfoundca' IB device can't be found: Success
I think the change is to quiet a Coverity detected error but Dan is the definitive source for this change.
-- Hal
Quoted 10 lines
Ira
Quoted 6 lines
src/ibstat.c +0
-0n =1 ; }Signature · 1 line
1.7.8.2
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 26 lines · Hal Rosenstock
Quoted 25 lines · Ira Weiny
Quoted 4 lines · On Wed, 12 Jun 2013 09:55:32 -0400 Hal Rosenstock…
From: Dan Ben Yosef <[email protected]>
Buffer may not have a null terminator if the source string's length is equal to the buffer size.
Good catch, but I think this is an issue in
umad_get_cas_names!Quoted 15 lines
Signed-off-by Dan Ben Yosef <[email protected]>--- src/ibstat.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)src/ibstat.c +0
-0@@ -279,6 +279,7 @@ int main(int argc, char *argv[])int dev_port =-1 ;int n, i;
Quoted 5 lines
Quoted 3 lines
src/ibstat.c int main(int argc, char *argv[]) · line 282
Quoted 1 line
src/ibstat.c +1
-0+memset (names,0 ,sizeof (names[0 ][0 ] *UMAD_MAX_DEVICES *UMAD_CA_NAME_LEN ));I don't think you need this as it will not fix
umad_get_cas_names.The proper memset is already in the tree.
It isn't in the tree; I was looking at modified source...
Quoted 17 lines
Quoted 12 lines
src/ibstat.c int main(int argc, char *argv[]) · line 318
Quoted 9 lines
src/ibstat.c +1
-1const struct ibdiag_opt opts[] = { {"list_of_cas" ,'l' ,0 ,NULL ,"list all IB devices" }, {"short" ,'s' ,0 ,NULL ,"short output" },@@ -314,7 +315,7 @@ int main(int argc, char *argv[])if (i >= n)IBPANIC ("'%s' IB device can't be found" , argv[0 ]); -strncpy (names[i], argv[0 ],sizeof names[i]); +strncpy (names[i], argv[0 ],sizeof names[i]-1 );This is actually dead code. IBPANIC exits, if your linking to libibmad. Do you have a different IBPANIC which does not exit? Do you have a use case which hits this bug?
Quoted 4 lines
[root@iqa-136 sbin]# ./ibstat
myverylongca_name_0123456789_0123456789
ibpanic: [9262] main: 'myverylongca_name_0123456789_0123456789' IB device can't be found: Success [root@iqa-136 sbin]# ./ibstat notfoundca
ibpanic: [9273] main: 'notfoundca' IB device can't be found: Success
Quoted 16 lines
I think the change is to quiet a Coverity detected error but Dan is the definitive source for this change.
-- Hal
Quoted 10 lines
Ira
Quoted 6 lines
src/ibstat.c +0
-0n =1 ; }Signature · 1 line
1.7.8.2
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 13 lines
-----Original Message-----
From: Hal Rosenstock [mailto:[email protected]]
Subject: Re: [PATCH infiniband-diags 2/6]ibstat.c: fix buffer-not-null- terminatedQuoted 7 lines · Hal Rosenstock
Quoted 6 lines · Ira Weiny
Quoted 3 lines · On Wed, 12 Jun 2013 09:55:32 -0400 Hal Rosenstock…
From: Dan Ben Yosef <[email protected]>
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ memset(names, 0, sizeof(names[0][0] * UMAD_MAX_DEVICES * +UMAD_CA_NAME_LEN));I don't think you need this as it will not fix
umad_get_cas_names.The proper memset is already in the tree.
It isn't in the tree; I was looking at modified source...
Sounds like that should be pushed upstream! ;-)
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
Review
Quoted 4 lines
(quoted diff) +0
-0const struct ibdiag_opt opts[] = { {"list_of_cas", 'l', 0, NULL, "list all IB devices"}, {"short", 's', 0, NULL, "short output"}, @@ -314,7 +315,7 @@int
Quoted 8 lines
Quoted 8 lines
Review
Quoted 6 lines
main(int argc, char *argv[])(quoted diff) +1
-1if (i >= n) IBPANIC("'%s' IB device can't be found", argv[0]); - strncpy(names[i], argv[0], sizeof names[i]); + strncpy(names[i], argv[0], sizeof names[i]-1);This is actually dead code. IBPANIC exits, if your linking to libibmad. Do
Quoted 12 lines
you have a different IBPANIC which does not exit? Do you have a use case which hits this bug?
Quoted 2 lines
Quoted 2 lines
[root@iqa-136 sbin]# ./ibstat
myverylongca_name_0123456789_0123456789Quoted 7 lines
Quoted 4 lines
ibpanic: [9262] main: '
myverylongca_name_0123456789_0123456789' IB device can't be found: Success
[root@iqa-136 sbin]# ./ibstat notfoundca
ibpanic: [9273] main: 'notfoundca' IB device can't be found: SuccessI think the change is to quiet a Coverity detected error but Dan is the definitive source for this change.
I think we should remove the dead code and that should fix Coverity. I thought it detected dead code. I wonder if I missed something?
Ira
Quoted 8 lines
Quoted 8 lines
-- Hal
Quoted 5 lines
Ira
Quoted 3 lines
(quoted diff) +0
-0n = 1; }
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
--
1.7.8.2
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 11 lines
-----Original Message-----
From: [email protected] [mailto:linux-rdma-
Subject: RE: [PATCH infiniband-diags 2/6]ibstat.c: fix buffer-not-null- terminatedQuoted 3 lines
Quoted 3 lines
I think the change is to quiet a Coverity detected error but Dan is the definitive source for this change.
I think we should remove the dead code and that should fix Coverity. I thought it detected dead code. I wonder if I missed something?
That is not dead code. I misread where the break jumps to.
However, the code is redundant and there is a bug.[*]
16:16:51 > ibstat -lmlx4_0mlx4_1
16:17:57 > ibstat -l mlx4_1mlx4_0
The intent was to copy argv[0] into names[0] and set n=1. But that is not happening...
Ira
[*] not that the above is really a valid use case.
Quoted 18 lines
Ira
Quoted 8 lines
Quoted 8 lines
-- Hal
Quoted 5 lines
Ira
Quoted 3 lines
(quoted diff) +0
-0n = 1; }Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
--
1.7.8.2
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at
http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html