Project

General

Profile

Bug #265 » 0001-Don-t-use-splitted-string-after-PASS-.-Fix-265.patch

Pierre-Louis Bonicoli, 2011-12-20 05:09

View differences:

src/irc.c
859 859

  
860 860
static int irc_cli_pass(bip_t *bip, struct link_client *ic, struct line *line)
861 861
{
862
	if (irc_line_count(line) != 2)
862
	int len = 0;
863
	int nb_spaces;
864
	int i;
865

  
866
	if ((irc_line_count(line) < 2)
867
		|| !irc_line_elem_case_equals(line, 0, "PASS"))
863 868
		return ERR_PROTOCOL;
864 869

  
865 870
	if ((ic->state & IRCC_READY) == IRCC_READY)
866 871
		return ERR_PROTOCOL;
867 872

  
868 873
	ic->state |= IRCC_PASS;
869
	if (ic->init_pass)
874
	if (ic->init_pass) {
870 875
		free(ic->init_pass);
871
	ic->init_pass = bip_strdup(irc_line_elem(line, 1));
872
	if ((ic->state & IRCC_READY) == IRCC_READY)
876
		ic->init_pass = NULL;
877
	}
878

  
879
	// concat all words except prefix: "PASS"
880
	for (i = 1; i < array_count(&line->words); i++) {
881
		len += strlen(array_get(&line->words, i));
882
	}
883
	nb_spaces = array_count(&line->words) - 2;
884
	len += nb_spaces + 1;
885

  
886
	ic->init_pass = bip_malloc(len);
887
	ic->init_pass[0] = 0;
888

  
889
	for (i = 1; i < array_count(&line->words) - 1; i++) {
890
		strcat(ic->init_pass, array_get(&line->words, i));
891
		strcat(ic->init_pass, " ");
892
	}
893

  
894
	strcat(ic->init_pass, array_get(&line->words, i));
895

  
896
	if ((ic->state & IRCC_READY) == IRCC_READY) {
873 897
		return irc_cli_startup(bip, ic, line);
898
	}
874 899
	return OK_FORGET;
875 900
}
876 901

  
877
- 
(1-1/2)