Changeset 166

Show
Ignore:
Timestamp:
08/03/04 17:25:03 (9 years ago)
Author:
alexcv
Message:

Removing some constants and magic numbers

Location:
trunk/wifidog/src
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog/src/wdctl.c

    r165 r166  
    8282{ 
    8383 
    84         strncpy(config.socket, DEFAULT_SOCK, sizeof(config.socket)); 
     84        config.socket = strdup(DEFAULT_SOCK); 
     85        config.command = WDCTL_UNDEF; 
    8586} 
    8687 
     
    104105            case 's': 
    105106                if (optarg) { 
    106                     strncpy(config.socket, optarg, sizeof(config.socket)); 
     107                    free(config.socket); 
     108                    config.socket = strdup(optarg); 
    107109                } 
    108110                break; 
     
    120122    } 
    121123 
    122     config.command = WDCTL_UNDEF; 
    123124    if (strcmp(*(argv + optind), "status") == 0) { 
    124125            config.command = WDCTL_STATUS; 
     
    151152        /* Connect to socket */ 
    152153        sock = socket(AF_UNIX, SOCK_STREAM, 0); 
     154        memset(&sa_un, 0, sizeof(sa_un)); 
    153155        sa_un.sun_family = AF_UNIX; 
    154         strcpy(sa_un.sun_path, sock_name); 
     156        strncpy(sa_un.sun_path, sock_name, (sizeof(sa_un.sun_path) - 1)); 
    155157 
    156158        if (connect(sock, (struct sockaddr *)&sa_un,  
  • trunk/wifidog/src/wdctl.h

    r150 r166  
    3535#define WDCTL_KILL      3 
    3636 
    37 /** Struct is 104 char long for unix domain socket path */ 
    38 #define MAX_SOCK_NAME_LEN 103 
    39  
    4037typedef struct { 
    41         char    socket[MAX_SOCK_NAME_LEN]; 
     38        char    *socket; 
    4239        int     command; 
    4340        char    *param; 
  • trunk/wifidog/src/wdctl_thread.c

    r165 r166  
    7474        debug(LOG_DEBUG, "Starting wdctl."); 
    7575 
     76        memset(&sa_un, 0, sizeof(sa_un)); 
    7677        sock_name = (char *)arg; 
    7778        debug(LOG_DEBUG, "Socket name: %s", sock_name); 
    7879 
    79         /* 104 is magic */ 
    80         if (strlen(sock_name) > 103) { 
     80        if (strlen(sock_name) > (sizeof(sa_un.sun_path) - 1)) { 
    8181                /* TODO: Die handler with logging.... */ 
    8282                exit(1); 
     
    9393 
    9494        debug(LOG_DEBUG, "Filling sockaddr_un"); 
    95         strcpy(sa_un.sun_path, sock_name); 
     95        strcpy(sa_un.sun_path, sock_name); /* XXX No size check because we 
     96                                            * check a few lines before. */ 
    9697        sa_un.sun_family = AF_UNIX; 
    9798         
     
    107108        } 
    108109 
    109         if (listen(sock, 16)) { 
     110        if (listen(sock, 5)) { 
    110111                debug(LOG_ERR, "Could not listen on control socket: %s", 
    111112                                strerror(errno));