[Kst] kdeextragear-2/kst/datapush [POSSIBLY UNSAFE]
George Staikos
staikos at kde.org
Tue Aug 12 10:21:16 CEST 2003
CVS commit by staikos:
some bugfixes and a quite command
M +27 -15 main.cpp 1.2 [POSSIBLY UNSAFE: printf]
--- kdeextragear-2/kst/datapush/main.cpp #1.1:1.2
@@ -210,5 +210,5 @@ int mainLoop(Listener *l, FILE *fp) {
bool trashed = false;
- if (FD_ISSET(desc, &efds)) {
+ if (FD_ISSET(desc, &efds)) { // exception occurred
trashed = true;
cout << "Exception detected on socket " << desc << endl;
@@ -216,9 +216,16 @@ int mainLoop(Listener *l, FILE *fp) {
char buf[1024];
if (0 < s->read(buf, 1024)) {
+ if (0 == strncmp(buf, "quit", 4)) { // user requested quit
+ s->close();
+ } else { // a number? dump starting at that point in the file.
long pt = 0;
buf[10] = 0; // truncate
sscanf(buf, "%ld", &pt);
- if (lseek(fd, pt, SEEK_SET) == pt) {
+ if (pt >= 0 && lseek(fd, pt, SEEK_SET) == pt) {
long readsz = fsize - pt;
+
+ sprintf(buf, "%ld\n", readsz >= 0 ? readsz : 0);
+ s->write(buf, strlen(buf));
+
while (readsz > 0) {
#define MIN(x,y) ((x) < (y) ? (x) : (y))
@@ -232,6 +239,10 @@ int mainLoop(Listener *l, FILE *fp) {
s->write(buf, len);
}
+ } else {
+ s->write("0\n", 2);
}
}
+ }
+
if (!s->connected()) {
trashed = true;
@@ -239,5 +250,5 @@ int mainLoop(Listener *l, FILE *fp) {
}
- if (trashed) {
+ if (trashed) { // add to the trash (deleted sockets)
trash.push_back(s);
} else {
@@ -250,5 +261,5 @@ int mainLoop(Listener *l, FILE *fp) {
n++;
- while (!trash.empty()) {
+ while (!trash.empty()) { // clean up the trash
sockets.remove(trash.back());
delete trash.back();
@@ -256,4 +267,5 @@ int mainLoop(Listener *l, FILE *fp) {
}
+ // new inbound connection
if (FD_ISSET(l->descriptor(), &rfds)) {
Socket *s = l->accept();
More information about the Kst
mailing list