Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F108593894
D30005.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
D30005.diff
View Options
diff --git a/usr.sbin/pkg/Makefile b/usr.sbin/pkg/Makefile
--- a/usr.sbin/pkg/Makefile
+++ b/usr.sbin/pkg/Makefile
@@ -25,6 +25,6 @@
CFLAGS+=-I${SRCTOP}/contrib/libucl/include
.PATH: ${SRCTOP}/contrib/libucl/include
-LIBADD= archive fetch ucl sbuf crypto ssl util
+LIBADD= archive fetch ucl crypto ssl util
.include <bsd.prog.mk>
diff --git a/usr.sbin/pkg/config.c b/usr.sbin/pkg/config.c
--- a/usr.sbin/pkg/config.c
+++ b/usr.sbin/pkg/config.c
@@ -33,7 +33,6 @@
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/utsname.h>
-#include <sys/sbuf.h>
#include <sys/sysctl.h>
#include <dirent.h>
@@ -214,7 +213,9 @@
static void
config_parse(const ucl_object_t *obj, pkg_conf_file_t conftype)
{
- struct sbuf *buf = sbuf_new_auto();
+ FILE *buffp;
+ char *buf = NULL;
+ size_t bufsz = 0;
const ucl_object_t *cur, *seq, *tmp;
ucl_object_iter_t it = NULL, itseq = NULL, it_obj = NULL;
struct config_entry *temp_config;
@@ -225,39 +226,44 @@
/* Temporary config for configs that may be disabled. */
temp_config = calloc(CONFIG_SIZE, sizeof(struct config_entry));
+ buffp = open_memstream(&buf, &bufsz);
+ if (buffp == NULL)
+ err(EXIT_FAILURE, "open_memstream()");
while ((cur = ucl_iterate_object(obj, &it, true))) {
key = ucl_object_key(cur);
if (key == NULL)
continue;
- sbuf_clear(buf);
+ if (buf != NULL)
+ memset(buf, 0, bufsz);
+ rewind(buffp);
if (conftype == CONFFILE_PKG) {
for (j = 0; j < strlen(key); ++j)
- sbuf_putc(buf, toupper(key[j]));
- sbuf_finish(buf);
+ fputc(toupper(key[j]), buffp);
+ fflush(buffp);
} else if (conftype == CONFFILE_REPO) {
if (strcasecmp(key, "url") == 0)
- sbuf_cpy(buf, "PACKAGESITE");
+ fputs("PACKAGESITE", buffp);
else if (strcasecmp(key, "mirror_type") == 0)
- sbuf_cpy(buf, "MIRROR_TYPE");
+ fputs("MIRROR_TYPE", buffp);
else if (strcasecmp(key, "signature_type") == 0)
- sbuf_cpy(buf, "SIGNATURE_TYPE");
+ fputs("SIGNATURE_TYPE", buffp);
else if (strcasecmp(key, "fingerprints") == 0)
- sbuf_cpy(buf, "FINGERPRINTS");
+ fputs("FINGERPRINTS", buffp);
else if (strcasecmp(key, "pubkey") == 0)
- sbuf_cpy(buf, "PUBKEY");
+ fputs("PUBKEY", buffp);
else if (strcasecmp(key, "enabled") == 0) {
if ((cur->type != UCL_BOOLEAN) ||
!ucl_object_toboolean(cur))
goto cleanup;
} else
continue;
- sbuf_finish(buf);
+ fflush(buffp);
}
for (i = 0; i < CONFIG_SIZE; i++) {
- if (strcmp(sbuf_data(buf), c[i].key) == 0)
+ if (strcmp(buf, c[i].key) == 0)
break;
}
@@ -332,7 +338,8 @@
cleanup:
free(temp_config);
- sbuf_delete(buf);
+ fclose(buffp);
+ free(buf);
}
/*-
diff --git a/usr.sbin/pkg/pkg.c b/usr.sbin/pkg/pkg.c
--- a/usr.sbin/pkg/pkg.c
+++ b/usr.sbin/pkg/pkg.c
@@ -33,7 +33,6 @@
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
-#include <sys/sbuf.h>
#include <sys/wait.h>
#include <archive.h>
@@ -595,7 +594,9 @@
read_pubkey(int fd)
{
struct pubkey *pk;
- struct sbuf *sig;
+ char *sigb;
+ size_t sigsz;
+ FILE *sig;
char buf[4096];
int r;
@@ -604,18 +605,22 @@
return (NULL);
}
- sig = sbuf_new_auto();
+ sigsz = 0;
+ sigb = NULL;
+ sig = open_memstream(&sigb, &sigsz);
+ if (sig == NULL)
+ err(EXIT_FAILURE, "open_memstream()");
while ((r = read(fd, buf, sizeof(buf))) >0) {
- sbuf_bcat(sig, buf, r);
+ fwrite(buf, 1, r, sig);
}
- sbuf_finish(sig);
+ fclose(sig);
pk = calloc(1, sizeof(struct pubkey));
- pk->siglen = sbuf_len(sig);
+ pk->siglen = sigsz;
pk->sig = calloc(1, pk->siglen);
- memcpy(pk->sig, sbuf_data(sig), pk->siglen);
- sbuf_delete(sig);
+ memcpy(pk->sig, sigb, pk->siglen);
+ free(sigb);
return (pk);
}
@@ -624,16 +629,17 @@
parse_cert(int fd) {
int my_fd;
struct sig_cert *sc;
- FILE *fp;
- struct sbuf *buf, *sig, *cert;
+ FILE *fp, *sigfp, *certfp, *tmpfp;
char *line;
- size_t linecap;
+ char *sig, *cert;
+ size_t linecap, sigsz, certsz;
ssize_t linelen;
- buf = NULL;
sc = NULL;
line = NULL;
linecap = 0;
+ sig = cert = NULL;
+ sigfp = certfp = tmpfp = NULL;
if (lseek(fd, 0, 0) == -1) {
warn("lseek");
@@ -652,41 +658,38 @@
return (NULL);
}
- sig = sbuf_new_auto();
- cert = sbuf_new_auto();
+ sigsz = certsz = 0;
+ sigfp = open_memstream(&sig, &sigsz);
+ if (sigfp == NULL)
+ err(EXIT_FAILURE, "open_memstream()");
+ certfp = open_memstream(&cert, &certsz);
+ if (certfp == NULL)
+ err(EXIT_FAILURE, "open_memstream()");
while ((linelen = getline(&line, &linecap, fp)) > 0) {
if (strcmp(line, "SIGNATURE\n") == 0) {
- buf = sig;
+ tmpfp = sigfp;
continue;
} else if (strcmp(line, "CERT\n") == 0) {
- buf = cert;
+ tmpfp = certfp;
continue;
} else if (strcmp(line, "END\n") == 0) {
break;
}
- if (buf != NULL)
- sbuf_bcat(buf, line, linelen);
+ if (tmpfp != NULL)
+ fwrite(line, 1, linelen, tmpfp);
}
fclose(fp);
-
- /* Trim out unrelated trailing newline */
- sbuf_setpos(sig, sbuf_len(sig) - 1);
-
- sbuf_finish(sig);
- sbuf_finish(cert);
+ fclose(sigfp);
+ fclose(certfp);
sc = calloc(1, sizeof(struct sig_cert));
- sc->siglen = sbuf_len(sig);
- sc->sig = calloc(1, sc->siglen);
- memcpy(sc->sig, sbuf_data(sig), sc->siglen);
-
- sc->certlen = sbuf_len(cert);
- sc->cert = strdup(sbuf_data(cert));
+ sc->siglen = sigsz -1; /* Trim out unrelated trailing newline */
+ sc->sig = sig;
- sbuf_delete(sig);
- sbuf_delete(cert);
+ sc->certlen = certsz;
+ sc->cert = cert;
return (sc);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Jan 27, 6:13 PM (1 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16203401
Default Alt Text
D30005.diff (5 KB)
Attached To
Mode
D30005: pkg(7): replace usage of sbuf(9) with open_memstream(3)
Attached
Detach File
Event Timeline
Log In to Comment