[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

misc_conv reading too much?



It appears that since the misc_conv conversation module's read_string()
function is using unbuffered io and is reading rather large chunks.
This means that the misc_conv conversation may be eating stdin that
was not intended for it.  For example, using misc_conv to retrieve
a user's name or password, then fork()ing or exec()ing another process.
If you're piping input into this program, some portion of the input will
be eaten by read_string() before it ever reaches the destination.

Here's a small diff to misc_conv to read a line at a time.
Rob

--- misc_conv.c 2002/03/27 06:18:21     1.9
+++ misc_conv.c 2002/05/30 17:27:59
@@ -181,7 +181,13 @@
            D(("<failed to set alarm>"));
            break;
        } else {
-           nc = read(STDIN_FILENO, line, INPUTSIZE-1);
+           for( nc = 0; (nc < INPUTSIZE) && (line[nc?nc-1:0] != '\n'); nc++ ) {
+               if( read(STDIN_FILENO, line+nc, 1) != 1 ) {
+                       break;
+               }
+           }
+           line[nc] = '\0';
+           
            if (have_term) {
                (void) tcsetattr(STDIN_FILENO, TCSADRAIN, &term_before);
                if (!echo || expired)             /* do we need a newline? */





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index] []