convert simple sprintf() to snprintf()

from maintainer Moritz Grimm <gtgbr at gmx.net>
This commit is contained in:
sturm 2005-04-16 15:37:31 +00:00
parent 363ceb8d12
commit 2945da0130
7 changed files with 132 additions and 16 deletions

View File

@ -1,8 +1,9 @@
# $OpenBSD: Makefile,v 1.27 2004/12/31 13:09:10 sturm Exp $
# $OpenBSD: Makefile,v 1.28 2005/04/16 15:37:31 sturm Exp $
COMMENT= "server for streaming Ogg Vorbis and MP3"
DISTNAME= icecast-2.2.0
PKGNAME= ${DISTNAME}p0
CATEGORIES= net audio
HOMEPAGE= http://www.icecast.org/

View File

@ -1,16 +1,16 @@
$OpenBSD: patch-conf_icecast_xml_in,v 1.2 2004/12/31 13:09:10 sturm Exp $
--- conf/icecast.xml.in.orig Tue Dec 21 18:17:55 2004
+++ conf/icecast.xml.in Tue Dec 21 18:20:06 2004
@@ -97,7 +97,7 @@
$OpenBSD: patch-conf_icecast_xml_in,v 1.3 2005/04/16 15:37:31 sturm Exp $
--- conf/icecast.xml.in.orig Thu Dec 2 22:15:35 2004
+++ conf/icecast.xml.in Mon Mar 7 20:20:46 2005
@@ -100,7 +100,7 @@
</mount>
-->
- <fileserve>1</fileserve>
+ <fileserve>0</fileserve>
<paths>
<!-- basedir is only used if chroot is enabled -->
@@ -108,7 +108,7 @@
<!-- set the mountpoint for a shoutcast source to use, the default if not
specified is /stream but you can change it here if an alternative is
@@ -117,7 +117,7 @@
<logdir>@localstatedir@/log/@PACKAGE@</logdir>
<webroot>@pkgdatadir@/web</webroot>
<adminroot>@pkgdatadir@/admin</adminroot>

View File

@ -1,7 +1,7 @@
$OpenBSD: patch-doc_Makefile_in,v 1.1 2004/02/02 19:32:37 fgsch Exp $
--- doc/Makefile.in.orig 2004-01-07 22:52:09.000000000 +0100
+++ doc/Makefile.in 2004-01-08 15:49:29.000000000 +0100
@@ -111,7 +111,7 @@ install_sh = @install_sh@
$OpenBSD: patch-doc_Makefile_in,v 1.2 2005/04/16 15:37:31 sturm Exp $
--- doc/Makefile.in.orig Tue Dec 21 20:31:03 2004
+++ doc/Makefile.in Mon Mar 7 20:20:46 2005
@@ -123,7 +123,7 @@ install_sh = @install_sh@
AUTOMAKE_OPTIONS = foreign

View File

@ -1,7 +1,7 @@
$OpenBSD: patch-src_admin_c,v 1.2 2004/12/31 13:09:10 sturm Exp $
--- src/admin.c.orig Tue Dec 21 18:43:25 2004
+++ src/admin.c Tue Dec 21 18:45:44 2004
@@ -579,7 +579,7 @@ static void command_show_listeners(clien
$OpenBSD: patch-src_admin_c,v 1.3 2005/04/16 15:37:31 sturm Exp $
--- src/admin.c.orig Sat Dec 11 00:56:55 2004
+++ src/admin.c Mon Mar 7 20:20:46 2005
@@ -651,7 +651,7 @@ static void command_show_listeners(clien
xmlNewChild(listenernode, NULL, "UserAgent", "Unknown");
}
memset(buf, '\000', sizeof(buf));

View File

@ -0,0 +1,12 @@
$OpenBSD: patch-src_auth_c,v 1.1 2005/04/16 15:37:31 sturm Exp $
--- src/auth.c.orig Mon Mar 7 13:59:17 2005
+++ src/auth.c Mon Mar 7 14:00:59 2005
@@ -365,7 +365,7 @@ int auth_htpasswd_deleteuser(auth_t *aut
}
tmpfile_len = strlen(state->filename) + 6;
tmpfile = calloc(1, tmpfile_len);
- sprintf(tmpfile, ".%s.tmp", state->filename);
+ snprintf(tmpfile, tmpfile_len, ".%s.tmp", state->filename);
tmp_passwdfile = fopen(tmpfile, "wb");

View File

@ -0,0 +1,78 @@
$OpenBSD: patch-src_util_c,v 1.1 2005/04/16 15:37:31 sturm Exp $
--- src/util.c.orig Mon Nov 8 02:21:54 2004
+++ src/util.c Mon Mar 7 14:10:16 2005
@@ -229,12 +229,14 @@ char *util_get_path_from_normalised_uri(
char *fullpath;
char *webroot;
ice_config_t *config = config_get_config();
+ size_t pathlen;
webroot = config->webroot_dir;
- fullpath = malloc(strlen(uri) + strlen(webroot) + 1);
+ pathlen = strlen(uri) + strlen(webroot) + 1;
+ fullpath = malloc(pathlen);
if (fullpath)
- sprintf (fullpath, "%s%s", webroot, uri);
+ snprintf(fullpath, pathlen, "%s%s", webroot, uri);
config_release_config();
return fullpath;
@@ -568,24 +570,29 @@ char *util_dict_urlencode(util_dict *dic
char *res, *tmp;
char *enc;
int start = 1;
+ size_t buflen;
for (res = NULL; dict; dict = dict->next) {
/* encode key */
if (!dict->key)
continue;
if (start) {
- if (!(res = malloc(strlen(dict->key) + 1))) {
+ buflen = strlen(dict->key) + 1;
+ if (!(res = malloc(buflen))) {
return NULL;
}
- sprintf(res, "%s", dict->key);
+ snprintf(res, buflen, "%s", dict->key);
start = 0;
} else {
- if (!(tmp = realloc(res, strlen(res) + strlen(dict->key) + 2))) {
+ buflen = strlen(res) + strlen(dict->key) + 2;
+ if ((tmp = realloc(res, buflen)) == NULL) {
free(res);
+ res = NULL;
return NULL;
- } else
+ } else {
res = tmp;
- sprintf(res + strlen(res), "%c%s", delim, dict->key);
+ snprintf(res + strlen(res), buflen - strlen(res), "%c%s", delim, dict->key);
+ }
}
/* encode value */
@@ -596,14 +603,18 @@ char *util_dict_urlencode(util_dict *dic
return NULL;
}
- if (!(tmp = realloc(res, strlen(res) + strlen(enc) + 2))) {
+ buflen = strlen(res) + strlen(enc) + 2;
+ if ((tmp = realloc(res, buflen)) == NULL) {
free(enc);
free(res);
+ enc = res = NULL;
return NULL;
- } else
+ } else {
res = tmp;
- sprintf(res + strlen(res), "=%s", enc);
- free(enc);
+ snprintf(res + strlen(res), buflen - strlen(res), "=%s", enc);
+ free(enc);
+ enc = NULL;
+ }
}
return res;

View File

@ -0,0 +1,25 @@
$OpenBSD: patch-src_yp_c,v 1.1 2005/04/16 15:37:31 sturm Exp $
--- src/yp.c.orig Fri Dec 17 20:01:26 2004
+++ src/yp.c Mon Mar 7 14:11:59 2005
@@ -365,6 +365,7 @@ static unsigned do_yp_touch (ypdata_t *y
char *val, *artist, *title;
int ret;
char *max_listeners;
+ size_t songlen;
artist = (char *)stats_get_value (yp->mount, "artist");
title = (char *)stats_get_value (yp->mount, "title");
@@ -378,10 +379,11 @@ static unsigned do_yp_touch (ypdata_t *y
separator = "";
}
if (title == NULL) title = strdup("");
- song = malloc (strlen (artist) + strlen (title) + strlen (separator) +1);
+ songlen = strlen(artist) + strlen(title) + strlen(separator) + 1;
+ song = malloc(songlen);
if (song)
{
- sprintf (song, "%s%s%s", artist, separator, title);
+ snprintf(song, songlen, "%s%s%s", artist, separator, title);
add_yp_info(yp, "yp_currently_playing", song, YP_CURRENT_SONG);
free (song);
}