Re: Problems with bookmarks.dpi

Johannes Hofmann <[email protected]>
Newsgroups gmane.comp.web.dillo.devel
Message-ID <[email protected]>
Hi Sebastian,

there is probabely something in your bm.txt that the current code
doesn't expect.
I tried to make the bookmarks file parser a bit safer (see attached
patch). Could you please try if it fixes your case?

Cheers,
Johannes

On Sat, Jan 23, 2016 at 03:08:31PM +0100, Sebastian Geerken wrote:
> Hi!
> 
> As I wrote in a previois post, bookmarks do not work. It seems that
> bookmarks.dpi crashes:
> 
> ----------------------------------------------------------------------
> $ gdb /usr/local/lib/dillo/dpi/bookmarks/bookmarks.dpi core
> GNU gdb (Debian 7.7.1+dfsg-5) 7.7.1
> Copyright (C) 2014 Free Software Foundation, Inc.
> [...]
> Reading symbols from /usr/local/lib/dillo/dpi/bookmarks/bookmarks.dpi...done.
> [New LWP 5661]
> Core was generated by `/usr/local/lib/dillo/dpi/bookmarks/bookmarks.dpi'.
> Program terminated with signal SIGSEGV, Segmentation fault.
> #0  Bms_load () at bookmarks.c:745
> 745              p = strchr(p, ' '); *p = 0;
> (gdb) l
> 740           if (buf[0] == 's') {
> 741              /* get section, url and title */
> 742              section = strtol(buf + 1, NULL, 10);
> 743              p = strchr(buf, ' '); *p = 0;
> 744              url = ++p;
> 745              p = strchr(p, ' '); *p = 0;
> 746              title = ++p;
> 747              p = strchr(p, '\n'); *p = 0;
> 748              u_title = Unescape_html_str(title);
> 749              Bms_add(section, url, u_title);
> (gdb) p p
> $1 = 0x1 <error: Cannot access memory at address 0x1>
> (gdb) bt
> #0  Bms_load () at bookmarks.c:745
> #1  Bms_cond_load () at bookmarks.c:792
> #2  Bmsrv_parse_token (Buf=0x1814280 "<cmd='open_url' url='dpi:/bm/'
> '>", sh=0x1810200) at bookmarks.c:1605
> #3  main () at bookmarks.c:1746
> ----------------------------------------------------------------------
> 
> Sebastian
> 



> _______________________________________________
> Dillo-dev mailing list
> [email protected]
> http://lists.dillo.org/cgi-bin/mailman/listinfo/dillo-dev

_______________________________________________
Dillo-dev mailing list
[email protected]
http://lists.dillo.org/cgi-bin/mailman/listinfo/dillo-dev
bookmarks.diff (text/x-diff, 1.4 KB)
diff -r 83f33dc92da9 dpi/bookmarks.c
--- a/dpi/bookmarks.c	Mon Jan 18 18:08:50 2016 +0000
+++ b/dpi/bookmarks.c	Sun Jan 24 16:28:37 2016 +0100
@@ -740,11 +740,20 @@
       if (buf[0] == 's') {
          /* get section, url and title */
          section = strtol(buf + 1, NULL, 10);
-         p = strchr(buf, ' '); *p = 0;
+         p = strchr(buf, ' ');
+         if (!p)
+            goto error;
+         *p = 0;
          url = ++p;
-         p = strchr(p, ' '); *p = 0;
+         p = strchr(p, ' ');
+         if (!p)
+            goto error;
+         *p = 0;
          title = ++p;
-         p = strchr(p, '\n'); *p = 0;
+         p = strchr(p, '\n');
+         if (!p)
+            goto error;
+         *p = 0;
          u_title = Unescape_html_str(title);
          Bms_add(section, url, u_title);
          dFree(u_title);
@@ -752,13 +761,22 @@
       } else if (buf[0] == ':' && buf[1] == 's') {
          /* section = strtol(buf + 2, NULL, 10); */
          p = strchr(buf + 2, ' ');
+         if (!p)
+            goto error;
          title = ++p;
          p = strchr(p, '\n'); *p = 0;
+         if (!p)
+            goto error;
          Bms_sec_add(title);
+      } else {
+         goto error;
+      }
 
-      } else {
-         MSG("Syntax error in bookmarks file:\n %s", buf);
-      }
+      dFree(buf);
+      continue;
+
+error: 
+      MSG("Syntax error in bookmarks file:\n %s", buf);
       dFree(buf);
    }
    fclose(BmTxt);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.