On Tue, 30 Aug 2022 14:09:40 +0200
Theo Buehler <t...@theobuehler.org> wrote:
> On Tue, Aug 30, 2022 at 01:01:47PM +0200, YASUOKA Masahiko wrote:
>> On Tue, 30 Aug 2022 11:56:53 +0200
>> Claudio Jeker <cje...@diehard.n-r-g.com> wrote:
>> > On Tue, Aug 30, 2022 at 11:18:01AM +0200, YASUOKA Masahiko wrote:
>> >> @@ -423,11 +423,13 @@ uu_decode(void)
>> >>   }
>> >>  }
>> >>  
>> >> +#define  ROUNDDOWN(x,y)  (((x)/(y)) * (y))
>> >> +
>> >>  static int
>> >>  base64_decode(void)
>> >>  {
>> >>   int n;
>> >> - char inbuf[PATH_MAX];
>> >> + char inbuf[ROUNDDOWN(PATH_MAX, 4) + 1];
>> >>   unsigned char outbuf[PATH_MAX * 4];
>> >>  
>> >>   for (;;) {
>> >> 
>> > 
>> > The fix is right but I wonder why is this code using PATH_MAX for a buffer
>> > size that has nothing to do with a file system path?
>> 
>> It is a mystery of the history?
>> 
>>   
>> https://github.com/sergev/4.4BSD-Lite2/blob/master/usr/src/usr.bin/uudecode/uudecode.c#L92
>> 
>> MAXPATHLEN was replaced to PATH_MAX in 2015.
>> 
>> ok?
>> 
>> Index: usr.bin/uudecode/uudecode.c
>> ===================================================================
>> RCS file: /cvs/src/usr.bin/uudecode/uudecode.c,v
>> retrieving revision 1.27
>> diff -u -p -r1.27 uudecode.c
>> --- usr.bin/uudecode/uudecode.c      28 Jun 2019 13:35:05 -0000      1.27
>> +++ usr.bin/uudecode/uudecode.c      30 Aug 2022 10:54:17 -0000
>> @@ -190,7 +190,7 @@ decode2(void)
>>      void *handle;
>>      struct passwd *pw;
>>      struct stat st;
>> -    char buf[PATH_MAX];
>> +    char buf[BUFSIZ];
>>  
>>      base64 = 0;
>>      /* search for header line */
>> @@ -342,7 +342,7 @@ uu_decode(void)
>>  {
>>      int i, ch;
>>      char *p;
>> -    char buf[PATH_MAX];
>> +    char buf[BUFSIZ];
>>  
>>      /* for each input line */
>>      for (;;) {
>> @@ -427,8 +427,8 @@ static int
>>  base64_decode(void)
>>  {
>>      int n;
>> -    char inbuf[PATH_MAX];
>> -    unsigned char outbuf[PATH_MAX * 4];
>> +    char inbuf[BUFSIZ];
> 
> You need an extra byte for the terminating NUL to fix the problem you
> wanted to fix:
> 
>       char inbuf[BUFSIZ + 1];
> 
> I'm not sure if we can rely on BUFSIZ to be a multiple of 4, I can't
> find anything that requires that. I think it's better to use a local
> #define with a comment as Claudio suggested.

Ah, I showed the diff separated from first one.
I'm sorry for confusing.  The following diff is combined.

> 
> 
>> +    unsigned char outbuf[BUFSIZ * 4];
>>  
>>      for (;;) {
>>              switch (get_line(inbuf, sizeof(inbuf))) {
>> 

Index: usr.bin/uudecode/uudecode.c
===================================================================
RCS file: /cvs/src/usr.bin/uudecode/uudecode.c,v
retrieving revision 1.27
diff -u -p -r1.27 uudecode.c
--- usr.bin/uudecode/uudecode.c 28 Jun 2019 13:35:05 -0000      1.27
+++ usr.bin/uudecode/uudecode.c 30 Aug 2022 12:15:56 -0000
@@ -190,7 +190,7 @@ decode2(void)
        void *handle;
        struct passwd *pw;
        struct stat st;
-       char buf[PATH_MAX];
+       char buf[BUFSIZ];
 
        base64 = 0;
        /* search for header line */
@@ -342,7 +342,7 @@ uu_decode(void)
 {
        int i, ch;
        char *p;
-       char buf[PATH_MAX];
+       char buf[BUFSIZ];
 
        /* for each input line */
        for (;;) {
@@ -423,12 +423,14 @@ uu_decode(void)
        }
 }
 
+#define        ROUNDDOWN(x,y)  (((x)/(y)) * (y))
+
 static int
 base64_decode(void)
 {
        int n;
-       char inbuf[PATH_MAX];
-       unsigned char outbuf[PATH_MAX * 4];
+       char inbuf[ROUNDDOWN(BUFSIZ, 4) + 1];
+       unsigned char outbuf[BUFSIZ * 4];
 
        for (;;) {
                switch (get_line(inbuf, sizeof(inbuf))) {

Reply via email to