ref: 82a5163b8e7a1e6abb8bbe4cceeca68899460aa0
parent: db0ad4542a57e73b2a1ad4d82b3ae3c43e8b8ab7
author: Ali Gholami Rudi <ali@rudi.ir>
date: Fri Apr 19 06:55:07 EDT 2013
ren: disallow invalid values for built-in variables
--- a/ren.c
+++ b/ren.c
@@ -342,7 +342,7 @@
{
int ps = !s || !*s || !strcmp("0", s) ? n_s0 : eval(s, n_s, 0);
n_s0 = n_s;
- n_s = ps;
+ n_s = MAX(1, ps);
}
void tr_ps(char **args)
@@ -354,8 +354,8 @@
{
int ll = args[1] ? eval(args[1], n_l, 'm') : n_l0;
n_l0 = n_l;
- n_l = ll;
- adj_ll(cadj, ll);
+ n_l = MAX(0, ll);
+ adj_ll(cadj, n_l);
}
void tr_in(char **args)
@@ -364,8 +364,8 @@
if (args[0][0] == '.')
ren_br(1);
n_i0 = n_i;
- n_i = in;
- adj_in(cadj, in);
+ n_i = MAX(0, in);
+ adj_in(cadj, n_i);
}
void tr_ti(char **args)
--- a/tr.c
+++ b/tr.c
@@ -18,7 +18,7 @@
{
int vs = args[1] ? eval(args[1], n_v, 'p') : n_v0;
n_v0 = n_v;
- n_v = vs;
+ n_v = MAX(0, vs);
}
static void tr_ls(char **args)
@@ -25,13 +25,13 @@
{
int ls = args[1] ? eval(args[1], n_L, 'v') : n_L0;
n_L0 = n_L;
- n_L = ls;
+ n_L = MAX(1, ls);
}
static void tr_pl(char **args)
{
- if (args[1])
- n_p = eval(args[1], n_p, 'v');
+ int n = eval(args[1] ? args[1] : "11i", n_p, 'v');
+ n_p = MAX(0, n);
}
static void tr_nr(char **args)
@@ -94,7 +94,7 @@
{
int po = args[1] ? eval(args[1], n_o, 'm') : n_o0;
n_o0 = n_o;
- n_o = po;
+ n_o = MAX(0, po);
}
static char *arg_regname(char *s, int len);
--- a/xroff.h
+++ b/xroff.h
@@ -22,6 +22,7 @@
#define ESC_Q "bCDhHlLNoSvwxX" /* quoted escape sequences */
#define ESC_P "*fgkns" /* 1 or 2-char escape sequences */
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define LEN(a) (sizeof(a) / sizeof((a)[0]))
/* number registers */