[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

PTY allocation error with samplesshd.c (libssh 0.5.2)


We have installed libssh 0.5.2 on Debian and Ubuntu. We tried the samplessh.c example file.

We have a "PTY allocation request failed on channel 0" on the client when connecting to the server. On Debian, it doesn't crash, it's just an annoying alert. On Ubuntu, the client crashes.

We think the error is that the server doesn't respond to SSH_CHANNEL_REQUEST_PTY messages.

Here is a patch to fix this bug (if it's one).

Regards,

Anthony VEREZ, Guilhem TIENNOT, François MONNIOT, Thibault INGARGIOLA
--- samplesshd.c	2012-01-10 10:59:25.944091485 +0100
+++ samplesshd.c	2012-01-10 10:54:21.544083690 +0100
@@ -38,22 +38,22 @@
 
 void set_pcap(ssh_session session);
 void set_pcap(ssh_session session){
-    if(!pcap_file)
-        return;
-    pcap=ssh_pcap_file_new();
-    if(ssh_pcap_file_open(pcap,pcap_file) == SSH_ERROR){
-        printf("Error opening pcap file\n");
-        ssh_pcap_file_free(pcap);
-        pcap=NULL;
-        return;
-    }
-    ssh_set_pcap_file(session,pcap);
+	if(!pcap_file)
+		return;
+	pcap=ssh_pcap_file_new();
+	if(ssh_pcap_file_open(pcap,pcap_file) == SSH_ERROR){
+		printf("Error opening pcap file\n");
+		ssh_pcap_file_free(pcap);
+		pcap=NULL;
+		return;
+	}
+	ssh_set_pcap_file(session,pcap);
 }
 
 void cleanup_pcap(void);
 void cleanup_pcap(){
-    ssh_pcap_file_free(pcap);
-    pcap=NULL;
+	ssh_pcap_file_free(pcap);
+	pcap=NULL;
 }
 #endif
 
@@ -270,7 +270,7 @@
     do {
         message=ssh_message_get(session);
         if(message && ssh_message_type(message)==SSH_REQUEST_CHANNEL &&
-           ssh_message_subtype(message)==SSH_CHANNEL_REQUEST_SHELL){
+           (ssh_message_subtype(message)==SSH_CHANNEL_REQUEST_SHELL || ssh_message_subtype(message)==SSH_CHANNEL_REQUEST_PTY)){
 //            if(!strcmp(ssh_message_channel_request_subsystem(message),"sftp")){
                 sftp=1;
                 ssh_message_channel_request_reply_success(message);
@@ -290,11 +290,17 @@
     do{
         i=ssh_channel_read(chan,buf, 2048, 0);
         if(i>0) {
+
             ssh_channel_write(chan, buf, i);
             if (write(1,buf,i) < 0) {
                 printf("error writing to buffer\n");
                 return 1;
             }
+            if (buf[0] == '\x0d')
+            {
+                write(1,"\n",1);
+                ssh_channel_write(chan,"\n",1);
+            }
         }
     } while (i>0);
     ssh_disconnect(session);
@@ -304,4 +310,5 @@
 #endif
     ssh_finalize();
     return 0;
-}
\ Pas de fin de ligne à la fin du fichier
+}
+

Archive administrator: postmaster@lists.cynapses.org