mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Try to capture some more potential buffer overflows caused by localization
A couple of these could clearly cause a crash just like the one fixed by commit 00865f5a1e1a ("equipment.c: Fix potential buffer overflow in size_data_funct()"). One would append user input to fixed length buffer without checking. We were hardcoding the (correct) max path length in macos.c - replaced by the actual OS constant. But the vast majority are just extremely generous guesses how long localized strings could possibly be. Yes, this commit is likely leaning towards overkill. But we have now been bitten by buffer overflow crashes twice that were caused by localization, so I tried to go through all of the code and identify every possible buffer that could be affected by this. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
93eeb03d67
commit
0129192958
13 changed files with 31 additions and 30 deletions
2
dive.c
2
dive.c
|
@ -354,7 +354,7 @@ static void match_standard_cylinder(cylinder_type_t *type)
|
||||||
double cuft;
|
double cuft;
|
||||||
int psi, len;
|
int psi, len;
|
||||||
const char *fmt;
|
const char *fmt;
|
||||||
char buffer[20], *p;
|
char buffer[40], *p;
|
||||||
|
|
||||||
/* Do we already have a cylinder description? */
|
/* Do we already have a cylinder description? */
|
||||||
if (type->description)
|
if (type->description)
|
||||||
|
|
|
@ -361,7 +361,7 @@ static void duration_data_func(GtkTreeViewColumn *col,
|
||||||
{
|
{
|
||||||
unsigned int sec;
|
unsigned int sec;
|
||||||
int idx;
|
int idx;
|
||||||
char buffer[16];
|
char buffer[40];
|
||||||
|
|
||||||
gtk_tree_model_get(model, iter, DIVE_INDEX, &idx, DIVE_DURATION, &sec, -1);
|
gtk_tree_model_get(model, iter, DIVE_INDEX, &idx, DIVE_DURATION, &sec, -1);
|
||||||
if (idx < 0)
|
if (idx < 0)
|
||||||
|
|
|
@ -1356,7 +1356,7 @@ static void weight_data_func(GtkTreeViewColumn *col,
|
||||||
int idx = (long)data;
|
int idx = (long)data;
|
||||||
int grams, decimals;
|
int grams, decimals;
|
||||||
double value;
|
double value;
|
||||||
char buffer[10];
|
char buffer[64];
|
||||||
|
|
||||||
gtk_tree_model_get(model, iter, idx, &grams, -1);
|
gtk_tree_model_get(model, iter, idx, &grams, -1);
|
||||||
decimals = convert_weight(grams, &value);
|
decimals = convert_weight(grams, &value);
|
||||||
|
|
|
@ -1793,7 +1793,7 @@ static gboolean profile_tooltip (GtkWidget *widget, gint x, gint y,
|
||||||
gint tx = x - drawing_area->x; /* get transformed coordinates */
|
gint tx = x - drawing_area->x; /* get transformed coordinates */
|
||||||
gint ty = y - drawing_area->y;
|
gint ty = y - drawing_area->y;
|
||||||
gint width, height, time = -1;
|
gint width, height, time = -1;
|
||||||
char buffer[256], plot[256];
|
char buffer[2048], plot[1024];
|
||||||
const char *event = "";
|
const char *event = "";
|
||||||
|
|
||||||
if (tx < 0 || ty < 0)
|
if (tx < 0 || ty < 0)
|
||||||
|
@ -2082,7 +2082,7 @@ void set_dc_nickname(struct dive *dive)
|
||||||
{
|
{
|
||||||
GtkWidget *dialog, *vbox, *entry, *frame, *label;
|
GtkWidget *dialog, *vbox, *entry, *frame, *label;
|
||||||
char nickname[160] = "";
|
char nickname[160] = "";
|
||||||
char dialogtext[1024];
|
char dialogtext[2048];
|
||||||
const char *name = nickname;
|
const char *name = nickname;
|
||||||
struct divecomputer *dc = &dive->dc;
|
struct divecomputer *dc = &dive->dc;
|
||||||
|
|
||||||
|
|
4
info.c
4
info.c
|
@ -793,7 +793,7 @@ static void dive_info_widget(GtkWidget *obox, struct dive *dive, struct dive_inf
|
||||||
GtkWidget *image;
|
GtkWidget *image;
|
||||||
#endif
|
#endif
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
char airtemp[6];
|
char airtemp[10];
|
||||||
const char *unit;
|
const char *unit;
|
||||||
double value;
|
double value;
|
||||||
|
|
||||||
|
@ -1152,7 +1152,7 @@ int edit_dive_info(struct dive *dive, gboolean newdive)
|
||||||
static GtkWidget *frame_box(GtkWidget *vbox, const char *fmt, ...)
|
static GtkWidget *frame_box(GtkWidget *vbox, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
char buffer[64];
|
char buffer[128];
|
||||||
GtkWidget *frame, *hbox;
|
GtkWidget *frame, *hbox;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
|
|
|
@ -270,7 +270,7 @@ sample_cb(dc_sample_type_t type, dc_sample_value_t value, void *userdata)
|
||||||
|
|
||||||
static void dev_info(device_data_t *devdata, const char *fmt, ...)
|
static void dev_info(device_data_t *devdata, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
static char buffer[256];
|
static char buffer[1024];
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
|
@ -358,7 +358,7 @@ static inline int year(int year)
|
||||||
static char *str_printf(const char *fmt, ...)
|
static char *str_printf(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
char buf[80];
|
char buf[1024];
|
||||||
|
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
vsnprintf(buf, sizeof(buf)-1, fmt, args);
|
vsnprintf(buf, sizeof(buf)-1, fmt, args);
|
||||||
|
|
11
macos.c
11
macos.c
|
@ -7,6 +7,7 @@
|
||||||
#include <CoreServices/CoreServices.h>
|
#include <CoreServices/CoreServices.h>
|
||||||
#include <mach-o/dyld.h>
|
#include <mach-o/dyld.h>
|
||||||
#include "gtkosxapplication.h"
|
#include "gtkosxapplication.h"
|
||||||
|
#include <sys/syslimits.h>
|
||||||
|
|
||||||
static GtkosxApplication *osx_app;
|
static GtkosxApplication *osx_app;
|
||||||
|
|
||||||
|
@ -148,9 +149,9 @@ int subsurface_fill_device_list(GtkListStore *store)
|
||||||
|
|
||||||
const char *subsurface_icon_name()
|
const char *subsurface_icon_name()
|
||||||
{
|
{
|
||||||
static char path[1024];
|
static char path[PATH_MAX];
|
||||||
|
|
||||||
snprintf(path, 1024, "%s/%s", gtkosx_application_get_resource_path(), ICON_NAME);
|
snprintf(path, sizeof(path), "%s/%s", gtkosx_application_get_resource_path(), ICON_NAME);
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
@ -173,7 +174,7 @@ const char *subsurface_gettext_domainpath(char *argv0)
|
||||||
{
|
{
|
||||||
/* on a Mac we ignore the argv0 argument and instead use the resource_path
|
/* on a Mac we ignore the argv0 argument and instead use the resource_path
|
||||||
* to figure out where to find the translation files */
|
* to figure out where to find the translation files */
|
||||||
static char buffer[256];
|
static char buffer[PATH_MAX];
|
||||||
const char *resource_path = gtkosx_application_get_resource_path();
|
const char *resource_path = gtkosx_application_get_resource_path();
|
||||||
if (resource_path) {
|
if (resource_path) {
|
||||||
snprintf(buffer, sizeof(buffer), "%s/share/locale", resource_path);
|
snprintf(buffer, sizeof(buffer), "%s/share/locale", resource_path);
|
||||||
|
@ -192,9 +193,9 @@ void subsurface_ui_setup(GtkSettings *settings, GtkWidget *menubar,
|
||||||
GtkWidget *vbox, GtkUIManager *ui_manager)
|
GtkWidget *vbox, GtkUIManager *ui_manager)
|
||||||
{
|
{
|
||||||
GtkWidget *menu_item, *sep;
|
GtkWidget *menu_item, *sep;
|
||||||
static char path[1024];
|
static char path[PATH_MAX];
|
||||||
|
|
||||||
snprintf(path, 1024, "%s/xslt", gtkosx_application_get_resource_path());
|
snprintf(path, sizeof(path), "%s/xslt", gtkosx_application_get_resource_path());
|
||||||
setenv("SUBSURFACE_XSLT_PATH", path, TRUE);
|
setenv("SUBSURFACE_XSLT_PATH", path, TRUE);
|
||||||
|
|
||||||
g_object_set(G_OBJECT(settings), "gtk-font-name", UI_FONT, NULL);
|
g_object_set(G_OBJECT(settings), "gtk-font-name", UI_FONT, NULL);
|
||||||
|
|
|
@ -806,7 +806,7 @@ static const char *country, *city;
|
||||||
static void divinglog_place(char *place, void *_location)
|
static void divinglog_place(char *place, void *_location)
|
||||||
{
|
{
|
||||||
char **location = _location;
|
char **location = _location;
|
||||||
char buffer[256], *p;
|
char buffer[1024], *p;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
len = snprintf(buffer, sizeof(buffer),
|
len = snprintf(buffer, sizeof(buffer),
|
||||||
|
|
8
print.c
8
print.c
|
@ -69,7 +69,7 @@ static void show_dive_header(struct dive *dive, cairo_t *cr, double w,
|
||||||
PangoLayout *layout;
|
PangoLayout *layout;
|
||||||
PangoRectangle ink_ext, logic_ext;
|
PangoRectangle ink_ext, logic_ext;
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
char buffer[160], divenr[40], *people;
|
char buffer[512], divenr[80], *people;
|
||||||
|
|
||||||
maxwidth = w * PANGO_SCALE;
|
maxwidth = w * PANGO_SCALE;
|
||||||
maxheight = h * PANGO_SCALE * 0.9;
|
maxheight = h * PANGO_SCALE * 0.9;
|
||||||
|
@ -355,7 +355,7 @@ static void print_weight_data (struct dive *dive, cairo_t *cr, int maxwidth, int
|
||||||
/* Print the dive OTUs */
|
/* Print the dive OTUs */
|
||||||
static void print_otus (struct dive *dive, cairo_t *cr, PangoLayout *layout, int maxwidth)
|
static void print_otus (struct dive *dive, cairo_t *cr, PangoLayout *layout, int maxwidth)
|
||||||
{
|
{
|
||||||
char buffer[40];
|
char buffer[128];
|
||||||
|
|
||||||
cairo_move_to (cr,(maxwidth*0.05) / ((double) PANGO_SCALE), 0);
|
cairo_move_to (cr,(maxwidth*0.05) / ((double) PANGO_SCALE), 0);
|
||||||
snprintf(buffer, sizeof(buffer), _("OTU"));
|
snprintf(buffer, sizeof(buffer), _("OTU"));
|
||||||
|
@ -370,7 +370,7 @@ static void print_otus (struct dive *dive, cairo_t *cr, PangoLayout *layout, int
|
||||||
/* Print the dive maxCNS */
|
/* Print the dive maxCNS */
|
||||||
static void print_cns (struct dive *dive, cairo_t *cr, PangoLayout *layout, int maxwidth)
|
static void print_cns (struct dive *dive, cairo_t *cr, PangoLayout *layout, int maxwidth)
|
||||||
{
|
{
|
||||||
char buffer[40];
|
char buffer[128];
|
||||||
|
|
||||||
|
|
||||||
cairo_move_to (cr,(maxwidth*0.05) / ((double) PANGO_SCALE), 0);
|
cairo_move_to (cr,(maxwidth*0.05) / ((double) PANGO_SCALE), 0);
|
||||||
|
@ -389,7 +389,7 @@ static void print_SAC (struct dive *dive, cairo_t *cr, PangoLayout *layout, int
|
||||||
double sac;
|
double sac;
|
||||||
int decimals;
|
int decimals;
|
||||||
const char *unit;
|
const char *unit;
|
||||||
char buffer[40];
|
char buffer[128];
|
||||||
|
|
||||||
cairo_move_to (cr,(maxwidth*0.05) / ((double) PANGO_SCALE), 0);
|
cairo_move_to (cr,(maxwidth*0.05) / ((double) PANGO_SCALE), 0);
|
||||||
snprintf(buffer, sizeof(buffer), _("SAC"));
|
snprintf(buffer, sizeof(buffer), _("SAC"));
|
||||||
|
|
|
@ -268,7 +268,7 @@ static void plot_text(struct graphics_context *gc, const text_render_options_t *
|
||||||
cairo_font_extents_t fe;
|
cairo_font_extents_t fe;
|
||||||
cairo_text_extents_t extents;
|
cairo_text_extents_t extents;
|
||||||
double dx, dy;
|
double dx, dy;
|
||||||
char buffer[80];
|
char buffer[256];
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
|
@ -346,7 +346,7 @@ static void plot_one_event(struct graphics_context *gc, struct plot_info *pi, st
|
||||||
{
|
{
|
||||||
int i, depth = 0;
|
int i, depth = 0;
|
||||||
int x,y;
|
int x,y;
|
||||||
char buffer[80];
|
char buffer[256];
|
||||||
|
|
||||||
/* is plotting this event disabled? */
|
/* is plotting this event disabled? */
|
||||||
if (event->name) {
|
if (event->name) {
|
||||||
|
|
|
@ -192,7 +192,7 @@ static void init_tree()
|
||||||
|
|
||||||
/* Add all the columns to the tree view */
|
/* Add all the columns to the tree view */
|
||||||
for (i = 0; i < N_COLUMNS; ++i) {
|
for (i = 0; i < N_COLUMNS; ++i) {
|
||||||
char buf[80];
|
char buf[256];
|
||||||
column = gtk_tree_view_column_new();
|
column = gtk_tree_view_column_new();
|
||||||
snprintf(buf, sizeof(buf), "%s\n%s", _(columnstop[i]), columnsbot[i]);
|
snprintf(buf, sizeof(buf), "%s\n%s", _(columnstop[i]), columnsbot[i]);
|
||||||
gtk_tree_view_column_set_title(column, buf);
|
gtk_tree_view_column_set_title(column, buf);
|
||||||
|
@ -500,7 +500,7 @@ void process_selected_dives(void)
|
||||||
|
|
||||||
static void set_label(GtkWidget *w, const char *fmt, ...)
|
static void set_label(GtkWidget *w, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
char buf[80];
|
char buf[256];
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
|
@ -531,7 +531,7 @@ static char *get_time_string(int seconds, int maxdays)
|
||||||
* to dive data, but for consistency we don't. */
|
* to dive data, but for consistency we don't. */
|
||||||
static void show_single_dive_stats(struct dive *dive)
|
static void show_single_dive_stats(struct dive *dive)
|
||||||
{
|
{
|
||||||
char buf[80];
|
char buf[256];
|
||||||
double value;
|
double value;
|
||||||
int decimals;
|
int decimals;
|
||||||
const char *unit;
|
const char *unit;
|
||||||
|
|
|
@ -145,7 +145,7 @@ static struct dive *uemis_start_dive(uint32_t deviceid)
|
||||||
/* send text to the importer progress bar */
|
/* send text to the importer progress bar */
|
||||||
static void uemis_info(const char *fmt, ...)
|
static void uemis_info(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
static char buffer[40];
|
static char buffer[256];
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
|
@ -544,7 +544,7 @@ static void parse_divespot(char *buf)
|
||||||
char *bp = buf + 1;
|
char *bp = buf + 1;
|
||||||
char *tp = next_token(&bp);
|
char *tp = next_token(&bp);
|
||||||
char *tag, *type, *val;
|
char *tag, *type, *val;
|
||||||
char locationstring[255] = "";
|
char locationstring[1024] = "";
|
||||||
int divespot, len;
|
int divespot, len;
|
||||||
double latitude, longitude;
|
double latitude, longitude;
|
||||||
|
|
||||||
|
|
|
@ -49,11 +49,11 @@ gboolean webservice_request_user_xml(const gchar *user_id,
|
||||||
SoupMessage *msg;
|
SoupMessage *msg;
|
||||||
SoupSession *session;
|
SoupSession *session;
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
gchar url[80] = {0};
|
gchar url[256] = {0};
|
||||||
|
|
||||||
session = soup_session_async_new();
|
session = soup_session_async_new();
|
||||||
strcat(url, "http://api.hohndel.org/api/dive/get/?login=");
|
strcat(url, "http://api.hohndel.org/api/dive/get/?login=");
|
||||||
strcat(url, user_id);
|
strncat(url, user_id, sizeof(url) - strlen(url) - 1);
|
||||||
msg = soup_message_new("GET", url);
|
msg = soup_message_new("GET", url);
|
||||||
soup_message_headers_append(msg->request_headers, "Accept", "text/xml");
|
soup_message_headers_append(msg->request_headers, "Accept", "text/xml");
|
||||||
soup_session_send_message(session, msg);
|
soup_session_send_message(session, msg);
|
||||||
|
@ -115,7 +115,7 @@ static void download_dialog_connect_cb(GtkWidget *w, gpointer data)
|
||||||
guint len, status_connect, status_xml;
|
guint len, status_connect, status_xml;
|
||||||
gchar *xmldata;
|
gchar *xmldata;
|
||||||
gboolean ret;
|
gboolean ret;
|
||||||
gchar err[128] = {0};
|
gchar err[256] = {0};
|
||||||
|
|
||||||
gtk_label_set_text(GTK_LABEL(state->status), _("Connecting..."));
|
gtk_label_set_text(GTK_LABEL(state->status), _("Connecting..."));
|
||||||
gtk_widget_set_sensitive(state->apply, FALSE);
|
gtk_widget_set_sensitive(state->apply, FALSE);
|
||||||
|
@ -126,7 +126,7 @@ static void download_dialog_connect_cb(GtkWidget *w, gpointer data)
|
||||||
if (status_xml != DD_STATUS_OK)
|
if (status_xml != DD_STATUS_OK)
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
} else {
|
} else {
|
||||||
sprintf(err, "%s %u!", download_dialog_status_text(DD_STATUS_ERROR_CONNECT), status_connect);
|
snprintf(err, sizeof(err), "%s %u!", download_dialog_status_text(DD_STATUS_ERROR_CONNECT), status_connect);
|
||||||
gtk_label_set_text(GTK_LABEL(state->status), err);
|
gtk_label_set_text(GTK_LABEL(state->status), err);
|
||||||
}
|
}
|
||||||
state->xmldata = xmldata;
|
state->xmldata = xmldata;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue