-/* $OpenBSD: cd9660.c,v 1.19 2016/12/17 16:12:15 krw Exp $ */
+/* $OpenBSD: cd9660.c,v 1.20 2017/04/06 19:09:45 natano Exp $ */
/* $NetBSD: cd9660.c,v 1.53 2016/11/25 23:02:44 christos Exp $ */
/*
#include <string.h>
#include <ctype.h>
#include <inttypes.h>
+#include <limits.h>
#include "makefs.h"
#include "cd9660.h"
return pathTableSize;
}
-void
-cd9660_compute_full_filename(cd9660node *node, char *buf)
+char *
+cd9660_compute_full_filename(cd9660node *node)
{
+ static char buf[PATH_MAX];
int len;
- len = CD9660MAXPATH + 1;
- len = snprintf(buf, len, "%s/%s/%s", node->node->root,
+ len = snprintf(buf, PATH_MAX, "%s/%s/%s", node->node->root,
node->node->path, node->node->name);
- if (len > CD9660MAXPATH)
- errx(1, "Pathname too long.");
+ if (len < 0) {
+ warn(NULL);
+ return NULL;
+ } else if (len >= PATH_MAX) {
+ warnc(ENAMETOOLONG, NULL);
+ return NULL;
+ }
+ return buf;
}
/*
-/* $OpenBSD: cd9660.h,v 1.12 2016/12/17 16:12:15 krw Exp $ */
+/* $OpenBSD: cd9660.h,v 1.13 2017/04/06 19:09:45 natano Exp $ */
/* $NetBSD: cd9660.h,v 1.21 2015/12/24 15:52:37 christos Exp $ */
/*
#define INODE_WARNX(__x)
#endif /* DEBUG */
-#define CD9660MAXPATH 4096
-
#define ISO_STRING_FILTER_NONE = 0x00
#define ISO_STRING_FILTER_DCHARS = 0x01
#define ISO_STRING_FILTER_ACHARS = 0x02
int cd9660_write_image(iso9660_disk *, const char *image);
int cd9660_copy_file(iso9660_disk *, FILE *, off_t, const char *);
-void cd9660_compute_full_filename(cd9660node *, char *);
+char *cd9660_compute_full_filename(cd9660node *);
int cd9660_compute_record_size(iso9660_disk *, cd9660node *);
/* Debugging functions */
-/* $OpenBSD: cd9660_write.c,v 1.7 2016/12/17 16:22:04 krw Exp $ */
+/* $OpenBSD: cd9660_write.c,v 1.8 2017/04/06 19:09:45 natano Exp $ */
/* $NetBSD: cd9660_write.c,v 1.17 2013/10/19 17:16:37 christos Exp $ */
/*
static int
cd9660_write_file(iso9660_disk *diskStructure, FILE *fd, cd9660node *writenode)
{
- char *buf;
char *temp_file_name;
- int ret;
off_t working_sector;
int cur_sector_offset;
iso_directory_record_cd9660 temp_record;
cd9660node *temp;
- int rv = 0;
/* Todo : clean up variables */
- temp_file_name = ecalloc(CD9660MAXPATH + 1, 1);
- buf = emalloc(diskStructure->sectorSize);
if ((writenode->level != 0) &&
!(writenode->node->type & S_IFDIR)) {
fsinode *inode = writenode->node->inode;
INODE_WARNX(("%s: writing inode %d blocks at %" PRIu32,
__func__, (int)inode->st.st_ino, inode->ino));
inode->flags |= FI_WRITTEN;
- cd9660_compute_full_filename(writenode,
- temp_file_name);
- ret = cd9660_copy_file(diskStructure, fd,
- writenode->fileDataSector, temp_file_name);
- if (ret == 0)
- goto out;
+ temp_file_name = cd9660_compute_full_filename(writenode);
+ if (temp_file_name == NULL)
+ return 0;
+ if (cd9660_copy_file(diskStructure, fd,
+ writenode->fileDataSector, temp_file_name) == 0)
+ return 0;
}
} else {
/*
temp->su_tail_size, fd);
if (ferror(fd)) {
warnx("%s: write error", __func__);
- goto out;
+ return 0;
}
cur_sector_offset += temp_record.length[0];
* Recurse on children.
*/
TAILQ_FOREACH(temp, &writenode->cn_children, cn_next_child) {
- if ((ret = cd9660_write_file(diskStructure, fd, temp))
- == 0)
- goto out;
+ if (cd9660_write_file(diskStructure, fd, temp) == 0)
+ return 0;
}
}
- rv = 1;
-out:
- free(temp_file_name);
- free(buf);
- return rv;
+ return 1;
}
/*