projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix up potential overflows in size calculations by replacing
[pspp]
/
src
/
groff-font.c
diff --git
a/src/groff-font.c
b/src/groff-font.c
index 9427089d3009f330e1e5997a6c59aab56583862e..5df16f43f0084f080f7f249e51681d398aa27e58 100644
(file)
--- a/
src/groff-font.c
+++ b/
src/groff-font.c
@@
-28,11
+28,15
@@
#include "alloc.h"
#include "error.h"
#include "filename.h"
#include "alloc.h"
#include "error.h"
#include "filename.h"
+#include "getline.h"
#include "hash.h"
#include "pool.h"
#include "str.h"
#include "version.h"
#include "hash.h"
#include "pool.h"
#include "str.h"
#include "version.h"
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+
int font_number_to_index (int);
int space_index;
int font_number_to_index (int);
int space_index;
@@
-388,10
+392,15
@@
lose:
static int
font_msg (int class, const char *format,...)
{
static int
font_msg (int class, const char *format,...)
{
+ struct error error;
va_list args;
va_list args;
+ error.class = class;
+ err_location (&error.where);
+ error.title = _("installation error: Groff font error: ");
+
va_start (args, format);
va_start (args, format);
-
tmsg (class, format, args, _("installation error: Groff font error: ")
);
+
err_vmsg (&error, format, args
);
va_end (args);
return 0;
va_end (args);
return 0;
@@
-402,7
+411,7
@@
font_msg (int class, const char *format,...)
static void
scan_badchars (char *line, int len)
{
static void
scan_badchars (char *line, int len)
{
-
unsigned
char *cp = line;
+ char *cp = line;
/* Same bad characters as Groff. */
static unsigned char badchars[32] =
/* Same bad characters as Groff. */
static unsigned char badchars[32] =
@@
-413,12
+422,15
@@
scan_badchars (char *line, int len)
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
- for (; len--; cp++)
- if (badchars[*cp >> 3] & (1 << (*cp & 7)))
- {
- font_msg (SE, _("Bad character \\%3o."), *cp);
- *cp = ' ';
- }
+ for (; len--; cp++)
+ {
+ int c = (unsigned char) *cp;
+ if (badchars[c >> 3] & (1 << (c & 7)))
+ {
+ font_msg (SE, _("Bad character \\%3o."), *cp);
+ *cp = ' ';
+ }
+ }
}
\f
/* Character name hashing. */
}
\f
/* Character name hashing. */
@@
-480,7
+492,7
@@
font_char_name_to_index (const char *name)
hash.size = 128;
hash.used = 0;
hash.next_index = 256;
hash.size = 128;
hash.used = 0;
hash.next_index = 256;
- hash.tab = x
malloc (sizeof *hash.tab * hash.size
);
+ hash.tab = x
nmalloc (hash.size, sizeof *hash.tab
);
hash.ar = pool_create ();
for (i = 0; i < hash.size; i++)
hash.tab[i].name = NULL;
hash.ar = pool_create ();
for (i = 0; i < hash.size; i++)
hash.tab[i].name = NULL;
@@
-502,7
+514,7
@@
font_char_name_to_index (const char *name)
int i, j;
hash.size *= 2;
int i, j;
hash.size *= 2;
- hash.tab = x
malloc (sizeof *hash.tab * hash.size
);
+ hash.tab = x
nmalloc (hash.size, sizeof *hash.tab
);
for (i = 0; i < hash.size; i++)
hash.tab[i].name = NULL;
for (i = 0; i < old_size; i++)
for (i = 0; i < hash.size; i++)
hash.tab[i].name = NULL;
for (i = 0; i < old_size; i++)
@@
-550,8
+562,8
@@
check_deref_space (struct font_desc *font, int min_size)
font->deref_size = min_size + 16;
if (font->deref_size < 256)
font->deref_size = 256;
font->deref_size = min_size + 16;
if (font->deref_size < 256)
font->deref_size = 256;
- font->deref = pool_realloc (font->owner, font->deref,
-
sizeof *font->deref * font->deref_size
);
+ font->deref = pool_
n
realloc (font->owner, font->deref,
+
font->deref_size, sizeof *font->deref
);
for (; i < font->deref_size; i++)
font->deref[i] = -1;
}
for (; i < font->deref_size; i++)
font->deref[i] = -1;
}
@@
-565,8
+577,8
@@
add_char_metric (struct font_desc *font, struct char_metrics *metrics, int code)
if (font->metric_used >= font->metric_size)
{
font->metric_size += 64;
if (font->metric_used >= font->metric_size)
{
font->metric_size += 64;
- font->metric = pool_realloc (font->owner, font->metric,
-
sizeof *font->metric * font->metric_size
);
+ font->metric = pool_
n
realloc (font->owner, font->metric,
+
font->metric_size, sizeof *font->metric
);
}
font->metric[font->metric_used] = metrics;
font->deref[code] = font->metric_used++;
}
font->metric[font->metric_used] = metrics;
font->deref[code] = font->metric_used++;
@@
-603,8
+615,8
@@
add_kern (struct font_desc *font, int ch1, int ch2, int adjust)
font->kern_size *= 2;
font->kern_max_used = font->kern_size / 2;
font->kern_size *= 2;
font->kern_max_used = font->kern_size / 2;
- font->kern = pool_malloc (font->owner,
-
sizeof *font->kern * font->kern_size
);
+ font->kern = pool_
n
malloc (font->owner,
+
font->kern_size, sizeof *font->kern
);
for (i = 0; i < font->kern_size; i++)
font->kern[i].ch1 = -1;
for (i = 0; i < font->kern_size; i++)
font->kern[i].ch1 = -1;
@@
-807,8
+819,8
@@
groff_read_DESC (const char *dev_name, struct groff_device_info * dev)
if (dev->n_sizes + 2 >= m_sizes)
{
m_sizes += 1;
if (dev->n_sizes + 2 >= m_sizes)
{
m_sizes += 1;
- dev->sizes = xrealloc (dev->sizes,
-
m_sizes *
sizeof *dev->sizes);
+ dev->sizes = x
n
realloc (dev->sizes,
+
m_sizes,
sizeof *dev->sizes);
}
dev->sizes[dev->n_sizes++][0] = lower;
dev->sizes[dev->n_sizes][1] = upper;
}
dev->sizes[dev->n_sizes++][0] = lower;
dev->sizes[dev->n_sizes][1] = upper;