libunwind-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libunwind] [patch] Handle strings that aren't NULL terminated


From: Ed Connell
Subject: [libunwind] [patch] Handle strings that aren't NULL terminated
Date: Fri, 18 Jun 2004 14:23:15 -0400

Intel's icc produces strings that aren't NULL terminated which causes
a crash in libunwind.  Here's a fix.

Cheers
Ed

diff -u -r libunwind-0.97/src/os-linux.h libunwind-0.97.edconn/src/os-linux.h
--- libunwind-0.97/src/os-linux.h       2004-06-18 11:15:31.000000000 -0400
+++ libunwind-0.97.edconn/src/os-linux.h        2004-06-18 12:26:57.000000000 
-0400
@@ -166,14 +166,14 @@
 /* Scan a string delimited by white-space.  Fails on empty string or
    if string is doesn't fit in the specified buffer.  */
 static inline char *
-scan_string (char *cp, char *valp, size_t buf_size)
+scan_string (char *cp, char *valp, size_t buf_size, char *end_cp)
 {
   size_t i = 0;
 
   if (!(cp = skip_whitespace (cp)))
     return NULL;
 
-  while (*cp != ' ' && *cp != '\t' && *cp != '\0')
+  while (cp < end_cp && *cp != ' ' && *cp != '\t' && *cp != '\0')
     {
       if (i < buf_size - 1)
        valp[i++] = *cp;
@@ -190,7 +190,7 @@
           unsigned long *low, unsigned long *high, unsigned long *offset,
           char *path, size_t path_size)
 {
-  char line[256 + PATH_MAX], perm[16], dash, colon, *cp;
+  char line[256 + PATH_MAX], perm[16], dash, colon, *cp, *end_cp;
   unsigned long major, minor, inum;
   size_t to_read = 256;        /* most lines fit in 256 characters easy */
   ssize_t i, nread;
@@ -237,6 +237,7 @@
                  }
            }
          cp = mi->buf;
+         end_cp = mi->buf_end;
          mi->buf = eol + 1;
          *eol = '\0';
        }
@@ -264,19 +265,20 @@
              continue; /* duh, no newline found */
            }
          cp = line;
+         end_cp = cp + sizeof(line);
        }
 
       /* scan: "LOW-HIGH PERM OFFSET MAJOR:MINOR INUM PATH" */
       cp = scan_hex (cp, low);
       cp = scan_char (cp, &dash);
       cp = scan_hex (cp, high);
-      cp = scan_string (cp, perm, sizeof (perm));
+      cp = scan_string (cp, perm, sizeof (perm), end_cp);
       cp = scan_hex (cp, offset);
       cp = scan_hex (cp, &major);
       cp = scan_char (cp, &colon);
       cp = scan_hex (cp, &minor);
       cp = scan_dec (cp, &inum);
-      cp = scan_string (cp, path, path_size);
+      cp = scan_string (cp, path, path_size, end_cp);
       if (!cp || dash != '-' || colon != ':')
        continue;       /* skip line with unknown or bad format */
       return 1;


reply via email to

[Prev in Thread] Current Thread [Next in Thread]