Skip to contentSkip to conversation

fix buffer overflow in sem_getvalue tests

PATCH In review Cyril Hrubis 1 participant 6 messages Feb 5, 2010 – Mar 18, 2010 4 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix buffer overflow in sem_getvalue tests

Hi!
Attached patch fixes possible buffer oveflow in sem_getvalue tests (the buffer overflow happens when getpid() returns number that couldn't fit into buffer) and also cleans coding style.

Signature · 2 lines
Cyril Hrubis
[email protected]
testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/5-1.c +10 -12
Index: ltp-full-20090930/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/5-1.c
===================================================================
@@ -9,8 +9,7 @@
 /*
  * This test case verifies that calling sem_getvalue doesn't change the 
  * state of the semaphore.
-*/
-
+ */
 
 #include <stdio.h>
 #include <errno.h>
@@ -24,34 +23,33 @@
 #define FUNCTION "sem_getvalue"
 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
 
-
-int main() {
-
-	char semname[20];
+int main(void)
+{
+	char semname[64];
 	sem_t *mysemp;
 	int val;
 
-	sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid());
+	snprintf(semname, 64, "/" FUNCTION "_" TEST "_%d", getpid());
 
 	mysemp = sem_open(semname, O_CREAT, 0777, 4);
 
-	if( mysemp == SEM_FAILED || mysemp == NULL ) {
+	if (mysemp == SEM_FAILED || mysemp == NULL) {
 		perror(ERROR_PREFIX "sem_open");
 		return PTS_UNRESOLVED;
 	}
 
 
-	if( sem_getvalue(mysemp, &val) == -1 ) {
+	if (sem_getvalue(mysemp, &val) == -1) {
 		perror(ERROR_PREFIX "sem_getvalue");
 		return PTS_UNRESOLVED; 
 	}
 
-	if ( sem_trywait(mysemp) == -1 ) {
+	if (sem_trywait(mysemp) == -1) {
 		perror(ERROR_PREFIX "sem_trywait");
 		return PTS_UNRESOLVED;
 	}
 
-	if( sem_getvalue(mysemp, &val) == -1 ) {
+	if (sem_getvalue(mysemp, &val) == -1) {
 		perror(ERROR_PREFIX "sem_getvalue");
 		return PTS_UNRESOLVED; 
 	}
@@ -60,7 +58,7 @@ int main() {
 	printf("Current value is: %d\n", val);
 	*/
 
-	if (val == 3 ) {
+	if (val == 3) {
 		puts("TEST PASSED");
 		sem_close(mysemp);
 		sem_unlink(semname);
testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/1-1.c +9 -11
Index: ltp-full-20090930/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/1-1.c
===================================================================
@@ -10,9 +10,7 @@
  * This test case will call sem_getvalue to update the location referenced
  * by the semaphpre without effecting the state of the semaphore.  The 
  * updated value represents the actual semaphore value when it was called.
-*/
-
-
+ */
 
 #include <stdio.h>
 #include <errno.h>
@@ -26,23 +24,22 @@
 #define FUNCTION "sem_getvalue"
 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
 
-
-int main() {
-
-	char semname[28];
+int main(void)
+{
+	char semname[64];
 	sem_t *mysemp;
 	int val;
 
-	sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid());
+	snprintf(semname, 64, "/" FUNCTION "_" TEST "_%d", getpid());
 
 	mysemp = sem_open(semname, O_CREAT, 0777, 1);
 
-	if( mysemp == SEM_FAILED || mysemp == NULL ) {
+	if (mysemp == SEM_FAILED || mysemp == NULL) {
 		perror(ERROR_PREFIX "sem_open");
 		return PTS_UNRESOLVED;
 	}
 
-	if( sem_getvalue(mysemp, &val) == -1 ) {
+	if (sem_getvalue(mysemp, &val) == -1) {
 		perror(ERROR_PREFIX "sem_getvalue");
 		return PTS_UNRESOLVED; 
 	}
@@ -50,7 +47,8 @@ int main() {
 	/*
 	printf("Current value is: %d\n", val);
 	*/
-	if (val == 1 ) {
+
+	if (val == 1) {
 		puts("TEST PASSED");
 		sem_close(mysemp);
 		sem_unlink(semname);
testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/2-1.c +8 -10
Index: ltp-full-20090930/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/2-1.c
===================================================================
@@ -8,8 +8,7 @@
 
 /*
  * When semaphore is locked, then the value returned by sem_getvalue is zero.
-*/
-
+ */
 
 #include <stdio.h>
 #include <errno.h>
@@ -23,29 +22,28 @@
 #define FUNCTION "sem_getvalue"
 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
 
-
-int main() {
-
-	char semname[28];
+int main(void)
+{
+	char semname[64];
 	sem_t *mysemp;
 	int val;
 
-	sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid());
+	snprintf(semname, 64, "/" FUNCTION "_" TEST "_%d", getpid());
 
 	mysemp = sem_open(semname, O_CREAT, 0777, 1);
 
-	if( mysemp == SEM_FAILED || mysemp == NULL ) {
+	if (mysemp == SEM_FAILED || mysemp == NULL) {
 		perror(ERROR_PREFIX "sem_open");
 		return PTS_UNRESOLVED;
 	}
 
 	/* Lock Semaphore */
-	if (sem_trywait(mysemp) == -1 ) {
+	if (sem_trywait(mysemp) == -1) {
 		perror(ERROR_PREFIX "trywait");
 		return PTS_UNRESOLVED;
 	}
 
-	if( sem_getvalue(mysemp, &val) < 0 ) {
+	if (sem_getvalue(mysemp, &val) < 0) {
 		perror(ERROR_PREFIX "sem_getvalue");
 		return PTS_UNRESOLVED; 
 	}
testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/2-2.c +23 -36

119 lines not on this page · raw message

testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/4-1.c +7 -10
Index: ltp-full-20090930/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/4-1.c
===================================================================
@@ -9,9 +9,7 @@
 /*
  * Upon successful completion of calling sem_getvalue, it shall return a value
  * of zero.
-*/
-
-
+ */
 
 #include <stdio.h>
 #include <errno.h>
@@ -25,23 +23,22 @@
 #define FUNCTION "sem_getvalue"
 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
 
-
-int main() {
-
-	char semname[28];
+int main(void)
+{
+	char semname[64];
 	sem_t *mysemp;
 	int val;
 
-	sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid());
+	snprintf(semname, 64, "/" FUNCTION "_" TEST "_%d", getpid());
 
 	mysemp = sem_open(semname, O_CREAT, 0777, 1);
 
-	if( mysemp == SEM_FAILED || mysemp == NULL ) {
+	if (mysemp == SEM_FAILED || mysemp == NULL) {
 		perror(ERROR_PREFIX "sem_open");
 		return PTS_UNRESOLVED;
 	}
 
-	if( sem_getvalue(mysemp, &val) != 0 ) {
+	if (sem_getvalue(mysemp, &val) != 0) {
 		puts("TEST FAILED");
 		return PTS_FAIL;
 	} else {

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation Stay online with enterprise data centers and the best network in the business Choose flexible plans and management services without long-term contracts Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

Hi!

Quoted 8 lines
Quoted 3 lines

Attached patch fixes possible buffer oveflow in sem_getvalue tests (the buffer overflow happens when getpid() returns number that couldn't fit into buffer) and also cleans coding style.

1. Why 64?
2. It should be #define'd and/or sizeof should be used in snprintf because they're fixed array buffers...

Just because I'm still not used to sizeof(array) (and had a little time for creating this patch) will resend cleaner version soon.

Signature · 11 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#3 lore raw
In reply to a message not in the archive

Hi!

Quoted 1 line

1. Why 64?

Well, it's big enough to hold the string (I'm too lazy to figure out exact maximal length for every possible architecture/compiler) and a few more bytes should not kill anyone...

Quoted 2 lines

2. It should be #define'd and/or sizeof should be used in snprintf because they're fixed array buffers...

Now there is sizeof() used in snprintf().

Signature · 2 lines
Cyril Hrubis
[email protected]
testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/5-1.c +10 -12
Index: ltp-full-20090930/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/5-1.c
===================================================================
@@ -9,8 +9,7 @@
 /*
  * This test case verifies that calling sem_getvalue doesn't change the 
  * state of the semaphore.
-*/
-
+ */
 
 #include <stdio.h>
 #include <errno.h>
@@ -24,34 +23,33 @@
 #define FUNCTION "sem_getvalue"
 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
 
-
-int main() {
-
-	char semname[20];
+int main(void)
+{
+	char semname[64];
 	sem_t *mysemp;
 	int val;
 
-	sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid());
+	snprintf(semname, sizeof(semname), "/" FUNCTION "_" TEST "_%d", getpid());
 
 	mysemp = sem_open(semname, O_CREAT, 0777, 4);
 
-	if( mysemp == SEM_FAILED || mysemp == NULL ) {
+	if (mysemp == SEM_FAILED || mysemp == NULL) {
 		perror(ERROR_PREFIX "sem_open");
 		return PTS_UNRESOLVED;
 	}
 
 
-	if( sem_getvalue(mysemp, &val) == -1 ) {
+	if (sem_getvalue(mysemp, &val) == -1) {
 		perror(ERROR_PREFIX "sem_getvalue");
 		return PTS_UNRESOLVED; 
 	}
 
-	if ( sem_trywait(mysemp) == -1 ) {
+	if (sem_trywait(mysemp) == -1) {
 		perror(ERROR_PREFIX "sem_trywait");
 		return PTS_UNRESOLVED;
 	}
 
-	if( sem_getvalue(mysemp, &val) == -1 ) {
+	if (sem_getvalue(mysemp, &val) == -1) {
 		perror(ERROR_PREFIX "sem_getvalue");
 		return PTS_UNRESOLVED; 
 	}
@@ -60,7 +58,7 @@ int main() {
 	printf("Current value is: %d\n", val);
 	*/
 
-	if (val == 3 ) {
+	if (val == 3) {
 		puts("TEST PASSED");
 		sem_close(mysemp);
 		sem_unlink(semname);
testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/1-1.c +9 -11
Index: ltp-full-20090930/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/1-1.c
===================================================================
@@ -10,9 +10,7 @@
  * This test case will call sem_getvalue to update the location referenced
  * by the semaphpre without effecting the state of the semaphore.  The 
  * updated value represents the actual semaphore value when it was called.
-*/
-
-
+ */
 
 #include <stdio.h>
 #include <errno.h>
@@ -26,23 +24,22 @@
 #define FUNCTION "sem_getvalue"
 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
 
-
-int main() {
-
-	char semname[28];
+int main(void)
+{
+	char semname[64];
 	sem_t *mysemp;
 	int val;
 
-	sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid());
+	snprintf(semname, sizeof(semname), "/" FUNCTION "_" TEST "_%d", getpid());
 
 	mysemp = sem_open(semname, O_CREAT, 0777, 1);
 
-	if( mysemp == SEM_FAILED || mysemp == NULL ) {
+	if (mysemp == SEM_FAILED || mysemp == NULL) {
 		perror(ERROR_PREFIX "sem_open");
 		return PTS_UNRESOLVED;
 	}
 
-	if( sem_getvalue(mysemp, &val) == -1 ) {
+	if (sem_getvalue(mysemp, &val) == -1) {
 		perror(ERROR_PREFIX "sem_getvalue");
 		return PTS_UNRESOLVED; 
 	}
@@ -50,7 +47,8 @@ int main() {
 	/*
 	printf("Current value is: %d\n", val);
 	*/
-	if (val == 1 ) {
+
+	if (val == 1) {
 		puts("TEST PASSED");
 		sem_close(mysemp);
 		sem_unlink(semname);
testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/2-1.c +8 -10
Index: ltp-full-20090930/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/2-1.c
===================================================================
@@ -8,8 +8,7 @@
 
 /*
  * When semaphore is locked, then the value returned by sem_getvalue is zero.
-*/
-
+ */
 
 #include <stdio.h>
 #include <errno.h>
@@ -23,29 +22,28 @@
 #define FUNCTION "sem_getvalue"
 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
 
-
-int main() {
-
-	char semname[28];
+int main(void)
+{
+	char semname[64];
 	sem_t *mysemp;
 	int val;
 
-	sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid());
+	snprintf(semname, sizeof(semname), "/" FUNCTION "_" TEST "_%d", getpid());
 
 	mysemp = sem_open(semname, O_CREAT, 0777, 1);
 
-	if( mysemp == SEM_FAILED || mysemp == NULL ) {
+	if (mysemp == SEM_FAILED || mysemp == NULL) {
 		perror(ERROR_PREFIX "sem_open");
 		return PTS_UNRESOLVED;
 	}
 
 	/* Lock Semaphore */
-	if (sem_trywait(mysemp) == -1 ) {
+	if (sem_trywait(mysemp) == -1) {
 		perror(ERROR_PREFIX "trywait");
 		return PTS_UNRESOLVED;
 	}
 
-	if( sem_getvalue(mysemp, &val) < 0 ) {
+	if (sem_getvalue(mysemp, &val) < 0) {
 		perror(ERROR_PREFIX "sem_getvalue");
 		return PTS_UNRESOLVED; 
 	}
testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/2-2.c +23 -36

119 lines not on this page · raw message

testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/4-1.c +7 -10
Index: ltp-full-20090930/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/4-1.c
===================================================================
@@ -9,9 +9,7 @@
 /*
  * Upon successful completion of calling sem_getvalue, it shall return a value
  * of zero.
-*/
-
-
+ */
 
 #include <stdio.h>
 #include <errno.h>
@@ -25,23 +23,22 @@
 #define FUNCTION "sem_getvalue"
 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
 
-
-int main() {
-
-	char semname[28];
+int main(void)
+{
+	char semname[64];
 	sem_t *mysemp;
 	int val;
 
-	sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid());
+	snprintf(semname, sizeof(semname), "/" FUNCTION "_" TEST "_%d", getpid());
 
 	mysemp = sem_open(semname, O_CREAT, 0777, 1);
 
-	if( mysemp == SEM_FAILED || mysemp == NULL ) {
+	if (mysemp == SEM_FAILED || mysemp == NULL) {
 		perror(ERROR_PREFIX "sem_open");
 		return PTS_UNRESOLVED;
 	}
 
-	if( sem_getvalue(mysemp, &val) != 0 ) {
+	if (sem_getvalue(mysemp, &val) != 0) {
 		puts("TEST FAILED");
 		return PTS_FAIL;
 	} else {

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw

Hi!

Quoted 11 lines
Quoted 3 lines

Well, it's big enough to hold the string (I'm too lazy to figure out exact maximal length for every possible architecture/compiler) and a few more bytes should not kill anyone...

SEM_NAME_MAX (see
http://publib.boulder.ibm.com/infocenter/iseries/v5r3/topic/apis/ipcsemo.htm
)?

This doesn't appear to exist on older versions of Linux (RHEL 4.6 for instance...)

Quoted 6 lines

The logic required to determine SEM_NAME_MAX should be easy to grab, or you could follow the following logic from the sem_open manpage:

ENAMETOOLONG
The length of the name argument exceeds {PATH_MAX} or a path- name component is longer than {NAME_MAX}.

My manual dated as 20-02-2009 says just:

ENAMETOOLONG
name was too long.

And 'man sem_overview' says we should use NAME_MAX - 4 (as on linux, named semaphores are files created in /dev/shm/ virtual filesystem that starts with 'sem.' prefix). Is semname declared as 'char semname[NAME_MAX - 4];' okay?

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw

Hi!

Quoted 17 lines
Quoted 17 lines
Quoted 7 lines

SEM_NAME_MAX (see
http://publib.boulder.ibm.com/infocenter/iseries/v5r3/topic/apis/ipcsemo.htm
)?

This doesn't appear to exist on older versions of Linux (RHEL 4.6 for instance...)

Quoted 6 lines

The logic required to determine SEM_NAME_MAX should be easy to grab, or you could follow the following logic from the sem_open manpage:

       ENAMETOOLONG
              The length of the name argument exceeds {PATH_MAX} or  a  path- name component is longer than {NAME_MAX}.

My manual dated as 20-02-2009 says just:

Quoted 8 lines
Quoted 7 lines

ENAMETOOLONG
       name was too long.

And 'man sem_overview' says we should use NAME_MAX - 4 (as on linux, named semaphores are files created in /dev/shm/ virtual filesystem that starts with 'sem.' prefix). Is semname declared as 'char semname[NAME_MAX - 4];' okay?

Patch attached.

Signature · 2 lines
Cyril Hrubis
[email protected]
testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/5-1.c +11 -12
Index: ltp-full-20090930/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/5-1.c
===================================================================
@@ -9,8 +9,7 @@
 /*
  * This test case verifies that calling sem_getvalue doesn't change the 
  * state of the semaphore.
-*/
-
+ */
 
 #include <stdio.h>
 #include <errno.h>
@@ -18,40 +17,40 @@
 #include <semaphore.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <limits.h>
 #include "posixtest.h"
 
 #define TEST "5-1"
 #define FUNCTION "sem_getvalue"
 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
 
-
-int main() {
-
-	char semname[20];
+int main(void)
+{
+	char semname[NAME_MAX - 4];
 	sem_t *mysemp;
 	int val;
 
-	sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid());
+	snprintf(semname, sizeof(semname), "/" FUNCTION "_" TEST "_%d", getpid());
 
 	mysemp = sem_open(semname, O_CREAT, 0777, 4);
 
-	if( mysemp == SEM_FAILED || mysemp == NULL ) {
+	if (mysemp == SEM_FAILED || mysemp == NULL) {
 		perror(ERROR_PREFIX "sem_open");
 		return PTS_UNRESOLVED;
 	}
 
 
-	if( sem_getvalue(mysemp, &val) == -1 ) {
+	if (sem_getvalue(mysemp, &val) == -1) {
 		perror(ERROR_PREFIX "sem_getvalue");
 		return PTS_UNRESOLVED; 
 	}
 
-	if ( sem_trywait(mysemp) == -1 ) {
+	if (sem_trywait(mysemp) == -1) {
 		perror(ERROR_PREFIX "sem_trywait");
 		return PTS_UNRESOLVED;
 	}
 
-	if( sem_getvalue(mysemp, &val) == -1 ) {
+	if (sem_getvalue(mysemp, &val) == -1) {
 		perror(ERROR_PREFIX "sem_getvalue");
 		return PTS_UNRESOLVED; 
 	}
@@ -60,7 +59,7 @@ int main() {
 	printf("Current value is: %d\n", val);
 	*/
 
-	if (val == 3 ) {
+	if (val == 3) {
 		puts("TEST PASSED");
 		sem_close(mysemp);
 		sem_unlink(semname);
testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/1-1.c +10 -11
Index: ltp-full-20090930/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/1-1.c
===================================================================
@@ -10,9 +10,7 @@
  * This test case will call sem_getvalue to update the location referenced
  * by the semaphpre without effecting the state of the semaphore.  The 
  * updated value represents the actual semaphore value when it was called.
-*/
-
-
+ */
 
 #include <stdio.h>
 #include <errno.h>
@@ -20,29 +18,29 @@
 #include <semaphore.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <limits.h>
 #include "posixtest.h"
 
 #define TEST "1-1"
 #define FUNCTION "sem_getvalue"
 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
 
-
-int main() {
-
-	char semname[28];
+int main(void)
+{
+	char semname[NAME_MAX - 4];
 	sem_t *mysemp;
 	int val;
 
-	sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid());
+	snprintf(semname, sizeof(semname), "/" FUNCTION "_" TEST "_%d", getpid());
 
 	mysemp = sem_open(semname, O_CREAT, 0777, 1);
 
-	if( mysemp == SEM_FAILED || mysemp == NULL ) {
+	if (mysemp == SEM_FAILED || mysemp == NULL) {
 		perror(ERROR_PREFIX "sem_open");
 		return PTS_UNRESOLVED;
 	}
 
-	if( sem_getvalue(mysemp, &val) == -1 ) {
+	if (sem_getvalue(mysemp, &val) == -1) {
 		perror(ERROR_PREFIX "sem_getvalue");
 		return PTS_UNRESOLVED; 
 	}
@@ -50,7 +48,8 @@ int main() {
 	/*
 	printf("Current value is: %d\n", val);
 	*/
-	if (val == 1 ) {
+
+	if (val == 1) {
 		puts("TEST PASSED");
 		sem_close(mysemp);
 		sem_unlink(semname);
testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/2-1.c +9 -10
Index: ltp-full-20090930/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/2-1.c
===================================================================
@@ -8,8 +8,7 @@
 
 /*
  * When semaphore is locked, then the value returned by sem_getvalue is zero.
-*/
-
+ */
 
 #include <stdio.h>
 #include <errno.h>
@@ -17,35 +16,35 @@
 #include <semaphore.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <limits.h>
 #include "posixtest.h"
 
 #define TEST "2-1"
 #define FUNCTION "sem_getvalue"
 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
 
-
-int main() {
-
-	char semname[28];
+int main(void)
+{
+	char semname[NAME_MAX - 4];
 	sem_t *mysemp;
 	int val;
 
-	sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid());
+	snprintf(semname, sizeof(semname), "/" FUNCTION "_" TEST "_%d", getpid());
 
 	mysemp = sem_open(semname, O_CREAT, 0777, 1);
 
-	if( mysemp == SEM_FAILED || mysemp == NULL ) {
+	if (mysemp == SEM_FAILED || mysemp == NULL) {
 		perror(ERROR_PREFIX "sem_open");
 		return PTS_UNRESOLVED;
 	}
 
 	/* Lock Semaphore */
-	if (sem_trywait(mysemp) == -1 ) {
+	if (sem_trywait(mysemp) == -1) {
 		perror(ERROR_PREFIX "trywait");
 		return PTS_UNRESOLVED;
 	}
 
-	if( sem_getvalue(mysemp, &val) < 0 ) {
+	if (sem_getvalue(mysemp, &val) < 0) {
 		perror(ERROR_PREFIX "sem_getvalue");
 		return PTS_UNRESOLVED; 
 	}
testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/2-2.c +23 -36

119 lines not on this page · raw message

testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/4-1.c +8 -10
Index: ltp-full-20090930/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/4-1.c
===================================================================
@@ -9,9 +9,7 @@
 /*
  * Upon successful completion of calling sem_getvalue, it shall return a value
  * of zero.
-*/
-
-
+ */
 
 #include <stdio.h>
 #include <errno.h>
@@ -19,29 +17,29 @@
 #include <semaphore.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <limits.h>
 #include "posixtest.h"
 
 #define TEST "4-1"
 #define FUNCTION "sem_getvalue"
 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
 
-
-int main() {
-
-	char semname[28];
+int main(void)
+{
+	char semname[NAME_MAX - 4];
 	sem_t *mysemp;
 	int val;
 
-	sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid());
+	snprintf(semname, sizeof(semname), "/" FUNCTION "_" TEST "_%d", getpid());
 
 	mysemp = sem_open(semname, O_CREAT, 0777, 1);
 
-	if( mysemp == SEM_FAILED || mysemp == NULL ) {
+	if (mysemp == SEM_FAILED || mysemp == NULL) {
 		perror(ERROR_PREFIX "sem_open");
 		return PTS_UNRESOLVED;
 	}
 
-	if( sem_getvalue(mysemp, &val) != 0 ) {
+	if (sem_getvalue(mysemp, &val) != 0) {
 		puts("TEST FAILED");
 		return PTS_FAIL;
 	} else {

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

A message that is not in the archive (sent off-list or not yet received): [email protected]

#9 lore raw
Quoted 6 lines
Quoted 1 line

Hi Garret,

can you put your Acked here ?

ping.

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list