From: natano Date: Thu, 6 Apr 2017 19:09:45 +0000 (+0000) Subject: Remove the CD9660MAXPATH define. It was used to construct the path for X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=299d8950f3190bb275a5d9e916bb8acfda4ba155;p=openbsd Remove the CD9660MAXPATH define. It was used to construct the path for opening the file, so PATH_MAX makes more sense here. While there change the code to do two less allocations per file. ok deraadt --- diff --git a/usr.sbin/makefs/cd9660.c b/usr.sbin/makefs/cd9660.c index c7b768bddb3..07aad8301ae 100644 --- a/usr.sbin/makefs/cd9660.c +++ b/usr.sbin/makefs/cd9660.c @@ -1,4 +1,4 @@ -/* $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 $ */ /* @@ -101,6 +101,7 @@ #include #include #include +#include #include "makefs.h" #include "cd9660.h" @@ -1453,16 +1454,22 @@ cd9660_generate_path_table(iso9660_disk *diskStructure) 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; } /* diff --git a/usr.sbin/makefs/cd9660.h b/usr.sbin/makefs/cd9660.h index 3ab3dc7fed4..90d6657e52b 100644 --- a/usr.sbin/makefs/cd9660.h +++ b/usr.sbin/makefs/cd9660.h @@ -1,4 +1,4 @@ -/* $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 $ */ /* @@ -61,8 +61,6 @@ #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 @@ -320,7 +318,7 @@ int cd9660_setup_boot_volume_descriptor(iso9660_disk *, 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 */ diff --git a/usr.sbin/makefs/cd9660/cd9660_write.c b/usr.sbin/makefs/cd9660/cd9660_write.c index 2dd1819fc7f..9bb3e383bb6 100644 --- a/usr.sbin/makefs/cd9660/cd9660_write.c +++ b/usr.sbin/makefs/cd9660/cd9660_write.c @@ -1,4 +1,4 @@ -/* $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 $ */ /* @@ -234,19 +234,14 @@ cd9660_write_path_tables(iso9660_disk *diskStructure, FILE *fd) 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; @@ -258,12 +253,12 @@ cd9660_write_file(iso9660_disk *diskStructure, FILE *fd, cd9660node *writenode) 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 { /* @@ -324,7 +319,7 @@ cd9660_write_file(iso9660_disk *diskStructure, FILE *fd, cd9660node *writenode) temp->su_tail_size, fd); if (ferror(fd)) { warnx("%s: write error", __func__); - goto out; + return 0; } cur_sector_offset += temp_record.length[0]; @@ -334,16 +329,11 @@ cd9660_write_file(iso9660_disk *diskStructure, FILE *fd, cd9660node *writenode) * 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; } /*