Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1374618

Re: alternatives to null-terminated byte arrays in syscalls in the future?

From One Thousand Gnomes <gnomes@lxorguk.ukuu.org.uk>
Newsgroups linux.kernel
Subject Re: alternatives to null-terminated byte arrays in syscalls in the future?
Date 2016-04-09 14:40 +0200
Message-ID <rm0lc-4YO-1@gated-at.bofh.it> (permalink)
References <rlLPd-1q5-17@gated-at.bofh.it>
Organization Intel Corporation

Show all headers | View raw


On Fri, 8 Apr 2016 14:04:00 -0700
Andrew Kelley <superjoe30@gmail.com> wrote:

> The open syscall looks like this:
> 
> SYSCALL_DEFINE3(open, const char __user *, filename, int, flags, umode_t, mode)
> 
> filename is a null terminated byte array. Null termination is one way
> to handle lengths of byte arrays, but arguably a better way is to keep
> track of the length in a separate field. Many programming languages
> use pointer + length instead of null termination for various reasons.
> 
> When it's time to make a syscall such as open, software which does not
> have a null character at the end of byte arrays are forced to allocate
> memory, do a memcpy, insert a null byte, perform the open syscall,
> then deallocate the memory.

That should only happen if the language wasn't carefully thought out. If
your name objects include both the length and the space available so you
can do array offset validation then

- you can check if the \0 will fit
- your app or interreter can add space for \0 or even include it
  specifically

I would also be very surprised if most applications doing such
conversions even showed up meaningfully in the profiling. pathname
syscalls are not the most common ones being executed.

Alan

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

alternatives to null-terminated byte arrays in syscalls in the future? Andrew Kelley <superjoe30@gmail.com> - 2016-04-08 23:10 +0200
  Re: alternatives to null-terminated byte arrays in syscalls in the future? Denys Vlasenko <vda.linux@googlemail.com> - 2016-04-08 23:20 +0200
    Re: alternatives to null-terminated byte arrays in syscalls in the future? Andrew Kelley <superjoe30@gmail.com> - 2016-04-08 23:30 +0200
  Re: alternatives to null-terminated byte arrays in syscalls in the  future? One Thousand Gnomes <gnomes@lxorguk.ukuu.org.uk> - 2016-04-09 14:40 +0200

csiph-web