FreeBSD Bugzilla – Attachment 212048 Details for
Bug 235589
sh(1): LINENO is unset in shell arithmetic
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
A possible fix
linno-3.diff (text/plain), 5.49 KB, created by
Paco Pascal
on 2020-02-29 18:53:23 UTC
(
hide
)
Description:
A possible fix
Filename:
MIME Type:
Creator:
Paco Pascal
Created:
2020-02-29 18:53:23 UTC
Size:
5.49 KB
patch
obsolete
>Index: eval.c >=================================================================== >--- eval.c (revision 358323) >+++ eval.c (working copy) >@@ -841,6 +841,8 @@ > const char *path = pathval(); > int i; > >+ setlinno(cmd->ncmd.linno); >+ > /* First expand the arguments. */ > TRACE(("evalcommand(%p, %d) called\n", (void *)cmd, flags)); > emptyarglist(&arglist); >Index: expand.c >=================================================================== >--- expand.c (revision 358323) >+++ expand.c (working copy) >@@ -681,11 +681,8 @@ > if (! is_name(*p)) > special = 1; > p = strchr(p, '=') + 1; >- if (varflags & VSLINENO) { >- set = 1; >- special = 1; >- val = NULL; >- } else if (special) { >+ >+ if (special) { > set = varisset(var, varflags & VSNUL); > val = NULL; > } else { >@@ -713,16 +710,7 @@ > if (set && subtype != VSPLUS) { > /* insert the value of the variable */ > if (special) { >- if (varflags & VSLINENO) { >- if (p - var > (ptrdiff_t)sizeof(buf)) >- abort(); >- memcpy(buf, var, p - var - 1); >- buf[p - var - 1] = '\0'; >- strtodest(buf, flag, subtype, >- varflags & VSQUOTE, dst); >- } else >- varvalue(var, varflags & VSQUOTE, subtype, flag, >- dst); >+ varvalue(var, varflags & VSQUOTE, subtype, flag, dst); > if (subtype == VSLENGTH) { > varlenb = expdest - stackblock() - startloc; > varlen = varlenb; >Index: nodetypes >=================================================================== >--- nodetypes (revision 358323) >+++ nodetypes (working copy) >@@ -58,6 +58,7 @@ > type int > args nodeptr # the arguments > redirect nodeptr # list of file redirections >+ linno int # value for LINENO > > NPIPE npipe # a pipeline > type int >Index: parser.c >=================================================================== >--- parser.c (revision 358323) >+++ parser.c (working copy) >@@ -694,6 +694,10 @@ > n->type = NCMD; > n->ncmd.args = args; > n->ncmd.redirect = redir; >+ if (funclinno) >+ n->ncmd.linno = plinno - funclinno; >+ else >+ n->ncmd.linno = plinno - 1; > return n; > } > >@@ -1622,7 +1626,6 @@ > int flags; > char *p; > static const char types[] = "}-+?="; >- int linno; > int length; > int c1; > >@@ -1656,21 +1659,6 @@ > c = pgetc_linecont(); > length++; > } while (!is_eof(c) && is_in_name(c)); >- if (length == 6 && >- strncmp(out - length, "LINENO", length) == 0) { >- /* Replace the variable name with the >- * current line number. */ >- STADJUST(-6, out); >- CHECKSTRSPACE(11, out); >- linno = plinno; >- if (funclinno != 0) >- linno -= funclinno - 1; >- length = snprintf(out, 11, "%d", linno); >- if (length > 10) >- length = 10; >- out += length; >- flags |= VSLINENO; >- } > } else if (is_digit(c)) { > if (subtype != VSNORMAL) { > do { >Index: parser.h >=================================================================== >--- parser.h (revision 358323) >+++ parser.h (working copy) >@@ -50,8 +50,6 @@ > /* variable substitution byte (follows CTLVAR) */ > #define VSTYPE 0x0f /* type of variable substitution */ > #define VSNUL 0x10 /* colon--treat the empty string as unset */ >-#define VSLINENO 0x20 /* expansion of $LINENO, the line number \ >- follows immediately */ > #define VSQUOTE 0x80 /* inside double quotes--suppress splitting */ > > /* values of VSTYPE field */ >Index: var.c >=================================================================== >--- var.c (revision 358323) >+++ var.c (working copy) >@@ -83,7 +83,6 @@ > void (*func)(const char *); > }; > >- > #ifndef NO_HISTORY > struct var vhistsize; > struct var vterm; >@@ -97,6 +96,9 @@ > struct var vps4; > static struct var voptind; > struct var vdisvfork; >+static struct var vlinno; >+#define LINNOBUFSIZ 64 >+static char vlinnobuf[LINNOBUFSIZ]; > > struct localvar *localvars; > int forcelocal; >@@ -103,34 +105,22 @@ > > static const struct varinit varinit[] = { > #ifndef NO_HISTORY >- { &vhistsize, VUNSET, "HISTSIZE=", >- sethistsize }, >+ { &vhistsize, VUNSET, "HISTSIZE=", sethistsize }, >+ { &vterm, VUNSET, "TERM=", setterm }, > #endif >- { &vifs, 0, "IFS= \t\n", >- NULL }, >- { &vmail, VUNSET, "MAIL=", >- NULL }, >- { &vmpath, VUNSET, "MAILPATH=", >- NULL }, >- { &vpath, 0, "PATH=" _PATH_DEFPATH, >- changepath }, >+ { &vifs, 0, "IFS= \t\n", NULL }, >+ { &vmail, VUNSET, "MAIL=", NULL }, >+ { &vmpath, VUNSET, "MAILPATH=", NULL }, >+ { &vpath, 0, "PATH=" _PATH_DEFPATH, changepath }, > /* > * vps1 depends on uid > */ >- { &vps2, 0, "PS2=> ", >- NULL }, >- { &vps4, 0, "PS4=+ ", >- NULL }, >-#ifndef NO_HISTORY >- { &vterm, VUNSET, "TERM=", >- setterm }, >-#endif >- { &voptind, 0, "OPTIND=1", >- getoptsreset }, >- { &vdisvfork, VUNSET, "SH_DISABLE_VFORK=", >- NULL }, >- { NULL, 0, NULL, >- NULL } >+ { &vps2, 0, "PS2=> ", NULL }, >+ { &vps4, 0, "PS4=+ ", NULL }, >+ { &voptind, 0, "OPTIND=1", getoptsreset }, >+ { &vdisvfork, VUNSET, "SH_DISABLE_VFORK=", NULL }, >+ { &vlinno, VREADONLY, vlinnobuf, NULL }, >+ { NULL, 0, NULL, NULL } > }; > > static struct var *vartab[VTABSIZE]; >@@ -164,6 +154,8 @@ > struct var **vpp; > char **envp; > >+ setlinno(1); >+ > for (ip = varinit ; (vp = ip->var) != NULL ; ip++) { > if (find_var(ip->text, &vpp, &vp->name_len) != NULL) > continue; >@@ -418,6 +410,11 @@ > INTON; > } > >+void >+setlinno(int n) >+{ >+ snprintf(vlinnobuf, LINNOBUFSIZ, "LINENO=%d", n); >+} > > > /* >Index: var.h >=================================================================== >--- var.h (revision 358323) >+++ var.h (working copy) >@@ -130,3 +130,4 @@ > void poplocalvars(void); > int unsetvar(const char *); > int setvarsafe(const char *, const char *, int); >+void setlinno(int n); >\ No newline at end of file
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 235589
:
206211
|
212048
|
212062
|
258089