Bonjour,

Mon programme récupère les arguments de la ligne de commande par le biais de getopt ;

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
char *server_addr = NULL , *serv_regexp = NULL , *host_regexp = NULL , *conf_file = NULL , *netw_error = NULL ;
 
 
 
int main( int argc , char *argv[] )
{
 
 
 
        /* errno initialisation and no-root launch protection */
        errno = 0 ;
 
 
        /* Analysing arguments */
        while( ( getoptret = getopt( argc , argv , "f:vs:p:h:r:" ) ) != -1 )
        {
                switch( getoptret )
                {
                        case 's':
                                server_addr = strdup( optarg );
                                break ;
                        case 'p':
                                port = strtol( optarg , NULL , 10 );
                                break ;
                        case 'h':
                                host_regexp = strdup( optarg );
                                break ;
                        case 'r':
                                serv_regexp = strdup( optarg ) ;
                                break ;
                        case 'f':
                                conf_file =strdup( optarg )  ;
                                break ;
                        case '?':
                                if( optopt == 's' || optopt == 'p' || optopt == 'h' || optopt == 'r' || optopt == 'f' )
                                {
                                        fprintf( stderr , "Option -%c need a parameter\n", optopt );
                                        exit( FALSE );
                                }
                        case 'v':
                                help_flag = true ;
                                break ;
 
 
                }
        }
La récupération des arguments se déroule bien sauf dans un cas précis, si je
passe .* comme argument à -r et/ou -s .
Je développe sous unix, le shell remplace mon .* ( si je ne le protège pas par des quotes ) par '.' et '..' .
Mon programme segfault dans ce cas là et ma variable serv_regex est NULL.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
argv[0] = 0xffbffd64 "./client"
(dbx) p argv[1]
argv[1] = 0xffbffd6d "-s"
(dbx) p argv[2]
argv[2] = 0xffbffd70 "1.1.1.1"
(dbx) p argv[3]
argv[3] = 0xffbffd7a "-p"
(dbx) p argv[4]
argv[4] = 0xffbffd7d "4521"
(dbx) p argv[5]
argv[5] = 0xffbffd82 "-h"
(dbx) p argv[6]
argv[6] = 0xffbffd85 "."
(dbx) p argv[7]
argv[7] = 0xffbffd87 ".."
(dbx) p argv[8]
argv[8] = 0xffbffd8a "-r"
(dbx) p argv[9]
argv[9] = 0xffbffd8d "."
(dbx) p argv[10]
argv[10] = 0xffbffd8f ".."
(dbx) p argv[11]
argv[11] = (nil)
(dbx) p serv_regexp
serv_regexp = (nil)
Une idée de comment je pourrais protéger mon programme d'une saisie utilisateur .* ?

Merci.