mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-30 06:46:45 -04:00
vt: limit maximum value of params in vt_param_get()
So that the value is clamped to the range [0, 0x7fffffff] and retains the same value, regardless of whether it's interpreted as a signed or unsigned integer. Closes #522
This commit is contained in:
parent
cf3eeff951
commit
2412d78268
2 changed files with 13 additions and 2 deletions
|
|
@ -103,6 +103,8 @@
|
||||||
(https://codeberg.org/dnkl/foot/issues/503).
|
(https://codeberg.org/dnkl/foot/issues/503).
|
||||||
* Sixels with transparent bottom border being resized below the size
|
* Sixels with transparent bottom border being resized below the size
|
||||||
specified in _”Set Raster Attributes”_.
|
specified in _”Set Raster Attributes”_.
|
||||||
|
* Crash caused by certain CSI sequences with very large parameter
|
||||||
|
values (https://codeberg.org/dnkl/foot/issues/522).
|
||||||
|
|
||||||
|
|
||||||
### Security
|
### Security
|
||||||
|
|
|
||||||
13
vt.h
13
vt.h
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
|
@ -10,9 +11,17 @@ void vt_from_slave(struct terminal *term, const uint8_t *data, size_t len);
|
||||||
static inline int
|
static inline int
|
||||||
vt_param_get(const struct terminal *term, size_t idx, int default_value)
|
vt_param_get(const struct terminal *term, size_t idx, int default_value)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* We zero excess bits in parsed param values. In most cases this will
|
||||||
|
* effectively be a no-op; but it prevents negative returns for edge
|
||||||
|
* cases involving unusually large values.
|
||||||
|
*/
|
||||||
|
static_assert(INT_MAX >= 0x7fffffff, "POSIX requires INT_MAX >= 0x7fffffff");
|
||||||
|
const unsigned value_mask = 0x7fffffff;
|
||||||
|
|
||||||
if (term->vt.params.idx > idx) {
|
if (term->vt.params.idx > idx) {
|
||||||
int value = term->vt.params.v[idx].value;
|
unsigned value = term->vt.params.v[idx].value & value_mask;
|
||||||
return value != 0 ? value : default_value;
|
return value != 0 ? (int)value : default_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return default_value;
|
return default_value;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue