summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <Alan.Coopersmith@sun.com>2006-03-17 03:05:32 +0000
committerAlan Coopersmith <Alan.Coopersmith@sun.com>2006-03-17 03:05:32 +0000
commitc46e8ae80540713ec24fd6d1eea68744937ef158 (patch)
tree12b6d1dba219dc5d665ec43bcded39661d13e791
parent6842e89f85b1fa30344e2bf3d28e51dbfd978370 (diff)
Specs say SmsInitialize & SmcOpenConnection return NULL terminated stringsXORG-7_0_99_901
in errorStringRet, but were just calling strncpy and not making sure strings were NULL terminated if errorLength wasn't long enough. (Noticed while evaluating Coverity ids 196 & 201.)
-rw-r--r--ChangeLog9
-rw-r--r--src/sm_client.c39
-rw-r--r--src/sm_manager.c18
3 files changed, 49 insertions, 17 deletions
diff --git a/ChangeLog b/ChangeLog
index 9272fc1..836e691 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2006-03-16 Alan Coopersmith <alan.coopersmith@sun.com>
+
+ * src/sm_manager.c:
+ * src/sm_client.c:
+ Specs say SmsInitialize & SmcOpenConnection return NULL terminated
+ strings in errorStringRet, but were just calling strncpy and not
+ making sure strings were NULL terminated if errorLength wasn't long
+ enough. (Noticed while evaluating Coverity ids 196 & 201.)
+
2005-12-14 Kevin E. Martin <kem-at-freedesktop-dot-org>
* configure.ac:
diff --git a/src/sm_client.c b/src/sm_client.c
index 02f9ccd..047924b 100644
--- a/src/sm_client.c
+++ b/src/sm_client.c
@@ -1,3 +1,4 @@
+/* $XdotOrg: $ */
/* $Xorg: sm_client.c,v 1.4 2001/02/09 02:03:30 xorgcvs Exp $ */
/*
@@ -90,8 +91,12 @@ char *errorStringRet;
SmVendorString, SmReleaseString, _SmVersionCount, _SmcVersions,
_SmAuthCount, _SmAuthNames, _SmcAuthProcs, NULL)) < 0)
{
- strncpy (errorStringRet,
- "Could not register XSMP protocol with ICE", errorLength);
+ if (errorStringRet && errorLength > 0) {
+ strncpy (errorStringRet,
+ "Could not register XSMP protocol with ICE",
+ errorLength);
+ errorStringRet[errorLength - 1] = '\0';
+ }
return (NULL);
}
@@ -101,10 +106,12 @@ char *errorStringRet;
{
if ((ids = (char *) getenv ("SESSION_MANAGER")) == NULL)
{
- strncpy (errorStringRet,
- "SESSION_MANAGER environment variable not defined",
- errorLength);
-
+ if (errorStringRet && errorLength > 0) {
+ strncpy (errorStringRet,
+ "SESSION_MANAGER environment variable not defined",
+ errorLength);
+ errorStringRet[errorLength - 1] = '\0';
+ }
return (NULL);
}
}
@@ -121,7 +128,10 @@ char *errorStringRet;
if ((smcConn = (SmcConn) malloc (sizeof (struct _SmcConn))) == NULL)
{
- strncpy (errorStringRet, "Can't malloc", errorLength);
+ if (errorStringRet && errorLength > 0) {
+ strncpy (errorStringRet, "Can't malloc", errorLength);
+ errorStringRet[errorLength - 1] = '\0';
+ }
IceCloseConnection (iceConn);
return (NULL);
}
@@ -148,8 +158,11 @@ char *errorStringRet;
*/
free ((char *) smcConn);
- strncpy (errorStringRet, "Internal error in IceOpenConnection",
- errorLength);
+ if (errorStringRet && errorLength > 0) {
+ strncpy (errorStringRet, "Internal error in IceOpenConnection",
+ errorLength);
+ errorStringRet[errorLength - 1] = '\0';
+ }
return (NULL);
}
@@ -201,9 +214,11 @@ char *errorStringRet;
if (ioErrorOccured)
{
- strncpy (errorStringRet, "IO error occured opening connection",
- errorLength);
-
+ if (errorStringRet && errorLength > 0) {
+ strncpy (errorStringRet, "IO error occured opening connection",
+ errorLength);
+ errorStringRet[errorLength - 1] = '\0';
+ }
free (smcConn->vendor);
free (smcConn->release);
free ((char *) smcConn);
diff --git a/src/sm_manager.c b/src/sm_manager.c
index 68cabcd..df9c221 100644
--- a/src/sm_manager.c
+++ b/src/sm_manager.c
@@ -1,3 +1,4 @@
+/* $XdotOrg: $ */
/* $Xorg: sm_manager.c,v 1.4 2001/02/09 02:03:30 xorgcvs Exp $ */
/*
@@ -130,8 +131,12 @@ char *errorStringRet;
if (!newClientProc)
{
- strncpy (errorStringRet,
- "The SmsNewClientProc callback can't be NULL", errorLength);
+ if (errorStringRet && errorLength > 0) {
+ strncpy (errorStringRet,
+ "The SmsNewClientProc callback can't be NULL",
+ errorLength);
+ errorStringRet[errorLength - 1] = '\0';
+ }
return (0);
}
@@ -150,9 +155,12 @@ char *errorStringRet;
NULL /* IceIOErrorProc */
)) < 0)
{
- strncpy (errorStringRet,
- "Could not register XSMP protocol with ICE", errorLength);
-
+ if (errorStringRet && errorLength > 0) {
+ strncpy (errorStringRet,
+ "Could not register XSMP protocol with ICE",
+ errorLength);
+ errorStringRet[errorLength - 1] = '\0';
+ }
return (0);
}
}