Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (17 years ago)
Author:
Bruno Cornec
Message:

Update to busybox 1.7.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.5/mindi-busybox/libbb/bb_askpass.c

    r821 r1765  
    99 */
    1010
    11 #include <stdio.h>
    12 #include <string.h>
    13 #include <unistd.h>
    14 #include <fcntl.h>
    15 #include <signal.h>
    1611#include <termios.h>
    17 #include <sys/ioctl.h>
    1812
    1913#include "libbb.h"
    20 #define PWD_BUFFER_SIZE 256
    21 
    2214
    2315/* do nothing signal handler */
     
    2820char *bb_askpass(int timeout, const char * prompt)
    2921{
     22    /* Was static char[BIGNUM] */
     23    enum { sizeof_passwd = 128 };
     24    static char *passwd;
     25
    3026    char *ret;
    31     int i, size;
     27    int i;
    3228    struct sigaction sa;
    3329    struct termios old, new;
    34     static char passwd[PWD_BUFFER_SIZE];
     30
     31    if (!passwd)
     32        passwd = xmalloc(sizeof_passwd);
     33    memset(passwd, 0, sizeof_passwd);
    3534
    3635    tcgetattr(STDIN_FILENO, &old);
    3736    tcflush(STDIN_FILENO, TCIFLUSH);
    38 
    39     size = sizeof(passwd);
    40     ret = passwd;
    41     memset(passwd, 0, size);
    4237
    4338    fputs(prompt, stdout);
     
    5651    }
    5752
    58     if (read(STDIN_FILENO, passwd, size-1) <= 0) {
    59         ret = NULL;
    60     } else {
    61         for(i = 0; i < size && passwd[i]; i++) {
    62             if (passwd[i]== '\r' || passwd[i] == '\n') {
    63                 passwd[i]= 0;
    64                 break;
    65             }
    66         }
     53    ret = NULL;
     54    /* On timeout, read will hopefully be interrupted by SIGALRM,
     55     * and we return NULL */
     56    if (read(STDIN_FILENO, passwd, sizeof_passwd-1) > 0) {
     57        ret = passwd;
     58        i = 0;
     59        /* Last byte is guaranteed to be 0
     60           (read did not overwrite it) */
     61        do {
     62            if (passwd[i] == '\r' || passwd[i] == '\n')
     63                passwd[i] = '\0';
     64        } while (passwd[i++]);
    6765    }
    6866
     
    7270
    7371    tcsetattr(STDIN_FILENO, TCSANOW, &old);
    74     fputs("\n", stdout);
     72    putchar('\n');
    7573    fflush(stdout);
    7674    return ret;
    7775}
    78 
Note: See TracChangeset for help on using the changeset viewer.