]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Off-by-one error
authorTilghman Lesher <tilghman@meg.abyt.es>
Tue, 20 Jul 2010 16:37:18 +0000 (16:37 +0000)
committerTilghman Lesher <tilghman@meg.abyt.es>
Tue, 20 Jul 2010 16:37:18 +0000 (16:37 +0000)
(closes issue #16506)
 Reported by: nik600
 Patches:
       20100629__issue16506.diff.txt uploaded by tilghman (license 14)

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@278023 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/manager.c

index 80841789c3d2b36ccb617d9002b6e38b79b98e35..42bac53cd6c35f0ec0d6367ba60f4b054a300f46 100644 (file)
@@ -2917,14 +2917,12 @@ static char *generic_http_callback(int format, struct sockaddr_in *requestor, co
                        char *buf;
                        size_t l;
 
-                       /* Ensure buffer is NULL-terminated */
-                       fprintf(ss.f, "%c", 0);
-
                        if ((l = lseek(ss.fd, 0, SEEK_END)) > 0) {
-                               if (MAP_FAILED == (buf = mmap(NULL, l, PROT_READ | PROT_WRITE, MAP_PRIVATE, ss.fd, 0))) {
+                               if (MAP_FAILED == (buf = mmap(NULL, l + 1, PROT_READ | PROT_WRITE, MAP_SHARED, ss.fd, 0))) {
                                        ast_log(LOG_WARNING, "mmap failed.  Manager request output was not processed\n");
                                } else {
                                        char *tmpbuf;
+                                       buf[l] = '\0';
                                        if (format == FORMAT_XML)
                                                tmpbuf = xml_translate(buf, params);
                                        else if (format == FORMAT_HTML)
@@ -2945,7 +2943,7 @@ static char *generic_http_callback(int format, struct sockaddr_in *requestor, co
                                                free(tmpbuf);
                                        free(s->outputstr);
                                        s->outputstr = NULL;
-                                       munmap(buf, l);
+                                       munmap(buf, l + 1);
                                }
                        }
                        fclose(ss.f);