Bug#521870: [libinotify-ocaml-dev] Bad string length
Subject: libinotify-ocaml-dev: Bug in file inotify.ml, bad string length
Package: libinotify-ocaml-dev
Version: 0.7
Severity: important
There is a bug in the file inotify.ml.
I contacted the author but he doesn't reply my emails.
There is a temporary buffer made of lots of \0.
The problem is that we create a new string based on this buffer. The len
is wrong so the fresh string contains too much \0.
For example: say you're monitoring a directory then you create a new
directory named "a".
Because of this event, inotify will notify that a new directory has been
created. Its length ? 16 chars.
That's right 16 chars instead of 1. I noticed this error because of a
badly working concat.
Here is a small working patch already submitted to the author :
Replace the old 'read' function by this one :
let read fd =
let ss = struct_size () in
let toread = to_read fd in
let ret = ref [] in
let buf = String.make toread '\000' in
let toread = Unix.read fd buf 0 toread in
let i = ref 0 in
while !i < toread
do
let wd, l, cookie, len = convert (String.sub buf !i ss) in
let s = if len > 0 then
let str_tmp = (String.sub buf (!i + ss) len) in
let len2 = (String.index str_tmp '\000') in
Some (String.sub str_tmp 0 len2)
else
None
in
ret := (wd, l, cookie, s) :: !ret;
i := !i + (ss + len);
done;
List.rev !ret
Gregory "Dest" BELLIER.
-- System Information:
Debian Release: 4.0
APT prefers oldstable
APT policy: (500, 'oldstable')
Architecture: i386 (i686)
Shell: /bin/sh linked to /bin/bash
Kernel: Linux 2.6.25.3
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
Reply to: