logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/
commit: 10ac3aa5885337bf7a969bf8bfca24f9dcd5428d
parent 4e06af59440ab1a824dd87ff8669bda47aae9571
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Wed, 23 Apr 2025 20:18:30 +0200

cmd/base64: make sure uuencode mainloop stops after EOF

Found via clang scan-build:

```
cmd/base64.c:385:15: warning: File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior [unix.Stream]
  385 |                                 int buf = getc(fin);
      |                                           ^~~~~~~~~
```

Diffstat:

Mcmd/base64.c8++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/cmd/base64.c b/cmd/base64.c @@ -369,13 +369,14 @@ end: static int uuencode(FILE *fin, const char *iname) { - while(1) + bool fin_eof = false; + while(!fin_eof) { char output[60] = ""; size_t pos = 0; int len = 0; - for(; len < 45; pos += 4, len += 3) + for(; (len < 45) && !fin_eof; pos += 4, len += 3) { uint8_t ibuf[3] = {0, 0, 0}; @@ -385,6 +386,7 @@ uuencode(FILE *fin, const char *iname) int buf = getc(fin); if(buf == EOF) { + fin_eof = true; break; } ibuf[c] = buf; @@ -438,8 +440,6 @@ uuencode(FILE *fin, const char *iname) errno = 0; return 1; } - - if(feof(fin)) break; } if(fflush(stdout) != 0)