diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2017-09-08 21:53:43 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2017-09-08 22:00:01 -0400 |
commit | ee701cc53db14144df5321e5861e5bcbde220193 (patch) | |
tree | d9f9012fa7a1cb1175adf45bd9a65072a342e13a /nslcd_systemd/util_test.go | |
parent | 5a7d3f0942dd7e661f63bb59be883e6e245c0ddd (diff) |
add a test for tricking the server into allocating huge buffers
Diffstat (limited to 'nslcd_systemd/util_test.go')
-rw-r--r-- | nslcd_systemd/util_test.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/nslcd_systemd/util_test.go b/nslcd_systemd/util_test.go index 15147b7..89cf7cb 100644 --- a/nslcd_systemd/util_test.go +++ b/nslcd_systemd/util_test.go @@ -191,3 +191,22 @@ func sdNotifyHandle(sock *net.UnixConn, fn func(dat []byte, oob []byte) error) e } } } + +func humanizeU64(n uint64) string { + str := fmt.Sprintf("%d", n) + bts := make([]byte, len(str)+(len(str)-1)/3) + + s := 0 + b := 0 + for s < len(str) && b < len(bts) { + if (s % 3 == 0 && s > 0) { + bts[len(bts)-1-b] = ',' + b++ + } + bts[len(bts)-1-b] = str[len(str)-1-s] + b++ + s++ + } + + return string(bts) +} |