dtcm: Coverity 88675
[oweals/cde.git] / cde / programs / dtsession / SmGlobals.c
index 51eeeef96da40f9e7044bd2c8b7b436ee072b1ac..0bb24e7edd643581c35c1564b667b6f111c490b9 100644 (file)
@@ -16,7 +16,7 @@
  * details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with these librararies and programs; if not, write
+ * License along with these libraries and programs; if not, write
  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  * Floor, Boston, MA 02110-1301 USA
  */
  *****************************************************************************
  *************************************<+>*************************************/
 #include <stdio.h>
+#include <errno.h>
+#include <string.h>
 #include <ctype.h>
 #include <sys/wait.h>
 #include <sys/types.h>
 #include <sys/utsname.h>
 #include <unistd.h>
-#ifdef __apollo
-#include <X11/apollosys.h>      /* for pid_t, in hp-ux sys/types.h */
-#endif
 #include <sys/stat.h>
 #include <sys/param.h>
 #include <X11/Intrinsic.h>
@@ -960,7 +959,7 @@ SetResSet( void )
  *
  *************************************<->***********************************/
 void 
-UndoSetSavePath ( )
+UndoSetSavePath (void)
 {
        char                    * buf;
 
@@ -1104,7 +1103,7 @@ SetSavePath(
             * runs a Current session and saves the session.
             */
            strcpy (savedDir, smGD.clientPath);
-            sprintf(smGD.etcPath, "%s.%s", smGD.clientPath, SM_OLD_EXTENSION);
+            snprintf(smGD.etcPath, sizeof(smGD.etcPath), "%s.%s", smGD.clientPath, SM_OLD_EXTENSION);
             status = stat(smGD.etcPath, &buf);
             if(status == 0)
            {
@@ -1161,7 +1160,10 @@ SetSavePath(
                 smGD.resourcePath[0] = 0;
                 return(-1);
             }
-            chmod(smGD.clientPath, 0755);
+            if(-1 == chmod(smGD.clientPath, 0755))
+            {
+                               fprintf(stderr, "%s chmod error %s\n", smGD.clientPath, strerror(errno));
+                       }
         }
         else
         {
@@ -1175,7 +1177,7 @@ SetSavePath(
             */
            char                * tmpName;
 
-            sprintf(smGD.etcPath, "%s.%s", smGD.clientPath, SM_OLD_EXTENSION);
+            snprintf(smGD.etcPath, sizeof(smGD.etcPath), "%s.%s", smGD.clientPath, SM_OLD_EXTENSION);
             status = stat(smGD.etcPath, &buf);
             if(status == 0)
            {
@@ -1184,7 +1186,7 @@ SetSavePath(
               len = strlen(smGD.savePath) + strlen(smGD.restoreSession) 
                 + strlen("XXXXXX") + 3;
               tmpName = (char *) XtCalloc(1, len);
-              sprintf(tmpName, "%s/%s.XXXXXX", smGD.savePath, 
+              snprintf(tmpName, len, "%s/%s.XXXXXX", smGD.savePath, 
                       smGD.restoreSession);
 
               strcpy (savedOldDir, smGD.etcPath);
@@ -1293,7 +1295,10 @@ SetFontSavePath(char *langPtr)
             smGD.fontPath[0] = 0;
             return(-1);
         }
-        chmod(smGD.fontPath, 0755);
+        if(-1 == chmod(smGD.fontPath, 0755))
+        {
+                       fprintf(stderr, "%s chmod error %s\n", smGD.fontPath, strerror(errno)); 
+               }
     }
 
     /*
@@ -1391,11 +1396,11 @@ RemoveFiles(
 
         _DtEnvControl(DT_ENV_RESTORE_PRE_DT);
         
-#if defined(__osf__) || defined(CSRG_BASED)
+#if defined(CSRG_BASED)
         setsid();
 #else
         (void) setpgrp();
-#endif /* __osf__ */
+#endif /* CSRG_BASED */
          
         execStatus = execlp("rm","rm", "-rf", path, (char *) 0);
         if(execStatus != 0)
@@ -1496,11 +1501,11 @@ MoveDirectory(
 
         _DtEnvControl(DT_ENV_RESTORE_PRE_DT);
         
-#if defined(__osf__) || defined(CSRG_BASED)
+#if defined(CSRG_BASED)
         setsid();
 #else
         (void) setpgrp();
-#endif /* __osf__ */
+#endif /* CSRG_BASED */
         
         execStatus = execlp("mv","mv", pathFrom, pathTo, (char *) 0);
         if(execStatus != 0)
@@ -1665,7 +1670,7 @@ TrimErrorlog( void )
     
     len = strlen(home) + strlen(DtPERSONAL_CONFIG_DIRECTORY) + 2;
     if (len > MAXPATHLEN) savePath = SM_REALLOC(savePath, len);
-    snprintf(savePath, len - 1, "%s/%s", home, DtPERSONAL_CONFIG_DIRECTORY);
+    snprintf(savePath, len, "%s/%s", home, DtPERSONAL_CONFIG_DIRECTORY);
     
     /*
      * If errorlog.old exists and it is not empty, delete
@@ -1694,7 +1699,7 @@ TrimErrorlog( void )
      */
     if (len + strlen(DtERRORLOG_FILE) > MAXPATHLEN)
       checkPath1 = SM_REALLOC(savePath, len + strlen(DtERRORLOG_FILE));
-    sprintf(checkPath1, "%s/%s", savePath, DtERRORLOG_FILE);
+    snprintf(checkPath1, len + strlen(DtERRORLOG_FILE), "%s/%s", savePath, DtERRORLOG_FILE);
 
     status = stat(checkPath1, &buf);
     if((status != -1) && (buf.st_size > 0))
@@ -2599,7 +2604,7 @@ SetAlternateSession (
                /*
                 * The directory for the specified session exists
                 * but it doesn't have any client databases.  Start
-                * a new user session.  If a user wants a sesssion
+                * a new user session.  If a user wants a session
                 * with no apps, they should create a zero-length
                 * session database.
                 */
@@ -2632,7 +2637,7 @@ SmExit (
 }
 
 void
-SetSIGPIPEToDefault ()
+SetSIGPIPEToDefault (void)
 {
        struct sigaction pipeSig;