clients: return NULL array on auto-completion failure

readline crashes if we return an empty completion list; return NULL
instead.

This is reproducible, for example, with:

 $ nmcli --ask connection add
 Interface name [*]: doesnotexist<TAB>
 Segmentation fault (core dumped)

 $ nmcli --ask connection add
 Interface name [*]:
 Connection type: avian-carr<TAB>
 Segmentation fault (core dumped)
This commit is contained in:
Beniamino Galvani
2017-06-21 14:18:24 +02:00
parent a84facb90c
commit afac7621ae
2 changed files with 29 additions and 8 deletions

View File

@@ -294,13 +294,18 @@ nm_meta_abstract_info_complete (const NMMetaAbstractInfo *abstract_info,
if (*out_to_free) {
char **v = *out_to_free;
for (i =0, j = 0; v[i]; i++) {
for (i = 0, j = 0; v[i]; i++) {
if (strncmp (v[i], text, text_len) != 0)
continue;
v[j++] = v[i];
}
v[j++] = NULL;
return (const char *const*) *out_to_free;
if (j)
v[j++] = NULL;
else {
g_free (v);
v = NULL;
}
return (const char *const*) v;
} else {
const char *const*v = values;
char **r;
@@ -312,6 +317,8 @@ nm_meta_abstract_info_complete (const NMMetaAbstractInfo *abstract_info,
}
if (j == i)
return values;
else if (!j)
return NULL;
r = g_new (char *, j + 1);
v = values;

View File

@@ -1759,7 +1759,12 @@ _complete_fcn_vpn_service_type (ARGS_COMPLETE_FCN)
values[j] = values[i];
j++;
}
values[j++] = NULL;
if (j)
values[j++] = NULL;
else {
g_free (values);
values = NULL;
}
}
return (const char *const*) (*out_to_free = values);
}
@@ -2378,7 +2383,12 @@ _complete_fcn_connection_type (ARGS_COMPLETE_FCN)
result[j++] = g_strdup (v);
}
}
result[j++] = NULL;
if (j)
result[j++] = NULL;
else {
g_free (result);
result = NULL;
}
return (const char *const*) (*out_to_free = result);
}
@@ -2526,10 +2536,14 @@ _complete_fcn_connection_master (ARGS_COMPLETE_FCN)
if (v && (!text || strncmp (text, v, text_len) == 0))
result[j++] = g_strdup (v);
}
result[j++] = NULL;
if (j)
result[j++] = NULL;
else {
g_free (result);
result = NULL;
}
*out_to_free = NULL;
return (const char *const*) result;
return (const char *const*) (*out_to_free = result);
}
static gboolean