OSSP CVS Repository

ossp - Difference in ossp-pkg/rc/rc_script.c versions 1.19 and 1.20
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/rc/rc_script.c 1.19 -> 1.20

--- rc_script.c  2003/05/21 12:49:21     1.19
+++ rc_script.c  2003/05/21 15:16:41     1.20
@@ -50,7 +50,10 @@
 
     pNew = (rc_script_t *)malloc(sizeof(rc_script_t));
     *pNew = malloc((strlen(scriptTostring(pOrig)) + 1) * sizeof(char));
-    strcpy(*pNew, scriptTostring(pOrig));
+    if (pNew)
+        strcpy(*pNew, scriptTostring(pOrig));
+    else
+        RC_THROW(RC_ERR_MEM);
 
     return(pNew);
 }
@@ -224,7 +227,7 @@
             /* Handle the section userid   */
             piSubtemp = strnstr(piStart, RC_DEF_UIG, piEnd - piStart);
             if (piSubtemp) { /* Userid pattern found */
-                for (nTmp = (int)piSubtemp + strlen(RC_DEF_UIG);\
+                for (nTmp = (int)piSubtemp + strlen(RC_DEF_UIG); \
                     isspace(*(char *)nTmp); nTmp += sizeof (char)); /* Strip */
                 nUid = strtol((char *)nTmp, &piSep, 10);
                 if ((char *)nTmp == piSep)      /* No userid number follows */
@@ -312,17 +315,24 @@
 rc_return_t scriptWrite(rc_script_t *pScript, const char *szPath)
 {
     int nFdtmp = open(szPath, O_WRONLY | O_CREAT, 0600);
-    FILE *pStream = fdopen(nFdtmp, "w");
+    FILE *pStream = NULL;
+
+    /* Initial sanity checks */
+    if (!pScript || nFdtmp < 0)
+        return(RC_THROW(RC_ERR_USE));
+    else
+        pStream = fdopen(nFdtmp, "w");
 
     /* Don't remove this! It encapsulates the script object, */
     /*                    which might not be a simple string */
-    if (pScript && pStream) {
+    if (pStream) {
         fprintf(pStream, "%s", *pScript);
         fclose(pStream);
         return(RC_THROW(RC_OK));
     }
     else
-        return(RC_THROW(RC_ERR_USE));
+        fprintf(stderr, "FIXME: Replace with a real ex_throw!\n");
+/*        return(RC_THROW(RC_ERR_USE));*/
 }
 
 /************************************************

CVSTrac 2.0.1