stack smashing detected


 
Thread Tools Search this Thread
Top Forums Programming stack smashing detected
# 1  
Old 03-17-2010
stack smashing detected

Like you can see in the title this is my problem! Here is what appears in the terminal
SmilieSmilieSmilie
Code:
*** stack smashing detected ***: ./a.out terminated
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x48)[0x317de8]
/lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x0)[0x317da0]
./a.out[0x80491ea]
[0x7245202a]
======= Memory map: ========
00236000-00237000 r-xp 00000000 00:00 0          [vdso]
00237000-00375000 r-xp 00000000 07:00 3443       /lib/tls/i686/cmov/libc-2.10.1.so
00375000-00377000 r--p 0013e000 07:00 3443       /lib/tls/i686/cmov/libc-2.10.1.so
00377000-00378000 rw-p 00140000 07:00 3443       /lib/tls/i686/cmov/libc-2.10.1.so
00378000-0037b000 rw-p 00000000 00:00 0 
0089d000-008b8000 r-xp 00000000 07:00 1331       /lib/ld-2.10.1.so
008b8000-008b9000 r--p 0001a000 07:00 1331       /lib/ld-2.10.1.so
008b9000-008ba000 rw-p 0001b000 07:00 1331       /lib/ld-2.10.1.so
00943000-0094d000 r-xp 00000000 07:00 3460       /lib/tls/i686/cmov/libnss_files-2.10.1.so
0094d000-0094e000 r--p 00009000 07:00 3460       /lib/tls/i686/cmov/libnss_files-2.10.1.so
0094e000-0094f000 rw-p 0000a000 07:00 3460       /lib/tls/i686/cmov/libnss_files-2.10.1.so
00c81000-00c9d000 r-xp 00000000 07:00 1381       /lib/libgcc_s.so.1
00c9d000-00c9e000 r--p 0001b000 07:00 1381       /lib/libgcc_s.so.1
00c9e000-00c9f000 rw-p 0001c000 07:00 1381       /lib/libgcc_s.so.1
08048000-0804a000 r-xp 00000000 07:00 134593     /home/giovanni/Scrivania/progetto1/a.out
0804a000-0804b000 r--p 00001000 07:00 134593     /home/giovanni/Scrivania/progetto1/a.out
0804b000-0804c000 rw-p 00002000 07:00 134593     /home/giovanni/Scrivania/progetto1/a.out
0938d000-093ae000 rw-p 00000000 00:00 0          [heap]
b78cf000-b78d0000 rw-p 00000000 00:00 0 
b78dc000-b78e0000 rw-p 00000000 00:00 0 
bfe3d000-bfe52000 rw-p 00000000 00:00 0          [stack]
Aborted

What is the possible problem??
This is the client code
Code:
#include <netdb.h>
#include <sys/select.h>
#include <unistd.h>            // interfaccia Unix standard
#include <errno.h>             // codici di errore
#include <sys/types.h>         // tipi predefiniti
#include <arpa/inet.h>         // per convertire ind. IP 
#include <sys/socket.h>        // socket  
#include <stdio.h>             // i/o
#include <stdlib.h>            // utilita'standard
#include <string.h>            // stringhe
#include <fcntl.h>             // file a basso livello
#include <time.h>              // tempo 
#define MAX        256

int main(int argc, char *argv[])
{
    int sd,l,scelta,inizio;
    struct sockaddr_in serv_ind;
    struct hostent *ipserv;    
    in_port_t porta;
    char msg[MAX];
    char nomeutente[20];
    char password[20];
    char utentepass[40];
    char nome[20];
    char pas[20];
    char nomepass[40];
    char pass[MAX];
    char dest[MAX];
    char ogg[MAX];
    char test[MAX];
    int msglun=MAX;
    fd_set setl,setw,sete;
    printf("\033[2J\033[H");
    // controlla argomenti
    if (argc !=3) {
        printf("\nErrore\n");
           printf("Esempio di connessione: \n");
        printf("./client nome_server porta (>1023) \n");
        printf("Premere Invio\n");
        getchar();
        exit(-1);
    }

    ipserv=gethostbyname(argv[1]);    // trova IP servente in base al nome
    // crea socket 
    if ( (sd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
        perror("Errore in creazione socket");
        exit(-1);
    }
    // indirizzo IP
    memset((void *)&serv_ind, 0, sizeof(serv_ind)); // pulizia ind
    serv_ind.sin_family = AF_INET;                  // ind di tipo INET 
    porta = atoi(argv[2]);
    serv_ind.sin_port = htons(porta);               // porta a cui collegarsi
    memcpy(&serv_ind.sin_addr.s_addr,ipserv->h_addr,ipserv->h_length);
    // copiato ip servente dalla struct ipserv a serv_ind.sin_addr
    // stabilisce la connessione
    if (connect(sd, (struct sockaddr *)&serv_ind, sizeof(serv_ind)) < 0) {
        perror("Errore nella connessione");
        exit(-1);
    }
    printf("Connessione stabilita con %s\n",inet_ntoa(serv_ind.sin_addr));

   printf("\n\n\t\t\t*** *** Menu *** ***\n\n");
   printf("********* Inizializzazione applicazione in corso**********\n\n");
   printf("\t1: registrazione nuovo utente\n");
   printf("\t2: login ----> accesso ai servizi del sistema\n");
   scanf("%d",&inizio);
   
   if (inizio==2) {
  send(sd,"/autenticazione",MAX,0);
  printf("inserisci nomeutente\n");
  scanf("%s",&nomeutente);
  printf("inserisci password\n");
  scanf("%s",&password);
  strcat(utentepass,nomeutente);
  strcat(utentepass,"/");
  strcat(utentepass,password);
  strcat(utentepass,"/");
  printf("%s",utentepass);
  printf("*****autenticazione in corso*******\n\n");
  send(sd,utentepass,MAX,0);
  recv(sd,nome,MAX,0);
  if(strcmp(nome,"/autenticato")==0)
 {
   printf("\033[2J\033[H");
   printf("Inserire l'opzione corrispondente alla funzione desiderata:\n\n");
   printf("\t1: Invia nuovo messaggio\n");
   printf("\t2: Leggi i messaggi spediti all'utente interessato\n");
   printf("\t3: Cancella tutti i messaggi\n");
   printf("\t4: Ricevi nuovo messaggio \n");
   printf("\t0: Uscita\n\n");
   scanf("%d",&scelta);
  
   
    switch (scelta)
   {
   
   case 1:   
             send(sd,"/invia",MAX,0);
           printf("creazione nuovo messaggio\n");
             printf("inserire destinatario\n");
             scanf("%s",&dest);
             printf("inserire oggetto\n");
             scanf("%s",&ogg);
             printf("inserire testo\n");
             scanf("%s",&test);
             strcat(dest," ---- ");
             strcat(dest,ogg);
             strcat(dest," ---- ");
             strcat(dest,test);
    
           FD_ZERO (&setl);      // azzera i set; solo setl viene davvero usato
           FD_ZERO (&setw);
           FD_ZERO (&sete);
           FD_SET(fileno(stdin),&setl); // aggiunge descrittore di stdin in setl
           FD_SET(sd,&setl);
           if (select(FD_SETSIZE,&setl,&setw,&sete, NULL)<0) {
              perror("Errore nella select");
              exit(1);
           }
           
           if (FD_ISSET(fileno(stdin),&setl)) {    // tastiera creo messaggio
              //for(l=0;((msg[l]=getchar())!='\n' && l<MAX-1);l++);
              //msg[l]='\0';
            send(sd,dest,MAX,0);
            printf("<---- OK\n");
        }
       break;

 case 2:
        printf("prova\n");
 break;

case 3:
        printf("test\n");
break;

case 4:
           send(sd,"/ricezione",MAX,0);
        printf("ricezione nuovi messaggi in corso\n");
         if ( (recv(sd,msg,MAX,0))<=0 ) {
                perror("Errore nella recive");
                exit(-1);
            }    
       printf("%s\n",msg);
        //if (FD_ISSET (sd,&setl)) {          
            //if ( (recv(sd,msg,MAX,0))<=0 ) {
              //  perror("Errore nella read");
            //    exit(-1);
          //  }    
           //  printf("%s\n",msg); 
        //}
        
break;

case 0:
         printf("chiusura applicazione in corso\n");
break;

default:
         printf("Comando sconosciuto!\n");
break;
    }
 }
//close(sd);
else {
printf("%s\n",nome);
return 0;
}
}
 else if(inizio==1){ 
        printf("\033[2J\033[H");
        printf("Registrazione nuovo utente\n\n");
        send(sd,"/registrazione",MAX,0);
        printf("inserisci nomeutente\n");
        scanf("%s",&nome);
        printf("inserisci password\n");
        scanf("%s",&pas);
        strcat(nomepass,nome);
        strcat(nomepass,"/");
        strcat(nomepass,pas);
        strcat(nomepass,"/");
        printf("%s\n",nomepass);
        send(sd,nomepass,MAX,0);
        char presente[20];
        recv(sd,presente,20,0);
        if(strcmp(presente,"/in_uso")==0){
         printf("nome utente e password già utilizzati\n");
           }
         else printf("registrazione effettuata\n\n");
        return 0;
} 
 else printf("operazione non valida\n");
}

if you want to see the server code I will post it!!

---------- Post updated at 08:42 AM ---------- Previous update was at 08:19 AM ----------

This is the server code

Code:
#include <sys/select.h>
#include <netdb.h>

#include <unistd.h>            // interfaccia Unix standard
#include <errno.h>             // codici di errore
#include <sys/types.h>         // tipi predefiniti
#include <arpa/inet.h>         // per convertire ind. IP 
#include <sys/socket.h>        // socket  
#include <stdio.h>             // i/o
#include <stdlib.h>            // utilita'standard
#include <string.h>            // stringhe
#include <fcntl.h>             // file a basso livello
#include <time.h>              // tempo 
#include "strutture.h"


#define MAX        256
#define BACKLOG 20
#define dimT FD_SETSIZE
#define MESS_SETSIZE 1024

int TotalClient = 0;
int TotalMessage = 0;
lpmess MsgList[MESS_SETSIZE]; 
lpclient ClientList[FD_SETSIZE];
void inserisciClient(char n[20],char p[20],int s);
int isPresente(char no[20],char pas[20]);
void stampa();
void inserisciMsg(char d[20],char o[60], char t[200], int s);


int main(int argc, char *argv[])
{
    fd_set pri;                     // pri lista di descrittori per select()
    fd_set set_lettura;             // temp altra lista di descrittori
    struct sockaddr_in indserv;     // indirizzo del servente
    struct sockaddr_in indcli;      // indirizzo di un cliente
    int sdgr;                       // numero descrittore piu' alto
    int sd;                         // socket
    int csd;                        // socket connesso con accept()
    int destinatario;
    char buf[MAX],buf2[MAX],risposta[MAX];        // buffer dei dati
    int bytel;
    in_port_t porta;
    int val=1;                      // per la setsockopt()
    socklen_t lind;
    struct hostent *cli;            // per trovare nome cliente dall'IP
    struct in_addr vet[MAX];        // per mem. IP cliente (max 256 clienti)        
    int i, j;
    

    printf("\033[2J\033[H");
    //controlli sui parametri
    if (argc!=2) {
        printf("Digitare ./server porta\n");        
        exit(-1);
    }
    porta=atoi(argv[1]);   
    FD_ZERO(&pri);                    // pulizia liste descrittori
    FD_ZERO(&set_lettura);
    // socket
    if ((sd = socket(PF_INET, SOCK_STREAM, 0))<0) {
        perror("Errore nella socket");
        exit(-1);
    }
    // rende l'indirizzo riutilizzabile
    if (setsockopt(sd,SOL_SOCKET,SO_REUSEADDR,&val,sizeof(int))<0) {
        perror("Errore nella setsockopt");
        exit(-1);
    }
    // bind
    indserv.sin_family = AF_INET;
    indserv.sin_addr.s_addr = INADDR_ANY;
    indserv.sin_port = htons(porta);
    memset(&(indserv.sin_zero), '\0', 8);
    if (bind(sd, (struct sockaddr *)&indserv, sizeof(indserv)) == -1) {
        perror("Errore nella bind");
        exit(-1);
    }
    // listen
    if (listen(sd,BACKLOG)<0) {
        perror("Errore nella listen");
        exit(-1);
    }
    printf("server avviato; 'Ctrl+c' per chiuderlo\n\n");
    // aggiunge sd al set principale
    FD_SET(sd, &pri);
    // conserva il descrittore di file piu' grande
    sdgr = sd; 
    /*
    * cuore del programma:
    * prima della select copia la lista pri (che contiene tutti i socket 
    * aperti e quello tuttora in ascolto) in set_lettura in modo che pri 
    * non venga "sporcato" dalla select; set_lettura è usato solo nella select 
    * e nel successivo test per rilevare socket attivi; eventuali nuovi
    * socket connessi vengono aggiunti a pri cosi' come i socket chiusi
    * vengono rimossi da pri
    */
    while(1) { 
        set_lettura = pri;                 // imposta set per la select()
        if (select(sdgr+1, &set_lettura, NULL, NULL, NULL)<0) {
            perror("Errore nella select");
            exit(-1);
        }
        // ispeziona le connessioni per cercare dati in arrivo
        for(i=0;i<=sdgr;i++) {
            if (FD_ISSET(i, &set_lettura)) {     // trovato un socket con dati
                if (i==sd) {
                    lind = sizeof(indcli);
                    if ((csd=accept(sd,(struct sockaddr *)&indcli,&lind))<0) { 
                        perror("Errore nella accept");
                    }
                    else {
                        FD_SET(csd, &pri);   // aggiunge socket conn al set pri
                        if (csd > sdgr) {    
                            sdgr = csd;
                        }
                        printf("server: connessione da %s sul "
                            "socket %d\n",inet_ntoa(indcli.sin_addr),csd);    
                        vet[csd]=indcli.sin_addr;         // conserva IP cliente
                    }
                }
                else {
                    
                    if ((bytel=recv(i,buf,sizeof(buf),0))<= 0) {

                        if (bytel==0) {
                            // connessione chiusa dal cliente
                            printf("server: socket %d chiuso\n", i);
                            //implementare elimina socket e scrivi socket *****************************************************
                        }
                        else {
                            perror("Errore in ricezione");
                        }
                        close(i); 
                        FD_CLR(i,&pri);     // toglie il socket da pri
                    }
                    else { 
                         if (strcmp("/registrazione",buf)==0) {
                          //registrazione nuovo utente
                          recv(i,buf,sizeof(buf),0);
                          printf("%s\n",buf);
                          char *app1=strtok(buf, "/");
                          char *app2=strtok(NULL, "/");
                          printf("%s\n",app1);
                          printf("%s\n",app2);
                          
                          if(isPresente(app1,app2)==0){
                            inserisciClient(app1,app2,i);
                              send(i,"/ok",MAX,0);
                              } 
                              else{
                                send(i,"/in_uso",MAX,0);       
                               }
                         }      

                        if (strcmp("/autenticazione",buf)==0) {
    
                          //autenticazione
                          recv(i,buf,sizeof(buf),0);
                          
                          printf("%s\n",buf);
                          char *app1=strtok(buf, "/");
                          char *app2=strtok(NULL, "/");
                          printf("%s\n",app1);
                          printf("%s\n",app2);
                          if(isPresente(app1,app2)==1)
                          send(i,"/autenticato",MAX,0);
                          else send(i,"nome utente e password non corretti",MAX,0);
                         }     
     
                         if (strcmp("/invia",buf)==0) {
    
                          //invio nuovo messaggio
                          
                          if(recv(i,buf2,sizeof(buf2),0)){
                                 perror("errore in ricezione");
                          }
                         }    

                        if (strcmp("/ricezione",buf)==0) {
    
                          //ricezione nuovo messaggio
                          
                          if(send(i,buf2,sizeof(buf2),0)){
                                 perror("Errore in spedizione");
                          }
                         }
                       
                    }          
                }                        // fine else: gestisce dati in arrivo 
            }                            // fine if (FD_ISSET(i.....))
        }                                // fine for i<=sdgr
    }                                    // fine while(1)
    return 0;
}








//metodi ausiliari

void inserisciClient(char n[20],char p[20], int s) 
{ 
     lpclient l; 
 
 
 
     if ((l = (lpclient) malloc(sizeof(client))) == NULL) 
     { 
         printf("[SERVER]-->** Errore: malloc() fallita\n"); 
         return ; 
     } 
 
 
    strcpy(l->nome,n);
    strcpy(l->password,p); 
     l->socket = s; 
 
     ClientList[TotalClient] = l; 
 
     TotalClient++; 
     printf("[SERVER]--> Accettato client %i nella ClientList, TotalClient=%i\n",l->socket,TotalClient); 
     return ; 
} 


int isPresente(char n[20],char p[20])
{
int i;
for(i=0;i<TotalClient;i++){
lpclient cl=ClientList[i];
if(strcmp(cl->nome,n)==0 && strcmp(cl->password,p)==0)
    return 1;
}
return 0;
}

void stampa(){ //da modificare
int i;
for(i=0;i<TotalClient;i++){
lpclient cl=ClientList[i];
  printf("client %d : nome %s ----- password %s ----- porta %d",i,cl->nome,cl->password,cl->socket);
  }
} 

void inserisciMsg(char d[20],char o[60], char t[200], int s) 
{ 
     lpmess l; 
 
 
 
     if ((l = (lpmess) malloc(sizeof(messaggio))) == NULL) 
     { 
         printf("[SERVER]-->** Errore: malloc() fallita\n"); 
         return ; 
     } 
 
 
    strcpy(l->destinatario,d);
    strcpy(l->oggetto,o);
    strcpy(l->testo,t); 
     l->socket = s; 
 
     MsgList[TotalMessage] = l; 
 
     TotalMessage++; 
     printf("[SERVER]--> Accettato messaggio %i nella MsgList, TotalMessage=%i\n",l->socket,TotalMessage); 
     return ; 
}


and here the struct I use
Code:
#ifndef STRUTTURE_H
#define STRUTTURE_H

#include <sys/types.h>

#define DEST 20 /* lunghezza del campo destinatario */
#define OGG 60 /* lunghezza del campo oggetto */
#define TEST  200 /* lunghezza del campo testo */



typedef struct my_message
{  
   char destinatario[DEST];
   char oggetto[OGG];
   char testo[TEST];
   int socket; //socket di arrivo del messaggio
} messaggio, * lpmess;


typedef struct my_client
{ 
char nome[20];
char password[20];
int socket;     // L'identificativo della socket da usare per scrivere al client
}client, * lpclient;



#endif

# 2  
Old 03-17-2010
Stack smashing means that, for example, one of the strcat, strcpy, etc. operations tried to place data beyond the end of a string variable, and the memory is allocated on stack space. You overwrote a stack canary, in other words.

The most common cause is strcpy, strcat. Array bounds overflow operations cause this to happen. Do you have valgrind or electric fence? There are a lot of tools for this kind of problem.
# 3  
Old 03-17-2010
Thank you very much... I think I know the problem now!! I'm starting to attempt!!
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Programming

Sleep function not detected

Hello Im using geany to write my c codes. Below is my code to make the internal LED of beaglebone flashing. But i cant seem to use the sleep or delay to make the program wait for a couple of miliseconds. I've included all include files that i can find but none of it solve the problem. Any help is... (1 Reply)
Discussion started by: HellRyder
1 Replies

2. UNIX for Dummies Questions & Answers

Kernel Stack vs User Mode Stack

Hi, I am new to the linux kernel development area. I want to know what is the difference between kernel mode stack and user mode stack? Does each process has a user mode stack and a kernel mode stack?? Or Each process has a user mode stack and there is only one kernel mode stack that is shared by... (4 Replies)
Discussion started by: saurabhkoar
4 Replies

3. Hardware

iPhone Not being detected

I'm New to the linux world I'm running OpenSuse and as soon as I installed everything was wokring like a charm. and i said to myself I'm so keeping this OpSys! everytime i would plug in my iPhone it would read it as anything else as a filesystem and i was able to go through the device files an etc,... (9 Replies)
Discussion started by: JuankyKong
9 Replies

4. Red Hat

glic detected on free

Hello, I have built a shared object on SuSe using gcc. I then copied this shared object to a RedHat machine and built a test application using gcc 3.4.6 which linked the shared object built on SuSe. When running the test application on RedHat, I get a glic detected on free message and the... (0 Replies)
Discussion started by: sbaratam
0 Replies

5. Solaris

dmfe0: TX stall detected

I just starting recieving in /var/adm/messages this kind of notice: dmfe: NOTICE: dmfe0: TX stall detected after 2 ticks in state 3; automatic recovery initiated does any one have any idea why this notice is generated ? thanks in advance. (1 Reply)
Discussion started by: pasalagua
1 Replies

6. Programming

what is stack winding and stack unwinding

helo can u tell me what do you mean by stack winding and stack unwinding Regards, Amit (2 Replies)
Discussion started by: amitpansuria
2 Replies

7. UNIX for Dummies Questions & Answers

Softlockup detected on cpu#0

hi everybody, I am working on Linuxdevicedrivers in kernel 2.6.My driver is for a HDLC transceiver chip. The problem is driver is not getting initialized properly.It is throwing one bug saying BUG:softlockup detected on cpu#0 which we see in /var/log/messages This is the first i am... (0 Replies)
Discussion started by: sriram.ec
0 Replies

8. Debian

HDD not detected by RHL 9 (or 7.2)

Hi, I have got myself a new hard disk- a 80 GB SATA IDE from Seagate. When I try installing Red Hat Linux 9(and RHL 7.2 too), it displays an error message saying that it fails to detect any hard drive. In the BIOS, I tried changing the drive configuration to "Legacy Drive", but that didnt help... (5 Replies)
Discussion started by: Abhishek Ghose
5 Replies
Login or Register to Ask a Question