diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2011-01-13 21:44:01 +0200 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2011-01-13 21:44:01 +0200 |
commit | 73d30668abd6b786a51f10376c3c829ec29c6537 (patch) | |
tree | 1d1b129f272a6f4e42a640aac40c648210f8b037 /extension/filefuncs.c | |
parent | cf72939296bf30c0859d5ebacd956f81ef95260e (diff) | |
download | egawk-73d30668abd6b786a51f10376c3c829ec29c6537.tar.gz egawk-73d30668abd6b786a51f10376c3c829ec29c6537.tar.bz2 egawk-73d30668abd6b786a51f10376c3c829ec29c6537.zip |
Filefuncs bug fix. Finish doc index.
Diffstat (limited to 'extension/filefuncs.c')
-rw-r--r-- | extension/filefuncs.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/extension/filefuncs.c b/extension/filefuncs.c index 46873f1f..7efa912e 100644 --- a/extension/filefuncs.c +++ b/extension/filefuncs.c @@ -264,18 +264,21 @@ do_stat(int nargs) /* for symbolic links, add a linkval field */ if (S_ISLNK(sbuf.st_mode)) { - char buf[BUFSIZ*2]; + char *buf; int linksize; - linksize = readlink(file->stptr, buf, sizeof(buf) - 1); - if (linksize >= 0) { - /* should make this smarter */ - if (linksize >= sizeof(buf) - 1) - fatal("size of symbolic link too big"); + emalloc(buf, char *, sbuf.st_size + 2, "do_stat"); + if (((linksize = readlink(file->stptr, buf, + sbuf.st_size + 2)) >= 0) && + (linksize <= sbuf.st_size)) { + /* + * set the linkval field only if we are able to + * retrieve the entire link value successfully. + */ buf[linksize] = '\0'; aptr = assoc_lookup(array, tmp = make_string("linkval", 7), FALSE); - *aptr = make_string(buf, linksize); + *aptr = make_str_node(buf, linksize, ALREADY_MALLOCED); unref(tmp); } } |