Code Monkey home page Code Monkey logo

Comments (8)

N-R-K avatar N-R-K commented on May 18, 2024

Github doesn't understand "partially fixes" and keeps closing this, pretty annoying. :/

But in any case, strftime is still happening on a fixed length buffer. So I don't think this is fully fixed.

from scrot.

N-R-K avatar N-R-K commented on May 18, 2024

I think the only remaining issue now is the strftime buffer. This would (almost) fix it:

     Stream ret = {0};
     long hostNameMax = 0;
-    char strf[4096];
+    char *strf = NULL;
+    size_t strfSize = 64;
     char *tmp;
     struct stat st;
 
-    if (strftime(strf, 4095, str, tm) == 0)
-        errx(EXIT_FAILURE, "strftime returned 0");
+    do {
+        strfSize *= 2;
+        strf = erealloc(strf, strfSize);
+    } while (strftime(strf, strfSize, str, tm) == 0); /* FIXME: infinite loop */
 
     imlib_context_set_image(im);

But the problem is strftime can validly return 0 and there's no way to distinguish between a valid 0 return vs a 0 return due to small buffer.

from scrot.

guijan avatar guijan commented on May 18, 2024

Filenames can't be the null string, dirname and basename will guarantee that the destination is at least "." when #226 is fixed.

I've been reading books instead of contributing as of late.

from scrot.

N-R-K avatar N-R-K commented on May 18, 2024

From the strftime manpage:

Note that the return value 0 does not necessarily indicate an error. For example, in many
locales %p yields an empty string.

So if someone does scrot "%p" strftime may "validly" return a zero. I don't think the chdir will fix that.

I've been reading books instead of contributing as of late.

It's voluntary work, do it at your own pace :)

from scrot.

guijan avatar guijan commented on May 18, 2024

Maybe we can use strptime() then.
https://pubs.opengroup.org/onlinepubs/007904875/functions/strptime.html
Or, set the first byte to zero, call strftime(), and if it's still 0 after the call and the size of the buffer is greater than 2 bytes, strftime() created a null string.

from scrot.

N-R-K avatar N-R-K commented on May 18, 2024

and if it's still 0 after the call and the size of the buffer is greater than 2 bytes

In the case of error 0 return, the contents of buf is undefined.

If the length of the result string (including the terminating null byte) would exceed max bytes, then strftime() returns 0, and the contents of the array are undefined.

So we can't read the contents of the buffer to make any conclusions.

Maybe we can use strptime() then.

I'll take a look into it.

from scrot.

guijan avatar guijan commented on May 18, 2024

POSIX says unspecified. It's unlikely an an implementation wouldn't output directly to the buffer anyway.

from scrot.

guijan avatar guijan commented on May 18, 2024

If the output file is an absolute path (starts with '/'), then strftime() can't create a 0-sized string. If the output file isn't an absolute path, prepending "./" to it is harmless and prevents the creation of a 0-sized string.

from scrot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.