]> git.webhop.me Git - lcd4linux.git/commitdiff
Fixes a buffer underrun error and possible array index issues by mcarey@...
authormichael <michael@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Wed, 31 Dec 2008 05:28:42 +0000 (05:28 +0000)
committermichael <michael@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Wed, 31 Dec 2008 05:28:42 +0000 (05:28 +0000)
git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@916 3ae390bd-cb1e-0410-b409-cd5a39f66f1f

plugin_asterisk.c

index a9012b2a1da989097417f1ab4efbbf197a9e59d4..790fab2722c52699b9c5fe821bbb610a6189d29b 100644 (file)
@@ -66,7 +66,7 @@ static void zapstatus(RESULT * result, RESULT * arg1)
 {
     FILE *infile;
     int skipline = 0;          // Skip the first in the file, it throws off the detection
-    char line[100], *SipLoc, Channel[25], Location[25], State[9], Application[25], EndPoint[8], Ret[50], inp;
+    char line[100], *SipLoc, Channel[25], Location[25], State[9], Application[25], EndPoint[8], Ret[50];
     int i = 0, ChannelInt = 0, ZapLine = 0;
     struct Line Lines[32];     // Setup 32 lines, ZAP 1-32 (memory is cheap)
 
@@ -85,6 +85,12 @@ static void zapstatus(RESULT * result, RESULT * arg1)
     system("asterisk -rx \"show channels\" > /tmp/asterisk.state");    // Crappy CLI way to do it
 
     infile = fopen("/tmp/asterisk.state", "r");
+
+    for (i = 0; i < 100; i++) {
+       line[i] = ' ';
+    }
+    line[99] = '\0';
+
     while (fgets(line, 100, infile) != NULL) {
        if (strstr(line, "Zap") != NULL) {
            for (i = 0; i < strlen(line); i++) {
@@ -105,7 +111,6 @@ static void zapstatus(RESULT * result, RESULT * arg1)
            memcpy(EndPoint, Application + 13, 7);
            EndPoint[7] = '\0';
 
-
            if (strstr(Application, "Bridged Call") != NULL) {
                // Subtract 48 from the character value to get the int
                // value. Subtract one more because arrays start at 0.
@@ -120,10 +125,8 @@ static void zapstatus(RESULT * result, RESULT * arg1)
                } else {
                    EndPoint[0] = '\0';
                }
-
                ChannelInt = (int) (Channel[4]) - 49;
                strcpy(Lines[ChannelInt].Channel, Channel);
-               strcpy(Lines[ChannelInt].EndPoint, EndPoint);
                Lines[ChannelInt].active = 1;
            }
        } else {
@@ -149,7 +152,12 @@ static void zapstatus(RESULT * result, RESULT * arg1)
     fclose(infile);
 
     ZapLine -= 1;
-    if (Lines[ZapLine].active == 1) {
+    if (ZapLine < 0 || ZapLine > 31) {
+       memset(Ret, ' ', 50);
+       Ret[0] = '\0';
+       strcat(Ret, "Invalid ZAP #");
+       SetResult(&result, R_STRING, &Ret);
+    } else if (Lines[ZapLine].active == 1) {
        memset(Ret, ' ', 50);
        Ret[0] = '\0';
        strcat(Ret, Lines[ZapLine].Channel);
@@ -163,7 +171,6 @@ static void zapstatus(RESULT * result, RESULT * arg1)
        strcat(Ret, ": inactive");
        SetResult(&result, R_STRING, &Ret);
     }
-
     return;
 }