commit ac9f5419653ea017eead9ad9ffb4770f4939cde9
parent ff557169e4f055be968e40fb80c85d75c60dabb9
Author: Bakkeby <bakkeby@gmail.com>
Date: Tue, 5 Jul 2022 15:32:06 +0200
[st][patch][ligatures] fix potential buffer overflow in shaping code ref. https://git.suckless.org/sites/commit/05a0d9b6bf500a7b2955c4299a1912eb302ce40b.html
Diffstat:
| M | hb.c | | | 20 | +++++++++++++++----- |
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/hb.c b/hb.c
@@ -1,12 +1,16 @@
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
-#include <X11/Xft/Xft.h>
#include <time.h>
+#include <X11/Xft/Xft.h>
+#include <X11/cursorfont.h>
#include <hb.h>
#include <hb-ft.h>
+
#include "st.h"
+#define FEATURE(c1,c2,c3,c4) { .tag = HB_TAG(c1,c2,c3,c4), .value = 1, .start = HB_FEATURE_GLOBAL_START, .end = HB_FEATURE_GLOBAL_END }
+
void hbtransformsegment(XftFont *xfont, const Glyph *string, hb_codepoint_t *codepoints, int start, int length);
hb_font_t *hbfindfont(XftFont *match);
@@ -18,6 +22,13 @@ typedef struct {
static int hbfontslen = 0;
static HbFontMatch *hbfontcache = NULL;
+/*
+ * Poplulate the array with a list of font features, wrapped in FEATURE macro,
+ * e. g.
+ * FEATURE('c', 'a', 'l', 't'), FEATURE('d', 'l', 'i', 'g')
+ */
+hb_feature_t features[] = { };
+
void
hbunloadfonts()
{
@@ -59,7 +70,7 @@ void
hbtransform(XftGlyphFontSpec *specs, const Glyph *glyphs, size_t len, int x, int y)
{
int start = 0, length = 1, gstart = 0;
- hb_codepoint_t *codepoints = calloc(len, sizeof(hb_codepoint_t));
+ hb_codepoint_t *codepoints = calloc((unsigned int)len, sizeof(hb_codepoint_t));
for (int idx = 1, specidx = 1; idx < len; idx++) {
if (glyphs[idx].mode & ATTR_WDUMMY) {
@@ -127,7 +138,7 @@ hbtransformsegment(XftFont *xfont, const Glyph *string, hb_codepoint_t *codepoin
}
/* Shape the segment. */
- hb_shape(font, buffer, NULL, 0);
+ hb_shape(font, buffer, features, sizeof(features)/sizeof(hb_feature_t));
/* Get new glyph info. */
hb_glyph_info_t *info = hb_buffer_get_glyph_infos(buffer, NULL);
@@ -140,4 +151,4 @@ hbtransformsegment(XftFont *xfont, const Glyph *string, hb_codepoint_t *codepoin
/* Cleanup. */
hb_buffer_destroy(buffer);
-}
-\ No newline at end of file
+}