procps-ng の master の sysctl を使っていたら Segmentation Fault を起こしたので issue をオープンしといた
問題のあるコミット
以下のような感じ
diff --git a/sysctl.c b/sysctl.c index 29f31af..be05722 100644 --- a/sysctl.c +++ b/sysctl.c @@ -158,6 +158,8 @@ static char *StripLeadingAndTrailingSpaces(char *oneline) /* * Read a sysctl setting */ +#define IOBUFSIZ (128<<10) +static char *iobuf; static int ReadSetting(const char *restrict const name) { int rc = 0; @@ -220,6 +222,9 @@ static int ReadSetting(const char *restrict const name) fp = fopen(tmpname, "r"); + if (iobuf) (fp, iobuf, _IOFBF, IOBUFSIZ); + if (!fp) { switch (errno) { case ENOENT: @@ -430,6 +435,9 @@ static int WriteSetting(const char *setting) fp = fopen(tmpname, "w"); + if (iobuf) + setvbuf(fp, iobuf, _IOFBF, IOBUFSIZ); + if (!fp) { switch (errno) { case ENOENT: @@ -793,6 +801,8 @@ int main(int argc, char *argv[]) argc -= optind; argv += optind; + iobuf = (char*)malloc(IOBUFSIZ); /* Allow to fail */ + if (DisplayAllOpt) return DisplayAll(PROC_PATH);
非特権ユーザで sysctl を実行すると、権限が足りない場合に fopen(3) が EACCESS で失敗して NULL を返すのだが、エラーを確認せずに setvbuf(3) しちゃって ぬるぽ で ガッ SIGSEGV するのだった
$ /usr/local/sbin/sysctl net.ipv4.tcp_fastopen_key Segmentation fault (core dumped) $ /usr/local/sbin/sysctl -w vm.overcommit_ratio=0 Segmentation fault (core dumped)
本来は以下のような挙動をとるはず
$ /usr/local/sbin/sysctl net.ipv4.tcp_fastopen_key sysctl: permission denied on key 'net.ipv4.tcp_fastopen_key' $ /usr/local/sbin/sysctl -w vm.overcommit_ratio=0 sysctl: permission denied on key 'vm.overcommit_ratio'
感想
- まだ master ブランチに入ってるだけでリリースされてないので、ささっと直してくれるだろう
- わりと「うっかり」したバグだよなぁ
- 何も反応なかったらパッチを送ってみよ