tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: Kristaps Dzonsons <kristaps@bsd.lv>
To: tech@mdocml.bsd.lv
Cc: Ingo Schwarze <schwarze@usta.de>, espie@nerim.net
Subject: Re: mandocdb tools, sqlite3, and ohash
Date: Fri, 08 Jun 2012 12:29:26 +0200	[thread overview]
Message-ID: <4FD1D406.9020704@bsd.lv> (raw)
In-Reply-To: <20120607180605.GA295@iris.usta.de>

> So far, i have read the file mandocdb.c and found the following
> potential issues.  I'm calling them "potential" because this is
> mostly coming from code inspection without much testing.

Ingo,

Thanks for looking this over!  I'll commit this code in bsd.lv with the 
following changes so we can stop throwing huge diffs back and forth.

I hadn't tested the -d, -u, and -t since using ohash.  I now see that I 
hadn't initialised the hashes in the right place (thus, FPE and 
segfaults from using unitialised or zeroed data).  Fixed.

>   1. Function main, OP_UPDATE case:
>      Is calling ofmerge, i.e. dbopen with real=0, correct?
>      It calls dbclose with real=0, thus calling rename to MANDOC_DB,
>      thus clobbering the original database instead of adding to it?

Yes, that was ugly.  I moved dbopen() into main() where it belongs 
(along with the matching dbclose)).

>      So far, i cannot really test this suspicion
>      because mandocdb -d always dies with segfaults or floating
>      point exceptions for me, i would have to ivestigate those
>      crashes first.
>
>   2. Function main, rebuild case:
>      Shouldn't this create the new db first, then move it into place
>      atomically in case of success?  The remove(MANDOC_DB) seems
>      problematic:  It is deleting an existing database, then creating
>      a new one only considerably later, if at all.

Also fixed by removing the remove() entirely---dbclose() does its own 
rename, so no need to remove.

>   3. Function main, with multiple relative directories:  e.g.
>        # cd /usr; mandocdb share/man local/man
>      That causes the first chdir to change into /usr/share/man
>      and the second to try to change into /usr/share/man/local/man.
>      That may not be a new issue, though.

Oops, I thought I was handling that correctly.  This is now fixed by 
having the main() loop invoke path_reset(), which jumps into the cwd 
then into the base dir, before any relative-path operations.  This 
cleaned up a nice bit of code, I think.

>   4. Function dbopen with real=0:
>      There seems to be a race, open to symlink attacks,
>      between remove(file) and sqlite3_open(file);
>      some kind of O_EXCL or something might be required.

Fixed---good point.  Pity there's no O_TRUNC for sqlite3.

>   5. Function dirscan:
>      Shouldn't an argc argument be int instead of size_t?

Also fixed.  Well, fixed because dirscan() is no more, now that I've 
moved the fchdir()/chdir() into reset_path().  The filescan() loop is 
now right in main().

>   6. Functions dirtreescan and filescan:
>      When a manual page has multiple hard links (MLINKS),
>      it looks like a matter of chance which one ends up being
>      used.  Is there any check whether the NAME agrees with
>      the file name?  Not sure anything is broken here, just
>      wondering.

Nope.  And that'd be a little tricksy given that a single file can have 
many NAMEs.

>   7. Function filescan:
>      Calling mandocdb -d with file argument(s) triggers
>      the use_all assertion.

Fixed (-d, -u, and -t all raise use_all).

>   8. Function inocheck:
>      The memset(&id seems pointless, values are assigned
>      to the members right afterwards.

It's not pointless at all.  That ohash_lookup_memory() is using the 
struct address and size, which may consist of padding.  memset() zeroes 
the padding bytes, otherwise we might lookup based on random values in 
the padding.

>   9. Function parse_mdoc_Fd:
>      This function triggers an assertion on #include<>.
>      Admittedly, that's not a new problem.
>      I'm not fixing it right now to avoid merge conflicts,
>      but we shouldn't forget.

Fixed anyway.

Thanks again, Ingo!  I really appreciate it!

Best,

Kristaps
--
 To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv

  reply	other threads:[~2012-06-08 10:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-07 15:15 Kristaps Dzonsons
2012-06-07 16:29 ` Joerg Sonnenberger
2012-06-07 18:06 ` Ingo Schwarze
2012-06-08 10:29   ` Kristaps Dzonsons [this message]
2012-06-08 12:25     ` Joerg Sonnenberger
2012-06-08 13:38       ` Kristaps Dzonsons
2012-06-08 14:13         ` Joerg Sonnenberger
     [not found] ` <20120607165106.GA8819@lain.home>
2012-06-08 12:05   ` Kristaps Dzonsons

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4FD1D406.9020704@bsd.lv \
    --to=kristaps@bsd.lv \
    --cc=espie@nerim.net \
    --cc=schwarze@usta.de \
    --cc=tech@mdocml.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).