This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/4940] New: Sprintf injecting extra data
- From: "ron at rongage dot org" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: 19 Aug 2007 19:29:59 -0000
- Subject: [Bug libc/4940] New: Sprintf injecting extra data
- Reply-to: sourceware-bugzilla at sourceware dot org
With the following code, span is set to 1 and tape is set to 0.
uint32_t put_fileinfo (MYSQL mysql, _filedata *fd, uint32_t span, uint32_t tape)
{
char sql[4096];
int x;
printf ("span = %d, tape = %d\n",span,tape);
memset (sql,0,4096);
sprintf (sql, "INSERT INTO files VALUES
(\"%s\",\"%s\",\"%d\",\"%ld\",\"%ld\",\"%ld\",\"%lld\",\"%ld\",\"%ld\",\"%ld\",\"%d\",\"%d\",\"%d\",\"%ld\",\"%ld\",now(),\"%ld\")",
fd->path, fd->name, fd->mode, fd->uid, fd->gid, fd->type, fd->size,
fd->dev, fd->rdev, fd->atime, fd->mtime, fd->ctime, fd->begin, fd->end, span, tape);
printf ("span = %d, tape = %d\n",span,tape);
x = do_sql(mysql, sql,1);
return (x);
}
Using the above code, three extra parameters are injected into the "sql" string
after the fd->rdev parameter. Here is example contents of SQL using the above code:
INSERT INTO files VALUES
("./src/.svn/text-base","tapeerase.svn-base","420","0","0","32768","46","769","0","0","0","1187550529","1157119100","1170011684","0",now(),"296")
Again, the values of span and tape are 1 and 0 respectively, checked before and
after the execution of the sprintf statement.
If I add "%ld %ld %ld" to the end of the format string, the correct data is
output in these last 3 positions (and gcc complains about the imbalance between
the format and the parameters).
glibc 2.3.5 as distributed with Slackware 10.2, gcc 3.4.6, AMD X2 4600 running
in 32 bit mode.
--
Summary: Sprintf injecting extra data
Product: glibc
Version: 2.3.5
Status: NEW
Severity: normal
Priority: P2
Component: libc
AssignedTo: drepper at redhat dot com
ReportedBy: ron at rongage dot org
CC: glibc-bugs at sources dot redhat dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=4940
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.