tech-pkg archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Fix format string warnings in net/libfetch (was: Re: Initial MirBSD support for pkgsrc)
On Tue, 28 Dec 2010, Greg Troxel wrote:
Any changes other than "add MirBSD stanza" probably should be proposed
as a separate patch, with rationale as to why it's correct.
As per Greg's request, I am proposing the patch to libfetch separately.
CCing joerg, the maintainer.
Rationale: On some operating systems, for example on MirBSD, the tm_year
member of struct tm is not an int but a long, in order to support a
64-bit time_t. Thus, it is dangerous to use tm_year with a "%d" format
in printf, the safe way is to cast to long and use "%ld". For scanf,
using &tm_year as an argument is unsafe as well, thus I used an
additional int.
Such changes have already been done some time ago in pkg_install, but
they have not yet been added to libfetch.
Thanks!
--Benny.
Index: net/libfetch/files/ftp.c
===================================================================
RCS file: /cvsroot/pkgsrc/net/libfetch/files/ftp.c,v
retrieving revision 1.36
diff -u -d -r1.36 ftp.c
--- net/libfetch/files/ftp.c 20 Aug 2010 17:56:49 -0000 1.36
+++ net/libfetch/files/ftp.c 28 Dec 2010 15:38:07 -0000
@@ -464,7 +464,7 @@
{
char *ln;
const char *filename;
- int filenamelen, type;
+ int filenamelen, type, year;
struct tm tm;
time_t t;
int e;
@@ -516,13 +516,13 @@
return (-1);
}
if (sscanf(ln, "%04d%02d%02d%02d%02d%02d",
- &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
+ &year, &tm.tm_mon, &tm.tm_mday,
&tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) {
ftp_seterr(FTP_PROTOCOL_ERROR);
return (-1);
}
tm.tm_mon--;
- tm.tm_year -= 1900;
+ tm.tm_year = year - 1900;
tm.tm_isdst = -1;
t = timegm(&tm);
if (t == (time_t)-1)
Index: net/libfetch/files/http.c
===================================================================
RCS file: /cvsroot/pkgsrc/net/libfetch/files/http.c,v
retrieving revision 1.29
diff -u -d -r1.29 http.c
--- net/libfetch/files/http.c 24 Jan 2010 19:10:35 -0000 1.29
+++ net/libfetch/files/http.c 28 Dec 2010 15:38:08 -0000
@@ -797,9 +797,9 @@
struct tm tm;
char buf[80];
gmtime_r(&last_modified, &tm);
- snprintf(buf, sizeof(buf), "%.3s, %02d %.3s %4d %02d:%02d:%02d GMT",
+ snprintf(buf, sizeof(buf), "%.3s, %02d %.3s %4ld %02d:%02d:%02d GMT",
weekdays + tm.tm_wday * 3, tm.tm_mday, months + tm.tm_mon * 3,
- tm.tm_year + 1900, tm.tm_hour, tm.tm_min, tm.tm_sec);
+ (long)tm.tm_year + 1900, tm.tm_hour, tm.tm_min, tm.tm_sec);
http_cmd(conn, "If-Modified-Since: %s\r\n", buf);
}
Home |
Main Index |
Thread Index |
Old Index