comparison src/sequence.c @ 5891:a0e751d6c3ad

Import the #'clear-string API from GNU, use it in tls.c src/ChangeLog addition: 2015-04-18 Aidan Kehoe <kehoea@parhasard.net> * sequence.c (Fclear_string): New, API from GNU. Zero a string's contents, making sure the text is not kept around even when the string's data is reallocated because of a changed character length. * sequence.c (syms_of_sequence): Make it available to Lisp. * lisp.h: Make it available to C code. * tls.c (nss_pk11_password): Use it. * tls.c (gnutls_pk11_password): Use it. * tls.c (openssl_password): Use it. tests/ChangeLog addition: 2015-04-18 Aidan Kehoe <kehoea@parhasard.net> * automated/lisp-tests.el: Test #'clear-string, just added. Unfortunately there's no way to be certain from Lisp that the old password data has been erased after realloc; it may be worth adding a test to tests.c, but *we'll be reading memory we shouldn't be*, so that gives me pause.
author Aidan Kehoe <kehoea@parhasard.net>
date Sat, 18 Apr 2015 23:00:14 +0100
parents e9bb3688e654
children
comparison
equal deleted inserted replaced
5888:a85efdabe237 5891:a0e751d6c3ad
4150 { 4150 {
4151 sequence = wrong_type_argument (Qsequencep, sequence); 4151 sequence = wrong_type_argument (Qsequencep, sequence);
4152 goto retry; 4152 goto retry;
4153 } 4153 }
4154 return sequence; 4154 return sequence;
4155 }
4156
4157 DEFUN ("clear-string", Fclear_string, 1, 1, 0, /*
4158 Fill STRING with ?\\x00 characters. Return nil.
4159
4160 This differs from `fill' with a ?\\x00 argument in that it ensures that
4161 STRING's existing contents are discarded, even in the event of reallocation
4162 due to a change in the byte length of STRING. In this implementation, the
4163 character length of STRING is not changed.
4164 */
4165 (string))
4166 {
4167 Ibyte nullbyte[MAX_ICHAR_LEN];
4168 Bytecount zerolen = set_itext_ichar (nullbyte, 0);
4169 Charcount scount;
4170
4171 CHECK_STRING (string);
4172
4173 scount = string_char_length (string);
4174
4175 /* First, clear the original string data. */
4176 memset (XSTRING_DATA (string), 0, XSTRING_LENGTH (string));
4177
4178 /* Now, resize if that's necessary, to make sure Lisp isn't confused by the
4179 character length of a string changing. */
4180 if (string_char_length (string) != scount)
4181 {
4182 Ibyte *p, *pend;
4183 Bytecount delta = (zerolen * scount) - XSTRING_LENGTH (string);
4184
4185 resize_string (string, 0, delta);
4186 p = XSTRING_DATA (string);
4187 pend = p + XSTRING_LENGTH (string);
4188
4189 while (p < pend)
4190 {
4191 memcpy (p, nullbyte, zerolen);
4192 p += zerolen;
4193 }
4194 }
4195
4196 init_string_ascii_begin (string);
4197 bump_string_modiff (string);
4198 sledgehammer_check_ascii_begin (string);
4199
4200 return Qnil;
4155 } 4201 }
4156 4202
4157 4203
4158 /* Replace the substring of DEST beginning at START and ending before END 4204 /* Replace the substring of DEST beginning at START and ending before END
4159 with the text at SOURCE, which is END - START characters long and 4205 with the text at SOURCE, which is END - START characters long and
8314 DEFSUBR (Fnreverse); 8360 DEFSUBR (Fnreverse);
8315 DEFSUBR (Freverse); 8361 DEFSUBR (Freverse);
8316 DEFSUBR (Fmerge); 8362 DEFSUBR (Fmerge);
8317 DEFSUBR (FsortX); 8363 DEFSUBR (FsortX);
8318 DEFSUBR (Ffill); 8364 DEFSUBR (Ffill);
8365 DEFSUBR (Fclear_string);
8319 DEFSUBR (Fmapconcat); 8366 DEFSUBR (Fmapconcat);
8320 DEFSUBR (FmapcarX); 8367 DEFSUBR (FmapcarX);
8321 DEFSUBR (Fmapvector); 8368 DEFSUBR (Fmapvector);
8322 DEFSUBR (Fmapcan); 8369 DEFSUBR (Fmapcan);
8323 DEFSUBR (Fmapc); 8370 DEFSUBR (Fmapc);