From f1923bdfa6300a0d32e3329eb2488447f76b8970 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 12 Jun 2015 09:30:39 +0100 Subject: Add non-metafied character length handling. Use this in regex module and add test using $'\ua0'. Rename mb_metacharinit() to mb_charinit() as it does not involve metafied characters. --- Src/glob.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'Src/glob.c') diff --git a/Src/glob.c b/Src/glob.c index 057d44a17..eff34a24e 100644 --- a/Src/glob.c +++ b/Src/glob.c @@ -2237,7 +2237,7 @@ xpandbraces(LinkList list, LinkNode *np) #ifdef MULTIBYTE_SUPPORT char *ncptr; int nclen; - mb_metacharinit(); + mb_charinit(); ncptr = wcs_nicechar(cend, NULL, NULL); nclen = strlen(ncptr); p = zhalloc(lenalloc + nclen); @@ -2805,7 +2805,7 @@ igetmatch(char **sp, Patprog p, int fl, int n, char *replstr, * ... now we know whether it's worth looking for the * shortest, which we do by brute force. */ - mb_metacharinit(); + mb_charinit(); for (t = s, umlen = 0; t < s + mlen; ) { set_pat_end(p, *t); if (pattrylen(p, s, t - s, umlen, 0)) { @@ -2831,7 +2831,7 @@ igetmatch(char **sp, Patprog p, int fl, int n, char *replstr, * so that match, mbegin, mend and MATCH, MBEGIN, MEND are * correct. */ - mb_metacharinit(); + mb_charinit(); tmatch = NULL; for (ioff = 0, t = s, umlen = umltot; t < s + l; ioff++) { set_pat_start(p, t-s); @@ -2855,7 +2855,7 @@ igetmatch(char **sp, Patprog p, int fl, int n, char *replstr, /* Largest possible match at tail of string: * * move forward along string until we get a match. * * Again there's no optimisation. */ - mb_metacharinit(); + mb_charinit(); for (ioff = 0, t = s, umlen = umltot; t < s + l; ioff++) { set_pat_start(p, t-s); if (pattrylen(p, t, s + l - t, umlen, ioff)) { @@ -2889,7 +2889,7 @@ igetmatch(char **sp, Patprog p, int fl, int n, char *replstr, } ioff = 0; /* offset into string */ umlen = umltot; - mb_metacharinit(); + mb_charinit(); do { /* loop over all matches for global substitution */ matched = 0; @@ -2986,7 +2986,7 @@ igetmatch(char **sp, Patprog p, int fl, int n, char *replstr, */ nmatches = 0; tmatch = NULL; - mb_metacharinit(); + mb_charinit(); for (ioff = 0, t = s, umlen = umltot; t < s + l; ioff++) { set_pat_start(p, t-s); if (pattrylen(p, t, s + l - t, umlen, ioff)) { @@ -3002,7 +3002,7 @@ igetmatch(char **sp, Patprog p, int fl, int n, char *replstr, * We need to find the n'th last match. */ n = nmatches - n; - mb_metacharinit(); + mb_charinit(); for (ioff = 0, t = s, umlen = umltot; t < s + l; ioff++) { set_pat_start(p, t-s); if (pattrylen(p, t, s + l - t, umlen, ioff) && -- cgit v1.2.3 From df5f825538720a9422859200d58d075d1dd075fc Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sun, 9 Aug 2015 17:37:23 -0700 Subject: 36033: a few more queue_signals() to protect global state changes --- ChangeLog | 5 +++++ Src/glob.c | 4 ++++ Src/pattern.c | 8 +++++++- 3 files changed, 16 insertions(+), 1 deletion(-) (limited to 'Src/glob.c') diff --git a/ChangeLog b/ChangeLog index 1456675bc..37043e679 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-08-09 Barton E. Schaefer + + * 36033: Src/glob.c, Src/pattern.c: a few more queue_signals() + to protect global state changes + 2015-08-09 Mikael Magnusson * unposted: Test/C03traps.ztst: add tests for outputting traps diff --git a/Src/glob.c b/Src/glob.c index eff34a24e..f82c3bd30 100644 --- a/Src/glob.c +++ b/Src/glob.c @@ -216,22 +216,26 @@ static struct globdata curglobdata; #define save_globstate(N) \ do { \ + queue_signals(); \ memcpy(&(N), &curglobdata, sizeof(struct globdata)); \ (N).gd_pathpos = pathpos; \ (N).gd_pathbuf = pathbuf; \ (N).gd_glob_pre = glob_pre; \ (N).gd_glob_suf = glob_suf; \ pathbuf = NULL; \ + unqueue_signals(); \ } while (0) #define restore_globstate(N) \ do { \ + queue_signals(); \ zfree(pathbuf, pathbufsz); \ memcpy(&curglobdata, &(N), sizeof(struct globdata)); \ pathpos = (N).gd_pathpos; \ pathbuf = (N).gd_pathbuf; \ glob_pre = (N).gd_glob_pre; \ glob_suf = (N).gd_glob_suf; \ + unqueue_signals(); \ } while (0) /* pathname component in filename patterns */ diff --git a/Src/pattern.c b/Src/pattern.c index 8fa1a727f..7d38988a0 100644 --- a/Src/pattern.c +++ b/Src/pattern.c @@ -520,6 +520,8 @@ patcompile(char *exp, int inflags, char **endexp) char *lng, *strp = NULL; Patprog p; + queue_signals(); + startoff = sizeof(struct patprog); /* Ensure alignment of start of program string */ startoff = (startoff + sizeof(union upat) - 1) & ~(sizeof(union upat) - 1); @@ -582,8 +584,10 @@ patcompile(char *exp, int inflags, char **endexp) if (!strp || (*strp && *strp != '/')) { /* No, do normal compilation. */ strp = NULL; - if (patcompswitch(0, &flags) == 0) + if (patcompswitch(0, &flags) == 0) { + unqueue_signals(); return NULL; + } } else { /* * Yes, copy the string, and skip compilation altogether. @@ -715,6 +719,8 @@ patcompile(char *exp, int inflags, char **endexp) if (endexp) *endexp = patparse; + + unqueue_signals(); return p; } -- cgit v1.2.3 From 45424e735d3c5aac5cf1171acb3a7c8047255ca0 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Mon, 10 Aug 2015 12:55:56 -0700 Subject: 36084: use zrealloc() consistently --- ChangeLog | 2 ++ Src/glob.c | 2 +- Src/text.c | 6 +++--- 3 files changed, 6 insertions(+), 4 deletions(-) (limited to 'Src/glob.c') diff --git a/ChangeLog b/ChangeLog index 472551069..6dc79b5df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2015-08-10 Barton E. Schaefer + * 36084: Src/glob.c, Src/text.c: use zrealloc() consistently + * 36079: Src/signals.c: do not allow update_job() and its helpers to run the signal queue while we are processing a job exit. diff --git a/Src/glob.c b/Src/glob.c index f82c3bd30..3af46904d 100644 --- a/Src/glob.c +++ b/Src/glob.c @@ -257,7 +257,7 @@ addpath(char *s, int l) { DPUTS(!pathbuf, "BUG: pathbuf not initialised"); while (pathpos + l + 1 >= pathbufsz) - pathbuf = realloc(pathbuf, pathbufsz *= 2); + pathbuf = zrealloc(pathbuf, pathbufsz *= 2); while (l--) pathbuf[pathpos++] = *s++; pathbuf[pathpos++] = '/'; diff --git a/Src/text.c b/Src/text.c index cf73004d5..3978a26a9 100644 --- a/Src/text.c +++ b/Src/text.c @@ -77,7 +77,7 @@ taddpending(char *str1, char *str2) */ if (tpending) { int oldlen = strlen(tpending); - tpending = realloc(tpending, len + oldlen); + tpending = zrealloc(tpending, len + oldlen); sprintf(tpending + oldlen, "%s%s", str1, str2); } else { tpending = (char *)zalloc(len); @@ -110,7 +110,7 @@ taddchr(int c) tptr--; return; } - tbuf = realloc(tbuf, tsiz *= 2); + tbuf = zrealloc(tbuf, tsiz *= 2); tlim = tbuf + tsiz; tptr = tbuf + tsiz / 2; } @@ -130,7 +130,7 @@ taddstr(char *s) if (!tbuf) return; - tbuf = realloc(tbuf, tsiz *= 2); + tbuf = zrealloc(tbuf, tsiz *= 2); tlim = tbuf + tsiz; tptr = tbuf + x; } -- cgit v1.2.3 From c0df3440a44ac74a09115b536019b8ca6076245f Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 21 Aug 2015 15:17:18 +0100 Subject: 36264: glob and pattern variable pathbuf is metafied. Document this and unmetafy it when passing to system calls, including lchdir() which is a system-level interface. --- ChangeLog | 3 +++ Src/glob.c | 14 ++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'Src/glob.c') diff --git a/ChangeLog b/ChangeLog index 66d1d09e1..5c2cdf8f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2015-08-21 Peter Stephenson + * 36264: Src/glob.c: pathbuf is apparently metafied; document + this and unmetafy for system calls. + * unposted: README, Etc/FAQ.yo: update latest release from 5.0.8 to 5.1 in descriptive text. diff --git a/Src/glob.c b/Src/glob.c index 3af46904d..dea1bf50e 100644 --- a/Src/glob.c +++ b/Src/glob.c @@ -102,8 +102,14 @@ int badcshglob; /**/ int pathpos; /* position in pathbuf (needed by pattern code) */ +/* + * pathname buffer (needed by pattern code). + * It is currently believed the string in here is stored metafied and is + * unmetafied temporarily as needed by system calls. + */ + /**/ -char *pathbuf; /* pathname buffer (needed by pattern code) */ +char *pathbuf; typedef struct stat *Statptr; /* This makes the Ultrix compiler happy. Go figure. */ @@ -495,7 +501,7 @@ scanner(Complist q, int shortcircuit) if (l >= PATH_MAX) return; - err = lchdir(pathbuf + pathbufcwd, &ds, 0); + err = lchdir(unmeta(pathbuf + pathbufcwd), &ds, 0); if (err == -1) return; if (err) { @@ -517,7 +523,7 @@ scanner(Complist q, int shortcircuit) else if (!strcmp(str, "..")) { struct stat sc, sr; - add = (stat("/", &sr) || stat(pathbuf, &sc) || + add = (stat("/", &sr) || stat(unmeta(pathbuf), &sc) || sr.st_ino != sc.st_ino || sr.st_dev != sc.st_dev); } @@ -564,7 +570,7 @@ scanner(Complist q, int shortcircuit) DPUTS(pathpos == pathbufcwd, "BUG: filename longer than PATH_MAX"); - err = lchdir(pathbuf + pathbufcwd, &ds, 0); + err = lchdir(unmeta(pathbuf + pathbufcwd), &ds, 0); if (err == -1) break; if (err) { -- cgit v1.2.3