Bug#100414: uninitialised variable fix
The previous patch leaves fd_stdin uninitialised. Here is an update.
Only in bnetd-0.4.24: bin
Only in bnetd-0.4.24: build
Only in bnetd-0.4.24/debian: debian.pcx
Only in bnetd-0.4.24/debian: files
Only in bnetd-0.4.24/debian: postinst.debhelper
Only in bnetd-0.4.24/debian: postrm.debhelper
Only in bnetd-0.4.24/debian: prerm.debhelper
Only in bnetd-0.4.24/debian: substvars
Only in bnetd-0.4.24/debian: tmp
Only in bnetd-0.4.24: sbin
Only in bnetd-0.4.24/src: Makefile
Only in orig/bnetd-0.4.24/src/autoconf: ansi2knr.c.orig
Only in bnetd-0.4.24/src/bnetd: account.o
Only in bnetd-0.4.24/src/bnetd: account_wrap.o
Only in bnetd-0.4.24/src/bnetd: adbanner.o
Only in bnetd-0.4.24/src/bnetd: autoupdate.o
Only in bnetd-0.4.24/src/bnetd: bits.o
Only in bnetd-0.4.24/src/bnetd: bits_chat.o
Only in bnetd-0.4.24/src/bnetd: bits_ext.o
Only in bnetd-0.4.24/src/bnetd: bits_game.o
Only in bnetd-0.4.24/src/bnetd: bits_login.o
Only in bnetd-0.4.24/src/bnetd: bits_net.o
Only in bnetd-0.4.24/src/bnetd: bits_packet.o
Only in bnetd-0.4.24/src/bnetd: bits_query.o
Only in bnetd-0.4.24/src/bnetd: bits_rconn.o
Only in bnetd-0.4.24/src/bnetd: bits_va.o
Only in bnetd-0.4.24/src/bnetd: channel.o
Only in bnetd-0.4.24/src/bnetd: character.o
Only in bnetd-0.4.24/src/bnetd: command.o
Only in bnetd-0.4.24/src/bnetd: connection.o
Only in bnetd-0.4.24/src/bnetd: file.o
Only in bnetd-0.4.24/src/bnetd: game.o
Only in bnetd-0.4.24/src/bnetd: game_conv.o
Only in bnetd-0.4.24/src/bnetd: game_rule.o
Only in bnetd-0.4.24/src/bnetd: gametrans.o
Only in bnetd-0.4.24/src/bnetd: handle_auth.o
Only in bnetd-0.4.24/src/bnetd: handle_bits.o
Only in bnetd-0.4.24/src/bnetd: handle_bnet.o
Only in bnetd-0.4.24/src/bnetd: handle_bot.o
Only in bnetd-0.4.24/src/bnetd: handle_file.o
Only in bnetd-0.4.24/src/bnetd: handle_init.o
Only in bnetd-0.4.24/src/bnetd: handle_telnet.o
Only in bnetd-0.4.24/src/bnetd: handle_udp.o
Only in bnetd-0.4.24/src/bnetd: helpfile.o
Only in bnetd-0.4.24/src/bnetd: ipban.o
Only in bnetd-0.4.24/src/bnetd: ladder.o
Only in bnetd-0.4.24/src/bnetd: ladder_calc.o
Only in bnetd-0.4.24/src/bnetd: main.o
Only in bnetd-0.4.24/src/bnetd: message.o
Only in bnetd-0.4.24/src/bnetd: prefs.o
Only in bnetd-0.4.24/src/bnetd: realm.o
Only in bnetd-0.4.24/src/bnetd: runprog.o
Only in bnetd-0.4.24/src/bnetd: server.o
Only in bnetd-0.4.24/src/bnetd: tick.o
Only in bnetd-0.4.24/src/bnetd: timer.o
Only in bnetd-0.4.24/src/bnetd: tracker.o
Only in bnetd-0.4.24/src/bnetd: udptest_send.o
Only in bnetd-0.4.24/src/bnetd: watch.o
Only in bnetd-0.4.24/src/bniutils: bni.o
Only in bnetd-0.4.24/src/bniutils: bni2tga.o
Only in bnetd-0.4.24/src/bniutils: bnibuild.o
Only in bnetd-0.4.24/src/bniutils: bniextract.o
Only in bnetd-0.4.24/src/bniutils: bnilist.o
Only in bnetd-0.4.24/src/bniutils: fileio.o
Only in bnetd-0.4.24/src/bniutils: tga.o
Only in bnetd-0.4.24/src/bniutils: tgainfo.o
Only in bnetd-0.4.24/src/bnpass: bnpass.o
Only in bnetd-0.4.24/src/bnproxy: bnproxy.o
Only in bnetd-0.4.24/src/bnproxy: virtconn.o
Only in bnetd-0.4.24/src/bntrackd: bntrackd.o
diff -ru orig/bnetd-0.4.24/src/client/bnbot.c bnetd-0.4.24/src/client/bnbot.c
--- orig/bnetd-0.4.24/src/client/bnbot.c Fri Mar 9 07:38:07 2001
+++ bnetd-0.4.24/src/client/bnbot.c Sun Apr 13 15:39:10 2003
@@ -63,9 +63,6 @@
# include <sys/file.h>
# endif
#endif
-#ifdef HAVE_TERMIOS_H
-# include <termios.h>
-#endif
#include "compat/termios.h"
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
@@ -121,6 +118,45 @@
}
+static int selecting_get_comm(char *result, size_t result_sz) {
+ static char buffer[MAX_MESSAGE_LEN];
+ static int bufused;
+
+ char *p;
+ ptrdiff_t thischnk;
+ int r;
+
+ for (;;) {
+ if ((p= memchr(buffer,'\n',bufused))) {
+ thischnk= p-buffer;
+ memcpy(result,buffer,thischnk);
+ result[thischnk]= 0;
+ bufused -= thischnk+1;
+ memmove(buffer, p+1, bufused);
+ return 1;
+ }
+ if (bufused == MAX_MESSAGE_LEN) {
+ fprintf(stderr,"bnbot: stdin: overlong input line\n");
+ return -1;
+ }
+ r= read(0, buffer+bufused, sizeof(buffer)-bufused);
+ if (r > 0) {
+ bufused += r;
+ } else if (r == 0) {
+ exit(0);
+ } else if (errno == EINTR) {
+ } else if (errno == EAGAIN) {
+ return 0;
+ } else {
+ perror("bnbot: stdin");
+ return -1;
+ }
+ }
+}
+
+static int org_stdin_flags;
+static void stdin_restore_flags(void) { fcntl(0,F_SETFL,org_stdin_flags); }
+
extern int main(int argc, char * argv[])
{
int a;
@@ -133,12 +169,8 @@
char text[MAX_MESSAGE_LEN];
struct hostent * host;
unsigned int commpos;
- struct termios in_attr_old;
- struct termios in_attr_new;
- int changed_in;
unsigned int currsize;
- int fd_stdin;
- unsigned int screen_width,screen_height;
+ int fd_stdin = 0;
if (argc<1 || !argv || !argv[0])
{
@@ -187,35 +219,9 @@
return STATUS_FAILURE;
}
- fd_stdin = fileno(stdin);
- if (tcgetattr(fd_stdin,&in_attr_old)>=0)
- {
- in_attr_new = in_attr_old;
- in_attr_new.c_lflag &= ~(ECHO | ICANON); /* turn off ECHO and ICANON */
- in_attr_new.c_cc[VMIN] = 0; /* don't require reads to return data */
- in_attr_new.c_cc[VTIME] = 1; /* timeout = .1 second */
- tcsetattr(fd_stdin,TCSANOW,&in_attr_new);
- changed_in = 1;
- }
- else
- {
- fprintf(stderr,"%s: could not set terminal attributes for stdin\n",argv[0]);
- changed_in = 0;
- }
-
- if (client_get_termsize(fd_stdin,&screen_width,&screen_height)<0)
- {
- fprintf(stderr,"%s: could not determine screen size\n",argv[0]);
- if (changed_in)
- tcsetattr(fd_stdin,TCSAFLUSH,&in_attr_old);
- return STATUS_FAILURE;
- }
-
if ((sd = psock_socket(PSOCK_PF_INET,PSOCK_SOCK_STREAM,0))<0)
{
fprintf(stderr,"%s: could not create socket (psock_socket: %s)\n",argv[0],strerror(psock_errno()));
- if (changed_in)
- tcsetattr(fd_stdin,TCSAFLUSH,&in_attr_old);
return STATUS_FAILURE;
}
@@ -226,8 +232,6 @@
if (psock_connect(sd,(struct sockaddr *)&saddr,sizeof(saddr))<0)
{
fprintf(stderr,"%s: could not connect to server \"%s\" port %hu (psock_connect: %s)\n",argv[0],servname,servport,strerror(psock_errno()));
- if (changed_in)
- tcsetattr(fd_stdin,TCSAFLUSH,&in_attr_old);
return STATUS_FAILURE;
}
@@ -235,8 +239,6 @@
{
fprintf(stderr,"%s: could not set TCP socket to non-blocking mode (psock_ctl: %s)\n",argv[0],strerror(psock_errno()));
psock_close(sd);
- if (changed_in)
- tcsetattr(fd_stdin,TCSAFLUSH,&in_attr_old);
return STATUS_FAILURE;
}
@@ -248,8 +250,6 @@
if (!(packet = packet_create(packet_class_init)))
{
fprintf(stderr,"%s: could not create packet\n",argv[0]);
- if (changed_in)
- tcsetattr(fd_stdin,TCSAFLUSH,&in_attr_old);
return STATUS_FAILURE;
}
bn_byte_set(&packet->u.client_initconn.class,CLIENT_INITCONN_CLASS_BOT);
@@ -259,21 +259,25 @@
if (!(rpacket = packet_create(packet_class_raw)))
{
fprintf(stderr,"%s: could not create packet\n",argv[0]);
- if (changed_in)
- tcsetattr(fd_stdin,TCSAFLUSH,&in_attr_old);
return STATUS_FAILURE;
}
if (!(packet = packet_create(packet_class_raw)))
{
fprintf(stderr,"%s: could not create packet\n",argv[0]);
- if (changed_in)
- tcsetattr(fd_stdin,TCSAFLUSH,&in_attr_old);
return STATUS_FAILURE;
}
packet_append_ntstring(packet,"\004");
client_blocksend_packet(sd,packet);
packet_del_ref(packet);
+
+ {
+ org_stdin_flags= fcntl(0, F_GETFL);
+ if (org_stdin_flags==-1) { perror("bnbot: fcntl F_GETFL"); exit(1); }
+ if (atexit(stdin_restore_flags)) { perror("bnbot: atexit"); exit(1); }
+ if (fcntl(0, F_SETFL, org_stdin_flags | O_NONBLOCK))
+ { perror("bnbot: fcntl F_SETFL"); exit(1); }
+ }
{
int highest_fd;
@@ -314,15 +318,13 @@
char * str=packet_get_raw_data(rpacket,0);
str[currsize] = '\0';
- printf("%s",str);
+ printf("%s\n",str);
fflush(stdout);
}
if (sd==-1) /* if connection was closed */
{
printf("Connection closed by server.\n");
- if (changed_in)
- tcsetattr(fd_stdin,TCSAFLUSH,&in_attr_old);
packet_del_ref(rpacket);
return STATUS_SUCCESS;
}
@@ -330,32 +332,31 @@
if (PSOCK_FD_ISSET(fd_stdin,&rfds)) /* got keyboard data */
{
- switch (client_get_comm("",text,sizeof(text),&commpos,-1,0,screen_width))
- {
- case -1: /* cancel */
- if (changed_in)
- tcsetattr(fd_stdin,TCSAFLUSH,&in_attr_old);
- return STATUS_FAILURE;
-
- case 0: /* timeout */
- break;
-
- case 1:
- if (!(packet = packet_create(packet_class_raw)))
+ for (;;) {
+ switch (selecting_get_comm(text,sizeof(text)))
{
- fprintf(stderr,"%s: could not create packet\n",argv[0]);
- if (changed_in)
- tcsetattr(fd_stdin,TCSAFLUSH,&in_attr_old);
- packet_del_ref(rpacket);
+ case -1: /* cancel */
return STATUS_FAILURE;
+
+ case 0: /* timeout */
+ goto xit_loop;
+
+ case 1:
+ if (!(packet = packet_create(packet_class_raw)))
+ {
+ fprintf(stderr,"%s: could not create packet\n",argv[0]);
+ packet_del_ref(rpacket);
+ return STATUS_FAILURE;
+ }
+ packet_append_ntstring(packet,text);
+ packet_append_ntstring(packet,"\r\n");
+ client_blocksend_packet(sd,packet);
+ packet_del_ref(packet);
+ commpos = 0;
+ text[0] = '\0';
}
- packet_append_ntstring(packet,text);
- packet_append_ntstring(packet,"\r\n");
- client_blocksend_packet(sd,packet);
- packet_del_ref(packet);
- commpos = 0;
- text[0] = '\0';
}
+ xit_loop:;
}
}
}
Only in bnetd-0.4.24/src/client: bnbot.c~
Only in bnetd-0.4.24/src/client: bnbot.o
Only in bnetd-0.4.24/src/client: bnchat.o
Only in bnetd-0.4.24/src/client: bnftp.o
Only in bnetd-0.4.24/src/client: bnstat.o
Only in bnetd-0.4.24/src/client: client.o
Only in bnetd-0.4.24/src/client: client_connect.o
Only in bnetd-0.4.24/src/client: udptest.o
Only in bnetd-0.4.24/src/common: addr.o
Only in bnetd-0.4.24/src/common: bn_type.o
Only in bnetd-0.4.24/src/common: bnethash.o
Only in bnetd-0.4.24/src/common: bnethashconv.o
Only in bnetd-0.4.24/src/common: bnettime.o
Only in bnetd-0.4.24/src/common: check_alloc.o
Only in bnetd-0.4.24/src/common: eventlog.o
Only in bnetd-0.4.24/src/common: hashtable.o
Only in bnetd-0.4.24/src/common: hexdump.o
Only in bnetd-0.4.24/src/common: list.o
Only in bnetd-0.4.24/src/common: network.o
Only in bnetd-0.4.24/src/common: packet.o
Only in bnetd-0.4.24/src/common: queue.o
Only in bnetd-0.4.24/src/common: util.o
Only in bnetd-0.4.24/src/compat: difftime.o
Only in bnetd-0.4.24/src/compat: gettimeofday.o
Only in bnetd-0.4.24/src/compat: inet_aton.o
Only in bnetd-0.4.24/src/compat: inet_ntoa.o
Only in bnetd-0.4.24/src/compat: psock.o
Only in bnetd-0.4.24/src/compat: strcasecmp.o
Only in bnetd-0.4.24/src/compat: strdup.o
Only in bnetd-0.4.24/src/compat: strerror.o
Only in bnetd-0.4.24/src/compat: strftime.o
Only in bnetd-0.4.24/src/compat: strncasecmp.o
Only in bnetd-0.4.24/src/compat: strtoul.o
Only in bnetd-0.4.24/src/compat: uname.o
Only in bnetd-0.4.24/src: config.cache
Only in bnetd-0.4.24/src: config.h
Only in bnetd-0.4.24/src: config.log
Only in bnetd-0.4.24/src: config.status
Only in bnetd-0.4.24/src: t
Reply to: