Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Where we use a fixed size char array as a buffer or as a member of a structure, use the sizeof() operator later in the same scope when we need to know the length of the array.
Matthew Seaman committed 12 years ago
commit 2f3cf0c1f8cadbbb55d859cf27c223097cd34efe
parent d7d8399
13 files changed +46 -46
modified libpkg/dns_utils.c
@@ -122,7 +122,7 @@ dns_getsrvinfo(const char *zone)

	while(qdcount > 0 && p < end) {
		qdcount--;
-
		if((len = dn_expand(q.buf, end, p, host, MAXHOSTNAMELEN)) < 0)
+
		if((len = dn_expand(q.buf, end, p, host, sizeof(host))) < 0)
			return (NULL);
		p += len + NS_QFIXEDSZ;
	}
@@ -134,7 +134,7 @@ dns_getsrvinfo(const char *zone)
	n = 0;
	while (ancount > 0 && p < end) {
		ancount--;
-
		len = dn_expand(q.buf, end, p, host, MAXHOSTNAMELEN);
+
		len = dn_expand(q.buf, end, p, host, sizeof(host));
		if (len < 0) {
			for (i = 0; i < n; i++)
				free(res[i]);
@@ -158,7 +158,7 @@ dns_getsrvinfo(const char *zone)
		NS_GET16(weight, p);
		NS_GET16(port, p);

-
		len = dn_expand(q.buf, end, p, host, MAXHOSTNAMELEN);
+
		len = dn_expand(q.buf, end, p, host, sizeof(host));
		if (len < 0) {
			for (i = 0; i < n; i++)
				free(res[i]);
@@ -181,7 +181,7 @@ dns_getsrvinfo(const char *zone)
		res[n]->port = port;
		res[n]->next = NULL;
		res[n]->finalweight = 0;
-
		strlcpy(res[n]->host, host, MAXHOSTNAMELEN);
+
		strlcpy(res[n]->host, host, sizeof(res[n]->host));

		p += len;
		n++;
modified libpkg/fetch.c
@@ -483,7 +483,7 @@ pkg_fetch_file_to_fd(struct pkg_repo *repo, const char *url, int dest, time_t *t
		else if (repo != NULL && repo->mirror_type == HTTP && repo->http != NULL) {
			strlcpy(u->scheme, http_current->url->scheme, sizeof(u->scheme));
			strlcpy(u->host, http_current->url->host, sizeof(u->host));
-
			snprintf(docpath, MAXPATHLEN, "%s%s", http_current->url->doc, doc);
+
			snprintf(docpath, sizeof(docpath), "%s%s", http_current->url->doc, doc);
			u->doc = docpath;
			u->port = http_current->url->port;
		}
modified libpkg/pkg_config.c
@@ -905,7 +905,7 @@ load_repo_files(const char *repodir)
			continue;
		p = &ent->d_name[n - 5];
		if (strcmp(p, ".conf") == 0) {
-
			snprintf(path, MAXPATHLEN, "%s/%s", repodir, ent->d_name);
+
			snprintf(path, sizeof(path), "%s/%s", repodir, ent->d_name);
			load_repo_file(path);
		}
	}
modified libpkg/pkg_elf.c
@@ -427,9 +427,9 @@ pkg_analyse_files(struct pkgdb *db, struct pkg *pkg, const char *stage)

	while (pkg_files(pkg, &file) == EPKG_OK) {
		if (stage != NULL)
-
			snprintf(fpath, MAXPATHLEN, "%s/%s", stage, pkg_file_path(file));
+
			snprintf(fpath, sizeof(fpath), "%s/%s", stage, pkg_file_path(file));
		else
-
			strlcpy(fpath, pkg_file_path(file), MAXPATHLEN);
+
			strlcpy(fpath, pkg_file_path(file), sizeof(fpath));

		ret = analyse_elf(pkg, fpath, action, db);
		if (developer) {
@@ -466,7 +466,7 @@ pkg_register_shlibs(struct pkg *pkg, const char *root)

	while(pkg_files(pkg, &file) == EPKG_OK) {
		if (root != NULL) {
-
			snprintf(fpath, MAXPATHLEN, "%s%s", root, pkg_file_path(file));
+
			snprintf(fpath, sizeof(fpath), "%s%s", root, pkg_file_path(file));
			analyse_elf(pkg, fpath, add_shlibs_to_pkg, NULL);
		} else
			analyse_elf(pkg, pkg_file_path(file), add_shlibs_to_pkg, NULL);
modified libpkg/pkg_jobs.c
@@ -1301,7 +1301,7 @@ pkg_jobs_fetch(struct pkg_jobs *j)
	while (pkg_jobs(j, &p) == EPKG_OK) {
		int64_t pkgsize;
		pkg_get(p, PKG_PKGSIZE, &pkgsize, PKG_REPOPATH, &repopath);
-
		snprintf(cachedpath, MAXPATHLEN, "%s/%s", cachedir, repopath);
+
		snprintf(cachedpath, sizeof(cachedpath), "%s/%s", cachedir, repopath);
		if (stat(cachedpath, &st) == -1)
			dlsize += pkgsize;
		else
modified libpkg/pkg_old.c
@@ -68,11 +68,11 @@ pkg_old_load_from_path(struct pkg *pkg, const char *path)
	if (!is_dir(path))
		return (EPKG_FATAL);

-
	snprintf(fpath, MAXPATHLEN, "%s/+CONTENTS", path);
+
	snprintf(fpath, sizeof(fpath), "%s/+CONTENTS", path);
	if (ports_parse_plist(pkg, fpath, NULL) != EPKG_OK)
		return (EPKG_FATAL);

-
	snprintf(fpath, MAXPATHLEN, "%s/+COMMENT", path);
+
	snprintf(fpath, sizeof(fpath), "%s/+COMMENT", path);
	if (access(fpath, F_OK) == 0)
		pkg_set_from_file(pkg, PKG_COMMENT, fpath, true);

@@ -238,29 +238,29 @@ pkg_register_old(struct pkg *pkg)
	pkg_old_emit_content(pkg, &content);

	pkg_config_string(PKG_CONFIG_DBDIR, &pkgdbdir);
-
	snprintf(path, MAXPATHLEN, "%s/%s-%s", pkgdbdir, name, version);
+
	snprintf(path, sizeof(path), "%s/%s-%s", pkgdbdir, name, version);
	mkdir(path, 0755);

-
	snprintf(path, MAXPATHLEN, "%s/%s-%s/+CONTENTS", pkgdbdir, name, version);
+
	snprintf(path, sizeof(path), "%s/%s-%s/+CONTENTS", pkgdbdir, name, version);
	fp = fopen(path, "w");
	fputs(content, fp);
	fclose(fp);

	pkg_get(pkg, PKG_DESC, &buf);
-
	snprintf(path, MAXPATHLEN, "%s/%s-%s/+DESC", pkgdbdir, name, version);
+
	snprintf(path, sizeof(path), "%s/%s-%s/+DESC", pkgdbdir, name, version);
	fp = fopen(path, "w");
	fputs(buf, fp);
	fclose(fp);

	pkg_get(pkg, PKG_COMMENT, &buf);
-
	snprintf(path, MAXPATHLEN, "%s/%s-%s/+COMMENT", pkgdbdir, name, version);
+
	snprintf(path, sizeof(path), "%s/%s-%s/+COMMENT", pkgdbdir, name, version);
	fp = fopen(path, "w");
	fprintf(fp, "%s\n", buf);
	fclose(fp);

	pkg_get(pkg, PKG_MESSAGE, &buf);
	if (buf != NULL && *buf != '\0') {
-
		snprintf(path, MAXPATHLEN, "%s/%s-%s/+DISPLAY", pkgdbdir, name, version);
+
		snprintf(path, sizeof(path), "%s/%s-%s/+DISPLAY", pkgdbdir, name, version);
		fp = fopen(path, "w");
		fputs(buf, fp);
		fclose(fp);
@@ -297,7 +297,7 @@ pkg_register_old(struct pkg *pkg)
	}
	if (sbuf_len(install_script) > 0) {
		sbuf_finish(install_script);
-
		snprintf(path, MAXPATHLEN, "%s/%s-%s/+INSTALL", pkgdbdir, name, version);
+
		snprintf(path, sizeof(path), "%s/%s-%s/+INSTALL", pkgdbdir, name, version);
		fp = fopen(path, "w");
		fputs(sbuf_data(install_script), fp);
		fclose(fp);
@@ -334,14 +334,14 @@ pkg_register_old(struct pkg *pkg)
	}
	if (sbuf_len(deinstall_script) > 0) {
		sbuf_finish(deinstall_script);
-
		snprintf(path, MAXPATHLEN, "%s/%s-%s/+DEINSTALL", pkgdbdir, name, version);
+
		snprintf(path, sizeof(path), "%s/%s-%s/+DEINSTALL", pkgdbdir, name, version);
		fp = fopen(path, "w");
		fputs(sbuf_data(deinstall_script), fp);
		fclose(fp);
	}

	while (pkg_deps(pkg, &dep)) {
-
		snprintf(path, MAXPATHLEN, "%s/%s-%s/+REQUIRED_BY", pkgdbdir,
+
		snprintf(path, sizeof(path), "%s/%s-%s/+REQUIRED_BY", pkgdbdir,
		    pkg_dep_name(dep), pkg_dep_version(dep));
		fp = fopen(path, "a");
		fprintf(fp, "%s-%s\n", name, version);
modified libpkg/pkgdb_repo.c
@@ -197,7 +197,7 @@ file_exists(sqlite3_context *ctx, int argc, sqlite3_value **argv)
		return;
	}

-
	snprintf(fpath, MAXPATHLEN, "%s/%s", path, sqlite3_value_text(argv[0]));
+
	snprintf(fpath, sizeof(fpath), "%s/%s", path, sqlite3_value_text(argv[0]));

	if (access(fpath, R_OK) == 0) {
		sha256_file(fpath, cksum);
modified libpkg/plugins.c
@@ -394,7 +394,7 @@ pkg_plugins_init(void)
		/*
		 * Load the plugin
		 */
-
		snprintf(pluginfile, MAXPATHLEN, "%s/%s.so", plugdir,
+
		snprintf(pluginfile, sizeof(pluginfile), "%s/%s.so", plugdir,
		    pkg_config_value(v));
		p = calloc(1, sizeof(struct pkg_plugin));
		if ((p->lh = dlopen(pluginfile, RTLD_LAZY)) == NULL) {
modified libpkg/rcscripts.c
@@ -54,7 +54,7 @@ pkg_start_stop_rc_scripts(struct pkg *pkg, pkg_rc_attr attr)

	pkg_get(pkg, PKG_PREFIX, &prefix);

-
	snprintf(rc_d_path, PATH_MAX, "%s/etc/rc.d/", prefix);
+
	snprintf(rc_d_path, sizeof(rc_d_path), "%s/etc/rc.d/", prefix);
	len = strlen(rc_d_path);

	while (pkg_files(pkg, &file) == EPKG_OK) {
modified libpkg/update.c
@@ -79,13 +79,13 @@ repo_fetch_remote_tmp(struct pkg_repo *repo, const char *filename, const char *e
	mode_t mask;
	const char *tmpdir;

-
	snprintf(url, MAXPATHLEN, "%s/%s.%s", pkg_repo_url(repo), filename, extension);
+
	snprintf(url, sizeof(url), "%s/%s.%s", pkg_repo_url(repo), filename, extension);

	tmpdir = getenv("TMPDIR");
	if (tmpdir == NULL)
		tmpdir = "/tmp";
	mkdirs(tmpdir);
-
	snprintf(tmp, MAXPATHLEN, "%s/%s.%s.XXXXXX", tmpdir, filename, extension);
+
	snprintf(tmp, sizeof(tmp), "%s/%s.%s.XXXXXX", tmpdir, filename, extension);

	mask = umask(022);
	fd = mkstemp(tmp);
@@ -174,7 +174,7 @@ load_fingerprint(const char *dir, const char *filename)
	char path[MAXPATHLEN];
	struct fingerprint *f = NULL;

-
	snprintf(path, MAXPATHLEN, "%s/%s", dir, filename);
+
	snprintf(path, sizeof(path), "%s/%s", dir, filename);

	p = ucl_parser_new(0);

@@ -281,13 +281,13 @@ repo_archive_extract_file(int fd, const char *file, const char *dest, struct pkg

		if (pkg_repo_signature_type(repo) == SIG_FINGERPRINT) {
			if (has_ext(archive_entry_pathname(ae), ".sig")) {
-
				snprintf(key, MAXPATHLEN, "%.*s",
+
				snprintf(key, sizeof(key), "%.*s",
				    (int) strlen(archive_entry_pathname(ae)) - 4,
				    archive_entry_pathname(ae));
				HASH_FIND_STR(sc, key, s);
				if (s == NULL) {
					s = calloc(1, sizeof(struct sig_cert));
-
					strlcpy(s->name, key, MAXPATHLEN);
+
					strlcpy(s->name, key, sizeof(s->name));
					HASH_ADD_STR(sc, name, s);
				}
				s->siglen = archive_entry_size(ae);
@@ -295,13 +295,13 @@ repo_archive_extract_file(int fd, const char *file, const char *dest, struct pkg
				archive_read_data(a, s->sig, s->siglen);
			}
			if (has_ext(archive_entry_pathname(ae), ".pub")) {
-
				snprintf(key, MAXPATHLEN, "%.*s",
+
				snprintf(key, sizeof(key), "%.*s",
				    (int) strlen(archive_entry_pathname(ae)) - 4,
				    archive_entry_pathname(ae));
				HASH_FIND_STR(sc, key, s);
				if (s == NULL) {
					s = calloc(1, sizeof(struct sig_cert));
-
					strlcpy(s->name, key, MAXPATHLEN);
+
					strlcpy(s->name, key, sizeof(s->name));
					HASH_ADD_STR(sc, name, s);
				}
				s->certlen = archive_entry_size(ae);
@@ -336,7 +336,7 @@ repo_archive_extract_file(int fd, const char *file, const char *dest, struct pkg
		}

		/* load fingerprints */
-
		snprintf(path, MAXPATHLEN, "%s/trusted", pkg_repo_fingerprints(repo));
+
		snprintf(path, sizeof(path), "%s/trusted", pkg_repo_fingerprints(repo));
		if ((load_fingerprints(path, &trusted)) != EPKG_OK) {
			pkg_emit_error("Error loading trusted certificates");
			rc = EPKG_FATAL;
@@ -349,7 +349,7 @@ repo_archive_extract_file(int fd, const char *file, const char *dest, struct pkg
			goto cleanup;
		}

-
		snprintf(path, MAXPATHLEN, "%s/revoked", pkg_repo_fingerprints(repo));
+
		snprintf(path, sizeof(path), "%s/revoked", pkg_repo_fingerprints(repo));
		if ((load_fingerprints(path, &revoked)) != EPKG_OK) {
			pkg_emit_error("Error loading revoked certificates");
			rc = EPKG_FATAL;
@@ -430,7 +430,7 @@ repo_fetch_remote_extract_tmp(struct pkg_repo *repo, const char *filename,
	tmpdir = getenv("TMPDIR");
	if (tmpdir == NULL)
		tmpdir = "/tmp";
-
	snprintf(tmp, MAXPATHLEN, "%s/%s.XXXXXX", tmpdir, archive_file);
+
	snprintf(tmp, sizeof(tmp), "%s/%s.XXXXXX", tmpdir, archive_file);

	mask = umask(022);
	dest_fd = mkstemp(tmp);
modified pkg/convert.c
@@ -90,29 +90,29 @@ convert_to_old(const char *pkg_add_dbdir, bool dry_run)
		pkg_to_old(pkg);
		pkg_old_emit_content(pkg, &content);

-
		snprintf(path, MAXPATHLEN, "%s/%s-%s", pkg_add_dbdir, name, version);
+
		snprintf(path, sizeof(path), "%s/%s-%s", pkg_add_dbdir, name, version);
		mkdir(path, 0755);

-
		snprintf(path, MAXPATHLEN, "%s/%s-%s/+CONTENTS", pkg_add_dbdir, name, version);
+
		snprintf(path, sizeof(path), "%s/%s-%s/+CONTENTS", pkg_add_dbdir, name, version);
		fp = fopen(path, "w");
		fputs(content, fp);
		fclose(fp);

		pkg_get(pkg, PKG_DESC, &buf);
-
		snprintf(path, MAXPATHLEN, "%s/%s-%s/+DESC", pkg_add_dbdir, name, version);
+
		snprintf(path, sizeof(path), "%s/%s-%s/+DESC", pkg_add_dbdir, name, version);
		fp = fopen(path, "w");
		fputs(buf, fp);
		fclose(fp);

		pkg_get(pkg, PKG_COMMENT, &buf);
-
		snprintf(path, MAXPATHLEN, "%s/%s-%s/+COMMENT", pkg_add_dbdir, name, version);
+
		snprintf(path, sizeof(path), "%s/%s-%s/+COMMENT", pkg_add_dbdir, name, version);
		fp = fopen(path, "w");
		fprintf(fp, "%s\n", buf);
		fclose(fp);

		pkg_get(pkg, PKG_MESSAGE, &buf);
		if (buf != NULL && buf[0] != '\0') {
-
			snprintf(path, MAXPATHLEN, "%s/%s-%s/+DISPLAY", pkg_add_dbdir, name, version);
+
			snprintf(path, sizeof(path), "%s/%s-%s/+DISPLAY", pkg_add_dbdir, name, version);
			fp = fopen(path, "w");
			fputs(buf, fp);
			fclose(fp);
@@ -120,7 +120,7 @@ convert_to_old(const char *pkg_add_dbdir, bool dry_run)

		pkg_get(pkg, PKG_MTREE, &buf);
		if (buf != NULL && buf[0] != '\0') {
-
			snprintf(path, MAXPATHLEN, "%s/%s-%s/+MTREE_DIRS", pkg_add_dbdir, name, version);
+
			snprintf(path, sizeof(path), "%s/%s-%s/+MTREE_DIRS", pkg_add_dbdir, name, version);
			fp = fopen(path, "w");
			fputs(buf, fp);
			fclose(fp);
@@ -157,7 +157,7 @@ convert_to_old(const char *pkg_add_dbdir, bool dry_run)
		}
		if (sbuf_len(install_script) > 0) {
			sbuf_finish(install_script);
-
			snprintf(path, MAXPATHLEN, "%s/%s-%s/+INSTALL", pkg_add_dbdir, name, version);
+
			snprintf(path, sizeof(path), "%s/%s-%s/+INSTALL", pkg_add_dbdir, name, version);
			fp = fopen(path, "w");
			fputs(sbuf_data(install_script), fp);
			fclose(fp);
@@ -194,13 +194,13 @@ convert_to_old(const char *pkg_add_dbdir, bool dry_run)
		}
		if (sbuf_len(deinstall_script) > 0) {
			sbuf_finish(deinstall_script);
-
			snprintf(path, MAXPATHLEN, "%s/%s-%s/+DEINSTALL", pkg_add_dbdir, name, version);
+
			snprintf(path, sizeof(path), "%s/%s-%s/+DEINSTALL", pkg_add_dbdir, name, version);
			fp = fopen(path, "w");
			fputs(sbuf_data(deinstall_script), fp);
			fclose(fp);
		}

-
		snprintf(path, MAXPATHLEN, "%s/%s-%s/+REQUIRED_BY", pkg_add_dbdir, name, version);
+
		snprintf(path, sizeof(path), "%s/%s-%s/+REQUIRED_BY", pkg_add_dbdir, name, version);
		while (pkg_rdeps(pkg, &dep) == EPKG_OK) {
			if (rq == NULL)
				rq = fopen(path, "w");
@@ -249,7 +249,7 @@ convert_from_old(const char *pkg_add_dbdir, bool dry_run)
			} else
				pkg_reset(p, PKG_OLD_FILE);
			printf("Converting %s...\n", dp->d_name);
-
			snprintf(path, MAXPATHLEN, "%s/%s", pkg_add_dbdir, dp->d_name);
+
			snprintf(path, sizeof(path), "%s/%s", pkg_add_dbdir, dp->d_name);
			if (pkg_old_load_from_path(p, path) != EPKG_OK) {
				fprintf(stderr, "Skipping invalid package: %s\n", path);
				continue;
modified pkg/create.c
@@ -135,7 +135,7 @@ pkg_create_matches(int argc, char **argv, match_t match, pkg_formats fmt,
		STAILQ_REMOVE_HEAD(&head, next);

		if (!overwrite) {
-
			pkg_snprintf(pkgpath, MAXPATHLEN, "%S/%n-%v.%S",
+
			pkg_snprintf(pkgpath, sizeof(pkgpath), "%S/%n-%v.%S",
			    outdir, e->pkg, e->pkg, format);
			if (access(pkgpath, F_OK) == 0) {
				pkg_printf("%n-%v already packaged, skipping...\n",
modified pkg/utils.c
@@ -588,7 +588,7 @@ print_jobs_summary(struct pkg_jobs *jobs, const char *msg, ...)
		switch (type) {
		case PKG_JOBS_INSTALL:
		case PKG_JOBS_UPGRADE:
-
			pkg_snprintf(path, MAXPATHLEN, "%S/%R", cachedir, pkg);
+
			pkg_snprintf(path, sizeof(path), "%S/%R", cachedir, pkg);

			if (stat(path, &st) == -1 || pkgsize != st.st_size)
				/* file looks corrupted (wrong size),
@@ -641,7 +641,7 @@ print_jobs_summary(struct pkg_jobs *jobs, const char *msg, ...)
			break;
		case PKG_JOBS_FETCH:
			dlsize += pkgsize;
-
			pkg_snprintf(path, MAXPATHLEN, "%S/%R", cachedir, pkg);
+
			pkg_snprintf(path, sizeof(path), "%S/%R", cachedir, pkg);
			if (stat(path, &st) != -1)
				oldsize = st.st_size;
			else