From: Porlock <porlock@mailinator.com>
To: 9fans@9fans.net
Subject: [9fans] Bug in ramfs.c
Date: Fri, 8 Aug 2014 12:45:16 +0100 [thread overview]
Message-ID: <53E4B84C.6080506@mailinator.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 961 bytes --]
There is a bug in ramfs which causes it to crash when the length of a
file is set to zero (using the wstat message). To see this bug, the
attached utility to set the file length is helpful.
Having first saved setlength.c into a plan9 directory, the following
commands can be used to see the bug :-
% 8c setlength.c && 8l -o setlength setlength.8
% ramfs -m /n/junk
% echo something >/n/junk/test
% ./setlength /n/junk/test 0
setting length of /n/junk/test to 0
ramfs: out of memory:
./setlength: dirwstat failed: i/o on hungup channel
% unmount /n/junk
The fix for the bug seems to be the following :-
/sys/src/cmd/ramfs.c:880,886 - ramfs2.c:880,886
erealloc(void *p, ulong n)
{
p = realloc(p, n);
- if(!p)
+ if(n && !p)
error("out of memory");
return p;
}
the point is that when n == 0, realloc(p, n) will always return null
(after first calling free(p)). So a null p is only an error if n > 0.
[-- Attachment #2: setlength.c --]
[-- Type: text/x-csrc, Size: 604 bytes --]
#include <u.h>
#include <libc.h>
void main(int argc, char **argv)
{
struct Dir st;
int i, n;
if (argc < 3) {
fprint(2, "usage: %s file length\n", argv[0]);
exits("usage");
}
n = atoi(argv[2]);
if (n < 0) {
fprint(2, "%s: invalid length\n", argv[0]);
exits("usage");
}
nulldir(&st);
st.length = n;
print("setting length of %s to %d\n", argv[1], n);
i = dirwstat(argv[1], &st);
if (i < 0) {
fprint(2, "%s: dirwstat failed: %r\n", argv[0]);
exits("dirwstat");
}
exits(0);
}
reply other threads:[~2014-08-08 11:45 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53E4B84C.6080506@mailinator.com \
--to=porlock@mailinator.com \
--cc=9fans@9fans.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).