提交 23b8e3bc 编写于 作者: R Rich Felker

fix off-by-one error in getgrnam_r and getgrgid_r, clobbering gr_name

bug report and patch by Michael Forney. the terminating null pointer
at the end of the gr_mem array was overwriting the beginning of the
string data, causing the gr_name member to always be a zero-length
string.
上级 211264e4
...@@ -26,14 +26,14 @@ static int getgr_r(const char *name, gid_t gid, struct group *gr, char *buf, siz ...@@ -26,14 +26,14 @@ static int getgr_r(const char *name, gid_t gid, struct group *gr, char *buf, siz
while (__getgrent_a(f, gr, &line, &len, &mem, &nmem)) { while (__getgrent_a(f, gr, &line, &len, &mem, &nmem)) {
if (name && !strcmp(name, gr->gr_name) if (name && !strcmp(name, gr->gr_name)
|| !name && gr->gr_gid == gid) { || !name && gr->gr_gid == gid) {
if (size < len + nmem*sizeof(char *) + 32) { if (size < len + (nmem+1)*sizeof(char *) + 32) {
rv = ERANGE; rv = ERANGE;
break; break;
} }
*res = gr; *res = gr;
buf += (16-(uintptr_t)buf)%16; buf += (16-(uintptr_t)buf)%16;
gr->gr_mem = (void *)buf; gr->gr_mem = (void *)buf;
buf += nmem*sizeof(char *); buf += (nmem+1)*sizeof(char *);
memcpy(buf, line, len); memcpy(buf, line, len);
FIX(name); FIX(name);
FIX(passwd); FIX(passwd);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册