Bonjour,

j'essaie de réaliser un petit programme assez simple avec un appel system sous linux.

Voici le programme qui fait l'appel système :

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
#include <stdio.h>
#include <stdlib.h>
#include <crypt.h>
#include <unistd.h>
#include <string.h>
 
int main (void) 
{
	char pid[16];
 
	// get pid of this programme and increment
	int intPid = getpid() + 1;
	printf("PID : %d\n",intPid);
 
	// prepare the call system
	char str1[50] = "./niveau4 ";
 
	// change int to string
	sprintf(pid, "%d", intPid);
 
	// prepare the pass
	char pass[33];
	sprintf(pass, "%s", crypt(pid, "$1$awesome"));
 
	// concat the call with the argument
	strcat(str1,pass);
 
	// check the value before call to system
	printf("String avant appel : \n%s\n", str1);
 
	// proceed to call
	system(str1);
 
	return 0;
}
Et le programme qui est appelé :

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
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <crypt.h>
 
 
int main (int argc, char *argv[]) {
  char pid[16];
  snprintf(pid, sizeof(pid), "%i", getpid());
 
  // print the value passed in argument (problem appear here)
  printf("Argument: %s\n", argv[1]);
 
  if(argc != 2) 
  {
  	return 0;
  }
 
  // print the argument attempted
  printf("\nCrypt %s\n",  crypt(pid, "$1$awesome"));
 
  // check if pass is correct
  if(strcmp(argv[1], crypt(pid, "$1$awesome")) == 0) 
  {
    printf("WIN!\n");
    system("/bin/sh -p");
  }
  else{
    printf("phail... :/\n");
  }
}
Et voila ce qui sort sur la console :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
PID : 12219
String avant appel : 
./niveau4 $1$awesome$cKZdLD/khV9HjalUTy1Z0/
Argument : /khV9HjalUTy1Z0/
 
Crypt $1$awesome$cKZdLD/khV9HjalUTy1Z0/
phail... :/
Comme on peut le voir, le string avant appel à l'air correct mais seul une partie du string est récupérer dans le deuxième programme.

Quelqu'un voit-il mon erreur ?

Merci d'avance de votre aide