Skip to content

Commit 9e50d21

Browse files
authored
Merge pull request #313 from ljxfstorm/f/relro-bitwise-bind-now
fix(relro): use bitwise check for DF_BIND_NOW flag
2 parents c006501 + 0a57b02 commit 9e50d21

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

pkg/checksec/relro.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,21 @@ func RELRO(name string) *relro {
3131
return &res
3232
}
3333

34-
// check both bind and bind_flag.
34+
// check both bind and flags.
3535
// if DT_BIND_NOW == 0, then it is set
36-
// if DT_FLAGS == 8, then DF_BIND_NOW is set
36+
// if (DT_FLAGS & 0x8) > 0, then DF_BIND_NOW is set
3737
// this is depending on the compiler version used.
3838
bind, _ := file.DynValue(elf.DT_BIND_NOW)
3939
if len(bind) == 0 {
4040
bind, _ = DynValueFromPTDynamic(file, elf.DT_BIND_NOW)
4141
}
42-
bind_flag, _ := file.DynValue(elf.DT_FLAGS)
43-
if len(bind_flag) == 0 {
44-
bind_flag, _ = DynValueFromPTDynamic(file, elf.DT_FLAGS)
42+
flags, _ := file.DynValue(elf.DT_FLAGS)
43+
if len(flags) == 0 {
44+
flags, _ = DynValueFromPTDynamic(file, elf.DT_FLAGS)
4545
}
4646

47-
if (len(bind) > 0 && bind[0] == 0) || (len(bind_flag) > 0 && bind_flag[0] == 8) {
47+
const DF_BIND_NOW = 0x8
48+
if (len(bind) > 0 && bind[0] == 0) || (len(flags) > 0 && (flags[0] & DF_BIND_NOW) > 0) {
4849
bindNow = true
4950
}
5051

0 commit comments

Comments
 (0)