Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
htop
Commits
858af250
Commit
858af250
authored
Feb 26, 2018
by
Hisham Muhammad
Browse files
Protect against overflows in RichString_setAttrn
parent
655c7293
Changes
2
Hide whitespace changes
Inline
Side-by-side
RichString.c
View file @
858af250
...
@@ -63,6 +63,10 @@ typedef struct RichString_ {
...
@@ -63,6 +63,10 @@ typedef struct RichString_ {
}*/
}*/
#ifndef CLAMP
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
#endif
#define charBytes(n) (sizeof(CharType) * (n))
#define charBytes(n) (sizeof(CharType) * (n))
static
void
RichString_extendLen
(
RichString
*
this
,
int
len
)
{
static
void
RichString_extendLen
(
RichString
*
this
,
int
len
)
{
...
@@ -103,6 +107,7 @@ static inline void RichString_writeFrom(RichString* this, int attrs, const char*
...
@@ -103,6 +107,7 @@ static inline void RichString_writeFrom(RichString* this, int attrs, const char*
inline
void
RichString_setAttrn
(
RichString
*
this
,
int
attrs
,
int
start
,
int
finish
)
{
inline
void
RichString_setAttrn
(
RichString
*
this
,
int
attrs
,
int
start
,
int
finish
)
{
cchar_t
*
ch
=
this
->
chptr
+
start
;
cchar_t
*
ch
=
this
->
chptr
+
start
;
finish
=
CLAMP
(
finish
,
0
,
this
->
chlen
-
1
);
for
(
int
i
=
start
;
i
<=
finish
;
i
++
)
{
for
(
int
i
=
start
;
i
<=
finish
;
i
++
)
{
ch
->
attr
=
attrs
;
ch
->
attr
=
attrs
;
ch
++
;
ch
++
;
...
@@ -132,6 +137,7 @@ static inline void RichString_writeFrom(RichString* this, int attrs, const char*
...
@@ -132,6 +137,7 @@ static inline void RichString_writeFrom(RichString* this, int attrs, const char*
void
RichString_setAttrn
(
RichString
*
this
,
int
attrs
,
int
start
,
int
finish
)
{
void
RichString_setAttrn
(
RichString
*
this
,
int
attrs
,
int
start
,
int
finish
)
{
chtype
*
ch
=
this
->
chptr
+
start
;
chtype
*
ch
=
this
->
chptr
+
start
;
finish
=
CLAMP
(
finish
,
0
,
this
->
chlen
-
1
);
for
(
int
i
=
start
;
i
<=
finish
;
i
++
)
{
for
(
int
i
=
start
;
i
<=
finish
;
i
++
)
{
*
ch
=
(
*
ch
&
0xff
)
|
attrs
;
*
ch
=
(
*
ch
&
0xff
)
|
attrs
;
ch
++
;
ch
++
;
...
...
RichString.h
View file @
858af250
...
@@ -59,6 +59,10 @@ typedef struct RichString_ {
...
@@ -59,6 +59,10 @@ typedef struct RichString_ {
}
RichString
;
}
RichString
;
#ifndef CLAMP
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
#endif
#define charBytes(n) (sizeof(CharType) * (n))
#define charBytes(n) (sizeof(CharType) * (n))
#define RichString_setLen(this, len) do{ if(len < RICHSTRING_MAXLEN && this->chlen < RICHSTRING_MAXLEN) { RichString_setChar(this,len,0); this->chlen=len; } else RichString_extendLen(this,len); }while(0)
#define RichString_setLen(this, len) do{ if(len < RICHSTRING_MAXLEN && this->chlen < RICHSTRING_MAXLEN) { RichString_setChar(this,len,0); this->chlen=len; } else RichString_extendLen(this,len); }while(0)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment