From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Ted Zlatanov Newsgroups: gmane.emacs.devel Subject: Re: libnettle/libhogweed WIP Date: Sat, 15 Apr 2017 22:39:57 -0400 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <87zifhulc2.fsf@lifelogs.com> References: <83a89gq3us.fsf@gnu.org> <87bmtjiv0w.fsf_-_@lifelogs.com> <83o9xjn06c.fsf@gnu.org> <87shmeb5ln.fsf_-_@lifelogs.com> <83y3w5z1ez.fsf@gnu.org> <87lgr6yakj.fsf@lifelogs.com> <87wpamww9k.fsf@lifelogs.com> <8337daggnj.fsf@gnu.org> <87d1cdwxt6.fsf@lifelogs.com> <83tw5pg1q3.fsf@gnu.org> Reply-To: emacs-devel@gnu.org NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1492310473 5425 195.159.176.226 (16 Apr 2017 02:41:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 16 Apr 2017 02:41:13 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Apr 16 04:41:07 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cza7c-0001Gu-VQ for ged-emacs-devel@m.gmane.org; Sun, 16 Apr 2017 04:41:05 +0200 Original-Received: from localhost ([::1]:58753 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cza7i-0002uv-Sa for ged-emacs-devel@m.gmane.org; Sat, 15 Apr 2017 22:41:10 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53020) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cza6r-0002to-3X for emacs-devel@gnu.org; Sat, 15 Apr 2017 22:40:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cza6m-0001H5-TR for emacs-devel@gnu.org; Sat, 15 Apr 2017 22:40:17 -0400 Original-Received: from [195.159.176.226] (port=36241 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cza6m-0001E8-NH for emacs-devel@gnu.org; Sat, 15 Apr 2017 22:40:12 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1cza6b-0008Sq-D4 for emacs-devel@gnu.org; Sun, 16 Apr 2017 04:40:01 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: emacs-devel@gnu.org Original-Lines: 63 Original-X-Complaints-To: usenet@blaine.gmane.org X-Face: bd.DQ~'29fIs`T_%O%C\g%6jW)yi[zuz6; d4V0`@y-~$#3P_Ng{@m+e4o<4P'#(_GJQ%TT= D}[Ep*b!\e,fBZ'j_+#"Ps?s2!4H2-Y"sx" Mail-Copies-To: never Cancel-Lock: sha1:EWtQ22bM+ZScFGD8IKz4Z3EMGGY= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:213985 Archived-At: On Sat, 15 Apr 2017 17:55:00 +0300 Eli Zaretskii wrote: >> From: Ted Zlatanov >> Date: Sat, 15 Apr 2017 10:27:33 -0400 >> >> These two comments are related: for example, the decryption with >> CAMELLIA-256-GCM produces less bytes of output that the input. But I >> don't want to try to anticipate that byte count--it complicates the code >> needlessly. So instead I want to cut the Lisp string `storage' to >> `storage_length' bytes after gnutls_aead_cipher_{encrypt,decrypt}() >> modifies `storage_length'. I can't find a macro or function to do it, so >> I used make_unibyte_string() for now and am asking how to do it better. EZ> I think STRING_SET_CHARS is what you want here. Thank you for letting me know. That macro has a terrible name and should probably be called STRING_SET_{SIZE,LENGTH} or similar. But yeah, it seems right. When I replace gnutls.c:1828 return make_unibyte_string (SSDATA (storage), storage_length); with STRING_SET_CHARS (storage, storage_length); return storage; I get a segfault running the tests: #+begin_src text Thread 1 "emacs" received signal SIGSEGV, Segmentation fault. compact_small_strings () at alloc.c:2227 2227 nbytes = s ? STRING_BYTES (s) : SDATA_NBYTES (from); [gdb]> bt #0 compact_small_strings () at alloc.c:2227 #1 sweep_strings () at alloc.c:2159 #2 0x00000000005542d4 in gc_sweep () at alloc.c:7088 #3 garbage_collect_1 (end=) at alloc.c:5965 #4 Fgarbage_collect () at alloc.c:6096 #5 0x000000000056b1ef in maybe_gc () at lisp.h:4667 #6 eval_sub (form=0x14ef193) at eval.c:2128 ... [gdb]> p s $1 = (struct Lisp_String *) 0x2020202020202020 [gdb]> p *s Cannot access memory at address 0x2020202020202020 #+end_src It happens during the tests with 100% certainty but I'm not sure what test or string specifically caused it. EZ> Buffer text is just a C string (with the slight complication of the EZ> gap), so I don't understand why you'd need to rewrite code that much. Like I said, the first 150 lines of secure_hash() demonstrate the complexity. I'll just pull them out into a common function and use that, and assume you're right that only buffer extraction and direct strings are needed, and that the other ideas I had were not so good. Thanks for your help Ted