Merged revisions 278023 via svnmerge from
authorTilghman Lesher <tilghman@meg.abyt.es>
Tue, 20 Jul 2010 16:50:11 +0000 (16:50 +0000)
committerTilghman Lesher <tilghman@meg.abyt.es>
Tue, 20 Jul 2010 16:50:11 +0000 (16:50 +0000)
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
  r278023 | tilghman | 2010-07-20 11:37:18 -0500 (Tue, 20 Jul 2010) | 7 lines

  Off-by-one error

  (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/trunk@278024 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/manager.c

index 42ad091..9d31eeb 100644 (file)
@@ -5523,19 +5523,17 @@ static int generic_http_callback(struct ast_tcptls_session_instance *ser,
                char *buf;
                size_t l;
 
-               /* Ensure buffer is NULL-terminated */
-               fprintf(s.f, "%c", 0);
-
                if ((l = ftell(s.f))) {
-                       if (MAP_FAILED == (buf = mmap(NULL, l, PROT_READ | PROT_WRITE, MAP_PRIVATE, s.fd, 0))) {
+                       if (MAP_FAILED == (buf = mmap(NULL, l + 1, PROT_READ | PROT_WRITE, MAP_PRIVATE, s.fd, 0))) {
                                ast_log(LOG_WARNING, "mmap failed.  Manager output was not processed\n");
                        } else {
+                               buf[l] = '\0';
                                if (format == FORMAT_XML || format == FORMAT_HTML) {
                                        xml_translate(&out, buf, params, format);
                                } else {
                                        ast_str_append(&out, 0, "%s", buf);
                                }
-                               munmap(buf, l);
+                               munmap(buf, l + 1);
                        }
                } else if (format == FORMAT_XML || format == FORMAT_HTML) {
                        xml_translate(&out, "", params, format);