[hackers] [scc] [cc2-qbe] Use copy in or/and operations || Roberto E. Vargas Caballero

2016-09-20 Thread git
commit 52958e5bbdf55f88a0abaab3b2cb130ba148710a
Author: Roberto E. Vargas Caballero 
AuthorDate: Tue Sep 20 12:20:42 2016 +0200
Commit: Roberto E. Vargas Caballero 
CommitDate: Tue Sep 20 12:20:42 2016 +0200

[cc2-qbe] Use copy in or/and operations

In the case of or/and operations we have a phi node, and we have
two possibilities in qbe for this case, the phi instruction or
the copy instruction. The copy instruction is more similar to
what were trying (incorrectly) until this moment.

diff --git a/cc2/arch/qbe/arch.h b/cc2/arch/qbe/arch.h
index 38eafbb..16b7835 100644
--- a/cc2/arch/qbe/arch.h
+++ b/cc2/arch/qbe/arch.h
@@ -144,4 +144,6 @@ enum asmop {
ASPARE,
ASALLOC,
ASFORM,
+
+   ASCOPYW,
 };
diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c
index 7b176df..fb60d1b 100644
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -443,11 +443,11 @@ rhs(Node *np, Node *ret)
bool(np, true, false);
 
setlabel(true);
-   assign(, ret, constnode(, 1, ));
+   code(ASCOPYW, ret, constnode(, 1, ), NULL);
code(ASJMP, NULL, phi, NULL);
 
setlabel(false);
-   assign(, ret, constnode(, 0, ));
+   code(ASCOPYW, ret, constnode(, 0, ), NULL);
 
setlabel(phi->u.sym);
return ret;
diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c
index e6845fd..677c5d6 100644
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
@@ -25,6 +25,8 @@ static struct opdata {
[ASLDS]   =  {.fun = unary,  .txt = "load", .letter = 's'},
[ASLDD]   =  {.fun = unary,  .txt = "load", .letter = 'd'},
 
+   [ASCOPYW] =  {.fun = unary,  .txt = "copy", .letter = 'w'},
+
[ASSTB]   =  {.fun = store,  .txt = "store", .letter = 'b'},
[ASSTH]   =  {.fun = store,  .txt = "store", .letter = 'h'},
[ASSTW]   =  {.fun = store,  .txt = "store", .letter = 'w'},



Re: [hackers] [slock] [PATCHSET] Some improvements and more security

2016-09-20 Thread Markus Teich
FRIGN wrote:
> I sat down this evening to write down some patches that have been floating
> around in my head for a while.

Heyho,

thanks for the patches.

> Subject: [PATCH 1/3] Localize and rework data structures
> …
> -typedef struct {
> +struct lock {
>   int screen;
>   Window root, win;
>   Pixmap pmap;
>   unsigned long colors[NUMCOLS];
> -} Lock;
> +};

Removing the typedef is against the coding style, but I like it for slock. If I
remember correctly the arguments were purely cosmetic: brevity (pro typedef) vs.
clarity (explicitly stating `struct bla` each time). Since slock is a security
relevant program I prefer clarity.

>  static void
> -cleanup(Display *dpy)
> +cleanup(Display **dpy, struct lock ***locks, int *nscreens)
>  {
>   int s;
>  
> - for (s = 0; s < nscreens; ++s)
> - unlockscreen(dpy, locks[s]);
> + for (s = 0; s < *nscreens; ++s)
> + unlockscreen(*dpy, (*locks)[s]);
> + *nscreens = 0;
>  
> - free(locks);
> - XCloseDisplay(dpy);
> + free(*locks);
> + *locks = NULL;
> + XCloseDisplay(*dpy);
> + *dpy = NULL;
>  }

The new cleanup function seems to only be a half measure. If you think zeroing
out nscreens and the dpy and locks pointers is worth it even though currently(!)
cleanup() is only called right before die() or return from main, why not do it
right after XOpenDisplay()? There are three die() calls which don't clean dpy
and one which doesn't clean nscreens. Either leave it as is or go all the way,
add checks like `if (*locks)` before cleaning and always use this state
resistant cleanup function.

> Subject: [PATCH 2/3] Rename getpw() and pws to gethash() and hash
> …
> - if (!(encrypted = crypt(passwd, pws)))
> + if (!(encrypted = crypt(passwd, hash)))

Additionally I'd rename `encrypted` to `hashed` to make it clear that crypt() is
just recomputing the hash.

> Subject: [PATCH 3/3] Stop using $USER for shadow entries
> …
> - const char *rval;
> + const char *hash;

This rename belongs in the second patch.

--Markus



Re: [hackers] [sbase][PATCH] ed: bugfixes to do with j, wrote ed.1.

2016-09-20 Thread Thomas Mannay

First patch I write, I don't notice the formatting got indented for no
reason. Man. Sorry about that.



[hackers] [sbase][PATCH] ed: bugfixes to do with j, wrote ed.1.

2016-09-20 Thread Thomas Mannay
---
 ed.1 | 204 +-
 ed.c | 250 ++-
 2 files changed, 331 insertions(+), 123 deletions(-)

diff --git a/ed.1 b/ed.1
index 93e3012..520ac5f 100644
--- a/ed.1
+++ b/ed.1
@@ -6,4 +6,206 @@
 .Nd text editor
 .Sh SYNOPSIS
 .Nm
-is the standard text editor.
+.Op Fl s
+.Op Fl p Ar string
+.Op Ar file
+.Sh DESCRIPTION
+.Nm
+is the standard text editor. It performs line-oriented operations on a buffer;
+The buffer's contents are manipulated in command mode and text is written to 
the
+buffer in input mode. Command mode is the default. To exit input mode enter a
+dot ('.') on a line of its own.
+
+If
+.Nm
+is invoked with a file as an argument, it will simulate an edit command and 
read
+the file's contents into a buffer. Changes to this buffer are local to
+.Nm
+until a write command is given.
+
+.Nm
+uses the basic regular expression syntax and allows any character but space and
+newline to be used as a delimiter in regular expressions.
+.Sh OPTIONS
+.Bl -tag -width Ds
+.It Fl s
+Suppress diagnostic messages
+.It Fl p Ar string
+Use
+.Ar string
+as a prompt when in command mode
+.El
+.Sh EXTENDED DESCRIPTION
+.Ss Addresses
+Commands operate on addresses. Addresses are used to refer to lines
+within the buffer. Address ranges may have spaces before and after the 
separator.
+Unless otherwise specified, 0 is an invalid address. The following symbols are
+valid addresses:
+.Bl -tag -width Ds
+.It n
+The nth line.
+.It .
+The current line, or "dot".
+.It $
+The last line.
+.It +
+The next line.
+.It +n
+The nth next line.
+.It ^ or -
+The previous line.
+.It ^n or -n
+The nth previous line.
+.It x,y
+The range of lines from x to y. The default value of x is 1, and the default
+value of y is $.
+.It x;y
+As above, except that the current line is set to x. Omitting x in this case 
uses
+the current line as the default value.
+.It /re/
+The next line matching re.
+.It ?re?
+The last line matching re.
+.It 'c
+The line marked by c. See k below.
+.El
+.Ss Commands.
+.Nm
+expects to see one command per line, with the following exception: commands may
+be suffixed with either a list, number, or print command. These suffixed
+commands are run after the command they're suffixed to has executed.
+
+The following is the list of commands that
+.Nm
+knows about. The parentheses contain the default addresses that a command uses.
+.Bl -tag -width Ds
+.It (.)a
+Append text after the addressed line. The dot is set to the last line
+entered. If no text was entered, the dot is set to the addressed line. An
+address of 0 appends to the start of the buffer.
+.It (.,.)c
+Delete the addressed lines and then accept input to replace them. The dot
+is set to the last line entered. If no text was entered, the dot is set to
+the line before the deleted lines.
+.It (.,.)d
+Delete the addressed lines. If there is a line after the deleted range, the
+dot is set to it. Otherwise, the dot is set to the line before the deleted 
range.
+.It e Ar file
+Delete the contents of the buffer and load in
+.Ar file
+for editing, printing the bytes read to standard output. If no filename is
+given,
+.Nm
+uses the currently remembered filename. The remembered filename is set to
+.Ar file
+for later use.
+.It E Ar file
+As above, but without warning if the current buffer has unsaved changes.
+.It f Ar file
+Set the currently remembered filename to
+.Ar
+file
+, or print the currently remembered filename if
+.Ar
+file is omitted.
+.It (1,$)g/re/command
+Apply command to lines matching re. The dot is set to the matching line before
+command is executed. When each matching line has been operated on, the dot is
+set to the last line operated on. If no lines match then the dot remains
+unchanged. The command used may not be g, G, v, or V.
+.It (1,$)G/re/
+Interactively edit the range of line addresses that match re. The dot is set to
+the matching line and printed before a command is input. When each matching 
line
+has been operated on, the dot is set to the last line operated on. If no lines
+match then the dot remains unchanged. The command used may not be a, c, i, g,
+G, v, or V.
+.It h
+Print the reason for the most recent error.
+.It H
+Toggle error explanations. If on, the above behaviour is produced on all
+subsequent errors.
+.It (.)i
+Insert text into the buffer before the addressed line. The dot is set to the
+last line entered. If no text was entered, the dot is set to the addressed line
+.It (.,.+1)j
+Join two lines together. If only one address is given, nothing happens. The dot
+is set to the newly joined line.
+.It (.)kc
+Mark the line with the lower case character c. The dot is unchanged.
+.It (.,.)l
+Unambiguously print the addressed lines. The dot is set to the last line 
written.
+.It (.,.)m(.)
+Move lines in the buffer to the line address on the right hand side. An address
+of 0 on the right hand side moves to the start of the buffer.