summaryrefslogtreecommitdiff
path: root/usr.bin/cdio
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2013-03-07 16:54:29 +0000
committerMarc Espie <espie@cvs.openbsd.org>2013-03-07 16:54:29 +0000
commit9067cde8a28a7fa12478e4a753845bd4be16cf6c (patch)
tree22e3d6bb7beea04460c98d5160af7e3ac50c026b /usr.bin/cdio
parent5c22fb50d1e7cadd430660d80a547192ddf522cf (diff)
fix atrocious code, do socket -> FILE* conversion correctly, with proper
error handling. okay millert@, otto@
Diffstat (limited to 'usr.bin/cdio')
-rw-r--r--usr.bin/cdio/cddb.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/usr.bin/cdio/cddb.c b/usr.bin/cdio/cddb.c
index 848ddfa8450..ccc5e4785fa 100644
--- a/usr.bin/cdio/cddb.c
+++ b/usr.bin/cdio/cddb.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cddb.c,v 1.16 2011/04/06 11:36:26 miod Exp $ */
+/* $OpenBSD: cddb.c,v 1.17 2013/03/07 16:54:28 espie Exp $ */
/*
* Copyright (c) 2002 Marc Espie.
*
@@ -242,6 +242,7 @@ char **
cddb(const char *host_port, int n, struct cd_toc_entry *e, char *arg)
{
int s = -1;
+ int s2 = -1;
FILE *cin = NULL;
FILE *cout = NULL;
char *type;
@@ -253,17 +254,21 @@ cddb(const char *host_port, int n, struct cd_toc_entry *e, char *arg)
s = parse_connect_to(host_port, "cddb");
if (s == -1)
goto end;
+ s2 = dup(s);
+ if (s2 == -1)
+ goto end;
cin = fdopen(s, "r");
if (!cin) {
warn("cddb: fdopen");
goto end;
}
- cout = fdopen(s, "w");
s = -1;
+ cout = fdopen(s2, "w");
if (!cout) {
warn("cddb: fdopen");
goto end;
}
+ s2 = -1;
line = get_answer(cin);
if (!line) {
warnx("cddb: won't talk to us");
@@ -371,6 +376,8 @@ end:
fclose(cin);
if (s != -1)
close(s);
+ if (s2 != -1)
+ close(s2);
return result;
}