summaryrefslogtreecommitdiff
path: root/extension
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2011-01-13 21:44:01 +0200
committerArnold D. Robbins <arnold@skeeve.com>2011-01-13 21:44:01 +0200
commit73d30668abd6b786a51f10376c3c829ec29c6537 (patch)
tree1d1b129f272a6f4e42a640aac40c648210f8b037 /extension
parentcf72939296bf30c0859d5ebacd956f81ef95260e (diff)
downloadgawk-73d30668abd6b786a51f10376c3c829ec29c6537.tar.gz
Filefuncs bug fix. Finish doc index.
Diffstat (limited to 'extension')
-rw-r--r--extension/ChangeLog5
-rw-r--r--extension/filefuncs.c17
2 files changed, 15 insertions, 7 deletions
diff --git a/extension/ChangeLog b/extension/ChangeLog
index 19cfbee0..926bf0b5 100644
--- a/extension/ChangeLog
+++ b/extension/ChangeLog
@@ -1,3 +1,8 @@
+Thu Jan 13 20:37:02 2011 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * filefuncs.c (do_stat): Malloc the buffer to read the contents
+ of the link. From mail of June 21, 2005.
+
Sun Jan 2 21:08:17 2011 Arnold D. Robbins <arnold@skeeve.com>
* filefuncs.c: Synched with code in gawk.texi, copyright dates
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);
}
}