lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:	Mon, 4 Apr 2016 11:06:49 -0600
From:	Steve Kenton <skenton@...edu>
To:	<linux-kernel@...r.kernel.org>
Subject: /sys inconsistent newline requirement on write

Feature or bug?

Using shell echo to write to /sys files normally adds an implicit
newline but
write() in a C program must add it explicitly. Some but not all /sys files
require a newline or the write fails. 'Extra' new lines from echo are
silently ignored and do not cause errors.

For example:
writing "1" to /sys/block/sd*/device/delete does not require a trailing
newline
writing "offline" to  /sys/block/sd*/device/state does require a
trailing newline

$ make test
$ sudo ./test
write failed without newline: Invalid argument

===================================================
// Test program to illustrate required newline for writes to
/sys/block/sd*/device/state
#include <stdio.h>
#include <fcntl.h>
int main(int argc, char **argv)
{
    int sysfd;
    
    if ((sysfd = open("/sys/block/sdb/device/state", O_WRONLY)) < 0)
        perror("open failed");
    else
    {
        if (write(sysfd, "offline", 7) < 0)
            perror("write failed without newline");
        if (write(sysfd, "offline\n", 8) < 0)
            perror("write failed with newline");
        if (close(sysfd))
            perror("close failed");
    }

    return 0;
}

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ