[BACK]Return to roff.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Diff for /mandoc/roff.c between version 1.207 and 1.211

version 1.207, 2014/04/20 16:46:05 version 1.211, 2014/06/29 21:20:31
Line 488  roff_alloc(struct mparse *parse, int options)
Line 488  roff_alloc(struct mparse *parse, int options)
 static enum rofferr  static enum rofferr
 roff_res(struct roff *r, char **bufp, size_t *szp, int ln, int pos)  roff_res(struct roff *r, char **bufp, size_t *szp, int ln, int pos)
 {  {
         char             ubuf[12]; /* buffer to print the number */          char             ubuf[24]; /* buffer to print the number */
         const char      *start; /* start of the string to process */          const char      *start; /* start of the string to process */
         const char      *stesc; /* start of an escape sequence ('\\') */          char            *stesc; /* start of an escape sequence ('\\') */
         const char      *stnam; /* start of the name, after "[(*" */          const char      *stnam; /* start of the name, after "[(*" */
         const char      *cp;    /* end of the name, e.g. before ']' */          const char      *cp;    /* end of the name, e.g. before ']' */
         const char      *res;   /* the string to be substituted */          const char      *res;   /* the string to be substituted */
         char            *nbuf;  /* new buffer to copy bufp to */          char            *nbuf;  /* new buffer to copy bufp to */
         size_t           maxl;  /* expected length of the escape name */          size_t           maxl;  /* expected length of the escape name */
         size_t           naml;  /* actual length of the escape name */          size_t           naml;  /* actual length of the escape name */
         size_t           ressz; /* size of the replacement string */  
         int              expand_count;  /* to avoid infinite loops */          int              expand_count;  /* to avoid infinite loops */
         int              npos;  /* position in numeric expression */          int              npos;  /* position in numeric expression */
         int              irc;   /* return code from roff_evalnum() */          int              irc;   /* return code from roff_evalnum() */
Line 520  roff_res(struct roff *r, char **bufp, size_t *szp, int
Line 519  roff_res(struct roff *r, char **bufp, size_t *szp, int
                                 break;                                  break;
   
                 if (0 == (stesc - cp) % 2) {                  if (0 == (stesc - cp) % 2) {
                         stesc = cp;                          stesc = (char *)cp;
                         continue;                          continue;
                 }                  }
   
Line 614  roff_res(struct roff *r, char **bufp, size_t *szp, int
Line 613  roff_res(struct roff *r, char **bufp, size_t *szp, int
                         ubuf[1] = '\0';                          ubuf[1] = '\0';
                         break;                          break;
                 case 'n':                  case 'n':
                         snprintf(ubuf, sizeof(ubuf), "%d",                          (void)snprintf(ubuf, sizeof(ubuf), "%d",
                             roff_getregn(r, stnam, naml));                              roff_getregn(r, stnam, naml));
                         break;                          break;
                 case 'w':                  case 'w':
                         snprintf(ubuf, sizeof(ubuf), "%d",                          (void)snprintf(ubuf, sizeof(ubuf), "%d",
                             24 * (int)naml);                              24 * (int)naml);
                         break;                          break;
                 }                  }
Line 628  roff_res(struct roff *r, char **bufp, size_t *szp, int
Line 627  roff_res(struct roff *r, char **bufp, size_t *szp, int
                             ln, (int)(stesc - *bufp), NULL);                              ln, (int)(stesc - *bufp), NULL);
                         res = "";                          res = "";
                 }                  }
                 ressz = strlen(res);  
   
                 /* Replace the escape sequence by the string. */                  /* Replace the escape sequence by the string. */
   
                 *szp += ressz + 1;                  *stesc = '\0';
                 nbuf = mandoc_malloc(*szp);                  *szp = mandoc_asprintf(&nbuf, "%s%s%s",
                       *bufp, res, cp) + 1;
   
                 strlcpy(nbuf, *bufp, (size_t)(stesc - *bufp + 1));  
                 strlcat(nbuf, res, *szp);  
                 strlcat(nbuf, cp, *szp);  
   
                 /* Prepare for the next replacement. */                  /* Prepare for the next replacement. */
   
                 start = nbuf + pos;                  start = nbuf + pos;
                 stesc = nbuf + (stesc - *bufp) + ressz;                  stesc = nbuf + (stesc - *bufp) + strlen(res);
                 free(*bufp);                  free(*bufp);
                 *bufp = nbuf;                  *bufp = nbuf;
         }          }
Line 1943  roff_so(ROFF_ARGS)
Line 1938  roff_so(ROFF_ARGS)
 {  {
         char *name;          char *name;
   
         mandoc_msg(MANDOCERR_SO, r->parse, ln, ppos, NULL);          name = *bufp + pos;
           mandoc_vmsg(MANDOCERR_SO, r->parse, ln, ppos, ".so %s", name);
   
         /*          /*
          * Handle `so'.  Be EXTREMELY careful, as we shouldn't be           * Handle `so'.  Be EXTREMELY careful, as we shouldn't be
Line 1952  roff_so(ROFF_ARGS)
Line 1948  roff_so(ROFF_ARGS)
          * or using absolute paths.           * or using absolute paths.
          */           */
   
         name = *bufp + pos;  
         if ('/' == *name || strstr(name, "../") || strstr(name, "/..")) {          if ('/' == *name || strstr(name, "../") || strstr(name, "/..")) {
                 mandoc_msg(MANDOCERR_SOPATH, r->parse, ln, pos, NULL);                  mandoc_vmsg(MANDOCERR_SO_PATH, r->parse, ln, ppos,
                       ".so %s", name);
                 return(ROFF_ERR);                  return(ROFF_ERR);
         }          }
   
Line 1990  roff_userdef(ROFF_ARGS)
Line 1986  roff_userdef(ROFF_ARGS)
                         cp += 2;                          cp += 2;
                         continue;                          continue;
                 }                  }
                   *cp = '\0';
                 *szp = strlen(n1) - 3 + strlen(arg[i]) + 1;                  *szp = mandoc_asprintf(&n2, "%s%s%s",
                 n2 = mandoc_malloc(*szp);                      n1, arg[i], cp + 3) + 1;
   
                 strlcpy(n2, n1, (size_t)(cp - n1 + 1));  
                 strlcat(n2, arg[i], *szp);  
                 strlcat(n2, cp + 3, *szp);  
   
                 cp = n2 + (cp - n1);                  cp = n2 + (cp - n1);
                 free(n1);                  free(n1);
                 n1 = n2;                  n1 = n2;
Line 2077  roff_setstrn(struct roffkv **r, const char *name, size
Line 2068  roff_setstrn(struct roffkv **r, const char *name, size
         /* Search for an existing string with the same name. */          /* Search for an existing string with the same name. */
         n = *r;          n = *r;
   
         while (n && strcmp(name, n->key.p))          while (n && (namesz != n->key.sz ||
                           strncmp(n->key.p, name, namesz)))
                 n = n->next;                  n = n->next;
   
         if (NULL == n) {          if (NULL == n) {

Legend:
Removed from v.1.207  
changed lines
  Added in v.1.211

CVSweb