Skip to content

Commit

Permalink
Fix disallowing --rscroll="*".
Browse files Browse the repository at this point in the history
The --rscroll parameter was being restricted as if it were
to be used as a printf format, like LESSBINFMT.
  • Loading branch information
gwsw committed Feb 14, 2023
1 parent 015dfda commit cc7bd14
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions charset.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ static void ilocale(void)
/*
* Define the printing format for control (or binary utf) chars.
*/
public void setfmt(char *s, char **fmtvarptr, int *attrptr, char *default_fmt)
public void setfmt(char *s, char **fmtvarptr, int *attrptr, char *default_fmt, int for_printf)
{
if (s && utf_mode)
{
Expand All @@ -380,10 +380,12 @@ public void setfmt(char *s, char **fmtvarptr, int *attrptr, char *default_fmt)
}
}

/* %n is evil */
if (s == NULL || *s == '\0' ||
(*s == '*' && (s[1] == '\0' || s[2] == '\0' || strchr(s + 2, 'n'))) ||
(*s != '*' && strchr(s, 'n')))
if (s == NULL || *s == '\0')
s = default_fmt;
else if (for_printf &&
((*s == '*' && (s[1] == '\0' || s[2] == '\0' || strchr(s + 2, 'n'))) ||
(*s != '*' && strchr(s, 'n'))))
/* %n is evil */
s = default_fmt;

/*
Expand Down Expand Up @@ -501,10 +503,10 @@ public void init_charset(void)
set_charset();

s = lgetenv("LESSBINFMT");
setfmt(s, &binfmt, &binattr, "*s<%02X>");
setfmt(s, &binfmt, &binattr, "*s<%02X>", TRUE);

s = lgetenv("LESSUTFBINFMT");
setfmt(s, &utfbinfmt, &binattr, "<U+%04lX>");
setfmt(s, &utfbinfmt, &binattr, "<U+%04lX>", TRUE);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion optfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ public void opt_rscroll(int type, char *s)
case TOGGLE: {
char *fmt;
int attr = AT_STANDOUT;
setfmt(s, &fmt, &attr, "*s>");
setfmt(s, &fmt, &attr, "*s>", FALSE);
if (strcmp(fmt, "-") == 0)
{
rscroll_char = 0;
Expand Down

0 comments on commit cc7bd14

Please sign in to comment.