This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug network/18126] New: libresolv res_init() does not correctly inititalize internals


https://sourceware.org/bugzilla/show_bug.cgi?id=18126

            Bug ID: 18126
           Summary: libresolv res_init() does not correctly inititalize
                    internals
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: network
          Assignee: unassigned at sourceware dot org
          Reporter: sourceware-bugs at internot dot info

Contrary to what one would think, res_init() does not correctly inititialize
the internals for further use by the libresolv family, and others.

When you call res_init(), it correctly "keeps" these:

        if (!_res.retrans)
                _res.retrans = RES_TIMEOUT;
        if (!_res.retry)
                _res.retry = 4;
        if (!(_res.options & RES_INIT))
                _res.options = RES_DEFAULT;
        else if (_res.nscount > 0)
                __res_iclose (&_res, true);     /* Close any VC sockets.  */


then calls __res_vinit():

        return (__res_vinit(&_res, 1));



However, programs that use the libresolv family and others, use the hidden
function, "__res_maybe_init".

__res_maybe_init determines if res_init(__res_vinit()) needs to be called or
not.

It does this:

        static time_t last_mtime;
        struct stat statbuf;
        int ret;

        if (resp->options & RES_INIT) {
                ret = stat (_PATH_RESCONF, &statbuf);
                __libc_lock_lock (lock);
                if ((ret == 0) && (last_mtime != statbuf.st_mtim.tv_sec)) {
                        last_mtime = statbuf.st_mtime;
                        atomicinc (__res_initstamp);
                }
                __libc_lock_unlock (lock);
                if (__res_initstamp != resp->_u._ext.initstamp) {
                        if (resp->nscount > 0)
                                __res_iclose (resp, true);
                        return __res_vinit (resp, 1);
                }
                return 0;


Since the internals have been initialized by res_init(), we don't need to
reinitalize, normally. The program checks if we do need to reinitalize, such as
due to the change in modifcation date of /etc/resolv.conf.

However, "last_mtime" is never set when using res_init(), so upon the first run
of __res_maybe_init(), it will always run __res_vinit(). This will wipe all
changes except for the ones that are kept, mentioned above.


"last_mtime" should be taken into consideration and handled, when calling
res_init().

-- 
You are receiving this mail because:
You are on the CC list for the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]