NCBI C++ ToolKit
corrupt.c
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2  * Copyright (C) 2015 Frediano Ziglio
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19 
20 /*
21  * Check sending integer till they overlap a packet.
22  * This is to check if an integer can spread in multiple
23  * packets. The problem raise from internal implementation
24  * and how is handled the overlapping.
25  */
26 #include "common.h"
27 #include <freetds/checks.h>
28 
29 #include <common/test_assert.h>
30 
31 static const char select_query[] = "\nselect 'test'";
32 
33 static void
35 {
36  int char_len;
37  char *buf, *p;
38  int i, len;
39  union {
41  TDS_UINT i;
42  TDS_INT8 i8;
43  char buf[8];
44  } conv;
45 
46  if (IS_TDS72_PLUS(tds->conn))
47  return;
48 
50 
51  /* try to build an invalid (unfinished) query split in two packets */
52  char_len = IS_TDS7_PLUS(tds->conn) ? 2 : 1;
53  buf = tds_new0(char, tds->out_buf_max + 200);
54  memset(buf, '-', tds->out_buf_max + 200);
55  strcpy(buf + (tds->out_buf_max - 8) / char_len - strlen(select_query) + 1, select_query);
56  memset(strchr(buf, 0), 0, 16);
57 
58  /* convert if needed */
59  len = (int) strlen(buf);
60  for (i = len; --i >= 0; ) {
61  char c = buf[i];
62  buf[i * char_len + 0] = c;
63  if (IS_TDS7_PLUS(tds->conn))
64  buf[i * char_len + 1] = 0;
65  }
66  len *= char_len;
67 
68  /* send the query using tds_put_int8, non allineati */
71  exit(1);
72  p = buf;
73  memcpy(conv.buf, p, 2);
75  p += 2;
76  for (; p < buf + len; p += 8) {
78  memcpy(conv.buf, p, 8);
79  tds_put_int8(tds, conv.i8);
80  }
83 
84  /* check result was fine */
86  fprintf(stderr, "Error in prepared query\n");
87  exit(1);
88  }
89  free(buf);
90 }
91 
92 int
93 main(int argc, char **argv)
94 {
95  TDSLOGIN *login;
96  TDSSOCKET *tds;
97  int ret;
98  int verbose = 0;
99  TDS_INT8 i8;
100  unsigned limit;
101 
102  fprintf(stdout, "%s: Testing login, logout\n", __FILE__);
103  ret = try_tds_login(&login, &tds, __FILE__, verbose);
104  if (ret != TDS_SUCCESS) {
105  fprintf(stderr, "try_tds_login() failed\n");
106  return 1;
107  }
108 
110 
113  return 1;
114  }
115 
116  tds_put_n(tds, "aaa", 3);
117  limit = tds->out_buf_max / 8 + 100;
118  for (i8 = 0; i8 < limit; ++i8) {
120  tds_put_int8(tds, i8);
121  }
122 
125 
127  return 0;
128 }
static TDSICONV * conv
Definition: charconv.c:168
#define CHECK_TDS_EXTRA(tds)
Definition: checks.h:31
static TDSSOCKET * tds
Definition: collations.c:37
int main(int argc, char **argv)
Definition: corrupt.c:93
static const char select_query[]
Definition: corrupt.c:31
static void unfinished_query_test(TDSSOCKET *tds)
Definition: corrupt.c:34
static TDSLOGIN * login
Definition: dataread.c:31
static const char si[8][64]
Definition: des.c:146
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
exit(2)
char * buf
int i
int len
true_type verbose
Definition: processing.cpp:890
@ TDS_QUERY
Definition: proto.h:333
#define tds_put_n
#define tds_send_cancel
#define tds_put_int8
#define tds_put_smallint
#define tds_process_simple_query
#define tds_flush_packet
#define tds_init_write_buf
#define tds_set_state
Definition: tds.h:584
Information for a server connection.
Definition: tds.h:1211
unsigned char out_flag
output buffer type
Definition: tds.h:1241
unsigned int out_buf_max
Maximum size of packet pointed by out_buf.
Definition: tds.h:1236
TDSCONNECTION conn[1]
Definition: tds.h:1215
int try_tds_logout(TDSLOGIN *login, TDSSOCKET *tds, int verbose)
Definition: common.c:128
int try_tds_login(TDSLOGIN **login, TDSSOCKET **tds, const char *appname, int verbose)
Definition: common.c:55
#define TDS_FAILED(rc)
Definition: tds.h:206
tds_sysdep_int64_type TDS_INT8
Definition: tds.h:153
#define IS_TDS72_PLUS(x)
Definition: tds.h:1710
@ TDS_PENDING
cilent is waiting for data
Definition: tds.h:866
@ TDS_WRITING
client is writing data
Definition: tds.h:864
#define IS_TDS7_PLUS(x)
Definition: tds.h:1708
#define tds_new0(type, n)
Definition: tds.h:1393
tds_sysdep_uint16_type TDS_USMALLINT
Definition: tds.h:148
#define TDS_SUCCESS
Definition: tds.h:203
tds_sysdep_uint32_type TDS_UINT
Definition: tds.h:150
void free(voidpf ptr)
Modified on Thu Feb 22 17:14:38 2024 by modify_doxy.py rev. 669887