Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9340fb8

Browse files
committed
In pg_upgrade, properly handle oids > 2^31 by using strtoul() internally
rather than atol().Per report from Brian Hirt
1 parenta1bb570 commit9340fb8

File tree

5 files changed

+35
-21
lines changed

5 files changed

+35
-21
lines changed

‎contrib/pg_upgrade/controldata.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
155155
pg_log(ctx,PG_FATAL,"%d: pg_resetxlog problem\n",__LINE__);
156156

157157
p++;/* removing ':' char */
158-
cluster->controldata.ctrl_ver=(uint32)atol(p);
158+
cluster->controldata.ctrl_ver=str2uint(p);
159159
}
160160
elseif ((p=strstr(bufin,"Catalog version number:"))!=NULL)
161161
{
@@ -165,7 +165,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
165165
pg_log(ctx,PG_FATAL,"%d: controldata retrieval problem\n",__LINE__);
166166

167167
p++;/* removing ':' char */
168-
cluster->controldata.cat_ver=(uint32)atol(p);
168+
cluster->controldata.cat_ver=str2uint(p);
169169
}
170170
elseif ((p=strstr(bufin,"First log file ID after reset:"))!=NULL)
171171
{
@@ -175,7 +175,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
175175
pg_log(ctx,PG_FATAL,"%d: controldata retrieval problem\n",__LINE__);
176176

177177
p++;/* removing ':' char */
178-
cluster->controldata.logid=(uint32)atol(p);
178+
cluster->controldata.logid=str2uint(p);
179179
got_log_id= true;
180180
}
181181
elseif ((p=strstr(bufin,"First log file segment after reset:"))!=NULL)
@@ -186,7 +186,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
186186
pg_log(ctx,PG_FATAL,"%d: controldata retrieval problem\n",__LINE__);
187187

188188
p++;/* removing ':' char */
189-
cluster->controldata.nxtlogseg=(uint32)atol(p);
189+
cluster->controldata.nxtlogseg=str2uint(p);
190190
got_log_seg= true;
191191
}
192192
elseif ((p=strstr(bufin,"Latest checkpoint's TimeLineID:"))!=NULL)
@@ -197,7 +197,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
197197
pg_log(ctx,PG_FATAL,"%d: controldata retrieval problem\n",__LINE__);
198198

199199
p++;/* removing ':' char */
200-
cluster->controldata.chkpnt_tli=(uint32)atol(p);
200+
cluster->controldata.chkpnt_tli=str2uint(p);
201201
got_tli= true;
202202
}
203203
elseif ((p=strstr(bufin,"Latest checkpoint's NextXID:"))!=NULL)
@@ -211,7 +211,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
211211
pg_log(ctx,PG_FATAL,"%d: controldata retrieval problem\n",__LINE__);
212212

213213
op++;/* removing ':' char */
214-
cluster->controldata.chkpnt_nxtxid=(uint32)atol(op);
214+
cluster->controldata.chkpnt_nxtxid=str2uint(op);
215215
got_xid= true;
216216
}
217217
elseif ((p=strstr(bufin,"Latest checkpoint's NextOID:"))!=NULL)
@@ -222,7 +222,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
222222
pg_log(ctx,PG_FATAL,"%d: controldata retrieval problem\n",__LINE__);
223223

224224
p++;/* removing ':' char */
225-
cluster->controldata.chkpnt_nxtoid=(uint32)atol(p);
225+
cluster->controldata.chkpnt_nxtoid=str2uint(p);
226226
got_oid= true;
227227
}
228228
elseif ((p=strstr(bufin,"Maximum data alignment:"))!=NULL)
@@ -233,7 +233,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
233233
pg_log(ctx,PG_FATAL,"%d: controldata retrieval problem\n",__LINE__);
234234

235235
p++;/* removing ':' char */
236-
cluster->controldata.align=(uint32)atol(p);
236+
cluster->controldata.align=str2uint(p);
237237
got_align= true;
238238
}
239239
elseif ((p=strstr(bufin,"Database block size:"))!=NULL)
@@ -244,7 +244,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
244244
pg_log(ctx,PG_FATAL,"%d: controldata retrieval problem\n",__LINE__);
245245

246246
p++;/* removing ':' char */
247-
cluster->controldata.blocksz=(uint32)atol(p);
247+
cluster->controldata.blocksz=str2uint(p);
248248
got_blocksz= true;
249249
}
250250
elseif ((p=strstr(bufin,"Blocks per segment of large relation:"))!=NULL)
@@ -255,7 +255,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
255255
pg_log(ctx,PG_FATAL,"%d: controldata retrieval problem\n",__LINE__);
256256

257257
p++;/* removing ':' char */
258-
cluster->controldata.largesz=(uint32)atol(p);
258+
cluster->controldata.largesz=str2uint(p);
259259
got_largesz= true;
260260
}
261261
elseif ((p=strstr(bufin,"WAL block size:"))!=NULL)
@@ -266,7 +266,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
266266
pg_log(ctx,PG_FATAL,"%d: controldata retrieval problem\n",__LINE__);
267267

268268
p++;/* removing ':' char */
269-
cluster->controldata.walsz=(uint32)atol(p);
269+
cluster->controldata.walsz=str2uint(p);
270270
got_walsz= true;
271271
}
272272
elseif ((p=strstr(bufin,"Bytes per WAL segment:"))!=NULL)
@@ -277,7 +277,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
277277
pg_log(ctx,PG_FATAL,"%d: controldata retrieval problem\n",__LINE__);
278278

279279
p++;/* removing ':' char */
280-
cluster->controldata.walseg=(uint32)atol(p);
280+
cluster->controldata.walseg=str2uint(p);
281281
got_walseg= true;
282282
}
283283
elseif ((p=strstr(bufin,"Maximum length of identifiers:"))!=NULL)
@@ -288,7 +288,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
288288
pg_log(ctx,PG_FATAL,"%d: controldata retrieval problem\n",__LINE__);
289289

290290
p++;/* removing ':' char */
291-
cluster->controldata.ident=(uint32)atol(p);
291+
cluster->controldata.ident=str2uint(p);
292292
got_ident= true;
293293
}
294294
elseif ((p=strstr(bufin,"Maximum columns in an index:"))!=NULL)
@@ -299,7 +299,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
299299
pg_log(ctx,PG_FATAL,"%d: controldata retrieval problem\n",__LINE__);
300300

301301
p++;/* removing ':' char */
302-
cluster->controldata.index=(uint32)atol(p);
302+
cluster->controldata.index=str2uint(p);
303303
got_index= true;
304304
}
305305
elseif ((p=strstr(bufin,"Maximum size of a TOAST chunk:"))!=NULL)
@@ -310,7 +310,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
310310
pg_log(ctx,PG_FATAL,"%d: controldata retrieval problem\n",__LINE__);
311311

312312
p++;/* removing ':' char */
313-
cluster->controldata.toast=(uint32)atol(p);
313+
cluster->controldata.toast=str2uint(p);
314314
got_toast= true;
315315
}
316316
elseif ((p=strstr(bufin,"Date/time type storage:"))!=NULL)

‎contrib/pg_upgrade/info.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ get_db_infos(migratorContext *ctx, DbInfoArr *dbinfs_arr, Cluster whichCluster)
242242

243243
for (tupnum=0;tupnum<ntups;tupnum++)
244244
{
245-
dbinfos[tupnum].db_oid=atol(PQgetvalue(res,tupnum,i_oid));
245+
dbinfos[tupnum].db_oid=str2uint(PQgetvalue(res,tupnum,i_oid));
246246

247247
snprintf(dbinfos[tupnum].db_name,sizeof(dbinfos[tupnum].db_name),"%s",
248248
PQgetvalue(res,tupnum,i_datname));
@@ -360,16 +360,16 @@ get_rel_infos(migratorContext *ctx, const DbInfo *dbinfo,
360360
RelInfo*curr=&relinfos[num_rels++];
361361
constchar*tblspace;
362362

363-
curr->reloid=atol(PQgetvalue(res,relnum,i_oid));
363+
curr->reloid=str2uint(PQgetvalue(res,relnum,i_oid));
364364

365365
nspname=PQgetvalue(res,relnum,i_nspname);
366366
strlcpy(curr->nspname,nspname,sizeof(curr->nspname));
367367

368368
relname=PQgetvalue(res,relnum,i_relname);
369369
strlcpy(curr->relname,relname,sizeof(curr->relname));
370370

371-
curr->relfilenode=atol(PQgetvalue(res,relnum,i_relfilenode));
372-
curr->toastrelid=atol(PQgetvalue(res,relnum,i_reltoastrelid));
371+
curr->relfilenode=str2uint(PQgetvalue(res,relnum,i_relfilenode));
372+
curr->toastrelid=str2uint(PQgetvalue(res,relnum,i_reltoastrelid));
373373

374374
tblspace=PQgetvalue(res,relnum,i_spclocation);
375375
/* if no table tablespace, use the database tablespace */

‎contrib/pg_upgrade/pg_upgrade.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ char *pg_strdup(migratorContext *ctx, const char *s);
376376
void*pg_malloc(migratorContext*ctx,intsize);
377377
voidpg_free(void*ptr);
378378
constchar*getErrorText(interrNum);
379+
unsignedintstr2uint(constchar*str);
380+
379381

380382
/* version.c */
381383

‎contrib/pg_upgrade/relfilenode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ get_pg_database_relfilenode(migratorContext *ctx, Cluster whichCluster)
9494

9595
i_relfile=PQfnumber(res,"relfilenode");
9696
if (whichCluster==CLUSTER_OLD)
97-
ctx->old.pg_database_oid=atol(PQgetvalue(res,0,i_relfile));
97+
ctx->old.pg_database_oid=str2uint(PQgetvalue(res,0,i_relfile));
9898
else
99-
ctx->new.pg_database_oid=atol(PQgetvalue(res,0,i_relfile));
99+
ctx->new.pg_database_oid=str2uint(PQgetvalue(res,0,i_relfile));
100100

101101
PQclear(res);
102102
PQfinish(conn);

‎contrib/pg_upgrade/util.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,15 @@ getErrorText(int errNum)
259259
#endif
260260
returnstrdup(strerror(errNum));
261261
}
262+
263+
264+
/*
265+
*str2uint()
266+
*
267+
*convert string to oid
268+
*/
269+
unsignedint
270+
str2uint(constchar*str)
271+
{
272+
returnstrtol(str,NULL,10);
273+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp