OSSP CVS Repository

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

ossp-pkg/rc/rc_script.c 1.2 -> 1.3

--- rc_script.c  2002/06/28 14:20:23     1.2
+++ rc_script.c  2002/06/28 17:43:23     1.3
@@ -98,23 +98,31 @@
 * scriptSection(rc_script_t *, const char *)    *
 * Parse a script for a given section            *
 ************************************************/
-const char *scriptSection(rc_script_t *pScript, const char *kszSecname)
+char *scriptSection(rc_script_t *pScript, const char *kszSecname)
 {
     char *szTempout = NULL;
     char *szTmpsec  = NULL;
     char *piStart   = NULL;
     char *piEnd     = NULL;
 
+    assert(pScript); /* Check for a valid incoming script */
     szTmpsec = malloc(strlen(kszSecname) + sizeof(char));
     strcpy(szTmpsec, "%");
     strcat(szTmpsec, kszSecname);
 
     piStart = strstr(*pScript, szTmpsec);            /* Find start of section */
+    if (!piStart)                                    /* Short circuit if the  */
+        return(NULL);                                /* section was not found */
+
     piStart = strstr(piStart, "\n") + sizeof(char);  /* Wrap to next line     */
     piEnd   = strstr(piStart + sizeof(char), "%"); /* FIXME: Remove hardcoded */
-    szTempout = malloc(piEnd - piStart + sizeof(char));
-    strncpy(szTempout, piStart, piEnd - piStart);
-    *(szTempout + (piEnd - piStart)) = NULL; /* Terminate the outgoing string */
+    if (piEnd) {
+        szTempout = malloc(piEnd - piStart + sizeof(char));
+        strncpy(szTempout, piStart, piEnd - piStart);
+        *(szTempout + (piEnd - piStart)) = NULL; /* Terminate outgoing string */
+    }
+    else /* We are operating on the last section of the file */
+        szTempout = strdup(piStart); /* FIXME: Can we assume '\0' at EOF? */
 
     return(szTempout);
 }

CVSTrac 2.0.1