Skip to content

Commit

Permalink
Yet another wonderful workaround...
Browse files Browse the repository at this point in the history
Should be slightly nicer that a segfault, though...
Because loading a system font is *probably* something someone would try
to do...
  • Loading branch information
NiLuJe committed Nov 4, 2018
1 parent f4c32d3 commit fa5d2ce
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
16 changes: 16 additions & 0 deletions fbink.c
Original file line number Diff line number Diff line change
Expand Up @@ -2059,6 +2059,22 @@ int
fbink_add_ot_font(const char* filename UNUSED_BY_MINIMAL, FONT_STYLE_T style UNUSED_BY_MINIMAL)
{
#ifdef FBINK_WITH_OPENTYPE
# ifndef FBINK_FOR_LINUX
# ifndef FBINK_FOR_KINDLE
# ifndef FBINK_FOR_CERVANTES
// NOTE: Bail if we were passed a Kobo system font, as they're obfuscated, and that'd segfault in stbtt_InitFont >_<"
char* path = strdup(filename);
char* dir = dirname(path);
if (!strcasecmp(dir, "/usr/local/Trolltech/QtEmbedded-4.6.2-arm/lib/fonts")) {
free(path);
WARN("Cannot use font '%s': it's an obfuscated Kobo system font", filename);
return ERRCODE(EXIT_FAILURE);
}
free(path);
# endif
# endif
# endif

// Init libunibreak the first time we're called
if (!otInit) {
init_linebreak();
Expand Down
7 changes: 7 additions & 0 deletions fbink_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@

#include <errno.h>
#include <fcntl.h>
#ifndef FBINK_FOR_LINUX
# ifndef FBINK_FOR_KINDLE
# ifndef FBINK_FOR_CERVANTES
# include <libgen.h> // We need dirname() on Kobo...
# endif
# endif
#endif
#include <linux/fb.h>
#include <linux/kd.h>
#include <stdlib.h>
Expand Down

5 comments on commit fa5d2ce

@shermp
Copy link
Contributor

@shermp shermp commented on fa5d2ce Nov 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Umm.. isn't this kind of overkill? We only care about the prefix of filename after all.

Therefore, wouldn't this do the same thing, without the need for string duplication and extra headers?

char prefix[] = "/usr/local/Trolltech/QtEmbedded-4.6.2-arm/lib/fonts";
if (!strncmp(filename, prefix, strlen(prefix)) {
    WARN("Cannot use font '%s': it's an obfuscated Kobo system font", filename);
    return ERRCODE(EXIT_FAILURE);
}

Note, because Linux uses case sensitive filepaths, I personally wouldn't try and handle the 'path not exist' error here, as that can (and should) already be handled elsewhere.

Just my two cents.

@NiLuJe
Copy link
Owner Author

@NiLuJe NiLuJe commented on fa5d2ce Nov 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed it would ;).

You caught that just in time, I was writing the changelog, just about to tag a release ;).

Thanks!

@NiLuJe
Copy link
Owner Author

@NiLuJe NiLuJe commented on fa5d2ce Nov 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And, yeah, good point on the case sensitivity being useless here, guess I spent too much time wondering how a vfat user partition could bite me in the ass ;).

@shermp
Copy link
Contributor

@shermp shermp commented on fa5d2ce Nov 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering the system partition is ext4, and that's where the system fonts are located....

@NiLuJe
Copy link
Owner Author

@NiLuJe NiLuJe commented on fa5d2ce Nov 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed! :)

Please sign in to comment.