Commits

Greg Ward  committed 498a6db

fossil: fix potential use of uninitialized string.

If 'fossil status' forgets to print a newline after "tags:", then
get_till_eol() would simply not bother to copy any bytes into dest,
which is an uninitialized char array (random junk). Fix by always
terminating dest -- make it an empty string if no newline in src.

  • Participants
  • Parent commits 02c2e64

Comments (0)

Files changed (1)

File src/fossil.c

     return isfile("_FOSSIL_");
 }
 
-char *
+void
 get_till_eol(char *dest, const char *src, int n)
 {
     char *last = strchr(src, '\n');
         int m = (last - src < n ? last - src : n);
         strncpy(dest, src, m);
         dest[m] = '\0';
-        return dest;
     }
     else {
-        return NULL;
+        // make sure caller doesn't use an uninitialized string
+        dest[0] = '\0';
     }
 }