Menu

#6 Keyphrase not detected and timeout

v1.0 (example)
closed
nobody
None
5
2023-01-01
2010-06-15
Anonymous
No

Keyphrase is not detected and timeout when -w option.
When keyphrase is at the end of a large text and when read is split between two reads then empty will not detect it and it will fail with "empty: Data stream is empty. Keyphrase wasn't found. Exit on timeout". The reason lies in watch4str: largv=0 assignement after each read. Due to the part of the keyphrase from the first read() is overwriten by the second part of the keyphrase (and not appended, as it suppose to) in the next read(), therefor not detected. The watch4str will make another attempt to read() and because this is the last line in the text it will remain blocked select() will exit on timeout.

Discussion

  • Sergey Mironov

    Sergey Mironov - 2010-07-20

    Hi. Let me suggest a patch that (i hope) can fix this issue. Note, that this patch slightly changes behavior of -w option: empty will flush buffers after each '\n' received. So regexp like "assword:\n\n" will never match. But does anybody need it?.

    PS I know, looks like it is bad place for patch :) Where should I send it?

    From 154a1849caefb764987386433639a0e0a4894e33 Mon Sep 17 00:00:00 2001
    From: Sergey Mironov <ierton@gmail.com>
    Date: Tue, 20 Jul 2010 16:50:38 +0400
    Subject: [PATCH] Fix -w regex match issues (probably)

    ---
    empty.c | 24 ++++++++++++++++--------
    1 files changed, 16 insertions(+), 8 deletions(-)

    diff --git a/empty.c b/empty.c
    index 555dcb5..86ca53e 100644
    --- a/empty.c
    +++ b/empty.c
    @@ -105,7 +105,7 @@

    #define tmpdir "/tmp"
    #define program "empty"
    -#define version "0.6.18b"
    +#define version "0.6.19b"

    /* -------------------------------------------------------------------------- */
    static void usage(void);
    @@ -874,8 +874,10 @@ int watch4str(int ifd, int ofd, int argc, char *argv[],
    struct timeval tv;

    int argt = 0;
    - int largv = 0;
    + int bread = 0;
    char *resp = NULL;
    + int found;
    + int i;

    stime = time(0);
    @@ -893,11 +895,10 @@ int watch4str(int ifd, int ofd, int argc, char *argv[],
    perrx(255, "Fatal select()");

    if (n > 0 && FD_ISSET(ifd, &rfd)) {
    - largv = 0;
    - if ((cc = read(ifd, buf + largv, sizeof(buf) - largv)) > 0) {
    + if ((cc = read(ifd, buf + bread, sizeof(buf)-bread-1)) > 0) {
    stime = time(0);

    - buf[cc + largv] = '\0';
    + buf[cc + bread] = '\0';

    if (vflg)
    (void)printf("%s", buf);
    @@ -914,10 +915,17 @@ int watch4str(int ifd, int ofd, int argc, char *argv[],
    return (argt + 1) / 2;
    }

    - if (largv == 0)
    - largv = longargv(argc, argv);
    + for(found=0,i=bread; i<bread+cc; i++) {
    + if(buf[i] == '\n') {
    + memmove(buf, buf+i+1, bread+cc-i-1);
    + bread = bread+cc-i-1;
    + found = 1;
    + break;
    + }
    + }

    - memmove(buf, buf + cc - largv, largv);
    + if(!found)
    + bread += cc;
    }

    if (cc <= 0) {
    --
    1.5.2.1

     
  • Sergey Mironov

    Sergey Mironov - 2010-07-27

    I've made a git branch of empty which contains patch reported and some other. Please take a look at http://git.ierton.ru/?p=empty.git;a=summary

     
  • mezantrop

    mezantrop - 2023-01-01

    Thank you so much. Accepted. Better late than never, right? :)

     
  • mezantrop

    mezantrop - 2023-01-01
    • status: open --> closed
    • Group: --> v1.0 (example)
     

Log in to post a comment.

MongoDB Logo MongoDB
Gen AI apps are built with MongoDB Atlas
Atlas offers built-in vector search and global availability across 125+ regions. Start building AI apps faster, all in one place.