続 nbpwd_mkdb

src/lib/libc/gen/pw_scan.c:gettime() の第一引数は time_t * なので、見事に pw_change の次に位置する pw_class を 0 で上書きしちゃってるね。で、ぬるぽって終了ね。

koharu# gdb obj.i386/pwd_mkdb
GNU gdb 6.5
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386--netbsdelf"...
(gdb) r -p -L -d /tmp/ /tmp/etc/master.passwd
Starting program: /usr/obj.i386/tools/pwd_mkdb/pwd_mkdb -p -L -d /tmp/ /tmp/etc/master.passwd

Program received signal SIGSEGV, Segmentation fault.
0x0804a3d3 in putdbents (dp=0xbb911040, pw=0xbfbfec8c,
    __nbcompat_passwd=0x8056a4e "*", flags=0,
    fn=0x8069fc0 "/tmp//etc/pwd.db.tmp", lineno=0, dbflg=8, uid_dbflg=8)
    at /usr/src/tools/pwd_mkdb/../../usr.sbin/pwd_mkdb/pwd_mkdb.c:656
656             COMPACT(pwd.pw_class);
(gdb) l
651             p += sizeof(pwd.pw_uid);
652             memmove(p, &pwd.pw_gid, sizeof(pwd.pw_gid));
653             p += sizeof(pwd.pw_gid);
654             memmove(p, &pwd.pw_change, sizeof(pwd.pw_change));
655             p += sizeof(pwd.pw_change);
656             COMPACT(pwd.pw_class);
657             COMPACT(pwd.pw_gecos);
658             COMPACT(pwd.pw_dir);
659             COMPACT(pwd.pw_shell);
660             memmove(p, &pwd.pw_expire, sizeof(pwd.pw_expire));
(gdb) p pwd
$1 = {pw_name = 0x80683a0 "root", pw_passwd = 0x80683a5 "", pw_uid = 0,
  pw_gid = 0, pw_change = 0, pw_class = 0x0, pw_gecos = 0x80683af "Charlie &",
  pw_dir = 0x80683b9 "/root", pw_shell = 0x80683bf "/bin/csh", pw_expire = 0}
(gdb) bt
#0  0x0804a3d3 in putdbents (dp=0xbb911040, pw=0xbfbfec8c,
    __nbcompat_passwd=0x8056a4e "*", flags=0,
    fn=0x8069fc0 "/tmp//etc/pwd.db.tmp", lineno=0, dbflg=8, uid_dbflg=8)
    at /usr/src/tools/pwd_mkdb/../../usr.sbin/pwd_mkdb/pwd_mkdb.c:656
#1  0x0804af3e in main (argc=Cannot access memory at address 0x0
)
    at /usr/src/tools/pwd_mkdb/../../usr.sbin/pwd_mkdb/pwd_mkdb.c:349
(gdb) b pwd_mkdb.c:501
Breakpoint 1 at 0x804a8ab: file /usr/src/tools/pwd_mkdb/../../usr.sbin/pwd_mkdb/pwd_mkdb.c, line 501.
(gdb) b pw_scan.c:198
Breakpoint 2 at 0x804b73b: file /usr/src/tools/compat/../../lib/libc/gen/pw_scan.c, line 198.
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y

Starting program: /usr/obj.i386/tools/pwd_mkdb/pwd_mkdb -p -L -d /tmp/ /tmp/etc/master.passwd

Breakpoint 1, scan (fp=0xbbbccf40, pw=0xbfbfec8c, flags=0xbfbfec70,
    lineno=0xbfbfecb4)
    at /usr/src/tools/pwd_mkdb/../../usr.sbin/pwd_mkdb/pwd_mkdb.c:501
501             if (!pw_scan(line, pw, &oflags)) {
(gdb) p pw
$2 = (struct __nbcompat_passwd *) 0xbfbfec8c
(gdb) p *pw
$3 = {pw_name = 0xbbb859ac "1?\203?\020\215e?[^_??\215v",
  pw_passwd = 0xbbbd2e74 "", pw_uid = -1077940948, pw_gid = -1077941064,
  pw_change = -1145546217, pw_class = 0xbbbf5e6c "?\001", pw_gecos = 0x0,
  pw_dir = 0x0, pw_shell = 0xbbbc41d8 "\230M\016", pw_expire = 134574564}
(gdb) c
Continuing.

Breakpoint 2, __nbcompat_pw_scan (
    bp=0x80683aa ":0:0:Charlie &:/root:/bin/csh", pw=0xbfbfec8c,
    flags=0xbfbfe778) at /usr/src/tools/compat/../../lib/libc/gen/pw_scan.c:198
198                     pw->pw_class = strsep(&bp, ":");        /* class */
(gdb) p *pw
$4 = {pw_name = 0x80683a0 "root", pw_passwd = 0x80683a5 "", pw_uid = 0,
  pw_gid = 0, pw_change = -1145546217, pw_class = 0xbbbf5e6c "?\001",
  pw_gecos = 0x0, pw_dir = 0x0, pw_shell = 0xbbbc41d8 "\230M\016",
  pw_expire = 134574564}
(gdb) n
199                     if (!(p = strsep(&bp, ":")))            /* change */
(gdb) p *pw
$5 = {pw_name = 0x80683a0 "root", pw_passwd = 0x80683a5 "", pw_uid = 0,
  pw_gid = 0, pw_change = -1145546217, pw_class = 0x80683aa "",
  pw_gecos = 0x0, pw_dir = 0x0, pw_shell = 0xbbbc41d8 "\230M\016",
  pw_expire = 134574564}
(gdb) n
201                     if (!gettime(&pw->pw_change, p, flags, dowarn, _PASSWORD_NOCHG))
(gdb) p *pw
$6 = {pw_name = 0x80683a0 "root", pw_passwd = 0x80683a5 "", pw_uid = 0,
  pw_gid = 0, pw_change = -1145546217, pw_class = 0x80683aa "",
  pw_gecos = 0x0, pw_dir = 0x0, pw_shell = 0xbbbc41d8 "\230M\016",
  pw_expire = 134574564}
(gdb) p/x *pw
$7 = {pw_name = 0x80683a0, pw_passwd = 0x80683a5, pw_uid = 0x0, pw_gid = 0x0,
  pw_change = 0xbbb85a17, pw_class = 0x80683aa, pw_gecos = 0x0, pw_dir = 0x0,
  pw_shell = 0xbbbc41d8, pw_expire = 0x80571e4}
(gdb) s
gettime (res=0xbfbfec9c, p=0x80683ab "0", flags=0xbfbfe778, dowarn=1, flag=4)
    at /usr/src/tools/compat/../../lib/libc/gen/pw_scan.c:69
69              if (*p == '\0') {
(gdb) p res
$8 = (time_t *) 0xbfbfec9c
(gdb) p *res
$9 = 578294371480787479
(gdb) n
74              l = strtoll(p, &ep, 0);
(gdb)
75              if (p == ep || *ep != '\0') {
(gdb)
79              if (errno == ERANGE && (l == LLONG_MAX || l == LLONG_MIN)) {
(gdb)
84              *res = (time_t)l;
(gdb)
93      }
(gdb) p *res
$10 = 0
(gdb) n
__nbcompat_pw_scan (bp=0x80683ad "0:Charlie &:/root:/bin/csh", pw=0xbfbfec8c,
    flags=0xbfbfe778) at /usr/src/tools/compat/../../lib/libc/gen/pw_scan.c:204
204                     if (!(p = strsep(&bp, ":")))            /* expire */
(gdb) p *pw
$11 = {pw_name = 0x80683a0 "root", pw_passwd = 0x80683a5 "", pw_uid = 0,
  pw_gid = 0, pw_change = 0, pw_class = 0x0, pw_gecos = 0x0, pw_dir = 0x0,
  pw_shell = 0xbbbc41d8 "\230M\016", pw_expire = 134574564}
(gdb) 
広告を非表示にする