Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: ClamAV: devel

small signed/unsigned mistake in libclamav/scanners.c

 

 

ClamAV devel RSS feed   Index | Next | Previous | View Threaded


juhl at dif

Feb 17, 2004, 2:28 PM

Post #1 of 4 (794 views)
Permalink
small signed/unsigned mistake in libclamav/scanners.c

Hi,

Here's a tiny patch for a small problem in libclamav/scanners.c
The problem is that the variable "scanned" is a signed long int *
everywhere, and is treated as such, yet the cl_scandesc function takes an
unsigned long int * argument and thus the signedness of the variable is
potentially lost when it's passed on to other functions. This may or may
not be causing any real trouble (haven't been looking that deep into it),
but changing the argument type for scanned for the cl_scandesc() function
to be long int * seems obviously correct to me and prevents this from ever
becoming a real issue.

Here's the small patch to make this change (against clamav-0.67) :


--- clamav-0.67/libclamav/scanners.c 2004-02-15 13:10:34.000000000 +0100
+++ clamav-0.67-juhl/libclamav/scanners.c 2004-02-17 23:21:47.000000000 +0100
@@ -751,7 +751,7 @@ int cli_magic_scandesc(int desc, char **
return ret;
}

-int cl_scandesc(int desc, char **virname, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options)
+int cl_scandesc(int desc, char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options)
{
int reclev = 0;




Kind regards,

Jesper Juhl


juhl at dif

Feb 17, 2004, 2:44 PM

Post #2 of 4 (782 views)
Permalink
Re: small signed/unsigned mistake in libclamav/scanners.c [In reply to]

On Tue, 17 Feb 2004, Jesper Juhl wrote:

>
> Hi,
>
> Here's a tiny patch for a small problem in libclamav/scanners.c
> The problem is that the variable "scanned" is a signed long int *
> everywhere, and is treated as such, yet the cl_scandesc function takes an
> unsigned long int * argument and thus the signedness of the variable is
> potentially lost when it's passed on to other functions. This may or may
> not be causing any real trouble (haven't been looking that deep into it),
> but changing the argument type for scanned for the cl_scandesc() function
> to be long int * seems obviously correct to me and prevents this from ever
> becoming a real issue.
>
> Here's the small patch to make this change (against clamav-0.67) :
>
Whoops, emabaressing, I only diffed the .c file, not the clamav.h as well,
here's a corrected patch - please consider applying :


diff -urp clamav-0.67/libclamav/clamav.h clamav-0.67-juhl/libclamav/clamav.h
--- clamav-0.67/libclamav/clamav.h 2004-02-15 12:44:12.000000000 +0100
+++ clamav-0.67-juhl/libclamav/clamav.h 2004-02-17 23:42:45.000000000 +0100
@@ -113,9 +113,9 @@ struct cl_cvd {
/* file scanning */
extern int cl_scanbuff(const char *buffer, unsigned int length, char **virname, const struct cl_node *root);

-extern int cl_scandesc(int desc, char **virname, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options);
+extern int cl_scandesc(int desc, char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options);

-extern int cl_scanfile(const char *filename, char **virname, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options);
+extern int cl_scanfile(const char *filename, char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options);

/* database loading */
extern int cl_loaddb(const char *filename, struct cl_node **root, int *virnum);
diff -urp clamav-0.67/libclamav/scanners.c clamav-0.67-juhl/libclamav/scanners.c
--- clamav-0.67/libclamav/scanners.c 2004-02-15 13:10:34.000000000 +0100
+++ clamav-0.67-juhl/libclamav/scanners.c 2004-02-17 23:38:12.000000000 +0100
@@ -751,14 +751,14 @@ int cli_magic_scandesc(int desc, char **
return ret;
}

-int cl_scandesc(int desc, char **virname, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options)
+int cl_scandesc(int desc, char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options)
{
int reclev = 0;

return cli_magic_scandesc(desc, virname, scanned, root, limits, options, &reclev);
}

-int cl_scanfile(const char *filename, char **virname, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options)
+int cl_scanfile(const char *filename, char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options)
{
int fd, ret;


Kind regards,

Jesper Juhl


juhl at dif

Feb 17, 2004, 2:51 PM

Post #3 of 4 (783 views)
Permalink
Re: small signed/unsigned mistake in libclamav/scanners.c [In reply to]

On Tue, 17 Feb 2004, Jesper Juhl wrote:

>
>
>
> On Tue, 17 Feb 2004, Jesper Juhl wrote:
>
> >
> > Hi,
> >
> > Here's a tiny patch for a small problem in libclamav/scanners.c
> > The problem is that the variable "scanned" is a signed long int *
> > everywhere, and is treated as such, yet the cl_scandesc function takes an
> > unsigned long int * argument and thus the signedness of the variable is
> > potentially lost when it's passed on to other functions. This may or may
> > not be causing any real trouble (haven't been looking that deep into it),
> > but changing the argument type for scanned for the cl_scandesc() function
> > to be long int * seems obviously correct to me and prevents this from ever
> > becoming a real issue.
> >
> > Here's the small patch to make this change (against clamav-0.67) :
> >
> Whoops, emabaressing, I only diffed the .c file, not the clamav.h as well,
> here's a corrected patch - please consider applying :
>
>
> diff -urp clamav-0.67/libclamav/clamav.h clamav-0.67-juhl/libclamav/clamav.h
> --- clamav-0.67/libclamav/clamav.h 2004-02-15 12:44:12.000000000 +0100
> +++ clamav-0.67-juhl/libclamav/clamav.h 2004-02-17 23:42:45.000000000 +0100
> @@ -113,9 +113,9 @@ struct cl_cvd {
> /* file scanning */
> extern int cl_scanbuff(const char *buffer, unsigned int length, char **virname, const struct cl_node *root);
>
> -extern int cl_scandesc(int desc, char **virname, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options);
> +extern int cl_scandesc(int desc, char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options);
>
> -extern int cl_scanfile(const char *filename, char **virname, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options);
> +extern int cl_scanfile(const char *filename, char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options);
>
> /* database loading */
> extern int cl_loaddb(const char *filename, struct cl_node **root, int *virnum);
> diff -urp clamav-0.67/libclamav/scanners.c clamav-0.67-juhl/libclamav/scanners.c
> --- clamav-0.67/libclamav/scanners.c 2004-02-15 13:10:34.000000000 +0100
> +++ clamav-0.67-juhl/libclamav/scanners.c 2004-02-17 23:38:12.000000000 +0100
> @@ -751,14 +751,14 @@ int cli_magic_scandesc(int desc, char **
> return ret;
> }
>
> -int cl_scandesc(int desc, char **virname, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options)
> +int cl_scandesc(int desc, char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options)
> {
> int reclev = 0;
>
> return cli_magic_scandesc(desc, virname, scanned, root, limits, options, &reclev);
> }
>
> -int cl_scanfile(const char *filename, char **virname, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options)
> +int cl_scanfile(const char *filename, char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options)
> {
> int fd, ret;
>
>
Yes, replying to myself again, but I just wanted to add that if there's
something I've overlooked and "scanned" for some reason really should be
unsigned, then ofcourse the opposite changes of the above has to be made
(changing all users and the variable itself to a unsigned value). If that
is the case (doesn't look like it to me), then just let me know and I'll
create a patch for that instead.


/Jesper Juhl


tk at lodz

Feb 21, 2004, 7:55 AM

Post #4 of 4 (781 views)
Permalink
Re: small signed/unsigned mistake in libclamav/scanners.c [In reply to]

On Tue, 17 Feb 2004 23:42:15 +0100 (CET)
Jesper Juhl <juhl [at] dif> wrote:

> Yes, replying to myself again, but I just wanted to add that if
> there's something I've overlooked and "scanned" for some reason really
> should be unsigned, then ofcourse the opposite changes of the above

It should be unsigned (the API is OK).

Best regards,
Tomasz Kojm
--
oo ..... tkojm [at] clamav www.ClamAV.net
(\/)\......... http://www.clamav.net/gpg/tkojm.gpg
\..........._ 0DCA5A08407D5288279DB43454822DC8985A444B
//\ /\ Sat Feb 21 15:38:27 CET 2004

ClamAV devel RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.