Browse Source

Merge pull request #47 from pwpiwi/fix_string_overflow

Fix potential string overflows.
pull/65/head
Tom G. Huang 4 years ago
committed by GitHub
parent
commit
6f9eb6cfe8
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      src/argtable3.c

10
src/argtable3.c

@ -643,7 +643,7 @@ void arg_print_option_ds(arg_dstr_t ds, const char* shortopts, const char* longo
suffix = suffix ? suffix : ""; suffix = suffix ? suffix : "";
/* there is no way of passing the proper optvalue for optional argument values here, so we must ignore it */ /* there is no way of passing the proper optvalue for optional argument values here, so we must ignore it */
arg_cat_optionv(syntax, sizeof(syntax), shortopts, longopts, datatype, 0, "|"); arg_cat_optionv(syntax, sizeof(syntax)-1, shortopts, longopts, datatype, 0, "|");
arg_dstr_cat(ds, syntax); arg_dstr_cat(ds, syntax);
arg_dstr_cat(ds, (char*)suffix); arg_dstr_cat(ds, (char*)suffix);
@ -730,7 +730,7 @@ void arg_print_syntax_ds(arg_dstr_t ds, void** argtable, const char* suffix) {
shortopts = table[tabindex]->shortopts; shortopts = table[tabindex]->shortopts;
longopts = table[tabindex]->longopts; longopts = table[tabindex]->longopts;
datatype = table[tabindex]->datatype; datatype = table[tabindex]->datatype;
arg_cat_option(syntax, sizeof(syntax), shortopts, longopts, datatype, table[tabindex]->flag & ARG_HASOPTVALUE); arg_cat_option(syntax, sizeof(syntax)-1, shortopts, longopts, datatype, table[tabindex]->flag & ARG_HASOPTVALUE);
if (strlen(syntax) > 0) { if (strlen(syntax) > 0) {
/* print mandatory instances of this option */ /* print mandatory instances of this option */
@ -789,7 +789,7 @@ void arg_print_syntaxv_ds(arg_dstr_t ds, void** argtable, const char* suffix) {
shortopts = table[tabindex]->shortopts; shortopts = table[tabindex]->shortopts;
longopts = table[tabindex]->longopts; longopts = table[tabindex]->longopts;
datatype = table[tabindex]->datatype; datatype = table[tabindex]->datatype;
arg_cat_optionv(syntax, sizeof(syntax), shortopts, longopts, datatype, table[tabindex]->flag & ARG_HASOPTVALUE, "|"); arg_cat_optionv(syntax, sizeof(syntax)-1, shortopts, longopts, datatype, table[tabindex]->flag & ARG_HASOPTVALUE, "|");
/* print mandatory options */ /* print mandatory options */
for (i = 0; i < table[tabindex]->mincount; i++) { for (i = 0; i < table[tabindex]->mincount; i++) {
@ -846,7 +846,7 @@ void arg_print_glossary_ds(arg_dstr_t ds, void** argtable, const char* format) {
const char* longopts = table[tabindex]->longopts; const char* longopts = table[tabindex]->longopts;
const char* datatype = table[tabindex]->datatype; const char* datatype = table[tabindex]->datatype;
const char* glossary = table[tabindex]->glossary; const char* glossary = table[tabindex]->glossary;
arg_cat_optionv(syntax, sizeof(syntax), shortopts, longopts, datatype, table[tabindex]->flag & ARG_HASOPTVALUE, ", "); arg_cat_optionv(syntax, sizeof(syntax)-1, shortopts, longopts, datatype, table[tabindex]->flag & ARG_HASOPTVALUE, ", ");
arg_dstr_catf(ds, format, syntax, glossary); arg_dstr_catf(ds, format, syntax, glossary);
} }
} }
@ -977,7 +977,7 @@ void arg_print_glossary_gnu_ds(arg_dstr_t ds, void** argtable) {
*(syntax + 4) = '\0'; *(syntax + 4) = '\0';
} }
arg_cat_optionv(syntax, sizeof(syntax), shortopts, longopts, datatype, table[tabindex]->flag & ARG_HASOPTVALUE, ", "); arg_cat_optionv(syntax, sizeof(syntax)-1, shortopts, longopts, datatype, table[tabindex]->flag & ARG_HASOPTVALUE, ", ");
/* If syntax fits not into column, print glossary in new line... */ /* If syntax fits not into column, print glossary in new line... */
if (strlen(syntax) > 25) { if (strlen(syntax) > 25) {

Loading…
Cancel
Save