News for hackers. Stuff that matters.
Re:Asmttpd – Web server for Linux written in amd64 assembly by JoshTriplett on Tuesday May 19, 2015 @02:43PM (#9572220)
It needs to do so to interoperate with the OS, so using those avoids having multiple conventions and converting between them.
Re:Asmttpd – Web server for Linux written in amd64 assembly by eddyb on Tuesday May 19, 2015 @03:01PM (#9572325)
AFAIK Linux doesn't use zero-terminated strings anywhere in its syscalls, or at least not in those like write, where you pass a size alongside the buffer.
Re:Asmttpd – Web server for Linux written in amd64 assembly by reipahb on Tuesday May 19, 2015 @03:34PM (#9572557)
However (almost?) all syscalls dealing with filesystem paths take null-terminated strings. See for example the implementation of the open() syscall:

https://github.com/torvalds/linux/blob/fb65d872d7a8dc629837a...

(Hence the need for the strncpy_from_user()-function: https://github.com/torvalds/linux/blob/fb65d872d7a8dc629837a...)

Re:Asmttpd – Web server for Linux written in amd64 assembly by eddyb on Tuesday May 19, 2015 @05:29PM (#9573284)
Ahh, I totally missed the path arguments, my bad.
Re:Asmttpd – Web server for Linux written in amd64 assembly by ranit on Tuesday May 19, 2015 @03:53PM (#9572674)
write() syscall writes a sequence of bytes (not string) therefore cannot use zero-terminated convention.
Re:Asmttpd – Web server for Linux written in amd64 assembly by JoshTriplett on Tuesday May 19, 2015 @04:16PM (#9572826)
open takes a NUL-terminated filename.
Re:Asmttpd – Web server for Linux written in amd64 assembly by TheLoneWolfling on Tuesday May 19, 2015 @11:00PM (#9574431)
I'm surprised it doesn't do length-prefixed strings with a null terminator anyways. Makes a whole lot of things easier.
Re:Asmttpd – Web server for Linux written in amd64 assembly by KMag on Wednesday May 20, 2015 @08:29AM (#9575827)
As a general principle, bugs are reduced when you use representations that don't allow inconsistent representations. Unless you have an overriding reason, it's best to use a data representation that doesn't allow non-canonical representations (if such exists).

If you null-terminate a length-prefixed string, what if there's a null in the middle of the string?

(1) Allow inconsistency, and go with the length prefix in case of inconsistency. You could allow null bytes in the middle, treating it as a normal length-prefixed string, but then why do you null-terminate the string? (Is it so that you can still pass the string to functions that will choke on embedded nulls? Why would you do that?) This is just asking for kernel bugs.

(2) Allow inconsistency and go with the position of the first null byte in the case of inconsistency. If the length prefix is inconsistent with the position of the first null byte, you could go with the position of the first null byte, but then why even have the length prefix?

(3) Disallow inconsistency. You could disallow embedded nulls, but then the length prefix is just there as a place to cache strlen calls? If you're defining a syscall interface and requiring the length and first null to be consistent, then you need to run strlen anyway in order to sanity check what userspace gave you... why not simplify the external interface to just be either null-terminated or length-prefixed?

Re:Asmttpd – Web server for Linux written in amd64 assembly by TheLoneWolfling on Wednesday May 20, 2015 @11:11AM (#9576832)
I should have specified a little more, perhaps. Don't think of it as a null-terminated + length-prefixed string. It's effectively a purely length-prefixed string. There just happens to always be a null one byte after the end of the string.

The length prefix is the only thing you use, ordinarily. The only time the null comes into play is if you've already had a bug.

Think of it like a stack protector.

Re:Asmttpd – Web server for Linux written in amd64 assembly by KMag on Monday May 25, 2015 @08:28PM (#9602327)
> Think of it like a stack protector.

... but one that doesn't terminate execution, but instead hides your bugs. In most use cases, I'd prefer to find my bugs in the majority of cases, rather than to hide the bugs except for corner cases.

[dead]
Re:Asmttpd – Web server for Linux written in amd64 assembly by dang on Tuesday May 19, 2015 @03:54PM (#9572677)
Please don't make usernames that attack another user. It's uncivil and distracts from the topic.